Skip to content

Commit

Permalink
Added --mathml option; removed Text.Pandoc.LaTeXMathML.
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
fiddlosopher committed Mar 18, 2010
1 parent d704f47 commit 56217f1
Show file tree
Hide file tree
Showing 12 changed files with 326 additions and 252 deletions.
5 changes: 5 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion data/LaTeXMathML.js.packed → data/LaTeXMathML.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 0 additions & 16 deletions data/LaTeXMathML.js.comment

This file was deleted.

70 changes: 70 additions & 0 deletions data/MathMLinHTML.js
Original file line number Diff line number Diff line change
@@ -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);
}
4 changes: 4 additions & 0 deletions man/man1/pandoc.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 3 additions & 4 deletions pandoc.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down
13 changes: 0 additions & 13 deletions src/Text/Pandoc/LaTeXMathML.hs

This file was deleted.

1 change: 1 addition & 0 deletions src/Text/Pandoc/Shared.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
20 changes: 18 additions & 2 deletions src/Text/Pandoc/Writers/HTML.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"]) )
Expand Down
17 changes: 13 additions & 4 deletions src/pandoc.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 =
Expand Down
6 changes: 3 additions & 3 deletions templates/html.template
Original file line number Diff line number Diff line change
Expand Up @@ -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)$
Expand Down
410 changes: 201 additions & 209 deletions tests/s5.fancy.html

Large diffs are not rendered by default.

0 comments on commit 56217f1

Please sign in to comment.