Fix nonce typo
[exsheet.git] / exsheet2.cls
1 % Stefan Huber, 2022
2
3 \NeedsTeXFormat{LaTeX2e}
4 \ProvidesClass{exsheet2}
5
6 \DeclareOption{10pt}{\PassOptionsToClass{\CurrentOption}{article}}
7 \DeclareOption{12pt}{\PassOptionsToClass{\CurrentOption}{article}}
8 \DeclareOption{twoside}{\PassOptionsToClass{\CurrentOption}{article}}
9
10 \DeclareOption{german}{\def \exsheetgerman{}}
11 \DeclareOption{ngerman}{\def \exsheetgerman{}}
12 \DeclareOption{austrian}{\def \exsheetgerman{}}
13 \DeclareOption{naustrian}{\def \exsheetgerman{}}
14 \DeclareOption{showanswers}{\def \exsheetshowanswers{}}
15 \DeclareOption{exam}{\def \exsheetexam{}}
16 \DeclareOption{nostudentinfo}{\def \exsheetnostudentinfo{}}
17 \DeclareOption{nogradeinfo}{\def \exsheetnogradeinfo{}}
18
19
20 \PassOptionsToClass{a4paper}{article}
21 \ProcessOptions\relax
22
23
24 \LoadClass{article}
25
26 \@ifundefined{exsheetgerman}{
27 \usepackage[american]{babel}
28 \newcommand{\theexercise}{Exercise}
29 \newcommand{\thepoint}{Point}
30 \newcommand{\thepoints}{Points}
31 \newcommand{\thename}{Name}
32 \newcommand{\thestudnumber}{Number}
33 \newcommand{\theanswer}{Answer}
34 \newcommand{\theduration}{Duration}
35 \newcommand{\thegrade}{Grade}
36 \newcommand{\theof}{of}
37 }{%
38 \usepackage[ngerman]{babel}
39 \newcommand{\theexercise}{Aufgabe}
40 \newcommand{\thepoint}{Punkt}
41 \newcommand{\thepoints}{Punkte}
42 \newcommand{\thename}{Name}
43 \newcommand{\thestudnumber}{Personenkennzeichen}
44 \newcommand{\theanswer}{Antwort}
45 \newcommand{\theduration}{Prüfungsdauer}
46 \newcommand{\thegrade}{Note}
47 \newcommand{\theof}{von}
48 }
49
50 \usepackage[useregional]{datetime2}
51
52 \RequirePackage{xifthen,geometry,fancyhdr,enumitem,comment,amssymb}
53
54 \newcounter{exsheet2@pointsum}
55 \def\droptotalpoints{unknown}
56 \AtBeginDocument{\AtEndDocument{%
57 \immediate\write\@mainaux{%
58 \string\gdef\string\droptotalpoints{\number\value{exsheet2@pointsum}}%
59 }
60 }}
61
62 \newcounter{exsheet2@excounter}
63 \setcounter{exsheet2@excounter}{1}
64 \newenvironment{exercise}[1][]{%
65 \vspace*{2em}%
66 \textbf{\theexercise~\arabic{exsheet2@excounter}}
67 \ifthenelse{\isempty{#1}}{}{%
68 \addtocounter{exsheet2@pointsum}{#1}
69 \ifnum#1=1%
70 \hfill[#1 \thepoint]%
71 \else%
72 \hfill[#1 \thepoints]%
73 \fi%
74 }%
75 \newline}
76 {\addtocounter{exsheet2@excounter}{1}}
77
78 \@ifundefined{exsheetshowanswers}{
79 \excludecomment{answer}
80 }{
81 \newenvironment{answer}{\vspace*{0.5em}\textit{\theanswer:} \hspace*{0.5em} }{}
82 }
83
84 \newenvironment{choices}{%
85 \begin{itemize}[label=$\square$, labelsep=2ex]
86 }{\end{itemize}}
87
88
89 \def\@course{}
90 \newcommand{\course}[1]{\def\@course{#1}}
91
92 \def\@curriculum{}
93 \newcommand{\curriculum}[1]{\def\@curriculum{#1}}
94
95 \def\@semester{}
96 \newcommand{\semester}[1]{\def\@semester{#1}}
97
98 \def\@auth{}
99 \renewcommand{\author}[1]{\def\@auth{#1}\def\@author{#1}}
100
101 \def\@institute{}
102 \newcommand{\institute}[1]{\def\@institute{#1}}
103
104 \def\@school{}
105 \newcommand{\school}[1]{\def\@school{#1}}
106
107 \def\@duration{}
108 \newcommand{\duration}[1]{\def\@duration{#1}}
109
110 \def\@instructions{}
111 \newcommand{\instructions}[1]{\def\@instructions{#1}}
112
113 \let\olddate\date
114 \DTMsavenow{exsheet2@today}
115 \renewcommand{\date}[1]{\olddate{#1}\DTMsavedate{exsheet2@today}{#1}}
116
117
118 \geometry{a4paper,textwidth=16cm,textheight=23cm}
119
120
121 \RequirePackage{lcg}
122 \reinitrand[first=10000,last=99999,counter=examnonce,quiet]
123 \rand
124
125 \fancypagestyle{exsheet}
126 {
127 \fancyhf{}%
128 \fancyhead[L]{%
129 \@course\\
130 \@semester
131 }
132 \fancyhead[C]{%
133 {\DTMsetdatestyle{iso}\DTMusedate{exsheet2@today}}
134 }
135 \fancyhead[R]{%
136 \@auth\\
137 \@curriculum
138 }
139 \@ifundefined{exsheetexam}{}{%
140 \fancyfoot[R]{%
141 \tiny nonce: \arabic{examnonce}
142 }
143 }
144 }
145
146 \setlength{\headheight}{2.5em}
147 \renewcommand{\headrulewidth}{1pt}
148
149 \setlength{\parindent}{0em}
150
151
152 \newcommand{\makestudentinfo}{%
153 {
154 \thename: \underline{\hspace{5cm}}
155 \hfill
156 \thestudnumber: \underline{\hspace{4cm}}
157 }
158 }
159
160 \newcommand{\makegradeinfo}{%
161 {
162 \thegrade: \underline{\hspace{5cm}}
163 \hfill
164 \thepoints: \underline{\hspace{2cm}} \theof\ \droptotalpoints
165 }
166 }
167
168
169 \let\oldmaketitle\maketitle
170
171
172 \@ifundefined{exsheetexam}{
173 \PassOptionsToClass{notitlepage}{article}
174 \renewcommand{\@maketitle}{%
175 \begin{center}
176 \vspace*{1em}
177 {\LARGE \bf \@title}
178 \vspace*{2em}
179 \end{center}
180 }
181 }{%
182 \renewcommand{\@maketitle}{%
183 \begin{titlepage}
184 \begin{center}
185 \vspace*{2cm}
186
187 \hrule
188 \vspace*{1cm}
189 {\LARGE \bf \@title}
190
191 \vspace*{1cm}
192 {
193 \large\bf%
194 \@course
195 \ifthenelse{\equal{\@semester}{}}{}{ (\@semester)}
196 }
197
198 \vspace*{1cm}
199 \hrule
200
201 \vspace*{2cm}
202
203 \@auth \\
204
205 \vspace*{1em}
206
207 {\DTMusedate{exsheet2@today}} \\
208
209 \vspace*{1em}
210 \@curriculum \\
211 \@institute \\
212 \@school \\
213
214 \ifthenelse{\equal{\@duration}{}}{}{%
215 \vspace*{1cm}
216 \theduration: \@duration
217 }
218 \end{center}
219
220 \vspace{4em}
221 \@instructions
222
223 \vfill
224
225 \ifthenelse{\isundefined{\exsheetnostudentinfo}}{%
226 \makestudentinfo
227 }{}
228
229 \ifthenelse{\isundefined{\exsheetnogradeinfo}}{%
230 \vspace{3em}
231 \makegradeinfo
232 }{}
233 \end{titlepage}
234 }
235 }
236
237 \renewcommand{\maketitle}{%
238 \oldmaketitle
239 \thispagestyle{exsheet}
240 \pagestyle{exsheet}
241 }
242