4

I want to modify the listoftheorems command so that at the end of each chapter, I can give a list of the theorems or definitions within the last chapter, and I want these divided by section (it should look like the ToC with bolded section headers and then theorem/definition listings underneath). I am using amsthm and I want it to look a bit like ToC like list of definitions (using theorem environments) (except with sections instead of chapters, and I want it to be generated at the end of each chapter).

My current setup is,

\documentclass[12pt]{book}

\setcounter{secnumdepth}{5}
\setcounter{tocdepth}{5}

\usepackage{etoolbox}
\usepackage{amsthm,thmtools}

% defining theorem environment
\declaretheorem[
numberwithin = section,
]{theorem}

\declaretheorem[
sibling=theorem,
]{definition}

\begin{document}

\chapter{TEST}

\section{First Section}

\begin{theorem}
This shouldn't be included in the list of theorems from chapter two
\end{theorem}

\chapter{Test}

\section{test}

\begin{definition}[test definition 1]
Test definition
\end{definition}


\begin{theorem}
Best theorem
\end{theorem}

\section{The next section}

\begin{theorem}
Test 2
\end{theorem}

\begin{theorem}
Test 3
\end{theorem}

Now here I want to add a list of the theorems from the last two sections.

\end{document}

I've tried without success to modify the listoftheorems command and adapt solutions from other threads to my need. Any help is much appreciated!

  • Hi, can you complete your code to make a small but complete document, including \documentclass and \begin{document} ... \end{document} with at least a dummy chapter and section.Then it will be easier for people to play with it and help you. – Alan Munn Aug 27 '15 at 23:59
  • Also, your theorem style is not really pertinent to the problem (colour etc.) so you could also simplify the code a bit too. – Alan Munn Aug 28 '15 at 0:17
  • Okay, @AlanMunn I updated the post with a working piece of test code. I at first didn't include a full document because I use a large number of packages and most or all of them probably won't affect the solution, but one previous solution I used interfered with the use of hyperref. – nphirning Aug 28 '15 at 5:43
1

You can do this with etoc.

\documentclass[12pt]{book}

\setcounter{secnumdepth}{5}
\setcounter{tocdepth}{5}

\usepackage{etoolbox}
\usepackage{amsthm,thmtools}

% defining theorem environment
\declaretheorem[
numberwithin = section,
]{theorem}

\declaretheorem[
sibling=theorem,
]{definition}

\usepackage{etoc}
\etocsetlevel{theorem}{6}

\AtEndEnvironment{theorem}{%
  \etoctoccontentsline{theorem}{\protect\numberline{\thetheorem}}%
}%

\makeatletter
\newcommand{\mylocallistoftheorems}[1]{%
  \begingroup
% per lazyness we are going to use the default chapter style for rendering
% sections, but the space for the number is then too short
% use tocloft's commands for easier customization
  \patchcmd{\l@chapter}{1.5em}{2em}{}{}%
  \patchcmd{\l@section}{1.5em}{2em}{}{}%
% make regular subection invisible
  \etocsetlevel{subsection}{6}%
% pretend theorem in TOC is like subsection
  \etocsetlevel{theorem}{2}% subsection
% make section (the top level local to chapter) be rendered in TOC like
% a chapter. Needs etoc 1.08k [2017/09/28] for \etocsavedchaptertocline
% else we can do manually saving \l@chapter before usage
  \etocsetstyle{section}
    {}
    {}
    {\etocsavedchaptertocline{\numberline{\etocnumber}\etocname}{\etocpage}}
    {}%
  \etocsetstyle{theorem}
    {}
    {}
% this will be rendered like a non-numbered section, but we could have used
% \numberline here also
    {\etocsavedsectiontocline{Theorem \etocnumber}{\etocpage}}
    {}%
% not deeper than theorem (= subsection)
% top level is anyhow section, as we are local to a chapter
  \etocsetnexttocdepth{theorem}%
% avoid the global book style which does a \clearpage
  \etocarticlestyle
% self-explanatory
  \renewcommand{\contentsname}{List of theorems of this chapter, per sections}%
% goes in pair with \invisiblelocaltableofcontents\label{foobar}
% right after \chapter command
  \tableofcontents\ref{#1}%
  \endgroup
}

\makeatother

\usepackage{hyperref}


\begin{document}

\tableofcontents

\chapter{TEST}

\section{First Section}

\begin{theorem}
This shouldn't be included in the list of theorems from chapter two
\end{theorem}

\chapter{Test}
\invisiblelocaltableofcontents\label{tocchap2}

\section{test}

\begin{definition}[test definition 1]
Test definition
\end{definition}


\begin{theorem}
Best theorem
\end{theorem}

\section{The next section}

\begin{theorem}
Test 2
\end{theorem}

\begin{theorem}
Test 3
\end{theorem}

Now here I want to add a list of the theorems from the last two sections.

\mylocallistoftheorems{tocchap2}

\end{document}

I have added hyperref for clearer demonstration.

enter image description here

It would be possible using \etoclink to get the hyperref link to theorems include the word Theorem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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