Skip to content

Instantly share code, notes, and snippets.

@alxarch
Created September 25, 2014 11:42
Show Gist options
  • Save alxarch/4f416d24ec26e87e224b to your computer and use it in GitHub Desktop.
Save alxarch/4f416d24ec26e87e224b to your computer and use it in GitHub Desktop.
Hack MathJax to use as a TeX to MathML converter.
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