Rmarkdown Retain .Tex File

Rmarkdown Retain .tex file

You can specify it in your YML header with:

output:
pdf_document:
keep_tex: true
---

More options on the rmarkdown site.

Keep auxiliary TeX files when rendering a rmarkdown document

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

Is there a way to keep LaTeX citation keys in .tex file when knitting r-markdown to PDF

I found the solution... Changing the citation-package worked. The default pandoc-citeproc seems not to create the citation-key in the .tex file, but natbib does. I simply changed it with:

pdf_document:
keep_tex: yes
latex_engine: xelatex
citation_package: natbib

Now the .Rmd citations, like [@Smith1995], are converted to \citep{Smith1995} in the corresponding .tex file.
Another option might be biblatex.

How to convert Rmarkdown file to working latex file

Pandoc generates LaTeX snippets by default, i.e., not a full document. This can be changed by calling pandoc with the --standalone option:

rmarkdown::pandoc_convert(
"test.md",
to = "latex",
output = "out.tex",
options = "--standalone"
)

You can let R do the work and shorten your commands to

render("test.Rmd", output_format = "latex_document")

A project of interest might be rticles.

Where is the .tex file kept when compiling Rmd in Rstudio server

Actually, this first line in the console

/usr/lib/rstudio-server/bin/pandoc/pandoc test.utf8.md --to latex --from       markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures --output /tmp/Rtmpb1x3Q0/preview-3bfe24922427.dir/test.tex --template /home/myusername/R/x86_64-pc-linux-gnu-library/3.1/rmarkdown/rmd/latex/default.tex --highlight-style tango --latex-engine pdflatex --variable 'geometry:margin=1in' 

told us that the output .tex file is in /tmp/Rtmpb1x3Q0/preview-3bfe24922427.dir/test.tex
Somehow I did not find the file last time, but on a recent instance, the .tex file is actually there, so that answers the question.

Rmarkdown to LaTeX

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

Is there any possibility to save kable table in .tex or .markdown?

knitr::kable() returns a character vector, which you can definitely write to a file, e.g.,

df <- data.frame("X_1" = c(1, 2), "X_2" =c(3,4))
df <- knitr::kable(df, format = 'latex')
writeLines(df, 'df.tex')


Related Topics



Leave a reply



Submit