-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Let pgf backend use bracket delimiters for detecting math mode. #23381
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for opening your first PR into Matplotlib!
If you have not heard from us in a while, please feel free to ping @matplotlib/developers
or anyone who has commented on the PR. Most of our reviewers are volunteers and sometimes things fall through the cracks.
You can also join us on gitter for real-time discussion.
For details on testing, writing docs, and our review process, please see the developer guide
We strive to be a welcoming and open project. Please follow our Code of Conduct.
I think that this probably makes sense, but please include a test for it. I think something like this could be used as a template: matplotlib/lib/matplotlib/tests/test_backend_pgf.py Lines 326 to 334 in cd9d371
Use $ for the reference and the new delimiters for the test.
For me, this still works correctly in the non-TeX backends with |
I'm hesitant with this inclusion. As far as I understand LaTeX:
|
That is a good point -- I've now made a change to reflect that.
At least in their TeX Live implementations, lualatex, pdflatex and xelatex don't allow nested
That is a very reasonable alternative if this doesn't work out. |
Do the they allow |
They don't |
I've had a go writing tests (see the last commit to this branch), I've tried them out locally, though I'm unfamiliar with pytest so they might need some checking. |
It would seem like a more robust(?) solution may be to just completely get rid of _tex_escape and instead configure tex to support |
Hi @painch - let us know if you need any guidance on moving this forward. Thanks! |
I think this is superseded by #23442. |
PR Summary
LaTeX (and lualatex/xelatex) allows math mode to be delimited by '\(', '\)', '\[' and '\]'. This PR changes the pgf backend to detect this, so that e.g. '_' and '^' are not inadvertently escaped in math-mode labels etc.
The current behaviour leads to errors when certain label names are used. For example I've put a minimum working example script$x^2$ correctly, whereas using just plain $x2$ . This PR fixes this issue.
mwe.py
and a tex filemwe.tex
below. Runningmwe.py show
allows the use of non-pgf backends (Qt5Agg in my case), and displays\(x^2\)
asmwe.py
thenlualatex mwe.tex
shows it asmwe.py:
mwe.tex: