Skip to content

Instantly share code, notes, and snippets.

Intro / General

rmarkdown and bookdown offer two different methods for managing citations and bibliographic references in a document.

The default setting for rmarkdown and bookdown (and pandoc itself) is to use a pandoc helper program (specifically, a “filter”) called pandoc-citeproc, which follows the specifications of the Citation Style Language (CSL) and obtains specific formatting instructions from one of the huge number of available CSL style files (default is chicago-author-date.csl).

In some circumstances, users might prefer to use either natbib (based on bibtex) or biblatex as a “citation package” instead.

@njbart
njbart / chicago-author-date-enhanced-20090102.csl
Last active January 2, 2019 10:21
hack for getting a biblatex-bookinbook-like output, see https://forums.zotero.org/discussion/75154/
<?xml version="1.0" encoding="utf-8"?>
<style xmlns="http://purl.org/net/xbiblio/csl" class="in-text" version="1.0" demote-non-dropping-particle="display-and-sort" page-range-format="chicago">
<info>
<title>Chicago Manual of Style 17th edition (author-date), enhanced</title>
<id>chicago-author-date-enhanced</id>
<link href="https://gist.github.com/njbart/116c190af4f3dca7ed800324aed0380f/raw/d13fc9ef60e10b06f3d7fda3bf78399f12553926/chicago-author-date-enhanced-20090102.csl" rel="self" />
<link href="http://www.chicagomanualofstyle.org/tools_citationguide.html" rel="documentation" />
<author>
<name>Julian Onions</name>
<?xml version="1.0" encoding="utf-8"?>
<style xmlns="http://purl.org/net/xbiblio/csl" class="in-text" version="1.0" demote-non-dropping-particle="display-and-sort" page-range-format="chicago">
<info>
<title>Chicago Manual of Style 17th edition (author-date)</title>
<id>http://www.zotero.org/styles/chicago-author-date</id>
<link href="http://www.zotero.org/styles/chicago-author-date" rel="self"/>
<link href="http://www.chicagomanualofstyle.org/tools_citationguide.html" rel="documentation"/>
<author>
<name>Julian Onions</name>
<email>julian.onions@gmail.com</email>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:z="http://www.zotero.org/namespaces/export#"
xmlns:dcterms="http://purl.org/dc/terms/"
xmlns:bib="http://purl.org/net/biblio#"
xmlns:foaf="http://xmlns.com/foaf/0.1/"
xmlns:dc="http://purl.org/dc/elements/1.1/">
<bib:Document rdf:about="#item_34383">
<z:itemType>webpage</z:itemType>
<dcterms:isPartOf>
@unpublished{t1,
title = {A Manuscript: 2014-12-31/2015-01-01},
author = {Doe, John},
date = {2014-12-31/2015-01-01},
origdate = {1777-07-27/1888-08-28},
eventdate = {1888-08-28},
urldate = {2014-12-31~}
}
@book{t2,
<!DOCTYPE HTML>
<html>
<head>
<style>
.csl-bib-body { line-height: 1.35; }
.csl-entry { clear: left; }
.csl-block { }
.csl-left-margin { clear: left; float: left; width: 100px; }
.csl-right-inline { margin-left: 100px; }
.csl-indent { margin-left: 3em; }
@njbart
njbart / chicago-author-date-plus.csl
Created October 11, 2015 10:40
chicago-author-date-plus.csl = chicago-author-date.csl with volume-title
<?xml version="1.0" encoding="utf-8"?>
<style xmlns="http://purl.org/net/xbiblio/csl" class="in-text" version="1.0" demote-non-dropping-particle="display-and-sort" page-range-format="chicago">
<info>
<title>Chicago Manual of Style 16th edition (author-date) plus</title>
<id>chicago-author-date-plus</id>
<!-- <link href="http://www.zotero.org/styles/chicago-author-date" rel="self"/>-->
<link href="http://www.chicagomanualofstyle.org/tools_citationguide.html" rel="documentation"/>
<author>
<name>Julian Onions</name>
<email>julian.onions@gmail.com</email>
[
{
"id": "x1",
"type": "chapter",
"title": "Firms and the welfare state: when, why, and how does social policy matter to employers?",
"container-title": "Varieties of capitalism: the institutional foundations of comparative advantage",
"publisher": "Oxford University Press",
"publisher-place": "Oxford",
"event-place": "Oxford",
"ISBN": "9780199247752",
@njbart
njbart / shortdoi.r
Created April 14, 2015 10:41
Replace DOIs by shortDOIs in CSL JSON
#! /usr/bin/env Rscript
library("jsonlite")
filename <- commandArgs(TRUE)[1]
bibdata <- fromJSON(filename, simplifyVector = FALSE, simplifyDataFrame = FALSE, simplifyMatrix = FALSE)
for (n in seq_along(bibdata)) {
if (exists('DOI', where=bibdata[[n]]))
pandoc -F pandoc-citeproc -t markdown-citations << EOT
Foo [@doe1].
Bar [@doe2].
Foo [@doe1].
Remove this line to see the problem [@doe2].
# References
---