From 328c91e3071f34f798f472661469b561468713ed Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Tue, 7 Feb 2012 19:40:26 -0800 Subject: Handle escaped $ in latex math. Closes #186. --- src/Text/Pandoc/Readers/LaTeX.hs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs index fb0bc34e8..2240a008d 100644 --- a/src/Text/Pandoc/Readers/LaTeX.hs +++ b/src/Text/Pandoc/Readers/LaTeX.hs @@ -136,6 +136,12 @@ mathDisplay p = displayMath <$> (try p >>= applyMacros' . trim) mathInline :: LP String -> LP Inlines mathInline p = math <$> (try p >>= applyMacros') +mathChars :: LP String +mathChars = concat <$> + many ( many1 (satisfy (\c -> c /= '$' && c /='\\')) + <|> (\c -> ['\\',c]) <$> (try $ char '\\' *> anyChar) + ) + double_quote :: LP Inlines double_quote = (doubleQuoted . mconcat) <$> (try $ string "``" *> manyTill inline (try $ string "''")) @@ -158,8 +164,8 @@ inline = (mempty <$ comment) <|> single_quote <|> (str "’" <$ char '\'') <|> (str "\160" <$ char '~') - <|> (mathDisplay $ string "$$" *> manyTill anyChar (try $ string "$$")) - <|> (mathInline $ char '$' *> manyTill anyChar (char '$')) + <|> (mathDisplay $ string "$$" *> mathChars <* string "$$") + <|> (mathInline $ char '$' *> mathChars <* char '$') <|> (superscript <$> (char '^' *> tok)) <|> (subscript <$> (char '_' *> tok)) <|> (failUnlessLHS *> char '|' *> doLHSverb) -- cgit v1.2.3