File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -94,9 +94,15 @@ def repl_mathdefault(m):
94
94
95
95
96
96
def common_texification (text ):
97
- """
97
+ r """
98
98
Do some necessary and/or useful substitutions for texts to be included in
99
99
LaTeX documents.
100
+
101
+ This distinguishes text-mode and math-mode by replacing the math separator
102
+ ``$`` with ``\(\displaystyle %s\)``. Escaped math separators (``\$``)
103
+ are ignored.
104
+
105
+ The following characters are escaped in text segments: ``_^$%``
100
106
"""
101
107
# Sometimes, matplotlib adds the unknown command \mathdefault.
102
108
# Not using \mathnormal instead since this looks odd for the latex cm font.
Original file line number Diff line number Diff line change 13
13
import matplotlib .pyplot as plt
14
14
from matplotlib .testing .compare import compare_images , ImageComparisonFailure
15
15
from matplotlib .testing .decorators import image_comparison , _image_directories
16
- from matplotlib .backends .backend_pgf import PdfPages
16
+ from matplotlib .backends .backend_pgf import PdfPages , common_texification
17
17
18
18
baseline_dir , result_dir = _image_directories (lambda : 'dummy func' )
19
19
@@ -89,6 +89,16 @@ def create_figure():
89
89
plt .ylim (0 , 1 )
90
90
91
91
92
+ @pytest .mark .parametrize ('plain_text, escaped_text' , [
93
+ (r'quad_sum: $\sum x_i^2$' , r'quad\_sum: \(\displaystyle \sum x_i^2\)' ),
94
+ (r'no \$splits \$ here' , r'no \$splits \$ here' ),
95
+ ('with_underscores' , r'with\_underscores' ),
96
+ ('% not a comment' , r'\% not a comment' ),
97
+ ('^not' , r'\^not' ),
98
+ ])
99
+ def test_common_texification (plain_text , escaped_text ):
100
+ assert common_texification (plain_text ) == escaped_text
101
+
92
102
# test compiling a figure to pdf with xelatex
93
103
@needs_xelatex
94
104
@pytest .mark .backend ('pgf' )
You can’t perform that action at this time.
0 commit comments