8000 Support ~ as nonbreaking space in mathtext. by anntzer · Pull Request #12947 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Support ~ as nonbreaking space in mathtext. #12947

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

Merged
merged 1 commit into from
Dec 7, 2018
Merged
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
4 changes: 4 additions & 0 deletions doc/api/next_api_changes/2018-12-07-AL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
``~`` now interpreted as space in mathtext
``````````````````````````````````````````
In constructs such as ``"$1~2$"``, mathtext now interprets the tilde as a
space, consistently with TeX (this was previously a parse error).
1 change: 1 addition & 0 deletions lib/matplotlib/mathtext.py
Original file line number Diff line number Diff line change
Expand Up @@ -2696,6 +2696,7 @@ def _make_space(self, percentage):
r'\:' : 0.22222, # 4/18 em = 4 mu
r'\;' : 0.27778, # 5/18 em = 5 mu
r'\ ' : 0.33333, # 6/18 em = 6 mu
r'~' : 0.33333, # 6/18 em = 6 mu, nonbreakable
r'\enspace' : 0.5, # 9/18 em = 9 mu
r'\quad' : 1, # 1 em = 18 mu
r'\qquad' : 2, # 2 em = 36 mu
Expand Down
8 changes: 7 additions & 1 deletion lib/matplotlib/tests/test_mathtext.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pytest

import matplotlib
from matplotlib.testing.decorators import image_comparison
from matplotlib.testing.decorators import check_figures_equal, image_comparison
import matplotlib.pyplot as plt
from matplotlib import mathtext

Expand Down Expand Up @@ -271,3 +271,9 @@ def test_single_minus_sign():

# If this fails, it would be all white
assert not np.all(array == 0xff)


@check_figures_equal(extensions=["png"])
def test_spaces(fig_test, fig_ref):
fig_test.subplots().set_title(r"$1\,2\>3\ 4$")
fig_ref.subplots().set_title(r"$1\/2\:3~4$")
0