-
Notifications
You must be signed in to change notification settings - Fork 407
hyphens in bib entry field names break VimtexContextMenu #2071
Description
Issue
It seems that for vimtex-context-citation, the parsing of the .bib file gets stuck on bib fields (keys) that have a hyphen character (-) in the name, as in the example below (it's also the case for other non-alphanumeric characters, but I haven't exhaustively checked).
Details: I've been using BibDesk for bibfile management, and it autogenerates some fields that have hyphens in them, such as date-added. Vimtex gets stuck on these, and doesn't parse any fields that appear after the first one with a hyphen in the fieldname. So if (as in the minimal example given below) this problematic field comes second in the bib entry, say, just after the author field (as it does usually for me, since BibDesk has keys alphabetically sorted), then in (n)vim, the vimtex context menu has no links to "Open doi" or "Open url", even though that info is in the bib entry, and under "Show entry", only the fields before the problematic one show up (so just author in this case).
To reproduce:
- Regular Vim:
vim --servername VIM -u minimal.vim minimal.tex - neovim:
nvim -u minimal.vim minimal.tex
minimal.vim
(I'm using vim-plug, so my vimtex dir is in "plugged")
set nocompatible
let &runtimepath = '~/.vim/plugged/vimtex,' . &runtimepath
let &runtimepath .= ',~/.vim/plugged/vimtex/after'
filetype plugin indent on
syntax enableminimal.tex
\documentclass{article}
\usepackage[natbib=true,backend=biber]{biblatex}
\begin{filecontents}[noheader,overwrite]{\jobname-refs.bib}
@article{nb68-minimal,
author = {N. Blachman},
doi = {10.1109/tit.1968.1054094},
journal = {{IEEE} Transactions on Information Theory},
number = {1},
url = {https://doi.org/10.1109/tit.1968.1054094},
title = {The amount of information that y gives about X},
volume = {14},
year = 1968,
}
@article{nb68-bibdesk,
author = {N. Blachman},
date-added = {2021-04-08 14:57:27 -0400},
date-modified = {2021-04-08 14:57:41 -0400},
doi = {10.1109/tit.1968.1054094},
journal = {{IEEE} Transactions on Information Theory},
title = {The amount of information that y gives about X},
url = {https://doi.org/10.1109/tit.1968.1054094},
volume = {14},
year = 1968,
Bdsk-Url-1 = {https://doi.org/10.1109/tit.1968.1054094},
}
\end{filecontents}
\addbibresource{\jobname-refs.bib}
\begin{document}
% *:VimtexContextMenu* works on this one:
\citet[][minimal]{nb68-minimal}
% *:VimtexContextMenu* only finds the `author` key for this one (it seems it gets stuck on the key `date-added`, which has a hyphen in it).
\citet[][bibdesk]{nb68-bibdesk}
\printbibliography{}
\end{document}Observed Behaviour
When I run :VimtexContextMenu (by putting the cursor on the cite key nb68-bibdesk typing <localleader>la), I get a context menu that has only three entries:
- 1: Edit entry
- 2: Show entry
- x: Abort
selecting 2, only the part of the bib entry that came before date-added is shown:

Expected Behaviour
When I remove the problematic BibDesk-added fields (with hyphens in them), as in the bib entry nb68-minimal, and open a context menu on that cite key instead, I get the expected
- 1: Edit entry
- 2: Show entry
- 3: Open doi
- 4: Open url
- x: Abort
and, selecting 2, I can see all of the fields, like so:

--
I really like the context menu! It's great for navigating to the referenced DOI / URL, to check things while working on a document, without having to scroll around. It seems like this might not be hard to fix, if it's a matter of changing how the bibfile is read in, but I haven't been able to figure out how myself (else I'd try to make a pull request... I'd be glad to try, but I might need to be pointed in the right direction, since I am very much a viml noob).