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

Skip to content

Commit b960ac4

Browse files
committed
Add text.parse_math rcParams
1 parent 2e921df commit b960ac4

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

lib/matplotlib/mpl-data/matplotlibrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,8 @@
301301
# Values other than 0 or 6 have no defined meaning.
302302
#text.antialiased: True # If True (default), the text will be antialiased.
303303
# This only affects raster outputs.
304+
#text.parse_math: True # Use mathtext if there is an even number of unescaped
305+
# dollar signs.
304306

305307

306308
## ***************************************************************************

lib/matplotlib/rcsetup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,7 @@ def _convert_validator_spec(key, conv):
932932
"text.hinting_factor": validate_int,
933933
"text.kerning_factor": validate_int,
934934
"text.antialiased": validate_bool,
935+
"text.parse_math": validate_bool,
935936

936937
"mathtext.cal": validate_font_properties,
937938
"mathtext.rm": validate_font_properties,

lib/matplotlib/tests/test_text.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,20 @@ def test_parse_math():
755755
fig.canvas.draw()
756756

757757

758+
def test_parse_math_rcparams():
759+
# Default is True
760+
fig, ax = plt.subplots()
761+
ax.text(0, 0, r"$ \wrong{math} $")
762+
with pytest.raises(ValueError, match='Unknown symbol'):
763+
fig.canvas.draw()
764+
765+
# Setting rcParams to False
766+
with mpl.rc_context({'text.parse_math': False}):
767+
fig, ax = plt.subplots()
768+
ax.text(0, 0, r"$ \wrong{math} $")
769+
fig.canvas.draw()
770+
771+
758772
@image_comparison(['text_pdf_font42_kerning.pdf'], style='mpl20')
759773
def test_pdf_font42_kerning():
760774
plt.rcParams['pdf.fonttype'] = 42

lib/matplotlib/text.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,11 @@ def __init__(self,
138138
rotation=None,
139139
linespacing=None,
140140
rotation_mode=None,
141-
usetex=None, # defaults to rcParams['text.usetex']
141+
usetex=None,
142142
wrap=False,
143143
transform_rotates_text=False,
144144
*,
145-
parse_math=True,
145+
parse_math=None,
146146
**kwargs
147147
):
148148
"""
@@ -163,7 +163,8 @@ def __init__(self,
163163
color if color is not None else mpl.rcParams["text.color"])
164164
self.set_fontproperties(fontproperties)
165165
self.set_usetex(usetex)
166-
self.set_parse_math(parse_math)
166+
self.set_parse_math(parse_math if parse_math is not None else
167+
mpl.rcParams['text.parse_math'])
167168
self.set_wrap(wrap)
168169
self.set_verticalalignment(verticalalignment)
169170
self.set_horizontalalignment(horizontalalignment)

0 commit comments

Comments
 (0)