The class package^{∗}

Andrew D. Lewis

1998/04/03

1 Introduction

The L^{A}TEX files described here are part of a general facility (I call it Class) for use when teaching a class. Hopefully, when you acquired the L^{A}TEX files, the rest of the stuff came with it. Here I will describe only the use and setup of the L^{A}TEX files.

2 The document classes

Class comes with two document classes, class and gradelist. The first is for use when making things like problems sheets, exams, etc. and the second if for making lists of grades. Both are based on article and so offer all the functionality of that class. Both document classes load the lastpage package. This is used for the headers which give the current page number as well as the total number of pages. They also have some other stuff which we now describe.

2.1 The class document class

The things which appear in the title of a problem sheet are apt to be different than those in a research article. So when you invoke \maketitle within class you will get something quite different than you will within article. Thus you need to specify different information. So, in place of the usual \author, \title, \date, you specify

\title 1. \title: This is the “title” of what you are writing: “Final Exam” if it is a final exam; “Assignment” if it is an assignment, etc.

\num 2. \num: If what you are writing has a number, specify it with num. For example, you might type

         \title{Assignment}
         \num{2}

\course 3. \course: If the course has a number or title, use course to specify it.

4. \headcourse: If the course title as defined by \course is not what you want in the page headings, you can change this by using \headcourse after

     \course.

\instructor 5. \instructor: to name the instructor.

\year 6. \year: ok, you have to figure this one out yourself…

All of these are optional. However, you should type \maketitle very near the beginning of your document to save errors later.

The class document class makes available the commands \dategiven and \datedue available. To see how these work, see the files in demo. If you don’t want this information printed on the assignment or exam, simply don’t use these commands in the preamble. This is done, for example, in the exams in demo. It is also possible to supply just one of these commands if that’s all you want.

If you are using the class document style for an exam, you may wish to have on the title page some space available for student information (i.e., name, student number, etc.) You may do this by specifying the studentinfo option to class. If you specify this option, you need to tell class what information it is you want.

\studentinfo You do this with the \studentinfo command. For example, I commonly use

 \studentinfo{$\overline{\qquad\textrm{Section, Instructor}\qquad}$\hss%
    $\overline{\quad\textrm{Student Number}\quad}$\hss%
    $\overline{\qquad\textrm{Name (printed)}\qquad}$}

Another thing you commonly do in writing problem sheets, etc. is to as-

problems sign problems. To help with this, class defines the environments problems,

subproblems
subsubproblems

subproblems, subsubproblems so you can layer your problem levels three deep. To start a problem the syntax is

     \problem**[point value]

(Think of \problem as \item with bells and whistles.) The stars are optional as is point value. The stars are for use when you wish to denote problems which are more difficult (one star) or very difficult (two stars). I go no more difficult than that. Have mercy on the poor students! The optional point value argument is for those times (for example, when writing an exam) when you wish to have it explicitly known what the problem is “worth.”

\probref To refer to a problem later, use the command \probref. This will format

things properly.

Well, if you are a conscientious teacher, not only will you have problems,

solution you will also have solutions. These may be included in the solution environment. You may start a solution environment anywhere in the problem sheet. Within the solution environment you may use the problems, subproblems, and subsubproblems environments. This suggests various possibilities for writing solutions to problems with multiple parts. Experiment and see what you like best.

∗This file has version number v3.0b, last revised 1998/04/03.

Of course it would be nice if the appearance of the solutions were optional (you may not want to hand them out with the copy of the exam the students take :-) ). Well, this is built into class by the specification of the options solutions and nosolutions. The default is nosolutions. To facilitate the solutions and nosolutions options, the package comment is loaded.

At times you may want to do something or not, depending on whether the solutions will be present. This may be accomplished by

\solutiontest{thing to do when solutions are printed}{thing to do when solutions are not present}

Use a blank argument (or \relax) in either of the entries if you need to.

2.2 The gradelist document class

The gradelist document class is more than a document class in the usual sense. It does computations and creates data files which can be used by other parts of the Class bundle (namely the program Grader).

This document class has the same macros for making titles as class. However, none of the other capacity of class is present in gradelist. It is easiest to illustrate how to use the features by example, so we refer to Figure 1. The new commands are

\name : writes the argument to the file names.out.

It also gives the name as TEX output.

\add : advances the grade for the assignment by an amount specified by the argument. The argument is a real number. The argument is also printed as TEX output.

\total : writes the assignment grade for that student to a file grades.out. It also increments the

                         counter \numberofstudents by 1. The

argument is printed as TEX output.

You should be able to figure out how to adapt this to your needs (i.e., change the student names and the number of problems…)

3 Implementation

1 ⟨∗class⟩

Get the options set up and load article as a template.

2

 3 \RequirePackage{lastpage,comment}
 4 \newif\if@ADL@solutions\@ADL@solutionsfalse
 5 \newif\if@ADL@sinfo\@ADL@sinfofalse

\documentclass{gradelist}
\title{Assignment}
\num{1}
\course{ACT1}
\instructor{L.~Olivier}
\year{1942}
\begin{document}
\maketitle
\begin{center}
\begin{tabular}{|l|c|c|c|c|c|}\hline
Name&Problem 1&Problem 2&Problem 3&Problem 4&Total\\\hline
\name{Bergman, I.}&
\add{5.5}&\add{4}&\add{6}&\add{5}&\total\\\hline
\name{Durante, J.}&
\add{4}&\add{6}&\add{3}&\add{4.75}&\total\\\hline
\name{Grant, C.}&
\add{6}&\add{3}&\add{5}&\add{6}&\total\\\hline
\name{Hepburn, K.}&
\add{6}&\add{6}&\add{4}&\add{6}&\total\\\hline
\name{Stewart, J.}&
\add{5.25}&\add{6}&\add{3}&\add{5}&\total\\\hline
\end{tabular}
\end{center}
The total number of students is \the\numberofstudents.
\end{document}

Figure 1: A typical grades.tex file.

 6 \DeclareOption{solutions}{\@ADL@solutionstrue}
 7 \DeclareOption{nosolutions}{\@ADL@solutionsfalse}
 8 \DeclareOption{studentinfo}{\@ADL@sinfotrue}
 9 \DeclareOption{nostudentinfo}{\@ADL@sinfofalse}
10 \DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
11 \ExecuteOptions{nosolutions,nostudentinfo}
12 \ProcessOptions
13 \LoadClass{article}

We need to change \maketitle quite a lot to make it do what we want. Make sure all the user specifications are optional!

14

15 \renewcommand\maketitle{\par\newpage\global\@topnum\z@%
16 \@maketitle\let\maketitle\relax\let\@maketitle\relax}
17 \renewcommand\@maketitle{\newpage%
18 \ifx\@ADL@instructor\@undefined\def\@ADL@instructor{\@empty}\fi%
19 \ifx\@ADL@year\@undefined\def\@ADL@year{\@empty}\fi%
20 \begin{center}\large\bfseries%
21 \ifx\@ADL@course\@undefined\def\@ADL@course{\@empty}\else\@ADL@course\fi%
22 \ifx\@title\@undefined\def\@title{\@empty}\\\else\\[0.05in]\@title\ %
23 \ifx\@ADL@number\@undefined\relax\else\# \@ADL@number\fi\fi%
24 \end{center}%
25 \@ifundefined{@ADL@dategiven}{\@ifundefined{@ADL@datedue}{\relax}%
26 {\par\vskip 1em\noindent\begin{tabular}{@{}ll@{}}%
27 \@ifundefined{@ADL@dategiven}{\relax}{%
28 Date Given:&\space\@ADL@dategiven\\}%
29 Date Due:&\space\@ADL@datedue\\\end{tabular}}}%
30 {\par\vskip 1em\noindent
31 \begin{tabular}{@{}ll@{}}%
32 Date Given:&\space\@ADL@dategiven\\%
33 \@ifundefined{@ADL@datedue}{\relax}{%
34 Date Due:&\space\@ADL@datedue\\}\end{tabular}}\par\vskip 1em}

This page style gives the “page 2 of 8” thing which is quite handy (helps the students keep track of everything).

35

36 \if@ADL@sinfo
37 %  \def\ps@headings{\def\@oddfoot{}\def\@evenfoot{}
38 %    \def\@oddhead{\ifnum\c@page=\@ne%
39 %    {\reset@font\@ADL@studentinfo}%
40 %    \else{\reset@font\@ADL@instructor\hfil\@title\ %
41 %    \ifx\@ADL@number\@undefined\relax\else\# \@ADL@number\ \fi%
42 %    (Page \thepage\ of~\pageref{LastPage})\hfil
43 %    \@ADL@year}\fi}\let\@evenhead\@oddhead}
44 \def\ps@headings{\def\@oddfoot{}\def\@evenfoot{}
45  \def\@oddhead{\ifnum\c@page=\@ne%
46  {\reset@font\@ADL@studentinfo}%
47  \else{\reset@font\@ADL@headcourse\hfill%
48  \thepage\ of \pageref{LastPage}}\fi}\let\@evenhead\@oddhead}
49 \else
50 %  \def\ps@headings{\def\@oddfoot{}\def\@evenfoot{}

51 %    \def\@oddhead{\ifnum\c@page=\@ne%
52 %    {\reset@font\@ADL@instructor\hfill\@ADL@year}%
53 %    \else{\reset@font\@ADL@instructor\hfil\@title\ %
54 %    \ifx\@ADL@number\@undefined\relax\else\# \@ADL@number\ \fi%
55 %    (Page \thepage\ of~\pageref{LastPage})\hfil
56 %    \@ADL@year}\fi}\let\@evenhead\@oddhead}
57 \def\ps@headings{\def\@oddfoot{}\def\@evenfoot{}
58  \def\@oddhead{\ifnum\c@page=\@ne%
59  {\reset@font\@ADL@instructor\hfill\@ADL@year}%
60  \else{\reset@font\@ADL@headcourse\hfill%
61  \thepage\ of \pageref{LastPage}}\fi}\let\@evenhead\@oddhead}
62 \fi
63 \pagestyle{headings}

Here are all the macros allowing the user to specify his/her “data.”

64

65 \renewcommand\title[1]{\def\@title{#1}}
66 \newcommand\num[1]{\def\@ADL@number{#1}}
67 \newcommand\course[1]{\def\@ADL@course{#1}\def\@ADL@headcourse{#1}}
68 \newcommand\headcourse[1]{\def\@ADL@headcourse{#1}}
69 \renewcommand\year[1]{\def\@ADL@year{#1}}
70 \newcommand\instructor[1]{\def\@ADL@instructor{#1}}
71 \newcommand\dategiven[1]{\def\@ADL@dategiven{#1}}
72 \newcommand\datedue[1]{\def\@ADL@datedue{#1}}
73 \newcommand\studentinfo[1]{\def\@ADL@studentinfo{#1}}

Here are the basic problem environments. Nothing too fancy here — just normal use of list. I have to go to some trouble to handle the stars.

74

75 \newcounter{problem}
76 \newcounter{subproblem}
77 \newcounter{subsubproblem}
78 \def\problems{\list{\textbf{P\arabic{problem}.}}{\itemindent\z@
79 \renewcommand{\makelabel}[1]
80 {\if@ADL@star\setbox1\hbox{*}\hspace{-\wd1}*##1\else
81 \if@ADL@dstar\setbox1\hbox{**}\hspace{-\wd1}**##1\else##1\fi\fi\hfil}
82 \settowidth{\labelwidth}{\textbf{P8.}}
83 \leftmargin\labelwidth\advance\leftmargin\labelsep\listparindent1em
84 \parsep\z@\usecounter{problem}\let\problem\probitem}}
85 \let\endproblems\endlist
86 \newenvironment{subproblems}{\list{\textbf{(\alph{subproblem})}}{\itemindent\z@
87 \renewcommand{\makelabel}[1]
88 {\if@ADL@star\setbox1\hbox{*}\hspace{-\wd1}*##1\else
89 \if@ADL@dstar\setbox1\hbox{**}\hspace{-\wd1}**##1\else##1\fi\fi\hfil}
90 \settowidth{\labelwidth}{\textbf{(m)}}
91 \leftmargin\labelwidth\advance\leftmargin\labelsep\listparindent1em
92 \parsep\z@\usecounter{subproblem}\let\subproblem\probitem}}
93 {\endlist}
94 \newenvironment{subsubproblems}{\list{\textbf{(\roman{subsubproblem})}}
95 {\itemindent\z@\renewcommand{\makelabel}[1]
96 {\if@ADL@star\setbox1\hbox{*}\hspace{-\wd1}*##1\else

 97 \if@ADL@dstar\setbox1\hbox{**}\hspace{-\wd1}**##1\else##1\fi\fi\hfil}
 98 \settowidth{\labelwidth}{\textbf{(iii)}}\leftmargin\labelwidth
 99 \advance\leftmargin\labelsep\usecounter{subsubproblem}\listparindent1em
100 \parsep\z@\let\subsubproblem\probitem}}
101 {\endlist}

Define \item when inside one of the problem environments. Also, define the appearance of the list items in the list and when referenced.

102

103 \newif\if@ADL@star\@ADL@starfalse
104 \newif\if@ADL@dstar\@ADL@dstarfalse
105 \newcommand\probitem{\@ADL@starfalse\@ADL@dstarfalse
106 \@ifstar{\@ADL@probstar}{\@ADL@probnostar}}
107 \newcommand\@ADL@probnostar{\@ifnextchar[{\@ADL@probitemval}{\item}}
108 \newcommand\@ADL@probstar{\@ifstar{\@ADL@@probdstar}{\@ADL@@probstar}}
109 \newcommand\@ADL@@probstar{\@ADL@startrue
110 \@ifnextchar[{\@ADL@probitemval}{\item}}
111 \newcommand\@ADL@@probdstar{\@ADL@dstartrue
112 \@ifnextchar[{\@ADL@probitemval}{\item}}
113 \def\@ADL@probitemval[#1]{\item $[$\textit{\textbf{#1}}$]$}
114 \renewcommand\theproblem{\arabic{problem}}
115 \renewcommand\thesubproblem{\alph{subproblem}}
116 \renewcommand\thesubsubproblem{\roman{subsubproblem}}
117 \newcommand\labelproblem{\theproblem.}
118 \newcommand\labelsubproblem{(\thesubproblem)}
119 \newcommand\labelsubsubproblem{(\thesubsubproblem)}
120 %\renewcommand\p@subproblem{\theproblem}
121 %\renewcommand\p@subsubproblem{\theproblem\thesubproblem\,}
122 \newcommand\probref[1]{\hbox{\textbf{P\ref{#1}}}}

The solution environment and associated widgets.

123

124 \if@ADL@solutions
125 \ClassWarning{class}{Solutions will be displayed}
126 \newenvironment{solution}{\trivlist
127 \item[\hskip\labelsep\small{\bfseries Solution:}]\small}
128 {\endtrivlist}
129 \else
130 \ClassWarning{class}{No solutions will be displayed}
131 \excludecomment{solution}
132 \fi

133

134 \newcommand\solutiontest[2]{\if@ADL@solutions#1\else#2\fi}

135

136 ⟨/class⟩

137 ⟨∗gradelist⟩

Large parts of gradelist mimic class, so I’ll only say what’s unique.

138

139 \RequirePackage{lastpage}
140 \LoadClass{article}

142 \renewcommand\maketitle{\par\newpage\global\@topnum\z@%
143 \@maketitle\let\maketitle\relax\let\@maketitle\relax}
144 \renewcommand\@maketitle{\newpage%
145 \ifx\@ADL@instructor\@undefined\def\@ADL@instructor{\@empty}\fi%
146 \ifx\@ADL@year\@undefined\def\@ADL@year{\@empty}\fi%
147 \begin{center}\large\bfseries%
148 \ifx\@ADL@course\@undefined\def\@ADL@course{\@empty}\else\@ADL@course\fi%
149 \ifx\@title\@undefined\def\@title{\@empty}\\\else\\[0.05in]\@title\ %
150 \ifx\@ADL@number\@undefined\relax\else\# \@ADL@number\fi\fi%
151 \end{center}%
152 \@ifundefined{@ADL@dategiven}{\@ifundefined{@ADL@datedue}{\relax}%
153 {\par\vskip 1em\noindent\begin{tabular}{@{}ll@{}}%
154 \@ifundefined{@ADL@dategiven}{\relax}{%
155 Date Handed Out:&\space\@ADL@dategiven\\}%
156 Date Due:&\space\@ADL@datedue\\\end{tabular}}}%
157 {\par\vskip 1em\noindent
158 \begin{tabular}{@{}ll@{}}%
159 Date Handed Out:&\space\@ADL@dategiven\\%
160 \@ifundefined{@ADL@datedue}{\relax}{%
161 Date Due:&\space\@ADL@datedue\\}\end{tabular}}\par\vskip 1em}

162

163 \def\ps@headings{\def\@oddfoot{}\def\@evenfoot{}
164 \def\@oddhead{\ifnum\c@page=\@ne%
165 {\reset@font\@ADL@instructor\hfill\@ADL@year}%
166 \else{\reset@font\@ADL@instructor\hfil\@title\ %
167 \ifx\@ADL@number\@undefined\relax\else\# \@ADL@number\ \fi%
168 (Page \thepage\ of~\pageref{LastPage})\hfil
169 \@ADL@year}\fi}\let\@evenhead\@oddhead}
170 \pagestyle{headings}

171

172 \renewcommand\title[1]{\def\@title{#1}}
173 \newcommand\num[1]{\def\@ADL@number{#1}}
174 \newcommand\course[1]{\def\@ADL@course{#1}}
175 \renewcommand\year[1]{\def\@ADL@year{#1}}
176 \newcommand\instructor[1]{\def\@ADL@instructor{#1}}

I need some TEX commands for doing arithmetic. These use TEX dimensions for such operations. I would not want to write FEM code in TEX.

177

178 \newcommand\@ADL@realmult[3]{\dimen0=#1pt \dimen2=#2\dimen0
179 \global\edef #3{\expandafter\c@lean\the\dimen2}}
180 \newcommand\@ADL@realadd[3]{\dimen0=#1pt \dimen2=#2pt
181 \advance \dimen0 by \dimen2
182 \global\edef #3{\expandafter\c@lean\the\dimen0}}
183 {\catcode`\p=12 \catcode`\t=12
184 \gdef\c@lean #1pt{#1}}

Here’s the “new” things needed by gradelist.

185

186 \newcount\numberofstudents\numberofstudents\z@

187 \newwrite\@ADL@names
188 \newwrite\@ADL@grades
189 \immediate\openout\@ADL@names=names.out
190 \immediate\openout\@ADL@grades=grades.out

And here are the basic user commands which are simple once you have the capability of doing arithmetic.

191

192 \newcommand\name[1]{#1\immediate\write\@ADL@names{#1}}
193 \newcommand\add[1]{\@ADL@realadd{#1}\@ADL@assignmentgrade
194 \@ADL@assignmentgrade #1}
195 \newcommand\total{\@ADL@assignmentgrade\immediate\write\@ADL@grades
196 {\@ADL@assignmentgrade}
197 \@ADL@realmult{0}{0}\@ADL@assignmentgrade
198 \global\advance\numberofstudents by 1}
199 \@ADL@realmult{0}{0}\@ADL@assignmentgrade

200

201 ⟨/gradelist⟩