14
14
15
15
import numpy as np
16
16
from pyparsing import (
17
- Empty , Forward , Literal , NotAny , oneOf , OneOrMore , Optional ,
17
+ Empty , Forward , Literal , NotAny , oneOf , OneOrMore , Optional , delimited_list ,
18
18
ParseBaseException , ParseException , ParseExpression , ParseFatalException ,
19
19
ParserElement , ParseResults , QuotedString , Regex , StringEnd , ZeroOrMore ,
20
20
pyparsing_common )
@@ -1700,6 +1700,7 @@ def names(elt):
1700
1700
csname = expr .split ("{" , 1 )[0 ]
1701
1701
err = (csname + "" .join ("{%s}" % name for name in names (args ))
1702
1702
if expr == csname else expr )
1703
+ print (csname , args , err )
1703
1704
return csname - (args | Error (f"Expected { err } " ))
1704
1705
1705
1706
@@ -1855,7 +1856,7 @@ def csnames(group, names):
1855
1856
+ r"|\\(?:{})(?![A-Za-z])" .format (
1856
1857
"|" .join (map (re .escape , tex2uni )))
1857
1858
)("sym" ).leaveWhitespace ()
1858
- p .unknown_symbol = Regex (r"\\[A-Za-z]* " )("name" )
1859
+ p .unknown_symbol = Regex (r"\\[A-Za-z]+ " )("name" )
1859
1860
1860
1861
p .font = csnames ("font" , self ._fontnames )
1861
1862
p .start_group = Optional (r"\math" + oneOf (self ._fontnames )("font" )) + "{"
@@ -1935,7 +1936,7 @@ def csnames(group, names):
1935
1936
p .operatorname = cmd (r"\operatorname" , "{" + ZeroOrMore (p .simple )("name" ) + "}" )
1936
1937
1937
1938
p .substack <<= cmd (
1938
- r"\substack" , OneOrMore (p .required_group ( "value" )) )
1939
+ r"\substack" , "{" + delimited_list ( OneOrMore (p .token ), delim = " \\ \\ " , combine = True )( "parts" ) + "}" )
1939
1940
1940
1941
p .placeable <<= (
1941
1942
p .accent # Must be before symbol as all accents are symbols
@@ -1952,8 +1953,8 @@ def csnames(group, names):
1952
1953
| p .underset
1953
1954
| p .sqrt
1954
1955
| p .overline
1955
- | p .text
1956
1956
| p .substack
1957
+ | p .text
1957
1958
)
1958
1959
1959
1960
p .auto_delim <<= (
@@ -1976,6 +1977,7 @@ def csnames(group, names):
1976
1977
1977
1978
# To add space to nucleus operators after sub/superscripts
1978
1979
self ._in_subscript_or_superscript = False
1980
+ self .p = p
1979
1981
1980
1982
def parse (self , s , fonts_object , fontsize , dpi ):
1981
1983
"""
@@ -2604,13 +2606,17 @@ def auto_delim(self, s, loc, toks):
2604
2606
toks ["right" ])
2605
2607
2606
2608
def substack (self , s , loc , toks ):
2609
+ print (list (toks .keys ()))
2610
+ print (toks ["parts" ])
2611
+ parts = toks ["parts" ].split ("\\ \\ " )
2612
+ print (parts )
2607
2613
state = self .get_state ()
2608
2614
thickness = state .get_current_underline_thickness ()
2609
2615
vlist = []
2610
2616
2611
- max_width = max (map (lambda c : c .width , toks [ 1 :] ))
2617
+ max_width = max (map (lambda c : c .width , parts ))
2612
2618
2613
- for sub in toks [ 1 :] :
2619
+ for sub in parts :
2614
2620
cp = HCentered ([sub ])
2615
2621
cp .hpack (max_width , 'exactly' )
2616
2622
vlist .append (cp )
0 commit comments