rr-markdownbookdowncitationscsl

Rmarkdown add an item to a bibliography without citing in the text, bibliography by order of appearance


I would like to have a bibliography which lists items that are cited in the text but also others that are not (e.g. using nocite). The csl style that I am using sorts by order of appearance with:

<sort>
  <key variable="citation-number"/>
</sort>

I cannot change the csl style as it corresponds to a specific scientific journal.

My problem is that the citations that are not quoted in the text systematically appear at the end of the bibliography, whereas I would like some of them to appear before the ones that are cited in the text, or even in between them.

Example of csl style: https://www.zotero.org/styles/springer-basic-brackets

I am using Rmarkdown and bookdown. Here is an example:

---
title: ""
author: ""
output:
  bookdown::pdf_document2:
bibliography: references.bib
csl: springer-basic-brackets.csl
nocite: |
  @item1
---

Cite this in the text [@item2].

Also cite this [@item3].

\newpage
# References {-}

<div id="refs"></div>

In this example I would like to have a bibliography with

item1
item2
item3

instead of

item2
item3
item1

I would like to even be able to get somehow:

item2
item1
tiem3

I tried using \nocite{} but it didn't work. Any advice?


Solution

  • I figured out a solution after looking at: https://tex.stackexchange.com/questions/591882/citation-within-a-latex-figure-caption-in-rmarkdown

    Using the following:

    (ref:invisible) [@item1]
    

    allowed me to get what I wanted.

    For instance:

    ---
    title: ""
    author: ""
    output:
      bookdown::pdf_document2:
        toc: no
    bibliography: references.bib
    csl: springer-basic-brackets.csl
    ---
    
    (ref:invisible) [@item1]
    
    Cite this in the text [@item2].
    
    Also cite this [@item3].
    
    # References {-}
    
    <div id="refs"></div>
    

    with references.bib:

    @article{item1,
        title = {Article1},
        author = {Author1},
        year = {2018},
    }
    
    @article{item2,
        title = {Article2},
        author = {Author2},
        year = {2019},
    }
    
    @article{item3,
        title = {Article1},
        author = {Author3},
        year = {2017},
    }
    

    produced:

    a screenshot of the pdf produced

    By changing the position of (ref:invisible) [@item1], the order of the bibliography changed accordingly, for instance:

    a screenshot of the pdf produced after changing the position of (ref:)