Rmarkdown to LaTeX

风格不统一 提交于 2019-12-04 10:47:32

问题


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?


回答1:


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:




回答2:


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


来源:https://stackoverflow.com/questions/39497696/rmarkdown-to-latex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!