Skip to content
Closed
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: 17 additions & 0 deletions doc/users/next_whats_new/mathtext_middle.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
``mathtext`` supports ``\middle``
---------------------------------

The ``\middle`` latex command is now supported by `.mathtext`. It is a
complement to ``\left`` and ``\right`` and used to add a middle sized
separator. Currently, only a single ``\middle`` between ``\left`` and
``\right`` is supported.

.. plot::
:include-source: true

import matplotlib.pyplot as plt
plt.figure(figsize=(2, 1))
plt.figtext(
0.05, 0.55,
r"$\left\{\sum_{i=0}^x a_i \middle | x \in \mathbb{N}\right\}$",
size=20, math_fontfamily='cm')
33 changes: 23 additions & 10 deletions lib/matplotlib/_mathtext.py
Original file line number Diff line number Diff line change
Expand Up @@ -1782,7 +1782,7 @@ class _MathStyle(enum.Enum):

_ambi_delims = set(r"""
| \| / \backslash \uparrow \downarrow \updownarrow \Uparrow
\Downarrow \Updownarrow . \vert \Vert""".split())
\Downarrow \Updownarrow . \vert \Vert \mid""".split())
_left_delims = set(r"( [ \{ < \lfloor \langle \lceil".split())
_right_delims = set(r") ] \} > \rfloor \rangle \rceil".split())
_delims = _left_delims | _right_delims | _ambi_delims
Expand Down Expand Up @@ -1950,7 +1950,10 @@ def csnames(group, names):

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)("mid1")
+ Optional(r"\middle" - (p.delim("mid") |
Error("Expected a delimiter")))("middle")
+ ZeroOrMore(p.simple | p.auto_delim)("mid2")
+ r"\right" - (p.delim("right") | Error("Expected a delimiter"))
)

Expand Down Expand Up @@ -2560,11 +2563,14 @@ def overline(self, s, loc, toks):
hlist = Hlist([rightside])
return [hlist]

def _auto_sized_delimiter(self, front, middle, back):
def _auto_sized_delimiter(self, front, mid1, back, middle=".", mid2=None):
if mid2 is None:
mid2 = []
state = self.get_state()
if len(middle):
height = max(x.height for x in middle)
depth = max(x.depth for x in middle)
content = mid1 + mid2
if len(content):
height = max(x.height for x in content)
depth = max(x.depth for x in content)
factor = None
else:
height = 0
Expand All @@ -2575,7 +2581,11 @@ def _auto_sized_delimiter(self, front, middle, back):
if front != '.':
parts.append(
AutoHeightChar(front, height, depth, state, factor=factor))
parts.extend(middle)
parts.extend(mid1)
if middle != ".":
parts.append(
AutoHeightChar(middle, height, depth, state, factor=factor))
parts.extend(mid2)
if back != '.':
parts.append(
AutoHeightChar(back, height, depth, state, factor=factor))
Expand All @@ -2585,6 +2595,9 @@ def _auto_sized_delimiter(self, front, middle, back):
def auto_delim(self, s, loc, toks):
return self._auto_sized_delimiter(
toks["left"],
# if "mid" in toks ... can be removed when requiring pyparsing 3.
toks["mid"].asList() if "mid" in toks else [],
toks["right"])
# if "mid*" in toks ... can be removed when requiring pyparsing 3.
toks["mid1"].asList() if "mid1" in toks else [],
toks["right"],
toks["mid"] if "mid" in toks else ".",
toks["mid2"].asList() if "mid2" in toks else []
)
2 changes: 1 addition & 1 deletion lib/matplotlib/_mathtext_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@
'succnsim' : 8937,
'gimel' : 8503,
'vert' : 124,
'|' : 124,
'|' : 8214,
'varrho' : 1009,
'P' : 182,
'approxident' : 8779,
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading