6 HTML, PDF, and Word (and more!)
One of the great things about Quarto is that we can convert it to many different output types. The top three that you might be most likely to use are HTML, PDF, and Microsoft Word. There are other formats! But we can discuss later.
In this section, we are going to briefly discuss how to render to these output formats, and some things that you might want to do for each of them.
6.1 Overview
- Teaching: 10 minutes
- Exercises: 15 minutes
6.2 Questions
- How do I convert to HTML, PDF, or Word?
- How do I set options specific to each of these?
- How can I include a screenshot of an interactive graphic in PDF or Word?
- How to make a HTML page “self contained”?
6.3 Objectives
6.4 How do I convert to HTML, PDF, or Word?
Here are three ways to do this:
- You can control this in the “render” button
You might notice that depending on the option you select, this changes things in the YAML - which is another way to control which output you have:
- You can change the YAML option
title: "Exploring gapminder"
format: html
title: "Exploring gapminder"
format: pdf
title: "Exploring gapminder"
format: docx
- You can call the
quarto render
function - from the terminal if you wish
quarto render example.qmd --to html
quarto render example.qmd --to docx
6.4.1 A note on workflow with Quarto: HTML first, PDF/word later
It can be easy to get caught up with how your document looks. I highly recommend avoiding compiling to PDF or word until you really need to. This is also recommended by the author of rmarkdown and knitr, Yihui Xie. Because HTML doesn’t have page breaks, this means that you can spend time working on generating content, and not trying to get figures to line up correctly.
This was a minor revelation to me, to understand that page breaks were the cause of so much angst and pain. Embrace HTML, I say!
6.5 How to make a HTML page “self contained”
PDFs are great because they are a very Portable Document Format (PDF!). But HTML can be really awesome as well because:
- no page breaks
- awesome online interactive data vis
- did I mention no page breaks?
But in order to share a HTML document you’ll need to also typically share a folder of other figures/files etc.
You can have everything crammed into a single HTML page by setting the option embed-resources
to true
:
title: HTML is great
format:
html:
embed-resources: true
- Using your “01-qmd-examples.qmd” Quarto document you were using earlier, generate three reports, one as HTML, one as PDF, and one as microsoft word. Remember, if you are having PDF problems, see the installation chapter note on installing LaTeX with the R package,
tinytex
.