1.2 Install LaTeX for PDF reports

If you would like to create PDF documents from R Markdown, you will need to have a LaTeX distribution installed. Although there are several traditional options including MiKTeX, MacTeX, and TeX Live, we recommend that R Markdown users install TinyTeX.

TinyTeX is a custom LaTeX distribution based on TeX Live that is small in size (150Mb on macOS/Linux and 220Mb on Windows when installed) but functions well in most cases, especially for R users. Installing or running TinyTeX does not require sysadmin privileges.1 You can install TinyTeX with the R package tinytex (Xie 2020d):

tinytex::install_tinytex()
# to uninstall TinyTeX, run tinytex::uninstall_tinytex()

Please note that “tinytex” refers to the R package, and “TinyTeX” refers to the LaTeX distribution. There are two advantages of using TinyTeX:

  1. TinyTeX is lightweight (compared to other LaTeX distributions), cross-platform, and portable. For example, you can store a copy of TinyTeX on your USB drive or other portable devices, and use it on other computers with the same operating system.

  2. When R Markdown is converted to PDF, Pandoc converts Markdown to an intermediate LaTeX document first. The R package tinytex has provided helper functions to compile LaTeX documents to PDF (the main function is tinytex::latexmk()). If you use TinyTeX and certain LaTeX packages are required but not installed, tinytex will try to automatically install them for you. It will also try to compile the LaTeX file for a sufficient number of times to make sure all cross-references are resolved.

If you are interested in the technical details, you may check out the article Xie (2019b) and the FAQ page at https://yihui.org/tinytex/faq/.

References

Xie, Yihui. 2019b. “TinyTeX: A Lightweight, Cross-Platform, and Easy-to-Maintain Latex Distribution Based on Tex Live.” TUGboat, no. 1: 30–32. http://tug.org/TUGboat/Contents/contents40-1.html.

Xie, Yihui. 2020d. Tinytex: Helper Functions to Install and Maintain Tex Live, and Compile Latex Documents. https://github.com/yihui/tinytex.


  1. Actually, we recommend that you do not use your root privilege (i.e., sudo) to install TinyTeX on Linux or macOS, if you are the only user of your system.↩︎