Skip to content

A fast script to render your Typst formulas to svg and png. Integrate formulas to your slides in seconds!

Notifications You must be signed in to change notification settings

xingjian-zhang/typst2img

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Typst Formula Renderer

A customization-allowed fast script to render your Typst formulas to svg or png.

Usage

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.

Installation

pip install -r requirements.txt

Convert to PNG

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

Examples

Euler Identity

Euler Identity

General Relativity

General Relativity

Mass Energy Equivalence

Mass Energy Equivalence

About

A fast script to render your Typst formulas to svg and png. Integrate formulas to your slides in seconds!

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published