@nocite:|引用出现在html&酒吧,但不是PDF

时间:2017-09-11 12:54:27

标签: pdf rstudio knitr pandoc bookdown

如果我通过@nocite插入引用,这些引用会显示在编织书的html和pub版本中,但不会显示在PDF中。如何确保参考书目在各种格式中保持一致?

这是一个MWE,其中有一个nocite引用被添加到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')
```

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

1 个答案:

答案 0 :(得分:0)

在.pdf的输出YAML中,如果删除选项testers_time,它应该可以正常工作。请参阅引文呈现的pandoc文档:https://pandoc.org/MANUAL.html#citation-rendering。如果传入“natbib”或“biblatex”,则不使用“pandoc-citeproc”。

我对此进行了实验,并且能够在df元素中生成引用,以便在HTML和.pdf中显示。执行此操作时,您需要包含citation_package: natbib或类似内容,就像写入HTML时一样。

请注意,我不是LaTeX的专家,并且无法说出当“natbib”或“biblatex”未用于.pdf构建时可能发生的任何意外后果。