README: Comment on exam generation
[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 \usepackage[american]{isodate}
27 \newcommand{\theexercise}{Exercise}
28 \newcommand{\thepoint}{Point}
29 \newcommand{\thepoints}{Points}
30 \newcommand{\thename}{Name}
31 \newcommand{\thestudnumber}{Number}
32 \newcommand{\theanswer}{Answer}
33 \newcommand{\theduration}{Duration}
34 \newcommand{\thegrade}{Grade}
35 \newcommand{\theof}{of}
36 }{%
37 \usepackage[ngerman]{babel}
38 \usepackage[german]{isodate}
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 \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
112 \geometry{a4paper,textwidth=16cm,textheight=23cm}
113
114
115 \RequirePackage{lcg}
116 \reinitrand[first=10000,last=99999,counter=examnonce,quiet]
117 \rand
118
119 \fancypagestyle{exsheet}
120 {
121 \fancyhf{}%
122 \fancyhead[L]{%
123 \@course\\
124 \@semester
125 }
126 \fancyhead[C]{%
127 {\isodate \today}
128 }
129 \fancyhead[R]{%
130 \@auth\\
131 \@curriculum
132 }
133 \@ifundefined{exsheetexam}{}{%
134 \fancyfoot[R]{%
135 \tiny nounce: \arabic{examnonce}
136 }
137 }
138 }
139
140 \setlength{\headheight}{2.5em}
141 \renewcommand{\headrulewidth}{1pt}
142
143 \setlength{\parindent}{0em}
144
145
146 \newcommand{\makestudentinfo}{%
147 {
148 \thename: \underline{\hspace{5cm}}
149 \hfill
150 \thestudnumber: \underline{\hspace{4cm}}
151 }
152 }
153
154 \newcommand{\makegradeinfo}{%
155 {
156 \thegrade: \underline{\hspace{5cm}}
157 \hfill
158 \thepoints: \underline{\hspace{2cm}} \theof\ \droptotalpoints
159 }
160 }
161
162
163 \let\oldmaketitle\maketitle
164
165
166 \@ifundefined{exsheetexam}{
167 \PassOptionsToClass{notitlepage}{article}
168 \renewcommand{\@maketitle}{%
169 \begin{center}
170 \vspace*{1em}
171 {\LARGE \bf \@title}
172 \vspace*{2em}
173 \end{center}
174 }
175 }{%
176 \renewcommand{\@maketitle}{%
177 \begin{titlepage}
178 \begin{center}
179 \vspace*{2cm}
180
181 \hrule
182 \vspace*{1cm}
183 {\LARGE \bf \@title}
184
185 \vspace*{1cm}
186 {\large \bf \@course\ (\@semester)}
187
188 \vspace*{1cm}
189 \hrule
190
191 \vspace*{2cm}
192
193 \@auth \\
194
195 \vspace*{1em}
196
197 \today\\
198
199 \vspace*{1em}
200 \@curriculum \\
201 \@institute \\
202 \@school \\
203
204 \vspace*{1cm}
205 \theduration: \@duration
206 \end{center}
207
208 \vspace{4em}
209 \@instructions
210
211 \vfill
212 \makestudentinfo
213
214 \vspace{3em}
215 \makegradeinfo
216 \end{titlepage}
217 }
218 }
219
220 \renewcommand{\maketitle}{%
221 \oldmaketitle
222 \thispagestyle{exsheet}
223 \pagestyle{exsheet}
224 }
225