Created
September 25, 2014 11:42
-
-
Save alxarch/4f416d24ec26e87e224b to your computer and use it in GitHub Desktop.
Hack MathJax to use as a TeX to MathML converter.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MathJax.Hub.Register.MessageHook("End PreProcess", function () { | |
[].slice.apply(document.querySelectorAll("script[type^=math]")).forEach(function (s) { | |
var mml = MathJax.InputJax.TeX.Parse(s.innerHTML).mml(); | |
var math = document.createElementNS("http://www.w3.org/1998/Math/MathML", "math"); | |
math.setAttribute("xmlns", "http://www.w3.org/1998/Math/MathML"); | |
// tricks toMathML extension | |
mml.parent = {}; | |
var mathml = mml.toMathML() | |
math.innerHTML = mathml | |
s.parentElement.replaceChild(math, s); | |
}); | |
}); | |
MathJax.Hub.Queue(["PreProcess", MathJax.Hub, document.body]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment