diff --git a/lib/matplotlib/_mathtext.py b/lib/matplotlib/_mathtext.py index 35f7f1c606cf..d86385e94589 100644 --- a/lib/matplotlib/_mathtext.py +++ b/lib/matplotlib/_mathtext.py @@ -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")) ) @@ -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 != '.': diff --git a/lib/matplotlib/tests/baseline_images/test_mathtext/mathtext1_dejavusans_07.png b/lib/matplotlib/tests/baseline_images/test_mathtext/mathtext1_dejavusans_07.png new file mode 100644 index 000000000000..a84cd1d28274 Binary files /dev/null and b/lib/matplotlib/tests/baseline_images/test_mathtext/mathtext1_dejavusans_07.png differ diff --git a/lib/matplotlib/tests/test_mathtext.py b/lib/matplotlib/tests/test_mathtext.py index 0a3354954280..dab981f29a23 100644 --- a/lib/matplotlib/tests/test_mathtext.py +++ b/lib/matplotlib/tests/test_mathtext.py @@ -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"