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

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

Open
whisperity opened this issue Jun 16, 2023 · 4 comments
Labels

Comments

@whisperity
Copy link

whisperity commented Jun 16, 2023

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


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
@whisperity whisperity added the bug label Jun 16, 2023
@lervag
Copy link
Owner

lervag commented Jun 16, 2023

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
Copy link
Author

whisperity commented Jun 16, 2023

@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
Copy link
Author

whisperity commented Jun 17, 2023

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
Copy link
Owner

lervag commented Jun 18, 2023

@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:

" {{{1 Completion regexes
let g:vimtex#re#neocomplete =
\ '\v\\%('
\ . '%(\a*cite|Cite)\a*\*?%(\s*\[[^]]*\]){0,2}\s*\{[^}]*'
\ . '|%(\a*cites|Cites)%(\s*\([^)]*\)){0,2}'
\ . '%(%(\s*\[[^]]*\]){0,2}\s*\{[^}]*\})*'
\ . '%(\s*\[[^]]*\]){0,2}\s*\{[^}]*'
\ . '|bibentry\s*\{[^}]*'
\ . '|%(text|block)cquote\*?%(\s*\[[^]]*\]){0,2}\s*\{[^}]*'
\ . '|%(for|hy)\w*cquote\*?\{[^}]*}%(\s*\[[^]]*\]){0,2}\s*\{[^}]*'
\ . '|defbibentryset\{[^}]*}\{[^}]*'
\ . '|\a*ref%(\s*\{[^}]*|range\s*\{[^,}]*%(}\{)?)'
\ . '|hyperref\s*\[[^]]*'
\ . '|includegraphics\*?%(\s*\[[^]]*\]){0,2}\s*\{[^}]*'
\ . '|%(include%(only)?|input|subfile)\s*\{[^}]*'
\ . '|([cpdr]?(gls|Gls|GLS)|acr|Acr|ACR)\a*\s*\{[^}]*'
\ . '|(ac|Ac|AC)\s*\{[^}]*'
\ . '|includepdf%(\s*\[[^]]*\])?\s*\{[^}]*'
\ . '|includestandalone%(\s*\[[^]]*\])?\s*\{[^}]*'
\ . '|%(usepackage|RequirePackage|PassOptionsToPackage)%(\s*\[[^]]*\])?\s*\{[^}]*'
\ . '|documentclass%(\s*\[[^]]*\])?\s*\{[^}]*'
\ . '|begin%(\s*\[[^]]*\])?\s*\{[^}]*'
\ . '|end%(\s*\[[^]]*\])?\s*\{[^}]*'
\ . '|\a*'
\ . ')'

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.

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

2 participants