| 1 |
% \def\EmailAddress{[email protected]} |
| 2 |
% \iffalse meta-comment |
| 3 |
% |
| 4 |
% Program mathexam |
| 5 |
% Copyright (C) 2007 Jan Hlavacek |
| 6 |
% |
| 7 |
% This program may be distributed and/or modified under the |
| 8 |
% conditions of the LaTeX Project Public License, either version 1.2 |
| 9 |
% of this license or (at your option) any later version. |
| 10 |
% The latest version of this license is in |
| 11 |
% http://www.latex-project.org/lppl.txt |
| 12 |
% and version 1.2 or later is part of all distributions of LaTeX |
| 13 |
% version 1999/12/01 or later. |
| 14 |
% |
| 15 |
% The Program's files are mathexam.dtx, mathexam.ins and mathexam.sty. |
| 16 |
% |
| 17 |
% Run latex with the input file mathexam.ins to generate the mathexam.sty |
| 18 |
% package file. Run latex with the input file mathexam.dtx to generate the |
| 19 |
% package documentation. |
| 20 |
% |
| 21 |
% \fi |
| 22 |
% |
| 23 |
% \CheckSum{179} |
| 24 |
% |
| 25 |
% \CharacterTable |
| 26 |
% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z |
| 27 |
% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z |
| 28 |
% Digits \0\1\2\3\4\5\6\7\8\9 |
| 29 |
% Exclamation \! Double quote \" Hash (number) \# |
| 30 |
% Dollar \$ Percent \% Ampersand \& |
| 31 |
% Acute accent \' Left paren \( Right paren \) |
| 32 |
% Asterisk \* Plus \+ Comma \, |
| 33 |
% Minus \- Point \. Solidus \/ |
| 34 |
% Colon \: Semicolon \; Less than \< |
| 35 |
% Equals \= Greater than \> Question mark \? |
| 36 |
% Commercial at \@ Left bracket \[ Backslash \\ |
| 37 |
% Right bracket \] Circumflex \^ Underscore \_ |
| 38 |
% Grave accent \` Left brace \{ Vertical bar \| |
| 39 |
% Right brace \} Tilde \~} |
| 40 |
% |
| 41 |
% \iffalse |
| 42 |
%<*driver> |
| 43 |
\ProvidesFile{mathexam.dtx} |
| 44 |
%</driver> |
| 45 |
%<package,ls>\NeedsTeXFormat{LaTeX2e} |
| 46 |
%<package>\ProvidesPackage{mathexam} |
| 47 |
%<*package> |
| 48 |
[2007/07/30 v1.00 Package for typesetting exams] |
| 49 |
%</package> |
| 50 |
%<*driver> |
| 51 |
\documentclass{ltxdoc} |
| 52 |
\usepackage[nohdr]{mathexam}[2007/07/30] |
| 53 |
\usepackage{hyperref} |
| 54 |
\EnableCrossrefs |
| 55 |
\CodelineIndex |
| 56 |
\RecordChanges |
| 57 |
\begin{document} |
| 58 |
\DocInput{mathexam.dtx} |
| 59 |
\PrintChanges |
| 60 |
\PrintIndex |
| 61 |
\end{document} |
| 62 |
%</driver> |
| 63 |
% \fi |
| 64 |
% |
| 65 |
% \GetFileInfo{mathexam.dtx} |
| 66 |
% |
| 67 |
% \DoNotIndex{\newcommand,\newenvironment} |
| 68 |
% |
| 69 |
% \changes{1.00}{2007/07/30}{Rewrote as a .dtx file for distribution} |
| 70 |
% |
| 71 |
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 72 |
% |
| 73 |
% \title{\bf The \textsf{mathexam} Package\thanks{This document |
| 74 |
% describes the version number \fileversion, last |
| 75 |
% revised \filedate.}} |
| 76 |
% |
| 77 |
% \author{Jan Hlavacek\\ |
| 78 |
% \small Email: \texttt{\EmailAddress}} |
| 79 |
% \date{30 July 2007} |
| 80 |
% \maketitle |
| 81 |
% |
| 82 |
% \begin{abstract} |
| 83 |
% This package can help you typeset exams (mostly in mathematics and related |
| 84 |
% disciplines where students are required to show their calculations followed by |
| 85 |
% one or more short answers). It provides commands for inclusion of space for |
| 86 |
% calculations, as well as commands for automatic creation of ``answer spaces''. |
| 87 |
% In addition, the package will automatically create page headers and footers, |
| 88 |
% and will let you include instructions and space for students to put their |
| 89 |
% name. |
| 90 |
% \end{abstract} |
| 91 |
% \thispagestyle{empty} |
| 92 |
% \tableofcontents |
| 93 |
% \section{Introduction} |
| 94 |
% |
| 95 |
% There are several classes and packages for typesetting exams in \LaTeX\ |
| 96 |
% available. However, I found out that none of them satisfy my needs. Some of |
| 97 |
% the classes and packages are very sophisticated, providing commands and |
| 98 |
% environments for things like fill in the blank, true/false and multiple choice |
| 99 |
% questions. In contrast, nearly all exams in my lower level undergraduate math |
| 100 |
% classes (including exams I took myself as an undergraduate) have basically the |
| 101 |
% same format: a list of questions, each followed by a vertical space for |
| 102 |
% students to do their calculations, each optionally followed by one or more |
| 103 |
% reserved spaces for students to write their final answers. |
| 104 |
% |
| 105 |
% Some of my colleagues use various word-processing softwares to type their |
| 106 |
% exams. Because of limitations of these programs, they usually end up typing |
| 107 |
% each questions, followed by bunch of blank lines, followed by something like |
| 108 |
% ``Answer underscore underscore underscore \ldots'', carefully inserting just |
| 109 |
% the right number of blank lines so that the each question will be on the same |
| 110 |
% page as its corresponding ``Answer:\ldots'', and the last ``Answer:\ldots'' on |
| 111 |
% each page will be somewhat close to the bottom of the page. This works fine |
| 112 |
% as long as you don't change the questions, the font, margins, and as long as |
| 113 |
% you always use the same printer to print the exam. Every time you do anything |
| 114 |
% that results in a change in pagination, you have to go back and insert or |
| 115 |
% delete blank lines in order to have everything align correctly again. |
| 116 |
% |
| 117 |
% \TeX\, with its stretchable vertical glue, can easily solve this |
| 118 |
% problem. This package provides a way for easy inclusion of vertical space |
| 119 |
% after questions, as well as single or multiple ``answer spaces''. |
| 120 |
% It does not take care of things like numbering of questions (I prefer to use |
| 121 |
% standard \LaTeX\ list making environments), tracking the number of points, |
| 122 |
% etc. |
| 123 |
% |
| 124 |
% \section{Installation} |
| 125 |
% |
| 126 |
% To install this package, simply run \LaTeX\ with the input file |
| 127 |
% \texttt{mathexam.ins} like this: |
| 128 |
% \begin{verbatim} |
| 129 |
% $ latex mathexam.ins |
| 130 |
% \end{verbatim} |
| 131 |
% That will create the file \texttt{mathexam.sty}. You need to move this file to |
| 132 |
% a place where \LaTeX\ can find it. |
| 133 |
% |
| 134 |
% To generate documentation for this package, run \LaTeX\ with the input file |
| 135 |
% \texttt{mathexam.dtx} instead, like |
| 136 |
% \begin{verbatim} |
| 137 |
% $ latex mathexam.dtx |
| 138 |
% \end{verbatim} |
| 139 |
% to generate the documentation in the \texttt{.dvi} format, or |
| 140 |
% \begin{verbatim} |
| 141 |
% $ pdflatex mathexam.dtx |
| 142 |
% \end{verbatim} |
| 143 |
% to create a \texttt{pdf} file. |
| 144 |
% |
| 145 |
% \section{Usage} \label{usage} |
| 146 |
% |
| 147 |
% To use the package, all you have to do is include |\usepackage{mathexam}| in |
| 148 |
% the preamble of your document: |
| 149 |
% \begin{verbatim} |
| 150 |
% \documentclass[11pt]{article} |
| 151 |
% \usepackage{mathexam} |
| 152 |
% \end{verbatim} |
| 153 |
% |
| 154 |
% \DescribeMacro{nohdr} |
| 155 |
% Normally, the \texttt{mathexam} package automatically generates headers and |
| 156 |
% footers for each page, containing information about the exam. In order to do |
| 157 |
% that, the package uses several other packages, namely \texttt{fancyhdr}, |
| 158 |
% \texttt{lastpage} and \texttt{ifthen}. These packages have to be installed on |
| 159 |
% your computer if you want the \texttt{mathexam} package generate headers. If |
| 160 |
% you don't have all of these packages, or if for some reason you don't want the |
| 161 |
% \texttt{mathexam} package to generate headers (you have your own way to |
| 162 |
% include headers, for example), you can call the \texttt{mathexam} package with |
| 163 |
% \texttt{nohdr} option: |
| 164 |
% \begin{verbatim} |
| 165 |
% \documentclass[11pt]{article} |
| 166 |
% \usepackage[nohdr]{mathexam} |
| 167 |
% \end{verbatim} |
| 168 |
% |
| 169 |
% \subsection{Main Commands} |
| 170 |
% |
| 171 |
% \DescribeMacro{\answer} |
| 172 |
% The command |\answer| inserts a stretchable vertical space followed by a |
| 173 |
% generic ``answer space'': |
| 174 |
% \begin{verbatim} |
| 175 |
% What is $1+1$? \answer |
| 176 |
% \end{verbatim} |
| 177 |
% produces: |
| 178 |
% |
| 179 |
% What is $1+1$? \answer |
| 180 |
% |
| 181 |
% \DescribeMacro{\addanswer} |
| 182 |
% The command |\addanswer| works just like |\answer| except that it does not |
| 183 |
% insert any extra vertical space. It can be used for example in situation where we |
| 184 |
% need two ``answer spaces'' immediately following each other: |
| 185 |
% \begin{verbatim} |
| 186 |
% Product of two numbers equals 24, while their sum is 10. What are the |
| 187 |
% numbers? \answer\addanswer |
| 188 |
% \end{verbatim} |
| 189 |
% produces: |
| 190 |
% |
| 191 |
% Product of two numbers equals 24, while their sum is 10. What are the |
| 192 |
% numbers? \answer\addanswer |
| 193 |
% |
| 194 |
% \subsection{Optional Arguments} |
| 195 |
% |
| 196 |
% In the examples above, there is a stretchable vertical glue between the text |
| 197 |
% of each problem and the ``answer space''. You cannot really see it in this |
| 198 |
% document, since the problems are surrounded by other text and we let \LaTeX\ |
| 199 |
% decide where to break the page. Normally, you would insert |\newpage| after |
| 200 |
% several problems, which would make the problems nicely distributed on the |
| 201 |
% page. |
| 202 |
% |
| 203 |
% Sometimes you want to make sure that certain problem has enough space for |
| 204 |
% students to write down their work. You can specify an exact amount of space between |
| 205 |
% the text of the problem and the ``answer space'' using an optional argument |
| 206 |
% with the |\answer| or |\addanswer| commands: |
| 207 |
% \begin{verbatim} |
| 208 |
% What is $1+1$? \answer[1in] |
| 209 |
% \end{verbatim} |
| 210 |
% produces: |
| 211 |
% |
| 212 |
% What is $1+1$? \answer[1in] |
| 213 |
% |
| 214 |
% Here, the space between the text of the problem and the ``answer space'' will |
| 215 |
% be 1 inch. In this aspect, |\addanswer[1in]| will work the exact same way. |
| 216 |
% The argument can be any glue, for example if you want to include at least one inch, |
| 217 |
% which can possibly stretch further, you can do |\answer[1in plus 1fill]| |
| 218 |
% |
| 219 |
% \subsection{Changing Labels for ``Answer Spaces''} |
| 220 |
% |
| 221 |
% Often you want to use different text instead of the default ``Answer:'' label |
| 222 |
% for an ``answer space''. This can easily be done with the ``stared'' version |
| 223 |
% of the commands. The commands |\answer*| and |\addanswer*| take one mandatory |
| 224 |
% argument (in addition to the optional argument described above) with the text |
| 225 |
% you want to use for the label. For example |
| 226 |
% \begin{verbatim} |
| 227 |
% Find the first two derivatives of the function $f(x) = x^2\cos(x)$. Simplify |
| 228 |
% your answers as much as possible. Show all your work. |
| 229 |
% \answer*[1in]{$f'(x)=$}\answer*[1in]{$f''(x)=$} |
| 230 |
% \end{verbatim} |
| 231 |
% produces |
| 232 |
% |
| 233 |
% Find the first two derivatives of the function $f(x) = x^2\cos(x)$. Simplify |
| 234 |
% your answers as much as possible. Show all your work. |
| 235 |
% \answer*[1in]{$f'(x)=$}\answer*[1in]{$f''(x)=$} |
| 236 |
% |
| 237 |
% Notice that here, vertical spaces before both of the ``answer spaces'' will be |
| 238 |
% 1 inch long. |
| 239 |
% In the following example, the answer spaces for $x$ and $y$ will be right |
| 240 |
% above each other: |
| 241 |
% \begin{verbatim} |
| 242 |
% If $x + y = 10$ and $2x - y = 8$, find $x$ and $y$. |
| 243 |
% \answer*[1in]{$x=$}\addanswer*{$y=$} |
| 244 |
% \end{verbatim} |
| 245 |
% produces |
| 246 |
% |
| 247 |
% If $x + y = 10$ and $2x - y = 8$, find $x$ and $y$. |
| 248 |
% \answer*[1in]{$x=$}\addanswer*{$y=$} |
| 249 |
% |
| 250 |
% \subsection{No ``Answer Space''} |
| 251 |
% |
| 252 |
% Sometimes you will have problems where the work is the answer, or the answer |
| 253 |
% is too long to fit into a short ``answer space''. For that purpose, the |
| 254 |
% package defines the |\noanswer| command. |
| 255 |
% |
| 256 |
% \DescribeMacro{\noanswer} |
| 257 |
% This command will simply include a stretchable vertical space after the |
| 258 |
% problem. Again, as with |\answer| and |\addanswer|, the command takes one |
| 259 |
% optional argument, which is an optional length of the vertical space. |
| 260 |
% |
| 261 |
% \subsection{Other Commands} |
| 262 |
% |
| 263 |
% The package provides several other commands for things like identifying the |
| 264 |
% exam, giving instructions to students, including space for student's name etc. |
| 265 |
% |
| 266 |
% \DescribeMacro{\ExamName}\DescribeMacro{\ExamClass}\DescribeMacro{\ExamHead} |
| 267 |
% The commands |\ExamName|, |\ExamClass| and |\ExamHead| are used for |
| 268 |
% identifying the exam. They will determine how will the headers of the exam |
| 269 |
% pages look like. For example, in the preamble of your document you could |
| 270 |
% specify |
| 271 |
% \begin{verbatim} |
| 272 |
% \ExamName{Final Exam} |
| 273 |
% \ExamClass{Calculus III} |
| 274 |
% \ExamHead{\today} |
| 275 |
% \end{verbatim} |
| 276 |
% The \texttt{mathexam} package will use the \texttt{fancyhdr} package to |
| 277 |
% include this information in the page headers. |
| 278 |
% |
| 279 |
% \DescribeMacro{\ExamNameLine} |
| 280 |
% The |\ExamNameLine| command can be used to include a line on which students |
| 281 |
% can write their name: |
| 282 |
% \begin{verbatim} |
| 283 |
% \ExamNameLine |
| 284 |
% \end{verbatim} |
| 285 |
% produces |
| 286 |
% |
| 287 |
% \ExamNameLine |
| 288 |
% |
| 289 |
% \DescribeMacro{\ExamInstrBox} |
| 290 |
% The command |\ExamInstrBox| lets you include some basic instructions to |
| 291 |
% students taking the exam. Example: |
| 292 |
% \begin{verbatim} |
| 293 |
% \ExamInstrBox{Please show all your work! Answers without supporting work will |
| 294 |
% not be given credit. Write answers in spaces provided. You have 1 hour and 50 |
| 295 |
% minutes to complete this exam.} |
| 296 |
% \end{verbatim} |
| 297 |
% produces |
| 298 |
% |
| 299 |
% \ExamInstrBox{Please show all your work! Answers without supporting work will |
| 300 |
% not be given credit. Write answers in spaces provided. You have 1 hour and 50 |
| 301 |
% minutes to complete this exam.} |
| 302 |
% |
| 303 |
% \section{Notes} |
| 304 |
% |
| 305 |
% \subsection{TODO} |
| 306 |
% |
| 307 |
% There are several things I plan to improve in the future: |
| 308 |
% \begin{itemize} |
| 309 |
% \item Some basic internationalization (right now everything is in English) |
| 310 |
% \item Add some code for printing point value of problems. |
| 311 |
% \end{itemize} |
| 312 |
% If you have any other suggestions, please contact me. |
| 313 |
% |
| 314 |
% \subsection{Bugs, Suggestions, Comments\ldots} |
| 315 |
% |
| 316 |
% If you find any bugs, or have any suggestions, comments, patches etc.~please |
| 317 |
% let me know at \texttt{\EmailAddress}. |
| 318 |
% \StopEventually{} |
| 319 |
% |
| 320 |
% \section{Implementation} |
| 321 |
% |
| 322 |
% First we will process options: |
| 323 |
% \begin{macrocode} |
| 324 |
\newif\ifExamHdr |
| 325 |
\ExamHdrtrue |
| 326 |
\DeclareOption{nohdr}{\ExamHdrfalse} |
| 327 |
\ProcessOptions |
| 328 |
% \end{macrocode} |
| 329 |
% |
| 330 |
% If ExamHdr is true, we load some packages we need |
| 331 |
% \begin{macrocode} |
| 332 |
\ifExamHdr |
| 333 |
\RequirePackage{fancyhdr} |
| 334 |
\RequirePackage{lastpage} |
| 335 |
\RequirePackage{ifthen} |
| 336 |
\fi |
| 337 |
% \end{macrocode} |
| 338 |
% |
| 339 |
% \begin{macro}{\ExamName} |
| 340 |
% \begin{macro}{\ExamClass} |
| 341 |
% \begin{macro}{\ExamHead} |
| 342 |
% Here we will set up macros that handle exam headers and footers. First we |
| 343 |
% will define the three commands that provide a user interface: |
| 344 |
% \begin{macrocode} |
| 345 |
\newcommand{\ExamName}[1]{\def\@xamname{#1}} |
| 346 |
\newcommand{\ExamClass}[1]{\def\@xamclass{#1}} |
| 347 |
\newcommand{\ExamHead}[1]{\def\@xamrighthdr{#1}} |
| 348 |
% \end{macrocode} |
| 349 |
% Then we will initialize the internal macros to some default values: |
| 350 |
% \begin{macrocode} |
| 351 |
\def\@xamname{\relax} |
| 352 |
\def\@xamclass{\relax} |
| 353 |
\def\@xamrighthdr{\relax} |
| 354 |
% \end{macrocode} |
| 355 |
% If ExamHdr is true, set up the fancy headers: |
| 356 |
% \begin{macrocode} |
| 357 |
\ifExamHdr |
| 358 |
\pagestyle{fancy} |
| 359 |
|
| 360 |
\lhead{\@xamclass} |
| 361 |
\chead{\@xamname} |
| 362 |
\rhead{Page \thepage\ of \pageref{LastPage}} |
| 363 |
|
| 364 |
\rfoot{\ifthenelse{\value{page}=\pageref{LastPage}}{The End.}{Cont.}} |
| 365 |
\cfoot{} |
| 366 |
% \end{macrocode} |
| 367 |
% Handle the first page differently: |
| 368 |
% \begin{macrocode} |
| 369 |
\AtBeginDocument{ |
| 370 |
\begin{center} |
| 371 |
\large\scshape \@xamclass \hfill \@xamname \hfill \@xamrighthdr |
| 372 |
\end{center}} |
| 373 |
|
| 374 |
\thispagestyle{empty} |
| 375 |
\fi |
| 376 |
% \end{macrocode} |
| 377 |
% \end{macro} |
| 378 |
% \end{macro} |
| 379 |
% \end{macro} |
| 380 |
% |
| 381 |
% \begin{macro}{\answer} |
| 382 |
% \begin{macro}{\addanswer} |
| 383 |
% Prepare auxiliary commands for |\answer| and |\addanswer|. First the regular |
| 384 |
% (non-stared) version: |
| 385 |
% \begin{macrocode} |
| 386 |
\newcommand{\answ@r}[1][\fill]{% |
| 387 |
\nopagebreak\vspace{#1}\par\nopagebreak\hfill\hbox to |
| 388 |
.5\columnwidth{Answer:\hrulefill}\vspace{\baselineskip}} |
| 389 |
|
| 390 |
\newcommand{\addansw@r}[1][\baselineskip]{% |
| 391 |
\nopagebreak\vspace{#1}\par\nopagebreak\hfill\hbox to |
| 392 |
.5\columnwidth{Answer:\hrulefill}\vspace{\baselineskip}} |
| 393 |
% \end{macrocode} |
| 394 |
% |
| 395 |
% Then the stared version: |
| 396 |
% \begin{macrocode} |
| 397 |
\newcommand{\answ@rstar}[2][\fill]{% |
| 398 |
\nopagebreak\vspace{#1}\par\nopagebreak\hfill\hbox to |
| 399 |
.5\columnwidth{#2\hrulefill}\vspace{\baselineskip}} |
| 400 |
|
| 401 |
\newcommand{\addansw@rstar}[2][\baselineskip]{% |
| 402 |
\nopagebreak\vspace{#1}\par\nopagebreak\hfill\hbox to |
| 403 |
.5\columnwidth{#2\hrulefill}\vspace{\baselineskip}} |
| 404 |
% \end{macrocode} |
| 405 |
% |
| 406 |
% Now we will pot them together. Look ahead to see if there is a star. If |
| 407 |
% there is, use the stared version: |
| 408 |
% \begin{macrocode} |
| 409 |
\def\answer{% |
| 410 |
\def\e@t*{}% |
| 411 |
\def\n@xt{\if\noexpand\myn@@xt*% |
| 412 |
\expandafter\expandafter\expandafter\answ@rstar\expandafter\e@t\else% |
| 413 |
\expandafter\answ@r\fi}% |
| 414 |
\futurelet\myn@@xt\n@xt} |
| 415 |
|
| 416 |
\def\addanswer{% |
| 417 |
\def\e@t*{}% |
| 418 |
\def\n@xt{\if\noexpand\myn@@xt*% |
| 419 |
\expandafter\expandafter\expandafter\addansw@rstar\expandafter\e@t\else% |
| 420 |
\expandafter\addansw@r\fi}% |
| 421 |
\futurelet\myn@@xt\n@xt} |
| 422 |
% \end{macrocode} |
| 423 |
% \end{macro} |
| 424 |
% \end{macro} |
| 425 |
% |
| 426 |
% \begin{macro}{\noanswer} |
| 427 |
% \begin{macrocode} |
| 428 |
\newcommand{\noanswer}[1][\fill]{\nopagebreak\vspace{#1}\par} |
| 429 |
% \end{macrocode} |
| 430 |
% \end{macro} |
| 431 |
% |
| 432 |
% Finally, couple of very simple macros. They could probably be made more |
| 433 |
% interesting and flexible. |
| 434 |
% \begin{macro}{\ExamNameLine} |
| 435 |
% \begin{macrocode} |
| 436 |
\newcommand{\ExamNameLine}{% |
| 437 |
\par |
| 438 |
\vspace{\baselineskip} |
| 439 |
Name:\hrulefill\relax |
| 440 |
\par} |
| 441 |
% \end{macrocode} |
| 442 |
% \end{macro} |
| 443 |
% |
| 444 |
% \begin{macro}{\ExamInstrBox} |
| 445 |
% \begin{macrocode} |
| 446 |
\newcommand{\ExamInstrBox}[1]{\begin{center}\vspace{\baselineskip}% |
| 447 |
\fbox{\fbox{\parbox{.8\hsize}{#1}}}\end{center}} |
| 448 |
% \end{macrocode} |
| 449 |
% \end{macro} |
| 450 |
% |
| 451 |
% \Finale |
| 452 |
|
| 453 |
\endinput |