I am looking for a way to automatically create a list of specific theorem environments, like for example a list of all definitions in the document, and found this code in a conversation from tex.stackexchange (https://tex.stackexchange.com/questions ... vironments) from 12 years ago:
Code: Select all
\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}
Another thing I don't get right is the from "egreg" proposed costumization of creating the output "Definition X.X -- Name" instead of "X.X Definition -- Name".
I'm just not able to understand this complicated code and it would be really nice, if someone could help me get it right

Thanks in advance