Skip to content

Remove need to detect math mode in pgf strings #23442

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

Merged
merged 3 commits into from
Jan 27, 2023

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Jul 18, 2022

See #23381 (comment) for motivation. Supersedes #23381. @painch Can you check whether this works for you?

Directly support ^% in pgf.

Support for ^ is inspired from the support for _ as implemented
in underscore.sty, but much simpler because 1) we don't care about
hyphenation, 2) we don't care about substituting a real underscore by
a rule box when the current font lacks an underscore (there's no real
way out if the font has no caret, anyways), and 3) we don't care about
the active character ending up in tex \commands because the character
is only made active in the context of matplotlib-provided strings, not
globally.

Also handle \displaystyle and \mathdefault at the TeX level.

Note that tex_escape is still being tested by
test_minus_signs_with_tex, which explicitly checks support for unicode
minus.


Edit: A test fails on the Ubuntu 18.04 texlive (and I can repro this locally) with pdflatex only because the strings get shifted a tiny bit. I'm actually a bit at loss as to why this shift occurs, and especially only with pdflatex on an older texlive. (In particular, I have separately checked the reported text metrics, which did not change; more debugging indicates that it's the \everymath{\displaystyle} which seems to very slightly shift the non-math text.) I would be tempted to just skip this test on the old Ubuntu 18.04 texlive (considering that it's just a slight image shift, and that the test still passes on the more recent Ubuntu image...
Edit^2: Looks like I can just get away with bumping the test tolerance by 1-per-thousand on old ghostscripts...

PR Summary

PR Checklist

Tests and Styling

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all).

Documentation

  • New features are documented, with examples if plot related.
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).

@anntzer anntzer force-pushed the pgfescape branch 2 times, most recently from 4e18ee1 to f6c48cd Compare July 18, 2022 17:21
Support for `^` is inspired from the support for `_` as implemented
in underscore.sty, but much simpler because 1) we don't care about
hyphenation, 2) we don't care about substituting a real underscore by
a rule box when the current font lacks an underscore (there's no real
way out if the font has no caret, anyways), and 3) we don't care about
the active character ending up in tex `\commands` because the character
is only made active in the context of matplotlib-provided strings, not
globally.
anntzer added 2 commits July 19, 2022 22:23
Note that tex_escape is still being tested by
test_minus_signs_with_tex, which explicitly checks support for unicode
minus.
Copy link
Member

@jklymak jklymak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I certainly do not understand all the latex involved. Be good to find someone else who does to take a quick look.

@ksunden ksunden added this to the v3.7.0 milestone Jan 27, 2023
@ksunden ksunden merged commit 2329fd4 into matplotlib:main Jan 27, 2023
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Jan 27, 2023
@anntzer anntzer deleted the pgfescape branch January 27, 2023 19:31
ksunden added a commit to ksunden/matplotlib that referenced this pull request Jan 27, 2023
anntzer added a commit that referenced this pull request Jan 27, 2023
Remove unused import of re introduced in #23442
@QuLogic QuLogic modified the milestones: v3.7.0, v3.8.0 Feb 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants