10

Is it possible to create multiple output formats from a Quarto/R Markdown document at once by specifying them in the YAML header?

My guess did not work:

---
title: Stacked Area chart with Annotations
format: 
  - html
  - gfm
---
dufei
  • 2,166
  • 1
  • 7
  • 18

1 Answers1

13

Try this way (and suppose file name is format_test.qmd)

format_test.qmd

---
title: "Untitled"
format:
  html: default
  gfm: default
---

## Quarto

Quarto enables you to weave together content and executable code
into a finished document. To learn more about Quarto 
see <https://quarto.org>.

## Running Code

When you click the **Render** button a document will 
be generated that includes both content and the output 
of embedded code. You can embed code like this:

```{r}
1 + 1
```

Then from console run this following code to generate both html and github flavoured markdown (gfm) file at once.

# install.packages("quarto")

quarto::quarto_render("format_test.qmd", output_format = "all")

Or if you prefer using the terminal (or if you are a non R-useR) you can run the following command in the terminal,

quarto render format_test.qmd --to html,gfm

Be careful to specify multiple formats without putting any space in between i.e. type them as html,gfm.

And running the above command in the terminal does not require you to specify format yaml option in your document. So, for

format_test.qmd

---
title: "Untitled"
---

## Quarto

Quarto enables you to weave together content and executable code
into a finished document. To learn more about Quarto 
see <https://quarto.org>.

quarto render format_test.qmd --to pdf,html,gfm

will generate three files in HTML, pdf, and markdown format.

shafee
  • 15,566
  • 3
  • 19
  • 47
  • In R Markdown [you can publish to multiple formats](https://stackoverflow.com/questions/44685485/specifying-multiple-simultaneous-output-formats-in-knitr-new) by including code similar to this in the yaml header,e.g. `knit: rmarkdown::render("format_test.rmd, output_format = "all")`. It seems like you should be able to do that in Quarto as well, but just substituting `quarto::quarto_render` for `rmarkdown::render` did not work. @dufei – Emmanuel Teitelbaum Jan 25 '23 at 15:44
  • 1
    Quarto doesn't have such knit hooks @EmmanuelTeitelbaum – shafee Jan 25 '23 at 15:49
  • Excellent answer. You may also wish to review the quarto documentation on this topic here: https://quarto.org/docs/get-started/authoring/rstudio.html – StatsStudent Feb 22 '23 at 20:03