Chapter 8 Multiple Output Formats

One main benefit of R Markdown is that it can create multiple output formats from a single source format, which could be one or multiple Rmd documents. For example, this book was written in R Markdown and compiled to three formats: PDF, ePub, and HTML.

Sometimes it can be challenging to make an output element of a code chunk work for all output formats. For example, it is extremely simple to create a rounded and circular image in HTML output with a single CSS rule (img { border-radius: 50%; }), but not so straightforward in LaTeX output (typically it will involve TikZ graphics).

Sometimes it is just impossible for an output element to work for all output formats. For example, you can easily create a GIF animation with the gifski package (see Section 3.11), and it will work perfectly for HTML output, but embedding such an animation in LaTeX output is not possible without extra steps of processing the GIF file and using extra LaTeX packages.

This chapter aims to provide several examples on how a document can be customized with output-specific features, while retaining the ability to export documents to multiple formats.