scribble-math/main.js
2017-01-15 17:47:02 +01:00

31 lines
945 B
JavaScript

window.startup = function() {
var tex = document.getElementsByClassName("tex");
Array.prototype.forEach.call(tex, function(el) {
katex.render(el.getAttribute("data-expr"), el);
});
var demoInput = document.getElementById("demo-input");
var demoOutput = document.getElementById("demo-output");
function doDemo() {
try {
katex.render("\\displaystyle{" + demoInput.value + "}", demoOutput);
} catch(err) {
while(demoOutput.lastChild) {
demoOutput.removeChild(demoOutput.lastChild);
}
var msg = document.createTextNode(err.message);
var span = document.createElement("span");
span.appendChild(msg);
demoOutput.appendChild(span);
span.setAttribute("class", "errorMessage");
}
}
demoInput.addEventListener("input", function() {
doDemo();
});
doDemo();
};