GeneralHyperref and pageref

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
jaykemper
Posts: 22
Joined: Wed Apr 15, 2009 12:11 am

Hyperref and pageref

Post by jaykemper »

I have a document that needs \pageref to produce something other than \thepage. I've gotten it to work like this

Code: Select all

\documentclass[twoside,11pt]{article}
%\usepackage{hyperref}

\makeatletter

\newcounter{minipage}
\setcounter{minipage}{3}
\renewcommand\theminipage{M-\@arabic\c@minipage}

\def\pagetoref{\thepage}

% Stole and overloaded this from latex.ltx:3873
% modified to use \pagetoref instead of \thepage
\def\label#1{\@bsphack
    \protected@write\@auxout{}%
    {\string\newlabel{#1}{{\@currentlabel}{\pagetoref}}}%
    \@esphack}

\makeatother

\begin{document}

\tableofcontents

\def\pagetoref{\theminipage}

Section \ref{sec:first} on page \pageref{sec:first}

\section{first section}
\label{sec:first}


\end{document}
I compile and get the desired results; however, when I add in the hyperref package, the \pageref shows \thepage, not \theminipage.

I've looked all through the hyperref.sty file looking for something to overload, but can't find anything. Any ideas?

Jay

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

jaykemper
Posts: 22
Joined: Wed Apr 15, 2009 12:11 am

Hyperref and pageref

Post by jaykemper »

I have some more information...I made a copy of the hyperref package and started makeing a few changes. I found some interesting things, but still got a dead end:

1. Changed all \thepage to \pagetoref (\def\pagetoref{\thepage}} for default usage). This did change the table of contents and all warning messages after \def\pagetoref{\theminipage}. Did not change \pageref.

2. On line 6188 of hyperref.sty

Code: Select all

\let\real@setref\@setref
\def\@setref#1#2#3{% csname, extract group, refname
    % #1 contains string of tokens, second is pageref% - Added by JCK
    (% - Added by JCK
     \expandafter\@firstoffive#1,% - Added by JCK
     \expandafter\@secondoffive#1,% - Added by JCK, this is the \pageref
     \expandafter\@thirdoffive#1,% - Added by JCK
     \expandafter\@fourthoffive#1,% - Added by JCK
     \expandafter\@fifthoffive#1)% - Added by JCK
  \ifx#1\relax
    \protect\G@refundefinedtrue
    \nfss@text{\reset@font\bfseries ?XX?}%
    \@latex@warning{%
      Reference `#3' on page \pagetoref \space undefined%
    }%
  \else
    \expandafter\Hy@setref@link#1\@empty\@empty\@nil{#2}%
  \fi
}
\def\Hy@setref@link#1#2#3#4#5#6\@nil#7{%
  \begingroup
    \toks0={\hyper@@link{#5}{#4}}%
    % #2 contains pageref% - Added by JCK
    \toks1=\expandafter{#7{#1}{#2}{#3}{#4}{#5}}%
    \edef\x{\endgroup
      \the\toks0 {\the\toks1 }%
    }%
  \x
}


So this function \@setref is called with all this information passed to it {the \@secondoffive of the first argument), but where is it called? I think I'm too deep and need to burrow my way up until I find out where the text for the \pageref is getting set.
Post Reply