-;; This package provides functionality to download PDFs and bibtex entries from a DOI, as well as to update a bibtex entry from a DOI. It depends slightly on org-ref, to determine where to save pdf files too, and where to insert bibtex entries in the default bibliography.
+;; This package provides functionality to download PDFs and bibtex entries from a DOI, as well as to update a bibtex entry from a DOI. It depends slightly on org-ref, to determine where to save pdf files too, and where to insert bibtex entries in the default bibliography.
;; The principle commands you will use from here are:
;; The principle commands you will use from here are:
;; There are some subtleties in doing this that are described here. To get the redirect, we have to use url-retrieve, and a callback function. The callback does not return anything, so we communicate through global variables. url-retrieve is asynchronous, so we have to make sure to wait for it to finish.
(defvar *doi-utils-waiting* t
;; There are some subtleties in doing this that are described here. To get the redirect, we have to use url-retrieve, and a callback function. The callback does not return anything, so we communicate through global variables. url-retrieve is asynchronous, so we have to make sure to wait for it to finish.
(defvar *doi-utils-waiting* t
- "stores waiting state for url retrieval.")
+ "Stores waiting state for url retrieval.")
(defvar *doi-utils-redirect* nil
(defvar *doi-utils-redirect* nil
- "stores redirect url from a callback function")
+ "Stores redirect url from a callback function.")
;; Once we have a redirect for a particular doi, we need to compute the url to the pdf. We do this with a series of functions. Each function takes a single argument, the redirect url. If it knows how to compute the pdf url it does, and returns it. We store the functions in a variable:
(defvar doi-utils-pdf-url-functions nil
;; Once we have a redirect for a particular doi, we need to compute the url to the pdf. We do this with a series of functions. Each function takes a single argument, the redirect url. If it knows how to compute the pdf url it does, and returns it. We store the functions in a variable:
(defvar doi-utils-pdf-url-functions nil
- "list of functions that return a url to a pdf from a redirect url. Each function takes one argument, the redirect url. The function must return a pdf-url, or nil.")
+ "List of functions that return a url to a pdf from a redirect url. Each function takes one argument, the redirect url. The function must return a pdf-url, or nil.")
;; ** APS journals
;; ** APS journals
@@ -220,7+220,7 @@ We get it out here by parsing the html."
"stores url to pdf download from a callback function")
;; I [[http://homepages.see.leeds.ac.uk/~eeaol/notes/2013/02/doi-metadata/][found]] you can download metadata about a DOI from http://dx.doi.org. You just have to construct the right http request to get it. Here is a function that gets the metadata as a plist in emacs.
(defun doi-utils-get-json-metadata (doi)
;; I [[http://homepages.see.leeds.ac.uk/~eeaol/notes/2013/02/doi-metadata/][found]] you can download metadata about a DOI from http://dx.doi.org. You just have to construct the right http request to get it. Here is a function that gets the metadata as a plist in emacs.
(defun doi-utils-get-json-metadata (doi)
- "Try to get json metadata for DOI. Open the DOI in a browser if we do not get it."
+ "Try to get json metadata for DOI. Open the DOI in a browser if we do not get it."
;; We can use that data to construct a bibtex entry. We do that by defining a template, and filling it in. I wrote this template expansion code which makes it easy to substitute values like %{} in emacs lisp.
(defun doi-utils-expand-template (s)
(json-read-from-string json-data)))))
;; We can use that data to construct a bibtex entry. We do that by defining a template, and filling it in. I wrote this template expansion code which makes it easy to substitute values like %{} in emacs lisp.
(defun doi-utils-expand-template (s)
- "expand a template containing %{} with the eval of its contents"
+ "Expand a template containing %{} with the eval of its contents."
(replace-regexp-in-string "%{\\([^}]+\\)}"
(lambda (arg)
(let ((sexp (substring arg 2 -1)))
(replace-regexp-in-string "%{\\([^}]+\\)}"
(lambda (arg)
(let ((sexp (substring arg 2 -1)))
@@ -434,7+434,7 @@ when the `:type' parameter in the JSON metadata is contained in
@@ -629,6+629,8 @@ prompt. Otherwise, you have to type or pste in a DOI."
(defun doi-utils-update-field ()
(defun doi-utils-update-field ()
+ "Update the field at point in the bibtex entry.
+Data is retrieved from the doi in the entry."
(interactive)
(let* ((doi (bibtex-autokey-get-field "doi"))
(results (doi-utils-get-json-metadata doi))
(interactive)
(let* ((doi (bibtex-autokey-get-field "doi"))
(results (doi-utils-get-json-metadata doi))
@@ -658,14+660,14 @@ prompt. Otherwise, you have to type or pste in a DOI."
;; These are pretty easy to construct, so we can write functions that will create them and open the url in our browser. There are some other options that could be considered, but since we usually have a doi, it seems like the best way to go for creating the links. Here are the functions.
(defun doi-utils-wos (doi)
;; These are pretty easy to construct, so we can write functions that will create them and open the url in our browser. There are some other options that could be considered, but since we usually have a doi, it seems like the best way to go for creating the links. Here are the functions.
;; The idea here is to perform a query on Crossref, get a helm buffer of candidates, and select the entry(ies) you want to add to your bibtex file. You can select a region, e.g. a free form citation, or set of words, or you can type the query in by hand.
;; The idea here is to perform a query on Crossref, get a helm buffer of candidates, and select the entry(ies) you want to add to your bibtex file. You can select a region, e.g. a free form citation, or set of words, or you can type the query in by hand.