Change bibliographystyle in R Markdown
Asked Answered
C

2

7

I want to change the bibliographystyle in R Markdown but nothing I found could help.

I do not want any "and"s in the bibliography (before the last author). My preferred option was if I could use alphadin (bst-file here) but I could not get it to work.

Here is my YAML so far:

---
output: 
  pdf_document
bibliography: literatur.bib
biblio-style: alphadin.bst
header-includes:
  - \usepackage{graphicx} 
  - \usepackage{float}       
  - \usepackage[ngerman]{babel} 
  - \usepackage{fancyhdr}
  - \usepackage{hyperref}
  - \pagenumbering{gobble}
  - \usepackage{booktabs}
  - \usepackage{natbib}  
---

The bst-file is in the same directory as the R Markdown file.

Centipede answered 26/4, 2018 at 17:21 Comment(0)
N
8

If you want to set the bibliography style to use a bst file, you need to force R Markdown to use natbib or biblatex as the citation manager. By default, it will use pandoc to build the citation. This article explains the behaviour more.

Secondly, once you have that working, you need to change the citation style of the file. By default, natbib will use author-year citations, but the bst file you provided does not work with these. So I have change the citation styles to numbers.

Below is a minimal example. It will create a bibliography file test.bib but you need to make sure the alphadin.bst file is in the same directory.

---
output: 
  pdf_document:
     citation_package: natbib
bibliography: test.bib
biblio-style: alphadin
header-includes:
  - \setcitestyle{numbers}
---

[@R-rmarkdown]

```{r}
knitr::write_bib(x = "rmarkdown", file = "test.bib")
```

enter image description here

Narration answered 26/4, 2018 at 20:14 Comment(3)
Thank you very much! It worked exactly like you said, I only had to write just "test" instead of "test.bib".Centipede
Done! Sorry, I didn't know the "accepted"-function ;)Centipede
@MichaelHarper I have a similar question here if you fancy having a look:Crenation
C
2

There is another way to set the citation style of natbib: natbiboptions: round in YAML. The combination of citation_package: natbib and natbiboptions: round is equivalent to \usepackage[round]{natbib}. Note that natbiboptions: round comes outside of the output key.

(In the following example, I used biblio-style: apalike but the example should work with any biblio-style.)

---
output: 
  pdf_document:
     citation_package: natbib
bibliography: test.bib
biblio-style: apalike
natbiboptions: round
---

[@R-rmarkdown]

```{r}
knitr::write_bib(x = "rmarkdown", file = "test.bib")
```
Chkalov answered 11/8, 2020 at 14:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.