8000 Add substack cmd for mathtext · matplotlib/matplotlib@cefc54e · GitHub
[go: up one dir, main page]

Skip to content

Commit cefc54e

Browse files
committed
Add substack cmd for mathtext
1 parent a861b8a commit cefc54e

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

lib/matplotlib/_mathtext.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1870,6 +1870,7 @@ def csnames(group, names):
18701870
p.required_group = Forward()
18711871
p.optional_group = Forward()
18721872
p.token = Forward()
1873+
p.substack = Forward()
18731874

18741875
set_names_and_parse_actions() # for mutually recursive definitions.
18751876

@@ -1933,6 +1934,9 @@ def csnames(group, names):
19331934

19341935
p.operatorname = cmd(r"\operatorname", "{" + ZeroOrMore(p.simple)("name") + "}")
19351936

1937+
p.substack <<= cmd(
1938+
r"\substack", OneOrMore(p.required_group("value")))
1939+
19361940
p.placeable <<= (
19371941
p.accent # Must be before symbol as all accents are symbols
19381942
| p.symbol # Must be second to catch all named symbols and single
@@ -1949,6 +1953,7 @@ def csnames(group, names):
19491953
| p.sqrt
19501954
| p.overline
19511955
| p.text
1956+
| p.substack
19521957
)
19531958

19541959
p.auto_delim <<= (
@@ -2597,3 +2602,24 @@ def auto_delim(self, s, loc, toks):
25972602
# if "mid" in toks ... can be removed when requiring pyparsing 3.
25982603
toks["mid"].asList() if "mid" in toks else [],
25992604
toks["right"])
2605+
2606+
def substack(self, s, loc, toks):
2607+
state = self.get_state()
2608+
thickness = state.get_current_underline_thickness()
2609+
vlist = []
2610+
2611+
max_width = max(map(lambda c: c.width, toks[1:]))
2612+
2613+
for sub in toks[1:]:
2614+
cp = HCentered([sub])
2615+
cp.hpack(max_width, 'exactly')
2616+
vlist.append(cp)
2617+
2618+
vlist = [val for pair in zip(vlist,
2619+
[Vbox(0, thickness * 2)] *
2620+
len(vlist)) for val in pair]
2621+
del vlist[-1]
2622+
2623+
vlt = Vlist(vlist)
2624+
result = [Hlist([vlt])]
2625+
return result
Loading

lib/matplotlib/tests/test_mathtext.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@
134134
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
135135
r'$1.$ $2.$ $19680801.$ $a.$ $b.$ $mpl.$',
136136
r'$\text{text}_{\text{sub}}^{\text{sup}} + \text{\$foo\$} + \frac{\text{num}}{\mathbf{\text{den}}}\text{with space, curly brackets \{\}, and dash -}$',
137-
137+
r'$\sum_{\substack{k = 1}{k \neq \lfloor n/2\rfloor}}^{n}P(i,j) \sum_{\substack{i \neq 0}{-1 \leq i \leq 3}{1 \leq j \leq 5}} F^i(x,y) \sum_{\substack{\left \lfloor \frac{n}{2} \right\rfloor}} F(n)$',
138138
]
139139

140140
digits = "0123456789"

0 commit comments

Comments
 (0)
0