Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

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

share|improve this answer
    
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
add comment

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}
share|improve this answer
    
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
show 4 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.