Skip to main content

typst-marimo

Generate images and values in a Marimo notebook; load them in Typst.

This is essentially a thin wrapper around matplotlib's savefig and Typst's image, with some guards:

  • a checksum to be sure that the images are up-to-date;
  • impossible to save two different images under the same name.

Installation

pip install typst-marimo

Usage

In Marimo:

import matplotlib.pyplot as plt
from typst_marimo import export_image_to_typst, export_value_to_typst

x = plt.plot(...)

# Usage is `export_image_to_typst(x)`, called from within a Marimo cell (not within a
# function) on a matplotlib object.
#
# This will save the image under `x.png`, using the name of the variable. Marimo
# requires all global variables to have unique names, so this safely avoids the
# possibility of accidentally using the same name twice.
#
# This command will also save `.typst-marimo/lib.typ` for loading from Typst.
export_image_to_typst(x)

y = "37 #sym.degree;C"

# Usage is `export_value_to_typst(y)`. Same as the above, but instead of saving a image
# then we save `str(y)`, and evaluate this as Typst code when imported.
export_value_to_typst(y)

Then run your marimo notebook, either via marimo ... your-notebook.py or via python your-notebook.py. This will save and generate your images, along with a checksum that they are up-to-date.

In Typst:

#import ".typst-marimo/lib.typ": import-image-from-marimo, import-value-from-marimo

// Usage is `import-image-from-marimo(notebook, variable, ..args)`, with
// remaining arguments passed on to `image`.
//
// Importantly (the whole point of this package), it will error out if the
// image is not up-to-date.
#let my-image = import-image-from-marimo("your-notebook.py", "x", width: 50%)

// Usage is `import-value-from-marimo(notebook, variable, mode)`.
//
// `mode` is the same as in `eval(..., mode: ...)`, and must be one of `"markup"`,
// `"math"` or `"code"`.
#let my-value = import-value-from-marimo("your-notebook.py", "y", mode: "markup")

FAQ

Typst incorrectly states that the Marimo notebook is out of date?

Marimo is happy to ignore some whitespace changes and in this case will avoid recompiling; Typst is not so lenient about detecting this. The easiest way to resolve this is to force a re-run of the whole notebook, via the 'Restart kernel' command in Marimo.

Metadata

Release files for typst_marimo 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for typst_marimo 0.1.3
File Size Uploaded
typst_marimo-0.1.3.tar.gz 8.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for typst_marimo 0.1.3
File Interpreter ABI Platform
typst_marimo-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 21.6 kB

Release files / typst_marimo-0.1.3.tar.gz

Download URL typst_marimo-0.1.3.tar.gz
Size 8.9 kB
Tags Source
SHA-256 checksum
How to use checksums
efe6460d3846bdd978079139e449b76a291eabbc07eba05e3e51365cca21321b
BLAKE2b-256 checksum
How to use checksums
3a8351155a5b5e5e4461132d4ef2d9a6e7cbe58b6f25ff9df93204ea3a5c9db1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.14

Release files / typst_marimo-0.1.3-py3-none-any.whl

Download URL typst_marimo-0.1.3-py3-none-any.whl
Size 12.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c300982840de5eee8ecf000a9437744bc5a6b32b9d824c6e884d5ab06f54282e
BLAKE2b-256 checksum
How to use checksums
c9828755f9fb3f215f5d019abe7c7830dd387c88e85814c8a37f241dd2d8a5a0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.14

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page