6

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:

enter image description here

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:

enter image description here

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.

11
  • 1
    is your example as minimal as possible?
    – cmhughes
    Commented Jul 23, 2021 at 10:42
  • Where is the activity environment defined? The syntax you are using for it and for the "bookexample" environments suggest that they are defined differently from the other theorem environments, and that they are perhaps defined bypassing thmtools, which would explain why they do not show up in the list of theorems. If you want to use thmtools you should try to redefine those two environments using the thmtools syntax. Commented Jul 23, 2021 at 13:24
  • If you are using thmtools, the \listoftheorems command supports filtering, so you can just list all definitions etc. See section 1.5 of its documentation for details. Commented Jul 23, 2021 at 13:27
  • In regards to "the label not being displayed": you are completely misunderstanding what the \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 the thmtools documentation since it looks like kaobook is using thmtools under the hood. Commented Jul 23, 2021 at 13:30
  • @cmhughes I made the example more minimal. Commented Jul 24, 2021 at 8:56

1 Answer 1

5
+100

lor

kaobook would classify this request as user-customisation.

So basically, you roll your own.

There are various ways.

Here, a KOMA-script version is shown as proof-of-concept, for one item, the remark. All other items will be clones of this method.

A very brief reading of the manual shows that KOMA-script has a handy command, \DeclareNewTOC, which handles all the necessaries for a new TOC list via an environment. Inside this environment, "\caption creates entries for this new content list" (manual, p406).

Here, we will define a non-floating float whose TOC heading will be "List of Remarks" and whose associated ancillary file's extension will be .rmk; the base name for associated commands and environments will be kremark:

\DeclareNewTOC[listname={List of Remarks},
type=kremark,
types=kremarks,
nonfloat,
name=Remark]{rmk}
\setuptoc{rmk}{chapteratlist}

The automatically-created nonfloat environment will be called kremark-.

Inside this environment will be: (1) the mdframed environment with all its formatting (taken more or less from the OP) called mdremark; and (2) a \caption{} command:

\begin{kremark-}%nonfloat float: KOMA
\begin{mdremark}%md
Text of remark
\caption{\emph{Text of caption}}
\end{mdremark}
\end{kremark-}

To save typing, the whole thing can be wrapped inside another environment (called, for want of a better name, myremark) which can take the caption text as a parameter, and the (multi-par) remark text as its body - easy in expl3 syntax:

\ExplSyntaxOn
\NewDocumentEnvironment{myremark}{ m +b }
{
\begin{kremark-}%nonfloat float: KOMA
\begin{mdremark}%md
#2 
\caption{\emph{#1}}
\end{mdremark}
\end{kremark-}
}
{ }
\ExplSyntaxOff

(kaobook already loads xparse, and lots of other packages)

Usage:

\begin{myremark}{title of remark}
Lorem ipsum ... ullamco laboris\sidenote{Colour is from mdframed; inside a KOMA nonfloating float env; inside a wrapper env which supplies the caption, with caption in turn generating the TOC entry.} 
\end{myremark}

Producing:

remark

Without the wrapper, you would have to type a lot of \begin...\ends:

\begin{kremark-}
The \verb|kremark| environment, contains the following:
\begin{mdremark}
The \verb|mdremark| environment, with a caption.
\caption{\emph{A bare remark}}
\end{mdremark}
Note the mdframed's colour and other format settings above.
\end{kremark-}

Output:

manual remark

MWE

\documentclass[
    fontsize=12pt, 
    twoside=false, 
    numbers=noenddot, 
]{kaobook}

\DeclareNewTOC[listname={List of Remarks},
type=kremark,
types=kremarks,
nonfloat,
name=Remark]{rmk}
\setuptoc{rmk}{chapteratlist}

\usepackage{kaotheorems}

\usepackage{xcolor}
\colorlet{lightcyan}{cyan!40}

\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=\myrfont,
    %frametitlefont={},
    frametitlerule=true,
    %linecolor=black,
    %backgroundcolor=LightBlue,
    %fontcolor=black,
    %frametitlebackgroundcolor=LightBlue,
middlelinecolor=red!15,
middlelinewidth=1.5pt,
backgroundcolor=red!2,
roundcorner=10pt,    
}

% 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=xTheorem,
    style=kaoplain,
    refname={theorem,theorems},
    Refname={Theorem,Theorems},
    numberwithin=section,
    mdframed={
        style=mdfkao,
        backgroundcolor=Goldenrod!32,
        frametitlebackgroundcolor=Goldenrod!45,
    },
]{xtheorem}

\declaretheorem[
    name=Proposition,
    refname={proposition,propositions},
    Refname={Proposition,Propositions},
    sibling=theorem,
    mdframed={
        style=mdfkao,
        backgroundcolor=Goldenrod!45!white,
        frametitlebackgroundcolor=Goldenrod!45!white,
    },
]{xproposition}

\declaretheorem[
    name=Lemma,
    refname={lemma,lemmas},
    Refname={Lemma,Lemmas},
    sibling=theorem,
    mdframed={
        style=mdfkao,
        backgroundcolor=Goldenrod!45!white,
        frametitlebackgroundcolor=Goldenrod!45!white,
    },
]{xlemma}

\declaretheorem[
    name=Corollary,
    refname={corollary,corollaries},
    Refname={Corollary,Corollaries},
    sibling=theorem,
    mdframed={
        style=mdfkao,
        backgroundcolor=Goldenrod!45!white,
        frametitlebackgroundcolor=Goldenrod!45!white,
    },
]{xcorollary}

\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,
    },
]{xdefinition}

\theoremstyle{kaoremark}
\declaretheorem[
    name={R},
    refname={remark,remarks},
    Refname={Remark,Remarks},
    numberwithin=section,
    mdframed={
        style=mdfkao,
        backgroundcolor=Goldenrod!12,
        frametitlebackgroundcolor=Goldenrod!45,
    },
]{mdremark}


\ExplSyntaxOn
\NewDocumentEnvironment{myremark}{ m +b }
{
\begin{kremark-}%nonfloat float: KOMA
\begin{mdremark}%md
#2 
\caption{\emph{#1}}
\end{mdremark}
\end{kremark-}
}
{ }
\ExplSyntaxOff



\begin{document}
\tableofcontents
\listofkremarks

\chapter{Chapter C}
\section{Section S}


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.



\begin{myremark}{title of remark}
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\sidenote{Colour is from mdframed; inside a KOMA nonfloating float env; inside a wrapper env which supplies the caption, with caption in turn generating the TOC entry.} 
\end{myremark}

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.

\begin{myremark}{another remark}
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\sidenote{A second remark.} 
\end{myremark}


\begin{kremark-}
The \verb|kremark| environment, contains the following:
\begin{mdremark}
The \verb|mdremark| environment, with a caption.
\caption{\emph{A bare remark}}
\end{mdremark}
Note the mdframed's colour and other format settings above.
\end{kremark-}


\end{document}
7
  • Hi Cicada, thanks for your solution. I am trying to run it but getting some errors. First error: kaotheorems.sty not found. I figured this is supposed to be mdftheorems.sty, is that correct? I changed the name from mdftheorems.sty to kaotheorems.sty and moved it out of the styles folder, which seemed to fix the error. Still getting some other errors though, like LaTeX Error: Float(s) lost. I made a new Overleaf based on your answer: overleaf.com/4146861246sdygfsmhdmvn Commented Jul 29, 2021 at 7:16
  • The github version is different to overleaf setup. I don't know overleaf.
    – Cicada
    Commented Jul 29, 2021 at 7:26
  • I can try to make the Overleaf template more like the version you got from Github. Should I rename mdftheorems.sty to kaotheorems.sty? Or are these supposed to be two separate files? Commented Jul 29, 2021 at 15:15
  • 1
    I created a blank Overleaf at overleaf.com/4146861246sdygfsmhdmvn and pasted your code verbatim into a blank doc and it fails to compile with error kaotheorems.sty not found. But I will award the bounty to you because I appreciate the time and effort you spent. Commented Aug 1, 2021 at 3:43
  • 1
    I was just following the manual instructions of the github kaobook.cls; something similar will be needed for overleaf version, but I don't know overleaf. It could bee overleaf is or is not up-to-date, or adapts kaobook.cls - try asking overleaf about it. Their support is quite good.
    – Cicada
    Commented Aug 1, 2021 at 3:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .