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

Skip to content

Commit 3b3c16d

Browse files
authored
Merge pull request #10175 from anntzer/agg-single-artist-usetex
FIX: When a single Text uses usetex, don't pass it through mathtext parser
2 parents da9c7e4 + 69aa017 commit 3b3c16d

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/matplotlib/backends/backend_agg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def get_text_width_height_descent(self, s, prop, ismath):
222222
to the baseline), in display coords, of the string *s* with
223223
:class:`~matplotlib.font_manager.FontProperties` *prop*
224224
"""
225-
if rcParams['text.usetex']:
225+
if ismath in ["TeX", "TeX!"]:
226226
# todo: handle props
227227
size = prop.get_size_in_points()
228228
texmanager = self.get_texmanager()

lib/matplotlib/tests/test_text.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
from matplotlib.testing.decorators import image_comparison
1515

1616

17+
needs_usetex = pytest.mark.xfail(
18+
not matplotlib.checkdep_usetex(True),
19+
reason="This test needs a TeX installation")
20+
21+
1722
@image_comparison(baseline_images=['font_styles'])
1823
def test_font_styles():
1924
from matplotlib import _get_data_path
@@ -459,3 +464,13 @@ def test_hinting_factor_backends():
459464
# Backends should apply hinting_factor consistently (within 10%).
460465
np.testing.assert_allclose(t.get_window_extent().intervalx, expected,
461466
rtol=0.1)
467+
468+
469+
@needs_usetex
470+
def test_single_artist_usetex():
471+
# Check that a single artist marked with usetex does not get passed through
472+
# the mathtext parser at all (for the Agg backend) (the mathtext parser
473+
# currently fails to parse \frac12, requiring \frac{1}{2} instead).
474+
fig, ax = plt.subplots()
475+
ax.text(.5, .5, r"$\frac12$", usetex=True)
476+
fig.canvas.draw()

0 commit comments

Comments
 (0)