org-roam / org-roam-bibtex

Org Roam integration with bibliography management software
GNU General Public License v3.0
571 stars 47 forks source link

Option to prefer pdf when running orb-process-file-field #98

Closed tim-hilt closed 4 years ago

tim-hilt commented 4 years ago

I create my .bib-file using Zotero. Zotero automatically takes snapshots of the webpage i'm capturing the resource from and the Better BibLaTeX-extension for Zotero adds both to the file-field in the .bib-file.

I think this behavior is favorable over not exporting the resulting html-file to the .bib-file or not storing the snapshot at all, however i'm a bit annoyed of having to choose the pdf-file now, everytime i create a new notes-file using the following template:

("n" "ref + noter" plain
           (function org-roam-capture--get-point)
           ""
           :file-name "${citekey}"
           :head ,(s-join "\n"
                          (list
                           (concat "#+TITLE: " orb-title-format)
                           "#+ROAM_KEY: ${ref}"
                           ""
                           "- tags :: "
                           ""
                           "* Notes :noter:"
                           ":PROPERTIES:"
                           ":NOTER_DOCUMENT: %(orb-process-file-field \"${citekey}\")"
                           ":NOTER_PAGE:"
                           ":END:"
                           "")))

Could there be an option to prefer the pdf? Or is there a simple workaround i can utilize?

myshevchuk commented 4 years ago

Can you share one of such BibTeX record for testing? Also, what is the value of bibtex-completion-pdf-extension?

myshevchuk commented 4 years ago

I'm specifically interested in the file field format. The file paths need not be real

tim-hilt commented 4 years ago

Sure! Here's one:

@article{khotanzadInvariantImageRecognition1990,
  title = {Invariant Image Recognition by {{Zernike}} Moments},
  author = {Khotanzad, A. and Hong, Y.H.},
  date = {1990-05},
  journaltitle = {IEEE Transactions on Pattern Analysis and Machine Intelligence},
  volume = {12},
  pages = {489--497},
  issn = {1939-3539},
  doi = {10.1109/34.55109},
  eventtitle = {{{IEEE Transactions}} on {{Pattern Analysis}} and {{Machine Intelligence}}},
  file = {/home/tim/Zotero/storage/U23EPDEB/Khotanzad und Hong - 1990 - Invariant image recognition by Zernike moments.pdf;/home/tim/Zotero/storage/K22VN4QZ/55109.html},
  number = {5}
}

Notice that the file-field has both, a pdf- and an html-file

myshevchuk commented 4 years ago

And what is the value of bibtex-completion-pdf-extension?

myshevchuk commented 4 years ago

Test the above pull request to see if it solves your problem.

tim-hilt commented 4 years ago

And what is the value of bibtex-completion-pdf-extension?

Sorry, i forgot half of your request! bibtex-completion-pdf-extension isn't modified in my settings, so it has the default value of ".pdf".

tim-hilt commented 4 years ago

Also, i never had a collaborator directly formulate a pull request as a response to an issue that i opened. So for starters: Thank you very much! This is a great experience! :)

And yes, the above pull request works flawlessly! Exactly what i was looking for!

myshevchuk commented 4 years ago

Great! Thank you for your feedback, it helps to make ORB better for the benefit of many.

Note that you can control which file names to retrieve based on extension by adjusting the value of orb-file-field-extensions ("pdf" by default). You can also re-enable file prompts by setting orb-file-field-extensions to nil.

As a bonus, one can now also use the %^{file} or ${file} wildcards in templates, which will do the correct thing.

...
:NOTER_DOCUMENT: ${file}
...

instead of

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

I will merge the pull request now. Beware though, that the file name retrieval relies on a function from bibtex-completion package, and I found that in certain circumstances, namely when both files are in the path specified in bibtex-completion-bibliorgaphy, only the last file name is retrieved unconditionally. This doesn't seem to be your case, though, since in your case the retrieval is done solely according to the value of the file field.

tim-hilt commented 4 years ago

Thanks again! This also really helps cleaning up my template!

myshevchuk commented 4 years ago

Sehr gerne!