Skip to content

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/matplotlib/backends/backend_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -991,11 +991,11 @@ def _embedTeXFont(self, fontinfo):

# Widths
widthsObject = self.reserveObject('font widths')
tfm = fontinfo.dvifont._tfm
font_metrics = fontinfo.dvifont._metrics
# convert from TeX's 12.20 representation to 1/1000 text space units.
widths = [(1000 * metrics.tex_width) >> 20
if (metrics := tfm.get_metrics(char)) else 0
for char in range(max(tfm._glyph_metrics, default=-1) + 1)]
widths = [(1000 * glyph_metrics.tex_width) >> 20
if (glyph_metrics := font_metrics.get_metrics(char)) else 0
for char in range(max(font_metrics._glyph_metrics, default=-1) + 1)]
self.writeObject(widthsObject, widths)

# Font dictionary
Expand Down
324 changes: 242 additions & 82 deletions lib/matplotlib/dviread.py

Large diffs are not rendered by default.

23 changes: 21 additions & 2 deletions lib/matplotlib/dviread.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class Text(NamedTuple):
@property
def font_effects(self) -> dict[str, float]: ...
@property
def index(self) -> int: ... # type: ignore[override]
@property
def glyph_name_or_index(self) -> int | str: ...

class Dvi:
Expand All @@ -56,14 +58,27 @@ class Dvi:

class DviFont:
texname: bytes
size: float
def __init__(
self, scale: float, tfm: Tfm, texname: bytes, vf: Vf | None
self, scale: float, metrics: Tfm | TtfMetrics, texname: bytes, vf: Vf | None
) -> None: ...
@classmethod
def from_luatex(cls, scale: float, texname: bytes): ...
@classmethod
def from_xetex(
cls, scale: float, texname: bytes, subfont: int, effects: dict[str, float]
): ...
def __eq__(self, other: object) -> bool: ...
def __ne__(self, other: object) -> bool: ...
@property
def size(self) -> float: ...
@property
def widths(self) -> list[int]: ...
@property
def path(self) -> Path: ...
@property
def subfont(self) -> int: ...
@property
def effects(self) -> dict[str, float]: ...

class Vf(Dvi):
def __init__(self, filename: str | os.PathLike) -> None: ...
Expand All @@ -89,6 +104,10 @@ class Tfm:
@property
def depth(self) -> dict[int, int]: ...

class TtfMetrics:
def __init__(self, filename: str | os.PathLike) -> None: ...
def get_metrics(self, idx: int) -> TexMetrics: ...

class PsFont(NamedTuple):
texname: bytes
psname: bytes
Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/mpl-data/matplotlibrc
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@
# zapf chancery, charter, serif, sans-serif, helvetica,
# avant garde, courier, monospace, computer modern roman,
# computer modern sans serif, computer modern typewriter
#text.latex.engine: latex
#text.latex.preamble: # IMPROPER USE OF THIS FEATURE WILL LEAD TO LATEX FAILURES
# AND IS THEREFORE UNSUPPORTED. PLEASE DO NOT ASK FOR HELP
# IF THIS FEATURE DOES NOT DO WHAT YOU EXPECT IT TO.
Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,7 @@ def _convert_validator_spec(key, conv):
# text props
"text.color": validate_color,
"text.usetex": validate_bool,
"text.latex.engine": ["latex", "xelatex", "lualatex"],
"text.latex.preamble": validate_string,
"text.hinting": ["default", "no_autohint", "force_autohint",
"no_hinting", "auto", "native", "either", "none"],
Expand Down
Loading
Loading