Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions lib/matplotlib/dviread.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,11 +595,12 @@ def _height_depth_of(self, char):
result.append(0)
else:
result.append(_mul2012(value, self._scale))
# cmsy10 glyph 0 ("minus") has a nonzero descent so that TeX aligns
# equations properly (https://tex.stackexchange.com/questions/526103/),
# but we actually care about the rasterization depth to align the
# dvipng-generated images.
if self.texname == b"cmsy10" and char == 0:
# cmsyXX (symbols font) glyph 0 ("minus") has a nonzero descent
# so that TeX aligns equations properly
# (https://tex.stackexchange.com/questions/526103/),
# but we actually care about the rasterization depth to align
# the dvipng-generated images.
if re.match(br'^cmsy\d+$', self.texname) and char == 0:
result[-1] = 0
return result

Expand Down
4 changes: 3 additions & 1 deletion lib/matplotlib/tests/test_usetex.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,13 @@ def test_mathdefault():
fig.canvas.draw()


def test_minus_no_descent():
@pytest.mark.parametrize("fontsize", [8, 10, 12])
def test_minus_no_descent(fontsize):
# Test special-casing of minus descent in DviFont._height_depth_of, by
# checking that overdrawing a 1 and a -1 results in an overall height
# equivalent to drawing either of them separately.
mpl.style.use("mpl20")
mpl.rcParams['font.size'] = fontsize
heights = {}
fig = plt.figure()
for vals in [(1,), (-1,), (-1, 1)]:
Expand Down