8000 Agg: When a single Text uses usetex, don't pass it through mathtext parser by anntzer · Pull Request #10175 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Agg: When a single Text uses usetex, don't pass it through mathtext parser #10175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 6, 2018
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
2 changes: 1 addition & 1 deletion lib/matplotlib/backends/backend_agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def get_text_width_height_descent(self, s, prop, ismath):
to the baseline), in display coords, of the string *s* with
:class:`~matplotlib.font_manager.FontProperties` *prop*
"""
if rcParams['text.usetex']:
if ismath in ["TeX", "TeX!"]:
# todo: handle props
size = prop.get_size_in_points()
texmanager = self.get_texmanager()
Expand Down
15 changes: 15 additions & 0 deletions lib/matplotlib/tests/test_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
from matplotlib.testing.decorators import image_comparison


needs_usetex = pytest.mark.xfail(
not matplotlib.checkdep_usetex(True),
reason="This test needs a TeX installation")


@image_comparison(baseline_images=['font_styles'])
def test_font_styles():
from matplotlib import _get_data_path
Expand Down Expand Up @@ -459,3 +464,13 @@ def test_hinting_factor_backends():
# Backends should apply hinting_factor consistently (within 10%).
np.testing.assert_allclose(t.get_window_extent().intervalx, expected,
rtol=0.1)


@needs_usetex
def test_single_artist_usetex():
# Check that a single artist marked with usetex does not get passed through
# the mathtext parser at all (for the Agg backend) (the mathtext parser
# currently fails to parse \frac12, requiring \frac{1}{2} instead).
fig, ax = plt.subplots()
ax.text(.5, .5, r"$\frac12$", usetex=True)
fig.canvas.draw()
0