@@ -1169,34 +1169,42 @@ code = try $ do
1169 optional whitespace >> attributes)
1169 optional whitespace >> attributes)
1170 return $ return $ B.codeWith attr $ removeLeadingTrailingSpace $ concat result
1170 return $ return $ B.codeWith attr $ removeLeadingTrailingSpace $ concat result
1172−mathWord :: Parser [Char] st String
1173−mathWord = liftM concat $ many1 mathChunk
1175−mathChunk :: Parser [Char] st String
1176−mathChunk = do char '\\'
1179− <|> many1 (satisfy $ \c -> not (isBlank c || c == '\\' || c == '$'))
1181math :: Parser [Char] ParserState (F Inlines)
1172math :: Parser [Char] ParserState (F Inlines)
1182math = (return . B.displayMath <$> (mathDisplay >>= applyMacros'))
1173math = (return . B.displayMath <$> (mathDisplay >>= applyMacros'))
1183 <|> (return . B.math <$> (mathInline >>= applyMacros'))
1174 <|> (return . B.math <$> (mathInline >>= applyMacros'))
1185mathDisplay :: Parser [Char] ParserState String
1176mathDisplay :: Parser [Char] ParserState String
1186−mathDisplay = try $ do
1177+mathDisplay =
1187− guardEnabled Ext_tex_math_dollars
1178+ (guardEnabled Ext_tex_math_dollars >> mathDisplayWith "$$" "$$")
1188− string "$$"
1179+ <|> (guardEnabled Ext_tex_math_single_backslash >>
1180+ mathDisplayWith "\\[" "\\]")
1181+ <|> (guardEnabled Ext_tex_math_double_backslash >>
1182+ mathDisplayWith "\\\\[" "\\\\]")
1184+mathDisplayWith :: String -> String -> Parser [Char] ParserState String
1185+mathDisplayWith op cl = try $ do
1189− many1Till (noneOf "\n" <|> (newline >>~ notFollowedBy' blankline)) (try $ string "$$")
1187+ many1Till (noneOf "\n" <|> (newline >>~ notFollowedBy' blankline)) (try $ string cl)
1191mathInline :: Parser [Char] ParserState String
1189mathInline :: Parser [Char] ParserState String
1192−mathInline = try $ do
1190+mathInline =
1193− guardEnabled Ext_tex_math_dollars
1191+ (guardEnabled Ext_tex_math_dollars >> mathInlineWith "$" "$")
1194− char '$'
1192+ <|> (guardEnabled Ext_tex_math_single_backslash >>
1193+ mathInlineWith "\\(" "\\)")
1194+ <|> (guardEnabled Ext_tex_math_double_backslash >>
1195+ mathInlineWith "\\\\(" "\\\\)")
1197+mathInlineWith :: String -> String -> Parser [Char] ParserState String
1198+mathInlineWith op cl = try $ do
1195 notFollowedBy space
1200 notFollowedBy space
1201+ words' <- many1Till (count 1 (noneOf "\n\\")
1202+ <|> (char '\\' >> anyChar >>= \c -> return ['\\',c])
1196− words' <- sepBy1 mathWord (many1 (spaceChar <|> (newline >>~ notFollowedBy' blankline)))
1203+ <|> count 1 newline <* notFollowedBy' blankline
1197− char '$'
1204+ *> return " ")
1198− notFollowedBy digit
1206+ notFollowedBy digit -- to prevent capture of $5
1199− return $ intercalate " " words'
1207+ return $ concat words'
1201-- to avoid performance problems, treat 4 or more _ or * or ~ or ^ in a row
1209-- to avoid performance problems, treat 4 or more _ or * or ~ or ^ in a row
1202-- as a literal rather than attempting to parse for emph/strong/strikeout/super/sub
1210-- as a literal rather than attempting to parse for emph/strong/strikeout/super/sub