GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Rasterize dvi files without dvipng. by anntzer · Pull Request #30039 · matplotlib/matplotlib

Conversation

@anntzer

@anntzer anntzer commented May 11, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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.

Edit: This closes #28766.

PR summary

PR checklist

  • "closes #0000" is in the body of the PR description to link the related issue
  • new and changed code is tested
  • Plotting related features are demonstrated in an example
  • New Features and API Changes are noted with a directive and release note
  • Documentation complies with general and docstring guidelines

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@anntzer anntzer added backend: agg topic: text/usetex status: needs comment/discussion needs consensus on next step labels May 11, 2025
@github-actions github-actions Bot added the topic: text/fonts label May 11, 2025
@anntzer
anntzer force-pushed the dvirender branch from b241ca4 to 9067209 Compare May 11, 2025 21:08
@anntzer anntzer mentioned this pull request May 12, 2025
Improve usetex and pgf troubleshooting docs. #30040
Merged
5 tasks
@oscargus

oscargus commented May 18, 2025

Copy link
Copy Markdown
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.)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@oscargus

oscargus commented May 18, 2025

Copy link
Copy Markdown
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"!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@anntzer

anntzer commented May 18, 2025

Copy link
Copy Markdown
Contributor Author

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added the status: needs rebase label May 24, 2025
@anntzer
anntzer force-pushed the dvirender branch from 9067209 to e545bb2 Compare May 24, 2025 09:40
@github-actions github-actions Bot removed the status: needs rebase label May 24, 2025
@QuLogic QuLogic added this to Font and text overhaul Jun 5, 2025
@anntzer anntzer mentioned this pull request Aug 14, 2025
[ENH]: Support parallel plotting #30420
Closed
@anntzer
anntzer force-pushed the dvirender branch from e545bb2 to 89343dc Compare September 4, 2025 07:18
@QuLogic

QuLogic commented Sep 4, 2025

Copy link
Copy Markdown
Member

Baseline images change slightly, for the better or the worse.

Shall we target the text-overhaul branch then? Likely wouldn't need the old dvipng code if it lands at the same time.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@anntzer
anntzer force-pushed the dvirender branch from 89343dc to f2b8e0e Compare September 4, 2025 08:53
@github-actions github-actions Bot added topic: mpl_toolkit topic: rcparams topic: path handling backend: ps backend: pdf topic: text/mathtext topic: styles CI: Run cibuildwheel Run wheel building tests on a PR labels Sep 4, 2025
@anntzer

anntzer commented Sep 4, 2025

Copy link
Copy Markdown
Contributor Author

Sure, that works too.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@anntzer
anntzer changed the base branch from main to text-overhaul September 4, 2025 08:54
@anntzer
anntzer force-pushed the dvirender branch from f2b8e0e to a0f6560 Compare September 4, 2025 08:55
@github-actions github-actions Bot removed topic: mpl_toolkit topic: rcparams labels Sep 4, 2025
@QuLogic QuLogic removed the status: waiting for other PR label Jan 31, 2026
@QuLogic

QuLogic commented Jan 31, 2026

Copy link
Copy Markdown
Member

Some bits of glyph positioning seem a bit off:

import matplotlib.pyplot as plt

plt.rcParams['mathtext.fontset'] = 'cm'

texts = [
    (0.8, r'$\frac{\$100.00}{xy}$'),
    (0.5, r'$\frac{X}{\frac{X}{Y}}$'),
    (0.3, r'$\overline{\omega}^x \frac{1}{2}_0^x$'),
]

fig = plt.figure(figsize=(3, 3))

for y, t in texts:
    fig.text(0.2, y, t, verticalalignment='center', fontsize=24)
    fig.text(0.5, y, t, verticalalignment='center', usetex=True, fontsize=24)

plt.show()
Figure_1
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

QuLogic
QuLogic reviewed Jan 31, 2026
View reviewed changes
Comment thread lib/matplotlib/backends/backend_agg.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread lib/matplotlib/backends/backend_agg.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@anntzer
anntzer force-pushed the dvirender branch from 7916e76 to c7e37ae Compare January 31, 2026 15:59
@anntzer

anntzer commented Jan 31, 2026

Copy link
Copy Markdown
Contributor Author

The issue occurred because text.index calls get_font() (to resolve glyph indices), which would undo the call to FT_Set_Transform... fixed, and added a comment, but I guess this suggests either get_font() shouldn't reset the transform, or text.index should switch from being a property to being a real method call (e.g. resolve_index()), to make the side-effect clearer. However that doesn't need to happen in this PR.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@QuLogic

QuLogic commented Jan 31, 2026

Copy link
Copy Markdown
Member

Also need to update the rcParams type stubs.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@anntzer
anntzer force-pushed the dvirender branch from c7e37ae to c86109e Compare January 31, 2026 22:26
@anntzer

anntzer commented Jan 31, 2026

Copy link
Copy Markdown
Contributor Author

done

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

QuLogic
QuLogic approved these changes Feb 3, 2026
View reviewed changes

@QuLogic QuLogic left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

LGTM, but we should do the usual dance of dropping the image updates before merging.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@anntzer

anntzer commented Feb 3, 2026

Copy link
Copy Markdown
Contributor Author

I should just drop the second commit?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

QuLogic
QuLogic reviewed Feb 5, 2026
View reviewed changes
Comment thread lib/matplotlib/rcsetup.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread lib/matplotlib/rcsetup.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread lib/matplotlib/mpl-data/matplotlibrc Resolved

Uh oh!

There was an error while loading. Please reload this page.

@QuLogic QuLogic mentioned this pull request Feb 5, 2026
Refactor RendererAgg.draw_{mathtext,text,tex} to use same base algorithm #31085
Merged
1 task done
@anntzer
anntzer force-pushed the dvirender branch from c86109e to a1831b6 Compare February 5, 2026 10:54
@anntzer

anntzer commented Feb 5, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, copy-edited. (Side question for @timhoffm: What's the policy for multiline rcParams descriptions in rcsetup.py? e.g. here for text.latex.engine I would like to be able to do a bullet list.)
@QuLogic Should I drop the second commit (baselines update) or should I let you do it?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@QuLogic

QuLogic commented Feb 5, 2026

Copy link
Copy Markdown
Member

I can take care of dropping the commit.

anntzer reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

tacaswell
tacaswell approved these changes Feb 5, 2026
View reviewed changes
ksunden
ksunden approved these changes Feb 5, 2026
View reviewed changes

@ksunden ksunden left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I leave to @QuLogic to merge because it's going into the text-overhaul branch

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@anntzer @QuLogic
Rasterize dvi files without dvipng
7627118
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.
@QuLogic
QuLogic force-pushed the dvirender branch from a1831b6 to 7627118 Compare February 5, 2026 19:40
@QuLogic QuLogic removed the status: needs comment/discussion needs consensus on next step label Feb 5, 2026
@QuLogic
QuLogic merged commit 695e9a1 into matplotlib:text-overhaul Feb 5, 2026
34 of 38 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@github-project-automation github-project-automation Bot moved this from Ready for Review to Done in Font and text overhaul Feb 5, 2026
@anntzer
anntzer deleted the dvirender branch February 5, 2026 21:24
@QuLogic QuLogic linked an issue Feb 6, 2026 that may be closed by this pull request
[Bug]: Alignment of minus sign when using LaTeX #28766
Closed
This was referenced Mar 4, 2026
Support colorization of text via TeX directives #31234
Draft
[Bug]: Alignment of minus sign when using LaTeX #28766
Closed
wavebyrd pushed a commit to wavebyrd/matplotlib that referenced this pull request Mar 13, 2026
@QuLogic
Merge pull request matplotlib#30039 from anntzer/dvirender
f50b739
Rasterize dvi files without dvipng.
QuLogic added a commit to QuLogic/matplotlib that referenced this pull request Apr 10, 2026
@QuLogic
Update test images for font/text overhaul
12d2a4d
This includes images changes for the following pull requests / commits:

* [Fix center of rotation with
  rotation_mode='anchor'](matplotlib#29199)
  (c44db77)
* [Remove ttconv backwards-compatibility
  code](matplotlib#30145)
  (8caff88)
* [Remove kerning_factor from
  tests](matplotlib#29816)
  (7b4d725)
* [Set text hinting to
  defaults](matplotlib#29816)
  (8255ae2)
* [Update FreeType to
  2.13.3](matplotlib#29816)
  (89c054d)
* [Implement text shaping with
  libraqm](matplotlib#30000)
  (b0ded3a,
  9813523)
* [Add language parameter to Text
  objects](matplotlib#29794)
  (7ce8eae)
* [Fix auto-sized glyphs with BaKoMa
  fonts](matplotlib#29936)
  (3ba2c13)
* [pdf: Improve text with characters outside embedded font
  limits](matplotlib#30512)
  (b70fb88,
  6cedcf7)
* [Prepare `CharacterTracker` for advanced font
  features](matplotlib#30608)
  (8274e17,
  70dc388,
  df670cf,
  ed5e074)
* [Add font feature API to
  Text](matplotlib#29695)
  (972a688)
* [Fix spacing in r"$\max
  f$"](matplotlib#30715)
  (4a99a83)
* [Implement libraqm for vector
  outputs](matplotlib#30607)
  (bd17cd4)
* [Drop the FT2Font intermediate
  buffer](matplotlib#30059)
  (9d7d7b4)
* [Rasterize dvi files without
  dvipng](matplotlib#30039)
  (7627118)
* [Update bundled FreeType and HarfBuzz
  libraries](matplotlib#30938)
  (a161658,
  9619bcc)
* [Fix positioning of wide mathtext
  accents](matplotlib#31069)
  (c2fa7ba)
* [Refactor RendererAgg.draw_{mathtext,text,tex} to use same base
  algorithm](matplotlib#31085)
  (931bcf3)
* [Implement TeX's fraction and script
  alignment](matplotlib#31046)
  (94ff452,
  4bfa0f9,
  1cd8510)
* [Fix confusion between text height and ascent in metrics
  calculations](matplotlib#31107)
  (60f2310)
* [mathtext: Fetch quad width & axis height from font
  metrics](matplotlib#31110)
  (692df3f,
  383028b)
* [mathtext: add mathnormal and distinguish between normal and italic
  family](matplotlib#31121)
  (a6913f3)
* [ENH: Ignore empty text for
  tightbbox](matplotlib#31285)
  (d772043)
* [Drop axis_artist tickdir image compat, due to text-overhaul
  merge](matplotlib#31281)
  (2057583)
* [text: Use font metrics to determine line
  heights](matplotlib#31291)
  (3ab6a27,
  d961462,
  97f4943)
* [ps/pdf: Override font height metrics to support AFM
  files](matplotlib#31371)
  (e0913d4)
* [TST: Cleanup back-compat code in tests touched by text
  overhaul](matplotlib#31295)
  (7c33379)
* [TST: Set tests touched by text overhaul to mpl20
  style](matplotlib#31300)
  (41c4d8d)
@QuLogic QuLogic mentioned this pull request Apr 10, 2026
Font and text overhaul #30161
Merged
4 tasks done
@Wrzlprmft Wrzlprmft mentioned this pull request Jun 19, 2026
[Bug]: minus signs not rendered in PDF export with TeX #31925
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@QuLogic QuLogic QuLogic approved these changes
@tacaswell tacaswell tacaswell approved these changes
@ksunden ksunden ksunden approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

backend: agg topic: rcparams topic: text/fonts topic: text/usetex

Projects

Font and text overhaul
Status: Done

Milestone

v3.11.0

Development

Successfully merging this pull request may close these issues.

[Bug]: Alignment of minus sign when using LaTeX

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@anntzer @oscargus @QuLogic @tacaswell @ksunden
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.