Skip to content

Navigation Menu

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

Appearance settings

Rasterize dvi files without dvipng. #30039

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
Loading
from

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented May 11, 2025

This patch drops the reliance on dvipng to rasterize dvi files prior to inclusion by agg, instead performing the rasterization ourselves (as a consequence, the rasterization output also becomes dependent of the freetype version used). Note that this approach will be needed anyways to support xetex and luatex, as dvipng doesn't support dvi files generated by these engines.

Baseline images change slightly, for the better or the worse. The top-left blue cross text in test_rotation.py ("Myrt0") seems to be better top-aligned against the blue line (the old version overshot a bit); the bounding box of the formulas in test_usetex.py seems a bit worse.

Small API point that needs to be discussed: do we want to keep the old dvipng-based codepath? (likely, at least temporarily) If so, what kind of switch do we want to expose to the end-user? I would suggest already looking forward to the future support for xetex/luatex which would likely be implemented using rcParams["text.latex.engine"] = {"latex", "xelatex", "lualatex"} and further add a possible "latex+dvipng" value in there, which would correspond to the old default; "latex" would be the dvipng-less codepath; both "latex" and "latex+dvipng" would behave the same for backends other than agg. (Also note that if we decide later to remove that dvipng codepath, it is easier to deprecate an allowable value from a rcParams entry than to completely deprecate an entry.)

I will either implement the switch or strip out the dvipng code, and write the corresponding docs, depending on the decision above.

PR summary

PR checklist

This patch drops the reliance on dvipng to rasterize dvi files prior to
inclusion by agg, instead performing the rasterization ourselves (as a
consequence, the rasterization output also becomes dependent of the
freetype version used).  Note that this approach will be needed anyways
to support xetex and luatex, as dvipng doesn't support dvi files
generated by these engines.

Baseline images change slightly, for the better or the worse.  The
top-left blue cross text in test_rotation.py ("Myrt0") seems to be
better top-aligned against the blue line (the old version overshot a
bit); the bounding box of the formulas in test_usetex.py seems a bit
worse.
@oscargus
Copy link
Member

do we want to keep the old dvipng-based codepath?

What is the consequence of not doing that? Font output depending on installed FreeType version?

It seems like the bonding boxes are a bit off in the new one? The top part of \frac{1}{2}\pi seems to be rendered outside of the box?

rcParams["text.latex.use_dvipng"]? Which maybe should be True for one release? (But must be set to False to use xelatex etc.)

@oscargus
Copy link
Member

The top part of \frac{1}{2}\pi seems to be rendered outside of the box?

But in most cases, the "new" bounding boxes look "better"!

@anntzer
Copy link
Contributor Author

anntzer commented May 18, 2025

do we want to keep the old dvipng-based codepath?

What is the consequence of not doing that? Font output depending on installed FreeType version?

It would, although I don't think this is really a problem (there's just 3 usetex baseline images which would now need to get the same treatment as all other baseline images with text, so that only very slightly makes things worse in that aspect). The main reason to keep the old path would be for strict backcompat if anyone really cares. Also, there's the somewhat obscure case of #20469, where dvipng was providing extra support for an otherwise unsupported font type, but this was already broken for other output formats anyways, and if/when we merge {xe,lua}tex support, users will be able to use TrueType versions of the concrete math font which will just work everywhere. (Plus, if someone wants to implement pk font support per #20469 (comment), that's still an option.)

It seems like the bonding boxes are a bit off in the new one? The top part of \frac{1}{2}\pi seems to be rendered outside of the box?

I did notice that, probably needs a more careful investigation. But I also suspect this may be related to how exactly we draw the bbox (which itself has nonzero thickness). Even if we arrange for it to have exactly 1-px width, we'd probably want it to be drawn immediately outside the outermost inked pixels, which means that the height/width would likely be 1-px bigger than the text extents, and I don't think we do any of that...

rcParams["text.latex.use_dvipng"]? Which maybe should be True for one release? (But must be set to False to use xelatex etc.)

Deprecating a rcParam is a bit annoying, hence the suggestion to fold into text.latex.engine.

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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.