Skip to content
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

[help] Get details of citation under cursor #2946

Closed
anandkumar89 opened this issue May 4, 2024 · 7 comments
Closed

[help] Get details of citation under cursor #2946

anandkumar89 opened this issue May 4, 2024 · 7 comments

Comments

@anandkumar89
Copy link

I'm trying to write a script that could open pdf linked to citation under cursor. Since vimtex parses bibtex files linked, is it possible to get entire details for the citation key under cursor ?

lervag added a commit that referenced this issue May 4, 2024
@lervag
Copy link
Owner

lervag commented May 4, 2024

Yes. You can use vimtex#cite#get_entry() for that.

@lervag lervag closed this as completed May 4, 2024
@anandkumar89
Copy link
Author

anandkumar89 commented May 5, 2024

Thanks a ton @lervag


for anyone stumbling here, looking for similar. I use zotero with better-bibtex to export bib files (file entry is automatically included). keymap below allows to open corresponding pdf when cursor is on the citation key.

vim.keymap.set('n', '<leader>zo', function()
		local citation_entry = vim.api.nvim_call_function('vimtex#cite#get_entry', {})
		local file_path = citation_entry['file']
		job:new({
				command = "/path/to/sioyek",
				args = { file_path },
				detached = true,
		}):start()
end, {desc="Open pdf related to citations"})

@lervag
Copy link
Owner

lervag commented May 5, 2024

Thanks a ton @lervag

No problem; thanks for the request!

Notice, just in case you were not aware, that there is already a context feature that sort of provides what you are looking for here. See :help vimtex-context-cite.

for anyone stumbling here, looking for similar. I use zotero with better-bibtex to export bib files (file entry is automatically included). keymap below allows to open corresponding pdf when cursor is on the citation key. …

I think this is a slightly improved version:

vim.keymap.set('n', '<leader>zo', function()
  local citation_entry = vim.fn['vimtex#cite#get_entry']()
  job:new({
    command = '/path/to/sioyek',
    args = { citation_entry.file },
    detached = true,
  }):start()
end, {desc='Open pdf related to citations'})

@anandkumar89
Copy link
Author

Thanks for the improved version!

I wasn't aware of context menu support, this issue seems redundant in the context. I tried, butopen pdf doesn't do anything for me, I'm able to open url, Show Entry etc. (I'm using sioyek with vimtex, and works fine)

@lervag
Copy link
Owner

lervag commented May 5, 2024

You can try to change the g:vimtex_context_pdf_viewer option.

@anandkumar89
Copy link
Author

Thank You for bearing with me 🚀

probably just a reminder to self about reading doc properly!

@lervag
Copy link
Owner

lervag commented May 5, 2024

No problem :)

Notice, using the context function means several key presses. If you frequently want to just open the corresponding pdf, then having the direct version you asked for in this issue makes sense. That's why I didn't immediately mention the context feature. ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants