Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit1936c94

Browse files
committed
Also handle\displaystyle and\mathdefault at the TeX level.
Note that tex_escape is still being tested bytest_minus_signs_with_tex, which explicitly checks support for unicodeminus.
1 parent972b815 commit1936c94

File tree

2 files changed

+13
-33
lines changed

2 files changed

+13
-33
lines changed

‎lib/matplotlib/backends/backend_pgf.py‎

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@
3838
@_api.caching_module_getattr
3939
class__getattr__:
4040
NO_ESCAPE=_api.deprecated("3.6",obj_type="")(
41-
property(lambdaself:_NO_ESCAPE))
41+
property(lambdaself:r"(?<!\\)(?:\\\\)*"))
4242
re_mathsep=_api.deprecated("3.6",obj_type="")(
43-
property(lambdaself:_split_math.__self__))
43+
property(lambdaself:r"(?<!\\)(?:\\\\)*\$"))
4444

4545

4646
@_api.deprecated("3.6")
@@ -58,7 +58,15 @@ def get_preamble():
5858

5959
def_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+
]
6270
ifmpl.rcParams["pgf.texsystem"]!="pdflatex":
6371
preamble.append("\\usepackage{fontspec}")
6472
ifmpl.rcParams["pgf.rcfonts"]:
@@ -83,13 +91,6 @@ def _get_preamble():
8391
mpl_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")
9495
defcommon_texification(text):
9596
return_tex_escape(text)
@@ -99,22 +100,8 @@ def _tex_escape(text):
99100
r"""
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-
fori,sinenumerate(parts):
114-
ifi%2:# mathmode replacements
115-
s=r"\(\displaystyle %s\)"%s
116-
parts[i]=s
117-
return"".join(parts)
104+
returntext.replace("\N{MINUS SIGN}",r"\ensuremath{-}")
118105

119106

120107
@_api.deprecated("3.6")

‎lib/matplotlib/tests/test_backend_pgf.py‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
importmatplotlib.pyplotasplt
1212
frommatplotlib.testingimport_has_tex_package,_check_for_pgf
1313
frommatplotlib.testing.compareimportcompare_images,ImageComparisonFailure
14-
frommatplotlib.backends.backend_pgfimportPdfPages,_tex_escape
14+
frommatplotlib.backends.backend_pgfimportPdfPages
1515
frommatplotlib.testing.decoratorsimport (
1616
_image_directories,check_figures_equal,image_comparison)
1717
frommatplotlib.testing._markersimport (
@@ -33,13 +33,6 @@ def compare_figure(fname, savefig_kwargs={}, tol=0):
3333
raiseImageComparisonFailure(err)
3434

3535

36-
@pytest.mark.parametrize('plain_text, escaped_text', [
37-
(r'quad_sum: $\sum x_i^2$',r'quad_sum: \(\displaystyle \sum x_i^2\)'),
38-
])
39-
deftest_tex_escape(plain_text,escaped_text):
40-
assert_tex_escape(plain_text)==escaped_text
41-
42-
4336
@needs_pgf_xelatex
4437
@needs_ghostscript
4538
@pytest.mark.backend('pgf')

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp