3

zref's counter module allows one to track which counter was (ref)stepped, similar in functionality to autoref. The property keeping track of this counter is aptly called counter.

Consider the following example:

\documentclass{article}

\usepackage{zref-user,zref-counter}
\usepackage{hyperref}

\begin{document}

Section counter: \zref[counter]{sec:label}\par
Figure counter: \zref[counter]{fig:label}

\section{A section}\zlabel{sec:label}

\begin{figure}
  \caption{A figure.}\zlabel{fig:label}
\end{figure}

\end{document}

With hyperref loaded, the counter outputs resemble:

enter image description here

Without hyperref loaded, the counter outputs resemble:

enter image description here

How can I make hyperref not influence the setting of the appropriate property value for counter?

4

In a class I wrote I used this to get around this problem:

\documentclass{article}
\usepackage{zref-user,zref-counter}
\usepackage{etoolbox}
\makeatletter
\pretocmd\refstepcounter{%
 \zref@setcurrent{counter}{#1}}{}{}
\makeatother
\usepackage{hyperref}


\begin{document}

Section counter: \zref[counter]{sec:label}\par
Figure counter: \zref[counter]{fig:label}

\section{A section}\zlabel{sec:label}

\begin{figure}
  \caption{A figure.}\zlabel{fig:label}
\end{figure}

\end{document}

An alternative is to add a patch after loading hyperref (and before loading cleveref):

\makeatletter
 \ZREF@patch{H@refstepcounter}{%
    \def\H@refstepcounter#1{%
      \zref@setcurrent{counter}{#1}%
      \ZREF@org@H@refstepcounter{#1}%
    }%
  }%
\makeatother

I did sent Heiko a message about this problem end of last year but forgot to check if something happened about it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.