git.iko.soy/typeable/pandoc
on master help sign in
LaTeX reader: Fixed dollar-math parsing...

...to ensure that space is left between a control seq and a following word that would otherwise change its meaning. Closes #5836.

commit65593043c33b97f55170a53eb330d7ce069774cd authorJohn MacFarlane <jgm@berkeley.edu> dateSat 2 Nov 2019, 12:44 (7 years ago) parentf39c44f
2 files changed+17−9
src/Text/Pandoc/Readers/LaTeX.hs+9−9 test/command/5836.md+8
src/Text/Pandoc/Readers/LaTeX.hs+9−9
@@ -629,28 +629,28 @@ dollarsMath :: PandocMonad m => LP m Inlines
629629dollarsMath = do
630630 symbol '$'
631631 display <- option False (True <$ symbol '$')
632− (do contents <- try $ T.unpack <$> pDollarsMath 0
632+ (do contents <- try $ T.unpack . untokenize <$> pDollarsMath 0
633633 if display
634634 then (mathDisplay contents <$ symbol '$')
635635 else return $ mathInline contents)
636636 <|> (guard display >> return (mathInline ""))
637637
638638-- Int is number of embedded groupings
639−pDollarsMath :: PandocMonad m => Int -> LP m Text
639+pDollarsMath :: PandocMonad m => Int -> LP m [Tok]
640640pDollarsMath n = do
641− Tok _ toktype t <- anyTok
641+ tk@(Tok _ toktype t) <- anyTok
642642 case toktype of
643643 Symbol | t == "$"
644− , n == 0 -> return mempty
644+ , n == 0 -> return []
645645 | t == "\\" -> do
646− Tok _ _ t' <- anyTok
647− return (t <> t')
648− | t == "{" -> (t <>) <$> pDollarsMath (n+1)
646+ tk' <- anyTok
647+ ((tk :) . (tk' :)) <$> pDollarsMath n
648+ | t == "{" -> (tk :) <$> pDollarsMath (n+1)
649649 | t == "}" ->
650650 if n > 0
651− then (t <>) <$> pDollarsMath (n-1)
651+ then (tk :) <$> pDollarsMath (n-1)
652652 else mzero
653− _ -> (t <>) <$> pDollarsMath n
653+ _ -> (tk :) <$> pDollarsMath n
654654
655655-- citations
656656
test/command/5836.md+8
@@ -17,3 +17,11 @@ $\vara \varb$
1717^D
1818\(\alpha b\)
1919```
20+```
21+% pandoc -f latex -t latex
22+\newcommand{\vara}{\alpha}
23+\newcommand{\varb}{b}
24+\[\vara \varb\]
25+^D
26+\[\alpha b\]
27+```