In the kernel the definition of protected@write includes the setting of the \thepage to
\relax. Why is this and are there other means to ensure that thepage is not expanded?
\long\def \protected@write#1#2#3{%
\begingroup
\let\thepage\relax
#2%
\let\protect\@unexpandable@protect
\edef\reserved@a{\write#1{#3}}%
\reserved@a
\endgroup
\if@nobreak\ifvmode\nobreak\fi\fi
}
perpagepackage where it imitates its behaviour for a custom counter -- takes a free ride into shipout:) – yannisl Feb 18 '13 at 21:56#2in the definition you show is just a hook to allow other commands to get similar local definitions. – David Carlisle Feb 18 '13 at 22:09