https://github.com/xingjian-zhang/typst2img
A fast script to render your Typst formulas to svg and png. Integrate formulas to your slides in seconds!
https://github.com/xingjian-zhang/typst2img
formula png slides svg typsetting typst typst-plugin
Last synced: 6 months ago
JSON representation
A fast script to render your Typst formulas to svg and png. Integrate formulas to your slides in seconds!
- Host: GitHub
- URL: https://github.com/xingjian-zhang/typst2img
- Owner: xingjian-zhang
- Created: 2024-03-30T17:46:25.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-03-30T18:44:37.000Z (over 1 year ago)
- Last Synced: 2025-04-11T05:58:13.707Z (6 months ago)
- Topics: formula, png, slides, svg, typsetting, typst, typst-plugin
- Language: Jupyter Notebook
- Homepage: https://github.com/xingjian-zhang/typst2img/blob/main/example.ipynb
- Size: 161 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Typst Formula Renderer
A customization-allowed fast script to render your Typst formulas to svg or png.
## Usage
Command line:
```bash
python render_typ.py '$y = A x + b$' -o output.svg
```In Jupyter Notebook (recommended):
```python
from render_typ import FormulaRendererformulas = [
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`](example.ipynb) for more examples.
## Installation
```bash
pip install -r requirements.txt
```## Convert to PNG
You can convert the SVG files to PNG using [ImageMagick `convert`](https://imagemagick.org/script/download.php). This feature is only tested on MacOS.
```bash
$ 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

### General Relativity

### Mass Energy Equivalence
