Skip to main content

Typst extension, adding support for generating images from a companion Marimo notebook

Project description

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")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

typst_marimo-0.1.0.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

typst_marimo-0.1.0-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

Details for the file typst_marimo-0.1.0.tar.gz.

File metadata

  • Download URL: typst_marimo-0.1.0.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for typst_marimo-0.1.0.tar.gz
Algorithm Hash digest
SHA256 bbf500c62c46f1bca769cb1f1470d19f1cbed3336911066971866c37ccfc4729
MD5 e4cc1b39420fccff0485285d8d163fc6
BLAKE2b-256 62f3bc8527eaf3d73660b047608823a214569d252780cdd06724b00fd3b0d714

See more details on using hashes here.

File details

Details for the file typst_marimo-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: typst_marimo-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for typst_marimo-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9b0194a1f092bc2425da94d0f372db0fa2061fe17dc848e44d99e639430d34de
MD5 f92bd5e9042c027b1c868224af31a58e
BLAKE2b-256 cc46c9e27b58800b8d5980ec2f07f8aa89b7406b63b442e3f750e57b076ab28b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page