% % PERMISSIONS: % % jscover.sty is distributed under the % Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License. % You can see the details of this license at % http://creativecommons.org/licenses/by-nc-sa/3.0/us/ % % If this package is amateurish, there are two reasons: % (1) I quit working on it as soon as it would do what I wanted, and % (2) I'm not a great TeXnician anyway. % If you adapt this package, I'd like to know about it; I don't want to use an inferior version! % Please do email me at swensonjATuwplattDOTedu. Thanks! % % KNOWN ISSUES: % % (*) You have to put in the \EndOfLastPage macro manually. % (*) The code forces the page numbering to start with page 0 (the cover page). % (*) The line \RequirePackage{amsmath} doesn't work the way I think it should. % % OBJECTIVE: % % This package makes the following commands available: % % Primary commands: % % \coverlabel % Start each exam problem with a \coverlabel macro. % By default, \coverlabel requires one integer argument; the point value of the problem. % If the "draft" or "final" option is in effect, then \coverlabel requires two arguments: % (1st) the textbook section to which the problem refers (or other text) % [The first argument will be ignored if "final" is in effect, % and will be set in an \fbox if "draft" is in effect.] % (2nd) the point value of the problem. % \pgbk % This ends a page, adds up the number of points available on that page, % and makes the total available to \CoverTable via \ref{a}, \ref{b}, ... % \EndOfLastPage % This is the alternative to \pgbk which must be used at the end of the last page... % It doesn't start an undesired new page; it does make the grand total available to CoverTable. % \CoverTable % a box that shows the total possible score on each page, with a blank for the student's score % % Secondary commands: % % \ref{LastProblem} % the number of problems on the exam % \theNumberOfProblems % the number of the current problem % \theTotalScore % a running total of the number of points available % \thePageTotalScore % a running total of the number of points available on the current page % % USAGE: % % Start each problem with something like: \coverlabel{\S46: Fundamentals of Graph Theory}{5} % ( ... for a 5-point problem from section 46, with "draft"/"final" ), % or with something like \coverlabel{5} % ( ... for a 5-point problem when not using "draft"/"final" ). % Make each page break with \pgbk (rather than \newpage). % The last command before \end{document} should be \EndOfLastPage. % % % James A. Swenson % University of Wisconsin - Platteville % 14 December 2007 % ----------------------------------------------------------- % % Identification % \NeedsTeXFormat{LaTeX2e} \ProvidesPackage{jscover}[2007/12/14] % % Initial Code % \RequirePackage{amsmath}% This provides the \nonumber switch for the equation environment \RequirePackage{forloop}% \forloop puts the right number of rows in \CoverTable \RequirePackage{lastpage}% Find the number of the last page, for headers and \CoverTable \RequirePackage{fancyhdr}% required for "headers" option % % Declaration of Options % \DeclareOption{headers}{% This will put "Page k of n" at the top of each page \setlength{\headheight}{15pt} \pagestyle{fancyplain} \lhead{} \chead{Page \fancyplain{}{\thepage\ of \pageref{LastPage}}} \rhead{} \lfoot{} \cfoot{} \rfoot{} } \DeclareOption{DoNotUseThisOption}{% % This initializes \coverlabel with the default (1-argument) behavior. % \usepackage[DoNotUseThisOption]{jscover} won't compile: hence the name. \newcommand{\coverlabel}[1] { [#1 points]% \addtocounter{PageTotalScore}{#1}% \stepcounter{NumberOfProblems}% } } \DeclareOption{nosection}{% % This is equivalent to the default, except that % it's safe to \usepackage[nosection]{jscover}. \renewcommand{\coverlabel}[1] { [#1 points]% \addtocounter{PageTotalScore}{#1}% \stepcounter{NumberOfProblems}% } } \DeclareOption{draft}{% % This will display the section numbers given in \coverlabel commands. \renewcommand{\coverlabel}[2]% {% [#2 points]% \addtocounter{PageTotalScore}{#2}% \stepcounter{NumberOfProblems}% \quad\fbox{#1}% } } \DeclareOption{final}{% % This option suppresses the section numbers. \renewcommand{\coverlabel}[2]% {% [#2 points]% \addtocounter{PageTotalScore}{#2}% \stepcounter{NumberOfProblems}% } } \ExecuteOptions{DoNotUseThisOption}% Initialize \coverlabel, so that the \renewcommand is really renewing it. \ProcessOptions% % % Main Code % \newenvironment{jsCoverNull}% % This is intended as a void environment; but if you put \label{foo} inside it, % it will throw the value of the equation counter for \ref{foo} to catch. % This is how the PageTotalScore gets back to the cover page. {% \begin{equation}% Now we have something to \label \nonumber% Suppress the equation number, so the process is invisible in the document } {\end{equation} } % % Stuff for totalling the scores % \newcounter{NumberOfProblems} \setcounter{NumberOfProblems}{0} \newcounter{TotalScore} \setcounter{TotalScore}{0} \newcounter{PageTotalScore} \setcounter{PageTotalScore}{0} \newcounter{row}% This is the counter in the forloop that builds the table on the cover page \newcounter{rowminusone}% This doesn't get auto-incremented when row does; it's a kludge to avoid \le \newcounter{jsplaceholder}% Temporary storage for the value of the equation counter \newcommand{\DataTransfer}{% \setcounter{jsplaceholder}{\theequation} \setcounter{equation}{\thePageTotalScore}% This feeds thePageTotalScore to the jsCoverNull environment \addtocounter{equation}{-1}% Cancel the auto-increment we'll get when we begin{jsCoverNull} \begin{jsCoverNull}\label{jsCoverLabel\alph{page}}\end{jsCoverNull}% This throws thePageTotalScore to the cover page \addtocounter{TotalScore}{\thePageTotalScore}% Add the points from this page to the grand total \setcounter{PageTotalScore}{0}% Get ready for the next page... \setcounter{equation}{\thejsplaceholder} } \newcommand{\pgbk}{\DataTransfer\newpage}% This way we don't have to put a newpage on the last page! \newcommand{\CoverTable} {% \begin{tabular}{|c|c|c|} \hline & & \\ Page & Possible & Score \\ \hline & & \\ \forloop{row}{1}{\value{rowminusone}<\pageref{LastPage}}{% This makes a row for each page after the cover page \setcounter{rowminusone}{\therow}\arabic{row} & \additup & \hspace{1.5in} \\% Page # -- PageTotalScore -- blank \hline & & \\% }% end of the forloop \textbf{TOTAL} & \ref{PointTotal} pts. & \\% This catches the TotalScore from \endoflastpage \hline \end{tabular} } \newcommand{\additup}{\ref{jsCoverLabel\alph{row}} pts.}% Catch the PageTotalScore from the jsCoverNull environment in \pgbk \AtBeginDocument { \thispagestyle{empty}% Don't number the first page... \setcounter{page}{0}% the cover page doesn't count (this helps build the table on the cover page) } \newcommand{\EndOfLastPage}{% \DataTransfer% \setcounter{jsplaceholder}{\theequation}% Hopefully unnecessary; we should be done setting equations by now. \setcounter{equation}{\theTotalScore}% Feed the grand total to the upcoming jsCoverNull environment \addtocounter{equation}{-1}% Cancel the auto-increment \begin{jsCoverNull}\label{PointTotal}\end{jsCoverNull}% Throw the grand total to the cover page \setcounter{equation}{\theNumberOfProblems}% \addtocounter{equation}{-1}% Cancel the auto-increment \begin{jsCoverNull}\label{LastProblem}\end{jsCoverNull}% Throw the number of problems to the cover page \setcounter{equation}{\thejsplaceholder} } %\AtEndDocument{\EndOfLastPage} does not work: it sets an invisible equation on page (n+1).