% Style file for producing IMS examination papers - a no year version.
% J.M. Bremner/updated by JRM 12.01.06 and EEB 04.01.07
% This version is to remove the problem that under WinXP and PFE the script running
% in the DOS window does not stop at the version trap but completes with the
% command entry \read-1 to \answer and no proper error message. OK under WinEdt 
%
\usepackage{a4wide,fancyhdr,amsmath}
%
% Some ideas:  use lower-level TeX constructs in place of, for example,
%                \makebox?
%              Replace speclist by sectlist (for, e.g., (a) (i)) and
%                questsectlist (for, e.g., 1. (a) (i))?  (Come to think of
%                it, I can't remember why speclist is necessary: wouldn't
%                "itemize" do?)
%              Abandon dependence on a4wide.
%              Move further towards LaTeX2e.
%
\DeclareOption{graphics}{\def\@graphicx{%
\ifx\pdftexversion\undefined
    \usepackage[dvips]{graphicx}
\else
    \usepackage[pdftex]{graphicx}
\fi}}
\ProcessOptions
\ifx\@graphicx\undefined\relax\else\@graphicx\fi
%
% Check for name conflicts.  Comment out in production version.
% (Some doubly commented out, since defined using \newcommand.)
%
%\newcommand{\alphasections}{}
%\newcommand{\answer}{}
%\newcommand{\@breakstyle}{}
%\newcommand{\nobreaks}{}
%\newcommand{\softbreaks}{}
%\newcommand{\hardbreaks}{}
%\newcommand{\BbbC}{}
%\newcommand{\BbbE}{}
%\newcommand{\BbbR}{}
%\newcommand{\breakpoint}{}
%%\newcommand{\chatty}{}
%%\newcommand{\corner}{}
%\newcommand{\Cov}{}
%\newcommand{\doteqdot}{}
%\newcommand{\dwm}{}
%\newcommand{\E}{}
%\newcommand{\ecirc}{}
%\newcommand{\finalprint}{}
%\newcommand{\hyphen}{}
%%\newcommand{\ignore}{}
%\newcommand{\ldot}{}
%\newcommand{\leftitem}{}
%\newcommand{\maketildedigitspace}{}
%\newcommand{\makehyphenminus}{}
%\newcommand{\makedotpoint}{}
%\newcommand{\marks}{}
%\newcommand{\marktext}{}
%\newcommand{\minus}{}
%\newcommand{\NexT}{}
%\newcommand{\numtable}{}
%\newcommand{\onemark}{}
%\newcommand{\papercode}{}
%\newcommand{\pgmarks}{}
%\newcommand{\phd}{}
%\newcommand{\point}{}
%\newcommand{\printstyle}{}
%\newcommand{\@printstyle}{}
%\newcommand{\@papercode}{}
%\newcommand{\realbar}{}
%%\newcommand{\regarray}{}
%\newcommand{\romansections}{}
%%\newcommand{\slantfrac}{}
%\newcommand{\stddocument}{}
%%\newcommand{\squeezein}{}
%\newcommand{\question}{}
%\newcommand{\tie}{}
%\newcommand{\ugmarks}{}
%\newcommand{\UnDeF}{}
%\newcommand{\V}{}
%\newcommand{\Var}{}
%%\newcommand{\Vec}{}
%\newcommand{\yearlastused}{}
%\newcommand{\zwm}{}
%
% End of name conflict checks
%
% Is this an old style file?
%
%\newcount\yearlastused \yearlastused=2005 \let\NexT\relax
%\ifnum\year>\yearlastused
%  \message{The style file you are using was last used in \number\yearlastused.  Is this OK?}
%  \message{Press RETURN/ENTER to continue, enter X to stop: } % Any character to stop, really
%  \read-1 to \answer
%  \if\answer\par \else \let\NexT\stop \fi
%\fi
%\NexT
%
% Have we changed to LaTeX2e?
%
\if@compatibility
  \message{Can't you use LaTeX 2e?  Support for LaTeX 2.09 may be withdrawn soon.}
\fi
%
% Additional style files and some settings
%
%\input a4wide.sty
%\input fancyhdr.sty
\addtolength{\headheight}{3pt} % Avoid "overfull \vbox" messages from fancyheadings
\parindent 0pt
\parskip 1ex
\renewcommand{\baselinestretch}{1.1}
\raggedbottom
%
\def\papercode #1 {\def\@papercode{#1}}
%
% Print styles:
%
%    0: temporary question codes, no title page or paper code,
%       pagebreaks anywhere
%    1: temporary question codes, no title page or paper code,
%       one question per page
%    2: temporary question codes, title page and paper code,
%       one question per page
%    3: final question numbers, title page and paper code,
%       pagebreaks between questions
%
% \finalprint equivalent to \printstyle 3
%
\newif\iffinal
\newif\iftitle
\def\printstyle#1{\def\@printstyle{#1}}
\def\finalprint{\printstyle 3}
\def\nobreaks{\def\@breakstyle{0}}
\def\softbreaks{\def\@breakstyle{1}}
\def\hardbreaks{\def\@breakstyle{2}}

\let\stddocument\document
\renewcommand{\document}{\stddocument\relax%
 \ifx\@printstyle\UnDeF % Not perfect, but should work!
  \relax
 \else
  \ifcase\@printstyle
   \relax\finalfalse\titlefalse\nobreaks % \relax important here!
  \or
   \finalfalse\titlefalse\hardbreaks
  \or
   \finalfalse\titletrue\hardbreaks
  \or
   \finaltrue\titletrue\softbreaks
  \fi
 \fi
 \iffinal
  \pagestyle{fancyplain}
  \def\headrulewidth{0pt}
  \chead{\fancyplain{}{\thepage}}
  \lhead[\@papercode]{}
  \rhead[]{\@papercode}
  \rfoot[]{\it Turn over}
  \cfoot{}
 \else
  \pagestyle{fancy}
  \def\headrulewidth{0pt}
  \chead{\thepage}
  \newcount\hour \newcount\minute \newcount\yr
  \hour=\time \divide\hour 60
  \minute=\hour \multiply\minute -60 \advance\minute\time\relax
  \yr=\year \advance\yr -2000
  \cfoot{Draft: \number\day/\number\month/\ifnum\yr<10 0\fi\number\yr,
         \number\hour.\ifnum\minute<10 0\fi\number\minute}
 \fi
 \iffinal\thispagestyle{plain}\fi} % End of expanded \document command
\let\stdenddocument\enddocument
\def\enddocument{\rfoot{}\stdenddocument}
%
% "If"s for producing different versions
%
\newif\ifpg
\newif\ifug
\newif\ifma
\newif\ifmsc
%
% Questions introduced by \question
%
\newcounter{question}
\def\thequestion{\arabic{question}}
\def\question #1 {\setcounter{section}{0}\addtocounter{question}{1}%
 \par\makebox[0pt][r]{\iffinal\thequestion\else#1\fi.\hspace{1em}}%
 \ignorespaces}
%
% Sections introduced by \section.  Numbering style controlled by
% \alphasections (standard) or \romansections; the alternate style
% is used for indented lists produced by the enumerate environment.
%
\newif\ifsecta
\def\romansections{\sectafalse}
\def\alphasections{\sectatrue}
\def\thesection{\ifsecta\alph{section}\else\roman{section}\fi}
\def\section{\addtocounter{section}{1}\ifnum\c@section>1\par\fi
             \makebox[2em][l]{(\thesection )}\ignorespaces}
\def\theenumi{\ifsecta\roman{enumi}\else\alph{enumi}\fi}
\def\labelenumi{(\theenumi)}
\def\breakpoint{\ifcase\@breakstyle\relax\or\filbreak\or\newpage\fi}
%
% Marks for question components may be given using the \marks command.
% This is based on the TeXbook, p.106.  It seems to works (goodness
% knows how).
%
% Use \renewcommand{\marktext} as appropriate.
%
% Adding \ugmarks, \pgmarks (April 1999) leads to very finnicky behaviour
% regarding spaces.  Maybe I should move to \def\marks{#1} one of
% these years.
%
\def\marktext{ marks}
\def\marks #1 {\unskip\nobreak\hfil\penalty50
 \hskip2em\hbox{}\nobreak\hfil[\thinspace#1\marktext\thinspace]%
 \parfillskip=0pt\finalhyphendemerits=0\par\parfillskip=0pt plus1fil}
\def\onemark{{\def\marktext{ mark}\marks 1 }}
\def\pgmarks #1 {\ifpg\marks #1 \fi}
\def\ugmarks #1 {\ifug\marks #1 \fi}
%
% Redefine first- and second-level list parameters.  Very ad hoc.
%
\def\@listI{\leftmargin 3.5em
 \labelwidth 3em
 \topsep \z@
 \partopsep \z@
 \parsep \parskip
 \itemsep \z@}
\let\@listi\@listI
\@listi
\def\@listii{\leftmargin 2.5em
 \labelwidth 2em
 \topsep \z@
 \partopsep \z@
 \parsep \parskip
 \itemsep \z@}
%
% Now a special list-type environment to deal with awkward customers.
%
\def\speclist{\list{}{\@listI}}
\let\endspeclist\endlist
%
% Normal usage involves this sort of thing:
%
%\item [(b)\hfill(i)]
%
% For really awkward customers you start off a question with a
% speclist item like this:
%
%\item [{\makebox[0em][r]{\iffinal \thequestion \else TS4\fi.%
%\hspace{1em}}(a)\hfill(i)}]
%
% Now a \leftitem definition for people who want some wording against
% the left margin in the middle of a list.  Note that the "label" is
% in fact part of the item text.
%
\def\leftitem[#1]{\item[]\makebox[0pt][r]{\makebox[\leftmargin][l]{#1}}%
\ignorespaces}
%
% Another list-type environment (IPlist) which mimics the form of lists
% produced by the troff (ms) .IP macro
%
\newlength{\IPindent}
\def\IPlabel#1{#1\hfil}% \hfil to avoid "underfull hbox" messages, and
%                        to allow some fancy alignment tricks
\newenvironment{IPlist}[1]%
{\settowidth{\IPindent}{#1}
\begin{list}{}
{\labelwidth\IPindent \leftmargin\IPindent
\labelsep0pt \let\makelabel\IPlabel}}%
{\end{list}}
%
% Now some stuff for numerical tables, to turn
%
%      tildes into digit-width spaces;
%      hyphens into minus signs (treated as digit-width for alignment
%        purposes);
%      dots into decimal points.
%
% Very much a groping-in-the-dark first attempt.  In particular, I've no
% idea why "." and "-" have to made active while the definitions are made
% (but it didn't work until I did this!).  There's room, I imagine, for
% some improvement in efficiency, and for introducing symbols to allow
% _real_ dots and hyphens.
%
% The commands have to come before the \begin{tabular}, and should be
% restricted in scope to the immediate vicinity of the table (so that
% things return to normal afterwards); usually the table will be enclosed
% in a \begin{center}, \end{center} pair, which will do the trick.
%
\def\maketildedigitspace{\newdimen\digitwidth
  \setbox0=\hbox{\rm0}
  \digitwidth=\wd0
  \def~{\kern\digitwidth}}
%
% That was based on an example in the TeXbook, p.241; this gave me the
% idea for the others.
%
\catcode`-=\active
\def\makehyphenminus{\catcode`-=\active
  \def-{\dwm}}
\catcode`-=12 % 12 == "other"
%
\catcode`.=\active
\def\makedotpoint{\catcode`.=\active \def.{$\cdot$}}
\catcode`.=12 % 12 == "other"
%
% And, if you want the lot:
%
\def\numtable{\maketildedigitspace\makehyphenminus\makedotpoint}
%
% Here's a \squeezein definition to insert an extra row of zero
% effective height into a table.  It seems to work for "standard" cases,
% but odd vertical spacing will confuse it, I'm sure.  It knows about
% \arraystretch, however.
%
% Here's an example of how you use it:
%
%    & 1 & 2 & 3 \\
% \squeezein{Block I &&&} % The "&"s can be omitted if there are no vertical rules
%    & 4 & 5 & 6 \\
%
\newcommand{\squeezein}[1]{
  \newdimen\halfspace\newdimen\spaceandahalf
  \halfspace=\normalbaselineskip % \baselineskip seems to be set to zero in tables
%\global\advance\halfspace by \ht\strutbox  % Some old stuff.  No longer needed, 
%\global\advance\halfspace by \dp\strutbox  % but keep just in case.
  \global\divide\halfspace by 2
  \spaceandahalf=\normalbaselineskip
  \global\advance\spaceandahalf by \halfspace
  \\[-\arraystretch\spaceandahalf]
  #1
  \\[-\arraystretch\halfspace]}
%
% Now a little array for the things that econometricians and their
% friends are so keen on when presenting fitted regression equations:
% two numbers one above the other, the lower one in brackets
% (typically an estimated coefficient and its standard error, or
% t-value).  To reduce the need for manual adjustment to the
% horizontal spacing around the array, its "width" is the width of
% the upper number.
%
\newcommand{\regarray}[2]{\begin{array}[t]{@{}c@{}}#1\\[-0.25ex]
\makebox[0em][c]{($#2$)}\end{array}}
%
% And now a nice little definition for a slanted in-line fraction.
% From the TeXbook, Ex. 11.6.
%
\newcommand{\slantfrac}[2]{\leavevmode\kern.1em\raise.5ex
  \hbox{\the\scriptfont0 #1}\kern-.1em/\kern-.15em\lower.25ex
  \hbox{\the\scriptfont0 #2}}
%
% Now an \ignore command, useful for temporarily deleting bits
%
\newcommand{\ignore}[1]{\typeout{Material ignored}}
%
% And a \chatty command, useful for such things as \chatty\newpage,
% \chatty{\input specdefs}
%
\newcommand{\chatty}[1]{#1\typeout{\protect #1}}
%
% Some other useful definitions
%
% Some should be converted to "proper" LaTeX2e eventually
%
\if@compatibility\def\point{\mbox{$\cdot$}}
\else\def\point{\ensuremath{\mathord\cdot}}\fi
\def\E{{\rm E}}
\def\V{{\rm V}}
\def\Var{{\rm Var}}
\def\Cov{{\rm Cov}}
\newcommand{\IMSVec}[1]{\stackrel{\rightarrow}{\it#1}} % Italic, not math italic!
\def\ecirc{\mathaccent23e}
\newcommand{\corner}[1]
  {\hbox{\vbox{\hrule\kern.1ex%
  \hbox{\kern.01em$\scriptstyle#1$\kern.02em}}\vrule depth.1ex}}
\def\BbbC
  {\mbox{\rlap{\kern.3em\vrule width .01em height1.5ex depth-.06ex}{\rm C}}}
\def\BbbR
  {\mbox{\rlap{\kern.3em\vrule width .01em height1.55ex}{\rm R}}}
\def\BbbE
  {\mbox{\rlap{\kern.3em\vrule width .01em height1.55ex}{\rm E}}}
% \doteqdot: a bodge; works only for 11pt.
\def\doteqdot{\mathrel{\rlap{\raise0.62ex\hbox{$\mkern4.5mu\cdot$}}
                      {\rlap{\lower0.70ex\hbox{$\mkern4.5mu\cdot$}}{=}}}}
%
\def\phd{\phantom{0}}% Phantom digit; \maketildedigitspace probably makes it redundant
\def\dwm{\phantom{0}\llap{$-$}}% Digit-width minus; used in \makehyphenminus
\def\zwm{\makebox[0pt][r]{$-$}}% Zero-width minus
\def\ldot{.}% Handy with \numtable, \makedotpoint
\def\hyphen{-}% Handy with \numtable, \makehyphenminus
\def\minus{-}% Handy with \numtable, \makehyphenminus
\let\tie=~ % Handy with \numtable, \maketildedigitspace
% "\bar"s aren't very visible, so use \overline instead; provide \realbar
% in case real "\bar"s are required
\let\realbar=\bar \def\bar{\overline}
% For clarity, it's best to use \displaystyle for in-line maths.  Let's
% automate this.  It can be turned off with \textstyle.
\everymath{\displaystyle}
% Julie's definitions for various papers
\newcommand{\blvec}[1]
{\mathop{#1}\limits^{\mbox{\normalsize$\leftarrow$}}}
\newcommand{\brvec}[1]
{\mathop{#1}\limits^{\mbox{\normalsize$\rightarrow$}}}
\newcommand{\IMSdddot}[1]{{\stackrel{\textstyle{.{\kern-.0884em}.{\kern-.0884em}.}}{#1}}}

