# Referencing label with conditional page info

I would like to have an easy way to reference a label and if that label is not on the current page then its page should be printed in the reference like "See example 2.3 (p.4)". I tried the varioref and the cleveref packages but their text output using \vref or \cref is too verbose for me. I couldn't find anything in the documentation to just print (p.4) instead. Or is there another alternative?

• Why couldn't you "find anything in the documentation"? Where did you look? Section 3 "Customization" of varioref.pdf has all the details. – Frank Mittelbach Aug 28 '13 at 19:20
• I saw that but couldn't figure out that this section with its non-existing examples is what I'm looking for. – user764754 Aug 28 '13 at 20:37

If you are using babel you can change the printed reference with package varioref as shown in the following MWE for German language.

\documentclass[ngerman]{scrartcl}% article

\usepackage{babel}
\usepackage{varioref}
\usepackage{blindtext}

\renewcommand{\reftextfaceafter}[1]{(Seite~\pageref{#1})}
\renewcommand{\reftextfacebefore}[1]{(Seite~\pageref{#1})}
\renewcommand{\reftextafter}[1]{(Seite~\pageref{#1})}
\renewcommand{\reftextbefore}[1]{(Seite~\pageref{#1})}
\renewcommand{\reftextcurrent}[1]{(Seite~\pageref{#1})}
\renewcommand{\reftextfaraway}[1]{(Seite~\pageref{#1})}
}

\begin{document}

\section{Abschnitt 1}
\label{sec:Test}

Und der erste Verweis auf Abschnitt~\vref{sec:Test}. %  <===============

\Blinddocument

Und der Verweis auf Abschnitt~\vref{sec:Test}.       %  <===============

\end{document}


The macro \addto{\extrasngerman} adds the new meanings for language ngerman. If you use another language change ngerman to your language.

Change (Seite~\pageref{#1}) to that you need, for example (p.~\pageref{#1}).

Edit:

The KOMA-Script macro \newcaptionname{ngerman}{...} is not able to handle a third argument (for \pageref{#1}) so you can't use it here.

• Perfect. One thing that is strange is that i get errors like "Extra \else." when I keep using cleveref. – user764754 Aug 28 '13 at 0:03
• @user764754 errors might be due to the order you load packages (or not all of them up-to-date): hyperref, babel and cleveref all overwrite some of the varioref definitions. – Frank Mittelbach Aug 28 '13 at 19:18

If you use varioref all the fixed texts are in easily changable macros, for example the package has

    \def\reftextfaraway#1{on page~\pageref{#1}}%


so you can have

    \renewcommand\reftextfaraway[1]{p.~\pageref{#1}}%


and similarly for any other texts it produces.

• Thanks! What worked for me was \addto\extrasngerman{\renewcommand{\reftextfaraway}[1]{(p.\pageref{#1})}} – user764754 Aug 27 '13 at 23:19
• @user764754 this is needed because Babel is used. All of that is documented in varioref.pdf (section 3). – Frank Mittelbach Aug 28 '13 at 19:16