Skip to content

akirakyle/emacs-doi2bib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 

Repository files navigation

doi2bib

Description

This package was adapted from doi-utils.el which is provided as part of John Kitchin’s org-ref package. This package simply provides the command doi2bib-add-bibtex-entry-from-doi which adds an entry to a a bibtex file

Motivation

I created this because this was the only thing I used biblio.el for and biblio.el could not give me properly formatted entries with the pages field filled in, specifically for articles from American Physical Society journals. The system in doi-utils.el is more flexible since it parses all the crossref information available as citeproc+json instead of just asking directly for bibtex.

Configuration

  • Set doi2bib-bibtex-file to a bibtex file you want to be the default used when prompted for a bibtex entry.
    • Set doi2bib-disable-bibtex-prompt to not be prompted for a bibtex file and always use doi2bib-bibtex-file.
  • Set bibtex-autokey-edit-before-use to nil if you don’t want to be prompted for editing the bibtex key.
    • Also see emacs’ builtin bibtex.el for more options on how to configure key generation and formatting. Here’s my settings
(use-package bibtex
  :init
  (setq bibtex-autokey-year-title-separator "_")
  (setq bibtex-entry-format t)
  (setq bibtex-align-at-equal-sign t)
  :config
  (setq bibtex-autokey-titleword-ignore
        (remove "[^[:upper:]].*" bibtex-autokey-titleword-ignore))
  
  (setq bibtex-BibTeX-entry-alist
        (mapcar (lambda (e) (cons (downcase (car e)) (cdr e)))
                bibtex-BibTeX-entry-alist))

  (setq bibtex-biblatex-entry-alist
        (mapcar (lambda (e) (cons (downcase (car e)) (cdr e)))
                bibtex-BibTeX-entry-alist))
  )

Integration with citar-org-roam

Hopefully someday I’ll write up my workflow using this package, but for now here’s a snippet of by config that sets up a handy shortcut which integrates with ~citar-org-roam~ to capture an org roam note based on a doi.

(use-package citar-org-roam
  :after citar org-roam
  :config
  (citar-org-roam-mode)
  
  (defun my-citar-org-roam--create-capture-note (citekey entry)
    "Open or create org-roam node for CITEKEY and ENTRY."
    (let ((title (citar-format--entry
                  "${author} (${year}): ${title}" entry)))
      (org-roam-capture-
       :templates
       '(("r" "reference" plain "%?" :if-new
          (file+head "references/${citekey}.org" "#+title: ${title}\n")
          :immediate-finish t
          :unnarrowed t))
       :info (list :citekey citekey)
       :node (org-roam-node-create :title title)
       :props '(:finalize find-file))
      (org-roam-ref-add (concat "@" citekey))
      (org-set-property "DOI" (citar-format--entry "${doi}" entry))))

  (citar-register-notes-source
   'my-citar-org-roam-source 
   (list :name "Org-Roam Notes"
         :category 'org-roam-node
         :items 'citar-org-roam--get-candidates
         :hasitems 'citar-org-roam-has-notes
         :open 'citar-org-roam-open-note
         :create 'my-citar-org-roam--create-capture-note
         :annotate 'citar-org-roam--annotate))
  (setq citar-notes-source 'my-citar-org-roam-source)
  )

(use-package doi2bib
  :straight (doi2bib :type git :host github :repo "akirakyle/emacs-doi2bib")
  :init 
  (setq doi2bib-bibtex-file (car citar-bibliography))
  (setq doi2bib-disable-bibtex-prompt t)
  
  (defun my-add-doi-to-org-roam ()
    (interactive)
    (citar-create-note
     (cdr (assoc "=key=" (call-interactively 'doi2bib-add-bibtex-entry-from-doi)))))
  (my-leader-def "ad" 'my-add-doi-to-org-roam)
  )

About

Emacs function to add a bibtex entry from a DOI

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published