I thought I was pretty cool when I modified \ref to also print a page number when the referenced float was more than a few pages back. But I really want it to be a nice link using the hyperref package as well!
How can I modify my command so that it will cause the page number to also be a link?
\documentclass{report}
\usepackage{mwe}
% \usepackage[% Un-commenting this causes the page number not to appear
% pagebackref=true,
% ]{hyperref}
\usepackage{ifthen}
\usepackage{calc}
\usepackage{xspace}
\let\oldref\ref
\renewcommand\ref[1]{%
\newcount\cnt
\cnt=\thepage
\advance\cnt by -2
\ifthenelse{%
\pageref{#1} < \cnt%
}{%
\oldref{#1}~p.\,\pageref{#1}\xspace%
}{%
\oldref{#1}%
}%
}
\begin{document}
\blindtext[1]
Figure~\ref{fig:example_image_a}
%
\begin{figure}
\centering
\includegraphics[width=0.6\textwidth]{example-image-a}%
\caption{
example-image-a
\label{fig:example_image_a}
}
\end{figure}
\Blindtext[10][10]
Figure~\ref{fig:example_image_a}
\end{document}

tex.serevealed this gem from http://tex.stackexchange.com/a/83051/45296 : "There are too many problems with varioref. Nobody has time to sort them out. Therefore this package is now unsupported." That said, it has been a while so I will take another look atcleveref– repurposer Nov 06 '15 at 18:03\pagerefisn't expandable, as far as I know and allocating\cnteach time when\refis called is ... well ... – Nov 06 '15 at 18:28hyperrefit's not loaded, but I don't really know what is the meaning of expandable – repurposer Nov 06 '15 at 18:31\pagerefgets correctly evaluated inside that `\ifthenelse stuff – Nov 06 '15 at 18:34