我正在使用RMarkdown
生成包含引用后的附录的报告。我将附录写在另一个RMarkdown
文件上,并修改了我的主体文件以进行编译。这是生成报告的主要Rmd文件的代码:
---
bibliography: bb.bib
fontsize: 11pt
nocite: '@*'
output:
pdf_document:
includes:
after_body: Demo2.Rmd
keep_tex: yes
link-citations: true
---
\newpage
\section{Testing}\label{sec1}
```{r}
summary(cars)
```
\section{Demo}
This was done using @shiina and we will use some info from Section \ref{sec1} to do.
```{r}
summary(iris[,1:2])
```
\section{References}
文件
bb.bib
包含以下引用:@article {shiina,
author = {Shiina, Takayuki and Birge, John R.},
title = {Stochastic unit commitment problem},
journal = {International Transactions in Operational Research},
volume = {11},
number = {1},
publisher = {Blackwell Publishing},
pages = {19--32},
year = {2004},
}
@book{groewe2001,
title={Stochastic unit commitment in hydro-thermal power production planning},
author={Gr{\"o}we-Kuska, N. and R{\"o}misch, W.},
year={2001},
series = { Preprints aus dem Institut f{\"u}r Mathematik },
publisher = { Humboldt-Universit{\"a}t zu Berlin, Institut f{\"u}r Mathematik },
}
最后,我的附录Rmd文件
Demo2.Rmd
包含以下结构:\appendix
\section*{Appendix}
\section{Additional info}
In this section we also follow @shiina to explain concepts.
编译可以正常工作并生成文档,但是附录部分中出现了问题。我使用带有
@shiina
的引用来引用某些内容,但是我在最终报告中得到了以下输出:黑色圆圈表示书目引文无效。代替
@shiina
,它应显示为Shiina and Birge (2004)
。我尝试用TeX文件替换Rmd文件,但是没有用。有什么办法可以纠正吗?,我不知道是否需要调整
after_body
或该怎么做。 最佳答案
因此,我确实找到了一个使用一些小技巧的解决方案。
---
bibliography: bb.bib
fontsize: 11pt
nocite: '@*'
output:
pdf_document:
keep_tex: true
includes:
after_body: Demo2.tex
link-citations: true
---
```{r,include=FALSE}
library(tidyverse)
rmarkdown::render('Demo2.Rmd')
a <- readChar('Demo2.tex', file.size('Demo2.tex'))
a <- a %>% str_remove('[[:space:]]*\\\\hypertarget[[\\w\\W]]+\\z') %>%
str_remove('\\A[[\\w\\W]]+begin.document.')
writeChar(a, 'Demo2.tex',eos = NULL)
```
\newpage
\section{Testing}\label{sec1}
```{r}
summary(cars)
```
\section{Demo}
This was done using @shiina and we will use some info from Section \ref{sec1} to do.
```{r}
summary(iris[,1:2])
```
\section{References}
和您的附录文件:
---
bibliography: bb.bib
fontsize: 11pt
output:
pdf_document:
keep_tex: yes
link-citations: true
---
\appendix
\section*{Appendix}
\section{Additional info}
In this section we also follow @shiina to explain concepts.
# References
结果是:
它的工作方式是在渲染实际文件之前先渲染
Demo2.Rmd
-文件,并保留关联的.tex
-文件。然后,我们不希望在主文件末尾包含所有不包含在内的所有部分的R块切割,并覆盖
Demo2.tex
文件。剩下的就是使引用正常工作所需的确切
tex
代码。感觉很脏,但应该可以。