Skip to content

Instantly share code, notes, and snippets.

@elektret
Created September 1, 2013 22:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elektret/6407629 to your computer and use it in GitHub Desktop.
Save elektret/6407629 to your computer and use it in GitHub Desktop.
MathJax: Converts TeX to MathML
<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01//EN'
'http://www.w3.org/TR/html4/strict.dtd'>
<html>
<head>
<title>MathJax: Converts TeX to MathML</title>
<style type='text/css'>
*
{
margin: 0px;
padding: 0px;
font-family: 'monospace';
font-size: 13px;
}
body
{
width: 944px;
margin: auto;
background-color: #ffffff;
}
div
{
margin-top: 10px;
margin-bottom: 20px;
}
h1, p, span
{
font-size: 16px;
}
form
{
float: left;
}
label
{
display: block;
}
textarea
{
width: 450px;
height: 450px;
padding: 5px;
margin: 5px;
border: 1px solid #000000;
}
textarea#output
{
background-color: #dedede;
}
</style>
<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>
(function () {
var QUEUE = MathJax.Hub.queue;
var math = null;
var mathml = null;
var toMathML = function(jax, callback) {
var mml;
try {
mml = jax.root.toMathML('');
} catch(err) {
if(!err.restart) { throw err }
return
MathJax.Callback.After([ toMathML, jax,callback ], err.restart);
}
MathJax.Callback(callback)(mml);
}
var showMathML = function(mml) {
mathml.innerHTML = '';
MathJax.HTML.addText(mathml, mml);
}
QUEUE.Push(function () {
math = MathJax.Hub.getAllJax('typed')[0];
mathml = document.getElementById('output');
});
window.updateMath = function(tex) {
QUEUE.Push([ 'Text', math, tex ], [ toMathML, math, showMathML ]);
}
})();
</script>
<div>
<h1>MathJax: Converts TeX to MathML</h1>
<p id='typed'>$${}$$</p>
<form>
<label>TeX</label>
<textarea id='input' onkeyup='updateMath(this.value)' /></textarea>
</form>
<form>
<label>MathML</label>
<textarea id='output' readonly='readonly'></textarea>
</form>
<div style='clear:both;'></div>
<p>
<a href='http://www.mathjax.org'>MathJax</a> |
<a href='https://github.com/mathjax/MathJax'>GitHub</a>
</p>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment