Fix nested braces in mathtext \text arguments - #32147
Conversation
|
Thank you for opening your first PR into Matplotlib! If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks. We also ask that you please finish addressing any review comments on this PR and wait for it to be merged (or closed) before opening a new one, as it can be a valuable learning experience to go through the review process. You can also join us on discourse chat 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. |
|
pyparsing has the builtin nested_expr; could that not be used instead of building our own machinery? |
PR summary
Closes #32105.
\textused pyparsing'sQuotedString, which ends at the first}, so that made\text{{example}}failed with a cryptic ParseException.I replaced that with a small brace-balanced token that tracks nesting depth.
Nested unescaped braces are treated as TeX groups (not rendered), matching real LaTeX, so
\text{{example}}renders the same as\text{example}. Literal braces continue to use\{and\}.AI Disclosure
I used Cursor (generative AI) to explore the mathtext parser, draft the regression tests, and help write this PR description (to make sure I am following standards). I reviewed the change, verified the behavior against TeX grouping semantics, and ran a local smoke test covering nested braces, escaped braces, the existing
\texttest string, and malformed input.PR quality check
N/A for example/release notes/docs: this is a bug fix restoring expected LaTeX-like behavior of an existing command.