Building the docs
The site in docs/ is built with Astro and
Starlight. It has three kinds of pages:
- Hand-written pages in
docs/src/content/docs/, as Markdown or MDX. - Tutorials, converted from the Jupyter notebooks in
tutorials/bystarlight-notebooks. Each notebook is executed and its outputs (text, figures, tables) are written into an MDX page. The figures are drawn with plasma-plots and its Plotly backend (plasma_plots.set_backend("plotly")in the first cell), so the page embeds them interactively, in the site’s light and dark colours. - Full examples, built from Python scripts in
examples/bydocs/tools/examples.py. Each page shows the module docstring, the complete source file, and its figures, converted to web figures (*.plotly.json, with a picture for each in light and dark mode) and embedded with the theme’sPlotlyFigure. - API reference, generated from the docstrings by starlight-pydocs, one page per module.
The configuration (defineDocs in docs/astro.config.mjs), the look, the header, the notebook
tool and the build workflow come from the shared
starlight-theme of the max-models projects;
change them there, and update the version in docs/package.json and
.github/workflows/docs.yml to pick up a new release.
Requirements
Section titled “Requirements”- Node 22 or newer.
- The package installed with the
docsextra:pip install -e ".[docs]". The pictures of the full examples’ figures need kaleido’s browser (plotly_get_chromeif none is installed); without one the figures are still embedded, only without a picture while they load.
Commands
Section titled “Commands”make docs-install # npm packages and the Python docs extramake docs-notebooks # execute tutorials/*.ipynb and convert them to pagesmake docs-examples # run examples/*.py and publish their figuresmake docs-dev # live preview at http://localhost:4321/OpenCR/make docs-build # the static site in docs/dist, as in CImake docs-preview # serve docs/distmake docs-clean # remove generated pages and build outputmake docs-notebooks only reruns a notebook whose cells changed since the last run; pass
FORCE=1 to rerun all of them.
Writing tutorials
Section titled “Writing tutorials”Put a Jupyter notebook in tutorials/. Tutorials are authored only as .ipynb files. Its first # Heading becomes the page title and the first
paragraph its description. Cell tags control the output:
| Tag | Effect |
|---|---|
remove-cell | the cell is left out of the page |
hide-input | the code is hidden, the outputs are kept |
fold-input | the code is in a closed “Show code” box |
remove-output | the outputs are left out |
raises-exception | an error output is shown, not a failure |
Math in $...$ and $$...$$ is rendered with KaTeX.
Figures
Section titled “Figures”Draw a figure with the .plasma.plot accessors, or in a plasma_plots.figure block with the
Matplotlib calls on its panel (ax = fig[0]) for a drawing of your own: at the end of the
block it is converted to a Plotly figure and shown. One figure per plot rather than a grid of
panels, which is too crowded on the page and on a phone; give the block the title
(plasma_plots.figure(title=...)) and the accessors title="". Leave the colours to the theme
("C0", "C1", … for the data, "k" for references), so they follow the light and dark
mode.
The tutorials call plasma_plots.set_math("latex") after set_backend("plotly"), and the
full examples’ figures are converted the same way: labels written with Matplotlib’s mathtext
(ax.set_xlabel("$T_e$ [eV]")) are typeset as LaTeX by MathJax on the page. A label is
typeset as one formula, so keep its math in $...$ and its words outside, and write unit
exponents as math too ("[m$^{-3}$]").
Writing full examples
Section titled “Writing full examples”Put a Python script in examples/ with a module docstring. Its first line becomes the page
title and the rest becomes the description. Draw the figures with plasma-plots (the
.plasma.plot accessors, or a plasma_plots.figure block for a drawing of your own), one
figure per plot, and leave them open at the end of the script: the docs builder converts every
open figure to a web figure and embeds it. The complete script is shown on the page.