How can I specify global and local chunk options for a quarto pdf book?

Viewed 442

I am trying to create a PDF book using Quarto. In particular, I want to know if there is a way to specify the global chunk options, which would be used for all the chunks in all the qmd pages. The global option is

echo = TRUE

(I think this syntax is in R Markdown, not Quarto.) But only for some code chunks in some of the pages, I want to hide the code (by setting echo = FALSE). How can I do this?

1 Answers

Setting Global Options

In quarto documents, books or presentation, to set options like echo, eval, warning, error, include, output globally, we need to specify them under execute yaml key.

So in quarto book, to set echo to true globally, we set echo: true under execute.

_quarto.yml

project:
  type: book
  
execute: 
  echo: true

book:
  title: "Quarto book"
  author: "Jane Doe"
  date: "8/7/2022"
  chapters:
    - index.qmd
    - intro.qmd
    - summary.qmd
    - references.qmd

bibliography: references.bib

format:
  pdf:
    documentclass: scrreprt

Setting local options

And setting these options locally (for some specific chunk in a specific qmd page) is same as r-markdown.

Say in my index.qmd, I can specify echo=FALSE for a chunk like this,

index.qmd

# Preface {.unnumbered}

This is a Quarto book.

To learn more about Quarto books visit <https://quarto.org/docs/books>.

```{r echo=FALSE}
1 + 1
```
Related