Use bookdown to only generate .tex - figures not being generated

I am currently writing my thesis in bookdown. I have a rather long table, which only renders correctly if I create my PDF using latexmk, since tinytex::latexmk()'s emulated version seems to run xelatex too few times. I found, the global option to make that possible: options(tinytex.latexmk.emulation = FALSE)

However, since bookdown deletes all of the intermediate files generated by latexmk, the PDF often takes unnecessarily long to build. I can set the keep option keep_tex: yes, but I would like to keep all the files in the root of the project. I have dug around and found the function rmarkdown::latex_document() (in the documentation), and wanted to use that, thinking I could then just use a Makefile to first render the .tex-file and figures, and then run latexmk as I want afterwards. This however create problems, as rendering a bookdown-project using rmarkdown::latex_document() doesn't render the figures. I have a small example here:

title: "A Book"
author: "Frida Gomam"
site: bookdown::bookdown_site
documentclass: memoir
  rmarkdown::latex_document: default

# Hello World

Hi. Bye.

```{r message=FALSE, warning=FALSE}

tibble(a = runif(n = 10), b = runif(10)) %>% 
  ggplot(aes(a, b)) +

When I use the Build command in RStudio, this runs rmarkdown::render_site(encoding = 'UTF-8') and produces the .tex-file, but the corresponding figure is not created. How can this be changed?

It turns out, that this was a bug in rmarkdown::latex_document() (see

If your problem has been solved (even by you!), you can mark a post as the solution. This helps people who come along later searching for help with a similar problem.

1 Like