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
}
