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