rstudio / bookdown

Authoring Books and Technical Documents with R Markdown
https://pkgs.rstudio.com/bookdown/
GNU General Public License v3.0
3.78k stars 1.27k forks source link

Bibtex references showing up twice...or not? #751

Closed rikcrutzen closed 2 years ago

rikcrutzen commented 5 years ago

We (@Matherion and me) use Bibtex for citations in RMarkdown project. A certain reference (Peters, G.-J.Y., and R. Crutzen. 2017. “Pragmatic Nihilism: How a Theory of Nothing Can Help Health Psychology Progress.” Health Psychology Review 11: 103–21.) shows up twice (while only being cited once) in the reference list of the specific chapter (see: https://a-bc.gitlab.io/bbc/selecting-determinants.html). Is this a known bug? Or does somebody know why this happens? What makes it even more striking is that this same reference does not show up twice in the reference list of the overall project (see: https://a-bc.gitlab.io/bbc/references.html). Any thoughts or ideas are welcome. Thank you in advance.


By filing an issue to this repo, I promise that

I understand that my issue may be closed if I don't fulfill my promises.

yihui commented 5 years ago

That sounds like a bug, but I don't have time to investigate it. If anyone is interested in helping out, please look for split_bib in https://github.com/rstudio/bookdown/blob/master/R/html.R and check what went wrong (possibly with parse_references() or relocate_references()). Thanks!

Matherion commented 5 years ago

I'll see whether I can figure out what's going wrong!

leowill01 commented 3 years ago

I'm seeing this bug in word_document2 output where it inserts all of my references twice, but the bug does not appear in pdf_document2 output [edit: also seeing the bug in PDF output, though it doesn't happen every time].

SessionInfo():

R version 4.1.1 (2021-08-10)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur 11.6
[...]
other attached packages:
[1] bookdown_0.24

loaded via a namespace (and not attached):
 [1] rstudioapi_0.13     knitr_1.36          magrittr_2.0.1     
 [4] rsthemes_0.2.1.9000 R6_2.5.1            rlang_0.4.11       
 [7] fastmap_1.1.0       stringr_1.4.0.9000  tools_4.1.1        
[10] xfun_0.26           sessioninfo_1.1.1   tinytex_0.34       
[13] cli_3.0.1           jquerylib_0.1.4     withr_2.4.2        
[16] htmltools_0.5.2     yaml_2.2.1          digest_0.6.28      
[19] lifecycle_1.0.1     sass_0.4.0.9000     vctrs_0.3.8        
[22] glue_1.4.2          evaluate_0.14       rmarkdown_2.11     
[25] stringi_1.7.5       compiler_4.1.1      bslib_0.3.0        
[28] jsonlite_1.7.2     

Edit: I seem to have (temporarily?) fixed the problem by moving the reference to the bibliography from the top-level YAML option:

bibliography: bibliography.bib

to the explicit pandoc options for each output format:

output:
  bookdown::pdf_document2:
    pandoc_args:
    - "--citeproc" # <----- EDIT 2: I did not include this line in the original post of this comment, and it was the problem
    - "--bibliography=bibliography.bib"

I'm using rmarkdown::render(), so it might be a problem with rmarkdown and not bookdown necessarily.

Edit 2: the problem was having a redundant "--citeproc" option in my YAML header [see comment below]

cderv commented 3 years ago

@leowill01 Are you able to share a reproducible example to help us investigate and fix this ?

THank you

leowill01 commented 3 years ago

I figured out what was wrong in my case. I had been using output: book down::pdf_document2: pandoc_args: to add additional arguments for including Lua filters (e.g. "--lua-filter=pandoc/scholarly-metadata.lua"), but I also had put the "--citeproc" option there as well. The problem arises because the default knit to bookdown::pdf_document2 command already includes a --citeproc option. So by including this again under pandoc_args:, I was telling it to insert the complete bibliography twice.

@rikcrutzen : Check to make sure you don't have an extra output: book down::[format]: pandoc_args: "--citeproc" enabled in the YAML header of the chapter you're having an issue with.

cderv commented 3 years ago

Oh indeed good find.

R Markdown output formats will usually add the --citeproc argument when bibliography: YAML field is detected. This is for ease of use for user so that they don't have a explicitly trigger citeproc.

I missed that from your message above.

Regarding the issue of this post, it is rather specific to one duplicated reference so I think this is different.

cderv commented 2 years ago

@Matherion sorry for the delay on this. Is this still an issue ?

I have clone your repo and rebuild the book locally and I can't see the duplicated reference. It is possible this has been fixed since, especially if it was introduced by a Pandoc version.

If this is still an issue please share your pandoc version. Thanks!

github-actions[bot] commented 2 years ago

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.