In the LaTeX world, we have MathJax and KaTeX to beautifully typeset math on the web. I would love to see equivalent projects for the Typst world since I love the simplicity of the Typst math syntax.
For KaTeX, see this discussion I’ve opened there.
In the LaTeX world, we have MathJax and KaTeX to beautifully typeset math on the web. I would love to see equivalent projects for the Typst world since I love the simplicity of the Typst math syntax.
For KaTeX, see this discussion I’ve opened there.
well, you can already already sort of do this through HTML export and frames, which will inline an SVG:
#html.frame($ 2 + 2 = 4 - 1 = 3$)
quick mafs
though the text doesn’t seem to be selectable (which is probably easy to fix).
more generally, you could integrate typst with whatever other markup language or framework you’re using. see for example astro-typst.
note that it wouldn’t be practical to use the typst compiler to render math at client-side as it’s several megabytes large. this is a more general opinion, but the much better approach is to either render at server-side (SSR), or statically generate (SSG), which is naturally the approach that typst uses (because it’s a document generator).
i don’t think KaTeX will (or should) be interested in implementing a custom typst parser just to render math. instead, the typst compiler should directly implement better equation output for HTML. but this is probably a ways to go.
given that this seems to be more about the nice syntax than the various other improvements over *TeX, you could use tex2typst to preprocess your typst math into tex math at server-side, then use whatever you want to render this tex code.
To add to @cAtte answer, Typst will eventually support HTML equations using MathML Core.
There was a showcase on Discord a few months ago of a package that partly implements HTML math export: akida/mathyml: Convert your equations to MathML - Codeberg.org
AFAIK, ther is no easy generic solution you can just plug in to your website. But there are some things you can try:
Any news on this?
Would be awesome to have a KaTeX version of Typst math that you can just import in the head of you html page and start writing something like
Bla bla $E=mc^2$ Bla bla
and it automatically renders (the js library generates the corresponding DOM elements).Whilst this isn’t quite the same, progress is being made on MathML Core output for equations in HTML export, see https://github.com/typst/typst/pull/7436. The main prerequisite Add a math IR by mkorje · Pull Request #7435 · typst/typst · GitHub should land very soon.