preserving Typst math syntax when converting to HTML or Bundle
I’d like to keep the original Typst math syntax in the exported HTML files and render them by using typlet, a newly published npm package built specifically for rendering Typst math.
However, when converting Typst files to HTML or bundle, math equations are converted to MathML by default. Is there a way to preserve the Typst math syntax instead?
best I can come up with is to use typlet’s renderMathInElement function to render strings containing the regular typst math syntax as equations:
#show: doc => html.html(lang: "en")[
#html.head[
#html.meta(charset: "utf-8")
#html.link(rel: "stylesheet", href: "https://cdn.jsdelivr.net/npm/typlet@0.1.0/fonts/typlet.css")
#html.script(src: "https://cdn.jsdelivr.net/npm/typlet@0.1.0/dist/typlet.min.js")
#html.script(src: "https://cdn.jsdelivr.net/npm/typlet@0.1.0/dist/contrib/auto-render.min.js")
]
#html.body[
#doc
#html.script("renderMathInElement(document.body);")
]
]
#"$x^2 + x$"
If you want to support equations in paged export too, you can use eval (just remember to disable the show rule above):
#let eq(it) = context {
if target() != "html" {
eval(it, mode: "math")
}
else {
"$"+it+"$"
}
}
#eq("x^2 + x")