%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% LaTeX2e document class for the second edition of                     %%
%%  ``Structure and Interpretation of Computer Programs''               %%
%%                                                                      %%
%%  The orginal version of these macros was adapted from Amy            %%
%%  Hendrickson's macros for ``Introduction to Algorithms'' by Cormen,  %%
%%  Leiserson and Rivest (MIT Press).  However, the code has been       %%
%%  thoroughly revised and rewritten by David M. Jones, egged on by     %%
%%  Julie Sussman, and if any of the original code persists, it's not   %%
%%  for lack of effort on his part.                                     %%
%%                                                                      %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%%   1/24/01 Julie: Change \chaptermark to put running head on both pages
%%                    I don't know why David made it blank on the right.
%%                  Also add \fmattermark to index, consistent with
%%                    David's comment there.
%%   12/8/00 Julie: Added index entry here for SICM
%%   12/6/00 Julie: Change explanation of italics in index
%%   12/3/00 Julie: Added cleardoublepage here for SICM
%%		Otherwise, since list of exercises in SICM is just 1 page,
%%		index starts on even page.  ***NOTE*** not tested with
%%		SICP (to be sure index starts in right place).
%%   11/29/00 jems: Index entries in equations have equation number
%%		  (like figure and exercise numbers)
%%		  Involved additions to indexing section and new line in
%%                equation environment.
%%
%%   10/24/00 jems: increased pnumwidth so xxiii fits in TOC
%%
%%   8/8/96  jw:  Changed \begin{exercise} to take title argument,
%%                and made the \expart and \expartstart use \bf.
%%
%%   8/1/96  jw:  Removed forewordauthor, patched out MT fonts.
%%   
%%   4/15/96 dmj: Changed \@theindex back to using \twocolumn instead
%%                of multicols.  Also changed font sizes in cmtt2
%%                family by a miniscule amount to keep TeX from giving
%%                the cmtt and cmtt2 fonts the same \hyphenchar.
%%   
%%   4/13/96 jems:Increased \parskip in references
%%		  Changed version to 2.0 -- the one used for the actual book!
%%   
%%   4/11/96 dmj: Removed \prefacesection from \theindex and converted
%%                theindex to use multicols so we have more control
%%                over what goes at the front of the index.
%%   
%%   4/11/96 jems:changed vskip in index
%%   
%%   4/9/96  dmj: Modified indexing code to provide support for "fake
%%                parens" in sorting \incodeplus entries, i.e.,
%%                \indcodeplus{foo}{bar} will be sorted as if it were
%%                "foo (bar)" rather than "foo bar".  Also added a few
%%                comments about various parts of the macros that
%%                could be improved on in obvious ways, but which
%%                we're leaving alone since we're only making
%%                absolutely essential changes now.  Caveat emptor.
%%   
%%   4/8/96  dmj: Added support for cropmarks.  Added \contentsheading
%%                for use in \tableofcontents in lieu of
%%                \prefacesection so the spacing after the heading can
%%                be adjusted separately.
%%   
%%   4/2/96  dmj: Patched exercise environment to fix problem with
%%                second paragraph of an exercise sometimes not being
%%                indented.  Patched \@fullindex and \@@ind to cajole
%%                index entries at the beginning of a paragraph to
%%                stick with the paragraph.
%%  
%%  3/19/96  dmj: Moved \begingroup...\endgroup pair from \pagekludge
%%                to \@longpage and \@shortpage so \pagekludge will
%%                work with things that need to make local changes.
%%                Redefined \subsubsectionmark to put subsubsection
%%                titles in running head.
%%  
%%  3/19/96 jems: changed space  below \subsubsubsection
%%  
%%  3/18/96  dmj: Added \subsubsubsection for use in chapter 4.
%%                Extended \shrinksurroundspace to work for any list
%%                environment.  Added \shrinkitemspace for shrinking
%%                inter-\item space inside lists.
%%  
%%  3/17/96  dmj: Removed blank line that had crept into the
%%                definition of \@esphack and was causing unwanted
%%                paragraph breaks.  Redefined \pagekludge to fix
%%                problem with embedding a \longpage or \shortpage
%%                command in a \pagekludge.
%%  
%%  3/15/96  dmj: Added \shrinksurroundingspace for adjusting vertical
%%                space around lisp environments.
%%  
%%  3/14/96  dmj: Redefined \@bsphack and \@esphack to make commands
%%		  ``vertically'' transparent.  Added \longpage and
%%		  \shortpage commands.  Changed \texttt to \tt in
%%		  indexing commands for compatbility with the markup
%%		  in the main text.
%%  
%%  3/13/96  dmj: changed \theindex in a different way to really fix
%%		  the problem with the page heading and also to
%%		  prevent the index from showing up twice in the table
%%		  of contents.  Modified banner at top of file to give
%%		  slightly more accurate summary of the history of the
%%		  current code.  Added cmtt2 family to allow
%%		  hyphenation of function names in the index.  Patched
%%		  exercise environment to solve some problems
%%		  associated with placement of the heading and
%%		  breaking after first line of text.  Added lisp*
%%		  environment as a version of lisp that prohibits
%%		  breaks before or after itself.
%%
%%  3/12/96 jems: change \prefacesection call in index as told by dmj
%%  
%%  3/11/96  dmj: Further work on indexing commands.  Removed
%%		  restriction on definitions inside of footnotes,
%%		  exercises or figures.  Added \indsee and \indseealso
%%		  commands.  Reorganized indexing code a bit.
%%  
%%  3/10/96 jems: Changed index format params, to squeeze more in
%% 		  Decrease \columnsep in theindex from 35pt to 18pt.
%%		  Decrease \subitem's hspace from 9pt to 6pt,
%%		  [unused] \subsubitem's hspace from 13.5pt to 10pt
%%		  all the \hangindent to 12pt from 18pt
%%  3/10/96 jems: **put back mt package deleted by David**
%%  3/10/96 jems: Added a note printed at start of index and edited other note.
%%  3/9/96   dmj: Added INDEXING section.  Deleted some more fossil
%%                code.  Moved a few sections of code around a little
%%                to promote more logical grouping.
%%  
%%  3/9/96  jems: New \expart macro for uniform spacing after part name
%%  3/6/96  jems: Decreased topsep in small (10-->9),
%%                for space around lisp in ex
%%  3/4/96  jems: Fix title and halftitle to use \LARGE instead of \Large
%%  
%%  3/3/96   dmj: Redefined \chaptermark to only put chapter number in
%%                the running heads if the chapter number is positive,
%%                so that it can be used in the frontmatter.  Removed
%%                all stretchability and shrinkability in vertical
%%                glue since TeX seems to be using those sometimes
%%                despite the \raggedbottom setting.  This was causing
%%                inconsistent spacing around various environments,
%%                notably lisp and bulletlist.
%%
%%  3/1/96   dmj: changed spacing after \prefacesection. Removed
%%                unwanted \vskips from \tableofcontents and something
%%                else.  Removed unneeded \markboth/\@mkboth's from
%%                \tableofcontents, \listofexercises, \theindex;
%%                replaced them by a call to \chaptermark inside
%%                \prefacesection.  Updated \@schapter and
%%                \@makeschapterhead so \chapter* can be used for the
%%                Preface, which needs to be handled differently from
%%                the other frontmatter.
%%
%% 2/29/96  jems: set \emergencystretch globally; add \hyphenation
%% 2/28/96   dmj: Added pagekludge and linedkludge; modified spacing
%%                after chapter headings and epigraphs
%%  
%% 2/28/96  jems: Add \hyphenation
%% 2/23/96  jems: Removed setting page # in maketitle
%% 2/23/96  jems: Renamed 'copyrightnotice' to 'publisher' (for title page)
%%		  Increased \hfuzz
%%		  Increased \topsep by 2 points to make up for
%%		  yesterday's change of \partopsep to 0.
%% 2/22/96   dmj: Replaced \matter by \prefacesection.  Removed
%%		  \pseighteenrm.  Reset \partopsep to 0 from its
%%		  original value of 2pt so the spacing above lists
%%		  doesn't depend on whether there is a blank line
%%		  there.  Removed some more code that was commented
%%		  out a few revisions ago.  Added references
%%		  environment for use in end-matter.tex.  Added a lot
%%		  of stuff for the frontmatter.  Added smallequation
%%		  environment for use in chapter 1.  Removed
%%		  \ninepoint, \pseighteenbf and \pstwelverm entirely.
%%		  Removed \fivrm and the star fonts.
%% 
%% 2/22/96  jems: use chaptertitlefont, not pseighteenrm, in prefacesection
%%                ?? Is pseighteenrm needed any more?
%%
%% 2/22/96   dmj: Fixed bug that caused extra space before exercises.
%%		  Fixed bug in epigraph that caused the following
%%		  paragraph to be indented unless the epigraph
%%		  immediately followed a \chapter. Finished List of
%%		  Exercises mechanism.
%% 
%% 2/22/96  jems: increased \abovedisplayskip in footnotes, for space
%%		  around "math"
%%
%% 2/21/96   dmj: added epigraph environment and \attribution macro.
%%                Further simplified \@makechapterhead.  Replaced
%%                \ninepoint by \small.  Cleaned up theindex some.
%%                Fixed tabular so that there will only be a paragraph
%%                break after the tabular if there is a blank line
%%                after the tabular.  Made a few other small changes.
%% 
%% 2/20/96   jems: increased topsep in small, for space around lisp in ex
%% 2/20/96   dmj: renamed \pstwelvebf to \sectiontitlefont; tweaked
%%                lisp code environment
%%
%% 2/19/96   dmj: ripped out some more no-longer-used code that had
%%                been commented out in previous round of revision;
%%                removed \outdentsize, \negoutdentsize, \fullwidth,
%%                \outerline, \pseighteenbit, \pselevenbf, \pstenbit,
%%                \pagewidth, qed code; simplified and generally
%%                unobfuscated \@makechapterhead, \section,
%%                \sectionnonum.
%%
%% 1/18/96 jems: front-matter change -- see vskip  for prefacesection
%%   and its user
%% 1/18/96 jems: font size def changes
%%   new normalcodesize, footnotecodesize, exercisecodesize, figurecodesize
%%   enlarge footnote code 7.6-->8, exercise code 8.7-->9
%% 1/18/96 jems: increase floatsep from 12 to 18
%% 1/17/96 jems: reduce vskip in caption; flush unwanted sevenpoint, eightpoint
%% 1/17/96   dmj: further edits
%% 1/16/96   dmj: merged code from sicpmac.sty and sicpmath.sty into
%%           sicp.cls; fixed (?) spacing around various environemnts;
%%           also ripped out a lot of code that didn't look like it
%%           was doing anything useful
%% 1/11/96   dmj: misc fixes
%% 1/10/96   dmj: fixed TOC, redefined \cleardoublepage, added frontmatter
%% 12/15/95 jems: make it \typeout the section # when Latex runs
%% 11/15/95 jems: change section titles from 11.8pt to 11.7 to fit longest one
%% 11/10/95 jems: removed stuff pertaining to 'part's of book & other mis stuff
%% 11/8/95   dmj: changed \em and \tti again.  \tti now uses Times
%%                Oblique and \em always changes to either Times Roman
%%                or Times Italic, and never any half-breed fonts.
%% 
%% 10/23/95 dmj: converted to LaTeX2e document class (and by dent of
%%               prodigious effort managed *not* to subcumb to the
%%               desire to start rewriting the code from scratch)
%% 
%% 10/22/95 Julie: reduce beforeskip/afterskip for \section
%% 10/21/95 Julie: textwidth narrowed 1 pica as specified by MIT Press
%%                 added 1pt under subsubsection (= subheading) title
%%
%% 10/14/95 Julie: Increase secnumdepth from 2 to 3
%%  to have numbered subsubsections (for chap.4)
%%  (leaving tocdepth at 2 so they won't appear in toc)
%%  Also had to uncomment two defs used for subsubsections
%%
%%  Also increase size of section headings (finally!)
%%
%% 10/13/95 Julie: Modified 'quote' and 'quotation'
%%  (used only in chap.4) to indent.  But I can't figure out how to indent
%%  both of them on both the right and the left.
%%
%% 8/7/95 Add macros to control spacing after ! and ? in \tt
%%  (Brian Harvey's macro as modified by Bonnie)
%%
%% 8/3/95 new version by Bonnie
%% to put subsection number & name in the right-hand running head
%% instead of section
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\NeedsTeXFormat{LaTeX2e}

\ProvidesClass{mbook}[1996/04/11 v2.1 SICP book style]

%\RequirePackage{mt}

\RequirePackage{multicol}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%                                                                    %%
%%                          MISCELLANEOUS                             %%
%%                                                                    %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def\?{\discretionary{-}{}{-}}

%\hyphenation{ge-ner-ic}
\hyphenation{sema-phore}
\hyphenation{Fi-bo-nacci}%it only knew Fi-bonacci, according to log

%%  put something inside angle brackets

\newcommand{\an}[1]{$\langle{\hbox{\em$\,$#1$\,$}}\rangle$}

%%  \hyphenpenalty1000

%%  Any overfull boxes that are less than \hfuzz overfull are ignored.
%%  The default value is 0.1pt.
%%  dmj, 2/22/96

\hfuzz=0.5pt

%%  When there is an overfull box, Tex will retry the paragraph
%%  adding at most \emergencystretch white space to each line.
%%  The default value is 0

\emergencystretch=3pt

%%  \longpage has 3 modes of use:
%%  
%%      \longpage          : enlarges length of current page by
%%		             \baselineskip
%%
%%      \longpage[<int>]   : enlarges length of current page by int
%%		             times \baselineskip.  Example:
%%		             \longpage[2]
%%
%%      \longpage[<dimen>] : enlarges length of current page by dimen.
%%		             Example: \longpage[3pt]
%%  
%%  \shortpage is analogous, but reduces the length of the page.

\def\longpage{%
    \@ifnextchar [{\@longpage}{\@longpage[1]}%
}

%%  Added grouping to keep the \@bsphack, \@esphack pair inside
%%  \enlargethispage from interfering with the space hacks wrapped
%%  around \pagekludge.  Similar change to \@shortpage. -- dmj,
%%  3/19/96

\def\@longpage[#1]{%
    \begingroup
        \@defaultunits\@tempdima#1\baselineskip\@nnil
        \enlargethispage{\@tempdima}%
    \endgroup
}

\def\shortpage{%
    \@ifnextchar [{\@shortpage}{\@shortpage[1]}%
}

\def\@shortpage[#1]{%
    \begingroup
        \@defaultunits\@tempdima#1\baselineskip\@nnil
        \enlargethispage{-\@tempdima}%
    \endgroup
}

%%  kludge is used to insert visual formatting commands in the
%%  manuscript when doing final pagination.  It can be used either as
%%  a command with one argument, e.g.
%%  
%%      \kludge{\looseness=1}
%%  
%%  or as an environment, e.g.
%%  
%%      \begin{kludge}{\emergencystretch=2pt}
%%      
%%      <paragraph>
%%      
%%      \end{kludge}
%%  
%%  The first form should be used with commands whose effects are
%%  limited to the current location, paragraph or page, while the
%%  second should be used when changing parameters whose scope must be
%%  manually limited.  The first category includes things like
%%  \pagebreak, \nopagebreak, \newpage, \linebreak, \nolinebreak,
%%  \looseness, \enlargethispage, and \suppressfloats.  The second
%%  category includes just about everything else, including
%%  \emergencystretch, \sloppy, \tolerance, \hyphenpenalty, etc.

%%  Note that in the begin/end form there MUST be a blank line
%%  before the \begin and before the \end.
%%  A blank line before the <paragraph> is optional

%%  kludges are disabled by default, but can be enabled with the
%%  'usekludges' document class option.

\let\@kludge\@gobble

\def\pagekludge#1{\@bsphack\@kludge{#1}\@esphack}

%%  \def\pagekludge{\@bsphack\@kludge}

\def\linekludge{\@bsphack\@kludge}

\def\kludge{\@bsphack\@kludge}

\def\endkludge{\@Esphack}
\def\endlinekludge{\@Esphack}

%%  \def\endpagekludge{\@Esphack}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%                                                                    %%
%%                           FONT STUFF                               %%
%%                                                                    %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\renewcommand{\ttdefault}{cmtt}
\SetMathAlphabet{\mathtt}{normal}{\encodingdefault}{\ttdefault}{m}{n}

%%  These are the sizes for lisp code environments in various
%%  contexts.  The names are self-explanatory, except for
%%  \exercisecodesize, which would be more logically called
%%  \smallcodesize, since it's used whenever \small is in effect. --
%%  dmj, 2/22/96

\def\normalcodesize{\fontsize{9.8}{11pt}\selectfont}

\def\exercisecodesize{\fontsize{9}{10pt}\selectfont}

\def\figurecodesize{\fontsize{8.7}{10pt}\selectfont}

\def\footnotecodesize{\fontsize{8}{9pt}\selectfont}

%% \frenchspacing moved to definitions of \tt and \tti since the
%% third argument to \DeclareFontFamily only gets called when a new
%% font is loaded, not when it is selected.

\DeclareFontFamily{OT1}{cmtt}{\hyphenchar \font\m@ne}

%% \tt within 10.8-point (normal) text is scaled to 10.5
%% \tt within  9.8-point (exercise, fig caption) text is scaled to 9.7
\DeclareFontShape{OT1}{cmtt}{m}{n}{
        <5><6><7> <7.6> <8> <8.7> cmtt8
        <9> cmtt9
        <9.8> fixed * [9.7] cmtt9
        <10>cmtt10
        <10.8> fixed * [10.5] cmtt10
%% what is the 10.95 (and the other strange sizes below) for?  (jems)
        <10.95>cmtt10
        <12><14.4><17.28><20.74><24.88>cmtt12
}{}

%% This definition will use Courier Oblique for \tti and \its.  The
%% number in square brackets is the scale factor that will be applied
%% when the font is loaded.  I.e., if you request the font at 10pt, it
%% will be loaded at 8.6pt, etc.  This isn't really right, since the
%% \tt font is scaled by different amounts, but it will do for now.
%% NB. Size .86 found empirically 11/8 by Julie to fit (sentence...
%% line in sample.tex. Mystery: Why did the 12345... line fit at
%% larger size, but not the (sentence... line? They're the same
%% length.

\DeclareFontShape{OT1}{cmtt}{m}{it}{
   <-> * [.86] pcrro7t
}{}

\DeclareFontShape{OT1}{cmtt}{m}{sc}
     {
      <5> <6> <7> <8> <9>
      <10> <10.95> <12> <14.4> <17.28> <20.74> <24.88> cmtcsc10
      }{}
\DeclareFontShape{OT1}{cmtt}{m}{ui}
  {<->sub * cmtt/m/it}{}
\DeclareFontShape{OT1}{cmtt}{bx}{n}
  {<->sub * cmtt/m/n}{}
\DeclareFontShape{OT1}{cmtt}{bx}{it}
  {<->sub * cmtt/m/it}{}
\DeclareFontShape{OT1}{cmtt}{bx}{ui}
  {<->sub * cmtt/m/it}{}

%%  For the index, we need to allow hyphenation of long function
%%  names.  There are a couple of ways to do this.  One would be to
%%  explicitly change the \hyphenchar of the cmtt family back to `-'
%%  inside the theindex environment.  The other is to set up a second
%%  font family, identical to the cmtt family except that the
%%  \hyphenchar is not set to -1.  The first method has the
%%  disadvantage that \hyphenchar is one of TeX's truly global
%%  paramaters, which means that for robustness, we would need to
%%  manually change the \hyphenchar's back to their original values at
%%  the end of the environment.  It would also require us to know
%%  precisely which fonts we needed.  All in all, too much bookkeeping
%%  would be involved.  The second mechanism is more transparent, but
%%  has the disadvantage of requiring certain fonts to be loaded
%%  twice.  But since we're not really memory-bound, this shouldn't be
%%  a problem, so that's the route we'll take.
%%  
%%  One potential problem with both of these methods is that they will
%%  also enable automatic hyphenation of functions names that don't
%%  have explicit hyphens.  I won't bother doing anything about this
%%  just yet, because I don't whether it will be a real problem.
%%  
%%  I'll only make the normal, non-italic version of cmtt available,
%%  since it seems unlikely we'll need anything else in the index.  It
%%  will be easy enough to add the other variants if necessary. --
%%  dmj, 3/13/96

\DeclareFontFamily{OT1}{cmtt2}{}

\DeclareFontShape{OT1}{cmtt2}{m}{n}{
        <5><6><7> <7.6> <8> <8.7> cmtt8
        <9> cmtt9
%%  
%%  Changed font sizes slightly so they won't share a \hyphenchar with
%%  the corresponding fonts in the cmtt family. -- dmj, 4/15/96
%%  
        <9.8> fixed * [9.7001] cmtt9
        <10>cmtt10
        <10.8> fixed * [10.5001] cmtt10
        <10.95>cmtt10
        <12><14.4><17.28><20.74><24.88>cmtt12
}{}

%%  Renamed from \pstwelvebf to \sectiontitlefont to reflect its
%%  usage. -- dmj, 2/20/96

\def\sectiontitlefont{\normalfont\fontsize{11.7}{14pt}\selectfont\bfseries}

\DeclareFixedFont{\chapternumberfont}{OT1}{\rmdefault}{\bfdefault}{n}{40pt}

\def\chaptertitlefont{\normalfont\fontsize{19}{21pt}\selectfont\bfseries}

\DeclareMathAlphabet{\mathsc}{\encodingdefault}{\rmdefault}{m}{sc}
\SetMathAlphabet{\mathsc}{bold}{\encodingdefault}{\rmdefault}{b}{sc}

\DeclareOldFontCommand{\rm}{\normalfont\rmfamily}{\mathrm}
\DeclareOldFontCommand{\sf}{\normalfont\sffamily}{\mathsf}
\DeclareOldFontCommand{\tt}{\normalfont\ttfamily\frenchspacing}{\mathtt}

\DeclareOldFontCommand{\smalltt}{\@lispcodesize\tt}{\mathsmalltt}

\newcommand{\@tt}{}
\let\@tt\tt

%%  \ltt is for use within lisp environments, where spaces are active
%%  and therefore not automatically skipped in contexts such as
%%  "{\tt foo}".  The \@gobble will eat the (single) space after the
%%  \tt.  It could be made to gobble up arbitrarily many spaces, but
%%  it's probably not worth the effort.  \tt will automatically be
%%  redefined to be equivalent to \ltt inside the lisp and smalllisp
%%  environments.

\def\ltt{\@tt\@gobble}

\DeclareOldFontCommand{\tti}
    {\normalfont\ttfamily\itshape\selectfont\frenchspacing}
    {\mathtti}

% computer output in Lisp code 

\newcommand{\its}[1]{{\tti #1}}

\DeclareOldFontCommand{\bf}{\normalfont\bfseries}{\mathbf}
\DeclareOldFontCommand{\it}{\normalfont\itshape}{\mathit}
\DeclareOldFontCommand{\bit}{\normalfont\bfseries\itshape}{\mathbf}
\DeclareOldFontCommand{\sl}{\normalfont\slshape}{\@nomath\sl}
\DeclareOldFontCommand{\sc}{\normalfont\scshape}{\mathsc}
\DeclareRobustCommand*{\cal}{\@fontswitch{\relax}{\mathcal}}
\DeclareRobustCommand*{\mit}{\@fontswitch{\relax}{\mathnormal}}

%%  This will redefine \em to behave as in LaTeX 2.09, i.e., \em will
%%  always give either Times Italic or Times Roman, and never
%%  something like CM Typewriter Italic or Times Bold-Italic.
%%  (Presumably the book was coded with that expectation.)

\DeclareRobustCommand\em{%
  \@nomath\em
  \ifdim \fontdimen\@ne\font>\z@\rm\else\it\fi}

\newdimen\hruleheight
\hruleheight=.1pt

\voffset=-2pc
\raggedbottom

%%  Redefined \cleardoublepage so that any entirely blank pages
%%  inserted by \cleardoublepage will not contain any page headers or
%%  footers, unless we are in draft mode. -- dmj, 1/96

\def\cleardoublepage{%
    \clearpage
    \if@twoside
        \ifodd\c@page\else
            \null
            \thispagestyle{empty}%
            \newpage
            \if@twocolumn\null\newpage\fi
        \fi
    \fi
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%                                                                    %%
%%                     DOCUMENT CLASS OPTIONS                         %%
%%                                                                    %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def\@ptsize{0}

% \@namedef{ds@11pt}{\def\@ptsize{1}}
% \@namedef{ds@12pt}{\def\@ptsize{2}} 

\@twosidetrue
\@mparswitchtrue

\DeclareOption{draft}{\overfullrule 5\p@} 

\DeclareOption{final}{\overfullrule\z@}

\DeclareOption{usekludges}{%
    \let\@kludge\@iden
}

%%  Added cropmarks option. -- dmj, 4/8/96

\DeclareOption{cropmarks}{%
    \AtEndOfClass{\let\shipout\cropmark@shipout}%
}

\ProcessOptions\relax

%%%%%%%%%%%%%%%%%%% The following code is a variation on bk10.sty 23 Sep 85

\lineskip 1pt
\normallineskip 1pt

\def\baselinestretch{1}

\def\normalsize{%
    \@setfontsize\normalsize{10.8}{13pt}%
    \abovedisplayskip 10pt % plus2pt minus5pt
    \belowdisplayskip \abovedisplayskip
    \abovedisplayshortskip \z@ % plus3pt
    \belowdisplayshortskip 6pt % plus3pt minus3pt
}

\def\small{%
    \@setfontsize\small{9.8}{11pt}%
    \let\@lispcodesize\exercisecodesize
%%  
%%  This \abovedisplay skip controls the amount of space around
%%  displayed math stuff when \small is in effect.
%%  
    \abovedisplayskip 8.5\p@ % plus 2pt minus 3pt
    \belowdisplayskip \abovedisplayskip
    \abovedisplayshortskip \z@ % plus2pt
    \belowdisplayshortskip\abovedisplayshortskip
%%  
%%  This \topsep (I think) controls the amount of space above lisp
%%  environments and bulletlists and other lists in exercises.
%%  
    \topsep 9pt % plus 2pt minus 2pt
    \def\@listi{%
        \topsep 4pt % plus 2pt minus 2pt
        \parsep 2pt % plus 1pt minus 1pt
        \itemsep1pt %3pt
    }%
}

%%  \let\ninepoint\small

\def\footnotesize{%
    \@setfontsize\footnotesize{8.7}{10pt}%
    \let\@lispcodesize\footnotecodesize
%%  
%%  This \topsep (I think) controls the amount of space above lisp
%%  environments and bulletlists and other lists in footnotes.
%%  
    \topsep 6pt % plus 1pt minus 1pt
%%  
%%  This \abovedisplay skip controls the amount of space around
%%  displayed math stuff in footnotes.
%%  
    \abovedisplayskip 3pt % plus 1pt minus 1pt
    \belowdisplayskip \abovedisplayskip
    \abovedisplayshortskip \z@ % plus 1pt
    \belowdisplayshortskip\abovedisplayshortskip
    \def\@listi{%
        \topsep 3pt % plus 1pt minus 1pt
        \parsep 2pt % plus 1pt minus 1pt
        \itemsep \parsep
    }
}

\def\scriptsize{\@setfontsize\scriptsize{7.6}{8pt}}%% << need these?

\def\tiny{\@setfontsize\tiny\@vpt\@vipt}%% << need these?

\def\large{\@setfontsize\large\@xiipt{16pt}}

\def\Large{\@setfontsize\Large\@xivpt{18}}

\def\LARGE{\@setfontsize\LARGE{18}{20pt}}

\def\huge{\@setfontsize\huge\@xxpt{25}}%% << need these?
%\def\Huge{\@setfontsize\Huge\@xxvpt{30}}%% << need these?
\def\Huge{\@setfontsize\Huge\@xxvpt\@xxvpt{30}}%% << need these?

\normalsize 

\marginparwidth .75in
\marginparsep 7pt 

\footskip.35in 

\columnsep 10pt
\columnseprule 0pt 

\footnotesep 13pt
\skip\footins 14pt  %24pt% -- somehow affects space above footnote

\floatsep 18pt % plus 2pt minus 2pt
\textfloatsep 18pt % plus 2pt minus 4pt

\intextsep 12pt % plus 2pt minus 2pt

\dblfloatsep 12pt       % plus 2pt minus 2pt
\dbltextfloatsep 20pt   % plus 2pt minus 4pt

%%  Took out stretchability of \@fptop to make figures flush against
%%  top of page on float pages. -- dmj, 2/21/96

\@fptop 0pt % plus 1fil

%%  \@fpsep should probably be the same as \floatsep, since it
%%  controls the spacing between floats on a float page.  Also, the
%%  stretch should have been left in \@fpbot.  But it's too late to
%%  change it for SICP II. -- dmj, 4/9/96

\@fpsep 8pt % plus 2fil

\@fpbot 0pt % plus 1fil 

\@dblfptop 0pt % plus 1fil
\@dblfpsep 8pt % plus 2fil
\@dblfpbot 0pt % plus 1fil

\marginparpush 5pt 

\parskip 0pt    % plus 1pt 

\parindent 1pc

%%  \topsep is the extra space added to the space above lists, such as
%%  bulletlists, lisp envionrments, etc.  It is reset by \small and
%%  \footnotesize. 

\topsep 10pt % plus 2pt minus 4pt

%%  \partopsep is the extra space added to \topsep above lists when
%%  there is a blank line before the list.

\partopsep\z@skip %% 2pt plus 1pt minus 1pt

\itemsep 1pt     % 4pt plus 2pt minus 1pt 
\@lowpenalty 51
\@medpenalty 151
\@highpenalty 301 
\@beginparpenalty -\@lowpenalty
\@endparpenalty -\@lowpenalty
\@itempenalty -\@lowpenalty 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%                                                                    %%
%%                          SPACING HACKS                             %%
%%                                                                    %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%  We have the following problem:  There are a number of commands and
%%  environments (notably, all the sectioning commands and all
%%  \list-based environments, including the exercise environment) that
%%  begin with an \addvspace command, which automatically adjusts the
%%  preceding vertical space to be at least the desired amount.  This
%%  means that if the current vertical list ends with
%%  
%%      \vskip <dimen>_1
%%
%%  and the next command executed is \addvspace{<dimen>_2}, where
%%  <dimen>_2 is greater than <dimen>_1, then the vertical list
%%  becomes
%%  
%%      \vskip  <dimen>_1
%%      \vskip -<dimen>_1
%%      \vskip  <dimen>_2
%%  
%%  However, if there is, for example, an \index, \label or
%%  \enlargethispage command between the \vskip and the \addvspace,
%%  then that command hides the previous \vskip, so we end up with
%%  something like this:
%%  
%%      \vskip  <dimen>_1
%%      <whatsit>
%%      \vskip  <dimen>_2
%%  
%%  producing an anomously large vertical space.  This happens, for
%%  example, if there is and index command between to exercises, or
%%  between an exercise and a section command.
%%  
%%  The analogous problem in horizontal mode is handled by using the
%%  \@bsphack and \@esphack macros to make commands ``transparent'' in
%%  horizontal mode, but as defined by default in LaTeX, they have no
%%  effect in vertical mode.  So, I'm adding a clause to be executed
%%  in vertical mode.  Essentially, the clause has the effect of
%%  moving any vertical space above the \index, etc., command to below
%%  the command.  More specifically, it will convert a vertical list
%%  of the form
%%  
%%      \vskip <dimen>_1
%%      <whatsit>
%%  
%%  to
%%
%%      \vskip <dimen>_1
%%      \vskip -<dimen>_1
%%      <whatsit>
%%      \vskip <dimen>_1
%%  
%%  so that a following \addvspace command can see the vertical skip
%%  and act accordingly.
%%  
%%  This should make it safe to put index commands and the such
%%  between exercises or between an exercise and a section command.
%%  
%%  CAVEATS:
%%  
%%  Unfortunately, it will still not make it save to put them at the
%%  very end of a paragraph, e.g.,
%%  
%%      end of paragraph.\index{foo}
%%  
%%  since TeX might still decide to put a line break between the . and
%%  the \index entry.
%%  
%%  Furthermore, it is still possible that TeX will decide to put a
%%  pagebreak *before* an index entry (or label, for that matter) if
%%  the index command immediately follows an exercise.  However, in
%%  such a case, the whatsit corresponding to the index entry will be
%%  the first item on the following page, so it should be possible to
%%  detect such cases automatically and then check by hand to make
%%  sure that none of them are problems.  -- dmj, 3/14/96

\newskip\@savvsk
\@savvsk\z@skip

\newcount\@savepen

\def\@bsphack{%
    \relax
    \ifhmode
        \@savsk \lastskip
        \@savsf \spacefactor
    \else
        \@savvsk \lastskip
        \ifdim\@savvsk > \z@
            \vskip-\@savvsk
        \else
            \ifnum\lastpenalty = \z@ \else
                \@savepen\lastpenalty
            \fi
        \fi
    \fi
}

\def\@esphack{%
    \relax
    \ifhmode
        \spacefactor \@savsf
        \ifdim \@savsk>\z@
            \ignorespaces
        \fi
    \else
        \ifdim \@savvsk>\z@
            \vskip\@savvsk
            \@savvsk\z@
        \else
            \ifnum\@savepen = \z@ \else
                \penalty\@savepen
                \@savepen\z@
            \fi
        \fi
    \fi
}

\def\@Esphack{%
    \relax
    \ifmmode\else
        \ifhmode
            \spacefactor\@savsf
            \ifdim \@savsk >\z@
                \global\@ignoretrue
                \ignorespaces
            \fi
        \else
            \ifdim \@savvsk>\z@
                \vskip\@savvsk
                \@savvsk\z@
            \else
                \ifnum\@savepen = \z@ \else
                    \penalty\@savepen
                    \@savepen\z@
                \fi
            \fi
        \fi
    \fi
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%                                                                    %%
%%                            SECTIONING                              %%
%%                                                                    %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%  Simplified and generally unobfuscated \@makechapterhead.  More
%%  could be done (in particular, it should be possible to replace the
%%  outer \vbox by a \vskip17pt in place of the second \vfill), but
%%  I'm trying to be conservative. -- dmj, 2/19/96

%%  To hell with caution.  Let's fix it right. -- dmj, 2/21/96

\def\@makechapterhead#1{%
    \begingroup
        \parindent\z@
        \parskip\z@
        \leftline{\chapternumberfont\thechapter}%
        \vskip 1pc
        \leftline{\chaptertitlefont#1}
        \addvspace{1.5pc}%determines space between chapter head & epigraph
    \endgroup
}

\def\@makeschapterhead#1{%
    \begingroup
        \parindent\z@
        \parskip\z@
        \leftline{\chaptertitlefont#1}
        \addvspace{1.5pc}%determines space between chapter head & epigraph
    \endgroup
}

\newcounter {chapter}

\@addtoreset{equation}{chapter}

\def\chapter{%
    \cleardoublepage
    \thispagestyle{empty}%% was plain
    \gdef\thesection{\thechapter.\arabic{section}}%
    \def\thechapter{\arabic{chapter}}%
    \global\@topnum\z@
    \@afterindentfalse
    \secdef\@chapter\@schapter
}

\def\@chapter[#1]#2{%
    \refstepcounter{chapter}
    \typeout{\@chapapp\space\thechapter.}%
    \addcontentsline{toc}{chapter}{\protect\numberline{\thechapter}#1}%
    \chaptermark{#1}%
    \addtocontents{lof}{\protect\addvspace{10pt}}%
    \addtocontents{lot}{\protect\addvspace{10pt}}%
    \if@twocolumn
        \@topnewpage[\@makechapterhead{#2}]%
    \else
        \@makechapterhead{#2}%
        \@afterheading
    \fi
} 

\def\@schapter#1{%
    \addcontentsline{toc}{fmatter}{\protect\numberline{}#1}%
    \fmattermark{#1}%
    \@makeschapterhead{#1}% 
    \@afterheading
}

%%  Modified \prefacesection to be more tastefully coded and have
%%  spacing more like \chapter. -- dmj, 2/22/96

\def\prefacesection#1{
    \cleardoublepage
    \addcontentsline{toc}{fmatter}{\protect\numberline{}#1}%
    \fmattermark{#1}%
    \thispagestyle{empty}%
    \begingroup
        \parindent\z@
        \parskip\z@
%% 2/22/96 Julie: changed to chaptertitlefont (suggested by designer)
        \leftline{\chaptertitlefont#1}
        \addvspace{6pc}%
    \endgroup
    \@afterindentfalse
    \@afterheading
}

%%  \contentsheading is for use in the table of contents in place of
%%  \prefacesection.  Currently identical to \prefacesection except
%%  for amount of space put in afterwards.  Not the most tasteful way
%%  to do things, but at least it's safe. -- dmj, 4/8/96

\def\contentsheading#1{
    \cleardoublepage
    \addcontentsline{toc}{fmatter}{\protect\numberline{}#1}%
    \fmattermark{#1}%
    \thispagestyle{empty}%
    \begingroup
        \parindent\z@
        \parskip\z@
%% 2/22/96 Julie: changed to chaptertitlefont (suggested by designer)
        \leftline{\chaptertitlefont#1}
%%  
%%  Change this to control amount of space between "Contents" heading
%%  and beginning of contents. -- dmj, 4/8/96
%%  
        \addvspace{9pc}%
    \endgroup
    \@afterindentfalse
    \@afterheading
}

\newcounter {section}[chapter]
\newcounter {subsection}[section]

\newcounter {subsubsection}[subsection]

%%  \newcounter {paragraph}[subsubsection]
%%  \newcounter {subparagraph}[paragraph]

\def\thechapter {\arabic{chapter}}
\def\thesection {\thechapter.\arabic{section}}
\def\thesubsection {\thesection.\arabic{subsection}}
\def\thesubsubsection {\thesubsection .\arabic{subsubsection}}

%%  \def\theparagraph {\thesubsubsection.\arabic{paragraph}}
%%  \def\thesubparagraph {\theparagraph.\arabic{subparagraph}}

\def\@chapapp{Chapter}

%%  Changed @afteridentrue to @afterindentfalse to suppress
%%  indentation of first paragraph of a section.

\def\@startsection#1#2#3#4#5#6{\if@noskipsec \leavevmode \fi
   \par \@tempskipa #4\relax
   \@afterindentfalse%% << ah, was true
   \ifdim \@tempskipa <\z@ \@tempskipa -\@tempskipa \@afterindentfalse\fi
   \if@nobreak \everypar{}\else
     \addpenalty\@secpenalty\addvspace\@tempskipa\fi \@ifstar
     {\@ssect{#3}{#4}{#5}{#6}}{\@dblarg{\@sect{#1}{#2}{#3}{#4}{#5}{#6}}}}

\def\@seccntformat#1{\csname the#1\endcsname\hskip 1em\relax}

%%  ``after'' is the extra space added to the ordinary leading.
%%  ``before'' is the extra space added before the heading in addition
%%  to the normal leading
%%  
%%  \@startsection {NAME}{LEVEL}{INDENT}{BEFORESKIP}{AFTERSKIP}{STYLE} 

%%  Removed elaborate chunk of code that was doing nothing useful
%%  except adding extra space before the section heading; added 4pt to
%%  the 'beforeskip' argument for backwards compatibility, but this
%%  still isn't quite right.  Made analogous changes in \sectionnonum.
%%  -- dmj, 2/19/96

\def\section{%
    \global\@topnum\z@
    \@startsection {section}{1}{\z@}{24pt}{11pt}
        {\typeout{SECTION\space\thesection}\sectiontitlefont}%
}

\def\subsection{\@startsection{subsection}{2}{\z@}{13pt}{6pt}{\bf}}

\def\subsubsection{%
    \@startsection{subsubsection}{3}{\z@}{6pt}{1pt}{\normalsize\bf}%
}

\def\subsubsubsection{%
    \@startsection{subsubsubsection}{4}{\z@}{6pt}{2pt}{\normalsize\it}%
}

\def\paragraph{%
    \@startsection{paragraph}{5}{\z@}{16pt}{1sp}{\normalsize\bit}%
}

\def\subparagraph{%
    \@startsection{subparagraph}{0pt}{16pt}{-1em}{\normalsize\bit}%
}

\newcommand{\subheading}{\subsubsection*}

\setcounter{secnumdepth}{3}

\leftmargini 0pc        %1pc%25pt -- this keeps list items from being indented
	                %            at all
\leftmarginii 1pc       %0pt%
\leftmarginiii 18.7pt
\leftmarginiv 17pt
\leftmarginv 10pt
\leftmarginvi 10pt
\leftmargin\leftmargini

\labelwidth=\leftmargini
\advance\labelwidth-\labelsep
\labelsep 0pt                   %5pt

\parsep 4pt % plus 2pt minus 1pt

\def\@listi{\leftmargin\leftmargini\itemsep\p@}

\def\@listii{%
    \leftmargin\leftmarginii
    \labelsep\z@                   %1pc
    \labelwidth\leftmarginii
    \advance\labelwidth-\labelsep
    \topsep 4pt % plus 2pt minus 1pt
    \parsep 2pt % plus 1pt minus 1pt
    \itemsep1pt                     % \parsep
}

\def\@listiii{%
    \leftmargin\leftmarginiii
    \labelwidth\leftmarginiii
    \advance\labelwidth-\labelsep
    \topsep 2pt % plus 1pt minus 1pt 
    \parsep \z@
%%    \partopsep 1pt % plus 0pt minus 1pt
    \itemsep \topsep
}

%\def\@listiv{\leftmargin\leftmarginiv %% probably don't need these levels
                                       %% used for 4th and 5th level
                                       %% of list indentation.
% \labelwidth\leftmarginiv\advance\labelwidth-\labelsep}
%\def\@listv{\leftmargin\leftmarginv
% \labelwidth\leftmarginv\advance\labelwidth-\labelsep}
%\def\@listvi{\leftmargin\leftmarginvi
% \labelwidth\leftmarginvi\advance\labelwidth-\labelsep}

\baselineskip=13pt

\textwidth= 26pc
\textheight=41\baselineskip
\headsep .12in  % space under running head
\topmargin .75in

%%I don't really understand what these are doing.  They seem to be off
%%by about 1/4 inch.  This also has to do with the output routine,
%%which probably has to be rewritten

\oddsidemargin 1in %% 95pt%% 
\evensidemargin 1in %% 87pt%% 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\arraycolsep 5pt
\tabcolsep 6pt
\arrayrulewidth .4pt
\doublerulesep 2pt 
\tabbingsep=5pt% \labelsep 
\skip\@mpfootins = \skip\footins
\fboxsep = 3pt \fboxrule = .4pt 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%                                                                    %%
%%                        LIST ENVIRONMENTS                           %%
%%                                                                    %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%  \shrinksurroundingspace takes a <dimen> as an argument and
%%  shrinks the vertical space before and after the next list
%%  environment by the amount (a negative argument will increase the
%%  space).  It should only ever be inserted directly before the list
%%  environment to which you want it to apply.  Example:
%%  
%%      last line of paragraph preceding code.
%%      \shrinksurroundingspace{2pt}
%%      \begin{lisp}
%%      <code>
%%      \end{lisp}
%%      First line of paragraph after code....
%%
%%  will result in that particular lisp environment having 2pt less
%%  space above and below it than normal. -- dmj, 3/15/96

\newdimen\@shrinkamount

\def\shrinksurroundingspace#1{%
    \global\@shrinkamount#1%
}

\def\shrinkitemspace#1{%
    \advance\itemsep-#1\relax
}

\let\@@@trivlist\@trivlist

\def\@trivlist{%
    \advance\topsep-\@shrinkamount
    \global\@shrinkamount\z@
    \@@@trivlist
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%                                                                    %%
%%                     THE EPIGRAPH ENVIRONMENT                       %%
%%                                                                    %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newcommand{\attribution}[1]{%
    \addvspace{5pt}%
    \begingroup
        \parindent\z@
        \linepenalty9000
        #1\par
    \endgroup
    \addvspace{1pc}%
}

\newenvironment{epigraph}{%
    \addvspace{1pc}%
    \raggedleft
    \begin{minipage}[t]{3.1in}%
    \small\raggedright
}{%
    \end{minipage}%
    \par
    \addvspace{3.5pc}%determines space below epigraph
    \global\@ignoretrue
    \aftergroup\@afterindentfalse
    \aftergroup\@afterheading
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%                                                                    %%
%%                        LISP ENVIRONMENTS                           %%
%%                                                                    %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%  Redefined lisp environment, essentially by copying verbatim
%%  environment and making a few changes -- dmj, 1/14/96

%%  Tweaked lisp environment again.  Moved line breaking parameters
%%  inside the trivlist and after the \@@par and rewrote \par. -- dmj,
%%  2/20/96

\let\@lispcodesize\normalcodesize

\newenvironment{lisp}{%
    \let\tt\ltt
%%  
%%  This definition of \\ should be completely unnecessary, but it's
%%  too late in the game to take any chances. -- dmj, 4/9/96
%%  
    \def\\{\newline\null}%
%%    \advance\topsep-\@shrinkamount
%%    \global\@shrinkamount\z@
    \trivlist\item\relax
            \@@par
            \parskip\z@skip
            \parindent\z@
            \interlinepenalty\@Mi
            \@tempswafalse
            \def\par{%
                \if@tempswa
%%  
%%  Some delicate tweaking here.  In the standard verbatim
%%  environment, \leavevmode and \null are unconditionally called
%%  here.  This has the effect of retaining blank lines at the top of
%%  a page after an \allowbreak, which is undesirable.  Instead, we
%%  check to see whether we're still in vertical mode.  If so, it
%%  means that the current line is empty, and we just stick in a
%%  vertical skip of \baselineskip.  Since \vskip's at the top of
%%  pages are swallowed by TeX, this has the desired effect of
%%  suppressing the extraneous blank line. If we're not in vertical
%%  mode, we call \@@par to end the current line, as usual.  The
%%  \leavevmode and \null are no longer necessary.  In either case, we
%%  still need to put in the \interlinepenalty.
%%  
%%  That's the theory.  Hopefully it will work. -- dmj, 2/20/96
%%  
                    \ifvmode
                        \vskip\baselineskip
                    \else
%%                          \leavevmode \null
                        \@@par
                    \fi
                    \penalty\interlinepenalty
                \else
                    \@tempswatrue
                    \ifhmode\@@par\penalty\interlinepenalty\fi
                \fi
            }%
        \obeylines \frenchspacing\@vobeyspaces \@lispcodesize \tt \@noligs
        \everypar \expandafter{\the\everypar \unpenalty}%
}{%
    \endtrivlist
}

%%  lisp* is identical to lisp, except that it changes
%%  \@beginparpenalty and \@endparpenalty to 10001, thus (hopefully)
%%  preventing breaks before or after the environment.  (If necessary,
%%  an \allowbreak can be used immediately before or after the lisp*
%%  to allow a break there.) -- dmj, 3/13/96

%%  Obviously, this could be integrated better with the lisp
%%  environment by having the two environments share all of the
%%  common code, but by implementing it this way, we avoided any
%%  possible problems that might have ensued if we had changed the
%%  lisp environment.  -- dmj, 4/9/96

\newenvironment{lisp*}{%
    \let\tt\ltt
    \def\\{\newline\null}%
    \trivlist
        \@beginparpenalty\@Mi
        \@endparpenalty\@Mi
        \interlinepenalty\@Mi
        \item\relax
            \@@par
            \parskip\z@skip
            \parindent\z@
            \@tempswafalse
            \def\par{%
                \if@tempswa
                    \ifvmode
                        \vskip\baselineskip
                    \else
                        \@@par
                    \fi
                    \penalty\interlinepenalty
                \else
                    \@tempswatrue
                    \ifhmode\@@par\penalty\interlinepenalty\fi
                \fi
            }%
        \obeylines \frenchspacing\@vobeyspaces \@lispcodesize \tt \@noligs
        \everypar \expandafter{\the\everypar \unpenalty}%
        \penalty\interlinepenalty
}{%
    \endtrivlist
}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%                                                                    %%
%%                      EXCERCISE ENVIRONMENT                         %%
%%                                                                    %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newcounter{exercise}[chapter]
\renewcommand{\theexercise}{\thechapter.\arabic{exercise}}

\newcommand{\exercise}[1]{%
    \refstepcounter{exercise}%
    \let\idx@extra\exc@idxnum
%%  
%%  \topsep determines the space above the exercise
%%  
    \topsep 12\p@
    \partopsep\z@skip
    \parskip\z@skip
    \listparindent\z@skip
    \trivlist
        \small
        \@tempdima\dp\strutbox
%%  
%%  The length at the end of the 'advance' line determines the space
%%  after the exercise head.
%%  
        \advance\@tempdima 3pt
%%  
%%  This is a sort of non-intuitive place to put the \addcontentsline,
%%  but at least it gets it out of the way so TeX won't be tempted to
%%  treat it as a separate paragraph and put in extra space.  It also
%%  has the effect of ensuring that we'll never get a page break
%%  between the \addcontentsline and the exercise heading, which would
%%  cause the page number for that exercise in the List of Exercises
%%  to be off by one. -- dmj, 2/22/96
%%  
        \item[\hskip\labelsep
            \addcontentsline{exc}{exclist}{\theexercise}%
            \@@line{\bfseries
                \vrule width\z@ height\z@ depth \@tempdima
                 Exercise~\theexercise:~#1 \hfill}]%
%%  
%%  By forcing TeX into horizontal mode and then causing a paragraph
%%  break, we should be able to cause the exercise header to be spit
%%  out as a separate paragraph, while still gaining the benefits of
%%  letting the list mechanism take care of vertical spacing for us.
%%  We then stick in a huge penalty to prevent a page break between
%%  the heading and the beginning of the paragraph, and then stick in
%%  some magic to suppress the indentation of the first paragraph of
%%  the exercise.
%%  
%%  This should solve two problems: (a) page breaks after the first
%%  line of the exercise text and (b) causing a figure placed at the
%%  very beginning of an exercise to mess up the spacing and heading
%%  of the exercise.  -- dmj, 3/13/96
%%  
        \leavevmode\par
        \penalty\@M
%%  
%%  Added \global to fix bug that occurred if the first paragraph of
%%  an exercise began with a group. -- dmj, 4/2/96
%%  
        \everypar{\kern-\parindent \global\everypar{}}%
}

\let\endexercise\endtrivlist			

%% Next commands are used as follows, in an exercise [Julie, 3/9/96]
%%
%% \expart{a}text here with no space before it
%% \expartstart{a}text here with no space before it
%%
%% If they were smart, they would name the parts itself, but they're not,
%% so we give the part name as an argument.
%% Purpose is to make uniform space (not stretchable) after ex part name.
%% \expartstart is for use at the start of an exercise,
%% \expart is for later in the exercise

\newcommand{\expart}[1]{%
\medskip
\noindent
{\bf #1.}\enskip%
}

\newcommand{\expartstart}[1]{%
{\bf #1.}\enskip%
}


\def\@currchap{0}

\def\listofexercises{%
    \@restonecolfalse
    \if@twocolumn \@restonecoltrue \onecolumn \fi
    \cleardoublepage
    \prefacesection{List of Exercises}%
%%    \markboth{List of Exercises}{List of Exercises}%
%%  
%%  Normally we'd use \@starttoc for something like this, but that
%%  causes problems because we need to wrap the .exc file in an
%%  exclist environment, and since \@starttoc begins a new group,
%%  LaTeX's \begin...\end mechanism gets confused.  So, we duplicate
%%  the relevant functionality from \@starrtoc here. -- dmj, 2/22/96
%%  
    \begingroup
        \def\@currchap{1}%
        \makeatletter
        \begin{exclist}%
            \@input{\jobname.exc}%
        \end{exclist}%
        \if@filesw
            \newwrite\tf@exc
            \immediate\openout\tf@exc \jobname.exc\relax
        \fi
        \global\@nobreakfalse
    \endgroup
    \if@restonecol\twocolumn\fi
    \newpage
    \markboth{}{}%
}

\def\l@exclist#1#2{%
    \@checkchap#1\@nil
    \leavevmode
    \hb@xt@3.5pc{\textbf{#1}\hfill#2}%
    \par
}

\def\@checkchap#1.#2\@nil{%
    \ifnum#1>\@currchap \relax
        \end{exclist}%
        \def\@currchap{#1}%
        \begin{exclist}%
    \fi
}

\newenvironment{exclist}{%
    \small
    \parindent\z@
    \begin{multicols}{5}
}{%
    \end{multicols}
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%                                                                    %%
%%                        MATH ENVIRONMENTS                           %%
%%                                                                    %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newdimen\mathindent
\AtEndOfClass{\mathindent\z@}

\def\theequation{\thechapter.\arabic{equation}}

\renewcommand\[{%
    \relax
    \ifmmode
        \@badmath
    \else
%%  
%%  Added setting of \topsep to make sure spacing around equations is
%%  correct inside of other lists.
%%  
        \begin{trivlist}%
            \topsep\abovedisplayskip
            \@beginparpenalty\predisplaypenalty
            \@endparpenalty\postdisplaypenalty
            \item[]\leavevmode
            \hb@xt@\linewidth\bgroup
                $\m@th\displaystyle %$
                \hskip\mathindent
                \bgroup
    \fi
}

\renewcommand\]{%
    \relax
    \ifmmode
        \egroup
        $\hfil% $
        \egroup
        \end{trivlist}%
    \else
        \@badmath
    \fi
}

\newenvironment{smallequation}{%
    \small
    \[
}{%
    \]
}

\renewenvironment{equation}{
    \@beginparpenalty\predisplaypenalty
    \@endparpenalty\postdisplaypenalty
    \refstepcounter{equation}%
%%  
%%  Added setting of \topsep to make sure spacing around equations is
%%  correct inside of other lists.
%%  
    \topsep\abovedisplayskip
%%  Next line added by Julie, 11/29/00, to get equation numbers into index
    \let\idx@extra\eq@idxnum
    \trivlist
        \item[]\leavevmode
        \hb@xt@\linewidth\bgroup $\m@th% $
        \displaystyle
        \hskip\mathindent
}{%
    $\hfil % $
    \displaywidth\linewidth
    \hbox{\@eqnnum}%
    \egroup
    \endtrivlist
}

%% \@eqnmar controls whether the eqnarray environment is centered or
%% flushleft; if the environment should be centered, \@eqnmar should
%% be set equal to \@centering; else it should be set equal to
%% \mathindent.  \@eqnhook takes care of some other modifications that
%% should be made in flushleft mode; normally it's a no-op.

\let\@eqnmar\mathindent
%\let\@eqnmar\@centering

%%  Actually, it's not clear that this is doing anything useful right
%%  now. -- dmj, 1/15/96

\def\@eqnhook{%
%%      \abovedisplayskip\topsep
%%      \ifvmode\advance\abovedisplayskip\partopsep\fi
%%      \belowdisplayskip\abovedisplayskip
    \belowdisplayshortskip\belowdisplayskip
    \abovedisplayshortskip\abovedisplayskip
}

%% I removed the two occurences of \hskip 2\arraycolsep and changed
%% the template for the second column to ${{}##{}}$.  This restores
%% the proper amount of space around the second column of the
%% eqnarray.  I also introduced the parameters \@eqnmar and \@eqnhook
%% to provide support for the flush left equation style.

\def\eqnarray{%
    \stepcounter{equation}%
    \def\@currentlabel{\p@equation\theequation}%
    \global\@eqnswtrue
    \m@th
    \global\@eqcnt\z@
    \tabskip\@eqnmar
    \let\\\@eqncr
    \@eqnhook
    $$\everycr{}%
    \halign to\displaywidth\bgroup
        \hskip\@centering
        $\displaystyle
        \tabskip\z@skip
        {##}$%
        \@eqnsel
       &\global\@eqcnt\@ne
        \hfil${{}##{}}$\hfil
       &\global\@eqcnt\tw@
        $\displaystyle{##}$%
        \hfil
        \tabskip\@centering
       &\global\@eqcnt\thr@@
        \hb@xt@\z@\bgroup\hss##\egroup
        \tabskip\z@skip
    \cr
}

\def\endeqnarray{%
        \@@eqncr
    \egroup
    \global\advance\c@equation\m@ne
    $$% $$ MATCHING
    \global\@ignoretrue 
}

%% Since we've removed the \arraycolsep's from \eqnarray, we have to
%% redefine \lefteqn to put that space back in.  It seems unlikely
%% that \arraycolsep is really what should be used here, but the
%% following definition maintains compatibility with the old
%% definition of eqnarray.

\def\lefteqn#1{\hbox to 4\arraycolsep{$\displaystyle #1$\hss}}

% Hack to fix TeX putting in delimiters that are too large. 
% Default \delimiterfactor=901.

\delimiterfactor=801

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%                                                                    %%
%%                        LIST ENVIRONMENTS                           %%
%%                                                                    %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% new environment for SICP.  Like itemize but doesn't indent

\def\bulletlist{\list{$\bullet\ $}{\itemindent 0pt}}
\let\endbulletlist\endlist

\def\descriptionlabel#1{\hspace\labelsep \bf #1}

\def\description{%
    \list{}{%
        \labelwidth\z@
        \itemindent-\leftmargin
        \let\makelabel\descriptionlabel
    }%
}

\let\enddescription\endlist

%%  This is perverse. -- dmj

\newbox\testnum
\setbox\testnum\hbox{\normalfont 1.}

\def\labelenumi{\hbox to1pc{\hbox to\wd\testnum{\hss\arabic{enumi}.}\hfill}}

\def\theenumi{\arabic{enumi}} 

\def\labelenumii{\llap{\hbox to\wd\testnum{\arabic{enumii}.\hfill}}}

\def\theenumii{\alph{enumii}}
\def\p@enumii{\theenumi}
\def\labelenumiii{\roman{enumiii}.}
\def\theenumiii{\roman{enumiii}}
\def\p@enumiii{\theenumi(\theenumii)}

%\def\labelenumiv{\Alph{enumiv}.}
%\def\theenumiv{\Alph{enumiv}} 
%\def\p@enumiv{\p@enumiii\theenumiii}

\def\labelitemi{\raise.5ex\hbox to1pc{$\scriptscriptstyle\bullet$\hfill}}
\def\labelitemii{\raise.5ex
\llap{\hbox to 1pc{$\scriptscriptstyle\bullet$\hss}}}
\def\labelitemiii{$\ast$}

%\def\labelitemiv{$\cdot$}

\def\verse{\let\\=\@centercr 
 \list{}{\itemsep\z@ \itemindent -1.5em\listparindent \itemindent 
 \rightmargin\leftmargin\advance\leftmargin 1.5em}\item[]}
\let\endverse\endlist

\def\quotation{\list{}{%
    \listparindent \z@
    \itemindent\listparindent
    \rightmargin=1pc
    \leftmargin=\rightmargin
    \parsep \z@skip % 0pt plus 1pt
    }\item[]}

\let\endquotation=\endlist

\def\quote{\list{}{\rightmargin=1pc \leftmargin=1pc}\item[]}
\let\endquote=\endlist

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%                                                                    %%
%%                      THE TABLE OF CONTENTS                         %%
%%                                                                    %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%\def\@pnumwidth{1.55em}
\def\@pnumwidth{1.6em}
\def\@tocrmarg {\@pnumwidth plus 1fil}

%%  \def\@dotsep{4.5}

\setcounter{tocdepth}{2}

%%  Cleaned this up some; mainly ripped out the more obvious
%%  stupidities (however, failure to have deleted any bit of the
%%  following code should in no way be construed as an endorsement of
%%  it).  -- dmj

\def\tableofcontents{%
    \@restonecolfalse
    \if@twocolumn \@restonecoltrue \onecolumn \fi
    \newpage
    \thispagestyle{empty}%
    \contentsheading{Contents}%
%%    \markboth{Contents}{Contents}%
%% following experiments: first works at cost of large empty space at start
%%  second doesn't work
%%    \vskip 3pc%3/5/96 jems: experiment in repaginating contents
%%    \vskip -4pc%3/5/96 jems: experiment in repaginating contents
    \@starttoc{toc}%
    \if@restonecol\twocolumn\fi
    \newpage
    \markboth{}{}%
}
 
%%  This is just like LaTeX's standard \@dottedtocline, but without
%%  the dots. --dmj

\def\@tocline#1#2#3#4#5{%
    \ifnum #1>\c@tocdepth \else
        \vskip \z@skip % plus.2\p@
        \begingroup
            \leftskip #2\relax
            \rightskip \@tocrmarg
            \parfillskip -\rightskip
            \parindent #2\relax
            \@afterindenttrue
            \interlinepenalty\@M
            \leavevmode
            \@tempdima #3\relax
            \advance\leftskip \@tempdima
            \null
            \hskip -\leftskip
            #4\nobreak\hfill \nobreak
            \hbox to\@pnumwidth{\hfil\reset@font\rm #5}%
            \par
        \endgroup
    \fi
}

%%  didn't customize this, since it's not needed for the current book.
%%  --dmj

%%  \def\l@part#1#2{%
%%      \addpenalty{-\@highpenalty}%
%%      \addvspace{11pt}%
%%      \begingroup
%%          \@tempdima 3em
%%          \parindent \z@
%%          \rightskip \@pnumwidth
%%          \parfillskip -\@pnumwidth
%%          {\leavevmode #1\hfil \hbox to\@pnumwidth{\hss #2}}%
%%          \par
%%          \vrule width0pt depth6pt
%%          \nobreak
%%      \endgroup
%%  }

%%  This seems pretty reasonable, so the only changes I made were to
%%  remove the page number from the bold face type and adjusted the
%%  value of \@tempdima to match the appropriate parameter in
%%  \l@section (see below).  (Actually, this should probably be
%%  redefined using \@tocline, but I won't bother.) -- dmj

\def\l@chapter#1#2{%
    \pagebreak[3]%
    \vskip 1.0em % plus 1pt
    \@tempdima 1.6em
    \begingroup
        \parindent \z@
        \rightskip \@pnumwidth
        \parfillskip -\@pnumwidth
        \bfseries
        {\leavevmode#1}\hfil \hbox to\@pnumwidth{\hss#2}%
        \par
    \endgroup
}

%%  We'll put an extra 6pt above sections, and an extra 2pt after
%%  them.  Because \addvspace is magical, the 2pt will only show up if
%%  the section is followed immediately by a subsection; if it's
%%  followed by another section, the spacing between them will be 6pt,
%%  not 8. -- dmj

\def\l@section#1#2{%
    \addvspace{6pt}%
%%  
%%  The arguments to @tocline are as follows:
%%      1     : the level of the section
%%      1.6em : the amount by which the section number should be
%%              indented from the left margin
%%      2.6em : The width of the box the section number is put in.
%%              Put another way, it's the indentation of the section
%%              title from the left margin.  This should match the
%%              value of \@tempdima set in \l@chapter.
%%      #1    : The section title (including the section number
%%              embedded in a \numberline command).
%%      #2    : the page number
%%  
%%  These last two parameters are just the last two arguments of
%%  \contentsline in the .toc file. -- dmj
%%  
%%    \@tocline{1}{1.6em}{2.6em}{#1}{#2}%
%%  Changed spacing in TOC
    \@tocline{1}{1.6em}{3em}{#1}{#2}%
%%      \addvspace{2pt}%
}

%%  We want the subsection numbers to line up with the section titles,
%%  so we sent the indentation parameter to be equal to the width of
%%  the section number. -- dmj

\def\l@subsection{%
%%    \@tocline{2}{1.6em}{2.6em}%
    \@tocline{2}{1.6em}{3em}%
}

%%  I won't bother with l@subsubsection, l@paragraph and
%%  l@subparagraph, since they aren't used in the current book. -- dmj

\def\l@subsubsection{\@tocline{3}{7.8em}{4.1em}}

\def\l@subsubsubsection{\@tocline{4}{7.8em}{4.1em}}

\def\l@paragraph{\@tocline{5}{10em}{5em}}
\def\l@subparagraph{\@tocline{6}{12em}{6em}}
 
%%  Added for things like the Bibliography.  Essentially the same as a
%%  section, but without a section number. -- dmj

\def\l@fmatter{%
    \addvspace{6pt}%
    \@tocline{1}{1.6em}{0em}%
}

%%  These could also be cleaned up, but I won't unless there's a need
%%  for it. -- dmj

%%  \def\listoffigures{%
%%  \@restonecolfalse
%%  \if@twocolumn\@restonecoltrue\onecolumn
%%  \fi
%%  \vbox to0pt%
%%  {\vss\vbox to 5.6pc% was 5.6pc WYN
%%  {\hbox{\chapheadfont List of Figures}\vfill}}%
%%  \thispagestyle{empty}%
%%  \vglue-22pt
%%  \addcontentsline{toc}{matter}{List of Figures}%
%%  \markboth{List of Figures}{List of Figures}%
%%  \thispagestyle{empty}%
%%  \let\contentsline=\lofcontentsline
%%  \@starttoc{lof}%
%%  \if@restonecol\twocolumn
%%  \fi
%%  \vfill\eject\markboth{}{}}
%%   
%%  \def\l@figure{\@tocline{1}{1.5em}{2.3em}}
%%   
%%  \def\listoftables{%
%%  \@restonecolfalse
%%  \if@twocolumn\@restonecoltrue\onecolumn
%%  \fi
%%  \vbox to0pt%
%%  {\vss\vbox to 5.6pc% was 5.6pc WYN
%%  {\hbox{\chapheadfont List of Tables}\vfill}}%
%%  \vglue-22pt
%%  \markboth{List of Tables}{List of Tables}%
%%  \addcontentsline{toc}{matter}{List of Tables}%
%%  \let\contentsline=\lofcontentsline
%%  \thispagestyle{empty}%
%%  \@starttoc{lot}\if@restonecol\twocolumn
%%  \fi
%%  \vfill\eject\markboth{}{}}
%%   
%%  \let\l@table\l@figure

\def\references{%
    \small
    \parskip 6\p@
    \parindent\z@skip
%%  
%%  If you uncomment \sloppy, TeX can typeset the bibliography without
%%  any overfull boxes, but it might be better to only enable \sloppy
%%  for the specific items that need it. -- dmj, 2/22/96
%%  
%%    \sloppy
%%    \sfcode`\.=1000\relax
}

\let\endreferences\relax
 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%                                                                    %%
%%                             INDEXING                               %%
%%                                                                    %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newif\if@restonecol

\def\indexname{Index}

%% 12/3/00 Julie: Added cleardoublepage here for SICM
\def\@theindex{%
    \cleardoublepage
    \columnseprule \z@
    \columnsep 18pt
%%  
%%  Reverted back to \twocolumn because multicols doesn't play nicely
%%  with \pagebreak, \nopagebreak and \longpage. -- dmj, 4/15/96
%%  
    \twocolumn[\chapter*{Index}

%% 12/8/00 Julie: Added index entry here for SICM
\ind{Zero-based indexing}

\begin{epigraph}
Any inaccuracies in this index may be explained by the fact that it
has been prepared with the help of a computer.

\attribution{%$
\ind{Knuth, Donald E.}%
Donald E. Knuth,
{\em Fundamental Algorithms} (Volume 1 of
{\em The Art of\/ Computer Programming})}
\end{epigraph}

\begin{small}
Page numbers for Scheme procedure definitions are in italics.\\
Page numbers followed by {\em n} indicate footnotes.
\end{small}
\vskip20pt
]
%%
%%  Added \fmattermark here since it doesn't seem to be migrating out
%%  from inside the \twocolumn command properly.  Also deleted the
%%  extra \addtocontents that used to be here and was causing the
%%  index to appear twice in the table of contents (strange that the
%%  \write migrated outside of the \twocolumn, but the \mark didn't; I
%%  should probably take a closer look at that.).
%%  -- dmj, 3/13/96 
%%
%%  1/24/01 Julie: David's comment above says that he added \fmattermark
%%    (here?), but it's nowhere to be found, and there are in fact no
%%    running heads in the index.  I'll try adding it, since running
%%    heads have been requested by the Press.
    \fmattermark{Index}
    \parindent\z@
    \parskip\z@skip % \z@ plus .3pt\relax
    \let\item\@idxitem
    \small
%%  
%%  This allows hyphenation of the penultimate line of a paragraph
%%  (i.e., index entry). -- dmj
%%  
%%   Attempt to get hyphenation just the way we want it...
%%
    \finalhyphendemerits=0
%%  
%%  Use the hyphenatable verstion of cmtt in the index. -- dmj,
%%  3/13/96
%%  
    \def\ttdefault{cmtt2}%
    \sloppy
    \raggedright
}

\def\end@theindex{%
    \onecolumn
}

%%  This isn't pretty, but it's necessary to fool index.sty. -- dmj,
%%  4/11/96

\newenvironment{theindex}{}{}

\AtBeginDocument{\let\theindex\@theindex\let\endtheindex\end@theindex}

%%  Added @subitem switch so we can tell if we're in a primary entry
%%  or a secondary entry. -- dmj, 3/11/96

\newif\if@subitem

\def\@idxitem{\par\@subitemfalse\hangindent 12pt}
\def\subitem{\par\@subitemtrue\hangindent 12pt \hspace*{6pt}}
\def\subsubitem{\par\@subitemtrue\hangindent 12pt \hspace*{10pt}}

\def\indexspace{\par \vskip 9pt \relax}

%%  THE SPECIFICATION:
%%
%%  Ok, here's the game plan.  We need the following 5 indexing
%%  commands:
%%  
%%      \ind         : ordinary index entry
%%
%%      \indcode     : the indexed item is in \tt font
%%
%%      \indprim     : same as \indcode except that the \tt indexed
%%                     item is followed by '(primitive procedure)' in
%%                     the ordinary font
%%
%%      \indsf       : same as indprim except has '(special form)'
%%                     instead of '(primitive procedure)'
%%  
%%      \indcodeplus : same as indcode except that the \tt indexed
%%                     item is followed by additional supplied text in
%%                     ordinary font
%%  
%%  Each of the first 4 commands takes a single mandatory argument,
%%  namely the text being index.  \indcodeplus takes two mandatory
%%  arguments, the first of which is the text to be indexed and the
%%  second of which is the annotation.  All five of the commands have
%%  a *-variant, which is used to indicate that this instance of the
%%  indexed text should be treated as a definition (i.e., the
%%  accompanying page number should be in italics).  All five also
%%  take an optional final argument, which is text to be used as a
%%  subentry of the main argument.
%%  
%%  In addition, we provide the following syntactic sugar for 'see'
%%  and 'see also' cross-references:
%%  
%%      \indsee{main-entry}[optional-subentry]{thing-to-see}
%%      \indseealso{main-entry}[optional-subentry]{thing-to-see}
%%  
%%  Cross references will be formatted slightly differently in
%%  subitems than in main items, to wit:
%%  
%%      abstraction. {\it See} data abstraction
%%  
%%      data, 1, 4
%%          tagged, 135 ({\it see also} manifest type})
%%  
%%  We do no extra processing on the argument of a \ind command.  For
%%  the other index commands, we change a main argument from "foo" to
%%  "foo@\textt{foo}" to get the proper sorting behaviour.  Also, if
%%  the annotation text of an \indcodeplus command does NOT begin with
%%  a comma, we add a space at the beginning of the annotation.
%%  Otherwise, we do no additional processing of the index entries at
%%  this time.  In particular, if the way an item is sorted must be
%%  modified in a way that isn't handled by these steps, it will have
%%  to be done by hand, possibly even by dropping down into an \index
%%  command and using the raw makeindex syntax.
%%  
%%  All entries are indexed by page number, but if the indexed entry
%%  occurs inside a figure or exercise, the figure or exercise number
%%  accompanies the page number, e.g.,
%%  
%%      {\tt accumulate}, 56 (ex. 1.26)
%%      Barton, 56 (fig. 2.7)
%%  
%%  If the indexed item is inside a footnote, the page number is
%%  suffixed by an italic n:
%%  
%%      abstract models for data, 82 \emph{n}
%%  
%%  RESTRICTIONS:
%%  
%%  We'll assume that we won't need to mix a page range specifier with
%%  a definition, and that a range specifier won't be used inside a
%%  figure, footnote or exercise.  We can relax this restriction later
%%  if need be.
%%  
%%  Also, if one of these little buggers makes it's way inside a
%%  \mark, all hell will most likely break loose.  I'll fix this when
%%  I have my wits about me again.
%%  
%%  -- dmj, 3/9/96

%%  THE IMPLEMENTATION:
%%  
%%  Each index entry will consist of 5 parts:
%%  
%%      \idx@primary    : the main index entry
%%      \idx@secondary  : the (optional) subitem
%%      \idx@annotation : an optional annotation to be appended to the
%%                        main entry
%%      \idx@font       : an optional font specifier to wrap the main
%%                        entry in
%%      \idx@extra      : an optional feature to be added via the
%%                        encapsulation feature.  There are 3 cases:
%%   
%%                          (a) emph: triggered by the *-variant of one
%%                              of the index commands.  This puts the
%%                              page number in italics
%%      
%%                          (b) ftnnum, figno or excnum: used within
%%                              footnotes, figures or exercises to
%%                              modify the page number
%%  
%%                          (c) see or see*: used by \indsee and
%%                              \indseealso to implement
%%                              crossreferences
%%
%%                        Parts (a) and (b) can be combined, in which
%%                        case the emph normally produced by (a) is
%%                        turned into a *-modifier on the ftnnum,
%%                        figno or excnum modifier.

%%  We'll build upon my index package. -- dmj, 3/9/96

\RequirePackage{index}

\makeindex

%%  Much magic here.  I should probably document this code someday.
%%  -- dmj, 3/9/96

\newcommand{\indexcomma}{%
    \@ifnextchar \see{\if@subitem\space\else. \fi}{, }
}

\renewcommand{\see}{%
    \@ifstar{\index@xref{ also}}{\index@xref{}}%
}

\newcommand*{\index@xref}[3]{%
    \if@subitem
        (\emph{see#1} #2)%
    \else
        \emph{See#1} #2%
    \fi
}

\let\idx@extra\@empty

\newcommand{\ftnnum}{%
    \@ifstar{\@ftnnum\emph}{\@ftnnum\@empty}
}

\newcommand{\@ftnnum}[2]{%
    #1{#2}\,\emph{n}%
}

\def\ftn@idxnum{%
    ftnnum%
}

\newcommand{\figno}[1]{%
    \@ifstar{\@figno\emph{#1}}{\@figno\@empty{#1}}
}

\newcommand{\@figno}[3]{%
    #1{#3} (fig.\ #2)%
}

\def\fig@idxnum{%
    figno{\thefigure}%
}

\newcommand{\excnum}[1]{%
    \@ifstar{\@excnum\emph{#1}}{\@excnum\@empty{#1}}
}

\newcommand{\@excnum}[3]{%
    #1{#3} (ex.\ #2)%
}

\def\exc@idxnum{%
    excnum{\theexercise}%
}

%% Equations added by copying exercises and figures just above
%%   for SICM [Julie 11/29/00]

\newcommand{\eqnum}[1]{%
    \@ifstar{\@eqnum\emph{#1}}{\@eqnum\@empty{#1}}
}

\newcommand{\@eqnum}[3]{%
    #1{#3} (eq.\ #2)%
}

\def\eq@idxnum{%
    eqnum{\theequation}%
}



%%  Some abbreviations for the makeindex special chars, to make them
%%  easier to see them in the macros below.

\newcommand{\@actualchar}{@}
\newcommand{\@encapchar}{|}
\newcommand{\@levelchar}{}
\edef\@levelchar{\string&}

\DeclareRobustCommand{\@fullindex}[2]{%
    \@bsphack
%%  
%%  Delicate tweak here.  If a paragraph begins with an index entry,
%%  e.g., 
%%  
%%      \ind{Euclid's Algorithm}[order of growth]%
%%      The fact that the number of steps required [...]
%%  
%%  then the \ind command gets processed when TeX is still in vertical
%%  mode (since TeX doesn't enter horizontal mode until it sees the
%%  "T") and, what's worse, the \write associated with the \ind will
%%  precede the \parskip associated with the following paragraph.
%%  This means that TeX might well decide to put a page break between
%%  the index entry and the paragraph it's associated with.  (This
%%  includes the case of having an index entry as the first thing in a
%%  lisp or exercise environment.)
%%  
%%  We can't solve the problem by executing a \leavevmode, since that
%%  could cause excess space at the beginning of a lisp environment.
%%  Instead, we try to patch things up by inserting an unbreakable
%%  penalty after the index entry (see \@@ind below).  This works fine
%%  at the beginning of a lisp or exercise, but not between two
%%  regular paragraphs, since the penalty would prohibit a break
%%  between the paragraphs.  We can fix this by putting \allowbreak
%%  (i.e., a 0 penalty) before the index entry, but we have to be
%%  careful because this could allow a break even in places we don't
%%  want one (such as after a section heading if the heading is
%%  immediately followed by an index entry).
%%  
%%  So, we adopt the following heuristic: we only put in the
%%  \allowbreak if there is neither a skip nor a penalty immediately
%%  preceding the index entry.  Since we've just called \@bsphack, we
%%  can just check \@savvsk and \@savepen to see if we should allow a
%%  break.  -- dmj, 4/2/96
%%  
    \ifvmode
        \ifdim \@savvsk>\z@ \else
            \ifnum\@savepen = \z@
                \allowbreak
            \fi
        \fi
    \fi
    \def\idx@font{#1}%
    \def\idx@annotation{#2}%
    \let\idx@annote@sort\@empty
    \ifx\idx@annotation\@empty \else
        \@checkforcomma#2\@nil
        \if@tempswa
            \def\idx@annotation{#2}%
            \let\idx@annote@sort\idx@annotation
        \else
            \def\idx@annotation{\space #2}%
            \let\idx@annote@sort\idx@annotation
%%  
%%  To disable fake parens for annotations, comment out the next 4
%%  lines. -- dmj, 4/9/96
%%  
            \@checkforparen#2\@nil
            \if@tempswa\else
                \def\idx@annote@sort{\space (#2)}%
            \fi
        \fi
    \fi
    \ifx\index\@gobble
        \@addtoindexfalse
    \fi
    \begingroup
        \@sanitize
        \@ifstar{\global\@tempswatrue\@ind}{\global\@tempswafalse\@ind}
}

\def\@checkforcomma#1#2\@nil{%
    \if,#1\relax
        \@tempswatrue
    \else
        \@tempswafalse
    \fi
}

\def\@checkforparen#1#2\@nil{%
    \if(#1\relax
        \@tempswatrue
    \else
        \@tempswafalse
    \fi
}

\def\@ind#1{%
    \endgroup
    \def\idx@primary{#1}%
    \@onelevel@sanitize\idx@primary
    \begingroup
        \@ifnextchar [{\@sanitize\@@ind}{\@sanitize\@@ind[]}%
}

\def\@@ind[#1]{%
    \endgroup
    \def\idx@secondary{#1}%
    \@onelevel@sanitize\idx@secondary
    \if@addtoindex
        \if@filesw\@addtoindex\fi
        \ifproofmode\@showidx{\idx@primary:: #1}\fi
    \fi
%%  
%%  End of delicate tweak began at beginning of \@fullindex. -- dmj,
%%  4/2/96
%%  
    \ifvmode \nobreak \fi
    \@esphack
}

\newif\if@actual
\@actualfalse

\def\@addtoindex{%
    \begingroup
        \@actualfalse
        \ifx\idx@font\@empty
            \ifx\idx@annotation\@empty \else
                \ifx\idx@annote@sort\idx@annotation \else
                    \@actualtrue
                \fi
            \fi
        \else
            \@actualtrue
        \fi
        \protected@edef\@tempa{%
            \idx@primary \idx@annote@sort
            \if@actual
                \@actualchar
                \ifx\idx@font\@empty
                    \idx@primary
                \else
                    {\@nearverbatim\idx@font\idx@primary}%
                \fi
                \idx@annotation
            \fi
            \ifx\idx@secondary\@empty \else
                \@levelchar \idx@secondary
            \fi
%%  
%%  Patched to handle definitions within figures, exercises or
%%  footnotes. -- dmj, 3/11/96
%%  
            \ifx\idx@extra\@empty
                \if@tempswa \@encapchar emph\fi
            \else
                \@encapchar \idx@extra \if@tempswa *\fi
            \fi
        }%
        \protected@edef\@tempa{\noexpand\@wrindex{default}{\@tempa}}%
    \expandafter\endgroup\@tempa
}

%%  With that out of the way, \ind, \indcode, \indprim and \indsf are
%%  trivial.

\DeclareRobustCommand{\ind}{%
    \@fullindex{}{}%
}

\DeclareRobustCommand{\indcode}{%
    \@fullindex\tt{}%
}

\DeclareRobustCommand{\indprim}{%
    \@fullindex\tt{(primitive procedure)}%
}

\DeclareRobustCommand{\indsf}{%
    \@fullindex\tt{(special form)}%
}

%%  This is sort of nasty, because we essentially have to permute the
%%  optional * and the two mandatory arguments before handing them
%%  over to \@fullindex.

\DeclareRobustCommand{\indcodeplus}{%
    \begingroup
        \@sanitize
        \@ifstar{\global\@tempswatrue\@indcodeplus}
                {\global\@tempswafalse\@indcodeplus}
}

\newcommand{\@indcodeplus}[2]{%
    \if@tempswa
        \def\@tempa{\@fullindex\tt{#2}*}%
    \else
        \def\@tempa{\@fullindex\tt{#2}}%
    \fi
    \expandafter\endgroup\@tempa{#1}%
}

\newcommand{\indsee}{\idx@xref{see}}
\newcommand{\indseealso}{\idx@xref{see*}}

\DeclareRobustCommand{\idx@xref}[1]{%
    \@bsphack
%%  
%%  Note the extra layer of grouping to prevent our redefinition of
%%  \idx@extra from interfering with the prevailing definition.
%%  
    \begingroup
        \let\idx@font\@empty
        \let\idx@annotation\@empty
        \let\idx@annote@sort\@empty
        \def\idx@extra{#1}%
        \ifx\index\@gobble
            \@addtoindexfalse
        \fi
%%  
%%  Have to make sure to turn @tempswa off.
%%  
        \@tempswafalse
        \begingroup
            \@sanitize
            \@idx@xref
}

\def\@idx@xref#1{%
        \endgroup
        \def\idx@primary{#1}%
        \@onelevel@sanitize\idx@primary
        \begingroup
            \@ifnextchar [{\@sanitize\@@idx@xref}{\@sanitize\@@idx@xref[]}%
}

\def\@@idx@xref[#1]#2{%
        \endgroup
        \def\idx@secondary{#1}%
        \@onelevel@sanitize\idx@secondary
        \def\@tempa{#2}%
        \@onelevel@sanitize\@tempa
        \edef\idx@extra{\idx@extra{\@tempa}}%
        \if@addtoindex
            \if@filesw\@addtoindex\fi
        \fi
    \endgroup
    \@esphack
}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%                                                                    %%
%%                              FLOATS                                %%
%%                                                                    %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%max # floats at top/bottom of page
%max % of page occupied by floats at top/bottom
%total is max # floats on page

\setcounter{topnumber}{3}%
\def\topfraction{.8}% was .7 (11/11/95, Julie)
\setcounter{bottomnumber}{1}
\def\bottomfraction{.3}
\setcounter{totalnumber}{5}%
%min fraction of page that must be text (rest can be floats)
\def\textfraction{.1}% was .2

%floatpagefraction is min % of float page occupied by floats
% (limits blank space)
%??what's the interaction among textfraction/topfraction/floatpagefraction ?
\def\floatpagefraction{.8}% was .7 (11/11/95, Julie)
\setcounter{dbltopnumber}{2}
\def\dbltopfraction{.7}
\def\dblfloatpagefraction{.5}

\newcounter{figure}[chapter]
\def\thefigure{\thechapter.\@arabic\c@figure}
\def\fps@figure{tbp}
\def\ftype@figure{1}
\def\ext@figure{lof}

\def\fnum@figure{{\small\bf Figure \thefigure}}
\let\figcaption\caption

\def\figure{%
    \let\@lispcodesize\figurecodesize
    \let\idx@extra\fig@idxnum
    \@float{figure}%
}

\let\endfigure\end@float
\@namedef{figure*}{\@dblfloat{figure}}
\@namedef{endfigure*}{\end@dblfloat}

\newcounter{table}[chapter]
\def\thetable{\thechapter.\@arabic\c@table}
\def\fps@table{tbp}
\def\ftype@table{2}
\def\ext@table{lot}

\def\fnum@table{{\bf Table \thetable}}

\newenvironment{table}
               {\@float{table}}
               {\end@float}

\@namedef{table*}{\@dblfloat{table}}
\@namedef{endtable*}{\end@dblfloat}

%%  \@makecaption should be rewritten to be a little more intelligent.
%%  Currently, there are problems if a \caption immediately follows a
%%  lisp environment in a figure, resulting in too much vertical space
%%  separating the lisp code from the caption.  Currently we're
%%  solving this by putting in a negative \vskip, but that's
%%  tasteless. --dmj, 4/9/96

\long\def\@makecaption#1#2{%
        \vskip13pt\noindent\small\bf#1\hskip1em\rm#2%
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%                                                                    %%
%%                             TABULAR                                %%
%%                                                                    %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%  The following will suppress the space normally put in at the
%%  left and right of arrays or tabular.  With this definition, every
%%  preamble will be treated as if it began and ended with "@{}",
%%  which has the effect of suppressing the \(array|tab)colsep space
%%  normally put in.  This replaces the much more complicated code
%%  previously found here.

\let\@@mkpream\@mkpream

\def\@mkpream#1{\@@mkpream{@{}#1@{}}}

%%  I think this pretty much mimics the previous definition of the
%%  tabular environment, except that it doesn't default to ninepoint
%%  type.

\def\tabular{%
    \par
    \parindent\z@skip
    \addvspace{6\p@}%
    \let\@halignto\@empty
    \@tabular
}

%%  Modified \endtabular to keep it from forcing a paragraph break
%%  afterwards.  Hope this doesn't break anything new. -- dmj, 2/21/96

\def\endtabular{%
    \crcr\egroup\egroup $\egroup
    \@topsepadd6\p@
    \ifhmode\unskip \par\fi
    \@endparenv
}

%%  Stabular identical to tabular, but with smaller font.  This is
%%  used in chapter 5.

\def\Stabular{%
    \par
    \parindent\z@skip
    \small
    \addvspace{6\p@}%
    \let\@halignto\@empty
    \@tabular
}

\let\endStabular\endtabular

%%  Might as well redefine tabular* too, even though it's not
%%  currently used.

\@namedef{tabular*}#1{%
    \par
    \parindent\z@skip
    \addvspace{6\p@}%
    \def\@halignto{to#1}%
    \@tabular
}

\expandafter \let \csname endtabular*\endcsname = \endtabular

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%                                                                    %%
%%                          PAGE HEADINGS                             %%
%%                                                                    %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\mark{{}{}} 

\def\ps@headings{%
    \let\@mkboth\markboth
    \def\@oddhead{\vbox to0pt{%
        \vss
        \hb@xt@\textwidth{\small\it\rightmark\hfill\thepage}%
        \vskip3pt
        \hb@xt@\textwidth{\hrulefill}%
    }}%
    \def\@evenhead{\vbox to0pt{%
        \vss
        \hb@xt@\textwidth{\small\it \thepage\hfill\leftmark}%
        \vskip3pt
        \hb@xt@\textwidth{\hrulefill}%
    }}%
    \let\@oddfoot\@empty
    \let\@evenfoot\@empty
}

%% Changed 1/24/01 by Julie, to put chapter running head on odd pages
%%   until overridden by section running head.  I don't know why David
%%   explicitly put a blank running head on the right, or why no one
%%   made us fix that for SICP.  But we're fixing it now for SICM.
\def\chaptermark#1{%
%    \markboth{\@chapapp\ \thechapter\hskip10pt #1}{}%
    \markboth{\@chapapp\ \thechapter\hskip10pt #1}{\@chapapp\ \thechapter\hskip10pt #1}%
}

\def\fmattermark#1{\markboth{#1}{#1}}

\def\sectionmark#1{\markright{\thesection\hskip10pt #1}}

\def\subsectionmark#1{\markright{\thesubsection\hskip10pt #1}}

%%  Added \subsubsectionmark to put subsubsection headings in the
%%  running head.  The subsection heading will still be used if there
%%  is no subsubsection.  Remove this line to suppress subsubsections
%%  in page headings. -- dmj, 3/19/96

\def\subsubsectionmark#1{\markright{\thesubsubsection\hskip10pt #1}}

\let\subsubsubsectionmark\@gobble

\ps@headings 

\pagenumbering{arabic}
\onecolumn 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%                                                                    %%
%%                           FRONTMATTER                              %%
%%                                                                    %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def\frontmatter{%
    \pagenumbering{roman}%
}

\def\endfrontmatter{%
    \cleardoublepage
    \def\do##1{\let##1\relax}%
        \do\maketitle
        \do\@maketitle
        \do\makehalftitle
        \do\@makehalftitle
        \do\title
        \do\@title
        \do\author
        \do\@authors
        \do\forewordauthor
        \do\@forewordaut
        \do\edition
        \do\@edition
        \do\publisher
        \do\@publisher
    \pagenumbering{arabic}%
}

\def\title{\gdef\@title}
\let\@title\@empty

\def\author{\gdef\@authors}
\let\@authors\@empty

\def\forewordauthor{\gdef\@forewordauthor}
\let\@forewordauthor\@empty

\def\edition{\gdef\@edition}
\let\@edition\@empty

\def\publisher{\gdef\@publisher}
\let\@publisher\@empty

\def\maketitle{%
    \par
    \@topnum\z@ % to prevent figures from falling at the top of page 1
    \begingroup
        \@maketitle
    \endgroup
}

\def\@maketitle{%
    \cleardoublepage
%    \setcounter{page}{0}%
    \thispagestyle{empty}% local to group
    \begingroup
        \parindent\z@skip
        \raggedright
        \begingroup
            \LARGE\bf
            \@title\par
        \endgroup
        \addvspace{3pc}%
        \ifx\@edition\@empty\else
            {\Large\@edition}\par
        \fi
        \addvspace{7pc}%
        {\large \@authors\par}%
%        \addvspace{1pc}
%        {\large foreword by \@forewordauthor\par}%
        \vfill
        {\normalsize\@publisher\par}% removed \copyright (jems 2/23/96)
    \endgroup
}

\def\makehalftitle{%
    \par
    \@topnum\z@ % to prevent figures from falling at the top of page 1
    \begingroup
        \@makehalftitle
    \endgroup
}

\def\@makehalftitle{%
    \cleardoublepage
    \thispagestyle{empty}% local to group
    \begingroup
        \parindent\z@skip
        \raggedright
        \begingroup
            \LARGE\bf
            \@title\par
        \endgroup
    \endgroup
}

\def\titlepage{%
    \newpage
    \thispagestyle{empty}%
    \c@page\z@
    \raggedright
    \parindent\z@skip
}

\let\endtitlepage\newpage

\def\halftitlepage{%
    \newpage
    \thispagestyle{empty}%
    \raggedright
    \parindent\z@skip
}

\let\endhalftitlepage\newpage


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%                                                                    %%
%%                            CROPMARKS                               %%
%%                                                                    %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%  The following code is adopted from Victor Eijkhout's very clever
%%  cropmark.tex, with a few changes as marked below.  (Most likely,
%%  these changes are only necessary because there's something weird
%%  about the way our \textwidth and margins are set up, but it's too
%%  late to play around with those.) -- dmj, 4/8/96

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Cropmark.tex
%
% This will put crop marks on everythings that's \shipout'ed.
% It will work with any format, since it relies on redefinition
% of \shipout. Exception: if you declare \output{} you will
% not get crop marks.
%
% Cut along the center of the rules to get exactly the shipped
% out box. To get padding around this box, use the parameters below.
%
% User adjustable parameters:
% \croplength    length of the crop rules
% \cropwidth     width of the crop rules
% \cropsep       separation between rule and page box
% \croppadtop    padding in case page box looks bigger than it is
% \croppadbot    (for instance with plain TeX head/footline)
% \croppadlr
%
% Date: 17 March 1992
%
% Author:
%    Victor Eijkhout
%    Department of Computer Science
%    University Tennessee at Knoxville
%    104 Ayres Hall
%    Knoxville, TN 37996
%    USA
%
%    eijkhout@cs.utk.edu
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% save the old \shipout command

\let\xshipout\shipout

% define a new one: investigate what's being shipped

%%  Changed name from \shipout to \cropmark@shipout so we can turn
%%  cropmarks off at will (see definition of cropmarks option near
%%  beginning of file).  -- dmj, 4/8/96

\def\cropmark@shipout{\futurelet\SomeBox\yshipout}

% if its a box register, do postprocessing with \afterassignment,
% otherwise do \afterassignment which will do \aftergroup
\def\yshipout
   {\ifx\SomeBox\box        \let\next\shipAfterRegister 
    \else \ifx\SomeBox\copy \let\next\shipAfterRegister
    \else                   \let\next\shipAfterBox \fi\fi
    \afterassignment\next\setbox0=
    }
\def\shipAfterBox{\aftergroup\shipAfterRegister}

% now we have whatever is being shipped in box0,
% so we can insert crop marks
\newdimen\croplength \croplength=20pt

%%  Changed \cropsep from 10pt to 5pt. -- dmj, 4/8/96

\newdimen\cropsep \cropsep=5pt %10pt  

%%  Changed \cropwidth from 2pt to .5pt. -- dmj, 4/8/96

\newdimen\cropwidth \cropwidth=.5pt % 2pt

%%  Changed \cropadtop from 0pt to -.5pc. -- dmj, 4/8/96

\newdimen\croppadtop \croppadtop=-.5pc

\newdimen\croppadbot \croppadbot=0pt

%%  Changed \cropadlr from 0pt to -1pc. -- dmj, 4/8/96

\newdimen\croppadlr  \croppadlr=-1pc %0pt

%%  Added \croppagewidth as horizontal distance between cropmarks. --
%%  dmj, 4/8/96

\newdimen\croppagewidth
\croppagewidth\textwidth
\advance\croppagewidth by 12pc

\def\crophrule{\vrule height\cropwidth depth0pt width\croplength}
\def\cropvrule{\vrule width\cropwidth depth0pt height\croplength}

\def\shipAfterRegister
   {\setbox0\vbox
       {\offinterlineskip
        \dimen0\cropsep\advance\dimen0\croplength
%%  
%%  Changed width from \wd0 to \croppagewidth. -- dmj, 4/8/96
%%  
        \setbox2\hbox to \croppagewidth %\wd0
               {\kern-\croppadlr\kern-.5\cropwidth
                \cropvrule\hfil\cropvrule
                \kern-.5\cropwidth\kern-\croppadlr}
%%  
%%  Changed width from \wd0 to \croppagewidth. -- dmj, 4/8/96
%%  
        \setbox4\hbox to \croppagewidth %\wd0
                    {\llap{\crophrule\kern\cropsep\kern\croppadlr}
                              \hfil
                              \rlap{\kern\croppadlr\kern\cropsep\crophrule}}
        % go a bit up, put vertical rules, put horizontal rules
        \kern-\dimen0
        \copy2
        \kern\cropsep\kern-.5\cropwidth
        \copy4
        \kern-.5\cropwidth
        % padding
        \kern\croppadtop
        % the box to be shipped
        \box0
%%  
%%  No registration marks at bottom of page.
%%  
%%          % padding
%%          \kern\croppadbot
%%          % and now the top in reverse
%%          \kern-.5\cropwidth
%%          \box4
%%          \kern-.5\cropwidth\kern\cropsep
%%          \box2
    }
    \xshipout\box0\relax}

%%  end of code from cropmark.tex

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%                                                                    %%
%%                            FOOTNOTES                               %%
%%                                                                    %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def\footnoterule{%
    \kern-3\p@ 
    \hrule width\textwidth height\hruleheight   % .1pt
    \kern 2.6\p@
}

\@addtoreset{footnote}{chapter} 

%%  Modification of \footnote to allow catcode changes inside
%%  footnotes, so things like \verb and the lisp enveironment work
%%  (cf. plain.tex)

\def\@footnotetext{%
    \insert\footins\bgroup
        \reset@font\footnotesize
        \interlinepenalty\interfootnotelinepenalty
        \splittopskip\footnotesep
        \splitmaxdepth \dp\strutbox
        \floatingpenalty \@MM
        \hsize\columnwidth
        \@parboxrestore
        \protected@edef\@currentlabel{%
            \csname p@footnote\endcsname\@thefnmark
        }%
        \color@begingroup
            \let\idx@extra\ftn@idxnum
            \@makefntext
            \rule\z@\footnotesep\ignorespaces
            \bgroup\aftergroup\@foot\let\next
}

\def\@foot{%
            \@finalstrut\strutbox
        \color@endgroup
    \egroup
}

%%  Here is the par indentation for multiple-par footnotes

\long\def\@makefntext{%
    \parindent 1em
    \noindent\@makefnmark
}

%%  The previous redefinitions of \ref and \pageref were identical to
%%  the standard definitions except that they put the reference
%%  numbers in an \hbox to keep it from being broken across lines.
%%  I'm not sure if this is still relevant, but here's the LaTeX2e
%%  version. -- dmj, 2/19/96

\def\@setref#1#2#3{%
    \ifx#1\relax
        \protect\G@refundefinedtrue
        \nfss@text{\reset@font\bfseries ??}%
        \@latex@warning{Reference `#3' on page \thepage\space
                undefined}%
    \else
        \mbox{\expandafter#2#1\null}%
  \fi
}

\def\today{\ifcase\month\or
 January\or February\or March\or April\or May\or June\or
 July\or August\or September\or October\or November\or December\fi
 \space\number\day, \number\year}

\widowpenalty=10000

\clubpenalty=10000

%\newcommand\appendix{\par
%  \setcounter{chapter}{0}%
%  \setcounter{section}{0}%
%  \renewcommand\@chapapp{\appendixname}%
%  \renewcommand\thechapter{\@Alph\c@chapter}}

\newcommand\appendix{%
    \par
    \setcounter{chapter}{0}%
    \setcounter{section}{0}%
    \setcounter{secnumdepth}{-2}
    \renewcommand\@chapapp{Appendix}%
    \renewcommand\thechapter{\@Alph\c@chapter}%
}

\newcommand\appendixname{Appendix}


\endinput

