@@ -1857,6 +1857,7 @@ def csnames(group, names):
18571857 p .optional_group = Forward ()
18581858 p .sqrt = Forward ()
18591859 p .subsuper = Forward ()
1860+ p .text = Forward ()
18601861 p .token = Forward ()
18611862 p .underset = Forward ()
18621863
@@ -1907,6 +1908,8 @@ def csnames(group, names):
19071908 r"\underset" ,
19081909 p .optional_group ("annotation" ) + p .optional_group ("body" ))
19091910
1911+ p .text <<= cmd (r"\text" , QuotedString ('{' , '\\ ' , endQuoteChar = "}" ))
1912+
19101913 p .placeable <<= (
19111914 p .accent # Must be before symbol as all accents are symbols
19121915 | p .symbol # Must be second to catch all named symbols and single
@@ -1922,6 +1925,7 @@ def csnames(group, names):
19221925 | p .underset
19231926 | p .sqrt
19241927 | p .overline
1928+ | p .text
19251929 )
19261930
19271931 p .simple <<= (
@@ -2022,6 +2026,15 @@ def non_math(self, s, loc, toks):
20222026
20232027 float_literal = staticmethod (pyparsing_common .convertToFloat )
20242028
2029+ def text (self , s , loc , toks ):
2030+ self .push_state ()
2031+ state = self .get_state ()
2032+ state .font = 'rm'
2033+ s = toks [1 ].replace (r'\$' , '$' ).replace (r'\{' , '{' ).replace (r'\}' , '}' )
2034+ hlist = Hlist ([Char (c , state ) for c in s ])
2035+ self .pop_state ()
2036+ return [hlist ]
2037+
20252038 def _make_space (self , percentage ):
20262039 # In TeX, an em (the unit usually used to measure horizontal lengths)
20272040 # is not the width of the character 'm'; it is the same in different
0 commit comments