# Using LuaLaTeX and knitr together

I would like to include R results in a LuaLaTeX document, which I prefer over XeLaTeX mainly because of the greater support of the package microtype. Do you know whether and how is it possible?

Moreover, for more structured documents, I like to call the chapters' .tex files with the command \input in a master file, which is then compiled. Therefore, I would also like to know, in case you have a solution to the first problem, if it allows such tree structure.

I am especially interested in solutions that refer to Sweave files compilation.

There's an option to change the LaTeX engine with R Markdown:

https://rmarkdown.rstudio.com/pdf_document_format.html#latex_engine

• that is definetely interesting to compile Rmarkdown files, however I am interested in compiling Sweave files - I will update the question text. – oibaFox Feb 10 '18 at 15:16

The following works in RStudio, the front-end I use for R programming:

First I created a .Rprofile file containing the following line:

RSTUDIO_PDFLATEX = "LuaLaTeX"


This sets the RStudio environment variable to for the TeX engine.

On a Mac and Linux, this is normally just in your home folder, i.e., ~/.Rprofile

Then the default engine that knitr (and Sweave, I assume) will use will be LuaLaTeX.

Note that you cannot use the % !TeX program = LuaLaTeX directive since this line is parsed by RStudio, and it only recognizes pdfLaTeX and XeLaTeX as valid engines. These engines, however, will still work on a per-file basis using % !TeX program = pdfLaTeX or % !TeX program = XeLaTeX.

As to your second question, yes, your .Rnw file behaves just like any LaTeX document, and \input and similar commands are possible.