If I insert references via @nocite, these references show up in the html and pub versions of the knit book but not in the PDF. How can I ensure that the bibliography stays consistent across formats?
Here is a MWE with a single nocite reference added to book.bib ... @Book{Lander2014, author = {Lander, Jared P}, title = {R for everyone: Advanced analytics and graphics}, year = {2014}, publisher = {Pearson Education}}
---
title: "A Minimal Book Example"
author: "Yihui Xie"
date: "`r Sys.Date()`"
site: bookdown::bookdown_site
output: bookdown::gitbook
documentclass: book
bibliography: [book.bib, packages.bib]
biblio-style: apalike
link-citations: yes
github-repo: rstudio/bookdown-demo
description: "This is a minimal example of using the bookdown package to write a book. The output format for this example is bookdown::gitbook."
nocite: |
@Lander2014
---
# Prerequisites
This is a _sample_ book written in **Markdown**. You can use anything that Pandoc's Markdown supports, e.g., a math equation $a^2 + b^2 = c^2$.
For now, you have to install the development versions of **bookdown** from Github:
```{r eval=FALSE}
devtools::install_github("rstudio/bookdown")
```
Remember each Rmd file contains one and only one chapter, and a chapter is defined by the first-level heading `#`.
To compile this example to PDF, you need to install XeLaTeX.
```{r include=FALSE}
# automatically create a bib database for R packages
knitr::write_bib(c(
.packages(), 'bookdown', 'knitr', 'rmarkdown'
), 'packages.bib')
```
Here is the sessionInfo()
> sessionInfo()
R version 3.4.1 (2017-06-30)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.6
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_3.4.1 backports_1.1.0 bookdown_0.5 magrittr_1.5 rsconnect_0.8.5 rprojroot_1.2
[7] htmltools_0.3.6 tools_3.4.1 yaml_2.1.14 Rcpp_0.12.12 stringi_1.1.5 rmarkdown_1.6
[13] knitr_1.17 stringr_1.2.0 digest_0.6.12 evaluate_0.10.1
Within the output YAML for the .pdf, if you remove the option
citation_package: natbib, it should work. See the pandoc docs on citation rendering: https://pandoc.org/MANUAL.html#citation-rendering. If "natbib" or "biblatex" are passed in, then "pandoc-citeproc" is not used.I experimented with this and was able to generate references in the
nociteelement to appear in both HTML and .pdf. When you do this, you will want to include# References {-}or something similar, just as you would when writing to HTML.Note that I am not expert in LaTeX and cannot speak to any unintended consequences which may occur when "natbib" or "biblatex" are not used for a .pdf build.