GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — mathtext: add support for unicode mathematics fonts by llohse · Pull Request #31064 · matplotlib/matplotlib Conversation
|
|
I opened a new PR, because this one is based on the text-overhaul branch and I messed up rebasing the old one. @QuLogic: Would you kindly take a look at this? Is this something you would consider for merging? For further discussion in case you don't reject this feature alltogether: How should the math font be configured? This also depends a bit on how prominent it should be visible. I could not think of a good way without introducing a new parameter in rcparams. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| 0x22d3: 0x22d2, | ||
| } | ||
|
|
||
| unicode_math_lut: dict[str, dict[CharacterCodeType, CharacterCodeType]] = { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Most of these are 1-to-1 mappings of a block; I wonder if there is a more compact representation that could be used? Something like:
# (start, end, new_start)
# up digits
(0x30, 0x39, 0x30),
...
# bf latin lower case
(0x61, 0x7a, 0x1d41a),
maybe plus a small dictionary with some of the exceptions, depending on how they fit into the blocks.
The lookup table could be generated from those if necessary.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This is exactly the way I generated the lookup table, offline:
At some point I did consider writing special mapping functions but I figured that a lookup table might be preferable for performance.
Do you prefer to generate the lookup table (for example on module load) instead of hardcoding the entire table?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| } | ||
|
|
||
|
|
||
| class UnicodeMathFonts(TruetypeFonts): |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
IIUC, math fonts should have tables with various layout metrics. We currently have those hard-coded in the various FontsConstantsBase subclasses, and they are likely incorrect for an arbitrary math font.
So this will likely need to parse this data out of the font and implement at least get_axis_height that was added in #31046, get_xheight maybe using #31050, and get_quad from #31110. But it is likely that you will want to refactor some of those remaining uses of the constants so that they fetch the information from the fonts as well.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I fully agree. Doing this may involve some refactoring though, because the FontsConstantsBase subclass could not be determined purely from fontname but would be dynamically populated based on the loaded OpenType font.
That said, I made some experiments locally. Unfortunately, Freetype does not parse the MATH table. We could use fonttools, which is a hard dependency anyway.
There are several open questions how to map the OpenType layout metrics to the legacy TeX-inspired variables used in mathtext. Does it make sense to postpone that to a separate PR and focus on the basics here?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
While I would like it to happen, I'm not sure this will be ready for 3.11. So if we're aiming for 3.12, I think it's okay to spend some time getting everything worked out in separate PRs.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
a8083e3 to
5988fac
Compare
5988fac to
2a66d49
Compare
There was an error while loading. Please reload this page.
|
I have just rebased the branch, split the baseline images into a separate commit, and added logic to handle mathnormal from #31121 in the new From my perspective, it is ready for another review. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
|
||
| def __init__(self, default_font_prop: FontProperties, load_glyph_flags: LoadFlags): | ||
| TruetypeFonts.__init__(self, default_font_prop, load_glyph_flags) | ||
| prop = mpl.rcParams['mathtext.mathfont'] # type: ignore[index] |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I think this will break the caching for MathTextParser._parse_cached, but I see it already doesn't really handle any of the other mathtext.* rcParams, so I guess that's something to work out at some point.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| 'tt': 'tt', | ||
| 'sf': 'sfup', | ||
| 'bf': 'bfup', | ||
| 'bfit': 'bfup', |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Typo or no such possibility? Probably could use a comment for the latter.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Bold italic digits are not defined in the Unicode standard. Actually, neither are regular italic digits (which I need to fix in the code).
In unicode-math, both are mapped to their upright variants.
This is related to a bigger open question. unicode-math maps \mathit (and \mathbf, \mathrm, \mathsf and \mathtt) to the corresponding non-mathematics fonts, which support all alphanumeric symbols and apply normal text kerning rules (and ligatures).
I have not defined such a mechanism here to keep it simple. Mapping mathrm is trivial. In principle one could load italic and bold versions with their corresponding options, too. Sans serif and typewriter would be a bigger stretch. I am not sure it is worth it, though.
Note that this only matters because we now have proper italic support in the other font classes.
I see two options:
I would prefer option 1 and leave option 2 as a project for the future.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
2a66d49 to
9455799
Compare
|
Please rebase on, and re-target to, |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Adds basic support for generic unicode OpenType mathematics fonts such as STIX Two Math or Cambria Math to be used within the mathtext engine.
9455799 to
7e2dd3e
Compare
|
Rebased to main. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@QuLogic @anntzer @timhoffm I would like to follow up on this PR. Would you still be interested in merging basic OpenType math-font support along the lines implemented here? I would be happy to rebase it and address further comments. Before proceeding, though, I would appreciate your guidance on whether this approach is acceptable in principle and what would still be needed for a merge. In particular, could support for OpenType MATH-table metrics be addressed in a subsequent PR, or would you consider it a prerequisite for merging this one? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
At least 1 approving review is required to merge this pull request.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.