Re: setting counter from roman numeral pageref
- From: Ulrich D i e z <eu_angelion@xxxxxxxxxxxxxx>
- Date: Fri, 6 Mar 2009 16:12:53 +0100
John wrote:
I have, from Heiko Oberdiek, some macros for taking a pageref and
turning it into a counter. So long as the pagerefs return arabic
numerals, the macros work perfectly. But if the pagerefs return roman
numerals (as in a preface or other front matter) I run into a problem,
since the macros expect a number but get a letter. I post Heiko's
macros below. Does anyone have an idea how to turn roman numerals into
counters?
You'd need to turn roman numerals into something which TeX can
use for counter-assignments - e.g., octal, hexadecimal or decimal
numbers in arabic-digit-notation, or a character-constant like
`a. This is feasible.
Another approach is making \thepage spit out both the arabic
and the roman notation of the page-counter and making it choose
the appropriate one via \@firstoftwo / \@secondoftwo depending
on how the control-sequence "\protect" is defined.
(Usually \protect equals \relax, but this is not the case
when the \label-macro writes to the aux-file or when warnings
go to screen or to log-file.)
You might be interested in Heiko Oberdiek's refcount-package.
It provides the facilities used by you.
The approach below is based on Heiko Oberdiek's refcount-package
and seems to work on my system.
Ulrich
\documentclass{book}
\usepackage[pageanchor=true,
plainpages=false,
colorlinks=true,
pdfpagelabels=true,
linkcolor=blue]{hyperref}
\usepackage{refcount}
\makeatletter
\DeclareRobustCommand*\MyPageReference[2][]{%
\expandafter\ifx\csname r@#2\endcsname\relax
#1\nfss@text{\reset@font\bfseries??}%
\refused{#2}%
\else
\hyperref{\getrefbykeydefault{#2}{url}{}}%
{page}%
{\getpagerefnumber{#2}}%
{#1\pageref*{#2}}%
\fi
}%
\newcommand*\getarabicpagerefnumber[1]{%
\expandafter\ifx\csname r@#1\endcsname\relax
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
{\rc@default}%
{%
\expandafter\expandafter
\expandafter\@firstoftwo
\expandafter\@gobbletwo
\romannumeral0\getpagerefnumber{#1}%
}%
}
\newcommand*\enablegetarabicpagerefnumber{%
\ifx\protect\relax
\expandafter\@gobbletwo
\else
\expandafter\@firstofone
\fi
{%
\ifx\protect\string
\expandafter\@gobble
\else
\expandafter\@firstofone
\fi
}%
{\protect\noexpand\protect\noexpand\protect}%
\@secondoftwo
}%
\makeatother
\begin{document}
\frontmatter
\makeatletter
\renewcommand\thepage{%
\enablegetarabicpagerefnumber
{\csname @arabic\endcsname\c@page}%
{\csname @roman\endcsname\c@page}%
}%
\makeatother
\section{A section on the first page}
text text text text\\
text text text text\\
text text text text
\newpage
text text text text \label{MyLabel}
\section{A section on the second page}
text text text text\\
text text text text\\
text text text text\\
text text text text\\
text text text text\\
text text text text\\
text text text text\\
text text text text\\
text text text text\\
text text text text\\
text text text text\\
text text text text\\
text text text text
\newpage
\section{A section on the third page}
text text text text\\
text text text text\\
text text text text
\newpage
This link goes to the head of page ii:\\
\verb|\MyPageReference[Page~]{MyLabel}|:
\MyPageReference[Page~]{MyLabel}.
\medskip
This link goes to the heading of section 1 (top of page i):\\
(Besides this, the first pdfLaTeX-run yields some confusing
warnings about non-existing destinations!)\\
\verb|\hyperref[MyLabel]{Page~\pageref*{MyLabel}}|:
\hyperref[MyLabel]{Page~\pageref*{MyLabel}}.
\medskip
This link goes to the heading of section 1 (top of page i)
while the link-text denotes page ii:\\
\verb|\pageref{MyLabel}|: \pageref{MyLabel}.
\medskip
This is the roman-numeral of MyLabel's page-number:
\getpagerefnumber{MyLabel}
\medskip
This is the arabic-numeral of MyLabel's page-number:
\getarabicpagerefnumber{MyLabel}
\medskip
Counter-Assignment:\\
\newcounter{MyCounter}
\setcounter{MyCounter}{\getarabicpagerefnumber{MyLabel}}
This is the value of MyCounter: \theMyCounter
\medskip
%% In order to compare the log-file-warnings for undefined
%% labels, you can activate all the following stuff:
%%
%% A single warning:\par
%\verb|\MyPageReference{undef}|:
%\MyPageReference{undef}.
%\medskip
%
%% Two warnings and a question-mark linked to the first page
%% of the document:\par
%\verb|\hyperref[undef]{Page~\pageref*{undef}}|:
%\hyperref[undef]{Page~\pageref*{undef}}.
%\medskip
%
%% A single warning:\par
%\verb|\pageref{undef}|:
%\pageref{undef}.
\end{document}
.
- Follow-Ups:
- Re: setting counter from roman numeral pageref
- From: Ulrich D i e z
- Re: setting counter from roman numeral pageref
- References:
- setting counter from roman numeral pageref
- From: burt
- setting counter from roman numeral pageref
- Prev by Date: Re: \hspace{\linewidth minus\linewidth}
- Next by Date: Re: \hspace{\linewidth minus\linewidth}
- Previous by thread: Re: setting counter from roman numeral pageref
- Next by thread: Re: setting counter from roman numeral pageref
- Index(es):
Relevant Pages
|
Loading