April 22, 2014

One of my enduring frustrations with the various academic publishing platforms (CJO, ScienceDirect, JSTOR and their ilk) is the wildly inconsistent way in which they export BibTeX entries for articles. Sometimes they put them right on the browser page for easy copy-and-paste; sometimes it comes up after a few clicks in a new window; sometimes you end up downloading a file with an impossibly long or counterintuitive name, or called something like science.bib (which Chrome tends to turn into science (14).bib as they accumulate). Since I really only need the BibTeX entry once to get into my master .bib file, that is a waste of time and resources. So if you’re using Emacs, here’s a simple function which might be helpful

(defun get-bibtex-from-doi (doi)
 "Get a BibTeX entry from the DOI"
 (interactive "MDOI: ")
 (let ((url-mime-accept-string "text/bibliography;style=bibtex"))
   (with-current-buffer 
     (url-retrieve-synchronously 
       (format "http://dx.doi.org/%s" 
       	(replace-regexp-in-string "http://dx.doi.org/" "" doi)))
     (switch-to-buffer (current-buffer))
     (goto-char (point-max))
     (setq bibtex-entry 
     	  (buffer-substring 
          	(string-match "@" (buffer-string))
              (point)))
     (kill-buffer (current-buffer))))
 (insert (decode-coding-string bibtex-entry 'utf-8))
 (bibtex-fill-entry))

This will ask you for the DOI (you can keep the http://dx.doi.org/ bit that you get if you do ‘Copy Link Address’ from the browser), pull the BibTeX entry via the DOI API, and insert it at point. (I’m assuming the buffer is in bibtex-mode already, since it doesn’t really make sense for it not to be.) Put this in your init.el and you can now do M-x get-bibtex-from-doi, or bind it to a keychord of your choice. The entry might still need fiddling with (e.g. to fix the citekey in line with your scheme, or to remove the Unicode characters if need be), but hopefully this might be useful.


Blog archive  |
 
comments powered by Disqus
 

About me

I’m Pavel Iosad, and I'm a Lecturer in Theoretical Phonology in the department of Linguistics and English Language at the University of Edinburgh. ¶ You can always go to the start page to learn more.

elsewhere

Updates

Subscribe to the  RSS feed, or follow me on Twitter at  @anghyflawn.

Search