

% Turn off special handling of vertical bars by lgrind, so tabular
% works properly.
%|-
% The order of sections in a class package:

% Identification Part
% Initial Code Part
% Declaration of Options
% Execution of Options
% Package Loading
% Main Code


% Identification Part:
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{ictexam04}[2004/02/01 For IVE ICT exams]

% Initial Code Part: empty

% Declaration of Options
\DeclareOption{supplementary}{%
  \AtEndOfClass%
  {%
    \renewcommand*{\examtype}{Supplementary Exam}%
  }%
}
% Why so many categories of parts to include or exclude?
% questionsonly --- for the question exam paper only.  Includes page
%                   breaks and stuff that only make sense for the
%                   final exam paper.  Also use to exclude the
%                   appendices, and references to the appendices.
% aquestion ---     An exam question.  Can exclude for solutions only.
% solution ---      A solution to a question.  Has the important side
%                   effect that there is an \item[\textbf{Solution:}]
%                   created at the start.
% markingscheme --- The marking scheme---for official solutions only.
% solns ---         Other stuff to be shown in solution, which are not
%                   actual answers to questions, and are not marking
%                   scheme.  Could be useful for things that should
%                   appear only in a solution, but for which you do
%                   not want an \item[\textbf{Solution:}] to appear.
% notmarkingscheme  This is for material that should appear when there
%                   is no marking scheme displayed, but we are
%                   displaying solutions.  An example is program code
%                   with marking scheme is displayed in one case, but
%                   for other cases when want to not show marking
%                   scheme, use notmarkingscheme to display the code
%                   without the marking scheme.



\DeclareOption{solutions}{%
  \AtEndOfClass%
  {%
    \excludeversion{questionsonly}%
    \includeversion{aquestion}%
    \includeversion{solution}%
    \includeversion{solns}%
    \includeversion{markingscheme}%
    \excludeversion{notmarkingscheme}%
    % Note that \gdef is much more hairy than \newcommand et al.
    % It does wierd things to environments.  Luckily,
    % it seems to do exactly what we want here.
    \gdef\department{Dept. of Information \& Comms Tech.\ \
      {\large SOLUTIONS}}
    \gdef\solution{\item[\textbf{Solution:}]}
  }%
}

% Solutions, but no questions:
\DeclareOption{solutionsonly}{%
  \AtEndOfClass%
  {%
    \excludeversion{questionsonly}%
    \excludeversion{aquestion}%
    \includeversion{solution}%
    \includeversion{solns}%
    \includeversion{markingscheme}%
    \excludeversion{notmarkingscheme}%
    % Note that \gdef is much more hairy than \newcommand et al.
    % It does wierd things to environments.  Luckily,
    % it seems to do exactly what we want here.
    \gdef\department{Dept. of Information \& Comms Tech.\ \
      {\large SOLUTIONS}}
    %\gdef\solution{\item[\textbf{Solution:}]}
  }%
}

\DeclareOption{studentsolutions}{%
  \AtEndOfClass%
  {%
    \excludeversion{questionsonly}%
    \includeversion{aquestion}%
    \includeversion{solution}%
    \includeversion{solns}%
    \excludeversion{markingscheme}%
    \includeversion{notmarkingscheme}%
    \gdef\department{Dept. of Information \& Comms Tech.\ \
      {\large SOLUTIONS}---no marking scheme}
    \gdef\solution{\item[\textbf{Answer:}]}
    \RequirePackage[%
      light,%
      %first,%
      % bottomafter%
    ]{draftcopy}
    % \draftcopySetGrey{0.95}% .90 is light, .85 is dark. .975 seemed
    % okay.
    \draftcopyName{unofficial}{150}
    \fancyfoot{}%
    \lhead{\parbox[b]{0.8\linewidth}{\subject---\examtype{}
        \nextyear --- some answers}}
    %\lhead{\subject---\examtype{} \nextyear --- some answers}
  }%
}

\DeclareOption{questionsonly}{%
  \AtEndOfClass%
  {%
    \includeversion{questionsonly}%
    \includeversion{aquestion}%
    \excludeversion{solution}%
    \excludeversion{markingscheme}%
    \excludeversion{notmarkingscheme}% Hmm, is this right???  Yes.
    \excludeversion{solns}%
  }%
}

\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}

% Execution of options

\ExecuteOptions{questionsonly}

\ProcessOptions

% Special class file commands

\LoadClass[%
   a4paper,%
   12pt%
   ]{article}

% Oh dear, geometry version 3 in teTeX 2 is incompatible.
%\RequirePackage[compat2]{geometry}

\RequirePackage{%
   geometry,%
   acro,%
   lastpage,%
   booktabs,%
   %nbox,%
   multicol,%
   multirow,%
   fancyhdr,%
   float,%
   amssymb,%
   psfrag,%
   amsmath,%
   graphicx,%
   amstext,%
   hhline,%
   cols,%
   key,%
   ifthen,%
   mdwlist,%
   calc,%
   alltt,%
   fancybox,%
   verbatim,%
   moreverb,%
   version,%
   nick%
}
\RequirePackage{varioref}[2004/02/27]

% \RequirePackage[pdfpagemode=None,
% pdfauthor={Nick Urbanik},
% pdfstartview=FitH,
% pdfpagemode=FitWidth,
% pdfkeywords={Operating Systems, Systems Integration},
% pdftitle={Final Examination, June 2002, Operating Systems
%   and Systems Integration},
% pdfsubject={Operating Systems and Systems Integration}
% ]{hyperref}

%\RequirePackage[nooneline,hang,bf]{caption2}
\RequirePackage[bf,flushleft,nooneline]{caption2}

% See Section 19.7, ``Custom Caption Styles'', page 57,
% epslatex.ps:
\newcaptionstyle{nocaption}{%
  \usecaptionmargin\captionfont%
  {{\bfseries\captionlabelfont\captionlabel.}}%
}

\@ifpackagelater{geometry}{2000/01/01}{%
  \geometry{compat2, left = 30mm, top = 15mm, right = 30mm, bottom = 29mm,
    headheight = 25.5pt, headsep = 8mm, footskip = 12mm}%
}{%
  \geometry{left = 30mm, top = 15mm, right = 30mm, bottom = 29mm,
    headheight = 25.5pt, headsep = 8mm, footskip = 12mm}%
}

\newlength{\ttWid}
\settowidth{\ttWid}{\texttt{\small{}m}}
\newcommand*{\threespace}{\underline{\hspace*{3\ttWid}}}
\newcommand*{\twospace}{\underline{\hspace*{2\ttWid}}}

\newenvironment{explanation}%
{%
   \begin{list}{}%
   {%
      \setlength{\parskip}{0.8em plus .2em minus .2em}
      \rightmargin \leftmargin
      \topsep 0pt%
   }%
   \small\item[]%
}%
{\end{list}}

% p. 74 of LaTeX Companion:
\newcommand{\marginlabel}[1]
    {\mbox{}\marginpar{\raggedright\hspace{0pt}#1}}

\DeclareRobustCommand{\marksFont}[1]{{\small#1}}

\DeclareRobustCommand{\marks}[1]{%
   \ifthenelse{\equal{#1}{1} \or \equal{#1}{0.5}}%
   {\mbox{}\marginpar{\raggedright\hspace{0pt}{\marksFont{(#1 mark)}}}}%
   %{\marginpar{\small\textmedium{#1 mark}}}%
% else
   %{\marginpar{\small\textmedium{#1 marks}}}%
   {\mbox{}\marginpar{\raggedright\hspace{0pt}{\marksFont{(#1 marks)}}}}%
}

% Stolen from exam.dtx:
%@-
%\providecommand\leftnote[1][-\baselineskip]{\@rlnote l{#1}}
%\providecommand\rightnote[1][-\baselineskip]{\@rlnote r{#1}}
%\providecommand\leftnote[1][-1.5\baslineskip]{\@rlnote l{#1}}
%\providecommand\rightnote[1][-1.5\baselineskip]{\@rlnote r{#1}}
\providecommand\leftnote[1][-0.75\baslineskip]{\@rlnote l{#1}}
\providecommand\rightnote[1][-0.75\baselineskip]{\@rlnote r{#1}}
%\providecommand\@rlnote[3]%
%{%
%   \noindent\vadjust%
%   {%
%      \vbox to\z@%
%      {%
%         \vskip#2\leftskip\z@skip\rightskip\z@skip\noindent
%         \if#1l%
%            \llap{#3\hskip\marginparsep}%
%         \else%
%            \hfill\rlap{\hskip\marginparsep#3}%
%         \fi%
%         \vss\vskip\z@skip%
%      }%
%   }%
%}

\providecommand\@rlnote[3]%
{%
   \noindent\vadjust%
   {%
      \vtop to\z@%
      {%
          \vskip-\baselineskip\leftskip\z@skip\rightskip\z@skip\noindent
          \if#1l%
             \llap{#3\hskip\marginparsep}%
          \else%
             \hfill\rlap{\hskip\marginparsep#3}%
          \fi%
          \vss\vskip\z@skip%
      }%
   }%
}

% Now try after looking at page 316 of the TeXbook:

%\def\strutdepth{\dp\strutbox}
%\providecommand\@rlnote[3]%
%{%
%   \noindent\vadjust%
%   {%
%      \vtop to\z@%
%      {%
%          \vskip#2\leftskip\z@skip\rightskip\z@skip\noindent
%          \if#1l%
%             \llap{#3\hskip\marginparsep}%
%          \else%
%             \hfill\rlap{\hskip\marginparsep#3}%
%          \fi%
%          \vss\vskip\z@skip%
%      }%
%   }%
%}

% This comes nowhere near working:

%\providecommand\@rlnote[3]%
%{%
%   \if#1l%
%       \llap{#3\hskip\marginparsep}%
%   \else%
%       \hfill\rlap{\hskip\marginparsep#3}%
%   \fi%
%}

%@+

%\DeclareRobustCommand{\marks}[1]{%
%   \ifthenelse{\equal{#1}{1}}%
%   {\mbox{}\rightnote{\raggedright\hspace{0pt}{\marksFont{#1 mark}}}}%
%% else
%   {\mbox{}\rightnote{\raggedright\hspace{0pt}{\marksFont{#1 marks}}}}%
%}

% Note that \topsep, \parsep, etc are set in size12.clo.
\newenvironment{question}{%
       \enumerate
%       \parskip 12pt plus 2pt minus 2pt%
%       \itemsep 15pt plus 7.5pt minus 3pt%
%       \topsep 30pt plus 12pt minus 12pt%
%       \parsep 12pt plus 2pt minus 2pt%
%       \partopsep 12pt plus 4pt minus 4pt\relax%
}{\endenumerate}

\newenvironment{subQuestion}{%
       \enumerate
%       \parskip 3pt plus 1pt minus 1pt%
%       \itemsep 5pt plus 2.5pt minus 1pt%
%       \topsep 7pt plus 2.5pt minus 1pt%
%       \parsep 3pt plus 1pt minus 1pt%
%       \partopsep 3pt plus 2pt minus 2pt\relax%
}{\endenumerate}

%@-
%% \def\@listi{\leftmargin\leftmargini
%%        \partopsep 12pt plus 4pt minus 4pt%
%%        \parskip 12pt plus 2pt minus 2pt%
%%        \itemsep 15pt plus 7.5pt minus 3pt%
%%        \topsep 30pt plus 12pt minus 12pt%
%%        \parsep 12pt plus 2pt minus 2pt%
%% %            \parsep 5\p@  \@plus2.5\p@ \@minus\p@
%% %            \topsep 10\p@ \@plus4\p@   \@minus6\p@
%% %            \itemsep5\p@  \@plus2.5\p@ \@minus\p@%
%% }
%% \let\@listI\@listi
%% \@listi
% From size12.clo, 25 March 2002:
%% \def\@listi{\leftmargin\leftmargini
%%             \parsep 5\p@  \@plus2.5\p@ \@minus\p@
%%             \topsep 10\p@ \@plus4\p@   \@minus6\p@
%%             \itemsep5\p@  \@plus2.5\p@ \@minus\p@}
%% \let\@listI\@listi
%% \@listi
%% \def\@listii {\leftmargin\leftmarginii
%%               \labelwidth\leftmarginii
%%               \advance\labelwidth-\labelsep
%%               \topsep    5\p@   \@plus2.5\p@ \@minus\p@
%%               \parsep    2.5\p@ \@plus\p@    \@minus\p@
%%               \itemsep   \parsep}
%% \def\@listiii{\leftmargin\leftmarginiii
%%               \labelwidth\leftmarginiii
%%               \advance\labelwidth-\labelsep
%%               \topsep    2.5\p@\@plus\p@\@minus\p@
%%               \parsep    \z@
%%               \partopsep \p@ \@plus\z@ \@minus\p@
%%               \itemsep   \topsep}
%% \def\@listiv {\leftmargin\leftmarginiv
%%               \labelwidth\leftmarginiv
%%               \advance\labelwidth-\labelsep]
                 

% My modifications to the above, to increase spacing between questions:
\def\@listi{\leftmargin\leftmargini
            \parsep 5\p@  \@plus2.5\p@ \@minus\p@
            \topsep 10\p@ \@plus4\p@   \@minus6\p@
            \itemsep35\p@  \@plus10\p@ \@minus5\p@}
\let\@listI\@listi
\@listi
\def\@listii {\leftmargin\leftmarginii
              \labelwidth\leftmarginii
              \advance\labelwidth-\labelsep
              \topsep    5\p@   \@plus2.5\p@ \@minus\p@
              \parsep    2.5\p@ \@plus\p@    \@minus\p@
              \itemsep   20\p@   \@plus6\p@ \@minus2\p@}
\def\@listiii{\leftmargin\leftmarginiii
              \labelwidth\leftmarginiii
              \advance\labelwidth-\labelsep
              \topsep    2.5\p@\@plus\p@\@minus\p@
              \parsep    \z@
              \partopsep \p@ \@plus\z@ \@minus\p@
              \itemsep   15\p@   \@plus5\p@ \@minus2\p@}
\def\@listiv {\leftmargin\leftmarginiv
              \labelwidth\leftmarginiv
              \advance\labelwidth-\labelsep
              \itemsep   8\p@\@plus4\p@\@minus\p@}

% To implement the ``Departmental Style'' (although I think that it is
% a Departmental Lack Of Style.)
\renewcommand\theenumii{\@roman\c@enumii}
\renewcommand\theenumiii{\@alph\c@enumiii}
\renewcommand\theenumiv{\@Alph\c@enumiv}
%\newcommand\labelenumi{\theenumi.}
\renewcommand{\labelenumi}{\textbf{Q\theenumi.}}
\renewcommand\labelenumii{\textbf{\theenumii)}}
\renewcommand\labelenumiii{\textbf{(\theenumiii)}}
\renewcommand\labelenumiv{\textbf{\theenumiv.}}
\renewcommand\p@enumii{\theenumi.}
\renewcommand\p@enumiii{\theenumi(\theenumii)}
\renewcommand\p@enumiv{\p@enumiii\theenumiii}
%% \renewcommand\theenumii{\@alph\c@enumii}
%% \renewcommand\theenumiii{\@roman\c@enumiii}
%% \renewcommand\theenumiv{\@Alph\c@enumiv}
%% \newcommand\labelenumi{\theenumi.}
%% \newcommand\labelenumii{(\theenumii)}
%% \newcommand\labelenumiii{\theenumiii.}
%% \newcommand\labelenumiv{\theenumiv.}
%% \renewcommand\p@enumii{\theenumi}
%% \renewcommand\p@enumiii{\theenumi(\theenumii)}
%% \renewcommand\p@enumiv{\p@enumiii\theenumiii}

%% \renewcommand{\theenumii}{\roman{enumii}}
%% \renewcommand{\labelenumii}{\textbf{\theenumii)}}
%% \renewcommand{\theenumiii'}{\alph{enumiii}}
%% \renewcommand{\labelenumiii}{\textbf{(\theenumiii)}}

% The following was the result of a major grepping and source viewing
% session.  I found the most helpful source to be ltxref.dtx, part of
% LaTeX2e.  The packages caption.dtx and caption2.dtx didn't help
% much.

% This works rather well; it could now be put into a package.
% Perhaps it would be appropriate to make it part of \caption, so that
% there is no special word required for each float type.

% Update: Donald told me how to do it right, bless him:
%% From: Donald Arseneau <asnd@triumf.ca>
%% Newsgroups: comp.text.tex
%% Subject: Re: References: my macros are broken; please help
%% Date: 19 Mar 2002 18:12:55 -0800
%% Organization: TRIUMF: Canada's national meson facility
%% Lines: 44
%% Sender: asnd@mutant
%% Message-ID: <yfipu207zrs.fsf@triumf.ca>
%% References: <3C94ECA4.81946117@vtc.edu.hk> <yfid6y2jl9o.fsf@triumf.ca> <3C96924D.BDC45404@vtc.edu.hk> <yfi1yehjfej.fsf@triumf.ca> <3C97C91F.F2C93D8A@vtc.edu.hk>
%% Mime-Version: 1.0
%% Content-Type: text/plain; charset=us-ascii
%% X-Trace: nntp.itservices.ubc.ca 1016590085 6793 142.90.112.22 (20 Mar 2002 02:08:05 GMT)
%% X-Complaints-To: abuse@interchange.ubc.ca
%% User-Agent: Gnus/5.0807 (Gnus v5.8.7) Emacs/20.7
%% Xref: dragon.vtc.edu.hk comp.text.tex:122897

%% Nick Urbanik <nicku@vtc.edu.hk> writes:

%% > Donald Arseneau wrote:
%% > 
%% > > Nick Urbanik <nicku@vtc.edu.hk> writes:
%% > >
%% > > > > >       \newFigTag{QB\ref{que:paging}}
%% > > > > or...).  Note that you are
%% > > > > using \ref in a label.
%% > > >
%% > > > Sorry to be so slow, but what would be a good idea to do instead?
%% > >
%% > > Think about what you really want.  I expect you don't want
%% > > a hyper-link to be part of the fig-tag.  (It can't work
%% > > even if you DID want that!)  Maybe you want to use
%% > > \@currentreference?
%% > 
%% > That doesn't seem to work.  

%% You noticed it was really \@currentlabel, and it does work.

%% > What I'm aiming for is a label for each
%% > figure that matches the question number, 

%% Why don't you make a new class of float, which is cleaner, rather
%% than calling them figures.

%% > Here is an example document that works as reuired, except that it does
%% > not work with hyperref, 

%% But it still doesn't explain WHAT labelling you want.  What is "match"?
%% Using \ref is neither feasible nor elegant.

%% Using \@currentlabel does work.

%% \newcommand*{\newFigTag}{
%%        \protected@edef\thefigure{Q\@currentlabel}%
%%        \def\@currentlabel{\thefigure}%
%%        \def\refstepcounter##1{}%
%% }

\newcommand*{\newQTag}{%
       \protected@edef\thefigure{Q\@currentlabel}%
       \protected@edef\thetable{Q\@currentlabel}%
       \protected@edef\theprogram{Q\@currentlabel}%
}

%% \newcommand*{\newFigTag}[1]{%
%%        \def\fnum@figure{Figure #1}%
%%        \def\@currentlabel{#1}%
%%        \def\refstepcounter##1{}%
%% }
%% \newcommand*{\newTabTag}[1]{%
%%        \def\fnum@table{Table #1}%
%%        \def\@currentlabel{#1}%
%%        \def\refstepcounter##1{}%
%% }
%% %\newcommand{\newTabTag}[1]{%
%% %       \def\fnum@table{Table #1}%
%% %}
%% \newcommand*{\newProgTag}[1]{%
%%        \def\fnum@program{Program listing #1}%
%% %       \def\fnum@program{Figure #1}%
%%        \def\@currentlabel{#1}%
%%        \def\refstepcounter##1{}%
%% }

\setlength{\marginparsep}{6mm}
\setlength{\marginparwidth}{20mm}
\newcommand*{\pinNumSize}{\scriptsize}

% Nick:
% This is what may override in the document:
% \newcommand*{\department}{Department of Information and Communications
%   Technology}%
\newcommand*{\subject}{Operating Systems and Systems Integration}%
%\newcommand*{\dateofexam}{June sometime}
\newcommand*{\dateofexam}{June 2004}%
\newcommand*{\subjectnumber}{CMT3321}%
\newcommand*{\department}{Department of Information and Communications
  Technology (Tsing Yi)}
\newcommand*{\courseName}{FT Higher Diploma in Computer Systems
  Administration}
\newcommand*{\courseCode}{41300}

\newcommand*{\headerfontsize}{\footnotesize}%
\newcommand*{\footerfontsize}{\scriptsize}
\newcommand{\examtype}{Main Examination}
\newcounter{year}
\setcounter{year}{2003}
\newcounter{nextyear}
\setcounter{nextyear}{\value{year}}
\addtocounter{nextyear}{1}
\newcommand*{\thisyear}{\arabic{year}}
\newcommand*{\nextyear}{\arabic{nextyear}}

\newsavebox{\fminibox}%
\newlength{\fminilength}%
\setlength{\fminilength}{\textwidth-2\fboxsep-2\fboxrule}%

\pagestyle{fancy}
\lhead{\headerfontsize\textbf{\upshape \department\\
\courseName{} (\courseCode)}}
\rhead{\headerfontsize\textbf{\upshape page \thepage{} of
    \pageref{LastPage}}}
%    \pageref{pag:lastpage}}}

\lfoot{\noindent\fbox{%
    \begin{minipage}[t]{\fminilength}%
      \headerfontsize\upshape
      \begin{minipage}[t]{0.35\fminilength}%
        \raggedright\subject{} (\subjectnumber)
      \end{minipage}%
      %\subject{} \hfill
      \hfill\thisyear/\nextyear
    \end{minipage}%
  }}

\cfoot{\headerfontsize\upshape\examtype}

\renewcommand{\floatpagefraction}{0.75} % default is .5, to increase
% density.
\renewcommand*{\bottomfraction}{0.6} % default is 0.3
\renewcommand*{\topfraction}{0.85} % default is 0.7
\renewcommand*{\textfraction}{0.1} % default is 0.2

\setlength{\extrarowheight}{0pt}
\floatstyle{ruled}
\floatname{program}{Figure}
\newfloat{program}{tbh}{lop}

\providecommand*{\dc}{\textsf{\relsize{-1}X}\xspace} % dc = Don't care.
%\renewcommand{\captionfont}{\raggedright}

\providecommand*{\half}{\fracSl{1}{2}\xspace}
\providecommand*{\quarter}{\fracSl{1}{4}\xspace}

\renewcommand\appendix{\par
  \setcounter{section}{0}%
  \setcounter{subsection}{0}%
  \gdef\thesection{\appendixname\ \@Alph\c@section}}

\includeversion{questionsonly}%
\includeversion{aquestion}%
\excludeversion{solution}%
\excludeversion{markingscheme}%
\excludeversion{solns}%

\newlength{\SA}
\newlength{\SB}
\newlength{\SC}
\newlength{\SD}
\newlength{\Se}
\newlength{\amount}
\settoheight{\SA}{\scriptsize $\star$}
\settoheight{\SB}{\footnotesize $\star$}
\settoheight{\SC}{\small $\star$}
\settoheight{\SD}{\normalsize $\star$}
\settoheight{\Se}{\large $\star$}

\setlength{\amount}{0.5\Se}

\gdef\solution{\item[\textbf{Solution:}]}

% [1][end of questions]{
\DeclareRobustCommand{\endOfExam}[1][end of questions]{%
\hfill%
\raisebox{\amount-0.5\SA}[0pt][0pt]{\makebox{\scriptsize $\star$}}
\raisebox{\amount-0.5\SB}[0pt][0pt]{\makebox{\footnotesize $\star$}}
\raisebox{\amount-0.5\SC}[0pt][0pt]{\makebox{\small $\star$}}
\raisebox{\amount-0.5\SD}[0pt][0pt]{\makebox{\normalsize $\star$}}
\raisebox{\amount-0.5\Se}[0pt][0pt]{\makebox{\large $\star$}}
\hspace{1em}
\textbf{#1}
\hspace{1em}
\raisebox{\amount-0.5\Se}[0pt][0pt]{\makebox{\large $\star$}}
\raisebox{\amount-0.5\SD}[0pt][0pt]{\makebox{\normalsize $\star$}}
\raisebox{\amount-0.5\SC}[0pt][0pt]{\makebox{\small $\star$}}
\raisebox{\amount-0.5\SB}[0pt][0pt]{\makebox{\footnotesize $\star$}}
\raisebox{\amount-0.5\SA}[0pt][0pt]{\makebox{\scriptsize $\star$}}
\hfill
}
\AtBeginDocument%
{%
\raggedright
}

% end of ictexam.cls
