git.iko.soy/typeable/pandoc
on master help sign in
Handle escaped $ in latex math. Closes #186.
328c91eJohn MacFarlane
src/Text/Pandoc/Readers/LaTeX.hs+8−2
@@ -136,6 +136,12 @@ mathDisplay p = displayMath <$> (try p >>= applyMacros' . trim)
136mathInline :: LP String -> LP Inlines
136mathInline :: LP String -> LP Inlines
137mathInline p = math <$> (try p >>= applyMacros')
137mathInline p = math <$> (try p >>= applyMacros')
138
138
139+mathChars :: LP String
140+mathChars = concat <$>
141+ many ( many1 (satisfy (\c -> c /= '$' && c /='\\'))
142+ <|> (\c -> ['\\',c]) <$> (try $ char '\\' *> anyChar)
143+ )
144+
139double_quote :: LP Inlines
145double_quote :: LP Inlines
140double_quote = (doubleQuoted . mconcat) <$>
146double_quote = (doubleQuoted . mconcat) <$>
141 (try $ string "``" *> manyTill inline (try $ string "''"))
147 (try $ string "``" *> manyTill inline (try $ string "''"))
@@ -158,8 +164,8 @@ inline = (mempty <$ comment)
158 <|> single_quote
164 <|> single_quote
159 <|> (str "’" <$ char '\'')
165 <|> (str "’" <$ char '\'')
160 <|> (str "\160" <$ char '~')
166 <|> (str "\160" <$ char '~')
161− <|> (mathDisplay $ string "$$" *> manyTill anyChar (try $ string "$$"))
167+ <|> (mathDisplay $ string "$$" *> mathChars <* string "$$")
162− <|> (mathInline $ char '$' *> manyTill anyChar (char '$'))
168+ <|> (mathInline $ char '$' *> mathChars <* char '$')
163 <|> (superscript <$> (char '^' *> tok))
169 <|> (superscript <$> (char '^' *> tok))
164 <|> (subscript <$> (char '_' *> tok))
170 <|> (subscript <$> (char '_' *> tok))
165 <|> (failUnlessLHS *> char '|' *> doLHSverb)
171 <|> (failUnlessLHS *> char '|' *> doLHSverb)