# Add automatic pageref to ref if referent is on another page

I'm working on my thesis right now and have a small issue I'm not absolutely sure how to solve. Make lots of cross-references and as the thesis won't be 4 pages long I find it helps to add page-references when referencing something on another page. Previously, I've manually written something like

see Equation \ref{regression} on page \pageref{regression}


whenever I want to do this. However, as 95% of my cross-references are to different pages I have written a macro:

\newcommand{\exactref}[1]{\ref{#1} on page \pageref{#1}}


However, there are edge cases. For instance, with some floats, the referent might be on the same page at one time, but with a small, seemingly unrelated edit, it might end up at a different page. It would be awesome if my macro could handle this by checking whether reference and referent are on the same page or not and only adding the pageref if not.

Meanwhile, I'm no LaTeX macro ninja and am not sure whether this behavior would even be possible without digging down deep into TeX itself. Has anyone got any pointers for me on how to go about this?