Revision: 3724 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3724&view=rev Author: mdboom Date: 2007-08-21 10:25:57 -0700 (Tue, 21 Aug 2007)
Log Message: ----------- Making parser more robust -- will only accept valid symbol names. (Re-)adding \hspace{ } command. Modified Paths: -------------- trunk/matplotlib/examples/mathtext_examples.py trunk/matplotlib/lib/matplotlib/_mathtext_data.py trunk/matplotlib/lib/matplotlib/mathtext.py Modified: trunk/matplotlib/examples/mathtext_examples.py =================================================================== --- trunk/matplotlib/examples/mathtext_examples.py 2007-08-21 15:24:26 UTC (rev 3723) +++ trunk/matplotlib/examples/mathtext_examples.py 2007-08-21 17:25:57 UTC (rev 3724) @@ -9,7 +9,7 @@ r'$100\%y\ x*y\ x/y x\$y$', r'$x\leftarrow y\ x\forall y\ x-y$', r'$x \sf x \bf x {\cal X} \rm x$', - r'$x\ x\,x\;x\quad x\qquad x\!x$', + r'$x\ x\,x\;x\quad x\qquad x\!x\hspace{0.5}y$', r'$\{ \rm braces \}$', r'$\left[\left\lfloor\frac{5}{\frac{\left(3\right)}{4}} y\right)\right]$', r'$\left(x\right)$', Modified: trunk/matplotlib/lib/matplotlib/_mathtext_data.py =================================================================== --- trunk/matplotlib/lib/matplotlib/_mathtext_data.py 2007-08-21 15:24:26 UTC (rev 3723) +++ trunk/matplotlib/lib/matplotlib/_mathtext_data.py 2007-08-21 17:25:57 UTC (rev 3724) @@ -1763,7 +1763,6 @@ 'Theta': 920, 'origof': 8886, 'blacksquare': 9632, -'hspace': 8202, 'solbar': 9023, 'neg': 172, 'sum': 8721, Modified: trunk/matplotlib/lib/matplotlib/mathtext.py =================================================================== --- trunk/matplotlib/lib/matplotlib/mathtext.py 2007-08-21 15:24:26 UTC (rev 3723) +++ trunk/matplotlib/lib/matplotlib/mathtext.py 2007-08-21 17:25:57 UTC (rev 3724) @@ -1750,12 +1750,10 @@ _overunder_symbols = Set(r''' \sum \prod \coprod \bigcap \bigcup \bigsqcup \bigvee \bigwedge \bigodot \bigotimes \bigoplus \biguplus - '''.split() - ) + '''.split()) _overunder_functions = Set( - r"lim liminf limsup sup max min".split() - ) + r"lim liminf limsup sup max min".split()) _dropsub_symbols = Set(r'''\int \oint'''.split()) @@ -1769,11 +1767,13 @@ autoDelim = Forward().setParseAction(self.auto_sized_delimiter) self._expression = Forward().setParseAction(self.finish).setName("finish") + float = Regex(r"-?[0-9]+\.?[0-9]*") + lbrace = Literal('{').suppress() rbrace = Literal('}').suppress() start_group = (Optional(latexfont) + lbrace) start_group.setParseAction(self.start_group) - end_group = rbrace + end_group = rbrace.copy() end_group.setParseAction(self.end_group) bslash = Literal('\\') @@ -1786,15 +1786,9 @@ "cosh gcd ln sup cot hom log tan coth inf max " "tanh") - number = Combine(Word(nums) + Optional(Literal('.')) + Optional( Word(nums) )) - fontname = oneOf("rm cal it tt sf bf") latex2efont = oneOf("mathrm mathcal mathit mathtt mathsf mathbf") - texsym = Combine(bslash + Word(alphanums) + NotAny("{")) - - char = Word(alphanums + ' ', exact=1).leaveWhitespace() - space =(FollowedBy(bslash) + (Literal(r'\ ') | Literal(r'\/') @@ -1806,19 +1800,18 @@ ) ).setParseAction(self.space).setName('space') - symbol = Regex("(" + ")|(".join( - [ - r"\\(?!quad)(?!qquad)(?!left[^a-z])(?!right[^a-z])[a-zA-Z0-9]+(?!{)", - r"[a-zA-Z0-9 ]", - r"[+\-*/]", - r"[<>=]", - r"[:,.;!'@[()]", - r"\\[$%{}]", - ]) - + ")" - ).setParseAction(self.symbol).leaveWhitespace() + customspace =(Literal(r'\hspace') + + lbrace + + float + + rbrace + ).setParseAction(self.customspace).setName('customspace') - rightBracket = Literal("[").setParseAction(self.symbol).leaveWhitespace() + symbol =(Regex(r"[a-zA-Z0-9 +\-*/<>=:,.;!'@()[\]]") + ^ Combine( + bslash + + oneOf(tex2uni.keys()) + ) + ).setParseAction(self.symbol).leaveWhitespace() accent = Group( Combine(bslash + accent) @@ -1873,13 +1866,13 @@ placeable <<(accent ^ function ^ symbol - ^ rightBracket ^ group ^ frac ^ sqrt ) simple <<(space + | customspace | font | subsuper ) @@ -2016,6 +2009,9 @@ box = self._make_space(num) return [box] + def customspace(self, s, loc, toks): + return [self._make_space(float(toks[1]))] + def symbol(self, s, loc, toks): # print "symbol", toks c = toks[0] @@ -2226,7 +2222,8 @@ y = Hlist([sub]) # y.width += SCRIPT_SPACE * xHeight shift_down = max(shift_down, SUB1 * xHeight) - clr = 2.0 * rule_thickness - ((shift_up - x.depth) - (y.height - shift_down)) + clr = (2.0 * rule_thickness - + ((shift_up - x.depth) - (y.height - shift_down))) if clr > 0.: shift_up += clr shift_down += clr This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ _______________________________________________ Matplotlib-checkins mailing list Matplotlib-checkins@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins