GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — mathtext: add mathnormal and distinguish between normal and italic family by llohse · Pull Request #31121 · matplotlib/matplotlib

Conversation

@llohse

@llohse llohse commented Feb 9, 2026 •
edited by QuLogic
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

PR summary

This adds \mathnormal to the mathtext parser and handles mathit and mathnormal/default differently, to replicate the behaviour of LaTeX. In particular, it produces italic digits, whereas normal produces upright digits.

closes #29253

This is implemented as follows:
For cm, add the cmti (Computer Modern Text Italic) and use it for it. Use cmmi for normal, but map digits to cmr (same as in LaTeX). Technically, LaTeX further distinguishes between normal and the default, where the default uses roman digits and normal uses the digits from cmmi, which are slightly offset.

For stix and dejavu, the font for digits is mapped to either upright or italic for normal and it, respesctively.

To facilitate these features, I have moved the _get_font_constants functionality into the respective font classes instead of a global lookup table. This gets rid of the non-local access to the private _get_fonts from the lookup table. Moreover, this change prepares for reading the constants dynamically, as is necessary with generic OpenType math fonts.
If this change is controversial, I could try to work around it.

@QuLogic I have filed the PR against the text-overhaul branch because of the massive changes therein with respect to main.

Examples

cm stix

PR checklist

  • "closes #0000" is in the body of the PR description to link the related issue
  • new and changed code is tested
  • Plotting related features are demonstrated in an example
  • New Features and API Changes are noted with a directive and release note
  • Documentation complies with general and docstring guidelines

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@github-actions github-actions Bot added the topic: text/mathtext label Feb 9, 2026
@llohse llohse mentioned this pull request Feb 10, 2026
[Bug]: Numbers in words not italic #29253
Closed
QuLogic
QuLogic reviewed Feb 14, 2026
View reviewed changes

@QuLogic QuLogic left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

We would need a test here, and I think a What's new note for the new math normal option would be good as well.

Can you link to where you obtained the font files? They do not match what I have in my TexLive installation, but there may be some version mismatch.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/matplotlib/_mathtext.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@llohse
llohse force-pushed the feat-mathnormal branch from 95d012c to c3a69c6 Compare February 14, 2026 12:36
@llohse

llohse commented Feb 14, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for your comments.

We would need a test here, and I think a What's new note for the new math normal option would be good as well.

Will do. I did not add tests yet, because a lot of tests where failing with the text-overaul branch at the time.

Can you link to where you obtained the font files? They do not match what I have in my TexLive installation, but there may be some version mismatch.

I got them from https://ctan.org/tex-archive/fonts/cm/ps-type1/bakoma.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@llohse

llohse commented Feb 14, 2026

Copy link
Copy Markdown
Contributor Author

@QuLogic it looks like the tests are still failing with the text-overhaul branch here. Do you know a workaround? It is a bit difficult to pinpoint the tests that I need to update, when everything fails.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@llohse
llohse force-pushed the feat-mathnormal branch from 3b4303a to cd3eb9a Compare February 14, 2026 13:17
@QuLogic

QuLogic commented Feb 14, 2026

Copy link
Copy Markdown
Member

It's a bit complicated; you would have to fetch from the text-overhaul-figures branch, then test against those, and commit only the new ones, if any. Of course, if you're only adding a new test, then that is simpler as you can just add it here directly. However, at the moment, that branch is a bit out of sync with text-overhaul as I'm preparing to merge #31107.

If you do update the test images yourself, please keep it as a separate commit so that it can be stripped before merging.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@llohse

llohse commented Feb 15, 2026

Copy link
Copy Markdown
Contributor Author

Thanks a lot.
I do expect some existing tests to fail, because the behaviour of \mathit has changed (and even uses an entirely different font for computer modern). Those baseline images would have to be updated in any case. I'll look into that, once you get your branch in sync again. In addition, I would add a small test case for \mathnormal.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@QuLogic

QuLogic commented Feb 18, 2026

Copy link
Copy Markdown
Member

The branches should be in sync again.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@QuLogic QuLogic mentioned this pull request Feb 18, 2026
mathtext: Fetch quad width & axis height from font metrics #31110
Merged
1 task done
@QuLogic QuLogic added this to Font and text overhaul Feb 18, 2026
@QuLogic QuLogic moved this to Ready for Review in Font and text overhaul Feb 18, 2026
@QuLogic QuLogic added this to the v3.11.0 milestone Feb 18, 2026
QuLogic
QuLogic reviewed Feb 18, 2026
View reviewed changes
Comment thread doc/release/next_whats_new/mathnormal.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread doc/release/next_whats_new/mathnormal.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread doc/release/next_whats_new/mathnormal.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@QuLogic

QuLogic commented Feb 18, 2026

Copy link
Copy Markdown
Member

Taking a quick look at the results, I see in mathfont_cm_10, the mathbf does now look bolder, and in mathfont_cm_20, the mathtt is now fixed-width. Additionally, items like \mathbb are now upright by default; I would have to check if that matches LaTeX though.

There does seem to be something wrong with \mathit though, as in mathfont_cm_{15,16,17} it appears that DejaVu Sans is being used instead of an italic Computer Modern.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@llohse

llohse commented Feb 18, 2026

Copy link
Copy Markdown
Contributor Author

Taking a quick look at the results, I see in mathfont_cm_10, the mathbf does now look bolder, and in mathfont_cm_20, the mathtt is now fixed-width. Additionally, items like \mathbb are now upright by default; I would have to check if that matches LaTeX though.

There does seem to be something wrong with \mathit though, as in mathfont_cm_{15,16,17} it appears that DejaVu Sans is being used instead of an italic Computer Modern.

Thanks for testing. Previously, the BakomaFonts class would force all digits (no matter what font was selected) to rm (cmr10) via the latex_to_bakoma lookup table. This would only happen for cm and was not consistent with the other font classes and with LaTeX (https://www.overleaf.com/learn/latex/Mathematical_fonts#Other_mathematical_fonts), although I am not entirely sure if this replicates some ancient version of LaTeX.

mathfont_cm_{15,16,17} looks correct on my end. It looks like cmti to me, as it should.

That said, some other tests still fail here, like mathtext_cm_00. The letters are displayed upright instead of italic in mathnormal mode. There seems to be a logic bug in the other classes. I'll do some debugging.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@llohse

llohse commented Feb 18, 2026

Copy link
Copy Markdown
Contributor Author

There does seem to be something wrong with \mathit though, as in mathfont_cm_{15,16,17} it appears that DejaVu Sans is being used instead of an italic Computer Modern.

This is likely due to an outdated local font cache, which does not include cmti10. rm ~/.cache/matplotlib/fontlist* prior to running the tests fixed this for me.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@llohse
llohse force-pushed the feat-mathnormal branch from 82f1cc6 to 16fe453 Compare February 18, 2026 14:04
@llohse

llohse commented Feb 18, 2026

Copy link
Copy Markdown
Contributor Author

I fixed all of the regressions that I could find. There are still a large number of the computer modern tests failing, which I cannot quite put my finger on.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@QuLogic

QuLogic commented Feb 18, 2026

Copy link
Copy Markdown
Member

There does seem to be something wrong with \mathit though, as in mathfont_cm_{15,16,17} it appears that DejaVu Sans is being used instead of an italic Computer Modern.

This is likely due to an outdated local font cache, which does not include cmti10. rm ~/.cache/matplotlib/fontlist* prior to running the tests fixed this for me.

Ah right, I forgot it doesn't update for the internal fonts. You can bump the __version__ in FontManager to force an update.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@llohse

llohse commented Feb 18, 2026

Copy link
Copy Markdown
Contributor Author

Some of the remaining test failures with Computer Modern seem to come from metrics being measured on cmti instead of cmmi. One example is _make_space, which measures the width of the 'm' glyph from the 'it' family (which has changed). There are more subtle places, though.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

anntzer
anntzer reviewed Feb 20, 2026
View reviewed changes
Comment thread lib/matplotlib/_mathtext_data.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

anntzer
anntzer reviewed Feb 20, 2026
View reviewed changes
Comment thread lib/matplotlib/_mathtext.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added topic: rcparams topic: styles labels Feb 21, 2026
@llohse

llohse commented Feb 21, 2026

Copy link
Copy Markdown
Contributor Author

The tests succeed now against the baseline images from QuLogic's branch, except for those few cases that are expected to fail due to the changed behaviour.

The previous failures were caused by the slanted attribute not being set correctly for fontname = normal font in the BakomaFonts class, causing the kerning do be slightly off.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@llohse
llohse force-pushed the feat-mathnormal branch from 78d80c0 to 2016c6e Compare February 26, 2026 08:56
@llohse

llohse commented Feb 26, 2026

Copy link
Copy Markdown
Contributor Author

I have updated the announcement to be more vocal about the changed behaviour of mathtext.default: it.
To my understanding, all the review comments are addressed. I would appreciate another review.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

anntzer
anntzer reviewed Feb 26, 2026
View reviewed changes
Comment thread lib/matplotlib/_mathtext.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

anntzer
anntzer reviewed Feb 26, 2026
View reviewed changes
Comment thread lib/matplotlib/_mathtext.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

anntzer
anntzer reviewed Feb 26, 2026
View reviewed changes
Comment thread lib/matplotlib/_mathtext.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@anntzer

anntzer commented Feb 26, 2026

Copy link
Copy Markdown
Contributor

Some tests would be nice (you can maybe use check_figures_equal to compare a mathnormal string and the corresponding mixture of mathrm & mathit, not so much to save a few baseline images but more importantly because that would actually test the semantics of mathnormal).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@llohse

llohse commented Feb 26, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

Some tests would be nice (you can maybe use check_figures_equal to compare a mathnormal string and the corresponding mixture of mathrm & mathit, not so much to save a few baseline images but more importantly because that would actually test the semantics of mathnormal).

Both 'normal' (via default math) and 'it' are already covered by the existing tests. A test for explicit \mathnormal is still missing. I'll try to add a test the way you propose.

Note that we cannot compare mathnormal with mathit even for letters, because they can be different fonts/alphabets (for example in the case of computer modern).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

anntzer
anntzer reviewed Feb 26, 2026
View reviewed changes
Comment thread lib/matplotlib/tests/test_mathtext.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added the status: needs rebase label Mar 1, 2026
@llohse
mathtext refactoring: replace FontConstants lookup
8137091
Replace lookup table for font constants based on the family name
by methods in their respective classes.

Removes non-local call of private _get_font method in
_get_font_constant_set.

This simplifies implementing dynamically loaded font constants.
@llohse
llohse force-pushed the feat-mathnormal branch from 29ef1bc to 80a4031 Compare March 2, 2026 08:45
@github-actions github-actions Bot removed the status: needs rebase label Mar 2, 2026
@llohse

llohse commented Mar 2, 2026

Copy link
Copy Markdown
Contributor Author

I have just rebased the branch against text-overhaul and resolved the merge conflicts due to #31110 being merged. Is there anything else that needs doing?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@QuLogic

QuLogic commented Mar 2, 2026

Copy link
Copy Markdown
Member

You can bump the __version__ in FontManager to force an update.

You need to do this when adding new internal fonts.

After clearing the cache, I see 14 test changes. For Computer Modern, we get mathit working as well as mathbf, mathtt and mathsf. But I see that mathbf+mathsf (test 57) doesn't get bold; is there a way to fix that one? For DejaVu Sans/Serif and STIX, these are tests 15&18 where mathit is now really italic. However, it seems that STIX Sans doesn't also get fixed?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@llohse

llohse commented Mar 2, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

Thanks for your feedback!

You can bump the __version__ in FontManager to force an update.

You need to do this when adding new internal fonts.

Done.

After clearing the cache, I see 14 test changes. For Computer Modern, we get mathit working as well as mathbf, mathtt and mathsf. But I see that mathbf+mathsf (test 57) doesn't get bold; is there a way to fix that one? For DejaVu Sans/Serif and STIX, these are tests 15&18 where mathit is now really italic. However, it seems that STIX Sans doesn't also get fixed?

I expect these 14.
Test 57: It now correctly renders sans-serif digits. Previously, numbers were hardcoded to it everywhere. Combining two environments was not implemented for cm (see below).

stixsans: Unfortunately, sans-serif italic digits are not defined as unicode symbols (see https://en.wikipedia.org/wiki/Mathematical_Alphanumeric_Symbols#Digits) nor in Stix 1. So we have to fall back to sans-serif upright here.

A general remark: Combining two environments such as mathbf + mathsf is unique to the hard-coded Stix implementation and is realized via font_class. Neither classic LaTeX nor lualatex (with or without unicode-math) support this -- they simply use the innermost environment. The modern way in lualatex with unicode-math would be a \mathsfbf environment, but that is something for a future PR.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

QuLogic
QuLogic approved these changes Mar 2, 2026
View reviewed changes

@QuLogic QuLogic left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Preferably, you could squash the FontManager bump into the commit that adds the new fonts as well.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

llohse reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
llohse added 2 commits March 2, 2026 14:24
@llohse
mathtext: implement \mathnormal and distinguish between normal and it
a6913f3
To replicate LaTeX behaviour, distinguish between "italic" and "normal"
math. In particular, digits should be set italic in the \mathit env.

For `cm`, use cmti font for "it"
For general UnicodeFont (stix, DejaVu, ...), maps digits to roman or
italic alphabet, depending on "normal" or "it" environment.
@llohse
Add test case for mathnormal
77d4e52
Ensure that \mathnormal is parsed and sets digits upright.
@llohse
llohse force-pushed the feat-mathnormal branch from a255f4a to 77d4e52 Compare March 2, 2026 13:24
@llohse
llohse requested a review from tacaswell March 2, 2026 16:07
@QuLogic QuLogic linked an issue Mar 2, 2026 that may be closed by this pull request
[Bug]: Numbers in words not italic #29253
Closed
ksunden
ksunden approved these changes Mar 6, 2026
View reviewed changes
@QuLogic
QuLogic merged commit 3539117 into matplotlib:text-overhaul Mar 6, 2026
19 of 36 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@github-project-automation github-project-automation Bot moved this from Ready for Review to Done in Font and text overhaul Mar 6, 2026
@llohse llohse mentioned this pull request Mar 10, 2026
mathtext: add support for unicode mathematics fonts #31064
Open
5 tasks
wavebyrd pushed a commit to wavebyrd/matplotlib that referenced this pull request Mar 13, 2026
@QuLogic
Merge pull request matplotlib#31121 from llohse/feat-mathnormal
8c03084
mathtext: add mathnormal and distinguish between normal and italic family
QuLogic added a commit to QuLogic/matplotlib that referenced this pull request Apr 10, 2026
@QuLogic
Update test images for font/text overhaul
12d2a4d
This includes images changes for the following pull requests / commits:

* [Fix center of rotation with
  rotation_mode='anchor'](matplotlib#29199)
  (c44db77)
* [Remove ttconv backwards-compatibility
  code](matplotlib#30145)
  (8caff88)
* [Remove kerning_factor from
  tests](matplotlib#29816)
  (7b4d725)
* [Set text hinting to
  defaults](matplotlib#29816)
  (8255ae2)
* [Update FreeType to
  2.13.3](matplotlib#29816)
  (89c054d)
* [Implement text shaping with
  libraqm](matplotlib#30000)
  (b0ded3a,
  9813523)
* [Add language parameter to Text
  objects](matplotlib#29794)
  (7ce8eae)
* [Fix auto-sized glyphs with BaKoMa
  fonts](matplotlib#29936)
  (3ba2c13)
* [pdf: Improve text with characters outside embedded font
  limits](matplotlib#30512)
  (b70fb88,
  6cedcf7)
* [Prepare `CharacterTracker` for advanced font
  features](matplotlib#30608)
  (8274e17,
  70dc388,
  df670cf,
  ed5e074)
* [Add font feature API to
  Text](matplotlib#29695)
  (972a688)
* [Fix spacing in r"$\max
  f$"](matplotlib#30715)
  (4a99a83)
* [Implement libraqm for vector
  outputs](matplotlib#30607)
  (bd17cd4)
* [Drop the FT2Font intermediate
  buffer](matplotlib#30059)
  (9d7d7b4)
* [Rasterize dvi files without
  dvipng](matplotlib#30039)
  (7627118)
* [Update bundled FreeType and HarfBuzz
  libraries](matplotlib#30938)
  (a161658,
  9619bcc)
* [Fix positioning of wide mathtext
  accents](matplotlib#31069)
  (c2fa7ba)
* [Refactor RendererAgg.draw_{mathtext,text,tex} to use same base
  algorithm](matplotlib#31085)
  (931bcf3)
* [Implement TeX's fraction and script
  alignment](matplotlib#31046)
  (94ff452,
  4bfa0f9,
  1cd8510)
* [Fix confusion between text height and ascent in metrics
  calculations](matplotlib#31107)
  (60f2310)
* [mathtext: Fetch quad width & axis height from font
  metrics](matplotlib#31110)
  (692df3f,
  383028b)
* [mathtext: add mathnormal and distinguish between normal and italic
  family](matplotlib#31121)
  (a6913f3)
* [ENH: Ignore empty text for
  tightbbox](matplotlib#31285)
  (d772043)
* [Drop axis_artist tickdir image compat, due to text-overhaul
  merge](matplotlib#31281)
  (2057583)
* [text: Use font metrics to determine line
  heights](matplotlib#31291)
  (3ab6a27,
  d961462,
  97f4943)
* [ps/pdf: Override font height metrics to support AFM
  files](matplotlib#31371)
  (e0913d4)
* [TST: Cleanup back-compat code in tests touched by text
  overhaul](matplotlib#31295)
  (7c33379)
* [TST: Set tests touched by text overhaul to mpl20
  style](matplotlib#31300)
  (41c4d8d)
@QuLogic QuLogic mentioned this pull request Apr 10, 2026
Font and text overhaul #30161
Merged
4 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@anntzer anntzer anntzer left review comments
@QuLogic QuLogic QuLogic approved these changes
@ksunden ksunden ksunden approved these changes
@tacaswell tacaswell Awaiting requested review from tacaswell

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

topic: rcparams topic: styles topic: text/mathtext

Projects

Font and text overhaul
Status: Done

Milestone

v3.11.0

Development

Successfully merging this pull request may close these issues.

[Bug]: Numbers in words not italic

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@llohse @QuLogic @anntzer @tacaswell @ksunden
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.