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 2023e):

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 (2019) and the FAQ page at https://yihui.org/tinytex/faq/.

References

———. 2019. “TinyTeX: A Lightweight, Cross-Platform, and Easy-to-Maintain LaTeX Distribution Based on TeX Live.” TUGboat 40 (1): 30–32. https://tug.org/TUGboat/Contents/contents40-1.html.
———. 2023e. Tinytex: Helper Functions to Install and Maintain TeX Live, and Compile LaTeX Documents. https://github.com/rstudio/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.↩︎