2
10
Fork
You've already forked mathyml
2
Convert your Typst equations to MathML
  • HTML 56.9%
  • Typst 42.6%
  • Python 0.3%
  • CSS 0.2%
2026年02月28日 11:29:20 +01:00
docs update docs 2025年05月29日 10:14:01 +02:00
examples use maybe-html automatically in to-mathml and try-to-mathml 2025年03月02日 08:55:04 +01:00
src fix mathfont include if the font is specified directly 2026年02月28日 11:29:20 +01:00
tests convert refs 2025年06月26日 18:17:39 +02:00
.gitignore initial commit 2025年02月26日 17:02:45 +01:00
install.py add install.py 2025年02月28日 20:59:14 +01:00
LICENSE add LICENSE 2025年02月28日 21:55:51 +01:00
README.md minor doc change 2025年03月03日 13:36:41 +01:00
typst.toml add typst.toml 2025年02月28日 20:52:35 +01:00

mathyml

mathyml converts your equations to MathML so that they work well with HTML export. See the manual for documentation.

Overview

Mathyml converts your typst equations to MathML Core. MathML Core is a language for describing mathematical notation and supported by major browsers (firefox and chrome). You can find an overview of MathML on mdn and in the specification.

Note that MathML rendering is certainly not perfect, some features work better and some worse. In general the output tends to look much better in firefox than chrome. See the section about missing/ non-working features below.

MathML Core is not complete and can't render everything itself. Instead it relies on Web Platform features (such as CSS) (see the explainer). You can find a list of of elements/ features used that do not come from MathML Core below.

Installation

Execute python install.py. This will install the mathyml package to the local package folder.

Quickstart

First, import mathyml and include the prelude, which defines replacements for elements which mathyml can't handle (e.g. bold or cal).

#import"@local/mathyml:0.1.0"#importmathyml:to-mathml#importmathyml.prelude:*

Include the required stylesheet (and the mathfont):

#mathyml.stylesheets()

Note that the mathfont is required, else the rendering looks really bad. The font is currently downloaded from github. I would recommend changing the font family to your liking and downloading the css files yourself (so that it works without an internet connection).

Convert equations manually:

Thefraction#to-mathml($1/3$)isnotadecimalnumber.Andweknow#to-mathml($a^2+b^2=c^2.$)

You can also convert equations automatically. If this panics, try try-to-mathml instead, which will create a svg on error.

#showmath.equation:to-mathmlTosolvethecubicequation$t^3+pt+q=0$(wheretherealnumbers$p,q$satisfy$4p^3+27q^2>0$)onecanuseCardano'sformula:$root(3,-q/2+sqrt(q^2/4+p^3/27))+root(3,-q/2-sqrt(q^2/4+p^3/27)).$

Missing/ non-working features

You can find a list of all missing/ non-working features in the manual. Here you can see the html output for the examples and tests.