update packages
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
;;; org-ref-arxiv.el --- arxiv utilities for org-mode -*- lexical-binding: t; -*-
|
||||
|
||||
;; Copyright (C) 2015 John Kitchin
|
||||
;; Copyright (C) 2015-2021 John Kitchin
|
||||
|
||||
;; Author: John Kitchin <jkitchin@andrew.cmu.edu>
|
||||
;; Keywords:
|
||||
@@ -33,12 +33,12 @@
|
||||
(require 'org-ref-utils)
|
||||
(require 'parsebib)
|
||||
|
||||
(require 'xml)
|
||||
|
||||
;; This is a local variable defined in `url-http'. We need it to avoid
|
||||
;; byte-compiler errors.
|
||||
(defvar url-http-end-of-headers)
|
||||
(defvar org-ref-default-bibliography)
|
||||
(defvar org-ref-pdf-directory)
|
||||
|
||||
|
||||
(declare-function parsebib-find-bibtex-dialect "parsebib")
|
||||
(declare-function org-ref-clean-bibtex-entry "org-ref-core")
|
||||
@@ -48,17 +48,17 @@
|
||||
;;* The org-mode link
|
||||
;; this just makes a clickable link that opens the entry.
|
||||
;; example: arxiv:cond-mat/0410285
|
||||
(org-ref-link-set-parameters "arxiv"
|
||||
:follow (lambda (link-string)
|
||||
(browse-url (format "http://arxiv.org/abs/%s" link-string)))
|
||||
:export (lambda (keyword desc format)
|
||||
(cond
|
||||
((eq format 'html)
|
||||
(format "<a href=\"http://arxiv.org/abs/%s\">arxiv:%s</a>"
|
||||
keyword (or desc keyword)))
|
||||
((eq format 'latex)
|
||||
;; write out the latex command
|
||||
(format "\\url{http://arxiv.org/abs/%s}{%s}" keyword (or desc keyword))))))
|
||||
(org-link-set-parameters "arxiv"
|
||||
:follow (lambda (link-string)
|
||||
(browse-url (format "http://arxiv.org/abs/%s" link-string)))
|
||||
:export (lambda (keyword desc format)
|
||||
(cond
|
||||
((eq format 'html)
|
||||
(format "<a href=\"http://arxiv.org/abs/%s\">arxiv:%s</a>"
|
||||
keyword (or desc keyword)))
|
||||
((eq format 'latex)
|
||||
;; write out the latex command
|
||||
(format "\\url{http://arxiv.org/abs/%s}{%s}" keyword (or desc keyword))))))
|
||||
|
||||
;;* Getting a bibtex entry for an arXiv article using remote service:
|
||||
;; For an arxiv article, there is a link to a NASA ADS page like this:
|
||||
@@ -76,23 +76,18 @@
|
||||
(concat
|
||||
"http://adsabs.harvard.edu/cgi-bin/bib_query?arXiv:"
|
||||
arxiv-number))
|
||||
(search-forward-regexp "name=\\\"bibcode\\\" value=\\\"\\(.*\\)\\\"")
|
||||
(search-forward-regexp "<link rel=\"canonical\" href=\"http://ui.adsabs.harvard.edu/abs/\\(.*\\)/abstract\"/>")
|
||||
(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))))))
|
||||
(url-retrieve-synchronously (format "https://ui.adsabs.harvard.edu/abs/%s/exportcitation" arxiv-bibliographic-code))
|
||||
(when (re-search-forward
|
||||
"<textarea.*>\\(.*\\(?:\n.*\\)*?\\(?:\n\\s-*\n\\|\\'\\)\\)</textarea>"
|
||||
nil t)
|
||||
(xml-substitute-special (match-string 1)))))
|
||||
|
||||
;;* Getting a bibtex entry for an arXiv article using arXiv API:
|
||||
;; Retrieves the meta data of an article view arXiv's http API,
|
||||
@@ -109,9 +104,12 @@
|
||||
abstract = {%s},
|
||||
url = {%s},
|
||||
}"
|
||||
"Template for BibTeX entries of arXiv articles.")
|
||||
"Template for BibTeX entries of arXiv articles.")
|
||||
|
||||
|
||||
(declare-function doi-utils-doi-to-bibtex-string "doi-utils")
|
||||
(declare-function org-ref-replace-nonascii "org-ref-bibtex")
|
||||
|
||||
(defun arxiv-get-bibtex-entry-via-arxiv-api (arxiv-number)
|
||||
"Retrieve meta data for ARXIV-NUMBER.
|
||||
Returns a formatted BibTeX entry."
|
||||
@@ -137,8 +135,12 @@ Returns a formatted BibTeX entry."
|
||||
(bibtex-mode)
|
||||
(bibtex-set-dialect (parsebib-find-bibtex-dialect) t)
|
||||
(org-ref-replace-nonascii)
|
||||
(bibtex-generate-autokey))))
|
||||
(format arxiv-entry-format-string key title names year arxiv-number category abstract url))))
|
||||
(bibtex-generate-autokey)))
|
||||
(doi (assq 'doi entry)))
|
||||
(if doi
|
||||
(doi-utils-doi-to-bibtex-string (nth 2 doi))
|
||||
;; no doi, so we fall back to the simple template
|
||||
(format arxiv-entry-format-string key title names year arxiv-number category abstract url)))))
|
||||
|
||||
|
||||
(defun arxiv-bibtexify-authors (authors)
|
||||
@@ -153,33 +155,39 @@ Returns a formatted BibTeX entry."
|
||||
(let* ((the-current-kill (ignore-errors (current-kill 0 t))) ;; nil if empty kill ring
|
||||
(arxiv-url-prefix-regexp "^https?://arxiv\\.org/\\(pdf\\|abs\\|format\\)/")
|
||||
(arxiv-cite-prefix-regexp "^\\(arXiv\\|arxiv\\):")
|
||||
(arxiv-id-old-regexp "[a-z-]+\\(\\.[A-Z]\\{2\\}\\)?/[0-9]\\{5,7\\}$") ; Ex: math.GT/0309136
|
||||
(arxiv-id-new-regexp "[0-9]\\{4\\}[.][0-9]\\{4,5\\}\\(v[0-9]+\\)?$") ; Ex: 1304.4404v2
|
||||
(arxiv-id-old-regexp "[a-z-]+\\(\\.[A-Z]\\{2\\}\\)?/[0-9]\\{5,7\\}") ; Ex: math.GT/0309136
|
||||
(arxiv-id-new-regexp "[0-9]\\{4\\}[.][0-9]\\{4,5\\}\\(v[0-9]+\\)?") ; Ex: 1304.4404v2
|
||||
(arxiv-id-regexp (concat "\\(" arxiv-id-old-regexp "\\|" arxiv-id-new-regexp "\\)")))
|
||||
(cond
|
||||
(;; make sure current-kill has something in it
|
||||
;; if current-kill is not a string, return nil
|
||||
(not (stringp the-current-kill))
|
||||
nil)
|
||||
(;; check if current-kill looks like an arxiv ID
|
||||
;; if so, return it
|
||||
;; Ex: 1304.4404v2
|
||||
(s-match (concat "^" arxiv-id-regexp) the-current-kill)
|
||||
the-current-kill)
|
||||
(;; check if current-kill looks like an arxiv cite
|
||||
;; if so, remove the prefix and return
|
||||
;; Ex: arXiv:1304.4404v2 --> 1304.4404v2
|
||||
(s-match (concat arxiv-cite-prefix-regexp arxiv-id-regexp) the-current-kill)
|
||||
(replace-regexp-in-string arxiv-cite-prefix-regexp "" the-current-kill))
|
||||
(;; check if current-kill looks like an arxiv url
|
||||
;; if so, remove the url prefix and return
|
||||
;; Ex: https://arxiv.org/pdf/1304.4404 --> 1304.4404
|
||||
(s-match (concat arxiv-url-prefix-regexp arxiv-id-regexp) the-current-kill)
|
||||
(replace-regexp-in-string arxiv-url-prefix-regexp "" the-current-kill))
|
||||
;; otherwise, return nil
|
||||
(t
|
||||
nil))))
|
||||
(cond
|
||||
(;; make sure current-kill has something in it
|
||||
;; if current-kill is not a string, return nil
|
||||
(not (stringp the-current-kill))
|
||||
nil)
|
||||
(;; check if current-kill looks like an arxiv ID
|
||||
;; if so, return it
|
||||
;; Ex: 1304.4404v2
|
||||
(s-match (concat "^" arxiv-id-regexp) the-current-kill)
|
||||
the-current-kill)
|
||||
(;; check if current-kill looks like an arxiv cite
|
||||
;; if so, remove the prefix and return
|
||||
;; Ex: arXiv:1304.4404v2 --> 1304.4404v2
|
||||
(s-match (concat arxiv-cite-prefix-regexp arxiv-id-regexp "$") the-current-kill)
|
||||
(replace-regexp-in-string arxiv-cite-prefix-regexp "" the-current-kill))
|
||||
(;; check if current-kill looks like an arxiv url
|
||||
;; if so, remove the url prefix and return
|
||||
;; Ex: https://arxiv.org/abs/1304.4404 --> 1304.4404
|
||||
(s-match (concat arxiv-url-prefix-regexp arxiv-id-regexp "$") the-current-kill)
|
||||
(replace-regexp-in-string arxiv-url-prefix-regexp "" the-current-kill))
|
||||
(;; check if current-kill looks like an arxiv PDF url
|
||||
;; if so, remove the url prefix, the .pdf suffix, and return
|
||||
;; Ex: https://arxiv.org/pdf/1304.4404.pdf --> 1304.4404
|
||||
(s-match (concat arxiv-url-prefix-regexp arxiv-id-regexp "\\.pdf$") the-current-kill)
|
||||
(replace-regexp-in-string arxiv-url-prefix-regexp "" (substring the-current-kill 0 (- (length the-current-kill) 4))))
|
||||
;; otherwise, return nil
|
||||
(t
|
||||
nil))))
|
||||
|
||||
(defvar bibtex-completion-bibliography)
|
||||
|
||||
;;;###autoload
|
||||
(defun arxiv-add-bibtex-entry (arxiv-number bibfile)
|
||||
@@ -192,7 +200,7 @@ Returns a formatted BibTeX entry."
|
||||
(completing-read
|
||||
"Bibfile: "
|
||||
(append (f-entries "." (lambda (f) (f-ext? f "bib")))
|
||||
org-ref-default-bibliography))))
|
||||
bibtex-completion-bibliography))))
|
||||
(save-window-excursion
|
||||
(find-file bibfile)
|
||||
(goto-char (point-max))
|
||||
@@ -224,11 +232,12 @@ Returns a formatted BibTeX entry."
|
||||
(match-string 1))))
|
||||
(url-copy-file pdf-url pdf)
|
||||
;; now check if we got a pdf
|
||||
(if (org-ref-pdf-p pdf)
|
||||
(org-open-file pdf)
|
||||
(unless (org-ref-pdf-p pdf)
|
||||
(delete-file pdf)
|
||||
(message "Error downloading arxiv pdf %s" pdf-url))))
|
||||
|
||||
(defvar bibtex-completion-library-path)
|
||||
|
||||
;;;###autoload
|
||||
(defun arxiv-get-pdf-add-bibtex-entry (arxiv-number bibfile pdfdir)
|
||||
"Add bibtex entry for ARXIV-NUMBER to BIBFILE.
|
||||
@@ -243,10 +252,14 @@ key."
|
||||
(completing-read
|
||||
"Bibfile: "
|
||||
(append (f-entries "." (lambda (f) (f-ext? f "bib")))
|
||||
org-ref-default-bibliography))
|
||||
(read-directory-name
|
||||
"PDF directory: "
|
||||
org-ref-pdf-directory)))
|
||||
bibtex-completion-bibliography))
|
||||
(cond
|
||||
((stringp bibtex-completion-library-path)
|
||||
bibtex-completion-library-path)
|
||||
((= 1 (length bibtex-completion-library-path))
|
||||
(car bibtex-completion-library-path))
|
||||
(t
|
||||
(completing-read "PDF dir: " bibtex-completion-library-path)))))
|
||||
|
||||
(arxiv-add-bibtex-entry arxiv-number bibfile)
|
||||
|
||||
@@ -276,7 +289,13 @@ key."
|
||||
(setq key (bibtex-read-key "Duplicate Key found, edit: " key))))
|
||||
(setq key (bibtex-read-key "Key not found, insert: ")))
|
||||
(insert key)
|
||||
(arxiv-get-pdf arxiv-number (concat pdfdir key ".pdf")))))
|
||||
(arxiv-get-pdf arxiv-number (concat pdfdir key ".pdf"))
|
||||
;; Check that it worked, and insert a field for it.
|
||||
(when (file-exists-p (concat pdfdir key ".pdf"))
|
||||
(bibtex-end-of-entry)
|
||||
(backward-char)
|
||||
(insert (format " file = {%s}\n " (concat pdfdir key ".pdf")))))))
|
||||
|
||||
|
||||
(provide 'org-ref-arxiv)
|
||||
;;; org-ref-arxiv.el ends here
|
||||
|
||||
Reference in New Issue
Block a user