Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I specify multiple bibliography (BibTeX) files in Pandoc Metadata?

Often, scientific journal websites and other sources offer downloadable *.bib files for referring to individual articles. If I use these, I like to keep them as they are instead of merging them into a single file. On the command line, several files can be specified by passing the --bibliography option multiple times. Can I also list multiple files in the YAML metadata inside the *.md document itself?

like image 705
das-g Avatar asked Feb 04 '23 14:02

das-g


2 Answers

If you want to use biblatex for a citation formatter, you can set up multiple bib files in your YAML front matter:

---
bibliography:
- mybib1.bib
- mybib2.bib
---

You'll need to compile with:

pandoc myfile.md -o myfile.pdf --biblatex

This works because the latex templates contains a $for(bibliography)$ loop:

$if(biblatex)$
\usepackage[$if(biblio-style)$style=$biblio-style$,$endif$$for(biblatexoptions)$$biblatexoptions$$sep$,$
$for(bibliography)$
\addbibresource{$bibliography$}
$endfor$
$endif$
like image 193
scoa Avatar answered Feb 07 '23 11:02

scoa


Bibliographies can be specified in document metadata, i.e. via for Markdown in YAML blocks:

---
bibliography:
- one.bib
- two.bib
- three.bib
---

This only works if pandoc-citeproc is invoked as a filter by passing --filter=pandoc-citeproc on the command line. E.g.,

$ pandoc --filter=pandoc-citeproc --from=markdown --to=latex my-file.md

To understand why, we must take a step back and look at the way pandoc handles citations. Usually, i.e. if no alternative citation method has been requested via --natbib or --biblatex, pandoc uses pandoc-citeproc to handle citations, ensuring comparable citation handling across different formats. pandoc-citeproc works as a pandoc filter: the program receives the full document in pandoc's JSON format and performs the following steps:

  1. get the bibliography file(s) from the bibliography metadata field;
  2. collect all citations in the document;
  3. create a bibliography and insert appropriate text in the document;
  4. encode the resulting document to JSON again and write to stdout.

Pandoc will then continue its work using the modified document.

The bibliography field can be set either via the command line or in the document itself. The only difference between using command line options or YAML metadata is that pandoc invokes pandoc-citeproc automatically if the bibliography is given as a CLI parameter. Since we don't want this, we need to tell pandoc explicitly that the pandoc-citeproc filter must be called.

like image 37
tarleb Avatar answered Feb 07 '23 13:02

tarleb