Quarto Essentials

Bogdan G. Popescu

John Cabot University

Introduction

What is Quarto

Quarto - open-source publishing system designed for creating dynamic, reproducible documents, including reports, presentations, and websites.

It supports multiple formats like HTML, PDF, Word, and slides.

Why Use Quarto?

  • Integrates well with R, Python, and Julia.
  • Enables embedding of code chunks directly in documents for dynamic content generation.
  • Facilitates reproducibility by linking code and results seamlessly.

Quarto Document Structure

YAML Header

  • The YAML header defines the document metadata, such as title, author, date, and output format.
---
title: "Statistical Analysis Report"
author: "Your Name"
date: "2024-11-05"
format: html
---

# Introduction

This is an example.

Quarto Document Structure

YAML Header

  • The YAML header defines the document metadata, such as title, author, date, and output format.
---
title: "Statistical Analysis Report"
author: "Your Name"
date: "2024-11-05"
format: html
---

# Introduction

This is an example.

Creating HTML Output

Basic YAML Configuration

To generate an HTML file, specify format: html in the YAML header.

Rendering the Document:

Use quarto render in R to generate the output.

Adding a Table of Contents

Enabling TOC:

  • Add toc: true in the YAML header to automatically generate a table of contents.

  • Control depth with toc-depth (e.g., 2 for two levels of headings).

---
title: "Statistical Analysis Report"
author: "Your Name"
date: "2024-11-05"
format: html
toc: true
---

# Introduction

This is an example.

Adding a Table of Contents

Customization

  • Rename the title with toc-title: "Contents".
---
title: "Statistical Analysis Report"
author: "Your Name"
date: "2024-11-05"
format: html
toc: true
toc-title: "Contents"
---

# Introduction

This is an example.

Equations

You can easily add inline equations in the following way

---
title: "Statistical Analysis Report"
author: "Your Name"
date: "2024-11-05"
format: html
toc: true
toc-title: "Contents"
---

# Introduction

This is an example.

This is an equation: $E=mc^{2}$

Equations

You can easily add inline equations in the following way

---
title: "Statistical Analysis Report"
author: "Your Name"
date: "2024-11-05"
format: html
toc: true
toc-title: "Contents"
---

# Introduction

This is an example.

This is an equation: $E=mc^{2}$

This is also an equation: 

$$E=mc^{2}$$

Equations

You can easily add inline equations in the following way

---
title: "Statistical Analysis Report"
author: "Your Name"
date: "2024-11-05"
format: html
toc: true
toc-title: "Contents"
---

# Introduction

This is an example.

This is an equation: $E=mc^{2}$

This is also an equation: 

$$E=mc^{2}$$

For more advanced equations, check: https://qmd4sci.njtierney.com/math

Code

Embedding Code

This is how we include code in our documents.

---
title: "Statistical Analysis Report"
author: "Your Name"
date: "2024-11-05"
format: html
toc: true
toc-title: "Contents"
---

# Introduction

This is an example.

This is an equation: $E=mc^{2}$

This is also an equation: 

$$E=mc^{2}$$

```{r}
summary(mtcars)
```

Code

Embedding Code

This is how we include code in our documents.

---
title: "Statistical Analysis Report"
author: "Your Name"
date: "2024-11-05"
format: html
toc: true
toc-title: "Contents"
---

# Introduction

This is an example.

This is an equation: $E=mc^{2}$

This is also an equation: 

$$E=mc^{2}$$

```{r echo=TRUE, eval=TRUE}
summary(mtcars)
```

Code

Embedding Code

This is how we only include code output in our documents.

---
title: "Statistical Analysis Report"
author: "Your Name"
date: "2024-11-05"
format: html
toc: true
toc-title: "Contents"
---

# Introduction

This is an example.

This is an equation: $E=mc^{2}$

This is also an equation: 

$$E=mc^{2}$$

```{r echo=FALSE, eval=TRUE}
summary(mtcars)
```

Code

Embedding Code

This is how we only include code without output in our documents.

---
title: "Statistical Analysis Report"
author: "Your Name"
date: "2024-11-05"
format: html
toc: true
toc-title: "Contents"
---

# Introduction

This is an example.

This is an equation: $E=mc^{2}$

This is also an equation: 

$$E=mc^{2}$$

```{r echo=TRUE, eval=FALSE}
summary(mtcars)
```

Code

Embedding Code

Many times you might have seen annoying library messages:

---
title: "Statistical Analysis Report"
author: "Your Name"
date: "2024-11-05"
format: html
toc: true
toc-title: "Contents"
---

# Introduction

This is an example.

This is an equation: $E=mc^{2}$

This is also an equation: 

$$E=mc^{2}$$

```{r echo=TRUE, eval=FALSE}
summary(mtcars)
```

```{r}
library(dplyr)
```

Code

Embedding Code

To avoid them in printing, you should do:

---
title: "Statistical Analysis Report"
author: "Your Name"
date: "2024-11-05"
format: html
toc: true
toc-title: "Contents"
---

# Introduction

This is an example.

This is an equation: $E=mc^{2}$

This is also an equation: 

$$E=mc^{2}$$

```{r echo=TRUE, eval=FALSE}
summary(mtcars)
```

```{r warning=FALSE, message=FALSE}
library(dplyr)
```

Embedding Resources

What is Self-Contained HTML?:

An HTML document that includes all dependencies (images, CSS, JavaScript) within a single file.

Why Use It?

Easy to share and view without requiring external resources.

This means that you will only see an html document being produced.

Embedding Resources

This a complicated document (with formulae, graphs) without resource-embedding.

---
title: "Statistical Analysis Report"
author: "Your Name"
date: "2024-11-05"
format: html
toc: true
toc-title: "Contents"
---

# Introduction

This is an example.

This is an equation: $E=mc^{2}$

This is also an equation: 

$$E=mc^{2}$$

```{r echo=TRUE, eval=FALSE}
summary(mtcars)
```

```{r}
library(dplyr)
```

Embedding Resources

This a complicated document (with formulae, graphs) with resource-embedding.

---
title: "Statistical Analysis Report"
author: "Your Name"
date: "2024-11-05"
format: html
toc: true
toc-title: "Contents"
embed-resources: true
---

# Introduction

This is an example.

This is an equation: $E=mc^{2}$

This is also an equation: 

$$E=mc^{2}$$

```{r echo=TRUE, eval=FALSE}
summary(mtcars)
```

```{r}
library(dplyr)
```

Text Formatting

This is how we format text within our document.

---
title: "Statistical Analysis Report"
author: "Your Name"
date: "2024-11-05"
format: html
toc: true
toc-title: "Contents"
---

# Introduction

```{r echo=TRUE, eval=FALSE}
summary(mtcars)
```

*This is italic text.*

**This is bold text.**

***This is bold and italic.***

This is reference to a `qmd` document.

Headings

This is how we add headings and subheadings.

---
title: "Statistical Analysis Report"
author: "Your Name"
date: "2024-11-05"
format: html
toc: true
toc-title: "Contents"
---

# Introduction

```{r echo=TRUE, eval=FALSE}
summary(mtcars)
```

The following are headers:

# Header 2
## Subheader 1
### Sub-subheader 1

Headings

This is how we can automatically number the headers.

---
title: "Statistical Analysis Report"
author: "Your Name"
date: "2024-11-05"
format: html
toc: true
toc-title: "Contents"
number-sections: true
---

# Introduction

```{r echo=TRUE, eval=FALSE}
summary(mtcars)
```

The following are headers:

# Header
## Subheader
### Sub-subheader

Headings

This is how we can remove some headers from being numbered.

---
title: "Statistical Analysis Report"
author: "Your Name"
date: "2024-11-05"
format: html
toc: true
toc-title: "Contents"
number-sections: true
---

# Introduction

```{r echo=TRUE, eval=FALSE}
summary(mtcars)
```

The following are headers:

# Header
## Subheader {.unnumbered}
### Sub-subheader {.unnumbered}

Headings

This is how we can remove some headers from being numbered and from the Table of Contents

---
title: "Statistical Analysis Report"
author: "Your Name"
date: "2024-11-05"
format: html
toc: true
toc-title: "Contents"
number-sections: true
---

# Introduction

```{r echo=TRUE, eval=FALSE}
summary(mtcars)
```

The following are headers:

# Header
## Subheader {.unnumbered .unlisted}
### Sub-subheader {.unnumbered .unlisted}

Pictures

This is how we add pictures.

---
title: "Statistical Analysis Report"
author: "Your Name"
date: "2024-11-05"
format: html
toc: true
toc-title: "Contents"
---

# Introduction

This is how we can include pictures:

![](figures/elephant.png){width="50%"}

Lists

This is how we add lists.

---
title: "Statistical Analysis Report"
author: "Your Name"
date: "2024-11-05"
format: html
toc: true
toc-title: "Contents"
---

# Introduction

* unordered list
  + sub-item 1
  + sub-item 2
    - sub-sub-item 1

1. ordered list
2. item 2
    i) sub-item 1
         A.  sub-sub-item 1

Tables

This is how we add tables.

---
title: "Statistical Analysis Report"
author: "Your Name"
date: "2024-11-05"
format: html
toc: true
toc-title: "Contents"
---

# Introduction

This is a table.

| Right | Left | Default | Center |
|------:|:-----|---------|:------:|
|    12 | 12   | 12      |   12   |
|   123 | 123  | 123     |  123   |
|     1 | 1    | 1       |   1    |

Diagrams

Quarto has native support for embedding Mermaid and Graphviz diagrams.

This enables you to create flowcharts, sequence diagrams, state diagrams.

---
title: "Statistical Analysis Report"
author: "Your Name"
date: "2024-11-05"
format: html
toc: true
toc-title: "Contents"
---

# Introduction

This is a diagram.

```{mermaid}
%%| echo: fenced
flowchart LR
  A[Hard edge] --> B(Round edge)
  B --> C{Decision}
  C --> D[Result one]
  C --> E[Result two]
```

Videos

You can include videos in documents using the {{< video >}} shortcode. For example, here we embed a YouTube video:

Videos can refer to video files (e.g. MPEG) or can be links to videos published on YouTube, Vimeo, or Brightcove.

{{< video https://www.youtube.com/embed/wo9vZccmqwc >}}

Callout Blocks

Markdown Syntax

:::{.callout-note}
Note that there are five types of callouts, including: 
`note`, `tip`, `warning`, `caution`, and `important`.
:::

Output

Note

Note that there are five types of callouts, including note, tip, warning, caution, and important.

Word Basics

In order to create Word docs you will need to install:

Terminal
quarto tools install chromium

Word Basics

In order to create Word docs you will need to install:

Terminal
quarto tools install chromium

Word Basics

In order to create Word docs you will need to install:

Terminal
quarto tools install chromium