Skip to content

How to render a formula in a template string #3245

Answered by ackh
ackh asked this question in Q&A
Discussion options

You must be logged in to vote

Alright, setting throwOnError to true emitted the error message KaTeX parse error: {equation} can be used only in display mode.. So I added displayMode: true. The working solution 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, { displayMode: true, throwOnError: true });
</script>

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by ackh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant