From f53fb554fe0acf88d7c697236bbd1373e78f3d83 Mon Sep 17 00:00:00 2001 From: fiddlosopher Date: Wed, 13 Aug 2008 03:02:42 +0000 Subject: Support for display math; changed ASCIIMathML -> LaTeXMathML: Resolves Issue #47. + Added a DisplayMath/InlineMath selector to Math inlines. + Markdown parser yields DisplayMath for $$...$$. + LaTeX parser yields DisplayMath when appropriate. Removed mathBlock parsers, since the same effect is achieved by the math inline parsers, now that they handle display math. + Writers handle DisplayMath as appropriate for the format. + Changed -m option to use LaTeXMathML rather than ASCIIMathML. LaTeXMathML is closer to LaTeX in its display of math, and supports many non-math LaTeX environments. + Modified HTML writer to print raw TeX when LaTeXMathML is being used instead of suppressing it. + Removed ASCIIMathML files from data/ and added LaTeXMathML. + Replaced ASCIIMathML with LaTeXMathML in source files. + Modified README and pandoc man page source. + Modified web page. + Added --latexmathml option (kept --asciimathml as a synonym for backwards compatibility) + Modified tests accordingly; added new tests for display math. git-svn-id: https://pandoc.googlecode.com/svn/trunk@1409 788f1e2b-df1e-0410-8736-df70ead52e1b --- Text/Pandoc/Readers/LaTeX.hs | 61 +++++++++++++++++------------------------ Text/Pandoc/Readers/Markdown.hs | 11 ++++++-- 2 files changed, 34 insertions(+), 38 deletions(-) (limited to 'Text/Pandoc/Readers') diff --git a/Text/Pandoc/Readers/LaTeX.hs b/Text/Pandoc/Readers/LaTeX.hs index 2ce0204ee..883c1bbd1 100644 --- a/Text/Pandoc/Readers/LaTeX.hs +++ b/Text/Pandoc/Readers/LaTeX.hs @@ -153,7 +153,6 @@ block = choice [ hrule , header , list , blockQuote - , mathBlock , comment , bibliographic , para @@ -218,26 +217,6 @@ blockQuote :: GenParser Char ParserState Block blockQuote = (environment "quote" <|> environment "quotation") >>~ spaces >>= return . BlockQuote --- --- math block --- - -mathBlock :: GenParser Char st Block -mathBlock = mathBlockWith (begin "equation") (end "equation") <|> - mathBlockWith (begin "displaymath") (end "displaymath") <|> - mathBlockWith (try $ string "\\[") (try $ string "\\]") - "math block" - -mathBlockWith :: GenParser Char st t - -> GenParser Char st end - -> GenParser Char st Block -mathBlockWith start end' = try $ do - start - spaces - result <- manyTill anyChar end' - spaces - return $ BlockQuote [Para [Math result]] - -- -- list blocks -- @@ -683,21 +662,31 @@ endline = try $ newline >> notFollowedBy blankline >> return Space -- math math :: GenParser Char st Inline -math = math1 <|> math2 "math" - -math1 :: GenParser Char st Inline -math1 = try $ do - char '$' - result <- many (noneOf "$") - char '$' - return $ Math result - -math2 :: GenParser Char st Inline -math2 = try $ do - string "\\(" - result <- many (noneOf "$") - string "\\)" - return $ Math result +math = (math3 >>= return . Math DisplayMath) + <|> (math1 >>= return . Math InlineMath) + <|> (math2 >>= return . Math InlineMath) + <|> (math4 >>= return . Math DisplayMath) + <|> (math5 >>= return . Math DisplayMath) + <|> (math6 >>= return . Math DisplayMath) + "math" + +math1 :: GenParser Char st String +math1 = try $ char '$' >> manyTill anyChar (char '$') + +math2 :: GenParser Char st String +math2 = try $ string "\\(" >> manyTill anyChar (try $ string "\\)") + +math3 :: GenParser Char st String +math3 = try $ char '$' >> math1 >>~ char '$' + +math4 :: GenParser Char st String +math4 = try $ (begin "equation") >> spaces >> manyTill anyChar (end "equation") + +math5 :: GenParser Char st String +math5 = try $ (begin "displaymath") >> spaces >> manyTill anyChar (end "displaymath") + +math6 :: GenParser Char st String +math6 = try $ (string "\\[") >> spaces >> manyTill anyChar (try $ string "\\]") -- -- links and images diff --git a/Text/Pandoc/Readers/Markdown.hs b/Text/Pandoc/Readers/Markdown.hs index ac7096d37..f030f07ad 100644 --- a/Text/Pandoc/Readers/Markdown.hs +++ b/Text/Pandoc/Readers/Markdown.hs @@ -870,14 +870,21 @@ mathWord = many1 ((noneOf " \t\n\\$") <|> (try (char '\\') >>~ notFollowedBy (char '$'))) math :: GenParser Char ParserState Inline -math = try $ do +math = (mathDisplay >>= return . Math DisplayMath) + <|> (mathInline >>= return . Math InlineMath) + +mathDisplay :: GenParser Char ParserState String +mathDisplay = try $ char '$' >> mathInline >>~ char '$' >>~ notFollowedBy digit + +mathInline :: GenParser Char ParserState String +mathInline = try $ do failIfStrict char '$' notFollowedBy space words' <- sepBy1 mathWord (many1 (spaceChar <|> (newline >>~ notFollowedBy' blankline))) char '$' notFollowedBy digit - return $ Math $ joinWithSep " " words' + return $ joinWithSep " " words' emph :: GenParser Char ParserState Inline emph = ((enclosed (char '*') (notFollowedBy' strong >> char '*') inline) <|> -- cgit v1.2.3