6

I am rendering two documents, that cross-reference items in each other. For that I am using the LaTeX package zref.

To make zref work, it needs the *.aux file of the documents which are created when calling pdflatex.

Unfortunately, using RStudio and its basic approach to render the document (the knit button, Cmd+Shift+K or rmarkdown::render()) these files will be deleted after the compilation was successful.

Unchecking the global option Tools -> Global Options -> Sweave -> Clean auxiliary output after compile does not help.

I know of two options to go around this:

  1. Manually compile the tex file after the pdf was rendered.

  2. Write a makefile that does that.

But is there another option I am not aware of?

Yihui Xie
  • 28,913
  • 23
  • 193
  • 419
Martin Schmelzer
  • 23,283
  • 6
  • 73
  • 98

1 Answers1

7

rmarkdown::render() eventually calls tinytex::latexmk() to compile the intermediate .tex to .pdf. To preserve auxiliary files, you need tinytex::latexmk(..., clean = FALSE). One way to set clean = FALSE is through the global option options(tinytex.clean = FALSE). You can set this in either your .Rprofile or a code chunk of your Rmd document.

The RStudio option you mentioned is only for Sweave documents (.Rnw).

Yihui Xie
  • 28,913
  • 23
  • 193
  • 419
  • Man I cannot wrap my head around that it works. Thanks! With all the stuff goin on around my RMD (`pandoc`, `rmarkdown`, `knitr`, `tinytex`) I sometimes do not see the obvious. – Martin Schmelzer Mar 29 '19 at 10:34
  • Would the same approach work for the manual that is build using devtools? I cannot find the tex files D: – Cris Mar 02 '20 at 23:11