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 makes varioref's \vrefformat no-op #225

Open
gusbrs opened this issue Jan 31, 2022 · 4 comments
Open

hyperref makes varioref's \vrefformat no-op #225

gusbrs opened this issue Jan 31, 2022 · 4 comments

Comments

@gusbrs
Copy link

gusbrs commented Jan 31, 2022

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:

hyperref/hyperref.dtx

Lines 13027 to 13058 in c25f44c

\renewcommand\Vref@star[2][]{%
\begingroup
\let\T@pageref\@pagerefstar
\Ref*{#2}
\vpageref[#1]{#2}%
\endgroup
}%
\renewcommand\Vr@f[2][]{%
\begingroup
\let\T@pageref\@pagerefstar
\hyperref[{#2}]{%
\Ref*{#2}
\vpageref[#1]{#2}%
}%
\endgroup
}%
\renewcommand\vr@f[2][]{%
\begingroup
\let\T@pageref\@pagerefstar
\hyperref[{#2}]{%
\ref*{#2}
\vpageref[#1]{#2}%
}%
\endgroup
}%
\renewcommand\vref@star[2][]{%
\begingroup
\let\T@pageref\@pagerefstar
\ref*{#2}
\vpageref[#1]{#2}%
\endgroup
}%

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).

@u-fischer
Copy link
Member

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 ?

@FrankMittelbach
Copy link
Member

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.

@u-fischer
Copy link
Member

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.

@FrankMittelbach
Copy link
Member

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

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

No branches or pull requests

3 participants