@@ -136,6 +136,12 @@ mathDisplay p = displayMath <$> (try p >>= applyMacros' . trim)
136136mathInline :: LP String -> LP Inlines
137137mathInline p = math <$> (try p >>= applyMacros')
138138
139+mathChars :: LP String
140+mathChars = concat <$>
141+ many ( many1 (satisfy (\c -> c /= '$' && c /='\\'))
142+ <|> (\c -> ['\\',c]) <$> (try $ char '\\' *> anyChar)
143+ )
144+
139145double_quote :: LP Inlines
140146double_quote = (doubleQuoted . mconcat) <$>
141147 (try $ string "``" *> manyTill inline (try $ string "''"))
@@ -158,8 +164,8 @@ inline = (mempty <$ comment)
158164 <|> single_quote
159165 <|> (str "’" <$ char '\'')
160166 <|> (str "\160" <$ char '~')
161− <|> (mathDisplay $ string "$$" *> manyTill anyChar (try $ string "$$"))
162− <|> (mathInline $ char '$' *> manyTill anyChar (char '$'))
167+ <|> (mathDisplay $ string "$$" *> mathChars <* string "$$")
168+ <|> (mathInline $ char '$' *> mathChars <* char '$')
163169 <|> (superscript <$> (char '^' *> tok))
164170 <|> (subscript <$> (char '_' *> tok))
165171 <|> (failUnlessLHS *> char '|' *> doLHSverb)