Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1df9efc

Browse files
authored
Merge pull request #17578 from adambrown1/bugfix-issue-17574
Search for minus of any font size to get height of tex result
2 parents ede8e56 + 053f535 commit 1df9efc

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

lib/matplotlib/dviread.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -595,11 +595,12 @@ def _height_depth_of(self, char):
595595
result.append(0)
596596
else:
597597
result.append(_mul2012(value, self._scale))
598-
# cmsy10 glyph 0 ("minus") has a nonzero descent so that TeX aligns
599-
# equations properly (https://tex.stackexchange.com/questions/526103/),
600-
# but we actually care about the rasterization depth to align the
601-
# dvipng-generated images.
602-
if self.texname == b"cmsy10" and char == 0:
598+
# cmsyXX (symbols font) glyph 0 ("minus") has a nonzero descent
599+
# so that TeX aligns equations properly
600+
# (https://tex.stackexchange.com/questions/526103/),
601+
# but we actually care about the rasterization depth to align
602+
# the dvipng-generated images.
603+
if re.match(br'^cmsy\d+$', self.texname) and char == 0:
603604
result[-1] = 0
604605
return result
605606

lib/matplotlib/tests/test_usetex.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,13 @@ def test_mathdefault():
6161
fig.canvas.draw()
6262

6363

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

0 commit comments

Comments
 (0)