Skip to content

Instantly share code, notes, and snippets.

@lgatto
Created January 27, 2024 16:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lgatto/f54888e7f16968f853346c67b232cae0 to your computer and use it in GitHub Desktop.
Save lgatto/f54888e7f16968f853346c67b232cae0 to your computer and use it in GitHub Desktop.
Create and yank bibtex entry from a DOI
(defun yank-bibtex-from-doi ()
"Create and yank bibtex entry from a DOI."
(interactive)
;; read the doi from minibuffer
(setq doi (read-from-minibuffer "doi: "))
;; define the curl shell command
(setq cmd
(concat
"curl -LH \"Accept: application/x-bibtex\" "
"https://doi.org/"
doi))
;; define the bibtex entry by calling the cmd and strip stderr
(setq bibtex
(shell-command-to-string
(concat cmd " 2>/dev/null")
)
)
(insert-for-yank bibtex)
)
@sje30
Copy link

sje30 commented Jan 29, 2024

the comment re: global vars is simply that after running your function, C-h v RET bibtex RET will show you the value of the bibtex variable. This might be intended, as it helps with debugging, but for finished functions, it is better to not clobber the global environment.

@lgatto
Copy link
Author

lgatto commented Jan 29, 2024

Thank you very much! The global var is a mistake, thank you for showing me (let*).

I also get the bibtex entry as a single long line (also from the command line). However, C-c C-q doesn't work for me (tested two GNU/Linux distros), but bibtex-reformat does exactly what I need.

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