From d3402bcd308cf9b115628c13e9e20ad532f43fe8 Mon Sep 17 00:00:00 2001 From: Martin von Gagern Date: Sun, 15 Jan 2017 17:47:02 +0100 Subject: [PATCH] Show katex errors in HTML output if rendering fails --- main.css | 4 ++++ main.js | 13 ++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/main.css b/main.css index 17a95fcc5..a33d29e57 100644 --- a/main.css +++ b/main.css @@ -206,3 +206,7 @@ body { .credits a { color: white; } + +.errorMessage { + color: red; +} \ No newline at end of file diff --git a/main.js b/main.js index ad9e8a5de..cad88cd23 100644 --- a/main.js +++ b/main.js @@ -8,7 +8,18 @@ window.startup = function() { var demoOutput = document.getElementById("demo-output"); function doDemo() { - katex.render("\\displaystyle{" + demoInput.value + "}", demoOutput); + 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() {