Refer to page numbers where table is referenced
Something like this?
\documentclass{article}
\usepackage{varioref}
\usepackage[colorlinks]{hyperref}
\usepackage[noabbrev]{cleveref}
\begin{document}
\begin{table} \caption{A}\label{tab:main} \end{table}
\clearpage \null \clearpage
In \vref{tab:main}, you can see \dots
For a discussion of \cref{tab:main}, see \cpageref{tab:main}.
\end{document}
When I first read this I thought that the question was asking for a command that gave the list of pages that contain a reference to a given table. That is, an analogue of backref for \autoref
instead of for \cite
. Rereading the question it probably does not ask for this but, nonetheless, I thought this an interesting question and the code below is one way of providing this functionality.
The code works by redefining the \autoref
command so that whenever it is called it first adds the current page number to a corresponding latex3 sequence. At the end of the document this sequence is saved to the aux file. Once the document has been compiled at least once the command \pagerefs{...}
can be used to print the list of pages that the reference appears on. So, for example, the MWE below produces:
Here is the code:
\documentclass{article}
\usepackage{lipsum}
\usepackage{etoolbox}
\usepackage{xparse}
\usepackage{hyperref}
\ExplSyntaxOn
\NewDocumentCommand\PageReferences{mm}{
\seq_if_exist:cF {g__pages_#1_seq}{
\seq_new:c {g__pages_#1_seq}
\seq_gset_from_clist:cn {g__pages_#1_seq} {#2}
}
}
\RenewDocumentCommand\autoref{sm}{
\seq_if_exist:cF {g_pages_#2_seq}{
\seq_new:c {g_pages_#2_seq}
\AtEndDocument{
\iow_now:cx { @auxout } {
\token_to_str:N \PageReferences{#2} { \seq_use:cn {g_pages_#2_seq}{,}}
}
}
}
\seq_if_in:cxF {g_pages_#2_seq} {\thepage} {
\seq_gput_right:cx {g_pages_#2_seq} {\thepage}
}
% now call the real autoref, which is really \HyPsd@autoref
\IfBooleanTF{#1}{\csuse{HyPsd@autoref}*{#2}}{\csuse{HyPsd@autoref}{#2}}
}
\NewDocumentCommand\pagerefs{m}{
\seq_if_exist:cTF {g__pages_#1_seq}{
\seq_use:cnnn {g__pages_#1_seq} { ~and~ } { ,~ } { ,~and~ }
}{??}
}
\ExplSyntaxOff
\begin{document}
\begin{equation}\label{E:1} 1+1=2 \end{equation}
Look at \autoref{E:1}! It occurs on pages \pagerefs{E:1}.
\lipsum
Look at \autoref{E:1}
\lipsum
Look at \autoref{E:1}
\lipsum
Look at \autoref{E:1}
\lipsum
Look at \autoref{E:1}
\lipsum
Look at \autoref{E:1}
\lipsum
\end{document}