Support {lua,xe}tex as alternative usetex engine. · matplotlib/matplotlib@044776d · GitHub
Skip to content

Commit 044776d

Browse files
committed
Support {lua,xe}tex as alternative usetex engine.
Currently, this PR is mostly a proof of concept; only the svg backend is supported (under rcParams["svg.fonttype"] = "none", the default). However, there is a companion branch on the mplcairo repository, also named "luadvi", which implements support for all output formats. Example (requiring both this PR, and mplcairo installed from its luadvi branch): ``` import matplotlib as mpl; mpl.use("module://mplcairo.qt") from matplotlib import pyplot as plt plt.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 :-)
1 parent 05b9179 commit 044776d

4 files changed

Lines changed: 38 additions & 14 deletions

File tree

lib/matplotlib/dviread.py

Lines changed: 6 additions & 6 deletions

lib/matplotlib/mpl-data/matplotlibrc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,9 @@
331331
# computer modern sans serif, computer modern typewriter
332332

333333
## The TeX engine/format to use. The following values are supported:
334-
## - "latex": The classic TeX engine (the current default). All backends render
335-
## TeX's output by parsing the DVI output into glyphs and boxes and emitting
336-
## those one by one.
334+
## - "latex", "xelatex", "lualatex": The corresponding TeX engines. All
335+
## backends render TeX's output by parsing the DVI output into glyphs and
336+
## boxes and emitting those one by one.
337337
## - "latex+dvipng": The same as "latex", with the exception that Agg-based
338338
## backends rely on dvipng to rasterize TeX's output. This value was the
339339
## default up to Matplotlib 3.10.

lib/matplotlib/rcsetup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,7 @@ def _convert_validator_spec(key, conv):
11111111
# text props
11121112
"text.color": validate_color,
11131113
"text.usetex": validate_bool,
1114-
"text.latex.engine": ["latex", "latex+dvipng"],
1114+
"text.latex.engine": ["latex", "latex+dvipng", "xelatex", "lualatex"],
11151115
"text.latex.preamble": validate_string,
11161116
"text.hinting": ["default", "no_autohint", "force_autohint",
11171117
"no_hinting", "auto", "native", "either", "none"],

lib/matplotlib/texmanager.py

Lines changed: 28 additions & 4 deletions

0 commit comments

Comments
 (0)