git.iko.soy/typeable/pandoc
on master help sign in
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.

commiteb733d136577f5968a283f5d09c036a90be55677 authorJohn MacFarlane <jgm@berkeley.edu> dateTue 8 May 2018, 09:11 (8 years ago) parent0d83ce3
1 file changed+22−7
src/Text/Pandoc/Readers/LaTeX.hs+22−7
src/Text/Pandoc/Readers/LaTeX.hs+22−7
@@ -1053,13 +1053,28 @@ dollarsMath :: PandocMonad m => LP m Inlines
10531053dollarsMath = do
10541054 symbol '$'
10551055 display <- option False (True <$ symbol '$')
1056− contents <- trim . toksToString <$>
1057− many (notFollowedBy (symbol '$') >> anyTok)
1058− if display
1059− then
1060− mathDisplay contents <$ try (symbol '$' >> symbol '$')
1061− <|> (guard (null contents) >> return (mathInline ""))
1062− else mathInline contents <$ symbol '$'
1056+ (do contents <- try $ T.unpack <$> pDollarsMath 0
1057+ if display
1058+ then (mathDisplay contents <$ symbol '$')
1059+ else return $ mathInline contents)
1060+ <|> (guard display >> return (mathInline ""))
1061+
1062+-- Int is number of embedded groupings
1063+pDollarsMath :: PandocMonad m => Int -> LP m Text
1064+pDollarsMath n = do
1065+ Tok _ toktype t <- anyTok
1066+ case toktype of
1067+ Symbol | t == "$"
1068+ , n == 0 -> return mempty
1069+ | t == "\\" -> do
1070+ Tok _ _ t' <- anyTok
1071+ return (t <> t')
1072+ | t == "{" -> (t <>) <$> pDollarsMath (n+1)
1073+ | t == "}" ->
1074+ if n > 0
1075+ then (t <>) <$> pDollarsMath (n-1)
1076+ else mzero
1077+ _ -> (t <>) <$> pDollarsMath n
10631078
10641079-- citations
10651080