12  Tweaking the YAML header

The YAML block appears at the top of every Quarto document.

A simple example:

---
title: "Introduction to Fluid Mechanics"
author: "Dr Jane Smith"
date: today
---

12.1 Table of Contents

Enable a table of contents:

format:
  html:
    toc: true

12.2 Section Numbering

format:
  html:
    number-sections: true

12.3 Themes

Quarto provides several built-in themes.

format:
  html:
    theme: cosmo

Other popular themes include:

  • flatly
  • litera
  • united
  • lumen
  • sandstone

If you specify a light and dark theme, then Quarto will add in a toggle button to allow users to switch.

format:
  html:
    theme:
      light: cosmo
      dark: darkly
Caution

If you use dark mode, please if you images have transparency (if you have black text on a transparent background this can be illegible).

12.4 Multiple Output Formats

Quarto can render several formats from the same source.

format:
  html:
    toc: true
  pdf:
    toc: true
  docx: default

Rendering the document then produces HTML, PDF, Word simultaneously.

Caution

Always check each output. Sometimes things may note always compile as you wish!

12.5 Creating Books and Lecture Notes

A common approach is to keep all chapter files in a dedicated chapters folder and store chapter-specific images in an images directory within that folder.

project:
  type: book

Example structure:

course-notes/
│
├── _quarto.yml
├── index.qmd
├── references.bib
│
└── chapters/
    ├── week1.qmd
    ├── week2.qmd
    ├── week3.qmd
    │
    └── images/
        ├── lecture-diagram.png
        ├── experiment-setup.jpg
        └── results-plot.svg

Example _quarto.yml:

project:
  type: book
 
book:
  title: "Physics 1A Lecture Notes"
 
chapters:
- index.qmd
- chapters/week1.qmd
- chapters/week2.qmd
- chapters/week3.qmd