Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b31d64c

Browse filesBrowse files
authored
Merge pull request #16900 from timhoffm/doc-common-texification
Document and test common_texification()
2 parents 1c93e76 + 1293733 commit b31d64c
Copy full SHA for b31d64c

File tree

Expand file treeCollapse file tree

2 files changed

+18
-2
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+18
-2
lines changed

‎lib/matplotlib/backends/backend_pgf.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_pgf.py
+7-1Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,15 @@ def repl_mathdefault(m):
9494

9595

9696
def common_texification(text):
97-
"""
97+
r"""
9898
Do some necessary and/or useful substitutions for texts to be included in
9999
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: ``_^$%``
100106
"""
101107
# Sometimes, matplotlib adds the unknown command \mathdefault.
102108
# Not using \mathnormal instead since this looks odd for the latex cm font.

‎lib/matplotlib/tests/test_backend_pgf.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_backend_pgf.py
+11-1Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import matplotlib.pyplot as plt
1414
from matplotlib.testing.compare import compare_images, ImageComparisonFailure
1515
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
1717

1818
baseline_dir, result_dir = _image_directories(lambda: 'dummy func')
1919

@@ -89,6 +89,16 @@ def create_figure():
8989
plt.ylim(0, 1)
9090

9191

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+
92102
# test compiling a figure to pdf with xelatex
93103
@needs_xelatex
94104
@pytest.mark.backend('pgf')

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.