% THIS FILE IS AUTOMATICALLY INPUT INTO GLASGOW LITERATE DOCUMENTS
%
% support for "literate programming" with Haskell (and other things)
%  contact: Will Partain (partain@dcs.glasgow.ac.uk)
%
% most of it is copies of semi-std .sty files;
% done this way so we don't have to rely on others having them

\newcommand{\ToDo}[1]{$\spadesuit$~{\bf ToDo:} {\em #1} $\spadesuit$}
\newcommand{\srcloc}[1]{\marginpar{\footnotesize\tt #1}}
\newcommand{\smiley}{%
\hbox{$\bigcirc\mskip-13.3mu{}^{..}
\mskip-11mu\scriptscriptstyle\smile\ $}}

\makeatletter

%% basic format, for better or worse, is "Simon's format"
%% intended for 11pt work
%%
%===================================================================
%\input{a4wide.sty}
%NAME: a4wide.sty
% "moretext" document style option.
% Jean-Francois Lamy, July 86
%
% Redefines the margins so that they are more in line with 
% what we are used to see.
%

%- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
%\input a4.sty
%%
%% This file was generated with `docstrip.tex' version v1.0b <89/11/05>
%%
%% The original source file was `a4.doc'.
%%
%% IMPORTANT NOTICE:
%% You are not allowed to distribute this file.
%% For distribution of the original source see
%% the copyright notice in the file `a4.doc'.
%%
\def\fileversion{1.2}
\def\filedate{26 Feb 90}
\def\docdate {26 Feb 90}
%% \CheckSum{134}
%% \CharacterTable
%%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%%   Digits        \0\1\2\3\4\5\6\7\8\9
%%   Exclamation   \!     Double quote  \"     Hash (number) \#
%%   Dollar        \$     Percent       \%     Ampersand     \&
%%   Acute accent  \'     Left paren    \(     Right paren   \)
%%   Asterisk      \*     Plus          \+     Comma         \,
%%   Minus         \-     Point         \.     Solidus       \/
%%   Colon         \:     Semicolon     \;     Less than     \<
%%   Equals        \=     Greater than  \>     Question mark \?
%%   Commercial at \@     Left bracket  \[     Backslash     \\
%%   Right bracket \]     Circumflex    \^     Underscore    \_
%%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%%   Right brace   \}     Tilde         \~}
%%
%%\typeout{Style option `A4' \fileversion\space<\filedate> (NP and JLB)}
%%\typeout{English documentation\space\space\space<\docdate> (JLB)}
\topmargin 0pt
\ifcase \@ptsize
    \textheight 53\baselineskip
\or
    \textheight 46\baselineskip
\or
    \textheight 42\baselineskip
\fi
\advance\textheight by \topskip
\ifcase \@ptsize
    \textwidth      5.00in
    \marginparwidth 1.00in
  \if@twoside
    \oddsidemargin  0.55in
    \evensidemargin 0.75in
  \else
    \oddsidemargin  0.55in
    \evensidemargin 0.55in
  \fi
\or
    \textwidth      5.20in
    \marginparwidth 1.00in
  \if@twoside
    \oddsidemargin  0.45in
    \evensidemargin 0.65in
  \else
    \oddsidemargin  0.45in
    \evensidemargin 0.45in
  \fi
\or
    \textwidth      5.70in
    \marginparwidth 0.80in
  \if@twoside
    \oddsidemargin  0.20in
    \evensidemargin 0.40in
  \else
    \oddsidemargin  0.20in
    \evensidemargin 0.20in
  \fi
\fi
\def\WideMargins{%
  \newdimen\ExtraWidth
  \ifcase \@ptsize
    \ExtraWidth = 0.5in
    \@widemargins
  \or
    \ExtraWidth = 0.5in
    \@widemargins
  \or
    \ExtraWidth = 0.7in
    \@widemargins
  \fi\let\WideMargins\relax\let\@widemargins\relax}
{\def\do{\noexpand\do\noexpand}
 \xdef\@preamblecmds{\@preamblecmds \do\WideMargins}
}
\def\@widemargins{%
    \global\advance\textwidth by -\ExtraWidth
    \global\advance\marginparwidth by \ExtraWidth
    \if@twoside
      \tw@sidedwidemargins
    \else
      \@nesidedwidemargins
    \fi}
\def\tw@sidedwidemargins{%
    \if@reversemargin
      \@tempdima=\evensidemargin
      \advance\@tempdima by -\oddsidemargin
      \advance\oddsidemargin by \ExtraWidth
      \advance\oddsidemargin by \@tempdima
      \advance\evensidemargin by -\@tempdima
    \else
      \advance\evensidemargin by \ExtraWidth
    \fi}
\def\@nesidedwidemargins{%
    \if@reversemargin
      \advance\oddsidemargin by \ExtraWidth
      \advance\evensidemargin by \ExtraWidth
    \fi}
%\endinput
% end of a4.sty
%- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

\ifcase \@ptsize
    % mods for 10 pt
    \oddsidemargin  0.15 in     %   Left margin on odd-numbered pages.
    \evensidemargin 0.35 in     %   Left margin on even-numbered pages.
    \marginparwidth 1 in        %   Width of marginal notes.
    \oddsidemargin 0.25 in      %   Note that \oddsidemargin = \evensidemargin
    \evensidemargin 0.25 in
    \marginparwidth 0.75 in
    \textwidth 5.875 in % Width of text line.
\or % mods for 11 pt
    \oddsidemargin 0.1 in      %   Left margin on odd-numbered pages.
    \evensidemargin 0.15 in    %   Left margin on even-numbered pages.
    \marginparwidth 1 in       %   Width of marginal notes.
    \oddsidemargin 0.125 in    %   Note that \oddsidemargin = \evensidemargin
    \evensidemargin 0.125 in
    \marginparwidth 0.75 in
    \textwidth 6.125 in % Width of text line.
\or % mods for 12 pt
    \oddsidemargin -10 pt      %   Left margin on odd-numbered pages.
    \evensidemargin 10 pt      %   Left margin on even-numbered pages.
    \marginparwidth 1 in       %   Width of marginal notes.
    \oddsidemargin 0 in      %   Note that \oddsidemargin = \evensidemargin
    \evensidemargin 0 in
    \marginparwidth 0.75 in
    \textwidth 6.375 true in % Width of text line.
\fi
% end of a4wide.sty
%===================================================================

% Block paragraphs
% NOTE: comment out these four lines if you want more
% standard LaTeX-looking paragraphs.
\setlength{\parskip}{0.25cm}
% partain: save the parindent value, for indenting code
\newlength{\litcodeindent}
\setlength{\litcodeindent}{\z@}
%\setlength{\litcodeindent}{\parindent}
% comment out this one line if you want std para indentation:
\setlength{\parindent}{0cm}
%\renewcommand{\textfraction}{0.2}
%\renewcommand{\floatpagefraction}{0.7}

% display environment: same as "quotation"
\def\display{\list{}{\listparindent \z@
    \itemindent\listparindent
    \rightmargin\leftmargin \parsep 0pt plus 1pt}\item[]}
\let\enddisplay=\endlist

% flushdisplay environment: same as "display" but without indent
\def\flushdisplay{\list{}{\listparindent \z@
    \itemindent\listparindent
    \leftmargin\z@ \rightmargin\leftmargin \parsep 0pt plus 1pt}\item[]}
\let\endflushdisplay=\endlist

% unflushverbatim environment: "verbatim" is naturally "flush"
% so this simply arranges "unflushness".  It presumes things are written as...
% \begin{unflushverbatim}
% \begin{verbatim}
% <stuff>
% \end{verbatim}
% \end{unflushverbatim}
%
\def\unflushverbatim{\list{}{\listparindent \z@
    \itemindent\listparindent
    \rightmargin\leftmargin \parsep 0pt plus 1pt}\item[]}
\let\endunflushverbatim=\endlist

%\newcommand{\BeginLitCode}{\par\noindent\begin{tabular}{@{\hspace*{1.2em}}l@{}}}
%\newcommand{\BeginLitCodeNoIndent}{\par\noindent\begin{tabular}{@{}l@{}}}
%\newcommand{\EndLitCode}{\end{tabular}}

% same, for now
%\newcommand{\BeginLitVerb}{\par\noindent\begin{tabular}{@{\hspace*{1.2em}}l@{}}}
%\newcommand{\BeginLitVerbNoIndent}{\par\noindent\begin{tabular}{@{}l@{}}}
%\newcommand{\EndLitVerb}{\end{tabular}}

% and some internal variants that set the page numbers differently
\newcommand{\indexttit}[1]{\index{#1@{\tt #1}|itindexpage}}
\newcommand{\itindexpage}[1]{{\it #1}}
%\newcommand{\indexPageUL}[1]{\index{#1|underline}}
\newcommand{\ttize}[1]{{\tt #1}}
\newcommand{\ttunderline}[1]{\underline{\tt #1}}

\newcommand{\heading}[1]{\par\vspace{2\baselineskip}\noindent #1\par}

\newcommand{\Haskell}{Haskell}

% slightly hacked...
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% File "comment.sty" (by Tom Hofmann, E-mail: wtho@cgch.UUCP)
% 1989-10-30
% 
% This File contains the definition of a LaTeX environment "comment"
% which allows to alternatively print or suppress parts of the document.
%
%
% Usage:
%
%    - Declare "comment" as documentstyle option or include this file
%      by "\input{comment.sty}"
%    - Embed comments in "\begin{comment}" and "\end{comment}"
%    - To print the document including the comments write "\printcomments"
%      before the first comment. Alternatively, write "\suppresscomments"
%      to print without comments.
%    - The default setting is "\printcomments".
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


% (1) Definition of the environment "comment" when notes are
%     to be printed.

% hack here
% orig: \def\printcomments{\def\comment{}}	% "\endcomment" can be missing

\def\printcomments{\def\comment{\par \small {\em Comment:}}}	% "\endcomment" can be missing

% (2) Definition of the environment "comment" when notes are not
%     to be printed.

%     Make '{' and '}' "other characters" and make '(' and ')'
%     "begingroup" and "endgroup" resp.  Thus make it possible
%     to have "\end{comment}" as part of a macro definition.

\begingroup\makeatletter		% since the catcodes of '{' and '}'
\catcode`{=12\relax\catcode`}=12\relax	% will change, use \begingroup and
\catcode`(=1\relax \catcode`)=2\relax	% \endgroup instead.

\gdef\suppresscomments(%

%     Make '{' and '}' searchable when expanding the macro by giving them
%     the same catcode in the subsequent text as in the macro definition.

	  \gdef\comment(\catcode`{=12\relax\catcode`}=12\relax\@NOTE)

%     Skip text between "\begin{comment}" and "\end{comment}"
%     (inclusive), but return an "\end{comment}" command to LaTeX for
%     the correct environment handling (see below).

	  \long\gdef\@NOTE##1\end{comment}(\@ENDNOTE))


\endgroup				% End of the enchantment.

%     Generate an environment-end command conformable to LaTeX.

{\makeatletter\gdef\@ENDNOTE{\end{comment}}}

\printcomments				% This is the default setting.

%========================================================================
% saves having to put this in all the time
%\input{makeidx.sty}
% makeidx.sty 20-Jan-87

\def\see#1#2{{\em see\/} #1}
\def\printindex{\@input{\jobname.ind}}
% end of makeidx.sty
\makeatother
%========================================================================

%========================================================================
\makeatletter
% file tgrind.sty
% NB: nuke line numbering
%%%%%%%%%%%
%NAME: tgrind.sty
% LaTeX tgrind environment

% Based on Van Jacobson's ``tgrindmac'', a macro package for TeX grinding
% Our job here is to simplify it quite a bit and make it conform to LaTeX

\newif\ifcomment\newif\ifstring
\newcount\linecount\newcount\linenext
\newbox\linesofar
\newdimen\TBwid
\newdimen\ts
\newbox\tbox

\def\tgrind{%
% Stuff we ignore for right now.
\let\Head=\@gobble
\def\File##1,##2,##3{}
\let\Proc=\@gobble
\let\ProcCont=\@gobble
%
% Each formfeed in the input is replaced by a "\NewPage" macro.  If
% you really want a page break here, define this as "\vfill\eject".
\def\NewPage{\filbreak\bigskip}
%
% Each line of the program text is enclosed by a "\L{...}".  We turn
% each line into an hbox of size hsize.  If we saw a procedure name somewhere
% in the line (i.e., "procbox" is not null), we right justify "procbox"
% on the line.  Every 10 lines we output a small, right justified line number.
\def\L##1{\par\hbox to\hsize{\CF\strut\global\advance\linecount by1
##1\hss\linebox}}
%
\linecount=0
\linenext=9
\def\linebox{\ifnum\linecount>\linenext\global\advance\linenext by10
% partain: \hbox{\sevrm\the\linecount}\fi}
% partain2: \hbox{\rm\tiny\the\linecount}\fi}
\hbox{}\fi}
%
% The following weirdness is to deal with tabs.  "Pieces" of a line
% between tabs are output as "\LB{...}".  E.g., a line with a tab at
% column 16 would be output as "\LB{xxx}\Tab{16}\LB{yyy}".  (Actually, to
% reduce the number of characters in the .tex file the \Tab macro
% supplies the 2nd & subsequent \LB's.) We accumulate the LB stuff in an
% hbox.  When we see a Tab, we grab this hbox (using "\lastbox") and turn
% it into a box that extends to the tab position.  We stash this box in
% "\linesofar" & use "\everyhbox" to get \linesofar concatenated onto the
% front of the next piece of the line.  (There must be a better way of
% doing tabs [cf., the Plain.tex tab macros] but I'm not not enough of a
% TeX wizard to come up with it.  Suggestions would be appreciated.)
\def\LB{\CF\hbox}
\setbox\linesofar=\null
\everyhbox={\box\linesofar}
\def\Tab##1{\setbox\tbox=\lastbox\TBwid=1\wd\tbox\advance\TBwid by 1\ts
\ifdim\TBwid>##1\ts
\setbox\linesofar=\hbox{\box\tbox\space}\else
\setbox\linesofar=\hbox to ##1\ts{\box\tbox\hfil}\fi\LB}
%
% A normal space is too thin for code listings.  We make spaces & tabs
% be in "\ts" units (which are the width of a "0" in the current font).
\setbox\tbox=\hbox{0} \ts=1\wd\tbox \setbox\tbox=\hbox{\hskip 1\ts}
\def\space{\hskip 1\ts\relax}
%
% Font changing stuff for keywords, comments & strings.  We put keywords
% in boldface, comments in text-italic & strings in typewriter.  Since
% we're usually changing the font inside of a \LB macro, we remember the
% current font in \CF & stick a \CF at the start of each new box.
% Also, the characters " and ' behave differently in comments than in
% code, and others behave differently in strings than in code.
\let\CF=\rm
\def\K##1{{\bf ##1}}	% Keyword
\def\C{\it\global\let\CF=\it\global\commenttrue\relax}	% Comment Start
\def\CE{\rm\global\let\CF=\rm\global\commentfalse\relax}% Comment End
\def\S{\tt\global\let\CF=\tt\global\stringtrue\relax}	% String Start
\def\SE{\rm\global\let\CF=\rm\global\stringfalse\relax}	% String End
%
% Special characters.
\def\{{\ifmmode\lbrace\else\ifstring{\char'173}\else$\lbrace$\fi\fi}
\def\}{\ifmmode\rbrace\else\ifstring{\char'175}\else$\rbrace$\fi\fi}
\def\!{\ifmmode\backslash\else\ifstring{\char'134}\else$\backslash$\fi\fi}
\def\|{\ifmmode|\else\ifstring{\char'174}\else$|$\fi\fi}
\def\<{\ifmmode<\else\ifstring<\else$<$\fi\fi}
\def\>{\ifmmode>\else\ifstring>\else$>$\fi\fi}
\def\/{\ifmmode/\else\ifstring/\else$/$\fi\fi}
\def\-{\ifmmode-\else\ifstring-\else$-$\fi\fi}
\def\_{\ifstring{\char'137}\else\underbar{\ }\fi}
\def\&{{\char'046}}
\def\#{{\char'043}}
\def\%{{\char'045}}
\def\~{{\char'176}}
\def\"{\ifcomment''\else{\tt\char'042}\fi}
\def\'{\ifcomment'\else{\tt\char'047}\fi}
\def\^{{\char'136}}
\def\${{\rm\char'044}}
%
\raggedright\obeyspaces%\let =\space%
}

% \tagrind*[FLOAT]{FILE}{CAPTION}{LABEL}
%    *		optional
%    FLOAT	float options
%    FILE	reads LaTeXgrind input in file FILE
%    CAPTION	for list of figures
%    LABEL	for \ref and \pageref
\def\tagrind{\@ifstar{\@stagrind}{\@tagrind}}

\def\@tagrind{\@ifnextchar[{\@@tagrind}{\@@tagrind[t]}}
\def\@stagrind{\@ifnextchar[{\@@stagrind}{\@@stagrind[t]}}

\def\@@tagrind[#1]#2#3#4{%
    \begin{figure}[#1]
	\hrule
	\vskip .5\baselineskip
	\begin{minipage}\columnwidth\small
	    \begin{tgrind}
		\input #2\relax
	    \end{tgrind}
	\end{minipage}
	\vskip .5\baselineskip plus .5\baselineskip
	\begingroup
	    \setbox\z@=\hbox{#4}%
	    \ifdim\wd\z@>\z@
		\caption{#3}%
		\label{#4}%
	    \else
		\captcont{#3}%
	    \fi
	\endgroup
	\vskip 2pt
	\hrule
    \end{figure}
}

\def\@@stagrind[#1]#2#3#4{%
    \begin{figure*}[#1]
	\hrule
	\vskip .5\baselineskip
	\begin{minipage}\textwidth\small
	    \begin{tgrind}
		\input #2\relax
	    \end{tgrind}
	\end{minipage}
	\vskip .5\baselineskip plus .5\baselineskip
	\begingroup
	    \setbox\z@=\hbox{#4}%
	    \ifdim\wd\z@>\z@
		\caption{#3}%
		\label{#4}%
	    \else
		\captcont{#3}%
	    \fi
	\endgroup
	\vskip 2pt
	\hrule
    \end{figure*}
}


\def\tgrindfile#1{%
    \par\addvspace{0.1in}
    \hrule
    \vskip .5\baselineskip
    \begin{footnotesize}
	\begin{tgrind}
	    \input #1\relax
	\end{tgrind}
    \end{footnotesize}
    \vskip .5\baselineskip
    \hrule
    \addvspace{0.1in}
}
% end of tgrind.sty
\makeatother
%========================================================================

%========================================================================
% changebar.sty
\makeatletter

%% This is file `changebar.sty' generated
%% on <1992/1/6> with the docstrip utility (v1.1k). 
%% 
%% The original source file was `changebar.doc'.
%% Included modules: `changebar'.
%% 
%% IMPORTANT NOTICE:
%% You are not allowed to distribute this file.
%% For distribution of the original source see 
%% the copyright notice in the file `changebar.doc'. 
%% 
\def\fileversion{v3.0-test}
\def\filedate{6 Nov 91}
\def\docdate{6 Nov 91}
%% \CheckSum{798}
%% \CharacterTable
%%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%%   Digits        \0\1\2\3\4\5\6\7\8\9
%%   Exclamation   \!     Double quote  \"     Hash (number) \#
%%   Dollar        \$     Percent       \%     Ampersand     \&
%%   Acute accent  \'     Left paren    \(     Right paren   \)
%%   Asterisk      \*     Plus          \+     Comma         \,
%%   Minus         \-     Point         \.     Solidus       \/
%%   Colon         \:     Semicolon     \;     Less than     \<
%%   Equals        \=     Greater than  \>     Question mark \?
%%   Commercial at \@     Left bracket  \[     Backslash     \\
%%   Right bracket \]     Circumflex    \^     Underscore    \_
%%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%%   Right brace   \}     Tilde         \~}
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\wlog{Document style option `changebar', \fileversion\space<\filedate>}
\chardef\atcatcode=\catcode`\@
\catcode`\@=11\relax
\def\cb@maxpoint{80}
\def\cb@minpoint{1}
\def\cb@nil{0}
\newcount\cb@nextpoint
\cb@nextpoint=\cb@minpoint
\newcount\cb@currentpoint
\newcount\cb@page
\newcount\cb@pagecount
\cb@pagecount=0
\newif\ifouterbars \outerbarsfalse
\newdimen\cb@odd
\newdimen\cb@even
\def\cb@positions{%
  \global\cb@odd =\hoffset
  \global\advance\cb@odd by \oddsidemargin
  \ifouterbars
    \global\advance\cb@odd by \textwidth
    \global\advance\cb@odd by \changebarsep
  \else
    \global\advance\cb@odd by -\changebarsep
  \fi
  \global\cb@even =\hoffset
  \global\advance\cb@even by \evensidemargin
  \if@twoside
    \ifouterbars
      \global\advance\cb@even by -\changebarsep
    \else
      \global\advance\cb@even by \textwidth
      \global\advance\cb@even by \changebarsep
    \fi
  \else
    \ifouterbars
      \global\advance\cb@even by \textwidth
      \global\advance\cb@even by \changebarsep
    \else
    \fi
      \global\advance\cb@even by -\changebarsep
  \fi}
{\catcode`\p=12\catcode`\t=12 \gdef\cb@removedim#1pt{#1}}
\def\driver#1{%
  \bgroup\edef\next{\def\noexpand\tempa{#1}}%
    \uppercase\expandafter{\next}%
    \def\LN{DVITOLN03}%
    \def\DVItoPS{DVITOPS}%
    \def\DVIPS{DVIPS}%
    \def\emTeX{EMTEX}%
    \global\chardef\cb@driver@setup=0
    \ifx\tempa\LN      \global\chardef\cb@driver@setup=0\fi
    \ifx\tempa\DVItoPS \global\chardef\cb@driver@setup=1\fi
    \ifx\tempa\DVIPS   \global\chardef\cb@driver@setup=2\fi
    \ifx\tempa\emTeX   \global\chardef\cb@driver@setup=3\fi
  \egroup}
{\def\do{\noexpand\do\noexpand}
 \xdef\@preamblecmds{\@preamblecmds \do\driver}
}
\def\cb@setup@specials{%
\ifcase\cb@driver@setup
  \def\cb@defpoint##1##2{\special{ln03:defpoint \the##1(\the##2,)}}
  \def\cb@connect##1##2##3{%
    \special{ln03:connect \the##1\space\space \the##2\space \the##3}}
  \def\cb@resetpoints{%
    \special{ln03:resetpoints \cb@minpoint \space\cb@maxpoint}}
\or
  \def\cb@defpoint##1##2{%
    \special{dvitops: inline
                \expandafter\cb@removedim\the##2\space 6.5536 mul\space
                /CBarX\the##1\space exch def currentpoint exch pop
                /CBarY\the##1\space exch def}}
  \def\cb@connect##1##2##3{%
    \special{dvitops: inline
                gsave \thechangebargrey\space 100 div setgray
                \expandafter\cb@removedim\the##3\space 6.5536 mul\space
                CBarX\the##1\space\space CBarY\the##1\space\space moveto
                CBarX\the##2\space\space CBarY\the##2\space\space lineto
                stroke grestore}}
  \let\cb@resetpoints\relax
\or
  \def\cb@defpoint##1##2{%
     \special{ps:
                \expandafter\cb@removedim\the##2\space 4.096 mul\space
                Resolution\space mul\space 300\space div\space
                /CBarX\the##1\space exch def currentpoint exch pop
                /CBarY\the##1\space exch def}}
    \def\cb@connect##1##2##3{%
      \special{ps:
                gsave \thechangebargrey\space 100 div setgray
                \expandafter\cb@removedim\the##3\space 4.096 mul\space
                Resolution\space mul\space 300\space div\space
                setlinewidth
                CBarX\the##1\space\space CBarY\the##1\space\space moveto
                CBarX\the##2\space\space CBarY\the##2\space\space lineto
                stroke grestore}}
    \let\cb@resetpoints\relax
\or
  \typeout{Changebar Warning: changebars only supported for v1.5+ of dvidrv}%
  \def\cb@defpoint##1##2{\special{em:point \the##1,\the##2}}
  \def\cb@connect##1##2##3{\special{em:line \the##1,\the##2,\the##3}}
  \let\cb@resetpoints\relax
\else
  \typeout{Changebar Warning: changebars not supported in unknown setup}
  \def\cb@defpoint##1##2{}
  \def\cb@connect##1##2##3{}
  \let\cb@resetpoints\relax
\fi
\global\let\cb@setup@specials\relax}
\def\cbstart{\@ifnextchar [{\cb@start}{\cb@start[\changebarwidth]}}
\def\cbend{\cb@end}
\def\cbdelete{\@ifnextchar [{\cb@delete}{\cb@delete[\deletebarwidth]}}
\def\cb@delete[#1]{\vbox to 0pt{\vss\cb@start[#1]\vskip #1\cb@end}}
\def\changebar{\@ifnextchar [{\cb@start}{\cb@start[\changebarwidth]}}%
\def\endchangebar{\cb@end}
\def\nochangebars{\def\cb@start[##1]{}%
                  \def\cb@delete[##1]{}%
                  \let\cb@end\relax}
\newlength{\changebarwidth}
\setlength{\changebarwidth}{2pt}
\newlength{\deletebarwidth}
\setlength{\deletebarwidth}{4pt}
\newlength{\changebarsep}
\setlength{\changebarsep}{30pt}
\newcounter{changebargrey}
\setcounter{changebargrey}{65}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\cb@start[#1]{\cb@currentpoint=\cb@nextpoint
        \@tempdima=#1\relax                             % for \cb@push
        \cb@push\cb@currentlist
        \ifvmode \cb@setBeginPoint\cb@currentpoint
        \else \vbox to 0pt{\vskip -\ht\strutbox         %jump up a line to
        \cb@setBeginPoint\cb@currentpoint               %set point
        \vskip \ht\strutbox}\fi
        \cb@writeAux\cb@advancePoint}
\def\cb@advancePoint{%
  \global\advance\cb@nextpoint by 2\relax
  \ifnum\cb@nextpoint>\cb@maxpoint
    \global\cb@nextpoint=\cb@minpoint\relax
  \fi}
\def\cb@end{%
  \cb@pop\cb@currentlist
  \ifnum\cb@currentpoint=\cb@nil
    \typeout{Changebar Warning: Badly nested changebars;
                                Expect erroneous results}%
  \else
    \cb@setEndPoint\cb@currentpoint
    \advance\cb@currentpoint by1\cb@writeAux
  \fi}
\def\cb@setBeginPoint#1{%
  \ifodd\cb@pagecount
    \cb@defpoint{#1}{\cb@even}%
  \else
    \cb@defpoint{#1}{\cb@odd}%
  \fi}
\def\cb@setEndPoint#1{%
  \@tempcnta=#1\advance\@tempcnta by1\relax
  \ifodd\cb@pagecount
    \cb@defpoint{\@tempcnta}{\cb@even}%
  \else
    \cb@defpoint{\@tempcnta}{\cb@odd}%
  \fi
  \cb@connect{#1}{\@tempcnta}{\@tempdima}}%
\def\cb@writeAux{%
  \if@filesw
    \begingroup
      \edef\point{\the\cb@currentpoint}%
      \edef\level{\the\@tempdima}%
      \let\the=0%
      \edef\cb@temp{\write\@auxout
          {\string\cb@barpoint{\point}{\the\cb@pagecount}{\level}}}%
      \cb@temp
    \endgroup
  \fi}
\let\cb@makecol=\@makecol
\def\@makecol{%
  \setbox\@cclv=\vbox{\cb@resetpoints\cb@beginSaves\unvbox\@cclv}%
  \gdef\cb@beginSaves{}
  \global\advance\cb@pagecount by 1%
  \cb@buildActive\cb@processActive
  \cb@makecol}
\def\cb@processActive{%
  \cb@pop\cb@spanlist
  \ifnum\cb@currentpoint=\cb@nil
  \else
    \setbox\@cclv=\vbox{\unvbox\@cclv\advance\cb@pagecount by -1%
                        \cb@setEndPoint\cb@currentpoint}%
    \cb@saveBeginPoint\cb@currentpoint
    \cb@push\cb@history
    \cb@processActive
  \fi}
\def\cb@saveBeginPoint#1{%
  \ifodd\cb@pagecount
    \xdef\cb@beginSaves{\cb@defpoint{#1}{\cb@even}\cb@beginSaves}%
  \else
    \xdef\cb@beginSaves{\cb@defpoint{#1}{\cb@odd}\cb@beginSaves}%
  \fi}
\def\cb@beginSaves{}                % initially empty
\def\cb@buildActive{\cb@initlist\cb@spanlist\cb@pushNextActive}
\def\cb@pushNextActive{%
  \cb@pop\cb@history
  \ifnum\cb@currentpoint=\cb@nil
  \else
    \ifnum\cb@page>\cb@pagecount
      \cb@push\cb@history
    \else
      \ifodd\cb@currentpoint
        \cb@push\cb@spanlist
      \else
        \cb@pop\cb@spanlist
      \fi
      \cb@pushNextActive
    \fi
  \fi}
\def\cb@initlist#1{\xdef#1{}}
\cb@initlist\cb@history % the history list; initially empty
\cb@initlist\cb@spanlist % list of bars spanning current page
\cb@initlist\cb@currentlist % used to implement nesting without using

\newwrite\cb@write % file for history list
\newread\cb@read
\immediate\openout\cb@write=\jobname.cb % open for building of history list
\def\cb@pop#1{%
  \ifx #1\cb@history
    \ifeof\cb@read
    \else
      {\endlinechar=-1\read\cb@read to\@temp
       \xdef\cb@history{\cb@history\@temp}%
      }%
    \fi
  \fi
  \ifx#1\@empty
    \cb@currentpoint=\cb@nil\cb@page=0%
  \else
    \expandafter\cb@carcdr#1e#1%
  \fi}
\def\cb@carcdr#1n#2p#3l#4e#5{%
  \cb@currentpoint=#1\cb@page=#2\@tempdima=#3\xdef#5{#4}}
\def\cb@push#1{%
  \xdef#1{\the\cb@currentpoint n\the\cb@page p\the\@tempdima l#1}}
\def\cb@barpoint#1#2#3{\immediate\write\cb@write{#1n#2p#3l}}
\let\cb@document=\document
\def\document{\cb@document
              \cb@setup@specials
              \cb@positions
              \immediate\closeout\cb@write
              \immediate\openin\cb@read=\jobname.cb}
\let\cb@enddocument\enddocument
\def\enddocument{\clearpage\cb@initlist\cb@history
   \immediate\closein\cb@read\immediate\openin\cb@read=\jobname.cb%
   \let\cb@barpoint=\cb@checkHistory\cb@enddocument}
\def\cb@checkHistory#1#2#3{\cb@pop\cb@history
        \ifnum #1=\cb@currentpoint
            \ifnum #2=\cb@page        % do nothing
            \else \cb@error           % page numbers mismatched
            \fi
        \else \cb@error               % point numbers mismatched
        \fi}
\def\cb@error{%
  \message{Changebar Warning: Changebar info has changed. %
                              Rerun to get right.}
  \gdef\cb@checkHistory##1##2##3{}%
  \let\cb@barpoint=\cb@checkHistory}
\let\cb@endfloat=\end@float
\def\end@float{%
  \cb@pop\cb@currentlist
  \ifnum\cb@currentpoint=\cb@nil
  \else
    \cb@push\cb@currentlist
    \global\@tempdima=\@tempdima
    \egroup
    \global\setbox\@currbox=%
        \vbox\bgroup\cb@start[\@tempdima]\unvbox\@currbox\cb@end
  \fi
  \cb@endfloat}
\let\endfigure=\end@float       % need to rebind these to new def
\let\endtable=\end@float
\let\cb@footnote=\@footnotetext
\long\def\@footnotetext#1{%
  \cb@pop\cb@currentlist
  \ifnum\cb@currentpoint=\cb@nil
    \cb@footnote{#1}
  \else
    \cb@push\cb@currentlist
    \edef\cb@temp{\the\@tempdima}%
    \cb@footnote{\cb@start[\cb@temp]#1\cb@end}%
  \fi}
\let\cb@mpfootnote=\@mpfootnotetext
\long\def\@mpfootnotetext#1{%
  \cb@pop\cb@currentlist
  \ifnum\cb@currentpoint=\cb@nil
    \cb@mpfootnote{#1}
  \else
    \cb@push\cb@currentlist
    \edef\cb@temp{\the\@tempdima}%
    \cb@mpfootnote{\cb@start[\cb@temp]#1\cb@end}%
  \fi}
\catcode`\@=\atcatcode \let\atcatcode\relax
%\endinput
%% 
%% End of file `changebar.sty'.
%
% end of changebar.sty; now we configure it:
%
% partain:
\driver{DVIPS}
% want black, thin lines
\setlength{\changebarwidth}{0.2pt}
\setcounter{changebargrey}{0}
%
\makeatother
%========================================================================

%========================================================================
\makeatletter

% Olin Shiver's code.sty
% partain: the stuff actually used is defined immediately afterwards
%--------
% code.sty: -*- latex -*-
% Latex macros for a "weak" verbatim mode.
% -- like verbatim, except \, {, and } have their usual meanings.

% Environments: code, tightcode,  codeaux, codebox, centercode
% Commands: \dcd, \cddollar, \cdmath, \cd, \codeallowbreaks, \codeskip, \^
% Already defined in LaTeX, but of some relevance: \#, \$, \%, \&, \_, \{, \}

% Changelog at the end of the file.

% These commands give you an environment, code, that is like verbatim
% except that you can still insert commands in the middle of the environment:
%     \begin{code}
%     for(x=1; x<loop_bound; x++)
%         y += x^3; /* {\em Add in {\tt x} cubed} */
%     \end{code}
%
% All characters are ordinary except \{}. To get \{} in your text, 
% you use the commands \\, \{, and \}.

% These macros mess with the definition of the special chars (e.g., ^_~%).
% The characters \{} are left alone, so you can still have embedded commands:
%	\begin{code} f(a,b,\ldots,y,z) \end{code}
% However, if your embedded commands use the formerly-special chars, as in
%    	\begin{code} x := x+1 /* \mbox{\em This is $y^3$} */ \end{code}
% then you lose. The $ and ^ chars are scanned in as non-specials,
% so they don't work. If the chars are scanned *outside* the code env,
% then you have no problem:
% 	\def\ycube{$y^3$}
% 	\begin{code} x := x+1 /* {\em This is \ycube} */ \end{code}
% If you must put special chars inside the code env, you do it by
% prefixing them with the special \dcd ("decode") command, that
% reverts the chars to back to special status:
%    	\begin{code} x := x+1 /* {\dcd\em This is $y^3$} */ \end{code}
% \dcd's scope is bounded by its enclosing braces. It is only defined within
% the code env. You can also turn on just $ with the \cddollar command;
% you can turn on just $^_ with the \cdmath command. See below.
%
% Alternatively, just use \(...\) for $...$, \sp for ^, and \sb for _.

% WARNING:
% Like \verb, you cannot put a \cd{...} inside an argument to a macro
% or a command. If you try, for example,
%     \mbox{\cd{$x^y$}}
% you will lose. That is because the text "\cd{$x^y$}" gets read in
% as \mbox's argument before the \cd executes. But the \cd has to
% have a chance to run before LaTeX ever reads the $x^y$ so it can
% turn off the specialness of $ and ^. So, \cd has to appear at
% top level, not inside an argument. Similarly, you can't have
% a \cd or a \code inside a macro (Although you could use \gdef to
% define a macro *inside* a \cd, which you could then use outside.
% Don't worry about this if you don't understand it.)

% BUG: In the codebox env, the effect of a \dcd, \cddollar, or \cdmath
%   command is reset at the end of each line. This can be hacked by
%   messing with the \halign's preamble, if you feel up to it.

% Useage note: the initial newline after the \begin{code} or 
%   \begin{codebox} is eaten, but the last newline is not.
%   So,
%     \begin{code}
%     foo
%     bar
%     \end{code}
%  leaves one more blank line after bar than does
%     \begin{code}
%     foo
%     bar\end{code}
%  Moral: get in the habit of terminating code envs without a newline
%  (as in the second example).
%

% All this stuff tweaks the meaning of space, tab, and newline.
%===============================================================================
% \cd@obeyspaces
% Turns all spaces into non-breakable spaces.
% Note: this is like \@vobeyspaces except without spurious space in defn.
% @xobeysp is basically a space; it's defined in latex.tex.
%
{\catcode`\ =\active\gdef\cd@obeyspaces{\catcode`\ =\active\let =\@xobeysp}}



% \cd@obeytabs
% Turns all tabs into 8 non-breakable spaces (which is bogus).
%
{\catcode`\^^I=\active %
  \gdef\cd@obeytabs{\catcode`\^^I=\active\let^^I=\cd@tab}}

\def\cd@tab{\@xobeysp\@xobeysp\@xobeysp\@xobeysp\@xobeysp\@xobeysp\@xobeysp\@xobeysp}



% \cd@obeylines
% Turns all cr's into linebreaks. Pagebreaks are not permitted between lines.
% This is copied from lplain.tex's \obeylines, with the cr def'n changed.
%
{\catcode`\^^M=\active % these lines must end with %
  \gdef\cd@obeylines{\catcode`\^^M=\active\let^^M=\cd@cr}}

% What ^M turns into. This def'n keeps blank lines from being compressed out.
\def\cd@cr{\par\penalty10000\leavevmode} 	% TeX magicness
%\def\cd@cr{\par\penalty10000\mbox{}}		% LaTeX


% \codeallowbreaks
% Same as \cd@obeylines, except pagebreaks are allowed.
% Put this command inside a code env to allow pagebreaks.

{\catcode`\^^M=\active % these lines must end with %
  \gdef\codeallowbreaks{\catcode`\^^M\active\let^^M\cd@crbr}}

%\def\cd@crbr{\leavevmode\endgraf} % What ^M turns into.
%partain:
\def\cd@crbr{\par\leavevmode} % What ^M turns into.


% \cd@obeycrsp 
% Turns cr's into non-breakable spaces. Used by \cd.

{\catcode`\^^M=\active % these lines must end with %
  \gdef\cd@obeycrsp{\catcode`\^^M=\active\let^^M=\@xobeysp}}

% =============================================================================

% Set up code environment, in which most of the common special characters
% appearing in code are treated verbatim, namely: $&#^_~%
% \ { } are still enabled so that macros can be called in this
% environment.  Use \\, \{, and \} to use these characters verbatim
% in this environment.
% 
% Inside a group, you can make
% all the hacked chars	special with the	\dcd		command
% $			special with the 	\cddollar	command
% $^_			special with the	\cdmath		command.
% If you have a bunch of math $..$'s in your code env, then a global \cddollar
% or \cdmath at the beginning of the env can save a lot of trouble.
% When chars are special (e.g., after a \dcd), you can still get #$%&_{} with
% \#, \$, \%, \&, \_, \{, and \} -- this is standard LaTeX.
% Additionally, \\ gives \ inside the code env, and when \cdmath
% makes ^ special, it also defines \^ to give ^.

%The hacked characters can be made special again
% within a group by using the \dcd command.

% Note: this environment allows no breaking of lines whatsoever; not
% at spaces or hypens.  To arrange for a break use the standard \- command,
% or a \discretionary{}{}{} which breaks, but inserts nothing.  This is useful,
% for example for allowing hypenated identifiers to be broken, e.g.
% \def\={\discretionary{}{}{}} %optional break
% FOO-\=BAR.

\def\setupcode{\parsep=0pt\parindent=0pt%
  \tt\frenchspacing\catcode``=13\@noligs%
  \def\\{\char`\\}%
  \let\dcd=\cd@dcd\let\cddollar=\cd@dollarspecial\let\cdmath=\cd@mathspecial%
  \@makeother\$\@makeother\&\@makeother\#%
  \@makeother\^\@makeother\_\@makeother\~%
  \@makeother\%\cd@obeytabs\cd@obeyspaces}
% other: $&#^_~%
% left special: \{}
% unnecessary: @`'"


%% codebox, centercode
%%=============================================================================
%% The codebox env makes a box exactly as wide as it needs to be
%% (i.e., as wide as the longest line of code is). This is useful
%% if you want to center a chunk of code, or flush it right, or
%% something like that. The optional argument to the environment,
%% [t], [c], or [b], specifies how to vertically align the codebox,
%% just as with arrays or other boxes. Default is [c].

%% Must be a newline immediately after "\begin{codebox}[t]"!

{\catcode`\^^M=\active % these lines must end with %
  \gdef\cd@obeycr{\catcode`\^^M=\active\let^^M=\cr}}

% If there is a [<letter>] option, then the following newline will
% be read *after* ^M is bound to \cr, so we're cool. If there isn't
% an option given (i.e., default to [c]), then the @\ifnextchar will
% gobble up the newline as it gobbles whitespace. So we insert the
% \cr explicitly. Isn't TeX fun?
\def\codebox{\leavevmode\@ifnextchar[{\@codebox}{\@codebox[c]\cr}} %]

\def\@codebox[#1]%
  {\hbox\bgroup$\if #1t\vtop \else \if#1b\vbox \else \vcenter \fi\fi\bgroup%
   \tabskip\z@\setupcode\cd@obeycr% just before cd@obey
   \halign\bgroup##\hfil\span}

\def\endcodebox{\crcr\egroup\egroup\m@th$\egroup}

% Center the box on the page:
\newenvironment{centercode}%
  {\begin{center}\begin{codebox}[c]}%
  {\end{codebox}\end{center}}


%% code, codeaux, tightcode
%%=============================================================================
%% Code environment as described above. Lines are kept on one page.
%% This actually works by setting a huge penalty for breaking
%% between lines of code. Code is indented same as other displayed paras.
%% Note: to increase left margin, use \begin{codeaux}{\leftmargin=1in}.

% To allow pagebreaks, say \codeallowbreaks immediately inside the env.
% You can allow breaks at specific lines with a \pagebreak form.

%% N.B.: The \global\@ignoretrue command must be performed just inside
%% the *last* \end{...} before the following text. If not, you will
%% get an extra space on the following line. Blech.

%% This environment takes two arguments. 
%% The second, required argument is the \list parameters to override the
%%     \@listi... defaults.
%%     - Usefully set by clients: \topsep \leftmargin
%%     - Possible, but less useful: \partopsep
%% The first, optional argument is the extra \parskip glue that you get around
%%     \list environments. It defaults to the value of \parskip.
\def\codeaux{\@ifnextchar[{\@codeaux}{\@codeaux[\parskip]}} %]
\def\@codeaux[#1]#2{%
  \bgroup\parskip#1%
	 \begin{list}{}%
	       {\parsep\z@\rightskip\z@\listparindent\z@\itemindent\z@#2}%
	       \item[]\setupcode\cd@obeylines}%
\def\endcodeaux{\end{list}\leavevmode\egroup\ignorespaces\global\@ignoretrue}

%% Code env is codeaux with the default margin and spacing \list params:
\def\code{\codeaux{}} \let\endcode=\endcodeaux

%% Like code, but with no extra vertical space above and below.
\def\tightcode{\codeaux[=0pt]{\topsep\z@}}%
\let\endtightcode\endcodeaux
%  {\vspace{-1\parskip}\begin{codeaux}{\partopsep\z@\topsep\z@}}%
%  {\end{codeaux}\vspace{-1\parskip}}



% Reasonable separation between lines of code
\newcommand{\codeskip}{\penalty0\vspace{2ex}}


% \cd is used to build a code environment in the middle of text.
% Note: only difference from display code is that cr's are taken
% as unbreakable spaces instead of linebreaks.

\def\cd{\leavevmode\begingroup\ifmmode\let\startcode=\startmcode\else%
	\let\startcode\starttcode\fi%
	\setupcode\cd@obeycrsp\startcode}

\def\starttcode#1{#1\endgroup}
\def\startmcode#1{\hbox{#1}\endgroup}


% Restore $&#^_~% to their normal catcodes
% Define \^ to give the ^ char.
% \dcd points to this guy inside a code env.
\def\cd@dcd{\catcode`\$=3\catcode`\&=4\catcode`\#=6\catcode`\^=7%
	   \catcode`\_=8\catcode`\~=13\catcode`\%=14\def\^{\char`\^}}

% Selectively enable $, and $^_ as special.
% \cd@mathspecial also defines \^ give the ^ char.
% \cddollar and \cdmath point to these guys inside a code env.
\def\cd@dollarspecial{\catcode`\$=3}
\def\cd@mathspecial{\catcode`\$=3\catcode`\^=7\catcode`\_=8%
		    \def\^{\char`\^}}


% Change log:
% Started off as some macros found in C. Rich's library.
% Olin 1/90:
% Removed \makeatletter, \makeatother's -- they shouldn't be there,
%   because style option files are read with makeatletter. The terminal
%   makeatother screwed things up for the following style options.
% Olin 3/91:
% Rewritten. 
% - Changed things so blank lines don't get compressed out (the \leavevmove
%   in \cd@cr and \cd@crwb). 
% - Changed names to somewhat less horrible choices. 
% - Added lots of doc, so casual hackers can more easily mess with all this.
% - Removed `'"@ from the set of hacked chars, since they are already
%   non-special. 
% - Removed the bigcode env, which effect can be had with the \codeallowbreaks
%   command.
% - Removed the \@noligs command, since it's already defined in latex.tex.
% - Win big with the new \dcd, \cddollar, and \cdmath commands.
% - Now, *only* the chars \{} are special inside the code env. If you need
%   more, use the \dcd command inside a group.
% - \cd now works inside math mode. (But if you use it in a superscript,
%   it still comes out full size. You must explicitly put a \scriptsize\tt
%   inside the \cd: $x^{\cd{\scriptsize\tt...}}$. A \leavevmode was added
%   so that if you begin a paragraph with a \cd{...}, TeX realises you
%   are starting a paragraph.
% - Added the codebox env. Tricky bit involving the first line hacked
%   with help from David Long.

% end of code.sty
%
% partain: things actually used
%% verbcode env is like tightcode:
%\def\verbcode{\codeaux[=0pt]{\topsep\z@\parskip\z@\leftmargin\litcodeindent}} \let\endverbcode=\endcodeaux
%\def\verbcode{\codeaux{\leftmargin\litcodeindent\cbstart}}%
\def\verbcode{%
  \bgroup\parskip\parskip%
	 \begin{list}{}%
	       {\parsep\z@\rightskip\z@\listparindent\z@\itemindent\z@\leftmargin\litcodeindent}%
	       \item[]\setupcode\cd@obeylines\cbstart}%
\def\endverbcode{\cbend\end{list}\leavevmode\egroup\ignorespaces\global\@ignoretrue}
%
\def\verbtext{\codeaux{\leftmargin\litcodeindent}} \let\endverbtext=\endcodeaux
%
\makeatother
%========================================================================
