From 4f826a6c9b6d59fe82b1ec7787ede7253fb344be Mon Sep 17 00:00:00 2001 From: Dimitri Lozeve Date: Thu, 24 Jun 2021 17:58:51 +0200 Subject: [PATCH] Add function to retrieve formatted citation from DOI Uses the API of the DOI service directly. Before, I had to add them to the bibtex file or use an external service like citation.crosscite.org. Now I can just copy-paste the DOI and get the formatted citation in the kill-ring directly. --- init.el | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/init.el b/init.el index 66a32f2..c105696 100644 --- a/init.el +++ b/init.el @@ -689,20 +689,32 @@ (require 'org-ref-isbn) (require 'org-ref-arxiv) - (setq bibtex-autokey-year-length 4)) + (setq bibtex-autokey-year-length 4) -(defun dl/formatted-citation-at-point () - "Kill the formatted citation for the reference at point using Pandoc." - (interactive) - (let* ((bibfile (expand-file-name (car (org-ref-find-bibliography)))) - (cslfile (concat (file-name-directory bibfile) "chicago-author-date.csl"))) - (kill-new - (shell-command-to-string - (format - "echo cite:%s | pandoc --filter=pandoc-citeproc --bibliography=%s --csl=%s -f org -t markdown_strict | tail -n +3 | tr '\n' ' '" - (org-ref-get-bibtex-key-under-cursor) - bibfile - cslfile))))) + (defun dl/formatted-citation-at-point () + "Kill the formatted citation for the reference at point using Pandoc." + (interactive) + (let* ((bibfile (expand-file-name (car (org-ref-find-bibliography)))) + (cslfile (concat (file-name-directory bibfile) "chicago-author-date.csl"))) + (kill-new + (shell-command-to-string + (format + "echo cite:%s | pandoc --filter=pandoc-citeproc --bibliography=%s --csl=%s -f org -t markdown_strict | tail -n +3 | tr '\n' ' '" + (org-ref-get-bibtex-key-under-cursor) + bibfile + cslfile))))) + + (defun dl/formatted-citation-from-doi (doi) + "Kill the formatted citation for the given DOI." + (interactive + (list (read-string + "DOI: " + ;; now set initial input + (doi-utils-maybe-doi-from-region-or-current-kill)))) + (let ((url-mime-accept-string "text/x-bibliography; style=chicago-author-date")) + (with-temp-buffer + (url-insert-file-contents (format "https://doi.org/%s" doi)) + (kill-new (buffer-string)))))) (use-package org-roam :straight t