Skip to content

mathtext support for \phantom, \llap, \rlap for faking text metrics.#30908

Merged
QuLogic merged 1 commit intomatplotlib:text-overhaulfrom
anntzer:texphantoms
Mar 11, 2026
Merged

mathtext support for \phantom, \llap, \rlap for faking text metrics.#30908
QuLogic merged 1 commit intomatplotlib:text-overhaulfrom
anntzer:texphantoms

Conversation

@anntzer
Copy link
Copy Markdown
Contributor

@anntzer anntzer commented Dec 29, 2025

Closes #28211 (although it doesn't implement \smash, which isn't really necessary). Goes on top of #30059 (some details of mathtext raster rendering are different prior to #30059 and I don't think it's really worth figuring out how to exactly write the code compatible with the old version).

The example in the given issue is supported via

from pylab import *
fig = figure(layout="constrained")
sfs = fig.subfigures(2)
ax0 = sfs[0].add_subplot()
ax0.plot([1, 2], label=r"$\rlap{\text{foo}}\phantom{\text{a longer label}}$")
sfs[0].legend(loc="outside right upper")
ax1 = sfs[1].add_subplot()
ax1.plot([1, 2], label="foo")
ax1.plot([2, 1], label="a longer label")
sfs[1].legend(loc="outside right upper")
show()
image

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mathtext gained support for the TeX macros ``\phantom``, ``\llap``, and
``\rlap``. ``\phantom`` allows to occupy some space on the canvas as if some
text was being rendered, without actually render that text, whereas ``\llap``
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
text was being rendered, without actually render that text, whereas ``\llap``
text was being rendered, without actually rendering that text, whereas ``\llap``

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

thanks, edited.

@QuLogic
Copy link
Copy Markdown
Member

QuLogic commented Feb 11, 2026

But still has conflicts...

@anntzer
Copy link
Copy Markdown
Contributor Author

anntzer commented Feb 11, 2026

rebased.

@QuLogic QuLogic added this to the v3.11.0 milestone Mar 2, 2026
@QuLogic QuLogic merged commit 88de239 into matplotlib:text-overhaul Mar 11, 2026
36 checks passed
@anntzer anntzer deleted the texphantoms branch March 11, 2026 19:12
wavebyrd pushed a commit to wavebyrd/matplotlib that referenced this pull request Mar 13, 2026
mathtext support for \phantom, \llap, \rlap for faking text metrics.
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