Skip to content

Improve ps handling of individual usetex strings. #17256

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
May 5, 2020
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
8 changes: 8 additions & 0 deletions lib/matplotlib/backends/backend_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,14 @@ def draw_path_collection(self, gc, master_transform, paths, all_transforms,

def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!', mtext=None):
# docstring inherited
if not hasattr(self, "psfrag"):
_log.warning(
"The PS backend determines usetex status solely based on "
"rcParams['text.usetex'] and does not support having "
"usetex=True only for some elements; this element will thus "
"be rendered as if usetex=False.")
self.draw_text(gc, x, y, s, prop, angle, ismath, mtext)
return

w, h, bl = self.get_text_width_height_descent(s, prop, ismath)
fontsize = prop.get_size_in_points()
Expand Down
13 changes: 11 additions & 2 deletions lib/matplotlib/tests/test_backend_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,19 @@ def test_transparency():


@needs_usetex
def test_failing_latex(tmpdir):
def test_failing_latex():
"""Test failing latex subprocess call"""
mpl.rcParams['text.usetex'] = True
# This fails with "Double subscript"
plt.xlabel("$22_2_2$")
with pytest.raises(RuntimeError):
plt.savefig(Path(tmpdir, "tmpoutput.ps"))
plt.savefig(io.BytesIO(), format="ps")


@needs_usetex
def test_partial_usetex(caplog):
caplog.set_level("WARNING")
plt.figtext(.5, .5, "foo", usetex=True)
plt.savefig(io.BytesIO(), format="ps")
assert caplog.records and all("as if usetex=False" in record.getMessage()
for record in caplog.records)
2 changes: 1 addition & 1 deletion lib/matplotlib/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ def draw(self, renderer):
if textobj.get_usetex():
textrenderer.draw_tex(gc, x, y, clean_line,
textobj._fontproperties, angle,
mtext=mtext)
ismath=ismath, mtext=mtext)
else:
textrenderer.draw_text(gc, x, y, clean_line,
textobj._fontproperties, angle,
Expand Down