#StackBounty: #exam #exercises #exsheets #exercisebank Any way to separate final Answer and Solution?

Bounty: 50

I am using exam package to typeset few problems along with its solutions.

question Evaluate $int frac{x^{4}}{x^{2}+1} d x$
begin{solution}
Solution: $int frac{mathrm{x}^{4}}{mathrm{x}^{2}+1} mathrm{~d} mathrm{x}=int frac{mathrm{x}^{4}-1+1}{mathrm{x}^{2}+1} mathrm{~d} mathrm{x}$
$$
begin{aligned}
    &=int frac{x^{4}-1}{x^{2}+1}+frac{1}{x^{2}+1} d x \
    &=intleft(x^{2}-1right) d x+int frac{1}{x^{2}+1} d x \
    &=frac{x^{3}}{3}-x+tan ^{-1} x+C
end{aligned}
$$
end{solution}

I want to separate "final answer" from the "solution".

So that I can give a handout containing:

  1. just questions & final answers.
    enter image description here
  2. Or sometimes just the questions (without answers or solutions).
  3. Or sometimes questions and solutions.

I am hoping for something like this:

question question
answer answer %or even begin{answer} end{answer} <-- for final answer
begin{solution}
  solution
end{solution}

Now, I should be able to print just final answers using printanswers (or some command like that) and printing of solutions controlled by printsolutions.

I don’t have any preference for exampackage, I am using it because it has printanswers and nice solution environment. I am open to use any other package.

EDIT: Adding some custom code to any latex packages/classes is also okay. I just need this thing to work. It would be ideal if there is a facility to deferred print the options.


Get this bounty!!!

#StackBounty: #table-of-contents #environments #books #exercises #kaobook List of Definitions, List of Theorems, List of Examples, and …

Bounty: 100

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}{%
  letl@definitionl@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}%
  parnoindenttextbf{The Definition~thedefinition. #1}%
  addcontentsline{def}{figure}
    {protectnumberline{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
tasklabel{correctchoice_1.1.1} Choice 4
end{tasks}

Question Multiple choice question
settasks{label={(Alph*)}}
begin{tasks}(4)
task Choice 1
task Choice 2
tasklabel{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.5topskip,
    skipbelow=.5topskip,
    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~thekaocounterautodot]
}{
    end{kaobox}
}

newcounter{kaocounter}
numberwithin{kaocounter}{section}
newcommand*{kaocounterformat}{% Format for the caption
    Comment~thekaocountercsname autodotendcsname}
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~thefloatingboxcsname autodotendcsname}
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}sffamilybfserieslarge,
            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}sffamilylarge, 
        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}sffamilybfserieslarge,
}

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}sffamilybfserieslarge
}

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}sffamilybfserieslarge,
            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}sffamilylarge, 
        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}sffamilybfserieslarge,
}

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}sffamilybfserieslarge
}

%----------------------------------------------------------------------------------------
%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}{bfseriesarabic{Question}. }
renewcommand{ExerciseName}{EXERCISES}
renewcommand{ExerciseHeader}{noindentdefstackalignment{l}% code from https://tex.stackexchange.com/a/195118/101651
    stackunder[0pt]{colorbox{cyan}{textcolor{white}{textbf{LARGEExerciseHeaderNB;largeExerciseName}}}}{textcolor{lightcyan}{rule{linewidth}{2pt}}}medskip}
renewcommand{AnswerName}{Exercises}
renewcommand{AnswerHeader}{ifthenelse{boolean{firstanswerofthechapter}}%
    {bigskipnoindenttextcolor{cyan}{textbf{CHAPTER thechapter}}newlinenewline%
        noindentbfseriesemph{textcolor{cyan}{AnswerName ExerciseHeaderNB, page %
                pageref{AnswerRef}}}smallskip}
    {noindentbfseriesemph{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

letopenboxrelax
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}%-.5topskip}
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=.5thm@preskip,
    %spacebelow=.5thm@postskip,
    %headfont=normalfontbfseries,%scshape,
    %notefont=normalfont, notebraces={ (}{)},
    bodyfont=normalfontitshape,
    %headformat={NAMEspaceNUMBERspaceNOTE},
    headpunct={},
    %postheadspace={.5em plus .1em minus .1em},
    %prefoothook={hfillqedsymbol}
]{kaoplain}

declaretheoremstyle[
    %spaceabove=.5thm@preskip,
    %spacebelow=.5thm@postskip,
    %headfont=normalfontbfseries,%scshape,
    %notefont=normalfont, notebraces={ (}{)},
    bodyfont=normalfontitshape,
    %headformat={NAMEspaceNUMBERspaceNOTE},
    headpunct={},
    postheadspace={.5em plus .1em minus .1em},
    %prefoothook={hfillqedsymbol}
]{kaodefinition}

declaretheoremstyle[
    %spaceabove=.5thm@preskip,
    %spacebelow=.5thm@postskip,
    %headfont=normalfontbfseries,
    %notefont=normalfont, notebraces={ (}{)},
    %bodyfont=normalfont,
    %headformat={footnotesize$triangleright$spacenormalsizeNAMEspaceNUMBERspaceNOTE},
    %headformat={NAMEspaceNUMBERspaceNOTE},
    headpunct={},
    postheadspace={.5em plus .1em minus .1em},
    %refname={theorem,theorems},
    %Refname={Theorem,Theorems},
]{kaoremark}

declaretheoremstyle[
    %spaceabove=.5thm@preskip,
    %spacebelow=.5thm@postskip,
    %headfont=normalfontbfseries,
    %notefont=normalfont, notebraces={ (}{)},
    %bodyfont=normalfont,
    %headformat={NAMEspaceNUMBERspaceNOTE},
    headpunct={},
    postheadspace={.5em plus .1em minus .1em},
    %prefoothook={hfillqedsymbol}
    %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.


Get this bounty!!!

#StackBounty: #hyperref #lists #exercises Using the Exercise package, how do we get the title of an answer group to match that of the e…

Bounty: 100

%--------------------------------------------------------------------------------------------------------- %
documentclass[english]{book}
%--------------------------------------------------------------------------------------------------------- %
%
usepackage[fleqn]{amsmath} %
usepackage[explicit]{titlesec} %
usepackage{titletoc} %
usepackage{fancyhdr} %
usepackage{fancyref} %
usepackage{babel} %
usepackage{tikz} % tikz - essential
usepackage{newtxtext} %
usepackage{libertine} %
usepackage{setspace} %
usepackage{colortbl} % changed to just colortbl
usepackage{stackengine} %
usepackage[paperwidth=170mm,paperheight=240mm,textwidth=132mm,lmargin=12.5mm,rmargin=12.5mm,bindingoffset=12.5mm,noheadfoot,nomarginpar,showframe,showcrop]{geometry}
usepackage[a4,frame,cam,center]{crop} %
usepackage{stackengine} %
usepackage{graphicx} %
usepackage[skins,theorems,most]{tcolorbox} %
usepackage{ifpdf} %
usepackage{exercise} %
usepackage{ifthen}newboolean{firstanswerofthechapter} %
usepackage{hyperref} %

definecolor{ThemeColor}{rgb}{0.50,0.04,0.04} % ThemeColor DarkRed
definecolor{DarkBlue}{rgb}{0.00,0.08,0.45} % #000086
definecolor{DarkOrange}{rgb}{0.55,0.22,0.05} % #FB9902
definecolor{DarkRed}{rgb}{0.45,0.06,0.06} % #880000
definecolor{LightOrange}{rgb}{1.00,0.87,0.64} % #FB9902
definecolor{LightYellow}{rgb}{1.00,1.00,0.85}

tcbset{myinnerbox/.style={no shadow, shrink tight, arc=1.5pt, extrude by=2.0mm,
colframe=black, boxrule=0.7pt, frame style={opacity=0.25},
interior style={opacity=0.5}, colback=black!5!white}}

%
% ------------------------------------- Exercise preliminaries ------------------------------------------- %
%

makeatletter
let @subQuestionHeader@original=@subQuestionHeader
newcommand{@subQuestionHeader@noItem}{ %
    hspace{0pt} % between (a) and (b)
    begingroup
        @getsubQuestionInfo
        subQuestionHeaderDifficulty
        subQuestionNBhspace{0.4pt} % adjust space from the ) bracket
    endgroup
    begingroup
        @getsubQuestionInfo
        subQuestionHeaderTitle
    endgroup % affects subquestion on new line
    ignorespaces
        }

newcommand{subQuestionOnSameLine}{ %
    let @subQuestionHeader=@subQuestionHeader@noItem
    subQuestion
}
newcommand{subQuestionOnNewLine}{ %
    let @subQuestionHeader=@subQuestionHeader@original {} % \[-9pt]
    subQuestion
}
makeatother

makeatletter
defendExerciseEnv{termineliste{1}@EndExeBoxvspace{6pt}%
vskipExerciseSkipAfter}

gdefendAnswerEnv{termineliste{1}@EndExeBoxvspace{8pt}termineliste{0}vskipAnswerSkipAfter}
makeatother

renewcommand{AtBeginExercise}{vspace{-6pt}}
%
% ----------------------------------------------- Define counters ------------------------------------ %
%
numberwithin{Exercise}{chapter} % ! not counterwithin
numberwithin{Answer}{chapter}
newcounter{problem}[Exercise] %

renewcommand{ExerciseName}{Exercise}
renewcommand{QuestionNB}{tcbhighmath[size=fbox,colframe=DarkRed,colback=blue!12!white]{arabic{Question}}hspace{3.2pt}}
renewcommand{QuestionHeaderTitle}{emph{(QuestionTitle)} }
renewcommand{subQuestionNB}{alph{subQuestion}hspace{0.7pt})hspace{1.3pt}}
renewcommand{ExerciseHeaderTitle}{hspace{2.4pt}-hspace{1.6pt}-hspace{1.6pt}-;ExerciseTitle}
renewcommand{QuestionHeaderDifficulty}{theQuestionDifficulty }


% Setting up the EXERCISES header (conditional)...
renewcommand{ExerciseHeader}
{ifthenelse{boolean{firstanswerofthechapter}} % line 1
%
{newpagenoindenthspace{1.5pt}vspace*{4pt} % line 2

% AAAAAAAAAAAA
{libertineSBfontsize{12}{14}selectfont{text{Exercises based on the content of text{chapterhspace{2.4pt}thechapter}}}} % END OF MAJOR TITLE line 5

vspace{9pt} % BBBBBBBBBBBB
noindentdefstackalignment{l}stackunder[4.5pt]{colorbox{LightOrange} % line 6
{libertineSBfontsize{11.5}{15}selectfont{textcolor{ThemeColor}{Exercise~ExerciseHeaderNB}}}ExerciseHeaderTitlenewlinesmallskip}
{textcolor{DarkOrange}{rule{linewidth}{1.2pt}}}} % ELSE line 7
%
    {noindentdefstackalignment{l}stackunder[4.5pt]{colorbox{LightOrange} % line 8
%
        {libertineSBfontsize{11.5}{15}selectfont{textcolor{ThemeColor} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%   
{Exercise~ExerciseHeaderNB}}}ExerciseHeaderTitlenewlinenewlinesmallskip} % line 9
{textcolor{DarkOrange}{rule{linewidth}{1.2pt}}}}} % line 10



% Setting up the ANSWERS header (conditional)...
renewcommand{AnswerHeader}
{ifthenelse{boolean{firstanswerofthechapter}} % this is correct
%
{newpagenoindenthspace{1.5pt}vspace*{4pt}
% AAAAAAAAAAAA
{libertineSBfontsize{11}{14}selectfont{Answershspace{1.2pt}/hspace{0.1pt}solutions to exercises based on text{chapterhspace{2.4pt}thechapter}}}  % END OF MAJOR TITLE line 5

vspace{9pt} % BBBBBBBBBB
noindentdefstackalignment{l}stackunder[4.5pt]
{colorbox{LightOrange} % continue
{libertineSBfontsize{11}{14}selectfont{textcolor{ThemeColor}
{Answers to exercise~ExerciseHeaderNBhspace{3.4pt}on hspace{0.6pt}phspace{1.5pt}pageref{AnswerRef}
ExerciseHeaderTitle},}}} %
{textcolor{DarkOrange}{rule{linewidth}{1.2pt}}}vspace{3pt}} % ELSE line 7
%
%
{noindentdefstackalignment{l}stackunder[4.5pt]{colorbox{LightOrange} % line 8
%
        {libertineSBfontsize{11}{14}selectfont{textcolor{ThemeColor} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
{Answers to exercise~ExerciseHeaderNBhspace{3.4pt}on hspace{0.6pt}phspace{1.5pt}pageref{AnswerRef}
ExerciseHeaderTitle},}}} %
{textcolor{DarkOrange}{rule{linewidth}{1.2pt}}}vspace{3pt}}}


begin{document}

setstretch{1.20}
chapter{} % Chapter 1

setboolean{firstanswerofthechapter}{true}
begin{Exercise}[title={title of FIRST exercise},label=chap_01_exer_01] % EX 1_1
Question{Question 1}
Question{Question 2}
end{Exercise}

setboolean{firstanswerofthechapter}{false}
begin{Exercise}[title={title of SECOND exercise},label=chap_01_exer_02] % EX 1_2
Question{Question 1}
Question{Question 2}
end{Exercise}

begin{Exercise}[title={title of THIRD exercise},label=chap_01_exer_03] % EX 1_3

Question{Question 1}
Question{Qustion 2}
end{Exercise}

setboolean{firstanswerofthechapter}{true}
begin{Answer}[ref={chap_01_exer_01}]
Question{Answer to question 1}
Question{Answer to question 2}
end{Answer}

vspace{6pt}
noindent {color{DarkBlue}fontsize{11}{12}selectfont{The wordinghspace{0.6pt}: ``,title of THIRD exercise,'' is what I wish to change - it should be the

noindent same as the title description in the corresponding questionhspace{0.7pt}.

vspace{4pt}
noindent It suggests the use of a construction using a ``,hash $1$,'' - but I do not understand that.}}

vspace{15pt}
setboolean{firstanswerofthechapter}{false}
begin{Answer}[ref={chap_01_exer_02}]
Question{Answer to question 1}
Question{Answer to question 2}
end{Answer}

begin{Answer}[ref={chap_01_exer_03}]
Question{Answer to question 1}

Question{Answer to question 2}
end{Answer}

end{document}


Get this bounty!!!