0

I'm trying to divide my list of theorems by chapter, similar to what is done in here. I'm using the thmtools package, and I'm quite close of getting it to work. I've used the following code from the link I posted:

\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

The only "problem" with this solution is that I'd like to have the full chapter name, not only the number. How does one modify this code in order to achieve this? I've tried tweaking this code by my-self, but I was not able to get it working.

  • \thmtlo@chaptervspacehack doesn't have access to the chapter name. It is called by every theorem and checks for changes in the chapter counter. The advantage of this approach is that chapters without theorems don't get listed. You also need to hack \@chapter to store the title (#1 short, #2 long) into a global macro. – John Kormylo Oct 26 '21 at 01:44
  • All my chapters actually have theorems, so is there a way to get it working in such case? – Davi Barreira Oct 26 '21 at 14:08

1 Answers1

1

Saves the chapter title into \chaptertitle.

\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} \newcommand{\chaptertitle}{}% reserve global name \makeatletter \patchcmd{@chapter}{\chaptermark{#1}}{\chaptermark{#1}\xdef\chaptertitle{#1}}{}{} \patchcmd\thmtlo@chaptervspacehack {\addtocontents{loe}{\protect\addvspace{10\p@}}} {\addtocontents{loe}{\protect\thmlopatch@endchapter\protect\thmlopatch@chapter{\thechapter~\chaptertitle}}} {}{} \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}


This version adds every chapter, not just the ones with theorems.

\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} \newcommand{\chaptertitle}{}% reserve global name \makeatletter \let\thmtlo@chaptervspacehack\relax \patchcmd{@chapter}{\chaptermark{#1}}{\chaptermark{#1}% \addtocontents{loe}{\par\noindent\textbf{@chapapp~\thechapter~#1}}} {}{} \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}

John Kormylo
  • 79,712
  • 3
  • 50
  • 120