本文介绍了如何在R markdown中没有前导的情况下生成LaTeX文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个LaTeX文档,该文档被拆分为多个 .tex 文件.

I have a LaTeX document that is split to multiple .tex files.

我正在使用R降价生成图形和表格.

I'm using R markdown to generate figures and tables.

是否可以从.Rmd生成.tex文件而不使用前导,这样我就可以只使用文档中的输出了?当前,我需要将部分输出手动复制到我的.tex文件中

Is it possible to generate .tex file from .Rmd without preamble, so that I will be able to just use output in my document? Currently, I need to manually copy part of the output to my .tex file

推荐答案

让我们假设您的子文档名为child.Rmd,并具有以下内容.

Let's suppose your child document is named child.Rmd and has the following contents.

```{r pressure, echo=FALSE, dev='pdf'}
plot(pressure)
```

运行

knitr::knit("child.Rmd")

,您将得到figure/pressure-1.pdfchild.md.然后运行

and you get figure/pressure-1.pdf and child.md. Then run

rmarkdown::pandoc_convert("child.md", to = "latex", output = "child.tex")

生成的child.tex文件内部仅包含\begin{figure} ~~ \end{figure}块.我希望这是理想的结果.

Resulting child.tex file only contains \begin{figure} ~~ \end{figure} block inside. I hope this is the desired result.

如果您没有充分的理由使用RMarkdown,我建议您使用R Sweave. knitr支持子文档

If you don't have a strong reason to use RMarkdown, I'd recommend R Sweave; knitr supports child documents

更新,您不必从Rmd文件中删除YAML标头;上面的knitr::knitrmarkdown::pandoc_convert组合将忽略YAML标头.看看此要点.运行run_this.R脚本,child.Rmd将转换为child.tex.您当然可以正常地将此Rmd文件呈现为html.

UPDATE You didn't have to remove YAML header from your Rmd file; the above knitr::knit and rmarkdown::pandoc_convert combination ignores the YAML header. Take a look at this gist. Run run_this.R script and child.Rmd will be converted to child.tex. You can of course render this Rmd file to html normally.

这篇关于如何在R markdown中没有前导的情况下生成LaTeX文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 05:02