Appendix C — Cheatsheet

Keywords

Quarto, reproducible publishing, coding agents, Markdown, Python, EPUB, data analysis, k-means clustering

A one-page reference for the patterns this book uses, with the chapter that explains each.

Front matter (YAML)

One source, several formats (Chapter 7):

---
title: "Project Report"
author: "Author Name"
date: today
format:
  html:
    toc: true
    format-links:
      - docx
      - {format: typst, text: PDF}
  docx: default
  typst:
    papersize: a4
  pptx: default
  revealjs:
    output-file: report-slides.html
  epub:
    toc: true
lang: en
---

Code cells and inline code

Options go at the top of a cell, as #| comments (Section 7.4):

  • #| label: fig-name numbers the figure and lets the text refer to it as @fig-name.
  • #| echo: false hides the code and shows the output.
  • #| eval: false shows the code without running it.
  • #| fig-cap: "…" is the caption under a figure.
  • #| fig-alt: "…" is the alt text screen readers announce.
  • #| tbl-cap: "…" is the caption of a table.
  • #| output: asis treats printed text as Markdown.

Inline code puts a computed value in a sentence (Section 7.3):

The dataset contains `{python} len(df)` rows across `{python} df['year'].nunique()` years.

Dashboards

A level-1 heading starts a page, a level-2 heading a row, and each cell’s output becomes a card (Section 8.1):

---
title: "Operations dashboard"
format: dashboard
---

# Overview

## Row {height=30%}

::: {.valuebox icon="trophy" color="primary"}
Most visited
`{{python}} top_name`
:::

## Row

```{python}
#| title: Visits by attraction
fig = px.bar(attractions, x="visits_2025", y="attraction")
fig
```

Assign Plotly figures and end the cell with fig; never call fig.show() in a dashboard.

Websites

_quarto.yml turns a folder into a website (Section 9.3, Section 23.4):

project:
  type: website
  execute-dir: project
  pre-render: scripts/analysis.py
  render:
    - index.qmd
    - report.qmd
website:
  title: "My project"
  navbar:
    left:
      - {text: Report, href: report.qmd}
      - text: Downloads
        menu:
          - {text: "Report (PDF)", href: report.pdf}
execute:
  freeze: false

Commands

Table C.1: The commands used in this book.
Command Does
uv init --bare starts a uv project in this folder
uv add pandas matplotlib adds packages to pyproject.toml and uv.lock, and installs them
uv run quarto preview file.qmd renders and serves a page, re-rendering on every save
uv run quarto render file.qmd renders one file in all its formats; --to docx for one format
uv run quarto render renders the whole project
uv run quarto publish gh-pages the first publish to GitHub Pages, interactive
uv run quarto publish gh-pages --no-prompt later updates, once the gh-pages branch exists
uv run quarto check jupyter shows which Python and Jupyter Quarto will use

Check and undo with Git

Run them in the project folder, before and after every change, yours or the agent’s (Section 5.4, Section 5.5, Section 9.1):

Table C.2: Checking and undoing with Git.
Command Does
git init -b main starts a history in this folder, on a branch called main (once per project)
git status lists the files changed, added or untracked since the last commit
git diff shows the changes not yet added, line by line: - the old line, + the new
git add . adds every change to the next commit; git add report.qmd adds one file
git commit -m "What changed" records the added changes as a commit, with a message saying what changed
git log --oneline lists the commits, newest first, one line each
git restore data/visits.csv throws away the uncommitted changes to one file, back to its last commit

Prompts

A reliable prompt (Section 2.6):

  1. Names the inputs and outputs: file names and column names, in backticks.
  2. Does one task.
  3. Ends with a check: “render it and tell me which file it wrote”, “check the PDF is one page”.
  4. Respects the data: “compute every number from the cited files; never invent one”.