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

Skip to content

Commit d99ff6d

Browse files
committed
Add substack cmd for mathtext
1 parent 088e50b commit d99ff6d

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

lib/matplotlib/_mathtext.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1864,6 +1864,7 @@ def csnames(group, names):
18641864
p.text = Forward()
18651865
p.token = Forward()
18661866
p.underset = Forward()
1867+
p.substack = Forward()
18671868

18681869
set_names_and_parse_actions() # for mutually recursive definitions.
18691870

@@ -1914,6 +1915,9 @@ def csnames(group, names):
19141915

19151916
p.text <<= cmd(r"\text", QuotedString('{', '\\', endQuoteChar="}"))
19161917

1918+
p.substack <<= cmd(
1919+
r"\substack", OneOrMore(p.required_group("value")))
1920+
19171921
p.placeable <<= (
19181922
p.accent # Must be before symbol as all accents are symbols
19191923
| p.symbol # Must be second to catch all named symbols and single
@@ -1930,6 +1934,7 @@ def csnames(group, names):
19301934
| p.sqrt
19311935
| p.overline
19321936
| p.text
1937+
| p.substack
19331938
)
19341939

19351940
p.simple <<= (
@@ -2599,3 +2604,23 @@ def auto_delim(self, s, loc, toks):
25992604
# if "mid" in toks ... can be removed when requiring pyparsing 3.
26002605
toks["mid"].asList() if "mid" in toks else [],
26012606
toks["right"])
2607+
2608+
def substack(self, s, loc, toks):
2609+
state = self.get_state()
2610+
thickness = state.get_current_underline_thickness()
2611+
vlist = []
2612+
2613+
max_width = sorted(toks[1:], key= lambda c: c.width)[-1].width
2614+
2615+
for sub in toks[1:]:
2616+
cp = HCentered([sub])
2617+
cp.hpack(max_width, 'exactly')
2618+
vlist.append(cp)
2619+
2620+
vlist = [x for l in (vlist[i:i+1] +
2621+
[Vbox(0, thickness * 2.0)] *
2622+
(i < len(vlist) - 1)
2623+
for i in range(0, len(vlist), 1)) for x in l]
2624+
vlt = Vlist(vlist)
2625+
result = [Hlist([vlt])]
2626+
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)}$',
138138
]
139139

140140
digits = "0123456789"

0 commit comments

Comments
 (0)
0