diff --git a/README b/README index ebaa899fa..7b02fb91f 100644 --- a/README +++ b/README @@ -329,6 +329,11 @@ For further documentation, see the `pandoc(1)` man page. `--gladtex`, and `--mimetex` for alternative ways of dealing with math in HTML.) +`--mathml` +: causes `pandoc` to convert all TeX math to MathML. + In standalone mode, a small javascript will be inserted that allows + the MathML to be viewed on some browsers. + `--jsmath`*=[url]* : causes `pandoc` to use the [jsMath] script to display TeX math in HTML or S5. The *url* should point to the jsMath load diff --git a/data/LaTeXMathML.js.packed b/data/LaTeXMathML.js similarity index 99% rename from data/LaTeXMathML.js.packed rename to data/LaTeXMathML.js index 472e26f91..4957624de 100644 --- a/data/LaTeXMathML.js.packed +++ b/data/LaTeXMathML.js @@ -1,4 +1,11 @@ - +/* +LaTeXMathML.js from http://math.etsu.edu/LaTeXMathML/ +Adapted by Jeff Knisely and Douglas Woodall from ASCIIMathML.js v. 1.4.7, +(c) 2005 Peter Jipsen http://www.chapman.edu/~jipsen. +Released under the GNU General Public License version 2 or later. +See the GNU General Public License (at http://www.gnu.org/copyleft/gpl.html) +for more details. +*/ var checkForMathML=true;var notifyIfNoMathML=true;var alertIfNoMathML=false;var mathcolor="";var mathfontfamily="";var showasciiformulaonhover=true;var isIE=document.createElementNS==null;if(document.getElementById==null) alert("This webpage requires a recent browser such as \nMozilla/Netscape 7+ or Internet Explorer 6+MathPlayer") function AMcreateElementXHTML(t){if(isIE)return document.createElement(t);else return document.createElementNS("http://www.w3.org/1999/xhtml",t);} diff --git a/data/LaTeXMathML.js.comment b/data/LaTeXMathML.js.comment deleted file mode 100644 index fc60b1f74..000000000 --- a/data/LaTeXMathML.js.comment +++ /dev/null @@ -1,16 +0,0 @@ -/* -LaTeXMathML.js from http://math.etsu.edu/LaTeXMathML/ -Adapted by Jeff Knisely and Douglas Woodall from ASCIIMathML.js v. 1.4.7, -(c) 2005 Peter Jipsen http://www.chapman.edu/~jipsen. - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or (at -your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License (at http://www.gnu.org/copyleft/gpl.html) -for more details. -*/ diff --git a/data/MathMLinHTML.js b/data/MathMLinHTML.js new file mode 100644 index 000000000..ad718cf7e --- /dev/null +++ b/data/MathMLinHTML.js @@ -0,0 +1,70 @@ +/* +March 19, 2004 MathHTML (c) Peter Jipsen http://www.chapman.edu/~jipsen +Released under the GNU General Public License version 2 or later. +See the GNU General Public License (at http://www.gnu.org/copyleft/gpl.html) +for more details. +*/ + +function convertMath(node) {// for Gecko + if (node.nodeType==1) { + var newnode = + document.createElementNS("http://www.w3.org/1998/Math/MathML", + node.nodeName.toLowerCase()); + for(var i=0; i < node.attributes.length; i++) + newnode.setAttribute(node.attributes[i].nodeName, + node.attributes[i].nodeValue); + for (var i=0; i"); + document.write(""); +} +if(typeof window.addEventListener != 'undefined'){ + window.addEventListener('load', convert, false); +} +if(typeof window.attachEvent != 'undefined') { + window.attachEvent('onload', convert); +} diff --git a/man/man1/pandoc.1.md b/man/man1/pandoc.1.md index 10a2581dc..ac6f633e7 100644 --- a/man/man1/pandoc.1.md +++ b/man/man1/pandoc.1.md @@ -118,6 +118,10 @@ should pipe input and output through `iconv`: provide a *URL*. If no *URL* is provided, the contents of the script will be inserted directly into the HTML header. +\--mathml +: Convert TeX math to MathML. In standalone mode, a small javascript + will be inserted that allows the MathML to be viewed on some browsers. + \--jsmath=*URL* : Use jsMath to display embedded TeX math in HTML output. The *URL* should point to the jsMath load script; if provided, diff --git a/pandoc.cabal b/pandoc.cabal index fefca87aa..6d8b95fe3 100644 --- a/pandoc.cabal +++ b/pandoc.cabal @@ -45,8 +45,8 @@ Data-Files: -- data for ODT writer reference.odt, -- data for LaTeXMathML writer - data/LaTeXMathML.js.comment, - data/LaTeXMathML.js.packed, + data/LaTeXMathML.js, + data/MathMLinHTML.js, -- data for S5 writer s5/default/slides.js.comment, s5/default/slides.js.packed, @@ -144,7 +144,7 @@ Library process >= 1, directory >= 1, bytestring >= 0.9, zip-archive >= 0.1.1.4, utf8-string >= 0.3, old-time >= 1, - HTTP >= 4000.0.5 + HTTP >= 4000.0.5, texmath, xml >= 1.3.5 && < 1.4 if impl(ghc >= 6.10) Build-depends: base >= 4 && < 5, syb else @@ -163,7 +163,6 @@ Library Text.Pandoc.CharacterReferences, Text.Pandoc.Shared, Text.Pandoc.ODT, - Text.Pandoc.LaTeXMathML, Text.Pandoc.Highlighting, Text.Pandoc.Readers.HTML, Text.Pandoc.Readers.LaTeX, diff --git a/src/Text/Pandoc/LaTeXMathML.hs b/src/Text/Pandoc/LaTeXMathML.hs deleted file mode 100644 index 0c8f74bdf..000000000 --- a/src/Text/Pandoc/LaTeXMathML.hs +++ /dev/null @@ -1,13 +0,0 @@ --- | Definitions for use of LaTeXMathML in HTML. --- (See ) -module Text.Pandoc.LaTeXMathML ( latexMathMLScript ) where -import System.FilePath ( () ) -import Text.Pandoc.Shared (readDataFile) - --- | String containing LaTeXMathML javascript. -latexMathMLScript :: Maybe FilePath -> IO String -latexMathMLScript datadir = do - jsCom <- readDataFile datadir $ "data" "LaTeXMathML.js.comment" - jsPacked <- readDataFile datadir $ "data" "LaTeXMathML.js.packed" - return $ "\n" diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs index a27a2c907..f093ddbee 100644 --- a/src/Text/Pandoc/Shared.hs +++ b/src/Text/Pandoc/Shared.hs @@ -979,6 +979,7 @@ data HTMLMathMethod = PlainMath | JsMath (Maybe String) -- url of jsMath load script | GladTeX | MimeTeX String -- url of mimetex.cgi + | MathML (Maybe String) -- url of MathMLinHTML.js deriving (Show, Read, Eq) -- | Methods for obfuscating email addresses in HTML. diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs index 020edea65..ddffa471b 100644 --- a/src/Text/Pandoc/Writers/HTML.hs +++ b/src/Text/Pandoc/Writers/HTML.hs @@ -42,6 +42,8 @@ import Data.List ( isPrefixOf, intersperse ) import Data.Maybe ( catMaybes ) import Control.Monad.State import Text.XHtml.Transitional hiding ( stringToHtml ) +import Text.TeXMath +import Text.XML.Light.Output data WriterState = WriterState { stNotes :: [Html] -- ^ List of notes @@ -111,17 +113,20 @@ pandocToHtml opts (Pandoc (Meta title' authors' date') blocks) = do LaTeXMathML (Just url) -> script ! [src url, thetype "text/javascript"] $ noHtml + MathML (Just url) -> + script ! + [src url, thetype "text/javascript"] $ noHtml JsMath (Just url) -> script ! [src url, thetype "text/javascript"] $ noHtml - _ -> case lookup "latexmathml-script" (writerVariables opts) of + _ -> case lookup "mathml-script" (writerVariables opts) of Just s -> script ! [thetype "text/javascript"] << primHtml s Nothing -> noHtml else noHtml let newvars = [("highlighting","yes") | stHighlighting st] ++ - [("math", renderHtmlFragment math) | stMath st] + [("math", renderHtmlFragment math) | stMath st] return (tit, auths, date, toc, thebody, newvars) inTemplate :: TemplateTarget a @@ -450,6 +455,17 @@ inlineToHtml opts inline = alt str, title str] GladTeX -> return $ primHtml $ "" ++ str ++ "" + MathML _ -> do + let dt = if t == InlineMath + then DisplayInline + else DisplayBlock + let conf = useShortEmptyTags (const False) + defaultConfigPP + case texMathToMathML dt str of + Right r -> return $ primHtml $ + ppcElement conf r + Left _ -> inlineToHtml opts + (Math t str) PlainMath -> inlineListToHtml opts (readTeXMath str) >>= return . (thespan ! [theclass "math"]) ) diff --git a/src/pandoc.hs b/src/pandoc.hs index cd2768bfc..e959baba1 100644 --- a/src/pandoc.hs +++ b/src/pandoc.hs @@ -32,8 +32,7 @@ module Main where import Text.Pandoc import Text.Pandoc.ODT import Text.Pandoc.Writers.S5 (s5HeaderIncludes) -import Text.Pandoc.LaTeXMathML (latexMathMLScript) -import Text.Pandoc.Shared ( tabFilter, ObfuscationMethod (..) ) +import Text.Pandoc.Shared ( tabFilter, ObfuscationMethod (..), readDataFile ) #ifdef _HIGHLIGHTING import Text.Pandoc.Highlighting ( languages ) #endif @@ -287,6 +286,13 @@ options = "URL") "" -- "Use LaTeXMathML script in html output" + , Option "" ["mathml"] + (OptArg + (\arg opt -> + return opt { optHTMLMathMethod = MathML arg }) + "URL") + "" -- "Use mathml for HTML math" + , Option "" ["mimetex"] (OptArg (\arg opt -> return opt { optHTMLMathMethod = MimeTeX @@ -709,8 +715,11 @@ main = do variables'' <- case mathMethod of LaTeXMathML Nothing -> do - s <- latexMathMLScript datadir - return $ ("latexmathml-script", s) : variables' + s <- readDataFile datadir $ "data" "LaTeXMathML.js" + return $ ("mathml-script", s) : variables' + MathML Nothing -> do + s <- readDataFile datadir $ "data""MathMLinHTML.js" + return $ ("mathml-script", s) : variables' _ -> return variables' let startParserState = diff --git a/templates/html.template b/templates/html.template index 8d1fafd36..820279939 100644 --- a/templates/html.template +++ b/templates/html.template @@ -33,12 +33,12 @@ $endif$ $for(css)$ $endfor$ +$if(math)$ + $math$ +$endif$ $for(header-includes)$ $header-includes$ $endfor$ -$if(latexmathml-script)$ - $latexmathml-script$ -$endif$ $if(title)$ diff --git a/tests/s5.fancy.html b/tests/s5.fancy.html index 42a6aaf8a..1379c3e2e 100644 --- a/tests/s5.fancy.html +++ b/tests/s5.fancy.html @@ -7,6 +7,207 @@ + @@ -268,215 +469,6 @@ document.onkeyup=keys;document.onkeypress=trap;document.onclick=clicker;}} window.onload=startup;window.onresize=function(){setTimeout('fontScale()',50);} -

My S5 Document