@@ -1709,6 +1709,7 @@ def __init__(self, c, width, state, always=False, char_class=Char):
17091709 char = char_class (sym , state )
17101710
17111711 Hlist .__init__ (self , [char ])
1712+ self .width = char .width
17121713
17131714class Ship (object ):
17141715 """Once the boxes have been set up, this sends them to output.
@@ -1744,11 +1745,14 @@ def hlist_out(self, box):
17441745 left_edge = self .cur_h
17451746 self .cur_s += 1
17461747 self .max_push = max (self .cur_s , self .max_push )
1747-
1748+ clamp = self .clamp
1749+
17481750 for p in box .children :
17491751 if isinstance (p , Char ):
17501752 p .render (self .cur_h + self .off_h , self .cur_v + self .off_v )
17511753 self .cur_h += p .width
1754+ elif isinstance (p , Kern ):
1755+ self .cur_h += p .width
17521756 elif isinstance (p , List ):
17531757 # @623
17541758 if len (p .children ) == 0 :
@@ -1787,14 +1791,12 @@ def hlist_out(self, box):
17871791 if glue_sign == 1 : # stretching
17881792 if glue_spec .stretch_order == glue_order :
17891793 cur_glue += glue_spec .stretch
1790- cur_g = round (self . clamp (float (box .glue_set ) * cur_glue ))
1794+ cur_g = round (clamp (float (box .glue_set ) * cur_glue ))
17911795 elif glue_spec .shrink_order == glue_order :
17921796 cur_glue += glue_spec .shrink
1793- cur_g = round (self . clamp (float (box .glue_set ) * cur_glue ))
1797+ cur_g = round (clamp (float (box .glue_set ) * cur_glue ))
17941798 rule_width += cur_g
17951799 self .cur_h += rule_width
1796- elif isinstance (p , Kern ):
1797- self .cur_h += p .width
17981800 self .cur_s -= 1
17991801
18001802 def vlist_out (self , box ):
@@ -1807,9 +1809,12 @@ def vlist_out(self, box):
18071809 left_edge = self .cur_h
18081810 self .cur_v -= box .height
18091811 top_edge = self .cur_v
1812+ clamp = self .clamp
18101813
18111814 for p in box .children :
1812- if isinstance (p , List ):
1815+ if isinstance (p , Kern ):
1816+ self .cur_v += p .width
1817+ elif isinstance (p , List ):
18131818 if len (p .children ) == 0 :
18141819 self .cur_v += p .height + p .depth
18151820 else :
@@ -1842,14 +1847,12 @@ def vlist_out(self, box):
18421847 if glue_sign == 1 : # stretching
18431848 if glue_spec .stretch_order == glue_order :
18441849 cur_glue += glue_spec .stretch
1845- cur_g = round (self . clamp (float (box .glue_set ) * cur_glue ))
1850+ cur_g = round (clamp (float (box .glue_set ) * cur_glue ))
18461851 elif glue_spec .shrink_order == glue_order : # shrinking
18471852 cur_glue += glue_spec .shrink
1848- cur_g = round (self . clamp (float (box .glue_set ) * cur_glue ))
1853+ cur_g = round (clamp (float (box .glue_set ) * cur_glue ))
18491854 rule_height += cur_g
18501855 self .cur_v += rule_height
1851- elif isinstance (p , Kern ):
1852- self .cur_v += p .width
18531856 elif isinstance (p , Char ):
18541857 raise RuntimeError ("Internal mathtext error: Char node found in vlist" )
18551858 self .cur_s -= 1
@@ -1923,6 +1926,21 @@ class Parser(object):
19231926
19241927 _dropsub_symbols = Set (r'''\int \oint''' .split ())
19251928
1929+ _fontnames = Set ("rm cal it tt sf bf default bb frak circled scr" .split ())
1930+
1931+ _function_names = Set ("""
1932+ arccos csc ker min arcsin deg lg Pr arctan det lim sec arg dim
1933+ liminf sin cos exp limsup sinh cosh gcd ln sup cot hom log tan
1934+ coth inf max tanh""" .split ())
1935+
1936+ _ambiDelim = Set (r"""
1937+ | \| / \backslash \uparrow \downarrow \updownarrow \Uparrow
1938+ \Downarrow \Updownarrow .""" .split ())
1939+
1940+ _leftDelim = Set (r"( [ { \lfloor \langle \lceil" .split ())
1941+
1942+ _rightDelim = Set (r") ] } \rfloor \rangle \rceil" .split ())
1943+
19261944 def __init__ (self ):
19271945 # All forward declarations are here
19281946 font = Forward ().setParseAction (self .font ).setName ("font" )
@@ -1946,15 +1964,10 @@ def __init__(self):
19461964
19471965 accent = oneOf (self ._accent_map .keys () + list (self ._wide_accents ))
19481966
1949- function = oneOf ("arccos csc ker min arcsin deg lg Pr arctan det "
1950- "lim sec arg dim liminf sin cos exp limsup sinh "
1951- "cosh gcd ln sup cot hom log tan coth inf max "
1952- "tanh" )
1967+ function = oneOf (list (self ._function_names ))
19531968
1954- fontname = oneOf ("rm cal it tt sf bf" )
1955- latex2efont = oneOf ("mathrm mathcal mathit mathtt mathsf mathbf "
1956- "mathdefault mathbb mathfrak mathcircled "
1957- "mathscr" )
1969+ fontname = oneOf (list (self ._fontnames ))
1970+ latex2efont = oneOf (['math' + x for x in self ._fontnames ])
19581971
19591972 space = (FollowedBy (bslash )
19601973 + (Literal (r'\ ' )
@@ -1993,7 +2006,8 @@ def __init__(self):
19932006 ).setParseAction (self .accent ).setName ("accent" )
19942007
19952008 function = (Suppress (bslash )
1996- + function ).setParseAction (self .function ).setName ("function" )
2009+ + function
2010+ ).setParseAction (self .function ).setName ("function" )
19972011
19982012 group = Group (
19992013 start_group
@@ -2065,11 +2079,9 @@ def __init__(self):
20652079 | placeable
20662080 )
20672081
2068- ambiDelim = oneOf (r"""| \| / \backslash \uparrow \downarrow
2069- \updownarrow \Uparrow \Downarrow
2070- \Updownarrow .""" )
2071- leftDelim = oneOf (r"( [ { \lfloor \langle \lceil" )
2072- rightDelim = oneOf (r") ] } \rfloor \rangle \rceil" )
2082+ ambiDelim = oneOf (self ._ambiDelim )
2083+ leftDelim = oneOf (self ._leftDelim )
2084+ rightDelim = oneOf (self ._rightDelim )
20732085 autoDelim << (Suppress (Literal (r"\left" ))
20742086 + ((leftDelim | ambiDelim ) | Error ("Expected a delimiter" ))
20752087 + Group (
@@ -2397,14 +2409,17 @@ def subsuperscript(self, s, loc, toks):
23972409 super = next1
23982410 sub = next2
23992411 else :
2400- raise ParseFatalException ("Subscript/superscript sequence is too long. Use braces { } to remove ambiguity." )
2412+ raise ParseFatalException (
2413+ "Subscript/superscript sequence is too long. "
2414+ "Use braces { } to remove ambiguity." )
24012415
24022416 state = self .get_state ()
24032417 rule_thickness = state .font_output .get_underline_thickness (
24042418 state .font , state .fontsize , state .dpi )
24052419 xHeight = state .font_output .get_xheight (
24062420 state .font , state .fontsize , state .dpi )
24072421
2422+ # Handle over/under symbols, such as sum or integral
24082423 if self .is_overunder (nucleus ):
24092424 vlist = []
24102425 shift = 0.
@@ -2433,6 +2448,7 @@ def subsuperscript(self, s, loc, toks):
24332448 result = Hlist ([vlist ])
24342449 return [result ]
24352450
2451+ # Handle regular sub/superscripts
24362452 shift_up = nucleus .height - SUBDROP * xHeight
24372453 if self .is_dropsub (nucleus ):
24382454 shift_down = nucleus .depth + SUBDROP * xHeight
0 commit comments