---
title: "Quarto templates"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Quarto templates}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(collapse = TRUE, comment = "#>", eval = FALSE)
```

[Quarto](https://quarto.org) is the successor of R Markdown.
It reads the same Markdown, runs the same R code with knitr,
and also works with Python and Julia.
`{iheiddown}` gives a Quarto template for each kind of document:

| Template | Output | Engine |
|---|---|---|
| `syllabus` | PDF | Typst |
| `problemset` | PDF | Typst |
| `thesis` | PDF | LaTeX (default) or Typst |
| `slides` | HTML and PowerPoint | reveal.js and Pandoc |
| `poster` | PDF | Typst |

## Start a document

In RStudio, choose *File* > *New Project* > *New Directory* >
*IHEID document (Quarto)*, and choose a template.

In Positron, in another editor, or in a script, use `use_quarto()`:

```{r}
iheiddown::use_quarto("syllabus", dir = "MINT001")
```

`use_quarto()` copies these files into the folder:

- the starter file, for example `syllabus.qmd`, to edit;
- the Quarto extension in `_extensions/`, which formats the document;
- `_brand.yml`, with the colours and fonts of the Institute;
- `iheid-logo.png`, the logo of the Institute;
- any example files that the template uses, such as a `.bib` file.

It does not change files that already exist,
unless you give `overwrite = TRUE`.

Render the document with the *Render* button,
or with `quarto render` in a terminal.
RStudio and Positron include Quarto.

## Typst or LaTeX?

[Typst](https://typst.app/docs/) makes PDF files, as LaTeX does.
Quarto includes Typst, so you do not need to install anything else,
and Typst is much faster than LaTeX.
All PDF templates use Typst.

The thesis also has a LaTeX format, with the layout of `thesis_pdf()`.
It is the default, because many supervisors and journals ask for LaTeX.
To use Typst, change the format in `_quarto.yml`:

```yaml
format:
  iheid-thesis-typst: default
```

Do not put LaTeX commands such as `\newpage` in the text:
they do not work with Typst.
Use the Quarto shortcode `{{< pagebreak >}}` instead.

## Move a document from R Markdown

Most of the Markdown and R code stays the same.
These are the main changes:

| R Markdown | Quarto |
|---|---|
| `output: iheiddown::syllabus_pdf` | `format: iheid-syllabus-typst` |
| `knitr::include_graphics("x.png")` | `![Caption](x.png)` |
| Chunk options in the header: `{r, echo=FALSE}` | Chunk options in the chunk: `#| echo: false` |
| `fig.cap = "..."` | `#| fig-cap: "..."` |
| A label `(\#fig:delays)` and `\@ref(fig:delays)` | `#| label: fig-delays` and `@fig-delays` |
| `\@ref(tab:x)` | `@tbl-x` |
| A section label `{#intro}` and `\@ref(intro)` | `{#sec-intro}` and `@sec-intro` |
| `_bookdown.yml` and `index.Rmd` | `_quarto.yml`, with the chapters under `book: chapters:` |
| `\newpage` | `{{< pagebreak >}}` |

Labels in Quarto start with `fig-`, `tbl-`, `eq-` or `sec-`.
Quarto then numbers the figure, table, equation or section,
and the reference is a link.

The `ai-statement` field works in the same way in both systems.
See `?ai_statement`.

## Slides

The slides follow the PowerPoint template of the Institute (2025):

- the title slide, with the title in a white box and the square logo;
- a chapter slide for each `#` heading, with a panel on the right;
- a content slide for each `##` heading;
- a key figure, with `::: {.key-figure}`;
- a closing slide, with `## Thank you {.closing}`.

The template has a photo where these slides have a grey panel.
To show your own photo, give `title-photo: photo.jpg` in the header,
or a `photo` attribute on the heading: `# A chapter {photo="photo.jpg"}`.

The starter file makes two formats.
`iheid-slides-revealjs` makes a web page, and
`iheid-slides-pptx` makes a PowerPoint file with the layouts of the template.
In PowerPoint, you can then choose other layouts of the template,
such as the lists and key figures, and add photos.

## The visual identity

The templates follow the visual identity of the Institute (March 2025):
the institutional red (`#E2001A`) for titles and links,
black or grey for the text, and Arial.
Arial is on Windows and macOS.
On Linux, install it, or set another font with `mainfont` in the header.
