-
From the documentation I derived the following working example that works as expected: <script>
const formulaElement = document.getElementById("formula");
const formula = "c = \\pm\\sqrt{a^2 + b^2}"
katex.render(formula, formulaElement, { throwOnError: false });
</script> However, I'm trying to render a more sophisticated formula using a template string and cannot make it work. The code looks as follows: <script>
const formulaElement = document.getElementById("formula");
const formula = String.raw`
\begin{equation}
\begin{split}
a &= b + c \\
&= e + f
\end{split}
\end{equation}
`;
katex.render(formula, formulaElement, { throwOnError: false });
</script> That second example does not render the formula but instead just prints it literally, i.e. all I'm getting in the web browser is the string |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Alright, setting <script>
const formulaElement = document.getElementById("formula");
const formula = String.raw`
\begin{equation}
\begin{split}
a &= b + c \\
&= e + f
\end{split}
\end{equation}
`;
katex.render(formula, formulaElement, { displayMode: true, throwOnError: true });
</script> |
Beta Was this translation helpful? Give feedback.
Alright, setting
throwOnError
totrue
emitted the error messageKaTeX parse error: {equation} can be used only in display mode.
. So I addeddisplayMode: true
. The working solution looks as follows: