MyST documents
MyST builds websites and documents, e.g., a
notebook publication, from Markdown and notebooks.
In a project's pipeline, a myst stage builds a MyST project,
given as its target_path:
the project's folder, i.e., where its myst.yml is, the myst.yml itself,
or a document in it, which builds only that document's exports,
as myst build does given a file:
Its documents, their myst.yml, and the files and results files they
show or include are found when the pipeline compiles,
so they're inputs without being listed,
and the site is built again when they change.
What it builds is its output, as myst build would write it:
the site, if myst.yml defines one,
or with arguments for myst build in args, e.g., [--html] or
[--pdf], what those build,
with exports where myst.yml or a document's front matter puts them,
or in _build/exports, named for their document, as MyST names them.
They're stored with DVC, in Git with output_storage: git,
or not kept at all with output_storage: null.
Listing outputs replaces these.
Run it with calkit run, like any other stage,
or only it, e.g., with calkit run site.
For a PDF, MyST uses Typst, with --typst and a typst export,
or LaTeX, with --pdf and a pdf export, which the environment has to
provide too.
Typst is a single program, e.g., typst in a Conda or Pixi environment,
so it's the simpler choice unless you need the LaTeX itself,
e.g., for a journal's template.
For LaTeX, compose a TeX Live environment
into the one with MyST with with, as for
TeX from Python.
An export without an output is written to _build/exports,
e.g., _build/exports/paper_typst/paper.pdf for paper.md,
beside the .typ or .tex it's made from.
A PDF, or another export that prints, shows values without their views,
and a figure or table only with a line saying what's wrong, if anything,
as Quarto's PDFs do; Markdown keeps them.
To keep only the PDF, e.g., in Git, give the export an output:
MyST is part of an environment, like any other tool a stage runs,
e.g., mystmd in a Conda, Pixi, uv, or pip environment,
and the build fails rather than quietly using one installed on
this machine,
unless the project lists myst as a requirement
or the environment is _system.
Figures, tables, files, and values from the pipeline
A document can show a figure, table, or other file from anywhere in the
project by its path, as LaTeX's \ckfigure, \cktable, and \ckinclude
and Quarto's
divs do, with directives like MyST's own figure,
whose content is the caption:
:::{ckfigure} figures/fit.png
:label: fig-fit
:width: 80%
The fit, with its residuals.
:::
:::{cktable} results/fits.csv
:label: tbl-fits
:rows: 10
Each run's fit.
:::
:::{ckinclude} results/summary.md
:::
Paths are relative to the project.
ckfigure shows an image as a numbered figure, with figure's options,
e.g., width, cktable a CSV or TSV file as a numbered table,
up to :rows: rows (25 by default),
and ckinclude a Markdown file's content, with its images found
relative to it, or any other file by its path.
:name: works as :label: does, and options can be lines or a YAML
block.
Values are shown with the ckvalue and ckrefval roles,
whose content reads as Quarto's shortcodes' arguments do,
e.g., a results file or a declared result's name, a key, and a format,
or a notebook and the variable a cell saved:
The slope is {ckvalue}`results/fit.json fit.slope .3f`,
and k is {ckvalue}`fit.ipynb k_25 .3f`,
as in {ckrefval}`liu2025 noise-sigma`.
Calkit reads and formats the values when it builds the project,
as Quarto and LaTeX documents format them,
so MyST doesn't read results files itself.
A myst stage depends on everything shown this way,
including results files, and a notebook's saved values, e.g.,
.calkit/notebooks/outputs/fit.ipynb/values.json.
Directives and roles in a file a document {include}s,
or shows with ckinclude, count for the document,
with an {include} inside an included file read relative to that file,
as MyST reads it, and those files are inputs too.
Roles aren't read in inline code, comments, or files included with
:literal: true, and are in a directive's argument, e.g., an
admonition's title.
The documents read are the ones MyST builds:
those myst.yml's toc lists, or without one, every Markdown file and
notebook in its folder, except in _build and hidden folders,
either way leaving out what its exclude patterns match.
Showing where they came from
As in a Quarto document,
each component is shown with where it came from collapsed under it,
saying what's wrong while it's collapsed, e.g.,
"Out of date: scripts/clean.py modified",
and, opened, a graph of the stages it's made from and nothing else,
then each of them, with its kind, environment, script or command,
last run, every input, and what it makes on the way,
with links to files on GitHub or GitLab and to components shown in the
document.
A value is followed by a small †mark, or a ! when it's out of date,
which names where it came from when it's hovered and links to that
value's view, collapsed, in a block at the end of the page,
which MyST also previews when the mark's hovered.
The marks are plain characters so every export can show them.
:provenance: false, or provenance=false in a role, turns it off for
one, and show_provenance: false in calkit.yaml for the whole project.
What's shown is worked out the same way it is for Quarto.
See examples/myst
for a site that shows a figure, table, and values this way,
from three stages in Python.
The directives and roles come from a MyST plugin Calkit writes beside
myst.yml, in _plugins/calkit.mjs, which myst.yml lists:
The build fails if it's not listed, saying so.
Keep the plugin in Git,
since without it MyST builds the site anyway,
without what the directives and roles show.
It isn't an input of the build stage,
since Calkit writes it when the pipeline compiles and when it builds.
Calkit also writes _plugins/calkit.css, which makes
book-theme show each collapsed section as a small, muted line, as in
Quarto, keeping what's wrong in a warning color, if myst.yml lists it:
Each time it builds, it works out where everything came from,
and the values, and writes them to .calkit/local/provenance,
which isn't kept in Git, for the plugin to read.
The document's own outputs, i.e., those of the stage that builds the
project, aren't checked,
since it can't say whether what's being built is up to date.
Building with MyST directly, e.g., with myst start,
shows what was recorded the last time Calkit built the project,
saying so while collapsed if a document or a file it shows has changed
since, e.g., "Recorded before data/clean.csv changed".
A table's rows are read from its file as it's built,
so they're always current,
but a value is shown as Calkit last read and formatted it,
with a ! when its file has changed since,
since MyST doesn't read results files, and formatting them as Quarto and
LaTeX do would take reimplementing Python's formatting in the plugin.
A document Calkit hasn't built on this machine says nothing is recorded,
and shows ?? for its values.
myst start also doesn't notice when a script or data file changes,
so a view can say a figure is up to date when it isn't anymore
until the project is built again.
MyST doesn't tell its plugins which format it's building,
so Calkit tells the plugin when a build makes only exports that print.
Exports built alongside a site, or with MyST directly,
get the same collapsed sections as the site:
Word and LaTeX exports leave components' sections out,
reporting each as a node they can't show,
and include the values' views at the end, as boxes,
with emoji, e.g., ✅, that pdflatex may not typeset.
myst build --strict reports the links in the views as unresolved,
and a link to a file at a commit that hasn't been pushed isn't made.