From eb733d136577f5968a283f5d09c036a90be55677 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Tue, 8 May 2018 09:11:39 -0700 Subject: LaTeX reader: handle `$` in `/text{..}` inside math. This fixes the main problem in #4576. There is still an issue about `\SI`, but that's a separate issue. --- src/Text/Pandoc/Readers/LaTeX.hs | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'src/Text/Pandoc') diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs index 041b552dc..39dffde76 100644 --- a/src/Text/Pandoc/Readers/LaTeX.hs +++ b/src/Text/Pandoc/Readers/LaTeX.hs @@ -1053,13 +1053,28 @@ dollarsMath :: PandocMonad m => LP m Inlines dollarsMath = do symbol '$' display <- option False (True <$ symbol '$') - contents <- trim . toksToString <$> - many (notFollowedBy (symbol '$') >> anyTok) - if display - then - mathDisplay contents <$ try (symbol '$' >> symbol '$') - <|> (guard (null contents) >> return (mathInline "")) - else mathInline contents <$ symbol '$' + (do contents <- try $ T.unpack <$> pDollarsMath 0 + if display + then (mathDisplay contents <$ symbol '$') + else return $ mathInline contents) + <|> (guard display >> return (mathInline "")) + +-- Int is number of embedded groupings +pDollarsMath :: PandocMonad m => Int -> LP m Text +pDollarsMath n = do + Tok _ toktype t <- anyTok + case toktype of + Symbol | t == "$" + , n == 0 -> return mempty + | t == "\\" -> do + Tok _ _ t' <- anyTok + return (t <> t') + | t == "{" -> (t <>) <$> pDollarsMath (n+1) + | t == "}" -> + if n > 0 + then (t <>) <$> pDollarsMath (n-1) + else mzero + _ -> (t <>) <$> pDollarsMath n -- citations -- cgit v1.2.3