TransWikia.com

Add xsim exercises in table of contents

TeX - LaTeX Asked by HelloEdit on April 22, 2021

I wanted to know if it was possible to insert the list of exercises in the table of contents via tableofcontent.

For each of my exercises, I use a template like this:

begin{exercise}[subtitle=title I would like to see in the TOC]

blablabla 

end{exercise}

2 Answers

Yes, you can do this with xsim and tocbasic: here's a working example.

Here's what we need:

  1. Telling the compiler that we want a TOC entry for each exercise, using DeclareTOCStyleEntry;
  2. Declare a new exercise template with DeclareExerciseEnvironmentTemplate (telling xsim that we want to typeset exercises our way).
  3. Add a addxcontentsline{toc}{exercise} command inside the template, where you can specify what to write in that TOC entry.
  4. Access the exercise's subtitle with GetExerciseProperty{subtitle}

Cheers.

Correct answer by J. Brown on April 22, 2021

You have three choices:

  1. redefine the default template,
  2. locally change the definition of subsection* with the halp of environment hooks, or
  3. use the option exercise/heading to choose a suitable command instead of the default subsection*.

Before I show the last and easiest choice there are other considerations to make: if we simply change subsection* to subsection the exercises will get subsection numbers and exercise numbers:

enter image description here

I don't think that this is a satisfying solution. Something like

newcommandaddsubsec[1]{%
  subsection*{#1}%
  addcontentsline{toc}{subsection}{#1}%
}

with xsimsetup{exercise/heading=addsubsec} seems a better solution:

documentclass{article}
usepackage{xsim}

newcommandaddsubsec[1]{%
  subsection*{#1}%
  addcontentsline{toc}{subsection}{#1}%
}

xsimsetup{exercise/heading=addsubsec}    

begin{document}

tableofcontents

section{Exercises}
begin{exercise}
  This is the first problem.
end{exercise}

begin{exercise}[subtitle=Another Problem]
  This is the second problem.
end{exercise}

end{document}

enter image description here

Answered by cgnieder on April 22, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP