summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/xsim/examples/xsim.texsx-350028.tex
blob: f0d977a131e6e0d4db7dc771ab45f76ec646a981 (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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
% http://tex.stackexchange.com/q/350028/
\documentclass{book}
\usepackage[T1]{fontenc}
\usepackage{xsim}
\usepackage[most]{tcolorbox}
\tcbuselibrary{skins,breakable}

\DeclareExerciseEnvironmentTemplate{tcolorbox}{%
  \tcolorbox[
    enhanced,
    colframe=green!20!black,
    colback=yellow!10!white,
    coltitle=green!40!black,
    fonttitle=\bfseries,
    underlay={%
      \begin{tcbclipinterior}
        \shade[
          inner color=\IfInsideSolutionTF{red!50!yellow}{green!80!yellow},
          outer color=yellow!10!white]
          (interior.north west) circle (2cm);
        \draw[help lines,step=5mm,yellow!80!black,shift={(interior.north west)}]
          (interior.south west) grid (interior.north east);
        \end{tcbclipinterior}%
      },
    attach title to upper=\quad,
    title = \XSIMmixedcase{\GetExerciseName}~\GetExerciseProperty{counter}
    \IfExercisePropertySetT{points}{%
      (\GetExerciseProperty{points}
      \IfExerciseGoalSingularTF{points}
        {\XSIMtranslate{point}}
        {\XSIMtranslate{points}})%
    }]%
  \IfInsideSolutionT{\label{solution:\ExerciseID}}%
}{%
  \endtcolorbox
  \vspace*{\baselineskip}
  \IfInsideSolutionTF{%
    \noindent Exercise~\GetExerciseProperty{counter} is on
    page~\GetExerciseProperty{page}.%
  }{%
    \noindent The solution of this exercise is on
    page~\pageref{solution:\ExerciseID}.%
  }%
  \vspace{\baselineskip}
}

\xsimsetup{
  exercise/template = tcolorbox ,
  solution/template = tcolorbox
}

\usepackage{fmtcount,etoolbox}
\newrobustcmd*\mystringnum[2]{\csname#1stringnum\endcsname{#2}}
\renewcommand*\thechapter{\mystringnum{number}{\value{chapter}}}
\renewcommand*\thesection{\arabic{chapter}.\arabic{section}}

% for the header: \MakeUppercase{\mystringnum{number}{1}}
%                 => \mystringnum{NUMBER}{1}
%                 => \NUMBERstringnum{1}
% elsewhere:      \mystringnum{number}{1}
%                 => \numberstringnum{1}

\usepackage{totcount}
\regtotcounter{chapter}

\newcounter{chapters}
\setcounter{chapters}{1}
\newcommand*\printsolutionsperchapter{%
  \whileboolexpr
    { test { \ifnumless {\value{chapters}} {\totvalue{chapter}+1} } }
    {%
      \printsolutions[chapter=\value{chapters},headings-template=per-chapter]
      \stepcounter{chapters}%
    }%
}

\begin{document}

\chapter{The First Chapter}

\begin{exercise}
  Compute the derivative of the following function:
  \begin{equation*}
    f(x) = \sin((\sin x)^2)
  \end{equation*}
\end{exercise}
\begin{solution}
  The derivative is:
  \begin{align*}
    f’(x) &= ( \sin((\sin x)^2) )'
           = \cos((\sin x)^2) \cdot 2\sin x \cos x
  \end{align*}
\end{solution}

\begin{exercise}
  Compute the derivative of the following function:
  \begin{equation*}
    f(x) = \sin((\sin x)^2)
  \end{equation*}
\end{exercise}
\begin{solution}
  The derivative is:
  \begin{align*}
    f’(x) &= ( \sin((\sin x)^2) )'
           = \cos((\sin x)^2) \cdot 2\sin x \cos x
  \end{align*}
\end{solution}

\chapter{The Second Chapter}

\begin{exercise}
  Compute the derivative of the following function:
  \begin{equation*}
    f(x) = (x^2+1) \sqrt{x^4+1}
  \end{equation*}
\end{exercise}
\begin{solution}
  The derivative is:
  \begin{align*}
    f’(x) &= ( (x^2+1) \sqrt{x^4+1} )'
           = 2x\sqrt{x^4+1} + \frac{2x^3(x^2+1)}{\sqrt{x^4+1}}
  \end{align*}
\end{solution}

\clearpage
\section{Solutions of the Exercices}

\printsolutionsperchapter

\end{document}