You need to put the toMathML call into the MathJax queue so that you
get the MathML version of the math after it is typeset. Here is code
that does that:
__________________________________________________________
<html>
<head>
<title>MathJax Dynamic Math Test Page</title>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
displayAlign: "left",
displayIndent: "2em"
});
</script>
<script type="text/javascript"
src="
http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML-full
">
</script>
</head>
<body>
<script>
//
// Use a closure to hide the local variables from the
// global namespace
//
(function () {
var QUEUE = MathJax.Hub.queue; // shorthand for the queue
var math = null; // the element jax for the math
output
var mathml = null; // the PRE tag where MathML is
shown
//
// Get MathML for a jax (asynchronous)
//
var toMathML = function (jax,callback) {
var mml;
try {
mml = jax.root.toMathML("");
} catch(err) {
if (!err.restart) {throw err} // an actual error
return
MathJax.Callback.After([toMathML,jax,callback],err.restart);
}
MathJax.Callback(callback)(mml);
}
var showMathML = function (mml) {
mathml.innerHTML = "";
MathJax.HTML.addText(mathml,mml);
}
//
// Get the element jax when MathJax has produced it.
//
QUEUE.Push(function () {
math = MathJax.Hub.getAllJax("MathOutput")[0];
mathml = document.getElementById("MathML");
});
//
// The onchange event handler that typesets the
// math entered by the user
//
window.UpdateMath = function (TeX) {
QUEUE.Push(
["Text",math,TeX],
[toMathML,math,showMathML]
);
}
})();
</script>
Type some TeX code:
<input id="MathInput" size="50" onchange="UpdateMath(this.value)" />
<p>
<div id="MathOutput">
You typed:
$${}$$
</div>
<p>
MathML for your expression:
<pre id="MathML">
</pre>
</body>
</html>
__________________________________________________________
Hope that does what you need.
Davide
On Nov 20, 2012, at 6:46 AM, <
kikk...@gmail.com> <
kikk...@gmail.com>
wrote: