Posts

Showing posts with the label mathjax

Await not awaiting

Await not awaiting I am getting started with both MathJax and using await where I am formatting a series of lines which can contain math. The math is denoted by the delimiters $...$ . $...$ Problem: I need to wait for MathJax to complete its conversion (I do get some sort of html output) however the conversion is not waiting and the rest of format() is executing. Part of my code is modeled after the answer given in this question. format() function MJ(math) { // as per the documentation, this returns a promise if no callback is set return mathjax.typeset({ math: math, format: "inline-TeX", html: true, }); } async function convert(line) { var re = /$(.*?)$/; var match = re.exec(line)[0]; var math = match.slice(1, -1); // ORIGINAL CODE // let result = await MJ(math).then(function(data){return line.replace(match,data.html);}); // return result; let result = await MJ(math); console.log(`MJ is ready: ${result.htm...