3838@_api .caching_module_getattr
3939class __getattr__ :
4040NO_ESCAPE = _api .deprecated ("3.6" ,obj_type = "" )(
41- property (lambda self :_NO_ESCAPE ))
41+ property (lambda self :r"(?<!\\)(?:\\\\)*" ))
4242re_mathsep = _api .deprecated ("3.6" ,obj_type = "" )(
43- property (lambda self :_split_math . __self__ ))
43+ property (lambda self :r"(?<!\\)(?:\\\\)*\$" ))
4444
4545
4646@_api .deprecated ("3.6" )
@@ -58,7 +58,15 @@ def get_preamble():
5858
5959def _get_preamble ():
6060"""Prepare a LaTeX preamble based on the rcParams configuration."""
61- preamble = [mpl .rcParams ["pgf.preamble" ]]
61+ preamble = [
62+ # Remove Matplotlib's custom command \mathdefault. (Not using
63+ # \mathnormal instead since this looks odd with Computer Modern.)
64+ r"\def\mathdefault#1{#1}" ,
65+ # Use displaystyle for all math.
66+ r"\everymath=\expandafter{\the\everymath\displaystyle}" ,
67+ # Allow pgf.preamble to override the above definitions.
68+ mpl .rcParams ["pgf.preamble" ],
69+ ]
6270if mpl .rcParams ["pgf.texsystem" ]!= "pdflatex" :
6371preamble .append ("\\ usepackage{fontspec}" )
6472if mpl .rcParams ["pgf.rcfonts" ]:
@@ -83,13 +91,6 @@ def _get_preamble():
8391mpl_in_to_pt = 1. / mpl_pt_to_in
8492
8593
86- _NO_ESCAPE = r"(?<!\\)(?:\\\\)*"
87- _split_math = re .compile (_NO_ESCAPE + r"\$" ).split
88- _replace_mathdefault = functools .partial (
89- # Replace \mathdefault (when not preceded by an escape) by empty string.
90- re .compile (_NO_ESCAPE + r"(\\mathdefault)" ).sub ,"" )
91-
92-
9394@_api .deprecated ("3.6" )
9495def common_texification (text ):
9596return _tex_escape (text )
@@ -99,22 +100,8 @@ def _tex_escape(text):
99100r"""
100101 Do some necessary and/or useful substitutions for texts to be included in
101102 LaTeX documents.
102-
103- This distinguishes text-mode and math-mode by replacing the math separator
104- ``$`` with ``\(\displaystyle %s\)``. Escaped math separators (``\$``)
105- are ignored.
106103 """
107- # Sometimes, matplotlib adds the unknown command \mathdefault.
108- # Not using \mathnormal instead since this looks odd for the latex cm font.
109- text = _replace_mathdefault (text )
110- text = text .replace ("\N{MINUS SIGN} " ,r"\ensuremath{-}" )
111- # split text into normaltext and inline math parts
112- parts = _split_math (text )
113- for i ,s in enumerate (parts ):
114- if i % 2 :# mathmode replacements
115- s = r"\(\displaystyle %s\)" % s
116- parts [i ]= s
117- return "" .join (parts )
104+ return text .replace ("\N{MINUS SIGN} " ,r"\ensuremath{-}" )
118105
119106
120107@_api .deprecated ("3.6" )