/
exercise.tex
197 lines (157 loc) · 5.4 KB
/
exercise.tex
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
% MACROS GENERATING THE GENERAL FLOW OF EXERCISES
% \setlist[itemize]{leftmargin=15pt, labelsep=5pt}
%\usepackage[parfill]{parskip}
% General list of sub-exercises, to be redefined soon...
\newenvironment{exEnum}
{
\begin{enumerate}}
{\end{enumerate}}
% Enumerate list of EQUIVALENT STATEMENTS (!)
\newenvironment{exEnumEquiv}
{
\begin{enumerate}[label={\makebox[1em][c]{{\upshape({\itshape\alph*})}}},ref=({\itshape\alph*})]}
{\end{enumerate}}
% Enumerate list of sub-exercises in the statement of problem
\newenvironment{exEnumStatement}
{
\begin{enumerate}[label={\upshape(\arabic*)},ref=(\arabic*)]}
{\end{enumerate}}
% Enumerate list of sub-exercises in the solution of a problem
\newenvironment{exEnumSolution}
{\mbox{}%
\begin{enumerate}[label=\textbf{\upshape\hyperref[\exRef]{\arabic{exnumber}}$\,$(\arabic*)}\hspace{3pt},ref=\arabic{exnumber}$\,$(\arabic*),%
leftmargin=0pt,%
itemindent=0pt,%
labelsep=0pt,%
align=left,%
listparindent=\parindent, %
parsep=0pt]
% \setlist[itemize]{leftmargin=*,labelsep=5pt}
\setlist[itemize]{leftmargin=\itemizemargin,labelsep=\itemizelabelsep}
% \setlist[itemize]{leftmargin=\itemizemargin,labelsep=5pt}
}
{\qedhere\end{enumerate}}
%macros for manipulation of toc
\newcommand{\nocontentsline}[3]{}
\newcommand{\tocless}[2]{\bgroup\let\addcontentsline=\nocontentsline#1{#2}\egroup}
%usage: \tocless\section{bla} or \tocless\subsection{bla}
%the following solution is taken from https://tex.stackexchange.com/questions/326412/multiple-page-numbers-on-element-of-toc
% the goal is to have two numbers in one row of the table of contents
\renewcommand\thechapter{\arabic{chapter}}
\renewcommand\thesection{\arabic{chapter}.\arabic{section}}
\renewcommand\thesubsection{\arabic{subsection}}
\makeatletter
\renewcommand{\@pnumwidth}{1cm}
\makeatother
\newcommand{\twonumbers}[2]{\hfill\makebox[0em][r]{#1}\makebox[1.2cm][r]{#2}}
\newcommand{\problems}[1]{%
\let\realsection\section%
\let\realchapter\chapter%
\newcommand{\pagebreaksol}{} %% Do nothing in this part.
%\renewcommand\addcontentsline[3]{}%
\renewcommand{\chapter}[1]{%
\cleardoublepage%
\thispagestyle{empty}%
\pdfbookmark[chapter]{##1}{chapter.\thechapter}%
\realchapter{##1}\label{section.\thesection}%
\thispagestyle{empty}%
\label{chapter.\thechapter}%
}%
\renewcommand{\section}[1]{%there is a problem when there is a pagebreak just before the section, then the bookmark points to the previous page
\pdfbookmark[section]{##1}{section.\thesection}%
\realsection{##1}\label{section.\thesection}%
}%
\cleardoublepage%
\thispagestyle{empty}%
\pdfbookmark[part]{#1}{part.\thepart}%
\tocless\part{#1}%
\thispagestyle{empty}%
}
\newcommand{\solutions}[1]{%
\cleardoublepage%
\thispagestyle{empty}%
\pdfbookmark[part]{#1}{part.\thepart}%
\part{#1}%
\thispagestyle{empty}%
\renewcommand{\pagebreaksol}{\pagebreak}
\renewcommand\addcontentsline[3]{}
% todo:
% (1) if ##2 is 'chapter' then the pageref should be to chapter.\thechapter
% (2) \thepage should be a hyperlink
% \addtocontents{##1}{\protect\contentsline{##2}{##3}{\twonumbers{\pageref{section.\thesection}}{\thepage}}{section.\thesection}}%
%}%
\renewcommand{\chapter}[1]{%
\cleardoublepage%
\thispagestyle{empty}%
\pdfbookmark[chapter]{##1}{sol.chapter.\thechapter}%
\realchapter{##1}\label{sol.section.\thesection}%
\thispagestyle{empty}
\label{sol.chapter.\thechapter}%
}%
\renewcommand{\section}[1]{%
\pdfbookmark[section]{##1}{sol.section.\thesection}%
\realsection{##1}\label{sol.section.\thesection}%
}%
%
\renewcommand{\assList}{FALSE}%
\setcounter{chapter}{0}%
}
%%%%%%%%%%%%%%%%%%%%%%%%% end of toc macros
\theoremstyle{definition}
\newcommand{\exRef}{}
\newtheorem{exStatement}{Problem}
\theoremstyle{plain}%
\newtheorem{exSolution}{Problem}
\newcounter{exnumber}
\newcommand{\exercise}[3]{
\ifthenelse{\equal{\assList}{TRUE}}{
\let\exEnum\exEnumStatement%
\let\endexEnum\endexEnumStatement%
\setcounter{exnumber}{\value{exStatement}}%
\stepcounter{exnumber}%
\renewcommand\theexStatement{\hyperref[sol:#1]{\arabic{exnumber}}}%
\renewcommand{\assBody}{TRUE}%
\begin{exStatement}
\label{#1}
#2
\end{exStatement}
\renewcommand{\assBody}{FALSE}%
}{%
\let\exEnum\exEnumStatement%
\let\endexEnum\endexEnumStatement%
\setcounter{exnumber}{\value{exSolution}}%
\stepcounter{exnumber}%
\renewcommand\theexSolution{\hyperref[#1]{\arabic{exnumber}}}%
\renewcommand{\assBody}{TRUE}%
% \begin{mdframed}[%backgroundcolor=lightgray!50,
% innertopmargin = 0pt,
% innerbottommargin = 4pt,
% innerrightmargin = 4pt,
% innerleftmargin = 4pt,
% topline=true,
% bottomline=true,
% rightline=true,
% leftline=true
% ]%
\begin{exSolution}
\label{sol:#1}\vspace{-3pt}
#2%
\end{exSolution}%
% \end{mdframed}
\renewcommand{\assBody}{FALSE}%
\let\exEnum\exEnumSolution%
\let\endexEnum\endexEnumSolution%
\def\exRef{sol:#1}%
\begin{proof}[{\bf Solution}]
#3
\end{proof}
}
}
% (SH) Exercise reference
\newcommand{\exref}[1]{Prob\-lem~\ref{#1}}
\newcommand{\assList}{TRUE}
\newcommand{\assBody}{TRUE}
\newcommand{\secintro}[1]{\ifthenelse{\equal{\assList}{TRUE}}{#1}{}}
\newcommand{\seclabel}[1]{\ifthenelse{\equal{\assList}{TRUE}}{\label{#1}}{\label{#1.sol}}}
\newcommand{\exlabel}[1]{\ifthenelse{\equal{\assList}{TRUE}}{\label{#1}}{}}
\newcommand{\exFootnote}[1]{\ifthenelse{\equal{\assList}{TRUE}}{\footnote{#1}}{\ifthenelse{\equal{\assBody}{FALSE}}{\footnote{#1}}{}}}