Need help getting noter/pdfs and org-roam-bibtex to work

I have a working org-roam instance working which is absolutely fantastic. I am using org-roam-bibtex to insert citations and when I create a note for a bibtex entry it’s captured with citekey, author etc. All very nice.

The next thing I’m after is being able to open the pdf and have notes in noter (just like the youtube video).

When I run org-roam-bibtex (C-c ]) and selecting entry “2 open pdf” the buffer redirects to “/” root in dired, i.e. when I try to open a pdf it doesn’t find the pdf. This is with all entries so I’m pretty sure I’m doing something fundamentally wrong.

This is my init-orgroam.el file:

;; Roam Research Emacs
(use-package org-roam
  :ensure t
  :hook
  (after-init . org-roam-mode)
  :custom
  (org-roam-directory "~/Org/slipbox/")
  :bind (:map org-roam-mode-map
	      (("C-c n l" . org-roam)
               ("C-c n f" . org-roam-find-file)
               ("C-c n g" . org-roam-graph))
              :map org-mode-map
              (("C-c n i" . org-roam-insert))
              (("C-c n I" . org-roam-insert-immediate))))

;; Allows for Org-roam to display in a web browser
(use-package org-roam-server
  :ensure t
  :config
  (setq org-roam-server-host "127.0.0.1"
        org-roam-server-port 8080
        org-roam-server-authenticate nil
        org-roam-server-export-inline-images t
        org-roam-server-serve-files nil
        org-roam-server-served-file-extensions '("pdf" "mp4" "ogv")
        org-roam-server-network-poll t
        org-roam-server-network-arrows nil
        org-roam-server-network-label-truncate t
        org-roam-server-network-label-truncate-length 60
        org-roam-server-network-label-wrap-length 20))

;; Add bibliography and bibliographical notes to Org Roam
(use-package org-roam-bibtex
  :ensure t
  :hook (org-roam-mode . org-roam-bibtex-mode)
  :bind (:map org-mode-map
              (("C-c n a" . orb-note-actions)))
  :config
  (setq orb-preformat-keywords
	'(("citekey" . "=key=") "title" "url" "file" "author-or-editor" "keywords"))
  (setq orb-process-file-field t)
  (setq orb-file-field-extensions "pdf")
  (setq orb-templates
	'(("r" "ref" plain (function org-roam-capture--get-point)
	   ""
	   :file-name "literature/${citekey}"
	   :head "#+TITLE: ${citekey}: ${title}\n#+ROAM_KEY: ${ref}\n- tags ::\n- keywords :: ${keywords}\n* ${title}\n:PROPERTIES:\n:Custom_ID: ${citekey}\n:URL: ${url}\n:AUTHOR: ${author-or-editor}\n:NOTER_DOCUMENT: ${file}\n:NOTER_PAGE:\n:END:"))))

(use-package company-org-roam
  :ensure t
  :config
  (push 'company-org-roam company-backends))
(provide 'init-orgroam)

and this is from my init-helm.el file

(use-package helm-bibtex
  :ensure t
  :init (autoload 'helm-bibtex "helm-bibtex" "" t)
  :config
  (setq bibtex-completion-notes-path "~/Org/slipbox/bib/bibnotes/")
  (setq reftex-default-bibliography '("~/Org/slipbox/bib/bib.bib"))
  (setq bibtex-completion-bibliography '("~/Org/slipbox/bib/bib.bib"))
  (setq bibtex-completion-pdf-field "file")
  (setq bibtex-completion-notes-template-multiple-files
	(concat
	 "#+TITLE: ${title}\n"
         "#+ROAM_KEY: cite:${=key=}\n"
	 "* TODO Notes\n"
	 ":PROPERTIES:\n"
	 ":Custom_ID: ${=key=}\n"
	 ":NOTER_DOCUMENT: ${file}\n"
	 ":AUTHOR: ${author-abbrev}\n"
	 ":JOURNAL: ${journaltitle}\n"
	 ":DATE: ${date}\n"
	 ":YEAR: ${year}\n"
	 ":DOI: ${doi}\n"
	 ":URL: ${url}\n"
	 ":END:\n\n"
  ))
  ;;  (setq org-ref-get-pdf-filename-function (lambda (key) (car (bibtex-completion-find-pdf key)))))
  )

It’s probably this property in your template.

;; Yours
":NOTER_DOCUMENT: ${file}\n"
;; From ORB's README (see Source below)
:NOTER_DOCUMENT: %(orb-process-file-field \"${citekey}\")

Source

Sorry, I would not be able to read all your config, but that’s what I notice.
I have written an article on PDF-Tools, Org-noter, and ORB. It was done on Windows; I believe it would be applicable if you are on a different OS.

EDIT

I see it looks like ORB has been updated… to use ${file} parameter.

Perhaps, then, you might need to update ORB to the latest commit (?).

@mshevchuk, you may be better equipped to comment, perhaps?

1 Like

Firstly, nobiot, thank you for your guides. I used it when I first started with org-roam and it was an invaluable resource. So thank you very much.
I replaced

":NOTER_DOCUMENT: ${file}\n"

with
:NOTER_DOCUMENT: %(orb-process-file-field \"${citekey}\")

and still the same result.

Here is an bibtex entry I am trying to access
@article{wolfmoon12,
title = {"{{The Moon}} over the {{Mountain}}": {{Stories}} by {{Atsushi Nakajima}} by {{Paul McCarthy}} and {{Nobuko Ochner}} (Review)},
shorttitle = {"{{The Moon}} over the {{Mountain}}"},
author = {Wolf, Charles De},
date = {2012},
journaltitle = {Monumenta Nipponica},
volume = {67},
pages = {371–374},
publisher = {{Sophia University}},
issn = {1880-1390},
doi = {10.1353/mni.2012.0021},
file = {files/1450/Wolf - 2012 - The Moon over the Mountain Stories by Atsushi N.pdf},
langid = {english},
number = {2}
}

EDIT:

#+TITLE: wolfmoon12: The Moon over the Mountain": Stories by Atsushi Nakajima by Paul McCarthy and Nobuko Ochner (review)
#+ROAM_KEY: cite:wolfmoon12
- tags ::
- keywords :: 
* The Moon over the Mountain": Stories by Atsushi Nakajima by Paul McCarthy and Nobuko Ochner (review)
:PROPERTIES:
:Custom_ID: wolfmoon12
:URL: 
:AUTHOR: Wolf, C. D.
:NOTER_DOCUMENT: files/1450/Wolf - 2012 - The Moon over the Mountain Stories by Atsushi N.pdf
:NOTER_PAGE:
:END:

this is the entry that capture gets.

I will try updating

When you open org-ref, do you see the a looped square symbol (⌘)?

If not, I think your Emacs (org-ref, helm-bibtex, one of them) does not recognize the PDF stored in this path: file = {files/1450/Wolf - 2012 - The Moon over the Mountain Stories by Atsushi N.pdf},

My bibtex entry for the example above looks like this:

I’m on Windows, so yours may have “/” instead of “\” in the path. As you can see, it’s a full path to the corresponding PDF (and html) files.

Is your path reachable? files/1450/Wolf - 2012 - The Moon over the Mountain Stories by Atsushi N.pdf – I’m guessing this is supposed to be a relative path from… somewhere?

Maybe you could manually change it to its full absolute path manually and see if that would work (you may need to relaunch org-ref / helm-bibtex to get it parse .bib again (or relaunch Emacs altogether).

thank you for your kind words, by the way :slight_smile:

1 Like

@nobiot, right. ORB has been recently updated to include a more user friendly option ${file} instead of more verbose %(orb-process-file-field \"${citekey}\").

The problem with @sinqbad’s config is that you set the wrong variable. You should put the template into orb-templates, because it replaces helm-bibtex note managing with its own. See examples of how to configure orb-templates in the README or search through this forum.

2 Likes

That can be an edge case. Under certain circumstances, bibtex-completion fails to retrieve the file name, for example if you have several file paths in the field, there may not be a space between them:

file = {path/to/file1.pdf;path/to/file2.pdf}

and not

file = {path/to/file1.pdf; path/to/file2.pdf}

Another thing to check is bibtex-completion-library-path - this is the variable bibtex-completion uses to look up the pdf files…

Aha! Well spotted. Thank you for jumping in :slight_smile:

1 Like

Thank you for your invaluable engagement and producing the best documentation :slight_smile:

2 Likes

@mshevchuk Thanks for you reply. I’m not sure what you mean by “set the wrong variable”.

Looking at orb-template documentation. It says to setq the org-template variable like thus,

(setq orb-templates
      '(("r" "ref" plain (function org-roam-capture--get-point) ""
         :file-name "${citekey}"
         :head "#+TITLE: ${citekey}: ${title}\n#+ROAM_KEY: ${ref}\n" ; <--
         :unnarrowed t)))

and at the end of my init-orgroam.el I have

(setq orb-templates
	'(("r" "ref" plain (function org-roam-capture--get-point)
	   ""
	   :file-name "literature/${citekey}"
	   :head "#+TITLE: ${citekey}: ${title}\n#+ROAM_KEY: ${ref}\n- tags ::\n- keywords :: ${keywords}\n* ${title}\n:PROPERTIES:\n:Custom_ID: ${citekey}\n:URL: ${url}\n:AUTHOR: ${author-or-editor}\n:NOTER_DOCUMENT: ${file}\n:NOTER_PAGE:\n:END:")))

which is the same right?

Or do you mean the template in my init-orghelm.el

(setq bibtex-completion-notes-template-multiple-files
	(concat
	 "#+TITLE: ${title}\n"
         "#+ROAM_KEY: cite:${=key=}\n"
	 "* TODO Notes\n"
	 ":PROPERTIES:\n"
	 ":Custom_ID: ${=key=}\n"
	 ":NOTER_DOCUMENT: ${file}\n"
	 ":AUTHOR: ${author-abbrev}\n"
	 ":JOURNAL: ${journaltitle}\n"
	 ":DATE: ${date}\n"
	 ":YEAR: ${year}\n"
	 ":DOI: ${doi}\n"
	 ":URL: ${url}\n"
	 ":END:\n\n"
  ))

@singbad, right, I mean bibtex-completion-notes-template-multiple-files. Sorry, I didn’t see you had orb-templates set - one had to scroll the example to see it. I therefore thought you had the former set instead of the latter. That would explain it. Having both variables is redundant because bibtex-completion-notes-template-multiple-files does nothing when org-roam-bibtex-mode is active.

Anyway, it seems you’ve got your template capturing the file field value, right? If you opt for using ${file} instead of %(orb-process-file-field \"${citekey}\"), keep in mind that orb-preformat-keywords must contain "file" element and orb-process-file-keyword must be set to non-nil.

Then of course you must make sure that bibtex-completion can find your files.

@mshevchuk thank you for your help.

@nobiot from what I can tell my bibtex-completion can “see” the pdf and even notes associated with it.
Screenshot_20200927_203523

I changed my bibtex entry to be a absolute path:
@article{wolfmoon12,
title = {"{{The Moon}} over the {{Mountain}}": {{Stories}} by {{Atsushi Nakajima}} by {{Paul McCarthy}} and {{Nobuko Ochner}} (Review)},
shorttitle = {"{{The Moon}} over the {{Mountain}}"},
author = {Wolf, Charles De},
date = {2012},
journaltitle = {Monumenta Nipponica},
volume = {67},
pages = {371–374},
publisher = {{Sophia University}},
issn = {1880-1390},
doi = {10.1353/mni.2012.0021},
file = {/home/solomon/Org/slipbox/bib/files/1450/Wolf - 2012 - The Moon over the Mountain Stories by Atsushi N.pdf},
langid = {english},
number = {2}
}
And after resetting emacs and reloading the bibtex file. When I try to open the pdf, it attempts to open in okular (a pdf viewer)
Screenshot_20200927_204557
but will fail to open.

I can manually open the pdf in emacs with C-x C-f and it will open fine with pdf-tools.

I also got rid of the template bibtex-completion-notes-template-multiple-files

(use-package helm-bibtex
  :ensure t
  :init (autoload 'helm-bibtex "helm-bibtex" "" t)
  :config
  (setq bibtex-completion-notes-path "~/Org/slipbox/bib/bibnotes/")
  (setq reftex-default-bibliography '("~/Org/slipbox/bib/bib.bib"))
  (setq bibtex-completion-bibliography '("~/Org/slipbox/bib/bib.bib"))
  (setq bibtex-completion-pdf-field "file")
  ;;  (setq org-ref-get-pdf-filename-function (lambda (key) (car (bibtex-completion-find-pdf key)))))
  )

and from what I can tell that orb-preformat-keywords does contain "file" element and orb-process-file-keyword is set to non-nil.

(use-package org-roam-bibtex
  :ensure t
  :hook (org-roam-mode . org-roam-bibtex-mode)
  :bind (:map org-mode-map
              (("C-c n a" . orb-note-actions)))
  :config
  (setq orb-preformat-keywords
	'(("citekey" . "=key=") "title" "url" "file" "author-or-editor" "keywords"))
  (setq orb-process-file-field t)
  (setq orb-process-file-keyword t)

What’s the value of variable bibtex-completion-pdf-open-function?
I suspect for you somehow it’s set to open the external editor (Okular) you mention.

For me it’s set to ‘find-file’.

Or… Action 2 is set to some custom action, somehow somewhere.

The reason for my suspicion is that by all the changes you have made, the behaviour has changed.

Originally, it was this:

When I run org-roam-bibtex (C-c ]) and selecting entry “2 open pdf” the buffer redirects to “/” root in dired, i.e. when I try to open a pdf it doesn’t find the pdf.

Now it’s this:

And after resetting emacs and reloading the bibtex file. When I try to open the pdf, it attempts to open in okular (a pdf viewer) but will fail to open.

So I think you are touching the right part of the configuration.

Now I suggest you look into why your Emacs tries to open the external PDF viewer.


EDIT:
See the excerpt from the documentation for the variable bibtex-completion-pdf-open-function below.
I think you have helm-open-file-with-default-tool, which then tries to use your system’s default viewer (which I suspect to be Okular). If so, change it to find-file (or remove the customization, so that it will be default back to find-file.

I don’t know where and how this value is set, though… It says the default is find-file.

Documentation:
The function used for opening PDF files.
This can be an arbitrary function that takes one argument: the
path to the PDF file.  The default is ‘find-file’ which opens the
PDF in Emacs (either with docview or, if installed, the much
superior pdf-tools.  When set to
‘helm-open-file-with-default-tool’, the systems default viewer
for PDFs is used.

For what’s worth, here is the config file I have done for the guide, highlighting the ORB part

(please read the :NOTER_DOCUMENT: %(orb-process-file-field \"${citekey}\") part as having the new keyword in your mind).

FYI… Just so that you might like to make comparison with something rather minimal.

According to Help (C-h v bibtex-completion-pdf-open-function) it’s value is ‘find-file’.

Looking at my init-orgroam.el which has he org-roam-bibtex use-package it look almost exactly the same as yours.

  (setq orb-process-file-field t)
  (setq orb-process-file-keyword t)
  (setq orb-file-field-extensions "pdf")

These were the only differences in our configs. And I even commented them out and tried again to no avail.

Maybe I’ve hit a bug, I might put in a report.

@sinqbad, I don’t know if you are up for this, but I’d put edebug-defun for function bibtex-completion-open-pdf and run the action as normal. That should bring up a debugging session like I see below. You should be able to press space to evaluate one line by line, and see what bibtex-completion-pdf-open-function variable evaluates to. Here in my session, after choosing a PDF file, the variable evaluates to find-file.

Two possibilities I can think of:

  1. If the debugger does not open a debegging session, that probably means that the action is not using this function (meaning, some other config maps the action number 2 to do something else).

  2. If your case also evaluates to find-file, maybe it’s advised by some other function like this (visible in C-h f (I made this up this function):

And/or launch Emacs as vanilla with emacs -q and load minimum packages, put minimum config and see if opening pdf works. If it does, there is something to fix in your config (it could be outside of .el files you have been looking at…).

@sinqbad, so did you set bibtex-completion-library-path as I suggested earlier?

Look, there are three different packages developed independently by different people: Org Ref, Helm BibTeX and Org Roam BibTeX. They are interconnected in certain ways but that it is. It may look like a mess (and it is to some extent) but this is what we have.

So, Helm BibTeX lets you search through your bibliorgaphy: you run helm-bibtex, a window popups and you can perform some actions on entries in you .bib file using a user friendly Helm interface.

Org Ref allows for cite:citekey style links, it is a third-party solution for currently missing Org Mode citation links. Org Ref links are clickable and you can perform some actions on that. Most of the actions have nothing to do with Helm BibTeX because Org Ref has native implementation for them, although it could also use Helm BibTeX (and does so in some cases).

Org Roam BibTeX makes Org Roam note-taking machinery become aware of BibTeX. It does so by relying on bibtex-completion (the same library that powers Helm BibTeX). It also shadows native note-taking facilities of Org Ref and Helm BibTeX, allowing one to use Org Roam instead. So with Org Roam BibTeX you can access your Org Roam notes from both Helm BibTeX and Org Ref.

If you cannot open an org-ref link, then that’s a problem with Org Ref configuration, which is unfortunately a very common thing, but it has nothing to do with ORB nor with Helm BibTeX.

OK, I’ve looked at how Org Ref opens PDF files from a cite:link.

  1. It calls a function specified in org-ref-open-pdf-function, which defaults to org-ref-open-pdf-at-point
  2. org-ref-open-pdf-at-point then calls a function specified in org-ref-get-pdf-filename-function, which defaults to org-ref-get-pdf-filename
  3. org-ref-get-pdf-filename expects the filename to be of format citekey.pdf. For a citekey citekey, when you click on a cite:citekey link, Org Ref will look for “citekey.pdf” in org-ref-pdf-directory.
  4. Fortunately, there is a variable org-ref-get-pdf-filename-function that can be set to function org-ref-get-pdf-filename-helm-bibtex, which will use Helm BibTeX to retrieve the filename. Helm BibTeX’ logic of filename retrieval is more complex: it looks at the file field (this is what you want) among a few other things.

I bet (setq org-ref-get-pdf-filename-function #'org-ref-get-pdf-filename-helm-bibtex) will solve your problem with cite: links.

1 Like