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 f4b2b68

Browse filesBrowse files
authored
Merge pull request #12947 from anntzer/texnbsp
Support ~ as nonbreaking space in mathtext.
2 parents 4c1d5c1 + cb6dda6 commit f4b2b68
Copy full SHA for f4b2b68

File tree

Expand file treeCollapse file tree

3 files changed

+12
-1
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+12
-1
lines changed
+4Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/mathtext.py
+1Lines 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
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

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_mathtext.py
+7-1Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.