Automatically create bibliography from bibtex in pandoc/markdown without inline citations
Asked Answered
A

5

21

How can I automatically create a citations list from a bibtex file, preferably in markdown (more specifically, pandoc) format?

I'm in the process of building my personal, academic website. As most personal, academic websites do, I am including a page listing my publications. However, I really don't want to write every citation by hand, so I'm attempting to find an automated method of creating the citations from one or more bibtex files.

Ideally there would be a tool I could just hand a bibtex file containing my publications to and it would spit out markdown (I'm using pandoc + makefile to create the site). I am currently unaware of any such tool.

Further complicating my needs is the fact that a simple flat listing of publications is not sufficient. I need to be able to list different publications under different categories (peer reviewed and non peer reviewed at the very minimum). Though if a tool like I was wishing for above does exist, I could easily maintain multiple bibtex files and use some bash-fu to accomplish this.

Antependium answered 24/11, 2012 at 21:20 Comment(0)
C
12

I wanted the same thing for the same reason (creating a website using Hakyll) and I found the "problem": the CSL file.

Pandoc, in fact, does this job perfectly and the solution provided by MacFarlane is correct, but it lacks explanation on the rule of the CSL file—it is what defines if you are going to have a numbered reference in the middle text with a list of publications in the end or not.

Julien Tanguy has created a CSL style that puts the publication simplied information from BibTeX in the place where the reference is cited, derived from Chicago style. Certainly you can use it (it is licensed under Creative Commons Attribution-Share Alike 3.0) but you can also create yours.

So, now (a long time after you've posted the question), I hope you have the complete answer.

Coe answered 5/1, 2014 at 15:10 Comment(1)
This style works, but displays URLs instead of DOI when available. An up-to-date equivalent can simply be created by downloading the "Chicago fullnote style" zotero.org/styles/chicago-fullnote-bibliography, and then, delete the <bibliography> ... </bibliography> block. Also you can tweak the et-al-use-first variable to display more authors if needed.Thrive
R
16

You can use pandoc's own citation support for this. Create a markdown file along the following lines:

# Peer-reviewed papers

1. [@me2001]
2. [@me2002]

# Non-peer-reviewed papers

1. [@me1999]
2. [@me1998]

where me1999 etc are the keys in your bibtex file. Then find or create a CSL file that formats the citations in the way you would like, and process with pandoc:

pandoc --bibliography mybiblio.bib --csl mycsl.csl -o citations.html -s citations.txt

Or you can add -t markdown and get a markdown version if you wish.

If you don't want to create the input markdown file by hand, you could probably write a script to generate it from your bibtex file, if it contains sufficient metadata to distinguish peer-reviewed from non-peer-reviewed papers.

Reconcile answered 26/11, 2012 at 2:59 Comment(3)
This is what I originally tried. What was happening was that it was putting an in text citation at the location of the keys, such as (Me 2001), rather than the full bibliographic citation. The full bibliography was being put at the end of the document. Is this just due to the CSL I used?Antependium
Does this still work John? I am having trouble getting the citations parsed when converting from .md to .md; the code provided above does not work for me.Ashling
You can use the 'markdown-citations' format for this. See here: groups.google.com/d/msg/pandoc-discuss/DJ_XxxvkJEg/KjJ6iDiVAwAJWashing
C
12

I wanted the same thing for the same reason (creating a website using Hakyll) and I found the "problem": the CSL file.

Pandoc, in fact, does this job perfectly and the solution provided by MacFarlane is correct, but it lacks explanation on the rule of the CSL file—it is what defines if you are going to have a numbered reference in the middle text with a list of publications in the end or not.

Julien Tanguy has created a CSL style that puts the publication simplied information from BibTeX in the place where the reference is cited, derived from Chicago style. Certainly you can use it (it is licensed under Creative Commons Attribution-Share Alike 3.0) but you can also create yours.

So, now (a long time after you've posted the question), I hope you have the complete answer.

Coe answered 5/1, 2014 at 15:10 Comment(1)
This style works, but displays URLs instead of DOI when available. An up-to-date equivalent can simply be created by downloading the "Chicago fullnote style" zotero.org/styles/chicago-fullnote-bibliography, and then, delete the <bibliography> ... </bibliography> block. Also you can tweak the et-al-use-first variable to display more authors if needed.Thrive
H
4

The earlier top-rated answers from 2012 and 2014 are, of course, valid; however, note that since pandoc version 2.11 (2020-10-11), pandoc now accepts bibtex (and a few other bibliography data formats) as input formats. This allows a solution much closer to what the original question was seeking: "a tool I could just hand a bibtex file containing my publications to and it would spit out markdown" so that "I could easily maintain multiple bibtex files and use some bash-fu". Now you can do exactly that: Keep your publications in separate bibtex files, then feed them to pandoc (for example, pandoc -f bibtex --citeproc --csl=chicago-annotated-bibliography.csl pubs.bib -o pubs.md) recursively and concatenate or include the results in your other text.

Hippolytus answered 10/4, 2021 at 22:12 Comment(0)
S
2

As others have pointed out, the easiest way to accomplish this is to use an appropriate CSL file. Kieran Healy provides such a file in his pandoc-templates repository, hosted on GitHub.

The chicago-syllabus.csl file makes a tiny change to a standard Chicago Notes CSL file so you can use it to output citation information in the body text of a document. This makes it useful for lists of references in CVs and course syllabuses.

Just download the file and pass the option --csl==<link to CSL-file> to pandoc (where <link to CSL-file> is the path to where your have stored the downloaded file.

Sedgewinn answered 22/9, 2016 at 11:2 Comment(0)
W
0

I am using bibtexbrowser for my personal site. It is a PHP script that is easy to integrate into other websites (as long as the server supports PHP). This solution unfortunately does not generate markdown, but it is fairly flexible and has the advantage of reading directly the bibtex file.

Alternatively you can use bibtex2html (or a similar tool) to generate HTML. Pandoc concatenates multiple input files and you can use raw html within Markdown, so it should be straightforward to include it anywhere you need. You can also use Pandoc to convert the HTML to Markdown if Markdown needs to be your final output.

Washrag answered 20/5, 2013 at 17:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.