From 4485ccb1a5c4a3e6541e55c88377edeec18eb61c Mon Sep 17 00:00:00 2001 From: John Kitchin Date: Sun, 8 Mar 2015 20:11:40 -0400 Subject: [PATCH] create arxiv functions for getting a bibtex entry from arxiv. --- arxiv.el | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/arxiv.el b/arxiv.el index c5548c1..f83e768 100644 --- a/arxiv.el +++ b/arxiv.el @@ -1,3 +1,29 @@ +;;; arxiv.el --- arxiv utilities for org-mode -*- lexical-binding: t; -*- + +;; Copyright (C) 2015 John Kitchin + +;; Author: John Kitchin +;; Keywords: + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Commentary: + +;; + +;;; Code: + (org-add-link-type "arxiv" ;; clicking @@ -12,3 +38,57 @@ (format "\\url{http://arxiv.org/abs/%s}" keyword))))) ;; arxiv:cond-mat/0410285 + +;; * Getting a bibtex entry for an arxiv article +;; For an arxiv article, there is a link to a NASA ADS page like this: +;; http://adsabs.harvard.edu/cgi-bin/bib_query?arXiv:1503.01742 +;; On that page, there is a link to a bibtex entry: +;; http://adsabs.harvard.edu/cgi-bin/nph-bib_query?bibcode=2015arXiv150301742H&data_type=BIBTEX&db_key=PRE&nocookieset=1 +;; +;; It looks like you need to get a Bibliographic code from the arxiv number to +;; then get the bibtex entry. + +(defun arxiv-get-bibliographic-code (arxiv-number) + "Get Bibliographic code for ARXIV-NUMBER." + (with-current-buffer + (url-retrieve-synchronously + (concat + "http://adsabs.harvard.edu/cgi-bin/bib_query?arXiv:" + arxiv-number)) + (search-forward-regexp "name=\\\"bibcode\\\" value=\\\"\\(.*\\)\\\"") + (match-string 1))) + +(defun arxiv-get-bibtex-entry (arxiv-bibliographic-code) + "Get bibtex entry for ARXIV-BIBLIOGRAPHIC-CODE" + (with-current-buffer + (url-retrieve-synchronously + (format + "http://adsabs.harvard.edu/cgi-bin/nph-bib_query?bibcode=%s&data_type=BIBTEX&db_key=PRE&nocookieset=1" + arxiv-bibliographic-code)) + (goto-char url-http-end-of-headers) + (if (search-forward "Retrieved 1 abstracts" (point-max) t) + (progn + (forward-line) + (buffer-substring (point) (point-max))) + (error "Did not get one entry: %s" (buffer-substring (point) (point-max)))))) + + +(defun arxiv-add-bibtex-entry (arxiv-number bibfile) + "Add bibtex entry for ARXIV-NUMBER to BIBFILE." + (interactive + (list (read-input "arxiv: ") + ;; now get the bibfile to add it to + (ido-completing-read + "Bibfile: " + (append (f-entries "." (lambda (f) (f-ext? f "bib"))) + org-ref-default-bibliography)))) + (save-window-excursion + (find-file bibfile) + (goto-char (point-max)) + (when (not (looking-at "^")) (insert "\n")) + (insert (arxiv-get-bibtex-entry (arxiv-get-bibliographic-code arxiv-number))) + (save-buffer))) + + +(provide 'arxiv) +;;; arxiv.el ends here -- 2.39.2