Coding dynamic mathematical content takes an extra step of calling the math and display functions from the Mathlifier library.
This value and the following are generated dynamically:
Reload the page to see new values.
<script>
import {math, display} from 'mathlifier';
const x = Math.ceil(Math.random()*100)
const inlineMath = math(`x=${x}`);
const displayedMath = display(`x^2 = ${x*x}`);
</script>
This value {@html inlineMath} and the following are generated dynamically:
{@html displayedMath2}
Reload the page to see new values. Truly reactive content are probably better served in a svelte file instead.
Mathlifier is my custom library that uses temml to generate MathML.
If you prefer to use the or temml libraries instead, install katex and modify the source code above with
import katex from 'katex';
const inlineMath = katex.renderToString(`x=${x}`);
const displayedMath = katex.renderToString(`x^2 = ${x * x}`, { displayMode: true }); import temml from 'temml';
const inlineMath = temml.renderToString(`x=${x}`);
const displayedMath = temml.renderToString(`x^2 = ${x * x}`, { displayMode: true });