From 57a91f3b6add303ef70aa29a14a8c67123ec7c0f Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Thu, 15 Jul 2010 19:01:00 -0700 Subject: Added --webtex option for HTML math. + Added --webtex command-line option, with optional parameter. (Defaults to using google charts API.) + Added WebTeX HTMLMathMethod. + Removed MimeTeX HTMLMathMethod. (WebTeX is generic and subsumes it.) + Modified --mimetex option to use WebTeX. + Thanks to lpeterse for the idea and some of the code. --- src/Text/Pandoc/Shared.hs | 2 +- src/Text/Pandoc/Writers/HTML.hs | 39 +++++++++++++++++++++++---------------- 2 files changed, 24 insertions(+), 17 deletions(-) (limited to 'src/Text') diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs index ac1cf7373..b8eb14177 100644 --- a/src/Text/Pandoc/Shared.hs +++ b/src/Text/Pandoc/Shared.hs @@ -457,7 +457,7 @@ data HTMLMathMethod = PlainMath | LaTeXMathML (Maybe String) -- url of LaTeXMathML.js | JsMath (Maybe String) -- url of jsMath load script | GladTeX - | MimeTeX String -- url of mimetex.cgi + | WebTeX String -- url of TeX->image script. | MathML (Maybe String) -- url of MathMLinHTML.js deriving (Show, Read, Eq) diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs index 3f9a417d2..20022e182 100644 --- a/src/Text/Pandoc/Writers/HTML.hs +++ b/src/Text/Pandoc/Writers/HTML.hs @@ -36,6 +36,7 @@ import Text.Pandoc.Templates import Text.Pandoc.Readers.TeXMath import Text.Pandoc.Highlighting ( highlightHtml ) import Text.Pandoc.XML (stripTags, escapeStringForXML) +import Network.HTTP ( urlEncode ) import Numeric ( showHex ) import Data.Char ( ord, toLower ) import Data.List ( isPrefixOf, intersperse ) @@ -462,16 +463,20 @@ inlineToHtml opts inline = -- non-math elements on the page from being treated as math by -- the javascript return $ thespan ! [theclass "LaTeX"] $ - if t == InlineMath - then primHtml ("$" ++ str ++ "$") - else primHtml ("$$" ++ str ++ "$$") - JsMath _ -> - return $ if t == InlineMath - then thespan ! [theclass "math"] $ primHtml str - else thediv ! [theclass "math"] $ primHtml str - MimeTeX url -> - return $ image ! [src (url ++ "?" ++ str), - alt str, title str] + case t of + InlineMath -> primHtml ("$" ++ str ++ "$") + DisplayMath -> primHtml ("$$" ++ str ++ "$$") + JsMath _ -> do + let m = primHtml str + return $ case t of + InlineMath -> thespan ! [theclass "math"] $ m + DisplayMath -> thediv ! [theclass "math"] $ m + WebTeX url -> do + let m = image ! [src (url ++ urlEncode str), + alt str, title str] + return $ case t of + InlineMath -> m + DisplayMath -> br +++ m +++ br GladTeX -> return $ primHtml $ "" ++ str ++ "" MathML _ -> do @@ -484,12 +489,14 @@ inlineToHtml opts inline = Right r -> return $ primHtml $ ppcElement conf r Left _ -> inlineListToHtml opts - (readTeXMath str) >>= - return . (thespan ! - [theclass "math"]) - PlainMath -> - inlineListToHtml opts (readTeXMath str) >>= - return . (thespan ! [theclass "math"]) ) + (readTeXMath str) >>= return . + (thespan ! [theclass "math"]) + PlainMath -> do + x <- inlineListToHtml opts (readTeXMath str) + let m = thespan ! [theclass "math"] $ x + return $ case t of + InlineMath -> m + DisplayMath -> br +++ m +++ br ) (TeX str) -> case writerHTMLMathMethod opts of LaTeXMathML _ -> do modify (\st -> st {stMath = True}) return $ primHtml str -- cgit v1.2.3