Org Roam Bibtex in a Sub Directory

Hey guys, recently I got some great help to help me organize different types of notes, the solution in my case ended up being sub-directories.

I explain more in there in case anyone wants to achieve a similar thing.

What I’m struggling with right now is to place my org roam bibtex notes in a subdirectory.

I use helm-bibtex to add notes to URL’s saved via zotero and exported with Better Bibtex into a single .bib file.

When I open helm-bibtex and use “Edit note” the location of this notes go to the parent folder of my org-roam directory. I’d like to place this notes into a sub-directory called “resources”

I’m using spacemacs (I’ll include my configurations at the end of this ) I placed my configurations in a private layer as instructed in the documentation, the only change from the defaults should be the keybinding.

My org roam parent directory is:

(org-roam-directory "~/Dropbox/org/notes/")

I’d like to place my org roam bibtex notes into:

(org-roam-directory "~/Dropbox/org/notes/resources")

if anyone knows a way to set a sub-directory I’d appreciate any help.
Thank you

(defconst org-roam-packages
  '(org-roam org-roam-bibtex)
  '(org-roam))

(defun org-roam/init-org-roam ()
  (use-package org-roam
    :hook
    (after-init . org-roam-mode)
    :custom
    (org-roam-directory "~/Dropbox/org/notes/")
    :init
    (progn
      (spacemacs/declare-prefix "a/" "org-roam")
      (spacemacs/set-leader-keys
       "a/l" 'org-roam
       "a/t" 'org-roam-dailies-today
       "a/f" 'org-roam-find-file
       "a/g" 'org-roam-graph)

      (spacemacs/declare-prefix-for-mode 'org-mode "m/" "org-roam")
      (spacemacs/set-leader-keys-for-major-mode 'org-mode
                                                "/l" 'org-roam
                                                "/t" 'org-roam-dailies-today
                                                "/b" 'org-roam-switch-to-buffer
                                                "/f" 'org-roam-find-file
                                                "/i" 'org-roam-insert
                                                "/g" 'org-roam-graph))))
(defun org-roam/init-org-roam-bibtex ()
  (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)))))
1 Like

We have very similar settings, although I edit my .bib file by hand. In any case, to place your org roam bibtex notes in your “resources” sub-directory you need to add the path into your orb-template. This is how I have it:

(use-package org-roam-bibtex
  :hook (org-roam-mode . org-roam-bibtex-mode)
  :bind (:map org-mode-map
         (("C-c n a" . orb-note-actions)))

  :custom
  (orb-templates
      '(("r" "ref" plain (function org-roam-capture--get-point) "%?"
         :file-name "refs/${citekey}"
         :head "#+TITLE: ${title}\n#+ROAM_KEY: ${ref}\n#+CREATED: %U\n#+EDITED: %U\n#+ROAM_TAGS: \n* Notes on ${citekey}\n :PROPERTIES:\n :Custom_ID:  ${citekey}\n :PDF: /home/julian/Documents/Refs/${citekey}.pdf\n :END:\n"
        :unnarrowed t
        :immediate-finish t)))
)

Note that in my template I have :file-name "refs/${citekey}. With this the org-roam-bibtex notes are created in my “refs” sub-folder within my org-roam-directory. The file name for my literature notes is simply the bibtex key. So if I make a note for an article with bibtex key “Jones2018”, the file created will be something like this:

my-org-roam-directory/refs/Jones2018.org

In my template I also defined the header of the file. I write my literature notes using org-noter

Which allows me to write my notes associated to particular locations of the pdf. With this information on the header I can create the notes file using org-roam-bibtex, call org-noter and start typing. It is a very nice setup.

2 Likes

@jmburgos Thanks man you just saved me so much time I didn’t know where the path was defined.

In case anyone else need to set things up I’ll write down what I changed from your configs:

Like you explained this is done in :file-name what comes before the ${citekey} determined the sub-directory.

In my case I changed mine to.

  :file-name "resources/${citekey}"

And now everything works. For those who might be using spacemacs I did all of this within my org-roam private layer.


Thanks again @jmburgos appreciate the help! And yeah I’ve been using org-noter, it’s amazing, but I wasn’t able to figure out how to make it work with org-roam-bibtex so your explanation was exactly what I needed!


If I understood correctly, in your case for org-noter, this is the path where you have your pdf files stored right?
/home/julian/Documents/Refs/

Do you have a link to your dotfiles perhaps? I’d really love to check it out since you are steps ahead of what I want to achieve!

Thank you!

Sorry, I do not have a link to my dotfiles… I have been meaning to upload them to github forever. In any case, org-noter works pretty much out of the box. My only configuration is this:

(use-package org-noter
  :defer t
  :bind (("C-x +" . org-noter)
         ("C-c +" . org-noter-insert-note))
  :config
  (setq org-noter-doc-split-fraction '(0.7 . 0.7)
	org-noter-property-doc-file "PDF"
	org-noter-property-note-location "PAGE"
        org-noter-hide-other nil
        org-noter-always-create-frame nil
  )
)

Yes, my pdfs are here: /home/julian/Documents/Refs/

no worries at all! Thanks for sharing the org-noter configs I’m setting up right now!
Awesome, let me know if you end up sharing your dotfiles!
Thanks again!

The other components of my “note-taking ecosystem” are ivy-bibtex and org-ref. With ivy-bibtex and org-roam-bibtex I can search my reference database (kept as a single bibtex file), select the “edit notes” options, and I get a note formatted with the template defined in orb-templates. With org-ref I get all the functionality of working links when I write documents, including the option to write notes on a reference already cited in a document. To make everything work together I have the following configuratons:

(use-package ivy-bibtex
  :bind ("C-x b" . ivy-bibtex)

  :config
  (setq bibtex-completion-bibliography '("/home/julian/Documents/org_files/references.bib")
	bibtex-completion-library-path '("/home/julian/Documents/Refs/")
	bibtex-completion-notes-path "/home/julian/Documents/org_notes/refs/"
	ivy-bibtex-default-action 'ivy-bibtex-insert-citation
)

  (defun bibtex-completion-format-citation-org-ref (keys)
    "Formatter for org-ref references."
    (s-join ", "
	    (--map (format "cite:%s" it) keys)))

  (setq bibtex-completion-format-citation-functions
	'(
	  (org-mode      . bibtex-completion-format-citation-org-ref)
	  (latex-mode    . bibtex-completion-format-citation-cite)
	  (markdown-mode . bibtex-completion-format-citation-pandoc-citeproc)
	  (default       . bibtex-completion-format-citation-default)
	  ))

  (advice-add 'bibtex-completion-candidates
	      :filter-return 'reverse)
)

(require 'org-ref)
(setq org-ref-completion-library 'org-ref-ivy-cite)
(setq org-ref-default-bibliography '("/home/julian/Documents/org_files/references.bib")
      org-ref-pdf-directory "/home/julian/Documents/Refs/"
      org-ref-default-citation-link "cite"
      org-ref-show-broken-links t
      org-ref-notes-directory "/home/julian/Documents/org_notes/refs/"
      bibtex-completion-notes-path "/home/julian/Documents/org_notes/refs/"
      )

(setq org-ref-notes-function
    (lambda (thekey)
     (let ((bibtex-completion-bibliography (org-ref-find-bibliography)))
	  (bibtex-completion-edit-notes
	   (list (car (org-ref-get-bibtex-key-and-file thekey)))))))

Awesome perfect, I’ll bookmark this and will keep coming back to this as I keep improving my system! Thanks