Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rmarkdown to LaTeX

I made a presentation in RStudio with RMarkdown/Knitr - it compiles without problems to a pdf (via LaTeX Beamer).

But I cannot get the LaTeX file. Is there any way to export also the LaTeX file which should be produced in the conversion?

like image 701
Revan Avatar asked Sep 14 '16 18:09

Revan


2 Answers

enter image description here In RStudio:

  • Click the gear - options button next to knit.
  • Click output options.
  • Click advanced.
  • Click Keep tex source file . . .

to answer the 1st comment, here is some sample LaTeX

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{DF <-}\KeywordTok{read.table}\NormalTok{(}
\DataTypeTok{text=}
\StringTok{"Year State Histadrut Private}
\StringTok{1985     27    26       47}
\StringTok{1993     10    14       76}
\StringTok{"}\NormalTok{,     }\DataTypeTok{header=}\OtherTok{TRUE}\NormalTok{)}

\KeywordTok{library}\NormalTok{(ggplot2)}
\KeywordTok{library}\NormalTok{(reshape2)}

produced by compiling

some simple RMD

```{r}
DF <-read.table(
text=
"Year State Histadrut Private
1985     27    26       47
1993     10    14       76
", header=TRUE)

library(ggplot2)
library(reshape2)
```

The output looks like: pdf output

like image 51
בנימן הגלילי Avatar answered Oct 05 '22 14:10

בנימן הגלילי


As of late 2018, the accepted answer above does not work (for me anyway). So this is a new answer for anyone who comes along looking for this question.

The accepted answer is close to what you need, but does not work in the current RStudio. In the current setup, I need to use the following code, in place of what is pictured above:

---
title: "Untitled"
author: "Author Person"
date: "November 26, 2018"
output: 
  pdf_document: 
    keep_tex: yes
---

This is similar to the originally accepted answer, but is formatted differently (indentation) and the pdf_document part has an ending colon. (Does indentation matter in YAML?)

Note that my answer is the YAML automatically inserted by the RStudio program when you follow the instructions above to use the GUI to make this setting. So I assume the formatting is in the preferred style.

However, as of 2018, the following does NOT work:

---
title: "Untitled"
author: "Author Person"
date: "November 26, 2018"
output: pdf_document
keep_tex: yes
---
like image 37
Doctorambient Avatar answered Oct 05 '22 15:10

Doctorambient