[Tex/LaTex] Stable alternative to \thepage

cross-referencingpage-numbering

As I read and found out the command \thepage doesn't always output the correct page number.

The proposed alternative is to use \pageref{here}\label{here}. But this seems too unhandy, because I have to change the label every time I want to get the current page, which makes it impossible to just replace it by a simple new command.

P.S.: In the end I want to define this:

\newcommand{\see}[1]{\cref{#1}\ifthenelse{\equal{\pageref{#1}}{\thepage}}{}{ on \cpageref{#1}}}

where the part on \cpageref{#1} should only be output if it is not the current page.

Best Answer

You can easily combine the \pageref{here}\label{here} in one command by using e.g. a counter to avoid multiple labels:

\documentclass{article}
\newcounter{labelhere}
\makeatletter
\newcommand\pagerefhere{%
 \stepcounter{labelhere}%
 \pageref{here\thelabelhere}\label{here\thelabelhere}}
\begin{document}

\pagerefhere blub \newpage \pagerefhere bla

\end{document}
Related Question