1.2 Install LaTeX (TinyTeX) 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 relatively small in size, 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 2020e):
Please note that “tinytex” refers to the R package, and “TinyTeX” refers to the LaTeX distribution. There are two advantages of using TinyTeX:
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.
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.
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. 2020e. Tinytex: Helper Functions to Install and Maintain Tex Live, and Compile Latex Documents. https://github.com/yihui/tinytex.
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.↩︎