Added --mathml option; removed Text.Pandoc.LaTeXMathML.
* Added data/MathMLinHTML.js, which is included when no URL is provided for --mathml. This allows MathML to be displayed in better browsers, as text/html. * The module was no longer necessary; its functionality (two lines) was incorporated into pandoc.hs. * Consolidated the two LaTeXMathML.js files into one. git-svn-id: https://pandoc.googlecode.com/svn/trunk@1909 788f1e2b-df1e-0410-8736-df70ead52e1b
This commit is contained in:
parent
d704f47b86
commit
56217f1004
12 changed files with 326 additions and 252 deletions
5
README
5
README
|
@ -329,6 +329,11 @@ For further documentation, see the `pandoc(1)` man page.
|
||||||
`--gladtex`, and `--mimetex` for alternative ways of dealing with
|
`--gladtex`, and `--mimetex` for alternative ways of dealing with
|
||||||
math in HTML.)
|
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]*
|
`--jsmath`*=[url]*
|
||||||
: causes `pandoc` to use the [jsMath] script to display
|
: causes `pandoc` to use the [jsMath] script to display
|
||||||
TeX math in HTML or S5. The *url* should point to the jsMath load
|
TeX math in HTML or S5. The *url* should point to the jsMath load
|
||||||
|
|
|
@ -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)
|
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")
|
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);}
|
function AMcreateElementXHTML(t){if(isIE)return document.createElement(t);else return document.createElementNS("http://www.w3.org/1999/xhtml",t);}
|
|
@ -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.
|
|
||||||
*/
|
|
70
data/MathMLinHTML.js
Normal file
70
data/MathMLinHTML.js
Normal file
|
@ -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<node.childNodes.length; i++) {
|
||||||
|
var st = node.childNodes[i].nodeValue;
|
||||||
|
if (st==null || st.slice(0,1)!=" " && st.slice(0,1)!="\n")
|
||||||
|
newnode.appendChild(convertMath(node.childNodes[i]));
|
||||||
|
}
|
||||||
|
return newnode;
|
||||||
|
}
|
||||||
|
else return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
function convert() {
|
||||||
|
var mmlnode = document.getElementsByTagName("math");
|
||||||
|
var st,str,node,newnode;
|
||||||
|
for (var i=0; i<mmlnode.length; i++)
|
||||||
|
if (document.createElementNS!=null)
|
||||||
|
mmlnode[i].parentNode.replaceChild(convertMath(mmlnode[i]),mmlnode[i]);
|
||||||
|
else { // convert for IE
|
||||||
|
str = "";
|
||||||
|
node = mmlnode[i];
|
||||||
|
while (node.nodeName!="/MATH") {
|
||||||
|
st = node.nodeName.toLowerCase();
|
||||||
|
if (st=="#text") str += node.nodeValue;
|
||||||
|
else {
|
||||||
|
str += (st.slice(0,1)=="/" ? "</m:"+st.slice(1) : "<m:"+st);
|
||||||
|
if (st.slice(0,1)!="/")
|
||||||
|
for(var j=0; j < node.attributes.length; j++)
|
||||||
|
if (node.attributes[j].nodeValue!="italic" &&
|
||||||
|
node.attributes[j].nodeValue!="" &&
|
||||||
|
node.attributes[j].nodeValue!="inherit" &&
|
||||||
|
node.attributes[j].nodeValue!=undefined)
|
||||||
|
str += " "+node.attributes[j].nodeName+"="+
|
||||||
|
"\""+node.attributes[j].nodeValue+"\"";
|
||||||
|
str += ">";
|
||||||
|
}
|
||||||
|
node = node.nextSibling;
|
||||||
|
node.parentNode.removeChild(node.previousSibling);
|
||||||
|
}
|
||||||
|
str += "</m:math>";
|
||||||
|
newnode = document.createElement("span");
|
||||||
|
node.parentNode.replaceChild(newnode,node);
|
||||||
|
newnode.innerHTML = str;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (document.createElementNS==null) {
|
||||||
|
document.write("<object id=\"mathplayer\"\
|
||||||
|
classid=\"clsid:32F66A20-7614-11D4-BD11-00104BD3F987\"></object>");
|
||||||
|
document.write("<?import namespace=\"m\" implementation=\"#mathplayer\"?>");
|
||||||
|
}
|
||||||
|
if(typeof window.addEventListener != 'undefined'){
|
||||||
|
window.addEventListener('load', convert, false);
|
||||||
|
}
|
||||||
|
if(typeof window.attachEvent != 'undefined') {
|
||||||
|
window.attachEvent('onload', convert);
|
||||||
|
}
|
|
@ -118,6 +118,10 @@ should pipe input and output through `iconv`:
|
||||||
provide a *URL*. If no *URL* is provided, the contents of the
|
provide a *URL*. If no *URL* is provided, the contents of the
|
||||||
script will be inserted directly into the HTML header.
|
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*
|
\--jsmath=*URL*
|
||||||
: Use jsMath to display embedded TeX math in HTML output.
|
: Use jsMath to display embedded TeX math in HTML output.
|
||||||
The *URL* should point to the jsMath load script; if provided,
|
The *URL* should point to the jsMath load script; if provided,
|
||||||
|
|
|
@ -45,8 +45,8 @@ Data-Files:
|
||||||
-- data for ODT writer
|
-- data for ODT writer
|
||||||
reference.odt,
|
reference.odt,
|
||||||
-- data for LaTeXMathML writer
|
-- data for LaTeXMathML writer
|
||||||
data/LaTeXMathML.js.comment,
|
data/LaTeXMathML.js,
|
||||||
data/LaTeXMathML.js.packed,
|
data/MathMLinHTML.js,
|
||||||
-- data for S5 writer
|
-- data for S5 writer
|
||||||
s5/default/slides.js.comment,
|
s5/default/slides.js.comment,
|
||||||
s5/default/slides.js.packed,
|
s5/default/slides.js.packed,
|
||||||
|
@ -144,7 +144,7 @@ Library
|
||||||
process >= 1, directory >= 1,
|
process >= 1, directory >= 1,
|
||||||
bytestring >= 0.9, zip-archive >= 0.1.1.4,
|
bytestring >= 0.9, zip-archive >= 0.1.1.4,
|
||||||
utf8-string >= 0.3, old-time >= 1,
|
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)
|
if impl(ghc >= 6.10)
|
||||||
Build-depends: base >= 4 && < 5, syb
|
Build-depends: base >= 4 && < 5, syb
|
||||||
else
|
else
|
||||||
|
@ -163,7 +163,6 @@ Library
|
||||||
Text.Pandoc.CharacterReferences,
|
Text.Pandoc.CharacterReferences,
|
||||||
Text.Pandoc.Shared,
|
Text.Pandoc.Shared,
|
||||||
Text.Pandoc.ODT,
|
Text.Pandoc.ODT,
|
||||||
Text.Pandoc.LaTeXMathML,
|
|
||||||
Text.Pandoc.Highlighting,
|
Text.Pandoc.Highlighting,
|
||||||
Text.Pandoc.Readers.HTML,
|
Text.Pandoc.Readers.HTML,
|
||||||
Text.Pandoc.Readers.LaTeX,
|
Text.Pandoc.Readers.LaTeX,
|
||||||
|
|
|
@ -1,13 +0,0 @@
|
||||||
-- | Definitions for use of LaTeXMathML in HTML.
|
|
||||||
-- (See <http://math.etsu.edu/LaTeXMathML/>)
|
|
||||||
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 $ "<script type=\"text/javascript\">\n" ++ jsCom ++ jsPacked ++
|
|
||||||
"</script>\n"
|
|
|
@ -979,6 +979,7 @@ data HTMLMathMethod = PlainMath
|
||||||
| JsMath (Maybe String) -- url of jsMath load script
|
| JsMath (Maybe String) -- url of jsMath load script
|
||||||
| GladTeX
|
| GladTeX
|
||||||
| MimeTeX String -- url of mimetex.cgi
|
| MimeTeX String -- url of mimetex.cgi
|
||||||
|
| MathML (Maybe String) -- url of MathMLinHTML.js
|
||||||
deriving (Show, Read, Eq)
|
deriving (Show, Read, Eq)
|
||||||
|
|
||||||
-- | Methods for obfuscating email addresses in HTML.
|
-- | Methods for obfuscating email addresses in HTML.
|
||||||
|
|
|
@ -42,6 +42,8 @@ import Data.List ( isPrefixOf, intersperse )
|
||||||
import Data.Maybe ( catMaybes )
|
import Data.Maybe ( catMaybes )
|
||||||
import Control.Monad.State
|
import Control.Monad.State
|
||||||
import Text.XHtml.Transitional hiding ( stringToHtml )
|
import Text.XHtml.Transitional hiding ( stringToHtml )
|
||||||
|
import Text.TeXMath
|
||||||
|
import Text.XML.Light.Output
|
||||||
|
|
||||||
data WriterState = WriterState
|
data WriterState = WriterState
|
||||||
{ stNotes :: [Html] -- ^ List of notes
|
{ stNotes :: [Html] -- ^ List of notes
|
||||||
|
@ -111,17 +113,20 @@ pandocToHtml opts (Pandoc (Meta title' authors' date') blocks) = do
|
||||||
LaTeXMathML (Just url) ->
|
LaTeXMathML (Just url) ->
|
||||||
script !
|
script !
|
||||||
[src url, thetype "text/javascript"] $ noHtml
|
[src url, thetype "text/javascript"] $ noHtml
|
||||||
|
MathML (Just url) ->
|
||||||
|
script !
|
||||||
|
[src url, thetype "text/javascript"] $ noHtml
|
||||||
JsMath (Just url) ->
|
JsMath (Just url) ->
|
||||||
script !
|
script !
|
||||||
[src url, thetype "text/javascript"] $ noHtml
|
[src url, thetype "text/javascript"] $ noHtml
|
||||||
_ -> case lookup "latexmathml-script" (writerVariables opts) of
|
_ -> case lookup "mathml-script" (writerVariables opts) of
|
||||||
Just s ->
|
Just s ->
|
||||||
script ! [thetype "text/javascript"] <<
|
script ! [thetype "text/javascript"] <<
|
||||||
primHtml s
|
primHtml s
|
||||||
Nothing -> noHtml
|
Nothing -> noHtml
|
||||||
else noHtml
|
else noHtml
|
||||||
let newvars = [("highlighting","yes") | stHighlighting st] ++
|
let newvars = [("highlighting","yes") | stHighlighting st] ++
|
||||||
[("math", renderHtmlFragment math) | stMath st]
|
[("math", renderHtmlFragment math) | stMath st]
|
||||||
return (tit, auths, date, toc, thebody, newvars)
|
return (tit, auths, date, toc, thebody, newvars)
|
||||||
|
|
||||||
inTemplate :: TemplateTarget a
|
inTemplate :: TemplateTarget a
|
||||||
|
@ -450,6 +455,17 @@ inlineToHtml opts inline =
|
||||||
alt str, title str]
|
alt str, title str]
|
||||||
GladTeX ->
|
GladTeX ->
|
||||||
return $ primHtml $ "<EQ>" ++ str ++ "</EQ>"
|
return $ primHtml $ "<EQ>" ++ str ++ "</EQ>"
|
||||||
|
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 ->
|
PlainMath ->
|
||||||
inlineListToHtml opts (readTeXMath str) >>=
|
inlineListToHtml opts (readTeXMath str) >>=
|
||||||
return . (thespan ! [theclass "math"]) )
|
return . (thespan ! [theclass "math"]) )
|
||||||
|
|
|
@ -32,8 +32,7 @@ module Main where
|
||||||
import Text.Pandoc
|
import Text.Pandoc
|
||||||
import Text.Pandoc.ODT
|
import Text.Pandoc.ODT
|
||||||
import Text.Pandoc.Writers.S5 (s5HeaderIncludes)
|
import Text.Pandoc.Writers.S5 (s5HeaderIncludes)
|
||||||
import Text.Pandoc.LaTeXMathML (latexMathMLScript)
|
import Text.Pandoc.Shared ( tabFilter, ObfuscationMethod (..), readDataFile )
|
||||||
import Text.Pandoc.Shared ( tabFilter, ObfuscationMethod (..) )
|
|
||||||
#ifdef _HIGHLIGHTING
|
#ifdef _HIGHLIGHTING
|
||||||
import Text.Pandoc.Highlighting ( languages )
|
import Text.Pandoc.Highlighting ( languages )
|
||||||
#endif
|
#endif
|
||||||
|
@ -287,6 +286,13 @@ options =
|
||||||
"URL")
|
"URL")
|
||||||
"" -- "Use LaTeXMathML script in html output"
|
"" -- "Use LaTeXMathML script in html output"
|
||||||
|
|
||||||
|
, Option "" ["mathml"]
|
||||||
|
(OptArg
|
||||||
|
(\arg opt ->
|
||||||
|
return opt { optHTMLMathMethod = MathML arg })
|
||||||
|
"URL")
|
||||||
|
"" -- "Use mathml for HTML math"
|
||||||
|
|
||||||
, Option "" ["mimetex"]
|
, Option "" ["mimetex"]
|
||||||
(OptArg
|
(OptArg
|
||||||
(\arg opt -> return opt { optHTMLMathMethod = MimeTeX
|
(\arg opt -> return opt { optHTMLMathMethod = MimeTeX
|
||||||
|
@ -709,8 +715,11 @@ main = do
|
||||||
|
|
||||||
variables'' <- case mathMethod of
|
variables'' <- case mathMethod of
|
||||||
LaTeXMathML Nothing -> do
|
LaTeXMathML Nothing -> do
|
||||||
s <- latexMathMLScript datadir
|
s <- readDataFile datadir $ "data" </> "LaTeXMathML.js"
|
||||||
return $ ("latexmathml-script", s) : variables'
|
return $ ("mathml-script", s) : variables'
|
||||||
|
MathML Nothing -> do
|
||||||
|
s <- readDataFile datadir $ "data"</>"MathMLinHTML.js"
|
||||||
|
return $ ("mathml-script", s) : variables'
|
||||||
_ -> return variables'
|
_ -> return variables'
|
||||||
|
|
||||||
let startParserState =
|
let startParserState =
|
||||||
|
|
|
@ -33,12 +33,12 @@ $endif$
|
||||||
$for(css)$
|
$for(css)$
|
||||||
<link rel="stylesheet" href="$css$" type="text/css" />
|
<link rel="stylesheet" href="$css$" type="text/css" />
|
||||||
$endfor$
|
$endfor$
|
||||||
|
$if(math)$
|
||||||
|
$math$
|
||||||
|
$endif$
|
||||||
$for(header-includes)$
|
$for(header-includes)$
|
||||||
$header-includes$
|
$header-includes$
|
||||||
$endfor$
|
$endfor$
|
||||||
$if(latexmathml-script)$
|
|
||||||
$latexmathml-script$
|
|
||||||
$endif$
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
$if(title)$
|
$if(title)$
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Add table
Reference in a new issue