-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexamstyle.sty
344 lines (243 loc) · 8.38 KB
/
examstyle.sty
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesPackage{examstyle}[2018/11/13 Custom Package]
%%%% AUTHOR: Jan Suchanek
\RequirePackage{pgf,tikz}
\usetikzlibrary{calc}
\RequirePackage{framed}
\RequirePackage{soul}
% for crossed-out text
\RequirePackage{color}
\RequirePackage{float}
\RequirePackage{flowfram} % for the answer box
\RequirePackage{environ} % for switching on and off answers
\RequirePackage{gensymb} % for degree sign
\RequirePackage{amssymb} % for tickbox
\RequirePackage{titletoc} % to display points in toc
\RequirePackage{tocloft} % for toc nicety
\renewcommand{\cftsecleader}{} % to make points flushright in toc
\renewcommand{\cftsubsecleader}{} % to make points flushright in toc
\renewcommand{\cftsubsubsecleader}{} % to make points flushright in toc
\RequirePackage{appendix} % for the subtotal environment
\RequirePackage{chngcntr} % for the subtotal environment
\RequirePackage{etoolbox} % for the subtotal environment
\RequirePackage{amsfonts} % for mathematics formula
\RequirePackage{amstext} % for mathematics formula
\RequirePackage{amsmath} % for mathematics formula
\RequirePackage{graphicx} % for inserting graphics
\RequirePackage{verbatim} % for adding multi-line comments
\RequirePackage{iflang} % to allow for German Lösung
%% CONDITIONALS
\newif\ifshowanswers
%% OPTIONS are 'mm', cm', 'in' or 'newpage' for white space per point:
\newcommand{\unit}{cm}%
\newcommand*{\pointspace}{}%
\newcommand{\writespace}{}%
\def\DisplayMarked{}% Comment this to remove "...marked text..."
%% 'whitespace' option mm
\DeclareOption{mm}{%
\renewcommand{\unit}{mm}%
\renewcommand*{\pointspace}{}%
\renewcommand{\writespace}{\vspace*{\dimexpr\pointspace \unit}}%
}
%% 'whitespace' option cm
\DeclareOption{cm}{%
\renewcommand{\unit}{cm}%
\renewcommand*{\pointspace}{}%
\renewcommand{\writespace}{\vspace*{\dimexpr\pointspace \unit}}%
}
%% 'whitespace' option in
\DeclareOption{in}{%
\renewcommand{\unit}{in}%
\renewcommand*{\pointspace}{}%
\renewcommand{\writespace}{\vspace*{\dimexpr\pointspace \unit}}%
}
%% 'whitespace' option newpage: force cm space then break page
\DeclareOption{newpage}{%
\renewcommand{\unit}{cm}%
\renewcommand*{\pointspace}{}%
\renewcommand{\writespace}{\vspace*{\dimexpr\pointspace \unit}\newpage}%
}
%% OPTION 'showanswers' for un-commenting.
\DeclareOption{showanswers}{%
\showanswerstrue
\renewcommand{\writespace}{}%
}
% Default is cm
\ExecuteOptions{cm}
\ProcessOptions\relax
% if you need more space, create it in the question environment itself using \vspace.
%% COUNTERS
% defines the counters
\newcounter{totalpoints}
\newcounter{subtotalpoints}[totalpoints]
\newcounter{points}[subtotalpoints]
\newcounter{subpoints}[points]
%% COMMANDS
% defines the command pagealert which creates a dashed frame around a page;
\newcommand{\pagealert}{
\ifshowanswers
\begin{tikzpicture}[remember picture, overlay]
\draw[loosely dashed,line width = 25pt] ($(current page.north west) + (0.1in,-0.1in)$) rectangle ($(current page.south east) + (-0.1in,0.1in)$);
\end{tikzpicture}
\else\fi
}
% defines the command quickanswer which is a command;
\newcommand{\quickanswer}[1]{\ifshowanswers#1\else\fi}
%% Gives out check box; ticktrue is given out ticked in the showanswers mode
\newcommand{\ticktrue}{
\ifshowanswers
\hspace{2ex}$\boxtimes$\hspace{1ex}
\else
\hspace{2ex}$\square$\hspace{1ex}
\fi%
}
\newcommand{\tickfalse}{
\hspace{2ex}$\square$\hspace{1ex}
}
%%% The same within a list environment.
\newcommand{\itemtrue}{
\ifshowanswers
\renewcommand\labelitemi{$\boxtimes$}\item
\else
\renewcommand\labelitemi{$\square$}\item
\fi%
}
\newcommand{\itemfalse}{
\renewcommand\labelitemi{$\square$}\item
}
% defines the command resetsubtotal to be used at the end of each part. It resets the counter for subtotal
\newcommand{\resetsubtotal}{%
\setcounter{subtotalpoints}{0}%
}
% defines the command givetotalpoints for the sum to be used at the end of the exam. It prints the total points at the end
\newcommand{\givetotalpoints}%
{%
\newpage\parbox{\textwidth}{%
\noindent%
\hrulefill%
\section*{\IfLanguageName{ngerman}{Punkte insgesamt: }{Total Points: } \hfill \arabic{totalpoints} points}
% \section*{Total Points Scored: }
\hrulefill%
}
\titlecontents{section}[2em]%
{\addvspace{1.0em plus 1pt}\bfseries}%
{\contentslabel{2em}}%
{\hspace*{-2em}}%
{}%
\addcontentsline{toc}{section}{\hfill (\IfLanguageName{ngerman}{Summe: }{Total: } \arabic{totalpoints} pt)}
}
% defines the command subtotal of a part; resets the subtotal when called
\newcommand{\subtotal}{%
\section*{Subtotal: \arabic{subtotalpoints} points}
\addcontentsline{toc}{section}{\hfill (\IfLanguageName{ngerman}{Zwischensumme: }{Subtotal: } \arabic{subtotalpoints} pt)}
\setcounter{subtotalpoints}{0} %% RESETS
}
%% ENVIRONMENTS
% defines the environment question using the command \writespace
\NewEnviron{question}[2]{%
\setcounter{subpoints}{#2}
\renewcommand*{\pointspace}{#2}%
\section{#1 \hfill (#2 pt)}%
\addtocounter{subtotalpoints}{#2}%
\addtocounter{totalpoints}{#2}%
\parbox{\textwidth}{\BODY\writespace}%
\ifnum\value{subpoints}=\pointspace
\else
\par\noindent\colorbox{red}{\parbox{\textwidth}{MISMATCH! You should not use the environment question for questions with subquestions; use question* instead! }}
\fi
}
% defines the environment question* without \writespace; use this when you include subquestions in your question environment, because these carry their own whitespace.
\newenvironment{question*}[2]{%
\setcounter{subpoints}{0}
\renewcommand*{\pointspace}{#2}%
\section{#1 \hfill (#2 pt)}%
\addtocounter{subtotalpoints}{#2}%
\addtocounter{totalpoints}{#2}%
}%
{%
\ifnum\value{subpoints}=\pointspace
\else
\par\noindent\colorbox{red}{\parbox{\textwidth}{MISMATCH! Subquestions have together \arabic{subpoints} points, but the overall question bears \pointspace\quad points!}}
\fi
}
%%% Exactly the same as question* so that question* becomes deprecaded.
\newenvironment{metaquestion}[2]{%
\setcounter{subpoints}{0}
\renewcommand*{\pointspace}{#2}%
\section{#1 \hfill (#2 pt)}%
\addtocounter{subtotalpoints}{#2}%
\addtocounter{totalpoints}{#2}%
}%
{%
\ifnum\value{subpoints}=\pointspace
\else
\par\noindent\colorbox{red}{\parbox{\textwidth}{MISMATCH! Subquestions have together \arabic{subpoints} points, but the overall question bears \pointspace\quad points!}}
\fi
}
% defines the environment question- without \writespace for stand alone questions such as those that require the student to fill in something in a table.
\newenvironment{question-}[2]{%
\setcounter{subpoints}{0}
\renewcommand*{\pointspace}{#2}%
\section{#1 \hfill (#2 pt)}%
\addtocounter{subtotalpoints}{#2}%
\addtocounter{totalpoints}{#2}%
}%
% defines the environment subquestion etc. using the command \writespace ; same as above, only subsection is used, and both subtotalpoints and totalpoints are not (!) increased. The starred versions again don't produce white space.
\NewEnviron{subquestion}[2]{%
\renewcommand*{\pointspace}{#2}%
\subsection{#1 \hfill (#2 pt)}%
\addtocounter{subpoints}{#2}%
\parbox{\textwidth}{\BODY\writespace}%
}
\newenvironment{subquestion*}[2]{%
\renewcommand*{\pointspace}{#2}%
\subsection{#1 \hfill (#2 pt)}%
\addtocounter{subpoints}{#2}%
}%
\newenvironment{subquestion-}[2]{%
\renewcommand*{\pointspace}{#2}%
\subsection{#1 \hfill (#2 pt)}%
\addtocounter{subpoints}{#2}%
}%
{%
}
% defines the environment hint which is simply boxed
\NewEnviron{hint}{%
\par\vspace{3ex}\noindent\fbox{\parbox{\textwidth}{\begin{center}\BODY\end{center}}}\vspace{3ex}%
}
% defines the environment answer
\NewEnviron{answer}{%
\ifshowanswers
\vspace{2\parsep}
\noindent \textrm{\textsc{\IfLanguageName{ngerman}{Lösung: }{Solution: }}} \noindent\textrm\BODY
\vspace{5ex}
\else\fi%
}
% defines the environment answer- for answers without any ado, for example if the answer is just a part of something
\NewEnviron{answer-}{%
\ifshowanswers
{\textrm\BODY}
\else\fi%
}
% defines the environment hide
\NewEnviron{hide}{%
\ifshowanswers
\else
\BODY
\fi%
}
%%% Environment Swapimage
\NewEnviron{swapimage}[3]{
\begin{figure}[H]
\begin{center}
\ifshowanswers
\textrm{\textsc{\IfLanguageName{ngerman}{Lösung: }{Solution: }}}\par
\includegraphics{#3}
\else
\includegraphics{#2}
\fi
\caption{\label{#1}\BODY}
\end{center}
\end{figure}
}
\endinput