Latexengine Engine to render latex, 'pdflatex', 'xelatex', or 'lualatex' X X libdir Directory of dependency files to use (Bootstrap, MathJax, etc.) X X X mathjax Set to local or a URL to use a local/URL version of MathJax to render X X X mdextensions Markdown extensions to add to default definition or R Markdown X X X X X X X X X X.
- R Markdown To Latex Converter
- R Markdown To Latex Transfer
- R Markdown Latex Template
- R Markdown Latex Cheat Sheet
- R Markdown To Latex Transfer
1.2 Install LaTeX (TinyTeX) for PDF reports


R Markdown To Latex Converter
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):
R markdownis a particular kind of markdown document. Authors should be cautious about following formatting advice for other types of markdown when working on R markdown. The distinguishing feature of R markdownis that it cooperates with R. Like LATEX with Sweave, code chunks can be included. When the document is compiled, the code is executed. There are many output formats supported by the R Markdown ecosystem and covering them all is unreasonable. So in this book we’ll stick primarily to four common output formats: HTML, LaTeX, Microsoft Word, and Microsoft PowerPoint. The RStudio IDE contains many helpful features for creating and editing R Markdown documents. Markdown and R Markdown. Markdown is a tool used to create formatted documents. Markdown source files, file type.md, contain text and formatting commands. Markdown's formatting commands are simpler than most other formatting languages, such as LaTeX or HTML, because it has a smaller number of features.
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.

R Markdown To Latex Transfer
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/.
Example
R-markdown code chunks
R-markdown is a markdown file with embedded blocks of R code called chunks. There are two types of R code chunks: inline and block.
Inline chunks are added using the following syntax:
They are evaluated and inserted their output answer in place.
Block chunks have a different syntax:
And they come with several possible options. Here are the main ones (but there are many others):
- echo (boolean) controls wether the code inside chunk will be included in the document
- include (boolean) controls wether the output should be included in the document
- fig.width (numeric) sets the width of the output figures
- fig.height (numeric) sets the height of the output figures
- fig.cap (character) sets the figure captions
They are written in a simple tag=value
format like in the example above.
R-markdown document example
Below is a basic example of R-markdown file illustrating the way R code chunks are embedded inside r-markdown.
Converting R-markdown to other formats
The R knitr
package can be used to evaluate R chunks inside R-markdown file and turn it into a regular markdown file.
The following steps are needed in order to turn R-markdown file into pdf/html:
- Convert R-markdown file to markdown file using
knitr
. - Convert the obtained markdown file to pdf/html using specialized tools like pandoc.

In addition to the above knitr
package has wrapper functions knit2html()
and knit2pdf()
that can be used to produce the final document without the intermediate step of manually converting it to the markdown format:
R Markdown Latex Template
If the above example file was saved as income.Rmd
it can be converted to a pdf
file using the following R commands:

The final document will be similar to the one below.
R Markdown Latex Cheat Sheet
R Markdown To Latex Transfer
