mathtext: add mathnormal and distinguish between normal and italic family#31121
mathtext: add mathnormal and distinguish between normal and italic family#31121QuLogic merged 3 commits intomatplotlib:text-overhaulfrom
Conversation
QuLogic
left a comment
There was a problem hiding this comment.
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.
95d012c to
c3a69c6
Compare
|
Thanks for your comments.
Will do. I did not add tests yet, because a lot of tests where failing with the text-overaul branch at the time.
I got them from https://ctan.org/tex-archive/fonts/cm/ps-type1/bakoma. |
|
@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. |
3b4303a to
cd3eb9a
Compare
|
It's a bit complicated; you would have to fetch from the If you do update the test images yourself, please keep it as a separate commit so that it can be stripped before merging. |
|
Thanks a lot. |
|
The branches should be in sync again. |
|
Taking a quick look at the results, I see in There does seem to be something wrong with |
Thanks for testing. Previously, the BakomaFonts class would force all digits (no matter what font was selected) to
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. |
This is likely due to an outdated local font cache, which does not include cmti10. |
82f1cc6 to
16fe453
Compare
|
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. |
Ah right, I forgot it doesn't update for the internal fonts. You can bump the |
|
Some of the remaining test failures with Computer Modern seem to come from metrics being measured on cmti instead of cmmi. One example is |
|
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 |
78d80c0 to
2016c6e
Compare
|
I have updated the announcement to be more vocal about the changed behaviour of |
|
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 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). |
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.
|
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? |
You need to do this when adding new internal fonts. After clearing the cache, I see 14 test changes. For Computer Modern, we get |
|
Thanks for your feedback!
Done.
I expect these 14. 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 |
QuLogic
left a comment
There was a problem hiding this comment.
Preferably, you could squash the FontManager bump into the commit that adds the new fonts as well.
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.
Ensure that \mathnormal is parsed and sets digits upright.
PR summary
This adds
\mathnormalto the mathtext parser and handlesmathitandmathnormal/default differently, to replicate the behaviour of LaTeX. In particular,itproduces italic digits, whereasnormalproduces upright digits.closes #29253
This is implemented as follows:
For
cm, add thecmti(Computer Modern Text Italic) and use it forit. Usecmmifornormal, but map digits tocmr(same as in LaTeX). Technically, LaTeX further distinguishes betweennormaland the default, where the default uses roman digits andnormaluses the digits from cmmi, which are slightly offset.For
stixanddejavu, 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
PR checklist