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