Skip to content

Let TeX handle multiline strings itself. #22360

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 4 commits into from
Mar 29, 2022
Merged

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Jan 30, 2022

PR Summary

Previously, multiline strings were split at \n and passed one at a time to TeX -- likely, this is a remnant of how multiline strings are handled for the non-TeX case, as Matplotlib also renders one line at a time. This series of commits switches things to instead pass entire multiline strings all at once to TeX, which is useful e.g. if a tex font command must apply to arbitrary strings that may contain newlines. Goes on top of #22359.

1st commit: Switch TeX baseline detection to use a dvi special.

Insert a \special at the end of the TeX output and record the baseline
position there. This should be more robust than trying to guess the
format of the dvi preamble, and more importantly this will also allow
detecting the last baseline of multiline TeX output, which will then
allow letting TeX handle multiline strings itself (while keeping the
correct alignment).

2nd commit: Let TeX handle newlines itself.

Note that it may be worth passing the baselineskip
(Text.get_linespacing()) as argument to texmanager, but that'll wait
for a bigger refactor... for now, let's stick to the old default of
1.25.

test_metrics_cache changes as the cache hit pattern changed for usetex
strings.


Edit: I suspect that the tests are failing on some builds because the tex cache needs to be invalidated (the minver test run is also the only one that clears the cache first). Will do something about that...

3rd commit: Pick TeX cache name based on entire TeX source.

This allows invalidating the cache when the source generation algorithm
changes.

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
Copy link
Contributor Author

anntzer commented Feb 1, 2022

rebased.

@jklymak
Copy link
Member

jklymak commented Mar 28, 2022

Is the failed doc build relevant? Moving to draft, feel free to move back when tests pass...

@jklymak jklymak marked this pull request as draft March 28, 2022 11:33
anntzer added 4 commits March 28, 2022 14:34
Insert a `\special` at the end of the TeX output and record the baseline
position there.  This should be more robust than trying to guess the
format of the dvi preamble, and more importantly this will also allow
detecting the last baseline of *multiline* TeX output, which will then
allow letting TeX handle multiline strings itself (while keeping the
correct alignment).
Note that it may be worth passing the baselineskip
(`Text.get_linespacing()`) as argument to texmanager, but that'll wait
for a bigger refactor... for now, let's stick to the old default of
1.25.

test_metrics_cache changes as the cache hit pattern changed for usetex
strings.
This allows invalidating the cache when the source generation algorithm
changes.
@anntzer
Copy link
Contributor Author

anntzer commented Mar 28, 2022

It seems spurious, but let's try again...
edit: yup, it works.

@anntzer anntzer marked this pull request as ready for review March 28, 2022 13:43
@jklymak jklymak merged commit 2fe38b5 into matplotlib:main Mar 29, 2022
@QuLogic QuLogic added this to the v3.6.0 milestone Mar 29, 2022
@anntzer anntzer deleted the multilinetex branch March 29, 2022 08:08
timhoffm added a commit that referenced this pull request Oct 2, 2022
Revert #22360: Let TeX handle multiline strings itself
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Oct 2, 2022
timhoffm added a commit that referenced this pull request Oct 3, 2022
…047-on-v3.6.x

Backport PR #24047 on branch v3.6.x (Revert #22360: Let TeX handle multiline strings itself)
@ksunden ksunden mentioned this pull request Feb 20, 2023
6 tasks
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.

3 participants