[Bug]: Spaced symbols should not be spaced when in limits etc
Author: oscargusCreated Jun 23, 2023Updated Sep 14, 2026
Labelstopic: text/mathtextstatus: inactive
Bug summary
As seen, LaTeX does not add a space around the arrows (or =/+-sign) when in subscripts, but mathtext does.
Note that there is no space around \to but in mathtext,around \rightarrow in mathtext, while for LaTeX they look exactly the same. (This is because \to is not listed in _mathtext.Parser._arrow_symbols, but it should be.)
Code for reproduction
import matplotlib.pyplot as plt
strings = [r'$\limsup_{x\to\infty}$',
r'$\limsup_{x\rightarrow\infty}$',
r'$x \to \infty$',
r'$x \rightarrow \infty$',
r'$\limsup_{x=a+b}$',
r'$x=a+b$',
r'$A^{a \times b}_{c \Uparrow d}$']
for i, s in enumerate(strings):
plt.text(0, i*0.15 + 0.05, s, fontsize=20)
plt.text(0.5, i*0.15 + 0.05, f"${s}$", usetex=True, fontsize=20)
plt.axis(False)
plt.savefig("spacing.png", dpi=200)Actual outcome
Expected outcome
No spaces around "spaced operators" in subscript.
Additional information
@devRD is this something you know how to fix?
Related to the failing test in https://github.com/matplotlib/matplotlib/pull/26173
Operating system
No response
Matplotlib Version
Latest main
Matplotlib Backend
No response
Python version
No response
Jupyter version
No response
Installation
None
Source: matplotlib/matplotlib