From cfc0264b41728c6b2f5dda142d57dc1d1d30b975 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 26 Nov 2023 19:26:29 +0200 Subject: [math] Added initial setup for a simple LaTeX renderer --- src/scripts/math.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/scripts/math.js (limited to 'src/scripts/math.js') diff --git a/src/scripts/math.js b/src/scripts/math.js new file mode 100644 index 0000000..63b7681 --- /dev/null +++ b/src/scripts/math.js @@ -0,0 +1,21 @@ +function eqToHTML(equation) { + equation = equation.slice(2, -2) + .replaceAll(/ /g, '') + .replaceAll(/[\/+\*-=:]/g, '$&') + .replaceAll(/\\frac{(.*)}{(.*)}/g, '$1$2') + .replaceAll(/\^{(.*)}/g, '$1'); + equation = equation + .replaceAll(/\\frac{(.*)}{(.*)}/g, '$1$2') + .replaceAll(/\^{(.*)}/g, '$1'); + + return '
' + equation + '
'; +} + +for (var par of document.getElementsByTagName('p')) { + var eqs = par.innerText.match(/\\\[[^\]]*\\\]/g); + if (eqs === null) continue; + + for (var equation of eqs) { + par.innerHTML = par.innerHTML.replace(equation, eqToHTML(equation)); + } +} -- cgit v1.3.1-23-gd82d