Skip to content

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Sep 4, 2025

TeX MetaFont (.mf) fonts (e.g., from \usepackage{concmath}) need to be converted to raster (.pk) fonts before usage. In dvipng or pdftex this is done by invoking mktexpk via kpsewhich.

This patch ensures that our calls to kpsewhich likewise also generate and finds the raster files (in Matplotlib's own temporary cache) when needed. The resolution (600dpi) is the documented default (see e.g. the -D option in man kpsewhich). Note that this is only a preliminary step towards full MF/PK font support, which would also require parsing the PK file (which I have implemented elsewhere) and embedding the glyphs into our final output (for which I have a preliminary version in mplcairo).

Work towards fixing #20469.

PR summary

PR checklist

@anntzer anntzer force-pushed the dvipkparse branch 3 times, most recently from 3fee17f to 76d704f Compare September 4, 2025 14:26
TeX MetaFont (.mf) fonts (e.g., from `\usepackage{concmath}`) need to be
converted to raster (.pk) fonts before usage.  In dvipng or pdftex this
is done by invoking mktexpk via kpsewhich.

This patch ensures that our calls to kpsewhich likewise also generate
and finds the raster files (in Matplotlib's own temporary cache) when
needed.  The resolution (600dpi) is the documented default (see e.g. the
-D option in `man kpsewhich`).  Note that this is only a preliminary
step towards full MF/PK font support, which would also require parsing
the PK file and embedding the glyphs into our final output.
Comment on lines +794 to +795
return ({} if self.resolve_path().match("*.600pk") else
PsfontsMap(find_tex_file("pdftex.map"))[self.texname].effects)
Copy link
Member

Choose a reason for hiding this comment

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

Very optional: I would not use a ternary operator here because that makes it harder to read. It's rather a return-early situation.

Suggested change
return ({} if self.resolve_path().match("*.600pk") else
PsfontsMap(find_tex_file("pdftex.map"))[self.texname].effects)
if self.resolve_path().match("*.600pk"):
return {}
return PsfontsMap(find_tex_file("pdftex.map"))[self.texname].effects

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