Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Description
Feature request
Feature summary
Allow users to specify a mathtext fallback font when custom mathtext font lacks a needed character.
More detail
Currently, a user can choose a font for the mathtext. For example, to use Open Sans for text and math, you can do:
rcParams['font.sans-serif'] = 'open sans'rcParams['mathtext.fontset'] = 'custom'rcParams['mathtext.it'] = 'sans:italic'
Open Sans has pretty good coverage of the characters needed for plots, including the Greek alphabet, but it's missing, for example, a character that maps to the latex command$\phi$
(it's phi maps to$\varphi$
). If you use the above configuration with textbox containing$\phi$
, the system falls back to computer modern, in accordance with thefallback_to_cm
rc parameter. It would be nice, however, to be able to fall back to a similar font for that character, preferable a sans serif font in a comparable weight.
This is already implemented for the default DejaVu Sans. It falls back to Stix Sans instead of CM to get a more uniform look. (In theDejaVuFonts
class, the line
self.cm_fallback = StixSansFonts(*args, **kwargs)
sets this.)
In my example with Open Sans, I can get a better result by changing the line
self.cm_fallback = BakomaFonts(*args, **kwargs)
to
self.cm_fallback = DejaVuSansFonts(*args, **kwargs)
in theUnicodeFonts
class. That way, the fallback is a sans-serif font similar to the main font.
It seems like it would be fairly easy to allow users to set the fallback to one of the built-in fonts (cm, dejavuserif, dejavusans, stix, stixsans). It would be nice to also allow custom fallbacks (but then we might need to have a fallback for the fallback in case the custom choice lacks a needed character). In my example, you might want to set the main font in Open Sans, but the fallback to Noto Sans (a very similar Google font with more characters).
There are many high-quality free (and not free) fonts that would benefit from a fallback that's not computer modern. This feature would therefore increase the number of usable custom fontsets.
Implementation questions
I'd be happy to try implementing this myself, but I'm a new contributor, and I'm sure I'd mess some things up. Here are a few questions that come to mind:
- Is this feature worth implementing?
- It would probably require a change to the rc parameters. Is there a policy in place for doing so?
- Like I mentioned above, allowing users to choose from one of the built-in fonts would be pretty straightforward. Is it worth also allowing custom fallbacks?