This works nicely:
\documentclass{article}
\begin{document}
\label{mylabel}
\pageref{mylabel}
\edef\mypage{\pageref{mylabel}}
\end{document}
But using hyperref
, thus replacing \pageref
by \pageref*
to have only the page number without the link, this does not work:
\documentclass{article}
\usepackage{hyperref}
\begin{document}
\label{mylabel}
\pageref*{mylabel}
\edef\mypage{\pageref*{mylabel}}
\end{document}
The error is:
! Undefined control sequence.
l.6 \edef\mypage
{\pageref*{mylabel}}
The control sequence at the end of the top line
of your error message was never \def'ed.
Why is that, and how can I do it better?
\def\mypage\relax
before\edef
fixes the error, but then\mypage
after\edef
raisesUse of \mypage doesn't match its definition. \end
\def\mypage\relax
there then the full definition is\def\mypage\relax\edef\mypage{\pageref*{mylabel}}
and\mypage
is defined such that it has to be followed by\relax\edef\mypage
and expands to\pageref*{mylabel}
(which would generate an error that the generated expand is not followed by\relax
the{}
are mandatory in\def
so it includes all the tokens up the the{}
it finds.