telescope-bibtex.nvim icon indicating copy to clipboard operation
telescope-bibtex.nvim copied to clipboard

Is it any opportunity to open attached pdf file from bibtex...

Open VolkovIlia opened this issue 3 years ago • 7 comments

I have bibtex file that is generated with link to pdf document (jabref and papers-cli generate it). Is it any opportunity to bind key for opening it while I search it in telescope... ?

@article{amini_rezaei2015,
 author = {Amini, Ehsan and Rezaei, Mehran},
 doi = {10.1016/s1872-2067(15)60922-6},
 file = {:/home/volk/Library/PDFs/2015/amini_rezaei2015.pdf:pdf},
 journal = {Chinese Journal of Catalysis},
 month = {10},
 number = {10},
 pages = {1711-1718},
 publisher = {Elsevier BV},
 title = {Preparation of mesoporous Fe-Cu mixed metal oxide nanopowder as active and stable catalyst for low-temperature CO oxidation},
 url = {http://dx.doi.org/10.1016/s1872-2067(15)60922-6},
 volume = {36},
 year = {2015}
}

VolkovIlia avatar Oct 25 '21 14:10 VolkovIlia

If telescope supports specifying result-sensitive actions this should be possible. However this is not a feature I have in mind for this plugin (at least right now, as I am busy doing other stuff and development of new features for this project is paused). I might look into it another time if more such actions come up. For now I see this more as a hack for a very specific use-case.

You can implement it yourself and then either open a PR or use it locally, of course.

noahares avatar Oct 27 '21 16:10 noahares

I would start here: telescope docs under replace_if. There you can specify the condition and change the action.

noahares avatar Oct 27 '21 16:10 noahares

I have bodged together an implementation for this over at https://github.com/erooke/telescope-bibtex.nvim/tree/open-file. Simply specify the pdf reader in the config:

require('telescope').setup {
  extensions = {
    bibtex = {
      reader = { 'evince' },
    }
  }
}

then call Telescope bibtex open and select what you want opened.

Currently has a quirk where if you close the terminal hosting vim before closing vim the reader closes. I'm not sure how to stop that happening.

erooke avatar Jan 24 '22 04:01 erooke

This looks good. How exactly is the format of the file field in the entry? To solve the problem of the viewer closing: plenary.Job takes a table of arguments to pass to libUV. LibUV has the option detached which acts like a disown and would keep the viewer alive even after neovim exits. (see options after uv.spawn(...) at libUV

noahares avatar Jan 24 '22 08:01 noahares

This looks good. How exactly is the format of the file field in the entry?

That is a great question I wish I had an answer to. I was unable to find a good description of what was going on. The following is my best guess based on searching through all the bib files in the jabref repository:

  • It is a ; separated list of files
  • Each entry in the list is of the form name:location:filetype
    • The filetype is very much a guess as they don't have any which are non-pdfs in their tests
    • The name seems to be mainly to differentiate supplementary material related to the entry
    • the location need not be on disk for example: file = {:http\://arxiv.org/pdf/2003.05580v3:PDF}

The current implementation deals with very little:

  • it assumes there is only one file associated with each entry. Because of this it ignores the name of the file.
  • it assumes the file type is pdf
  • it assumed the file lives on disk

For my use case all of that is true but it's the main reason I hadn't submitted it as a pull request yet as it feels too hacky at the moment.

erooke avatar Jan 24 '22 20:01 erooke

For what its worth helm-bibtex has implemented this feature. They support:

  • File = {/path/to/article.pdf}
  • File = {:/path/to/article.pdf:PDF}
  • File = {:/path/to/article.pdf:PDF;:/path/to/supplementary_materials.pdf:PDF}

as file specifications.

erooke avatar Jan 24 '22 20:01 erooke

I've proposed a reply here : https://github.com/nvim-telescope/telescope-bibtex.nvim/issues/73#issuecomment-2058456940

uses mappings to add this feature.

anandkumar89 avatar Apr 16 '24 07:04 anandkumar89