I need a list like the list of figures
for \ref
entries in the text to instances of a custom Theorem
environment. Here's a MWE with a handbuilt example. The solution should add features to this code I built using the answer to write contents of an environment to document and toc.
\documentclass[12pt]{book}
\usepackage{amsthm}
\usepackage{environ}
\usepackage{hyperref}
\newcommand{\gref}[1]{%
[Goal~\ref{goal:#1}]
}
\makeatletter
\newcommand\l@goal[1]{%
\addpenalty{\@highpenalty}%
\vskip \z@ \@plus \p@
\begingroup
\parindent\z@
\rightskip\@pnumwidth
\parfillskip-\@pnumwidth
\leavevmode #1\nobreak\hfil\nobreak\null\par
\penalty\@highpenalty
\endgroup}
\newcommand{\egregaddtocontents}[1]{%
\addtocontents{toc}{\protect\l@goal{#1}}}
% arrange goal numbering by chapter
\newtheorem{Goal}{Goal}[chapter]
\NewEnviron{goal}[1]{%
\begin{Goal}
\label{goal:#1}
%{\em label:} #1 %comment in/out to restore/suppress printing label
\normalfont{}\noindent
\BODY
\egregaddtocontents{\BODY}
}
[\end{Goal}]
\makeatother
\begin{document}
\tableofcontents{}
\chapter{First}
\begin{goal}{firstfirst}
learn more \LaTeX
\end{goal}
\begin{goal}{firstsecond}
spend time on content, not \LaTeX
\end{goal}
stuff
\chapter{Second}
\begin{goal}{secondfirst}
have fun in any case
\end{goal}
Chapter contents here, referring to some goals:
\section{whatever}
Reference to a chapter 1 goal: \gref{firstsecond}
Reference to a chapter 2 goal: \gref{secondfirst}
\section{another}
Second reference to a chapter 2 goal: \gref{secondfirst}
\chapter*{List of Goal References}
Built by hand, should be automated. Format not yet specified.
\begin{itemize}
\item \gref{firstfirst}
learn more \LaTeX
\item \gref{firstsecond}
spend time on content, not \LaTeX
\begin{itemize}
\item Section 2.1, page 5 [link to that page]
\end{itemize}
\item \gref{secondfirst}
have fun in any case
\begin{itemize}
\item Section 2.1, page 5 [link to that page]
\item Section 2.2, page 5 [link to that page]
\end{itemize}
\end{itemize}
\end{document}
Here's the list from the MWE. The format is \itemize
but that's just temporary - the solution should allow me to change it easily.
Perhaps there's already a package that does the job. If not, perhaps build on top of or cannibalize code that creates the index and the list of figures, since I require features from both.
tocloft
to write that myself and answer my own question - but I hope someone else finds the challenge entrancing before I get around to it. – Ethan Bolker Jun 23 '12 at 22:17