6

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}
lockstep
  • 250,273

2 Answers2

5

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

enter image description here

\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%

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

% your theorem- with some tweaks
\newtheoremstyle{mystyle}
  {\topsep}
  {\topsep}
  {}
  {}
  {\bfseries}
  {:}
  {\newline}
  {\thmname{#1}\thmnumber{ #2}\thmnote{ (#3)}%
        \ifstrempty{#3}{\addcontentsline{prb}{section}{#1 \themydef}}{\addcontentsline{prb}{section}{#1 \themydef~(#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}
cmhughes
  • 100,947
5

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}%
      {\addcontentsline{def}{subsection}{#1~\themydef}}%
      {\addcontentsline{def}{subsection}{#1~\themydef~(#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}

enter image description here

Gonzalo Medina
  • 505,128