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
# PK fonts have no encoding information; report glyphs as ASCII but
# with a "?" to indicate that this is just a guess.
return (f"{chr(self.glyph)}?" if chr(self.glyph).isprintable() else
"??")
Copy link
Member

@QuLogic QuLogic Sep 6, 2025

Choose a reason for hiding this comment

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

Should we fall back to something like f'pk{self.glyph:x}' so that they are all unique? (the pk prefix is something like the uni prefix on Unicode-encoded glyphs)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, went for a variant.

Comment on lines 768 to 771
try:
psfont = PsfontsMap(find_tex_file("pdftex.map"))[self.texname]
except LookupError as exc:
Copy link
Member

Choose a reason for hiding this comment

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

I assume it would never had generated a LookupError anyway, but the PsfontsMap constructor seems like a lot to put in this try.

Copy link
Contributor Author

@anntzer anntzer Sep 7, 2025

Choose a reason for hiding this comment

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

Sure, took it out. (Also removed an unrelated and now unused PsfontsMap call.)

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.
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.

2 participants