使用 YAML 标头在 Markdown 中使用自定义引用样式 [英] Use custom citation style in markdown using YAML header

查看:187
本文介绍了使用 YAML 标头在 Markdown 中使用自定义引用样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在 Markdown 文件中使用自定义引用样式,但每次我编织时引用都使用默认(芝加哥)样式.我曾尝试将输出格式从 JS 显示演示文稿更改为 HTML 文档到 PDF 文档,但它仍然不起作用.我使用 knitcitations 包使用文档的 DOI 进行引用,并使用 bibliography() 函数编写参考书目.我也尝试使用 Zotero 上的 apa.csl 样式,但引用仍然以默认样式完成.apa.csl 文件与我尝试使用引文的文件存储在同一文件夹中,就像 newbiblio.bib 文件一样,我在其中存储了我想引用的项目的书目信息.

以下是我的降价代码:

---标题:htmlcitetest"引用包:natbibcsl: "apa.csl"输出:pdf_document:pandoc_args: ["--natbib"]书目风格:unsrt参考书目:newbiblio.bib---```{r 设置,包括 = FALSE}knitr::opts_chunk$set(echo = TRUE)图书馆(bibtex)图书馆(针织品)选项(引用格式"=pandoc")图书馆(RefManageR)清洁围兜()``## R 降价- 这是引文 [^1][^1]: `r citet("10.1098/rspb.2013.1372")````{r, message=FALSE}参考书目()``

此链接(

方法二:在Natbib中指定样式

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

---输出:pdf_document:引用包:natbib参考书目:test.bib书目风格:humannat---```{r}knitr::write_bib(x = c("knitr", "rmarkdown") , file = "test.bib")``一些参考 [@R-knitr]另一个参考 [@R-rmarkdown]# 参考

<块引用>

除非您有特殊原因,否则我可能会使用 pandoc-citeproc 和 csl 文件.它与 RMarkdown 世界很好地集成在一起.使用 Natbib 只会变得有点混乱,而且根据我的经验,更容易引发错误.

I am trying to use a custom citation style in a markdown file, but the citation uses the default (Chicago) style each time I knit. I have tried changing the output format from a JS reveal presentation to an HTML document to a PDF document, but it still does not work. I am using the knitcitations package to cite using the document's DOI, and the bibliography() function to write the bibliography. I have also tried using the apa.csl style found on Zotero, yet the citation is still done in the default styple. The apa.csl file is stored in the same folder as the file that I am trying to use citations in, as is the newbiblio.bib file, in which I have stored the bibliographical information for the item I want to cite.

Below is my markdown code:

---
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()
```

This link (http://rmarkdown.rstudio.com/authoring_bibliographies_and_citations.html) says that I should be able to format my YAML header like this:

---
title: "Sample Document"
output: html_document
bibliography: newbiblio.bib
csl: apa.csl
---

However, when I do that, the file knits to a markdown (.md) file, but it is not processed into the output. I recieve this error:

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

The contents of my .bib file are:

@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},
}

I also do not understand why the biblio-style option in the YAML header does not to do anything. Essentially, all I need is a way to use a custom citation style I have already made with a markdown document. Any help would be greatly appreciated!

解决方案

Without a reproducible example, it is hard to know exactly what is happening, but it looks like you are mixing two different configurations.

Method 1: Specifying a custom CSL file

The method of using a CSL file only works if you are using pandoc-citeproc. For example, I have downloaded the IEEE style, and saved it in the same directory as my RMarkdown file as ieee.csl. This MWE builds a separate bibliography file:

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

Method 2: Specifying styles in Natbib

If you want to use natbib to build the citations and bibliography, you have to use the biblio-style option. This following example should work without downloading anything:

---
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.

这篇关于使用 YAML 标头在 Markdown 中使用自定义引用样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆