1import katex from '../katex.mjs'; 2 3let scripts = document.body.getElementsByTagName("script"); 4scripts = Array.prototype.slice.call(scripts); 5scripts.forEach(function (script) { 6 if (!script.type || !script.type.match(/math\/tex/i)) { 7 return -1; 8 } 9 10 const display = script.type.match(/mode\s*=\s*display(;|\s|\n|$)/) != null; 11 const katexElement = document.createElement(display ? "div" : "span"); 12 katexElement.setAttribute("class", display ? "equation" : "inline-equation"); 13 14 try { 15 katex.render(script.text, katexElement, { 16 displayMode: display 17 }); 18 } catch (err) { 19 //console.error(err); linter doesn't like this 20 katexElement.textContent = script.text; 21 } 22 23 script.parentNode.replaceChild(katexElement, script); 24}); 25