% \iffalse meta-comment % An Infrastructure for marking up Assignments % $URL: https://svn.kwarc.info/repos/stex/trunk/sty/hwexam/hwexam.dtx $ % $Rev: 1999 $; last modified by $Author: kohlhase $ % $Date: 2012-01-28 08:32:11 +0100 (Sat, 28 Jan 2012) $ % Copyright (c) 2007 Michael Kohlhase, all rights reserved % this file is released under the % LaTeX Project Public License (LPPL) % \fi % % \iffalse %\NeedsTeXFormat{LaTeX2e}[1999/12/01] %\ProvidesPackage{hwexam}[2012/01/28 v0.9b homework assignments and exams] %\ProvidesClass{hwexam}[2012/01/28 v0.9b assignment and exam documents] % %<*driver> \documentclass{ltxdoc} \usepackage{url,float} \usepackage{hwexam} \usepackage[show]{ed} \usepackage[hyperref=auto,style=alphabetic]{biblatex} \bibliography{kwarc} \usepackage[eso-foot,today]{svninfo} \svnInfo $Id: hwexam.dtx 1999 2012-01-28 07:32:11Z kohlhase $ \svnKeyword $HeadURL: https://svn.kwarc.info/repos/stex/trunk/sty/hwexam/hwexam.dtx $ \usepackage{stex-logo} \usepackage{../ctansvn} \usepackage{hyperref} \makeindex \floatstyle{boxed} \newfloat{exfig}{thp}{lop} \floatname{exfig}{Example} \def\tracissue#1{\cite{sTeX:online}, \hyperlink{http://trac.kwarc.info/sTeX/ticket/#1}{issue #1}} \begin{document}\DocInput{hwexam.dtx}\end{document} % % \fi %\CheckSum{432} % % \changes{v0.9}{2006/09/18}{First Version with Documentation} % \changes{v0.9a}{2010/06/25}{more semantic headers for exams} % \changes{v0.9b}{2010/09/20}{adding \texttt{assignment.cls}} % \changes{v0.9c}{2010/09/20}{renaming from \texttt{assignment} to \texttt{hwexam} to % avoid name clashes with existing \texttt{assignment.cls} on CTAN.} % % \GetFileInfo{hwexam.sty} % % \MakeShortVerb{\|} %\def\scsys#1{{{\sc #1}}\index{#1@{\sc #1}}} % \def\latexml{\scsys{LaTeXML}} % % \title{\texttt{hwexam.sty/cls}: An Infrastructure for formatting Assignments % and Exams\thanks{Version {\fileversion} (last revised {\filedate})}} % \author{Michael Kohlhase\\ % Jacobs University, Bremen\\ % \url{http://kwarc.info/kohlhase}} % \maketitle % % \begin{abstract} % The |hwexam| packge and class allows individual course assignment sheets and % compond assignment documents using problem files marked up with the |problem| package. % \end{abstract} % \setcounter{tocdepth}{2}\tableofcontents\newpage % %\section{Introduction}\label{sec:intro} % % The |hwexam| package and class supplies an infrastructure that allows to format % nice-looking assignment sheets by simply including problems from problem files marked up % with the |problem| package~\cite{Kohlhase:problem:ctan}. It is designed to be % compatible with |problems.sty|, and inherits some of the functionality. % % \section{The User Interface} % % \subsection{Package and Class Options}\label{sec:user:options} % % The |hwexam| package and class take the options |solutions|, |notes|, |hints|, |pts|, % |min|, and |boxed| that are just passed on to the |problems| package (cf. its % documentation for a description of the intended behavior). % % If the \DescribeMacro{showmeta}|showmeta| option is set, then the metadata keys are % shown (see~\cite{Kohlhase:metakeys:ctan} for details and customization options). % % The |hwexam| class additionally accepts the options |report|, |book|, |chapter|, |part|, % and |showignores|, of the |omdoc| package~\cite{Kohlhase:smomdl:ctan} on which it is % based and passes them on to that. For the |extrefs| option % see~\cite{Kohlhase:sref:ctan}. % % \subsection{Assignments} % % This package supplies the \DescribeEnv{assignment}|assignment| environment that groups % problems into assignment sheets. It takes an optional KeyVal argument with the keys % \DescribeMacro{number}|number| (for the assignment number; if none is given, 1 is % assumed as the default or --- in multi-assignment documents --- the ordinal of the % |assignment| environment), \DescribeMacro{title}|title| (for the assignment title; this % is referenced in the title of the assignment sheet), \DescribeMacro{type}|type| (for the % assignment type; e.g. ``quiz'', or ``homework''), \DescribeMacro{given}|given| (for the % date the assignment was given), and \DescribeMacro{due}|due| (for the date the % assignment is due). % % \subsection{Typesetting Exams} % % Furthermore, the |hwexam| package takes the option % \DescribeMacro{multiple}|multiple| that allows to combine multiple assigment sheets into % a compound document (the assignment sheets are treated as section, there is a table of % contents, etc.). % % Finally, there is the option \DescribeMacro{test}|test| that modifies the behavior to % facilitate formatting tests. Only in |test| mode, the macros |\testspace|, % |\testnewpage|, and |\testemptypage| have an effect: they generate space for the % students to solve the given problems. Thus they can be left in the {\LaTeX} source. % % \DescribeMacro{\testspace}|\testspace| takes an argument that expands to a dimension, % and leaves vertical space accordingly. \DescribeMacro{\testnewpage}|\testnewpage| makes % a new page in |test| mode, and \DescribeMacro{\testemptypage}|\testemptypage| generates % an empty page with the cautionary message that this page was intentionally left empty. % % Finally, the \DescribeEnv{testheading}|\testheading| takes an optional keyword argument % where the keys \DescribeMacro{duration}|duration| specifies a string that specifies the % duration of the test, \DescribeMacro{min}|min| specifies the equivalent in number of % minutes, and \DescribeMacro{reqpts}|reqpts| the points that are required for a perfect % grade. % \begin{exfig}[ht] % \makeatletter % \@problem{1.1}{4}{10} % \@problem{2.1}{4}{8} % \@problem{2.2}{6}{10} % \@problem{2.3}{6}{10} % \@problem{3.1}{4}{8} % \@problem{3.2}{4}{8} % \@problem{3.3}{2}{4} % \makeatother % \begin{verbatim} % \title{320101 General Computer Science (Fall 2010)} % \begin{testheading}[duration=one hour,min=60,reqpts=27] % Good luck to all students! % \end{testheading} % \end{verbatim} % \vspace*{-3ex}\hrule\vspace*{.5ex} formats to\vspace*{1ex} % \hrule\par\noindent\vspace*{2ex} % \title{320101 General Computer Science (Fall 2010)} % \begin{testheading}[duration=one hour,min=60,reqpts=27] % good luck % \end{testheading} % \caption{A generated test heading.}\label{fig:testheading} % \end{exfig} % % \subsection{Including Assignments} % % The \DescribeMacro{\includeassignment}|\includeassignment| macro can be used to include % an assignment from another file. It takes an optional KeyVal argument and a second % argument which is a path to the file containing the problem (the macro assumes that % there is only one |assignment| environment in the included file). The keys % \DescribeMacro{number}|number|, \DescribeMacro{title}|title|, % \DescribeMacro{type}|type|, \DescribeMacro{given}|given|, and \DescribeMacro{due}|due| % are just as for the |assignment| environment and (if given) overwrite the ones specified % in the |assignment| environment in the included file. % % % \section{Limitations}\label{sec:limitations} % % In this section we document known limitations. If you want to help alleviate them, % please feel free to contact the package author. Some of them are currently discussed in % the \sTeX TRAC~\cite{sTeX:online}. % \begin{compactenum} % \item none reported yet % \end{compactenum} % % \StopEventually{\newpage\PrintIndex\newpage\PrintChanges\printbibliography}\newpage % \newpage % % \section{Implementation: The hwexam Class}\label{sec:impl:cls} % % The functionality is spread over the |hwexam| class and package. The class provides % the |document| environment and pre-loads some convenience packages, whereas the package % provides the concrete functionality. % % |hwexam.dtx| generates four files: |hwexam.cls| (all the code between % {\textsf{$\langle$*cls$\rangle$}} and {\textsf{$\langle$/cls$\rangle$}}), |hwexam.sty| % (between {\textsf{$\langle$*package$\rangle$}} and % {\textsf{$\langle$/package$\rangle$}}) and their {\latexml} bindings (between % {\textsf{$\langle$*ltxml.cls$\rangle$}} and {\textsf{$\langle$/ltxml.cls$\rangle$}} and % {\textsf{$\langle$*ltxml.sty$\rangle$}} and {\textsf{$\langle$/ltxml.sty$\rangle$ % respetively}}). We keep the corresponding code fragments together, since the % documentation applies to both of them and to prevent them from getting out of sync. % % \subsection{Class Options}\label{sec:impl:cls:options} % % To initialize the |hwexam| class, we declare and process the necessary options by % passing them to the respective packages and classes they come from. % % \begin{macrocode} %<*cls> \DeclareOption{test}{\PassOptionsToPackage{\CurrentOption}{hwexam}} \DeclareOption{multiple}{\PassOptionsToPackage{\CurrentOption}{hwexam}} \DeclareOption{showmeta}{\PassOptionsToPackage{\CurrentOption}{metakeys}} \DeclareOption{extrefs}{\PassOptionsToPackage{\CurrentOption}{sref}} \DeclareOption{notes}{\PassOptionsToPackage{\CurrentOption}{problem}} \DeclareOption{hints}{\PassOptionsToPackage{\CurrentOption}{problem}} \DeclareOption{solutions}{\PassOptionsToPackage{\CurrentOption}{problem}} \DeclareOption{pts}{\PassOptionsToPackage{\CurrentOption}{problem}} \DeclareOption{min}{\PassOptionsToPackage{\CurrentOption}{problem}} \DeclareOption{boxed}{\PassOptionsToPackage{\CurrentOption}{problem}} \DeclareOption{extract}{\PassOptionsToPackage{\CurrentOption}{problem}} \DeclareOption*{\PassOptionsToClass{\CurrentOption}{omdoc}} \ProcessOptions % %<*ltxml.cls> # -*- CPERL -*- package LaTeXML::Package::Pool; use strict; use LaTeXML::Package; use LaTeXML::Util::Pathname; use Cwd qw(cwd abs_path); DeclareOption('test',,sub {PassOptions('hwexam','sty',ToString(Digest(T_CS('\CurrentOption')))); }); DeclareOption('multiple',sub {PassOptions('hwexam','sty',ToString(Digest(T_CS('\CurrentOption')))); }); DeclareOption('showmeta',sub {PassOptions('metakeys','sty',ToString(Digest(T_CS('\CurrentOption')))); }); DeclareOption('extrefs',sub {PassOptions('sref','sty',ToString(Digest(T_CS('\CurrentOption')))); }); DeclareOption('notes',sub {PassOptions('problem','sty',ToString(Digest(T_CS('\CurrentOption')))); }); DeclareOption('hints',sub {PassOptions('problem','sty',ToString(Digest(T_CS('\CurrentOption')))); }); DeclareOption('solutions',sub {PassOptions('problem','sty',ToString(Digest(T_CS('\CurrentOption')))); }); DeclareOption('pts',sub {PassOptions('problem','sty',ToString(Digest(T_CS('\CurrentOption')))); }); DeclareOption('min',sub {PassOptions('problem','sty',ToString(Digest(T_CS('\CurrentOption')))); }); DeclareOption('boxed',sub {PassOptions('problem','sty',ToString(Digest(T_CS('\CurrentOption')))); }); DeclareOption('extract',sub {PassOptions('problem','sty',ToString(Digest(T_CS('\CurrentOption')))); }); DeclareOption(undef,sub {PassOptions('omdoc','cls',ToString(Digest(T_CS('\CurrentOption')))); }); ProcessOptions(); % % \end{macrocode} % % We load |article.cls|, and the desired packages. For the {\latexml} bindings, we make % sure the right packages are loaded. % % \begin{macrocode} %<*cls> \LoadClass{omdoc} \RequirePackage{stex} \RequirePackage{hwexam} \RequirePackage{graphicx} \RequirePackage{a4wide} \RequirePackage{amssymb} \RequirePackage{amstext} \RequirePackage{amsmath} % %<*ltxml.cls> LoadClass('omdoc'); RequirePackage('stex'); RequirePackage('hwexam'); RequirePackage('graphicx'); RequirePackage('amssymb'); RequirePackage('amstext'); RequirePackage('amsmath'); % % \end{macrocode} % % \section{Implementation: The hwexam Package} % % \subsection{Package Options} % % The first step is to declare (a few) package options that handle whether certain % information is printed or not. Some come with their own conditionals that are set by the % options, the rest is just passed on to the |problems| package. % % \begin{macrocode} %<*package> \DeclareOption{showmeta}{\PassOptionsToPackage{\CurrentOption}{metakeys}} \newif\iftest\testfalse \newif\ifsolutions\solutionsfalse \DeclareOption{test}{\testtrue\solutionsfalse} \newif\ifmultiple\multiplefalse \DeclareOption{multiple}{\multipletrue} \DeclareOption*{\PassOptionsToPackage{\CurrentOption}{problem}} \ProcessOptions % % \end{macrocode} % Then we make sure that the necessary packages are loaded (in the right versions). % \begin{macrocode} %<*package> \RequirePackage{keyval}[1997/11/10] \RequirePackage{problem} % % \end{macrocode} % % Here comes the equivalent header information for {\latexml}, we also initialize the % package inclusions. Since {\latexml} does not handle options yet, we have nothing to % do. % \begin{macrocode} %<*ltxml> # -*- CPERL -*- package LaTeXML::Package::Pool; use strict; use LaTeXML::Package; RequirePackage('problem'); % % \end{macrocode} % % Then we register the namespace of the requirements ontology % \begin{macrocode} %<*ltxml> RegisterNamespace('assig'=>"http://omdoc.org/ontology/assignments#"); RegisterDocumentNamespace('assig'=>"http://omdoc.org/ontology/assignments#"); % % \end{macrocode} % % \subsection{Assignments} % % We will prepare the keyval support for the |assignment| environment. % % \begin{macrocode} %<*package> \addmetakey{assig}{number} \addmetakey*{assig}{title} \addmetakey{assig}{type} \addmetakey{assig}{given} \addmetakey{assig}{due} % \end{macrocode} % % The next three macros are intermediate functions that handle the case gracefully, where % the respective token registers are undefined. % % The |\given@due| macro prints information about the given and due status of the % assignment. Its arguments specify the brackets. % % \begin{macrocode} \def\given@due#1#2{% \ifx\assig@given\@empty\else\ifx\assig@due\@empty\else{#1}\fi\fi% \ifx\assig@given\@empty\else{Given {\assig@given}}\fi% \ifx\assig@given\@empty\else\ifx\assig@due\@empty\else{, }\fi\fi% \ifx\assig@due\@empty\else{Due {\assig@due}}\fi% \ifx\assig@given\@empty\else{\ifx\assig@due\@empty\else{#2}\fi}\fi} % \end{macrocode} % % With them, we can define the central |assignment| environment. This has two forms % (separated by |\ifmultiple|) in one we make a title block for an assignment sheet, and % in the other we make a section heading and add it to the table of % contents. % % \begin{macro}{assignment@titleblock} % This macro prints the title block of a section. If the |multiple| package option is % given we make a section heading out of this, and if not, a title block. Note that as % |problem|s are numbered by section, we also set the section counter in the latter % case. % \begin{macrocode} \ifmultiple \def\assignment@titleblock{% \@ifundefined{assig@number}{\stepcounter{section}}{\setcounter{section}{\assig@number}}% \section*{\protect\document@hwexamtype~\arabic{section}:~\assig@title\given@due{\\(})}% \addcontentsline{toc}{section}{\document@hwexamtype~{\arabic{section}}:~\assig@title}% \setcounter{problem}{0}} \else \def\assignment@titleblock{% \setcounter{section}{\assig@number} \begin{center}\bf \Large\@title\\ \document@hwexamtype~\assig@number:~\assig@title\strut\\ \large{\given@due()} \end{center}} \fi % \end{macrocode} % \end{macro} % % \begin{macro}{assignment@process@keys} % this macro collects the keys from its arugment and corrects them from the outside. % \begin{macrocode} \def\assignment@process@keys#1{\metasetkeys{assig}{#1} \ifx\inclassig@title\@empty\else\def\assig@title{\inclassig@title}\fi \ifx\inclassig@type\@empty\else\def\assig@type{\inclassig@type}\fi \ifx\inclassig@number\@empty\else\def\assig@number{\inclassig@number}\fi \ifx\inclassig@due\@empty\else\def\assig@due{\inclassig@due}\fi \ifx\inclassig@given\@empty\else\def\assig@given{\inclassig@given}\fi} % \end{macrocode} % for this to work we need to define the |\inclassig| macros in case no % |\includeassignment| is ever called. % \begin{macrocode} \def\inclassig@title{} \def\inclassig@type{} \def\inclassig@number{} \def\inclassig@due{} \def\inclassig@given{} % \end{macrocode} % \end{macro} % % \begin{environment}{assignment} % \begin{macrocode} \newenvironment{assignment}[1][]{\assignment@process@keys{#1}% \assignment@titleblock}{} % % \end{macrocode} % % \begin{macrocode} %<*ltxml> DefEnvironment('{assignment} OptionalKeyVals:assig', "" . "" . "" . "Assignment ?&KeyVal(#1,'num')(&KeyVal(#1,'num').)()" . "?&KeyVal(#1,'title')((&KeyVal(#1,'title')))" . "" . "?&KeyVal(#1,'given')(&KeyVal(#1,'given'))()" . "?&KeyVal(#1,'due')(&KeyVal(#1,'due'))()" . "?&KeyVal(#1,'pts')(&KeyVal(#1,'pts'))()" . "" . "#body" ."\n", afterDigest=> sub { my ($stomach, $kv) = @_; my $kvi = LookupValue('inclassig'); my @keys = qw(id num title pts given due); my @vals = $kvi && map($kvi->getValue($_), @keys); foreach my $i(0..$#vals) { $kv->setValue($keys[$i],$vals[$i]) if $vals[$i]; }});#$ % % \end{macrocode} % \end{environment} % % \begin{macrocode} %<*package> \def\assig@default@type{Assignment} \addmetakey[\assig@default@type]{document}{hwexamtype} % % \end{macrocode} % % \subsection{Including Assignments} % % The next command is essentially a glorified |\include| statement, it just sets some % internal macros first that overwrite the local points, \ednote{these keys should be done % with \texttt{\textbackslash addmetakey}} % % \begin{macrocode} %<*package> \addmetakey{inclassig}{number} \addmetakey{inclassig}{title} \addmetakey{inclassig}{type} \addmetakey{inclassig}{given} \addmetakey{inclassig}{due} \newcommand{\includeassignment}[2][]{\metasetkeys{inclassig}{#1}\include{#2}} \newcommand{\inputassignment}[2][]{\metasetkeys{inclassig}{#1}\input{#2}} % %<*ltxml> DefMacro('\includeassignment [] {}', sub { my ($stomach, $arg1, $arg2) = @_; AssignValue('inclassig',$arg1) if $arg1; (Invocation(T_CS('\input'),$arg2)->unlist); }); DefMacro('\inputassignment [] {}','\input{#2}'); % % \end{macrocode} % % \subsection{Typesetting Exams} % % \begin{macrocode} %<*package> \addmetakey{quizheading}{tas} \newcommand\quizheading[1]{\def\@tas{#1}% \large\noindent NAME: \hspace{8cm} MAILBOX:\\[2ex]% \ifx\@tas\@empty\else% \noindent TA: \@for\@I:=\@tas\do{{\Large$\Box$}\@I\hspace*{1em}}\\[2ex]\fi} % % \end{macrocode} % \begin{macrocode} %<*package> \addmetakey{testheading}{min} \addmetakey{testheading}{duration} \addmetakey{testheading}{reqpts} \newenvironment{testheading}[1][]{\metasetkeys{testheading}{#1} {\noindent\large{}Name: \hfill Matriculation Number:\hspace*{2cm}\strut\\[1ex] \begin{center}\Large\textbf{\@title}\\[1ex]\large\@date\\[3ex]\end{center} {\textbf{You have \ifx\test@heading@duration\@empty\testheading@min minutes\else\testheading@duration\fi (sharp) for the test}};\\ Write the solutions to the sheet.}\par\noindent \newcount\check@time\check@time=\testheading@min \advance\check@time by -\theassignment@totalmin The estimated time for solving this exam is {\theassignment@totalmin} minutes, leaving you {\the\check@time} minutes for revising your exam. \newcount\bonus@pts\bonus@pts=\theassignment@totalpts \advance\bonus@pts by -\testheading@reqpts You can reach {\theassignment@totalpts} points if you solve all problems. You will only need {\testheading@reqpts} points for a perfect score, i.e.\ {\the\bonus@pts} points are bonus points. \vfill \begin{center} {\Large\em % You have ample time, so take it slow and avoid rushing to mistakes!\\[2ex] Different problems test different skills and knowledge, so do not get stuck on one problem.}\vfill\par\correction@table \\[3ex] \end{center}} {\newpage} % %<*ltxml> DefEnvironment('{testheading}OptionalKeyVals:omdoc',''); % % \end{macrocode} % % \begin{macrocode} %<*package> \def\testspace#1{\iftest\vspace*{#1}\fi} \def\testnewpage{\iftest\newpage\fi} \def\testemptypage{\iftest\begin{center}This page was intentionally left blank for extra space\end{center}\vfill\eject\else\fi} % %<*ltxml> DefConstructor('\testspace{}',''); DefConstructor('\testnewpage',''); DefConstructor('\testemptypage',''); % % \end{macrocode} % % \begin{macro}{\@problem} % This macro acts on a problem's record in the |*.aux| file. Here we redefine it to % generate the correction table. % \begin{macrocode} %<*package> \def\@problem#1#2#3{\stepcounter{assignment@probs} \def\@test{#2}\ifx\@test\@empty\else\addtocounter{assignment@totalpts}{#2}\fi \def\@test{#3}\ifx\@test\@empty\else\addtocounter{assignment@totalmin}{#3}\fi \xdef\correction@probs{\correction@probs & #1}% \xdef\correction@pts{\correction@pts & #2} \xdef\correction@reached{\correction@reached &}} % % \end{macrocode} % \end{macro} % % \begin{macro}{\correction@table} % This macro generates the correction table % \begin{macrocode} %<*package> \newcounter{assignment@probs} \newcounter{assignment@totalpts} \newcounter{assignment@totalmin} \def\correction@probs{prob.}% \def\correction@pts{total}% \def\correction@reached{reached}% \stepcounter{assignment@probs} \def\correction@table{\begin{tabular}{|l|*{\theassignment@probs}{c|}|p{3cm}|}\hline% &\multicolumn{\theassignment@probs}{c||}% {\footnotesize To be used for grading, do not write here} &\\\hline \correction@probs & Sum & grade\\\hline \correction@pts &\theassignment@totalpts & \strut\hspace{3cm}\strut\\\hline \correction@reached & & \\[.7cm]\hline \end{tabular}} % % \end{macrocode} % \end{macro} % % \subsection{Leftovers} % % at some point, we may want to reactivate the logos font, then we use % \begin{verbatim} % here we define the logos that characterize the assignment % \font\bierfont=../assignments/bierglas % \font\denkerfont=../assignments/denker % \font\uhrfont=../assignments/uhr % \font\warnschildfont=../assignments/achtung % % \def\bierglas{{\bierfont\char65}} % \def\denker{{\denkerfont\char65}} % \def\uhr{{\uhrfont\char65}} % \def\warnschild{{\warnschildfont\char 65}} % \def\hardA{\warnschild} % \def\longA{\uhr} % \def\thinkA{\denker} % \def\discussA{\bierglas} % \end{verbatim} % % Finally, we need to terminate the file with a success mark for perl. % \begin{macrocode} %1; % \end{macrocode} % \Finale \endinput % \iffalse % LocalWords: GPL structuresharing STR %%% Local Variables: %%% mode: doctex %%% TeX-master: t %%% End: % \fi