@@ -1750,12 +1750,10 @@ class Parser(object):
17501750 _overunder_symbols = Set (r'''
17511751 \sum \prod \coprod \bigcap \bigcup \bigsqcup \bigvee
17521752 \bigwedge \bigodot \bigotimes \bigoplus \biguplus
1753- ''' .split ()
1754- )
1753+ ''' .split ())
17551754
17561755 _overunder_functions = Set (
1757- r"lim liminf limsup sup max min" .split ()
1758- )
1756+ r"lim liminf limsup sup max min" .split ())
17591757
17601758 _dropsub_symbols = Set (r'''\int \oint''' .split ())
17611759
@@ -1769,11 +1767,13 @@ def __init__(self):
17691767 autoDelim = Forward ().setParseAction (self .auto_sized_delimiter )
17701768 self ._expression = Forward ().setParseAction (self .finish ).setName ("finish" )
17711769
1770+ float = Regex (r"-?[0-9]+\.?[0-9]*" )
1771+
17721772 lbrace = Literal ('{' ).suppress ()
17731773 rbrace = Literal ('}' ).suppress ()
17741774 start_group = (Optional (latexfont ) + lbrace )
17751775 start_group .setParseAction (self .start_group )
1776- end_group = rbrace
1776+ end_group = rbrace . copy ()
17771777 end_group .setParseAction (self .end_group )
17781778
17791779 bslash = Literal ('\\ ' )
@@ -1786,15 +1786,9 @@ def __init__(self):
17861786 "cosh gcd ln sup cot hom log tan coth inf max "
17871787 "tanh" )
17881788
1789- number = Combine (Word (nums ) + Optional (Literal ('.' )) + Optional ( Word (nums ) ))
1790-
17911789 fontname = oneOf ("rm cal it tt sf bf" )
17921790 latex2efont = oneOf ("mathrm mathcal mathit mathtt mathsf mathbf" )
17931791
1794- texsym = Combine (bslash + Word (alphanums ) + NotAny ("{" ))
1795-
1796- char = Word (alphanums + ' ' , exact = 1 ).leaveWhitespace ()
1797-
17981792 space = (FollowedBy (bslash )
17991793 + (Literal (r'\ ' )
18001794 | Literal (r'\/' )
@@ -1806,19 +1800,18 @@ def __init__(self):
18061800 )
18071801 ).setParseAction (self .space ).setName ('space' )
18081802
1809- symbol = Regex ("(" + ")|(" .join (
1810- [
1811- r"\\(?!quad)(?!qquad)(?!left[^a-z])(?!right[^a-z])[a-zA-Z0-9]+(?!{)" ,
1812- r"[a-zA-Z0-9 ]" ,
1813- r"[+\-*/]" ,
1814- r"[<>=]" ,
1815- r"[:,.;!'@[()]" ,
1816- r"\\[$%{}]" ,
1817- ])
1818- + ")"
1819- ).setParseAction (self .symbol ).leaveWhitespace ()
1803+ customspace = (Literal (r'\hspace' )
1804+ + lbrace
1805+ + float
1806+ + rbrace
1807+ ).setParseAction (self .customspace ).setName ('customspace' )
18201808
1821- rightBracket = Literal ("[" ).setParseAction (self .symbol ).leaveWhitespace ()
1809+ symbol = (Regex (r"[a-zA-Z0-9 +\-*/<>=:,.;!'@()[\]]" )
1810+ ^ Combine (
1811+ bslash
1812+ + oneOf (tex2uni .keys ())
1813+ )
1814+ ).setParseAction (self .symbol ).leaveWhitespace ()
18221815
18231816 accent = Group (
18241817 Combine (bslash + accent )
@@ -1873,13 +1866,13 @@ def __init__(self):
18731866 placeable << (accent
18741867 ^ function
18751868 ^ symbol
1876- ^ rightBracket
18771869 ^ group
18781870 ^ frac
18791871 ^ sqrt
18801872 )
18811873
18821874 simple << (space
1875+ | customspace
18831876 | font
18841877 | subsuper
18851878 )
@@ -2016,6 +2009,9 @@ def space(self, s, loc, toks):
20162009 box = self ._make_space (num )
20172010 return [box ]
20182011
2012+ def customspace (self , s , loc , toks ):
2013+ return [self ._make_space (float (toks [1 ]))]
2014+
20192015 def symbol (self , s , loc , toks ):
20202016 # print "symbol", toks
20212017 c = toks [0 ]
@@ -2226,7 +2222,8 @@ def subsuperscript(self, s, loc, toks):
22262222 y = Hlist ([sub ])
22272223 # y.width += SCRIPT_SPACE * xHeight
22282224 shift_down = max (shift_down , SUB1 * xHeight )
2229- clr = 2.0 * rule_thickness - ((shift_up - x .depth ) - (y .height - shift_down ))
2225+ clr = (2.0 * rule_thickness -
2226+ ((shift_up - x .depth ) - (y .height - shift_down )))
22302227 if clr > 0. :
22312228 shift_up += clr
22322229 shift_down += clr
0 commit comments