38
38
@_api .caching_module_getattr
39
39
class __getattr__ :
40
40
NO_ESCAPE = _api .deprecated ("3.6" , obj_type = "" )(
41
- property (lambda self : _NO_ESCAPE ))
41
+ property (lambda self : r"(?<!\\)(?:\\\\)*" ))
42
42
re_mathsep = _api .deprecated ("3.6" , obj_type = "" )(
43
- property (lambda self : _split_math . __self__ ))
43
+ property (lambda self : r"(?<!\\)(?:\\\\)*\$" ))
44
44
45
45
46
46
@_api .deprecated ("3.6" )
@@ -58,7 +58,15 @@ def get_preamble():
58
58
59
59
def _get_preamble ():
60
60
"""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
+ ]
62
70
if mpl .rcParams ["pgf.texsystem" ] != "pdflatex" :
63
71
preamble .append ("\\ usepackage{fontspec}" )
64
72
if mpl .rcParams ["pgf.rcfonts" ]:
@@ -83,13 +91,6 @@ def _get_preamble():
83
91
mpl_in_to_pt = 1. / mpl_pt_to_in
84
92
85
93
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
-
93
94
@_api .deprecated ("3.6" )
94
95
def common_texification (text ):
95
96
return _tex_escape (text )
@@ -99,22 +100,8 @@ def _tex_escape(text):
99
100
r"""
100
101
Do some necessary and/or useful substitutions for texts to be included in
101
102
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.
106
103
"""
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{-}" )
118
105
119
106
120
107
@_api .deprecated ("3.6" )
0 commit comments