A customization-allowed fast script to render your Typst formulas to svg or png.
Command line:
python render_typ.py '$y = A x + b$' -o output.svg
In Jupyter Notebook (recommended):
from render_typ import FormulaRenderer
formulas = [
r'$ A = pi r^2 $',
r'$ "area" = pi dot "radius"^2 $',
r'$ cal(A) := { x in RR | x "is natural" } $',
r'$ x < y => x gt.eq.not y $',
r'$ mat(1, 2; 3, 4) $',
r'''$ sum_(k=0)^n k
&= 1 + ... + n \
&= (n(n+1)) / 2 $''',
]
# Render in-line in a notebook.
basic_renderer = FormulaRenderer()
for f in formulas:
basic_renderer.render(f)
# Save to file.
named_formulas = {
"mass_energy_equivalence": r'$ E = m c^2 $',
"euler_identity": r'$ e^(i pi) + 1 = 0 $',
"general_relativity": r'$ G_(mu nu) + Lambda g_(mu nu) = kappa T_(mu nu) $',
}
for k, v in named_formulas.items():
basic_renderer.render(v, name=k)
See example.ipynb
for more examples.
pip install -r requirements.txt
You can convert the SVG files to PNG using ImageMagick convert
. This feature is only tested on MacOS.
$ make all
convert -density 1000 output/euler_identity.svg output/euler_identity.png
convert -density 1000 output/general_relativity.svg output/general_relativity.png
convert -density 1000 output/mass_energy_equivalence.svg output/mass_energy_equivalence.png