Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit60e1ce5

Browse files
committed
Simplify definition of mathtext symbols.
Use a single regex that handles both single_symbol (a single character)and symbol_name (`\knowntexsymbolname`), and also slightly simplify the"end-of-symbol-name" regex.This parsing element comes up extremely often, and removing oneindirection layers shaves off ~3-4% off drawing all the current mathtexttests, i.e.```MPLBACKEND=agg python -c 'import time; from pylab import *; from matplotlib.tests.test_mathtext import math_tests; fig = figure(figsize=(3, 10)); fig.text(0, 0, "\n".join(filter(None, math_tests)), size=6); start = time.perf_counter(); [fig.canvas.draw() for _ in range(10)]; print((time.perf_counter() - start) / 10)'```
1 parent7c19d85 commit60e1ce5

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

‎lib/matplotlib/_mathtext.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
importfunctools
99
importlogging
1010
importos
11+
importre
1112
importtypes
1213
importunicodedata
1314

@@ -1710,15 +1711,13 @@ def set_names_and_parse_actions():
17101711
p.float_literal=Regex(r"[-+]?([0-9]+\.?[0-9]*|\.[0-9]+)")
17111712
p.space=oneOf(self._space_widths)("space")
17121713

1713-
p.single_symbol=Regex(
1714-
r"([a-zA-Z0-9 +\-*/<>=:,.;!\?&'@()\[\]|%s])|(\\[%%${}\[\]_|])"%
1715-
"\U00000080-\U0001ffff"# unicode range
1716-
)("sym")
17171714
p.accentprefixed="\\"+oneOf(self._accentprefixed)("sym")
1718-
p.symbol_name= (
1719-
oneOf([rf"\{sym}"forsymintex2uni])("sym")
1720-
+Regex("(?=[^A-Za-z]|$)").leaveWhitespace())
1721-
p.symbol= (p.single_symbol|p.symbol_name).leaveWhitespace()
1715+
p.symbol=Regex(
1716+
r"[a-zA-Z0-9 +\-*/<>=:,.;!\?&'@()\[\]|\U00000080-\U0001ffff]"
1717+
r"|\\[%${}\[\]_|]"
1718+
+r"|\\(?:{})(?![A-Za-z])".format(
1719+
"|".join(map(re.escape,tex2uni)))
1720+
)("sym").leaveWhitespace()
17221721
p.unknown_symbol=Regex(r"\\[A-Za-z]*")("name")
17231722

17241723
p.font="\\"+oneOf(self._fontnames)("font")

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp