-
-
Notifications
You must be signed in to change notification settings - Fork 242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
open pdf from bib field #172
Comments
Indeed,
|
The best way to do this is to define a function of your own to find and Line 262 in f7729df
Basically you get the key at point, find the bibtex entry, and derive a Jonathan Gregory writes:
Professor John Kitchin |
Thanks for the comments. Unfortunately I don't know lisp enough to create my own function from scratch. However I noticed that if I set the "File" field in helm-bibtex and then from org-ref I press C-] to insert citation and I click on tab I am given the option to open the pdf and it works (regardless of whether the file is in the default bibpdf folder or in a path set in the File field) but when I click on the citation link created by org-ref that no longer works. This suggests to me that it should be feasible to get the citation link to open the pdf from the file field with existing org-ref functionality, as long as we establish some additional links between org-ref functions and helm-bibtex functions. I haven't figured this out yet, so I'm open to further suggestions. |
@vcurdia From @jkitchin's suggestion, you will need something like the code below. But we need to change a few things in the source code first before it can actually work. (setq org-ref-open-pdf-function 'my/org-ref-open-pdf-at-point)
(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 (funcall org-ref-get-pdf-filename-function key))
(pdf-other (car (helm-bibtex-find-pdf-in-library key))))
(cond ((file-exists-p pdf-file)
(org-open-file pdf-file))
(helm-bibtex-pdf-field
(funcall helm-bibtex-pdf-open-function
(helm-bibtex-find-pdf-in-field key)))
((file-exists-p pdf-other)
(funcall helm-bibtex-pdf-open-function pdf-other))
(message "No PDF found for %s" key)))) |
I tried this after updating org-ref with today's update. When trying to use the pdf in the File field, it still works in helm-bibtex (when searching the database using C-] ). However, when I create the cite link with org-ref and then click on the link it is broken and I get the following message: org-ref-cite-candidates: Wrong type argument: stringp, nil To be sure, this is the entry in my bib file: @Article{DelNegroFRBNYDSGE2016a, and these are the relevant lines in my .emacs ;; Use org-ref ;; Default bib for reftex ;; see org-ref for use of these variables ;; Helm-bibtex options ;; Allow for file field to be recognized in org-ref |
Try adding this line to your org document and see if that helps: |
That didn't fix the problem. I was already using the following at the end of my org file: Let me be clear: if the pdf is in the main folder with all BibPDF files then the org-ref link works fine. It's only if I specify the path/filename in the bib entry that it doesn't work. Two examples: bib file: @Article{DelNegroFRBNYDSGE2016, @Article{DelNegroFRBNYDSGE2016a, org file: cite:DelNegroFRBNYDSGE2016 First link works because the file DelNegroFRBNYDSGE2016.pdf is in the folder BibPDF which is the default BibPDF folder. The second link does not work. I assume that it is because the functions searching through the path and filename in bib entry File field crash at some point. |
I tested a few times with the new changes and it seems to be working fine. You will also need to update the function below: (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 (funcall org-ref-get-pdf-filename-function key))
(pdf-other (bibtex-completion-find-pdf key)))
(cond ((file-exists-p pdf-file)
(org-open-file pdf-file))
(pdf-other
(org-open-file pdf-other))
(message "No PDF found for %s" key)))) |
Also update to bibtex-completion.
It works now!! Thanks a lot. |
Here's how I force it open within Emacs:
|
I can't get this to work. I've started using zotero and want to keep the pdfs in their original subdirectories (it's only one directory deep). I can access the pdfs when I tab on an org-ref link inside an org file, which opens up helm-bibtex. But when I press return on a link opening org-ref, it can't find the pdf. It was working fine with all pdfs in one directory with no subdirectories. Any suggestions. None of the lisp above works. The message I get is "let*: Symbol’s value as variable is void: message". |
That error message means there is probably a bug in some function where
message is incorrectly used in a let* body. What is the function you use
to get a pdf file name?
On Fri, Jul 9, 2021 at 2:58 AM Jonathan Tonkin ***@***.***> wrote:
I can't get this to work. I've started using zotero and want to keep the
pdfs in their original subdirectories (it's only one directory deep). I can
access the pdfs when I tab on an org-ref link inside an org file, which
opens up helm-bibtex. But when I press return on a link opening org-ref, it
can't find the pdf. It was working fine with all pdfs in one directory with
no subdirectories. Any suggestions. None of the lisp above works. The
message I get is "let*: Symbol’s value as variable is void: message".
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#172 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAMJCVQU6TAKIHTFFXJUW4TTW2MZNANCNFSM4CAGWBTA>
.
--
John
…-----------------------------------
Professor John Kitchin (he/him/his)
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu
|
I tried the above suggestion, so it'd be
|
I am traveling, so I can’t see real clearly, but I think the way you use
the message incorrectly. It looks like it doesn’t fall through correctly in
the cond. it should be wrapped in (t (message …)) instead.
On Fri, Jul 9, 2021 at 1:27 PM Jonathan Tonkin ***@***.***> wrote:
I tried the above suggestion, so it'd be org-ref-get-pdf-filename-function
I assume.
(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 (funcall
org-ref-get-pdf-filename-function key)) (pdf-other
(bibtex-completion-find-pdf key))) (cond ((file-exists-p pdf-file)
(org-open-file pdf-file)) (pdf-other (org-open-file pdf-other)) (message
"No PDF found for %s" key))))
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#172 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAMJCVXJUCIKGXOMBGV66CLTW4WPNANCNFSM4CAGWBTA>
.
--
John
…-----------------------------------
Professor John Kitchin (he/him/his)
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu
|
Thanks. Tried that and it now tells me the pdf can't be found. So at least gives the right error message, but helm-bibtex can find the pdf. |
Figured it out. Replaced |
I had a similar problem and the function described by some in this issue had helped me. However, after about a year (probably due to some version update) it stopped working. In my case, the problem was that the function "bibtex-completion-find-pdf" was not being able to find the pdf. The solution was to set the variable bibtex-completion-library-path: |
This happened to me about a couple of weeks ago. I stopped using this custom-made function and it just works fine. I wonder if helm-bibtex incorporated some version of this into their codes. |
I've recently started using org-ref to include citations in my org notes. I like the idea of it allowing me to open the pdf straight from the cite link.
However, that only works if all my pdfs are in a single large folder. I usually keep the pdfs in subfolders and I would like to specify the pdf location on a per-bib entry basis. This works in Helm-bibtex using the following command:
(setq helm-bibtex-pdf-field "File")
However, when I click on the cite link from my org file using the link created by org-ref it does not find the pdf. I guess that this happens because org-ref does not recognize the bib entry field "File" as a store for the pdf location of that entry.
I tried a couple of alternative ways to force org-ref to use the find-pdf function of helm-bibtex but my very limited knowledge of lisp was not enough to get that to work unfortunately.
Can anyone let me know if the behavior that I describe is feasible or not with some tweaks in my ".emacs"?
Also, if it were possible to specify multiple files (to include support materials), that would be really great. I know that this is possible as well in helm-bibtex.
The text was updated successfully, but these errors were encountered: