I have a html document
<div>
<p>One paragraph</p>
<p>Another paragraph</p>
</div>
and in some of the paragraphs, I have
<p>Some text and a formula $a = b + c$.</p>
and I want the text withing the $-signs to be rendered as TeX math using KaTeX.
The problem is that if I want to use it in the browser, I have to use
katex.render("c = \\pm\\sqrt{a^2 + b^2}", element);
so I need to assign an element.
So should I really write my html document like this or are there any other options:
<div>
<p>One paragraph</p>
<p>Another paragraph</p>
<p>Some text and a formula <span id="firstFormula"></span>.</p>
<p>More text and another formula <span id="secondFormula"></span>.</p>
</div>
<script>
const firstFormula = document.getElementById('firstFormula');
katex.render("c = \\pm\\sqrt{a^2 + b^2}", firstFormula);
const secondFormula = document.getElementById('secondFormula');
katex.render("c = \\pm\\sqrt{a^2 + b^2}", secondFormula);
</script>
and repeat the same pattern for each formula?
It seems a bit weird that I cannot just write the text and replace all the text formulas with tex rendered output.
How does, for instance, Khan Academy do it on this page where they combine text and formulas? Do they render everything on the server and send it to the client?
Is it better to use MathJax in this situation? I am just more keen on KaTeX since it is much faster.