Search code examples
rlatexr-markdownbibliographycsl

How to insert two separate bibliographies (without citing them in the body text) under two separate headers in R Markdown?


Consider the following R Markdown code:

---
title: 'John Doe'
output: pdf_document
bibliography: [bib1.bib, bib2.bib]
nocite: '@*'
csl: vancouver.csl
---

# Peer-reviewed publications

# Other publications

bib1.bib code:

@article{article1,
Author = {Doe, John},
Title = {{Article 1 name}},
Journal = {{Journal 1 name}},
Year = {{2021}},
Volume = {{1}},
Pages = {{1-2}},
}

@article{article2,
Author = {Doe, John},
Title = {{Article 2 name}},
Journal = {{Journal 2 name}},
Year = {{2020}},
Volume = {{1}},
Pages = {{1-2}},
}

bib2.bib code:

@article{article3,
Author = {Doe, John},
Title = {{Article 3 name}},
Journal = {{Journal 3 name}},
Year = {{2021}},
Volume = {{1}},
Pages = {{1-2}},
}

The knit output:

enter image description here

However, I'm rather looking after the following output:

enter image description here

Please note that I don't want in-text citations but rather the whole bibliographies listed, which is why I approached the problem by adding the "nocite: '@*'" to the code, but I couldn't get the result I'm after.

By the way, I used the csl style vancouver.csl (please see: https://www.zotero.org/styles?q=vancouver) here.

Any help is greatly appreciated.


Solution

  • You could use biblatex to split the bibliographies:

    ---
    title: 'John Doe'
    output: 
      pdf_document:
        keep_tex: true
    csl: vancouver.csl
    header-includes:
      - \include{preamble.tex}
    ---
    
    

    with preamble.tex:

    \usepackage[style=vancouver]{biblatex}
    \addbibresource{bib1.bib}
    \addbibresource{bib2.bib}
    
    \DeclareSourcemap{
      \maps[datatype=bibtex]{
        \map[overwrite]{
          \perdatasource{bib1.bib}
          \step[fieldset=keywords, fieldvalue={,peer}, append]
        }
      }
    }
    
    \AtEndDocument{\nocite{*}
    \printbibliography[keyword={peer},title={Peer-reviewed publications}]
    \DeclareFieldFormat{labelnumber}{%
      \ifinteger{#1}
        {\number\numexpr#1-2\relax}
        {#1}}
    \printbibliography[notkeyword={peer},title={Other publications}]}
    

    And then compile the resulting filename.tex file with

    pdflatex filename
    biber filename
    pdflatex filename
    

    enter image description here