diff options
| author | John MacFarlane <jgm@berkeley.edu> | 2018-05-08 09:11:39 -0700 | 
|---|---|---|
| committer | John MacFarlane <jgm@berkeley.edu> | 2018-05-08 09:11:39 -0700 | 
| commit | eb733d136577f5968a283f5d09c036a90be55677 (patch) | |
| tree | 8919a59057e336dce44131d253b2e3074653fadc | |
| parent | 0d83ce3bc4c68efa9d19f065a056d27d9b8ec56d (diff) | |
| download | pandoc-eb733d136577f5968a283f5d09c036a90be55677.tar.gz | |
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.
| -rw-r--r-- | src/Text/Pandoc/Readers/LaTeX.hs | 29 | 
1 files changed, 22 insertions, 7 deletions
| 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 | 
