Skip to content

Add middle for delims #26333

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions lib/matplotlib/_mathtext.py
Original file line number Diff line number Diff line change
Expand Up @@ -1965,9 +1965,10 @@ def csnames(group, names):
| p.boldsymbol
)

mdelim = r"\middle" - (p.delim("mdelim") | Error("Expected a delimiter"))
p.auto_delim <<= (
r"\left" - (p.delim("left") | Error("Expected a delimiter"))
+ ZeroOrMore(p.simple | p.auto_delim)("mid")
+ ZeroOrMore(p.simple | p.auto_delim | mdelim)("mid")
+ r"\right" - (p.delim("right") | Error("Expected a delimiter"))
)

Expand Down Expand Up @@ -2586,13 +2587,23 @@ def overline(self, s, loc, toks):
def _auto_sized_delimiter(self, front, middle, back):
state = self.get_state()
if len(middle):
height = max(x.height for x in middle)
depth = max(x.depth for x in middle)
height = max([x.height for x in middle if not isinstance(x, str)])
depth = max([x.depth for x in middle if not isinstance(x, str)])
factor = None
for idx, el in enumerate(middle):
if isinstance(el, str) and el == '\\middle':
c = middle[idx + 1]
if c != '.':
middle[idx + 1] = AutoHeightChar(
c, height, depth, state, factor=factor)
else:
middle.remove(c)
del middle[idx]
else:
height = 0
depth = 0
factor = 1.0

parts = []
# \left. and \right. aren't supposed to produce any symbols
if front != '.':
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions lib/matplotlib/tests/test_mathtext.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
r'$\text{text}_{\text{sub}}^{\text{sup}} + \text{\$foo\$} + \frac{\text{num}}{\mathbf{\text{den}}}\text{with space, curly brackets \{\}, and dash -}$',
r'$\boldsymbol{abcde} \boldsymbol{+} \boldsymbol{\Gamma + \Omega} \boldsymbol{01234} \boldsymbol{\alpha * \beta}$',
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$',
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]$',
]

digits = "0123456789"
Expand Down