lervag / vimtex

VimTeX: A modern Vim and neovim filetype plugin for LaTeX files.
MIT License
5.5k stars 389 forks source link

`\hyperref[` not behaving as `\ref{` and not showing list of labels to cross-reference #2730

Closed whisperity closed 2 months ago

whisperity commented 1 year ago

Description

Reference label completion list does not open following \hyperref[ (for custom-labelled references) even though \ref{ or \cref{ opens the list normally.

Steps to reproduce

\documentclass{report}

\usepackage{hyperref}
\usepackage{cleveref} % #pragma comment "must be loaded *after* hyperref!"

\begin{document}

\chapter{X}\label{ChX}
\section{Foo}\label{Foo}
\subsection{Bar}\label{Bar}

%

\end{document}

Navigate to the line indicated by % and start typing \ref{ or \cref{, and \hyperref[

Expected behavior

A dropdown should appear for all three commands, like this: `\ref{` drop-down auto-completing labels

Actual behavior

No drop-down is shown for arguments of the \hyperref[ command.

![Stale \hyperref[ command entered](https://github.com/lervag/vimtex/assets/1969470/8a9fc6e3-6d54-477b-9436-f21808f22d60)


The code is valid nevertheless and the PDF otherwise generates normally:

Generated PDF file for the minimal example

Do you use a latexmkrc file?

Yes (but this should not be relevant to the issue).

$pdf_mode = 5;
$dvi_mode = $postscript_mode = 0;
$max_repeat = 12;
$out_dir = "Build";

VimtexInfo

System info:
  OS: Ubuntu 22.04.1 LTS
  Vim version: NVIM v0.9.0-dev-1204+g0ce626b78
  Has clientserver: true
  Servername: /run/user/1000/nvim.8073.0

VimTeX project: minimal
  base: minimal.tex
  root: /home/whisperity/University/PhD-Thesis
  tex: /home/whisperity/University/PhD-Thesis/minimal.tex
  main parser: fallback current file
  document class:
  packages: atbegshi atbegshi-ltx atveryend atveryend-ltx auxhook bigintcalc bitset cleveref etoolbox gettitlestring hycolor hyperref iftex infwarerr intcalc keyval kvdefinekeys kvoptions kvsetkeys letltxmacro ltxcmds nameref pdfescape pdftexcmds refcount rerunfilecheck stringenc uniquecounter url
  compiler: latexmk
    engine: -xelatex
    options:
      -shell-escape
      -verbose
      -file-line-error
      -synctex=1
      -interaction=nonstopmode
    build_dir: Build
    callback: 1
    continuous: 1
    executable: latexmk
    job:
      jobid: 992
      output: /tmp/nvim.whisperity/3lfpQp/3
      cmd: max_print_line=2000 latexmk -shell-escape -verbose -file-line-error -synctex=1 -interaction=nonstopmode -xelatex -outdir=Build -pvc -view=none -e '$compiling_cmd = ($compiling_cmd ? $compiling_cmd . " ; " : "") . "echo vimtex_compiler_callback_compiling"' -e '$success_cmd = ($success_cmd ? $success_cmd . " ; " : "") . "echo vimtex_compiler_callback_success"' -e '$failure_cmd = ($failure_cmd ? $failure_cmd . " ; " : "") . "echo vimtex_compiler_callback_failure"' 'minimal.tex'
      pid: 87146
  viewer: General
    job:
      pid: -
      cmd: xdg-open '/home/whisperity/University/PhD-Thesis/Build/minimal.pdf'
  qf method: LaTeX logfile
lervag commented 1 year ago

Reference label completion list does not open following \hyperref[ (for custom-labelled references)

Why did you link "custom-labelled-references" to http://example.com?

Expected behavior

A dropdown should appear for all three commands, like this: …

First: You are leaving out a lot of VERY important context here. I believe I can infer things correctly, but it would be much better if I did not need to make any assumptions about your issue.

To be specific: "A dropdown should appear" is only right if you either 1) specify that you press e.g. <c-x><c-o> to trigger omnicompletion or 2) use some type of autocompletion plugin. You did not specify which of these, which makes your description incomplete.

Now, completion for \hyperref[... is available, and if you test it with regular omnicompletion with <c-x><c-o> I believe you will find that it works as expected. Thus, I believe the problem lies with your configuration or choice of autocomplete engine.

Notice, there is a reason why the issue template asks for a minimal example that involves a minimal test.vim or vimrc file. :)

whisperity commented 1 year ago

@lervag Thanks for the reply! I never had to press anything to open a completion drop down so I didn't know about that keybind at all before. Is it Vimtex-specific or something else?

I do use coc.nvim when running NeoVim, but to the best of my understanding it should be disabled for non-C++ files. Tomorrow I will investigate a bit further. I was surprised to see this behaviour because otherwise I saw mentions of the hyperref commands in the source code alongside cleveref's and whatnot so I tried to infer that it should work or at least worked in the past...

whisperity commented 1 year ago

Alright, it turns out that pressing C-x C-o will bring forth the autocompletion appropriately. And it turns out that there is a thing called coc-vimtex which drove the whole autocompletion up until this point.

Do you know of that plugin, or is it completely third-party? I found some mentions of the completion in VimTex's help file. But it looks like this issue should be reposted to that project instead?

lervag commented 1 year ago

@lervag Thanks for the reply!

:)

I never had to press anything to open a completion drop down so I didn't know about that keybind at all before. Is it Vimtex-specific or something else?

It is not VimTeX specific, no. It is built-in to Vim and neovim. I believe, based on what you are writing, that you are not very aware of which features you are using that are built-in and which ones are provided by plugins. It also doesn't seem like you are fully aware of which plugins you are using. This makes it harder for me to help. I would strongly suggest reading the Vim user manual (:help user-manual), as I believe learning the basics and intermediate built-in Vim features is a good idea for everyone who really wants to use Vim (or neovim).

Alright, it turns out that pressing C-x C-o will bring forth the autocompletion appropriately.

Good; as expected.

And it turns out that there is a thing called coc-vimtex which drove the whole autocompletion up until this point.

Do you know of that plugin, or is it completely third-party? I found some mentions of the completion in VimTex's help file. But it looks like this issue should be reposted to that project instead?

Yes, coc-vimtex is a wrapper for coc.nvim that brings VimTeXs omni-complete function as a source.

I believe the reason you don't get automatic completion is because the pattern used to trigger completion either lacks the hyperref part or has some bug:

https://github.com/neoclide/coc-vimtex/blob/master/src/index.js#LL19C1-L19C916

Compare this to similar regexes provided by VimTeX, e.g. this one:

https://github.com/lervag/vimtex/blob/28c71043604271d37be9582c89128d2acedff065/autoload/vimtex/re.vim#L36-L60

So, to fix this, you need to get whomever is maintaining coc-vimtex to check if there is either a bug with the regex or if it lacks the hyperref word.

lervag commented 2 months ago

Closing this as it seems resolved by my last comment.