Conditional pageref for labels far away
(Updated answer after the OP posted a second, more elaborate MWE.)
The varioref
package implements the following decision rule with regard to generating page call-outs:
If the item being cross-referenced and the cross-reference are on the same page, no page-related affix is produced;
If the item being cross-referenced and the cross-reference are on adjoining pages, either "on the previous page" or "on the following page" is affixed to the cross-reference.
If the item being cross-referenced and the cross-reference itself are two or more pages apart, a "on page x" affix is generated.
If you know in advance that there will be several pages between the cross-reference and the item being cross-referenced, you may also use the instruction \fullref
, which is simpler (uses fewer machine cycles...) than \vref
.
If you use both varioref
and hyperref
, you should load the cleveref
package as well: Doing so fixes a (mild) conflict between the former two packages. If you load cleveref
, the items' names ("equation", "theorem", etc) will be prefixed automatically to the cross-reference call-outs.
\documentclass{scrreprt}
\usepackage{blindtext} % lorem ipsum...
\usepackage{amsmath}
\usepackage[amsmath]{ntheorem}
\usepackage{varioref} % for \vref and \fullref macros
\usepackage[colorlinks]{hyperref}
\usepackage[nameinlink]{cleveref}
\newtheorem{thm}{Theorem}
\begin{document}
\setcounter{chapter}{1} % just for this example
% theorem foo, with cross-reference to an equation
\begin{thm}\label{thm:foo}
The future belongs to those who believe in their dreams (see \vref{eqn:bar}).
\end{thm}
% some pages of text...
\blindtext[15]
% equation bar, with cross-reference to a theorem
\begin{align}\label{eqn:bar}
a+b=c\quad\text{(cf.\ \fullref{thm:foo})}
\end{align}
\end{document}