% \CheckSum{1040} % %\iffalse % this is a METACOMMENT ! % % File: exam.dtx Copyright (C) 1993-1996 Hans van der Meer % % \begin{macrocode} %<*driver> \documentclass{ltxdoc} \setlength\overfullrule{5pt} \usepackage{verbatim} \IfFileExists{exam.cls}{\def\noexamples{}}% {\ClassWarningNoLine{ltxdoc}{Install exam.cls first}% \def\noexamples{\fbox{\huge Install exam.cls first}\end{document}}} \makeatletter \let\old@maketitle=\maketitle \let\LoadClass=\@gobble \let\@oldtableofcontents=\tableofcontents \input{exam.cls}% \let\tableofcontents=\@oldtableofcontents \let\maketitle=\old@maketitle \makeatother \noexamples \ProvidesFile{exam.dtx}[1997/03/14 3.30 Slides and notes] \GetFileInfo{exam.dtx} \title{The \textsf{exam} package% \thanks{This file has version \fileversion\space dated \filedate.}} \author{Hans van der Meer\\hansm@wins.uva.nl} \date{Printed \today} \CodelineNumbered \DisableCrossrefs \RecordChanges \begin{document} \maketitle \DocInput{exam.dtx} \end{document} % % \end{macrocode} %\fi % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % \changes{3.00}{1994/02/13}{First version for LaTeX2E and docstrip} % \changes{3.01}{1994/03/24}{added mbox{} to Copyright (missing item error)} % \changes{3.10}{1994/10/19}{updated several features} % \changes{3.11}{1994/10/21}{added dumpitemno and ignorespace in SRset} % \changes{3.12}{1994/10/25}{changed pagenumbering index} % \changes{3.13}{1994/11/10}{help shows class options} % \changes{3.14}{1994/11/24}{empty default for mainfolder, etc.} % \changes{3.15}{1994/12/10}{default language initialization added} % \changes{3.16}{1995/01/19}{require latest latex because of box trouble} % \changes{3.17}{1995/01/26}{maketitle redefinition better in exam.cfg} % \changes{3.18}{1995/02/02}{options, documentation, checksquare->boxtimes} % \changes{3.19}{1995/03/10}{pagestyle tuned, added options} % \changes{3.20}{1995/07/12}{table of contents problem solved} % \changes{3.21}{1995/08/07}{writing toc-entry in question displaced} % \changes{3.22}{1995/08/09}{folders default set to @currdir} % \changes{3.23}{1995/10/26}{help standard, textbo removed, small changes} % \changes{3.24}{1995/10/30}{ignorespaces added to longanswer start} % \changes{3.25}{1995/12/17}{error in altanswer repaired} % \changes{3.26}{1996/08/10}{cleaning, fixing loose ends, simplified where possible} % \changes{3.27}{1996/08/19}{dir path separator changed in folder macros} % \changes{3.28}{1996/08/23}{shortanswer changed, documentation polished} % \changes{3.29}{1997/03/08}{directory macros changed} % \changes{3.30}{1997/03/14}{CurrentDirectory for @currdir added} % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % \DoNotIndex{\#} % \DoNotIndex{\@@input} % \DoNotIndex{\@dblarg} % \DoNotIndex{\@depth} % \DoNotIndex{\@empty} % \DoNotIndex{\@firstoftwo} % \DoNotIndex{\@height} % \DoNotIndex{\@ifstar} % \DoNotIndex{\@ifundefined} % \DoNotIndex{\@m} % \DoNotIndex{\@makeother} % \DoNotIndex{\@namedef} % \DoNotIndex{\@ne} % \DoNotIndex{\@sanitize} % \DoNotIndex{\@secondoftwo} % \DoNotIndex{\@tempdima} % \DoNotIndex{\@tempdimb} % \DoNotIndex{\@title} % \DoNotIndex{\@warning} % \DoNotIndex{\@whilenum} % \DoNotIndex{\@width} % \DoNotIndex{\\} % \DoNotIndex{\{} % \DoNotIndex{\}} % \DoNotIndex{\^} % \DoNotIndex{\ } % \DoNotIndex{\addtolength} % \DoNotIndex{\addvspace} % \DoNotIndex{\advance} % \DoNotIndex{\begin} % \DoNotIndex{\begingroup} % \DoNotIndex{\bgroup} % \DoNotIndex{\bigskip} % \DoNotIndex{\bigskipamount} % \DoNotIndex{\box} % \DoNotIndex{\catcode} % \DoNotIndex{\count@} % \DoNotIndex{\csname} % \DoNotIndex{\def} % \DoNotIndex{\dimen@} % \DoNotIndex{\divide} % \DoNotIndex{\do} % \DoNotIndex{\dotfill} % \DoNotIndex{\dp} % \DoNotIndex{\edef} % \DoNotIndex{\egroup} % \DoNotIndex{\else} % \DoNotIndex{\emph} % \DoNotIndex{\end} % \DoNotIndex{\endcsname} % \DoNotIndex{\endgroup} % \DoNotIndex{\endlist} % \DoNotIndex{\enskip} % \DoNotIndex{\enspace} % \DoNotIndex{\ensuremath} % \DoNotIndex{\expandafter} % \DoNotIndex{\f@baselineskip} % \DoNotIndex{\fbox} % \DoNotIndex{\fi} % \DoNotIndex{\footnotesize} % \DoNotIndex{\gdef} % \DoNotIndex{\global} % \DoNotIndex{\hbox} % \DoNotIndex{\hfil} % \DoNotIndex{\hfill} % \DoNotIndex{\hrule} % \DoNotIndex{\hskip} % \DoNotIndex{\hspace} % \DoNotIndex{\hss} % \DoNotIndex{\ht} % \DoNotIndex{\if} % \DoNotIndex{\ifcase} % \DoNotIndex{\ifdim} % \DoNotIndex{\ifnum} % \DoNotIndex{\ifodd} % \DoNotIndex{\ifx} % \DoNotIndex{\ignorespaces} % \DoNotIndex{\item} % \DoNotIndex{\itemsep} % \DoNotIndex{\leavevmode} % \DoNotIndex{\let} % \DoNotIndex{\list} % \DoNotIndex{\llap} % \DoNotIndex{\m@ne} % \DoNotIndex{\makebox} % \DoNotIndex{\mbox} % \DoNotIndex{\medskip} % \DoNotIndex{\medskipamount} % \DoNotIndex{\multiply} % \DoNotIndex{\newcommand} % \DoNotIndex{\newcount} % \DoNotIndex{\newcounter} % \DoNotIndex{\newenvironment} % \DoNotIndex{\newif} % \DoNotIndex{\newlength} % \DoNotIndex{\newpage} % \DoNotIndex{\newsavebox} % \DoNotIndex{\newtoks} % \DoNotIndex{\next} % \DoNotIndex{\noexpand} % \DoNotIndex{\noindent} % \DoNotIndex{\null} % \DoNotIndex{\number} % \DoNotIndex{\or} % \DoNotIndex{\p@} % \DoNotIndex{\par} % \DoNotIndex{\parbox} % \DoNotIndex{\parsep} % \DoNotIndex{\partopsep} % \DoNotIndex{\phantom} % \DoNotIndex{\protect} % \DoNotIndex{\providecommand} % \DoNotIndex{\raggedright} % \DoNotIndex{\relax} % \DoNotIndex{\renewcommand} % \DoNotIndex{\rlap} % \DoNotIndex{\rmfamily} % \DoNotIndex{\romannumeral} % \DoNotIndex{\selectfont} % \DoNotIndex{\setbox} % \DoNotIndex{\setcounter} % \DoNotIndex{\setlength} % \DoNotIndex{\settowidth} % \DoNotIndex{\sffamily} % \DoNotIndex{\sloppy} % \DoNotIndex{\small} % \DoNotIndex{\smallskip} % \DoNotIndex{\smallskipamount} % \DoNotIndex{\space} % \DoNotIndex{\stepcounter} % \DoNotIndex{\string} % \DoNotIndex{\strut} % \DoNotIndex{\test} % \DoNotIndex{\textbf} % \DoNotIndex{\textemdash} % \DoNotIndex{\textsl} % \DoNotIndex{\texttt} % \DoNotIndex{\the} % \DoNotIndex{\thinspace} % \DoNotIndex{\tw@} % \DoNotIndex{\topsep} % \DoNotIndex{\typeout} % \DoNotIndex{\undefined} % \DoNotIndex{\underbar} % \DoNotIndex{\uppercase} % \DoNotIndex{\upshape} % \DoNotIndex{\vadjust} % \DoNotIndex{\value} % \DoNotIndex{\vbox} % \DoNotIndex{\vfil} % \DoNotIndex{\vfill} % \DoNotIndex{\vskip} % \DoNotIndex{\vspace} % \DoNotIndex{\vss} % \DoNotIndex{\wd} % \DoNotIndex{\xdef} % \DoNotIndex{\z@} % \DoNotIndex{\z@skip} % % \begin{abstract} % This article describes the use and the implementation of the % \emph{exam class}. % Its purpose is the typesetting of exams. % Exam questions can be multiple choice or free long\slash short % answer questions. % Options are the typesetting of the exam itself, an exam % showing all the answers and a collection of questions and answers. % Questions can be parametrized. % Use of a random generator provides for automatic shuffling % of multiple choice items. % \end{abstract} % % \tableofcontents % % \section{Usage} % % \subsection{Exam production} % % An exam can be built from the following template. % For special issues as the use of default names for % various directories, language selection, etc. see % the implementation section. % % You may customize the typesetting by providing % a file \emph{exam.cfg} in the search path; this file % is read just before typesetting begins. % The example of this file gives a language customization % and an implementation for a title page. % % \medskip\noindent % \DescribeEnv{exam} % |\documentclass[options]{exam}|\\ % |\title{title of exam}|\\ % |\author{the examinator}|\\ % |\target{the students}|\\ % |\begin{document}|\\ % |\begin{exam}[startvalue random generator]{date of exam}|\\ % |\question{directory}{file}|\\ % |\question[parameter value]{directory}{file}|\\ % |....|\\ % |\end{exam}|\\ % |... % possibly other exams|\\ % |\end{document}| % % \subsection{Format of a problem} % % \DescribeEnv{problem} % A problem is built by environment |problem|. % In it several elements can be placed. These are: % \begin{enumerate} % \item \DescribeMacro{\parameterproblem} % |\parameterproblem{text}|: used to communicate to the % maintainer of the problems the possibilities offered % by the transfer of macro |\parameter| on posing % the question; an example of this will follow. % Can also find a place before the problem declaration. % \item |\begin{problem}[#1]|; the optional parameter % can have the value |\compact| (no pagebreak within problem, default) % or the value |\split| (pagebreak may occur in problem). % \item |\problemdate{date}|: a macro to remember on which % day the problem was born; % \item \DescribeMacro{\score} % |\score{value}|: use this macro for the number of % points the answer is worth; it is possible to include % several score items in one problem for partial rewards. % The score value is not shown when an exam is typeset, % the student must earn these points! % \item text of the question. % \item the answer or multiple choice list; % see the description below. % \item |\remark[h]{b}|: a boxed remark with heading h and body b. % \item |\end{problem}|. % \end{enumerate} % % \subsection{Examples of Question and Typesetting} % % \subsubsection{Simple Problem} % % \begin{center} % \textbf{problem --- coding} % \end{center} % \medskip % |\begin{problem}|\\ % |\problemdate{\today}|\\ % |What is the question?|\\ % |\score{2}|\\ % |\shortanswer{To be or not to be.}|\\ % |\end{problem}| % % \medskip % \DescribeMacro{\question} % This problem is called up with\\ % |\question{}{exampa}|\\ % which we show without |answers| option and with both the |answers| and % |series| option set. % \begin{center} % \textbf{problem --- result --- without answers} % \end{center} % \medskip % \begin{center} % \begin{minipage}{.9\linewidth}\setlength\linewidth{.8\linewidth} % \answersfalse % \MakePercentComment\question{}{exampa}\MakePercentIgnore % \end{minipage} % \end{center} % \medskip % \begin{center} % \textbf{problem --- result --- with answers} % \end{center} % \medskip % \begin{center} % \begin{minipage}{.9\linewidth}\setlength\linewidth{.8\linewidth} % \answerstrue\seriestrue % \addtocounter{problemnum}{-1} % \MakePercentComment\question{}{exampa}\MakePercentIgnore % \end{minipage} % \end{center} % % \subsubsection{Parametrized Problem} % % \DescribeMacro{\parameter} % The next example shows the use of |\parameter| for the selection % of alternate questions. It is given both value 1 and 2 and called % with respectively:\\ % |\question[1]{}{exampb}|\\ % |\question[2]{}{exampb}|\\ % However, remember that |\parameter| can be defined to anything; % e.g. the number that goes into a calculation, a word substituted % at a specific place, etc. % % \medskip % \begin{center} % \textbf{parameterproblem --- coding} % \end{center} % \medskip % |\parameterproblem{1= to be\\2= not to be}|\\ % |\problemdate{\today}|\\ % |\begin{problem}|\\ % |\score{2}|\\ % |What is\ifnum\parameter=1\relax \else n't\fi\ the question?|\\ % |\shortanswer{\ifnum\parameter=1\relax To be or n\else N\fi ot to be.}|\\ % |\end{problem}| % \medskip % \begin{center} % \textbf{parameterproblem --- result --- parameter = 1} % \end{center} % \medskip % \begin{center} % \begin{minipage}{.9\linewidth}\setlength\linewidth{.8\linewidth} % \answerstrue\seriestrue % \MakePercentComment\question[1]{}{exampb}\MakePercentIgnore % \end{minipage} % \end{center} % \medskip % \begin{center} % \textbf{parameterproblem --- result --- parameter = 2} % \end{center} % \medskip % \begin{center} % \begin{minipage}{.9\linewidth}\setlength\linewidth{.8\linewidth} % \answerstrue\seriestrue % \addtocounter{problemnum}{-1} % \MakePercentComment\question[2]{}{exampb}\MakePercentIgnore % \end{minipage} % \end{center} % % \subsection{Answers} % \DescribeMacro{\answer} % \DescribeMacro{\altanswer} % The basic macros for showing and suppressing answers are % |\answer| that shows its argument when the \emph{answers} % option is chosen, and |\altanswer| that alternates its % two arguments. Both macros have a first, optional argument % for specifying the width of the box wherein the text % is placed. % % \medskip % \begin{center} % \textbf{answer --- coding} % \end{center} % \medskip % |\answer{answer}| % % \medskip % \begin{center} % \textbf{answer --- result --- % left without, right with answers} % \end{center} % \medskip % \begin{center} % \fbox{\parbox[t]{.4\linewidth}{\strut\answersfalse % \answer{answer} % }}\qquad\fbox{\parbox[t]{.4\linewidth}{\strut\answerstrue % \answer{answer}}} % \end{center} % % \medskip % \begin{center} % \textbf{altanswer --- coding} % \end{center} % \medskip % |\altanswer{answer NO}{answer YES}| % % \medskip % \begin{center} % \textbf{altanswer --- result --- % left without, right with answers} % \end{center} % \medskip % \begin{center} % \fbox{\parbox[t]{.4\linewidth}{\strut\answersfalse % \altanswer{answer NO}{answer YES} % }}\qquad\fbox{\parbox[t]{.4\linewidth}{\strut\answerstrue % \altanswer{answer NO}{answer YES}}} % \end{center} % % \DescribeMacro{\shortanswer} % Some questions can be answered by a few words, a short sentence. % The command |\shortanswer| serves this purpose; % its argument is the answer. % % \medskip % \begin{center} % \textbf{short answer --- coding} % \end{center} % |\shortanswer{The answer.}| % % \medskip % \begin{center} % \textbf{short answer --- result --- % left without answers, right with answers} % \end{center} % \medskip % \begin{center} % \renewcommand*\shortwhite{2mm} % \fbox{\parbox[t]{.4\linewidth}{\answersfalse % Answer the next question: % \shortanswer{The answer.}}} % \qquad % \fbox{\parbox[t]{.4\linewidth}{\answerstrue % Answer the next question: % \shortanswer{The answer.}}} % \end{center} % % \DescribeEnv{longanswer} % When however more space is needed by the student, the % environment |longanswer| can be used. % This environment has one optional parameter, meant % for specifying the amount of white space to be reserved % for the students answer. % % \medskip % \begin{center} % \textbf{long answer --- coding} % \end{center} % \medskip % |\begin{longanswer}[5mm]|\\ % |The answer.|\\ % |\end{longanswer}| % % \medskip % \begin{center} % \textbf{long answer --- result --- % left without answers, right with answers} % \end{center} % \medskip % \begin{center} % \fbox{\parbox[t]{.4\linewidth}{\answersfalse % Answer the next question: % \begin{longanswer}[5mm] % The answer. % \end{longanswer}}} % \qquad % \fbox{\parbox[t]{.4\linewidth}{\answerstrue % Answer the next question: % \begin{longanswer}[5mm] % The answer. % \end{longanswer}}} % \end{center} % % \DescribeMacro{\answerstart} % The answer is headed by a call to |\answerstart|; redefine % to your taste. % % \DescribeMacro{\shortwhite} % \DescribeMacro{\longwhite} % The default of white space reserved for the depth of the short answer % can be changed by redefinition of |\shortwhite|. % The default for the white space of the long answer % can be changed by redefinition of |\longwhite|. % % \subsection{Multiple Choice} % % \DescribeEnv{choice} % Multiple choice is provided for by environment |choice|. % Within this environment a itemized list of alternatives is given. % \DescribeMacro{\baditem} % \DescribeMacro{\gooditem} % However instead of |\item| one codes |\baditem{text}| for wrong answers % and |\gooditem{text}| for the correct one; the answer being put % into the argument of these two macros. % \DescribeMacro{\ordered} % \DescribeMacro{\random} % The optional parameter of this environment can be |\ordered| for % production of the alternatives in the order specified, or % |\random| for randomization; randomize is the default, unless % the \emph{series} option is specified in the |\documentclass| call. % % \medskip % \begin{center} % \textbf{multiple choice example --- coding} % \end{center} % \medskip % |\begin{choice}[\ordered]|\\ % |\baditem{first wrong answer}|\\ % |\gooditem{the right answer}|\\ % |\baditem{second wrong answer}|\\ % |\end{choice}| % % \medskip % \begin{center} % \textbf{multiple choice --- result --- % left without answers, right with answers} % \end{center} % \medskip % \begin{center} % \fbox{\parbox[t]{.4\linewidth}{\answersfalse % Choose appropriate alternative: % \begin{choice}[\ordered] % \baditem{first wrong answer} % \gooditem{the right answer} % \baditem{2nd wrong answer} % \end{choice}}} % \qquad % \fbox{\parbox[t]{.45\linewidth}{\answerstrue % Choose appropriate alternative: % \begin{choice}[\ordered] % \baditem{first wrong answer} % \gooditem{the right answer} % \baditem{2nd wrong answer} % \end{choice}}} % \end{center} % % \DescribeMacro{\badmark} % \DescribeMacro{\goodmark} % The marks for the multiple choice items are produced % by the macros |\badmark| and |\goodmark|. For their % redefinition see the implementation section of this % document. % % \subsection{Shuffling it Yourself} % % \DescribeMacro{\loaditem} % The selection of alternatives is implemented by the % mechanism in macros |\loaditem| and friends. % Pieces text can be loaded (in this implementation at most 5) and % selectively dumped into the typeset input stream. % It is a useful mechanism when one has to produce % a whole series of variations on the same theme. % % Macro |\loaditem| can be used to load from one to five % items in a data store. % \DescribeMacro{\shuffle} % This data store can be shuffled % by a call to |\shuffle|. % \DescribeMacro{\dumpitem} % \DescribeMacro{\dumpitems} % Popping items from the store % is effected by macros |\dumpitem| (pop one item) and % |\dumpitems| (all items). Clearing of the store % is done by |\resetloadcounter|. % \DescribeMacro{\SRtest} % With |\SRtest{1}{2}| one can make a random choice between two % alternatives. % % \medskip % \begin{center} % \textbf{load and dump --- coding} % \end{center} % \medskip % |\SRset{349} % start random generator|\\ % |\resetloadcounter % initialize load stack|\\ % |\loaditem{\fbox{item 1}\space} % load 4 items of text|\\ % |\loaditem{\fbox{item 2}\space}|\\ % |\loaditem{\fbox{item 3}\space}|\\ % |\loaditem{\fbox{item 4}\space}|\\ % |Here comes nr~2: \dumpitemno{2} % dump 2nd item|\\ % |\par|\\ % |\shuffle % randomize|\\ % |Here nr~2 again after randomization: \dumpitemno{2}|\\ % |\par|\\ % |Dump the whole lot: \dumpitems| % % \medskip % \begin{center} % \textbf{load and dump --- result} % \end{center} % \medskip % \begin{center} % \parbox[t]{.8\linewidth}{% % \SRset{349} % \resetloadcounter % \loaditem{\fbox{item 1}\space} % \loaditem{\fbox{item 2}\space} % \loaditem{\fbox{item 3}\space} % \loaditem{\fbox{item 4}\space} % Here comes nr~2: \dumpitemno{2}\par % \shuffle % Nr~2 after randomization: \dumpitemno{2}\par % Dump the whole lot: \dumpitems % } % \end{center} % % % \section{Summary of Options and Macros} % % \subsection{Options} % % \begin{flushleft}\sloppy % |answers| problems with answers\\ % |pages| each problen on a separate page\\ % |questiononly| suppress open space for answers\\ % |nosep| suppress separation between successive problems\\ % |scores| add score values\\ % |series| produce problem collection % \end{flushleft} % % \subsection{Exam Production} % % \begin{flushleft}\sloppy % |\target{name}| exam meant for these people\\ % |\begin{exam}[randomstart]{date}...\end{exam}| dated exam\\ % |\begin{exam}{date}...\end{exam}| randomstart=0, i.e. not random\\ % |\begin{exam}{}...\end{exam}| today's date\\ % |\question[variant]{dir}{file}| call problem variant from dir/file\\ % |\question{dir}{file}| no problem variants % \end{flushleft} % % \subsection{Problem Definition} % % \begin{flushleft}\sloppy % |\parameterproblem[param]{explication}| set default, show explication\\ % |\begin{problem}...\end{problem}| problem definition, kept wholly on page\\ % |\begin{problem}[\split]...\end{problem}| do not confine to one page\\ % |\problemdate{date}| reference date for problem\\ % |\score{value}| set problems worth in points\\ % |\remark[label]{text}| place remark if series option\\[\smallskipamount] % |\answer[width]{answer}| coding in an answer\\ % |\altanswer[width]{alt}{answer}| alternate text instead of answer\\ % |\shortanswer{answer}| short answer or row of dots\\ % |\begin{longanswer}[height]...\end{longanswer}| long answer or space\\[\smallskipamount] % |\begin{choice}...\end{choice}| randomly permuted multiple choice\\ % |\begin{choice}[\ordered]...\end{choice}| not permuted\\ % |\baditem{text}| inside a |choice| text for false item\\ % |\gooditem{text}| ditto for good item\\[\smallskipamount] % |\loaditem{anything}| put `anything' to memory stack\\ % |\dumpitem| pop top from memory stack\\ % |\dumpitems| pop whole memory stack\\ % |\shuffle| randomize memory stack % % \end{flushleft} % % \subsection{Styling and Customization} % % \begin{flushleft}\sloppy % |\everyproblem| token register executed at start of each problem\\ % |\scoreboxsize{size}| set size of square score box\\ % |\shortwhite| default vertical space short answers, change |\renewcommand|\\ % |\longwhite| ditto for long answers\\ % |\marksize| size of multiple choice marks, |\selectfont| expression\\ % |\badmark| symbol for multiple choice item box\\ % |\goodmark| ditto for the good one\\ % |\headerfont| font for page header\\ % |\bodyfont| font for exam text\\ % |\titlefont| font for titles\\ % |\Mainfolder{dir}| set |\mainfolder| to dir\\ % |\Commonfolder{dir}| set |\commonfolder| to dir\\ % |\Figuresfolder{dir}| set |\figuresfolder| to dir % \end{flushleft} % % \StopEventually{\PrintChanges} % % \newpage % \begin{macrocode} %<*cls> % \end{macrocode} % % \section{Identification} % % This document class can only be used with \LaTeXe, so we make % sure that an appropriate message is displayed when another \TeX{} % format is used. We require the latest version that has no known % troubles with this class. % \begin{macrocode} \NeedsTeXFormat{LaTeX2e}[1995/12/01] % \end{macrocode} % % Announce the Class name and its version. % \begin{macrocode} \ProvidesClass{exam}[1997/03/14 vs 3.30 exam package] % \end{macrocode} % % \section{Declaration of Class Options} % % In this part we define the options for this class that are additional % to those of its parent class. % % \subsection{Switching answers on and off} % % \begin{macro}{\ifanswers} % The flag |\ifanswers| governs the production of answers in the % typesetting of problems. With the |answers| options in the % optional argument of the document class this option is turned on. % Then also we show the score values. % % \begin{macrocode} \newif\ifanswers \answersfalse \DeclareOption{answers}{\answerstrue\scorestrue} % \end{macrocode} % \end{macro} % % \subsection{Each problem on separate page} % % \begin{macro}{\ifproblempages} % The flag |\ifproblempages| governs the typesetting of problems % on separate pages, or their collection of more than one to a page. % If separate pages are chosen, a separator between problems % is unnecessary. % % \begin{macrocode} \newif\ifproblempages \problempagesfalse \DeclareOption{pages}{\problempagestrue\problemsepfalse} % \end{macrocode} % \end{macro} % % \subsection{Suppress prompt for answer} % % \begin{macro}{\ifreservespace} % The flag |\ifreservespace| governs the typesetting of space % for answers. If true, all reservation of answer space is % suppressed. It is set by option |questiononly|; % this option has no effect when the |answers| option is on. % % \begin{macrocode} \newif\ifreservespace \reservespacetrue \DeclareOption{questiononly}{\reservespacefalse} % \end{macrocode} % \end{macro} % % \subsection{Visible separation between problems} % % \begin{macro}{\ifproblemsep} % The value of flag |\ifproblemsep| determines the appearance % of a visible separation between successive problems. % % \begin{macrocode} \newif\ifproblemsep \problemseptrue \DeclareOption{nosep}{\problemsepfalse} % \end{macrocode} % \end{macro} % % \subsection{Showing score values} % % \begin{macro}{\ifscores} % The flag |\ifshowscores| determines when score values are printed. % % \begin{macrocode} \newif\ifscores \scoresfalse \DeclareOption{scores}{\scorestrue} % \end{macrocode} % \end{macro} % % \subsection{Typeset a Catalogue of Problems} % % \begin{macro}{\ifseries} % The flag |\ifseries| initiates the production of a problem catalogue. % In order to show answers and score values, the respective flags are set. % % \begin{macrocode} \newif\ifseries \seriesfalse \DeclareOption{series}{\seriestrue\answerstrue\scorestrue} % \end{macrocode} % \end{macro} % % \subsection{Show Options} % % Show options to the user with option |help|. % % \begin{macrocode} \DeclareOption{help}{\ClassWarningNoLine{exam}{% available options for exam:\MessageBreak answers:\space show questions with answers;\MessageBreak nosep:\space no separators between problems;\MessageBreak pages:\space each problem on a page;\MessageBreak questiononly:\space suppress answer space in exams;\MessageBreak scores:\space typeset score values always;\MessageBreak series:\space\space typeset catalogue of problems}} % \end{macrocode} % % \section{Loading of Parent Class} % % Since the \emph{exam class} is implemented as a modification % of an existing document class, we must load the parent class. % \begin{macro}{\parentclass} % In order to make changes in parent class easy, the % name of this class is parametrized in macro |\parentclass|. % Obvious candidates are \emph{article} and \emph{report}. % In order to provide some flexibility, we allow for the case % that the user has already defined |\parentclass| (before % the call to |\documentclass|. In that case we refrain % from redefinition. % % \begin{macrocode} \providecommand\parentclass{article} % \end{macrocode} % \end{macro} % % The options of the |\documentclass| call which are not specific for the % \emph{exam class} must be passed to the parent class. % We take the opportunity to select the production of a titlepage % (not automatically added if the parent class is \emph{article}. % After this we process the local options. % % \begin{macrocode} \DeclareOption*{\PassOptionsToClass{\CurrentOption}{\parentclass}} \PassOptionsToClass{titlepage}{\parentclass} \ProcessOptions % \end{macrocode} % % Then we load the parent class. % % \begin{macrocode} \LoadClass{\parentclass} % \end{macrocode} % % A table of contents can be produced when a series is run or when % producing an exam including answers, otherwise kill the % corresponding macro. % % \begin{macrocode} \ifseries\else\ifanswers\else\let\tableofcontents=\relax\fi\fi % \end{macrocode} % % \section{Helpfull Macros} % % \begin{macro}{\@ifemptyarg} % Testing for the presence or absence of a parameter. % % \begin{macrocode} \providecommand\@ifemptyarg[1]{% {absence}{presence} \ifx\@empty#1\@empty \expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi} % \end{macrocode} % \end{macro} % % \begin{macro}{\examerror} % \begin{macro}{\examwarning} % Define |\examerror| and |\examwarning| to issue proper % warnings in case of errors. % Note that the error macro provides for a help text in its % second argument. % % \begin{macrocode} \newcommand*\examerror[2]{\ClassError{exam}{!!!! #1}{#2}} \newcommand*\examwarning[1]{\ClassWarning{exam}{!!!! #1}} % \end{macrocode} % \end{macro} % \end{macro} % % \section{Produce an Exam} % % \begin{macro}{\examnum} % First we need a counter for exams, since in one run more than % one exam can be produced. % By stepping this counter we will effect the automatic reset of % the counter that numbers the problems and % the counter that remembers the score value. % % \begin{macrocode} \newcounter{examnum} % \end{macrocode} % \end{macro} % % \begin{environment}{exam} % Exams are produced within the |exam| environment. This environment takes % 2 parameters. The first one is optional and provides the initial value % of the random generator.\footnote{Not used when a series % is run.} The default is 0, which effectively shuts off randomness. % The second parameter must be present, but can be empty. % It fixes the date for which the exam is planned; an empty argument % fills in the current date. % % \begin{macrocode} \newenvironment{exam}[2][0]{% \stepcounter{examnum}% \@ifemptyarg{#2}{}{\date{#2}}% % \end{macrocode} % % When answers are requested we start with a titlepage.\footnote{% % If not inhibited by the |notitlepage| option.} % In the case of exam production, typesetting of the titlepage % is deferred to the end of the exam, % so that we may print on it the number of problems. % We write a few messages to the table of contents (date and initial % value of the random generator) when an exam with answers % is in production. % Disable the random generator for a series. % % \begin{macrocode} \ifanswers \pagenumbering{roman}% \maketitle\newpage\mbox{}\newpage \fi \pagenumbering{arabic}% \ifseries\SRset{0}\else \SRset{#1}% \addtocontents{toc}{\protect\contentsline{section}% {\Exam~\theexamnum~\textemdash~\@date~% \textemdash~random start #1}{}}% \fi % \end{macrocode} % % In each separate exam the first page gets the number one. % % \begin{macrocode} \setcounter{page}{1}}% % \end{macrocode} % % At the end of the exam produced for the students % a titlepage is made. If answers are given for the exam % we also provide the total of the scores. % % \begin{macrocode} {\ifseries\else \typeout{Total value scores = \thetotalscore}% \ifanswers \addtocontents{toc}{\protect\contentsline{section}% {Total value scores = \thetotalscore}{}}% \else\maketitle \fi\fi} % \end{macrocode} % \end{environment} % % \section{Choosing Problems} % % \begin{macro}{\problemnum} % We start with a counter |\problemnum| with which the problems % of the exam are neatly numbered. This counter is automatically % reset each time a new |exam| environment is entered. % \begin{macro}{\problemid} % A textual identification of the current problem is collected % in token register |\problemid|. % % \begin{macrocode} \newcounter{problemnum}[examnum] \newtoks\problemid % \end{macrocode} % \end{macro} % \end{macro} % % \begin{macro}{\question} % \textbf{Each question must reside in its own file} which is called up % by macro |\question|. Of its three parameters the first is % optional and provides a means of communication with the % problem itself. To achieve this the first % argument of |\question| is cached % in macro |\parameter|.\footnote{As most uses of this mechanism % boil down to a choice between several alternatives, the % number~1 is provided by macro {\ttfamily\protect\bslash parameterproblem} % as a convenient default value. See also the discussion % under the heading ``Parametrized Problems''.} % The default behaviour here is not touching the % definition of |\parameter| in case of an empty argument; % in many cases a forgotten argument will then lead to % a ``missing something'' error. The benefit of not % touching |\parameter| in case of an empty argument % is that this macro now also can be initialized by % other means, e.g. by definition earlier in the problem coding. % % The second parameter of |\question| is the name of the (sub)directory % where the file named in the third parameter can be found. % This second parameter doubles up as section name in the % series production.\footnote{It is silently assumed % that all problems of a given category reside in a common % directory.} % % \begin{macrocode} \newcommand*\question[3][]{% \@ifemptyarg{#1}{}{\renewcommand\parameter{#1}}% % \end{macrocode} % % When a series is run we look for the start of a new section and % perform the appropriate actions if indeed a new section is found. % I.e.\ eject the page and then reset the section name % and the problem counter. % Note the use of uppercase in order to smooth out differences in typing. % The identification of the problem is set to its file name and, % in the case of a series, is mentioned in the output. % Then the problem number is incremented. % % \begin{macrocode} \ifseries \uppercase{\def\@namesection{#2}}% \ifx\namesection\@namesection \else \newpage \global\let\namesection=\@namesection \addcontentsline{toc}{subsection}{\namesection}% \setcounter{problemnum}{0}% \fi \fi \problemid={\MakeUppercase{#3}}% \ifseries \noindent\underbar{\emph{File\,:}~\texttt{\the\problemid}}\par \nopagebreak\medskip\nopagebreak \fi \stepcounter{problemnum}% % \end{macrocode} % % If appropriate a summary of this problem is written to the table of contents. % % \begin{macrocode} \ifanswers \addcontentsline{toc}{subsection}% {\hbox to1cm{\theproblemnum:\hss}#3}% \fi % \end{macrocode} % % Reading of the problem itself is surrounded by calculations % on the score that this question will bring. % Scores are mentioned on the console except when a series is run. % In a problem all contributions from the various parts of the % problem are collected in counter |scorecounter|. % At the end of the problem |totalscore| is % updated with this value.\footnote{% % Note the resets for |totalscore| with |examnum| % and |scorecounter| with |problemnum| in their declaration.} % The code guards against typing errors in the name of the file. % % \begin{macrocode} \edef\@curquestion{\mainfolder\@ifemptyarg{#2}{}{#2\@currdir}#3}% \IfFileExists{\@curquestion}{\@@input \@curquestion}% {\examwarning{File \@curquestion: not found}}% \ifseries\else \addtocounter{totalscore}{\value{scorecounter}}% \typeout{\Problem\space\theproblemnum: score=\thescorecounter}% \fi } % \end{macrocode} % \end{macro} % % \begin{macro}{namesection} % Macro |\namesection| gets its initial value here: % % \begin{macrocode} \newcommand*\namesection{\Collection} % \end{macrocode} % \end{macro} % % \subsection{Parametrized Problems} % % \begin{macro}{\reset@parameter} % A parametrized problem gets its parameter from the first % argument of macro |\question|, as already have been mentioned. % This is effected by definition of macro |\parameter| to % the value of that argument. % We add code here to (re)initialize this macro. % % \begin{macrocode} \newcommand*\reset@parameter{\gdef\parameter{}} \reset@parameter % \end{macrocode} % \end{macro} % % \begin{macro}{\parameterproblem} % The first argument of |\parameterproblem| is optional and % sets a default by for |\parameter|; % set to the number~1 if not explicitely given. % It is recommended that |\parameterproblem| is placed % before the first use of |\parameter| or even before the % |\begin{problem}|. % Furthermore, in typesetting an exam this macro will print a warning % if |\parameter| has not been set on the |\question| call. % % |\parameterproblem| will typeset its second argument in a framed box. % Usually this tells the reader which selections are available; however, % only in the case a series is run, otherwise `silence' is the word. % The description is placed by macro |\remark| which does the % necessary suppression. % % \begin{macrocode} \newcommand\parameterproblem[2][1 ]{% \ifx\parameter\@empty \ifseries\else\examwarning{\string\parameter\space set to `#1'}\fi \renewcommand\parameter{#1}% \fi \remark[Parameter \Problem]{#2}} % \end{macrocode} % \end{macro} % % % \section{Typesetting a Problem} % % Each problem must be enclosed in an environment |problem|. % Within this environment a default setup exists. % \begin{macro}{\everyproblem} % By supplying code in token register |\everyproblem| one % can influence the typesetting of each problem. % % \begin{macrocode} \newtoks\everyproblem % \end{macrocode} % \end{macro} % % \begin{environment}{problem} % The |problem| environment also has one optional parameter % for specific adjustments of the options setting. % Execution of options occurs in the order: % default setup, possible modification by |\everyproblem| and % final customization through the optional parameter. % This mechanism provides for maximum flexibility. % % \begin{macrocode} \newenvironment{problem}[1][]{% % \end{macrocode} % % Choose by default for keeping the whole problem on a page, % execute any code in the token register and honor the % option calls from the user. % % \begin{macrocode} \compact\the\everyproblem#1\relax % \end{macrocode} % % In order to keep everything on page we will enclose % the problem in a |\vbox|, coded in % macro |\@boxing|. Otherwise |\@boxing| is a noop and % \TeX's pagebuilder can choose its breakpoint freely. % For the declaration of |\@boxing| see section~\ref{ref:boxing}. % % The problem is typeset with a standard opening % programmed in |\problemstart|, completing the % opening manoeuvres of the environment. % % \begin{macrocode} \@boxing\bgroup\noindent\problemstart\ignorespaces}% % \end{macrocode} % % After processing the body of the problem some postprocessing follows % and the possible |\vbox| is closed by an |\egroup|. % % In particular a visual separation from the next problem is added, % if not suppressed. % In the case of series production the origin date % of the problem is added too.\footnote{Only if it has been % provided to it by the proper macro call, of course.} % % \begin{macrocode} {\par\ifproblemsep \nopagebreak\smallskip\nopagebreak \hbox to\linewidth{\hrulefill \ifseries \emph{\footnotesize\thinspace\the\@problemdate}% \fi}\fi \egroup\par % \end{macrocode} % % Start a new page or separate the problem from the next one by a skip. % % \begin{macrocode} \ifproblempages\newpage\else\bigskip\fi % \end{macrocode} % % The origin date and the communicated value % in macro |\parameter| are cleared for the next problem. % % \begin{macrocode} \reset@problemdate\reset@parameter} % \end{macrocode} % \end{environment} % % \subsection{Code for Options to Problem} % \label{ref:boxing} % % \begin{macro}{\compact} % \begin{macro}{\split} % The options to |problem| are |\compact| or |\split|. % These options govern the possibility for the problem % to be split between successive pages or the necessity % to keep everything on page; the last one being the % favoured behaviour in this implementation. % Note the |\noident| before the |\vbox| that prevents % an unwanted shift to the right. % % \begin{macrocode} \newcommand*\compact{\def\@boxing{\noindent\vbox}} \newcommand*\split{\def\@boxing{}} % \end{macrocode} % \end{macro} % \end{macro} % % % \subsection{Numbering the Problem} % % \begin{macro}{\problemstart} % \begin{macro}{\@problemstart} % A problem gets a standard opening clause, coded in % macro |\@problemstart|. The opening code is used to % format the first paragraph with a nice indentation.\footnote{% % This indentation is also used in the left margin in multiple % choice listings in order to limit the variation in margins.} % % \begin{macrocode} \newcommand*\problemstart{% \hangafter-2\settowidth\hangindent{\@problemstart}% \noindent\llap{\@problemstart}} \newcommand*\@problemstart{% \textbf{\Problem\,\ifnum\value{problemnum}<10 \phantom{0}\fi \theproblemnum}.\enskip} % \end{macrocode} % \end{macro} % \end{macro} % % \subsection{Date of Origin} % % \begin{macro}{\@problemdate} % \begin{macro}{\problemdate} % \begin{macro}{\@resetproblemdate} % The user may specify an original date or date of last change % for the problem to be printed when a series is produced. % The global assignments are here just in case things happen in % a deeper nested level. % % \begin{macrocode} \newtoks\@problemdate \newcommand*\problemdate[1]{\global\@problemdate={#1}\ignorespaces} \newcommand*\reset@problemdate{\global\@problemdate={}} \reset@problemdate % \end{macrocode} % \end{macro} % \end{macro} % \end{macro} % % \subsection{Score Values} % % Associated with each problem are of course the benefits the % student receives for a good answer to (part of) the problem. % \begin{macro}{\score} % The |\score| macro exists for this purpose. % If answers are not included, just an empty square is printed % into which the teacher can express his satisfaction with % the answer given. When answers are included in the printout % the each call |\score{value}| shows up in the right margin % of the document.\footnote{At the end of each problem a summary % of its total score plus a grand total are presented % on the console.} % % \begin{macro}{\totalscore} % \begin{macro}{\scorecounter} % These counters collect the values. Note that |\totalscore| % is reset for each new exam and |\scorecounter| for each problem. % % \begin{macrocode} \newcounter{totalscore}[examnum] \newcounter{scorecounter}[problemnum] % \end{macrocode} % \end{macro} % \end{macro} % % \begin{macro}{\scoreboxsize} % \begin{macro}{\scorebox} % The next commands are used for the production of the box % for the score value. % % \begin{macrocode} \newcommand*\scoreboxsize{6mm} \newcommand*\scorebox[1]{% \fbox{\vbox to\scoreboxsize{\vss\hbox to \scoreboxsize{\hss#1\hss}\vss}}} % \end{macrocode} % \end{macro} % \end{macro} % % Finally the next code puts the score box on paper. % It takes the value of the score as its argument and adds % it to the running sum for this problem. % % \begin{macrocode} \newcommand*\score[1]{% \addtocounter{scorecounter}{#1}% \rightnote{\scorebox{\ifscores#1\fi}}% \ignorespaces} % \end{macrocode} % \end{macro} % % \begin{macro}{\leftnote} % \begin{macro}{\rightnote} % We do not use |\marginpar| for the placement of the score values, % because we do not want these items wandering around, as % |\marginpar|'s sometimes do. % % \begin{macro}{\@rlnote}\mbox{} % \begin{macrocode} \providecommand\leftnote{\@rlnote l} \providecommand\rightnote{\@rlnote r} \providecommand\@rlnote[2]{% \leavevmode\noindent \vadjust{\vbox to\z@{% \leftskip\z@skip\rightskip\z@skip \noindent \if#1l\llap{#2\hskip\marginparsep}% \else\hfill\rlap{\null\hskip\marginparsep\relax#2}\fi \vss\vskip\z@skip }}\ignorespaces} % \end{macrocode} % \end{macro} % \end{macro} % \end{macro} % % \subsection{Adding remarks} % % In making a catalogue of problems (option \emph{series} selected) % it is useful when remarks can be added that stand out against the rest % of the text. % \begin{macro}{\remark} % Macro |\remark| provides such a mechanism. % Its first (optional) argument is set emphasized, its second argument % hangs on the first. The complete remark is placed % in a |\parbox| and then boxed and centered. % % \begin{macrocode} \newcommand\remark[2][]{% \ifseries \begin{center}% \fbox{\parbox{.9\linewidth}{% \sloppy\hangafter\@ne \sbox\@tempboxa{\emph{#1}\@ifemptyarg{#1}{}{:~}}% \hangindent=\wd\@tempboxa \strut\usebox{\@tempboxa}#2}}% \end{center}% \nopagebreak\addvspace{\bigskipamount}\nopagebreak \fi} % \end{macrocode} % \end{macro} % % \section{Answers} % % In this section various ways of typesetting answers are provided. % % \begin{macro}{\longwhite} % \begin{macro}{\shortwhite} % We start with two definitions for long and short stretches of white % space. These are meant for leaving room for the students answer. % % \begin{macrocode} \newcommand*\longwhite{25mm} \newcommand*\shortwhite{8mm} % \end{macrocode} % \end{macro} % \end{macro} % % \begin{macro}{\answerstart} % Just as with the typesetting of the problem, we provide % a macro to start an answer. Note that the text is % parametrized in order to keep switching to other % languages simple. % % \begin{macrocode} \newcommand*\answerstart{\noindent\emph{\Answer}:\enspace} % \end{macrocode} % \end{macro} % % \subsection{Switching Answer On and Off} % % \begin{macro}{\answer} % Macro call |\answer| holds the answer and shows it when % answers are requested. The optional first argument specifies % a width for the box into which the typesetting takes places. % The answer is centered by default; change it with |\hfil|'s. % Implementation of |\answer| is by the next macro |\altanswer|. % \begin{macrocode} \newcommand*\answer[2][]{\altanswer[#1]{}{#2}} % \end{macrocode} % \end{macro} % % \subsection{Alternating Some Stuff and Answer} % % \begin{macro}{\altanswer} % With |\altanswer| the text alternates between two possibilities: % the first one is typeset when answers are suppressed, the second % one for the opposite case. Optional width argument and placement % are the same as for |\answer|. % % \begin{macrocode} \newcommand*\altanswer[3][]{% \@ifemptyarg{#1}% {\mbox{\ifanswers#3\else#2\fi}}% {\makebox[#1]{\ifanswers#3\else#2\fi}}% } % \end{macrocode} % \end{macro} % % \subsection{Problem with a Short Answer} % % \begin{macro}{\shortanswer} % A question ``Give a short answer to \ldots'' is formatted % in |\shortanswer|. Usually the answer will fit on one line. % In the exam a row of dots is produced, otherwise the answer will show. % The optional argument provides the width of the box into which % the data are typeset. % % \begin{macrocode} \newcommand*\shortanswer[1]{\par \ifanswers \addvspace{\smallskipamount}% \settowidth\@tempdima{\answerstart\quad}% \setlength\@tempdimb{\linewidth}% \addtolength\@tempdimb{-\@tempdima}% \answerstart\parbox[t]{\@tempdimb}{\noindent#1}% \par\medskip \else\ifreservespace \addvspace{\shortwhite}% \answerstart\mbox{}\dotfill\quad\mbox{}\par \medskip \fi\fi } % \end{macrocode} % \end{macro} % % \subsection{Problem with a Long Answer} % % \begin{environment}{longanswer} % For elaborate questions, problems, etc.\ an environment is available. % The |longanswer| environment takes as optional argument the length % of white to be reserved for the student. % % Code for opening of the environment. % It opens a box in order to let the answer disappear % and places a rule in order to guarantee sufficient % white space. % % \begin{macrocode} \newenvironment{longanswer}[1][\longwhite]{ \par \ifanswers \addvspace{\medskipamount}\answerstart \nopagebreak\par\noindent \else\ifreservespace \addvspace{\medskipamount}\answerstart \nopagebreak\par\noindent \hrule\@height#1\@width\z@\par \fi \setbox\z@\vbox\bgroup\leavevmode \fi\ignorespaces} % \end{macrocode} % % Aftermath of |longanswer|. If necessary close the box % and empty it to get rid of the answer. % \begin{macrocode} {\ifanswers\par\medskip\else\egroup\setbox\z@\hbox{}\fi} % \end{macrocode} % \end{environment} % % \section{Multiple Choice Questions} % % Multiple choice problems must be placed % in an |choice| environment, a modification % of |itemize|. % % We will make it possible to % shuffle the items of a multiple % choice problem randomly. These items are held in a series % of token registers declared below. % % \begin{macro}{\loadcounter} % \begin{macro}{\resetloadcounter} % \begin{macro}{\incloadcounter} % \begin{macro}{\decloadcounter} % We need a counter into which to keep the number of items % at any time loaded into the token registers declared above. % Also we provide for resetting, incrementing and decrementing % of this register. Note the global assignments. % % \begin{macrocode} \newcount\loadcounter \newcommand*\resetloadcounter{\global\loadcounter\z@} \newcommand*\incloadcounter{\global\advance\loadcounter\@ne} \newcommand*\decloadcounter{\global\advance\loadcounter\m@ne} % \end{macrocode} % \end{macro} % \end{macro} % \end{macro} % \end{macro} % % We want a specific behaviour when the list of items is typeset. % However, we cannot be sure at which listlevel this will occur. % \begin{macro}{\@listk} % Therefore we predeclare a replacement for |\@listi|, |\@listii|, % or whatsoever, and swap the |\@list..| at the right time. % Note the choice for the leftside margin, derived from the % width of the text with which the problem starts. This choice % diminishes the number of different margins. It is easily adapted % to your own taste. % % \begin{macrocode} \newcommand*\@listk{% \settowidth{\leftmargin}{\@problemstart}% \topsep\medskipamount \partopsep\z@ \itemsep\smallskipamount \parsep\z@} % \end{macrocode} % \end{macro} % % \subsection{Typesetting Multiple Choice} % % \begin{environment}{choice} % The multiple choice environment |choice| takes one argument, % the modifier options to the environment typesetting. % Here the options are |\random| and |\ordered|; the names % speak for themselves. Note that random permutation is not % executed if a series is run. Furthermore the counter % for the number of items loaded is reset. % % \begin{macrocode} \newenvironment{choice}[1][]{% \ifseries\ordered\else\random\fi#1\relax \resetloadcounter % \end{macrocode} % % The following code is taken from \LaTeX's |itemize|. % I did not find a more elegant way to bend this environment % to my whims. % % \begin{macrocode} \ifnum\@itemdepth>3 \@toodeep \else \advance\@itemdepth\@ne \expandafter\let \csname @list\romannumeral\the\@itemdepth\endcsname=\@listk \list{\badmark}{\def\makelabel##1{\hss\llap{##1}}}% \fi}% % \end{macrocode} % % At the end of |choice| we dump all the items that may have been % collected inbetween and finish the |list|. % % \begin{macrocode} {\@dumpitems\endlist} % \end{macrocode} % \end{environment} % % \subsection{Code for Options to Choice} % % \begin{macro}{\random} % The option |\random| codes macros |\@loaditem| and % |\@dumpitems| so that the items are actually loaded, % then shuffled and dumped afterwards. % \begin{macro}{\ordered} % The |\ordered| option makes them noops and thus the % items will be typeset on the fly. % % \begin{macrocode} \newcommand*\random{% \def\@loaditem{\loaditem}% \def\@dumpitems{\shuffle\dumpitems}} \newcommand*\ordered{\def\@loaditem{}\def\@dumpitems{}} % \end{macrocode} % \end{macro} % \end{macro} % % \subsection{Formatting the Item Mark} % % \begin{macro}{\marksize} % \begin{macro}{\badmark} % \begin{macro}{\goodmark} % We require two marks: one for the bad guys and one % for the good guy. We use the two symbols |\square| and |\boxtimes|, % but provide replacements (later on, after giving exam.cfg a chance % to define them) in case these are undefined. % Typeset these marks in fixed size (unchanged baselineskip) % provided by macro |\marksize|. % % \begin{macrocode} \newcommand*\marksize{\fontsize{12}{\f@baselineskip}\selectfont} \newcommand*\badmark{{\marksize\ensuremath{\square}}} \newcommand*\goodmark{% \ifanswers{\marksize\ensuremath{\boxtimes}}\else\badmark\fi} % \end{macrocode} % \end{macro} % \end{macro} % \end{macro} % % \begin{macro}{\baditem} % \begin{macro}{\gooditem} % Each item can either be right or wrong. We take the precaution % to suppress the difference when typesetting the actual exam. % Enclose each item in your list in the argument to % |\gooditem| and |\baditem|. They % will load the item in memory prior to (possible) random shuffling. % % \begin{macrocode} \newcommand*\baditem[1]{\@loaditem{\item[\badmark]#1}} \newcommand*\gooditem[1]{\@loaditem{\item[\goodmark]#1}} % \end{macrocode} % \end{macro} % \end{macro} % % \subsection{Loading and Dumping Items} % % \begin{macro}{\@itemA} % \begin{macro}{\@itemB} % \begin{macro}{\@itemC} % \begin{macro}{\@itemD} % \begin{macro}{\@itemE} % This series of token registers % can hold five alternatives. The mechanism that loads the % items is sufficiently general to use it for other purposes too. % Use your imagination! % That there are five of them is remembered in a definition % because we will need this number to prevent overfilling the store. % % \begin{macro}{\@itemstore}\mbox{} % \begin{macrocode} \newtoks\@itemA \newtoks\@itemB \newtoks\@itemC \newtoks\@itemD \newtoks\@itemE \newcommand\@itemstore{5} % \end{macrocode} % \end{macro} % \end{macro} % \end{macro} % \end{macro} % \end{macro} % \end{macro} % % \begin{macro}{\loaditem} % According to the value of |loadcounter| the token registers % |\@itemA|, etc.\ are filled. Argument to macro |\loaditem| % is the contents of the item. % % \begin{macrocode} \newcommand\loaditem[1]{% \ifcase\loadcounter \@itemA={#1}% \or\@itemB={#1}% \or\@itemC={#1}% \or\@itemD={#1}% \or\@itemE={#1}% \fi \ifnum\loadcounter<\@itemstore \incloadcounter \else\examwarning{\string\loaditem\space ignored, too many}\fi} % \end{macrocode} % \end{macro} % % \begin{macro}{\dumpitemno} % Produce items that were loaded. % % \begin{macrocode} \newcommand*\dumpitemno[1]{% \ifnum#1>\loadcounter \examwarning{\string\dumpitemno[#1] ignored, out range}% \else\ifcase#1\relax \or\the\@itemA \or\the\@itemB \or\the\@itemC \or\the\@itemD \or\the\@itemE \fi\fi} % \end{macrocode} % \end{macro} % % \begin{macro}{\dumpitem} % \begin{macro}{\dumpitems} % With |\dumpitem| the last one comes out and is chopped off % from the stack, with |\dumpitems| the whole lot is dumped. % By means of |\dumpitemno| one can peek inside the stack: % its parameter gives the position to be produced, the item itself % remains on the stack. % \begin{macrocode} \newcommand*\dumpitem{\dumpitemno{\loadcounter}\decloadcounter} \newcommand*\dumpitems{\@whilenum\loadcounter>\z@\do{\dumpitem}} % \end{macrocode} % \end{macro} % \end{macro} % % \subsubsection{Shuffling Items} % % \begin{macro}{\shuffle} % This macro permutes |loadcounter| items in the % token registers |\@itemA|, etc. Undoubtedly it % can be done better, but who's perfect? % % \begin{macrocode} \newcommand*\shuffle{% \ifcase\loadcounter \or \or\shuffle@ii \or\shuffle@\@itemA\@itemC \shuffle@ii \shuffle@\@itemB\@itemC \or\shuffle@iv \or\shuffle@\@itemD\@itemE \shuffle@iv \shuffle@\@itemD\@itemE \fi } % \end{macrocode} % \end{macro} % % \begin{macro}{\shuffle@} % \begin{macro}{\shuffle@ii} % \begin{macro}{\shuffle@iv} % \begin{macro}{\@item@} % Random interchange of two and four items. % % \begin{macrocode} \newtoks\@item@ \newcommand*\shuffle@[2]{\SRtest{}{\@item@=#1 #1=#2 #2=\@item@}} \newcommand*\shuffle@ii{\shuffle@\@itemA\@itemB} \newcommand*\shuffle@iv{% \SRtest{\shuffle@\@itemA\@itemB}{\shuffle@\@itemC\@itemD}% \SRtest{\shuffle@\@itemA\@itemC}{\shuffle@\@itemB\@itemD}} % \end{macrocode} % \end{macro} % \end{macro} % \end{macro} % \end{macro} % % \subsubsection{Random Generator Implementation} % % \begin{macro}{\SRset} % \begin{macro}{\SRbit} % \begin{macro}{\SRtest} % \begin{macro}{\SRvalue} % Not much commentary with these macros. They are % described in Tugboat~1994, vol.~15.1, p.~57--58. % % \begin{macro}{\@SR} % \begin{macro}{\@SRconst} % \begin{macro}{\@SRadvance}\mbox{} % \begin{macrocode} \ifx\@SR\undefined\newcount\@SR\fi \providecommand\@SRconst{2097152} \providecommand\SRset[1]{\global\@SR#1 \ignorespaces} \providecommand\@SRadvance{% \begingroup \ifnum\@SR<\@SRconst\relax\count@\z@\else\count@\@ne\fi \ifodd\@SR\advance\count@\@ne\fi \global\divide\@SR\tw@ \ifodd\count@\global\advance\@SR\@SRconst\relax\fi \endgroup} \providecommand\SRbit{\@SRadvance\ifodd\@SR1\else0\fi} \providecommand\SRtest[2]{\@SRadvance \ifodd\@SR#2\else#1\fi\ignorespaces} \providecommand\SRvalue{\number\@SR } \SRset{0} % \end{macrocode} % \end{macro} % \end{macro} % \end{macro} % \end{macro} % \end{macro} % \end{macro} % \end{macro} % % \section{Page Style} % % \begin{macro}{\thehead} % For a page style |examheadings| is offered. % Choose it by supplying to |\pagestyle|. % % \begin{macro}{\ps@examheadings}\mbox{} % \begin{macrocode} \newcommand*\thehead{% \textsl{\@title\enspace:\enspace \ifseries\namesection\else\@date\fi}} \newcommand*\ps@examheadings{% \let\@oddfoot\@empty \let\@evenfoot\@empty \renewcommand*\@oddhead{% \vbox{% \hbox to\textwidth{\headerfont\thehead\hfil\upshape\thepage}% \vskip1.5\p@ \hrule\@height.5\p@\@width\textwidth }}% \let\@evenhead\@oddhead} % \end{macrocode} % \end{macro} % \end{macro} % % \section{Titlepage} % % \begin{macro}{\target} % With target we denote the group of students for whom % the exam is meant. Defined with |\target| and called up % with |\@target|, just like |\author|, etc. % % \begin{macrocode} \newcommand*\target[1]{\gdef\@target{#1}}\def\@target{} % % \end{macrocode} % \end{macro} % % The titlepage is best set by a redefined |\maketitle|. Of course it % needs to be suppressed if the \texttt{notitlepage} option is given % on the |\documentclass| call. Provide two versions, one % for a real exam and one for collections and/or answers. % See the example below, supplied in \emph{exam.cfg}. % % The titlepage is set by a redefined |\maketitle|. Of course it % needs to be suppressed if the notitlepage option is given % on the |\documentclass| call. Provided are two versions, one % for a real exam and one for collections and/or answers. % % \subsection{Example titlepage} % % \begin{macrocode} %<*cfg> % \if@titlepage \renewcommand*\maketitle{% \begin{titlepage} \begin{center}\titlefont \vspace*{1cm}% \mbox{}\rule{2cm}{0.4pt}\mbox{}\par \addvspace{1cm}% \begin{Large} \textbf{\ifseries\Collection\else\Exam\fi}\\[10mm] \end{Large} \begin{large} \@title\\[5mm] \ifseries\@author\else\@target\fi\\[5mm] \@date\\[10mm] \end{large} \mbox{}\rule{2cm}{0.4pt}\mbox{}\par \addvspace{2cm}% \ifseries \vfill\vfill \begin{flushleft}\emph{Copyright notice, if any.}\end{flushleft}% \else\ifanswers \begin{huge}\Answers\end{huge}\par \else \begin{minipage}{.75\textwidth}% \raggedright\parindent\medskipamount Name:\enspace\dotfill\strut\par Address:\enspace\dotfill\strut\par City:\enspace\dotfill\strut\par Student number:\enspace\dotfill\strut\par \vspace{1cm}% \begin{itemize}% \item Please write legible, what cannot be read cannot be given credit. \item Put your name and student number on all on all separate sheets of paper. \item This exam has \theproblemnum\ problems. \end{itemize}% \end{minipage}\\[10mm] Good luck!\par \fi \fi \end{center}% \end{titlepage}\let\maketitle=\relax} % \end{macrocode} % % And in case no title page requested: % % \begin{macrocode} \else\let\maketitle=\relax\fi % % \end{macrocode} % % % \section{Language Dependent Items} % % \begin{macro}{\Exam} % \begin{macro}{\Collection} % \begin{macro}{\Answers} % \begin{macro}{\Answer} % \begin{macro}{\Problem} % Predefine all language specific macros, % default is the English language. % % \begin{macrocode} %<*cls> \newcommand*\Exam{EXAM} \newcommand*\Collection{COLLECTION OF EXAMS} \newcommand*\Answers{ANSWERS} \newcommand*\Answer{Answer} \newcommand*\Problem{Problem} % \end{macrocode} % \end{macro} % \end{macro} % \end{macro} % \end{macro} % \end{macro} % % \subsection{Dutch equivalents} % % \begin{macrocode} % %<*cfg> \renewcommand*\Answers{ANTWOORDEN} \renewcommand*\Answer{Antwoord} \renewcommand*\Exam{TENTAMEN} \renewcommand*\Collection{TENTAMENBUNDEL} \renewcommand*\Problem{Opgave} % %<*cls> % \end{macrocode} % % \section{Initializations} % % \subsection{Fonts} % % \begin{macro}{\headerfont} % \begin{macro}{\bodyfont} % \begin{macro}{\titlefont} % Fonts for pageheader, body of the text and on the titlepage. % % \begin{macrocode} \newcommand*\headerfont{\rmfamily\small} \newcommand*\bodyfont{\sffamily} \newcommand*\titlefont{\rmfamily\upshape} % \end{macrocode} % \end{macro} % \end{macro} % \end{macro} % % And initialize to |\bodyfont|. % % \begin{macrocode} \bodyfont % \end{macrocode} % % \subsection{Directory Localization} % % \begin{macro}{\CurrentDirectory} % \begin{macro}{\DirectorySeparator} % We can determine from |\@currdir| which % character separates directories in a path name. % E.g. in UNIX this is |/| from the string |./|, but % in the MacOS the current directory and the separator are both |:|. % Therefore we extract from |\@currdir| the last character % (of two at most).\\ % Make |\CurrentDirectory| a synonyme for |\@currdir|. % % \begin{macrocode} \let\CurrentDirectory=\@currdir \def\DirectorySeparator#1#2`\^^M{\@ifemptyarg{#2}{#1}{#2}} \edef\DirectorySeparator{% \expandafter\DirectorySeparator\CurrentDirectory`\^^M} % \end{macrocode} % \end{macro} % \end{macro} % % \begin{macro}{\LastChar} % Another macro delivers the last character of a string. % % \begin{macrocode} \providecommand*{\LastChar}[1]{% \@ifemptyarg{#1}{}{\expandafter\@lastchar#1`\^^M}} \def\@lastchar#1#2`\^^M{\@ifemptyarg{#2}{#1}{\@lastchar#2`\^^M}} % \end{macrocode} % \end{macro} % % \begin{macro}{\DirectoryName} % The next macro ensures that a path name ends correctly, when % a filename is concatenated with it. % If the directory separator character isn't the last character, % it is added. % % \begin{macrocode} \providecommand*{\DirectoryName}[1]{\@ifemptyarg{#1}{}% {\if\LastChar{#1}\DirectorySeparator\relax#1\else #1\DirectorySeparator\fi}} % \end{macrocode} % \end{macro} % % \begin{macro}{\Setfolder} % Macro |\Setfolder| can be used to install a standard % folder (directory) name. % E.g. a name |\figuresfolder| can be defined as the % standard place for figures. % Supply as first argument to |\Setfolder| the macro name % for the folder. e.g. |\figuresfolder| and as second % parameter its location on disk. % Below three of these folders (here initialized % with empty names) are defined in the example configuration file. % \begin{macrocode} \newcommand*\Setfolder[2]{\edef#1{\DirectoryName{#2}}} % %<*cfg> \Setfolder{\mainfolder}{} \Setfolder{\commonfolder}{} \Setfolder{\figuresfolder}{} % %<*cls> % \end{macrocode} % \end{macro} % % \subsection{Configuration File} % % Last, but not least, see if there is a configuration % file \texttt{exam.cfg} and read it for the final adjustments. % % \begin{macrocode} \InputIfFileExists{exam.cfg}{}{} % \end{macrocode} % % \subsection{Macros Needed but Possibly Missing} % % \begin{macro}{\square} % \begin{macro}{\boxtimes} % Possibly the following macros are still undefined; here we guarantee % they are available. You may define them yourselves in % \emph{exam.cfg} or in your document. % % \begin{macrocode} \providecommand\square{\bigcirc} \providecommand\boxtimes{\surd} % \end{macrocode} % \end{macro} % \end{macro} % \begin{macrocode} % % \end{macrocode} % % \section{Coding of Example Questions} % % \begin{macrocode} %<*exa> \begin{problem} \problemdate{\today} What is the question? \score{2} \shortanswer{To be or not to be.} \end{problem} % % \end{macrocode} % % \begin{macrocode} %<*exb> \parameterproblem{1= to be\\2= not to be} \problemdate{\today} \begin{problem} \score{2} What is\ifnum\parameter=1\relax\else n't\fi\ the question? \shortanswer{\ifnum\parameter=1\relax To be or n\else N\fi ot to be.} \end{problem} % % \end{macrocode} % \Finale %