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.

For one of my documents I use these commands to setup my theorem environments with amsthm:

\usepackage{xcolor}
\usepackage{framed}
\colorlet{shadecolor}{lightgray!25}

\newtheoremstyle{definitionsty}{3pt}{3pt}{\slshape}{}{\bfseries}{.}{.5em}{}
\theoremstyle{definitionsty}
\newtheorem{tdefn}{Definition}[chapter]
\newenvironment{defn}
  {\begin{shaded}\begin{tdefn}}
  {\end{tdefn}\end{shaded}}

Then I am able to define something via \begin{defn}[My Hilarious Definition] blabla\end{defn} and I wanted to include a list, either at the end in the appendix or between the ToC and the first chapter, with the names and numbering of the definitions based on the chapters corresponding to their page, i.e.

Chapter 1 (Kapitel 1 because this is a german document)
    Definition 1.1    - My Hilarious Thing ..........  2
    Definition 1.2    - Another Super Duper Thingy ..  4
...
Chapter 2 (aka. Kapitel 2)
    Definition 2.1    - Math on Crack ............... 27

However I only want the definitions because am I not really able to name all my usual theorems so I have to omit them in this listing.

Can anyone suggest a good snippet on how to create such a list?

share|improve this question

3 Answers 3

up vote 8 down vote accepted

The thmtools package provides for a "List of theorems". However it doesn't provide by default to print "Chapter n" and there's the additional problem that only chapters where a definition is set should appear.

So here it is: I have to patch the command that thmtools uses for annotating a chapter break in the .loe file. Instead of \addvspace{10pt} I make it add more.

In this way, each chapter in the .loe file is surrounded by

\thmlopatch@chapter
...
\thmlopatch@endchapter

and so it's possible to typeset the part represented by ... in a box in order to see if something results. Since we'll call

\listoftheorems[ignoreall,show={tdefn}]

only definitions will survive. If something is in the box, then the contents is retypeset preceded by "Chapter n".

Also the way the optional name is typeset is changed (\thmformatoptarg).

\documentclass[a4paper]{book}
\usepackage{amsthm,thmtools}
\usepackage{xcolor}
\usepackage{framed}
\colorlet{shadecolor}{lightgray!25}

\newtheorem{thm}{Theorem}[chapter]

\newtheoremstyle{definitionsty}{3pt}{3pt}{\slshape}{}{\bfseries}{.}{.5em}{}
\theoremstyle{definitionsty}
\newtheorem{tdefn}{Definition}[chapter]
\newenvironment{defn}
  {\begin{shaded}\begin{tdefn}}
  {\end{tdefn}\end{shaded}}

\usepackage{etoolbox}
\makeatletter
\patchcmd\thmtlo@chaptervspacehack
  {\addtocontents{loe}{\protect\addvspace{10\p@}}}
  {\addtocontents{loe}{\protect\thmlopatch@endchapter\protect\thmlopatch@chapter{\thechapter}}}
  {}{}
\AtEndDocument{\addtocontents{loe}{\protect\thmlopatch@endchapter}}
\long\def\thmlopatch@chapter#1#2\thmlopatch@endchapter{%
  \setbox\z@=\vbox{#2}%
  \ifdim\ht\z@>\z@
    \hbox{\bfseries\chaptername\ #1}\nobreak
    #2
    \addvspace{10\p@}
  \fi
}
\def\thmlopatch@endchapter{}

\makeatother
\renewcommand{\thmtformatoptarg}[1]{ -- #1}
\renewcommand{\listtheoremname}{List of definitions}


\begin{document}

\frontmatter
\listoftheorems[ignoreall,show={tdefn}]

\mainmatter
\chapter{X}

\begin{defn}[My hilarious definition]
bla bla
\end{defn}

\chapter{Y}

\begin{thm}
b
\end{thm}

\chapter{Z}

\begin{defn}[My hilarious definition 2]
bla bla
\end{defn}

\begin{thm}
a
\end{thm}

\end{document}

enter image description here

Note that in chapter 2 there's a theorem and no definition, so it won't be listed in the "list of definitions".


If you want to customize the appearance of the entries in the list, then add

\def\ll@tdefn{%
   \protect\thmtopatch@numbernametext
     \ifx\@empty\thmt@shortoptarg\else[\thmt@shortoptarg]\fi
     {\csname the\thmt@envname\endcsname}%
     {\thmt@thmname}%
}

\newcommand\thmtopatch@numbernametext[3][]{%
    #3 #2%
  \if\relax\detokenize{#1}\relax\else\space -- #1\fi
}

before \makeatother in the code above. This will print

Definition 1.1 – My hilarious definition ........ 1

In the definition of \thmtopatch@numbernametext, #1 stands for the (optional) name ("My hilarious definition"), #2 for the environment's name ("Definition") and #3 for the number.

For an output of the form

1.1 – My hilarious definition ............ 1

you might define

\newcommand\thmtopatch@numbernametext[3][]{%
    #2 -- %
  \if\relax\detokenize{#1}\relax #3\else #1\fi
}

so that a definition without the optional name argument will be printed generically as

3.1 – Definition .................. 42

share|improve this answer
    
This looks very good, however which options do I have to customize the output per line? You have in your example a list fo X.X Definition -- Name, how could get either Definition X.X -- Name or X.X -- Name in this list? –  Christian Ivicevic Oct 1 '12 at 13:08
1  
@ChristianIvicevic This is more complicated. I'll think about it. –  egreg Oct 1 '12 at 13:13

Here's a solution using the ntheorem package and its \listtheorems command. The formatting is not optimal, but you can fix it yourself.

\documentclass{book}
\usepackage{amsmath}
\usepackage[standard,amsmath]{ntheorem}
\numberwithin{Theorem}{chapter}
\numberwithin{Definition}{chapter}

\let\oldchapter\chapter
\def\chapter#1{\oldchapter{#1}\addtotheoremfile[Definition]{\newline
\textbf{Chapter \thechapter \qquad #1}}}

\begin{document}
\chapter{Test}
\begin{Theorem}[False Theorem]
This is not a theorem
\end{Theorem}

\begin{Definition}[A definition]
Something
\end{Definition}

List of theorems:
\listtheorems{Theorem}

List of definitions:
\listtheorems{Definition}
\end{document}

Sample output:

enter image description here

The trick is to

  1. Use \listtheorems{Definition} to only list the Definitions, and not other Theorem environments
  2. Modify the definition of \chapter so that each new chapter will write to the list of definitions an appropriate heading.

You should consult section 2.4 of the ntheorem documentation for more about the usage, and play around with the new \chapter definition to format the chapter headings to your liking.

share|improve this answer
1  
It seems that the OP is using amsthm which is incompatible with ntheorem. –  tohecz Oct 1 '12 at 12:40

Here's a solution using the original amsthm definition for the theorem-like structure, and the LaTeX kernel \@starttoc command; the etoolbox package was used to include the information for the chapters that include definitions in the new list of definitions; only chapters in which there are definitions will be included in this new list.

Definition entries with a note will be listed using the format

Definition <Number> Note ......<page number>

and a generic definition (without using the optional argument for a note) will be listed as:

Definition <Number> ...........<page number>

Here's the code:

\documentclass{book}
\usepackage{amsthm}
\usepackage{etoolbox}
\usepackage{xcolor}
\usepackage{framed}

\colorlet{shadecolor}{lightgray!25}

\newtheoremstyle{definitionsty}{3pt}{3pt}{\slshape}{}{\bfseries}{.}{.5em}{\addcontentsline{lod}{section}{#1~\protect\numberline{#2}{#3}}}
\theoremstyle{definitionsty}
\newtheorem{tdefn}{Definition}[chapter]
\newenvironment{defn}
  {\begin{shaded}\begin{tdefn}}
  {\end{tdefn}\end{shaded}}

\makeatletter
% A command to create the new List of Definitions
\newcommand\listofdefinitions{%
  \chapter*{List Of Definitions}\@starttoc{lod}}

% initial definitions to save the chapter info (name and number)
\def\thischaptertitle{}
\def\thischapternumber{}
\newtoggle{noDefs}

\apptocmd{\@chapter}%
  {\gdef\thischaptertitle{#1}\gdef\thischapternumber{\thechapter}%
    \global\toggletrue{noDefs}}{}{}

% the defn environment does the job: the first time it is used after a \chapter command, 
% it writes the information of the chapter to the LoD
\AtBeginDocument{%
  \AtBeginEnvironment{defn}{%
    \iftoggle{noDefs}{
      \addcontentsline{lod}{chapter}{\chaptername~\thischapternumber\hspace{1em}\thischaptertitle}{}
      \global\togglefalse{noDefs}
    }{}
  }%
}

\makeatother

\begin{document}

\listofdefinitions
\chapter{Test Chapter With Definitions}
\begin{defn}[My Hilarious Thing]
    Definition 1.2    - Another Super Duper Thingy
Test
\end{defn}
\begin{defn}[A Super Duper Thingy]
Test
\end{defn}
\chapter{Test Chapter Without Definitions}
\chapter{Another Test Chapter With Definitions}
\begin{defn}[Another Super Duper Thingy]
Test
\end{defn}
\begin{defn}
Test
\end{defn}

\end{document}

enter image description here

share|improve this answer

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.