Skip to content

Instantly share code, notes, and snippets.

@tiarno
Created July 30, 2013 19:54
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 tiarno/6116323 to your computer and use it in GitHub Desktop.
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…
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();
@tiarno
Copy link
Author

tiarno commented Jul 30, 2013

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment