Skip to content

Instantly share code, notes, and snippets.

@tmalsburg
Last active April 16, 2024 09:27
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmalsburg/c4e8c9bc9a94a7f9faea21f1c7b2cd0f to your computer and use it in GitHub Desktop.
Save tmalsburg/c4e8c9bc9a94a7f9faea21f1c7b2cd0f to your computer and use it in GitHub Desktop.
An Emacs command that takes the DOI in the clipboard and inserts the corresponding BibTeX entry at point.
(require 'url-http)
(defun insert-bibtex-from-doi ()
(interactive)
(let* ((doi (string-trim (gui-get-primary-selection)))
(url (if (string-prefix-p "https://doi.org/" doi)
doi
(concat "https://doi.org/" doi)))
(url-request-method "GET")
(url-mime-accept-string "application/x-bibtex"))
(insert
(with-current-buffer (url-retrieve-synchronously url t)
(goto-char (point-min))
(while (not (looking-at "\n"))
(forward-line 1))
(let ((string (buffer-substring-no-properties (point) (point-max))))
(kill-buffer)
(decode-coding-string (string-trim string) 'utf-8))))
(bibtex-clean-entry t)))
@tmalsburg
Copy link
Author

@abcdw
Copy link

abcdw commented Apr 16, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment