我试图在markdown文件中使用自定义引文样式,但每次编织时引文都使用默认(芝加哥)样式.我已经尝试将输出格式从JS显示演示文稿更改为
HTML文档到PDF文档,但它仍然无效.我正在使用knitcitations包来引用文档的DOI,以及参考书目()函数来编写参考书目.我也尝试使用Zotero上的apa.csl样式,但引用仍然在默认的样式中完成. apa.csl文件存储在与我尝试使用引文的文件相同的文件夹中,newbiblio.bib文件也是如此,我在其中存储了我想引用的项目的书目信息.
以下是我的降价代码:
---
title: "htmlcitetest"
citation_package: natbib
csl: "apa.csl"
output:
pdf_document:
pandoc_args: ["--natbib"]
biblio-style: unsrt
bibliography: newbiblio.bib
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(bibtex)
library(knitcitations)
options("citation_format" = "pandoc")
library(RefManageR)
cleanbib()
```
## R Markdown
- This is a citation [^1]
[^1]: `r citet("10.1098/rspb.2013.1372")`
```{r, message=FALSE}
bibliography()
```
这个链接(http://rmarkdown.rstudio.com/authoring_bibliographies_and_citations.html)
说我应该能够像这样格式化我的YAML标题:
---
title: "Sample Document"
output: html_document
bibliography: newbiblio.bib
csl: apa.csl
---
但是,当我这样做时,文件编织到markdown(.md)文件,但它不会被处理到输出中.我收到这个错误:
pandoc-citeproc: 23:3-23:10: Expected end element for: Name {nameLocalName = "category", nameNamespace = Just "http://purl.org/net/xbiblio/csl", namePrefix = Nothing}, but received: EventEndElement (Name {nameLocalName = "info", nameNamespace = Just "http://purl.org/net/xbiblio/csl", namePrefix = Nothing})
pandoc: Error running filter /Applications/RStudio.app/Contents/MacOS/pandoc/pandoc-citeproc
Filter returned error status 1
Error: pandoc document conversion failed with error 83
Execution halted
我的.bib文件的内容是:
@Article{Boettiger_2013,
doi = {10.1098/rspb.2013.1372},
url = {http://dx.doi.org/10.1098/rspb.2013.1372},
year = {2013},
month = {jul},
publisher = {The Royal Society},
volume = {280},
number = {1766},
pages = {20131372--20131372},
author = {C. Boettiger and A. Hastings},
title = {No early warning signals for stochastic transitions: insights from large deviation theory},
journal = {Proceedings of the Royal Society B: Biological Sciences},
}
我也不明白为什么YAML标题中的biblio风格选项不会做任何事情.基本上,我只需要一种方法来使用我已经用降价文档制作的自定义引文样式.任何帮助将不胜感激!
最佳答案 如果没有可重复的示例,很难确切知道发生了什么,但看起来您正在混合两种不同的配置.
方法1:指定自定义CSL文件
使用CSL文件的方法仅在使用pandoc-citeproc时才有效.例如,我已经下载了IEEE样式,并将其保存在与我的RMarkdown文件相同的目录中,如ieee.csl.这个MWE构建了一个单独的参考书目文件:
---
output: pdf_document
bibliography: test.bib
csl: ieee.csl
---
```{r}
knitr::write_bib(x = c("knitr", "rmarkdown") , file = "test.bib")
```
Some ref [@R-knitr]
Some again [@R-knitr]
Another ref [@R-rmarkdown]
# References
方法2:在Natbib中指定样式
如果您想使用natbib来构建引文和参考书目,您必须使用biblio风格的选项.以下示例应该无需下载任何内容:
---
output:
pdf_document:
citation_package: natbib
bibliography: test.bib
biblio-style: humannat
---
```{r}
knitr::write_bib(x = c("knitr", "rmarkdown") , file = "test.bib")
```
Some ref [@R-knitr]
Another ref [@R-rmarkdown]
# References
Unless you have a particular reason, I would probably go down the route of using pandoc-citeproc and a csl file. It integrates well with the RMarkdown world. Using Natbib just gets a bit more confusing, and from my experience is more prone to throwing errors.