mathtext: Use DejaVu display symbols when available #5612
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
With the new DejaVu font default many of the symbols (most notably the integral, product, and summation symbol) are very small, as they are designed for inline math. The DejaVu fonts include display-sized variants for some of the math symbols outside of the unicode range. According to @mdboom, it is currently non-trivial to access these variants in a consistent manner from matplotlib, so here I did a bit of hack so we can always access them:
.display
and move them to the unicode index corresponding to the regular glyph. I created two ttf files with this:DejaVuSansDisplay.ttf
andDejaVuSerifDisplay.ttf
. The family names have an additionalDisplay
at the end to differentiate them from the regular fonts. These are pretty small, as they only have a dozen characters.subset.py
with the fonts inlib/matplotlib/mpl-data/fonts/ttf
. I think it's good to keep it so this modification can be done in the future if we update the version of DejaVu fonts, but I am not sure this is the right place. A better location might betools
. Ideas? It has an Apache license, so AFAICT it's ok to distribute it.mathtext.py
will now look first for a glyph in the display version of the fonts (I have added them as fontnameex
, following thecmex
example), and if not found will use the regular version.The baseline images definitely look better, specially the ones that include fractions and integrals.