FAQ
overflow

Great Answers to
Questions About Everything

QUESTION

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.

{ asked by white_gecko }

ANSWER

Simply load varioref before cleveref and use \vref in the document body. See section 2.3 of the varioref manual for details about suppressing textual references.

\documentclass{article}

\usepackage{varioref}
\renewcommand\reftextfaceafter{on page~\thevpagerefnum}
\renewcommand\reftextfacebefore{on page~\thevpagerefnum}
\renewcommand\reftextafter{on page~\thevpagerefnum}
\renewcommand\reftextbefore{on page~\thevpagerefnum}

\usepackage{cleveref}

\begin{document}

\section{foo}\label{foo}

\clearpage

\section{bar}\label{bar}

\section{gnu}

See also \vref{foo}.

See also \vref{bar}.

\end{document}

Output (p. 2):

enter image description here

{ answered by lockstep }
Tweet