hyperref icon indicating copy to clipboard operation
hyperref copied to clipboard

`hyperref` makes `varioref`'s `\vrefformat` no-op

Open gusbrs opened this issue 3 years ago • 4 comments

Currently, hyperref makes varioref's user customization option \vrefformat no-op, as shown in the MWE below:

\documentclass{article}

\usepackage[nospace]{varioref}
\usepackage{hyperref}

\renewcommand*{\vrefformat}[2]{%
  Foo \ref{#2} \vpageref[#1]{#2}}

\begin{document}

\section{Section 1}
\label{sec:section-1}

\clearpage{}

\vref{sec:section-1}

\end{document}

Renders:

Screenshot from 2022-01-31 17-06-08

Commenting hyperref out of the above document renders:

Screenshot from 2022-01-31 17-07-41

This happens because hyperref redefines \vr@f and \vref@star (I haven't tested, but I presume the same problem occurs with \Vref for the same reason). And does so without using \vrefformat (and \Vrefformat), but hard-coding the formats in the redefinitions it makes.

As far as I can tell, this is done at: https://github.com/latex3/hyperref/blob/c25f44c5d880a5897376d947957e7a129b376e6c/hyperref.dtx#L13027-L13058

I don't know if there's a reason for this that I've missed, but it seems possible, at first glance, to use \vrefformat instead of hard-coding it (maybe redefining \vrefdefaultformat for this). And thus not override this user option from varioref.

Edit: Besides what was already mentioned, the above also means that \usepackage[japanese]{varioref} won't work with hyperref (well, theoretically at least, I don't actually know how to set up a document in Japanese).

gusbrs avatar Jan 31 '22 20:01 gusbrs

yes it is wrong, but looking at it I think it would be better if the support for links would be done by varioref directly and hyperref would stop to patch (and break) it. @FrankMittelbach ?

u-fischer avatar Apr 09 '22 21:04 u-fischer

yes the right place is in varioref to offer support for hyperref not the other way around, but that requires sync of the two (which was more or less impossible in the past with hyperref just patching all over the place. :-)). We can do this now, now that we control both sides ... you have write acces to varioref too ... we should put that on the agenda for a change in the not too distant future.

FrankMittelbach avatar Apr 09 '22 21:04 FrankMittelbach

I can easily directly surround all the hyperref (and nameref) code with some test that disables it under some condition that varioref can then activate, \ifdefined\vp@nohyperrefpatches. The only thing I find a bit bewildering is why hyperref (re)defines \Ref only if varioref is loaded, this looks rather odd, I guess that should be moved outside first.

u-fischer avatar Apr 09 '22 22:04 u-fischer

The only thing I find a bit bewildering is why hyperref (re)defines \Ref only if varioref is loaded, this looks rather odd, I guess that should be moved outside first.

historical? if i remember correctly \Ref wasn't in the kernel initially

FrankMittelbach avatar Apr 10 '22 07:04 FrankMittelbach