From d1832da9e104d61aa6ee0161aefeabf4aef9bbd2 Mon Sep 17 00:00:00 2001 From: fiddlosopher Date: Sun, 2 Dec 2007 00:36:32 +0000 Subject: Added Text.Pandoc.Readers.TeXMath and changed default handling of math. + Text.Pandoc.Readers.TeXMath exports readTeXMath, which reads raw TeX math and outputs a string of pandoc inlines that tries to render it as far as possible, lapsing into literal TeX when needed. + Added Text.Pandoc.Readers.TeXMath to pandoc.cabal + ghc66 version. + Modified writers so that readTeXMath is used for default HTMl output in HTML, S5, RTF, Docbook. + Updated README with information about how math is rendered in all formats. + Updated test suite. git-svn-id: https://pandoc.googlecode.com/svn/trunk@1129 788f1e2b-df1e-0410-8736-df70ead52e1b --- Text/Pandoc/Writers/Docbook.hs | 3 ++- Text/Pandoc/Writers/HTML.hs | 19 ++++++++++--------- Text/Pandoc/Writers/Man.hs | 5 +++-- Text/Pandoc/Writers/RST.hs | 7 ++----- Text/Pandoc/Writers/RTF.hs | 3 ++- 5 files changed, 19 insertions(+), 18 deletions(-) (limited to 'Text/Pandoc/Writers') diff --git a/Text/Pandoc/Writers/Docbook.hs b/Text/Pandoc/Writers/Docbook.hs index 2cad0ca39..f0fde18a4 100644 --- a/Text/Pandoc/Writers/Docbook.hs +++ b/Text/Pandoc/Writers/Docbook.hs @@ -30,6 +30,7 @@ Conversion of 'Pandoc' documents to Docbook XML. module Text.Pandoc.Writers.Docbook ( writeDocbook) where import Text.Pandoc.Definition import Text.Pandoc.Shared +import Text.Pandoc.Readers.TeXMath import Data.List ( isPrefixOf, drop ) import Text.PrettyPrint.HughesPJ hiding ( Str ) @@ -274,7 +275,7 @@ inlineToDocbook opts EmDash = text "—" inlineToDocbook opts EnDash = text "–" inlineToDocbook opts (Code str) = inTagsSimple "literal" $ text (escapeStringForXML str) -inlineToDocbook opts (Math str) = inlineToDocbook opts (Code str) +inlineToDocbook opts (Math str) = inlinesToDocbook opts $ readTeXMath str inlineToDocbook opts (TeX str) = empty inlineToDocbook opts (HtmlInline str) = empty inlineToDocbook opts LineBreak = text $ "" diff --git a/Text/Pandoc/Writers/HTML.hs b/Text/Pandoc/Writers/HTML.hs index 881e3c07c..70814eb15 100644 --- a/Text/Pandoc/Writers/HTML.hs +++ b/Text/Pandoc/Writers/HTML.hs @@ -32,6 +32,7 @@ import Text.Pandoc.Definition import Text.Pandoc.ASCIIMathML import Text.Pandoc.CharacterReferences ( decodeCharacterReferences ) import Text.Pandoc.Shared +import Text.Pandoc.Readers.TeXMath import Text.Regex ( mkRegex, matchRegex ) import Numeric ( showHex ) import Data.Char ( ord, toLower ) @@ -401,16 +402,16 @@ inlineToHtml opts inline = in do contents <- inlineListToHtml opts lst return $ leftQuote +++ contents +++ rightQuote (Math str) -> modify (\st -> st {stMath = True}) >> - (return $ case writerHTMLMathMethod opts of - ASCIIMathML _ -> - stringToHtml ("$" ++ str ++ "$") - MimeTeX url -> - image ! [src (url ++ "?" ++ str), + (case writerHTMLMathMethod opts of + ASCIIMathML _ -> + return $ stringToHtml ("$" ++ str ++ "$") + MimeTeX url -> + return $ image ! [src (url ++ "?" ++ str), alt str, title str] - GladTeX -> - tag "eq" << str - PlainMath -> - stringToHtml str) + GladTeX -> + return $ tag "eq" << str + PlainMath -> + inlineListToHtml opts (readTeXMath str)) (TeX str) -> return noHtml (HtmlInline str) -> return $ primHtml str (Link [Code str] (src,tit)) | "mailto:" `isPrefixOf` src -> diff --git a/Text/Pandoc/Writers/Man.hs b/Text/Pandoc/Writers/Man.hs index 899cd9f57..bd170f6ba 100644 --- a/Text/Pandoc/Writers/Man.hs +++ b/Text/Pandoc/Writers/Man.hs @@ -30,7 +30,8 @@ Conversion of 'Pandoc' documents to groff man page format. -} module Text.Pandoc.Writers.Man ( writeMan) where import Text.Pandoc.Definition -import Text.Pandoc.Shared +import Text.Pandoc.Shared +import Text.Pandoc.Readers.TeXMath import Text.Printf ( printf ) import Data.List ( isPrefixOf, drop, nub, intersperse ) import Text.PrettyPrint.HughesPJ hiding ( Str ) @@ -268,7 +269,7 @@ inlineToMan opts Ellipses = return $ text "\\&..." inlineToMan opts (Code str) = return $ text $ "\\f[B]" ++ escapeCode str ++ "\\f[]" inlineToMan opts (Str str) = return $ text $ escapeString str -inlineToMan opts (Math str) = return $ text $ escapeCode str +inlineToMan opts (Math str) = inlineToMan opts (Code str) inlineToMan opts (TeX str) = return empty inlineToMan opts (HtmlInline str) = return $ text $ escapeCode str inlineToMan opts (LineBreak) = return $ text "\n.PD 0\n.P\n.PD\n" diff --git a/Text/Pandoc/Writers/RST.hs b/Text/Pandoc/Writers/RST.hs index 4a7242d1f..7dd99f2ea 100644 --- a/Text/Pandoc/Writers/RST.hs +++ b/Text/Pandoc/Writers/RST.hs @@ -32,6 +32,7 @@ reStructuredText: module Text.Pandoc.Writers.RST ( writeRST) where import Text.Pandoc.Definition import Text.Pandoc.Shared +import Text.Pandoc.Readers.TeXMath import Text.Pandoc.Blocks import Data.List ( isPrefixOf, isSuffixOf, drop, intersperse ) import Text.PrettyPrint.HughesPJ hiding ( Str ) @@ -151,10 +152,6 @@ blockToRST :: WriterOptions -- ^ Options -> State WriterState Doc blockToRST opts Null = return empty blockToRST opts (Plain inlines) = wrappedRST opts inlines -blockToRST opts (Para [Math str]) = - let str' = if "\n" `isSuffixOf` str then str ++ "\n" else str ++ "\n\n" in - return $ hang (text "\n.. raw:: latex\n") 3 $ text "\\[" <> - (vcat $ map text (lines str')) <> text "\\]" blockToRST opts (Para inlines) = do contents <- wrappedRST opts inlines return $ contents <> text "\n" @@ -286,7 +283,7 @@ inlineToRST opts Apostrophe = return $ char '\'' inlineToRST opts Ellipses = return $ text "..." inlineToRST opts (Code str) = return $ text $ "``" ++ str ++ "``" inlineToRST opts (Str str) = return $ text $ escapeString str -inlineToRST opts (Math str) = return $ char '$' <> text str <> char '$' +inlineToRST opts (Math str) = return $ text $ "$" ++ str ++ "$" inlineToRST opts (TeX str) = return empty inlineToRST opts (HtmlInline str) = return empty inlineToRST opts (LineBreak) = return $ char ' ' -- RST doesn't have linebreaks diff --git a/Text/Pandoc/Writers/RTF.hs b/Text/Pandoc/Writers/RTF.hs index 9c5e6cbd3..64d73a30f 100644 --- a/Text/Pandoc/Writers/RTF.hs +++ b/Text/Pandoc/Writers/RTF.hs @@ -30,6 +30,7 @@ Conversion of 'Pandoc' documents to RTF (rich text format). module Text.Pandoc.Writers.RTF ( writeRTF ) where import Text.Pandoc.Definition import Text.Pandoc.Shared +import Text.Pandoc.Readers.TeXMath import Text.Regex ( matchRegexAll, mkRegex ) import Data.List ( isSuffixOf ) import Data.Char ( ord ) @@ -272,7 +273,7 @@ inlineToRTF EmDash = "\\u8212-" inlineToRTF EnDash = "\\u8211-" inlineToRTF (Code str) = "{\\f1 " ++ (codeStringToRTF str) ++ "} " inlineToRTF (Str str) = stringToRTF str -inlineToRTF (Math str) = latexToRTF str +inlineToRTF (Math str) = inlineListToRTF $ readTeXMath str inlineToRTF (TeX str) = "" inlineToRTF (HtmlInline str) = "" inlineToRTF (LineBreak) = "\\line " -- cgit v1.2.3