Org-roam-bibtex for Org-Roam v2

It’s happening because of the way how ORB runs capture. Thanks for letting me know, I’ll look into it. Meanwhile, press C-g to abort the capture.

This should be fixed now.

With M-: or M-x eval-expression. This was just to check what element Org would return for [cite:@key]. So when point is on a link, (org-element-context) returns a link element - a list starting with (link ...). If it’s on a headline - then a headline element (headline ...). I expected (after inspecting oc.el and relevant parts of org.el) that for a citation [cite:@key] this function would return (citation ...) but it returns (paragraph ...) meaning that Org parser did not recognize the citation as Org element and treated it as a part of a paragraph. This explains why following or exporting a citation does not work. But I can’t figure why Org element does not parse the citation in my instance. I therefore wondered may be you had any similar issues.

Actually, when I ran make in the cloned repository, the command quit with an error during building the Org manual. Lisp files were successfully compiled before that, so I assumed it was fine to continue. But maybe something else was not built properly and this was the cause of my issue.

Hi @mshevchuk, thanks for your help. Unfortunately, running org-roam-db-sync and then evaluating orb-make-notes-cache did not solve the issue. Any other suggestion about what to check next? (as a last resort, I can simply recreate the note, it is not a big deal – but I’m keen on understanding a bit better how Org, Org-roam, and OB work under the hood).

Thanks for fixing the abort issue!

Just to be clear, after rechanging the filename and updating the cache, I can insert/access the note without issues with Org-roam. It is just accessing it within helm-bibtex with org-roam-bibtex mode on that does not work (I’m prompted to capture a new note).

Try to reproduce your issue with another note. Carefully record all the steps you’ve taken and report them here so I can repeat them in the exact order.

I tried to reproduce your issue with the following but failed:

  1. Create a note test.org, for example with a dummy test BibTeX record
  2. Rename the note outside Emacs: test.orgtest2.org
  3. Helm-bibtex → Edit notes → a new note test.org is created (no capture prompts) → delete it without saving
  4. org-roam-db-sync
  5. Helm-bibtex → Edit notes → a new note test.org is created (no capture prompts) → delete it without saving
  6. orb-make-notes-cache
  7. Helm-bibtex → Edit notes → I’m taken to the original note, now under test2.org filename .

Notice that I did not rename the file back and I did not turn org-roam-bibtex-mode on/off. When I rename the file back to test.org, I have to go through steps 4 and 6 once again to fix it.

By the way, could it be that you also modified the value of ROAM_REFS? Does the value match the citation key of the BibTeX record?

Thanks @mshevchuk for your detail advice. Here are my steps:

  1. Add a dummy Bibtex entry to my reference.bib file;
  2. Enter Emacs and turn on org-roam-bibtex-mode;
  3. Create a new note, test.org, through helm-bibtex for the dummy entry;
  4. Close Emacs and rename the note using the ID, say as 202105152349test.org;
  5. Enter Emacs and org-roam gives me a warning of invalid ref cite:test2021, skipping... for the renamed note (but I did not change the ROAM_REFS, that’s the original);
  6. Run org-roam-db-sync, activate org-roam-bibtex-mode and evaluate (orb-makes-notes-cache);
  7. Through helm-bibtex I see that the dummy citation entry has no note now;
  8. Rechange the name of the note to the original outside Emacs;
  9. Enter Emacs, run org-roam-db-sync, activate org-roam-bibtex-mode and evaluate (orb-makes-notes-cache);
  10. Now, helm-bibtex correctly shows me that the dummy entry has a note but I cannot access it if org-roam-bibtex is on (I’m prompted to capture a new note).

I cannot reproduce this part. It seems you don’t have Org-ref loaded. Org-ref is required by Org-roam to be able to recognize cite:links. Maybe it’s loaded too late?

In fact, after quitting and relaunching Emacs (steps 4 and 5) I’m able to navigate to the renamed note without additional steps.

Mmmh. So, in my config file I first load and set all relevant variables for org-roam (including the capture templates). Afterwards, I load and set everything for org-roam-bibtex and do (require 'org-ref) after (require 'org-roam-bibtex). Is org-ref required too late? Or might there be something else wrong in my config order?

If you load Org-ref with ORB (as in README), then Org-ref will be loaded only after you turn on org-roam-bibtex-mode. This would explain why you don’t get the Org-roam database updated properly with org-roam-db-sync before you run org-roam-bibtex-mode.

This part is very strange. The same function is used by ORB to tell helm-bibtex that a note exists and to decide whether to create a new note when you call Edit notes.

Hard to tell for sure without looking at it. Probably the latter though.

I’ll try to change my config order following your suggestions @mshevchuk as soon as I can. In the meantime, I’ll post my config settings here in case you can spot something wrong straight away. Thanks a lot for your help and time!

It looks more or less fine. But when do you do org-roam-setup?

It’s in the first screenshot, line 339.

I have almost your config, and I am still having the warnings at startup

(use-package! org-ref
  :after org
  :config
  (setq org-ref-default-bibliography '("~/Dropbox/home/documents/org/roam/_library.bib")
        org-ref-notes-function 'orb-org-ref-edit-note
        org-ref-completion-library 'org-ref-helm-bibtex
        org-ref-get-pdf-filename-function 'org-ref-get-pdf-filename-helm-bibtex)

  (setq bibtex-completion-pdf-extension '(".pdf" ".djvu")
        bibtex-completion-pdf-field "file"))

(use-package! org-roam-bibtex
  :after org-roam
  :config
  (require 'org-ref)
  (setq orb-preformat-keywords
        '("citekey" "title" "url" "author-or-editor" "keywords" "file" "year")
        orb-process-file-keyword t
        orb-file-field-extensions '("pdf")
        orb-note-actions-interface 'helm
        orb-insert-interface 'helm-bibtex))

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

I removed all the packages in doom and compiled all again. I don’t know what else to do?

Right, I missed it. You can try moving (require 'org-ref) just before (org-roam-setup). But the things can be more complicated because of how you load other Org-related packages and how you install or load Org itself. Org is sometimes tricky and is well-known to suffer from weird loading issues. You may also want to check if you have any compiled files, try removing them and restart Emacs.

Do you have other Org-related packages in your config? How do you load Org itself, just with the org module in init.el?

Weird; I get a void symbol error if I do that.

If I eval org-element-object-containers, I get this, which seems to suggest it recognizes the citation as a citation?

(bold citation footnote-reference italic link subscript radio-target strike-through superscript table-cell underline paragraph ...)