# Varioref, cleveref and autonum together

I'm trying to mix varioref, cleveref and autonum to have the following behaviors:

• Automatic adding of reference type (i.e. adding "section" when referencing a section). -> cleveref;
• Adding the "on next/following page" -> varioref;
• Not numbering equations which are not referenced -> autonum.

Any combination of two of the three works well, but the three fail with undefined references.

A simple example:

\documentclass{article}

\usepackage{amsmath}

\usepackage{varioref}
%\usepackage{hyperref}
\usepackage{cleveref}

\usepackage{autonum}

\begin{document}

\begin{align} x \label{eqnx} \end{align} % referenced, must have number (1)
\begin{align} y \label{eqny} \end{align} % referenced, must have number (2)
\begin{align} z \label{eqnz} \end{align} % not referenced, must not have any number

\pagebreak

\vref{eqnx,eqny} %% Solution 1: What I'm looking for, does not work

% \cref{eqnx,eqny} \vpageref{eqnx,eqny} %% Solution 2: A different way of writing Solution 1. Works. Note that this is not really equal to Solution 1.

%\vref{eqnx,eqny} \ref{eqnx} \ref{eqny} %% Solution 3: WORKS, use vref as solution1, but there is also references using standard \ref

\end{document}


Edit: A solution was provided, but finally I think that not numbering equation, even if they are not referenced, is a bad practice because reviewers cannot easily reference them. So except for special use cases, I discourage the usage of autonum.

• I tried \usepackage{mathtools}\mathtoolsset{showonlyrefs=true} instead of autonum and amsmath, but no luck either. There are less errors if the math packages are loaded after the reference packages, though. – Crissov Feb 4 '14 at 9:12
• @Crissov, from what I have read, the mathtools package is deprecated in favor of autonum when used with cleveref because "autonum was designed to work with cleveref". Obviously it does not ;(. – Guillaum Feb 4 '14 at 13:11

Since it seems you want the \vref command to work with Comma Separated Lists, you should use \autonum@generatePatchedReferenceCSL{vref} as in the following.

\documentclass{article}
\usepackage[%
paperwidth=3in,
paperheight=2in,
margin=0.1in,
bottom=0.3in,
footskip=0pt]{geometry} % Only to get smaller pages for MWE

\usepackage{amsmath}

\usepackage{varioref}
\usepackage{cleveref}

\usepackage{autonum}

\makeatletter
\autonum@generatePatchedReferenceCSL{vref}
\makeatother

\begin{document}

\begin{align} x \label{eqnx} \end{align} % referenced, must have number (1)
\begin{align} y \label{eqny} \end{align} % referenced, must have number (2)
\begin{align} z \label{eqnz} \end{align} % not referenced, must not have any number

\pagebreak

\vref{eqnx,eqny}

\end{document}


From section 3.3 "Reference commands" in the documentation:

For reference commands expecting a comma separated list of label names as an argument, you can use \autonum@generatePatchedReferenceCSL{NewReferenceCommand}.

According to the documentation, one can use \autonum@generatePatchedReference{NewReferenceCommand} to make "normal reference commands expecting a single label name as an argument" work with autonum.

Adding the following should make things work:

\makeatletter
\autonum@generatePatchedReference{vref}
\makeatother

• The correct thing here is to use \autonum@generatePatchedReferenceCSL{vref} since vref can be used with Comma Separated Lists, as in OPs MWE. – hooy Sep 10 '15 at 7:37
• Using the correction from @hooy this actually works. Thank you. – Guillaum Jan 27 '16 at 8:45