The following MWE shows my attempt to create a list of references in a document, with links from text to reference and back. It works well in text, but badly in figures when I try make the reference link follow the caption.
Hyperlinks work correctly but their text representations are wrong.
This may be an xy-problem (http://mywiki.wooledge.org/XyProblem). If there's a better solution than my attempted hack, feel free...
I've played with subcaptions as suggested at How to put two labels for one figure with no success.
\documentclass{book}
\usepackage{answers}
\usepackage{environ}
\usepackage{graphicx}
\usepackage{xifthen}
%\usepackage{subcaption}
\usepackage{hyperref}
\newcommand{\referencesFilename}{references}
\newcounter{csmrefcounter}
\newcounter{gotoref}
\NewEnviron{csmr}[1][]{%
\refstepcounter{csmrefcounter}
\stepcounter{gotoref}
\ifthenelse{\isempty{#1}}
{[R\ref{RR\arabic{gotoref}}]% not inside figure
\label{R\arabic{csmrefcounter}}
}
{\caption{#1 [R\ref{RR\arabic{gotoref}}]}% inside figure
\label{R\arabic{csmrefcounter}}
}%
\Writetofile{\referencesFilename}{\protect\item[R\ref{R\arabic{csmrefcounter}}]}
\Writetofile{\referencesFilename}{\protect\refstepcounter{gotoref}}
\Writetofile{\referencesFilename}{\protect\label{RR\arabic{gotoref}}}
\Writetofile{\referencesFilename}{\BODY }
}
\newcommand{\getreferences}{%
\newpage
\chapter{References}
\setcounter{gotoref}{0}
\begin{itemize}
\input{\referencesFilename}
\end{itemize}
}
\begin{document}
\Opensolutionfile{\referencesFilename}
\chapter{Fermi Problems}
\begin{quotation}
Every day the National Security Agency intercepts and
stores \emph{1.7 billion} international e-mails, phone calls, texts and
other communications.%
\begin{csmr}
ACLU National Newsletter, Summer 2012. Testing behavior if this is a
very long reference, perhaps spanning multiple lines.
\end{csmr}
\end{quotation}
Here's a second reference
\begin{csmr}
Second text reference.
\end{csmr}
inline in the text.
Now test the referencing mechanism for figures.
\begin{figure}
\centering
FIGURE 1 - without a reference
\caption{caption for Figure 1}
\label{fig:1}
\end{figure}
\begin{figure}
\centering
FIGURE 2 - with a reference
\begin{csmr}[caption for Figure 2 - correct reference label here:]
Reference for Figure 2. The link goes to the right place, but displays
incorrectly, showing the figure number rather than the reference number.
\end{csmr}
\label{fig:2}
\end{figure}
\begin{figure}
\centering
FIGURE 3 - without a reference
\caption{caption for Figure 3}
\label{fig:3}
\end{figure}
Try to refer to the figure labels: first one is
\ref{fig:1}, second is \ref{fig:2}, third is
\ref{fig:3}. Note that the link to Figure 2 displays the (wrong!)
reference number rather than the figure number, but goes the the right
place.
\Closesolutionfile{\referencesFilename}
\getreferences
\end{document}