我在R中使用knitr包和pandoc将.Rmd文件转换为PDF.Pandoc链接到.bib文件并自动在PDF末尾插入参考书目.bib文件中的条目如下所示,取自http://johnmacfarlane.net/pandoc/demo/biblio.bib:
@Book{item1,
author="John Doe",
title="First Book",
year="2005",
address="Cambridge",
publisher="Cambridge University Press"
}
@Article{item2,
author="John Doe",
title="Article",
year="2006",
journal="Journal of Generic Studies",
volume="6",
pages="33-34"
}
Run Code Online (Sandbox Code Playgroud)
为了构建我的参考书目,我使用以下函数,取自:http://quantifyingmemory.blogspot.co.il/2013/02/reproducible-research-with-r-knitr.html
knitsPDF <- function(name) {
library(knitr)
knit(paste0(name, ".Rmd"), encoding = "utf-8")
system(paste0("pandoc -o ", name, ".pdf ", name, ".md --bibliography /Users/.../Desktop/test.bib --csl /Users/.../Desktop/taylor-and-francis-harvard-x.csl"))
}
Run Code Online (Sandbox Code Playgroud)
我的.Rmd文件的内容是:
This is some text [@item1]
This is more text [@item2]
# References
Run Code Online (Sandbox Code Playgroud)
输出的PDF看起来像这样:

如果我尝试插入附录,则引用仍会在文档末尾打印,如下所示:

如何在引用后插入附录?
[我的环境:Win 7 Pro/R 3.2.1/knitr_1.12.3/R Studio版本0.99.892]
我正在尝试.Rmd使用R Studio,Knit - > PDF格式撰写文章,我一直关注http://rmarkdown.rstudio.com/authoring_bibliographies_and_citations.html,详细了解如何获取pandoc和pandoc-citeproc制作参考文献部分和引文中的文字.
我的中文提供参考是在几个不同的.bib文件,这些文件在使用乳胶时.Rnw的文件,都是在发现我的本地texmf目录树下通过
\bibliography{statistics, graphics}
Run Code Online (Sandbox Code Playgroud)
我似乎无法使这项工作pandoc-citeproc.我的YAML标头具有以下内容,适用于一个 .bib文件,只要它与源.Rmd文件位于同一目录中:
---
title: "Notes on Testing Equality of Covariance Matrices"
author: "Michael Friendly"
date: '`r format(Sys.time(), "%B %d, %Y")`'
output:
pdf_document:
fig_caption: yes
keep_tex: yes
number_sections: yes
csl: apa.csl
bibliography: statistics.bib
---
Run Code Online (Sandbox Code Playgroud)
根据上面给出的链接中的建议,我试过:
bibliography: [statistics.bib,graphics.bib]
Run Code Online (Sandbox Code Playgroud)
这给了:
pandoc-citeproc.exe: "stdin" (line 50, column 12):
unexpected ":"
expecting letter, …Run Code Online (Sandbox Code Playgroud) 我想在 Rmarkdown 文档中包含主要文本和补充文本的单独参考部分。这里和这里建议的方法在很大程度上有效,但如果两个指定的 .bib 文件中都出现了引用,那么它们就会出现在两个列表中,即使它们仅在一个部分中被引用。
我通过重命名第二个 .bib 文件中的键,然后在补充中使用更改后的引文键来解决这个问题。这是有效的,直到我在正文和补充中引用了同一篇论文。然后它们被解释为不同的引文,因此它们被标记为“a”和“b”,例如(Smith et al. 2000a)和(Smith et al. 2000b),即使它们是完全相同的参考文献。
我通过在第二个 .bib 文件中仅包含补充中引用的那些参考文献来解决这个问题。如果这些参考文献也在正文中被引用,我将不修改它们,但如果它们仅出现在补充中,那么我会修改引用键。然后修改后的键仅在第二个参考书目中生成外观。这似乎可行,但很麻烦(如果添加或删除文本引用等,则容易出错)。
有没有更好的办法?我想要的是指定一个 .bib 文件,其中包括将引用的任何可能的参考文献(加上更多 - 它链接到 Zotero,我使用该citr包插入引用)。然后我想要某种方法来重置扫描引文的范围。例如,我有
---
bibliography: "My Library.bib"
output:
bookdown::pdf_book:
fig_caption: yes
df_print: paged
number_sections: no
pandoc_args: --lua-filter=multiple-bibliographies.lua
toc: no
keep_tex: true
base_format: rticles::elsevier_article
---
# Main text
A bunch of text here with citations.
<!-- list all citation (and only those) occurring before the "\restartbib" function. -->
# Refereneces
::: {#refs}
:::
\restartbib
# …Run Code Online (Sandbox Code Playgroud) 我想引用一个项目中使用的 R 包,但由于它们相当多,我认为创建两个单独的参考部分是个好主意:一个包含我特定领域的引用,一个包含 R 的引用包。
我的第一个想法是检查我是否可以在 .bib 文件中一次导出所有使用的包的引用,但我不确定 R Markdown 可以处理 .bib 文件和特定于我的论文的参考书目域和 R 包的 .bib 文件。
由于函数citation()或toBibtex()生成 Bibtex 引文,我认为可以直接在 .Rmd 文件中使用这些函数生成专用于 R 包的参考部分。但是,当这些命令包含在带有 R Markdown 的块中时,似乎不可能自动格式化引用。
这是我正在尝试做的事情的可重现示例:
---
title: "Cite R packages"
author: ""
date: "01/02/2020"
output: pdf_document
bibliography: test.bib
---
This is a citation of a paper: @mayer2011.
# Bibliography {-}
\setlength{\parindent}{-0.2in}
\setlength{\leftskip}{0.2in}
\noindent
<div id="refs"></div>
```{r refmgr references, results="asis", echo=FALSE}
# Print
```
\setlength{\parindent}{0in}
\setlength{\leftskip}{0in}
\setlength{\parskip}{0pt}
# Bibliography for R packages {-}
```{r} …Run Code Online (Sandbox Code Playgroud) [仅供参考:这个问题与 rmarkdown 有关:如何为文档使用多个参考书目
在 LaTeX 文档甚至 Rmarkdown 中.Rnw,我可以简单地使用类似的东西
\bibliography{graphics, statistics, timeref}
Run Code Online (Sandbox Code Playgroud)
让 BibTeX
在我的本地目录下搜索文件graphics.bib、statistics.bib、 和。timeref.bibtexmf
在.Rmd使用yaml标题的文件中,我被迫使用绝对路径(不可移植)或相对路径(笨重、容易出错)列出每个参考书目文件。这是最近的一个例子:
---
title: "My Cool Paper"
author: "Me"
date: "`r format(Sys.time(), '%d %B, %Y')`"
output:
html_document
bibliography:
- "../../../localtexmf/bibtex/bib/graphics.bib"
- "../../../localtexmf/bibtex/bib/statistics.bib"
- "../../../localtexmf/bibtex/bib/timeref.bib"
---
Run Code Online (Sandbox Code Playgroud)
问题:就像我可以r format(Sys.time(), '%d %B, %Y')使用 R 来填写日期一样,我可以使用一些 R 表达式来查找/填写 .bib 文件的路径吗bibliography:?
好的,从前面的问题来看,我尝试使用
bibliography:
- "`r system('kpsewhich graphics.bib')`"
- "`r system('kpsewhich statistics.bib')`" …Run Code Online (Sandbox Code Playgroud)