Callisto is a package to read Jupyter notebooks. Currently it covers two use cases:
-
Render notebook cells (or a whole notebook), e.g. to embed a notebook as a chapter in a Typst document,
-
Extract elements from specific cells, e.g. to insert a cell’s source code or its output in a Typst document.
Here’s a rendering example:
#import "@preview/callisto:0.2.2"
// Render the first 5 cells
#callisto.render(range(5), nb: json("Lorenz.ipynb"))
Or using config
to set defaults for the reading functions:
#import "@preview/callisto:0.2.2"
#let (render, result) = callisto.config(nb: json("Lorenz.ipynb"))
// Render the first 5 cells
#render(range(5))
Cells can be specified in various ways. For example the cell source can include a header that defines a label (as with Quarto):
#| label: plot1
import matplotlib
plt.plot([1, 2, 3, 4], [1, 4, 9, 16])
We can use this plot1
label to find the cell from Typst:
// Get result of plot1 cell
#result("plot1")
For more examples, see the quick start and tutorial.
Future plans
The current templates (plain
and notebook
) are very basic. I think there’s potential for designing beautiful templates, so Typst could become one of the preferred ways to render Jupyter notebooks as documents.
For the next major release, I want to experiment with functionality a la prequery, to enable round-trips between Typst and Jupyter: write code blocks in a Typst document, and have them automatically extracted and executed by Jupyter, and the result automatically included in the Typst document.