You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: Alignment of minus sign when using LaTeX #28766
There seems to be a different alignment for the minus sign depending on if the string contains only the minus sign or more characters when LaTeX is used.
Matplotlib just grabs the generated image, cropped to minimal size, and position it in the correct location.
Although it may seem silly that this example doesn't work, one may also imagine much more complicated equations with multiple fractions etc, where it is clear that there is no way to really align two different equations as if they were written as one. That information is simply missing in the output Matplotlib gets.
Actually the information is already available (#16476), and indeed the bug is not present in any backend except agg; the problem arises because, even though the dvi file correctly places the minus sign well above the intended baseline position, the dvi parser cannot report the raster image of the minus sign as having "negative" depth (likely ultimately because in _output(), _font._height_depth_of(g) doesn't know about these negative depths).
Other backends (including mplcairo's raster backend) don't have this issue because they simply read the baseline and glyph coordinates from the dvi file and redraw the glyphs themselves, which is probably the better approach in any case (see also part of #20469 (comment) as well as the paragraph I've deleted at https://github.com/matplotlib/matplotlib/pull/28810/files.
Activity
oscargus commentedon Sep 3, 2024
Matplotlib just grabs the generated image, cropped to minimal size, and position it in the correct location.
Although it may seem silly that this example doesn't work, one may also imagine much more complicated equations with multiple fractions etc, where it is clear that there is no way to really align two different equations as if they were written as one. That information is simply missing in the output Matplotlib gets.
timhoffm commentedon Sep 3, 2024
One could add that information by adding a constant prefix including letters with descenders and ascenders, e.g. "gH", and then strip away the prefix.
QuLogic commentedon Sep 4, 2024
I thought we did measure something with
lpsomewhere, but not sure if that is linked to this code path.anntzer commentedon Sep 19, 2024
Actually the information is already available (#16476), and indeed the bug is not present in any backend except agg; the problem arises because, even though the dvi file correctly places the minus sign well above the intended baseline position, the dvi parser cannot report the raster image of the minus sign as having "negative" depth (likely ultimately because in
_output(),_font._height_depth_of(g)doesn't know about these negative depths).Other backends (including mplcairo's raster backend) don't have this issue because they simply read the baseline and glyph coordinates from the dvi file and redraw the glyphs themselves, which is probably the better approach in any case (see also part of #20469 (comment) as well as the paragraph I've deleted at https://github.com/matplotlib/matplotlib/pull/28810/files.
anntzer commentedon Mar 4, 2026
Closed by #30039.