Repository navigation
[Bug]: Font lookup when rendering math text #32164
Description
Activity
Hi! I'd like to work on this issue. Could you please assign it to me?
- linked a pull request that will close this issueAdd font family to mismatched font weight warning #32104
on Aug 3, 2026 There is already an existing PR for this issue.
So the handling of
mathtext.defaultis a bit strange; I can confirm that it does do what it says, but I can't figure out that path to it, since the rcParam is read in very few places. For now, I'll unlink the PR to keep this open, and will continue investigating later.- removed a link to a pull requestAdd font family to mismatched font weight warning #32104
on Sep 4, 2026 OK, now that we have the font family in the warning, it's a bit clearer where this is coming from. The changed font doesn't really matter; it's just the
font.weight: 300that does it:findfont: Failed to find font weight 300 for DejaVu Sans, now using 400. findfont: Failed to find font weight 300 for DejaVu Sans, now using 400. findfont: Failed to find font weight 300 for STIXGeneral, now using 400. findfont: Failed to find font weight 300 for STIXGeneral, now using 400. findfont: Failed to find font weight 300 for STIXNonUnicode, now using 400. findfont: Failed to find font weight 300 for STIXNonUnicode, now using 400. findfont: Failed to find font weight 300 for STIXSizeOneSym, now using 400. findfont: Failed to find font weight 300 for STIXSizeTwoSym, now using 400. findfont: Failed to find font weight 300 for STIXSizeThreeSym, now using 400. findfont: Failed to find font weight 300 for STIXSizeFourSym, now using 400. findfont: Failed to find font weight 300 for STIXSizeFiveSym, now using 400. findfont: Failed to find font weight 300 for cmmi10, now using 400. findfont: Failed to find font weight 300 for cmsy10, now using 400. findfont: Failed to find font weight 300 for cmr10, now using 400. findfont: Failed to find font weight 300 for cmtt10, now using 400. findfont: Failed to find font weight 300 for cmti10, now using 400. findfont: Failed to find font weight 300 for cmb10, now using 400. findfont: Failed to find font weight 300 for cmss10, now using 400. findfont: Failed to find font weight 300 for cmex10, now using 400. findfont: Failed to find font weight 300 for DejaVu Sans, now using 400. findfont: Failed to find font weight 300 for DejaVu Sans, now using 400. findfont: Failed to find font weight 300 for DejaVu Sans Mono, now using 400. findfont: Failed to find font weight 300 for DejaVu Sans Display, now using 400.This comes from the initialization of
DejaVuFonts:
matplotlib/lib/matplotlib/_mathtext.py
Lines 705 to 724 in a7db543
def __init__(self, default_font_prop: FontProperties, load_glyph_flags: LoadFlags): # This must come first so the backend's owner is set correctly if isinstance(self, DejaVuSerifFonts): self._fallback_font = StixFonts(default_font_prop, load_glyph_flags) else: self._fallback_font = StixSansFonts(default_font_prop, load_glyph_flags) self.bakoma = BakomaFonts(default_font_prop, load_glyph_flags) TruetypeFonts.__init__(self, default_font_prop, load_glyph_flags) # Include Stix sized alternatives for glyphs self._fontmap.update({ '1': 'STIXSizeOneSym', '2': 'STIXSizeTwoSym', '3': 'STIXSizeThreeSym', '4': 'STIXSizeFourSym', '5': 'STIXSizeFiveSym', }) for key, name in self._fontmap.items(): fullpath = findfont(name) self.fontmap[key] = fullpath self.fontmap[name] = fullpath
which is created because of the defaultmathtext.fontset. This could be set to some other fontset, but cannot really be set to a custom font (despite thecustomoption) without #31064.The problem in all those cases is that we request our bundled fonts by family name only. This allows the defaults from rcParams to slip through and then the lookup searches for it in 300 weight, which doesn't exist. The easiest fix should be to force the font weight, at least until the full Unicode math font support is added.
- linked a pull request that will close this issueUse more specific patterns for bundled mathtext fonts #32302
on Sep 5, 2026
Bug summary
With this in
matplotlibrc:I expect all text (math and regular) to be rendered with the "Ubuntu" font at a size of 10.0 and a weight of 300. This is what happens. However, when I use math text, I get this warning multiple times:
It seems that the math text rendering machinery looks up the glyphs for the math text in a different font before looking them up in the desired font.
It would be great if the warning could specify which font is being looked up.
Code for reproduction
Actual outcome
Expected outcome
No warnings.
Additional information
No response
Operating system
Windows 11
Matplotlib Version
3.11.0
Matplotlib Backend
qtagg
Python version
3.14.6
Jupyter version
No response
Installation
pixi