Org-roam-bibtex for Org-Roam v2

So, @FilTower and @maikol, although you use different approaches to configure your Emacs installation, you suffer from a similar issue. You can try disabling all your Org-mode related config and then start re-enabling Org-roam and ORB stuff piece by piece to see what triggers the issue.

Let’s continue on Org-cite here

I could solve the issue taking a more extreme approach

(use-package! org
  :init
  (require 'org-ref)
...
)

Now I can jump correctly to the right node I can create correctly new literature nodes.

Maybe in the README should be advised to the user to load org-ref as soon as possible in their configs.

Thanks for your patience and help @mshevchuk

@maikol. The approach is indeed extreme. Especially in Doom. One should not have (use-package! org ...) in their config.el if they use the org module in init.el (which I suspect you do). This is true for any package, not just Org. Also, (require 'org-ref) in the :init section of (use-package! org) can lead to unpredictable consequences. Most probably, your Org infrastructure is now broken. Did you also have (use-package! org) before these changes? If yes, then it explains your original issue.

The problem is that Emacs ships with an older version of Org, while Doom also installs a newer version. If you instruct Emacs to load Org several times – not necessarily explicitly, but also implicitly by loading Org-related packages – you are risking to have both versions loaded simultaneously, unless this is done properly. Doom takes special care to correctly load the newer version of Org in the org module. If you mess its efforts with another (use-package! org ...) in your config, two versions will be loaded simultaneously overriding parts of each other and leaving Emacs in a broken state, which is very hard to debug.

P.S. If you need to change Org defaults, use (after! org) instead of (use-package! org) in your config.el. You can also put (require 'org-ref) there.

I have used (use-package! org ...) with V1 without any trouble. The current version of org in my machine (org-version) is 9.5.

I changed my (use-package! org ...) by (after! org ...) and at least for me, I don’t see any changes. However, maybe the latter is better for the reasons you explained before.

Thanks again for your help.

When I just started using Doom a year ago, I had some troubles configuring Org with use-package! in my config.el. Henrik Lissner told me on Discord, that one in principle could use use-package! with deferring keywords such as :defer t, but the after! macro should be preferable in such cases. So I’m selling it for what I’ve bought it.

After a recent Doom upgrade I started having troubles with Org-agenda. They could be fixed by manually loading org-agenda.el from Doom’s directory. At the same time, org-version was reported as 9.5. I finally fixed the issue by running doom build. Maybe you’ve also run into this sort of troubles?

In any case, the following config is 100% working in a clean Doom installation:

(setq org-directory (file-truename "~/Documents/org")
      org-roam-directory (file-truename "~/Documents/org/zettelkasten"))

(use-package! org-roam
  :after org
  :commands
  (org-roam-buffer
   org-roam-setup
   org-roam-capture
   org-roam-node-find)
  :config
  (setq org-roam-mode-section-functions
        '(org-roam-backlinks-section org-roam-reflinks-section))
  (require 'find-lisp)
  (setq org-id-extra-files (find-lisp-find-files org-roam-directory "\.org$"))
  (org-roam-setup))

(use-package! org-ref
  :after org
  :commands
  (org-ref-cite-hydra/body
   org-ref-bibtex-hydra/body)
  :config
  (setq org-ref-default-bibliography
        '("~/Documents/org/zettelkasten/references/literature.bib"))
  (setq org-ref-show-broken-links nil))

(use-package! org-roam-bibtex
  :after org-roam
  :config
  (require 'org-ref)
  (setq org-roam-capture-templates
        '(("d" "default" plain "%?" :if-new
           (file+olp "%<%Y%m%d%H%M%S>-${slug}.org" ("heading 1" "heading 2"))
           :unnarrowed t)
          ("r" "multi-file" plain "%?"
           :if-new
           (file+head "test/${citekey}.org" "#+title: ${title}\n")
           :unnarrowed t)
          ("n" "single-file" plain "%?"
           :if-new
           (file+olp "test/references.org" ("${citekey}"))
           :unnarrowed t))))

(after! org-roam
  (org-roam-bibtex-mode))

(after! bibtex-completion
  (setq bibtex-completion-bibliography '("~/Documents/org/zettelkasten/references/literature.bib")))

Thanks! I will keep an eye on these details. I have to make a cleanup to my config.el.

Thanks @mshevchuk for updating org-roam-bibtex to comply with the major redesign in org-roam, as it is an important feature for me. Previously, I was not quite sure to migrate to v2 but when the update for org-roam-bibtex is up I guess it’s the straw that broke the camel’s back.

But currently I face a little problem and hope if @mshevchuk or everyone in this discourse group could help me.
As per documentation on Github - updated orb-manual.org with regard to Handling Long Templates, as I already used that feature in older orb, I set up my org-roam-capture-template as such:

(setq orb-file-field-extensions '("pdf" "epub" "mobi" "azw3" "djvu"))
(setq orb-preformat-keywords
      '(("citekey" . "=key=") "title" "cover" "url" "tags" "date" "abstract" "year" "journal" "note" "volume" "pages" "doi" "isbn" "issn" "publisher" "file" "author-or-editor" "keywords"))
(setq org-roam-capture-templates
        '(("d" "default" plain "%?"
           :if-new
           (file+head "%<%Y%m%d%H%M%S>-${slug}.org"
                      "#+title: ${title}\n")
           :unnarrowed t)
          ("b" "bookref" plain
           (file "~/Emacs/Custom/orgtemplates/bookref.org")
           :if-new
           (file+head "noter/${citekey}.org"
                      "#+TITLE: bref-${title}\n")
           :unnarrowed t)
          ("a" "articref" plain
           (file "~/Emacs/Custom/orgtemplates/articref.org")
           :if-new
           (file+head "noter/${citekey}"
                      "#+TITLE: aref-${title}\n")
           :unnarrowed t)))

Unfortunately, that setup gives error orb-edit-note caught an error during capture: Template needs to specify `:if-new'. But when I revert to default setup by commenting it worked as intended, without the template of course.

    `("b" "bookref" plain "%?"
               ;; (file "~/Emacs/Custom/orgtemplates/bookref.org")
               :if-new
               (file+head "noter/${citekey}.org"
                          "#+TITLE: bref-${title}\n")
               :unnarrowed t)

I am guessing there is a syntax error or maybe a problem in my template files. But I am not quite sure yet. But here are my org template file, I regard all of my reference note the same way as I use Zotero and Calibre as catalog programs.

#+CREATED: %U
#+LAST_MODIFIED: %U
#+STARTUP: content

- tags :: %^{tags}
  
* Cover
[[file:%^{cover}]]

* Overview
%^{note}

* Notes
:PROPERTIES:
:CUSTOM_ID: %^{citekey}
:URL: %^{url}
:AUTHOR: %^{author-or-editor}
:NOTER_DOCUMENT: %^{file}
:YEAR: %^{year}
:PUBLISHER: %^{publisher}
:VOLUME: %^{volume}
:ISBN: %^{isbn}
:END:

Thanks in advance,

Has anyone seen this error? I am in the process of migrating over to v2, and when I try to call helm-bibtex, I get this error:

ORG ROAM ERROR: (wrong-number-of-arguments (0 . 0) 1)
To try reinitializing org-roam, run ’M-x org-roam-mode’
condition-case: Error in a Doom startup hook: org-load-hook, +org-init-roam-maybe-h, (wrong-number-of-arguments (0 . 0) 1)

I’m not sure where to start with debugging it, since… it doesn’t seem to have source code?!

+org-init-roam-maybe-h is a function without a source file.

Signature
(+org-init-roam-maybe-h)

Documentation
Activate org-roam-mode. If it fails, fail gracefully.

References
Could not find source file.

Find all references Functions used by +org-init-roam-maybe-h

Debugging
Enable tracing
Disassemble Forget

;; Closure converted to defun by helpful.
(defun +org-init-roam-maybe-h nil "Activate `org-roam-mode'. If it fails, fail gracefully."
       (if
           (condition-case err
               (progn
                 (org-roam-mode 1)
                 t)
             ((debug error)
              (message "ORG ROAM ERROR: %s" err)
              nil))
           nil
         (message "To try reinitializing org-roam, run 'M-x org-roam-mode'")
         (org-roam-mode -1)))

In general, things seem to be mostly working, I can find nodes and create new nodes.

I’m using Doom. And my package inits look like this:

(package! org-roam
  :recipe (:host github :repo "org-roam/org-roam" :branch "v2"))

(package! org-roam-bibtex
  :recipe (:host github :repo "org-roam/org-roam-bibtex" :branch "org-roam-v2"))

(unpin! bibtex-completion helm-bibtex ivy-bibtex)

I’d turn on toggle-debug-on-error and get the stack to tell me the offending function.

1 Like
Debugger entered--Lisp error: (wrong-number-of-arguments (0 . 0) 1)
  org-roam-mode(1)
  (progn (org-roam-mode 1) t)
  (condition-case err (progn (org-roam-mode 1) t) ((debug error) (message "ORG ROAM ERROR: %s" err) nil))
  (if (condition-case err (progn (org-roam-mode 1) t) ((debug error) (message "ORG ROAM ERROR: %s" err) nil)) nil (message "To try reinitializing org-roam, run 'M-x org-roam-...") (org-roam-mode -1))
  +org-init-roam-maybe-h()
  funcall(+org-init-roam-maybe-h)
  (condition-case e (funcall hook) ((debug error) (signal 'doom-hook-error (list hook e))))
  doom-run-hook(+org-init-roam-maybe-h)
  run-hook-wrapped(doom-run-hook +org-init-roam-maybe-h)
  (condition-case e (run-hook-wrapped hook #'doom-run-hook) ((debug doom-hook-error) (if debug-on-error nil (lwarn hook :error "Error running hook %S because: %s" (if (symbolp (car (cdr e))) (symbol-name (car (cdr e))) (car (cdr e))) (car (cdr (cdr e))))) (signal 'doom-hook-error (cons hook (cdr e)))))
  (let ((hook (car --dolist-tail--))) (condition-case e (run-hook-wrapped hook #'doom-run-hook) ((debug doom-hook-error) (if debug-on-error nil (lwarn hook :error "Error running hook %S because: %s" (if (symbolp (car ...)) (symbol-name (car ...)) (car (cdr e))) (car (cdr (cdr e))))) (signal 'doom-hook-error (cons hook (cdr e))))) (setq --dolist-tail-- (cdr --dolist-tail--)))
  (while --dolist-tail-- (let ((hook (car --dolist-tail--))) (condition-case e (run-hook-wrapped hook #'doom-run-hook) ((debug doom-hook-error) (if debug-on-error nil (lwarn hook :error "Error running hook %S because: %s" (if (symbolp ...) (symbol-name ...) (car ...)) (car (cdr ...)))) (signal 'doom-hook-error (cons hook (cdr e))))) (setq --dolist-tail-- (cdr --dolist-tail--))))
  (let ((--dolist-tail-- hooks)) (while --dolist-tail-- (let ((hook (car --dolist-tail--))) (condition-case e (run-hook-wrapped hook #'doom-run-hook) ((debug doom-hook-error) (if debug-on-error nil (lwarn hook :error "Error running hook %S because: %s" (if ... ... ...) (car ...))) (signal 'doom-hook-error (cons hook (cdr e))))) (setq --dolist-tail-- (cdr --dolist-tail--)))))
  doom-run-hooks(org-load-hook)
  apply(doom-run-hooks org-load-hook)
  run-hooks(org-load-hook)
  byte-code("\300\301\302\"\210\303\304!\210\305\306!\207" [add-hook org-mode-hook #f(compiled-function () #<bytecode 0x1fe3f4a3877d>) provide org run-hooks org-load-hook] 3)
  require(org)
  byte-code("\300\301!\210\300\302!\210\300\303!\207" [require cl-lib org org-refile] 2)
  require(org-capture)
  byte-code("\300\301!\210\300\302!\210\300\303!\210\300\304!\210\300\305!\210\300\306!\210\300\307!\210\300\310!\210\300\311!\210\312\313\314\315\316\317%\210\320\321\314\322\316\313..." [require browse-url parsebib cl-lib dash s f biblio filenotify org-capture custom-declare-group bibtex-completion nil "Helm plugin for searching entries in a BibTeX bibl..." :group completion custom-declare-variable bibtex-completion-bibliography "The BibTeX file or list of BibTeX files.\nOrg-bibte..." :type (choice file (repeat file)) bibtex-completion-library-path "A directory or list of directories in which PDFs a..." (choice directory (repeat directory)) bibtex-completion-pdf-open-function 'find-file "The function used for opening PDF files.\nThis can ..." function bibtex-completion-pdf-extension ".pdf" "The extension of a BibTeX entry's \"PDF\" file.\nThis..." string bibtex-completion-find-additional-pdfs "If non-nil, all files whose base name starts with ..." boolean bibtex-completion-pdf-symbol "⌘" "Symbol used to indicate that a PDF file is availab..." bibtex-completion-format-citation-functions '((org-mode . bibtex-completion-format-citation-ebib) (latex-mode . bibtex-completion-format-citation-cite) (markdown-mode . bibtex-completion-format-citation-pandoc-citeproc) (python-mode . bibtex-completion-format-citation-sphinxcontrib-bibtex) (rst-mode . bibtex-completion-format-citation-sphinxcontrib-bibtex) (default . bibtex-completion-format-citation-default)) "The functions used for formatting citations.\nThe p..." (alist :key-type symbol :value-type function) bibtex-completion-notes-path "The place where notes are stored.\nThis is either a..." (choice file directory (const nil)) bibtex-completion-notes-template-multiple-files "#+TITLE: Notes on: ${author-or-editor} (${year}): ..." "Template used to create a new note when each note ..." bibtex-completion-notes-template-one-file "\n* ${author-or-editor} (${year}): ${title}\n  :PROP..." ...] 8)
  require(bibtex-completion)
  byte-code("\306\307!\210\306\310!\210\306\311!\210\306\312!\210\306\313!\210\314\30\315\211\31\32\315\33\10:\203j\0\10@\21\316\317\11P!\22\316\320\11P!\23\321\n..." [--cl-var-- var oldvar newvar prop --dolist-tail-- require helm helm-net helm-easymenu helm-files bibtex-completion ("bibliography" "library-path" "pdf-open-function" "pdf-symbol" "format-citation-functions" "notes-path" "notes-template-multiple-files" "notes-template-one-file" "notes-key-pattern" "notes-extension" "notes-symbol" "fallback-options" "browser-function" "additional-search-fields" "no-export-fields" "cite-commands" "cite-default-command" "cite-prompt-for-optional-arguments" "cite-default-as-initial-input" "pdf-field") nil intern "helm-bibtex-" "bibtex-completion-" defvaralias (saved-value saved-variable-comment) put make-obsolete-variable "2016-03-20" custom-declare-variable helm-bibtex-full-frame t "Non-nil means open `helm-bibtex' using the entire ..." :group :type boolean easy-menu-add-item ("Tools" "Helm" "Tools") ["BibTeX" helm-bibtex t]] 9)
  autoload-do-load((autoload "helm-bibtex" ("/Users/greg/.emacs.d/.local/autoloads.27.2.elc" . 787085) t nil) helm-bibtex)
  command-execute(helm-bibtex)

I’m not sure where +org-init-roam-maybe-h comes from. I’ll grep for it next.

Interesting. On a hunch, I replaced this line

       (org +roam +noter)         ; organize your plain life in plain text

with this one

       org

and that problem went away… now helm-bibtex comes up, but it’s not finding my bibliography notes. I’ll try adding +noter back in.

This “+” sign should indicate that it is a Doom addition. It is probably enabled by +roam. Does it support V2? If not, I’d avoid using it.

Good hunch! Removing that +roam modifier did in fact clear up that error.

Hi @reza_ama, thank you. I’m aware of this error because I caught it myself when I switched to the new version for personal “production” use. The error is related to the fact that the structure of new org-roam-capture-templates has changed – there is no explicit (function org-roam-capture--get-point) element – but I failed to account for this change in one of the relevant places.

In any case, It’s been fixed on my end for a couple of days now, be sure to upgrade to the most latest commit on the org-roam-v2 branch (actually, the fix was introduced in the second last commit as of now, 0702fee).

@gcoladon the +roam flag activates the built-in support for Org-roam in Doom. Basically, it takes care of installing and configuring the package for you and also adds a few Doom-specific hacks. Since Doom does not support v2 as of now, the few Doom-specific additions to Org-roam such as +org-init-roam-maybe-h do not work and actually cause harm.

1 Like

Just pulled the latest commit on the org-roam-v2 branch using straight.el and it works as expected. Before, I downloaded the tagged v0.6.0-pre.1 version and adding it manually to my load-path, as I believe that straight.el is yet to support pulling from either release nor tags.

I just realized that instead of showing the content of #+title:, like in v1, org-roam-ref-find listed the content of :roam_refs: which is not a problem, just rather different. But I believe that the UI aspect would get fixed soon.

So Thank you @mschevchuk for your help and explanation.

On the side note, I have been trying to cleaning my init.el, one of which is by making it more dynamic. so Instead of expressing the path as a string,

("b" "bookref" plain 
           (file "~/Emacs/Custom/orgtemplates/bookref.org")
           :if-new
           (file+head "noter/%<%Y%m%d%H%M%S>-${citekey}.org"
                      "#+TITLE: bref-${title}\n")
           :unnarrowed t)

I want it to use

("b" "bookref" plain 
           (file (concat user-emacs-directory "orgtemplates/bookref.org)                                        
           ;; or maybe `expand-file-name'
           :if-new
           (file+head "noter/%<%Y%m%d%H%M%S>-${citekey}.org"
                      "#+TITLE: bref-${title}\n")
           :unnarrowed t)

But it returns stringp error. I realize that it doesn’t work the same as org-roam-capture-templates, since adding , would suffice for the template to run the function and concatenate the given variable and string. In that regard, is there a better way to accomplish this?

Great that it worked for you. I will tag the latest commit because it entails several important fixes.

I’m thinking about adding several shortcut “find” commands to ORB for common subset queries (like ref vs non-ref). If you have any particular ideas, please feel free to share them here. So even if org-roam-ref-find is not fixed upstream, it can be easily incorporated into ORB.

You can use the backquote syntax almost anywhere in Elisp. Don’t forget the backquote:

(setq org-roam-capture-templates
   ;; the backquote is important
    `(("b" "bookref" plain 
           (file ,(concat user-emacs-directory "orgtemplates/bookref.org)                                        
           ;; or maybe `expand-file-name'
           :if-new
           (file+head "noter/%<%Y%m%d%H%M%S>-${citekey}.org"
                      "#+TITLE: bref-${title}\n")
           :unnarrowed t)))

Right. OK, yes now everything seems to be working correctly.

I have on tiny feature request to get your thoughts on though. What would you think of a defcustom to tell org-roam-bibtex which template code to use? If you would accept such a feature, I could try to get it working and send you a PR for it.

I’m thinking of introducing a marker to tell an ORB template from other templates. Something like:

(setq org-roam-capture-templates
    '(("r" "literature reference" plain 
           "%?"                                       
           :if-new
           (file+head "${citekey}.org"
                      "#+TITLE: ${title}\n")
           :unnarrowed t
           :type org-roam-bibtex)))

Should @jethro be interested in supporting this upstream in Org-roam, I could take on the necessary adjustments. The benefit of introducing it upstream is that one could then get rid of other template variables such as org-roam-capture-ref-templates and org-roam-dailies-capture-templates. Personally, I view it as a cleaner approach in terms of compliance with the DRY principle than having several closely related entities.

If it’s not something interesting for upstream Org-roam, it can still easily be arranged just for ORB.

However, I will also gladly look at your alternative suggestion, @gcoladon.

2 Likes