What code to write to keep literature org-notes in a subfolder of the slip-box?

I am using Doom Emacs and have managed to set up org-roam-bibtex somewhat properly now. At least all parts seems to be working without flaws or errors. However, for the moment I keep both my org-roam notes (slip-box notes) and org-ref/noter notes (literature notes) in the same folder. But I would prefer to keep my literature notes in a subfolder of the slip-box folder. Would be very grateful if someone could help me out here. Here below is the relevant code in my 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/zettelkasten")

;;------------------------------------------------------------------------------------
;;  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))

;;-------------------------------------------------------------------------------------
;;  deft
;;-------------------------------------------------------------------------------------
(setq deft-directory "/Users/joafr/org/zettelkasten/"
      deft-use-filename-as-title nil)

;;-------------------------------------------------------------------------------------
;;  ivy-bibtex
;;-------------------------------------------------------------------------------------
(after! ivy-bibtex
  :config
  (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/org/zettelkasten/"
      bibtex-completion-notes-template-multiple-files ""))

(use-package! ivy-hydra
  :demand t)

;;;;;;;;;;UGLY CODE, SHOULD BE PLACED ELSEWHERE BUT DO NOT DARE TO EDIT NOW;;;;;;;;;;
(after! org
  :config
  (setq org-directory "/Users/joafr/org/zettelkasten/"))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;------------------------------------------------------------------------------------
;;  org-ref
;;------------------------------------------------------------------------------------
(use-package! org-ref
    :after org
    :commands
    (org-ref-cite-hydra/body
     org-ref-bibtex-hydra/body)
    :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")))
    :config
    (setq
         org-ref-completion-library 'org-ref-ivy-cite
         org-ref-get-pdf-filename-function 'org-ref-get-pdf-filename-helm-bibtex
         org-ref-default-bibliography (list "/Users/joafr/Documents/bibfiles/library.bib")
         org-ref-bibliography-notes "/Users/joafr/org/zettelkasten/"
         org-ref-note-title-format "* TODO %y - %t\n :PROPERTIES:\n  :Custom_ID: %k\n  :NOTER_DOCUMENT: %F\n :ROAM_KEY: cite:%k\n  :AUTHOR: %9a\n  :JOURNAL: %j\n  :YEAR: %y\n  :VOLUME: %v\n  :PAGES: %p\n  :DOI: %D\n  :URL: %U\n :END:\n\n"
         org-ref-notes-directory "/Users/joafr/org/zettelkasten/"
         org-ref-notes-function 'orb-edit-notes
    ))

;;--------------------------------------------------------------------------------------
;;  org-roam
;;--------------------------------------------------------------------------------------
(after! org-roam
  :config
  (setq org-roam-directory "/Users/joafr/org/zettelkasten/"))

(use-package! org-roam-bibtex
  :after org-roam
  :hook (org-roam-mode . org-roam-bibtex-mode)
  :config
  (require 'org-ref)
  (setq org-roam-bibtex-preformat-keywords
      '("citekey" "title" "url" "file" "author-or-editor" "keywords"))
  (setq orb-templates
        '(("r" "ref" plain (function org-roam-capture--get-point)
           ""
           :file-name "${citekey}"
           :head "#+TITLE: ${citekey}: ${title}\n#+ROAM_KEY: ${ref}

- tags ::
- keywords ::

\n* ${citekey}: ${title}\n  :PROPERTIES:\n  :Custom_ID: ${citekey}\n  :URL: \n  :AUTHOR: ${author}\n  :NOTER_DOCUMENT: ${file}\n  :NOTER_PAGE: \n  :END:\n\n"

           :unnarrowed t))))

;;----------------------------------------------------------------------------------------
;;  org-noter
;;-----------------------------------------------------------------------------------------
(use-package! org-noter
  :after org
  :config
  (setq
   ;; The WM can handle splits - var tidigare "other-frame"
   org-noter-notes-window-location 'horizontal-split
   ;; Please stop opening frames
   org-noter-always-create-frame nil
   ;; I want to see the whole file
   org-noter-hide-other nil
   ;; Everything is relative to the main notes file
   org-noter-notes-search-path (list "/Users/joafr/org/zettelkasten/")
)
   )

;;-----------------------------------------------------------------------------------------
;;  org-capture
;;------------------------------------------------------------------------------------------
;; Actually start using templates
(after! org-capture
  ;; Firefox and Chrome
  (add-to-list 'org-capture-templates
               '("P" "Protocol" entry ; key, name, type
                 (file+headline +org-capture-notes-file "Inbox") ; target
                 "* %^{Title}\nSource: %u, %c\n #+BEGIN_QUOTE\n%i\n#+END_QUOTE\n\n\n%?"
                 :prepend t ; properties
                 :kill-buffer t))
  (add-to-list 'org-capture-templates
               '("L" "Protocol Link" entry
                 (file+headline +org-capture-notes-file "Inbox")
                 "* %? [[%:link][%(transform-square-brackets-to-round-ones \"%:description\")]]\n"
                 :prepend t
                 :kill-buffer t))
)

That I think has already been asked here, probably more than once. Anyway, simply specify the :file-name in your templates as relative path:

(setq orb-templates
        '(("r" "ref" plain (function org-roam-capture--get-point)
           ""
           :file-name "sub-dir/${citekey}"
 ...)

This works generally for org-roam-capture-templates of which orb-templates is just a special case.

I also find it convenient to further subdivide notes depending on the type of the associated BibTeX entry:

(setq orb-templates 
    ...
    :file-name "references/${entry-type}/${citekey}"
    ...)

So notes on books settle down in “references/book” directory, notes on articles in “references/article” and so on.

Keep in mind that you need to register with orb-preformat-keywords any keyword (placeholder) you’d like to be expanded . So, for the above to work properly, you’ll also need:

(setq orb-preformat-keywords '("entry-type" "citekey" ...))

The entry-type keyword is special in the sense it does not have an associated BibTeX field. Instead, it is what follows the “@” in a BibTeX entry. There are several other special keywords, they can be found in orb-bibtex-field-aliases; citekey is one of them too. All other field names can be used as is, that is as they appear in the BibTeX entry, e.g. chapter, isbn, pagetotal, also whatever custom fields a user may come up with. The only requirement is they must be put on the orb-preformat-keywords list in order to be used as template placeholders.

2 Likes

Also, the after! macro does not need any keywords such as :config. It simply does not recognize them. The after! block evaluates all forms sequentially cleverly arranging this to be done after the package or packages in question (the first argument to the statement) have been loaded. So on one hand, having a keyword in an after! block is harmless because it is a constant that can be evaluated properly by the interpreter to return the same object. Since it does nothing functional, the result of the evaluation is discarded and the next form is evaluated, (setq ...) in the above example. On the other hand, a :config keyword in the after! block gives a false impression it is useful there.

1 Like

Thanks for this tip, I also am new to Doom and haven’t learned this sort of thing yet.

2 Likes

Thanks a lot! It worked out well.

1 Like