Skip to content

Commit ce7f8a1

Browse files
committed
Add override_math to Text
1 parent 11258c2 commit ce7f8a1

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

lib/matplotlib/text.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ def __init__(self,
123123
linespacing=None,
124124
rotation_mode=None,
125125
usetex=None, # defaults to rcParams['text.usetex']
126+
override_math=False,
126127
wrap=False,
127128
transform_rotates_text=False,
128129
**kwargs
@@ -142,6 +143,7 @@ def __init__(self,
142143
color if color is not None else mpl.rcParams["text.color"])
143144
self.set_fontproperties(fontproperties)
144145
self.set_usetex(usetex)
146+
self.set_override_math(override_math)
145147
self.set_wrap(wrap)
146148
self.set_verticalalignment(verticalalignment)
147149
self.set_horizontalalignment(horizontalalignment)
@@ -1237,7 +1239,7 @@ def _preprocess_math(self, s):
12371239
if s == " ":
12381240
s = r"\ "
12391241
return s, "TeX"
1240-
elif cbook.is_math_text(s):
1242+
elif not self.get_override_math() and cbook.is_math_text(s):
12411243
return s, True
12421244
else:
12431245
return s.replace(r"\$", "$"), False
@@ -1274,6 +1276,22 @@ def get_usetex(self):
12741276
"""Return whether this `Text` object uses TeX for rendering."""
12751277
return self._usetex
12761278

1279+
def set_override_math(self, override_math):
1280+
"""
1281+
Parameters
1282+
----------
1283+
override_math : bool
1284+
Whether to override mathtext parsing with the normal parsing
1285+
"""
1286+
self._override_math = bool(override_math)
1287+
1288+
def get_override_math(self):
1289+
"""
1290+
Return whether this `Text` object is supposed to
1291+
override mathtext parsing with normal parsing.
1292+
"""
1293+
return self._override_math
1294+
12771295
def set_fontname(self, fontname):
12781296
"""
12791297
Alias for `set_family`.

0 commit comments

Comments
 (0)