Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Support {lua,xe}tex as alternative usetex engine.#29807

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
anntzer wants to merge1 commit intomatplotlib:main
base:main
Choose a base branch
Loading
fromanntzer:luadvi

Conversation

@anntzer
Copy link
Contributor

@anntzeranntzer commentedMar 25, 2025
edited
Loading

Currently, this PR is mostly a proof of concept; it only implements the
dvi generation and parsing parts, but does not implement rendering in
any of the builtin backends, except svg (under rcParams["svg.fonttype"]
= "none", the default). However, there is a companion branch on the
mplcairo repository, also named "luadvi", which implements support.

Example (requiring both this PR, and mplcairo installed from its luadvi
branch; or try saving to svg with the builtin svg backend):

importmatplotlibasmpl;mpl.use("module://mplcairo.qt")frommatplotlibimportpyplotaspltplt.rcParams["text.latex.engine"]="lualatex"# or "xelatex"plt.rcParams["text.latex.preamble"]= (# {lua,xe}tex can use any font installed on the system, spec'd using its# "normal" name.  Try e.g. DejaVu Sans instead.r"\usepackage{fontspec}\setmainfont{TeX Gyre Pagella}")plt.figtext(.5,.5,r"\textrm{gff\textwon}",usetex=True)plt.show()

TODO:

  • Fix many likely remaining bugs.
  • Rework font selection in texmanager, which is currently very ad-hoc
    due to the limited number of fonts supported by latex.
  • Implement rendering support in the (other) builtin backends. In
    particular, the Agg (and, if we care, cairo) backend will require
    significant reworking because dvipng, currently used to rasterize dvi
    to png, doesn't support luatex-generated dvi; instead we will need to
    proceed as with the other backends, reading the glyphs one at a time
    from the dvi file and rasterizing them one at a time to the output
    buffer. Working on the other backends is not very high on my priority
    list (as I already have mplcairo as playground...) so it would be nice
    if others showed some interest for it :-)

See#20262,#22715,#28131.

PR summary

PR checklist

@anntzeranntzer changed the titleSupport luatex as alternative usetex engine.Support {lua,xe}tex as alternative usetex engine.Mar 26, 2025
@anntzeranntzerforce-pushed theluadvi branch 2 times, most recently from4d488f4 to697d106CompareMarch 26, 2025 23:42
@anntzeranntzerforce-pushed theluadvi branch 3 times, most recently fromff9ecdd to4f93376CompareMarch 27, 2025 22:39
@anntzeranntzerforce-pushed theluadvi branch 2 times, most recently from85a73b8 tof1b16f2CompareMarch 28, 2025 10:48
@anntzeranntzerforce-pushed theluadvi branch 2 times, most recently fromc134a34 toccf927cCompareMarch 30, 2025 13:49
@QuLogicQuLogic moved this toWaiting for other PR inFont and text overhaulJun 5, 2025
@anntzeranntzerforce-pushed theluadvi branch 2 times, most recently from521c6f8 tocc4a8a3CompareSeptember 3, 2025 10:58
Currently, this PR is mostly a proof of concept; only the svg backendis supported (under rcParams["svg.fonttype"] = "none", the default).However, there is a companion branch on the mplcairo repository, alsonamed "luadvi", which implements support for all output formats.Example (requiring both this PR, and mplcairo installed from its luadvibranch):```import matplotlib as mpl; mpl.use("module://mplcairo.qt")from matplotlib import pyplot as pltplt.rcParams["text.latex.engine"] = "lualatex"  # or "xelatex"plt.rcParams["text.latex.preamble"] = (    # {lua,xe}tex can use any font installed on the system, spec'd using its    # "normal" name.  Try e.g. DejaVu Sans instead.    r"\usepackage{fontspec}\setmainfont{TeX Gyre Pagella}")plt.figtext(.5, .5, r"\textrm{gff\textwon}", usetex=True)plt.show()```Font effects are supported by mplcairo, e.g.`\fontspec{DejaVu Sans}[FakeSlant=0.2] abc`.TODO:- Fix many likely remaining bugs.- Rework font selection in texmanager, which is currently very ad-hoc  due to the limited number of fonts supported by latex.- Implement rendering support in the (other) builtin backends.  In  particular, the Agg (and, if we care, cairo) backend will require  significant reworking because dvipng, currently used to rasterize dvi  to png, doesn't support luatex-generated dvi; instead we will need to  proceed as with the other backends, reading the glyphs one at a time  from the dvi file and rasterizing them one at a time to the output  buffer.  Working on the other backends is not very high on my priority  list (as I already have mplcairo as playground...) so it would be nice  if others showed some interest for it :-)
r"\ifpdftex",
r"\usepackage[utf8]{inputenc}",
r"\DeclareUnicodeCharacter{2212}{\ensuremath{-}}",
font_preamble,
Copy link
Member

Choose a reason for hiding this comment

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

Moving this would be a behaviour change, wouldn't it? I don't recall whichusepackage wins though. Also, do we not want to allow a preamble for other engines?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I don't think moving the font preamble after inputenc & DeclareUnicodeCharacter would really make a difference for latex, and there's no behaviour change for xe/lualatex as these weren't supported before.

However, it is correct that there's a bit of behavior design that needs to be decided here, which is what is the default font for xe/lualatex? Right now the behavior for latex is: pick one of the few supported fonts (PSNFSS) that more or less matches the rcParams settings,defaulting to computer modern serif (as the default rcParam, DejaVu Sans, is not supported). Note that the Text object's FontProperties is not used (except for the fontsize).

For xel/lualatex, right now this PR does the same thing, and we could very well just document "setrcParams["text.latex.preamble"] = r"\usepackage{fontspec}\setmainfont{...}" to pick whatever font with xe/lualatex". Alternatively, a perhaps better option would be to actually use the Text object's FontProperties (which would need to be threaded down to TexManager, but that seems likely doable) and draw text using the standardly configured font (similarly torcParams["pgf.rcfonts"] = True for the pgf backend). In that case, usetex with xe/lualatex wouldnot use computer modern, unless the Text's FontProperties say so.

My preference would definitely be for the latter case (just use whatever fonts are configured using the normal mechanism), but I deferred this discussion (and implementation) until the preliminary parts of the work (dvi parsing) got in. Thoughts?

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@QuLogicQuLogicQuLogic left review comments

At least 1 approving review is required to merge this pull request.

Assignees

No one assigned

Projects

Status: Waiting for other PR

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@anntzer@QuLogic

[8]ページ先頭

©2009-2025 Movatter.jp