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.


2 Answers 2


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


  • 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, 2018 at 15:16

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

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


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

This file is normally in your home folder, i.e., ~/.Renviron

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.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .