Reputation: 694
The top voted answer to this question, How to move the bibliography in markdown/pandoc, says that you can control the location of the references in rmarkdown/pandoc by adding <div id="refs"></div>
where the references are supposed to appear. This does not work in the pdf_book format from the bookdown package if _output.yml contains a pdf_book output. An example is a directory containing two files:
_output.yml
bookdown::gitbook:
bookdown::pdf_book:
latex_engine: xelatex
citation_package: natbib
keep_tex: yes
index.Rmd
---
title: "An example"
author: "Me"
date: "`r Sys.Date()`"
site: bookdown::bookdown_site
documentclass: book
bibliography: [packages.bib]
biblio-style: apalike
link-citations: yes
---
# Prerequisites
```{r include=FALSE}
# automatically create a bib database for R packages
knitr::write_bib(c(
.packages(), 'bookdown'
), 'packages.bib')
```
I want references *here*
<div id="refs"></div>
# Introduction
We are using the **bookdown** package [@R-bookdown].
Calling bookdown::render_book(output_format = 'bookdown::pdf_book')
creates a pdf file that has references at the end of the document, not at the location specified by <div id="refs"></div>
. In contrast calling bookdown::render_book(output_format = 'bookdown::gitbook')
does place the references at the specified location.
If I delete _output.yml or delete the pdf_book section,
_output.yml
bookdown::gitbook:
Then running bookdown::render_book(output_format = 'bookdown::pdf_book')
does place the references in the correct location.
My package version info is:
R version 4.0.3 (2020-10-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042), RStudio 1.4.1103
Locale:
LC_COLLATE=English_Canada.1252 LC_CTYPE=English_Canada.1252
LC_MONETARY=English_Canada.1252 LC_NUMERIC=C
LC_TIME=English_Canada.1252
Package version:
assertthat_0.2.1 base64enc_0.1.3 bookdown_0.21.6 callr_3.5.1
cli_2.3.0 compiler_4.0.3 crayon_1.4.1 curl_4.3
desc_1.2.0 digest_0.6.27 evaluate_0.14 glue_1.4.2
graphics_4.0.3 grDevices_4.0.3 highr_0.8 htmltools_0.5.1.1
jsonlite_1.7.2 knitr_1.31 magrittr_2.0.1 markdown_1.1
methods_4.0.3 mime_0.10 pkgbuild_1.2.0 prettyunits_1.1.1
processx_3.4.5 ps_1.5.0 R6_2.5.0 remotes_2.2.0
rlang_0.4.10 rmarkdown_2.7.1 rprojroot_2.0.2 rstudioapi_0.13
stats_4.0.3 stringi_1.5.3 stringr_1.4.0 tinytex_0.29
tools_4.0.3 utils_4.0.3 withr_2.4.1 xfun_0.21
yaml_2.2.1
Why does having an otherwise valid _output.yml prevent me from changing the location of the references? Are there options I can add to _output.yml that will make pdf_book respect <div id="refs"></div>
?
Upvotes: 0
Views: 326
Reputation: 6542
From the answer I posted on Github https://github.com/rstudio/bookdown/issues/1082#issuecomment-811026589
Changing placement of the bibliography using a div of id refs
as explained in https://bookdown.org/yihui/rmarkdown-cookbook/bibliography.html#include-appendix-after-bibliography is a Pandoc citation processor feature. See https://pandoc.org/MANUAL.html#placement-of-the-bibliography
Using Pandoc's citeproc
is the default for pdf_document()
and pdf_book()
, but here n your output file _output.yml
, you are explicitly changing citation_package
to natbib
for the bookdown::pdf_book
format.
When you call bookdown::render_book(output_format = 'bookdown::pdf_book')
, depending on the case you tested, this will happen
_output.yaml
it will use the configuration define there and use natbib
_output.yaml
it will use the default config for the format and --citeproc
will be use.You can only control the placement of the bibliography with a div of id refs
in the second case.
You just need to change the citation_package:
accordingly to want you need, and remove the field if you want to use Citations features from Pandoc processor.
Upvotes: 2