8000 Merge pull request #17485 from anntzer/usenotex · matplotlib/matplotlib@a3d7a42 · GitHub
[go: up one dir, main page]

Skip to content

Commit a3d7a42

Browse files
authored
Merge pull request #17485 from anntzer/usenotex
Support marking a single artist as not-usetex.
2 parents 510482f + e919969 commit a3d7a42

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

doc/api/api_changes_3.3/behaviour.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,3 +301,9 @@ When `.cbook.get_sample_data` is used to load a npy or npz file and the
301301
keyword-only parameter ``np_load`` is True, the file is automatically loaded
302302
using `numpy.load`. ``np_load`` defaults to False for backwards compatibility,
303303
but will become True in a later release.
304+
305+
``get_text_width_height_descent`` now checks ``ismath`` rather than :rc:`text.usetex`
306+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
307+
... to determine whether a string should be passed to the usetex machinery or
308+
not. This allows single strings to be marked as not-usetex even when the
309+
rcParam is True.

lib/matplotlib/backends/_backend_pdf_ps.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def get_canvas_width_height(self):
8080

8181
def get_text_width_height_descent(self, s, prop, ismath):
8282
# docstring inherited
83-
if mpl.rcParams["text.usetex"]:
83+
if ismath == "TeX":
8484
texmanager = self.get_texmanager()
8585
fontsize = prop.get_size_in_points()
8686
w, h, d = texmanager.get_text_width_height_descent(

lib/matplotlib/tests/test_text.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,11 +558,23 @@ def test_single_artist_usetex():
558558
# Check that a single artist marked with usetex does not get passed through
559559
# the mathtext parser at all (for the Agg backend) (the mathtext parser
560560
# currently fails to parse \frac12, requiring \frac{1}{2} instead).
561-
fig, ax = plt.subplots()
562-
ax.text(.5, .5, r"$\frac12$", usetex=True)
561+
fig = plt.figure()
562+
fig.text(.5, .5, r"$\frac12$", usetex=True)
563563
fig.canvas.draw()
564564

565565

566+
@pytest.mark.parametrize("fmt", ["png", "pdf", "svg"])
567+
def test_single_artist_usenotex(fmt):
568+
# Check that a single artist can be marked as not-usetex even though the
569+
# rcParam is on ("2_2_2" fails if passed to TeX). This currently skips
570+
# postscript output as the ps renderer doesn't support mixing usetex and
571+
# non-usetex.
572+
plt.rcParams["text.usetex"] = True
573+
fig = plt.figure()
574+
fig.text(.5, .5, "2_2_2", usetex=False)
575+
fig.savefig(io.BytesIO(), format=fmt)
576+
577+
566578
@image_comparison(['text_as_path_opacity.svg'])
567579
def test_text_as_path_opacity():
568580
plt.figure()

lib/matplotlib/textpath.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def _get_char_id_ps(self, font, ccode):
5252
return char_id
5353

5454
def get_text_width_height_descent(self, s, prop, ismath):
55-
if rcParams['text.usetex']:
55+
if ismath == "TeX":
5656
texmanager = self.get_texmanager()
5757
fontsize = prop.get_size_in_points()
5858
w, h, d = texmanager.get_text_width_height_descent(s, fontsize,

0 commit comments

Comments
 (0)
0