]> git.donarmstrong.com Git - org-ref.git/blobdiff - arxiv.el
use `parsebib-find-bibtex-dialect` to find the dialect
[org-ref.git] / arxiv.el
index f83e768bdd65796679392c8153bc6c6d125c51cf..4ca96afa9f6e24964776a0c49a43215d74cdba69 100644 (file)
--- a/arxiv.el
+++ b/arxiv.el
 ;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; 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
@@ -76,7 +79,7 @@
 (defun arxiv-add-bibtex-entry (arxiv-number bibfile)
   "Add bibtex entry for ARXIV-NUMBER to BIBFILE."
  (interactive
-   (list (read-input "arxiv: ")
+   (list (read-string "arxiv: ")
         ;;  now get the bibfile to add it to
         (ido-completing-read
          "Bibfile: "
    (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))
+                  ;; <meta name="citation_pdf_url" content="http://arxiv.org/pdf/0801.1144" />
+                  (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)
+      ;; 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))
+       (message "%s saved" pdf)))
+
+    (org-open-file pdf)))
+
 (provide 'arxiv)
 ;;; arxiv.el ends here