Add function to get bibtex from doi.

This commit is contained in:
2022-01-21 17:33:47 +00:00
parent 4f9a4b2a7c
commit 515bb8dbf6

View File

@@ -168,7 +168,25 @@
;;TRAMP
(load "~/.emacs.d/elisp/tramp-setup.el")
(load "~/.emacs.d/elisp/outline-keymap.el")
(load "~/.emacs.d/elisp/bibtex-setup.el")
(load "~/.emacs.d/elisp/keypad.el")
;; from https://www.anghyflawn.net/blog/2014/emacs-give-a-doi-get-a-bibtex-entry/
(defun get-bibtex-from-doi (doi)
"Get a BibTeX entry from the DOI"
(interactive "MDOI: ")
(let ((url-mime-accept-string "text/bibliography;style=bibtex"))
(with-current-buffer
(url-retrieve-synchronously
(format "http://dx.doi.org/%s"
(replace-regexp-in-string "http://dx.doi.org/" "" doi)))
(switch-to-buffer (current-buffer))
(goto-char (point-max))
(setq bibtex-entry
(buffer-substring
(string-match "@" (buffer-string))
(point)))
(kill-buffer (current-buffer))))
(insert (decode-coding-string bibtex-entry 'utf-8))
(bibtex-fill-entry))