# Using environ to make a list of environments?

In my document I use an amsthm environment called question, which I use to, well, pose questions to myself for later reference. However, they are spread out in the text.

I know ntheorem has a \listoftheorems command or something like that which does exactly what I want. However, I have quite some bad experiences with ntheoremconcerning the use of ntheoremtogether with other packages (it only occured when I used mathtools and something which I have forgotten about...) which introduced quite strange bugs, so I would want to avoid ntheorem altogether for the moment.

So, is this possible to do this with environ as it provides some useful hooks? Preferably it would be nice if the list also allows me (optionally) to include a short description and of course a page number. The environment is defined as \newtheorem{question}{Question}.

Edit: I have found thmtools which apparently also has a command \listoftheorems (and a way to redefine the heading). Would it be possible to extend this command such that I am able to add a small description?

-
In my opinion, your new edit should be a follow-up question. –  Gonzalo Medina Jul 19 '12 at 23:57
@GonzaloMedina Okay. Agreed. Will do. –  Jonas Teuwen Jul 19 '12 at 23:57

First of all there is the tocloft package, that is meant for this kind of work and takes away a little of the effort in Gonzalo's answer. Also I would propose to define a new environment, so you don't have to use an extra command, but can have an actual, optional argument:

\documentclass{article}
\usepackage{amsthm}
\usepackage{tocloft}

\newtheorem{xquestion}{Question}

\newcommand\listxquestionsname{List of Questions}
\newlistof{question}{xquestion}{\listxquestionsname}
\newcommand\qdescription[1]{%
{\protect\makebox[2.5cm][l]{Question~\thexquestion\hfill}#1}}

\newenvironment{question}[1][]{\begin{xquestion}\qdescription{#1}}{\end{xquestion}}

\begin{document}

\listofquestion
\bigskip

\begin{question}[Optional description for question one]
Test question One
\end{question}

\begin{question}
Test question Two
\end{question}

\end{document}


-
Thanks, both answers are nice. The "problem" that I have with your package is that it might introduce new bugs when I include other packages and so on and I don't know what can go wrong in the code. But I will check out the code! Maybe it is quite short. Thanks a lot! –  Jonas Teuwen Jul 19 '12 at 10:20
That might be true. But I must say that in my experience it was mostly easier and less error prone to use a package than to fiddle myself with TeX and LaTeX macros. In particular when dealing with such special purpose packages, bugs and incompatibilities have been astonishingly rare. –  canaaerus Jul 19 '12 at 10:31
Thanks! I have made an implementation which (seems) to work, but maybe I am doing it wrong. –  Jonas Teuwen Jul 19 '12 at 23:54

The following example shows one possible solution using the LaTeX kernel command \@starttoc to produce the new list of questions. The \qdescription command is used to generate an entry in the new list of questions as well as to provide an optional description:

\documentclass{article}
\usepackage{amsthm}

\makeatletter
\newcommand\listquestionsname{List of Questions}
\newcommand\qdescription[1]{%
{\protect\makebox[2.5cm][l]{Question~\thequestion\hfill}#1}}
\newcommand\listofquestions{%
\let\listofquestions\relax % (AM)
\section*{\listquestionsname}\@starttoc{qst}%
}
\newcommand*\l@question{\@dottedtocline{1}{1.5em}{2.3em}}
\makeatother

\newtheorem{question}{Question}

\begin{document}

\listofquestions

\begin{question}
Test question One
\qdescription{Optional description for question one}
\end{question}

\begin{question}
Test question Two
\qdescription{}
\end{question}

\end{document}


-