The problem:
I have several Rmarkdown documents representing different sections of my thesis (e.g. chapter 1 results, chapter 2 results), and I would like to combine the knitted latex versions of these documents with other TeX files into a master TeX 'thesis' document. The problem is, that when knitting to PDF and keeping the TeX file to include in the master TeX document, Rstudio auto-generates a bunch of preamble that ends up clashing with my preamble in the master.TeX document.
A less than ideal, workaround:
I have been working around this issue by deleting this preamble by hand before including the knitted output into the master.tex
file.
So far my current workflow is as follows:
- set the output to pdf_document in the YAML header, with the keep_tex option set to true.
- knitPDF using the Rstudio button
- delete the preamble at the beginning of the knitted TeX files by hand.
- include the files into my master.tex file using \include{}
The question:
I would like to convert Rmd to LaTeX, without having to delete the preamble manually before including the knitted TeX files into a master TeX file. How do I do this?
Sweave is not an option:
I'm sure I could achieve this by working with Sweave, however I like the flexibility of output formats that Rmarkdown offers: I can knit to html and view in my browser as I'm writing, to quickly view the progress of my work and ensure that there are no bugs, and I can also choose to knit to word to share with my supervisor who works only in word. Then, when I'm ready to compile everything into my master LaTeX document for printing, I can select knit to PDF in Rstudio to obtain the latex output.