This is somewhat a follow-up to this question about custom Kaobook environments. In that question, I was able to successfully define some new environments for the kaobook
class and have them all share numbering:
Goal
I would like to issue commands::
\listofdefinitions
\listoftheorems
\listofexamples
\listofactivities
to automatically generate lists in the table of contents, similar to the existing commands
\tableofcontents
\listoffigures
\listoftables
.
Some things I tried:
1.) Following this answer, I tried
\makeatletter
\renewcommand{\listofdefinitions}{%
\let\l@definition\l@figure
\chapter*{\listdefinitionname}%
\@starttoc{loa}%
}
\makeatother
but this did not work and issued an error.
2.) Following this answer, I also tried
\newcommand{\listdefinitionname}{My list of definitions}
\newlistof{definition}{def}{\listdefinitionname}
\newcommand{\definition}[1]{%
\refstepcounter{definition}%
\par\noindent\textbf{The Definition~\thedefinition. #1}%
\addcontentsline{def}{figure}
{\protect\numberline{\thechapter.\thedefinition}#1}\par%
}
\makeatletter
but this also issued an error, saying definition
is already defined.
3.) I read that the thmtools
package has a \listoftheorems
command, which I tried to use, but it lists everything together under the same heading:
As you can see, there are a few problems:
- Definitions and Theorems are grouped together - I would like separate lists for each environment type
- Activities and Examples are missing (?)
- The "label" of each definition, theorem, etc. is not displayed.
- The end-of-section
exercises
are showing in the list.
Any ideas how to fix these problems? If it helps, here is a link to the Overleaf project. Feel free to play around with the code.
main.tex
\documentclass[
fontsize=10pt, % Base font size
twoside=false, % Use different layouts for even and odd pages (in particular, if twoside=true, the margin column will be always on the outside)
%open=any, % If twoside=true, uncomment this to force new chapters to start on any page, not only on right (odd) pages
%chapterprefix=true, % Uncomment to use the word "Chapter" before chapter numbers everywhere they appear
%chapterentrydots=true, % Uncomment to output dots from the chapter name to the page number in the table of contents
numbers=noenddot, % Comment to output dots after chapter numbers; the most common values for this option are: enddot, noenddot and auto (see the KOMAScript documentation for an in-depth explanation)
%draft=true, % If uncommented, rulers will be added in the header and footer
%overfullrule=true, % If uncommented, overly long lines will be marked by a black box; useful for correcting spacing problems
]{kaobook}
% Set the language
\usepackage[english]{babel} % Load characters and hyphenation
\usepackage[english=british]{csquotes} % English quotes
% Load mathematical packages for theorems and related environments. NOTE: choose only one between 'mdftheorems' and 'plaintheorems'.
\usepackage{styles/mdftheorems}
%\usepackage{styles/plaintheorems}
%https://tex.stackexchange.com/questions/369265/math-book-how-to-write-exercise-and-answers
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{multicol}
\usepackage{xcolor}
\colorlet{lightcyan}{cyan!40!white}
\usepackage{etoolbox}
\usepackage[T1]{fontenc}
\usepackage[skins,hooks,xparse,breakable]{tcolorbox}
\usepackage{xcolor}
\usepackage{chngcntr}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\tableofcontents
\listoftheorems
\chapter{Chapter Name}
\section{Section}
\begin{activity}[Name of Activity 1][activity:activityname]
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
\end{activity}
\begin{definition}\labdef{Name of Definition 2}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
\end{definition}
\begin{theorem}\label{Name of Theorem 3}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
\end{theorem}
\begin{bookexample}[Name of Example 3][ex:example_4]
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
\end{bookexample}
Referring to Example \ref{ex:example_4}.
\begin{solution}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
\end{solution}
\begin{definition} \labdef{Name of Definition 5}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
\end{definition}
\begin{theorem} \label{Name of Theorem 6}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
\end{theorem}
\begin{bookexample}[Name of Example 7][ex:example_7]
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
\end{bookexample}
\begin{solution}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
\end{solution}
\newpage
\begin{Exercise}\label{EX11}
\vspace{-\baselineskip}% <-- You don't need this line of code if there's some text here
\Question Multiple choice question
\settasks{label={(\Alph*)}}
\begin{tasks}(4)
\task Choice 1
\task Choice 2
\task Choice 3
\task\label{correctchoice_1.1.1} Choice 4
\end{tasks}
\Question Multiple choice question
\settasks{label={(\Alph*)}}
\begin{tasks}(4)
\task Choice 1
\task Choice 2
\task\label{correctchoice_1.1.2} Choice 3
\task Choice 4
\end{tasks}
\Question Multi-part question
\settasks{label={\roman*.}}
\begin{tasks}(1)
\task Part 1
\task Part 2
\task Part 3
\end{tasks}
\end{Exercise}
\begin{Answer}[ref={EX11}]
\Question This is a solution of Ex 1
\end{Answer}
\setboolean{firstanswerofthechapter}{false}
\end{document}
Edit 7/24:
Now also including environments.sty
and mdftheorems.sty
, where some of the kaobox environments are defined. (Sorry, I am new to this Overleaf Kaobook template and didn't know it had these dependencies spread across multiple files.) I do not know how these 2 files work, so I am going to paste them as-is.
environments.sty
%% environments.sty
%% Copyright 2020 Federico Marotta
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
% http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
%
% The Current Maintainer of this work is Federico Marotta
%
% This work consists of all the files listed in MANIFEST.md.
\ProvidesPackage{styles/environments}
%----------------------------------------------------------------------------------------
% ITEMS
%----------------------------------------------------------------------------------------
\RequirePackage{amssymb}
\renewcommand{\labelitemi}{\small$\blacktriangleright$}
\renewcommand{\labelitemii}{\textbullet}
\RequirePackage{enumitem}
\setlist[itemize]{noitemsep}
\setlist[enumerate]{noitemsep}
\setlist[description]{noitemsep}
%----------------------------------------------------------------------------------------
% SIMPLE BOXED ENVIRONMENT
%----------------------------------------------------------------------------------------
% kaobox (while tcolorbox may be more rich, I find it too complicated so I prefer mdframed)
\RequirePackage{tikz}
\RequirePackage[framemethod=TikZ]{mdframed}
%\mdfsetup{skipabove=\topskip,skipbelow=0pt}
\mdfdefinestyle{kaoboxstyle}{
skipabove=1.5\topskip,
skipbelow=.5\topskip,
rightmargin=0pt,
leftmargin=0pt,
%innertopmargin=3pt,
%innerbottommargin=3pt,
innerrightmargin=7pt,
innerleftmargin=7pt,
topline=false,
bottomline=false,
rightline=false,
leftline=false,
%linewidth=1pt,
%roundcorner=0pt,
%font={},
%frametitlefont={},
frametitlerule=true,
linecolor=black,
%backgroundcolor=LightBlue,
fontcolor=black,
%frametitlebackgroundcolor=LightBlue,
}
\newmdenv[
style=kaoboxstyle,
backgroundcolor=RoyalBlue!20!White,
frametitlebackgroundcolor=RoyalBlue!20!White,
]{kaobox}
\newmdenv[
style=kaoboxstyle,
backgroundcolor=Cyan!15!White,
frametitlebackgroundcolor=Cyan!15!White,
]{objective}
\newmdenv[
style=kaoboxstyle,
backgroundcolor=Green!15!White,
frametitlebackgroundcolor=Green!15!White,
frametitle=Solution,
]{solution}
\newmdenv[
style=kaoboxstyle,
backgroundcolor=Gray!15!White,
frametitlebackgroundcolor=Gray!15!White,
frametitle=Proof,
]{kaoproof}
\newmdenv[
style=kaoboxstyle,
backgroundcolor=Magenta!15!White,
frametitlebackgroundcolor=Magenta!15!White,
]{note}
\newmdenv[
style=kaoboxstyle,
backgroundcolor=Purple!15!White,
frametitlebackgroundcolor=Purple!15!White,
frametitle=Summary
]{summary}
%----------------------------------------------------------------------------------------
% ENVIRONMENT WITH A COUNTER
%----------------------------------------------------------------------------------------
\newenvironment{kaocounter}{
\refstepcounter{kaocounter}
\begin{kaobox}[frametitle=Comment~\thekaocounter\autodot]
}{
\end{kaobox}
}
\newcounter{kaocounter}
\numberwithin{kaocounter}{section}
\newcommand*{\kaocounterformat}{% Format for the caption
Comment~\thekaocounter\csname autodot\endcsname}
\newcommand*{\fnum@kaocounter}{\kaocounterformat}
%----------------------------------------------------------------------------------------
% FLOATING ENVIRONMENT WITH TOC ENTRIES
%----------------------------------------------------------------------------------------
\newenvironment{kaofloating}{%
\@float{kaofloating}%
}{%
\end@float%
}
\newcommand*{\fps@floatingbox}{tbph}
\newcommand*{\ftype@floatingbox}{5}
\newcommand*{\floatingboxformat}{%
Insight~\thefloatingbox\csname autodot\endcsname}
\newcommand*{\fnum@floatingbox}{\floatingboxformat}
\newcommand*{\ext@floatingbox}{loi}
\addtotoclist[float]{loi}
\newcommand*{\listofloiname}{List of Insights}
\newcommand*{\l@floatingbox}{\l@figure}
\newcommand*{\listofinsights}{\listoftoc{loi}}
%----------------------------------------------------------------------------------------
% https://tex.stackexchange.com/questions/603869/custom-example-environment-with-colorbox-and-vertical-line-for-kaobook-documen
%----------------------------------------------------------------------------------------
\usepackage[skins,hooks,xparse,breakable]{tcolorbox}
\usepackage[table]{xcolor}
\usepackage{chngcntr}
% comment this line during integration because kaocounter would have been declared
%\newcounter{kaocounter}
% you may not need the line below as well if it has already been configured using other approaches
\counterwithin{kaocounter}{section}
\definecolor{greentitle}{RGB}{61,170,61}
\definecolor{greentitleback}{RGB}{216,233,213}
\definecolor{drakgreentitle}{RGB}{24,131,80}
\DeclareTColorBox{bookexample}{O{}o}{
enhanced,
breakable,
arc=0pt,
boxrule=0pt,
colframe=white,
colback=white,
top=3em, % you can change the top spacing
overlay unbroken and first={
% draw box on the left
\node[fill=greentitleback,
font=\color{greentitle}\sffamily\bfseries\large,
anchor=south west,
inner sep=3pt,
left=2mm,
right=2mm,
xshift=1mm,
yshift=-2em, % you can change xshift and yshift to adjust the title placement
] (titlebox) at (frame.north west)
% notice the difference here, kaocounter is used instead
{Example \refstepcounter{theorem}\thetheorem
% add cross-referencing support
\IfValueT{#2}{\label{#2}}
};
% write title on the right
\node[font=\color{drakgreentitle}\sffamily\large,
anchor=west
] at ($(titlebox.east)+(2mm,0mm)$) {#1};
% draw the vertical line on the left
\draw[draw=greentitleback, line width=2pt]
(titlebox.north west-|frame.north west)--(frame.south west);
},
overlay middle and last={
\draw[draw=greentitleback, line width=2pt]
(frame.north west)--(frame.south west);
}
fonttitle=\color{greentitle}\sffamily\bfseries\large,
}
\DeclareTColorBox{genericbox}{m}{
enhanced,
breakable,
arc=0pt,
boxrule=0pt,
colback=white,
attach boxed title to top left,
boxed title style={
colback=white,
colframe=white,
},
title={#1},
fonttitle=\color{greentitle}\sffamily\bfseries\large
}
\DeclareTColorBox{activity}{O{}o}{
enhanced,
breakable,
arc=0pt,
boxrule=0pt,
colframe=white,
colback=white,
top=3em, % you can change the top spacing
overlay unbroken and first={
% draw box on the left
\node[fill=Cyan!15!White,
font=\color{Cyan}\sffamily\bfseries\large,
anchor=south west,
inner sep=3pt,
left=2mm,
right=2mm,
xshift=1mm,
yshift=-2em, % you can change xshift and yshift to adjust the title placement
] (titlebox) at (frame.north west)
% notice the difference here, kaocounter is used instead
{Activity \refstepcounter{theorem}\thetheorem
% add cross-referencing support
\IfValueT{#2}{\label{#2}}
};
% write title on the right
\node[font=\color{Cyan}\sffamily\large,
anchor=west
] at ($(titlebox.east)+(2mm,0mm)$) {#1};
% draw the vertical line on the left
\draw[draw=Cyan!15!White, line width=2pt]
(titlebox.north west-|frame.north west)--(frame.south west);
},
overlay middle and last={
\draw[draw=Cyan!15!White, line width=2pt]
(frame.north west)--(frame.south west);
}
fonttitle=\color{Cyan}\sffamily\bfseries\large,
}
\DeclareTColorBox{genericbox}{m}{
enhanced,
breakable,
arc=0pt,
boxrule=0pt,
colback=white,
attach boxed title to top left,
boxed title style={
colback=white,
colframe=white,
},
title={#1},
fonttitle=\color{greentitle}\sffamily\bfseries\large
}
%----------------------------------------------------------------------------------------
%https://tex.stackexchange.com/questions/369265/math-book-how-to-write-exercise-and-answers
%----------------------------------------------------------------------------------------
\usepackage{ifthen}
\newboolean{firstanswerofthechapter}
\usepackage{chngcntr}
\usepackage{stackengine}
\usepackage{tasks}
\newlength{\longestlabel}
\settowidth{\longestlabel}{\bfseries viii.}
\settasks{label={(\Alph*)}, label-format={\bfseries}, label-width=\longestlabel,
item-indent=20pt, label-offset=2pt, column-sep={10pt}}
\usepackage[lastexercise,answerdelayed]{exercise}
\counterwithin{Exercise}{chapter}
\counterwithin{Answer}{chapter}
\renewcounter{Exercise}[chapter]
\newcommand{\QuestionNB}{\bfseries\arabic{Question}.\ }
\renewcommand{\ExerciseName}{EXERCISES}
\renewcommand{\ExerciseHeader}{\noindent\def\stackalignment{l}% code from https://tex.stackexchange.com/a/195118/101651
\stackunder[0pt]{\colorbox{cyan}{\textcolor{white}{\textbf{\LARGE\ExerciseHeaderNB\;\large\ExerciseName}}}}{\textcolor{lightcyan}{\rule{\linewidth}{2pt}}}\medskip}
\renewcommand{\AnswerName}{Exercises}
\renewcommand{\AnswerHeader}{\ifthenelse{\boolean{firstanswerofthechapter}}%
{\bigskip\noindent\textcolor{cyan}{\textbf{CHAPTER \thechapter}}\newline\newline%
\noindent\bfseries\emph{\textcolor{cyan}{\AnswerName\ \ExerciseHeaderNB, page %
\pageref{\AnswerRef}}}\smallskip}
{\noindent\bfseries\emph{\textcolor{cyan}{\AnswerName\ \ExerciseHeaderNB, page \pageref{\AnswerRef}}}\smallskip}}
\setlength{\QuestionIndent}{16pt}
mdftheorems.sty
%% mdftheorems.sty
%% Copyright 2020 Federico Marotta
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
% http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
%
% The Current Maintainer of this work is Federico Marotta
%
% This work consists of all the files listed in MANIFEST.md.
\ProvidesPackage{styles/mdftheorems}
% Use mdframed to shade the background of theorems
\let\openbox\relax
\usepackage{amsmath} % Improved mathematics
\usepackage{amsfonts} % Mathematical fonts
\usepackage{amssymb} % AMS symbols and environments
\usepackage{amsthm} % Mathematical environments
\usepackage{thmtools}
\usepackage{tikz}
\usepackage[framemethod=TikZ]{mdframed}
% Box style
\mdfsetup{skipabove=\topskip,skipbelow=0pt}%-.5\topskip}
\mdfdefinestyle{mdfkao}{
skipabove=\topskip,
skipbelow=\topskip, % Does not work :(
rightmargin=0pt,
leftmargin=0pt,
innertopmargin=7pt,
innerbottommargin=3pt,
innerrightmargin=5pt,
innerleftmargin=5pt,
topline=false,
bottomline=false,
rightline=false,
leftline=false,
%linewidth=1pt,
%roundcorner=0pt,
%font={},
%frametitlefont={},
frametitlerule=true,
%linecolor=black,
%backgroundcolor=LightBlue,
%fontcolor=black,
%frametitlebackgroundcolor=LightBlue,
}
% Theorem styles
\declaretheoremstyle[
%spaceabove=.5\thm@preskip,
%spacebelow=.5\thm@postskip,
%headfont=\normalfont\bfseries,%\scshape,
%notefont=\normalfont, notebraces={ (}{)},
bodyfont=\normalfont\itshape,
%headformat={\NAME\space\NUMBER\space\NOTE},
headpunct={},
%postheadspace={.5em plus .1em minus .1em},
%prefoothook={\hfill\qedsymbol}
]{kaoplain}
\declaretheoremstyle[
%spaceabove=.5\thm@preskip,
%spacebelow=.5\thm@postskip,
%headfont=\normalfont\bfseries,%\scshape,
%notefont=\normalfont, notebraces={ (}{)},
bodyfont=\normalfont\itshape,
%headformat={\NAME\space\NUMBER\space\NOTE},
headpunct={},
postheadspace={.5em plus .1em minus .1em},
%prefoothook={\hfill\qedsymbol}
]{kaodefinition}
\declaretheoremstyle[
%spaceabove=.5\thm@preskip,
%spacebelow=.5\thm@postskip,
%headfont=\normalfont\bfseries,
%notefont=\normalfont, notebraces={ (}{)},
%bodyfont=\normalfont,
%headformat={\footnotesize$\triangleright$\space\normalsize\NAME\space\NUMBER\space\NOTE},
%headformat={\NAME\space\NUMBER\space\NOTE},
headpunct={},
postheadspace={.5em plus .1em minus .1em},
%refname={theorem,theorems},
%Refname={Theorem,Theorems},
]{kaoremark}
\declaretheoremstyle[
%spaceabove=.5\thm@preskip,
%spacebelow=.5\thm@postskip,
%headfont=\normalfont\bfseries,
%notefont=\normalfont, notebraces={ (}{)},
%bodyfont=\normalfont,
%headformat={\NAME\space\NUMBER\space\NOTE},
headpunct={},
postheadspace={.5em plus .1em minus .1em},
%prefoothook={\hfill\qedsymbol}
%refname={theorem,theorems},
%Refname={Theorem,Theorems},
]{kaoexample}
\theoremstyle{kaoplain}
\declaretheorem[
name=Theorem,
style=kaoplain,
refname={theorem,theorems},
Refname={Theorem,Theorems},
numberwithin=section,
mdframed={
style=mdfkao,
backgroundcolor=Goldenrod!45!white,
frametitlebackgroundcolor=Goldenrod!45!white,
},
]{theorem}
\declaretheorem[
name=Proposition,
refname={proposition,propositions},
Refname={Proposition,Propositions},
sibling=theorem,
mdframed={
style=mdfkao,
backgroundcolor=Goldenrod!45!white,
frametitlebackgroundcolor=Goldenrod!45!white,
},
]{proposition}
\declaretheorem[
name=Lemma,
refname={lemma,lemmas},
Refname={Lemma,Lemmas},
sibling=theorem,
mdframed={
style=mdfkao,
backgroundcolor=Goldenrod!45!white,
frametitlebackgroundcolor=Goldenrod!45!white,
},
]{lemma}
\declaretheorem[
name=Corollary,
refname={corollary,corollaries},
Refname={Corollary,Corollaries},
sibling=theorem,
mdframed={
style=mdfkao,
backgroundcolor=Goldenrod!45!white,
frametitlebackgroundcolor=Goldenrod!45!white,
},
]{corollary}
\theoremstyle{kaodefinition}
\declaretheorem[
name=Definition,
refname={definition,definitions},
Refname={Definition,Definitions},
%numberwithin=section,
sibling=theorem,
mdframed={
style=mdfkao,
backgroundcolor=Goldenrod!45!white,
frametitlebackgroundcolor=Goldenrod!45!white,
},
]{definition}
\theoremstyle{kaoremark}
\declaretheorem[
name=Remark,
refname={remark,remarks},
Refname={Remark,Remarks},
numberwithin=section,
mdframed={
style=mdfkao,
backgroundcolor=Goldenrod!45!white,
frametitlebackgroundcolor=Goldenrod!45!white,
},
]{remark}
\theoremstyle{kaoexample}
\declaretheorem[
name=Example,
refname={example,examples},
Refname={Example,Examples},
numberwithin=section,
mdframed={
style=mdfkao,
backgroundcolor=Goldenrod!45!white,
frametitlebackgroundcolor=Goldenrod!45!white,
},
]{example}
%\renewcommand{\thetheorem}{\arabic{chapter}.\arabic{section}.\arabic{theorem}}
%\renewcommand{\thetheorem}{\arabic{subsection}.\arabic{theorem}}
%\renewcommand{\qedsymbol}{$\blacksquare$}
Edit 7/25: Here is a link to kaobook.cls
file for those who need it (thanks @cmhughes!) and the link to the Overleaf project, in case it helps.
thmtools
, which would explain why they do not show up in the list of theorems. If you want to usethmtools
you should try to redefine those two environments using thethmtools
syntax.thmtools
, the\listoftheorems
command supports filtering, so you can just list all definitions etc. See section 1.5 of its documentation for details.\label
command does. It is for cross referencing. If you want to have "named" theorems, you can pass it as an optional argument to the theorem environments. Again, please look at thethmtools
documentation since it looks likekaobook
is usingthmtools
under the hood.