From 5add058677eb98bbf4ecc131efff2ba63f556e8b Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Fri, 24 Feb 2012 18:23:43 -0500 Subject: [PATCH 1/2] Fix a couple of problems with auto-sized delimiters: \left{ should be \left\{ etc. If the delimiters have no content, they were getting shrinked down to nothing. --- lib/matplotlib/mathtext.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/lib/matplotlib/mathtext.py b/lib/matplotlib/mathtext.py index 9ab50b5dce7b..e93066a34b72 100644 --- a/lib/matplotlib/mathtext.py +++ b/lib/matplotlib/mathtext.py @@ -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): @@ -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 @@ -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) @@ -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) @@ -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 @@ -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 @@ -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 From 49be6b50f94c3bbf1ad2e4761ece3a90c34edef4 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Mon, 27 Feb 2012 13:48:25 -0500 Subject: [PATCH 2/2] Fix auto-sized square brackets --- lib/matplotlib/mathtext.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/mathtext.py b/lib/matplotlib/mathtext.py index e93066a34b72..d7700a42d3b6 100644 --- a/lib/matplotlib/mathtext.py +++ b/lib/matplotlib/mathtext.py @@ -2122,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