Skip to content

Commit 17de827

Browse files
authored
Fixed decimal points not appearing at end of Mathtext string. (#23357)
* Fixed decimal points not appearing at end of Mathtext string. * Added test for Mathtext strings ending with decimal point.
1 parent 4b311a2 commit 17de827

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

lib/matplotlib/_mathtext.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2000,16 +2000,16 @@ def symbol(self, s, loc, toks):
20002000
self._make_space(0.2)],
20012001
do_kern=True)]
20022002
elif c in self._punctuation_symbols:
2003+
prev_char = next((c for c in s[:loc][::-1] if c != ' '), '')
2004+
next_char = next((c for c in s[loc + 1:] if c != ' '), '')
20032005

20042006
# Do not space commas between brackets
20052007
if c == ',':
2006-
prev_char = next((c for c in s[:loc][::-1] if c != ' '), '')
2007-
next_char = next((c for c in s[loc + 1:] if c != ' '), '')
20082008
if prev_char == '{' and next_char == '}':
20092009
return [char]
20102010

20112011
# Do not space dots as decimal separators
2012-
if c == '.' and s[loc - 1].isdigit() and s[loc + 1].isdigit():
2012+
if c == '.' and prev_char.isdigit() and next_char.isdigit():
20132013
return [char]
20142014
else:
20152015
return [Hlist([char, self._make_space(0.2)], do_kern=True)]

lib/matplotlib/tests/test_mathtext.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@
128128
r'$\sqrt[ab]{123}$', # github issue #8665
129129
r'$x \overset{f}{\rightarrow} \overset{f}{x} \underset{xx}{ff} \overset{xx}{ff} \underset{f}{x} \underset{f}{\leftarrow} x$', # github issue #18241
130130
r'$\sum x\quad\sum^nx\quad\sum_nx\quad\sum_n^nx\quad\prod x\quad\prod^nx\quad\prod_nx\quad\prod_n^nx$', # GitHub issue 18085
131+
r'$1.$ $2.$ $19680801.$ $a.$ $b.$ $mpl.$',
131132
]
132133

133134
digits = "0123456789"

0 commit comments

Comments
 (0)