Created
July 30, 2013 19:54
-
-
Save tiarno/6116323 to your computer and use it in GitHub Desktop.
MathJax testing for TeX and rendering errors. Create HTML page (with math) to include the MathJax library and then include this file. When the page is loaded, the js console will show when errors are encountered and the data about the error will be POSTed via ajax to a rest-type service named here as 'service/mathmltest'. That service should acc…
This file contains hidden or 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
function ajaxRequest(){ | |
return new XMLHttpRequest(async=false); | |
} | |
function mltest (){ | |
var filename = window.location.href.substr(window.location.href.lastIndexOf("/")+1); | |
MathJax.Hub.Config({TeX: {noUndefined: {disabled: true}}}); | |
MathJax.Hub.Queue(function() {console.log('finished rendering');}); | |
MathJax.Hub.Register.MessageHook("TeX Jax - parse error",function (message) { | |
console.log('error encountered'); | |
var mydata = {}; | |
var myrequest = new ajaxRequest(); | |
mydata['message'] = message[1]; | |
mydata['source'] = message[2]; | |
mydata['mode'] = message[3] ? "display mode" : "inline"; | |
mydata['filename'] = filename; | |
myrequest.open('POST', 'service/mathmltest'); | |
myrequest.setRequestHeader("Content-type", "application/text"); | |
myrequest.send(JSON.stringify(mydata)); | |
}); | |
}; | |
mltest(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code was first written and posted on the MathJax google group by Davide P. Cervone. I added a few things and created this gist. See https://groups.google.com/forum/#!topic/mathjax-users/cx9qx5Yhae8 for details.