8000 Support ~ as nonbreaking space in mathtext. · matplotlib/matplotlib@cb6dda6 · GitHub
[go: up one dir, main page]

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 cb6dda6

Browse files
committed
Support ~ as nonbreaking space in mathtext.
... consistently with TeX. (AFAICT we never break mathtext over multiple lines so it's just a normal space for us.) See e.g. https://tex.stackexchange.com/a/74354/4101 for reference.
1 parent 99d8900 commit cb6dda6

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
``~`` now interpreted as space in mathtext
2+
``````````````````````````````````````````
3+
In constructs such as ``"$1~2$"``, mathtext now interprets the tilde as a
4+
space, consistently with TeX (this was previously a parse error).

lib/matplotlib/mathtext.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2696,6 +2696,7 @@ def _make_space(self, percentage):
26962696
r'\:' : 0.22222, # 4/18 em = 4 mu
26972697
r'\;' : 0.27778, # 5/18 em = 5 mu
26982698
r'\ ' : 0.33333, # 6/18 em = 6 mu
2699+
r'~' : 0.33333, # 6/18 em = 6 mu, nonbreakable
26992700
8000 r'\enspace' : 0.5, # 9/18 em = 9 mu
27002701
r'\quad' : 1, # 1 em = 18 mu
27012702
r'\qquad' : 2, # 2 em = 36 mu

lib/matplotlib/tests/test_mathtext.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import pytest
66

77
import matplotlib
8-
from matplotlib.testing.decorators import image_comparison
8+
from matplotlib.testing.decorators import check_figures_equal, image_comparison
99
import matplotlib.pyplot as plt
1010
from matplotlib import mathtext
1111

@@ -271,3 +271,9 @@ def test_single_minus_sign():
271271

272272
# If this fails, it would be all white
273273
assert not np.all(array == 0xff)
274+
275+
276+
@check_figures_equal(extensions=["png"])
277+
def test_spaces(fig_test, fig_ref):
278+
fig_test.subplots().set_title(r"$1\,2\>3\ 4$")
279+
fig_ref.subplots().set_title(r"$1\/2\:3~4$")

0 commit comments

Comments
 (0)
0