Skip to content

mathtext \left and \right delimiters not working #715

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 2 commits into from
Feb 27, 2012
Merged
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
26 changes: 17 additions & 9 deletions lib/matplotlib/mathtext.py
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,11 @@ def _get_glyph(self, fontname, font_class, sym, fontsize):
('\leftbrace', '{'),
('\rightbrace', '}'),
('\leftbracket', '['),
('\rightbracket', ']')]:
('\rightbracket', ']'),
(r'\{', '{'),
(r'\}', '}'),
(r'\[', '['),
(r'\]', ']')]:
_size_alternatives[alias] = _size_alternatives[target]

def get_sized_alternatives_for_symbol(self, fontname, sym):
Expand Down Expand Up @@ -970,6 +974,9 @@ def _map_virtual_font(self, fontname, font_class, uniindex):

_size_alternatives = {}
def get_sized_alternatives_for_symbol(self, fontname, sym):
fixes = {'\{': '{', '\}': '}', '\[': '[', '\]': ']'}
sym = fixes.get(sym, sym)

alternatives = self._size_alternatives.get(sym)
if alternatives:
return alternatives
Expand Down Expand Up @@ -1829,7 +1836,7 @@ class AutoHeightChar(Hlist):
fonts), the correct glyph will be selected, otherwise this will
always just return a scaled version of the glyph.
"""
def __init__(self, c, height, depth, state, always=False):
def __init__(self, c, height, depth, state, always=False, factor=None):
alternatives = state.font_output.get_sized_alternatives_for_symbol(
state.font, c)

Expand All @@ -1841,7 +1848,8 @@ def __init__(self, c, height, depth, state, always=False):
if char.height + char.depth >= target_total:
break

factor = target_total / (char.height + char.depth)
if factor is None:
factor = target_total / (char.height + char.depth)
state.fontsize *= factor
char = Char(sym, state)

Expand Down Expand Up @@ -2114,9 +2122,9 @@ class Parser(object):
| \| / \backslash \uparrow \downarrow \updownarrow \Uparrow
\Downarrow \Updownarrow .""".split())

_left_delim = set(r"( [ { < \lfloor \langle \lceil".split())
_left_delim = set(r"( [ \{ < \lfloor \langle \lceil".split())

_right_delim = set(r") ] } > \rfloor \rangle \rceil".split())
_right_delim = set(r") ] \} > \rfloor \rangle \rceil".split())

def __init__(self):
# All forward declarations are here
Expand Down Expand Up @@ -2772,8 +2780,6 @@ def _genfrac(self, ldelim, rdelim, rule, style, num, den):
ldelim = '.'
if rdelim == '':
rdelim = '.'
elif rdelim == r'\}':
rdelim = '}'
return self._auto_sized_delimiter(ldelim, result, rdelim)
return result

Expand Down Expand Up @@ -2883,16 +2889,18 @@ def _auto_sized_delimiter(self, front, middle, back):
if len(middle):
height = max([x.height for x in middle])
depth = max([x.depth for x in middle])
factor = None
else:
height = 0
depth = 0
factor = 1.0
parts = []
# \left. and \right. aren't supposed to produce any symbols
if front != '.':
parts.append(AutoHeightChar(front, height, depth, state))
parts.append(AutoHeightChar(front, height, depth, state, factor=factor))
parts.extend(middle)
if back != '.':
parts.append(AutoHeightChar(back, height, depth, state))
parts.append(AutoHeightChar(back, height, depth, state, factor=factor))
hlist = Hlist(parts)
return hlist

Expand Down