Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keep auxiliary TeX files when rendering a rmarkdown document

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?

like image 916
Martin Schmelzer Avatar asked Mar 28 '19 16:03

Martin Schmelzer


1 Answers

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).

like image 140
Yihui Xie Avatar answered Sep 18 '22 10:09

Yihui Xie