@@ -48,6 +48,8 @@ module Text.Pandoc.Parsing ( (>>~),
48 romanNumeral,
48 romanNumeral,
49 emailAddress,
49 emailAddress,
51 withHorizDisplacement,
53 withHorizDisplacement,
@@ -455,6 +457,39 @@ uri = try $ do
455 let uri' = scheme ++ ":" ++ fromEntities str'
457 let uri' = scheme ++ ":" ++ fromEntities str'
456 return (uri', escapeURI uri')
458 return (uri', escapeURI uri')
460+mathInlineWith :: String -> String -> Parser [Char] st String
461+mathInlineWith op cl = try $ do
464+ words' <- many1Till (count 1 (noneOf "\n\\")
465+ <|> (char '\\' >> anyChar >>= \c -> return ['\\',c])
466+ <|> count 1 newline <* notFollowedBy' blankline
469+ notFollowedBy digit -- to prevent capture of $5
470+ return $ concat words'
472+mathDisplayWith :: String -> String -> Parser [Char] st String
473+mathDisplayWith op cl = try $ do
475+ many1Till (noneOf "\n" <|> (newline >>~ notFollowedBy' blankline)) (try $ string cl)
477+mathDisplay :: Parser [Char] ParserState String
479+ (guardEnabled Ext_tex_math_dollars >> mathDisplayWith "$$" "$$")
480+ <|> (guardEnabled Ext_tex_math_single_backslash >>
481+ mathDisplayWith "\\[" "\\]")
482+ <|> (guardEnabled Ext_tex_math_double_backslash >>
483+ mathDisplayWith "\\\\[" "\\\\]")
485+mathInline :: Parser [Char] ParserState String
487+ (guardEnabled Ext_tex_math_dollars >> mathInlineWith "$" "$")
488+ <|> (guardEnabled Ext_tex_math_single_backslash >>
489+ mathInlineWith "\\(" "\\)")
490+ <|> (guardEnabled Ext_tex_math_double_backslash >>
491+ mathInlineWith "\\\\(" "\\\\)")
458-- | Applies a parser, returns tuple of its results and its horizontal
493-- | Applies a parser, returns tuple of its results and its horizontal
459-- displacement (the difference between the source column at the end
494-- displacement (the difference between the source column at the end
460-- and the source column at the beginning). Vertical displacement
495-- and the source column at the beginning). Vertical displacement