%%
%%    File : cstn.cls    (LaTeX2e class file)
%%  Author : Martin Reddy (mxr@dcs.ed.ac.uk) 
%% Version : 2.5
%%
%% V2.5 : included all of paul's style improvements
%% V2.3b: if localdriver.sty not found, just give the \special
%% V2.3a: default pt size = 11pt (12pt with a4 option)
%% V2.3 : \revisionhistory gives \author name if \maintainer not specified
%%        \special command is conditional on dvips driver
%%
%% DCS Technote LaTeX2e class. see "texdoc cstn" for more info.
%%
%% Based upon original class written by David Aspinall, May 1995.
%% With contributions from Paul Anderson, October 1996.
%% (Some parts borrowed from ltxguide.cls). 
%% 
%% Notes:
%%  printing a5: dvips <file> | psbook | psnup -2 -s1.0 | lpr -Zduplex,tumble
%%  to do: font used for figure captions == sf
%%

\NeedsTeXFormat{LaTeX2e}[1994/12/01]
\ProvidesClass{cstn}[1996/06/24 DCS tech note style v2.5 (MXR)]

\RequirePackage{ifthen}

\newboolean{usea5paper}
\newcommand{\tnpapersize}{}     % the default paper size
\newcommand{\tnpntsize}{}       % the default font size

% All options are passed to the article class.
 
\DeclareOption{a4}{
  \renewcommand{\tnpntsize}{12pt}
  \renewcommand{\tnpapersize}{a4paper}
  \setboolean{usea5paper}{false}
}

\DeclareOption{a5}{
  \renewcommand{\tnpapersize}{a5paper}
  \setboolean{usea5paper}{true}
}

\DeclareOption{12pt}{\renewcommand{\tnpntsize}{12pt}}
\DeclareOption{11pt}{\renewcommand{\tnpntsize}{11pt}}
\DeclareOption{10pt}{\renewcommand{\tnpntsize}{}}

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

\ExecuteOptions{a5,11pt}
\ProcessOptions

%%
%% Class and package loading
%%

\LoadClass[\tnpapersize,\tnpntsize,twoside]{article}

\RequirePackage{pifont}   % for the default prompt in \userinput,\response

%%
%% Set page size for a4 and a5 versions
%%

\ifthenelse{\boolean{usea5paper}}
  {\addtolength{\oddsidemargin}{-0.25in}
   \addtolength{\evensidemargin}{-0.25in}  
   \addtolength{\topmargin}{-1.0in}
   \addtolength{\textwidth}{0.5in}
   \addtolength{\textheight}{1.5in}
   \IfFileExists{localdriver.sty}{%
     \RequirePackage{localdriver} % for DoIfDriver{}{}
     \DoIfDriver{dvips}{\special{papersize=148mm,210mm}}
   }{
     \typeout{Warning: localdriver.sty not found. Including dvips special}
     \special{papersize=148mm,210mm}
   }
  }{\RequirePackage{a4wide}} % just use a4wide.sty for the a4 margins

% the TN is designed to be printed with ``book'' so that the first
% forms the cover. This means that the evensidemargins and oddside
% margins are the wrong way around! We need to swap them to get the
% right gutters. (PAUL)

\newdimen\tmp
\let\tmp=\oddsidemargin
\let\oddsidemargin=\evensidemargin
\let\evensidemargin=\tmp
\let\@themargin=\oddsidemargin

% We have quite narrow columns and big characters, so we loosen the
% tolerance. People are unlikely to want to do too much fine tuning of
% the layout and this gives acceptable results with a few less error
% messages. (PAUL)

\tolerance=1200

%%
%% The tech note description variables
%%

\newcommand{\@initialdate}{??}
\newcommand{\@revision}{1.0}
\newcommand{\@revdesc}{}
\newcommand{\@maintainer}{}
\newcommand{\@tnnumber}{??}

\newcommand{\initialdate}[1]{\renewcommand{\@initialdate}{#1}}
\newcommand{\maintainer}[1]{\renewcommand{\@maintainer}{#1}}
\newcommand{\tnnumber}[1]{\renewcommand{\@tnnumber}{#1}}
\newcommand{\revision}[3][]{%
  \renewcommand{\@revdesc}{#1}%
  \renewcommand{\@revision}{#2}%
  \ifthenelse{\equal{#3}{}}{}{\renewcommand{\@date}{#3}}%
}

%%
%% handle \oldrevision. This is more complicated because we have to
%% remember all parameters to all previous \oldrevision calls too.
%% We do this by writing all info to a .tnt file (Tech Note Temp file)
%%

\newboolean{isfileopen}
\setboolean{isfileopen}{false}
\def\fax@outputname{\jobname.tnt}
\newwrite\fax@output

\newcommand{\@openfaxfile}{%
  \ifthenelse{\boolean{isfileopen}}{}%
    {\immediate\openout\fax@output=\fax@outputname%
     \setboolean{isfileopen}{true}%
    }
}
\newcommand{\@closefaxfile}{%
  \ifthenelse{\boolean{isfileopen}}%
    {\immediate\closeout\fax@output\setboolean{isfileopen}{false}}{}
}
\newcommand{\@inputfaxfile}{%
  \IfFileExists{\fax@outputname}{\input{\fax@outputname}}\relax
}

\newcommand{\faxitemize}{\noindent\ensuremath{\bullet}\ }
\newcommand{\faxenditem}{\vskip 1ex\par }

\newcommand{\oldrevision}[3][]{%
  \@openfaxfile%
  \immediate\write\fax@output{\string\faxitemize \relax %
    Revision #2 (#3). #1\faxenditem}%
}

%%
%% Set up the font sizes and dimensions for the title section
%%

\newlength{\lefttitlelen}

\ifthenelse{\boolean{usea5paper}}
  {\newcommand{\numberfontsize}{\large}
   \newcommand{\titlefontsize}{\Large}
   \newcommand{\versionfontsize}{\small}
   \newcommand{\authorfontsize}{\large}
   \newcommand{\maintainerfontsize}{\normalsize}
   \setlength{\lefttitlelen}{2in}}
  {\newcommand{\numberfontsize}{\LARGE}
   \newcommand{\titlefontsize}{\huge}
   \newcommand{\versionfontsize}{\normalsize}
   \newcommand{\authorfontsize}{\LARGE}
   \newcommand{\maintainerfontsize}{\large}
   \setlength{\lefttitlelen}{2in}}

\newlength{\righttitlelen}
\setlength{\righttitlelen}{\textwidth}
\addtolength{\righttitlelen}{-\lefttitlelen}

%%
%% Generate the title section
%%

\ifthenelse{\boolean{usea5paper}}
  {\renewcommand{\numberfontsize}{\Large}
   \renewcommand{\titlefontsize}{\LARGE}
   \renewcommand{\authorfontsize}{\Large}}
  {\renewcommand{\numberfontsize}{\huge}
   \renewcommand{\titlefontsize}{\Huge}
   \renewcommand{\authorfontsize}{\huge}}

\renewcommand{\maketitle}{%
   \renewcommand{\thefootnote}{\@fnsymbol\c@footnote}
   \let\footnotesize\small
   \noindent\vskip -0.2ex%
   \begin{minipage}[t]{\lefttitlelen}
     \numberfontsize\sffamily\textsl{CS--TN--\@tnnumber}
     \vspace*{5ex}
   \end{minipage}%
   \begin{minipage}[t]{\righttitlelen}
     \begin{flushright}\titlefontsize\sffamily\bfseries\@title\end{flushright}
   \end{minipage}
   \begin{flushleft}
     \sl\authorfontsize\sffamily\@author%
     \ifthenelse{\equal{\@maintainer}{}}%
        {}%
       {\\\maintainerfontsize{\rm (Currently
           maintained by} \@maintainer\/\rm)}%
     \vskip -2ex\noindent
   \end{flushleft}%
   \vspace*{1cm}
   \@thanks\setcounter{footnote}{0}
   \renewcommand{\thefootnote}{\@arabic\c@footnote}
}

%%
%% Put all section headings in sans serif font
%%

\renewcommand{\section}{\@startsection
  {section}{1}{0pt}{\baselineskip}{0.4\baselineskip}
  {\sffamily\Large\bfseries}}

\renewcommand{\subsection}{\@startsection
  {subsection}{2}{0pt}{\baselineskip}{0.4\baselineskip}
  {\sffamily\large\bfseries}}

\renewcommand{\subsubsection}{\@startsection
  {subsubsection}{3}{0pt}{\baselineskip}{0.4\baselineskip}
  {\sffamily\normalsize\bfseries}}

%%
%% Generate the revision history
%%

\newcommand{\revisionhistory}{%
  \@closefaxfile\relax
  \section*{Revision History}
  This document is published as technical note number \@tnnumber\ by
  the Department of Computer Science at the University of Edinburgh.
  The document's revision history is as follows:
  
\begin{quotation}
  \ifthenelse{\equal{\@revision}{1.0}}%
     {\faxitemize{Initial release (\@date).\faxenditem}}%
     {\faxitemize{Revision \@revision\ (\@date). \@revdesc\faxenditem}
      \@inputfaxfile
      \faxitemize{Initial release (\@initialdate).\faxenditem}
      \ifthenelse{\equal{\@initialdate}{??}}%
        {\typeout{WARNING: "initialdate" has not been defined.}}{}%
     }
\end{quotation}

  This document is currently maintained by
  \ifthenelse{\equal{\@maintainer}{}}{{\def\\{\ and}\@author}.}{\@maintainer.}
  \raisebox{0.2ex}{\copyright}\
  Department of Computer Science, University of Edinburgh.
}

%%
%% Style settings
%%
 
% No paragraph indentation, space between paragraphs.
 
\setlength{\parindent}{0pt}
\setlength{\parskip}{\smallskipamount}

% Run the toc tighter:

\setcounter{tocdepth}{1}
\def\@starttoc#1{\begingroup
  \makeatletter
  \parskip\z@\@plus\p@\relax         % <----
  \@input{\jobname.#1}\if@filesw
  \expandafter\newwrite\csname tf@#1\endcsname
             \immediate\openout
                 \csname tf@#1\endcsname \jobname.#1\relax
  \fi \global\@nobreakfalse \endgroup}

\renewcommand*{\l@section}[2]{%
  \ifnum \c@tocdepth >\z@
    \addpenalty{\@secpenalty}%
    \addvspace{0.2em \@plus\p@}%   <----
    \setlength\@tempdima{1.5em}%
    \begingroup
      \parindent \z@ \rightskip \@pnumwidth
      \parfillskip -\@pnumwidth
      \leavevmode \bfseries
      \advance\leftskip\@tempdima
      \hskip -\leftskip
      #1\nobreak\hfil \nobreak\hbox to\@pnumwidth{\hss #2}\par
    \endgroup
  \fi}

%%
%% A declaration of a command, in a box, set out into the margin.
%%

\newenvironment{decl}%
    {\par\addvspace{2.3ex}
     \vskip -\parskip%
     \noindent\hspace{\leftmargini}%
     \begin{tabular}{|l|}\hline\ignorespaces}%
    {\hfill\\\hline\end{tabular}\nobreak\par\nobreak
     \vspace{2.3ex}\vskip -\parskip}

%%
%% Verbatim hacks
%%

\let\o@verbatim\verbatim
\def\verbatim{%
  \ifhmode\unskip\par\fi
% \nopagebreak              % Overridden by list penalty
  \small
  \o@verbatim
}
 
% Here we extend the font-setting command to include making <> active
% (ie adjusting the input encoding).
%\renewcommand \verbatim@font {%
%  \normalfont \ttfamily
%  \catcode`\<=\active
%  \catcode`\>=\active
%}

% instead of making the <...> (set to italics) only work in verbatim
% mode (cstn v2.1 and previously), we shall make it work all the time

\catcode`\<=\active
\catcode`\>=\active
 
% Make |...| a synonym for \verb|...|.
 
\catcode`\|=\active
\def|{\verb|}

\def\ttbaron{\catcode`\|\active\def|{\verb|}}
\def\ttbaroff{\catcode`\|=12\def|{\symbol{124}}}
\newenvironment{normalpipe}{\ttbaroff}{\ttbaron}
 
% Make active <...> produce italics surrounded by angle brackets (used in
% verbatim and \verb).
% << produces a less-than, and >> produces a greater-than.
 
\begingroup
  \catcode`\<=\active
  \catcode`\>=\active
  \gdef<{\@ifnextchar<\@lt\@meta}
  \gdef>{\@ifnextchar>\@gt\@gtr@err}
  \gdef\@meta#1>{\m{#1}}
  \gdef\@lt<{\char`\<}
  \gdef\@gt>{\char`\>}
\endgroup
\def\@gtr@err{%
   \ClassError{cstn}{%
      Isolated \protect>%
   }{%
      In this document class, \protect<...\protect>
      is used to indicate a parameter.\MessageBreak
      I've just found a \protect> on its own.
      Perhaps you meant to type \protect>\protect>?
   }%
}
\def\verbatim@nolig@list{\do\`\do\,\do\'\do\-}

%%
%% Commands
%%

% This is a bunch of logical items which simply map onto different
% fonts. It is nice to keep them logical (like filename), so that
% we can do othger things later if we want:

\newcommand{\object}[1]{\texttt{#1}}
\newcommand{\method}[1]{\textsf{#1}}
\newcommand{\resource}[1]{\texttt{#1}}
\newcommand{\resvalue}[1]{\texttt{#1}}
\newcommand{\user}[1]{\texttt{#1}}
\newcommand{\group}[1]{\texttt{#1}}
\newcommand{\ypmap}[1]{\texttt{#1}}
\newcommand{\hostname}[1]{\texttt{#1}}
\newcommand{\domain}[1]{\texttt{#1}}
\newcommand{\newsgroup}[1]{\texttt{#1}}
\newcommand{\data}[1]{\texttt{#1}}
\newcommand{\target}[1]{\texttt{#1}}
\newcommand{\action}[1]{\texttt{#1}}
\newcommand{\define}[1]{{\em #1\/}}
\newcommand{\programname}[1]{\texttt{#1}}
\newcommand{\filename}[1]{\texttt{#1}}
\newcommand{\url}[1]{\texttt{#1}}
\newcommand{\envvar}[1]{\texttt{\$#1}}
\newcommand{\email}[1]{\texttt{<<#1>>}}
\newcommand{\menu}[1]{{\sffamily\bfseries#1}}


% commands to simulate user input and computer response

\newcommand{\defaultprompt}{\ding{220}}
\newcommand{\setprompt}[1]{\renewcommand{\defaultprompt}{#1}}
\newcommand{\typedinput}[2][\defaultprompt]{#1\ {\sf #2}}
\newcommand{\response}[2][\defaultprompt]{\texttt{#2}}
\newcommand{\cmd}[2]{\typedinput{#1}\\\response[]{#2}}

% Various forms of argument:

\newcommand{\m}[1]{\mbox{$\langle$\it #1\/$\rangle$}}
%\renewcommand{\arg}[1]{{\tt\string{}\m{#1}{\tt\string}}}
\renewcommand{\arg}[1]{\m{#1}}
\newcommand{\oarg}[1]{{\tt[}\m{#1}{\tt]}}

% commands to get a tilde symbol for home directory names

\newcommand{\twiddle}{\ensuremath{\sim}}

% commands for keyboard symbols

\newcommand{\@tnstrut}{\hbox{\vrule height1.6ex depth0pt width0pt}}
\newcommand{\key}[1]{\framebox{\@tnstrut\sffamily#1}}
\newcommand{\keycomb}[2]{%
  \ifthenelse{\equal{#2}{}}%
    {\key{#1}}%
    {\key{#1\,\raisebox{.09ex}{\footnotesize+}\,#2}}%
}

\newcommand{\shiftkey}[1][]{\keycomb{Shift}{#1}}
\newcommand{\altkey}[1][]{\keycomb{Alt}{#1}}
\newcommand{\ctrlkey}[1][]{\keycomb{Ctrl}{#1}}
\newcommand{\metakey}[1][]{\keycomb{M-x}{#1}}
\newcommand{\tabkey}{\key{Tab}}
\newcommand{\esckey}{\key{Esc}}
\newcommand{\enterkey}{\key{Enter}}
\newcommand{\deletekey}{\key{Delete}}
\newcommand{\backspacekey}{\key{\raisebox{1.42ex}{}%
         \raisebox{0.2ex}{\ensuremath{\mathbf{\longleftarrow}}}}}

% This is an environment for displaying sections of code, or
% sequences of commands.

\newenvironment{display}%
{\begin{list}{}{\setlength\topsep{0pt}}\item[]}%
{\end{list}}

% Quite often, we want to use verbatim to paste in a lump of code
% or othe data (eg. a makefile). The page is too narrow to do this
% in many cases, so we provide a command to use a smaller font
% for the verbatim environment (and another to change it back).
% (There is probably a better way of doing this)

\newcommand{\smallverb}{%
\renewcommand{\verbatim@font}{\normalfont\ttfamily\scriptsize}}
\newcommand{\normalverb}{%
\renewcommand{\verbatim@font}{\normalfont\ttfamily}}

% There is no bold tt font in the standard CM set. This is a pain
% because bold tt gets generated automatically whenever a filename
% (for example) occurs in a description label, or a section heading.
% One solution is to substitute courier for the tt, but I think
% this looks a bit ugly - the weight and spacing seems to clash with
% the CM (the code to do this is commented out).
% The default substitution is plain tt, but this is not very good -
% you want description labels to stand out, and it looks silly mixed
% with bold roman. So.. this code substitutes bold sf for bold tt.
% It works well in section headings and labels (I think).

\DeclareFontShape{OT1}{cmtt}{bx}{n}
     {
      <-> cmssbx10
      }{}

% This whole lump of stuff reformats the section headings a bit.
% With small pages, you don't want to waste too much vertical space
% for the headings, so this closes up the vertical space used and
% makes subsubsection into a run-in. To make the main sections stand
% out a bit more, it puts the section numbers in boxes.

% Section header

\newcommand{\@sectionFont}{%
    \fontfamily{\sfdefault}\fontseries{\bfdefault}%
    \fontshape{\shapedefault}\large}

% Section header number

\newcommand{\@secNoFont}{%
    \fontfamily{\sfdefault}\fontseries{\bfdefault}%
    \fontshape{\shapedefault}\normalsize}

% Subsection header

\newcommand{\@subSectionFont}{%
    \fontfamily{\sfdefault}\fontseries{\bfdefault}%
    \fontshape{\shapedefault}\normalsize}

% Subsubsection header

\newcommand{\@subSubSectionFont}{%
    \fontfamily{\sfdefault}\fontseries{\bfdefault}%
    \fontshape{\shapedefault}\normalsize}

% Smaller afterskip than default

\renewcommand\section{\@startsection {section}{1}{\z@}%
                                   {-3.5ex \@plus -1ex \@minus -.2ex}%
                                   {1pt}%
                                   {\reset@font\@sectionFont}}

% Smaller afterskip and smaller font

\renewcommand\subsection{\@startsection{subsection}{2}{\z@}%
                                     {-3.25ex\@plus -1ex \@minus -.2ex}%
                                     {1pt}%
                                     {\reset@font\@subSectionFont}}

% Run-in headingsfor subsubsections

\renewcommand\subsubsection[1]{\@subsubsection{#1:}}
\newcommand\@subsubsection{\@startsection{subsubsection}{3}{\z@}%
                                     {-3.25ex\@plus -1ex \@minus -.2ex}%
                                     {-0.5em}%
                                     {\reset@font\@subSubSectionFont}}

\newcommand{\@thepart}{\thepart\hspace{1em}}
\newcommand{\@thesection}{{\@secNoFont\fbox{\thesection}\hspace{1em}}}
\newcommand{\@thesubsection}{\thesubsection\hspace{1em}}
\newcommand{\@thesubsubsection}{\thesubsubsection\hspace{0.5em}}
\newcommand{\@theparagraph}{\theparagraph\hspace{0.5em}}
\newcommand{\@thesubparagraph}{\thesubparagraph\hspace{0.5em}}
\renewcommand{\@seccntformat}[1]{\csname @the#1\endcsname}

% Font for running headers & footers

\newcommand{\@headFont}{%
    \fontfamily{\sfdefault}\fontseries{\seriesdefault}%
    \fontshape{\sldefault}\footnotesize}

\newcommand{\@footFont}{%
    \fontfamily{\sfdefault}\fontseries{\seriesdefault}%
    \fontshape{\sldefault}\footnotesize}

% Set up the default header and footer definitions

\def\ps@headings{\let\@mkboth\markboth
 \def\@oddfoot{\@footFont\ \hfill(\arabic{page})}%
 \def\@oddhead{\vbox{\hrule \@depth0.5pt \vskip-2.5ex%
     \hbox to \textwidth{\@headFont\@date\hfill CS--TN--\@tnnumber}}}%
 \def\@evenfoot{\@footFont(\arabic{page})\hfill}%
 \def\@evenhead{\vbox{\hrule \@depth0.5pt \vskip-2.5ex \hbox to
     \textwidth{\@headFont CS--TN--\@tnnumber\hfill Revision \@revision}}}}
 
\pagestyle{headings}
\thispagestyle{empty}

%%
%% EOF: cstn.cls
%%
