Skip to content

Commit f51036b

Browse files
committed
Allow text operators to take an unbracketed argument.
Closes #276.
1 parent 768340f commit f51036b

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/Text/TeXMath/Readers/TeX.hs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -662,14 +662,19 @@ cancel c = do
662662
"\\xcancel" -> ECancel XSlash <$> texToken
663663
_ -> mzero
664664

665+
textContents :: (Text -> Exp) -> TP [Exp]
666+
textContents op = char '{' *> manyTill chunk (char '}')
667+
where
668+
chunk = (op . T.concat <$> many1 textual)
669+
<|> (char '{' *> (asGroup <$> manyTill chunk (char '}')))
670+
<|> innermath
671+
665672
text :: Text -> TP Exp
666673
text c = do
667674
op <- maybe mzero return $ M.lookup c textOps
668-
char '{'
669-
let chunk = ((op . T.concat) <$> many1 textual)
670-
<|> (char '{' *> (asGroup <$> manyTill chunk (char '}')))
671-
<|> innermath
672-
contents <- manyTill chunk (char '}')
675+
contents <- textContents op
676+
<|> ((:[]) . op <$> textCommand)
677+
<|> ((:[]) . op . T.singleton <$> noneOf "\n\t\r \\{}")
673678
spaces
674679
case contents of
675680
[] -> return (op "")

test/regression/276.test

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<<< tex
2+
x = y\text.x
3+
>>> native
4+
[ EIdentifier "x"
5+
, ESymbol Rel "="
6+
, EIdentifier "y"
7+
, EText TextNormal "."
8+
, EIdentifier "x"
9+
]

0 commit comments

Comments
 (0)