%^^A* copyright
% \iffalse
% $Id: monster.dtx,v 1.39 1995/03/01 21:54:00 swift Exp $
%
%   This program is part of the Frankenstein package for LaTeX2e.
%
%   Copyright (C) 1995 Matt Swift <swift@bu.edu>
%
%   This program is free software; you can redistribute it and/or modify
%   it under the terms of the GNU General Public License as published by
%   the Free Software Foundation; either version 2 of the License, or
%   (at your option) any later version.
%
%   This program is distributed in the hope that it will be useful,
%   but WITHOUT ANY WARRANTY; without even the implied warranty of
%   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%   GNU General Public License for more details.
%
%   You should have received a copy of the GNU General Public License
%   along with this program; if not, write to the Free Software
%   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
%
%^^A* driver
%<*driver>
\documentclass{ltxdoc}
\usepackage{verbatim}
\usepackage{monster}
\date{\filedate}
\author{Matt Swift \texttt{<swift@bu.edu>}}
\lastchange{\fileversion}
\CodelineIndex
% \DescribeOnly % uncomment to make user-only documentation
\EnableCrossrefs
% \DisableCrossrefs % uncomment to skip making the index
\begin{document}
\newcommand\stack[2]{{\ttfamily #1 $\rightarrow$ #2}}
\newenvironment{bibfunction}
    {\begin{environment}}
  {\end{environment}}
\newtextmacro[\smaller\ttfamily]{\monster}{Frankenstein}
\newtextmacro[\ttfamily]{\bigmonster}{Frankenstein}
\begin{story}{\larger[2] \bigmonster}
             [\larger version \Frankenversion]
\makeatletter
\renewcommand\partname{Part}
\makeatother
% The following are also from manmac.tex, with names changed.  This document
% is supposed to be 10pt size; otherwise manfnt will have to be loaded at
% another size, in order to be able to define a perfect \MFeleven.
\newcommand\MFten{{\manual META}\-{\manual FONT}} 
\newlet\MF\MFten
% \newcommand\MFnine{{\manual hijk}\-{\manual lmnj}}
% \newcommand\MFeight{{\manual opqr}\-{\manual stuq}}
% \newcommand\MFtenslanted{{\manual 89:;<=>:}}
% I have altered the following to use \meta. 
\renewcommand\marg[1]
  {{\ttfamily\char`\{\meta{#1}\char`\}}}
\renewcommand\oarg[1]
  {{\ttfamily[\meta{#1}]}}
\DocInput{monster.dtx}
\end{story}
\appendix
\clearpage
\bibliographystyle{achicago}
\bibliography{monster}
\PrintIndex
\end{document}
%</driver>
% \fi
%^^A* abstract
% \begin{abstract}
% The \monster package provides macros useful for typesetting verse, prose,
% drama, and critical papers that cite them.
%
% Many of its features are also of general interest to \LaTeX{} users and
% programmers.
%
% A document prepared with the \monster package for \LaTeXe{} comprises one or
% more units of text called \textsl{bits} each marked as belonging to one of a
% variety of available \textsl{bit style}s.  The master document typesets each
% bit according to its style, and assembles them into an organic whole
% according to a \textsl{copy style} that controls global formatting---the
% gross anatomy.  The bits can reside in the master document itself, be
% included in the standard ways from data files (dead files), or be pilfered
% with new commands from files that stand on their own as source files (live
% files).
%
% \monster is in \emph{alpha} release stage.  The four parts provided as
% independent packages are stable.  But please consider the unfinished staet of
% the whole when you decide to use it, and when you give me feedback on the
% package. \monster in its present state of development is sufficient to set my
% doctoral thesis, but it has many features that I am not actively using now,
% and that may be broken.  Many intended features have not been written yet at
% all.
% \end{abstract}
% \tableofcontents
% \clearpage
% \part{User Documentation}
% \section{The anatomy of \bigmonster}
% \begin{tabular}{ll}
%   \texttt{story}  &  longer prose \\
%   \texttt{prose}  &  a short prose unit \\
%   \texttt{poem}   &  verse  \\
%   \texttt{script} &  a stage production script\\
%   \texttt{play}   &  a typeset play\\
%   \texttt{epistle}&  like the standard letter environment\\
% \end{tabular}
%
% Bits have types to let copy styles know what to do with them. 
%
% Copy styles control the following things:  
% \begin{description}
% \item[document initial formatting]
% \item[bit initial formatting]  
% \item[bit terminal formatting] 
% \item[running headers and footers] 
% \item[interbit formatting]
% \end{description}
%
% bits are parallel.  unlike book, where you have imparallel stuff. 
%
% Bit types determine the formatting of the bits themselves, not the document
% that contains them.  To a copy style, a bit should just be a bit, which
% supplies a fixed number of pieces of information.  If the pieces of
% information are left blank because they don't apply to that particular bit
% type or individual bit, the copy style should handle the situation
% gracefully.
%
% When a bit begins, it sets the appropriate variables, and calls |\MakeCover|
% if it is the first bit in the document.  Then the bit calls |\MakeTitle|.
% |\MakeTitle|'s actions depend both on the copy style and on the present bit
% style.
%
% Logically, the three standard classes |book|, |report|, and |letter| ought to
% be options of a single class.  With a few exceptions like the |\chapter|
% sectioning command, the same source file can be set with all three
% successfully, and the only changes are in the global look of the document.
%
% The standard classes also have confusing names which suggest that they
% describe the contents, rather than a certain manner of global formatting.  It
% is not appropriate to describe them by a name that is a guess as to what kind
% of material they will be suitable for.
%
% A better system would add another layer of abstraction underneath a single
% standard class.  Let me refer to this imaginary class, which would contain
% only those definitions common to the three standard classes, as |std.cls|.
%
% The task would then be to identify all the independent options to |std.cls|,
% add some new ones as described below, and then assemble a few good
% combinations of options. This would the disadvantage of having two differenet
% abstract kinds of options to the |\documentclass| command.  But this seems
% acceptable if an good naming system is used that distinguishes on/of switches
% from options which represent a collection of on/off switches. 
%
% While most global options would be set at the beginning and never changed,
% some can sensibly be changed later in the document.  When this is the case,
% user commands that mimic the switch options can be defined, for use on
% special occasions when an existing copy style (ie collection of options to
% std.cls, or bit style won't do the trick.  For example, copy style A usually
% handles bit type B by doing C and D; but for a certain special case of bit
% type B, doing C is not appropriate, so an overriding command is issued.  For
% example |\anonymous| might be used to inhibit a copystyle from automatically
% appending the author's name to the end of a certain bit.
%
% Now I will make a case for another level of abstraction, which actually does
% identify the \emph{type} of text that is being set.  We want to consider all
% text to be set as belonging to exactly one ``bit'' of text, and identify each
% bit with a bit type (better word than bit style!).  We can do this by
% enclosing all text inside exactly one environment named after its bit type.
% Bits will have a communication protocol through which they supply information
% to the higher levels of macros.  Information like titles, and setting marks.
% The copy styles determine what to do with this information, and in fact what
% to do with the bit itself.  Once it is in an environment of its own, a copy
% style has a lot of control over what to do with it.  
%
% This is how it is now. 
%\begin{verbatim}
%                         The LaTeX2e kernel
%
%                      the standard class (imaginary)
%                 (all formatting common to the three standard ones)
%
%                           Frankenstein's extensions
%                       (dialogue, epistle, lips, bits)
%
%                     book      report       article
%                (font size, general sectioning, margins)
%
%                   blank   comments  submission  null
%              (what comes before, between, and after bits)
%                 (what comes at top and bottom of pages)
%
%                poem play script story letter prose
%                      (internal sectioning)            
%                           (titling)
%                      (new internal macros)                      
%\end{verbatim}
%
% Page styles do not deserve their own level in this hierarchy; pagestyles
% should be set by the copy style.    Page styles involve the apearance of the
% headers; and they depend upon the sectioning commands to provide the
% information.  In general, this mediation of what to do with information
% within the bit is handled by a copy style. 
%
% The copy style extracts from the bits all the information it needs to set.
% The definition of a bit style will therefore have a convention to set certain
% values.  
%
% The copy style level and the book/report/article level overlap are really
% roughly at the same level, and do not interfere with each other.
% |\maketitle| is one example of a conflict, and this should be disabled
% outside a the null bit style, as should the commands which pass information
% to |\maketitle| (except as they are redefined by \monster of course).  Where
% else is there a conflict?  These informations should really go inside the bit
% environment, and not be either in the preamble or simply in the document
% environment but not a bit environment (which in this system are theoretically
% identical locations, since all text inside the document environment should be
% enclosed in a bit environment.  They are information which should be exported
% whenever the bit is exported; they are part of the bit itself. 
% This includes all new macros definitions!  There is a grey area
% in package use.  There are two distinctions to be made: is the package
% required to set the macros in the bit, assuming the use of the 2e kernel (and
% the use of std.cls???), or does it only make a cosmetic alteration. Second,
% are the changes to be exported or not?  Exporteds are still overridable. 
%
% A file set without declaring any bits should be thought of as using a
% nameless null bit style that does nothing, just sets its contents in the
% standard \LaTeX{} way.  This works just fine, of course, and all the features
% of the features of \monster except some of those invovling bits are available
% to you, like end-signs at the end of a bit, and so on.  For this reason, you
% are encouraged to use the provided real null bit style, |nullbit|.  By
% declaring your text as a bit with a bitstyle of |nullbit|, you register the
% bit abstractly with the rest of the \monster package, and this might be
% useful to you in the future. Of course, you can always just add the
% declaration when you need it.
%
% Generic sectioning commands; including bits. 
% \section{bit styles}
%     \subsection{\texttt{story}}
%     \subsection{\texttt{poem}}
%     \subsection{\texttt{script} and \texttt{play}}
%
% Explain that we allow ``continued'' on top of right-hand pages with |twoside|
% because |script| really is not intended for |twoside|. 
%
% Example:  
% \begin{verbatim}
% \character{ap}{Appleby}{Appleby, his father}
%       \ap
%       \apsays
% \end{verbatim}
%     \subsection{epistle}
%     \subsection{prose}
% The |prose| bit style is sort of a bastard thing, like a titled block quote,
% but I have found it useful as an alternative to the standard sectioning
% commands.  It is an environment, and therefore under more abstract control
% than a section. 
% \section{Copy styles}
%     \subsection{\texttt{standard}}
%     \subsection{\texttt{comments}}
%     \subsection{\texttt{blank}}
%     \subsection{\texttt{submission}}
%     \subsection{\texttt{coverpage}}
% \section{New Environments}
% The bit styles are for independent units of text.  They can be nested, and it
% makes sense to do this when the included bit is independent.  You might want
% to cite an entire poem, with its title and so on.
%     \subsection{epigraphs}
% \section{Ellipses}
% \DescribeMacro{\lips}
% The macro |\lips| should be used for all text ellipses, that is, those that
% are not part of a mathematical expression.  
%
% Here are examples of correct usage: 
% \begin{verbatim*}
%   Hello\lips. And
%   \par \lips and
%   Hello \lips and
%   Hello!\lips And    % (also `?', `.', `:', `,' and `:')
%   Hello\lips and
%   Hello! \lips And   % (also `?', `.', `:', `,' and `:')
%   Hello \lips and
%  \end{verbatim*}
% In the first two examples, |\ldots| would do exactly the same thing as
% |\lips|.  In the rest of the examples, |\lips| is different and superior than
% |\ldots| or |\ldots| plus any simple fix like \verb*"\ ".  My model as usual
% has been \emph{The Chicago Manual} \cite{chicago}.
%
% \section{Citations}
%
% The citation macros of the \monster package owe much to other people.
% Names and more infomation are in the implementation section. 
%
% To do citations, the \monster package alters certain definitions in the
% \LaTeXe{} format in a way that does not simply \emph{extend} them, but alters
% them.  When a package makes extensions, the only potential for trouble comes
% from other packages which try to extend the same definitions.  In the case of
% citations, even packages which try to use the definitions in the normal way
% \emph{might} cause problems.
%
% This behavior certainly should be improved, and it is a priority for future
% versions.  It would be helpful if users would let the author know if they 
% encounter any difficulties.   
%
%
%   Citation format: 
%     	      (author-last-name year)
%             (author-last-name and author-last-name year)
%             (author-last-name et al. year)
%             (author-last-name)
%             author-last-name
%             author-last-name (year)
%             (author-last-name and author-last-name)
%             (author-last-name et al.)
%             (year) or (year,year)
%             year or year,year
%
%   Reference list ordering: alphabetical by author or whatever passes
%    for author in the absence of one.
%
% This BibTeX style has support for abbreviated author lists and for
%    year-only citations.  This is done by having the citations
%    actually look like
%
%    |\citeauthoryear{full-author-info}{abbrev-author-info}{year}|
%
% The LaTeX style has to have the following (or similar)
%
% -------------------------------------------------------------------------
%
% The ``chicago'' BibTeX bibliography style creates citations with labels:
% \begin{quote}
%       |\citeauthoryear{author-info}{abbrev. author-info}{year}|
% \end{quote}
%
% These labels are processed by the following \LaTeX{} commands:
%\begin{verbatim}
%  \cite{key}
%    which produces citations with full author list and year.
%    eg. (Brown 1978; Jarke, Turner, Stohl, et al. 1985)
%  \citeNP{key}
%    which produces citations with full author list and year, but without
%    enclosing parentheses:
%    eg. Brown 1978; Jarke, Turner and Stohl 1985
%  \citeA{key}
%    which produces citations with only the full author list.
%    eg. (Brown; Jarke, Turner and Stohl)
%  \citeANP{key}
%    which produces citations with only the full author list, without
%    parentheses eg. Brown; Jarke, Turner and Stohl
%  \citeN{key}
%    which produces citations with the full author list and year, but
%    can be used as nouns in a sentence; no parentheses appear around
%    the author names, but only around the year.
%      eg. Shneiderman (1978) states that......
%    \citeN should only be used for a single citation.
%  \shortcite{key}
%    which produces citations with abbreviated author list and year.
%  \shortciteNP{key}
%    which produces citations with abbreviated author list and year.
%  \shortciteA{key}
%    which produces only the abbreviated author list.
%  \shortciteANP{key}
%    which produces only the abbreviated author list.
%  \shortciteN{key}
%    which produces the abbreviated author list and year, with only the
%    year in parentheses. Use with only one citation.
%  \citeyear{key}
%    which produces the year information only, within parentheses.
%  \citeyearNP{key}
%    which produces the year information only.
%\end{verbatim}
% Abbreviated author lists use the ``et al.'' construct.
%
% `NP' means `no parentheses'.
% \subsection{Text macros}
% First a general discussion.
%
% \textsl{Text macros} expand to a piece of text, and insert the proper space
% following, depending on context.  If I define a text macro |\foo| to be
% \meta{text}, I can use |\foo| in place of \meta{text} almost anywhere.  For
% details of how the spacing is handled, see the macros.  Examples that produce
% correct formatting:
% \begin{quote}
%                    |\newtextmacro{ww}{Wordsworth}| \\
%                    |\newwork{prelude}{The Prelude}            % in italic|
%
%                    |The manuscripts of \ww's \prelude differ|\lips \\
%                    |Before beginning \prelude, \ww wrote|\lips
% \end{quote}
%
% \textsl{Abbreviation macros} are text macros that expand to something
% different the first time they are used.  It is expected that the second be
% an abbreviation of the first, but that need not be the case.  Examples:
% \begin{quote}
%  |\newname{nixon}{Richard Milhous Nixon}[Nixon]| \\
%  |\newname{ww}{George Gordon, Lord Byron}{Byron}| \\
%  |\newname{jekyll}{Dr.~Henry Jekyll}[Jekyll]|\\
%  |\newname{ama}{American Medical Association (AMA)}{AMA}| \\
% \end{quote}
%
% Here are the particular commands.  First the primitive ones.
%
% \DescribeMacro{\NewTextMacro}
% |\NewTextMacro|\marg{command}\marg{text} defines |\|\meta{command} to expand
% to \meta{text} and insert the right space after it, depending on context.  To
% \DescribeMacro{\spacebeforelist}
% control behavior explicitly, you can set |\spacebeforelist| analogously to
% |\nocorrlist|.
%
% \DescribeMacro{\newabbrev}
% |\newabbrev|\marg{command}\marg{initial text}\marg{subsequent text} defines
% |\|\meta{command} to be \meta{initial text} (like a text macro, inserting the
% right following space) the first time it is used, and \meta{subsequent text}
% subsequently.  To use one or the other in a particular circumstance, the
% commands |\|\meta{command}|short| and |\|\meta{command}|long| are also
% defined.
% \DescribeMacro{\AbbrevLongSuffix}
% \DescribeMacro{\AbbrevShortSuffix}
% (You can change those suffixes by setting |\AbbrevShortSuffix| and
% |\AbbrevLongSuffix|.)
%
% \DescribeMacro{\ResetAbbrevs}
% Calling |\ResetAbbrevs| starts all the abbreviation macros over again; their
% next occurrence will be the ``first.''  This command could be put in the
% chapter hook.
%
% The following user commands are provided.
% \DescribeMacro{\newtextmacro}
% This is the simplest one:
% |\newtextmacro|\oarg{style}\marg{command}\marg{text}.   Its arguments have
% just the same meaning as for |\NewTextMacro|, but in a different order, and
% the \meta{style} parameter is optional.
%
% \DescribeMacro{\newbook}
% |\newbook|\marg{command}\marg{text}\oarg[abbrev] defines |\|\meta{command} to
% be a text macro with emphasized text.  If an optional argument is given, it
% defines an abbreviation with emphasized text.
%
% \DescribeMacro{\newwork}
% |\newwork| is an alias for a |\newbook| at the moment. In the future,
% ``works'' will be distinguished from books by being listed in a separate
% bibliography, e.g., of primary works which are referred to by short titles.
% The defining command will then need to take a Bib\TeX\ key as an argument
% also.  The first use of the work will serve as a citation to that
% bibliography, and all uses of the work will generate an index entry. 
%
% \DescribeMacro{\newname}
% |\newname|\marg{command}\marg{name}\marg{abbrev} defines |\|\meta{command} to
% be a plain abbreviation (no style-changing). 
%
% \section{Configuring \bigmonster}
% \section{New marks}
% This file provides two extra marks in all three positions: top, bottom, and
% first.  These are both available to the user, but provisions are made for a
% package to safely claim the second for internal use, allowing the user only
% to use the first extra mark.
%
% Furthermore, an example is provided of how to use the extra mark to insert
% text at the top of a page, depending on its values in the different
% positions.  The example given is setting a play script; we put ``Speaker
% (continued)'' at the top of a page, whenever a speaker's speech is broken
% across the page.   This example is provided in the documentation, but is
% commented out. 
%
% Warning!  These marks are \emph{not} independent variables!  The \TeX{} mark
% can carry an arbitrary number of independent variables, but this is
% \emph{not} the same as an arbitrary number of independent marks!  Think
% carefully about why, because it will get you otherwise!  A command to set one
% of the parts of the mark sets the \emph{whole} mark, because there really is
% only one.  The current value of the mark is kept in a separate variable,
% which is consulted to supply the other parts of the mark to set, when you
% issue a command to change just one part.  But suppose the mark variable $x$
% has not yet been set, so it's value is the initial one (empty).  And then
% suppose the first marking command on a given page sets mark variable $y$.
% However this command sets the \TeX{} mark is going to determine the value of
% |\firstmark| for mark variable $y$ \emph{and} $x$ and all the others.
% There's no way around this, unless you want to write in \texttt{WEB}, in
% which case you're not using \TeX{} any more.
%
% So extra marks are not what they might seem to be.  Any scheme which wants to
% use the marks needs to know exactly under what circumstances \emph{all}
% commands that set the mark will be used. 
%
% The present test file is a good example of how messy marks get, and it's also
% a good way to understand them. 
%
% In general, here is the internal situation.  \TeX{} stores the current value
% of a variable called the mark at certain times during processing, into three
% different registers, or ``positions,'' top, bottom, and first.  There is
% really only one mark variable, but you can make it hold an arbitrary number
% of different pieces of information.  We also call those ``marks,'' since they
% behave as if there were more than one mark.  That is the first confusion.
%
% \LaTeX{} internals handle the \TeX{} mark so that it carries two independent
% pieces of information.  This would mean six variables, one for each piece of
% information.  But \LaTeX{} doesn't really need all six; for each piece of
% information, it is only interested in one of the three positions.  These are
% made available as the ``left'' and ``right'' ``marks.''  This is the second
% confusion.  
%
% These macros add two extra independent pieces of information to the \TeX\
% mark, called ``xmarkone'' and ``xmarktwo.''  All three positions of these
% marks are made available, unlike the first two \LaTeX{} ones, which only have
% one position.  
%
% \DescribeMacro{\xmarkone}
% \DescribeMacro{\xmarktwo}
% To set the extra marks, use the commands |\xmarkone|\marg{value} and
% |\xmarktwo|\marg{value}.
%
% \DescribeMacro{\topxmarkone}
% \DescribeMacro{\botxmarkone}
% \DescribeMacro{\firstxmarkone}
% \DescribeMacro{\topxmarktwo}
% \DescribeMacro{\botxmarktwo}
% \DescribeMacro{\firstxmarktwo}
% The values of the extra marks are available in |\topxmarkone|,
% |\botxmarkone|, and |\firstxmarkone|, and analogously for the second mark.
%
% These are the user and package-writer's versions.  The internals add
% unfortunately another whole layer of complication.  Nothing's tricky but the
% number of permutations. 
%
% There is one more wrinkle.  In the development of \monster, I wanted these
% extra marks only for one purpose.  And in fact, I only needed one extra mark.
% Instead of reserving one of the two the whole time, I decided to write
% commands to claim it from and free it for the user.  This is sort of
% overkill, since adding more marks is quite trivial, but that is how I've done
% it.
%
% \DescribeMacro{\ClaimXMarkTwo}
% The commands described above are for when the second extra mark is ``free''
% for the user.  A package can ``claim'' the second mark, making references to
% xmarktwo in the commands described above produce a warning, and keep them
% from actually setting the mark.  The command is simply |\ClaimXMarkTwo|.  The
% second mark is then accessed by the package via a set of commands with a
% \DescribeMacro{\sc@mark}
% \DescribeMacro{\sc@topmark}
% \DescribeMacro{\sc@botmark}
% \DescribeMacro{\sc@firstmark}
% different names.  I thought this layer of abstraction was important.  The
% package commands for the claimed mark are |\sc@mark|\marg{value} to set the
% mark, and |\sc@topmark|, |\sc@botmark|, and |\sc@firstmark| to read them.  
%
% \DescribeMacro{\FreeXMarkTwo}
% Once claimed, the first extra mark can be freed by the package by saying
% |\FreeXMarkTwo|.
%
%     \subsection{Credits}
% I was able to write this code because of explicit help from this kind
% gentleman who responded to a posting of mine on |comp.text.tex|:
%
% Piet (``Pete'') van Oostrum, Dept of Computer Science, Utrecht University,
% Padualaan 14, P.O. Box 80.089, 3508 TB Utrecht, The Netherlands.  Telephone:
% +31 30 531806 Telefax: +31 30 513791 Internet: |piet@cs.ruu.nl| PGP public
% key by finger or WWW |http://www.cs.ruu.nl/~piet|
%
% I have adapted his code slightly, to make the two extra marks independent,
% and provide a top, first, and bottom mark for each of them. 
%     \subsection{Example}
%
% It defines an environment for scripts in which speeches begin with the
% |\speak| macro, whose argument is the speaker's name.  The command also sets
% the mark.  A wrapper for the standard output routine is defined, which checks
% the mark positions, and inserts text if appropriate, i.e., the value of one
% of the mark positions itself, |\GiveSpeakerContinued| macro.
%
% I will have to review where exactly page breaks can occur in a vertical list,
% to do the penalties and vspace right here.
%
% If the |\pagebreak| breaks the page, |\sc@botmark| is left empty; if the page
% breaks at any other time, it will have something in it. A pagebreak will not
% occur between the end of preceding text and the |\pagebreak| here; there is
% no reason to break before \TeX{} gets to the command |\sc@mark{\@empty}|. 
%
% \begin{verbatim}
%\newcommand\speak[1]
%  {\sc@possiblyfinishdirecting
%  \sc@mark{\@empty}%
%  \pagebreak[2]\smallbreak 
%  \sc@mark{\GiveSpeakerContinued{#1}}%
%  \GiveSpeaker{#1}%
%  \nopagebreak\par\noindent}
% \end{verbatim}
% \section{Including Files}
% \DescribeMacro{\include*}
% |\include| was always pretty useless to me because it did a |\clearpage|
% before and after the |\input|.  The macro |\include*| is defined below to be
% like |\include| but without the |\clearpage|s. 
%
% The other thing we do is define a command |\includedoc|, which includes a
% file which is allowed to have its own |\documentclass| and |\begin{document}|
% and |\end{document}| and |\usepackage| commands.  
%
% This opens up a whole new world of truly modular \LaTeX{} files.  There is
% even nothing special about extracting the |document| environment, we can
% extract \emph{any} environment, or perhaps even other things.
%
% There are some problems, however.  Maybe the |\usepackage| is necessary,
% maybe it would conflict.  Same with other commands like the |\newcommand|
% family. It is simply not (yet) an issue in \LaTeX{} design to consider the
% implications of parent files.  The problems are not insurmountable.  We can
% begin by working with a convention, and ultimately maybe make some changes in
% certain macros.  I will be getting to all this.  I admit I have not looked
% carefully to see whether the design specifications of \LaTeX3{} address these
% important issues. 
%
% The macros here will be useful in many circumstances, when the included files
% are themselves simple.  
%
% \DescribeMacro{\includedoc}
% \DescribeMacro{\includedoc*}
% \DescribeMacro{\includedocskip}
% \DescribeMacro{\includedocskip*}
% There are now two main commands, |\includedoc| and |includedocskip|, each
% with a |*| version analogous to the new |\include*|.  Each take a filename as
% an argument just like |\include|. 
%
% |\includedoc|\marg{filename} reads everything in the file except for
% |\documentclass|, |\usepackage|, |\begin{document}|, |\end{document}| (and
% whatever follows it).  
%
% |includedocskip|\marg{filename} does the same except it also skips everything
% between |\documentclass| and |\begin{document}|.
%
% \DescribeMacro{\gobbleopt}
% \DescribeMacro{\gobble}
% \DescribeMacro{\gobbletwo}
% \DescribeMacro{\disable}
% At present there is a makeshift way to ignore additional commands when using
% |\includedoc| and |\includedocskip|. If you want to cause |\foo| which takes
% no arguments to be disabled, say |\disable{\let\foo\relax}|. If |\foo| takes
% one mandatory argument, say |\let\foo\gobble| instead.  If |\foo| takes one
% optional and one mandatory, say |\let\foo\gobbleopt|.  If |\foo| takes two
% mandatory arguments, say |\let\foo\gobbletwo|.  For other permutations of
% arguments, you can extrapolate from the macros defined below. 
% \section{Extending the \monster package}
%     \subsection{automatic extension}
%
% The \monster package provides several macros which create new copy styles
% and bit styles.
%
% Please share any useful new copy and bit styles you create with the
% author, so that your work can help improve the next version. 
%
% You can create a new copy style |fred| simply by saying
% |\NewCopyStyle{fred}|.  The functioning of copy style |fred| is controlled by
% a fixed number of macros with the prefix |\sc@cs@fred@|.  If
% |\sc@cs@fred@command| is undefined, however, then |\sc@cs@standard@command|
% is used.  Copy style |fred|, then, will initially be the same as the
% |standard| copy style, until you write one or more of the following
% |\sc@cs@fred@| macros to replace the corresponding |\sc@cs@standardd@|
% macros:
%
% Creating new bit styles is analogous to creating new copy styles.
% |\NewBitStyle{thelma}| creates a new bit style which will be exactly the same
% as the |story| bit style, unless any of the following commands are defined:
%
% |\CopyStyle| will be set to the name of the copy style, so that the bit
% styles can adapt their behavior to different copy styles.  
%     \subsection{more advanced hacking}
%       \subsubsection{naming} 
%
% I have tried to follow the \LaTeXe\ guidelines for macro naming.  User
% commands are all lower case.  Package macros which a sophisticated user might
% use, or which a programmer might use in extending this package, are in both
% caps and lower case.  Macros and variables that are completely contingent on
% other macros, usually package macros, have the prefix |sc@|.  Sometimes that
% rule recurses to |\sc@@|.  A handful of scratch variables also have the
% |\sc@| prefix.  When the existing definition or value of |\foo| is saved for
% later use or restoration, I save it in |\sc@saved@foo|.  (This \LaTeX\
% sources usually use the |\@@| prefix to do this.)  This system of naming is
% not very precise, and I would welcome suggestions for improvement, both
% theoretical and particular.
%
% I have made compatibility the highest priority, though there is certainly
% room for improvement.  I encourage hackers to attach the same importance to
% it, and to help us all out by sharing your code.  
%       \subsubsection{hooks}
%
% At the beginning of every bit, |\PreBit| is called with |\BitStyle|
% containing the the bit style's name.  The \monster package itself does not
% use the |\PreBit| hook.  To put something into the hook, don't redefine it,
% use |\addto@macro|\marg{hook}\marg{tokens} which puts \meta{tokens} at the
% end of \meta{hook} just as they appear in the argument at the time
% |\addto@macro| is called, with no expansion.
%
% \section{bugs}
% \label{bugs}
%
% Please add to this list if you can, by sending mail to \Author. 
%
% \begin{itemize}
%
% \item The scoping of information like |\lastchange| could be improved.  If an
% included bit (with |\includebit|) ends on page $n$, this information will be
% restored from the next higher level before that page ends.  Thus if an
% included bit begins and ends on the same page, the footer for, say, the
% |standard| copy style will not reflect the bit but the master file.  I'm not
% sure what behavior I want.  I think the version control boxes should stack
% like footnotes, but in the footer, if this can be done.
%
% \item Spacing at the top of bits is empirical right now, because I wrote them
% when I had not figured out the details of |\topskip| glue and the \LaTeX{}
% output routine, and how |\vspace*| works.
%
% There is probably a lot of documentation and code lying around that is
% obsolete.   And documentation of things that aren't done yet.
% 
% \item The bibstyle has only been checked for the entry types I use:  book,
% inbook, incollection, article, thesis, and manual (?).    And what is there
% has not been rigorously tested or checked for conformity with the
% \emph{Chicago Manual}. 
% \end{itemize}
%
% \clearpage
% \part{Implementation}
% \StopEventually{}
% \section{Preliminaries}
%     \subsection{Version control and requirements}
%    \begin{macrocode}
%<*all>
%    \end{macrocode}
% First we want to declare the package version, and make sure the package is
% running in the environment it needs. 
%
% \begin{macro}{\fileinfo}
% \begin{macro}{\fileversion}
% \begin{macro}{\filedate}
% \begin{macro}{\docdate}
% \begin{macro}{\Frankenversion}
% \begin{macro}{\sc@ppoptarg}
%    \begin{macrocode}
\def\fileinfo%
%<monster>{for scholarly and creative writing}
%<safedefs>{extra safe defining commands}
%<lips>{for text ellipses}
%<includex>{extra ways to include files}
%<tmacros>{text macros and abbreviations}
%<autoload>{load code as needed}
%<achicagosty>{use Chicago Manaul A style bib}
\def\fileversion{v0.16}
\def\filedate{1995/03/01}
%<*monster>
\def\docdate{1995/03/01}
%</monster>
\def\Frankenversion{\expandafter\@cdr\fileversion\@nil}

\@ifdefinable{PPOptArg}
  {\edef\sc@ppoptarg{\filedate\space \fileversion\space \fileinfo}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% Now we declare the package, check for \LaTeX2e, and load the other packages
% needed. 
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
%<*monster>
\@ifclassloaded{article}
    {}
  {\@ifclassloaded{report}
      {}
    {\@ifclassloaded{book}
        {}
      {\@ifclassloaded{letter}
          {}
        {\PackageWarning{monster}
           {This document does not use a standard class. \MessageBreak
           Strange things might happen.}}}}}
%</monster>
\ProvidesPackage
%<monster>{monster}
%<safedefs>{safedefs}
%<lips>{lips}
%<includex>{includex}
%<tmacros>{tmacros}
%<autoload>{autoload}
%<achicagosty>{achicago}
                   [\sc@ppoptarg]
\typeout% must come before any \RequirePackage commands
%<!(monster|lips)>{A piece of Frankenstein: %
%<lips>{Frankenstein's lips: %
%<monster>{The whole of Frankenstein: %
\sc@ppoptarg}
%<monster|tmacros|achicagosty>\RequirePackage{ifthen}
%<parts>\RequirePackage{safedefs}
%<monster>\RequirePackage{relsize}
%</all>
%    \end{macrocode}
%     \subsection{New general defining commands}
% The defining commands defined in this section are available as a separate
% package, |safedefs|.  We want the first four to go to every part except those
% that are going to require |safedefs|, namely the those with the |parts|
% variable set true.
%    \begin{macrocode}
%<*all&!parts>
%    \end{macrocode}
%
% The first two have to be bootstraped, so their definitions are a little more
% complicated.
% \begin{macro}{\@ifundefined@cs}
% To make the macros clearer to read, we want a version of |\@ifundefined| that
% works on command sequences.
%    \begin{macrocode}
\@ifundefined{@ifundefined@cs}
    {\newcommand}
  {\CheckCommand}
\@ifundefined@cs[1]
  {\expandafter\expandafter\expandafter\@ifundefined
  \expandafter\expandafter\expandafter{\expandafter\@cdr\string#1\@nil}}
%    \end{macrocode}
% \end{macro}
%  \begin{macro}{\requirecommand}
%  |\requirecommand| is like |\providecommand|, but if the command is already
%  defined, we then call |\CheckCommand| to make sure it's the same thing.
%  Using |\requirecommand| guarantees that a command sequence will have the
%  given definition; or an error will occur.  
%    \begin{macrocode}   
\@ifundefined{requirecommand}
    {\newcommand}
  {\CheckCommand}
\requirecommand[1]
  {\@ifundefined@cs{#1}
      {\newcommand}
    {\CheckCommand}
  {#1}}
%    \end{macrocode}
%  \end{macro}
%
% \begin{macro}{\InitCS}
% \begin{macro}{\ReserveCS}
% |\InitCS| sets a macro to empty. |\ReserveCS| does the same with
% |\requirecommand|. 
%    \begin{macrocode}
\requirecommand\InitCS[1]
  {\def#1{}}
\requirecommand\ReserveCS[1]
  {\requirecommand{#1}{}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
%  \begin{macro}{\sc@t@a}
%  \begin{macro}{\sc@t@b}
% Everyone gets these two scratch variables, too.  If a package changes them
% while loading as opposed to executing them, it should reset them, so as not
% to cause a warning when none is warranted. 
%    \begin{macrocode}
\ReserveCS\sc@t@a
\ReserveCS\sc@t@b
%    \end{macrocode}
%  \end{macro}
%  \end{macro}
%
% From now on, the commands will only be in |safedefs| and in the main
% package.  The other parts will get them by requiring |safedefs|.
%    \begin{macrocode}
%</all&!parts>
%<*monster|safedefs>
%    \end{macrocode}
%
% The following two macros reserve names before acting on them. 
% \begin{macro}{\newtokens}
% \begin{macro}{\newlet}
% |\newtokens| should definitely be |outer|.  Because |\newtoks| is |outer|, we
% have to fool |\def| into allowing it to be in its argument by using
% |\csname|\lips|\endcsname|. 
%
% FIX: wouldlike to have |\newtokens| be |\outer|, but I have to hack with
% getting ``require'' right.
%    \begin{macrocode}
\requirecommand\newtokens[1]
  {\@ifdefinable #1
    {\csname newtoks\endcsname#1}}
\requirecommand\newlet[2]
  {\@ifdefinable #1
      {\let#1#2}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\providetokens}
% \begin{macro}{\providelength}
% \begin{macro}{\providesavebox}
% \begin{macro}{\providecounter}
% \begin{macro}{\provideboolean}
% Now we provide some commands analogous to |\providecommand|. 
% FIX these need something else in the else clauses; a warning? 
%    \begin{macrocode}
\requirecommand\providetokens[1]
  {\@ifundefined@cs{#1}
      {\csname newtokens\endcsname#1}
    {}}
\requirecommand\providelength[1]
  {\@ifundefined@cs{#1}
      {\newlength{#1}}
    {}}
\requirecommand\providesavebox[1]
  {\@ifundefined@cs{#1}
      {\newsavebox{#1}}
    {}}
\requirecommand\providecounter[1]
  {\@ifundefined{c@#1}
      {\newcounter{#1}}
    {}}
\requirecommand\provideboolean[1]
  {\@ifundefined{#1true}
      {\newboolean{#1}}
    {}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
%  \begin{macro}{\addto@macro}
%  We need a local version of the kernel's |\g@addto@macro|.
%    \begin{macrocode}
\requirecommand\addto@macro[2]
  {\sc@toks@a=\expandafter{#1#2}%
  \edef#1{\the\sc@toks@a}}
%    \end{macrocode}
%  \end{macro}
%
% \begin{macro}{\gsetboolean}
% We need a global version of |\setboolean|.
%    \begin{macrocode}
\newcommand\gsetboolean[2]
  {\lowercase{\def\sc@t@a{#2}}%
  \@ifundefined{@tempswa\sc@t@a}%
    {\PackageError
%<monster>{Frankenstein}
%<safedefs>{safedefs}
                       {You can only set a boolean to `true' or `false'}}
    {\@ifundefined{#1\sc@t@a}
      {\PackageError
%<monster>{Frankenstein}
%<safedefs>{safedefs}
                      {Boolean #1 undefined}}
      {\global\csname#1\sc@t@a\endcsname}}}
%    \end{macrocode}
% \end{macro}
%
%  \begin{macro}{\NewNameDef}
%  \begin{macro}{\RequireNewName}
% These will define macro names that |\newcommand| won't like.  But unlike
% |\@namedef|, this still checks whether something is defined, and gives an
% error if it is.  
%    \begin{macrocode}
\requirecommand\NewNameDef[3]
  {\@ifundefined{#1}
      {\@namedef{#1}#2{#3}}
    \@notdefinable}
\requirecommand\RequireNewName[3]
  {\@ifundefined{#1}
      {\@namedef{#1}#2{#3}}
    {\expandafter\CheckCommand\csname#1\endcsname{#3}}}
%    \end{macrocode}
%  \end{macro}
%  \end{macro}
%
% The following two abbreviations make certain constructions easier to read.
% \begin{macro}{\Elet}
% |\Elet| expands the second thing after it once.  It is analogous to |\edef|,
% but only expands once.  The convention is that a capital E means the macro
% expands just once.  |\global| works before it.
%    \begin{macrocode}
\requirecommand\Elet
  {\expandafter\let\expandafter}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\EElet}
% |\EElet| expands the two things that come after it once each.  |\global|
% works before it.
%    \begin{macrocode}
\requirecommand\EElet
  {\expandafter\expandafter\expandafter\let\expandafter\expandafter}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NewUserInfo}
% Use |\NewUserInfo|\marg{name} where \meta{name} has some capital letters.  It
% will define the lowercase version of \meta{name} to be a user command that
% redefines the uppercase version to its argument.  Using |\lowercase| is
% tricky, since it gets expanded only in \TeX's stomach.
%    \begin{macrocode}
\newcommand\NewUserInfo[1]
  {\InitCS{#1}%
  \edef\sc@t@a{\edef\noexpand\sc@t@b{\E@cdr\string#1\@nil}}%
  \lowercase\expandafter{\sc@t@a}%
  \expandafter\NewNameDef\expandafter{\sc@t@b}{##1}
    {\renewcommand{#1}{##1}}}
%    \end{macrocode}
% \end{macro}
%
% These next two aren't really defining commands, but they are quite useful.
%  \begin{macro}{\E@cdr}
%  This is a fairly common construction with |\@cdr|. 
%    \begin{macrocode}
\RequireNewName{E@cdr}{#1\@nil}
  {\expandafter\@cdr#1\@nil}
%    \end{macrocode}
%  \end{macro}
%
% \begin{macro}{\sc@gobbleopt}
% Saying |\let\foo\sc@gobbleopt| will cause occurrences of |\foo|\marg{baz}
% |\foo|\oarg{bar}\marg{baz} to be entirely ignored. 
%    \begin{macrocode}
\requirecommand\sc@gobbleopt
  {\@ifnextchar [{\sc@@gobbleopt}{\@gobble}}
\RequireNewName{sc@@gobbleopt}{[#1]#2}{}
%    \end{macrocode}
%  \end{macro}
%
% Finally a couple of conveniences for debugging.
%  \begin{macro}{\fullerrorcontext}
%  \mbox{}
%    \begin{macrocode}
\requirecommand\fullerrorcontext[1][\@M]
  {\setcounter{errorcontextlines}{#1}%
  \showboxbreadth #1%
  \showboxdepth #1}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\debug}
% Set to 0, 1, or~2.   We don't use |\ifthenelse| since \monster parts will use
% this.
%    \begin{macrocode}
\requirecommand\debug[1]
  {\ifnum #1 > 0%
       \fullerrorcontext\relax
    \else
      \fullerrorcontext\m@ne
  \fi
  \tracingoutput#1%
  \tracingpages#1%
  \tracingmacros#1%
  \tracingcommands#1}
%    \end{macrocode}
%  \end{macro}
%
%    \begin{macrocode}
%</monster|safedefs>
%    \end{macrocode}
%     \subsection{Scratch variables}
%    \begin{macrocode}
%<*monster|parts>
%    \end{macrocode}
%
%  \begin{macro}{\sc@t@c}
%  \begin{macro}{\sc@t@d}
%  \begin{macro}{\sc@t@e}
%  \begin{macro}{\sc@t@f}
% \begin{macro}{\sc@next}
% \begin{macro}{\sc@lastmark}
% \begin{macro}{\sc@toks@a}
% \begin{macro}{\sc@toks@b}
% \begin{macro}{\sc@len}
% \begin{macro}{\sc@box}
% \begin{macro}{\c@sc@count}
% \begin{macro}{sc@bool}
% Scratch varirables.
%    \begin{macrocode}
%<*monster>
\ReserveCS\sc@t@c
\ReserveCS\sc@t@d
\ReserveCS\sc@t@e
\ReserveCS\sc@t@f
%</monster>
%<monster|markx>\InitCS\sc@lastmark
\ReserveCS\sc@next
\providetokens\sc@toks@a
\providetokens\sc@toks@b
\providelength\sc@len
\providesavebox\sc@box
\providecounter{sc@count}
%<monster|tmacros>\provideboolean{sc@bool}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%
% \begin{macro}{\sc@begingobble}
% \begin{macro}{\sc@endgobble}
%    \begin{macrocode}
%<*monster|achicagosty>
\requirecommand\sc@begingobble
  {\begin{lrbox}{\sc@box}}
\requirecommand\sc@endgobble
  {\end{lrbox}\sbox\sc@box{}}
%</monster|achicagosty>
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
%    \begin{macrocode}
%</monster|parts>
%    \end{macrocode}
%     \subsection{Local new defining commands}
%    \begin{macrocode}
%<*monster>
%    \end{macrocode}
%
% \begin{macro}{\NewMonsterCommand}
% \begin{macro}{\NewMonsterCommandOneArg}
% Commands defined with the |\NewMonsterCommand| macros will be disabled when
% reading a bit included with |\includebit|.  All formatting commands should be
% defined with one of these macros, so that included bits will relinquish
% global formatting to the top level file.
%
% If the |\newcommand| in |\NewMonsterCommand| gives an error and the user
% continues, the command will still be disabled by |\DisableMonster|.  A
% situation not worth handling.
%
% Arguments are passed directly to |\newcommand|. 
%    \begin{macrocode}
\ReserveCS\DisableMonster
\newcommand\NewMonsterCommand[1]
  {\g@addto@macro\DisableMonster{\let#1\relax}%
  \newcommand{#1}}

\newcommand\NewMonsterCommandOneArg[1]
  {\g@addto@macro\DisableMonster{\let#1\@gobble}%
  \newcommand{#1}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
%    \begin{macrocode}
\newcommand\MakeStarCommand[4] % args: name arg-template nostardef stardef
  {\NewNameDef{#1@nostar}{#2}
    {#3}%
  \NewNameDef{#1@star}{#2}
    {#4}%
  \newcommand#1%
    {\@ifstar
        {\nameuse{#1@star}}
      {\nameuse{#1@nostar}}}}

\newcommand\SwitchStar[1]
  {\Elet\sc@t@a\csname #1@nostar\endcsname
  \EElet\csname #1@nostar\endcsname\csname #1@star\endcsname
  \expandafter\let\csname #1@star\endcsname\sc@t@a}

% fix necessary?

\newcommand\GlobalSwitchStar[1]
  {\Elet\sc@t@a\csname #1@nostar\endcsname
  \global\EElet\csname #1@nostar\endcsname\csname #1@star\endcsname
  \global\expandafter\let\csname #1@star\endcsname\sc@t@a}
%    \end{macrocode}
%
%
% Uses of this should be replaced with reassignStar
%    \begin{macrocode}
\newcommand\AssignStarNoStar[3]
  {\renewcommand #1
    {\@ifstar
      	{#2}
      {#3}}}

\newcommand\ReassignStar[4] % args: name arg-template nostardef stardef
  {\@namedef{#1@nostar}{#2}
    {#3}%
  \@namedef{#1@star}{#2}
    {#4}}
%    \end{macrocode}
%     \subsection{Autoloading}
%    \begin{macrocode}
%</monster>
%<*monster|autoload>
%    \end{macrocode}
%
% This is a big package, and we don't want to have to load all parts of it in
% every time we use it.  We implement here a way to make a command, when
% expanded, cause the input of a file of macros.  The way we do this is to have
% |\foo| call |\usepackage| and then call itself.  The package will presumably
% redefine |\foo| to something else, but we catch it if this does not happen. 
%
% Here are a couple of lines from the |afterpreamble| docstrip module of the
% \LaTeXe{} kernel.  
%    \begin{macrocode}
\def\reserved@a#1\do\@clsextension#2\do\@vwrend#3\relax{%
  \gdef\@preamblecmds{#1#3}}
\expandafter\reserved@a\@preamblecmds\relax
%    \end{macrocode}
%
% A caveat.  The authors of \LaTeXe{} keep the |pkgindoc| package under
% wraps for a good reason: it is unstable to load many packages after the
% |\begin{document}| command.  I am using |pkgindoc| as a convenient way to
% keep track of what's already been loaded.  But really I should copy the
% mechanism and keep track of a separate list of load-as-needed files that have
% been loaded.  The danger with this way is that an unknowing person can load
% in a package that will screw things up where normally they couldn't. 
% FIX A bug:  a |\par| is sneaking in somehow at the time of the first loading
% of the file. 
%
%  \begin{macro}{\MakeAutoLoad}
%  This defines the \meta{command} to load the second package.  Before doing
%  this, it redefines \meta{command} to produce an error that will be given in
%  the case that the loaded package fails to redefine it.  Finally,
%  \meta{command} is called.
% 
%  The recursion issues are perhaps surprisingly minimal.  The only difficulty
%  is that we can't tell whether the command is already defined because there
%  is a conflict, or already defined because the proper package has already
%  been loaded.  We could make some checking arrangement very easily, but this
%  seems unnecessary.  A top-level |\MakeAutoLoad| command can be preceded by a
%  |\ReserveCS| command.  If problems occur, I will make this a more secure
%  macro.
%  
%    \begin{macrocode}
\newcommand\MakeAutoLoad[3][] % args: [opt-pkg-args] pkg cs 
  {\providecommand{#3}
    {\renewcommand{#3}
      {\PackageError
%<monster>{monster}
%<autoload>{autoload}
                {Loading #2 with args [#1] failed to redefine \protect#3}}%
    \RequirePackage[#1]{#2}%
    #3}}
%    \end{macrocode}
%  \end{macro}
%
%    \begin{macrocode}
%</monster|autoload>
%<*monster>
%    \end{macrocode}
%     \subsection{Options processing}
% The following parameters must be known before the package is loaded.
%    \begin{macrocode}
\newboolean{Achicago}
\newboolean{UseConfig}
%    \end{macrocode}
%
% These booleans can be set after the package is loaded, so
% user commands are provided to do this.  It makes sense for the first four to
% change in the course of a document, so two commands are provided for each.
%
% Whenever user commands are added that should be set only in the top level
% file,  we add a disabling command to |\DisableMonster|.
%    \begin{macrocode}
\newboolean{BitContents}
\NewMonsterCommand\bitcontents{\setboolean{BitContents}{true}}
\NewMonsterCommand\nobitcontents{\setboolean{BitContents}{false}}

\newboolean{Anonymous}
\NewMonsterCommand\anonymous{\setboolean{Anonymous}{true}}
\NewMonsterCommand\usemyname{\setboolean{Anonymous}{false}}

\newboolean{SuppressEnds}
\NewMonsterCommand\noends{\setboolean{SuppressEnds}{true}}
\NewMonsterCommand\useends{\setboolean{SuppressEnds}{false}}

%</monster>
%<*monster|achicagosty>
\newboolean{Annotate}
%<monster>\NewMonsterCommand
%<achicagosty>\newcommand
\annotate{\setboolean{Annotate}{true}}
%<monster>\NewMonsterCommand
%<achicagosty>\newcommand
\noannotate{\setboolean{Annotate}{false}}
%</monster|achicagosty>
%<*monster>

\newboolean{SuppressCover}
\NewMonsterCommand\nocover{\setboolean{SuppressCover}{true}}
\NewMonsterCommand\usecover{\setboolean{SuppressCover}{false}}

\ReserveCS\CopyStyle
\NewMonsterCommandOneArg\copystyle[1]{\renewcommand\CopyStyle{#1}}
%    \end{macrocode}
% Some of these options seem superfluous, but it's easier to be uniform about
% everything. 
%    \begin{macrocode}
\DeclareOption{stdbib}{\setboolean{Achicago}{false}}
\DeclareOption{achicagobib}{\setboolean{Achicago}{true}}

\DeclareOption{noconfig}{\setboolean{UseConfig}{false}}
\DeclareOption{useconfig}{\setboolean{UseConfig}{true}}

\DeclareOption{comments}{\renewcommand{\CopyStyle}{comments}}
\DeclareOption{coverpage}{\renewcommand\CopyStyle{coverpage}}
\DeclareOption{submission}{\renewcommand\CopyStyle{submission}}
\DeclareOption{blank}{\renewcommand\CopyStyle{blank}}
\DeclareOption{standard}{\renewcommand\CopyStyle{standard}}
%    \end{macrocode}
% We provide redundant options for the default settings, so that to change the
% defaults, the only thing that needs to be changed in the |\ExecuteOptions|
% command itself. 
%    \begin{macrocode}
\DeclareOption{bitcontents}{\bitcontents}
\DeclareOption{nobitcontents}{\nobitcontents}

\DeclareOption{useends}{\useends}
\DeclareOption{noends}{\noends}

\DeclareOption{anonymous}{\anonymous}
\DeclareOption{usemyname}{\usemyname}

\DeclareOption{usecover}{\usecover}
\DeclareOption{nocover}{\nocover}

%</monster>
%<*monster|achicagosty>
\DeclareOption{annotate}{\annotate}
\DeclareOption{noannotate}{\noannotate}

\ExecuteOptions
%<achicagosty>{noannotate}
%<monster>{bitcontents,achicagobib,useconfig,standard,%
%<monster>      	      	useends,usemyname,usecover,noannotate} 
\ProcessOptions
%</monster|achicagosty>
%<*monster>
%    \end{macrocode}
% \section{General user commands}
%       \subsection{Dates}
%    \begin{macrocode}
\renewcommand\today
  {\number\day\space\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\year}

\newcommand\todayabbrev
  {\number\day\space\ifcase\month\or 
        Jan\or Feb\or
        Mar\or Apr\or May\or Jun\or Jul\or Aug\or Sep\or
        Oct\or Nov\or Dec\fi\space\number\year}
%    \end{macrocode}
%       \subsection{Attribution}
%
% \begin{macro}{\attrib}
% \begin{macro}{\PreTrib}
% \begin{macro}{\PostTrib}
% \begin{macro}{\AttribMinSkip}
% These macros should never be |\let| to |\relax| or |\renewcommand| will
% refuse to work on them. 
%    \begin{macrocode}
\newcommand\PreTrib{(}
\newcommand\PostTrib{)}

\newlength{\AttribMinSkip}
  \setlength{\AttribMinSkip}{2em}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%  \begin{macro}{\sc@attribinit}
%  This heart of this code is from the \TeX book \cite[106]{texbook}. 
%    \begin{macrocode}
\newcommand\sc@attribinit
  {\renewcommand\PreCiteWork
    {\csname}%
  \let\PostCiteWork\@empty
  \let\PreCite\@empty
  \let\PostCite\@empty}
    
\newcommand\attrib[1]
  {{\sc@attribinit\unskip\nobreak\hfil\penalty50
  \hskip\AttribMinSkip\vadjust{}\nobreak\hfil
  {\PreTrib\relax#1}{\PostTrib}%
  \parfillskip\z@ \finalhyphendemerits0 \par}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%       \subsection{Hooks}
%  \begin{macro}{\@makefntext}
%  We want to add a hook to the usual definition here, to gain some control
%  over relative sizing in footnotes.
%    \begin{macrocode}
\renewcommand\@makefntext[1]
  {\parindent 1em%
  \noindent
  \hbox to 1.8em{\hss\@makefnmark}%
  {\PreFootnote
  #1}}
%    \end{macrocode}
%  \end{macro}
%
% \begin{macro}{sc@in@footnote}
% \begin{macro}{\PreFootnote}
% \begin{macro}{\PreChunk}
% \begin{macro}{\PreQuote}
% \begin{macro}{\PreQuotes}
% \begin{macro}{\PreQuotation}
% \begin{macro}{\PreVerse}
% I think macros are much more convenient as hooks than tokens. 
% I use the prefixes |Pre| or |Post|.  
%    \begin{macrocode}
\newboolean{sc@in@footnote}
\newcommand\PreFootnote{\setboolean{sc@in@footnote}{true}}
\ReserveCS\PreChunk
\newcommand\PreQuote{\PreChunk}
\newcommand\PreQuotation{\PreChunk}
\newcommand\PreVerse{\PreChunk}
\newcommand\PreQuotes{\PreChunk}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% Additions to the above hooks should be made with |\addto@macro|.  Deletions
% should be accomplished by scoping.
%    \begin{macrocode}
\NewMonsterCommand\smallblocks
  {\addto@macro\PreChunk
    {\ifthenelse{\boolean{sc@in@footnote}}
        {}
      {\smaller}}}
%    \end{macrocode}
%
%  \begin{environment}{verse}
%  \begin{environment}{quotation}
%  \begin{environment}{quote}
%  \begin{environment}{quotes}
%  These environments are the same for the standard document classes, and the
%  only change is to insert the above hooks.
%
% The hook cannot be put into the second argument, which is called before the
% paragraph preceding the environment has been ended (unless the environment
% started a new one).  
%    \begin{macrocode}
\renewenvironment{verse}
               {\let\\\@centercr  % the next \relax is only for my emacs
               \relax\begin{list}{}{\setlength{\itemsep}{\z@}%
                        \setlength{\itemindent}{-1.5em}%
                        \setlength{\listparindent}{\itemindent}%
                        \setlength{\rightmargin}{\leftmargin}%
                        \addtolength{\leftmargin}{1.5em}}%
                \item[]\PreVerse\relax}
               {\end{list}}
\renewenvironment{quotation}
               {\begin{list}{}{\setlength{\listparindent}{1.5em}%
                        \setlength{\itemindent}{\listparindent}%
                        \setlength{\rightmargin}{\leftmargin}%
                        \setlength{\parsep}{\z@ \@plus\p@}}%
                \item[]\PreQuotation\relax}
               {\end{list}}
\renewenvironment{quote}
               {\begin{list}{}{\setlength{\rightmargin}{\leftmargin}}%
                \item[]\PreQuote\relax}
               {\end{list}}
\newenvironment{quotes}
    {\begin{list}{}{\setlength{\rightmargin}{\leftmargin}%
                    \setlength{\itemsep}{1ex\@plus.4ex\@minus.2ex}%
                    \setlength{\parsep}{\z@\@plus.2ex}%
                    \setlength{\listparindent}{1.5em}%
                    \setlength{\itemindent}{\listparindent}}%
                    \PreQuotes\relax}
               {\end{list}}
%    \end{macrocode}
%  \end{environment}
%  \end{environment}
%  \end{environment}
%  \end{environment}
%       \subsection{Epigraphs}
%
%  \begin{macro}{\PreEpigraph}
%  \begin{macro}{\epigraph}
%    \begin{macrocode}
\newcommand\PreEpigraph
  {\raggedleft
  \PreChunk
  \slshape}

\newcommand\epigraph[3][.5\textwidth]%  args: [width] text attribution
  {\begingroup
  \renewcommand\PreTrib{---}%
  \renewcommand\PostTrib{}%
  \hfill\parbox{#1}{\PreEpigraph\relax #2}%
  \par\smallskip
  \attrib{\PreEpigraph\relax #3}%
  \bigskip
  \endgroup}
%    \end{macrocode}
%  \end{macro}
%  \end{macro}
%       \subsection{Ellipses}
%    \begin{macrocode}
%</monster>
%<*monster|lips>
%    \end{macrocode}
% |\DeclareRobustCommand| only warns in the log if the argument is already
% defined.  
%
% \begin{macro}{\lips}
% If |\lips| is followed by other than a period, we need to perform a check for
% vertical mode. 
%    \begin{macrocode}
\ReserveCS\lips
\DeclareRobustCommand\lips
  {\@ifnextchar .%
      {\sc@lips}
    {\sc@lipscheck}}
%    \end{macrocode}
% \begin{macro}{\sc@lips}
% This is the actual ellipsis.  
%    \begin{macrocode}
\newcommand{\sc@lips}
  {$\m@th\mathinner{\ldotp}$~$\m@th
  \mathinner{\ldotp}$~$\m@th\mathinner{\ldotp}$~}

\ReserveCS\sc@lipscheck
\DeclareRobustCommand{\sc@lipscheck}
  {\ifvmode\else\unskip~\fi
  \sc@lips}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% You might want to compare the \LaTeX{} version, which is
% \begin{verbatim}
% \DeclareTextCommandDefault{\textellipsis}{%
%   .\kern\fontdimen3\font
%   .\kern\fontdimen3\font
%   .\kern\fontdimen3\font
% }
% \def\mathellipsis{\mathinner{\ldotp\ldotp\ldotp}}
% \DeclareRobustCommand{\dots}{%
%   \ifmmode\mathellipsis\else\textellipsis\fi
% }
% \let\ldots\dots
% \end{verbatim}
%    \begin{macrocode}
%</monster|lips>    
%    \end{macrocode}
% \section{New environments}
%    \begin{macrocode}
%<*monster>
%    \end{macrocode}
%     \subsection{\texttt{dialogue}}
%
% We use |\speak| and |\direct| in several contexts in the \monster package,
% each one has quite a different definition.
%
% See comments near the renewed |article| class environments for a discussion
% of where the |\PreDialogue| hook ought to be. 
%
% standard classes |\partopsep|, |\parsep|, |\topsep|, and |\itemsep| to
% positive values.  leftmargin goes to 2.5em in onecolumn.  labelsep .5em;
% labelwidth |\leftmargin| - |\labelsep|
%
% The first line of a new speaker has the name flush with the left margin of
% the surrounding text, then the default |\labelsep|, then the first line of
% dialogue.  Subsequent lines all begin 2.5em in, and end 2.5em before the
% surrounding text.  Interparagraph space is the same as the surrounding
% text's. Extra positive stretchability of .5ex is added between speakers; I
% hope that the units will be relative to the current size \emph{in} the
% environment, not the current size when the setting is done.   
%    \begin{macrocode}
\newcommand\DialogueLabel[1]
  {\scshape\lowercase{#1}:}

\newcommand\PreDialogue{\PreChunk}
\newenvironment{dialogue}
    {\begin{list}{}
      {\setlength{\itemsep}{\z@ \@plus .5ex\relax}%
      \setlength{\parsep}{\parskip}%
      \setlength{\rightmargin}{\leftmargin}%
      \def\speak##1{\item[{##1}]}%
      \def\direct##1{[{\DirectStyle ##1}]}%
      \let\makelabel\DialogueLabel}%
      \PreDialogue\relax}
  {\end{list}}
%    \end{macrocode}
%     \subsection{\texttt{comments}}
%
% hack to allow my files in for the moment!
%    \begin{macrocode}
\let\comment\relax
\let\smallcomments\relax
\let\endcomment\relax

\newlet\sc@saved@comment\comment
\newlet\sc@saved@endcomment\endcomment

\newcommand\DefaultCommentPrefix
  {$\bullet$\hspace{\@ne em}}

\newlet\CommentPrefix\DefaultCommentPrefix

\newcommand\CommentStyle
  {\sffamily}

\NewMonsterCommand\nocomments
  {\let\comment\sc@saved@comment
  \let\sc@saved@par\par
  \renewcommand\par
    {\endcomment\sc@saved@par}}

\NewMonsterCommand\showcomments
  {\renewcommand\comment
    {\CommentStyle\CommentPrefix\relax}
  \let\par\sc@saved@par}
%    \end{macrocode}
% \section{Including files}
%    \begin{macrocode}
%</monster>
%<*monster|includex>
%    \end{macrocode}
%
% \begin{macro}{\disable}
% This allows the disabling hacks.
%    \begin{macrocode}
%<includex>\ReserveCS\DisableMonster  % This line is elsewhere for main package
\newcommand\disable[1]
  {\g@addto@macro\DisableMonster{#1}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\sc@saved@include}
% \begin{macro}{\include}
% \begin{macro}{\sc@include}
% \begin{macro}{\sc@@include}
% This is a simple redefinition of |\include| without the |\clearpage|
% commands.  Nothing tricky going on. 
%    \begin{macrocode}
\newlet\sc@saved@include\include
\renewcommand\include
  {\@ifstar
      \sc@include
    \sc@saved@include}

\newcommand\sc@include
  {\relax
  \ifthenelse{\@auxout = \@partaux}
      {\@latex@error{\string\include\space cannot be nested}\@eha}
    {\sc@@include}}

\newcommand\sc@@include[1]
  {\if@filesw
    \immediate\write\@mainaux{\string\@input{#1.aux}}%
  \fi
  \@tempswatrue
  \if@partsw 
    \@tempswafalse
    \edef\@tempb{#1}%
    \@for \@tempa:=\@partlist
      \do{\ifx\@tempa
            \@tempb
            \@tempswatrue
          \fi}%
  \fi
  \if@tempswa 
    \let\@auxout\@partaux 
    \if@filesw
      \immediate\openout\@partaux #1.aux%
      \immediate\write\@partaux{\relax}%
    \fi
    \@input@{#1.tex}%
    \@writeckpt{#1}%
    \if@filesw
      \immediate\closeout\@partaux 
    \fi
  \else
    \@nameuse{cp@#1}%
  \fi
  \let\@auxout\@mainaux}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% Now we start dealing with the much more tricky extraction of the |document|
% environment.
%
% We start with considering how to quit inputting a file.  The idea is to make
% the |\end{document}| command of the included file call |\endinput|.  But
% there is a hitch that characters on the line after the |\end{document}| get
% inserted when you don't want them to.  To beat that limitation, we have to do
% some work.
%
% \begin{macro}{\sc@radical@shutdown}
% We will add a bunch of commands to this macro, with the idea of |\catcode|ing
% everything and its brother to a comment.   This would be a brute force
% method! 
%    \begin{macrocode}
\ReserveCS\sc@radical@shutdown
%    \end{macrocode}
% First log a message that we're about to do some crazy things. In case
% something ever goes wrong, this might help.
%    \begin{macrocode}
\addto@macro\sc@radical@shutdown
  {\PackageInfo%
%<monster>{monster}
%<includex>{includex}
                    {\protect\sc@radical@shutdown\space beginning}}
%    \end{macrocode}
% Now we start adding |\catcode| commands.  These first two should be
% redundant; but just in case someone changed things\lips.
%    \begin{macrocode}
\addto@macro\sc@radical@shutdown{\catcode`\%=14}    % 14 = comment
\addto@macro\sc@radical@shutdown{\catcode`\^=7}     % 7 = superscript
%    \end{macrocode}
% \begin{macro}{\sc@disable@char}
% Next, we define a command we weill use in a loop in a moment.
%    \begin{macrocode}
\newcommand\sc@disable@char[1]
  {\addto@macro\sc@radical@shutdown
    {\catcode`#1=14}}  % 14 = comment
%    \end{macrocode}
% The following list contains every keyboard char except these three, which are
% treated specially: |%#|.  
% The first is already a comment, and we handle the second in a moment.  Each
% character in the following list is |\catcode|d to a comment:
%    \begin{macrocode}
\@tfor\sc@t@a:=abcdefghijklmnopqrstuvwxyz%
                ABCDEFGHIJKLMNOPQRSTUVWXYZ%
                ~!@$&*()_+-=[]|/?.,<>%
                1234567890%
                `'";:%
                \^\\\{\}\ % this is really the chars "^\{}" and space
    \do {\expandafter\sc@disable@char\sc@t@a}
%    \end{macrocode}
% Using the scratch variable will cause other \monster parts to complain if
% they are used with |includex.sty|, so we reinitialize it.
%    \begin{macrocode}
%<includex>\InitCS\sc@t@a
%    \end{macrocode}
% We add |#| separately, because it's tricky or impossible to put it into the
% list we just used.
%    \begin{macrocode}
\sc@disable@char\#
%    \end{macrocode}
% \end{macro}
% We end the macro with |\endinput|.  This has to come after all the previous,
% otherwise, \TeX{} goes ahead and reads to the end of the line immediately,
% with regular catcodes.  This is a good theory, I'm not sure it's necessary.
%    \begin{macrocode}
\addto@macro\sc@radical@shutdown{\endinput}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\sc@radical@shutdown@aftergroup}
% We need to use |\sc@radical@shutdown| this way.
%    \begin{macrocode}
\newcommand\sc@radical@shutdown@aftergroup
  {\aftergroup\sc@radical@shutdown}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\includedoc}
% \begin{macro}{\includedoc*}
% Now we start from the other end, defining the user command.
%    \begin{macrocode}
\newcommand\includedoc
  {\@ifstar
      {\sc@includebit}
    {\clearpage
    \sc@includebit[\clearpage]}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\gobbleopt}
% \begin{macro}{\gobble}
% \begin{macro}{\gobbletwo}
% Here we provide user versions of some internal gobblig commands.  This is
% only a temporary solution to the bigger problem of scoping control. 
%    \begin{macrocode}
\newlet\gobbleopt\sc@gobbleopt
\newlet\gobble\@gobble
\newlet\gobbletwo\@gobbletwo
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\sc@includebit}
% The commented-out code is for some eventual extensions. 
%    \begin{macrocode}
\newcommand\sc@includebit[2][]
  {%\setcounter{sc@count}{\thebit}%
  \begingroup
  \DisableMonster  
  \let\usepackage\sc@gobbleopt
  \let\enddocument\sc@radical@shutdown@aftergroup
  \let\documentclass\sc@gobbleopt  
  \let\documentstyle\sc@gobbleopt  % why worry about branching if 2.09..
  \renewcommand\document{}%
  \include*{#2}% 
  \endgroup
%  \ifthenelse{\value{sc@count} = \value{bit}} 
%      {\PackageWarning{monster}
%      	{Included file #1 did not contain a proper bit}}
%    {}%
  \par
  #1}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\includedocskip}
% \begin{macro}{\includedocskip*}
% Now we make a similar command that \emph{entirely} skips the preamble,
% whereas |\includedoc| only skipped those commands that we specifically
% disabled.  Obviously this whole business of the preamble needs to be
% radically reconceived if convenient modularity of documents is to be had.  At
% the moment, no distinction is made between things like |\newcommand| and
% |\usepackage| that should be exported to a parent file, and those things that
% should not.
%    \begin{macrocode}
\newcommand\includedocskip
  {\@ifstar
      {\sc@includebitskip}
    {\clearpage
    \sc@includebitskip[\clearpage]}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% I tried combining |\sc@includebitskip| and |\sc@includebit| but something
% changed when I used a conditional to do this.  I'm sure the problem could be
% figured out and the two combined.
%
% \begin{macro}{\sc@includebitskip}
% We begin skipping with the |\documentclass| or |\documentstyle| command, and
% stop with the |\begin{document}| command.  With some hacking to the new
% |verbatim| environment, this could be done.  I haven't done this yet, so this
% is implemented by stuffing everything into a macro argument.  I can't think
% of a |\begin| occurring between |\documentclass| the |\begin| document, but
% that will screw things up if it does.
%
% The commented lines here are once again for a future extension.
%    \begin{macrocode}
\newcommand\sc@includebitskip[2][]
  {% \setcounter{sc@count}{\thebit}%
  \begingroup
  \DisableMonster
  \let\enddocument\sc@radical@shutdown@aftergroup
  \long\def\documentclass##1\begin{%
    \begingroup
    \def\@currenvir{document}%
    \@gobble}  % "{document}" is still to be read.
  \let\documentstyle\documentclass
  \include*{#2}%
  \endgroup
%  \ifthenelse{\value{sc@count} = \value{bit}}
%      {\PackageWarning{monster}
%      	{Included file #1 did not contain a proper bit}}
%    {}%
  \par
  #1}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\chapterinclude}
% \begin{macro}{\sc@chapterinclude}
% \begin{macro}{\sc@@chapterinclude}
%    \begin{macrocode}
\newcommand\chapterinclude[1]
  {\@ifnextchar [
      {\sc@chapterinclude{#1}}
    {\sc@chapterinclude{#1}[]}}

\NewNameDef{sc@chapterinclude}{#1[#2]}
  {\@ifnextchar [
      {\sc@@chapterinclude{#1}{#2}}
    {\sc@@chapterinclude{#1}{#2}[]}}

\NewNameDef{sc@@chapterinclude}{#1#2[#3]#4}
  {\@ifnextchar [
      {\sc@@@chapterinclude{#1}{#2}{#3}{#4}}
    {\sc@@@chapterinclude{#1}{#2}{#3}{#4}[]}}
%    \end{macrocode}
% Args are \meta{chapter name}, \meta{chapter star}, \meta{interim commands},
% \meta{include name}, \meta{include star}.
%    \begin{macrocode}
\NewNameDef{sc@@@chapterinclude}{#1#2#3#4[#5]}
  {\@tempswatrue
  \if@partsw
    \@tempswafalse
    \edef\reserved@b{#4}%
    \@for\reserved@a:=\@partlist\do
      {\ifx\reserved@a\reserved@b\@tempswatrue\fi}%
  \fi
  \if@tempswa
    \relax\chapter#2{#1}  % \relax is there only to fool my Emacs mode
    #3
    \include#5{#4}
  \fi}  
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
%    \begin{macrocode}
%</monster|includex>
%<*monster>
%    \end{macrocode}
% \section{Copystyles}
% \begin{macro}{\Lastchange}
% \begin{macro}{\lastchange}
%  \begin{macro}{\Comments}
%  \begin{macro}{\comments}
%  \begin{macro}{\Words}
%  \begin{macro}{\words}
%  \begin{macro}{\SubTitle}
%  \begin{macro}{\subtitle}
% Comments must be one line only, no |\\|.
% The volume is kind of a catch-all piece of information.  I have used it as a
% volume, and for the name of the person to whom I am handing a paper.
%    \begin{macrocode}
\NewUserInfo\Lastchange
\NewUserInfo\Comments
\NewUserInfo\Words
\NewUserInfo\CoverNotes
\NewUserInfo\Volume
\NewUserInfo\SubTitle
%    \end{macrocode}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%  \end{macro}
% \end{macro}
% \end{macro}
%
%  \begin{macro}{\Author}
%  \begin{macro}{\author}
%  \begin{macro}{\Date}
%  \begin{macro}{\date}
%  \begin{macro}{\title}
%  \begin{macro}{\Title}
% When we redefine |\author|, |\date|, and |\title|, we add a new action to the
% original meaning.  This means that standard commands like |\maketitle| will
% still perform as expected, if someone prefers to use that instead of the
% commands in the \monster package. 
%    \begin{macrocode}
\newlet\sc@saved@author\author
\ReserveCS\Author
\renewcommand\author[1]
  {\sc@saved@author{#1}
  \renewcommand\Author{#1}}

\newlet\sc@saved@date\date
\newcommand\Date{\todayabbrev}
\renewcommand\date[1]
  {\sc@saved@date{#1}
  \renewcommand\Date{#1}}

\newlet\sc@saved@title\title
\ReserveCS\Title
\renewcommand\title[1]
  {\sc@saved@title{#1}
  \renewcommand\Title{#1}}
%    \end{macrocode}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%
%  \begin{macro}{\copywrite}
%    \begin{macrocode}
\newcommand\copywrite[1]
  {\edef\Comments{\copyright#1 All rights reserved. \Comments}}
%    \end{macrocode}
%     \subsection{ends}
%  \end{macro}
%
%  \begin{macro}{\EndSign}
% FIX: Can inhibit pagebreaking better here. 
%    \begin{macrocode}
\newcommand\EndSign
  {\nopagebreak\par\nopagebreak\vspace{2\bigskipamount}%
  \nopagebreak\hfill
  \begin{tabular}{c}%
    {\scshape\Author}\\ 
    {\smaller\itshape\Date}%
  \end{tabular}}
%    \end{macrocode}
%  \end{macro}
%
% \begin{macro}{\theend}
% User command which (almost) always makes an |\EndSign|:
%    \begin{macrocode}
\NewMonsterCommand\theend
  {\ifthenelse{\boolean{Anonymous}}
      {}
    {\EndSign}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\TheEnd}
% This is what is called at the end of a bit:
%    \begin{macrocode}
\newcommand\TheEnd
  {\ifthenelse{\equal{\CopyStyle}{prizes}   \or
      	       \boolean{Anonymous}	    \or
	       \boolean{SuppressEnds}	    \or
               \value{page} < 2}
      {}
    {\EndSign}}
%    \end{macrocode}
% \end{macro}
%     \subsection{beginnings}
%     \subsection{covers}
% We use macros instead of boxes, because at this point some of the macros in
% the boxes may change their meaning.  
%
% Algorithm: We will maintain two hboxes to textwidth each time Makecover is
% called.  Set the footboxes to |\v@idbox| here.  Whenever MakeCover is called,
% it should stack another |\vbox| with the right information in it into both
% boxes.  The information is expanded, and thus the macro contents can change
% between calls to MakeCover, but the box being built inserts two different
% |\vboxes| with their value at the moment. 
%
% \begin{verbatim}
% \newsavebox\sc@vcbox
% \newsavebox\sc@vcauthorbox
% \sbox
% \end{verbatim}
%  \begin{macro}{\sc@vbox}
%  \begin{macro}{\VersionControlBox}
%    \begin{macrocode}
\newcommand\sc@vcbox
  {\footnotesize  %  FIX do I want a relative size here?
  \ifthenelse{\equal{\Lastchange}{\@empty}}
      {}
    {\textsl{Version}: \textsf{\Lastchange}}%
  \hspace{\@ne em}%
  \textsl{Copy}: \textsf{\todayabbrev}}

\newcommand\VersionControlBox
  {\hfill \sc@vcbox \hfill}

\newcommand\VersionControlAuthorBox
    {\sc@vcbox \hfill \textsc{\Author}}

\newcommand\ps@standard
  {\let\@oddhead\@empty%
  \renewcommand\@oddfoot
    {\VersionControlAuthorBox}}

\newcommand\MakeCoverstandard
  {\thispagestyle{standard}}

\newcommand\MakeCoverblank
  {\ifthenelse{\value{page} < 2}
      {\thispagestyle{empty}}
    {}}
%    \end{macrocode}
%  \end{macro}
%  \end{macro}
% The way \LaTeXe{} makes the header is as follows: a |\vfil| is inserted, then
% the contents of |\@oddhead|.  So if we put a |\parbox| in the header, its
% baseline will be the baseline of the header box.  We assume that the top line
% of |\CommentsParBox| would normally comfortably fill the header box.  If
% that's true, then there is no wasted space between the top of the header box
% and the top of |\CommentsParBox|, if we set the contents of |\CommentsParBox|
% in a |\parbox[t]|, which is like |\vtop| because the baseline of the whole
% box is the baseline of the top line inside it.  In other words, the top line
% of |\CommentsParBox| is in the header, and everything below it extends below
% the header.  
%
% \LaTeXe{} then forces the depth of the header box to be~0, and then
% adds |\headsep| space.  We want to increase |\headsep| by the depth of
% |\CommentsParBox| (i.e., the amount that would overlap the text below the
% header box), minus the depth of the last line inside |\CommentsParBox|, which
% is the amount of normal overlap that would occur if the last line of
% |\CommentsParBox| were in the header by itself. Got all that?
%
% The depth of a |\parbox[t]| is the distance from the baseline of the first
% line inside it to the very bottom.  The depth of a |\parbox[b]| is the depth
% of the bottom line inside it.  The difference, given the same contents of
% |\CommentsParBox|, is exactly the amount we want to increase |\headsep|. 
%
%    \begin{macrocode}
\newcommand\sc@makeoddheadparbox[1]
  {\renewcommand\@oddhead
    {\parbox[t]{\textwidth}{#1}}%
  \sbox\sc@box{\parbox[t]{\textwidth}{#1}}%
  \addtolength{\headsep}{\dp\sc@box}
  \sbox\sc@box{\parbox[b]{\textwidth}{#1}}%
  \addtolength{\headsep}{-\dp\sc@box}}
%    \end{macrocode}
%
% The contents of this are set in a |\parbox|. 
%    \begin{macrocode}
\newcommand\CommentsParBox
  {\Comments	\hfill	  \textsc{\Author}\\
  \Words    	\hfill	  \texttt{\Volume}}

\newcommand\ps@comments
  {\renewcommand\@oddfoot
    {\VersionControlBox}%
  \sc@makeoddheadparbox\CommentsParBox}
%    \end{macrocode}
% This should be automatically defined?   No, maybe we want to do something
% else for MakeCover - like produce real text. 
%    \begin{macrocode}
\newcommand\MakeCovercomments
  {\thispagestyle{comments}}

% The contents of this are set in a |\parbox|. 
\newcommand\SubmissionParBox
  {\Author  	\hfill  \Comments \\
  \AddressOne	\hfill	\Words    \\
  \AddressTwo	\hfill}

\newcommand\ps@submission
  {\renewcommand\@oddfoot
    {\VersionControlBox}%
  \sc@makeoddheadparbox\SubmissionParBox}

\newcommand\MakeCoversubmission
  {\thispagestyle{submission}}

\newcommand\MakeCovercoverpage
  {\thispagestyle{empty}%
  \vspace*{\fill}%
  \begin{center}
    {\larger[5] \Title}
    \ifthenelse{\equal{\SubTitle}{\@empty}}
      	{}
      {\\ {\larger[3] \SubTitle}}
  \end{center} 
  \ifthenelse{\equal{\Volume}{\@empty}}
      {}
    {\bigskip
    \begin{center}
      \larger \scshape from \\
      \larger[4] \Volume
    \end{center}}
  \vfill\CoverNotes\vfill
  \par{\sffamily\hfill
  \begin{tabular}{r@{\hspace{\@ne em}}r}
     Copy of:&\todayabbrev\\
     Version of:&\Lastchange\\
     Date:&\Date\\      
     \multicolumn{2}{r}{\larger\scshape\rule{\z@}{6ex} \Author}
  \end{tabular}}
  \newpage
  \setcounter{page}{\@ne}}

\newcommand\MakeCoverprizes
  {\thispagestyle{empty}%
  \vspace*{\fill}%
  \begin{center}
    {\larger[5] \Title}
    \ifthenelse{\equal{\SubTitle}{\@empty}}
      	{}
      {\\ {\larger[3] \SubTitle}}
  \end{center}%
  \ifthenelse{\equal{\Volume}{\@empty}}
      {\relax}
    {\bigskip
    \begin{center}
      \larger \scshape from \\
      \larger[4] \rmfamily \Volume
    \end{center}}%
  \vfill
  \begin{flushright}
    \Comments \\
    \ \\
    {\scshape \Author} \\
    \authaddress
  \end{flushright}%
  \newpage
  \setcounter{page}{\@ne}}

\newcommand\MakeCover
  {\ifthenelse{\boolean{SuppressCover}}
      {\MakeCoverblank}
    {\csname MakeCover\CopyStyle\endcsname}}
%    \end{macrocode}
% might want to play with this
%  |\vskip \z@ plus.00006fil\relax}  (was \@textop)|
%     \subsection{letterhead}
%
%  \begin{macro}{\AddressOne}
%  \begin{macro}{\AddressTwo}
%  \begin{macro}{\PhoneNumber}
%  \begin{macro}{\Email}
%  \begin{macro}{\Country}
%  \begin{macro}{\addressone}
%  \begin{macro}{\addresstwo}
%  \begin{macro}{\phonenumber}
%  \begin{macro}{\email}
%  \begin{macro}{\country}
%    \begin{macrocode}
\NewUserInfo\AddressOne
\NewUserInfo\AddressTwo
\NewUserInfo\PhoneNumber
\NewUserInfo\Email
\NewUserInfo\Country
%    \end{macrocode}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%
%  \begin{macro}{\LetterHeadBox}
% This macro expects \Author, \AddressOne, and \AddressTwo to be nonempty.
% If any of those are blank, no error will occur, but it may look wrong. 
% \Country, \Email, and \PhoneNumber can be blank.  
%    \begin{macrocode}
\newcommand\LetterHeadBox
  {\vbox{%
    \begin{center}%
      {\larger\scshape \Author}\\
      {\smaller\sffamily 
      \AddressOne\\
      \AddressTwo 
      \ifthenelse{\equal{\Country}{\@empty}}
      	  {}
      	{\country}
      \ifthenelse{\equal{\PhoneNumber}{\@empty}}
      	  {}
        {\\ {\smaller[2] \scshape\PhoneNumber}}
      \ifthenelse{\equal{\Email}{BlankStr}}
      	  {}
        {\\{\smaller[2] \ttfamily<\Email>}}
    \end{center}}}}
%    \end{macrocode}
%  \end{macro}
%     \subsection{Story titles}
%    \begin{macrocode}
\ReserveCS\Header

\newcommand\MakeStoryTitlestandard
  {\ifthenelse{\equal{\Volume}{\@empty}}
      {\renewcommand\Header{\Title}}
    {\renewcommand\Header{\Volume}}
  \ifthenelse{\equal{\Title}{\@empty}}
      {\indent}
    {\markboth{\Header}{\Title}
    \begin{center}
    {\larger[2]\Title}
    \ifthenelse{\equal{\SubTitle}{\@empty}}
      	{}
      {\\ \SubTitle}
    \end{center}
    \whitespace\par}}

\newcommand\MakeStoryTitlesubmission
  {\ifthenelse{\equal{\Title}{\@empty}}
      {}
    {\begin{center}%
    {\larger[2]\Title}
    \ifthenelse{\equal{\SubTitle}{\@empty}}
      	{}
      {\\\SubTitle}
    \end{center}
    \par
    \whitespace}
  \ifthenelse{\equal{\Volume}{\@empty}}
      {\markboth{\Title \textit{\ by \Author}}{\Title \textit{\ by \Author}}}
    {\markboth{\Volume}{\Title \textit{\ by \Author}}}}

\newcommand\MakeStoryTitle
  {\ifthenelse{\equal{\CopyStyle}{submission}}
      {\MakeStoryTitlesubmission}     
    {\MakeStoryTitlestandard}}
%    \end{macrocode}
% \section{The principle bit styles}
% story : prose :: play : dialogue
%     \subsection{bits, bitbits, bitbitbits}
%
% The main units are bits.  To describe what happens when a bit is begun, you
% need a grid of bit styles and copy styles.
%
% Provided here are some generic commands to section bits.  The behavior of
% these does \emph{not} presently depend on the copy style or the bit style.
% It would make sense, however, to implement acts and scenes actually using
% |\bitbit| and |\bitbitbit| commands.  Perhaps I will do this in the future. 
%
% In fact, I should make these have generic names also, so that it is easy to
% define a new copystyle or a bit style, and add in as many changes from the
% standard story as necessary. 
%    \begin{macrocode}
\newcounter{bit}
\newcounter{bitbit}[bit]
\newcounter{bitbitbit}[bitbit]
%    \end{macrocode}
%
% Check definitions of these: am I being redundant? 
%
% \def\goodbreak{\par\penalty-500}
%
% \def\bigbreak{\par\ifdim\lastskip<\bigskipamount
%  \removelastskip\penalty-200\bigskip\fi }
%
% \medbreak is penalty -100 small is 50; I don't understand penalties and so
% on. 
%    \begin{macrocode}
\newcommand\InterBitBreak{\goodbreak\bigbreak}  
\newcommand\InterBitBitBreak{\goodbreak\smallbreak} 
\newcommand\InterBitBitBitBreak{\goodbreak\smallbreak}

\newcommand\bitbit
  {\@ifstar
      {\sc@bitbit{}}
    {\refstepcounter{bitbit}%
    \sc@bitbit{\thebitbit\ }}}
    
\newcommand{\sc@bitbit}[2]
  {\ifthenelse{\value{bitbit} =\@ne}
      {}
    {\InterBitBitBreak}%
  \noindent #1{\smaller\bfseries #2}\par
  \smallskip}

\newcommand\bitbitbit
  {\@ifstar
      {\sc@bitbitbit{}}
    {\refstepcounter{bitbitbit}%
    \sc@bitbitbit{\thebitbitbit\ }}}
    
\newcommand{\sc@bitbitbit}[2]
  {\ifthenelse{\value{bitbitbit} =\@ne}
      {}
    {\InterBitBitBitBreak}%
  \noindent #1{\smaller\bfseries #2}\par
  \smallskip}

\newcommand\BitHook
  {\refstepcounter{bit}
  \ifthenelse{\equal{\Title}{\@empty}}
      {}
    {\ifthenelse{\boolean{BitContents}}
       {\addtocontentsline{toc}{\Title}{\level}}
      {}}
  \ifthenelse{\value{bit} =\@ne}
      {\MakeCover}
    {\InterBitBreak}}
%    \end{macrocode}
%     \subsubsection{story and prose}
%    \begin{macrocode}
%  \begin{environment}{story}
\ReserveCS\PreStory
\newenvironment{story}[1]
    {\@ifnextchar[{\sc@beginstory{#1}}{\sc@beginstory{#1}[]}}
  {\TheEnd}

\NewNameDef{sc@beginstory}{#1[#2]}
  {\title{#1}
  \subtitle{#2}
  \stepcounter{bit}
  \ifthenelse{\value{bit} =\@ne}
      {\MakeCover}
    {\InterBitBreak}
  \PreStory
  \MakeStoryTitle}

\newcommand\PreProse{\PreChunk}
\newenvironment{prose}[1]
    {\title{#1}%
    \stepcounter{bit}%
    \ifthenelse{\value{bit} =\@ne}
        {\MakeCover}
      {\InterBitBreak}%
    \PreProse
    \MakeProseTitle}
  {\TheEnd}

\newcommand\MakeProseTitle
  {\ifthenelse{\equal{\Title}{\@empty}}
      {}
    {{\larger\bfseries\noindent\Title}\par\smallskip}}
%    \end{macrocode}
%     \subsection{script and play}
%       \subsubsection{characters}
%    \begin{macrocode}
\newcommand\ReferStyle
  {\scshape}

\newcommand\refer{}  % next command only logs a warning if already defined
\DeclareTextFontCommand\refer\ReferStyle
%    \end{macrocode}
% only in preamble!

% Example:  |\newcharacter{ap}{Appleby}{Appleby, his father}|
% First line of |\character| definition defines the new command sequence
%       |\ap|
% The next line defines
%       |\apsays|
% The next line defines
%       |\charnum<num>|   where |<num>| is a digit n if Appleby is the nth
%                       character (starting with 0).

%    \begin{macrocode}
\newcommand\SpeakAppend
  {says}
\newcommand\sc@cast{}
\newcommand\newcharacter[3]
  {\expandafter\NewTextMacro\csname #2\endcsname{\scshape}{#1}%
  \expandafter\newcommand\csname #2\SpeakAppend\endcsname{\speak{#1}}%
  \addto@macro\sc@cast{,#3}}

% The \@cdr gets rid of the first silly comma.

\newcommand\DramPer
  {\ifthenelse{\equal{\sc@cast}{\@empty}}
      {}
    {\expandafter\Elet\expandafter\sc@t@a\expandafter\@cdr\sc@cast\@nil
    \let\sc@cast\sc@t@a
    {\larger\scshape Cast}
    \begin{verse}
    \expandafter\@for\expandafter\sc@t@a\expandafter:\expandafter=\sc@cast
      \do {\sc@t@a\\}
    \end{verse}%
% Prepare for another set of characters.
    \renewcommand\sc@cast{}%
    \bigbreak}}
%    \end{macrocode}
%       \subsubsection{sectioning}
%
% |play|s and |script|s are bits, acts are bitbits, scenes are bitbitbits
% We don't use the generic |\bitbit| and |\bitbitbit| sectioning
% command, but perhaps we should. 
%
% We pull some fancy stuff with the output routine here.  The algorithm is a
% simpler version of Knuth's \cite[260ff]{texbook}.
%    \begin{macrocode}
\newtokens\sc@toks@saved@output
\sc@toks@saved@output=\output
%    \end{macrocode}
%
% The |\sc@botmark|, if not empty, will contain text to be inserted at the top
% of the next page. It must contain vertical not horizontal material. 
%
% We actually need to communicate the boolean |sc@directing| via the mark,
% because only the information in the marks is guaranteed to reflect the state
% at the end of the page, and not several lines later.   What is it with
% expanding the mark that is so tricky with |\ifthenelse|? A pain in the neck!
%    \begin{macrocode}
\newcommand\sc@outputwrapper
  {\setlength{\sc@len}{\dp255}%
  \the\sc@toks@saved@output
  \ifthenelse{\equal{\sc@botmark}{\@empty}\or\boolean{sc@directing}}
      {}
    {\sc@botmark
    \addtolength{\sc@len}{-\prevdepth}%
    \kern\sc@len}}

\newcommand\script
  {\MakeDirectTakeArg
  \relax\begin{sc@script}} % \relax only for my emacs
\NewNameDef{endscript}{}
  {\end{sc@script}}
\NewNameDef{script*}{}
  {\MakeDirectTakeNoArg
  \relax\begin{sc@script}} % \relax only for my emacs
\NewNameDef{endscript*}{}
  {\end{sc@script}}

\newenvironment{sc@script}[1]
    {\title{#1}%
    \ClaimXMarkTwo
    \PackageInfo{monster}{The script environment is changing \protect\output.}
    \output={\sc@outputwrapper}%
    \let\maxdepth\maxdimen
    \let\@maxdepth\maxdimen
    \renewcommand\thepage
      {\arabic{bitbit}--\arabic{bitbitbit}\hspace{\@ne em}\arabic{page}}%
    \refstepcounter{bit}%
    \ifthenelse{\value{bit} =\@ne}
        {\MakeCover}
      {\InterBitBreak}
    \MakeStoryTitle
    \DramPer}
  {\sc@possiblyfinishdirecting
  \TheEnd
  \PackageInfo{monster}{\protect\output is back to normal now.}}

\newcommand\act
  {\sc@possiblyfinishdirecting%
  \sc@mark{\@empty}%
  \stepcounter{bitbit}%
  \pagebreak[3]\bigbreak
  \centerline{\larger[2] Act \thebitbit}%
  \nopagebreak\smallskip}

\newcommand\scene
  {\sc@possiblyfinishdirecting
  \sc@mark{\@empty}%
  \stepcounter{bitbitbit}%
  \pagebreak[3]\bigbreak
  \centerline{\larger Scene \thebitbitbit}%
  \nopagebreak\smallskip}

\newcommand\oneact
  {\renewcommand\thepage
    {\arabic{bitbitbit}\hspace{\@ne em}\arabic{page}}}
%    \end{macrocode}
%       \subsubsection{speakers and stage directions}
%    \begin{macrocode}
\newlength{\halfacross}
  \setlength{\halfacross}{\textwidth}
  \divide\halfacross by 2
\newlength{\quarteracross}
  \setlength{\quarteracross}{\textwidth}
  \divide\quarteracross by 4

\newenvironment{DramaTab}[1]
    {\begin{list}{}
      {\setlength{\leftmargin}{#1}%
      \setlength{\listparindent}{\z@}%
      \sloppy}%
        \item\relax}
  {\end{list}}

\newcommand\DirectStyle
  {\smaller\slshape}

% The |\relax|es eat leading and trailing whitespace.
\newcommand\setstage[1]
  {\begin{DramaTab}{\halfacross}%
      \DirectStyle
      \DirectOpen
      \ignorespaces
      #1\unskip
      \DirectClose
  \end{DramaTab}}
%    \end{macrocode}
%
% It is a question of style whether to announce the speaker's name a second
% time, if his speech continues after a stage direction in a paragraph by
% itself.  If the page breaks immediately before the stage direction, or
% duringit, no continuation message will be given.  If it breaks after the
% stage direction, and before the next speaker is announced with the |\speak|
% command, a continuation message appropriate to the speaker \emph{before} the
% stage direction is given.  Of course, sectioning commands will cancel any
% continuation messages. 
%
% Communicating via the mark is giving me a problem. |\ifthenelse| can't
% recognize whatever I do, it seems.   I need to solve this problem and replace
% sc@boolean with mark information. 
%
% Also, when using the no-argument form on a source with arguments, you cannot
% swallow the spaces with |\ignorespaces|, because the open brace shields them.
%
% There are problems with certain combinations of taking arguments and
% reannouncing speakers after a stage direction.  I should draw a chart, and
% see how I can handle things.  
%    \begin{macrocode}
\newcommand\DirectOpen
  {\textrm{(}}
\newcommand\DirectClose
  {\textrm{)}}
%    \end{macrocode}

%    \begin{macrocode}
\newcommand\DirectNoArg
  {\sc@noargs@finishdirecting
  \sc@direct}

\newcommand\DirectWithArg[1]
  {\sc@args@finishdirecting
  \sc@direct
  #1%
  \sc@really@finishdirecting}

\newboolean{sc@directing}

\newcommand\sc@direct
  {\global\let\sc@lastmark\sc@themark
  \sc@mark{\@empty}%
  \setboolean{sc@directing}{true}%
  \pagebreak[0]% mild encouragement
  \begin{DramaTab}{\quarteracross}%
    \DirectStyle\DirectOpen\ignorespaces}

\newcommand\sc@really@finishdirecting
  {\unskip
  \DirectClose
  \end{DramaTab}
  \setboolean{sc@directing}{false}%
  \sc@mark\expandafter{\sc@lastmark}}

\newcommand\sc@args@finishdirecting
  {}
\newcommand\sc@noargs@finishdirecting
  {\ifthenelse{\boolean{sc@directing}}
      	{\sc@really@finishdirecting}
    {\relax}}

\ReserveCS\direct
\ReserveCS\sc@possiblyfinishdirecting
\newcommand\MakeDirectTakeArg
  {\let\sc@possiblyfinishdirecting\sc@args@finishdirecting
  \let\direct\DirectWithArg}
\newcommand\MakeDirectTakeNoArg
  {\let\sc@possiblyfinishdirecting\sc@noargs@finishdirecting
  \let\direct\DirectNoArg}
%    \end{macrocode}
%
% Could possibly do penalties better.  Adding a |\nopagebreak\relax| at the end
% bombed.
%
% \TeX's |\centerline| is just too elegant to avoid here.
%    \begin{macrocode}
\newcommand\GiveSpeaker[1]
  {\centerline{\textsc{#1}}}
%    \end{macrocode}
%
% \TeX's |\rlap| is just too elegant to avoid here.
% The space is explicit just for clarity.
%    \begin{macrocode}
\newcommand\GiveSpeakerContinued[1]
  {\GiveSpeaker{#1\space\rlap{\textsl{(continued)}}}}
%    \end{macrocode}
%
% I will have to review where exactly page breaks can occur in a vertical list,
% to do the penalties and vspace right here.
%    \begin{macrocode}
\newcommand\speak[1]
  {\sc@possiblyfinishdirecting
  \sc@mark{\@empty}%
  \pagebreak[2]\smallbreak
  \sc@mark{\GiveSpeakerContinued{#1}}%
  \GiveSpeaker{#1}%
  \nopagebreak\par\noindent}
%    \end{macrocode}
%     \subsection{dramatic verse}
%
% The |dverse| environment, short for ``dramatic verse,'' is a primitive
% environment.  In particular, it doesn't handle lines that are too long.
% |\@vobeyspaces| is stolen from the standard |verbatim| environment, from
% which a lot more ideas should be taken.  The goal of this environment is to
% provide a verbatim environment, but with provision for stage directions.
%
% Customization: 
%
% |\DVStyle| and |\DVBegin| are both executed at the beginning of the
% environment.  Use the first for formatting the environment, and the second
% for separating it from earlier text.
%
% |\DVDirect| is invoked by a |\direct| in the environment. It handles the
% stage directions.  Right now, it pushes them flush right and invokes
% |\DVCommentStyle|.
%
% |\DVEnd| is invoked at the close of the environment.
%
% Each line is its own group.  By doing this, we get away without containing
% the stage directions in an explicit group.  
%
% Comments work. Blank lines are swallowed. Penalties and interline spacing are
% probably not so great. 
%
% would begingroup endgroups work just as well?
%    \begin{macrocode}
\newcommand\DVStyle
  {\setlength{\parindent}{\z@}
  \normalfont}
\newcommand\DVDirectStyle{\normalfont\slshape}
\newcommand\DVDirect{\hfill\DVDirectStyle}
\newcommand\DVBegin{\smallskip}
\newcommand\DVEnd{\smallskip}
\newcommand\DVSpeakStyle{\normalfont\scshape}
\newcommand\DVSpeak[1]
  {\DVSpeakStyle\hfill#1\hfill}
\newenvironment{dverse}
    {\DVBegin
    \DVStyle
    \let\speak\DVSpeak
    \everypar={\egroup\bgroup\@vobeyspaces}%
    \let\direct\DVDirect
    \obeylines\bgroup}
  {\egroup\DVEnd}
%    \end{macrocode}
%\begin{dverse}
%
%This is line one.  % Blank lines don't print. This can be fixed. 
%
%This is line two, after a blank line. 
%This is line three with a        gap.
%  This is line three starting after two spaces. 
%This is line four with a direction. \\ stage direction
%This is line five also with a stage direction.       \direct   Get off stage!
%This is line six, which is very very very very %  This is still a comment!
%very very very very very very very very long!
%\end{dverse}
%     \subsection{poetry}

% Algorithm for end-of-line line numbers.

% A \textsl{roller} is a queue with a fixed number of elements.
% \textsl{Rolling} a roller once puts the front element at the end of the
% queue.

% Rollers are implemented as command sequences which when expanded \emph{once}
% are token lists.  The tokens are the elements of the queue.  The one roller
% we make has two kinds of elements, which are the contents of the following
% two macros.  Since we are going to refer to them by these macros, their
% contents can be anything that will expand to a single distinct character.
% Letters, whitespace, and punctuation characters will probably all work, but
% I haven't thought through anything but letters.
%    \begin{macrocode}
\newcommand\PrintLN{z}
\newcommand\NoPrintLN{a}
%    \end{macrocode}
%
% All the elements of this roller are |\NoPrintLN| elements except for one
% |\PrintLN| element, which begins at the back.  At every linebreak we roll the
% roller. The one |\PrintLN| element will be at the front once every $n$ lines,
% where $n$ is the number of elements in the roller.  This will be the signal
% to print a line number. 
%
% |\MakeRoller{\foo}|\marg{n} makes |\foo| a roller with \meta{n} elements.
% No check is made to see if |\foo| is already defined. 
% For the moment, I have not generalized the idea of rollers very far, and so
% |\MakeRoller| only makes a roller suitable for the line numbering mechanism.
%
% |\edef|'ing |\sc@t@a| the way we do is different than using
% |\g@addto@macro| because what gets added is being expanded.
%    \begin{macrocode}
\newcommand\MakeRoller[2]
  {\InitCS\sc@t@a
  \setcounter{sc@count}{#2}%
  \@whilenum \value{sc@count} >\@ne 
    \do {\edef\sc@t@a{\sc@t@a\NoPrintLN}%
        \addtocounter{sc@count}{\m@ne}}
  \edef\sc@t@a{\sc@t@a\PrintLN}%
  \edef#1{\sc@t@a}}
%    \end{macrocode}
%
% We want the |LineNumber| counter to be a local counter, so we use a \TeX\
% counter.  We initialize to 1 not 0, so that the counter is correct at at the
% beginning of the line all the way through until the |\\|.
%    \begin{macrocode}
\newcommand\LineNumber{}
\newcount\LineNumber
  \LineNumber\@ne 
%    \end{macrocode}
%
% |\setlinenumber|\marg{num} sets |LineNumber| to \meta{num}.  It also rolls
% the roller into the right position, so that if we are numbering every 10th
% line, and at the beginning of the environment we say |\setlinenumber{97}|,
% the lines $100, 110,\ldots$ get numbered, not $107, 117, \ldots$.  If we are
% numbering every $k$th line, the right position is the one rolled
% $(\mbox{\meta{num}} \bmod k) - 1$ times from the line 1 position.
%
% The real line number is in argument \#1.  We borrow |\LineNumber| as a
% temporary counter, since we are about to change it anyway, and |\mod| uses
% |\sc@count|.
%    \begin{macrocode}
\newcommand\setlinenumber[1]
  {\MakeRoller\Roller{\LNInterval}
  \ifthenelse{#1 =\@ne}
      {\relax}
    {\LineNumber = \mod{#1}{\LNInterval}%
    \@whilenum \LineNumber >\@ne 
      \do {\Roll\Roller
          \advance\LineNumber by \m@ne}}
  \LineNumber = #1}
%    \end{macrocode}
%
% I don't think we have to worry about line numbers being too large for
% a counter.    This should be a local counter, as should many of these
% temporary variables. 
%    \begin{macrocode}
\newcommand\mod[2]
  {\setcounter{sc@count}{#1}%
  \@whilenum \value{sc@count} < #2
    \do {\addtocounter{sc@count}{-#2}}
  \value{sc@count}}

\newcommand\LineNumStyle
  {\scriptsize}
\newcommand\DefaultLNInterval
  {10}
\newcommand\LNInterval
  {\DefaultLNInterval}
\newcommand\Roller{}

% You may use |\numberevery| repeatedly and it should do the right thing.
\newcommand\numberevery[1]
  {\renewcommand\LNInterval{#1}%
  \MakeRoller\Roller{\LNInterval}%
  \setlinenumber{\LineNumber}}

\numberevery{\DefaultLNInterval}

% We initialize these to a default value just in case |\stopnumbering| is every
% called in an inappropriate place.
\newcommand\sc@saved@cr
  {\\}
\newtokens\sc@saved@everypar
  \sc@saved@everypar=\everypar
%    \end{macrocode}
%
% The effect of |\startnumbering| will end with its current group or
% |\stopnumbering|, whichever comes first.
%    \begin{macrocode}
\newcommand\righthandlinenumbers
  {\AssignStarNoStar\startnumberinglines%
    {\sc@numberlines@left}{\sc@numberlines@right}}
\newcommand\lefthandlinenumbers
  {\AssignStarNoStar\startnumberinglines%
    {\sc@numberlines@right}{\sc@numberlines@left}}

\ReserveCS\startnumberinglines
\righthandlinenumbers
%    \end{macrocode}
%
% I think these should be done entirely on the basis of LaTeX |\list| or
% |\trivlist| environments.  
%
% for left numbers:
% \begin{verbatim}
% \makelabel {\llap{\number\LineNumber\hspace{\@ne em}}}
% \let\\={step line num ; \sc@saved@cr }
% get an \ifthenelse into everypar
% \end{verbatim}
%    \begin{macrocode}
\newcommand\sc@numberlines@right
  {\let\sc@saved@cr\\%
  \sc@saved@everypar=\everypar
  \everypar=\expandafter{\the\sc@saved@everypar\advance\LineNumber by\@ne}
  \renewcommand{\\}
    {\edef\sc@t@a{\expandafter\@car\Roller\@nil}  % put into \equal?
    \Roll\Roller
    \advance\LineNumber by\@ne
    \ifthenelse{\equal{\sc@t@a}{\PrintLN}}
        {\hspace*{\fill}%
        {\LineNumStyle\relax\number\LineNumber}}
      {\relax}%
    \sc@saved@cr}}

\newboolean{sc@doln}
\newcommand\sc@numberlines@left
  {\let\sc@saved@cr\\%
  \sc@saved@everypar=\everypar
  \everypar=\expandafter{\the\sc@saved@everypar\advance\LineNumber by\@ne
                         \ifthenelse{\boolean{sc@doln}}
                             {\llap{+\number\LineNumber\hspace{\@ne em}}}
                           {\llap{!\number\LineNumber\hspace{\@ne em}}}}
  \renewcommand{\\}
    {\Roll\Roller
    \edef\sc@t@a{\expandafter\@car\Roller\@nil}  % put into \equal?
    \advance\LineNumber by\@ne
    \ifthenelse{\equal{\sc@t@a}{\PrintLN}}
        {\setboolean{sc@doln}{true}}
      {\setboolean{sc@doln}{false}}
    \sc@saved@cr \sc@saved@cr}}

\newcommand\stopnumberinglines
  {\let\\\sc@saved@cr
  \everypar=\sc@saved@everypar}

% |\Roll|\marg{roller} moves the front element of \meta{roller} to the back.
\newcommand\Roll[1]
  {\edef#1{\expandafter\sc@roll #1\sc@llor}}
\newcommand\sc@roll{}
\newcommand\sc@llor{}
\def\sc@roll#1\sc@llor{%
  \@cdr#1\@nil\@car#1\@nil}

\newcommand\makethisspace[1]
  {\settowidth{\sc@len}{#1}%
  \hspace*{\sc@len}}

\newcommand\dropline[2]
  {\settowidth{\sc@len}{#1}%
  #1\\\hspace*{\sc@len}#2}

\newcommand\PrePoem{\PreChunk}
\newenvironment{poem}[2]
    {\title{#1}%
    \subtitle{#2}%
    \stepcounter{bit}%
    \ifthenelse{\value{bit} =\@ne}
        {\MakeCover}
      {\InterBitBreak}%
    \PrePoem
    \MakePoemTitle
    \begin{verse}}
  {\end{verse}%
  \TheEnd}
                                        
\newcommand\MakePoemTitle
  {\ifthenelse{\equal{\Title}{\@empty}}
      {}
    {\begin{verse}%
    \hspace*{-.3em} %to compensate for either \bf or \large
                    %or both, I don't know
    {\larger\bfseries\Title}
    \ifthenelse{\equal{\SubTitle}{\@empty}}
        {}
      {\\ \SubTitle}
    \end{verse}}}
%    \end{macrocode}
%     \subsection{letter and epistle}
% The |letter| environment looks very much same as the standard |letter|
% environment in the standard letter class.  A lot of the code is from that
% class, but I have made it work as a bit style.  In particular, this means you
% can use |\includebits| to include a file that was written for the standard
% letter class, if you desire.  
%
% If you use the \monster package with the standard letter class, the
% \monster package will disable its own |letter| environment.  It does qnot
% make sense to have them both available.    Abstractly, the standard letter
% class should be emulated as a copy style, since it is a way of collecting
% bits together.  
%
% The contents of a |letter| environment should be set properly by an |epistle|
% environment, too.  The \monster package can be used with the letter class.
% Within the |epistle| environment, certain user commands in the letter class
% are redefined, and will behave slightly differently than those in the letter
% class, but their usage does not change.
%
%  (This code is based on |letter.cls 1.2n|.)
%
% only put redef's into epistle.
%
% aak!
%    \begin{macrocode}
\newcommand\Signature{}
%\newenvironment{epistle}
%  {\renewcommand\signature[1]}
 %   {\renewcommand\Signature{#1}}
  %\newcommand\FromAddress{\Author \\
   %   	      	        \AddressOne \\
%      	      	        \AddressTwo}

\newcommand\fromaddress[1]
  {\renewcommand\FromAddress{#1}}
\newcommand\ToAddress{}
\newcommand\toaddress[1]
  {\renewcommand\ToAddress{#1}}
\newcommand\CcName{cc} 
\newcommand\EnclName{encl}
\newcommand\PageName{Page}
\newcommand\HeadToName{To}
%    \end{macrocode}
%
% the processing takes |\address| and makes |\fromname| and |\fromaddress|. 
% these
%    \begin{macrocode}
\newcommand\stopepistle{}

\newenvironment{epistle}[1]
  { \newpage
    \if@twoside \ifodd\c@page
                \else\thispagestyle{empty} \hbox{}\newpage\fi
    \fi
    \c@page\@ne
    \interlinepenalty200 % smaller than the TeXbook value
    \@processto{\leavevmode\ignorespaces #1}}
  {\stopepistle\@@par\pagebreak\@@par
    \if@filesw
      \begingroup
        \let\\\relax
        \def\protect##1{\string##1\space}%
          \immediate\write\@auxout
            {\string\@mlabel{\returnaddress}{\toname\\\toaddress}}%
      \endgroup
    \fi}

\newcommand\@processto[1]
  {\@xproc #1\\@@@\ifx\toaddress\@empty
    \else \@yproc #1@@@\fi}

\long\def\@xproc #1\\#2@@@{\renewcommand\toname{#1}\renewcommand\toaddress{#2}}
\long\def\@yproc #1\\#2@@@{\renewcommand\toaddress{#2}}

\newcommand\stopbreaks
  {\interlinepenalty \@M
   \def\par{\@@par\nobreak}\let\\\@nobreakcr
   \let\vspace\@nobreakvspace}
\newcommand\@nobreakvspace
  {\@ifstar{\@nobreakvspacex}{\@nobreakvspacex}}
\newcommand\@nobreakvspacex[1]
  {\ifvmode\nobreak\vskip #1\relax\else
  \@bsphack\vadjust{\nobreak\vskip #1}\@esphack\fi}
\newcommand\@nobreakcr
  {\vadjust{\penalty\@M}\@ifstar{\@xnewline}{\@xnewline}}
\newcommand\startbreaks
  {\let\\\@normalcr
   \interlinepenalty 200\def\par{\@@par\penalty 200\relax}}

\newlength\longindentation
  \setlength{\longindentation}{.5\textwidth}
\newlength\indentedwidth
  \setlength{\indentedwidth}{\textwidth}
  \addtolength{\indentedwidth}{-\longindentation}

\newcommand\opening[1]
  {{\raggedleft
    \begin{tabular}{l}%
      \ignorespaces
      \FromAddress \\*[2\parskip]%
      \Date
    \end{tabular}%
  \par}%
  \vspace{2\parskip}%
  {\raggedright
    \ToName \\ \ToAddress 
  \par}%
  \vspace{2\parskip}%
  #1\par\nobreak}

\newcommand\closing[1]
  {\par\nobreak\vspace{\parskip}%
  \stopbreaks
  \noindent
  \hspace*{\longindentation}
  \parbox{\indentedwidth}{\raggedright
       \ignorespaces #1\\[6\medskipamount]%
       \ifx\@empty\fromsig
           \FromName
       \else \Signature \fi\strut}%
   \par}

\newcommand\cc[1]
  {\par\noindent
  \parbox[t]{\textwidth}{\@hangfrom{\reset@font\rm \ccname: }%
                       \ignorespaces #1\strut}\par}
\newcommand\encl[1]
  {\par\noindent
  \parbox[t]{\textwidth}{\@hangfrom{\reset@font\rm \enclname: }%
                       \ignorespaces #1\strut}\par}

\newcommand\ps
  {\par\startbreaks}
%    \end{macrocode}
% \section{Bibliography and citation}
%     \subsection{Credits}
% 
% \Author{} wrote \monster  incorporating |chicago{,a}.bst| and |chicago.sty| 
% (v4, 92/8).
%
% Glenn Paulley |<gnpaulle@bluebox.uwaterloo.ca>| (Data Structuring Group;
% Department of Computer Science; University of Waterloo; Waterloo, Ontario
% Canada; N2L 3G1; tel 519/885--1211, fax 519/885--1208) wrote
% |Chicago{,a}|.bst based on |newapa.bst|.
%
% Steven N.~Spencer wrote |newapa.bst| based on |plain.bst|, |named.bst|, and
% |apalike.bst|, with contributions from Young Ryu, Brain Reiser.
%
% |plain.bst| was written by the author of \BibTeX, Oren Patashnik?
%     \subsection{Code}
% The majority are specific for the \emph{Chicago Manual}-based bibliography
% style, |achicago.bst|, supplied with the \monster package.  Much of this
% section will be skipped if the |stdbib| option has been given.
%
% |\citework| is supposed to be a general command for citing things declared
% with |\newwork|.  It has one optional and one required argument so that it is
% parallel with the other citing commands, but I cannot see any use for it
% without the optional argument.  Environments can exert complete control over
% how this macro looks by resetting the three parameters.  The default will
% look good outside all environments, in running text.
%
% The second argument is expected to be something defined with |\newwork|.  
% 
% Frank G Bennett, Jr
% Law Department, SOAS, London
% Tel: (071)323-6351
% email: fbennett@rumple.soas.ac.uk
%
% An incomplete but definitely testable package of enhanced bibliography code
% is available for anonymous FTP from rumple.soas.ac.uk.  The relevant files
% there are: camel.doc, law.doc and camelman.ps.  The first two are both
% necessary if you want to run the style and see what it can do.  If you just
% want to look at the documentation, fetch camelman.ps instead.
%
%
% Be careful what is put into the internal macros, because they are rammed up
% against user text without a |\relax|.  
%
% Needs modification to hand the empty optional arg.  Watch interfering with
% things surrounding macros might have set. |\relax|'s are intentionally left
% out to let constructions like |\csname| \lips |\endcsname| work on the
% arguments. 
%    \begin{macrocode}
\newcommand\PreCiteWork{(\csname}
\newcommand\PostCiteWork{)}
\newcommand\MidCiteWork{\endcsname, }
\newcommand\citework[2]
  {\PreCiteWork#2\MidCiteWork#1\PostCiteWork}
%    \end{macrocode}
%
% We want the remaining macros in this section to be available in their own
% piece. 
%    \begin{macrocode}
%</monster>
%<*monster|achicagosty>
%    \end{macrocode}
%
%  \begin{macro}{\sc@q@check}
%  \begin{macro}{\sc@q@ifnextchar}
%  \begin{macro}{\sc@q@ifnch}
%  \begin{macro}{\sc@q@handle@single}
%  \begin{macro}{\sc@q@handle@double}
% These macros are modeled after the definition of |\@ifnextchar| which skips
% spaces.  These skip spaces, |\egroup|, |\endgroup|, |\SCclosedoublequote| and
% |\SCclosesinglequote|, doing the right thing after each. 
%    \begin{macrocode}
\newcommand\sc@q@check
  {\futurelet\sc@t@c\sc@q@ifnch}
%    \end{macrocode}
% These have to be global because we want to continued our look-ahead past ends
% of groups. 
%    \begin{macrocode}
\newcommand\sc@q@ifnextchar[3]
  {\global\let\sc@t@e=#1%
  \gdef\sc@t@a{#2}%
  \gdef\sc@t@b{#3}%
  \sc@q@check}

\newcommand\sc@q@ifnch
  {\ifx \sc@t@c \@sptoken \let\sc@t@d\sc@q@xifnch \else
    \ifx \sc@t@c \endgroup 
        \def\sc@t@d{\aftergroup\sc@q@check}\else
      \ifx \sc@t@c \egroup  
          \def\sc@t@d{\aftergroup\sc@q@check}\else
        \ifx \sc@t@c \SCclosedoublequote 
            \let\sc@t@d\sc@q@handle@double\else
          \ifx \sc@t@c \SCclosesinglequote
              \let\sc@t@d\sc@q@handle@single\else
            \ifx \sc@t@c \sc@t@e \let\sc@t@d\sc@t@a \else
              \let\sc@t@d\sc@t@b
            \fi
          \fi
        \fi
      \fi
    \fi
  \fi
  \sc@t@d}

\NewNameDef{sc@q@handle@double}{\SCclosedoublequote}
  {\g@addto@macro\sc@t@f{\,''}%
  \sc@q@check}

\NewNameDef{sc@q@handle@single}{\SCclosesinglequote}
  {\g@addto@macro\sc@t@f{\,'}%
  \sc@q@check}
%    \end{macrocode}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%
%  \begin{macro}{\sc@q@xifnch}
% This little bit of trickery sneaks a space in as the |\def| template, thereby
% causing a following space to get gobbled.
%    \begin{macrocode}
\ReserveCS\sc@q@xifnch
\let\sc@t@b\:
\def\:{\sc@q@xifnch} \expandafter\def\: {\sc@q@check}
\let\:\sc@t@b
%    \end{macrocode}
%  \end{macro}
%  \begin{macro}{\SCclosedoublequote}
%  \begin{macro}{\SCclosesinglequote}
%  \begin{macro}{\sc@closequote}
% Here we define the two user commands to close a single or double quote,
% sucking a following comma or period inside them as necessary, and creating
% the right space inbetween successive punctuation.
%    \begin{macrocode}
\newcommand\SCclosedoublequote
  {\gdef\sc@t@f{''}%
  \sc@closequote}
\newcommand\SCclosesinglequote
  {\gdef\sc@t@f{'}%
  \sc@closequote}
\newcommand\sc@closequote
  {\sc@q@ifnextchar .
      {.\sc@t@f\@gobble}
    {\sc@q@ifnextchar ,
        {,\sc@t@f\@gobble}
      {\sc@t@f\space}}}
%    \end{macrocode}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%
%  \begin{macro}{\majortitle}
%  \begin{macro}{\minortitle}
%  \begin{macro}{\SCTITdoublequote}
%  \begin{macro}{\SCTITsinglequote}
% Now we define wrappers for titles within titles, and two common functions
% that might be used as the wrapper; |\emph| is a third.  These will do the
% right thing when nesting, and take advantage of the quote-closing macros that
% we just defined.
% 
% These commands is most useful for including directly into the |.bib|
% database.  The bibstyle can alter the definition as appropriate for different
% entry types.  The |achicago| bibstyle assumes that the global definitions of
% |\majortitle| and |\minortitle| are appropriate for an emphasized top-level
% title.  Top-level emphasis is done with |{\em }| and not with |\emph| because
% |\emph| screws up the macros hereabouts.  If you discover a need for italic
% correction around the entire title, let me know and I'll work on resolving
% the conflict. 
%    \begin{macrocode}
\newcommand\SCTITdoublequote[1]
  {\begingroup
  \let\majortitle\SCTITsinglequote
  \let\minortitle\SCTITsinglequote
  ``#1\SCclosedoublequote
  \endgroup}
\newcommand\SCTITsinglequote[1]
  {\begingroup
  \let\majortitle\SCTITdoublequote
  \let\minortitle\SCTITdoublequote
  `#1\SCclosesinglequote
  \endgroup}
\newlet\majortitle\emph
\newlet\minortitle\SCTITdoublequote
%    \end{macrocode}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%  \end{macro}
% 
%    \begin{macrocode}
%<*!achicagosty>
\ifthenelse{\not\boolean{Achicago}}
    {}   % do nothing
%    \end{macrocode}
% The clause beginning here is very long, and the final |}| is way down.
%    \begin{macrocode}
  {%
%</!achicagosty>
  \AtBeginDocument{\bibliographystyle{achicago}}  
%    \end{macrocode}
%
% The |achicago| bibliography style will insert some macros that are not
% defined by \LaTeX, and some that must have new meanings.  They are:
% |\begin{thebibliography}|, |\end{thebibligraphy}|, |\bibitem|, |\citeN|,
% |\SCcite|, |\SCduplicate|,  |\SCduplicate|,
% |\begin{SCannotation}|, |\end{SCannotation}|
%
% Some of these commands should properly have |@| in their names, but
% |@|-commands cannot appear in the |.bbl| file.  As a compromise, the names
% have the prefix |SC|. 
%
%  \begin{macro}{\SCduplicate}
% The argument will contain the actual `long.label' that is a duplicate, in
% case it might ever be of use.  But for now, we just want to replace
% duplicates with 3-em dashes.  FIX: we could for example make this print its
% argument if it is occurring at the top of a column or page, or just the top
% of a left-hand column on a left-hand page. 
%    \begin{macrocode}
\newcommand\SCduplicate[1]
  {\sc@mmmdash}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\sc@mmmdash}
% A 3em-dash.
%    \begin{macrocode}
\newcommand\sc@mmmdash
  {\rule[.6ex]{3em}{.03ex}}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\PreAnnotation}
%  \begin{environment}{SCannotation}
% This sets up the |SCannotation| environment.  When the boolean |Annotate| is
% false, we gobble everything between |\begin{SCannotation}| and
% |\end{SCannotation}|.
%    \begin{macrocode}
\newcommand\PreAnnotation
%<!achicagosty>{\PreChunk}
%<achicagosty>{}
\newenvironment{SCannotation}
    {\ifthenelse{\boolean{Annotate}}
      	{\let\PreQuotation\PreAnnotation
      	\relax\begin{quotation}}  % \relax only for my emacs
      {\sc@begingobble}}
  {\ifthenelse{\boolean{Annotate}}
      {\end{quotation}}
    {\sc@endgobble}}
%    \end{macrocode}
%  \end{environment}
%  \end{macro}
%
%  \begin{macro}{\SCcite}
%  \begin{macro}{\sc@one@three}
%  \begin{macro}{\sc@two@three}
% |\SCcite| is what |achicago.bst| produces.  Its args are `long.label',
% `short.label', and `year.label'.
%    \begin{macrocode}
\ReserveCS\SCcite

\newcommand\sc@one@three[3]{#1}
\newcommand\sc@two@three[3]{#2}
%    \end{macrocode}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%
% This spits out arguments |#1| and |#3| with |#2| intervening iff
% |\@tempswatrue|.
%\begin{verbatim}
% \newcommand\sc@citeformat[3]
%  {\renewcommand\@cite[2]{#1\if@tempswa#2\fi#3}
%\end{verbatim}
%
%  \begin{macro}{\PreCite}
%  \begin{macro}{\PostCite}
% Should have one single command be what each of the following executes.  Its
% arguments determine what all the other stupid things do. 
%    \begin{macrocode}
\newcommand\PreCite{(}
\newcommand\PostCite{)}
%    \end{macrocode}
%  \end{macro}
%  \end{macro}
%
%  \begin{macro}{\cite}
%  \begin{macro}{\citeNP}
%  \begin{macro}{\citeA}
%  \begin{macro}{\citeN}
%  \begin{macro}{\citeANP}
% |\PreCite1[, 2]\PostCite  \sc@citeformat{\PreCite##1}{, ##2}{\PostCite}|
%    \begin{macrocode}
\renewcommand\cite
  {\renewcommand\@cite[2]
    {\PreCite##1\if@tempswa , ##2\fi\PostCite}%
  \renewcommand\SCcite[3]{##1 ##3}%
  \sc@cite@sc}

% 1[, 2]    \sc@citeformat{##1}{, ##2}{}
\newcommand\citeNP
  {\renewcommand\@cite[2]
    {##1\if@tempswa , ##2\fi}%
  \renewcommand\SCcite[3]{##1 ##3}%
  \sc@cite@sc}

% 1[, 2])  \sc@citeformat{##1}{, ##2}{)}
\newcommand\citeN
  {\renewcommand\@cite[2]
    {##1\if@tempswa , ##2)\else{)}\fi}%
  \renewcommand\SCcite[3]{##1 (##3}\sc@cite@comma}

% \PreCite1[, 2]\PostCite  \sc@citeformat{\PreCite##1}{, ##2}{\PostCite}
\newcommand\citeA
  {\renewcommand\@cite[2]
    {\PreCite##1\if@tempswa , ##2\fi\PostCite}%
  \let\SCcite\sc@one@three\sc@cite@sc}

% 1[, 2]    \sc@citeformat{##1}{, ##2}{}
\newcommand\citeANP
  {\renewcommand\@cite[2]
    {##1\if@tempswa , ##2\fi}%
  \let\SCcite\sc@one@three\sc@cite@sc}
%    \end{macrocode}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%    
%  \begin{macro}{\shortcite}
%  \begin{macro}{\shortciteNP}
%  \begin{macro}{\shortciteN}
%  \begin{macro}{\shortciteA}
%  \begin{macro}{\shortciteANP}
%    \begin{macrocode}
\newcommand\shortcite
  {\renewcommand\@cite[2]
    {\PreCite##1\if@tempswa , ##2\fi\PostCite}%
  \renewcommand\SCcite[3]{##2 ##3}\sc@cite@sc}
\newcommand\shortciteNP
  {\renewcommand\@cite[2]
    {##1\if@tempswa , ##2\fi}%
  \renewcommand\SCcite[3]{##2 ##3}\sc@cite@sc}
\newcommand\shortciteN
  {\renewcommand\@cite[2]
    {##1\if@tempswa , ##2)\else{)}\fi}%
  \renewcommand\SCcite[3]{##2 (##3}\@cite@comma}
\newcommand\shortciteA
  {\renewcommand\@cite[2]
    {\PreCite##1\if@tempswa , ##2\fi\PostCite}%
  \let\SCcite\sc@two@three\sc@cite@sc}
\newcommand\shortciteANP
  {\renewcommand\@cite[2]
    {##1\if@tempswa , ##2\fi}%
  \let\SCcite\sc@two@three\sc@cite@sc}
%    \end{macrocode}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%
%  \begin{macro}{\citeyear}
%  \begin{macro}{\citeyearNP}
%    \begin{macrocode}
% \PreCite1[, 2]\PostCite  \sc@citeformat{\PreCite##1}{, ##2}{\PostCite}
\newcommand\citeyear
  {\renewcommand\@cite[2]
    {\PreCite##1\if@tempswa , ##2\fi\PostCite}%
  \renewcommand\SCcite[3]{##3}\sc@cite@comma}

% 1[, 2]    \sc@citeformat{##1}{, ##2}{}
\newcommand\citeyearNP
  {\renewcommand\@cite[2]
    {##1\if@tempswa , ##2\fi}%
  \renewcommand\SCcite[3]{##3}\sc@cite@comma}
%    \end{macrocode}
%  \end{macro}
%  \end{macro}
%
%  \begin{macro}{\sc@citesep}
%  \begin{macro}{\sc@cite@sc}
%  \begin{macro}{\sc@cite@comma}
%    \begin{macrocode}
\ReserveCS\sc@citesep
\newcommand\sc@cite@sc
  {\renewcommand\sc@citesep{; }%
  \sc@cite}
\newcommand\sc@cite@comma
  {\renewcommand\sc@citesep{, }%
  \sc@cite}
%    \end{macrocode}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%
%  \begin{macro}{\sc@cite}
% This command executes |\b@foo| for every |foo| in the list of cited labels,
% and separates them by arg \#1.
%
% For some reason my first solution with |\setboolean| didn't work right.
% There has got to be a more elegant solution to this whole thing.
%    \begin{macrocode}
\newcommand\sc@cite
  {\@ifnextchar [{\@tempswatrue\sc@@cite}{\@tempswafalse\sc@@cite[]}}
\ReserveCS\sc@@cite
\def\sc@@cite[#1]#2%
  {\if@filesw\immediate\write\@auxout{\string\citation{#2}}\fi%
  \def\sc@t@a{}%
  \@cite{%
    \@for\sc@label:=#2\do%
      {\sc@t@a%
      \def\sc@t@a{\sc@citesep}%
      \@ifundefined{b@\sc@label}%
      	  {{\bfseries ?}%
          \@warning{Citation `\sc@label' on page \thepage\space undefined}}%
        {\csname b@\sc@label\endcsname}}}%
    {#1}}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\@biblabel}
% No labels in the bibliography.  See explanation elsewhere. 
%    \begin{macrocode}
\let\@biblabel\@gobble
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\bibhang}
%  \begin{macro}{\bibindent}
% Set length of hanging indentation for bibliography entries.
% Indent second and subsequent lines of bibliographic entries.
% |\newblock| is set to |{}|.
%    \begin{macrocode}
\newlength\bibhang
  \setlength{\bibhang}{2em}
\setlength{\bibindent}{1.5em}
%    \end{macrocode}
%  \end{macro}
%  \end{macro}
%
% These names are funny; see classes.dvi; report doesn't define |\refname|,
% anyway.  
%    \begin{macrocode}
\def\refname{Works Cited} 

\@ifundefined{refname}%
   {\@ifundefined{chapter}%
       {\newcommand\refname{References}}
     {\newcommand\refname{Bibliography}}}
 {}

\@ifundefined{chapter}%
 {\def\thebibliography#1{\section*{\refname\@mkboth
   {\uppercase{\refname}}{\uppercase{\refname}}}\list
   {[\arabic{enumi}]}{\settowidth\labelwidth{[#1]}
   \leftmargin\labelwidth
   \advance\leftmargin\labelsep
   \advance\leftmargin\bibindent
   \itemindent -\bibindent
   \listparindent \itemindent
   \parsep \z@
   \usecounter{enumi}}
   \def\newblock{}
   \sloppy
   \sfcode`\.=1000\relax}}
 {\def\thebibliography#1{\chapter*{\refname\@mkboth
   {\uppercase{\refname}}{\uppercase{\refname}}}\list
   {[\arabic{enumi}]}{\settowidth\labelwidth{[#1]}
   \leftmargin\labelwidth
   \advance\leftmargin\labelsep
   \advance\leftmargin\bibindent
   \itemindent -\bibindent
   \listparindent \itemindent
   \parsep \z@
   \usecounter{enumi}}
   \def\newblock{}
   \sloppy
   \sfcode`\.=1000\relax}}
%    \end{macrocode}
%  Now we handle our conditional for the package option to \monster and the
%  breaking off of the |achicagosty| piece.
%    \begin{macrocode}
%</monster|achicagosty>
%<*monster>
  } % close \boolean{Achicago} conditional 
%    \end{macrocode}
% \section{Text macros}
%    \begin{macrocode}
%</monster>
%<*monster|tmacros>
%    \end{macrocode}
%
% \begin{macro}{\AbbrevLongSuffix}
% \begin{macro}{\AbbrevShortSuffix}
% When a text macro |\foo| is created, two additional commands with these
% suffixes are also created. 
%    \begin{macrocode}
\newcommand\AbbrevLongSuffix{long}
\newcommand\AbbrevShortSuffix{short}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\NewTextMacro}
% I wrote some really nice code to implement text macros in 2.09 sometime early
% in '94 when I was beginning work on my thesis.  I thought what I'd done was
% pretty special.  On December~2, 1994, though, I read Chris and Frank's code
% for |\DeclareTextFontCommand|, and I have to admit it sure put the chop to
% what I'd done.  Go boys go.
%
% The checking that |\sw@slant| does for skips and penalties on the list is
% going to be superfluous for the applications I imagine.  But we trade that
% for a more flexible macro. 
%
% We don't check for |\nocorr| or an empty body;  maybe we should when it's
% first defined; but I ran into really hairy expansion troubles trying to do
% that and use |\DeclareRobustCommand|. 
%    \begin{macrocode}
\newcommand\NewTextMacro[3] % args: \csname, style, body
  {\DeclareRobustCommand#1%
      {\leavevmode
      {\maybe@ic #2\aftergroup \maybe@ic@space #3}}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\newtextmacro}
% Having an optional argument makes things below harder.  We provide a user
% command for creating a text macro that is just the same as |\NewTextMacro|
% but with a different argument format.
%    \begin{macrocode}
\DeclareRobustCommand\newtextmacro[3][] % args: [style] \csname body
  {\NewTextMacro{#2}{#1}{#3}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\maybe@ic@space}
% \begin{macro}{\maybe@ic@space@}
% When a text macro is followed by a letter or any other token no in
% |\nospacelist|, a following space is inserted.  It does not make sense to
% have any item in both |\nospacelist| and |\nocorrlist|, since an italic
% correction should be inserted before a space.
%
% Because we want to possibly insert a following space, a single macro
% |\maybe@ic| for both sides of the text is no longer sufficient. 
%    \begin{macrocode}
\newcommand\maybe@ic@space
  {\futurelet\@let@token\maybe@ic@space@}
%    \end{macrocode}
% The reason we can use |\test@next| again is that all it is doing is setting
% the switch false if |\@let@token| is in the list |\spaceafter|. 
%
% \begin{macro}{\sc@ifnewformat}
% Here is where a little change occurred in the December release; temporary
% variable |\@tempa| became |\reserved@a| in |\test@next|.  For the moment, we
% want to be able to work with both releases, so we define a conditional.
%    \begin{macrocode}
\newcommand\sc@ifnewformat
  {\@ifl@t@r\fmtversion{1994/06/01}}
%    \end{macrocode}
% \end{macro}
%
% |\test@next| sets the switch false if the lettoken is on the list.
%
% following token:        action
% ----------------------------------
%   a nocorr              nothing
%   tie, a nospace        sw@slant
%   other                 sw@slant + space
% \begin{verbatim}
%        \sc@toks@a=\expandafter\expandafter\expandafter
%                   {\expandafter\@cdr\@let@token\@nil}%
%        \edef\sc@t@a{\the\sc@toks@a}%
%         \ifx\sc@t@a\@empty
%         now we can safely to an \ifcat

% LET T = the next token
% IF slanted font is current 
%   IF T NOT IN \nocorrlist
%     \sw@slant
%     IF T NOT IN \nospacelist
%       SPACE
%     FI
%   FI           
% FI
% \end{verbatim}
%
% Now we define one or the other version, depending on the format date.  This
% macro is similar to |\maybe@ic@|, but we do another check through
% |\nospacelist|.  
%    \begin{macrocode}
\sc@ifnewformat                       % ifnewformat is TRUE
{\newcommand\maybe@ic@space@             
  {\ifdim \fontdimen\@ne\font>\z@
  \else
    \@tempswatrue
    \expandafter
    \@tfor\expandafter\reserved@a\expandafter:\expandafter=%
        \nocorrlist
      \do \test@next
    \if@tempswa
      \sw@slant
      \expandafter
      \@tfor\expandafter\reserved@a\expandafter:\expandafter=%
          \nospacelist
        \do \test@next
      \if@tempswa\space
      \fi
    \fi
  \fi}}
{\newcommand\maybe@ic@space@             
  {\ifdim \fontdimen\@ne\font>\z@
  \else
    \@tempswatrue
    \expandafter
    \@tfor\expandafter\@tempa\expandafter:\expandafter=%
        \nocorrlist
      \do \test@next
    \if@tempswa 
      \sw@slant
      \expandafter
      \@tfor\expandafter\@tempa\expandafter:\expandafter=%
          \nospacelist
        \do \test@next
      \if@tempswa\space
      \fi
    \fi
  \fi}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\nospacelist}
% Put these in the order of their frequency. 
%    \begin{macrocode}
\newcommand\nospacelist
  {':;?-~!)]\bgroup\egroup}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\newabbrev}
% This command defines a new abbreviation.  The optional argument is treated as
% a style-changing command.  
%    \begin{macrocode}
\newcommand\newabbrev[1][] % oarg: style
  {\sc@newabbrev{\NewTextMacro}{#1}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ResetAbbrevs}
% Each time an abbreviation is defined, something will be added to the contents
% of this command.
%    \begin{macrocode}
\ReserveCS\ResetAbbrevs
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\sc@toks@shortcom}
% \begin{macro}{\sc@toks@plaincom}
% \begin{macro}{\sc@toks@longcom}
% The first three of the following toks registers will expand to the three
% |\csname|s we are going to define.  The remaining two will be used later.
%    \begin{macrocode}
\newtokens\sc@toks@shortcom
\newtokens\sc@toks@longcom
\newtokens\sc@toks@plaincom
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% The above are simply holders, to keep what's in them from expanding under the
% |\xdef| below.  I tried |\noexpand|s, which might have been clearer, but to
% no avail.  What's below is a pain in the neck, but it works.  Someday I will
% make another stab at simplifying. 
%
% \begin{macro}{\sc@newabbrev}
% Here is the main abbreviation maker.  The first argument is another macro to
% call.  It's there to make things simpler, but also because I have in mind
% alternatives to |\NewTextMacro| that are not yet implemented.  The second
% argument is expected to be a style command, such as |\em|, or empty.  The
% third argument is the main macro name to be created, and the fourth and fifth
% arguments are the initial expansion, and the subsequent expansion for the
% macro. 
%
% The first part sets our three toks variables to the three command sequences
% that this macro is going to define. 
%    \begin{macrocode}
\newcommand\sc@newabbrev[5] % args: maker style name longtext shorttext
  {\sc@toks@shortcom=\expandafter{\csname #3\AbbrevShortSuffix\endcsname}
  \sc@toks@longcom=\expandafter{\csname #3\AbbrevLongSuffix\endcsname}
  \sc@toks@plaincom=\expandafter{\csname #3\endcsname}
%    \end{macrocode}
% The next two lines define the explicitly long version and the explicitly
% short version.
%    \begin{macrocode}
  \expandafter#1\the\sc@toks@longcom{#2}{#4}
  \expandafter#1\the\sc@toks@shortcom{#2}{#5}
%    \end{macrocode}
%  Perhaps the following should be sent out to its own macro.  Would that
%  simplify this knotty expansion problem?  Anyway, the strategy is to define
%  the main command to check its own reserved boolean variable to see whether
%  this macro has been called before, and expand to different things according
%  to its value.  
%    \begin{macrocode}
  \newboolean{#3 mentioned}
%    \end{macrocode}
% This next line is a local change; should it be global? 
%    \begin{macrocode}
  \addto@macro\ResetAbbrevs{\gsetboolean{#3 mentioned}{false}}
%    \end{macrocode}
% Here's the real screwy part.  To get the expansion right, I put two
% lines of code into toks registers.
%    \begin{macrocode}
  \sc@toks@a={\ifthenelse{\boolean{#3 mentioned}}}
  \sc@toks@b={\gsetboolean{#3 mentioned}{true}}
%    \end{macrocode}
% And then I use them here.  This code defines the main abbreviation macro to a
% simple |\ifthenelse|.  The expanded code is given in the comments.
%    \begin{macrocode}
  \expandafter\@ifdefinable\the\sc@toks@plaincom
    {\expandafter\xdef\the\sc@toks@plaincom
      {\the\sc@toks@a% I.E.:  {\ifthenelse{\boolean{#3 mentioned}}}
          {\the\sc@toks@shortcom}
        {\the\sc@toks@b% I.E.:{\gsetboolean{#3 mentioned}{true}}
      	\the\sc@toks@longcom}}}}
%    \end{macrocode}
% The |\csname|s (either |\foolong| or |\fooshort|) \emph{must} be the very
% last thing to occur in the definitions, or the |\futurelet| that checks
% following spacing in |\NewTextMacro| will break.  No space must sneak into
% the macros!
% \end{macro}
%
% From here on out, we are just applying these things to make a few user
% commands.  
% \begin{macro}{\newname}
%    \begin{macrocode}
\newcommand\newname
  {\newabbrev[]}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\newwork}
% \begin{macro}{\sc@newworkabbrev}
%    \begin{macrocode}
\newcommand\newwork[2]
  {\@ifnextchar [ 
      {\sc@newworkabbrev{#1}{#2}}
    {\expandafter\NewTextMacro\csname #1\endcsname{\em}{#2}}}

\ReserveCS\sc@newworkabbrev
\def\sc@newworkabbrev#1#2[#3]
  {\sc@newabbrev{\NewTextMacro}{\em}{#1}{#2}{#3}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\newbook}
%    \begin{macrocode}
\newcommand\newbook[2]
   {\newwork{#1}{#2}} 
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
%</monster|tmacros>
%<*monster>
%    \end{macrocode}
% \section{Extra marks}
% This whole thing is a naming nightmare, there are so many macros and so many
% permutations of marks and positions and so on.  I've tried to be good, but I
% have not succeeded in making things as simple as the user commands. 
%
% \begin{macro}{\sc@xmarkwarngobble}
% \begin{macro}{\sc@xmarkwarn}
% First we define some warnings for when a package wants to claim the first
% extra mark.  The gobbling version is for when a command tries to set the
% mark; the non-gobbling version is for a command that is supposed to expand to
% the mark.
%    \begin{macrocode}
\newcommand\sc@xmarkwarngobble[1]
  {\PackageWarning{markx}
    {The second extra mark is not available, because \protect\ClaimXMarkTwo
      	      	      	      	      	      		      	\MessageBreak
    has been called.  I am ignoring this command and proceeding.}}
\newcommand\sc@xmarkwarn
  {\PackageWarning{markx}
    {The second extra mark is not available, because \protect\ClaimXMarkTwo
      	      	      	      	      	      		      	\MessageBreak
    has been called.  I am ignoring this command and proceeding.}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\xmarktwo}
% \begin{macro}{\thexmarktwo}
% \begin{macro}{\botxmarktwo}
% \begin{macro}{\firstxmarktwo}
% \begin{macro}{\sc@mark}
% \begin{macro}{\sc@botmark}
% \begin{macro}{\sc@firstmark}
% \begin{macro}{\sc@topmark}
% Here we make sure no other package is using these, because we're going to
% |\let| them below.
%    \begin{macrocode}
\ReserveCS\xmarktwo
\ReserveCS\thexmarktwo
\ReserveCS\botxmarktwo
\ReserveCS\firstxmarktwo
\ReserveCS\sc@mark
\ReserveCS\sc@botmark
\ReserveCS\sc@firstmark
\ReserveCS\sc@topmark
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\ClaimXMarkTwo}
% \begin{macro}{\FreeXMarkTwo}
% This are the command to claim or free the extra mark for or from private
% package use.  They simply reassign user commands between the real mark
% commands and the warning commands just defined. 
%
% FIX: These should be |\outer|. 
%    \begin{macrocode}
\newcommand\ClaimXMarkTwo
  {\PackageInfo{markx}
    {Claimed the second extra mark for the \protect\sc@ mark commands}%
  \let\xmarktwo\sc@xmarkwarngobble
  \let\botxmarktwo\sc@xmarkwarn
  \let\firstxmarktwo\sc@xmarkwarn
  \let\topxmarktwo\sc@xmarkwarn
  \let\sc@mark\sc@xmarktwo
  \let\thesc@mark\sc@thexmarktwo
  \let\sc@botmark\sc@botxmarktwo
  \let\sc@firstmark\sc@firstxmarktwo
  \let\sc@topmark\sc@topxmarktwo}

\newcommand\FreeXMarkTwo
  {\PackageInfo{markx}
    {Freed the second extra mark.  \protect\sc@ mark commands disabled.}%
  \let\xmarktwo\sc@xmarktwo
  \let\thexmarktwo\sc@thexmarktwo
  \let\botxmarktwo\sc@botxmarktwo
  \let\firstxmarktwo\sc@firstxmarktwo
  \let\topxmarktwo\sc@topxmarktwo
  \let\sc@mark\@gobble
  \let\thesc@mark\@empty
  \let\sc@botmark\@empty
  \let\sc@firstmark\@empty
  \let\sc@topmark\@empty}
%    \end{macrocode}
% \end{macro}
% \end{macro}

% \begin{macro}{\xmarkone}
% \begin{macro}{\sc@xmarktwo}
% \begin{macro}{\markboth}
% \begin{macro}{\markright}
% These four commands set the current value of the mark, and the real \TeX\
% mark, to their arguments.
%    \begin{macrocode}
\renewcommand\markright[1]
  {{\let\protect\@unexpandable@protect
  \let\label\relax \let\index\relax \let\glossary\relax
  \expandafter\@mark@rightmark\sc@themark{#1}%
  \mark{\sc@themark}}\if@nobreak\ifvmode\nobreak\fi\fi}
\renewcommand\markboth[2]
  {{\let\protect\@unexpandable@protect
  \let\label\relax \let\index\relax \let\glossary\relax
  \expandafter\@mark@bothmarks\sc@themark{#1}{#2}%
  \mark{\sc@themark}}\if@nobreak\ifvmode\nobreak\fi\fi}
\newcommand\xmarkone[1]
  {{\let\protect\@unexpandable@protect
  \let\label\relax \let\index\relax \let\glossary\relax
  \expandafter\sc@mark@xmarkone\sc@themark{#1}%
  \mark{\sc@themark}}\if@nobreak\ifvmode\nobreak\fi\fi}
\newcommand\sc@xmarktwo[1]
  {{\let\protect\@unexpandable@protect
  \let\label\relax \let\index\relax \let\glossary\relax
  \expandafter\sc@mark@xmarktwo\sc@themark{#1}%
  \mark{\sc@themark}}\if@nobreak\ifvmode\nobreak\fi\fi}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\@mark@rightmark}
% \begin{macro}{\@mark@bothmarks}
% \begin{macro}{\sc@mark@xmarkone}
% \begin{macro}{\sc@mark@xmarktwo}
% These are auxiliary commands used in setting the marks.
%    \begin{macrocode}
\newcommand\@mark@rightmark[5]
  {\gdef\sc@themark{{#1}{#5}{#3}{#4}}}
\newcommand\@mark@bothmarks[6]
  {\gdef\sc@themark{{#5}{#6}{#3}{#4}}}
\newcommand\sc@mark@xmarkone[5]
  {\gdef\sc@themark{{#1}{#2}{#5}{#4}}}
\newcommand\sc@mark@xmarktwo[5]
  {\gdef\sc@themark{{#1}{#2}{#3}{#5}}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\mask@leftmark}
% \begin{macro}{\mask@rightmark}
% \begin{macro}{\mask@xmarkone}
% \begin{macro}{\mask@xmarktwo}
% These four are parallel; they are masks for the \TeX{} mark variable which
% comprises four parts.  I'm omitting the |sc@| prefix to remain parallel with
% the existing commands.
%    \begin{macrocode}
\newcommand\mask@leftmark[4] {#1}
\newcommand\mask@rightmark[4]{#2}
\newcommand\mask@xmarkone[4]   {#3}
\newcommand\mask@xmarktwo[4]   {#4}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\topxmarkone}
% \begin{macro}{\sc@topxmarktwo}
% \begin{macro}{\botxmarkone}
% \begin{macro}{\sc@botxmarktwo}
% \begin{macro}{\firstxmarkone}
% \begin{macro}{\sc@firstxmarktwo}
% Here are the commands to produce each of the two new marks in the three
% positions of top, bot, and first.  The four sets of braces seem superfluous
% to me.  If these marking commands are always used to set the mark, then they
% will never be used.
%    \begin{macrocode}
\newcommand\topxmarkone
  {\expandafter\mask@xmarkone\topmark{}{}{}{}}
\newcommand\sc@topxmarktwo
  {\expandafter\mask@xmarktwo\topmark{}{}{}{}}
\newcommand\firstxmarkone
  {\expandafter\mask@xmarkone\firstmark{}{}{}{}}
\newcommand\sc@firstxmarktwo
  {\expandafter\mask@xmarktwo\firstmark{}{}{}{}}
\newcommand\botxmarkone
  {\expandafter\mask@xmarkone\botmark{}{}{}{}}
\newcommand\sc@botxmarktwo
  {\expandafter\mask@xmarktwo\botmark{}{}{}{}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\rightmark}
% \begin{macro}{\leftmark}
% These are analogous commands for the value of the two \LaTeX{} mark
% positions.  There are only two of them, where there could be six, because
% \LaTeX{} does not need to use the remaining four pieces of information.
%    \begin{macrocode}
\renewcommand\rightmark
  {\expandafter\mask@rightmark\firstmark{}{}{}{}}
\renewcommand\leftmark
  {\expandafter\mask@leftmark\botmark{}{}{}{}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\theleftmark}
% \begin{macro}{\therightmark}
% \begin{macro}{\thexmarkone}
% \begin{macro}{\thexmarktwo}
% These commands use the masks above to produce the \emph{current value} of the
% particular mark asked for.  The current value is stored in |\sc@themark|.  I
% do not see much use for these. Debugging?
%    \begin{macrocode}
\newcommand\theleftmark
  {\expandafter\mask@leftmark\sc@themark{}{}{}{}}
\newcommand\therightmark
  {\expandafter\mask@rightmark\sc@themark{}{}{}{}}
\newcommand\thexmarkone
  {\expandafter\mask@xmarkone\sc@themark{}{}{}{}}
\newcommand\sc@thexmarktwo
  {\expandafter\mask@xmarktwo\sc@themark{}{}{}{}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\sc@themark}
% Finally, we initialize things.  We start with the second mark freed.  This
% must be done near the end, because it contains |\let|s!
%    \begin{macrocode}
\newcommand\sc@themark{{}{}{}{}}
\FreeXMarkTwo
%    \end{macrocode}
% \end{macro}
% \section{Header junk}
%    \begin{macrocode}
\NewUserInfo\HeaderSize
\NewUserInfo\HeaderAdjust

\headersize{\footnotesize}
\headeradjust{\hspace*{-.68em}}  % FIX, can we calculate this constant?

\newcommand\emptyheads
  {\let\forcemkboth\markboth % provision to force heads
  \let\markboth\@gobbletwo
  \let\@mkboth\@gobbletwo}

\renewcommand{\@oddhead}
  {{\HeaderSize\HeaderAdjust\hbox {}\slshape\rightmark\hfil\rmfamily\thepage}}
%    \end{macrocode}
% \section{Miscellaneous}
%  \begin{macro}{\Frankenstein}
%  \begin{macro}{\BigFrankenstein}
%    \begin{macrocode}
\NewTextMacro\Frankenstein{\smaller\ttfamily}{Frankenstein}
\NewTextMacro\BigFrankenstein{\ttfamily}{Frankenstein}
\providecommand\BibTeX
  {{\rmfamily B\kern-.05em{\scshape i\kern-.025em b}\kern-.08em
    T\kern-.1667em\raisebox{-.7ex}{E}\kern-.125emX}}
%    \end{macrocode}
%  \end{macro}
%  \end{macro}
%
% For bible references.
% The |\unskip| is to close up extra space.
%    \begin{macrocode}
\newcommand\bible[2]
  {\ignorespaces#1\,:\,#2\unskip}
\newcommand\whitespace
  {\bigbreak}
\newcommand\lin
  {$\ell$~}
%    \end{macrocode}
% Have to choose in src whether to have a tie.
%    \begin{macrocode}
\newcommand\lins
  {$\ell\mskip-1.85mu\ell$}  
%    \end{macrocode}
% \section{Configuration file}
%
% The configuration file is loaded at the very end of the package. There are
% several places where an individual user of the \monster package would want
% to make permanent changes.  
%
% If you do not wish to use a configuration file, your \TeX{} program may spend
% some unnecessary time looking through the whole search path for it.  There
% are three solutions, none of them very elegant. First, simply modify this
% file to exclude the following lines. Second, create an empty |monster.cfg|
% somewhere early in the search path.  Third, use the package option
% |noconfig|.  I expect most users will want to use the configuration file, and
% this won't be a problem.  But if anyone has a better solution, I'd like to
% hear about it. 
%
% You should be able to set margins in the configuration file.  Please
% notify me if you find one that needs to be set before loading the package,
% and I will try to fix it. 
%
% Here is a sample configuration file. 
%
%\begin{verbatim}
%\pagestyle{headings}

%\author{B. Studly}
%\addressone{59 Beast Road \#666}
%\addresstwo{Gehenna MA 02134}
%
%\newcommand{\includesexphone}
%  {\phonenumber{$617$/sex--pots}}
%\newcommand{\includephone}
%  {\phonenumber{$\mit617$/$\mit739$--$\mit7687$}}
%\newcommand{\includeemail}
%  {\email{beast@media.mit.edu}}
%\newcommand{\includecountry}
%  {\country{USA}}
%\end{verbatim}
%    \begin{macrocode}
\ifthenelse{\boolean{UseConfig}}
    {\InputIfFileExists{monster.cfg}
        {\typeout{Loading Frankenstein configuration file}}
      {\typeout{No file monster.cfg.}}}
  {}
%    \end{macrocode}
% \clearpage
% \part{\emph{Chicago Manual} style A with author-date}
%    \begin{macrocode}
%</monster>
%<*achicago>

% A BibTeX bibliography style
%    conforming to the Chicago Manual's A style
%       but with B style author-date citations
% VERSION 0.2 (alpha -- this works for my dissertation)

%    \end{macrocode}
%
% \section{Credits}
% I have adapted this style from |chicago.bst|, which in turn was based on 
% \begin{verbatim}
%     author          = "Glenn Paulley",
%     version         = "4",
%     date            = "28 August 1992",
%     time            = "10:23:39 199",
%     filename        = "chicago.bst",
%     address         = "Data Structuring Group
%                        Department of Computer Science
%                        University of Waterloo
%                        Waterloo, Ontario, Canada
%                        N2L 3G1",
%     telephone       = "(519) 885-1211",
%     FAX             = "(519) 885-1208",
%     email           = "gnpaulle@bluebox.uwaterloo.ca",
% \end{verbatim}
% \section{User documentation}
%
% Is mostly style A, but borrows the author-date reference system from style B.
% \section{Implementation}
%     \subsection{Preliminary}
%
% These are global variables. 
%    \begin{macrocode}
INTEGERS { output.state before.all mid.sentence after.sentence after.block }
INTEGERS { multiresult nameptr namesleft numnames len last.extra.num }

STRINGS { s t u }
STRINGS { last.label last.label.and.year next.extra.label}
%    \end{macrocode}
%
% Any fields in the database  not on this list (and also mentioned below)
% will be ignored by this bibliography style.
%    \begin{macrocode}
ENTRY
  { address
    annotation
    author
    booktitle
    chapter
    citation          % always overrides the citation label
    edition           % use for anything after title, including # of vols.
    editor
    howpublished
    illustrator       % for books only
    institution       % for theses only
    journal
    key               % often default for author, editor, organization
    month             % also season for journals
    note
    number
    organization
    pages
    publisher
    republisher       % publisher of reprint
    school
    series            % if no comma between this and number, put number here
    title
    translator        % for books only
    type              % this overrides "Chap." and thesis-type
    volume
    year              % date of cited edition
    yearpub           % date cited edition first published (reprint cited)    
%    yearfirst =       % date original edition published, if different 
  }                   % yearfirst is not implemented yet
  {}
  { 
%    \end{macrocode}
% `long.label' is used by the regular citing commands; `short.label' is used by
%  the short citing commands (|\shortcite| etc.).
%    \begin{macrocode}
  short.label long.label 
%    \end{macrocode}
% `year label' is always the year entry, I think.  `extra.label' is nothing or
%  a lower-case letter.  `sort.year.label' is the catenation of the two.
%    \begin{macrocode}
    year.label extra.label sort.year.label 
%    \end{macrocode}
% This will contain key for the final sort. 
%    \begin{macrocode}
    sort.label
%    \end{macrocode}
% `printed.author' will contain the string actually written to the |.bbl| file.
% It is kept separate from the `author' entry for clarity.  
%    \begin{macrocode}
    printed.author }
%    \end{macrocode}
% stop with the |\end{document}|.
%
% This bibstyle does not distinguish between sentences and blocks.  In the
% style file, |\newblock| is a null command.  But going to the trouble of
% removing the functionality seemed a dumb idea to me.  I should say, however,
% that I have not paid attention to the difference between blocks and sentences
% while I revised, and someone who wishes to modify this style in a way that
% distinguishes between the two ought to review the type functions and make
% sure that sentences and blocks are done appropriately for their purposees.
%    \begin{macrocode}
FUNCTION {init.state.consts}
{ #0 'before.all :=
  #1 'mid.sentence :=
  #2 'after.sentence :=
  #3 'after.block :=
}
%    \end{macrocode}
%     \subsection{Macros}
% These are required, and the user can redefine them.  The billions of macros
% for obscure journals in all the standard styles just waste memory.
%    \begin{macrocode}
MACRO {jan} {"January"}
MACRO {feb} {"February"}
MACRO {mar} {"March"}
MACRO {apr} {"April"}
MACRO {may} {"May"}
MACRO {jun} {"June"}
MACRO {jul} {"July"}
MACRO {aug} {"August"}
MACRO {sep} {"September"}
MACRO {oct} {"October"}
MACRO {nov} {"November"}
MACRO {dec} {"December"}
%    \end{macrocode}
%     \subsection{Basic logic}
%  \begin{bibfunction}{not}
%  \begin{bibfunction}{and}
%  \begin{bibfunction}{or}
%    \begin{macrocode}
FUNCTION {not}
{   { #0 
    }
    { #1 
    }
  if$
}

FUNCTION {and}
{   'skip$
    { pop$ 
      #0 
    }
  if$
}

FUNCTION {or}
{   { pop$ 
      #1 
    }
    'skip$
  if$
}
%    \end{macrocode}
%  \end{bibfunction}
%  \end{bibfunction}
%  \end{bibfunction}
%
%     \subsection{Punctuation}
%  \begin{bibfunction}{comma}
%  \begin{bibfunction}{space}
%  \begin{bibfunction}{colon}
%  \begin{bibfunction}{unidentified}
% The reason these are functions not macros is so the user cannot change them.
% These definitions are made so that later functions are easier to read.
%
% They need to come before the output functions.
% FIX move unidentified somewhere else.
%    \begin{macrocode}
FUNCTION {comma}
{ ","
}

FUNCTION {colon}
{ ":"
}

FUNCTION {space}
{ " "
}

FUNCTION {unidentified} 
{ "HiGHlY*Peco@lIEr" 
}
%    \end{macrocode}
%  \end{bibfunction}
%  \end{bibfunction}
%  \end{bibfunction}
%  \end{bibfunction}
%     \subsection{Output functions}
% The standard `output' function automatically handles interunit punctuation.
%
% A call to `output' should be made with a string and a punctuation mark on the
% stack.  The punctuation mark is what should \emph{precede} the string in
% question, should it be in the middle of a sentence.  Strings which begin
% sentences are preceded by periods.  And finally, strings which begin a new
% block are preceded by periods and the |\newblock| command.
%
% Calls to `output.internal' function leave the string on the stack until the
% next time this is called.  Then they get printed out.  The function
% `output.begin' puts an empty string on the stack, and `output.end' cleans up
% with a |write$| command.  The output of the previous string is preceded by
% one of the following depending on the present `output.state'.
%
%\begin{verbatim}
%  { punct " " } 
%  { add.period$ newline$ "\newblock " }
%  { add.period$ space * space * } 
%\end{verbatim}
%
%  \begin{bibfunction}{output.begin}
% We need to begin an output series with an empty string on the stack.
%    \begin{macrocode}
FUNCTION{output.begin}
{ ""
  before.all 'output.state :=
}
%    \end{macrocode}
%  \end{bibfunction}
%
%  \begin{bibfunction}{output.end}
% This cleans up after an output series.
%    \begin{macrocode}
FUNCTION {output.end}
{ write$ }
%    \end{macrocode}
%  \end{bibfunction}
%
%    \begin{macrocode}
FUNCTION {new.block}
{ output.state before.all =
    'skip$
    { after.block 'output.state := 
    }
  if$
}
%    \end{macrocode}
%
%    \begin{macrocode}
FUNCTION {new.sentence}
{ output.state after.block =
    'skip$
    { output.state before.all =
        'skip$
        { after.sentence 'output.state := 
        }
      if$
    }
  if$
}
%    \end{macrocode}
%
% \begin{bibfunction}{output.internal}
% \stack{punct string/entry(nonnull)}{null}
%    \begin{macrocode}
FUNCTION {output.internal}
{ 's :=     % string
  space * 't :=     % punctuation + space
  output.state mid.sentence =
    { t * write$ 
    }
    { output.state after.block =
        { add.period$ write$
          newline$
          "\newblock " write$
        }
        { output.state before.all =
            'write$
            { add.period$ space * write$ }
          if$
        }
      if$
      mid.sentence 'output.state :=
    }
  if$
%    \end{macrocode}
% the actual string is left on the stack here:
%    \begin{macrocode}
  s
}
%    \end{macrocode}
% \end{bibfunction}
%
% \begin{bibfunction}{output}
% \stack{string/entry punct}{either null OR punct string/entry(nonnull)}
%
% checks if string/entry is null.  If so, do nothing.  If not, do the output
% routine with the given punct
%    \begin{macrocode}
FUNCTION {output}
{ swap$ duplicate$ empty$
    { pop$
      pop$
    }
    'output.internal
  if$
}
%    \end{macrocode}
% \end{bibfunction}
%
% \begin{bibfunction}{output.bibitem}
% FIX: This might should be made into a make.bibitem and output as usual, but
% how do we do the newlines?
%
% The optional argument to |\bibitem| will be made the definition of |\b@foo|
% where |foo| is the |cite$| label.  |\b@foo| will be executed by all the
% various citing commands with a definition of |\SCcite| that is appropriate to
% each citing command.
%
% The |thebibliography| environment actually ignores the optional argument to
% |\bibitem|.  The environment sets the formatting so that the first part of
% the main entry hangs out to the left and looks like a label.
%    \begin{macrocode}
FUNCTION {output.bibitem}
{ newline$
  "\bibitem[\protect\SCcite{" write$
  long.label write$
  "}{" write$
  short.label write$
  "}{" write$
  year.label write$
  "}]{" write$
  cite$ write$
  "}" write$
  newline$
}
%    \end{macrocode}
% \end{bibfunction}
%
%  \begin{bibfunction}{output.annotation}
% Annotations can be omitted simply by nullifying the |SCannotation|
% environment.  The package or class file should take care of this.
%    \begin{macrocode}
FUNCTION {output.annotation}
{ annotation empty$
	{ "" }
	{ "\begin{SCannotation}"
	  annotation *
	  "\end{SCannotation}" *
	}
  if$
}
%    \end{macrocode}
%  \end{bibfunction}
%     \subsection{Simple auxiliary functions}
%  \begin{bibfunction}{begin.entry}
%  This begins an entry.
%    \begin{macrocode}
FUNCTION {begin.entry}
{ output.begin
  output.bibitem
}
%    \end{macrocode}
%  \end{bibfunction}
%
%  \begin{bibfunction}{finish.entry}
% This finishes up an entry.
% \stack{string}{null}
%    \begin{macrocode}
FUNCTION {finish.entry}
{ add.period$
  output.end
  newline$
  output.annotation write$
}
%    \end{macrocode}
%  \end{bibfunction}
%
%  \begin{bibfunction}{field.or.null}
% \mbox{}
%  \begin{macro}
%    \begin{macrocode}
FUNCTION {field.or.null}
{ duplicate$ empty$
    { pop$ 
      "" 
    }
    'skip$
  if$
}
%    \end{macrocode}
%  \end{macro}
%
% \begin{bibfunction}{emphasize}
% Emphasize the top string on the stack and provide italic corrections.  Null
% goes to null.  \stack{string or entry}{string}
%    \begin{macrocode}
FUNCTION {emphasize}
{ duplicate$ empty$
    { pop$ "" }
    { "\emph{" swap$ * "}" * }
  if$
}
%    \end{macrocode}
% \end{bibfunction}
%
% \begin{bibfunction}{emphasize.alternate}
% Emphasize the top string on the stack with no checking for italic
% corrections.  Null goes to null.  \stack{string or entry}{string}
% FIX: I should probably eliminate my conflict with |\emph|. 
%    \begin{macrocode}
FUNCTION {emphasize.alternate}
{ duplicate$ empty$
    { pop$ "" }
    { "{\em " swap$ * "}" * }
  if$
}
%    \end{macrocode}
% \end{bibfunction}
%
% \begin{bibfunction}{entry.clip}
% \stack{string}{string}
% Clips a string down to the proper length.
%    \begin{macrocode}
FUNCTION {entry.clip}
{ #1 entry.max$ substring$ }
%    \end{macrocode}
%  \end{bibfunction}
%
% \begin{bibfunction}{check}
% \stack{S warning}{S}
% Issues warning if S is |empty$|. 
%    \begin{macrocode}
FUNCTION {check}
{ 't := 
  duplicate$ empty$
    { "empty " t * " in " * cite$ * warning$ 
    }
    'skip$
  if$
}
%    \end{macrocode}
%  \end{bibfunction}
%
%    \begin{macrocode}
FUNCTION {multi.page.check}
{ 't :=
  #0 'multiresult :=
    { multiresult not
      t empty$ not
      and
    }
    { t #1 #1 substring$
      duplicate$ "-" =
      swap$ duplicate$ "," =
      swap$ "+" =
      or or
    { #1 'multiresult := }
    { t #2 global.max$ substring$ 't := }
      if$
    }
  while$
  multiresult
}
%    \end{macrocode}
%
% \begin{bibfunction}{n.dashify}
% \stack{string}{string}
% makes single-dashes into double-dashes
%    \begin{macrocode}
FUNCTION {n.dashify}
{ 't :=
  ""
  { t empty$ not }
    { t #1 #1 substring$ "-" =
        { t #1 #2 substring$ "--" = not
          { "--" *
            t #2 global.max$ substring$ 't :=
          }
          { { t #1 #1 substring$ "-" = }
              { "-" *
                t #2 global.max$ substring$ 't :=
              }
            while$
          }
        if$
        }
        { t #1 #1 substring$ *
          t #2 global.max$ substring$ 't :=
        }
      if$
    }
  while$
}
%    \end{macrocode}
% \end{bibfunction}
%  
%  \begin{bibfunction}{tie.or.space.connect}
%    \begin{macrocode}
FUNCTION {tie.or.space.connect}
{ duplicate$ text.length$ #3 <
    { "~" 
    }
    { " " 
    }
  if$
  swap$ * *
}
%    \end{macrocode}
%  \end{bibfunction}
% \begin{bibfunction}{either.or.check}
% \stack{msg field}{null}
% If field is not empty, give a warning appropriate for saying this field and
% an already-existing field can't be both used in the same entry. 
%    \begin{macrocode}
FUNCTION {either.or.check}
{ empty$
    'pop$
    { "can't use both " swap$ * " fields in " * cite$ * warning$ 
    }
  if$
}
%    \end{macrocode}
% \end{bibfunction}
%     \subsection{Queue functions}
% The queue functions expect a string on the stack.  If it is null, this means
% permission to leave the entry the function is named after on the stack, if it
% exists.  If it does not exist, a null string is left on the stack.  
% A chain of queue functions will leave the first non-null entry on the stack. 
%
% a null string left on the stack must be the same as nothing!!!!!!! See
% original definition  and use of `format.key'
%
% This is more descriptive than just sticking the empty string out there to
% start off a queue.
% \begin{bibfunction}{start.q}
%    \begin{macrocode}
FUNCTION {start.q}
{ ""
}
%    \end{macrocode}
% \end{bibfunction}
%
% \begin{bibfunction}{key.q}    
% \begin{bibfunction}{author.q}    
% \begin{bibfunction}{organization.q}    
% \begin{bibfunction}{editor.q}    
%    \begin{macrocode}
FUNCTION {key.q}
{ duplicate$ empty$
    { pop$
      key field.or.null 
    }
    'skip$
  if$
}

FUNCTION {organization.q}
{ duplicate$ empty$
    { pop$
      organization field.or.null 
    }
    'skip$
  if$
}

FUNCTION {editor.q}
{ duplicate$ empty$
    { pop$
      editor field.or.null 
    }
    'skip$
  if$
}

FUNCTION {author.q}
{ duplicate$ empty$
    { pop$
      author field.or.null 
    }
    'skip$
  if$
}
%    \end{macrocode}
% \end{bibfunction}
% \end{bibfunction}
% \end{bibfunction}
% \end{bibfunction}
%
% \begin{bibfunction}{check.q}
% This should be the final queue command, though it is not a true queue
% command, since a warning string should be on the top of the stack.  The
% warning string should be a English disjunctive list of the queue commands
% that have come before it, so the user can tell which fields are missing.  For
% example "author, organization, or key" if the queue has been `author.q'
% `organization.q' `key.q'.  If the stack's string (other than the warning
% string) is null, it issues the warning, and puts on an emergency string of
% the first three letters of the LaTeX key (|cite$|), which should allow things
% to proceed.
%
% \stack{t warning}{t OR u}
% if t null, warn, and put u on stack, else leave t. 
%    \begin{macrocode}
FUNCTION {check.q}
{ 's :=
  duplicate$ empty$
    { pop$
      cite$ #1 #3 substring$ 'u :=
      "Need " s * " in " * cite$ * "; using:  " * u * warning$
      u
    }
    'skip$
  if$
}    
%    \end{macrocode}
% \end{bibfunction}
%     \subsection{Format queue functions}
% These are both format and queu functions
% There are 4 cases for labels:
% a) one author             Foo
% b) one to n               Foo, Bar, and Baz
% c) use of "and others"    Foo, Bar et al.
% d) more than n            Foo et al.
%
% If an empty string is on the stack, we leave it there.  Else we format the
% string. 
% \begin{bibfunction}{format.short.label.names.q}
%    \begin{macrocode}
FUNCTION {format.short.label.names.q}
{ duplicate$ empty$
    'skip$
    { 's :=
      s num.names$ 'numnames :=
      % This is the number of others allowed before forcing "et al".
      numnames #2 >    
	{ s #1 "{vv~}{ll}" format.name$ " et~al." * 
	}
	{ numnames #1 - 'namesleft :=
	  #2 'nameptr :=
	  s #1 "{vv~}{ll}" format.name$
	  { namesleft #0 > }
	    { nameptr numnames =
		{ s nameptr "{ff }{vv }{ll}{ jj}" format.name$ "others" =
		    { " et~al." * 
		    }
		    { ", and " * s nameptr "{vv~}{ll}" format.name$ * 
		    }
		  if$
		}
		{ ", " * s nameptr "{vv~}{ll}" format.name$ * 
		}
	      if$
	      nameptr #1 + 'nameptr :=
	      namesleft #1 - 'namesleft :=
	    }
	  while$
        }
      if$
    }
  if$
}
%    \end{macrocode}
% \end{bibfunction}
% \begin{bibfunction}{format.long.label.names.q}
% Takes an entry with names and produces something appropriate for
% `long.label'.  If the string on the stack is empty, it is passed on. 
%    \begin{macrocode}
FUNCTION {format.long.label.names.q}
{ duplicate$ empty$
    'skip$
    { 's :=
      #1 'nameptr :=               % nameptr = 1;
      s num.names$ 'numnames :=    % numnames = num.name$(s);
      numnames 'namesleft :=
	{ namesleft #0 > }
	{ s nameptr "{vv~}{ll}" format.name$ 't :=  % get the next name
	  nameptr #1 >
	    { namesleft #1 >
		  { ", " * t * 
		  }
		  { numnames #2 >
		      { "," * 
		      }
		      'skip$
		    if$
		    t "others" =
			{ " et~al." * 
			}
			{ " and " * t * 
			}
		      if$
		   }
		 if$
	    }
	    't
	  if$
	  nameptr #1 + 'nameptr :=          % nameptr += 1;
	  namesleft #1 - 'namesleft :=      % namesleft =- 1;
	}
      while$
    }
  if$
}
%    \end{macrocode}
% \end{bibfunction}
%     \subsection{Format names functions}
% The format functions operate on a string on the stack.  They make no
% warnings, produce no output, and place no spaces or punctuation before or
% after their string.
%
% \begin{bibfunction}{format.names.lastfirst}
% Format a name list. Output first author last name first, and subsequent
% authors with first name first.
%    \begin{macrocode}
FUNCTION {format.names.lastfirst}
{ 's :=
  #1 'nameptr :=               % nameptr = 1;
  s num.names$ 'numnames :=    % numnames = num.name$(s);
  numnames 'namesleft :=
    { namesleft #0 > }
    { nameptr #1 =
        {s nameptr "{vv~}{ll}{, jj}{, ff}" format.name$ 't := 
      	}
        {s nameptr "{ff~}{vv~}{ll}{, jj}" format.name$ 't := 
      	}
      if$
      nameptr #1 >
        { namesleft #1 >
              { ", " * t * 
      	      }
              { numnames #2 >
                  { "," * 
      	      	  }
                  'skip$
                if$
                t "others" =
                    { " et~al." * 
      	      	    }
                    { " and " * t * 
      	      	    }
                  if$
               }
             if$
        }
        't
      if$
      nameptr #1 + 'nameptr :=          % nameptr += 1;
      namesleft #1 - 'namesleft :=      % namesleft =- 1;
    }
  while$
}
%    \end{macrocode}
% \end{bibfunction}
%
% \begin{bibfunction}{format.names.firstfirst}
% Same as |format.names.lastfirst| but all names are first name first.
%    \begin{macrocode}
FUNCTION {format.names.firstfirst}
{ 's :=
  #1 'nameptr :=               % nameptr = 1;
  s num.names$ 'numnames :=    % numnames = num.name$(s);
  numnames 'namesleft :=
  { namesleft #0 > }
    { s nameptr "{ff~}{vv~}{ll}{, jj}" format.name$ 't := 
      nameptr #1 >
        { namesleft #1 >
            { ", " * t * 
      	    }
            { numnames #2 >
                { "," * 
      	      	}
                'skip$
              if$
              t "others" =
                  { " et~al." * 
      	      	  }
                  { " and " * t * 
      	      	  }
                if$
             }
           if$
        }
        't
      if$
      nameptr #1 + 'nameptr :=          % nameptr += 1;
      namesleft #1 - 'namesleft :=      % namesleft =- 1;
    }
  while$
}
%    \end{macrocode}
% \end{bibfunction}
%
% \begin{bibfunction}{format.names.initials}
% Format names with first initial followed by last name. 
%    \begin{macrocode}
FUNCTION {format.names.initials}
{ 's :=
  #1 'nameptr :=               % nameptr = 1;
  s num.names$ 'numnames :=    % numnames = num.name$(s);
  numnames 'namesleft :=
    { namesleft #0 > }
    { s nameptr "{f.~}{vv~}{ll}{, jj}" format.name$ 't :=
      nameptr #1 >
        { namesleft #1 >
              { ", " * t * 
      	      }
              { numnames #2 >
              	  { "," * 
      	      	  }
                  'skip$
                if$
                t "others" =
                  { " et~al." * 
 	      	  }
                  { " and " * t * 
      	      	  }
                if$
               }
             if$
        }
        't
      if$
      nameptr #1 + 'nameptr :=          % nameptr += 1;
      namesleft #1 - 'namesleft :=      % namesleft =- 1;
    }
  while$
}
%    \end{macrocode}
% \end{bibfunction}
%     \subsection{Make functions}
% `Make' commands all expect nothing on the stack, and leave one string there.
% Side effects of setting global variables are noted in the comments. 
%
%  \begin{bibfunction}{make.authors}
% If `printed.author' differs from `author' then it is a duplicate author, and
% we don't bother to format it, we just return it.  If they're the same, then
% we format the `author' field as usual.
%    \begin{macrocode}
FUNCTION {make.authors}
{ printed.author empty$
    { "" 
    }
    { printed.author author =
   	{ author format.names.lastfirst 
      	}
        { printed.author 
      	}
      if$ }
  if$
}
%    \end{macrocode}
%  \end{bibfunction}
%
%  \begin{bibfunction}{make.yearpub}
% This puts the |yearpub| field in square brackets if it exists.
%    \begin{macrocode}
FUNCTION  {make.yearpub}
{ yearpub empty$
    { "" }
    { "[" yearpub * "]" * space * }
  if$
}
%    \end{macrocode}
%  \end{bibfunction}
%
%  \begin{bibfunction}{make.year}
%  \begin{bibfunction}{make.year.nomonth}
% Makes a year string.  I'm not sure both `extra.label' and month should be
% here.  FIX
%    \begin{macrocode}
FUNCTION {make.year}
{ year empty$
    { ""
    }
    { make.yearpub year * extra.label *
      month empty$
        'skip$
        { comma * space * month * }
      if$
    }
  if$
}

FUNCTION {make.year.nomonth}
{ year empty$
    { "" }
    { make.yearpub year * extra.label * }
  if$
}
%    \end{macrocode}
%  \end{bibfunction}
%  \end{bibfunction}
%
%  \begin{bibfunction}{make.editors.primary}
% This is for when the editor is the leading thing.
%    \begin{macrocode}
FUNCTION {make.editors.primary}
{ editor empty$
    { "" 
    }
    { editor format.names.lastfirst
      editor num.names$ #1 >
      	{ ",~eds." * 
      	}
      	{ ",~ed." * 
      	}
      if$
    }
  if$
}
%    \end{macrocode}
%  \end{bibfunction}
%
%  \begin{bibfunction}{make.editors.secondary}
% This is for making editors' names that follow a title.  
%    \begin{macrocode}
FUNCTION {make.editors.secondary}
{ editor empty$
    { "" 
    }
    { output.state after.sentence = 
      output.state after.block = or
        { "E" }
        { "e" }
      if$
      "dited by " * editor format.names.firstfirst * 
    }
  if$
}
%    \end{macrocode}
%  \end{bibfunction}
%
% \begin{bibfunction}{make.translators}
% \begin{bibfunction}{make.translators}
% Translators and illustrators are always considered secondary.   
%    \begin{macrocode}
FUNCTION {make.translators}
{ translator empty$
    { "" 
    }
    { output.state after.sentence = 
      output.state after.block = or
        { "T" }
        { "t" }
      if$
      "ranslated by " * translator format.names.firstfirst *
    }
  if$
}

FUNCTION {make.illustrators}
{ illustrator empty$
    { "" 
    }
    { output.state after.sentence = 
      output.state after.block = or
        { "I" }
        { "i" }
      if$
      "llustrated by " * illustrator format.names.firstfirst *
    }
  if$
}
%    \end{macrocode}
% \end{bibfunction}
% \end{bibfunction}
%
%  \begin{bibfunction}{make.booktitle.emph}
%  \begin{bibfunction}{make.title.emph}
% We expect that |\majortitle| and |\minortitle| globally have a definition
% appropriate for emphasized whole titles.  The complicated checking |\emph|
% does to see whether italic corrections should be inserted screws up my
% |\sc@closequote| macro.  Since we're setting the whole title here, checking
% for italic corrections is pointless, and we can get away with grouping and
% |\em|, i.e., `emphasize.alternate'.  FIX: if we need italic corrections here,
% then we need to fix the conflict. 
%    \begin{macrocode}
FUNCTION {make.title.emph}
{ title field.or.null emphasize.alternate }

FUNCTION {make.booktitle.emph}
{ booktitle field.or.null emphasize.alternate }
%    \end{macrocode}
%  \end{bibfunction}
%  \end{bibfunction}
%
% \begin{bibfunction}{make.title.doublequote}
% We put the title in quotes.  We use the command |\SCclosedoublequote| to
% close the quote, to handle following periods.  We also set the definitions
% for |\majortitle| and |\minortitle|.  We are assuming the global definition
% is valid for emphasized titles.  The alternative is not to use a global
% definition.  But this makes many unnecessary divisions, or at best an
% equivalence, in the worst case bibliography of all titles being
% `make.title.doublequote's.
%    \begin{macrocode}
FUNCTION {make.title.doublequote}  
{ title empty$
    { "" 
    }
    { "\begingroup" 
      "\let\majortitle\emph \let\minortitle\SCTITsinglequote" *
      "``" * title * "\SCclosedoublequote" * 
      "\endgroup" *
    }	
  if$			
}
%    \end{macrocode}
% \end{bibfunction}
%    
%    \begin{macrocode}
FUNCTION {make.month.article}
{ month empty$
    { "" 
    }
    { "(" month * ")" *
    }
  if$
}
%    \end{macrocode}
%
%    \begin{macrocode}
FUNCTION {make.pages}
{ pages empty$
    { "" 
    }
    { pages multi.page.check
	{ pages n.dashify 
      	}
  	{ pages 
      	}
      if$
    }
  if$
}
%    \end{macrocode}
%
% FIX find a place for this comment.
% It is more flexible to not say ``ed.''\ following this field.   Then this
% becomes the general field for describing the edition of the book, number of
% volumes, ``reprint, with foreward by'' etc.
%
% \begin{bibfunction}{make.crossref}
% \mbox{}
%    \begin{macrocode}
FUNCTION {make.crossref}
{ "\citeNP{" crossref * "}" *
}
%    \end{macrocode}
% \end{bibfunction}
%
%  \begin{bibfunction}{make.number}
% Makes the number with appropriate capitalization.
%    \begin{macrocode}
FUNCTION {make.number}
{ number empty$
    { ""
    }
    { output.state mid.sentence =
        { "no." }
        { "No." }
      if$
      number tie.or.space.connect    
    }
  if$
}
%    \end{macrocode}
%  \end{bibfunction}
%
% \begin{bibfunction}{make.volume.seriesq}
%  The |series| is not required. 
%    \begin{macrocode}
FUNCTION {make.volume.seriesq}
{ volume empty$
    { ""
    }
    { "Volume" volume tie.or.space.connect
      series empty$
        'skip$
        { " of " * series emphasize * 
        }
      if$
      "volume and number" number either.or.check
    }
  if$
}
%    \end{macrocode}
% \end{bibfunction}
%
% FIX where can this comment go?
%  For some series numbers it is more appropriate not to have a comma: ``\lips
%  Bulletin no.~12.''  But we put in commas by default.
% \begin{bibfunction}{make.chapter.in}
% To say for example ``Part 3'' instead of ``Chapter 3'', put ``Part'' into the
% |type| field, and the number and the preposition into the |chapter| field,
% e.g., ``3 of''.   A tie is automatically put in between the |type| field
% and the |chapter| field in this case.  We can't make a decision based on the
% length of the |chapter| field when it's going to contain the preposition.
%
% was: format.chapter.pages
%    \begin{macrocode}
FUNCTION {make.chapter.in}
{ chapter empty$
    { ""
    }
    { type empty$
        { "Chapter" 
          chapter tie.or.space.connect
          " in " *
        }
        { type "t" change.case$ 
          "~" * chapter * " " *
        }
      if$
    }
  if$
}
%    \end{macrocode}
% \end{bibfunction}
%    
% \begin{bibfunction}{make.chapter}
%    \begin{macrocode}
FUNCTION {make.chapter}
{ chapter empty$
    { ""
    }
    { type empty$
        { "Chapter"
        }
        { type "t" change.case$
        }
      if$
      chapter tie.or.space.connect
    }
  if$
}
%    \end{macrocode}
% \end{bibfunction}
% 
% \begin{bibfunction}{make.number.tr}
% was: format.tr.number
%    \begin{macrocode}
FUNCTION {make.number.tr}
{ type empty$
    { "Technical Report" 
    }
    { type "t" change.case$ 
    }
  if$
  number empty$
    'skip$
    { number tie.or.space.connect 
    }
  if$
}
%    \end{macrocode}
% \end{bibfunction}
%     \subsection{Label functions}
% \begin{bibfunction}{calc.labels}
% Sets `short.label', `long.label' and `year.label' from the original database.
% Should only need to be called once.
%    \begin{macrocode}
FUNCTION {calc.labels}
{ type$ "book" =
  type$ "inbook" =
  or
    { start.q 
      author.q format.short.label.names.q
      editor.q format.short.label.names.q
      key.q 
      "author, editor, or key to make `short.label'" check.q
    }
    { type$ "proceedings" =
	{ start.q
      	  editor.q format.short.label.names.q 
      	  organization.q 
      	  key.q
      	  "editor, organization, or key to make `short.label'" check.q
      	}
	{ type$ "manual" =
	    { start.q
	      author.q format.short.label.names.q
      	      organization.q 
      	      key.q
      	      "author, organization, or key to make `short.label'" check.q}
	    { start.q
      	      author.q format.short.label.names.q
      	      key.q
      	      "author or key to make `short.label'" check.q 
      	    }
	  if$
	}
      if$
    }
  if$
  'short.label :=

  start.q
  author.q format.long.label.names.q
  editor.q format.long.label.names.q
  organization.q
  key.q
  "author, editor, organiztion, or key to make `long.label'" check.q
  'long.label :=

  year field.or.null purify$ #-1 #4 substring$
  'year.label :=
}
%    \end{macrocode}
% \end{bibfunction}
%     \subsection{Entry types}
%       \subsubsection{Article}
% \begin{bibfunction}{article}
%  A crossref from an article says ``See this, pages xxx.''
% See the \emph{Chicago Manual} 16:107 for this peculiar bit about the spacing
% after the colon.
%    \begin{macrocode}
FUNCTION {article}
{ begin.entry
  make.authors "author" check key.q comma output
  new.block
  make.year.nomonth "year" check comma output
  new.block
  make.title.doublequote "title" check comma output
  new.block
  crossref empty$
    { journal emphasize "journal" check comma output
      volume field.or.null
      number empty$
        { volume empty$
            { "missing volume and number in " cite$ * warning$ 
              ""
            }
            { colon
            }
          if$
        }
        { volume empty$
            { "number but no volume in " cite$ * warning$
              "no." number tie.or.space.connect
              comma * space *
            }
            { space * "(" number * ")" *
              colon * space *
            }
          if$
        }
      if$ *
      make.pages "pages" check *
      space output
      make.month.article space output
    }
    { "See " make.crossref * comma output
      make.pages "pages" check comma output
    }
  if$
  new.block
  note comma output
  finish.entry
}
%    \end{macrocode}
% \end{bibfunction}
%       \subsubsection{Book}
% \begin{bibfunction}{book}
%    \begin{macrocode}
FUNCTION {book}
{ begin.entry
  author empty$
    { make.editors.primary "author and editor" check comma output 
    }  
    { make.authors comma output
    }
  if$
  new.sentence
  make.year "year" check comma output 
  new.block
  make.title.emph "title" check comma output
  new.sentence
  edition comma output
  new.block
  crossref empty$
    { volume empty$
        { series comma output
          make.number
        }
        { make.volume.seriesq
        }
      if$
      comma output
      editor empty$ author empty$ or
        'skip$
      	{ new.sentence
	  make.editors.secondary comma output
	}
      if$
      new.sentence
      make.translators comma output
      new.sentence
      make.illustrators comma output
      new.sentence
      address comma output
      publisher "publisher" check colon output
    }
    { volume empty$
        { "In "
        }
        { "Volume" volume tie.or.space.connect
          " of " *
        }
      if$    
      make.crossref * comma output
    }
  if$
  new.block
  note comma output
  finish.entry
}
%    \end{macrocode}
% \end{bibfunction}
%       \subsubsection{Inbook}
% \begin{bibfunction}{inbook}
% The \emph{Chicago Manual} doesn't seem to recognize parts of a book without
% their own titles.  We make up our own version, moving the chapter and page
% information from the end of the |booktitle| to the front.
%%    \begin{macrocode}
FUNCTION {inbook}
{ begin.entry
  author empty$
    { make.editors.primary "author and editor" check comma output
    }
    { make.authors comma output
    }
  if$
  new.sentence
  make.year "year" check comma output
  new.block
  crossref empty$
%    \end{macrocode}
%  We are going to leave an extra copy of `make.chapter.in' on the stack here
%  so that we know whether to put pages or not after the |booktitle| sentence
%  (with editors, and so on). 
%    \begin{macrocode}
    { make.chapter.in duplicate$ duplicate$ empty$
        { pop$
          pages empty$
            { "missing chapter, type, and pages in " cite$ * warning$ 
              "In "
            }
            { "Pages " make.pages * " in "
            }
          if$
        }
        'skip$
      if$
      comma output
      make.booktitle.emph "booktitle" check space output
      make.editors.secondary comma output
      volume empty$
        { series comma output
          make.number
        }
        { make.volume.seriesq
        }
      if$
      comma output
      edition comma output
%    \end{macrocode}
%  Here we branch again on `make.chapter.in'.  If it is not empty, then we go
%  ahead and `make.pages'.  If it is empty we don't, because this means that if
%  |pages| were given, they have already been put earlier.
%    \begin{macrocode}
      empty$
        'skip$
        { make.pages comma output }
      if$
      new.sentence
      make.translators comma output
      new.sentence
      make.illustrators comma output
      new.sentence
      address comma output
      publisher "publisher" check colon output
    }
    { "See " make.crossref * comma output
      make.chapter comma output
      make.pages comma output
      chapter empty$ pages empty$ and
        { "missing chapter and pages in " cite$ * warning$ }      
        'skip$
      if$
    }
  if$
  new.block
  note comma output
  finish.entry
}
%    \end{macrocode}
% \end{bibfunction}
%       \subsubsection{Incollection}
% \begin{bibfunction}{incollection}
% \mbox{}
%    \begin{macrocode}
FUNCTION {incollection}
{ begin.entry
  author empty$
    { make.editors.primary "author and editor" check comma output
    }
    { make.authors comma output
    }
  if$
  new.sentence
  make.year "year" check comma output
  new.block
  make.title.doublequote "title" check comma output
  new.sentence
  crossref empty$
    { make.chapter.in duplicate$ empty$
        { pop$
          "In "
        }
        'skip$      
      if$
      comma output
      make.booktitle.emph "booktitle" check space output
      make.editors.secondary comma output
      volume empty$
        { series comma output
          make.number
        }
        { make.volume.seriesq
        }
      if$
      comma output
      edition comma output
      make.pages comma output
      chapter empty$ type empty$ and pages empty$ and
        { "missing chapter, type, and pages in " cite$ * warning$ }
        'skip$        
      if$
      new.sentence
      make.translators comma output
      new.sentence
      make.illustrators comma output
      new.sentence
      address comma output
      publisher "publisher" check colon output
    }
    { new.block
      "See " make.crossref * comma output
      make.chapter comma output
      make.pages comma output
      chapter empty$ pages empty$ and
        { "missing chapter and pages in " cite$ * warning$ }      
        'skip$
      if$
    }
  if$
  new.block
  note comma output
  finish.entry
}
%    \end{macrocode}
% \end{bibfunction}
%       \subsubsection{Majorthesis}
% \begin{bibfunction}{format.thesis}
% \begin{bibfunction}{thesis}
% \begin{bibfunction}{phdthesis}
% \begin{bibfunction}{mastersthesis}
% \begin{bibfunction}{majorthesis}
% \begin{bibfunction}{minorthesis}
% Theses are all set in the same way, with a different type name.  A plain
% |thesis| ought to have a type.  The other four aliases supply an explicit
% type.  This is something that could be hooked into a variable and done with
% the |babel| package:  |\majorthesisname| and so on.  
%    \begin{macrocode}
FUNCTION {format.thesis}
{ 's :=
  begin.entry
  make.authors "author" check key.q comma output
  new.block
  make.year "year" check comma output
  new.block
  make.title.doublequote "title" check comma output
  new.block
  s "type" check comma output
  school "school" check comma output
  address comma output
  new.block
  note comma output
  finish.entry
}
FUNCTION {thesis}
{ type field.or.null format.thesis }
FUNCTION{mastersthesis}
{ "Master's thesis" format.thesis }
FUNCTION {minorthesis}
{ mastersthesis }
FUNCTION {phdthesis}
{ "Ph.D.~diss." format.thesis }
FUNCTION {majorthesis}
{ phdthesis }
%    \end{macrocode}
% \end{bibfunction}
% \end{bibfunction}
% \end{bibfunction}
% \end{bibfunction}
% \end{bibfunction}
% \end{bibfunction}
%       \subsubsection{Manual}
% \begin{bibfunction}{manual}
% This is not done yet: fix.
%    \begin{macrocode}
FUNCTION {manual}
{ begin.entry
  author empty$
    { editor empty$
        { organization "organization" check key.q
      	}
        { make.editors.primary "author and editor" check
      	}
      if$
    }
    { make.authors
    }
  if$
  comma output
  new.block
  make.year "year" check comma output
  new.block
  make.title.emph "title" check comma output
  new.sentence
  edition comma output
  new.sentence
  address comma output
  organization "organization" check colon output
  new.block
  note comma output
  finish.entry
}
%    \end{macrocode}
% \end{bibfunction}
%       \subsubsection{Booklet}
%    \begin{macrocode}
FUNCTION {booklet}
{ begin.entry
  make.authors key.q comma output
  new.block
  make.year "year" check comma output
  new.block
  title "title" check comma output
  new.block
  howpublished comma output
  address comma output
  new.block
  note comma output
  finish.entry
}
%    \end{macrocode}
%       \subsubsection{Inproceedings}
% \begin{bibfunction}{inproceedings}
% \begin{bibfunction}{conference}
%    \begin{macrocode}
FUNCTION {inproceedings}
{ begin.entry
  make.authors "author" check key.q comma output
  new.block
  make.year "year" check comma output
  new.block
  title "title" check comma output
  new.block
  crossref empty$
    { make.editors.secondary comma output
      make.booktitle.emph "booktitle" check comma output
      volume empty$
        { series comma output
          make.number comma output
        }
        { make.volume.seriesq
        }
      if$
      comma output
      edition comma output
      new.sentence
      address comma output
      make.pages comma output
      new.sentence
      organization comma output
      publisher colon output
    }
    { "See " make.crossref * comma output
      make.chapter comma output
      make.pages check comma output
      chapter empty$ pages empty$ and
        { "missing chapter and pages in " cite$ * warning$ }      
        'skip$
      if$
    }
  if$
  new.block
  note comma output
  finish.entry
}
FUNCTION {conference} 
{ inproceedings }
%    \end{macrocode}
% \end{bibfunction}
% \end{bibfunction}
%       \subsubsection{Proceedings}
% \begin{bibfunction}{proceedings}
%    \begin{macrocode}
FUNCTION {proceedings}
{ begin.entry
  make.editors.primary key.q comma output
  if$
  new.block
  make.year "year" check comma output
  new.block
  make.title.emph "title" check comma output
  new.sentence
  edition comma output
  new.sentence
  volume empty$
    { series comma output
      make.number comma output
    }
    { make.volume.seriesq
    }
  if$
  comma output
  address comma output
  new.sentence
  organization comma output
  publisher colon output
  new.block
  note comma output
  finish.entry
}
%    \end{macrocode}
% \end{bibfunction}
%       \subsubsection{Misc}
% Should title be emphasized or quoted?
%    \begin{macrocode}
FUNCTION {misc}
{ begin.entry
  make.authors key.q comma output
  new.block
  make.year "year" check comma output
  new.block
  title comma output
  new.sentence
  howpublished comma output
  new.block
  note comma output
  finish.entry
}
%    \end{macrocode}
%       \subsubsection{Techreport}
% \begin{bibfunction}{techreport}
% \mbox{}
%    \begin{macrocode}
FUNCTION {techreport}
{ begin.entry
  make.authors "author" check key.q comma output
  new.block
  make.year "year" check comma output
  new.block
  title "title" check comma output
  new.sentence
  make.number.tr comma output
  institution "institution" check comma output
  address comma output
  new.block
  note comma output
  finish.entry
}
%    \end{macrocode}
% \end{bibfunction}
%       \subsubsection{Unpublished}
% \begin{bibfunction}{unpublished}
% \mbox{}
%    \begin{macrocode}
FUNCTION {unpublished}
{ begin.entry
  make.authors "author" check key.q comma output
  new.block
  make.year "year" check comma output
  new.block
  title "title" check comma output
  new.block
  note "note" check comma output
  finish.entry
}
%    \end{macrocode}
% \end{bibfunction}
%       \subsubsection{Default}
% \begin{bibfunction}{default.type}
% \mbox{}
%    \begin{macrocode}
FUNCTION {default.type} 
{ misc }
%    \end{macrocode}
% \end{bibfunction}
%     \subsection{Sorting}
% \begin{bibfunction}{sortify}
% Prepare the string on the stack for sort comparison
% \stack{\meta{string}}{\meta{string}}
%    \begin{macrocode}
FUNCTION {sortify}
{ purify$
  "l" change.case$
}
%    \end{macrocode}
% \end{bibfunction}
%
% \begin{bibfunction}{chop.word}
% \stack{\meta{string} \meta{num} \meta{string}}{\meta{string}}
% \begin{verbatim}
% stack: S n T
%
% if S = substr(1,n,T)
%    then substr(n+1, max, T)
%    else S
%
% if T begins with S, then chop it off. 
% \end{verbatim}
%    \begin{macrocode}
FUNCTION {chop.word}
{ 's :=
  'len :=
  s #1 len substring$ =
    { s len #1 + global.max$ substring$ }
    's
  if$
}
%    \end{macrocode}
% \end{bibfunction}
%
% \begin{bibfunction}{sort.format.names}
% \stack{\meta{list of names}}{\meta{list of names suitable for sorting}}
%    \begin{macrocode}
FUNCTION {sort.format.names}
{ 's :=
  #1 'nameptr :=
  ""
  s num.names$ 'numnames :=
  numnames 'namesleft :=
    { namesleft #0 > }
    { nameptr #1 >
        { "   " * 
 	}
        'skip$
      if$
      s nameptr "{vv{ } }{ll{ }}{  f{ }}{  jj{ }}" format.name$ 't :=
      nameptr numnames = t "others" = and
        { " et~al." * 
        }
        { t sortify * 
        }
      if$
      nameptr #1 + 'nameptr :=
      namesleft #1 - 'namesleft :=
    }
  while$
}
%    \end{macrocode}
% \end{bibfunction}
%
% \begin{bibfunction}{sort.format.title}
% \stack{\meta{title}}{\meta{title suitable for sorting}}
%    \begin{macrocode}
FUNCTION {sort.format.title}
{ 't :=
  "A " #2
    "An " #3
      "The " #4 t chop.word
    chop.word
  chop.word
  sortify
  #1 global.max$ substring$
}
%    \end{macrocode}
% \end{bibfunction}
%
% \begin{bibfunction}{author.sort}
% Put an author-sort string on the stack.  If there is no author entry, 
% use the key entry. 
%    \begin{macrocode}
FUNCTION {author.sort}
{ author empty$
    { key empty$
         { "to sort, need author or key in " cite$ * warning$
           "" }
         { key sortify }
      if$
    }
    { author sort.format.names }
  if$
}
%    \end{macrocode}
% \end{bibfunction}
%
% \begin{bibfunction}{editor.sort}
% Put an editor-sort string on the stack.  If there is no editor entry, use the
% key entry. 
%    \begin{macrocode}
FUNCTION {editor.sort}
{ editor empty$
    { key empty$
         { "to sort, need editor or key in " cite$ * warning$
           ""
         }
         { key sortify }
      if$
    }
    { editor sort.format.names }
  if$
}
%    \end{macrocode}
% \end{bibfunction}
%
% \begin{bibfunction}{author.editor.sort}
% Put an author-sort string on the stack.  If there is no author entry, use the
% editor entry.  If there is no editor entry either, use the key entry. 
%    \begin{macrocode}
FUNCTION {author.editor.sort}
{ author empty$
    { "missing author in " cite$ * warning$
      editor empty$
         { key empty$
             { "to sort, need author, editor, or key in " cite$ * warning$
               ""
             }
             { key sortify }
           if$
         }
         { editor sort.format.names }
      if$
    }
    { author sort.format.names }
  if$
}
%    \end{macrocode}
% \end{bibfunction}
%
% \begin{bibfunction}{author.organization.sort}
% Put an author-sort string on the stack.  If there is no author entry, use the
% organization entry.  if there is no org entry either, use the key entry. 
%    \begin{macrocode}
FUNCTION {author.organization.sort}
{ author empty$
    { organization empty$
	{ key empty$
	    { "to sort, need author, organization, or key in " cite$ * warning$
	      ""
	    }
	    { key sortify }
	  if$
	}
	{ organization sortify }
      if$
    }
    { author sort.format.names }
  if$
}
%    \end{macrocode}
% \end{bibfunction}
%
% \begin{bibfunction}{editor.organization.sort}
% Put an editor-sort string on the stack.  If there is no editor entry, use the
% organization entry. If there is no org entry either, use the key entry. 
%    \begin{macrocode}
FUNCTION {editor.organization.sort}
{ editor empty$
    { organization empty$
	{ key empty$
	    { "to sort, need editor, organization, or key in " cite$ * warning$
	      ""
	    }
	    { key sortify }
	  if$
	}
	{ organization sortify }
      if$
    }
    { editor sort.format.names }
  if$
}
%    \end{macrocode}
% \end{bibfunction}
%
% \begin{bibfunction}{first.presort}
% Create labels with |calc.labels|, and then set |sort.key$| based on entry
% type.
%    \begin{macrocode}
FUNCTION {first.presort}
{ calc.labels
  long.label sortify
  year.label *
  "    " *
  type$ "book" =
  type$ "inbook" =
  or
    'author.editor.sort
    { type$ "proceedings" =
	'editor.organization.sort
	{ type$ "manual" =
	    'author.organization.sort
	    'author.sort
	  if$
	}
      if$
    }
  if$
  entry.clip
  'sort.label :=          

  sort.label *
  "    "  *
  title field.or.null sort.format.title * 
  entry.clip
  'sort.key$ :=
}
%    \end{macrocode}
% \end{bibfunction}
%
% \begin{bibfunction}{initialize.extra.label.stuff}
%    \begin{macrocode}
FUNCTION {initialize.extra.label.stuff}
{ unidentified 'last.label :=
  unidentified 'last.label.and.year :=
  "" 'next.extra.label :=
  #0 'last.extra.num :=
}
%    \end{macrocode}
% \end{bibfunction}
%
% \begin{bibfunction}{forward.pass}
% Pass through the new list, comparing current entry's long label to the last
% entry's (`last.label.and.year').  If the same, step `extra.label' through the
% lowercase letters.  If not, set `last.label.and.year' appropriately, set
% `extra.label' to nil, and set `last.extra.num' to~0.  After this has been
% iterated, `extra.label' will be blank for all first entries, and ``b,''
% ``c,'' or more for second entries, third entries, and so on. The ``a'''s will
% be added in the right places by the reverse pass.
%
% We also use the forward pass to set the proper value of `final.label', which
% is a 3em dash whenever the current label is the same as `last.label', and
% simply the current label otherwise.
%    \begin{macrocode}
FUNCTION {forward.pass}
{ long.label year.label * entry.clip
  duplicate$
  last.label.and.year =
     { pop$
       last.extra.num #1 + 'last.extra.num :=
       last.extra.num int.to.chr$ 'extra.label :=
     }
     { "a" chr.to.int$ 'last.extra.num :=
       "" 'extra.label :=
       'last.label.and.year := 
     }
  if$
%    \end{macrocode}
% When `long.label' is `unidentified' twice in a row, it shouldn't count as a
% repeated name.  FIX wait am minute, we should not be comparing `long.label'
% but something else!  `long.label' reduces information possibly!
%    \begin{macrocode}
  long.label entry.clip
  duplicate$ unidentified =
      { pop$
      	unidentified 'last.label :=
        author field.or.null 'printed.author :=
      }
    { duplicate$
      last.label =
          { pop$
          "\SCduplicate{"
      	  author field.or.null * 
      	  "}" *
      	  'printed.author :=
          }
        { 'last.label :=
           author field.or.null 'printed.author :=
        }
      if$
    }
  if$ 
}
%    \end{macrocode}
% \end{bibfunction}
%
% \begin{bibfunction}{reverse.pass}
% Pass through in reverse order, making `extra.label' ``a'' on entries that
% come after ones with ``b'''s.  `next.extra.label' contains the extra.label of
% the entry which follows the current entry in \emph{forward} order.
%    \begin{macrocode}
FUNCTION {reverse.pass}
{ next.extra.label "b" =
    { "a" 'extra.label := }
     'skip$
  if$
  year.label extra.label * 'sort.year.label :=
  extra.label 'next.extra.label :=
}
%    \end{macrocode}
% \end{bibfunction}
%
% \begin{bibfunction}{second.presort}
% Now that all `extra.label''s are correct,  we are ready to make the final
% sort key:  `sort.label' + year + title
%    \begin{macrocode}
FUNCTION {second.presort}
{ sort.label
  "    "
  *
  year field.or.null sortify
  *
  "    "
  *
  title field.or.null
  sort.format.title
  *
  #1 entry.max$ substring$
  'sort.key$ :=
}
%    \end{macrocode}
% \end{bibfunction}
%
% \begin{bibfunction}{begin.bib}
% \begin{bibfunction}{end.bib}
%    \begin{macrocode}
FUNCTION {begin.bib}
{ preamble$ empty$
    'skip$
    { preamble$ write$ newline$ }
  if$
  "\begin{thebibliography}{}" write$ newline$
}
FUNCTION {end.bib}
{ newline$
  "\end{thebibliography}" write$ newline$
}
%    \end{macrocode}
% \end{bibfunction}
% \end{bibfunction}
%     \subsection{Actions}
%    \begin{macrocode}
READ

EXECUTE {init.state.consts}

ITERATE {first.presort}
SORT 

EXECUTE {initialize.extra.label.stuff}

ITERATE {forward.pass}
REVERSE {reverse.pass}

ITERATE {second.presort}
SORT 

EXECUTE {begin.bib}
ITERATE {call.type$}
EXECUTE {end.bib}
%    \end{macrocode}
%    \begin{macrocode}
%</achicago>
%    \end{macrocode}
%^^A* Finale
% \Finale
\endinput
