Title: [Bug]: Unkown symbol in $..$ when text.usetex: False · Issue #22537 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: Unkown symbol in $..$ when text.usetex: False · Issue #22537 · matplotlib/matplotlib
X Title: [Bug]: Unkown symbol in $..$ when text.usetex: False · Issue #22537 · matplotlib/matplotlib
Description: Bug summary Placing non-standard tex commands like \unit{mm} from siunitx package on $...$ when used for labels (and probably other text elements) does not work when tex rendering by matplotlib is disabled. Does it still check stuff in $...
Open Graph Description: Bug summary Placing non-standard tex commands like \unit{mm} from siunitx package on $...$ when used for labels (and probably other text elements) does not work when tex rendering by matplotlib is ...
X Description: Bug summary Placing non-standard tex commands like \unit{mm} from siunitx package on $...$ when used for labels (and probably other text elements) does not work when tex rendering by matplotlib is ...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/22537
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: Unkown symbol in $..$ when text.usetex: False ","articleBody":"### Bug summary\n\nPlacing non-standard tex commands like \\unit{mm} from siunitx package on $...$ when used for labels (and probably other text elements) does not work when tex rendering by matplotlib is **disabled**.\r\nDoes it still check stuff in $ signs for valid commands? \r\n\r\n\n\n### Code for reproduction\n\n```python\nimport locale\r\nimport matplotlib\r\nimport matplotlib.pyplot as plt\r\n\r\nmatplotlib.use('TkAgg')\r\nplt.style.use('matplotlib_style.mplstyle') \r\n# text.usetex: False \r\n# text.latex.preamble: r'\\usepackage{amsmath}\\usepackage{siunitx}'\r\nlocale.setlocale(locale.LC_ALL, '')\r\n\r\nfig, ax = plt.subplots()\r\nax.plot([0], [0], 'x')\r\n\r\nax.set_xlabel(r'$\\Delta x$ \\unit{mm}') # \u003c- does work\r\nax.set_xlabel(r'$\\Delta x \\unit{mm}$') # \u003c- does not work \r\nplt.savefig('fig.svg') # plt.show() does not work either\n```\n\n\n### Actual outcome\n\nTraceback (most recent call last):\r\n File \"/venv/lib/python3.10/site-packages/matplotlib/_mathtext.py\", line 2237, in parse\r\n result = self._expression.parseString(s)\r\n File \"/venv/lib/python3.10/site-packages/pyparsing/core.py\", line 1134, in parse_string\r\n raise exc.with_traceback(None)\r\npyparsing.exceptions.ParseFatalException: Unknown symbol: \\unit, found '\\' (at char 0), (line:1, col:1)\r\n\r\n...\r\n\r\nValueError: \r\n\\unit{mm}\r\n^\r\nUnknown symbol: \\unit, found '\\' (at char 0), (line:1, col:1)\r\n\n\n### Expected outcome\n\nLabel with plain text (not Tex rendered yet) text in .svg file \r\n(rendering those later with latex svg package)\n\n### Additional information\n\nSeems to happen when non standard commands are used in math mode (like $\\unit{mm}$)\r\nBoth $\\unit{mm}$ and \\unit{mm} work with siunitx package and xetex\n\n### Operating system\n\nPopOS 21.10\n\n### Matplotlib Version\n\n3.5.1\n\n### Matplotlib Backend\n\nTkAgg\n\n### Python version\n\n3.10.0 | Make \"In console: python --version or python3 --version\" in bug report form\n\n### Jupyter version\n\n_No response_\n\n### Installation\n\npip","author":{"url":"https://github.com/Nikongen","@type":"Person","name":"Nikongen"},"datePublished":"2022-02-22T23:17:01.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":6},"url":"https://github.com/22537/matplotlib/issues/22537"}
| 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:e182a139-70cd-78a8-ebf8-6d590aa2a757 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 95EE:C563C:1CADC1:26A0A5:6A51332A |
| html-safe-nonce | 39c58eb4c1fcfaed4c1370ff8649c497b5aee2fa5994aa7762d37e0db5d1ca73 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NUVFOkM1NjNDOjFDQURDMToyNkEwQTU6NkE1MTMzMkEiLCJ2aXNpdG9yX2lkIjoiMzY4MTgzMjg4NDg5MTYyODMzMSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 4c1ec866f7440ca1e5eeb746407d1c2ec7bb7b08e7debef3319929f17e7375d1 |
| hovercard-subject-tag | issue:1147463605 |
| 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/22537/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5d3136daf3349b4daa3fc1d25c622ea63a53b7a6fd7ce6b81a5d568f0c310ed4/matplotlib/matplotlib/issues/22537 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5d3136daf3349b4daa3fc1d25c622ea63a53b7a6fd7ce6b81a5d568f0c310ed4/matplotlib/matplotlib/issues/22537 |
| og:image:alt | Bug summary Placing non-standard tex commands like \unit{mm} from siunitx package on $...$ when used for labels (and probably other text elements) does not work when tex rendering by matplotlib is ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Nikongen |
| hostname | github.com |
| expected-hostname | github.com |
| None | e840f405b2718e8f2d55aafa9ff27dbce17e29d0c253011d05ea0fea3c78baff |
| 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 | 4ae6027e8ba70c79dc08249bb6cdc1a09d788496 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width