8000 Add middle for delims · randomrahulm/matplotlib@b5d9b43 · GitHub
[go: up one dir, main page]

Skip to content

Commit b5d9b43

Browse files
committed
Add middle for delims
1 parent 2aee6cc commit b5d9b43

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

lib/matplotlib/_mathtext.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1965,9 +1965,10 @@ def csnames(group, names):
19651965
| p.boldsymbol
19661966
)
19671967

1968+
mdelim = r"\middle" - (p.delim("mdelim") | Error("Expected a delimiter"))
19681969
p.auto_delim <<= (
19691970
r"\left" - (p.delim("left") | Error("Expected a delimiter"))
1970-
+ ZeroOrMore(p.simple | p.auto_delim)("mid")
1971+
+ ZeroOrMore(p.simple | p.auto_delim | mdelim)("mid")
19711972
+ r"\right" - (p.delim("right") | Error("Expected a delimiter"))
19721973
)
19731974

@@ -2586,13 +2587,23 @@ def overline(self, s, loc, toks):
25862587
def _auto_sized_delimiter(self, front, middle, back):
25872588
state = self.get_state()
25882589
if len(middle):
2589-
height = max(x.height for x in middle)
2590-
depth = max(x.depth for x in middle)
2590+
height = max([x.height for x in middle if not isinstance(x, str)])
2591+
depth = max([x.depth for x in middle if not isinstance(x, str)])
25912592
factor = None
2593+
for idx, el in enumerate(middle):
2594+
if isinstance(el, str) and el == '\\middle':
2595+
c = middle[idx + 1]
2596+
if c != '.':
2597+
middle[idx + 1] = AutoHeightChar(
2598+
c, height, depth, state, factor=factor)
2599+
else:
2600+
middle.remove(c)
2601+
del middle[idx]
25922602
else:
25932603
height = 0
25942604
depth = 0
25952605
factor = 1.0
2606+
25962607
parts = []
25972608
# \left. and \right. aren't supposed to produce any symbols
25982609
if front != '.':
Loading

lib/matplotlib/tests/test_mathtext.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
r'$\text{text}_{\text{sub}}^{\text{sup}} + \text{\$foo\$} + \frac{\text{num}}{\mathbf{\text{den}}}\text{with space, curly brackets \{\}, and dash -}$',
137137
r'$\boldsymbol{abcde} \boldsymbol{+} \boldsymbol{\Gamma + \Omega} \boldsymbol{01234} \boldsymbol{\alpha * \beta}$',
138138
r'$\left\lbrace\frac{\left\lbrack A^b_c\right\rbrace}{\left\leftbrace D^e_f \right\rbrack}\right\rightbrace\ \left\leftparen\max_{x} \left\lgroup \frac{A}{B}\right\rgroup \right\rightparen$',
139+
r'$\left( a\middle. b \right)$ $\left( \frac{a}{b} \middle\vert x_i \in P^S \right)$ $\left[ 1 - \middle| a\middle| + \left( x - \left\lfloor \dfrac{a}{b}\right\rfloor \right) \right]$',
139140
]
140141

141142
digits = "0123456789"

0 commit comments

Comments
 (0)
0