Currently, within my thesis, I am numberings theorems (and remarks, etc.) with a global counter. This makes it difficult in the printed version to find the theorem if a reference is too far away from the label. Is there any simple way I can modify my reference commands to add a "on page XXX" in case of having lets say a 3 page gap between ref and label? Do you have any suggestions or experiences?
As far as I understood the documentations, packages such as varioref only support a one-page-diff condition; but even this I was not able to activate.
Minimal working example:
\documentclass{scrreprt}
\usepackage{blindtext} % lore ipsum...
\usepackage{amsthm}
\newtheorem{thm}{Theorem}
\begin{document}
% example theorem:
\begin{thm}\label{thm:foo}
The future belongs to those who believe in their dreams.
\end{thm}
% generate more than 3 pages of text:
\blindtext[20]
% reference:
Reference to theorem \ref{thm:foo}. Here an automatic
``on page \pageref{thm:foo}'' would be nice.
\end{document}
MWE for Mico (see discussion below):
\documentclass{scrreprt}
\usepackage{blindtext} % lore ipsum...
\usepackage{amsmath}
\usepackage{ntheorem}
\usepackage{varioref}
\usepackage{hyperref}
\newtheorem{thm}{Theorem}
\begin{document}
% theorem foo
\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]
% cross-reference to theorem within equation which is labeled itself (same works for figures)
\begin{align}\label{eqn:bar}
a+b=c\quad\text{(cf. Theorem \vref{thm:foo})}
\end{align}
\end{document}
Leads to
! Package amsmath Error: Multiple \label's: label 'eqn:bar' will be lost.! Package amsmath Error: Multiple \label's: label '4@xvr' will be lost.- several further warnings...
(Partial) Solution (based on Christians idea)
After playing around with Christians suggestion I came up with a solution (it SEEMS to work). I have to store the manipulated \ref command to \vref before hyperref is loaded. Then, I can use \ref as standard ref and \vref as optional "on page" version. For some strange reason this only works together with babel. It is important to add a "%" in order to avoid wrong spacing.
\documentclass{scrreprt}
\usepackage{blindtext} % lore ipsum...
\usepackage{amsmath}
\usepackage[english]{babel} % < for some strange reason HAS to be loaded
%% --- ref manipulations as suggested by Christian Hupfer:
\makeatletter
\let\latex@@ref\ref
\newcounter{pagegaptreshhold}
\setcounter{pagegaptreshhold}{2}
\newcounter{tmpcntr}
\renewcommand{\ref}[1]{%
\setcounter{tmpcntr}{\value{page}}%
\addtocounter{tmpcntr}{-\getpagerefnumber{#1}}%
\ifnum\value{tmpcntr} < 0 %
\setcounter{tmpcntr}{\numexpr -1*\value{tmpcntr}}%
\fi%
\ifnum\value{tmpcntr} > \value{pagegaptreshhold}
\latex@@ref{#1} on page \pageref{#1}%
\else%
\latex@@ref{#1}%
\fi%
}
\makeatother
%% --- end cmhughes suggestion ---
\let\vref\ref
\usepackage{hyperref}
\newtheorem{thm}{Theorem}
\begin{document}
% theorem foo
\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[30]
% cross-reference to theorem within equation which is labeled itself (same works for figures)
\begin{align}\label{eqn:bar}
a+b=c\quad\text{(cf. Theorem \vref{thm:foo})}
\end{align}
In particular, we have now the choice between
\begin{itemize}
\item ``on page''-if-too-far-away-style: Theorem \vref{thm:foo}
\item classic style: Theorem \ref{thm:foo}
\end{itemize}
\end{document}
hyperref– Oct 31 '15 at 14:39cleverefpackage as well (afterhyperref), as doing so fixes a minor but long-standing incompatibility betweenvariorefandhyperref. – Mico Nov 01 '15 at 18:29cleverefchanges so many things (adding extra "theorem" etc.) and throws further warnings ("destination with the same identifier ... duplicate ignored")... :-/ Can't I use just "the fix" fromcleverefwithout introducing all the other inconveniences? – matheburg Nov 02 '15 at 06:09cleverefdoesn't throw away warnings and error messages -- it actually fixes the problems that give rise to the warnings and error messages. If you need bothvariorefandhyperref, loadingcleverefas well is -- for now at least -- the way to go. I use the macros of thecleverefpackage extensively in my own papers and can thus wholeheartedly recommend its use. – Mico Nov 02 '15 at 06:22cleverefdoes not "throw away" errors and warnings, but it "throws new warnings"; but my major problem is that it introduces "theorem" before a ref of kind "thm:foo"; do you know how to deactivate this behaviour? – matheburg Nov 02 '15 at 07:34