hyperref icon indicating copy to clipboard operation
hyperref copied to clipboard

Code behavior and doc explanation about class option "implicit"

Open muzimuzhi opened this issue 6 years ago • 3 comments

Problem reproduction

This latex document produces error "Undefined control sequence: \@pagerefstar"

\documentclass{article}
\usepackage[implicit=false]{hyperref}
\begin{document}
a\label{key}
b\pageref*{key}
\end{document}

While compiling, the following steps happen in turn (this may contain mistakes):

  1. hyperref processes package options(s), which makes \Hy@implicitfalse
  2. \pageref is redefined to use \@pagerefstar in star form
  3. \ifHy@implicit is tested, then \MaybeStopEarly is defined to contain \endinput
  4. \MaybeStopEarly is expanded since not equal to \relax, hence \endinput is inserted
  5. defintion of \@pagerefstar is skipped, hence \@pagerefstar is never defined, which causes the Undefined control sequence error.

Questions

  1. In the current doc of hyperref, Sec. 3.1, option implicit is documented as redefines LaTeX internals. But even if implicit=false is used, result of using \pageref* is still changed, compared to article class without hyperref.
    To make things more consistency, do we need to restore/postpone the redefinition of \pageref if implicit=false is used?
  2. Maybe it is better to provide a list of "what does the option implicit=false turn off" to the current implicit-related documentation. This will remind user "which part of hyperref is turned off if I set implicit to false or use a document class like beamer which turns off implicit implicitly"

There must be other commands acts like \pageref, I use \pageref as an example only.

muzimuzhi avatar Aug 29 '19 05:08 muzimuzhi

Related source ranges (this reflects what I have known so far, and may contain mistakes):

step 2 https://github.com/ho-tex/hyperref/blob/068644918d98531b2376b536ed2263803b34b871/hyperref.dtx#L7742-L7744

step 3 https://github.com/ho-tex/hyperref/blob/068644918d98531b2376b536ed2263803b34b871/hyperref.dtx#L7351-L7375

step 4 https://github.com/ho-tex/hyperref/blob/068644918d98531b2376b536ed2263803b34b871/hyperref.dtx#L10661-L10665

step 5 https://github.com/ho-tex/hyperref/blob/068644918d98531b2376b536ed2263803b34b871/hyperref.dtx#L13311-L13313

muzimuzhi avatar Aug 29 '19 05:08 muzimuzhi

Hm. yes from the logic and the documentation implicit=false should prevent the redefinition of \pageref. But then \pageref*{key} will not error but instead give

Reference `*' on page 1 undefined on input line 141

and print ??key, which isn't ideal either. Probably the best would be to add

\ifHy@implicit \else \let \@pagerefstar\T@pageref \fi 

after the \pageref definition.

u-fischer avatar Sep 18 '19 16:09 u-fischer

But then \pageref*{key} will not error but instead give

Reference `*' on page 1 undefined on input line 141

and print ??key, which isn't ideal either.

Yes, and this is truly the same behavior with latex2e.

I understand that an ideal output is preferred, but then the related part of documentation is not easy to write.

Personally, I never use option implicit. But since beamer class loads hyperref with implicit=false, and this changes the syntax of user commands of hyperref, beamer users may need a documentation which lists "what does the option implicit=false turn off" and hence "which part of functions of hyperref is supported in beamer". Again personally, I think it is the responsibility of hyperref to provide such documentation, which then can be referred in doc of beamer.

muzimuzhi avatar Sep 19 '19 03:09 muzimuzhi