Citation management in Org mode

For a long time, I was using Emacs to manage academic resources and produce nice LaTeX pdf files. It was a little bit of trouble getting it going, and it was a pain to use it with attendings since they prefer to work off of word. I ended up uninstalling all the plugins I need to use with it, which I now regret. So this blog post will serve as a log while I try to reinstall the modules and get it all running again.

Org-Ref

Org-Ref is a supposedly obselete package available on the Melpa database. It provides a lot of the machinery that lets Org play nicely with bibtex files and citations.

It looks like a lot of my old config stuck around. I had to add a few lines to my init code:

;; Initialize Org-Ref for citations
(require 'org-ref)

(setq reftex-default-bibliography '("~/org/bibliography/references.bib"))

;; see org-ref for use of these variables
(setq org-ref-bibliography-notes "~/org/bibliography/notes.org"
      org-ref-default-bibliography '("~/org/bibliography/references.bib")
      org-ref-pdf-directory "~/org/bibliography/bibtex-pdfs/")

(setq bibtex-completion-bibliography "~/org/bibliography/references.bib"
      bibtex-completion-library-path "~/org/bibliography/bibtex-pdfs"
      bibtex-completion-notes-path "~/org/bibliography/helm-bibtex-notes")

;; open pdf with system pdf viewer (works on mac)
(setq bibtex-completion-pdf-open-function
  (lambda (fpath)
    (start-process "open" "*open*" "open" fpath)))

LaTeX Specifics

Along the way, I had to install MacTEX to handle emacs org tex output. I had one small dependency issue, listed below for reference.

==> Pouring ghostscript--9.23_1.high_sierra.bottle.tar.gz
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink bin/dvipdf
Target /usr/local/bin/dvipdf
already exists. You may want to remove it:
  rm '/usr/local/bin/dvipdf'

To force the link and overwrite all conflicting files:
  brew link --overwrite ghostscript

To list all files that would be deleted:
  brew link --overwrite --dry-run ghostscript

I’m also finding pdflatex already installed. I think there might be a problem with telling emacs which shell scripts to use. There’s a package called exec-path-from-shell that helps with this. You have to initialize it once it’s installed with the command (exec-path-from-shell-initialize).

I had to add a bit of code to my Init in order to get Org to process bibliographies with Bibtex:

(setq org-latex-pdf-process
      '("pdflatex -interaction nonstopmode -output-directory %o %f"
	"bibtex %b"
	"pdflatex -interaction nonstopmode -output-directory %o %f"
	"pdflatex -interaction nonstopmode -output-directory %o %f"))

Use

Citations are placed in the file ~/org/bibliography/references.bib. Citations are indexed automatically from this file and can be added to other org files with the key combination C-c ]. The LaTeX header I’m using is as follows:

#+LaTeX_HEADER: \usepackage{mathptmx}
#+LaTeX_HEADER: \usepackage{pifont}
#+LaTeX_HEADER: \usepackage[margin=1.0in]{geometry}
#+LaTeX_HEADER: \usepackage[backend=bibtex,sorting=none]{biblatex}
#+LaTeX_HEADER: \addbibresource{~/org/bibliography/references.bib}  %% point at your bib file
#+LaTeX_HEADER: \newcommand{\point}[1]{\noindent \textbf{#1}}
#+LaTeX_HEADER: \usepackage{hyperref}
#+LaTeX_HEADER: \usepackage{csquotes}
#+LaTeX_HEADER: \usepackage[mla]{ellipsis}
#+LaTeX_HEADER: \parindent = 0em
#+LaTeX_HEADER: \setlength\parskip{.5\baselineskip}
#+LaTeX_HEADER: \usepackage[T1]{fontenc}
#+LaTeX_HEADER: \usepackage[scaled]{beraserif}
#+LaTeX_HEADER: \usepackage[scaled]{berasans}
#+LaTeX_HEADER: \usepackage[scaled]{beramono}
#+LaTeX_HEADER: \usepackage{textcomp}
#+STARTUP: overview

Make sure to add \printbibliography at the end of the file. Exports with LaTeX should now work!

To add new entries to the bibliography by DOI, use the command doi-utils-add-bibtex-entry-from-doi. For now, I’ve linked this command with the key combo C-c d. So just type in that combo, hit enter, and there you go. Supposedly there is a mode that can find and download pdf files of the articles you link to, but I haven’t found a way to make that work yet.

So now LaTeX and Bibtex are up and running. I’ll write up another post on LaTeX specific options later, and I’ll break down the info in the header.

 
comments powered by Disqus