diff options
| Commit | cfc0264b41728c6b2f5dda142d57dc1d1d30b975 (patch) | |
|---|---|---|
| Author | 2023-11-26 19:26:29 +0200 | |
| Committer | 2023-11-26 19:26:29 +0200 | |
| Files | 00febb6a8d57daacbedf878db60ce01dc2b55a39 /src/scripts | |
| syndamia.com-latex.tar syndamia.com-latex.tar.gz syndamia.com-latex.zip | ||
| Parent | 11a6c3776e148e89387fdda7e90867661cecded5 (diff) | |
[math] Added initial setup for a simple LaTeX renderer latex
1 files changed, 21 insertions, 0 deletions
| -rw-r--r-- | src/scripts/math.js | 21 |
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, '<span class="operator">$&</span>') + .replaceAll(/\\frac{(.*)}{(.*)}/g, '<span class="divide"><span><span class="dividend">$1</span></span><span><span class="divisor">$2</span></span></span>') + .replaceAll(/\^{(.*)}/g, '<sup>$1</sup>'); + equation = equation + .replaceAll(/\\frac{(.*)}{(.*)}/g, '<span class="divide"><span><span class="dividend">$1</span></span><span><span class="divisor">$2</span></span></span>') + .replaceAll(/\^{(.*)}/g, '<sup>$1</sup>'); + + return '<div class="equation">' + equation + '</div>'; +} + +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)); + } +} |