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}

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