Reference management with Emacs, BibTeX, and Zotero

In this entry I describe what I use for reference and citation management in Emacs. It is nothing original, and relies on a couple of excellent packages, to whose authors I am deeply indebted. However, it took me a while to figure out which tools where most suitable for me, so I share this summary in the hope that it may be of help to others.

My setup allows me to:

  • get citations easily into my database from journals' websites or from pdf metadata (Zotero)
  • export data to a BibTeX file, kept automatically updated, from which various Emacs packages take the job (Zotero)
  • insert citations into LaTeX documents with a powerful and convenient search interface (reftex and helm-bibtex)
  • insert citations into org-mode documents, which correctly export to LaTex and HTML (org-ref and helm-bibtex)
  • open the article's PDF from Emacs (from the link or through a search interface)
  • take notes about an article and get at them through the citation link or a search interface (helm-bibtex)

Getting citations: Zotero

Zotero is a reference database manager which can generate bibliographies in different formats, which works as a standalone application or as a Firefox extension (which is an especially convenient way to add citations to the database). It can also take a PDF file and use the PDF metadata to find the appropriate citation. It is widely documented online.

I use Zotero as a BibTeX manager. That is, references are stored in Zotero's database (that I keep synchronised in the office and the laptop through a account thanks to Zotero's DAV support). It is very convenient to collect references from websites and for a quick search, but I do not use it to generate citations. Instead, I rely on BetterBibTex (a Zotero extension) to export to a .bib file (I freely use TeX markup in Zotero, which BetterBibTex respects if the entry is marked with a #LaTeX tag). I write exclusively in Emacs and insert references and generate bibliographies using several Emacs packages, directly in LaTeX documents, or in org-mode documents which get eventually exported to LaTeX or HTML.

Writing in LaTeX

When writing directly a LaTeX document, I insert with reftex or helm-bibtex (the first is bundled with Emacs, the second is available from MELPA). You need to specify the .bib files you will be using, plus some useful key-bindings.

(setq reftex-default-bibliography '("~/biblio/main.bib") )
(setq helm-bibtex-bibliography '("~/biblio/main.bib")
(add-hook 'TeX-mode-hook
  (lambda() (define-key TeX-mode-map "\C-ch" 'helm-bibtex)) )

Both packages, when you hit the chosen keybinding (for reftex it is C-c [ by default), open a search window from which you select the reference (powerful regexp-based queries are possible, check the respective documentations) and a \cite or similar command is inserted for you. I have not explored helm-bibtex sufficiently to have an opinion on which interface is superior as regards the search facilities. However, helm-bibtex has the ability to open the PDF file and the notes related to the reference (see below).

Writing in org-mode

When writing org-mode documents, I insert citations with org-ref (available from MELPA). I changed the key binding from C-c ] to C-c [ to have it the same as reftex (though this hides another org-mode key). org-ref opens helm-bibtex for the search, but inserts the citation in its own format (as cite:key). This is converted to the appropriate LaTeX command on export; you also need to include bibliography and bibliographystyle links at some place in the document (usually the end) to get the reference list at that point:


org-ref supports other link types besides citation links (like references to figures or other labels). Check out the documentation.

Opening the article's PDF

From the helm-bibtex search window, one of the actions is to open the pdf. This relies on a link in the corresponding BiBTeX entry. When exporting from Zotero, the files are listed in a file field (there is no need to export both entries and files, since BetterBibTex will link directly to the Zotero attached file). You must tell helm-bibtex which field to look for. It will open all the specified files, by default in Emacs itself, but you can change this to another viewer as shown:

(setq  helm-bibtex-pdf-field "file")
(setq helm-bibtex-pdf-open-function
  (lambda (fpath)
    (start-process "evince" "*helm-bibtex-evince*" "/usr/bin/evince" fpath)))

If you move to an already-entered citation command, in both LaTeX and Org modes the minibuffer shows information on the cited entry. In Org, you can click with the mouse for additional options (an approach I don't like). One of the options is open the PDF file, but I haven't been able to get it to work. Another option is to open the helm-bibtex search window and insert the citation key as a search term: this will get directly to the entry, and then one can invoke the open PDF action as if the whole process originated from a search from scratch. This is almost what I want, except that inserting the key is not straightforward. In principle, typing M-n with the search window open inserts the word-at-point in the minibuffer. This is great except that sometimes the keys comprise more than one word (because they include characters such as colons or underscores). Then M-n doesn't work. For multiword keys, one can use C-w, which inserts from point to end of word, and inserts the following words on repeating the key. However, apart from the multiple key presses, this will only work if the point is exactly at the beginning of the key. This is an issue, while minor, I would like to fix but currently don't know how.


With helm-bibtex one can link BibTeX entries to notes in an org-mode file. I use a single .org file for all bibliographic notes, which can be accessed as one of the actions (press TAB) from the helm-bibtex search window. The file is specified in your .emacs with something like

(setq helm-bibtex-notes-path "~/doc/apuntes/")

You can also access the notes from a previously-inserted citation like you access the PDF (except you select a different action from the search window). All comments above apply also to opening the notes.


I am rather happy with this solution for reference management, which combines the best of Zotero's convenience for getting references in a database with the power of the Emacs tools described above to make effective use of the database. However, it is only recently that I discovered org-ref and helm-bibtex, so I expect to learn more on them and hopefully share on updates to this post.

How I created my web home

This website is made of static html pages generated by Nikola from Emacs Orgmode sources (I've learnt to stay away from CMSs). Nikola is a Python package that translates a collection of plain-text sources in a variety of markup languages to html, providing support for blogging and commenting, and visually styling the site through different themes. Themes in turn rely on an independent template system (it can be Mako or Jinja2) plus a set of CSS and font files (and some themes support replacing CSSs and fonts using a bootswatch theme).

Leer más…

Identifying disks by UUID

To get a the UUID of a disk, do

$ sudo blkid /dev/sdb1
/dev/sdb1: UUID="a48cf280-fcc7-4283-ab31-5a23440bd2fa" TYPE="ext4" 

Now you can refer to the device as /dev/disk-by-uuid/xxx. Or you can mount by UUID from fstab as follows:

UUID=a48cf280-fcc7-4283-ab31-5a23440bd2fa /external     ext4    rw,user,noauto

Using babel and xypic

As widely documented, babel redefines the catcode for several characters, making xypic pictures to fail. The cure is to use \shorthandoff{}, like this (the spanish option redefines "):

\xy (stuff) \endxy

Burning mixed (audio and data) CDs

There are two ways to mix audio and data on a CD. The first is to use a single session, using the first track for data and the rest for audio (this works because most CD players will ignore the data track). The command (Debian) is something like

wodim -v dev=/dev/cdrom -data cdimage.raw -audio track*.cdaudio

The second option is the best according to advice I’ve found, and the only I’ve actually tried. It’s to burn a two-session CD, puting audio in the first session and data in the second. This second session is ignored by players, but can be read by a computer when you mount the CD.

This is how you do it: First, burn the audio:

wodim -v dev=/dev/cdrom [-sao] -multi -audio  *.wav

(-v = verbose, -sao = session-at-once). Now find and save the number of the last record written:

NEXT_TRACK=$(cdrecord -msinfo)

Create the image:

genisoimage -o image.iso -r -J -C $NEXT_TRACK cd-data/*

(-J = Joliet, -r = intelligent Rock Ridge, -C = starting sector). To verify the image:

isoinfo -i cd_plus.iso -f -R -J -N ${NEXT_TRACK/*,}

Finally, burn the second session:

wodim dev=/dev/cdrom -eject -data cd_plus.iso

Converting among graphic formats

Command-line utilities to convert between graphic formats I have found useful:

  • eps to pdf: ps2pdf with -dEPSCrop option to produce the pdf “bounding box”
  • epstopdf (part of texlive package). Seems better than the above, automatically uses bounding box and respects orientation.
  • convert is a command-line tool to convert among various formats. Very easy basic usage (assumes target format from file extension). Part of ImageMagic.
  • pdftk is a tool to manipulate pdf files (split, join and much more).

Extracting images from MSWord documents

The best way is to save the document as web page (from the File menu) and look in the directory for the image files.

Creating BibTex styles

To create a new BibTeX style, run

latex makebst.tex

to proceed through a long list of questions about the style. The result is another file that will produce a .bst file after running it through LaTeX again. If you change your mind about an answer, you can edit the intermediate file, it has pretty obvious format.

Check this post for more information about .bst files.