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
|
||||
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
|
||||
|
|
|
@ -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);}
|
|
@ -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
|
||||
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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
| 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.
|
||||
|
|
|
@ -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 $ "<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 ->
|
||||
inlineListToHtml opts (readTeXMath str) >>=
|
||||
return . (thespan ! [theclass "math"]) )
|
||||
|
|
|
@ -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 =
|
||||
|
|
|
@ -33,12 +33,12 @@ $endif$
|
|||
$for(css)$
|
||||
<link rel="stylesheet" href="$css$" type="text/css" />
|
||||
$endfor$
|
||||
$if(math)$
|
||||
$math$
|
||||
$endif$
|
||||
$for(header-includes)$
|
||||
$header-includes$
|
||||
$endfor$
|
||||
$if(latexmathml-script)$
|
||||
$latexmathml-script$
|
||||
$endif$
|
||||
</head>
|
||||
<body>
|
||||
$if(title)$
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue