Open
Description
Bug summary
When placing some multiline text where one line includes math mode text and the other does not, then the lines aren't perfectly aligned and there is a slight mismatch (see screenshot).
Code for reproduction
from matplotlib import pyplot as plt
fig, ax = plt.subplots()
txt = "$k$1|\n1|"
ax.text(1, 0.5, txt, ha="right", ma="right", transform=ax.transAxes)
fig.savefig("/tmp/bla.pdf")
fig.savefig("/tmp/bla.png")
Actual outcome
Expected outcome
That the lines are properly aligned as speicified. What I noticed is that when directly comparing the output with and without math mode in the offending line is that the line is actually shifted to the top right a tiny amount.
Additional information
No response
Operating system
Arch linux
Matplotlib Version
3.10.0
Matplotlib Backend
qtagg
Python version
Python 3.13.1
Jupyter version
n/a
Installation
Linux package manager