-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[Bug]: Unkown symbol in $..$ when text.usetex: False #22537
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
matplotlib's own tex parser cannot support every tex package in existence and I think we should draw a fairly strict line to keep things manageable (e.g., not going beyond standard latex commands + amsmath). Certainly siunitx seems out of scope (even though it is a package I like very much). |
As I said I don’t want it to parse the tex commands. It’s supposed to handle the text in the label as plain/raw text. What I wanted to point out is that it seems to parse/check the text when $ signs appear, although the rcParams disable tex parsing Edit: accidentally clicked the wrong button 🤦🏽♂️ |
Ah, for that you can use https://matplotlib.org/stable/api/text_api.html#matplotlib.text.Text.set_parse_math. |
Thanks for that #:+1: |
It is currently not possible, but you can, which you may have realized, pass I guess it can be possible to add it to the rc-file though. |
I created a PR to support |
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 $ signs for valid commands?
Code for reproduction
Actual outcome
Traceback (most recent call last):
File "/venv/lib/python3.10/site-packages/matplotlib/_mathtext.py", line 2237, in parse
result = self._expression.parseString(s)
File "/venv/lib/python3.10/site-packages/pyparsing/core.py", line 1134, in parse_string
raise exc.with_traceback(None)
pyparsing.exceptions.ParseFatalException: Unknown symbol: \unit, found '' (at char 0), (line:1, col:1)
...
ValueError:
\unit{mm}
^
Unknown symbol: \unit, found '' (at char 0), (line:1, col:1)
Expected outcome
Label with plain text (not Tex rendered yet) text in .svg file
(rendering those later with latex svg package)
Additional information
Seems to happen when non standard commands are used in math mode (like$\unit{mm}$ )$\unit{mm}$ and \unit{mm} work with siunitx package and xetex
Both
Operating system
PopOS 21.10
Matplotlib Version
3.5.1
Matplotlib Backend
TkAgg
Python version
3.10.0 | Make "In console: python --version or python3 --version" in bug report form
Jupyter version
No response
Installation
pip
The text was updated successfully, but these errors were encountered: