Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add feature to fallback to stix font in mathtext #11644

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions lib/matplotlib/mathtext.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,10 @@ class UnicodeFonts(TruetypeFonts):

def __init__(self, *args, **kwargs):
# This must come first so the backend's owner is set correctly
if rcParams['mathtext.fallback_to_cm']:
if rcParams['mathtext.fallback'] == 'stix':
self.cm_fallback = StixFonts(*args, **kwargs)
elif (rcParams['mathtext.fallback'] == 'cm' or
rcParams['mathtext.fallback_to_cm']):
self.cm_fallback = BakomaFonts(*args, **kwargs)
else:
self.cm_fallback = None
Expand All @@ -772,6 +775,21 @@ def __init__(self, *args, **kwargs):
font = findfont(prop)
self.fontmap['ex'] = font

# include STIZ sized alternatives for glyphs if fallback is STIX
Copy link
Contributor

@anntzer anntzer Nov 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

STIX? (typo)

if isinstance(self.cm_fallback, StixFonts):
stixsizedaltfonts = {
0: 'STIXGeneral',
1: 'STIXSizeOneSym',
2: 'STIXSizeTwoSym',
3: 'STIXSizeThreeSym',
4: 'STIXSizeFourSym',
5: 'STIXSizeFiveSym'}

for size, name in stixsizedaltfonts.items():
fullpath = findfont(name)
self.fontmap[size] = fullpath
self.fontmap[name] = fullpath

_slanted_symbols = set(r"\int \oint".split())

def _map_virtual_font(self, fontname, font_class, uniindex):
Expand Down Expand Up @@ -825,13 +843,17 @@ def _get_glyph(self, fontname, font_class, sym, fontsize, math=True):
warnings.warn(
"Substituting with a symbol from Computer Modern.",
MathTextWarning)
elif isinstance(self.cm_fallback, StixFonts):
warnings.warn("Substituting with a symbol from STIX.",
MathTextWarning)

if (fontname in ('it', 'regular') and
isinstance(self.cm_fallback, StixFonts)):
return self.cm_fallback._get_glyph(
'rm', font_class, sym, fontsize)
else:
return self.cm_fallback._get_glyph(
fontname, font_class, sym, fontsize)
fontname = 'rm'

return self.cm_fallback._get_glyph(
fontname, font_class, sym, fontsize)

else:
if (fontname in ('it', 'regular')
and isinstance(self, StixFonts)):
Expand Down
15 changes: 15 additions & 0 deletions lib/matplotlib/rcsetup.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,20 @@ def validate_font_properties(s):
return s


def validate_mathtext_fallback(s):
fallback_fonts = ['cm', 'stix']
if s is None or s == 'None':
return None

if not isinstance(s, str):
raise ValueError("Must be a string or None.")

if s.lower() in fallback_fonts:
return s

raise ValueError("%s is not a valid fallback font name. Valid fallback "
"font names are %s." % (s, ", ".join(fallback_fonts)))

validate_fontset = ValidateInStrings(
'fontset',
['dejavusans', 'dejavuserif', 'cm', 'stix', 'stixsans', 'custom'])
Expand Down Expand Up @@ -1117,6 +1131,7 @@ def _validate_linestyle(ls):
'mathtext.fontset': ['dejavusans', validate_fontset],
'mathtext.default': ['it', validate_mathtext_default],
'mathtext.fallback_to_cm': [True, validate_bool],
'mathtext.fallback': [None, validate_mathtext_fallback],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs some documentation. In particular it seems fallback overrides fallback_to_cm if its set; there should be a comment in here.

Preferably, we would deprecate fallback_to_cm and make cm the default for mathtext.fallback.

This needs to be in matplotlibrc.template as well, right?

anntzer reacted with thumbs up emoji

'image.aspect': ['equal', validate_aspect], # equal, auto, a number
'image.interpolation': ['nearest', validate_string],
Expand Down

AltStyle によって変換されたページ (->オリジナル) /