X-Git-Url: https://git.donarmstrong.com/?p=org-ref.git;a=blobdiff_plain;f=arxiv.el;h=783719535f48a44cc58da1b8a0a6735b6a4f268b;hp=f83e768bdd65796679392c8153bc6c6d125c51cf;hb=dc95e48a4703e9f1e17aa5cebfe8f8af825b5829;hpb=4485ccb1a5c4a3e6541e55c88377edeec18eb61c
diff --git a/arxiv.el b/arxiv.el
index f83e768..7837195 100644
--- a/arxiv.el
+++ b/arxiv.el
@@ -19,11 +19,14 @@
;; along with this program. If not, see .
;;; Commentary:
-
+;; this library creates a new org-link for Arxiv (http://arxiv.org/) entries,
+;; and provides functions to retrieve bibtex entries from an Arxiv number.
;;
+;; An Arxiv number might look like: cond-mat/0410285 or 1503.01742
;;; Code:
-
+;; * The org-mode link
+;; this just makes a clickable link that opens the entry.
(org-add-link-type
"arxiv"
;; clicking
@@ -90,5 +93,29 @@
(save-buffer)))
+(defun arxiv-get-pdf (arxiv-number pdf)
+ "Retrieve a pdf for ARXIV-NUMBER and save it to PDF."
+ (interactive "sarxiv: \nsPDF: ")
+ (let ((pdf-url (with-current-buffer
+ (url-retrieve-synchronously
+ (concat
+ "http://arxiv.org/abs/" arxiv-number))
+ ;;
+ (search-forward-regexp
+ "name=\\\"citation_pdf_url\\\" content=\\\"\\(.*\\)\\\"")
+ (match-string 1))))
+ (url-copy-file pdf-url pdf)
+ ;; now check if we got a pdf
+ (with-temp-buffer
+ (insert-file-contents pdf-file)
+ ;; PDFS start with %PDF-1.x as the first few characters.
+ (if (not (string= (buffer-substring 1 6) "%PDF-"))
+ (progn
+ (message "%s" (buffer-string))
+ (delete-file pdf-file))
+ (message "%s saved" pdf-file)))
+
+ (org-open-file pdf)))
+
(provide 'arxiv)
;;; arxiv.el ends here