summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/xsim/examples/xsim.listofexercises.tex
blob: c2a9a3fe362c7637fd4129da9455b43db2ccf162 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
% https://tex.stackexchange.com/q/94766/
\documentclass[a4paper,10pt]{book}
\usepackage[utf8]{inputenc}

\usepackage{xsim}
\xsimsetup{
  exercise/within=chapter,
  exercise/template=theorem ,
  exercise/the-counter=\thechapter.\arabic{exercise}
}

\DeclareExerciseEnvironmentTemplate{theorem}
  {%
    \par\addvspace{\baselineskip}
    \noindent
    \XSIMexpandcode{\noexpand\label{\ExerciseType:\ExerciseID}}
    \Large\textbf{%
      \space\GetExerciseProperty{counter}%
      \GetExercisePropertyT{subtitle}{ (\PropertyValue)}%
    } \normalsize\itshape
  }
  {\par\addvspace{\baselineskip}}

\usepackage{multicol}
  
\newcommand\listofexercises{
  \chapter*{List of Exercises}
  \def\CurrentExerciseChapter{}%
  \ForEachPrintedExerciseByType{
    \global\let\LastExerciseChapter\CurrentExerciseChapter
    \xdef\CurrentExerciseChapter{\ExercisePropertyGet{##1}{##2}{chapter}}%
    \XSIMifeqF{\LastExerciseChapter}{\CurrentExerciseChapter}
      {
        \XSIMifblankF{\LastExerciseChapter}{\end{multicols}}
        \begin{multicols}{2}%
          [\contentsline{chapter}{Chapter \CurrentExerciseChapter}{}{}]
      }
    \contentsline
      {section}
      {%
        Exercise \ExercisePropertyGet{##1}{##2}{counter}%
        \XSIMifblankF{##4}{ (##4)}%
      }
      {\pageref{##1:##2}}{}%
  }
  \end{multicols}
}

% \usepackage{hyperref}
% \newcommand\theHexercise{\thechapter.\arabic{exercise}}

\begin{document}

\chapter{kinetic}
\begin{exercise}
  435-1
\end{exercise}
\begin{exercise}[subtitle=Foo Bar]
  435-2
\end{exercise}
\begin{exercise}
  435-3
\end{exercise}

\chapter{momentum}
\begin{exercise}
  436-1
\end{exercise}
\begin{exercise}
  436-2
\end{exercise}
\begin{exercise}
  436-3
\end{exercise}
\begin{exercise}
  436-4
\end{exercise}

\listofexercises

\end{document}