Link to this sectionNative Typst to MathML in My Blog

Quick update: math equations on my blog are now rendered using native Typst-to-MathML conversion!

Last year, when Typst enhanced its HTML export in version 0.14, I redesigned my blog to use Typst for authoring content. At the time, though, Typst’s HTML export didn’t support math equations. The workaround was to render them as SVG images, which preserved the visual quality but came with several drawbacks: (1) the equations weren’t selectable, (2) they didn’t scale well across different font sizes, (3) they broke in dark mode, and (4) they couldn’t line-wrap to fit the surrounding typography. So I ended up using a third-party library called mathyml to convert math equations into MathML. 11.It hooks into Typst’s #show rule to extract the structured math content, and while its feature coverage is limited, it handles most everyday cases just fine. It served me well, but I was still hoping for a proper built-in solution.

I’d been keeping an eye on the progress of native MathML support (#7436) in Typst, and on May 12, 2026, the PR finally got merged. With this feature, Typst can directly emit math equations as MathML during HTML export. Fantastic news for my blog! Naturally, I decided to upgrade and switch to native MathML rendering.

There’s just one catch: the feature hasn’t landed in a stable Typst release yet, and understandably it’s not available in the downstream libraries that power my blog either. So I had to build those libraries myself against the latest Typst. Turns out it wasn’t as straightforward as I’d hoped. Let me explain.

I use astro-typst to integrate Typst into Astro, which in turn uses typst.ts as the underlying Typst engine. Typst.ts shares a lot of code with tinymist, the Typst LSP service. Both projects had pinned their Typst dependency to 0.14, and since then Typst’s APIs have gone through a fair number of breaking changes. So the upgrade was decidedly non-trivial. It touched a lot of code across both typst.ts and tinymist.

My plan was to fork typst.ts, bump its pinned Typst version to the latest main branch, and vendor in some of tinymist’s code to get everything working. 22.Admittedly, this is not the cleanest approach. It pretty much rules out contributing these changes back upstream. But honestly, I don’t have much bandwidth to maintain a fork properly; I just wanted things to work for my blog, and for now that’s good enough. With assistance from Claude Code and DeepSeek V4 Pro, I managed to finish the whole upgrade in a single day. 33.I have to say, having an AI assistant tag-team a Rust codebase across multiple crates is quite the experience. Now my blog renders math equations using native Typst-to-MathML conversion, and it works beautifully.

If you’d also like to use the bleeding-edge Typst in your own project, feel free to check out my fork of typst.ts at GitHub. Or, if you’re using pnpm, you can simply override the dependency with my pre-built version:

overrides:
  "@myriaddreamin/typst-ts-node-compiler": "npm:@wybxc/[email protected]"
  "@myriaddreamin/typst-ts-renderer": "npm:@wybxc/[email protected]"
  "@myriaddreamin/typst.ts": "npm:@wybxc/[email protected]"

Below are a few sample math equations to give you a sense of the rendering quality with native Typst-to-MathML conversion:

The Poincaré–Birkhoff–Witt theorem is a fundamental result in Lie theory that connects the symmetric algebra and the universal enveloping algebra. Let 𝔤 be a Lie algebra over a field 𝔽, and let 𝒰︀(𝔤) be its universal enveloping algebra. Choose a basis {𝐱𝑖} and denote the symmetric algebra by 𝘚(𝔤). Then the PBW theorem asserts the existence of a graded algebra isomorphism

𝚐𝚛𝒰︀(𝔤)≅𝘚(𝔤),

where 𝚐𝚛 denotes the associated graded algebra with respect to the standard filtration. In the representation theory of Lie algebras, the adjoint action is often written as 𝚊𝚍𝐱(𝔶)=[𝐱,𝔶] (with 𝔶∈𝔤). Usually the ground field is taken to be ℂ or ℝ, in which case 𝒰︀(𝔤) has a natural Hopf algebra structure, and the left regular action is given by 𝘓𝐱(𝑢)=𝐱𝑢. This result profoundly reveals the intrinsic connection between Lie algebras and associative algebras.