Although C-c ] can be set to anything of course, I doubt it calls org-roam-bibtex (there is no such function in ORB package). By default, org-ref-insert-link is bound to C-c ], which inserts a cite link by default. It can even some other things such open a PDF file, à la helm-bibtex (or ivy-bibtex), but org-ref-insert-link and helm-bibtex are not the same!
I think the author is just confused by the variety of packages, which is of no surprise. @sinqbad early Emacs experience can be overwhelming and one needs some time to get used - slowly but steadily. In your Emacs journey, C-h f, C-h v and C-h k are your best friends.
I now seem to be able to reproduce the whole problem. It’s Org-ref… I have been using Helm-bibtex’s functions to open PDF documents. See the screen shot (this should work for you now).
While in the Helm completion (via C-]), while selecting the bib entry, pressing Tab gets you to this screen. The second function [f2] is the one I have been talking about.
Clicking on the cite:citeky gets you to this screen, which I didn’t understand that you had been talking about all along (apologies for this misintepretation). It does not find the PDF files linked to bib entry in my machine, either.
As mshevchuk’s analysis, this “2. Open pdf” option calls function org-ref-open-pdf-at-point (Org-ref function), and cannot find my PDF (via function org-ref-get-pdf-filename, which returns nil).
(defun my/org-ref-open-pdf-at-point ()
"Open the pdf for bibtex key under point if it exists."
(interactive)
(let* ((results (org-ref-get-bibtex-key-and-file))
(key (car results))
(pdf-file (car (bibtex-completion-find-pdf key))))
(if (file-exists-p pdf-file)
(find-file pdf-file) ; original in org-ref-help,
; opens external viewer (org-open-file pdf-file)
(message "No PDF found for %s" key))))
(setq org-ref-open-pdf-function #'my/org-ref-open-pdf-at-point)
M-x org-ref-help opens a detailed help document on Org-ref.
In Appendex, there is a section named “Customizing how PDFs are opened”, section “A note for Mendeley, JabRef and Zotero users”. There is a sample configuration for Mendeley as well.
I think I’ll update the section of Zero to Emacs with this.
It doesn’t. The function org-ref-open-pdf-at-point is still the one used. However, to get the filename, this function calls the function specified in org-ref-get-pdf-filename, which is just a variable to hold the name of the actual function. Setting org-ref-get-pdf-filename-function to org-ref-get-pdf-filename-helm-bibtex changes the way filenames are retrieved, in a way similar to what you suggested in my/org-ref-open-pdf-at-point. The latter is of course a valid solution, moreover it is more flexible since the user is in the full control.
Sorry, the name of the variable to set is org-ref-get-filename-function. This explains it - I used the correct variable when testing but made a mistake when reporting, sorry for the mess. I updated my answers accordingly.
Your solution opens up a PDF document in an external viewer.
Function org-ref-open-pdf-at-point uses org-open-file, which seems to call an external viewer by default for PDF files, which you can customize…
It’s a rabbit hole; I can finally see the end of the tunnel
This thread of conversations has a lot of gems in it, but getting really crowded.
Sorry, @sinqbad, you would be hard pressed to decipher a solution that would work in the end, but this should be it (I might separate the solutions out as a tips post).
Two options, if you want to open PDF documents from the cite:citekey link of Org-ref:
Use the way described in org-ref-help and adapt the code to call find-file (code quoted again below)
Follow @mshevchuk’s solution: (setq org-ref-get-pdf-filename-function #'org-ref-get-pdf-filename-helm-bibtex) and customize variable org-file-apps so that org-open-file function uses find-file to open PDF files
My motivation is to change the default action after I click the cite:key (or C-c C-o org-open-at-point). This is what I use most.
@nobiot actions list are a little bit different to me. But I find the following code might be help me to solve this problem.
(helm :sources (helm-build-sync-source "test"
;; A function can be used as well
;; to provide candidates.
:candidates '( "bar" "baz" "foo"))
:buffer "*helm test*")
After executing this funciton, I find the buffer name is “helm test”.
So, I guess, I could start from the name of buffer, which is defined by :buffer to find the function.
@cool_ran, yes, I think it would be a good separate post.
I believe you can find an answer to your question by reading org-ref-help document… (it’s a command, so M-x org-ref-help).
When you open a cite:key link, the function currently registered for that link pops up. You can see all link types that Org is aware of in org-link-parameters variable. Org Ref links such as cite: and co. (autocite:, nocite:, etc.) call a function registered in org-ref-cite-onclick-function variable. It can be set before org-ref is loaded to support different completion styles. The default one and the one you are using is org-ref-helm-bibtex.
I don’t use Helm, so I can’t tell whether what you want can be set from within the Helm framework. Quite likely, you have to inspect code of the org-ref-helm-bibtex function and adjust it or/and other relevant pieces to your needs. I’m afraid it may be hard-coded, but can’t tell it for sure.
Yeah, although Org Ref is a very tricky package requiring a lot of struggle to properly run it, it is at the same time highly customizable, allowing one to plug in their custom functions almost everywhere without touching the core code.
It’s like jumping in the deep end. Rewarding once you figure it out but frustrating when you can’t crack it. But thank you for all your help. Makes it much easier to dive in.
Thank you for taking the time to write and explain that to me. It really does help to contextulise and expand my knowledge.
I see what I am doing wrong now thank to both @mshevchuk and @nobiot.
Seriously, thank you so much for all the work you’ve put into this. I tried your solution code and it worked! It only worked with the absolute path entry that I had manually put in. Otherwise, with a relative path entry it still will fail to open anything.
That leads me to believe I’m in fact having two problems and mistaking them for the same problem. That is 1) I was using org-ref “2. Open pdf” org-ref-open-pdf-at-point rather than the helm-bibtex menu (C-c ] ) and 2) something wrong with relative path OR the naming of the pdfs.
“[f2] Open PDF, URL or DOI” still won’t open the pdf. I think it’s because of what bibtex-completion-library-path says, that “Bibtex-completion assumes that the names of these PDFs are composed of the BibTeX-key plus a “.pdf” suffix.”
So I’m guessing that I have to get zotero to export appropriately. I’ll test out it out.
I will try doing this. However, how do I edebug-defun the function bibtex-completion-open-pdf. When I type M-x edebug-defun says “Cannot more futher down” i.e. I think it’s acting on the buffer.
You need to be in the source code where the function is defined – you cursor needs to be somewhere in the defun for the function. (defun is the keyword to define a function). You can easily navigate to where you need to be via C-h f.
You can remove your edebug point with a commend something like edebug remove instrument or something like this.
I figured out why the relative paths aren’t being parsed properly. According to this https://github.com/tmalsburg/helm-bibtex/issues/124 issue, having the file field in a jabref format solves the issue. Eg.
@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 = {Full Text PDF:files/1450/Wolf - 2012 - The Moon over the Mountain Stories by Atsushi N.pdf:application/pdf},
langid = {english},
number = {2},
timestamp = {2020-06-27T04:55:41Z}
}
Notice the file field is very different than earlier in the thread.
I use Zotero as my bibliography management and betterbib(la)tex to export. To export the bibtex file with the jabref go to Zotero > Edit > Preferences > Better BibTeX > export > Fields > Include JabRef-specific metadata: