Writing documentation#

Draft Describes the documentation system as built in version 0.1.

The documentation lives in documentation/, separate from the solver. It is a Sphinx site written in Markdown (MyST), with the PyData theme.

Layout#

documentation/
├── README.md                  build the site in two commands
├── requirements-docs.txt      tools to build the site (not needed to run the solver)
├── figure_notebooks/          notebooks that produce the figures from the solver
└── source/
    ├── conf.py                configuration
    ├── index.md               landing page
    ├── references.bib         bibliography
    ├── _static/               logo, CSS
    ├── figures/generated/     figures written by figure_notebooks/ (+ provenance .json)
    ├── getting-started/  theory/  user-guide/  developer-guide/
    ├── api/                   API reference, generated from the docstrings
    ├── validation/  examples/
    └── bibliography.md

Build and preview#

python -m venv documentation/.venv              # once
documentation/.venv/Scripts/python -m pip install -r documentation/requirements-docs.txt   # once (Windows path)

documentation/.venv/Scripts/python -m sphinx -W --keep-going -b html documentation/source documentation/_build/html
documentation/.venv/Scripts/python -m sphinx -W --keep-going -b html -D language=fr documentation/source documentation/_build/html/fr
python -m http.server 8000 -d documentation/_build/html     # then open http://localhost:8000

-W turns every warning into an error: a broken internal link, a missing figure or an unknown reference stops the build. The second build is the French site (see Translations below). The same commands run on GitHub for every push (see below).

Adding a page#

  1. Create source/<section>/<name>.md. Start it with a title and a status line:

    # Title of the page
    
    {.mom-status}
    {bdg-info}`Draft` One sentence: what the page was written from (files, commit).
    
  2. Add <name> to the toctree of source/<section>/index.md. The navigation is built from the toctrees: there is no menu to edit by hand.

  3. Build. A page missing from every toctree raises a warning, hence an error.

Page status#

Badge

Meaning

Planned

Outline only: what the page will cover.

Draft

Written and checked against the code, not yet reviewed.

Reviewed

Reviewed and validated by the maintainer.

For features, the same idea applies with Stable, Experimental, Known issue and Not functional, as on Feature status.

Theory pages#

Follow the structure of RWG basis functions: the idea, the definition and equations, a table of symbols with their name in the code, an In this solver section that says exactly what the code does (and nothing it does not do), assumptions and limits, where to look in the code, references.

Equations#

Inline: $\nabla_s\cdot\mathbf f_n$. Numbered and referenced:

```{math}
:label: eq-my-label
Z\,I = V
```

As shown in {eq}`eq-my-label`, ...

Reuse the symbols of Notation and conventions.

References#

Cite with {footcite:p}`rao1982` (parenthetical) or {footcite:t}`rao1982` (textual), and end the page with a footbibliography block. Every key must exist in source/references.bib.

Before adding an entry, check it against its DOI on Crossref (https://api.crossref.org/works/<DOI>) or, for a book without a DOI, against its ISBN record, and write where and when it was checked in a comment above the entry. Never add a reference from memory.

Figures#

Figures that show solver results are produced by a notebook in figure_notebooks/, never drawn by hand and never copied from older images:

  • the notebook calls the current solver code, shows the figure inline and saves it to source/figures/generated/ (SVG preferred);

  • it also writes a .json provenance file next to the figure (solver commit, date, the checks it ran);

  • the page embeds the figure with the class mom-generated and says in the caption which notebook and which commit produced it.

Interactive figures (Plotly)#

The 3D views the solver draws with Plotly (surface currents, patterns) can be shown interactive: the reader rotates and zooms them in the page. The notebook exports each such figure twice:

  • a static image (name.png, with fig.write_image), shown by a normal {figure} directive, which keeps the caption and the number and is what readers without JavaScript (and print) see;

  • an HTML fragment (name.html, fig.to_html(full_html=False, include_plotlyjs=False)) wrapped in <div class="mom-live-figure pst-js-only">.

The page loads plotly.js once, then includes the fragment right before the figure:

```{raw} html
<script src="../_static/plotly/plotly.min.js"></script>
```

```{raw} html
:file: ../figures/generated/name.html
```

```{figure} ../figures/generated/name.png
...
```

_static/js/live-figures.js moves the live view into the figure, in place of the image and of its “enlarge” link. plotly.js is not stored in the repository: conf.py copies it at build time from the plotly package pinned in requirements-docs.txt, the same version as the notebooks (first_simulation.json records it). A 3D pattern on the observation sphere weighs about 0.5 MB.

Refreshing a figure#

To refresh a figure after a change in the solver, re-run its notebook with the harmolab environment, from the figure_notebooks/ folder:

jupyter nbconvert --to notebook --execute --inplace theory_rwg_basis_function.ipynb

Design rules#

All of them are in source/_static/css/custom.css.

  • Font. Iosevka for text, headings and code, served with the site (_static/fonts/iosevka/, SIL Open Font License). Base size --mom-font-size: 12pt (16 px on screen); every other size scales with it. Figure notebooks load the same font files, so figures and pages match.

  • Colours. Those of the logo (_logos/): blue for \(T^+\), amber for \(T^-\). Use them with the same meaning in figures.

  • Clickable areas. At least 44 × 44 px. A link that leads somewhere else in the site is better as a card (grid-item-card with :link:) than as a short link in a sentence: the whole card is the target.

  • Hover. A clickable block reacts as a whole (title, text and image together): it rises by 2 px with a light shadow (0 2px 8px rgba(0,0,0,0.04)) in 180 ms. No rotation, no large scaling. Nothing moves when the visitor’s system asks for reduced motion.

  • Generated figures use the class mom-generated and a :target: pointing to the image itself: the whole figure, caption included, then opens the full-size image.

  • Light and dark mode. One button in the header (_templates/theme-toggle.html, _static/js/theme-toggle.js), not the theme’s three-entry dropdown: the site opens in the visitor’s system mode, and a click switches to the other one. Switching back to the system’s mode makes the site follow the system again. The choice is kept in the visitor’s browser. The icon shows the mode a click leads to (a moon in light mode, a sun in dark mode).

  • Language. A button next to it (_templates/language-toggle.html, _static/js/language-toggle.js) opens the same page, at the same section, in the other language; it shows the language a click leads to (FR on the English site, EN on the French one).

  • Resizable columns. _static/js/resizable-sidebars.js adds a handle between each sidebar and the page (drag, double-click to reset, arrow keys when focused); the width is kept in the reader’s browser. It only acts where the sidebars are columns (from 960 px wide for the left one, 1200 px for the right one) and never while the left one is collapsed.

API reference#

The pages in source/api/ contain only automodule directives: the text comes from the docstrings of the solver at build time, so it cannot fall out of date. Docstrings written in NumPy style are formatted; other docstrings are shown verbatim, exactly as help() would print them (see _docstring_verbatim_fallback in conf.py). To document a new module, add an automodule block to the matching page.

gmsh, cupy and threadpoolctl are not installed in the documentation environment: conf.py mocks them so that the modules importing them can still be read.

Translations#

The pages are written in English; the French site is built from the same sources with Sphinx’s gettext translation, into the fr/ folder of the English site. The translations are in documentation/locale/fr/LC_MESSAGES/, one .po file per page, in which every paragraph, heading, list item, table cell and caption of the page (a message) is followed by its French text. Code blocks, equations on their own line and figures are not translated: they are the same on both sites.

After changing a page, run

documentation/.venv/Scripts/python documentation/update_translations.py

It extracts the messages of every page, adds the new ones to the .po files with an empty translation, marks as fuzzy the ones whose English text changed (with the old translation kept as a starting point) and prints, per page, how many messages are translated, fuzzy or still to do. The French site shows a message in English as long as it is untranslated or fuzzy: translate it, remove the #, fuzzy line, and build.

In a translation, keep every role target, reference and inline equation exactly as in the English text ({doc}`...`, {eq}`...`, {footcite:p}`...`, $...$); only the visible text of a link may change. The build warns, hence fails, when a translation has a different number of cross-references than the English text.

The two HTML blocks of the landing page are not messages: they are kept in source/_html/ as hero.en.html / hero.fr.html and pipeline.en.html / pipeline.fr.html, and index.md picks one with {only} lang_fr / {only} not lang_fr.

The docstrings of the API reference stay in English, the language of the code; only the titles and introductions of the API pages are translated.

Publication#

.github/workflows/docs.yml builds the English and French sites with -W on every push and pull request that touches documentation/ or harmolab/. On the main branch it also publishes the result to GitHub Pages.