Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Use luatex in --luaonly mode to query kpsewhich. #19558

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 1 commit into from
May 25, 2021

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Feb 22, 2021

luatex --luaonly runs a lua interpreter with relevant tex libraries
available, which avoids the overhead of repeatedly initializing
kpathsea (the old approach, very slow on macos and windows). An
alternative approach would be to use luatex followed by \directlua
calls, but on windows it appears that one needs to use lualatex to get
a working interactive prompt, and just loading the latex format takes
seconds(!).

For the simple following benchmark:

python -c 'from pylab import *; mpl.use("pdf"); rcParams["text.usetex"] = True; plot(); savefig("test.pdf", backend="pdf")'

On a macos machine, this patch brings runtime from ~4.5s to ~2.5s.
On a windows machine, this patch brings runtime from ~6.5s to ~1.7s.

We also need to figure out how to best advertise this (do we emit a
warning suggesting to install luatex on windows and macos if luatex is
not present?).


See also #19531 and #19551 for other approaches; I opened separate PRs to
simplify comparison of the approaches.

PR Summary

PR Checklist

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (run flake8 on changed files to check).
  • New features are documented, with examples if plot related.
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • Conforms to Matplotlib style conventions (install flake8-docstrings and run flake8 --docstring-convention=all).
  • 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).

Copy link
Member

@jkseppan jkseppan left a comment

Choose a reason for hiding this comment

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

This looks like a very clean solution. TeX Live has shipped luatex since at least 2016 and MiKTeX since at least 2017. I think it's possible to install TeX without luatex, so this added dependency should get a mention in the release notes.

@anntzer anntzer force-pushed the texluakpsewhich branch from bf71732 to 9b74f28 Compare May 1, 2021 12:46
@anntzer
Copy link
Contributor Author

anntzer commented May 1, 2021

this added dependency

Right now it's not a new dependency (we just silently fall back to the old slow path if luatex is not present); the question is indeed whether we want to emit a noisier warning or even just fail in that case and make luatex a hard dependency. (I think there's some appeal to keep dependencies minimal?)
Also note that #19531 achieves the same result without adding a dependency on luatex, but doesn't work on Windows due to obscure buffering issues...

@jklymak
Copy link
Member

jklymak commented May 21, 2021

I'll move this to draft until you decide what to do about the dependency...

@jklymak jklymak marked this pull request as draft May 21, 2021 03:41
@anntzer anntzer force-pushed the texluakpsewhich branch from 9b74f28 to fac36da Compare May 21, 2021 12:34
@anntzer
Copy link
Contributor Author

anntzer commented May 21, 2021

I decided to just mention it in the docs and live with it, it's optional anyways.

@anntzer anntzer marked this pull request as ready for review May 21, 2021 12:35
@anntzer anntzer force-pushed the texluakpsewhich branch from fac36da to 5353b1c Compare May 21, 2021 12:37
@jklymak
Copy link
Member

jklymak commented May 21, 2021

WARNING: error while formatting signature for matplotlib.texmanager.TexManager.get_rgba: Handler <function mangle_signature at 0x7fd341a9b200> for event 'autodoc-process-signature' threw an exception (exception: Unknown section Example in the docstring of <function TexManager.get_rgba at 0x7fd33a8397a0> in /home/circleci/project/lib/matplotlib/texmanager.py.)

@jklymak jklymak marked this pull request as draft May 21, 2021 13:40
@anntzer anntzer marked this pull request as ready for review May 21, 2021 13:53
@anntzer anntzer force-pushed the texluakpsewhich branch from 5353b1c to b8cf12e Compare May 21, 2021 13:53
@anntzer
Copy link
Contributor Author

anntzer commented May 21, 2021

thanks, hopefully fixed now

@jklymak jklymak marked this pull request as draft May 22, 2021 15:46
@jklymak jklymak added the status: needs clarification Issues that need more information to resolve. label May 22, 2021
`luatex --luaonly` runs a *lua* interpreter with relevant tex libraries
available, which avoids the overhead of repeatedly initializing
kpathsea (the old approach, very slow on macos and windows).  An
alternative approach would be to use `luatex` followed by `\directlua`
calls, but on windows it appears that one needs to use `lualatex` to get
a working interactive prompt, and just loading the latex format takes
seconds(!).

For the simple following benchmark:
```sh
python -c 'from pylab import *; mpl.use("pdf"); rcParams["text.usetex"] = True; plot(); savefig("test.pdf", backend="pdf")'
```
On a macos machine, this patch brings runtime from ~4.5s to ~2.5s.
On a windows machine, this patch brings runtime from ~6.5s to ~1.7s.

We also need to figure out how to best advertise this (do we emit a
warning suggesting to install luatex on windows and macos if luatex is
not present?).
@anntzer anntzer removed the status: needs clarification Issues that need more information to resolve. label May 22, 2021
@anntzer anntzer force-pushed the texluakpsewhich branch from b8cf12e to 20009ae Compare May 22, 2021 22:00
@anntzer anntzer marked this pull request as ready for review May 22, 2021 23:04
@QuLogic QuLogic merged commit 6f9652b into matplotlib:master May 25, 2021
@QuLogic QuLogic added this to the v3.5.0 milestone May 25, 2021
@anntzer anntzer deleted the texluakpsewhich branch May 26, 2021 04:53
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.

4 participants