Skip to content

Let pgf backend use bracket delimiters for detecting math mode. #23381

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/matplotlib/backends/backend_pgf.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def _get_preamble():


_NO_ESCAPE = r"(?<!\\)(?:\\\\)*"
_split_math = re.compile(_NO_ESCAPE + r"\$").split
_split_math = re.compile(_NO_ESCAPE + r"(?:\$|\\[()])").split
_replace_escapetext = functools.partial(
# When the next character is _, ^, $, or % (not preceded by an escape),
# insert a backslash.
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
16 changes: 15 additions & 1 deletion lib/matplotlib/tests/test_backend_pgf.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,11 @@ def create_figure():

# text and typesetting
plt.plot([0.9], [0.5], "ro", markersize=3)
plt.text(0.9, 0.5, 'unicode (ü, °, µ) and math ($\\mu_i = x_i^2$)',
plt.text(0.9, 0.5, 'unicode (ü, °, µ), math ($\\mu_i = x_i^2$),' \
+ 'and parenthesis delimiters (\\(\\sqrt{\\mu_i} = x_i\\)).',
ha='right', fontsize=20)
plt.xlabel('sans-serif, blue, \\(x\\)..',
family='sans-serif', color='blue')
plt.ylabel('sans-serif, blue, $\\frac{\\sqrt{x}}{y^2}$..',
family='sans-serif', color='blue')

Expand All @@ -62,6 +65,7 @@ def create_figure():
@pytest.mark.parametrize('plain_text, escaped_text', [
(r'quad_sum: $\sum x_i^2$', r'quad\_sum: \(\displaystyle \sum x_i^2\)'),
(r'no \$splits \$ here', r'no \$splits \$ here'),
(r'nor \\(here either)', r'nor \\(here either)'),
('with_underscores', r'with\_underscores'),
('% not a comment', r'\% not a comment'),
('^not', r'\^not'),
Expand Down Expand Up @@ -333,6 +337,16 @@ def test_minus_signs_with_tex(fig_test, fig_ref, texsystem):
fig_test.text(.5, .5, "$-1$")
fig_ref.text(.5, .5, "$\N{MINUS SIGN}1$")

@check_figures_equal(extensions=["pdf"])
@pytest.mark.parametrize("texsystem", ("pdflatex", "xelatex", "lualatex"))
@pytest.mark.backend("pgf")
def test_minus_signs_with_tex_and_parentheses(fig_test, fig_ref, texsystem):
if not _check_for_pgf(texsystem):
pytest.skip(texsystem + ' + pgf is required')
mpl.rcParams["pgf.texsystem"] = texsystem
fig_test.text(.5, .5, "\\(-1\\)")
fig_ref.text(.5, .5, "\\(\N{MINUS SIGN}1\\)")


@pytest.mark.backend("pgf")
def test_sketch_params():
Expand Down