使用 YAML 标头在 Markdown 中使用自定义引用样式

J. *_*rew 6 yaml citations pandoc knitr r-markdown

我试图在降价文件中使用自定义引用样式,但每次编织时引用都使用默认(芝加哥)样式。我曾尝试将输出格式从 JS 显示演示文稿更改为 HTML 文档到 PDF 文档,但它仍然不起作用。我使用 knitcitations 包使用文档的 DOI 进行引用,并使用 bibliography() 函数编写参考书目。我也尝试使用 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()
```
Run Code Online (Sandbox Code Playgroud)

这个链接(http://rmarkdown.rstudio.com/authoring_bibliographies_and_citations.html)说我应该能够像这样格式化我的 YAML 标头:

---
title: "Sample Document"
output: html_document
bibliography: newbiblio.bib
csl: apa.csl
---
Run Code Online (Sandbox Code Playgroud)

但是,当我这样做时,文件会组合成一个降价 (.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
Run Code Online (Sandbox Code Playgroud)

我的 .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},
}
Run Code Online (Sandbox Code Playgroud)

我也不明白为什么 YAML 标头中的 biblio-style 选项不做任何事情。从本质上讲,我所需要的只是一种使用我已经用降价文档制作的自定义引用样式的方法。任何帮助将不胜感激!

Mic*_*per 4

如果没有可重现的示例,就很难确切地知道发生了什么,但看起来您正在混合两种不同的配置。

方法 1:指定自定义 CSL 文件

仅当您使用 pandoc-citeproc 时,使用 CSL 文件的方法才有效。例如,我已经下载了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
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

方法2:在Natbib中指定样式

如果您想使用 natbib 构建引文和参考书目,则必须使用该biblio-style选项。以下示例无需下载任何内容即可运行:

---
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
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

除非您有特殊原因,否则我可能会使用 pandoc-citeproc 和 csl 文件。它与 RMarkdown 世界完美集成。使用 Natbib 只会让人更加困惑,而且根据我的经验,更容易引发错误。