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

Bibtex citation completion requires full path of bib file #2184

Closed
shrimpram opened this issue Sep 28, 2021 · 6 comments
Closed

Bibtex citation completion requires full path of bib file #2184

shrimpram opened this issue Sep 28, 2021 · 6 comments
Labels

Comments

@shrimpram
Copy link

shrimpram commented Sep 28, 2021

Description

When trying to complete citations with bibtex, I was running into errors when I simply included the file name of the bib file. My bib files are located in my texmf tree directory, and are found by kpsewhich. However, in order for citation completions to work in vimtex I need to use the full path of the bib file.

E.g. merely having \addbibresource{somefile.bib} does not make the citation completion menu appear when I press <C-x><C-o>, but I need to include the whole path, \addbibresource{~/Library/texmf/bibtex/bib/somefile.bib}.

Steps to reproduce

  1. nvim -u minimal.vim minimal.tex
  2. Uncomment out the first bib file option "\addbibresource{somefile.bib}"
  3. Go over to \cite{}
  4. Try to complete citations using <C-x><C-o>
Here is the `minimal.vim` file
set nocompatible
let &runtimepath  = '~/test/vimtex,' . &runtimepath
let &runtimepath .= ',~/test/vimtex/after'
filetype plugin indent on
syntax enable
" Add relevant options and VimTeX configuration below.
Here is the `minimal.tex`
\documentclass{minimal}
\usepackage{biblatex}

% \addbibresource{somefile.bib}
% \addbibresource{~/Library/texmf/bibtex/bib/somefile.bib}

\begin{document}

\cite{}

\end{document}

Expected behavior

The citation completion menu should pop up with all of the bibliography entries in somefile.bib

Actual behavior

There is no citation completion when using \addbibresource{somefile.bib}, but there is citation completion when using \addbibresource{~/Library/texmf/bibtex/bib/somefile.bib}.

However, compilation works on both versions without error and kpsewhich somefile.bib returns the location, the only issue is in completion.

Do you use a latexmkrc file?

No

VimtexInfo

System info
  OS: macOS 11.6 (20G165)
  Vim version: NVIM v0.6.0-dev+356-gbec7f47ce
  Has clientserver: true
  Servername: /var/folders/zh/j15t9snn5wdbyz3rh4gxj6t00000gn/T/nvimVMydBY/0

VimTeX project: minimal
  base: minimal.tex
  root: /Users/shreeram/test
  tex: /Users/shreeram/test/minimal.tex
  main parser: current file verified
  document class: minimal
  packages: bibtex
  compiler: latexmk
    engine: -xelatex
    options:
      -verbose
      -file-line-error
      -synctex=1
      -interaction=nonstopmode
    callback: 1
    continuous: 1
    executable: latexmk
  viewer: General
  qf method: LaTeX logfile
@shrimpram shrimpram added the bug label Sep 28, 2021
@clason
Copy link
Contributor

clason commented Sep 28, 2021

\addbibresource is from BibLaTeX, not BibTeX, and VimTeX checks loaded packages for enabling features.

TL;DR: your minimal.tex has a typo; it's \usepackage{biblatex}, not \usepackage{bibtex}.

@shrimpram
Copy link
Author

Apologies, I fixed that typo but the issue is still there.

@lervag
Copy link
Owner

lervag commented Sep 28, 2021

First: I've fixed the typo in your original post as well.

Now, I'm curious if this could be an issue with the caching mechanism. Can you try to clear the cache with :VimtexClearCache kpsewhich and then try again with the relative path?

@shrimpram
Copy link
Author

Yes clearing the cache solved the issue, the relative path opens the citation completion menu. Thank you for your help!

lervag added a commit that referenced this issue Sep 28, 2021
Important: This updates the caching mechanism for vimtex#kpsewhich#find
to avoid cache conflicts for local results. It means that after
updating, one must clear the kpsewhich cache with:

    :VimtexClearCache kpsewhich

refer: #2184
@lervag
Copy link
Owner

lervag commented Sep 28, 2021

Great, happy to hear it. However, you actually found a bug here. I've fixed it, but after updating, you will need to clear the cache again.

@lervag
Copy link
Owner

lervag commented Sep 28, 2021

Just to add to this for potential interested readers, including future self: It seems more or less common to use the same name for reference file in different projects, e.g. reference.bib. The old implementation did not account for the fact that a file like reference.bib may be different in different projects. That is, since the results were cached, every project after the first would resolve the reference.bib that was local to the first project, and not the one local to itself. This also means that one could potentially have strange completion issues because the resolved bib file was not the correct one. In fact, I am sure this must have happened to a lot of people, so I'm surprised it has not been reported before!

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

No branches or pull requests

3 participants