# Creating list of for \newtheoremstyle

I want to create an list of theorems much like the list of figures, but couldn't find a packacke or tutorial to solve my problem. I tried this http://texblog.org/2008/07/13/define-your-own-list-of/ but couldn't get it to work :-/

This is "my" theorem style:

\usepackage{amsthm}
\newtheoremstyle{mystyle}
{\topsep}
{\topsep}
{}
{}
{\bfseries}
{:}
{\newline}
{\thmname{#1}\thmnumber{ #2}\thmnote{ (#3)}}
\theoremstyle{mystyle}
\newtheorem{mydef}{Definition}

-

Here's a different approach using the kernel command \@starttoc (entries in the new list as formatted as standard subsections in article, but this can be easily modified):

\documentclass{article}
\usepackage{amsthm}
\usepackage{etoolbox}
\usepackage{lipsum}% just to generate text

\usepackage{amsthm}
\newtheoremstyle{mystyle}
{\topsep}{\topsep}{}{}{\bfseries}{:}{\newline}
{\thmname{#1}\thmnumber{ #2}\thmnote{ (#3)}%
\ifstrempty{#3}%

\theoremstyle{mystyle}
\newtheorem{mydef}{Definition}

\makeatletter
\newcommand\definitionname{Definition}
\newcommand\listdefinitionname{List of Definitions}
\newcommand\listofdefinitions{%
\section*{\listdefinitionname}\@starttoc{def}}
\makeatother

\begin{document}

\listofdefinitions

\begin{mydef}[A note]
\lipsum[2]
\end{mydef}

\begin{mydef}
\lipsum[2]
\end{mydef}

\begin{mydef}
\lipsum[2]
\end{mydef}

\end{document}


-
Thanks! Worked like a charm :) –  distractedBySquirrels Apr 15 '12 at 11:36
I have a follow up question: Is there a way to remove the indent of the list? –  distractedBySquirrels Apr 15 '12 at 11:40
Nevermind... it actually pretty simple. change the parameters of \addcontentsline –  distractedBySquirrels Apr 15 '12 at 11:45

Here's a solution which basically

• adds a contents line to the file \jobname.prb
• reads that file with the command \listmytheorems

I've used the extension .prb simply because I've used in previous work

Custom list of environments (per section)

I've used the etoolbox which provides many commands- the only one relevant to my code is \ifstrempty

\documentclass{article}

\usepackage{amsthm}     % for theorems
\usepackage{lipsum}     % for sample text
\usepackage{etoolbox}   % \ifstrempty (and more)

% enable the \jobname.prb file
% (hacked from the ntheorem package)
\makeatletter%
\def\prb@enablelistofproblems{%
\begingroup%
\if@filesw%
\expandafter\newwrite\csname tf@prb\endcsname%
\immediate\openout \csname tf@prb\endcsname \jobname.prb\relax%
\fi%
\@nobreakfalse%
\endgroup}%

% enable the \jobname.prb files at the end
% of the document
\AtEndDocument{\prb@enablelistofproblems}%
\makeatother%

\def\listmytheorems{%
% open the \jobname.prb and read the contents
\par%
\openin\File=\jobname.prb%
\loop\unless\ifeof\File%
\fileline%
\repeat%
\closein\File%
}%

% your theorem- with some tweaks
\newtheoremstyle{mystyle}
{\topsep}
{\topsep}
{}
{}
{\bfseries}
{:}
{\newline}
{\thmname{#1}\thmnumber{ #2}\thmnote{ (#3)}%
}
\theoremstyle{mystyle}
\newtheorem{mydef}{Definition}

\begin{document}

\subsection*{List of my definitions}
\listmytheorems

\begin{mydef}[description goes here]
\lipsum[1]
\end{mydef}

\begin{mydef}
\lipsum[1]
\end{mydef}

\begin{mydef}
\lipsum[1]
\end{mydef}

\begin{mydef}
\lipsum[1]
\end{mydef}

\begin{mydef}
\lipsum[1]
\end{mydef}

\begin{mydef}
\lipsum[1]
\end{mydef}

\end{document}

-
Could it be possible in case like \begin{mydef}[description goes here] to only have description goes here in the list of definitions ? –  projetmbc Apr 12 '12 at 20:41
@projetmbc: And remove the preceding Description X? –  Werner Apr 12 '12 at 22:42
What is the utility of one list containing Definition 1, Definition 2,... ? On the other hand, I think very usefull to have the list of important definitions and theorems in one course. –  projetmbc Apr 12 '12 at 23:06
@projetmbc yes, change {#1 \themydef~(#3)} to {#3} –  cmhughes Apr 13 '12 at 16:47
Thanks. Indeed, I've changed \ifstrempty{#3}{\addcontentsline{prb}{section}{#1 \themydef}}{\addcontentsline{prb}{section}{#1 \themydef~(#3)}} to \ifstrempty{#3}{}{\addcontentsline{prb}{section}{#3}}. That's perfect ! –  projetmbc Apr 13 '12 at 16:55