R code in LaTeX in YAML before_body include

流过昼夜 提交于 2019-12-07 12:08:55

问题


I have a LaTeX section that I put at the top of my knitr generated PDF document. I achieved this by using the YAML options

output:
    pdf_document: 
        includes: 
            before_body: file.tex

file.tex contains code like this

\textsf{Reporting: `r 2+2`}

but this doesn't work. Is there another way that I can get this value? Passing in a parameter is fine if that's possible.

Thanks!


回答1:


You have to knit file.tex. I suggest you rename file.tex, e.g., to file.Rnw, and in your main R Markdown document:

```{r, include=FALSE}
writeLines(knitr::knit_child('file.Rnw'), 'file.tex')
```


来源:https://stackoverflow.com/questions/49881851/r-code-in-latex-in-yaml-before-body-include

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