Chapter 7 Referencing

Rmarkdown supposedly support many differentent reference managers. I have tried them all, and can only really recommend using Zotero with the Better BibTex plugin. I was, for various reasons, not able to get of the others to work, either they lack a stable identifier key (Endnote), or produces corrupted bibtex (Mendeley, Papers).

Zotero is not great, but it gets the job done. It has relatively poor support for handhelds (e.g., collecting references when browsing from mobile3), and after recent MacOS updates, the citation plugin does not work in Safari. It works fine from Firefox though, so that would be another recommended tool to add to your toolchain.

Better BibTex works on top of Zotero; When you import or add a reference to Zotero, Better BibTex writes this reference into a bibtex file and provided a citation identifier (which is customizable). The Zotero libarary and this bibtex file is kept in sync, so changes you make to Zotero (changing/fixing references, adding references) is also updated in the bibtex file. The citation identifier is what goes into you manuscrupt, and connects the manuscript with the reference library. From Zotero, you can customize how this key is copied, so that you can paste it into your document in a way that is supported by Rmarkdown and pandoc.

You link the bibtex file to your document in the YAML header.

bibliography: "/Location/of/your/file.bib"

Like in Endnote, you are able to use different styles of formatting for different journals. The easy approach is to downlod a csl file which contains the definitions and takes care of the formatting for you. A great resource to use is the Zotery Style Repository. The style of references you wish for your paper, is then provided by linking to this csl file in the YAML frontmatter, like this:

csl: journal-of-adolescent-health.csl

With this information, Rmarkdown is able to compile your manuscript, pick up the references, look these up in the bib file, format them according to the style specified in your csl file, and produce a formatted paper - when you press the Knit button.

I often write from three computers, my laptop, my computer at work and my computer at home. In order to have references synced, I place all pdfs and the .bib file in my dropbox folder. I set this up using settings in Zotero and Better BibTex. To store pds in Dropbox folder, go to Zotero - Preferences - Advanced - Files and Folders and set the folder under “Linked Attachment Base Directory”. Do not change the Data Directory Location! In order to not have the generation of the bibtex file interfere with Dropbox syncing (i.e. writing lots of changes makes Dropbox eager to sync all the time), I have set up Better BibTex to sync only when Zotero is idle. This setting is in Zotero - Preferences - Better BibTex - Automatic export which is set to “When Idle” using the dropdown menu.


  1. Personally, I have a copy of Papers set up on mobile and computer, so I collect references on Papers on my phone, they get synced to my computer, and then I export them from Papers to Zotero to get them into Zotero.