Org-ref code in doom emacs init file

Hi! This is my first post so please be gentle. I am on doom emacs, and an ivy-bibtex user since about a year back and installed org-roam-bibtex yesterday. I have managed so far to set up a system within org-roam-bibtex so that my slip-notes goes into one folder and my literature notes goes into a subfolder of that folder. I have also managed to make my slip notes have title, roam alias, and time stamps for created and last modified. As for the literature notes I have made them have a title that starts with their citekey, and include a roam keyand time stamps for createdand last modified. So far so good. However, I have so far not manage to integrate the org-ref part into my system, meaning I cannot use org-noter for reading and citing an article that I am reading. I have tried to enter some org-ref code into my init file following the instructions on org-ref’s github page but I do not get it to work. I would therefore really need som guidance on how to integrate the org-ref and org-noter code into my current init file code. Please remember that I am on doom emacs. Below is the code relevant for the set up in config.el:

;;------------------------------------------------------------------------------------
;; org
;;------------------------------------------------------------------------------------
;; If you use `org' and don't want your org files in the default location below,
;; change `org-directory'. It must be set before org loads!
(setq org-directory "~/org/")

;;------------------------------------------------------------------------------------
;; pdf-tools
;;------------------------------------------------------------------------------------
(use-package! pdf-tools
  :load-path "site-lisp/pdf-tools/lisp"
  :magic ("%PDF" . pdf-view-mode)
  :config
  (pdf-tools-install :no-query)
  (setq-default pdf-view-display-size 'fit-page)
  (setq pdf-annot-activate-created-annotations t)
  (setq pdf-view-resize-factor 1.1)
  (setq pdf-view-use-unicode-ligther nil)
  )

;;---------------------------------------------------------------------------------------
;;  ivy-bibtex
;;---------------------------------------------------------------------------------------
(autoload 'ivy-bibtex "ivy-bibtex" "" t)
;; ivy-bibtex requires ivy's `ivy--regex-ignore-order` regex builder, which
;; ignores the order of regexp tokens when searching for matching candidates.
;; Add something like this to your init file:
(setq ivy-re-builders-alist
      '((ivy-bibtex . ivy--regex-ignore-order)
        (t . ivy--regex-plus)))
(setq bibtex-completion-bibliography "/Users/joafr/Documents/bibfiles/library.bib"
      bibtex-completion-library-path "/Users/joafr/Documents/bibpdfs"
      bibtex-completion-notes-path "/Users/joafr/Documents/bibnotes"
      bibtex-completion-notes-extension ".org"
      bibtex-completion-find-additional-pdfs t
      bibtex-completion-notes-template-multiple-files "Notes on ${author-or-editor} (${year}) - ${title}"
      bibtex-completion-notes-template-one-file "# Notes on ${author-or-editor} (${year}): ${title}")
(delete-file "~/Library/Colors/Emacs.clr")

;;------------------------------------------------------------------------------------
;; org-roam
;;------------------------------------------------------------------------------------
(setq org-roam-directory "/Users/joafr/org/zettelkasten")
 (use-package! org-roam-bibtex
  :after org-roam
  :hook (org-roam-mode . org-roam-bibtex-mode)
  :bind (:map org-mode-map
         (("C-c n a" . orb-note-actions)))
  :config
  (require 'org-ref)) ; optional: if Org Ref is not loaded anywhere else, load it here

;;;; Add the cite-key in the title of the notes and make sure they end up in bibnotes folder.
(setq orb-templates
      '(("r" "ref" plain (function org-roam-capture--get-point) "%?"
         :file-name "bibnotes/${citekey}"
         :head "#+TITLE: ${citekey}: ${title}\n#+ROAM_KEY: ${ref}\n#+CREATED: %U\n#+LAST_MODIFIED: %U\n"
         :unnarrowed t)))

(setq org-roam-capture-templates
        '(("d" "default" plain (function org-roam-capture--get-point) "%?"
         :file-name "%<%Y%m%d%H%M%S>-${slug}"
         :head "#+TITLE: ${title}\n#+ROAM_ALIAS: \n#+CREATED: %U\n#+LAST_MODIFIED: %U\n"
         :unnarrowed t)))

In my ìnit.el`, I have simply written:
Skärmavbild 2021-04-18 kl. 12.50.21

An in my packages.el file I have included the following code:

(package! pdf-tools)
(package! ivy-bibtex)
(package! pandoc)
(package! polymode)
(package! poly-R)
(package! poly-markdown)
(package! doom-themes)
(package! org-noter)
(package! org-roam-bibtex
  :recipe (:host github :repo "org-roam/org-roam-bibtex"))

;; When using org-roam via the `+roam` flag
(unpin! org-roam)

;; When using bibtex-completion via the `biblio` module
(unpin! bibtex-completion helm-bibtex ivy-bibtex)

Grateful for any help I can get.

Hi, here is my Doom config for Org-ref.

First, you need to tell Doom to install Org-ref. In packages.el you should have:

(package! org-ref)

Second, you need to tell Doom some details on how to load and configure the package. In config.el you should have somethings like this:

(use-package! org-ref

  ;; this bit is highly recommended: make sure Org-ref is loaded after Org
  :after org

  ;; Put any Org-ref commands here that you would like to be auto loaded:
  ;; you'll be able to call these commands before the package is actually loaded.
  :commands
  (org-ref-cite-hydra/body
   org-ref-bibtex-hydra/body)

  ;; if you don't need any autoloaded commands, you'll need the following
  ;; :defer t

  ;; This initialization bit puts the `orhc-bibtex-cache-file` into `~/.doom/.local/cache/orhc-bibtex-cache
  ;; Not strictly required, but Org-ref will pollute your home directory otherwise, creating the cache file in ~/.orhc-bibtex-cache
  :init
  (let ((cache-dir (concat doom-cache-dir "org-ref")))
    (unless (file-exists-p cache-dir)
      (make-directory cache-dir t))
    (setq orhc-bibtex-cache-file (concat cache-dir "/orhc-bibtex-cache"))))

Third, you should load the package. In principle, you could interactively call one of the commands specified in the :commands section, but that means that all of the Org-ref functionality will not be available until you do this. Most notably, cite:links will not be recognized in your Org documents. Furthermore, Org Roam BibTeX requires Org-ref be loaded to function properly. Therefore, it is advisable to load Org-ref explicitly with a (require 'org-ref) statement somewhere in your config.el.

Something like the following should probably be fine.

(after! org
  (require 'org-ref))

or

(after! org-roam 
  (require 'org-ref))

Alternatively, you could load it with some other package that is loaded after Org.

I load it with my private package that contains additional functions and config for Org, but Org Roam BibTeX is a good place too:

(use-package! org-roam-bibtex
  :after org-roam
  :hook (org-roam-mode . org-roam-bibtex-mode)
  :config
  (require 'org-ref))

Remember, you need only one (require 'org-ref) statement, so choose what is most appropriate in your situation.

1 Like

Thanks a lot @mshevchuk for making the effort to provide me with such an informative and detailed answer! I really appreciate it. I will go through your feedback and come back to you after I have made the suggested edits and tell you how it worked out.