# Compress “page” label with varioref and cleveref

In case of multiple cross-references of same kind (say sections), even if not consecutive, cleveref's \cref command compresses the references' labels by using the plural form: for instance, \cref{foo2,foo4,foo6} could prints:

sections 2, 4 and 6

instead of:

section 2, section 4 and section 6

If varioref is also loaded, the page numbers can be added thanks to its \vref command (redefined by cleveref) used instead of \cref.

But, then, the "page" label is not compressed, as shown by the following MWE where \vref{foo2,foo4,foo6} prints:

sections 2, 4 and 6 on page 4, on page 8 and on page 12.

where one could expect:

sections 2, 4 and 6 on pages 4, 8 and 12.

especially since:

• \cpageref does the right job,
• cleveref's documented code claims to use \cpageref instead of \vpageref in its redefinition of \vref:

Since \cref can cope with multiple references, we extend the page referencing magic of \vref et al. to use \cpageref instead, assisted by \@setvpageref and \@vpagerefrange (which typeset page references using varioref commands). The former takes care of multi-references, the latter take care of the varioref page referencing magic.

Do you see what's going on?

\documentclass{article}
\usepackage{multido}
\usepackage{varioref}
\usepackage{cleveref}
%
\newcommand{\test}[1]{%
\section{#1}\label{#1}
\newpage
#1
\newpage
}
%
\begin{document}
\begin{itemize}
\item \verb|\cref{foo2,foo4,foo6}|: \cref{foo2,foo4,foo6}
\item \verb|\vref{foo2,foo4,foo6}|: \vref{foo2,foo4,foo6}
\item \verb|\cpageref{foo2,foo4,foo6}|: \cpageref{foo2,foo4,foo6}
\item \verb|\vpageref{foo2,foo4,foo6}|: \vpageref{foo2,foo4,foo6}
\end{itemize}
\newpage
\multido{\i=1+1}{6}{%
\test{foo\i}
}
\end{document}

• you mean that \vref need to be redefined in some way to be \cref{#1} on \cpageref{#1}. I think the best is to write to the author. – touhami Jan 23 '16 at 14:03
• @touhami Indeed, and I have the secret hope he subscribed to the cleveref tag ;) – Denis Bitouzé Jan 23 '16 at 17:23

## 1 Answer

This is due to limitations of varioref. Consecutive page references are compressed when you use varioref with cleveref. But avoiding printing "on page x" before each page reference (or group thereof) would mean rewriting large parts of varioref.

At that point, cleveref would probably be replacing varioref rather than hooking into it. Perhaps this would make sense. But it's unlikely to happen any time soon.

• When it will happen, cleveref's users will likely be very happy :) – Denis Bitouzé Aug 26 '16 at 17:09