Skip to content

Commit

Permalink
LaTeX reader: handle $ in /text{..} inside math.
Browse files Browse the repository at this point in the history
This fixes the main problem in #4576.
There is still an issue about `\SI`, but that's a separate issue.
  • Loading branch information
jgm committed May 8, 2018
1 parent 0d83ce3 commit eb733d1
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/Text/Pandoc/Readers/LaTeX.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit eb733d1

Please sign in to comment.