Title: [ENH]: OpenType fonts for mathematical formulas · Issue #31104 · matplotlib/matplotlib · GitHub
Open Graph Title: [ENH]: OpenType fonts for mathematical formulas · Issue #31104 · matplotlib/matplotlib
X Title: [ENH]: OpenType fonts for mathematical formulas · Issue #31104 · matplotlib/matplotlib
Description: Problem When rendering mathematical equations, matplotlib currently only supports a hard-coded number of fonts (configured via mathtext.fontset). While it is possible to configure custom fonts (via mathtext.fontset: custom), this require...
Open Graph Description: Problem When rendering mathematical equations, matplotlib currently only supports a hard-coded number of fonts (configured via mathtext.fontset). While it is possible to configure custom fonts (via...
X Description: Problem When rendering mathematical equations, matplotlib currently only supports a hard-coded number of fonts (configured via mathtext.fontset). While it is possible to configure custom fonts (via...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/31104
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[ENH]: OpenType fonts for mathematical formulas","articleBody":"### Problem\n\nWhen rendering mathematical equations, matplotlib currently only supports a hard-coded number of fonts (configured via `mathtext.fontset`). While it is possible to configure custom fonts (via `mathtext.fontset: custom`), this requires to set separate fonts for upright, italic, fraktur, double-struck, etc. variants -- which is fundamentally incompatible with the way modern OpenType mathematics fonts are designed.\n\nThe current approach has several shortcomings:\n\n * It is not generally possible to use consistent fonts for text and mathematics (except for special cases covered by the hard-coded options). Think of matching the fonts for a textbook (using _STIX Two_,_Minion_, ...) or in a slide show (_Cambria_)\n * The UX of configuring fonts is inconsistent and somewhat counter intuitive.\n * (The mathtext codebase and font selection logic is relatively complex and inaccessible, with all the hardcoded fonts, fixes for their quirks, and fallbacks for missing symbols).\n\nUnicode defines mathematical alphanumeric symbols as unique codepoints (see https://en.wikipedia.org/wiki/Mathematical_Alphanumeric_Symbols), in contrast to different fonts all defining different styles for the same ASCII characters/codepoints.\nMathematical formulas can be rendered with OpenType mathematics fonts such as _STIX Two Math_, _Cambria Math_, or _Latin Modern Math_, etc.. For modern LaTeX (LuaTeX and XeTeX), this is implemented in the [unicode-math](https://ctan.org/pkg/unicode-math) package.\nInstead of using different fonts based on the style to render the same codepoints (as it is currently implemented in matplotlib), this maps alphanumeric characters to different codepoints based on the style, and render them from a single font.\n\n\nSince there is a major overhaul of matplotlib's text rendering currently under way (#30161), I thought now is a good time to bring this up.\n \n\n### Proposed solution\n\nI propose to add support for OpenType mathematics fonts. Basic support is introduced in PR #31064 . The implementation is inspired by the unicode-math package for LaTeX.\n\nThis enables to configure and use arbitrary OpenType mathematics fonts to\n * match text and math fonts with the surrounding document\n * makes the UX more consistent\n \nWhat do you think of this idea in general?\n\nThere are some open design questions:\n * How should the fonts be configured?\n * How to do unit tests? This may require vendoring at least one OpenType mathematics font. Currently, I have added STIX Two Math to the test data.\n \n The next logical steps would be (i) to make use of the font metrics from the MATH tables instead of using default values (ii) support scaled variants of symbols.\n","author":{"url":"https://github.com/llohse","@type":"Person","name":"llohse"},"datePublished":"2026-02-06T08:56:38.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":5},"url":"https://github.com/31104/matplotlib/issues/31104"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:ba4aa581-e458-4e04-1292-4808f6ff5678 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CD46:33CA96:554C27:70E2D6:6A519A96 |
| html-safe-nonce | 1b5622e843a729e8164aab3354580db32458e2ae9b80e15a8342da2b2afffce8 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRDQ2OjMzQ0E5Njo1NTRDMjc6NzBFMkQ2OjZBNTE5QTk2IiwidmlzaXRvcl9pZCI6IjIxMTk4MzY0MDMwMDcyMjgzOCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | cb19030001ff054203e7d5ee6606b79ac855919cd408ce8500a78526c885dad2 |
| hovercard-subject-tag | issue:3905662012 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/matplotlib/matplotlib/31104/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5680f7f1ddf1bfedc6815cf9195e251a174b2549f833de3ae874df52520b9201/matplotlib/matplotlib/issues/31104 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5680f7f1ddf1bfedc6815cf9195e251a174b2549f833de3ae874df52520b9201/matplotlib/matplotlib/issues/31104 |
| og:image:alt | Problem When rendering mathematical equations, matplotlib currently only supports a hard-coded number of fonts (configured via mathtext.fontset). While it is possible to configure custom fonts (via... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | llohse |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| go-import | github.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git |
| octolytics-dimension-user_id | 215947 |
| octolytics-dimension-user_login | matplotlib |
| octolytics-dimension-repository_id | 1385122 |
| octolytics-dimension-repository_nwo | matplotlib/matplotlib |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1385122 |
| octolytics-dimension-repository_network_root_nwo | matplotlib/matplotlib |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7aed05249554b889eb33d002851a973eebcc7e91 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width