Plan 9 from Bell Labs’s /usr/web/sources/contrib/steve/root/sys/lib/texmf/tex/latex/custom-bib/merlin.mbs

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


%\iffalse         THIS IS A META COMMENT
%==================================================================== 
%       Master  Bibliography  Style
%    for customizing bibliographic style files (.bst)
%    with the help of     docstrip.tex
%    and the auxiliary program     makebst.tex
%--------------------------------------------------------------------
%   (See version and date in the \ProvidesFile command below)
%--------------------------------------------------------------------
%    This file supports numerical and author-year citation styles
%        for natbib, harvard, astronom, authordate, apalike
%    It also supports languages other than English
%--------------------------------------------------------------------
%    This file is self-documenting: simply LaTeX it!
%  (Alternatively, extract documentation driver with option `driver')
%==================================================================== 
%
%<*!tail>
 %-------------------------------------------------------------------
 % The original source file contains the following version information:
%\fi
 % \ProvidesFile{merlin.mbs}[1996/12/16 3.82 (PWD)]
%\iffalse
 %
 % NOTICE:
 % This file may be used for non-profit purposes.
 % It may not be distributed in exchange for money, 
 %   other than distribution costs.
 %   
 % The author provides it `as is' and does not guarantee it in any way.
 % 
 % Copyright (C) 1994, 1995, 1996 Patrick W. Daly
% Max-Planck-Institut f\"ur Aeronomie
% Postfach 20
% D-37189 Katlenburg-Lindau
% Germany
% 
% E-mail: daly@linmpi.mpae.gwdg.de   
 %-------------------------------------------------------------------
%</!tail>
%<*a&!a>
% The following ensures that the driver part is not seen by makebst
% The driver part must not contain any \end other than \end{document} !
\ifx\endoptions\undefined\let\tempx=\relax\else
  \long\def\tempx#1\end#2{}\fi\tempx
%</a&!a>
%<*driver>
   \NeedsTeXFormat{LaTeX2e}%
   \documentclass[a4paper,10pt,twoside]{article}%
   \usepackage{doc}%
   \raggedbottom
   \CodelineNumbered
   \RecordChanges
 %  Comment out next line to print coding
   \OnlyDescription
   \setlength{\oddsidemargin}{0.5\paperwidth}
   \addtolength{\oddsidemargin}{-0.5\textwidth}
   \addtolength{\oddsidemargin}{-1in}
   \setlength{\evensidemargin}{\oddsidemargin}

\begin{document}
   \DocInput{merlin.mbs}
\end{document}
%</driver>
%                   END OF META COMMENT   \fi
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
% \CheckSum{277}
% \setcounter{StandardModuleDepth}{1}
% \setcounter{IndexColumns}{2}
% \setlength{\IndexMin}{10cm}
%
% \changes{1.0}{1993 Aug 16}{Initial version}
% \changes{2.0}{1994 Jan 31}{Add multilingual capabilities}
% \changes{2.1--2.5}{1995 May 2}{Changes to \texttt{babel.mbs} parallel 1.3--1.7
%    in \texttt{genbst.mbs}}
% \changes{1.3(2.1)}{1994 Jul 1}{Change documentation to \LaTeXe}
% \changes{1.3(2.1)a}{1994 Sep 1}{Alter wording of article title capitalization
%          choice}
% \changes{1.4(2.2)}{1994 Sep 5}{Add full author name possibilities}
% \changes{1.4(2.2)}{1994 Sep 5}{Fix up some punctuations}
% \changes{1.4(2.2)a}{1994 Sep 7}{Add possibility to put titles in quotes}
% \changes{1.5(2.3)}{1994 Sep 15}{Accommodate new \texttt{harvard.sty}}
% \changes{1.5(2.3)}{1994 Sep 15}{Add full names for \texttt{natbib} v5.3}
% \changes{1.5(2.3)a}{1994 Oct 11}{Add option so year can contain any text}
% \changes{1.5(2.3)b}{1995 Jan 18}{Allow edited by to be in parentheses}
% \changes{1.5(2.3)b}{1995 Jan 18}{Allow (year) to have no punctuation 
%     following}
% \changes{1.5(2.3)c}{1995 Jan 20}{Journal volume numbers with more choice}
% \changes{1.6(2.4)}{1995 Feb 2}{Date with no punctuation preceding it}
% \changes{1.6(2.4)}{1995 Feb 2}{Editor names can be reversed like authors'}
% \changes{1.6(2.4)}{1995 Feb 2}{Can abbreviate `edited by' to `ed(s).'}
% \changes{1.6(2.4)}{1995 Feb 2}{Released version}
% \changes{1.7(2.5)}{1995 Feb 9}{Add \texttt{seq-key} option}
% \changes{3.0}{1995 Mar 15}{Becomes \texttt{merlin.mbs}, with language 
%      support in additional files}
% \changes{3.0}{1995 Feb 27}{Allow full author names to be reversed}
% \changes{3.0}{1995 Mar 1}{Add \texttt{isbn} field option}
% \changes{3.0}{1995 Mar 3}{Citation names can be bold or small caps}
% \changes{3.0}{1995 Mar 8}{Colon and space may follow year}
% \changes{3.0}{1995 Mar 15}{Names can be reversed, dotless intials}
% \changes{3.0}{1995 Mar 17}{Volume, number can be followed by semi-colon}
% \changes{3.0}{1995 Mar 20}{Allow word editor or ed to be in parentheses}
% \changes{3.0}{1995 Mar 20}{Abbreviated journal names can have dots removed}
% \changes{3.1}{1995 May 4}{Fix `edited by' so it is not abbreviated
%         automatically with `editor'}
% \changes{3.1}{1995 May 6}{Re-do head/tail options to allow easy update of
%         older \texttt{.dbj} files}
% \changes{3.2}{1995 May 19}{Minimum number of authors can be up to 6, not  5}
% \changes{3.2}{1995 May 19}{Allow date as part of journal spec., for medical
%         journals}
% \changes{3.2}{1995 May 19}{Suppress `pages' and `pp'}
% \changes{3.2}{1995 May 19}{Allow date to be `1994 Jul', with or without dot}
% \changes{3.2}{1995 Jun 7}{Authors as Jones C.T.}
% \changes{3.2}{1995 Jun 16}{Sort without \emph{von} part}
% \changes{3.2}{1995 Jul 31}{Release as version 3.2}
% \changes{3.3}{1995 Aug 7}{Extra labels put in braces so they are treated 
%     as one unit by natbib}
% \changes{3.3}{1995 Aug 7}{Publisher's address can precede name}
% \changes{3.3}{1995 Sep 4}{Add full authors only if different from short list}
% \changes{3.4}{1995 Sep 5}{Add number of references as argument to
%      \texttt{thebibliography} environment}
% \changes{3.4}{1995 Sep 28}{Fix placement of \texttt{bolden} in
%      \texttt{format.vol.num.pages}}
% \changes{3.4}{1995 Sep 28}{Add possibility of date between volume and pages}
% \changes{3.4}{1995 Sep 28}{Word `and' can be in normal font in citations}
% \changes{3.5}{1995 Oct 4}{Tech Reports to have titles like books}
% \changes{3.5}{1995 Oct 9}{Delimit \texttt{\char`\\harvardyearright} properly}
% \changes{3.5}{1995 Oct 9}{Add option to sort by year (numerical only)}
% \changes{3.5}{1995 Oct 12}{Allow multiple journal-name files}
% \changes{3.5}{1995 Oct 16}{Allow months in dates even for author-year}
% \changes{3.5}{1995 Oct 24}{Fix sorting bug for limited number of authors}
% \changes{3.5}{1995 Oct 30}{Add \texttt{named} format for author--year cites}
% \changes{3.6}{1995 Nov 2}{Blocks can be separated by semi-colons}
% \changes{3.6}{1995 Nov 23}{Journal titles in normal font}
% \changes{3.6}{1995 Nov 23}{Volume subnumber added to pages}
% \changes{3.6}{1995 Nov 24}{Book pages in parentheses}
% \changes{3.6}{1995 Dec 7}{Put Jr at end for AGU author style}
% \changes{3.6}{1995 Dec 7}{Put `and' in same font in list and citation}
% \changes{3.6}{1996 Jan 30}{Allow `et al' to be in normal font}
% \changes{3.6a}{1996 Feb 1}{Fix bugs with \texttt{xand} option}
% \changes{3.7}{1996 Feb 2}{Fix small caps with NFSS}
% \changes{3.7}{1996 Feb 5}{Fix clash of \texttt{emphasize} and 
%      \texttt{purify\$}}
% \changes{3.8}{1996 Feb 29}{Add \texttt{alpha}-type style}
% \changes{3.8}{1996 Mar 1}{Style alpha is never unsorted}
% \changes{3.8}{1996 Mar 12}{Allow blanks between blocks}
% \changes{3.8}{1996 Mar 12}{Publisher in parentheses}
% \changes{3.8}{1996 Mar 15}{Allow author-year to be sorted by year}
% \changes{3.8}{1996 Mar 16}{Cited `and' resets only one attribute}
% \changes{3.8}{1996 Mar 19}{Allow date to be between volume and number}
% \changes{3.81}{1996 Jun 17}{Add \texttt{\char`\\natexlab} for \texttt{natbib} 6.3}
% \changes{3.81}{1996 Jun 19}{Fix coding for adding `page' to journals}
% \changes{3.81}{1996 Jun 19}{Add `volume' to journals}
% \changes{3.81}{1996 Jun 19}{Remove word `in'}
% \changes{3.81}{1996 Jun 19}{Place publisher before chapter/pages}
% \changes{3.81}{1996 Jun 25}{Allow period after date}
% \changes{3.81}{1996 Jun 26}{Commas between blocks, except for article titles
%         where period comes}
% \changes{3.81}{1996 Sep 12}{Allow comma before date}
% \changes{3.81}{1996 Sep 13}{Reorganize incollection organization and
%             publisher}
% \changes{3.81}{1996 Sep 13}{Allow edition to come before publisher}
% \changes{3.81}{1996 Sep 16}{Allow author--year to be in citation order}
% \changes{3.81}{1996 Sep 16}{Publisher, address, date can all be in
%            parentheses}
% \changes{3.81}{1996 Sep 18}{Remove extraneous hyphen before
%           \texttt{\char`\\getans}}
% \changes{3.82}{1996 Nov 15}{Allow pages at end before notes}
% \changes{3.82}{1996 Nov 15}{Fix bug with quoted titles when title missing}
% \changes{3.82}{1996 Dec 16}{Fix bug that put comma before publisher in
%           parentheses}
% \changes{3.82}{1996 Dec 16}{Allow AGU author style with full names}
%
% \pagestyle{myheadings}
% \markboth{P. W. Daly}{A General Master Bibliography Style}
%
% \title{{\bfseries A Master Bibliographic Style File}\\
%      for numerical, author--year, multilingual applications}
%    
% \author{Patrick W. Daly}
%         
% \GetFileInfo{merlin.mbs}
% \date{This paper describes file \texttt{\filename},\\
%  version \fileversion{} from \filedate}
% 
% \maketitle
%
% \MakeShortVerb{\|}
% 
% \parskip=1ex \parindent=0pt
%
% \newcommand{\btx}{{\sc Bib}\TeX}
% \newcommand{\dtx}{\textsf{docstrip}}
% 
% \section{Introduction}
% A problem facing users of \btx{} is that there is no standard for
% formatting lists of references. Publishers and journals insist
% on completely arbitrary placement of commas, colons, and ordering of
% entries. Furthermore, author--year styles of citations are supported by
% certain special \LaTeX{} packages, but each for only a very limited
% number of bibliographic styles. Finally, most such style files are for
% English only, and any adaptations to other languages must duplicate the
% entire spectrum of such files.
% 
% All of these obstacles are in principle easily overcome by simply
% reprogramming \btx{} by means of an appropriate \emph{bibliographic style
% file} (extension \texttt{.bst}). \btx{} is in fact extremely flexible;
% unfortunately its programming language is very low-level, permitting only
% the most basic of hacks for the normal user.
% 
% The solution to this is a \emph{generic} or \emph{master bibliographic
% style file} (extension \texttt{.mbs}) containing \dtx{} options for
% alternative coding. By selecting the desired options, one can customize a
% \texttt{.bst} file to one's needs. 
% 
% This file, \texttt{\filename}, is my latest version of a general-purpose
% \texttt{.mbs} file to meet as many bibliographic needs as possible.
% It was originally assembled from Oren Patashnik's standard files {\tt
% plain.bst} and \texttt{unsrt.bst}, plus his non-standard file {\tt
% apalike.bst}, a very basic author--year citation style.
% It has since evolved extensively as I have added features found in
% available \texttt{.bst} files, and those demanded by publishers or
% suggested to me by many user/contributors.
% 
% To produce a customized bibliographic style (\texttt{.bst}) file from this
% master file, simply \TeX{} or \LaTeX{} the `program' \texttt{makebst.tex}.
% When asked for the name of the master file, answer with
% \begin{quote}\tt\filename\end{quote}
% and then reply to the questions in the following menus. The last question
% is whether you want to generate the \texttt{.bst} file right away. 
% 
% More details on this process and on the options available are to be found
% in the rest of this article.
% 
% \section{History of this File}
% 
% Since the first release of this generic file, in November 1993, under the 
% name \texttt{genbst.mbs}, I have received innumerable
% suggestions for additions, most of which I have tried to include. Often
% this has resulted in reorganizing the coding, and adding new functions.
% The resulting \texttt{.bst} files are now quite different from those of
% Patashnik, although the underlying ideas are the same.
% 
% A second version was released shortly afterwards that paralleled the first
% one except that it included support for languages other than English.
% That file was named \texttt{babel.mbs}, following the \texttt{babel}
% system of Johannes Braams. Although I always viewed it as version 2 of
% \texttt{genbst.mbs}, all additions to the one were also included in the
% other. This of course was tedious and prone to error. I looked forward to
% the day when \texttt{babel.mbs} would become the only supported version.
% The reason I was reluctant to do that before was that the overhead per
% language was fairly high, and I dreaded to think how large the file would
% become when 20 or 30 languages were added.
% 
% I have now found a way to put the language definitions into separate files,
% one per language. This means that new languages do not burden the basic
% file, and that users need only keep those support files that might
% interest him or her. New ones may also be made up locally by hacking an
% existing language definition file. (The file \texttt{english.mbs} is
% supplied only for this purpose.)
% 
% For this reason, \texttt{\filename} is released as version~3 of
% \texttt{genbst.mbs} and \texttt{babel.mbs}. In spite of the new name, it
% should be regarded as their direct successor. Needless to say, this means
% that the earlier two \texttt{.mbs} files will no longer be maintained.
% 
% To include language support, all explicit English words like
% \textsl{editor} and \textsl{chapter} have been replaced by functions
% whose definitions may be altered in the resulting \texttt{.bst} file
% (less desirable method) or which may be redefined by an external
% language definition file (preferred method).  Alternatively, one can select
% the pseudo-language named \texttt{babel} which inserts \LaTeX{} commands 
% for the explicit words, the definitions of which must be
% contained in a file called {\tt babelbst.tex}. Only the languages English
% and \texttt{babel} are included internally to \texttt{\filename}; all
% others are contained in external language definition files.
% 
% Another new feature is the possibility of including a file containing
% prestored shorthand designations for certain journal names. Such a file
% is provided for physics journals, but others could be made up using this
% one as a model. See Section~\ref{sec:jnames}.
% 
% To take advantage of these external files, one must use
% \texttt{makebst} version~3; \texttt{\filename} may still be used with
% earlier versions, but without the external files.
% 
% \def\temp{merlin.mbs}\ifx\temp\filename
% This file is now named after the legendary magician in the hope that it
% can produce wonders by incanting the right magic formulas. However, one
% should bear in mind that even Merlin was not omnipotent. It would be too
% much to hope that all bibliographic wishes will be fulfilled quickly and
% easily, but we shall try as best we can. Watch the wizardry at work!
% \fi
% 
% \section{About Master Bibliographic Style Files}
% 
% For details about how master bibliography style files are to be
% constructed, see the documentation on \texttt{makebst}. Here only a
% rough overview is given.
% 
% \subsection{The \dtx{} Program}
% The \dtx{} program, written by Frank Mittelbach, is now a fundamental
% part of the \LaTeXe{} installation. Its original purpose is to remove
% comment lines from documented files, but has the secondary function of
% selecting alternative lines of coding.
% 
% A master \btx{} bibliographic style file is one that, when processed by
% \dtx{} with selected options, produces a regular \btx{} \texttt{.bst}
% file with the desired features.
% 
% In this sense, \dtx{} functions something like a C preprocessor. In fact,
% Oren Patashnik's original \texttt{.bst} files were all produced from a single
% source file by means of the preprocessor. The advantage of \dtx{} is that
% it is portable to all installations with \TeX.
%
% \subsection{The \dtx{} Batch Job}
% 
% The \dtx{} program can be run either interactively, where the user must
% answer questions via the keyboard, or by means of a batch job where all
% the inputs are prepared in a file beforehand. For producing a \btx{}
% style file from a master file, the batch job method is the only feasible
% one, simply because of the large number of options available. (There is
% another reason for employing a batch job: the interactive method adds an
% |\endinput| command at the end, something that \btx{} will protest
% about.)
% 
% The batch job files in general do not have any particular extension but I
% use \texttt{.dbj} for \emph{\dtx{} batch job}. These files are useful
% because they document the options used to produce the \texttt{.bst} file,
% and they may be edited to experiment with alternative options.
%
% \subsection{The \texttt{makebst} Program}
% 
% It is possible to make up a batch job file by hand using the option
% information listed in Section~\ref{sec:options}, but my accompanying
% program \texttt{makebst} simplifies the task considerably. It reads menu
% information in the master file itself in order to present the user with
% an interactive list of choices, translating the answers into appropriate
% options that are then written to a batch job file.
% 
% To run it, simply process \texttt{makebst.tex} with \TeX\ or \LaTeX, and
% answer the questions. The first of these is whether you want some
% instructions or not, and the second is the name of the \texttt{.mbs} that
% you want to use. The next query is about the name of the desired
% \texttt{.bst} file (which will also be the root name of the batch job).
% After that, all further questions come from menu information in the
% master file.
% 
% At the very end, \texttt{makebst} asks if it should run the batch job for
% you. Isn't that a fine service?
% 
% \section{Multilingual Adaptation}
% The original \texttt{.bst} files from Oren Patashnik contain explicit
% English words that are output into the final text. Since \LaTeX{} is
% increasingly being used for other languages, and since the official
% version since December 1991 also uses macros in place of explicit words,
% it seems appropriate for \btx{} to follow suit.
% 
% In this master bibliographic style file {\tt\filename}, all explicit
% words have been replaced by functions: e.g., the word \textsl{editor} has
% become the function \texttt{bbl.editor}. Depending on the language option
% chosen, this function is defined to be the text {\tt"editor"},
% {\tt"Redakteur"}, or {\tt"redacteur"}, for English, German, and French,
% respectively. 
% 
% There is another special `language' called \texttt{babel} that instead inserts
% the text |"\bbleditor{}"|; the definitions of these \LaTeX{} commands
% must be in a separate file named \texttt{babelbst.tex} that is read in at
% the start of the bibliography.
% 
% Only English and \texttt{babel} are supported directly in
% \texttt{\filename}; all other language definitions are contained in
% separate definition files, e.g., \texttt{french.mbs}, \texttt{german.mbs}.
% 
% The language selection is made during the \texttt{makebst} run, which
% asks for the name of the language definition file as the first menu item. If
% either English or \texttt{babel} is wanted, reply with the default, which
% is \texttt{\filename} itself; otherwise give the name of the desired
% language file. 
% 
% \begin{quote}\slshape
%   \textbf{Note:} the language definition files can only be used with
%   \texttt{makebst} version~3 or later, and
%   
%   with an external definition file, the \dtx{} run requires two passes
%   through \texttt{\filename}, doubling the processing time.
% \end{quote}
%   
% \subsection{Adding a New Language Definition File}
% 
% To create a new language definition file, simply take one of the existing
% ones, like \texttt{english.mbs}, and replace the explicit English words
% with their translations. There are, however, a number of points that can
% complicate this procedure.
% 
% \begin{enumerate}
% \item
%   Do not forget to change the documentation in the file, especially
%   version number, date, author.
%   
% \item
%   There are option menus that need to be translated too. It might also be
%   desirable to add or remove options. In most cases, the options in the
%   language files involve possible abbreviations, like
%   \begin{quote}
%      \verb!\mes{^^JABBREVIATE WORD `PAGES':}!\\
%      \verb!\optdef{*}{}{`Page(s)'}{(no abbreviation)}!\\
%      \verb!\optdef{a}{pp}{`Page' abbreviated}{as p. or pp.}!\\
%      \verb!\getans!
%   \end{quote}
%   
%   In this example, the option \texttt{pp} appears later in the definition
%   \begin{quote}
%      \verb!FUNCTION {bbl.pages}!\\
%      \verb+%<!pp>{ "pages" }+\\
%      \verb!%<pp>{ "pp." }!
%   \end{quote}
%   This a \emph{local} option, that only affects the coding in the definition
%   file. It is possible to add more local options.
%   
% \item
%   However, all options, whether activated by the main file or by the
%   definition file, apply to both. In other words, there really is no such
%   thing as a local option. In the above example, \texttt{pp} is only
%   local because it is never used in \texttt{\filename}.
% 
% \item
%   Add the name of the language as an option, with
%   \begin{quote}
%      \verb!\mes{^^JOptions for ENGLISH}!\\
%      \verb!\wr{\spsp\spsp\sep english\pc: English language}!
%   \end{quote}  
%   (This is how options are added without |\optdef| and |\getans|.) The
%   main file just might recognize it in order to take some
%   language-specific action. The least it should do is add a comment at
%   the start of the \texttt{.bst} file stating for which language it is to
%   be used.
% 
% \item
%   There could be some problems with edition numbers due to language
%   dependent ways of treating ordinal numbers (1st, 2nd, 3rd in English;
%   1$^{\mbox{\scriptsize re}}$, 2$^{\mbox{\scriptsize e}}$, 
%   3$^{\mbox{\scriptsize e}}$ in French; 1., 2., 3., in German). Some
%   accommodation already exists for the oddball language English, and
%   further hacking may be needed for others.
%   
% \item
%   If there should be any need for a double-quote character in
%   the translations (German needs it for umlauts) then there is trouble
%   because the \btx{} strings do not allow it. Instead, use the command
%   |\qq|, as in the German word |F\qq{u}nfte| for {\sl F\"unfte} (fifth).
%   It is then vital to add the option \texttt{umlaut} with
%   \begin{quote}
%      \verb!\wr{\spsp\spsp\sep umlaut\pc: Activate umlaut command}!
%   \end{quote}
% 
% Bernd Raichle points out that |\^^b| can be used in place of |\"|
% within \btx{} code. One can thus replace |F\qq{u}nfte| with |F\^^b unfte|
% and do away with the \texttt{umlaut} option.
%
% \end{enumerate}
% 
% \subsection{Changing \texttt{babelbst.tex} for a New Language}
%
% Alternatively, a new language can be added by
% modifying the file \texttt{babelbst.tex} and selecting the language {\tt
% babel} for the \texttt{.bst} file. If this is the only language to be used,
% then just change the English words in the definitions. 
% 
% However, some form of switching would be more desirable. With \TeX\
% version 3, there is a |\language| parameter to control the hyphenation
% patterns, and this could be used to select the correct language. For
% example, if language 0 is English and language 1 German, then put the
% English version of \texttt{babelbst.tex} into \texttt{englbst.tex} and the 
% German
% version in \texttt{germbst.tex}. Then \texttt{babelbst.tex} could contain:
% \begin{quote}\begin{verbatim}
% \ifcase\language \input{englbst} \or \input{germbst} 
%   \else \input{englbst} \fi
% \end{verbatim}
% \end{quote}
% 
% This is of course installation dependent. 
% 
% \subsection{Extracting the Sample \texttt{babelbst.tex} File}
%
% A sample \texttt{babelbst.tex} (for English) is contained in this master
% file.  Extract it with \dtx{} and the option \texttt{bblbst}. It may be
% edited (and possibly renamed) for other languages as needed.
% 
% \subsection{Problem with Edition Numbers}
% Something to note here is the ordinal numbers for editions. \btx{}
% demands that the field \texttt{edition} be given in the database as a word
% \textsl{First}, \textsl{Second}, etc., or as \textsl{1st}, \textsl{2nd}, 
% etc. This is bad policy
% because it is language dependent. So what I do is to test for the words
% \textsl{first} through \textsl{fifth} (case independently) and replace them 
% with language-dependent equivalents. If the {\tt<ord>} option is selected,
% these equivalents are ordinal numbers for that language. Any other words
% cannot be interpreted and must be printed as is. 
% 
% However, if the \texttt{edition} is given as a number, with or without
% following letters, then the numbers 1 through 5 are replaced by their
% words; any higher numbers just have the ordinal ending (\textsl{th} 
% in English) added to them. 
% 
% These numbers are only used with the word \textsl{edition} or 
% its equivalent in other languages, so the translators need
% to provide only the one gender, e.g., feminine for both German and
% French.
% 
% \section{Prestoring Names of Journals}\label{sec:jnames}
% 
% The standard \texttt{.bst} files contain the names of some 20 journals
% in the field of computing, stored as macros for easy reference within the
% database \texttt{.bib} files. For example, the \textsl{Journal of
% Computer and System Sciences} can be referred to as \texttt{jcss}.
% With the option \texttt{jabr} (for journal abbreviation) this same
% shorthand produces \textsl{J.~Comput. Syst. Sci.}.
% 
% Some \texttt{.bst} files for physics journals include additional journal
% names, and it is conceivable that other faculties might wish to prepare
% their own such lists, with each name present in a full or abbreviated
% form. Such an external file can now be added with \texttt{\filename} and
% \texttt{makebst} version~3.
% 
% As a model, I supply a file \texttt{physjour.mbs} with the names of
% physics journals which I have taken from other \texttt{.bst} files.
% I also have a contributed file \texttt{photjour.mbs} containing names of
% optics journals.
% 
% In fact, version~3.5 can even include multiple journal-name files.
% Thus one can decide whether to include both, one, or none of the above
% files.
% 
% \section{Updating Older \texttt{.dbj} Files}\label{sec:update}
% If you have existing \texttt{.dbj} files for generating \texttt{.bst}
% files from the older version \texttt{genbst.mbs}, these may be run with
% \texttt{\filename} by simply changing the name of the source
% \texttt{.mbs} file. For example, where the older \texttt{.dbj} file contains
% the line
% \begin{quote}
% |\generateFile{mystyle.bst}{f}{\from{genbst.mbs}{%|
% \end{quote}
% edit the file so that \texttt{genbst.mbs} is replaced by
% \texttt{\filename}. The resulting \texttt{mystyle.bst} file will then be
% an updated version of the older one, containing all the same features.
% 
% \section{Acknowledgements}
% I wish to thank all the people who have taken the trouble to send me
% suggestions or special requests. Admittedly, it has been out of
% self-interest on their part, since they had bibliographic needs to be
% met. And I have often questioned the need for many of their demands. Yet,
% that is part of the bibliographic jungle that I am trying to eliminate.
% If I thought that bibliographies were arbitrarily formatted before I
% started this project, I have more than sufficient confirmation since
% then. The fault lies not with the poor contributors, but with the
% publishers who cannot agree on a decent standard.
% 
% I especially want to thank Frank Mittelbach, not only for creating \dtx{}
% in the first place, but also for sending me his bibliographic requirements,
% and for suggesting an improvement to \texttt{makebst}.
% 
% And finally, all of us must thank Oren Patashnik for providing \btx;
% without its flexibility and programmability (in spite of the complexity
% of the language) the master bibliographic styles would not be possible at
% all.
% 
% \section{The Options}\label{sec:options}
% Here I present a list of all the \dtx{} options that are
% available in this file {\tt\filename}.
% The normal user can skip this section since he will probably make use
% of the menus via \texttt{makebst}. These are described in
% Section~\ref{sec:menu}. The menus provide much more informative prompts
% than the heavily abbreviated option names listed here. In other words,
% the options described in this section are meant for internal (programmer)
% usage, while the normal interface for the user is the menus.
% 
% I have tried to avoid
% conflicts with mutually exclusive options by always letting one dominate if
% more than one has been specified. Such options have the same prefix, such
% as \texttt{nm-rev} and \texttt{nm-init}. 
% If one uses \texttt{makebst} to produce the
% \dtx{} batch job, then it is impossible to give mutually
% exclusive options unless one edits the batch file oneself afterwards.
% (Anything is possible with computer freaks!)
% 
% Most mutually exclusive options have the same prefix before the hyphen.
% 
% \newenvironment{opt}{%
% \begin{list}{}{\labelwidth2cm \leftmargin2.5cm \labelsep1em \rightmargin0pt
%  \def\makelabel##1{\ttfamily##1 \hfill}}}{\end{list}}
% \textbf{Citation style:} whether or not a numerical or author--year system 
% is to be used.
% \begin{opt}
% \item[--] default is numerical, standard \LaTeX, as for {\tt
%           plain.bst}.\\
%           |\bibitem{key}...|
% \item[cite] special for listing entire databases; the cite key is used 
%             as the label so it may be listed.\\
%             |\bibitem[key]{key}...|
% \item[ay] for author--year style of citations. Various forms of |\bibitem|
%           are provided under this option, to support different types
%           of \LaTeX{} styles for interfacing with the author--year system.
% \item[alph] for \texttt{alpha.bst} style of citations; essentially numerical
%           but an abbreviation of the author names plus year is used as
%           the label.
% \end{opt}
% 
% If \texttt{ay} has been selected, then the type of author--year interface
% is selectable. Some of these, like \texttt{natbib} and \texttt{harvard}
% exist in two versions because of updates in these systems. 
% \begin{opt}
% \item[--] default is the system I invented for my \texttt{natbib.sty}.\\
%            |\bibitem[author(year)]{key}...|   
% \item[nat] for extended format of \texttt{natbib.sty} version 5.3\\
%            |\bibitem[author(year)full author]{key}...|   
% \item[alk] for the \texttt{apalike.sty} of Oren Patashnik and related
%            systems\\
%            |\bibitem[author, year]{key}...|
% \item[har] for the Harvard family of styles (with \texttt{harvard.sty}).\\
%            |\harvarditem[short]{long}{year}{key}...|
% \item[harnm] for the extended Harvard family, containing some extra commands
%            used by \LaTeXe\ version 2.0.3 of \texttt{harvard.sty} 
% \item[ast] for astronomy family of styles (with \texttt{astron.sty}).\\
%            |\bibitem[\protect\astroncite{author}{year}]{key}...|
% \item[cay] for the Chicago family of styles (with \texttt{chicago.sty}).\\
%            |\bibitem[\protect\citeauthoryear{long}{short}{year}]{key}...|
% \item[nmd] for the `named' variant of Chicago (with \texttt{named.sty}).\\
%            |\bibitem[\protect\citeauthoryear{author}{year}]{key}...|
% \item[cn] for the ``author--date'' group of styles (with {\tt
%            authordate1-4.sty})\\
%            |\bibitem[\protect\citename{author, }year]{key}...|
% \end{opt}
% 
% \textbf{Sequence:} the order in which the references are listed.
% \begin{opt}
% \item[--]      default is alphabetical by all authors, date, title
% \item[seq-yr]  order by year, authors, title
% \item[seq-no]  sequence by citation order
% \item[seq-lab] (author--year) by label, date, title (means that Daly 
%                precedes Daly and Williams, precedes Daly et al.)
% \item[seq-key] (author--year) like \texttt{seq-lab} except that for 
%                identical authors and year, the cite keyword is used
%                instead of the title
% \item[vonx]    ignore \emph{von} part of name when ordering (default is
%                to consider \emph{von} as part of the whole surname)
% \end{opt}
% 
% \textbf{Language selection:} the translations of certain explicit words.
% \begin{opt}
% \item[--]      default is English, for \textsl{and}, \textsl{chapter},
%                  \textsl{editor}, etc.;
% \item[babel]     replace words with \LaTeX{} commands that are defined 
%                  in the file \texttt{babelbst.tex};
% \end{opt}
% 
% If one of the external language definition files is used, then the name of
% its language should be in the list of active options. Many other language
% names are already included as options in this main file simply for the
% purpose of adding a comment at the start of the \texttt{.bst} file.
% 
% \textbf{Names formatting:} how initials and surnames are to be combined.
% \begin{opt}
% \item[--]       default is full names, given names first
% \item[nm-revf]  full names, surname first
% \item[nm-init]  initials plus surname
% \item[nm-rev]   surname plus initials
% \item[nm-rev1]  surname plus initials (1st name only) then initials 
%                 plus surname
% \item[nm-revv1] same as \texttt{nm-rev1} but with full names
% \item[nm-rv]    as \texttt{nm-rev}, but initials without dots
% \item[nm-rvv]   as \texttt{nm-rev}, but initials without spaces
% \item[nm-rvx]   as \texttt{nm-rev}, but initials without dots or spaces
% \item[ed-rev]   editors' names are reversed the same as authors'
% \item[aunm-semi] a semi-colon is placed between author names instead of
%                  a comma
% \end{opt}
% 
% \textbf{Number of names:} normally all names listed (in reference list)
% \begin{opt}
% \item[nmlm]     limit number of names
% \item[x1...x9]  (with \texttt{nmlm}) maximum number of names to appear
% \item[m1...m6]  (with \texttt{nmlm}) minimum number before \textsl{et al.} 
%                   written;
%                 no check for consistency is taken; one \texttt{x} and 
%                 one \texttt{m} number must be given, and {\tt x}$\le${\tt m}
% \end{opt}
% 
% \textbf{Names font:} in the reference list
% \begin{opt}
% \item[--]       default is names in normal typeface
% \item[nmft-sc]  names in small caps
% \item[nmft-it]  names in italics   
% \item[nmft-bf]  names in bold      
% \item[nmand-rm] `and' in normal font, not same as authors'.
% \end{opt}
% 
% \textbf{Block punctuation:} between logical sections (not mutually
% exclusive)
% \begin{opt}
% \item[--]       default is period after each logical section, including end
% \item[blk-com]  use commas, except at very end (changes \textsl{In} to
%                     \textsl{in})
% \item[blk-tit]  like \texttt{blk-com} except period follows titles of
%                      articles and books
% \item[blk-tita] like \texttt{blk-com} except period follows article title
% \item[com-semi] with \texttt{blk-com}, uses semi-colon instead of comma
% \item[com-blank] with \texttt{blk-com}, uses blanks instead of comma
% \item[in-col]   puts a colon after \textsl{In} or \textsl{in} for edited works
% \item[in-x]     suppresses the word \textsl{in} for edited works
% \item[fin-bare] no punctuation at the very end
% \item[au-col] puts a colon after the author/editor block
% \end{opt}
% 
% \textbf{Date:} position and enclosure
% \begin{opt}
% \item[--]       default is date at end, before notes; for author--year,
%                   date consists only of year, no month
% \item[dt-jnl]   date at end as for default, except for journal articles 
%                   where it follows the journal name as part of specification
% \item[dt-end]   date goes after any notes
% \item[dt-beg]   date goes after authors' names 
% \item[yr-par]   date in parentheses ()
% \item[yr-brk]   date in brackets []
% \item[yr-com]   date preceded by comma and space
% \item[yr-col]   date preceded by colon and space
% \item[yr-per]   date preceded by period and space
% \item[yr-blk]   date preceded by space
% \item[dtrev]    date as year month instead of month year
% \item[dtbf]     date bold face
% \item[aymth]    include month even for author-year
% \item[yrp-x]    suppresses punctuation following month, year when date
%                 is just after authors
% \item[yrp-col]  adds colon and space after date when just after authors
% \item[yrp-semi] adds semi-colon and space after date when just after authors
% \item[yrp-per]  adds period and space after date
% \item[yrpp-xsp] removes blank following year punctuation
% \item[note-yr]  permits text (like ``in press'') in the \texttt{year} field
% \end{opt}
% 
% \textbf{Article in journal:} style of title, volume, pages
% \begin{opt}
% \item[--]       default is: Title. \textit{Journal}, vol(num):p1--p2
% \item[volp-sp]  as above, but with a space, vol(num):~p1--p2
% \item[volp-semi] semi-colon instead of colon:   vol(num);~p1--p2
% \item[volp-com] comma and space instead of colon:   vol(num),~p1--p2
% \item[volp-blk] only space instead of colon:   vol(num)~p1--p2
% \item[volp-dt] date between volume and pages: vol(num), (1994) p1--p2
% \item[vol-bf]   volume in bold
% \item[vol-it]   volume in italics
% \item[vol-2bf]  volume and number bold
% \item[vnum-x]   no number for journals, only volume
% \item[vnum-sp]  space between, as vol (num)
% \item[vnum-cm]  replace vol(num) with vol, num
% \item[vnum-nr]  replace vol(num) with vol, no. num
% \item[vnum-h]   replace vol(num) with vol, \#num
% \item[vnum-dt]  as vol (year) num
% \item[vnum-pg]  as vol, (num)p1--(num)p2
% \item[jpg-1]    only starting page given
% \item[jwdpg]    include `page' or `pp' for articles
% \item[jwdvol]   include `volume' or `vol' for articles
% \item[jnm-x]    no punctuation after journal name
% \item[tit-it]   article title in italics
% \item[tit-q]    article title in single quotes
% \item[tit-qq]   article title in double quotes
% \item[jtit-x]   no article title (applies only to journals and 
%                 collections)
% \item[atit-u]   article title capitalized as in entry, default is
%                 sentence capitalization (first word and words following
%                 colons)
% \item[jxper]    abbreviated journal names have periods removed, as
%                 `Phys Rev'
% \item[jttl-rm]  name of journal not in italics
% \item[pp-last]  pages appear at end, before any notes
% \end{opt}
% 
% \textbf{Thesis title:} formatted like a book or article
% \begin{opt}
% \item[--]       default is like a book title
% \item[thtit-a]  titles of PhD and Master theses formatted like articles
% \end{opt}
%
% \textbf{Technical Report title:} formatted like book or article
% \begin{opt}
% \item[--]       default is like an article title
% \item[trtit-b]  titles of technical reports formatted like books
% \end{opt}
%
% \textbf{Books:}  title font style, pages, and address location
% \begin{opt}
% \item[--]       default is italicized
% \item[btit-rm]  book title plain
% \item[bkpg-par] pages in books place in parentheses
% \item[add-pub]  publisher's address before name, colon separated
% \item[pub-par]  publisher and address in parentheses
% \item[pub-date] publisher with address and date in parentheses
% \item[pre-pub]  publisher placed before chapter and page information
% \item[pre-edn]  edition before publisher
% \end{opt}
% 
% \textbf{ISBN number:} include or not
% \begin{opt}
% \item[--]       default is no ISBN number
% \item[isbn]     include an ISBN number as optional entry for books, booklets, 
%                 incollections, inproceedings
% \end{opt}
% 
% \textbf{Abbreviations:} of various words, default is no abbreviations
% \begin{opt}
% \item[pp]       abbreviate \textsl{page(s)} as \textsl{p.} and \textsl{pp.}
% \item[ppx]      no word \textsl{page(s)} or abbreviation
% \item[ed]       abbreviate \textsl{editor(s)} as \textsl{ed.} and 
%                     \textsl{eds.}
% \item[abr]      abbreviate \textsl{volume}, \textsl{edition},
%                     \textsl{technical report}, etc.
% \item[mth-bare] months abbreviated without dots
% \item[jabr]     abbreviate names of prestored journals
% \item[ord]      write edition numbers as 1st, 2nd, instead as words.
% \end{opt}
% 
% \textbf{Editor:} alternative for \emph{in edited} work
% \begin{opt}
% \item[--]       ``in \emph{names}, editors, \emph{title}''
% \item[edpar]    ``in \emph{names} (editors), \emph{title}''
% \item[edby]     ``in \emph{title}, edited by \emph{names}''
% \item[edby-par] ``in \emph{title} (edited by \emph{names})''
% \item[edcap]    (with \texttt{edby-par}) capitalizes ``Edited by'' or
%                    ``Editor''
% \item[edbyx]    (with \texttt{edby} or \texttt{edby-par}) replaces text
%                 \textsl{edited by} by \textsl{editor(s)} before the names,
% \item[edbyy]    (with \texttt{edby} or \texttt{edby-par}) replaces text
%                 \textsl{edited by} by \textsl{editor(s)} after the names,
%                 as ``in \emph{title}, \emph{names}, editors''.
% \end{opt}
%
% \textbf{Citation label:} what is written by the |\cite| command
% \begin{opt}
% \item[--]       default is no special font
% \item[lab-it]   label (names printed by |\cite|) in italics
% \item[lab-sc]   label in small caps
% \item[lab-bf]   label in bold face
% \item[and-rm]   word `and' in labels in normal font
% \item[xlab-it]  extra label (letter after year) in italics
% \end{opt}
% 
% \textbf{Emphasis:} defines what `italicized' really means
% \begin{opt}
% \item[--]       default is |\em| (can switch between |\it| 
%                 and |\rm|
% \item[em-it]    use |\it| instead (always italic)
% \item[em-x]     no emphasis
% \end{opt}
% 
% \textbf{Special punctuation:} 
% \begin{opt}
% \item[amper]    use \& in place of \textsl{and}
% \item[varand]   use command |\BIBand| in place of \textsl{and}
% \item[and-xcom] no comma before last \textsl{and} of an author list 
%                   (citations and references)
% \item[and-com]  add comma before \textsl{and} even for two authors (in list of
%                  references)
% \item[xand]    no \textsl{and} in an author list (references)
% \item[etal-it]  \textsl{et al.} in italics
% \item[etal-rm]  \textsl{et al.} in roman
% \end{opt}
% 
% \textbf{Font commands:}
% \begin{opt}
% \item[--]     use \LaTeX~2.09 font commands
% \item[nfss]   use |\textbf|, |\textit|, |\emph| in place of |\bf|, |\it|,
%                and |\em|; only works then with \LaTeXe
% \end{opt}
%
% \section{The Menu Information}\label{sec:menu}
% Here I describe the options and menu information for this particular
% master file \texttt{\filename}. To construct a \dtx{} driver file
% to generate a desired \texttt{.bst} file, simply process \texttt{makebst.tex}
% with \TeX\ or \LaTeX, and give 
% \begin{quote}\tt\filename\end{quote}
% when prompted for the name of the master file. Then answer the questions
% in the menus that follow. The menu information is extracted from here.
% 
% All the menu information is nested between \dtx{} guard options
% |%<*options>| \dots\ |%</options>|, and the last command is
% |\endoptions|. The rest of the file is nested between 
% \begin{quote}
%   |%<*!options&!driver&!bblbst>| \dots\ |</!options&!driver&!bblbst>| 
% \end{quote}
% in order to exclude it if \dtx{} is used to
% extract the menu information, the documentation driver, or the
% \texttt{babelbst.tex} file.
% 
% The main coding is divided into two sections, the \emph{head} and
% \emph{tail}; in between come any external language or journal name
% support files. The head part is marked with the \dtx{} guard option
% |<!tail>| and the tail with |<!head>|. This roundabout means of doing
% things makes it possible to process \texttt{\filename} with \texttt{.dbj}
% files that were generated for the older \texttt{genbst.mbs} file by
% simply changing the name of the source file as shown in
% Section~\ref{sec:update}. If both \texttt{head} and \texttt{tail} (and
% \texttt{exlang}) options are omitted, as they are in the older
% \texttt{.dbj} files, \texttt{\filename} is processed completely in one
% pass. To include external files, two passes are needed, one for each
% part, with the external file(s) coming in between.
% 
% Note too that if the internal language commands are taken (i.e., if
% \texttt{exlang} option is not given) then the default language is
% English, which is tested for as |<!babel>|. This too permits the simple
% update of older \texttt{.dbj}, at least for English.
% 
% \subsection*{Selecting Language}
% Explicit words in the bibliography style, such as \textsl{and},
%      \textsl{editor}, etc.,
% are represented by functions \texttt{bbl.and}, \texttt{bbl.editor}, and so on.
% By default these functions translate to the normal English text, but
% other languages are also possible. 
% 
% The definitions of these functions for other languages are contained in
% external files. At this point, we can make use of features in
% \texttt{makebst} (version~3.0 or later) to ask for the name of such a
% definition file, and store it in |\cfile|. If no external file is
% specified, then the internal definitions are taken, for which there are
% two possibilities: English or \LaTeX{} commands (Babel).
% 
% The commands |\MBswitch|, |\mes|, |\MBaskfile|, |\wr|, |\pc|, |\spsp| are
% defined in \texttt{makebst.tex}.
% 
% If |\MBswitch| does not exist, then the version of \texttt{makebst}
% cannot support external files.
% 
%    \begin{macrocode}
%<*options>
\mes{<<< For more information about the meanings of^^J%
     <<< the various options, see the section on ^^J%
     <<< Menu Information in the .mbs file documentation.}

\mes{^^JEXTERNAL FILES:}
\expandafter\ifx\csname MBswitch\endcsname\relax
\mes{^^J**************^^J%
        Makebst version is less than 3.0^^J%
        Cannot add external file for language definition^^J%
        **************}
\def\cfile{}\def\jfile{}\else
\MBaskfile{^^JName of language definition file}(\mroot.\mext)i\cfile
\edef\ctemp{\mroot.\mext}
\ifx\ctemp\cfile\def\cfile{}\fi
%    \end{macrocode}
% 
% A second type of external file that can be added is one containing names
% of journals that are to be prestored into the \texttt{.bst} file.
% Several file names are allowed here, with the root names separated by
% commas, and with the common extension added at the end. To assist later
% parsing of the names, an additional comma is added before the extension.
% 
% Note that in this case |\MBaskfile| treats the file(s) as output, i.e.,
% it does not check if the file(s) actually exist.
% 
% The macro |\Mgetnext| allows the root names to be extracted from the
% list of file names.
%    \begin{macrocode}
\def\jfile{}
\ask{\yn}{^^JInclude file(s) for extra journal names? (NO)}
\if!\yn!\else\if\yn n\else\if\yn N\else
\MBaskfile{^^JFile to include}(physjour,photjour.mbs)o\jfile
\edef\jfile{\froot,.\fext}
\fi\fi\fi
\fi
\def\Mgetnext#1,#2.#3??{\def\froot{#1}\def\Mrest{#2}\def\fext{#3}}
%    \end{macrocode}
% 
% If no external files are specified, then both |\cfile| and |\jfile| are
% empty. In this case, do \emph{not} set the options \texttt{head} and 
% \texttt{tail}, which control the \dtx{} passes through
% \texttt{filename}. Now only one pass is made. 
% 
% If there is an external definition file, or if an external list of
% journal names, then some extra text must be
% written to fit in with that already written by \texttt{makebst}. This is
% explained in that documentation. The |\MBswitch| command turns the curly
% braces |{..}| into normal characters, and the parentheses |(..)| take on
% their grouping functionality. This permits unbalances braces to be
% written to the output file.
% 
%    \begin{macrocode}
\if!\cfile\jfile!\else
\begingroup\MBswitch
\wr(\spsp head,\string\MBopta})
\if!\cfile!\else
\wr(\string\from{\cfile}{\string\MBopta})
\fi
\if!\jfile!\else
\let\jxfile\jfile
\loop
%    \end{macrocode}
%
% Parse the list of journal name files, adding a new |\from| for each one.
%
%    \begin{macrocode}
\expandafter\Mgetnext\jxfile??
\wr(\string\from{\froot.\fext}{\string\MBopta})
\edef\jxfile(\Mrest.\fext)
\if!\Mrest!\def\Mtst(1)\else\def\Mtst()\fi
\if!\Mtst!
\repeat
\fi
\wr(\string\from{\mroot.\mext}{tail,\string\MBopta}})
\wr(\string\def\string\MBopta{\pc)
\endgroup
\fi
%    \end{macrocode}
%
% Ask whether
% explicit English words wanted or \LaTeX{} commands whose definitions are
% to be found in the file \texttt{babelbst.tex}.
%
%    \begin{macrocode}
\if!\cfile!
\mes{^^JINTERNAL LANGUAGE SUPPORT:}
\optdef{*}{}{English}{words used explicitly}
\optdef{b}{babel}{Babel}{(words replaced by commands defined in babelbst.tex)}
\getans
\else
\wr{\spsp\spsp\sep exlang\pc: External language file}
\def\sep{,}
\fi
%    \end{macrocode}
%
% \subsection*{Author--year or numerical}
% The first question is whether a numerical or author--year citation style
% is to be used. If the latter, the supporting system is my {\tt
% natbib.sty}, which expects |\bibitem| to have an optional argument
% containing the short form of the authors, plus year in parentheses.
% E.g.,
% \begin{quote}
% |\bibitem[Daly et al.(1990)]{key}...|
% \end{quote}
% There is now a newer version of \texttt{natbib.sty} (v5.3) that
% supports an optional full author list too, as
% \begin{quote}
% |\bibitem[Daly et al.(1990)Daly, Keppler, and Williams]{key}...|
% \end{quote}
% Other systems are also supported, such as the Harvard family of
% bibliography styles (with \texttt{harvard.sty}), which have entries in the
% form
% \begin{quote}
% |\harvarditem[Daly et al.]{Daly, Keppler,|\\
% |       and Williams}{1990}{key}...|
% \end{quote}
% or the astronomy family (with \texttt{astron.sty}) with entries like
% \begin{quote}
% |\bibitem[\protect\astroncite{Daly et al.}{1990}]{key}...|
% \end{quote}
% or the Chicago family (with \texttt{chicago.sty}) with entries like
% \begin{quote}
% |\bibitem[\protect\citeautheryear{Daly, Keppler, and|\\
% |      Williams}{Daly et al.}{1990}]{key}...|
% \end{quote}
% or the `named' variant of Chicago (with \texttt{named.sty}) with entries like
% \begin{quote}
% |\bibitem[\protect\citeauthoryear{Daly et al.}{1990}]{key}...|
% \end{quote}
% or the so-called ``author--date'' group (with \texttt{authordate1-4.sty})
% with entries of the form
% \begin{quote}
% |\bibitem[\protect\citename{Daly et al.}1990]{key}...|
% \end{quote}
% Finally, there is the \texttt{apalike} format of Oren Patashnik, for use
% with \texttt{apalike.sty} that has entries of the form
% \begin{quote}
% |\bibitem[Daly et al., 1990]{key}...|
% \end{quote}
% 
% In addition to numerical or author--year citation styles, there is also a
% \texttt{cite} style available in which the label is the same as the cite
% key. This is for listing entire contents of databases with the cite key
% visible. 
% 
% A flag |\ifnumerical| is established because some of the following menu
% features depend on which system is to be used.
%
%    \begin{macrocode}
\newif\ifnumerical \numericalfalse
\newif\ifmytemp\mytempfalse
\mes{^^JSTYLE OF CITATIONS:}
\optdef{*}{}{Numerical}{as in standard LaTeX}
\optdef{a}{ay}{Author-year}{with some non-standard interface}
\optdef{b}{alph}{Alpha style}{(labels like DAL90)}
\optdef{c}{cite}{Cite key}{(special for listing contents of bib file)}
\getans
\numericaltrue
\if\ans a\numericalfalse\fi
\mytemptrue
\if\ans b\mytempfalse\fi

\ifnumerical\else
\mes{^^JAUTHOR--YEAR SUPPORT SYSTEM:}
\optdef{*}{nat}{Natbib}{for use with natbib.sty v5.3}
\optdef{o}{}{Older Natbib}{without full authors citations}
\optdef{l}{alk}{Apalike}{for use with apalike.sty}
\optdef{h}{har}{Harvard}{system with harvard.sty}
\optdef{a}{ast}{Astronomy}{system with astron.sty}
\optdef{c}{cay}{Chicago}{system with chicago.sty}
\optdef{n}{nmd}{Named}{system with named.sty}
\optdef{d}{cn}{Author-date}{system with authordate1-4.sty}
\getans

%    \end{macrocode}
% The \texttt{harvard} family has been extended for \LaTeXe, and the new
% \texttt{.bst} files allow the word \textsl{and} and the brackets around years
% to be variable with commands. A URL entry is added, for the on-line
% network reference. These features may be added too.
%    \begin{macrocode}
\if\ans h%
\mes{^^JHARVARD EXTENSIONS INCLUDED:}
\optdef{*}{harnm}{With Harvard extensions}{for LaTeX2e version of harvard.sty}
\optdef{n}{}{Older Harvard}{style, for LaTeX 2.09}
\getans\fi
\fi

%    \end{macrocode}
% 
% \subsection*{Ordering of the listed references}
%   Choices here depend on citation style. The default in both cases is
% alphabetical order of all authors. For numerical style, one may also
% choose an unsorted order, which means the order is the same as the original
% citations. This corresponds to \texttt{unsrt.bst}. Order of citation is 
% also offered for author--year for \texttt{natbib}-type styles that can
% also be used for numerical listings.
% 
% Another possibility is to order first by year, then authors. This too only
% makes sense for numerical citations. However, it is offered for author--year
% in the event that a \texttt{natbib}-type style is used for numerical
% listings. 
%
% For the alpha style, the ordering is by label only, so no option is 
% offered here (|\ifnumerical| is \meta{true} and |\ifmytemp| is \meta{false}).
%
% For author--year, the second choice is by label. (The label is the
% optional |\bibitem| argument, and is what is printed in place of the
% |\cite| command.) With this option, all the papers with the same first
% author are ordered so that the one-author papers come first, followed by
% the two-author papers, followed by the multiple-author papers. This is a
% more sensible system for author--year citations, and is demanded by some
% journals (like JGR).
%
% One problem that can arise here is when two or more references have the
% same set of authors and year; normally they are then ordered by the
% title, ignoring initial words like \textsl{the} and \textsl{a}, with the 
% letters a, b,
% c, \dots, added to the year. This can mean that a set of references with
% a natural sequence will be put into a different order. An alternative is
% to order them by the citation keyword instead of by title. This of course
% assumes that the keywords in this case reflect that natural sequence.
%    \begin{macrocode}
\ifnumerical
\ifmytemp
\mes{^^JORDERING OF REFERENCES:}
\optdef{*}{}{Alphabetical}{by all authors}
\optdef{c}{seq-no}{Citation order}{(unsorted, like unsrt.bst)}
\optdef{d}{seq-yr}{Year ordered}{and then by authors}
\getans
\fi
\else
\mes{^^JORDERING OF REFERENCES:}
\optdef{*}{}{Alphabetical}{by all authors}
\optdef{l}{seq-lab}{By label}%
   {(Jones before Jones and James before Jones et al)}
\optdef{k}{seq-key}{By label and cite key}{instead of label and title, as above}
\optdef{d}{seq-yr}{Year ordered}{and then by authors (for publication lists)}
\optdef{c}{seq-no}{Citation order}{(unsorted, only meaningful for numericals)}
\getans
\fi

%    \end{macrocode}
% The standard \btx\ styles consider the \emph{von} part of the name to be a
% fixed part of the surname. European usage tends to alphabetize ignoring these
% honorifics. 
%    \begin{macrocode}
\if\ans c\else
\mes{^^JORDER ON VON PART:}
\optdef{*}{}{Sort on von part}{(de la Maire before Defoe)}
\optdef{x}{vonx}{Sort without von part}{(de la Maire after Mahone)}
\getans
\fi

%    \end{macrocode}
% 
% \subsection*{Formatting author names}
% The default is that the full names of the authors are listed, given names
% first, unabbreviated. Of course, if only the initials have been given in
% the \texttt{.bib} file, then that is all that can appear in the list. Other
% possibilities are to use initials (even if full names in the \texttt{.bib}
% file) either before or after the surnames. A specialty of the journals of
% the American Geophysical Union is to have only the first name with
% reversed initials.
%
% If the reference is part of a larger work with editors, then the editor
% names appear later in the reference text, usually as ``edited by \dots''
% or as ``\emph{names} (editors)''. In these cases, the editor names are 
% not usually reversed (surname first) even if the authors' names are.
% An option is provided to format such editor names exactly as the authors'.
%    \begin{macrocode}
\mes{^^JAUTHOR NAMES:}
\optdef{*}{}{Full, surname last}{(John Frederick Smith)}
\optdef{f}{nm-revf}{Full, surname first}{(Smith, John Frederick)}
\optdef{i}{nm-init}{Initials + surname}{(J. F. Smith)}
\optdef{r}{nm-rev}{Surname + initials}{(Smith, J. F.)}
\optdef{s}{nm-rv}{Surname + dotless initials}{(Smith J F)}
\optdef{x}{nm-rvx}{Surname + pure initials}{(Smith JF)}
\optdef{y}{nm-rvv}{Surname + spaceless initials}{(Smith J.F.)}
\optdef{a}{nm-rev1}{Only first name reversed, initials}%
   {(AGU style: Smith, J. F., H. K. Jones)}
\optdef{b}{nm-revv1}{First name reversed, with full names}%
   {(Smith, John Fred, Harry Kab Jones)}
\getans

\mytempfalse
\if\ans r\mytemptrue\fi
\if\ans s\mytemptrue\fi
\if\ans a\mytemptrue\fi
\if\ans f\mytemptrue\fi
\if\ans x\mytemptrue\fi
\if\ans y\mytemptrue\fi
\ifmytemp
\mes{^^JEDITOR NAMES IN COLLECTIONS:}
\if\ans r
\optdef{*}{}{Editor names NOT reversed}{as edited by J. J. Smith}
\fi
\if\ans s
\optdef{*}{}{Editor names NOT reversed}{as edited by J J Smith}
\fi
\if\ans a
\optdef{*}{}{Editor names NOT reversed}{as edited by J. J. Smith}
\fi
\if\ans x
\optdef{*}{}{Editor names NOT reversed}{as edited by JJ Smith}
\fi
\if\ans f
\optdef{*}{}{Editor names NOT reversed}{as edited by John James Smith}
\fi
\if\ans y
\optdef{*}{}{Editor names NOT reversed}{as edited by J.J. Smith}
\fi
\optdef{r}{ed-rev}{Editor names reversed}{just like authors'}
\getans
\fi

\mes{^^JPUNCTUATION BETWEEN AUTHOR NAMES:}
\optdef{*}{}{Author names separated by commas}{}
\optdef{s}{aunm-semi}{Names separated by semi-colon}{}
\getans

%    \end{macrocode}
%
% \subsection*{Number of authors}
% Normally the complete list of authors as given in the \texttt{.bib} file is
% presented in the reference list. However, some journals prefer to limit
% them to a maximum. If there are more than this maximum number of author
% names, then a minimum number plus \textsl{et al.} are listed.
% 
% Because no test for consistency of the numbers is carried out in the
% \texttt{.bst} file itself (it might be possible, but I found it too complex),
% this is done here.
%    \begin{macrocode}
\mes{^^JNUMBER OF AUTHORS:}
\optdef{*}{}{All authors}{included in listing}
\optdef{l}{nmlm}{Limited authors}{(et al replaces missing names)}
\getans
\if\ans l
\loop
  \ask{\num}{Maximum number of authors (1-9)}
  \ifnum\num>9\relax
  \mes{*** Must be between 1 and 9}
\repeat
\wr{\spsp\spsp\sep x\num\pc: Maximum of \num\space authors}
\mes{\spsp You have selected maximum \num\space authors}
\ifnum\num>6\def\numx{6}\else\edef\numx{\num}\fi
\loop
  \ask{\num}{Minimum number (before et al given) (1-\numx)}
  \ifnum\num>\numx
  \mes{*** Must be between 1 and \numx}
\repeat
\wr{\spsp\spsp\sep m\num\pc: Minimum of \num\space authors}
\mes{\spsp You have selected minimum \num\space authors}
\fi

%    \end{macrocode}
% 
% \subsection*{Typeface of names}
% The author names in the list of references normally appear in the current
% typeface. This may be changed to small caps, bold, or italics.
%    \begin{macrocode}
\mes{^^JTYPEFACE FOR AUTHORS IN LIST OF REFERENCES:}
\optdef{*}{}{Normal font for authors}{}
\optdef{s}{nmft-sc}{Small caps authors}{(\string\sc)}
\optdef{i}{nmft-it}{Italic authors}{(\string\it\space or \string\em)}
\optdef{b}{nmft-bf}{Bold authors}{(\string\bf)}
\getans

\mytempfalse
\if\ans i\mytemptrue\fi
\if\ans s\mytemptrue\fi
\if\ans b\mytemptrue\fi
\ifmytemp
\mes{^^JFONT FOR `AND' THE IN LIST:}
\optdef{*}{}{`And' in author font}{(JONES AND JAMES)}
\optdef{r}{nmand-rm}{`And' in normal font}{(JONES and JAMES)}
\getans
\fi

%    \end{macrocode}
%
% \subsection*{Position of date}
% This applies to author--year style only. It makes sense to put the date
% immediately after the author list, since the two items (author and year)
% are the identifiers of the reference. Default position is at the
% end of the references, before any notes. It is also possible to place
% it even after the notes.
% 
% Medical journals have a system where the date is part of the journal
% specification, as Lancet 1994;45(2):34--40. Otherwise the date appears at
% the end.
%    \begin{macrocode}
\mes{^^JDATE POSITION:}
\optdef{*}{}{Date at end}{}
\optdef{b}{dt-beg}{Date after authors}{}
\optdef{j}{dt-jnl}{Date part of journal spec.}{(as 1994;45:34-40) else at end}
\optdef{e}{dt-end}{Date at very end}{after any notes}
\getans

\if\ans b\mytemptrue\else\if\ans j\mytemptrue\else\mytempfalse\fi\fi
%    \end{macrocode}
%
% \subsection*{Format of date}
% The year may be enclosed in parentheses, brackets, or preceded by a
% colon. If none of these are selected, the date (month plus year) appears. 
% For author--year, the date normally consists only of the year, no month,
% but this may be overridden.
%
% If the date comes just after the authors, then one might want special
% punctuation following it, like a colon, or space only. The latter is
% probably desirable if the date is brackets or parentheses.
%
% The date can even be put into bold face.
%    \begin{macrocode}
\ifnumerical
\mes{^^JDATE FORMAT:}
\optdef{*}{}{Plain month and year}{without any brackets}
\optdef{p}{yr-par}{Date in parentheses}{as (May 1993)}
\optdef{b}{yr-brk}{Date in brackets}{as [May 1993]}
\optdef{c}{yr-col}{Date preceded by colon}{as `: May 1993'}
\optdef{d}{yr-per}{Date preceded by period}{as `. May 1993'}
\optdef{m}{yr-com}{Date preceded by comma}{as `, May 1993'}
\optdef{s}{yr-blk}{Date preceded by space}{only, as ` May 1993'}
\getans

\mes{^^JREVERSED DATE:}
\optdef{*}{}{Date as month year}{}
\optdef{r}{dtrev}{Date as year month}{}
\getans
\else
\mes{^^JDATE FORMAT: (no months for author-year)}
\optdef{*}{}{Year plain}{without any brackets}
\optdef{p}{yr-par}{Year in parentheses}{as (1993)}
\optdef{b}{yr-brk}{Year in brackets}{as [1993]}
\optdef{c}{yr-col}{Year preceded by colon}{as `: 1993'}
\optdef{d}{yr-per}{Year preceded by period}{as `. 1993'}
\optdef{m}{yr-com}{Date preceded by comma}{as `, 1993'}
\optdef{s}{yr-blk}{Year preceded by space}{only, as ` 1993'}
\getans

\mes{^^JINCLUDE MONTHS:}
\optdef{*}{}{Date is year only}{without the month}
\optdef{m}{aymth}{Include month in date}{}
\getans

\if\ans m
\mes{^^JREVERSED DATE:}
\optdef{*}{}{Date as month year}{}
\optdef{r}{dtrev}{Date as year month}{}
\getans
\fi
\fi

\ifmytemp
\mes{^^JDATE PUNCTUATION:}
\optdef{*}{}{Date with standard block punctuation}{(comma or period)}
\optdef{c}{yrp-col}{Colon after date}{as 1994:}
\optdef{s}{yrp-semi}{Semi-colon after date}{as 1994;}
\optdef{p}{yrp-per}{Period after date}{even when blocks use commas}
\optdef{x}{yrp-x}{No punct. after date}{}
\getans

\mes{^^JBLANK AFTER DATE:}
\optdef{*}{}{Space after date}{and punctuation}
\optdef{x}{yrpp-xsp}{No space after date}{as 1994:45}
\getans

\fi

\mes{^^JDATE FONT:}
\optdef{*}{}{Date in normal font}{}
\optdef{b}{dtbf}{Date in bold face}{}
\getans

%    \end{macrocode}
% 
% Normally in author--year citations, the \texttt{year} entry is truncated
% to the last 4 characters, which should be the 4 digits of the year. Some
% users have requested the possibility of suppressing this truncation so
% that they may put text in the \texttt{year} field, such as ``in press.''
% Another use for it is when years are given as ``1968--72''. Actually,
% I have no idea why the year should be truncated at all.
%    \begin{macrocode}
\ifnumerical\else
\mes{^^JTRUNCATE YEAR:}
\optdef{*}{note-yr}{Year text full}{as 1990--1993 or `in press'}
\optdef{t}{}{Year truncated}{to last 4 digits}
\getans
\fi

%    \end{macrocode}
%
% \subsection*{Article title in journal}
% The title of an article in a journal or in a collection (a book, or
% conference proceedings) may appear plain, in italics, within single
% or double quotes. 
% 
% Furthermore, it may have sentence capitalization (first
% word and word following colon) or be capitalized as in the \texttt{.bib} file
% entry. That is why it is recommended to capitalize the entry text as it
% should appear when fully capitalized, putting words that are always
% capitalized in braces. Example:
% \begin{quote}
% |TITLE="The Results of the {Giotto} Mission"|
% \end{quote}
% which produces either ``The results of the Giotto mission'' or ``The
% Results of the Giotto Mission'', depending on option.
% 
% Additionally, the article titles may be fully suppressed.
%    \begin{macrocode}
\mes{^^JTITLE OF ARTICLE:}
\optdef{*}{}{Title plain}{with no special font}
\optdef{i}{tit-it}{Title italic}{(\string\em)}
\optdef{q}{tit-q}{Title in single quotes}{(`Title')}
\optdef{d}{tit-qq}{Title in double quotes}{(``Title'')}
\getans

\mes{^^JCAPITALIZATION OF ARTICLE TITLE:}
\optdef{*}{}{Sentence style}{(first word and those in braces)}
\optdef{t}{atit-u}{Title style}{(just as in bib entry)}
\getans

\mes{^^JARTICLE TITLE PRESENT:}
\optdef{*}{}{Article title present}{in journals and proceedings}
\optdef{x}{jtit-x}{No article title}{}
\getans

%    \end{macrocode}
% 
% \subsection*{Journal names}
% Abbreviated journal names normally contain periods; the periods may be
% removed with this option. In fact, only letters, numbers, and spacing are
% retained.
%    \begin{macrocode}
\mes{^^JJOURNAL NAMES:}
\optdef{*}{}{Periods in journal names}{are retained, as `Phys. Rev.'}
\optdef{x}{jxper}{Dotless journal names}{as `Phys Rev'}
\getans

%    \end{macrocode}
% Journal title is normally printed in italics; can be left in normal font.
%    \begin{macrocode}
\mes{^^JJOURNAL TITLE FONT:}
\optdef{*}{}{Journal title italics}{}
\optdef{r}{jttl-rm}{Journal title normal}{font}
\getans

%    \end{macrocode}
%
% \subsection*{Title of Theses and Technical Reports}
% The title of a these (PhD or Master's) is normally treated the same
% as that of a book. Optionally, it may be formatted like that of 
% an article.
%
% The title of a technical report is normally treated the same as that
% of an article. Optionally, it may be formatted like that of a book.
%
%    \begin{macrocode}
\mes{^^JTHESIS TITLE:}
\optdef{*}{}{Thesis titles like books}{}
\optdef{a}{thtit-a}{Thesis title like article}{}
\getans

\mes{^^JTECHNICAL REPORT TITLE:}
\optdef{*}{}{Tech. report title like articles}{}
\optdef{b}{trtit-b}{Tech. report title like books}{}
\getans

%    \end{macrocode}
%
% \subsection*{Journal reference}
% Great diversity of opinion exists as to how a journal reference is to be
% formatted. It consists of a volume, possibly a number, and page limits.
% The number is really only necessary if the page numbers within one volume
% start at 1 for each physical `number'. Since journals are often bound
% together in one volume later, it makes more sense to number the pages
% continuously through the whole volume. However, this is not always so,
% and then the `number' is necessary for the full specification.
% 
% A number of styles for journal specifications are
% \begin{quote}
%   \begin{tabular}{l@{\qquad}l}
% 21(2):33--55             & 21, no.\ 2: 33--55\\
% \textbf{21}(2):33--55    & \textbf{21}, \#2, 33--55\\
% \textit{21}(2), 33--55   & \textit{21} (2); 33--55 \\
% 21(2) (1995) 33--55      & 21, (2)33--(2)55\\
% 21(2) 33--55             & vol.~21 (2), pp.~33--55
%   \end{tabular}
% \end{quote}
% 
% Here both start and stop page numbers have been given; often only the
% start page is wanted.
% 
%    \begin{macrocode}
\mes{^^JJOURNAL VOLUME NUMBER:}
\optdef{*}{}{Volume plain}{as vol(num)}
\optdef{i}{vol-it}{Volume italic}{as {\string\em\space vol}(num)}
\optdef{b}{vol-bf}{Volume bold}{as {\string\bf\space vol}(num)}
\optdef{d}{vol-2bf}{Volume and number bold}{as {\string\bf\space vol(num)}}
\getans

%    \end{macrocode}
%
% The form of the `number' is also given: in parentheses, with `no.', 
% with \#, or omitted.
%    \begin{macrocode}
\mes{^^JJOURNAL VOL AND NUMBER:}
\optdef{*}{}{Journal vol(num)}{as 34(2)}
\optdef{s}{vnum-sp}{Journal vol (num)}{as 34 (2)}
\optdef{c}{vnum-cm}{Journal vol, num}{as 34, 2}
\optdef{n}{vnum-nr}{Journal vol, no. num}{as 34, no. 2}
\optdef{h}{vnum-h}{Journal vol, \string\# number}{as 34, \string\#2}
\optdef{p}{vnum-pg}{Journal vol, number(page)}{as 34, (2)33}
\optdef{d}{vnum-dt}{Journal vol (year) num}{as 34 (1994) 2}
\optdef{x}{vnum-x}{Journal vol, no number}{as 34}
\getans

\mes{^^JVOLUME PUNCTUATION:}
\optdef{*}{}{Volume with colon}{as vol(num):ppp}
\optdef{s}{volp-sp}{Volume with colon and space}{as vol(num): ppp}
\optdef{h}{volp-semi}{Volume with semi-colon}{as vol(num); ppp}
\optdef{c}{volp-com}{Volume with comma}{as vol(num), ppp}
\optdef{b}{volp-blk}{Volume with blank}{as vol(num) ppp}
\optdef{d}{volp-dt}{Volume with date}{as vol(num), date ppp}
\getans

\mes{^^JPAGE NUMBERS:}
\optdef{*}{}{Start and stop page numbers}{given}
\optdef{f}{jpg-1}{Only start page number}{}
\getans

\mes{^^JWORD `PAGE' IN ARTICLES:}
\optdef{*}{}{Article pages numbers only}{as 234-256}
\optdef{p}{jwdpg}{Include `page' in articles}{as pp. 234--256}
\getans

%    \end{macrocode}
% 
% Some journals want page numbers at the end, even for books, proceedings, as
% well as for journals. 
%    \begin{macrocode}
\mes{^^JPOSITION OF PAGES:}
\optdef{*}{}{Pages given mid text}{as is normal}
\optdef{e}{pp-last}{Pages at end}{but before any notes}
\getans

\mes{^^JWORD `VOLUME' IN ARTICLES:}
\optdef{*}{}{Article volume as number only}{as 21}
\optdef{p}{jwdvol}{Include `volume' in articles}{as vol. 21}
\getans

%    \end{macrocode}
%
% It is possible to decide whether the journal name should be
% separated from the following specifications with a blank or comma.
%    \begin{macrocode}
\mes{^^JJOURNAL NAME PUNCTUATION:}
\optdef{*}{}{Comma after journal}{name}
\optdef{x}{jnm-x}{Space after journal}{name}
\getans

%    \end{macrocode}
%
% \subsection*{Books}
% The title of a book (as opposed to an article in a book or journal) is
% normally italicized. This may be set to the regular font.
%
% The page numbers in books may be set in parentheses, as (pp.\ 345--350).
%    \begin{macrocode}
\mes{^^JBOOK TITLE:}
\optdef{*}{}{Book title italic}{(\string\em)}
\optdef{p}{btit-rm}{Book title plain}{(no font command)}
\getans

\mes{^^JPAGES IN BOOKS:}
\optdef{*}{}{Book pages normal}{as pp. 50-55}
\optdef{p}{bkpg-par}{Book pages in parentheses}{as (pp. 50-55)}
\getans

%    \end{macrocode}
% Some psychology journals wish to have the publisher's address preceding
% the name, separated by colon, as 
% \begin{quote}New York: Wiley and Sons\end{quote}
%
% Some journals (e.g.\ Nature) put publisher in parentheses with date,
% as (Wiley and Sons, New York, 1983). These normally put the date in 
% parentheses at the end anyway, so this is a merging of the two sets of
% parentheses.
%    \begin{macrocode}
\mes{^^JPUBLISHER ADDRESS:}
\optdef{*}{}{Publisher, address}{as Harcourt, New York}
\optdef{a}{add-pub}{Address: Publisher}{as New York: Harcourt}
\getans

\mes{^^JPUBLISHER IN PARENTHESES:}
\optdef{*}{}{Publisher as normal block}{without parentheses}
\optdef{p}{pub-par}{Publisher in parentheses}{}
\optdef{d}{pub-date}{Publisher and date in parentheses}{(Oxford, 1994)}
\getans

\mes{^^JPUBLISHER POSITION:}
\optdef{*}{}{Publisher after chapter, pages}{}
\optdef{p}{pre-pub}{Publisher before chapter, pages}{}
\optdef{e}{pre-edn}{Publisher after edition}{}
\getans

%    \end{macrocode}
% \subsection*{ISBN number}
% Books normally possess an ISBN number. This may be included as an
% optional entry for \texttt{book}, \texttt{inbook}, \texttt{booklet},
% \texttt{incollection}, \texttt{proceedings}, \texttt{inproceedings}.
%    \begin{macrocode}
\mes{^^JISBN NUMBER:}
\optdef{*}{isbn}{Include ISBN}{for books, booklets, etc.}
\optdef{x}{}{No ISBN}{}
\getans

%    \end{macrocode}
%
% \subsection*{Edited by}
% For an article within an edited collection, the normal form is 
% \begin{quote}
% In J. K. James, editor, \emph{Title of Collection} \dots
% \end{quote}
% Alternative forms are
% \begin{quote}
% In J. K. James (editor), \emph{Title} \dots\\
% In \emph{Title}, edited by J. K. James \dots\\
% In \emph{Title} (Edited by J. K. James) \dots
% \end{quote}
%    \begin{macrocode}
\mes{^^JEDITOR IN WHOLE BOOK:}
\optdef{*}{}{Word `editor' after name}{of book editor without author}
\optdef{a}{edpar}{`(editor)'}{in parentheses, after name}
\getans

\mes{^^JEDITOR IN COLLECTIONS:}
\optdef{*}{}{.., editor, booktitle}{of collection}
\optdef{b}{edby}{Booktitle, edited by .. }{}
\optdef{p}{edby-par}{Booktitle (edited by ..)}{}
\optdef{e}{edby}{Booktitle, editor ..}{}
\optdef{k}{edby-par}{Booktitle (editor..)}{}
\optdef{j}{edby}{Booktitle, .., editor}{}
\optdef{m}{edby-par}{Booktitle (.., editor)}{}
\getans

\mytempfalse
\if\ans e\mytemptrue\fi
\if\ans k\mytemptrue\fi
\ifmytemp
\wr{\spsp\sep edbyx\pc: Replace `edited by' by `editor(s)'}
\fi

\mytempfalse
\if\ans j\mytemptrue\fi
\if\ans m\mytemptrue\fi
\ifmytemp
\wr{\spsp\sep edbyy\pc: Replace `edited by..' by `.., editor(s)'}
\fi

\mytempfalse
\if\ans p\mytemptrue\fi
\if\ans k\mytemptrue\fi
\ifmytemp
\mes{^^JCAPITALIZE `EDITOR' OR `EDITED BY':}
\optdef{*}{}{`(editor,..)' or `(edited by..)'}{in lowercase}
\optdef{c}{edcap}{`(Editor,..)' or `(Edited by..)'}{in uppercase}
\getans
\fi

%    \end{macrocode}
%
% \subsection*{Block punctuation}
% Blocks are logical sections of the reference specification, such as the
% author block, the journal block, editor block, etc. These are normally
% separated by periods, but alternatively a comma may be used. Another
% choice is to use commas except after titles where a period is given.
%
% \LaTeX\ offers an \texttt{openbib} option, which means that the blocks
% are not only new sentences, but new lines as well. This can only
% function when the default option here is taken, for then the command
% |\newblock| is placed between the blocks. This command is normally
% defined to do nothing, but \LaTeX\ redefines it to issue a new line
% when open bibliographies are wanted.
%    \begin{macrocode}
\mes{^^JPUNCTUATION BETWEEN SECTIONS (BLOCKS):}
\optdef{*}{}{\string\newblock\space after blocks}
   {(periods or new lines with openbib option)}
\optdef{c}{blk-com}{Comma between blocks}{}
\optdef{s}{blk-com}{Semi-colon between blocks}{}
\optdef{b}{blk-com}{Blanks between blocks}{}
\optdef{t}{blk-tit}{Period after titles of articles, books, etc}{else commas}
\optdef{a}{blk-tita}{Period after titles of articles}{else commas}
\getans

\if\ans s
\wr{\spsp\spsp\sep com-semi\pc: Semi-colon replaces comma between blocks} 
\fi
\if\ans b
\wr{\spsp\spsp\sep com-blank\pc: Blank replaces comma between blocks} 
\fi

\mes{^^JPUNCTUATION AFTER AUTHORS:}
\optdef{*}{}{Author block normal}{with regular block punctuation}
\optdef{c}{au-col}{Author block with colon}{}
\getans

%    \end{macrocode}
%
% \subsection*{\textsl{In} with colon}
% When referring to works in a collection, one begins the block describing
% that collection with \textsl{In}. Optionally, one may add a colon.
%    \begin{macrocode}
\mes{^^JPUNCTUATION AFTER `IN':}
\optdef{*}{}{Space after `in'}{for edited works or proceedings}
\optdef{c}{in-col}{Colon after `in'}{(as `In: ...')}
\optdef{x}{in-x}{No word `in'}{for edited works}
\getans

%    \end{macrocode}
% 
% \subsection*{Final punctuation}
% The punctuation at the end of the reference is normally a period. This
% may be suppressed.
%    \begin{macrocode}
\mes{^^JFINAL PUNCTUATION:}
\optdef{*}{}{Period at very end}{of the listed reference}
\optdef{x}{fin-bare}{No period at end}{}
\getans

%    \end{macrocode}
%
% \subsection*{Abbreviations}
% A number of words may be abbreviated: pages, editors, volume, chapter,
% and so on. The first two may be independently set to abbreviation, the
% rest with a single option. 
% 
% Additionally, the edition numbers may be
% output as words (first, second, etc.) or as numbers (1st, 2nd, etc.). 
% (Recall that the input in the \texttt{.bib} file is always as English
% words.)
%    \begin{macrocode}

\if!\cfile!
\mes{^^JABBREVIATE WORD `PAGES':}
\optdef{*}{}{`Page(s)'}{(no abbreviation)}
\optdef{a}{pp}{`Page' abbreviated}{as p. or pp.}
\optdef{x}{ppx}{`Page' omitted}{}
\getans

\mes{^^JABBREVIATE WORD `EDITORS':}
\optdef{*}{}{`Editor(s)'}{(no abbreviation)}
\optdef{a}{ed}{`Editor' abbreviated}{as ed. or eds.}
\getans

\mes{^^JOTHER ABBREVIATIONS:}
\optdef{*}{}{No abbreviations}{of volume, edition, chapter, etc}
\optdef{a}{abr}{Abbreviations}{of such words}
\getans

\if\ans a
\mes{^^JMONTHS WITH DOTS:}
\optdef{*}{}{Months with dots}{as Jan.}
\optdef{x}{mth-bare}{Months without dots}{as Feb Mar}
\getans
\fi

\mes{^^JEDITION NUMBERS:}
\optdef{*}{}{Write out editions}{as first, second, third, etc}
\optdef{n}{ord}{Numerical editions}{as 1st, 2nd, 3rd, etc}
\getans
%    \end{macrocode}
%
% The above choices about abbreviations are made only if the internal
% languages are taken (English or \texttt{babel}). For an external language
% definition file, these choices, along with possible other ones, are made
% in the external file, which is read in at this point.
%    \begin{macrocode}
\else
\input\cfile
\fi

%    \end{macrocode}
%
% This file contains the standard set of stored journal names present in
% the basic bibliography style files. If other files containing journal
% names are to be included, they may only contain the option \texttt{jabr}
% since that option is selected here. No option menus from the journal-name
% files will be read in.
%    \begin{macrocode}
\mes{^^JSTORED JOURNAL NAMES:}
\optdef{*}{}{Full journal names}{for prestored journals}
\optdef{a}{jabr}{Abbreviated journal names}{}
\getans

%    \end{macrocode}
% \subsection*{Citation label}
% This applies to author--year style only. The label is the text written
% by the |\cite| command, and for author--year style, this is something like
% `Daly et al.\ (1990b)'. One may select italics for the authors and for the
% extra label attached to the year. The year always remains plain.
% 
% If a font is selected for the cited authors, then the word `and' may be
% optionally put in the normal font.
% 
% It is not possible to select the type of brackets for the year, since
% this is determined by the \LaTeX{} style option that manages the
% author--year citations. This is not standard \LaTeX, so that there are a
% number of private style files for achieving this.
%    \begin{macrocode}
\ifnumerical\else
\mes{^^JFONT OF CITATION LABELS IN TEXT:}
\optdef{*}{}{Cited authors plain}{as result of \string\cite\space command}
\optdef{i}{lab-it}{Cited authors italic}{}
\optdef{s}{lab-sc}{Cited authors small caps}{}
\optdef{b}{lab-bf}{Cited authors bold}{}
\getans

\mytempfalse
\if\ans i\mytemptrue\fi
\if\ans s\mytemptrue\fi
\if\ans b\mytemptrue\fi
\ifmytemp
\mes{^^JFONT FOR `AND' IN CITATIONS:}
\optdef{*}{}{Cited `and' in author font}{}
\optdef{r}{and-rm}{Cited `and' in normal font}{}
\getans
\fi

\mes{^^JFONT OF EXTRA LABEL:^^J(The extra letter on the year)}
\optdef{*}{}{Extra label plain}{}
\optdef{i}{xlab-it}{Extra label italic}{}
\getans
\fi

%    \end{macrocode}
%
% \subsection*{Variations on \textsl{and}}
% It is possible to replace the word \textsl{and} with an ampersand \&, and to
% specify whether a comma is to precede \textsl{and} in a list of more than two
% names.
%
% A variable \textsl{and} may be provided for with the command |\BIBand|
% in place of the word. In this case, the command must be defined in the 
% document file or some other package called. (This is intended for situations
% where an ampersand is wanted in parenthetical citations, but the word in 
% textual ones.)
%
%    \begin{macrocode}
\mes{^^JAMPERSAND:}
\optdef{*}{}{Use word `and'}{in author lists}
\optdef{a}{amper}{Use ampersand}{in place of `and'}
\optdef{v}{varand}{Use \string\BIBand}{in place of `and'}
\getans

\mes{^^JCOMMA BEFORE `AND':}
\optdef{*}{}{Comma before `and'}{as `Tom, Dick, and Harry'}
\optdef{n}{and-xcom}{No comma before `and'}{as `Tom, Dick and Harry'}
\optdef{c}{and-com}{Comma with 2 authors}{as `Tom, and Harry'}
\getans

\mes{^^JNO `AND' IN REFERENCE LIST:}
\optdef{*}{}{With `and'}{before last author in reference list}
\optdef{x}{xand}{No `and'}{as `Tom, Dick, Harry'}
\getans

%    \end{macrocode}
%
% \subsection*{Font of \textsl{et al}}
% One can chose that \textsl{et~al.}\ be put into italics.
% Or, if the authors are in a different font from the regular one, the 
% \textsl{et~al.}\ can still be Roman.
%    \begin{macrocode}
\mes{^^JFONT OF `ET AL':}
\optdef{*}{}{Plain et al}{}
\optdef{i}{etal-it}{Italic et al}{}
\optdef{r}{etal-rm}{Roman et al}{even when authors something else}
\getans

%    \end{macrocode}
%
% \subsection*{Define emphasis}
% In everything that been mentioned so far, italicization should be
% understood to mean `emphasize' in the \LaTeX{} sense. This means that the
% command |\em| is used. This is not the same as |\it|, which is always
% italics. Rather, with |\em|, the font style switches between |\rm| and
% |\it| depending on the context. Here one may choose to true italics, or
% to switch off italics altogether.
%    \begin{macrocode}
\mes{^^JEMPHASIS:^^J(affects all so-called italics)}
\optdef{*}{}{Use emphasis}{ie, \string\em, allows font switching}
\optdef{i}{em-it}{Use true italics}{ie, \string\it, absolute italics}
\optdef{x}{em-x}{No italics}{at all}
\getans

%    \end{macrocode}
% \subsection*{New Font Selection Scheme}
% Bold face, italics, and emphasis are made with the \LaTeX~2.09 commands.
% This makes them compatible with \LaTeXe{} as well, but it is possible that
% in future they might die out. Also, they might not be provided with
% future classes. Allow an option to use the New Font Selection Scheme (NFSS)
% font commands in \LaTeXe. If this option is taken, then the \texttt{.bst}
% file may only be used with \LaTeXe.
%    \begin{macrocode}
\mes{^^JNEW FONT SELECTION SCHEME:}
\optdef{*}{}{No NFSS}{use 2.09 font commands}
\optdef{n}{nfss}{NFSS}{use \string\textbf, \string\emph, not \string\bf,
                       \string\em}
\getans

%    \end{macrocode}
% 
% Terminate the options list. If a language definition file has been called, 
% then we have a closing brace too many, so add another dummy opening brace.
%    \begin{macrocode}
\if!\cfile\jfile!\else
\begingroup\MBswitch
\wr(,{\pc)
\endgroup
\fi

\endoptions
%</options>
%    \end{macrocode}
% \StopEventually{\PrintChanges}
% 
% \section{The Bibliographic Coding}
% 
%    \begin{macrocode}
%<*!options&!driver&!bblbst>
%<*!tail>
 %   For use with BibTeX version 0.99a or later
 %-------------------------------------------------------------------
%<*!exlang>
%<!babel> % This bibliography style file is intended for texts in ENGLISH
%<*babel>
 % This bibliography style file requires a file named  babelbst.tex
 %   containing the definitions of word commands like \bbleditor, etc.
%</babel>
%</!exlang>
%<*exlang>
 % This bibliography style file is intended for texts in 
%<bahasa> %   BAHASA
%<brazilian> %   BRAZILIAN
%<catalan> %   CATALAN
%<croatian> %   CROATIAN
%<czech> %   CZECH
%<danish> %   DANISH
%<dutch> %   DUTCH
%<english> %   ENGLISH
%<esperanto> %   ESPERANTO
%<finnish> %   FINNISH
%<french> %   FRENCH
%<galacian> %   GALACIAN
%<german> %   GERMAN
%<hungarian> %   HUNGARIAN
%<italian> %   ITALIAN
%<norwegian> %   NORWEGIAN
%<norsk> %   NORWEGIAN
%<polish> %   POLISH
%<portuguese> %   PORTUGUESE
%<romanian> %   ROMANIAN
%<russian> %   RUSSIAN
%<slovak> %   SLOVAK
%<slovenian> %   SLOVENIAN
%<spanish> %   SPANISH
%<swedish> %   SWEDISH
%<turkish> %   TURKISH
%</exlang>
%<*ay>
 % This is an author-year citation style bibliography. As such, it is 
 % non-standard LaTeX, and requires a special package file to function properly.
 % Such a package is    natbib.sty   by Patrick W. Daly
%<*alk>
 % or:                  apalike.sty  by Oren Patashnik
 % The form of the \bibitem entries is
 %   \bibitem[Jones et al., 1990]{key}...
%</alk>
%<*!(har|ast|alk|cay|nmd|cn)>
 % The form of the \bibitem entries is
 %   \bibitem[Jones et al.(1990)]{key}...
%<nat> %   \bibitem[Jones et al.(1990)Jones, Baker, and Smith]{key}...
 % The essential feature is that the label (the part in brackets) consists
 % of the author names, as they should appear in the citation, with the year
 % in parentheses following. There must be no space before the opening
 % parenthesis!
%<nat> % With natbib v5.3, a full list of authors may also follow the year.
 % In natbib.sty, it is possible to define the type of enclosures that is
 % really wanted (brackets or parentheses), but in either case, there must
 % be parentheses in the label.
 % The \cite command functions as follows:
 %   \cite{key} ==>>                Jones et al. (1990)
 %   \cite[]{key} ==>>              (Jones et al., 1990)
 %   \cite[chap. 2]{key} ==>>       (Jones et al., 1990, chap. 2)
 %   \cite[e.g.][]{key} ==>>        (e.g. Jones et al., 1990)
 %   \cite[e.g.][p. 32]{key} ==>>   (e.g. Jones et al., p. 32)
 %   \citeauthor{key}               Jones et al.
%<nat> %   \citefullauthor{key}           Jones, Baker, and Smith
 %   \citeyear{key}                 1990
%</!(har|ast|alk|cay|nmd|cn)>
%<*har>
 % or:                  harvard.sty  by Peter Williams and Thorsten Schnier
%<harnm> % (needs natbib v5.3  or  harvard v2.0.3)
 % The form of the bibitem entries is
 %   \harvarditem[Jones et al.]{Jones, Baker, and Smith}{1990}{key}...
%</har>
%<*cay>
 % or:                  chicago.sty 
 % The form of the bibitem entries is
 %   \bibitem[\protect\citeauthoryear{Jones, Baker, and Smith}
 %        {Jones et al.}{1990}{key}...
%</cay>
%<*nmd>
 % or:                  named.sty 
 % The form of the bibitem entries is
 %   \bibitem[\protect\citeauthoryear{Jones et al.}{1990}]{key}...
%</nmd>
%<*ast>
 % or:                  astron.sty 
 % The form of the bibitem entries is
 %   \bibitem[\protect\astroncite{Jones et al.}{1990}]{key}...
%</ast>
%<*cn>
 % or:                  authordate1-4.sty
 % The form of the bibitem entries is
 %   \bibitem[\protect\citename{Jones et al.}1990]{key}...
%</cn>
%</ay>
%<*!ay>
%<*!alph&!cite>
 % This is a numerical citation style, and as such is standard LaTeX.
%</!alph&!cite>
%<*alph>
 % This is a labelled citation style similar to the standard alpha.bst,
 %   where labels are of the form Dal90 or DBK89.
%</alph>
%<*cite&!alph>
 % This is a special pseudo-numerical bibliography style, intended to be 
 %   used to list all the entries in a bib database
%</cite&!alph>
 % It requires no extra package to interface to the main text.
 % The form of the \bibitem entries is 
%<!alph&!cite> %   \bibitem{key}...
%<alph> %   \bibitem[label]{key}...
%<!alph&cite> %   \bibitem[key]{key}...
%<*!cite|alph>
 % Usage of \cite is as follows:
%<*!alph&!cite>
 %   \cite{key} ==>>          [#]
 %   \cite[chap. 2]{key} ==>> [#, chap. 2]
 % where # is a number determined by the ordering in the reference list.
%</!alph&!cite>
%<*alph>
 %   \cite{key} ==>>          [label]
 %   \cite[chap. 2]{key} ==>> [label, chap. 2]
 % The order in the reference list is by label.
%</alph>
%<*seq-no&!alph> 
 % The order in the reference list is that by which the works were originally 
 %   cited in the text, or that in the database.
%</seq-no&!alph> 
%<*!seq-no&!alph> 
 % The order in the reference list is alphabetical by authors.
%</!seq-no&!alph> 
%</!cite|alph>
%</!ay>
 %---------------------------------------------------------------------

%    \end{macrocode}
% \changes{1.5(2.3)}{1994 Sep 16}{Add URL entry type for \texttt{harnm} option}
%  The new \texttt{harvard.sty} of \LaTeXe{} includes an entry URL, or
%  rather it is included in the new \texttt{.bst} files for it. Add it 
%  here too, but only for option \texttt{harnm}.
%
% \changes{3.0}{1995 Mar 1}{Add optional entries \texttt{isbn}}
% Books normally have an ISBN number.
% This entry is (optionally) included, modelled after that in
% \texttt{xbtxbst.doc}.
%    \begin{macrocode}
ENTRY
  { address
    author
    booktitle
    chapter
    edition
    editor
    howpublished
    institution
%<isbn>    isbn
    journal
    key
    month
    note
    number
    organization
    pages
    publisher
    school
    series
    title
    type
%<harnm>    URL
    volume
    year
  }
  {}
%<!ay&!alph>  { label }
%<!ay&alph>  { label extra.label sort.label }
%<ay>  { label extra.label sort.label short.list }

INTEGERS { output.state before.all mid.sentence after.sentence after.block }

FUNCTION {init.state.consts}
{ #0 'before.all :=
  #1 'mid.sentence :=
  #2 'after.sentence :=
  #3 'after.block :=
}

STRINGS { s t }

FUNCTION {output.nonnull}
{ 's :=
  output.state mid.sentence =
%<!blk-com|(!com-semi&!com-blank)>    { ", " * write$ }
%<blk-com&com-semi>    { "; " * write$ }
%<blk-com&!com-semi&com-blank>    { " " * write$ }
    { output.state after.block =
        { add.period$ write$
          newline$
          "\newblock " write$
        }
        { output.state before.all =
            'write$
            { add.period$ " " * write$ }
          if$
        }
      if$
      mid.sentence 'output.state :=
    }
  if$
  s
}

FUNCTION {output}
{ duplicate$ empty$
    'pop$
    'output.nonnull
  if$
}

FUNCTION {output.check}
{ 't :=
  duplicate$ empty$
    { pop$ "empty " t * " in " * cite$ * warning$ }
    'output.nonnull
  if$
}

FUNCTION {fin.entry}
%<*!fin-bare>
{ add.period$
  write$
%</!fin-bare>
%<*fin-bare>
{ duplicate$ empty$   
    'pop$
    'write$
  if$
%</fin-bare>
  newline$
}

FUNCTION {new.block}
{ output.state before.all =
    'skip$
    { after.block 'output.state := }
  if$
}

FUNCTION {new.sentence}
{ output.state after.block =
    'skip$
    { output.state before.all =
        'skip$
        { after.sentence 'output.state := }
      if$
    }
  if$
}

%    \end{macrocode}
%
% \begin{macro}{`add.blank'}
% \changes{1.5(2.3)b}{1995 Jan 10}{Add function}
% When text is printed with \texttt{output} or
% \texttt{output.check}, the \texttt{output.state} is set such that
% a comma will precede the next output text. For special effects, we want to
% suppress this comma, inserting a blank instead. Hence the
% \texttt{output.state} is changed to \texttt{before.all}, meaning no
% punctuation is to be inserted.
%    \begin{macrocode}
FUNCTION {add.blank}
{  " " * before.all 'output.state :=
}

%    \end{macrocode}
% \end{macro}
% \begin{macro}{`add.colon'}
% \changes{3.4}{1995 Sep 28}{Add macro}
%    \begin{macrocode}
%<*au-col>
FUNCTION {add.colon}
{ empty$
    'skip$
    { before.all 'output.state := ":" output add.blank }
  if$
}

%</au-col>
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{`no.blank.or.punct'}
% \changes{3.2}{1995 May 19}{Add function}
% \changes{3.2}{1995 May 30}{Present only for option \texttt{yrpp-xsp}}
% Another frill is to suppresss both blanks and punctuation. The |\hspace|
% permits a line break at this point.
%    \begin{macrocode}
%<*yrpp-xsp>
FUNCTION {no.blank.or.punct}
{  "\hspace{0pt}" * before.all 'output.state :=
}

%</yrpp-xsp>
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{`date.block'}
% \changes{3.0}{1995 Mar 9}{Add function}
% \changes{3.81}{1996 Jun 25}{Add option \texttt{yrp-per}}
% The \texttt{date.block} function is used for special punctuating effects
% after the date.
%    \begin{macrocode}
FUNCTION {date.block}
{
%<*!yrp-x>
%<yrp-col>  ":" *
%<*!yrp-col>
%<yrp-semi>  ";" * 
%<*!yrp-semi>
%<!blk-com&!blk-tit&!blk-tita>  new.block
%<(blk-com|blk-tit|blk-tita)&!yrp-per>  skip$
%<(blk-com|blk-tit|blk-tita)&yrp-per>  new.sentence
%</!yrp-semi>
%</!yrp-col>
%</!yrp-x>
%<*yrp-x|yrp-col|yrp-semi>
%<!yrpp-xsp>  add.blank
%<yrpp-xsp>  no.blank.or.punct
%</yrp-x|yrp-col|yrp-semi>
}

%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
FUNCTION {not}
{   { #0 }
    { #1 }
  if$
}

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

FUNCTION {or}
{   { pop$ #1 }
    'skip$
  if$
}

%    \end{macrocode}
% \begin{macro}{`non.stop'}
% \changes{1.4(2.2)a}{1994 Sep 8}{Add to test if last character
%   is punctuation: . ! ?}
% This function (my invention) tests if the last character in the string
% on the stack is \texttt{. ! ?} by using \texttt{add.period\$}. It is to
% be used for conditional italic correction or adding commas.
%    \begin{macrocode}
FUNCTION {non.stop}
{ duplicate$ 
   "}" * add.period$ 
   #-1 #1 substring$ "." =
} 

%    \end{macrocode}
% \end{macro}
%    \begin{macrocode}
%<*!ay>
FUNCTION {new.block.checka}
{ empty$
    'skip$
    'new.block
  if$
}

%</!ay>
FUNCTION {new.block.checkb}
{ empty$
  swap$ empty$
  and
    'skip$
    'new.block
  if$
}

%<*!ay>
FUNCTION {new.sentence.checka}
{ empty$
    'skip$
    'new.sentence
  if$
}

FUNCTION {new.sentence.checkb}
{ empty$
  swap$ empty$
  and
    'skip$
    'new.sentence
  if$
}

%</!ay>
FUNCTION {field.or.null}
{ duplicate$ empty$
    { pop$ "" }
    'skip$
  if$
}

%    \end{macrocode}
% \begin{macro}{`emphasize'}
% Emphasis can be either italic or the alternating font. The font command
% may be NFSS or regular \LaTeX~2.09 declarations.
%\changes{1.3(2.1)}{1994 Jul 1}{Add \texttt{nfss} option}
%    \begin{macrocode}
FUNCTION {emphasize}
%<*!em-x>
{ duplicate$ empty$
    { pop$ "" }
%<*!nfss>
%<!em-it>    { "{\em " swap$ * "\/}" * }
%<em-it>    { "{\it " swap$ * "\/}" * }
%</!nfss>
%<*nfss>
%<!em-it>    { "\emph{" swap$ * "}" * }
%<em-it>    { "\textit{" swap$ * "}" * }
%</nfss>
  if$
}
%</!em-x>
%<em-x>{ skip$ }

%<*nmft-bf|vol-bf|vol-2bf|lab-bf|dtbf>
%    \end{macrocode}
% \end{macro}
% \begin{macro}{`bolden'}
% The bold font command may be NFSS or the regular \LaTeX~2.09 declaration.
%\changes{1.3(2.1)}{1994 Jul 1}{Add \texttt{nfss} option}
%    \begin{macrocode}
FUNCTION {bolden}
{ duplicate$ empty$
    { pop$ "" }
%<!nfss>    { "{\bf " swap$ * "}" * }
%<nfss>    { "\textbf{" swap$ * "}" * }
  if$
}

%</nmft-bf|vol-bf|vol-2bf|lab-bf|dtbf>
%<*lab-sc|nmft-sc>
%    \end{macrocode}
% \end{macro}
% \begin{macro}{`scaps'}
% To put text into small caps.
%\changes{3.0}{1995 Mar 3}{Add function}
%    \begin{macrocode}
FUNCTION {scaps}
{ duplicate$ empty$
    { pop$ "" }
%<!nfss>    { "{\sc " swap$ * "}" * }
%<nfss>    { "\textsc{" swap$ * "}" * }
  if$
}

%</lab-sc|nmft-sc>
%<*and-rm|nmand-rm|etal-rm>
%    \end{macrocode}
% \end{macro}
% \begin{macro}{`roman.list'}
% \changes{3.4}{1995 Sep 28}{Add function}
% \begin{macro}{`roman.cite'}
% \changes{3.8}{1996 Mar 16}{Add function}
% These functions are use to print the words `and' and `et al.' in the
% authors' names in the regular font. Since the list of references and the
% citations can in principle have different author fonts, we need two such
% commands. For non-NFSS, these just select |\rm|, but for NFSS, the one
% attribute specifying the authors' fonts is reset.
% 
%    \begin{macrocode}
FUNCTION {roman.list}
{ duplicate$ empty$
    { pop$ "" }
%<!nfss>    { "{\rm " swap$ * "}" * }
%<*nfss>
%<nmft-bf>    { "{\mdseries " swap$ * "}" * }
%<(nmft-it|nmft-sc)&!nmft-bf>    { "{\upshape " swap$ * "}" * }
%<!nmft-it&!nmft-sc&!nmft-bf>    { "{\normalfont " swap$ * "}" * }
%</nfss>
  if$
}

FUNCTION {roman.cite}
%<!nfss>{ roman.list }
%<*nfss>
{ duplicate$ empty$
    { pop$ "" }
%<lab-bf>    { "{\mdseries " swap$ * "}" * }
%<(lab-it|lab-sc)&!lab-bf>    { "{\upshape " swap$ * "}" * }
%<!lab-it&!lab-sc&!lab-bf>    { "{\normalfont " swap$ * "}" * }
  if$
}
%</nfss>

%</and-rm|nmand-rm|etal-rm>
%    \end{macrocode}
% \end{macro}\end{macro}
%
% \begin{macro}{`capitalize'}
% \changes{3.0}{1995 Mar 7}{Add capitalizing function}
% Capitalizing is easy for regular languages, but for \texttt{babel},
% some trickery stuff is needed; definitions of |\capitalize| and
% |\Capitalize| are written to the \texttt{.bbl} file.
%    \begin{macrocode}
FUNCTION {capitalize}
%<!babel>{ "u" change.case$ "t" change.case$ }
%<babel>{ "\capitalize" swap$ * }

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{`space.word'}
% \changes{2.0}{1994 Jan 31}{Add function to space out words; necessary
%          for the multilingual functions.}
% The function \texttt{space.word} adds a space before and after the word or
% words currently on the stack. This was added for the \texttt{bbl.}$nnn$
% functions, that contain only a word without spacing, but replace explicit
% text in the originals that were spaced out. Its seems more flexible to
% define the word functions to be without spacing.
%    \begin{macrocode}
FUNCTION {space.word}
{ " " swap$ * " " * }

 % Here are the language-specific definitions for explicit words.
 % Each function has a name bbl.xxx where xxx is the English word.
%<*!exlang>
%    \end{macrocode}
% \end{macro}
% \begin{macro}{`bbl.xxx'}
% \changes{2.0}{1994 Jan 31}{Replace all explicit words with functions
%     of the form \texttt{bbl.xxx}.}
% \changes{3.6}{1996 Jan 15}{Add option \texttt{varand}}
% These are the default English words. There is no default language
% option: one of \texttt{english} or \texttt{babel} must be given.
%    \begin{macrocode}
%<*!babel>
 % The language selected here is ENGLISH
FUNCTION {bbl.and}
%<!varand>{ "and"}
%<varand>{ "\BIBand{}"}

FUNCTION {bbl.editors}
%<!ed>{ "editors" }
%<ed>{ "eds." }

FUNCTION {bbl.editor}
%<!ed>{ "editor" }
%<ed>{ "ed." }

FUNCTION {bbl.edby}
{ "edited by" }

FUNCTION {bbl.edition}
%<!abr>{ "edition" }
%<abr>{ "edn." }

FUNCTION {bbl.volume}
%<!abr>{ "volume" }
%<abr>{ "vol." }

FUNCTION {bbl.of}
{ "of" }

FUNCTION {bbl.number}
%<!abr>{ "number" }
%<abr>{ "no." }

FUNCTION {bbl.nr}
{ "no." }

FUNCTION {bbl.in}
{ "in" }

FUNCTION {bbl.pages}
%<!pp&!ppx>{ "pages" }
%<pp>{ "pp." }
%<!pp&ppx>{ "" }

FUNCTION {bbl.page}
%<!pp&!ppx>{ "page" }
%<pp>{ "p." }
%<!pp&ppx>{ "" }

FUNCTION {bbl.chapter}
%<!abr>{ "chapter" }
%<abr>{ "chap." }

FUNCTION {bbl.techrep}
%<!abr>{ "Technical Report" }
%<abr>{ "Tech. Rep." }

FUNCTION {bbl.mthesis}
{ "Master's thesis" }

FUNCTION {bbl.phdthesis}
{ "Ph.D. thesis" }

FUNCTION {bbl.first}
%<!ord>{ "First" }
%<ord>{ "1st" }

FUNCTION {bbl.second}
%<!ord>{ "Second" }
%<ord>{ "2nd" }

FUNCTION {bbl.third}
%<!ord>{ "Third" }
%<ord>{ "3rd" }

FUNCTION {bbl.fourth}
%<!ord>{ "Fourth" }
%<ord>{ "4th" }

FUNCTION {bbl.fifth}
%<!ord>{ "Fifth" }
%<ord>{ "5th" }

FUNCTION {bbl.st}
{ "st" }

FUNCTION {bbl.nd}
{ "nd" }

FUNCTION {bbl.rd}
{ "rd" }

FUNCTION {bbl.th}
{ "th" }

%<*!abr>
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"}

%</!abr>
%<*abr>
MACRO {jan} {"Jan."}

MACRO {feb} {"Feb."}

MACRO {mar} {"Mar."}

MACRO {apr} {"Apr."}

MACRO {may} {"May"}

MACRO {jun} {"Jun."}

MACRO {jul} {"Jul."}

MACRO {aug} {"Aug."}

MACRO {sep} {"Sep."}

MACRO {oct} {"Oct."}

MACRO {nov} {"Nov."}

MACRO {dec} {"Dec."}

%</abr>
%</!babel>
%    \end{macrocode}
%
% Here are the definitions for \texttt{babel} option, i.e., explicit
% translations are not used, but rather only \LaTeX{} macros that must be
% defined in the file \texttt{babelbst.tex}. This could allow automatic
% language selection.
%    \begin{macrocode}
%<*babel>
 % The BABEL language selection is made here; definitions in babelbst.tex.
FUNCTION {bbl.and}
{ "\bbland{}"}

FUNCTION {bbl.editors}
%<!ed>{ "\bbleditors{}" }
%<ed>{ "\bbleds{}" }

FUNCTION {bbl.editor}
%<!ed>{ "\bbleditor{}" }
%<ed>{ "\bbled{}" }

FUNCTION {bbl.edby}
{ "\bbledby{}" }

FUNCTION {bbl.edition}
%<!abr>{ "\bbledition{}" }
%<abr>{ "\bbledn{}" }

FUNCTION {bbl.volume}
%<!abr>{ "\bblvolume{}" }
%<abr>{ "\bblvol{}" }

FUNCTION {bbl.of}
{ "\bblof{}" }

FUNCTION {bbl.number}
%<!abr>{ "\bblnumber{}" }
%<abr>{ "\bblno{}" }

FUNCTION {bbl.nr}
{ "\bblno{}" }

FUNCTION {bbl.in}
{ "\bblin{}" }

FUNCTION {bbl.pages}
%<!pp&!ppx>{ "\bblpages{}" }
%<pp>{ "\bblpp{}" }
%<!pp&ppx>{ "" }

FUNCTION {bbl.page}
%<!pp&!ppx>{ "\bblpage{}" }
%<pp>{ "\bblp{}" }
%<!pp&ppx>{ "" }

FUNCTION {bbl.chapter}
%<!abr>{ "\bblchapter{}" }
%<abr>{ "\bblchap{}" }

FUNCTION {bbl.techrep}
%<!abr>{ "\bbltechreport{}" }
%<abr>{ "\bbltechrep{}" }

FUNCTION {bbl.mthesis}
{ "\bblmthesis{}" }

FUNCTION {bbl.phdthesis}
{ "\bblphdthesis{}" }

FUNCTION {bbl.first}
%<!ord>{ "\bblfirst{}" }
%<ord>{ "\bblfirsto{}" }

FUNCTION {bbl.second}
%<!ord>{ "\bblsecond{}" }
%<ord>{ "\bblsecondo{}" }

FUNCTION {bbl.third}
%<!ord>{ "\bblthird{}" }
%<ord>{ "\bblthirdo{}" }

FUNCTION {bbl.fourth}
%<!ord>{ "\bblfourth{}" }
%<ord>{ "\bblfourtho{}" }

FUNCTION {bbl.fifth}
%<!ord>{ "\bblfifth{}" }
%<ord>{ "\bblfiftho{}" }

FUNCTION {bbl.st}
{ "\bblst{}" }

FUNCTION {bbl.nd}
{ "\bblnd{}" }

FUNCTION {bbl.rd}
{ "\bblrd{}" }

FUNCTION {bbl.th}
{ "\bblth{}" }

MACRO {jan} {"\bbljan{}"}

MACRO {feb} {"\bblfeb{}"}

MACRO {mar} {"\bblmar{}"}

MACRO {apr} {"\bblapr{}"}

MACRO {may} {"\bblmay{}"}

MACRO {jun} {"\bbljun{}"}

MACRO {jul} {"\bbljul{}"}

MACRO {aug} {"\bblaug{}"}

MACRO {sep} {"\bblsep{}"}

MACRO {oct} {"\bbloct{}"}

MACRO {nov} {"\bblnov{}"}

MACRO {dec} {"\bbldec{}"}

%</babel>
%    \end{macrocode}
%
% \begin{macro}{`eng.ord'}
% \changes{2.0}{1994 Jan 31}{Add function to format English ordinals.}
% This function adds English endings for ordinals 1, 2, 3. However, if
% the second last digit is 1, then the ending is `th' for all last digits.
% So far, all other languages included do not have this problem, and it is
% sufficient to add the \textsl{th} equivalent. This might change with further
% languages. 
% 
% This function must be included with \texttt{babel} too, since that includes
% English. This means that the language definition files must also provide
% for |\bblst|, |\bblnd|, and |\bblrd|, setting them all equal to |\bblth|.
%
%    \begin{macrocode}
%<*english|!exlang>
FUNCTION {eng.ord}
{ duplicate$ "1" swap$ * 
  #-2 #1 substring$ "1" =
     { bbl.th * }
     { duplicate$ #-1 #1 substring$ 
       duplicate$ "1" =
         { pop$ bbl.st * }
         { duplicate$ "2" =
             { pop$ bbl.nd * }
             { "3" =
                 { bbl.rd * }
                 { bbl.th * }
               if$
             }
           if$
          }
       if$
     }         
   if$
}

%</english|!exlang>
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
%</!exlang>
%</!tail>
%<*!head>
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
%<*!jabr>
MACRO {acmcs} {"ACM Computing Surveys"}

MACRO {acta} {"Acta Informatica"}

MACRO {cacm} {"Communications of the ACM"}

MACRO {ibmjrd} {"IBM Journal of Research and Development"}

MACRO {ibmsj} {"IBM Systems Journal"}

MACRO {ieeese} {"IEEE Transactions on Software Engineering"}

MACRO {ieeetc} {"IEEE Transactions on Computers"}

MACRO {ieeetcad}
 {"IEEE Transactions on Computer-Aided Design of Integrated Circuits"}

MACRO {ipl} {"Information Processing Letters"}

MACRO {jacm} {"Journal of the ACM"}

MACRO {jcss} {"Journal of Computer and System Sciences"}

MACRO {scp} {"Science of Computer Programming"}

MACRO {sicomp} {"SIAM Journal on Computing"}

MACRO {tocs} {"ACM Transactions on Computer Systems"}

MACRO {tods} {"ACM Transactions on Database Systems"}

MACRO {tog} {"ACM Transactions on Graphics"}

MACRO {toms} {"ACM Transactions on Mathematical Software"}

MACRO {toois} {"ACM Transactions on Office Information Systems"}

MACRO {toplas} {"ACM Transactions on Programming Languages and Systems"}

MACRO {tcs} {"Theoretical Computer Science"}

%</!jabr>
%<*jabr>
MACRO {acmcs} {"ACM Comput. Surv."}

MACRO {acta} {"Acta Inf."}

MACRO {cacm} {"Commun. ACM"}

MACRO {ibmjrd} {"IBM J. Res. Dev."}

MACRO {ibmsj} {"IBM Syst.~J."}

MACRO {ieeese} {"IEEE Trans. Softw. Eng."}

MACRO {ieeetc} {"IEEE Trans. Comput."}

MACRO {ieeetcad}
 {"IEEE Trans. Comput.-Aided Design Integrated Circuits"}

MACRO {ipl} {"Inf. Process. Lett."}

MACRO {jacm} {"J.~ACM"}

MACRO {jcss} {"J.~Comput. Syst. Sci."}

MACRO {scp} {"Sci. Comput. Programming"}

MACRO {sicomp} {"SIAM J. Comput."}

MACRO {tocs} {"ACM Trans. Comput. Syst."}

MACRO {tods} {"ACM Trans. Database Syst."}

MACRO {tog} {"ACM Trans. Gr."}

MACRO {toms} {"ACM Trans. Math. Softw."}

MACRO {toois} {"ACM Trans. Office Inf. Syst."}

MACRO {toplas} {"ACM Trans. Prog. Lang. Syst."}

MACRO {tcs} {"Theoretical Comput. Sci."}

%</jabr>
%    \end{macrocode}
%
% \begin{macro}{`write.url'}
% \changes{1.5(2.3)}{1994 Sep 16}{Add \texttt{write.url} for option 
%   \texttt{harnm}}
% This function taken over from \texttt{agsm.sty}, the main \texttt{harvard}
% bib style.
%    \begin{macrocode}
%<*harnm>
FUNCTION {write.url}
{ URL empty$
    { skip$ }
    { "\newline\harvardurl{" URL * "}" * write$ newline$ }
  if$
}

%</harnm>
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{`format.names'}
% \changes{1.5(2.3)}{1994 Sep 16}{Add \texttt{harvard} command for `and' with
%    new option \texttt{harnm}}
% \changes{3.0}{1995 Feb 27}{Add option \texttt{nm-revf}}
% \changes{3.0}{1995 Mar 15}{Add option \texttt{nm-rvx}}
% \changes{3.2}{1995 Jun 7}{Add option \texttt{nm-rvv}}
% \changes{3.6}{1995 Dec 7}{Jr to go at end with \texttt{nm-rev1} (AGU style)}
% \changes{3.6}{1995 Dec 8}{Add option \texttt{nmand-rm}}
% \changes{3.6}{1996 Jan 30}{Add option \texttt{etal-rm}}
% \changes{3.7}{1996 Feb 5}{Add option \texttt{aunm-semi}}
% \changes{3.82}{1996 Dec 16}{Add option \texttt{nm-revv1} (AGU style with full
%      names)}
% The \texttt{harvard} package now (version 2.0.3, for \LaTeXe) uses 
% |\harvardand| in place of the word \textsl{and} so that it can be changed
% at run time. This is allowed for with the option \texttt{harnm}, which
% need not be used only with the \texttt{har} option.
% This seems like a useless feature for \texttt{.bst} files made from
% this multilanguage source. However, it is included anyway, which means
% if \texttt{harnm} option selected, one must redefine |\harvardand|
% in the document for the language being used.
%    \begin{macrocode}
INTEGERS { nameptr namesleft numnames }

FUNCTION {format.names}
{ 's :=
  #1 'nameptr :=
  s num.names$ 'numnames :=
  numnames 'namesleft :=
    { namesleft #0 > }
%<*!nm-rev1&!nm-revv1>
    { s nameptr 
%<nm-init>      "{f.~}{vv~}{ll}{, jj}" format.name$ 't :=
%<*!nm-init>
%<nm-rev>      "{vv~}{ll}{, jj}{, f.}" format.name$ 't := 
%<*!nm-rev>
%<nm-rv>      "{vv~}{ll}{ jj}{ f{~}}" format.name$ 't := 
%<*!nm-rv>
%<nm-rvx>      "{vv~}{ll}{ jj}{ f{}}" format.name$ 't := 
%<*!nm-rvx>
%<nm-rvv>      "{vv~}{ll}{ jj}{ f{.}.}" format.name$ 't := 
%<*!nm-rvv>
%<nm-revf>      "{vv~}{ll}{, jj}{, ff}" format.name$ 't := 
%<*!nm-revf>
      "{ff~}{vv~}{ll}{, jj}" format.name$ 't :=
%</!nm-revf>
%</!nm-rvv>
%</!nm-rvx>
%</!nm-rv>
%</!nm-rev>
%</!nm-init>
%</!nm-rev1&!nm-revv1>
%<*nm-rev1>
    { nameptr #1 >
        { s nameptr "{f.~}{vv~}{ll}{, jj}" format.name$ 't := }
        { s nameptr "{vv~}{ll}{, f.}{, jj}" format.name$ 't := }
      if$
%</nm-rev1>
%<*!nm-rev1&nm-revv1>
    { nameptr #1 >
        { s nameptr "{ff~}{vv~}{ll}{, jj}" format.name$ 't := }
        { s nameptr "{vv~}{ll}{, ff}{, jj}" format.name$ 't := }
      if$
%</!nm-rev1&nm-revv1>
      nameptr #1 >
        { 
%<*nmlm>
%<m1>          nameptr #2 =
%<m2>          nameptr #3 =
%<m3>          nameptr #4 =
%<m4>          nameptr #5 =
%<m5>          nameptr #6 =
%<m6>          nameptr #7 =
%<x1>          numnames #1 > and
%<x2>          numnames #2 > and
%<x3>          numnames #3 > and
%<x4>          numnames #4 > and
%<x5>          numnames #5 > and
%<x6>          numnames #6 > and
%<x7>          numnames #7 > and
%<x8>          numnames #8 > and
%<x9>          numnames #9 > and
            { "others" 't :=
              #1 'namesleft := }
            'skip$
          if$
%</nmlm>
          namesleft #1 >
%<!aunm-semi>            { ", " * t * }
%<aunm-semi>            { "; " * t * }
            {
%<(and-com|xand)&!aunm-semi>              "," *
%<(and-com|xand)&aunm-semi>              ";" *
%<*!and-xcom&!and-com&!xand>
              numnames #2 >
%<!aunm-semi>                { "," * }
%<aunm-semi>                { ";" * }
                'skip$
              if$
%</!and-xcom&!and-com&!xand>
              t "others" =
%<!etal-it&!etal-rm>                { " et~al." * }
%<!etal-it&etal-rm>                { " " * "et~al." roman.list * }
%<etal-it>                { " " * "et~al." emphasize * }
%<*!harnm>
%<!amper&!xand&!nmand-rm>                { bbl.and space.word * t * }
%<!amper&!xand&nmand-rm>                { bbl.and roman.list space.word * t * }
%<amper&!xand>                { " \& " * t * }
%</!harnm>
%<harnm&!xand>                { " \harvardand\ " * t * }
%<xand>                { " " * t * }
              if$
            }
          if$
        }
        't
      if$
      nameptr #1 + 'nameptr :=
      namesleft #1 - 'namesleft :=
    }
  while$
}

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{`format.names.ed'}
% \changes{1.6(2.4)}{1995 Feb 2}{Add option \texttt{ed-rev} to allow editor
%    to be formatted just like authors'}
% \changes{3.0}{1995 Feb 27}{Option \texttt{nm-revf} to act just as default}
% When editors are used in place of authors to identify the work, the
% names are always formatted just like authors'. However, in collections,
% where ``edited by'' or ``\emph{names} (editors)'' are given, it is
% normal not the reverse the names, even if the authors' are. The option
% \texttt{ed-rev} sees to it that editor names are always formatted exactly
% like those of authors, being reversed if necessary.
%
% The option \texttt{nm-revf} in this case acts the same as the default
% when no \texttt{nm-} option given: full names with surname last. Therefore
% it is not necessary to test for it at all, since it, like the default,
% has the lowest priority: any other \texttt{nm-} option clobbers it.
%
% The option \texttt{aunm-semi} will put a semi-colon between editor names, just
% as for authors, when \texttt{ed-rev} selected, in keeping with the idea
% that in this case both authors and editors are to be formatted the same.
%    \begin{macrocode}
FUNCTION {format.names.ed}
%<ed-rev>{ format.names }
%<*!ed-rev>
{ 's :=
  #1 'nameptr :=
  s num.names$ 'numnames :=
  numnames 'namesleft :=
    { namesleft #0 > }
    { s nameptr 
%<nm-init|nm-rev|nm-rev1>      "{f.~}{vv~}{ll}{, jj}" 
%<*!nm-init&!nm-rev&!nm-rev1>
%<nm-revv1>      "{ff~}{vv~}{ll}{, jj}" 
%<*!nm-revv1>
%<nm-rv>      "{f{~}~}{vv~}{ll}{ jj}" 
%<*!nm-rv>
%<nm-rvx>      "{f{}~}{vv~}{ll}{ jj}" 
%<*!nm-rvx>
%<nm-rvv>      "{f{.}.~}{vv~}{ll}{ jj}" 
%<*!nm-rvv>
      "{ff~}{vv~}{ll}{, jj}" 
%</!nm-rvv>
%</!nm-rvx>
%</!nm-rv>
%</!nm-revv1>
%</!nm-init&!nm-rev&!nm-rev1>
      format.name$ 't := 
      nameptr #1 >
        { 
          namesleft #1 >
%<!aunm-semi>            { ", " * t * }
%<aunm-semi>            { "; " * t * }
            {
%<(and-com|xand)&!aunm-semi>              "," *
%<(and-com|xand)&aunm-semi>              ";" *
%<*!and-xcom&!and-com&!xand>
              numnames #2 >
%<!aunm-semi>                { "," * }
%<aunm-semi>                { ";" * }
                'skip$
              if$
%</!and-xcom&!and-com&!xand>
              t "others" =
%<!etal-it&!etal-rm>                { " et~al." * }
%<!etal-it&etal-rm>                { " " * "et~al." roman.list * }
%<etal-it>                { " " * "et~al." emphasize * }
%<*!harnm>
%<!amper&!xand&!nmand-rm>                { bbl.and space.word * t * }
%<!amper&!xand&nmand-rm>                { bbl.and roman.list space.word * t * }
%<amper&!xand>                { " \& " * t * }
%</!harnm>
%<harnm&!xand>                { " \harvardand\ " * t * }
%<xand>                { " " * t * }
              if$
            }
          if$
        }
        't
      if$
      nameptr #1 + 'nameptr :=
      namesleft #1 - 'namesleft :=
    }
  while$
}

%</!ed-rev>
%    \end{macrocode}
% \end{macro}
%    \begin{macrocode}
%<*ay>
FUNCTION {format.key}                   
{ empty$
    { key field.or.null }
    { "" }
  if$
}

%</ay>
%    \end{macrocode}
% \begin{macro}{`format.authors'}
%    \begin{macrocode}
FUNCTION {format.authors}
{ author empty$
    { "" }
    {
%<nmft-sc>      author format.names scaps 
%<*!nmft-sc>
%<nmft-bf>      author format.names bolden 
%<*!nmft-bf>
%<nmft-it>      author format.names emphasize 
%<*!nmft-it>
      author format.names 
%</!nmft-it>
%</!nmft-bf>
%</!nmft-sc>
    }
  if$
}

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{`format.editors'}
% \changes{3.0}{1995 Mar 20}{Add option \texttt{edpar}}
% The option \texttt{edpar} puts the word `editor' in parentheses.
% In \texttt{genbst.mbs}, this occurred automatically with the option
% \texttt{ed}, to abbreviate `editor' to `ed'. In \texttt{babel.mbs},
% this was not the case, because of complications with the word functions.
% Now this possibility is added as a special option, which means there is
% some inconsistency with older \texttt{.dbj} files that called \texttt{ed}:
% the abbreviated `ed' is not put in parentheses unless \texttt{edpar} is
% also called.
%    \begin{macrocode}
FUNCTION {format.editors}
{ editor empty$
    { "" }
    {
%<nmft-sc>      editor format.names scaps 
%<*!nmft-sc>
%<nmft-bf>      editor format.names bolden 
%<*!nmft-bf>
%<nmft-it>      editor format.names emphasize 
%<*!nmft-it>
      editor format.names 
%</!nmft-it>
%</!nmft-bf>
%</!nmft-sc>
      editor num.names$ #1 >
%<*!edpar>
        { ", " * bbl.editors * }
        { ", " * bbl.editor * }
%</!edpar>
%<*edpar>
        { " (" * bbl.editors * ")" * }
        { " (" * bbl.editor * ")" * }
%</edpar>
      if$
    }
  if$
}

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{`format.in.editors'}
% \changes{3.0}{1995 Mar 20}{Add option \texttt{edpar}}
% See the note about the option \texttt{edpar} above.
%    \begin{macrocode}
FUNCTION {format.in.editors}
{ editor empty$
    { "" }
    { editor format.names.ed
%<*!edby&!edby-par>
      editor num.names$ #1 >
%<*!edpar>
        { ", " * bbl.editors * }
        { ", " * bbl.editor * }
%</!edpar>
%<*edpar>
        { " (" * bbl.editors * ")" * }
        { " (" * bbl.editor * ")" * }
%</edpar>
      if$
%</!edby&!edby-par>
    }
  if$
}

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{`format.isbn'}
% \changes{3.0}{1995 Mar 1}{Add function}
%    \begin{macrocode}
%<*isbn>
FUNCTION {format.isbn}
{ isbn empty$
    { "" }
    { 
%<!blk-com&!blk-tit&!blk-tita>      new.block 
      "ISBN " isbn * }
  if$
}

%</isbn>
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{`format.title'}
% \changes{1.4(2.2)a}{1994 Sep 7}{Add enquote function to put titles in quotes,
%    such that punctuation is inside quotes.}
% \changes{3.8}{1996 Apr 17}{Fix bug in quoted title and \texttt{blk-com}}
%    \begin{macrocode}
FUNCTION {format.title}
{ title empty$
    { "" }
%<!atit-u>    { title "t" change.case$ 
%<atit-u>    { title 
%<tit-it>      emphasize
%<*!tit-it&(tit-q|tit-qq)>
      "\enquote{" swap$ * 
%<*blk-com>
      non.stop
%<!com-semi&!com-blank>        { ",} " * }
%<com-semi>        { ";} " * }
%<!com-semi&com-blank>        { "} " * }
        { "} " * }
      if$
%</blk-com>
%<!blk-com>      add.period$ "}" *
%</!tit-it&(tit-q|tit-qq)>
    }
  if$
}

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{`end.quote.title'}
% \changes{3.82}{1996 Nov 15}{Add macro to finish off quoted titles}
% For a quoted title, the punctuation appears in the quotes. For commas
% between block, this means the inter-block punctuation is already present,
% so it must be suppressed after every \texttt{format.title output}. This
% is done by setting the \texttt{output.state} to \texttt{before.all}, but
% only if there really was a title. Call this macro every time after
% titles are output.
%    \begin{macrocode}
%<*blk-com&(tit-q|tit-qq)>  
FUNCTION {end.quote.title}
{ title empty$
    'skip$
    { before.all 'output.state := }
  if$
}

%</blk-com&(tit-q|tit-qq)>  
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{`make.full.names'}
% \changes{1.1}{1993 Nov 12}{Add key labels to \texttt{calc.long.label} and
%     get {\tt'author} and {\tt'editor} in right order when author
%     missing.}
% \changes{1.4(2.2)}{1994 Sep 5}{Remove \texttt{calc.long.label} and
%     \texttt{format.long.lab.names}, replacing them with 
%     \texttt{format.full.names}, \texttt{make.full.names}, and adding
%     \texttt{author.editor.key}, \texttt{author.key}, and \texttt{editor.key}}
% \changes{1.4(2.2)a}{1994 Sep 7}{Remove option \texttt{and-com} from 
%     \texttt{make.full.names}}
% \changes{1.5(2.3)}{1994 Sep 15}{Add full names for \texttt{natbib} v5.3}
% \changes{3.6}{1995 Dec 8}{Suppress `and' in full list if suppressed in short}
% \changes{3.6}{1995 Dec 8}{Font of `and' in lists same as in citations}
% In versions before 2.2, there were two functions \texttt{calc.long.label}
% and \texttt{format.long.lab.names} that made up the string
% \texttt{long.label} for each entry. This contains the full author list.
% However, there was a bug in the one routine, entered by mistake when an
% earlier bug was removed, and more seriously, the string
% \texttt{long.label} was limited to \texttt{entry.max\$} characters, 100 on
% my system. Author lists were truncated.  Thus, \texttt{make.full.names}
% is used instead to enter the full list of names directly in the
% \texttt{output.bibitem} function, without an intermediate string. This
% involves changing the order of some function definitions, especially
% \texttt{output.bibitem} must come later.
%    \begin{macrocode}
%<*har|cay|nat>
FUNCTION {format.full.names}
{'s :=
  #1 'nameptr :=
  s num.names$ 'numnames :=
  numnames 'namesleft :=
    { namesleft #0 > }
    { s nameptr 
      "{vv~}{ll}" format.name$ 't :=
      nameptr #1 >
        { 
%<*nmlm>
%<m1>          nameptr #2 =
%<m2>          nameptr #3 =
%<m3>          nameptr #4 =
%<m4>          nameptr #5 =
%<m5>          nameptr #6 =
%<x1>          numnames #1 > and
%<x2>          numnames #2 > and
%<x3>          numnames #3 > and
%<x4>          numnames #4 > and
%<x5>          numnames #5 > and
%<x6>          numnames #6 > and
%<x7>          numnames #7 > and
%<x8>          numnames #8 > and
%<x9>          numnames #9 > and
            { "others" 't :=
              #1 'namesleft := }
            'skip$
          if$
%</nmlm>
          namesleft #1 >
            { ", " * t * }
            {
%<*!and-xcom>
              numnames #2 >
                { "," * }
                'skip$
              if$
%</!and-xcom>
              t "others" =
%<!etal-it&!etal-rm>                { " et~al." * }
%<!etal-it&etal-rm>                { " " * "et~al." roman.cite * }
%<etal-it>                { " " * "et~al." emphasize * }
%<*!harnm>
%<!amper&!and-rm>                { bbl.and space.word * t * }
%<!amper&and-rm>                { bbl.and roman.cite space.word * t * }
%<amper>                { " \& " * t * }
%</!harnm>
%<harnm>                { " \harvardand\ " * t * }
              if$
            }
          if$
        }
        't
      if$
      nameptr #1 + 'nameptr :=
      namesleft #1 - 'namesleft :=
    }
  while$
}

FUNCTION {author.editor.key.full}
{ author empty$
    { editor empty$
        { key empty$
            { cite$ #1 #3 substring$ }
            'key
          if$
        }
        { editor format.full.names }
      if$
    }  
    { author format.full.names }
  if$
}

FUNCTION {author.key.full}
{ author empty$
    { key empty$
         { cite$ #1 #3 substring$ }
          'key
      if$
    }  
    { author format.full.names }
  if$
}

FUNCTION {editor.key.full}
{ editor empty$
    { key empty$
         { cite$ #1 #3 substring$ }
          'key
      if$
    }  
    { editor format.full.names }
  if$
}

FUNCTION {make.full.names}
{ type$ "book" =
  type$ "inbook" =
  or
    'author.editor.key.full
    { type$ "proceedings" =
        'editor.key.full
        'author.key.full
      if$
    }
  if$
%<lab-it>  emphasize
%<lab-bf&!lab-it>  bolden
%<lab-sc&!lab-it&!lab-bf>  scaps
}

%</har|cay|nat>
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{`output.bibitem'}
%\changes{1.1}{1993 Nov 12}{Test for missing year, set to {\tt????}.}
% The \texttt{output.bibitem} function formats the |\bibitem| entries.
%\changes{1.4(2.2)}{1994 Sep 5}{Move to later location, add
%   \texttt{make.full.names} instead of inserting string \texttt{long.label}}
%\changes{1.5(2.3)}{1994 Sep 16}{Add option \texttt{nat} for full author list
%  for \texttt{natbib.sty} version~5.3}
%    \begin{macrocode}
FUNCTION {output.bibitem}
{ newline$
%<*ay>
%<!har>  "\bibitem[" write$
%<har>  "\harvarditem" write$
%<nmd>  "\protect\citeauthoryear{" write$
%<ast>  "\protect\astroncite{" write$
%<cay>  "\protect\citeauthoryear{" make.full.names * "}{" * write$
%<cn>  "\protect\citename{" write$
%<!har>  label write$
%<har>  make.full.names duplicate$ label =
%<har>    'skip$
%<har>    { "[" label * "]" * write$ }
%<har>  if$
%<har>  "{" swap$ * "}{" * write$ 
%<har>  year duplicate$ empty$
%<cn>  ", }" year duplicate$ empty$
%<cay|nmd|ast>  "}{" year duplicate$ empty$
%<har|cn|cay|nmd|ast>    { pop$ "????" }
%<har|cn|cay|nmd|ast>    'skip$
%<har|cn|cay|nmd|ast>  if$
%<har>  extra.label * "}{" * write$
%<cn>  * extra.label * "]{" * write$
%<cay|nmd|ast>  * extra.label * "}]{" * write$
%<alk>  "]{" write$
%<!(har|cay|nmd|ast|alk|cn|nat)>  ")]{" write$
%<nat>  ")" make.full.names duplicate$ short.list =
%<nat>     { pop$ }
%<nat>     { * }
%<nat>   if$
%<nat>  "]{" * write$
%</ay>
%<!ay&!(cite|alph)>  "\bibitem{" write$
%<!ay&(cite|alph)>  "\bibitem[" label * "]{" * write$
  cite$ write$
  "}" write$
  newline$
  ""
  before.all 'output.state :=
}

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{`bracket.number'}
% \changes{3.6}{1995 Nov 23}{Add function to put `number' on pages}
% For the scheme in which the `number' is added to the pages, provide this
% function which is called in \texttt{num.pages}. This adds number at
% the start and after any hyphens.
%    \begin{macrocode}
%<*vnum-pg>
FUNCTION {bracket.number}
{ number empty$
  'skip$
  { "(" number * ")" * * }
  if$
}

FUNCTION {num.pages}
{ 't :=
  "0" 's :=
  ""
  bracket.number
    { t empty$ not }
    { t #1 #1 substring$ "-" =
        { "1" 's := }
        { "1" s =
            'bracket.number 
            'skip$
          if$
          "0" 's :=
        }
     if$
     t #1 #1 substring$ *
     t #2 global.max$ substring$ 't :=
    }
  while$
}

%</vnum-pg>
%    \end{macrocode}
% \end{macro}
%    \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}
%
% \begin{macro}{`word.in'}
% \changes{2.0}{1994 Jan 31}{Function \texttt{word.in} constructed out of 
%        \texttt{bbl.in} or \texttt{bbl.iin}.}
% \changes{3.0}{1995 Feb 16}{Use only \texttt{bbl.in} and capitalize it
%         as necessary; remove \texttt{bbl.iin}}
% \changes{3.81}{1996 Jun 19}{Add option \texttt{in-x} to suppress `in'}
% The function \texttt{word.in} prints the word \textsl{in} for references 
% that are
% contained in a larger work, or in conference proceedings. One may have a
% colon after the word with the option \texttt{in-col}. If blocks of text are
% to be separated with commas (option \texttt{blk-com}) then the word remains
% in lower case, as it is defined in \texttt{bbl.in}; but if blocks act as
% sentences, then it must be capitalized.^^A by using \texttt{bbl.iin}.
%    \begin{macrocode}
FUNCTION {word.in}
%<in-x>{ "" }
%<*!in-x>
%<blk-com|blk-tita>{ bbl.in
%<!blk-com&!blk-tita>{ bbl.in capitalize 
%<in-col>  ":" *
  " " * }
%</!in-x>

%    \end{macrocode}
% \end{macro}
% \begin{macro}{`format.date'}
% \changes{1.4(2.2)}{1994 Sep 6}{Add option \texttt{yr-per} to put period 
%    before date}
% \changes{1.5(2.3)}{1994 Sep 16}{Add \texttt{harvard} bracket names to year
%    with new option \texttt{harnm}}
% \changes{1.6(2.4)}{1995 Feb 2}{Add \texttt{yr-blk} for no punctuation before
%    the date}
% \changes{3.2}{1995 May 19}{Add \texttt{dtrev} option for year month}
% \changes{3.2}{1995 May 19}{Add \texttt{mth-bare} for dotless abbreviation
%    of months}
% \changes{3.4}{1995 Sep 28}{Add \texttt{volp-dt} for date after volume}
% \changes{3.5}{1995 Oct 9}{Add brace pair after 
%      \texttt{\char`\\harvardyearright}}
% \changes{3.5}{1995 Oct 16}{Add \texttt{aymth} option for months in dates}
% \changes{3.8}{1996 Mar 19}{Add \texttt{vnum-dt} option}
% \changes{3.81}{1996 Sep 12}{Add \texttt{yr-com} option}
% \changes{3.82}{1996 Dec 12}{Fix bug that left off extra label for plain year}
% The new \texttt{harvard.sty} allows variable brackets around the date
% in the reference list. It uses |\harvardyearleft| and |\harvardyearright|
% in the \texttt{.bst} files. Allow this with the option \texttt{harnm},
% which could actually be used without the \texttt{har} option. Note that
% this overrides the other year formatting options.
%    \begin{macrocode}
%<*ay>
FUNCTION {format.date}
{ year duplicate$ empty$
    { "empty year in " cite$ * "; set to ????" * warning$ 
       pop$ "????" }
    'skip$
  if$
%<*aymth>
  month empty$
    'skip$
    { month
%<dtrev>      swap$
      " " * swap$ *
    }
  if$
%<mth-bare>  purify$
%</aymth>
%<dtbf>  bolden
  extra.label *
%<*!harnm>
%<*yr-par|yr-brk|yr-col|yr-blk|yr-com|yr-per>
%<!volp-dt&!vnum-dt>  before.all 'output.state := 
%<yr-par>  " (" swap$ * ")" *
%<!yr-par&yr-brk>  " [" swap$ * "]" *
%<!yr-par&!yr-brk&yr-col>  ": " swap$ * 
%<!yr-par&!yr-brk&!yr-col&yr-com>  ", " swap$ * 
%<!yr-par&!yr-brk&!yr-col&!yr-com&yr-per>  after.sentence 'output.state :=
%<!yr-par&!yr-brk&!yr-col&!yr-com&!yr-per&yr-blk>  " " swap$ *
%</yr-par|yr-brk|yr-col|yr-blk|yr-com|yr-per>
%</!harnm>
%<harnm>  " \harvardyearleft " swap$ * "\harvardyearright{}" *
}

%</ay>
%<*!ay>
FUNCTION {format.date}
{ year empty$
    { month empty$
        { "" }
        { "there's a month but no year in " cite$ * warning$
          month
        }
      if$
    }
    { month empty$
        'year
%<!dtrev>        { month " " * year * }
%<dtrev>        { year " " * month * }
      if$
%<mth-bare>      purify$
    }
  if$
%<dtbf>  bolden
%<*yr-par|yr-brk|yr-col|yr-com|yr-per|yr-blk>
  duplicate$ empty$
    'skip$
    {
%<!volp-dt&!vnum-dt>    before.all 'output.state := 
%<yr-par>    " (" swap$ * ")" *
%<!yr-par&yr-brk>    " [" swap$ * "]" *
%<!yr-par&!yr-brk&yr-col>    ": " swap$ *
%<!yr-par&!yr-brk&!yr-col&yr-com>    ", " swap$ *
%<!yr-par&!yr-brk&!yr-col&!yr-com&yr-per>    after.sentence 'output.state :=
%<!yr-par&!yr-brk&!yr-col&!yr-com&!yr-per&yr-blk>    " " swap$ *
    }
  if$
%</yr-par|yr-brk|yr-col|yr-com|yr-per|yr-blk>
}

%</!ay>
%    \end{macrocode}
% \end{macro}
%    \begin{macrocode}
FUNCTION {format.btitle}
%<!btit-rm>{ title emphasize
%<btit-rm>{ title 
}

FUNCTION {tie.or.space.connect}
{ duplicate$ text.length$ #3 <
    { "~" }
    { " " }
  if$
  swap$ * *
}

FUNCTION {either.or.check}
{ empty$
    'pop$
    { "can't use both " swap$ * " fields in " * cite$ * warning$ }
  if$
}

FUNCTION {format.bvolume}
{ volume empty$
    { "" }
    { bbl.volume volume tie.or.space.connect
      series empty$
        'skip$
        { bbl.of space.word * series emphasize * }
      if$
      "volume and number" number either.or.check
    }
  if$
}

FUNCTION {format.number.series}
{ volume empty$
    { number empty$
        { series field.or.null }
        { output.state mid.sentence =
            { bbl.number }
            { bbl.number capitalize }
          if$
          number tie.or.space.connect
          series empty$
            { "there's a number but no series in " cite$ * warning$ }
            { bbl.in space.word * series * }
          if$
        }
      if$
    }
    { "" }
  if$
}

%    \end{macrocode}
%
% \begin{macro}{`is.num'}
% \changes{2.0}{1994 Jan 31}{Add function to test for digit.}
% This function takes the single-character string on the stack and returns
% 1 if it is a digit, else 0.
%    \begin{macrocode}
FUNCTION {is.num}
{ chr.to.int$ 
  duplicate$ "0" chr.to.int$ < not 
  swap$ "9" chr.to.int$ > not and
}
    
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{`extract.num'}
% \changes{2.0}{1994 Jan 31}{Add function to extract leading number from
%        a literal string.}
% This function tests the string on the stack to see if it begins with a
% number. If so, that number is left on the stack; if the string contains
% no numbers at the start, it is left unchanged. The idea is to convert
% \textsl{1st} to \textsl{1} and leave \textsl{first} as is. 
% This is used by {\tt convert.edition}.
%    \begin{macrocode}
FUNCTION {extract.num}
{ duplicate$ 't :=
  "" 's :=
  { t empty$ not }
  { t #1 #1 substring$
    t #2 global.max$ substring$ 't :=
    duplicate$ is.num
      { s swap$ * 's := }
      { pop$ "" 't := }
    if$
  }
  while$
  s empty$
    'skip$ 
    { pop$ s }
  if$
}

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{`convert.edition'}
% \changes{2.0}{1994 Jan 31}{Add function to convert \texttt{edition} entry
%      text from word to a function}
% The function \texttt{convert.edition} takes the text in the field 
% \texttt{edition} and changes it to the language-specific equivalent. As
% originally planned for \btx, this field should contain the words
% \textsl{First}, \textsl{Second}, etc. Being so explicit, 
% it is not so easy to translate, nor to
% convert to \textsl{1st}, \textsl{2nd}, etc., if one wanted. 
% This function carries out the translation, by changing 
% \textsl{first} or \textsl{1} to \texttt{bbl.first}, and so
% on. The field is reduced to lower case to make it case insensitive. If no
% translation is found, then the original text in \texttt{edition} is used
% instead, as it stands. However, if the original is a number greater than
% the maximum for which text is provided, then \texttt{bbl.th} is added to
% it.
%    \begin{macrocode}
FUNCTION {convert.edition}
{ edition extract.num "l" change.case$ 's :=
  s "first" = s "1" = or
    { bbl.first 't := }
    { s "second" = s "2" = or
        { bbl.second 't := }
        { s "third" = s "3" = or
            { bbl.third 't := }
            { s "fourth" = s "4" = or
                { bbl.fourth 't := }
                { s "fifth" = s "5" = or
                    { bbl.fifth 't := }
                    { s #1 #1 substring$ is.num
%<!english&exlang>                        { s bbl.th * 't := }
%<english|!exlang>                        { s eng.ord 't := }
                        { edition 't := }
                      if$
                    }
                  if$
                }
              if$
            }
          if$
        }
      if$
    }
  if$
  t
}

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{`format.edition'}
% \changes{2.0}{1994 Jan 31}{Add call to \texttt{convert.edition}}
% This function formats the text for the edition specification, such as
% ``Second edition''. It combines the edition number with the word
% \textsl{edition}. 
%    \begin{macrocode}
FUNCTION {format.edition}
{ edition empty$
    { "" }
    { output.state mid.sentence =
        { convert.edition "l" change.case$ " " * bbl.edition * }
        { convert.edition "t" change.case$ " " * bbl.edition * }
      if$
    }
  if$
}

%    \end{macrocode}
% \end{macro}
%    \begin{macrocode}
INTEGERS { multiresult }

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{macro}{`format.pages'}
% \changes{3.6}{1995 Nov 24}{Add option \texttt{bkpg-par}}
%    \begin{macrocode}
FUNCTION {format.pages}
{ pages empty$
    { "" }
    { pages multi.page.check
%<*!bkpg-par>
        { bbl.pages pages n.dashify tie.or.space.connect }
        { bbl.page pages tie.or.space.connect }
%</!bkpg-par>
%<*bkpg-par>
        { "(" bbl.pages pages n.dashify tie.or.space.connect ")" * * }
        { "(" bbl.page pages tie.or.space.connect ")" * * }
%</bkpg-par>
      if$
    }
  if$
}

%    \end{macrocode}
% \end{macro}
%    \begin{macrocode}
%<*jpg-1>
FUNCTION {first.page}
{ 't :=
  ""
    {  t empty$ not t #1 #1 substring$ "-" = not and }
    { t #1 #1 substring$ *
      t #2 global.max$ substring$ 't :=
    }
  while$
}

%</jpg-1>
%    \end{macrocode}
%
% \begin{macro}{`format.journal.pages'}
% \changes{3.82}{1996 Nov 15}{Remove from \texttt{format.vol.num.pages} to
%        be a separate function}
%    \begin{macrocode}
FUNCTION {format.journal.pages}
{
  pages empty$
    'skip$
    { duplicate$ empty$
        { pop$ format.pages }
%<*!jpg-1>
%<volp-dt&!vnum-pg&!jwdpg>        { " " * pages n.dashify * }
%<volp-dt&vnum-pg>        { " " * pages num.pages n.dashify * }
%<volp-dt&!vnum-pg&jwdpg>        { " " * bbl.pages "~" * * pages n.dashify * }
%<*!volp-dt>
%<volp-sp&!vnum-pg&!jwdpg>        { ": " * pages n.dashify * }
%<volp-sp&vnum-pg>        { ": " * pages num.pages n.dashify * }
%<volp-sp&!vnum-pg&jwdpg>        { ": " * bbl.pages "~" * * pages n.dashify * }
%<*!volp-sp>
%<volp-blk&!vnum-pg&!jwdpg>        { " " * pages n.dashify * }
%<volp-blk&vnum-pg>        { " " * pages num.pages n.dashify * }
%<volp-blk&!vnum-pg&jwdpg>        { " " * bbl.pages "~" * * pages n.dashify * }
%<*!volp-blk>
%<volp-com&!vnum-pg&!jwdpg>        { ", " * pages n.dashify * }
%<volp-com&vnum-pg>        { ", " * pages num.pages n.dashify * }
%<volp-com&!vnum-pg&jwdpg>        { ", " * bbl.pages "~" * * pages n.dashify * }
%<*!volp-com>
%<volp-semi&!vnum-pg&!jwdpg>        { "; " * pages n.dashify * }
%<volp-semi&vnum-pg>        { "; " * pages num.pages n.dashify * }
%<volp-semi&!vnum-pg&jwdpg>        { "; " * bbl.pages "~" * * pages n.dashify * }
%<*!volp-semi>
%<!vnum-pg&!jwdpg>        { ":" * pages n.dashify * }
%<vnum-pg>        { ":" * pages num.pages n.dashify * }
%<!vnum-pg&jwdpg>        { ":" * bbl.pages "~" * * pages n.dashify * }
%</!volp-semi>
%</!volp-com>
%</!volp-blk>
%</!volp-sp>
%</!volp-dt>
%</!jpg-1>
%<*jpg-1>
%<volp-dt&!vnum-pg&!jwdpg>        { " " * pages first.page * }
%<volp-dt&vnum-pg>        { " " * pages first.page num.pages * }
%<volp-dt&!vnum-pg&jwdpg>        { " " * bbl.page "~" * * pages first.page * }
%<*!volp-dt>
%<volp-sp&!vnum-pg&!jwdpg>        { ": " * pages first.page * }
%<volp-sp&vnum-pg>        { ": " * pages first.page num.pages * }
%<volp-sp&!vnum-pg&jwdpg>        { ": " * bbl.page "~" * * pages first.page * }
%<*!volp-sp>
%<volp-blk&!vnum-pg&!jwdpg>        { " " * pages first.page * }
%<volp-blk&vnum-pg>        { " " * pages first.page num.pages * }
%<volp-blk&!vnum-pg&jwdpg>        { " " * bbl.page "~" * * pages first.page * }
%<*!volp-blk>
%<volp-com&!vnum-pg&!jwdpg>        { ", " * pages first.page * }
%<volp-com&vnum-pg>        { ", " * pages first.page num.pages * }
%<volp-com&!vnum-pg&jwdpg>        { ", " * bbl.page "~" * * pages first.page * }
%<*!volp-com>
%<volp-semi&!vnum-pg&!jwdpg>        { "; " * pages first.page * }
%<volp-semi&vnum-pg>        { "; " * pages first.page num.pages * }
%<volp-semi&!vnum-pg&jwdpg>        { "; " * bbl.page "~" * * pages first.page * }
%<*!volp-semi>
%<!vnum-pg&!jwdpg>        { ":" * pages first.page * }
%<vnum-pg>        { ":" * pages first.page num.pages * }
%<!vnum-pg&jwdpg>        { ":" * bbl.page "~" * * pages first.page * }
%</!volp-semi>
%</!volp-com>
%</!volp-blk>
%</!volp-sp>
%</!volp-dt>
%</jpg-1>
      if$
    }
  if$
}

%    \end{macrocode}
% \end{macro}
% \begin{macro}{`format.vol.num.pages'}
% \changes{1.4(2.2)}{1994 Sep 6}{Add option \texttt{volp-sp} to put space
%    after colon in vol:~page.}
% \changes{1.5(2.3)c}{1995 Jan 20}{Add options \texttt{vnum-h}, 
%   \texttt{vnum-nr} and \texttt{vnum-x} for various formats of 
%   journal vol number}
% \changes{1.7(2.5)}{1995 Feb 9}{Add options \texttt{vnum-sp} and 
%     \texttt{vnum-cm}}
% \changes{3.0}{1995 Mar 17}{Add option \texttt{volp-semi}}
% \changes{3.4}{1995 Sep 28}{Put \texttt{bolden} in right place for
%    \texttt{vol-2bf} option}
% \changes{3.8}{1996 Mar 19}{Put date between volume and number}
% \changes{3.8}{1996 Mar 19}{Add possibilitity of `page' word}
% \changes{3.81}{1996 Jun 19}{Activate \texttt{jwdpg} option properly}
% \changes{3.81}{1996 Jun 19}{Add possibilitity of `volume' word}
% \changes{3.82}{1996 Nov 15}{Add option \texttt{pp-last}}
% The option \texttt{vnum-dt} is most unpleasing. There should be more choice
% about how the number is formatted. It should be a separate option from
% the \texttt{vnum-} series, but it was a special wish. Option \texttt{jwdpg}
% is also part of this special wish. (Was not properly programmed until 3.81).
%
% The option \texttt{pp-last} is similar to \texttt{vnum-dt}, and might
% actually be able to replace it if used correctly with other options. But
% that is speculation on my part. What it does is to suppress the pages 
% in the formatting macros, and sees to it that the pages are added just
% before any notes in those entries that take pages. This applies to more than
% just \texttt{article}, but to \texttt{inbook}, \texttt{incollection} as well.
%    \begin{macrocode}
FUNCTION {format.vol.num.pages}
{ volume field.or.null
%<*jwdvol>
  volume empty$
    'skip$
    { bbl.volume "~" * swap$ * }
  if$
%</jwdvol>
%<vol-bf&!vol-2bf>  bolden
%<!vol-bf&!vol-2bf&vol-it>  emphasize
%<vnum-dt>  format.date * 
%<*!vnum-x&!vnum-pg>
  number empty$
    'skip$
    { 
%<vnum-sp>      "~(" number * ")" * *
%<!vnum-sp&vnum-cm>      ", " number * *
%<!vnum-sp&!vnum-cm&vnum-nr>      ", " bbl.nr * number tie.or.space.connect *
%<!vnum-sp&!vnum-cm&!vnum-nr&vnum-h>      ", \#" number * *
%<!vnum-sp&!vnum-cm&!vnum-nr&!vnum-h&vnum-dt>      " " number * *
%<!vnum-sp&!vnum-cm&!vnum-nr&!vnum-h&!vnum-dt>      "(" number * ")" * *
      volume empty$
        { "there's a number but no volume in " cite$ * warning$ }
        'skip$
      if$
    }
  if$
%</!vnum-x&!vnum-pg>
%<!vol-bf&vol-2bf>  bolden
%<volp-dt>  format.date * 
%<!pp-last>  format.journal.pages
}

%    \end{macrocode}
% \end{macro}
%    \begin{macrocode}
FUNCTION {format.chapter.pages}
{ chapter empty$
%<!pp-last>    'format.pages
%<pp-last>    { "" }
    { type empty$
        { bbl.chapter }
        { type "l" change.case$ }
      if$
      chapter tie.or.space.connect
%<*!pp-last>
      pages empty$
        'skip$
        { ", " * format.pages * }
      if$
%</!pp-last>
    }
  if$
}

%    \end{macrocode}
% \begin{macro}{`format.in.ed.booktitle'}
% \changes{1.5(2.3)b}{1995 Jan 18}{Add option \texttt{edby-par} to put editors
%   in parentheses}
% \changes{1.6(2.4)}{1995 Feb 2}{If \texttt{ed} and \texttt{edby} given 
%   together, abbreviate `edited by' to `ed(s).'}
% \changes{3.1}{1995 May 2}{Add option \texttt{edbyx} to replace `edited by'
%    by `ed(s).'}
% \changes{3.81}{1996 Jun 26}{Add option \texttt{edcap}}
% Prior to version 3.81, the \textsl{Editor} or \textsl{Edited by} in
% parentheses was meant to be capitalized, but this did not work properly.
% Now the option \texttt{edcap} produces this, and default is not capitalized.
%    \begin{macrocode}
FUNCTION {format.in.ed.booktitle}
{ booktitle empty$
    { "" }
    { editor empty$
        { word.in booktitle emphasize * }
%<!edby&!edby-par>        { word.in format.in.editors * ", " * 
%<!edby&!edby-par>          booktitle emphasize * }
%<*edby|edby-par>
        { word.in booktitle emphasize * 
%<edby>          ", " * 
%<edby-par>          " (" * 
%<!edbyx&!edbyy>          bbl.edby 
%<*edbyx>
          editor num.names$ #1 >
            { bbl.editors }
            { bbl.editor }
          if$
%</edbyx>
%<edby-par&edcap>          capitalize 
%<edbyx|!edbyy>          *
          " " *
          format.in.editors * 
%<*edbyy>
          ", " *
          editor num.names$ #1 >
            { bbl.editors }
            { bbl.editor }
          if$
          *
%</edbyy>
%<edby-par>          ")" *
        }
%</edby|edby-par>
      if$
    }
  if$
}

%    \end{macrocode}
% \end{macro}
%    \begin{macrocode}
%<*!ay>
FUNCTION {empty.misc.check}
{ author empty$ title empty$ howpublished empty$
  month empty$ year empty$ note empty$
  and and and and and
%<!seq-no|alph>  key empty$ not and
    { "all relevant fields are empty in " cite$ * warning$ }
    'skip$
  if$
}

%</!ay>
FUNCTION {format.thesis.type}
{ type empty$
    'skip$
    { pop$
      type "t" change.case$
    }
  if$
}

FUNCTION {format.tr.number}
{ type empty$
    { bbl.techrep }
    'type
  if$
  number empty$
    { "t" change.case$ }
    { number tie.or.space.connect }
  if$
}

%    \end{macrocode}
%
% \begin{macro}{`format.article.crossref'}
%\changes{1.3(2.1)}{1994 Jul 1}{Emphasize \texttt{journal} with 
%   \texttt{emphasize}, not explicitly}
% The \texttt{journal} field was emphasized emplicitly, but it should be
% done by command.
%    \begin{macrocode}
FUNCTION {format.article.crossref}
{ 
%<*!ay>
  key empty$
    { journal empty$
        { "need key or journal for " cite$ * " to crossref " * crossref *
          warning$
          ""
        }
        { word.in journal emphasize * } 
      if$
    }
    { word.in key * " " *}
  if$
%</!ay>
%<ay>  word.in
  " \cite{" * crossref * "}" *
}

%    \end{macrocode}
% \end{macro}
%    \begin{macrocode}
%<*!ay>
FUNCTION {format.crossref.editor}
{ editor #1 "{vv~}{ll}" format.name$
  editor num.names$ duplicate$
  #2 >
%<!etal-it&!etal-rm>    { pop$ " et~al." * }
%<!etal-it&etal-rm>    { pop$ " " * "et~al." roman.list * }
%<etal-it>    { pop$ " " * "et~al." emphasize * }
    { #2 <
        'skip$
        { editor #2 "{ff }{vv }{ll}{ jj}" format.name$ "others" =
%<!etal-it&!etal-rm>            { " et~al." * }
%<!etal-it&etal-rm>            { " " * "et~al." roman.list * }
%<etal-it>            { " " * "et~al." emphasize * }
%<*!harnm>
%<!amper>            { bbl.and space.word * editor #2 "{vv~}{ll}" format.name$ * }
%<amper>            { " \& " * editor #2 "{vv~}{ll}" format.name$ * }
%</!harnm>
%<harnm>            { " \harvardand\ " * editor #2 "{vv~}{ll}" format.name$ * }
          if$
        }
      if$
    }
  if$
}

%</!ay>
%    \end{macrocode}
%
% \begin{macro}{`format.book.crossref'}
%\changes{1.3(2.1)}{1994 Jul 1}{Emphasize \texttt{series} with 
%   \texttt{emphasize}, not explicitly}
% The \texttt{series} field was emphasized emplicitly, but it should be
% done by command.
%    \begin{macrocode}
FUNCTION {format.book.crossref}
{ volume empty$
    { "empty volume in " cite$ * "'s crossref of " * crossref * warning$
      word.in
    }
%<(blk-com|blk-tita)>    { bbl.volume volume tie.or.space.connect
%<!(blk-com|blk-tita)>    { bbl.volume capitalize
%<!(blk-com|blk-tita)>      volume tie.or.space.connect
      bbl.of space.word * 
    }
  if$
%<*!ay>
  editor empty$
  editor field.or.null author field.or.null =
  or
    { key empty$
        { series empty$
            { "need editor, key, or series for " cite$ * " to crossref " *
              crossref * warning$
              "" *
            }
            { series emphasize * }
          if$
        }
        { key * }
      if$
    }
    { format.crossref.editor * }
  if$
%</!ay>
  " \cite{" * crossref * "}" *
}

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{`format.incoll.inproc.crossref'}
%\changes{1.3(2.1)}{1994 Jul 1}{Emphasize \texttt{booktitle} with 
%     \texttt{emphasize},  not explicitly}
% The \texttt{booktitle} field was emphasized emplicitly, but it should be
% done by command.
%    \begin{macrocode}
FUNCTION {format.incoll.inproc.crossref}
{ 
%<*!ay>
  editor empty$
  editor field.or.null author field.or.null =
  or
    { key empty$
        { booktitle empty$
            { "need editor, key, or booktitle for " cite$ * " to crossref " *
              crossref * warning$
              ""
            }
            { word.in booktitle emphasize * }
          if$
        }
        { word.in key * " " *}
      if$
    }
    { word.in format.crossref.editor * " " *}
  if$
%</!ay>
%<ay>  word.in
  " \cite{" * crossref * "}" *
}

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{`format.publisher'}
% \changes{3.3}{1995 Aug 7}{Add option \texttt{add-pub} which makes use
%    of this function}
% \changes{3.8}{1996 Mar 12}{Add option \texttt{pub-par} to put publisher
%    in parentheses}
% \changes{3.81}{1996 Sep 16}{Add option \texttt{pub-date} to put publisher
%    and date in parentheses together}
% \changes{3.82}{1996 Dec 16}{Add \texttt{add.blank} for \texttt{pub-par}}
% Psychology journals often want \textit{address}: \textit{publisher}.
%
% \textsl{Nature} wants publisher and date in parentheses, and when both
% are there, they are merged into one set.
% Call function \texttt{add.blank} before parentheses so suppress preceding
% punctuation, which looks strange when publisher in parentheses.
%    \begin{macrocode}
FUNCTION {format.publisher}
{ publisher empty$
    { "empty publisher in " cite$ * warning$ }
    'skip$
  if$
  ""
%<*pub-date&!ay>
  year empty$
    { "empty year in " cite$ * warning$ }
    'skip$
  if$
%</pub-date&!ay>
%<*!(pub-date&ay)>
  address empty$ publisher empty$ and
%<pub-date>  year empty$ and
    'skip$
    {
%</!(pub-date&ay)>
%<pub-par|pub-date>      add.blank "(" *
%<*add-pub>
      address empty$
        'skip$
        { address * }
      if$
      publisher empty$
        'skip$
%</add-pub>
%<*!add-pub>
      publisher empty$
        { address empty$
          'skip$
          { address * }
          if$
        }
        { publisher *
          address empty$
            'skip$
            { ", " * address * }
          if$
        }
%</!add-pub>
%<*add-pub>
        { address empty$
            'skip$
            { ": " * }
          if$
          publisher *
        }
%</add-pub>
      if$
%<*pub-date&!ay>
      year empty$
        'skip$
        { publisher empty$ address empty$ and
            'skip$
            { ", " * }
          if$
          year *
        }
      if$
%</pub-date&!ay>
%<*pub-date&ay>
      year duplicate$ empty$
        { "empty year in " cite$ * "; set to ????" * warning$ 
          pop$ "????" }
        'skip$
      if$
      publisher empty$ address empty$ and
        { * }
        { ", " swap$ * * }
      if$
%</pub-date&ay>
%<pub-par|pub-date>      ")" *
%<*!(pub-date&ay)>
    }
  if$
%</!(pub-date&ay)>
  output
}

%    \end{macrocode}
% \end{macro}
% \changes{1.5(2.3)b}{1995 Jan 18}{Add option \texttt{yrp-x} to suppress 
%    punctuation following date at beginning}
% \changes{3.0}{1995 Mar 8}{Add option \texttt{yrp-col} to add colon after
%    date at beginning}
% \changes{3.0}{1995 Mar 20}{Add option \texttt{jxper} to remove periods
%    from journal name}
% \changes{3.2}{1995 May 19}{Add option \texttt{dt-jnl} to make date part of
%    the journal specification, follows journal name.}
% \changes{3.4}{1995 Sep 28}{Add option \texttt{au-col}}
% \changes{3.6}{1995 Nov 23}{Add option \texttt{jttl-rm}}
% \changes{3.7}{1996 Feb 5}{Put \texttt{purify\$} before \texttt{emphasize}}
% \changes{3.81}{1996 Jun 26}{Add option \texttt{blk-tita} for article only}
%    \begin{macrocode}
FUNCTION {article}
{ output.bibitem
  format.authors "author" output.check
%<ay>  author format.key output
%<au-col>  author add.colon
%<dt-beg>  format.date "year" output.check
%<dt-beg>  date.block
%<!dt-beg&!blk-com&!blk-tit&!blk-tita>  new.block
%<*!jtit-x>
  format.title "title" output.check
%<blk-com&(tit-q|tit-qq)>  end.quote.title
%<!blk-com&!blk-tit&!blk-tita>  new.block
%<blk-tit|blk-tita>  new.sentence
%</!jtit-x>
  crossref missing$
    { journal 
%<jxper>      purify$
%<!jttl-rm>      emphasize 
      "journal" output.check
%<jnm-x>      add.blank
%<*!dt-beg&!dt-end&dt-jnl&!volp-dt&!vnum-dt>
      format.date "year" output.check
      date.block
%</!dt-beg&!dt-end&dt-jnl&!volp-dt&!vnum-dt>
      format.vol.num.pages output
%<!dt-beg&!dt-end&!dt-jnl&!volp-dt&!vnum-dt>      format.date "year" output.check
    }
    { format.article.crossref output.nonnull
      format.pages output
    }
  if$
%<pp-last>  format.journal.pages
%<!blk-com&!blk-tit&!blk-tita>  new.block
  note output
%<*!dt-beg&dt-end>
%<!blk-com&!blk-tit&!blk-tita>  new.block 
  format.date "year" output.check
%</!dt-beg&dt-end>
  fin.entry
%<harnm>  write.url
}

%    \end{macrocode}
%\changes{2.0a}{1994 Aug 30}{Fix up \texttt{new.sentence} so not added with
%        \texttt{blk-com}}
%    \begin{macrocode}
FUNCTION {book}
{ output.bibitem
  author empty$
    { format.editors "author and editor" output.check
%<ay>      editor format.key output
%<au-col>      editor add.colon
    }
    { format.authors output.nonnull
%<au-col>      author add.colon
      crossref missing$
        { "author and editor" editor either.or.check }
        'skip$
      if$
    }
  if$
%<dt-beg&!pub-date>  format.date "year" output.check
%<dt-beg&!pub-date>  date.block
%<!dt-beg&!blk-com&!blk-tit&!blk-tita>  new.block
  format.btitle "title" output.check
  crossref missing$
    { format.bvolume output
%<!blk-com&!blk-tit&!blk-tita>      new.block
%<blk-tit>  new.sentence
      format.number.series output
%<pre-edn>      format.edition output
%<!blk-com&!blk-tit&!blk-tita>      new.sentence
      format.publisher
    }
    {
%<!blk-com&!blk-tit&!blk-tita>      new.block
%<blk-tit>  new.sentence
      format.book.crossref output.nonnull
%<!dt-beg&!dt-end&pub-date>      format.date "year" output.check
    }
  if$
%<!pre-edn>  format.edition output
%<!dt-beg&!dt-end&!pub-date>  format.date "year" output.check
%<isbn>  format.isbn output
%<!blk-com&!blk-tit&!blk-tita>  new.block
  note output
%<*!dt-beg&dt-end&!pub-date>
%<!blk-com&!blk-tit&!blk-tita>  new.block 
  format.date "year" output.check
%</!dt-beg&dt-end&!pub-date>
  fin.entry
%<harnm>  write.url
}

FUNCTION {booklet}
{ output.bibitem
  format.authors output
%<ay>  author format.key output
%<au-col>  author add.colon
%<ay&dt-beg>  format.date "year" output.check
%<!ay&dt-beg>  format.date output
%<dt-beg>  date.block
%<!dt-beg&!blk-com&!blk-tit&!blk-tita>  new.block
  format.title "title" output.check
%<blk-com&(tit-q|tit-qq)>  end.quote.title
%<!blk-com&!blk-tit&!blk-tita>  new.block
%<blk-tit>  new.sentence
  howpublished output
  address output
%<ay&!dt-beg&!dt-end>  format.date "year" output.check
%<!ay&!dt-beg&!dt-end>  format.date output
%<!blk-com&!blk-tit&!blk-tita>  new.block
  note output
%<*ay&!dt-beg&dt-end>
%<!blk-com&!blk-tit&!blk-tita>  new.block 
  format.date "year" output.check
%</ay&!dt-beg&dt-end>
%<*!ay&!dt-beg&dt-end>
%<isbn>  format.isbn output
%<!blk-com&!blk-tit&!blk-tita>  new.block 
  format.date output
%</!ay&!dt-beg&dt-end>
  fin.entry
%<harnm>  write.url
}

%    \end{macrocode}
% The medical journals, with option \texttt{dt-jnl}, have the date as part of
% the journal specification. For chapters in books, they want date and pages
% to appear at the end, with a space between them. (For journals, there is to be
% no space.) Suppress the chapter specification (for now).
% 
% The \texttt{dt-jnl} option usually behaves as the default, except for some
% special entries, like this one.
%    \begin{macrocode}
FUNCTION {inbook}
{ output.bibitem
  author empty$
    { format.editors "author and editor" output.check
%<ay>      editor format.key output
%<au-col>      editor add.colon
    }
    { format.authors output.nonnull
%<au-col>      author add.colon
      crossref missing$
        { "author and editor" editor either.or.check }
        'skip$
      if$
    }
  if$
%<dt-beg&!pub-date>  format.date "year" output.check
%<dt-beg&!pub-date>  date.block
%<!dt-beg&!blk-com&!blk-tit&!blk-tita>  new.block
  format.btitle "title" output.check
  crossref missing$
    { 
%<pre-pub>      format.publisher 
      format.bvolume output
%<*dt-beg|dt-end|!dt-jnl>
      format.chapter.pages "chapter and pages" output.check
%</dt-beg|dt-end|!dt-jnl>
%<!blk-com&!blk-tit&!blk-tita>      new.block
%<blk-tit>  new.sentence
      format.number.series output
%<pre-edn>      format.edition output
%<!blk-com&!blk-tit&!blk-tita>      new.sentence
%<!pre-pub>      format.publisher
    }
    { 
%<*dt-beg|dt-end|!dt-jnl>
      format.chapter.pages "chapter and pages" output.check
%</dt-beg|dt-end|!dt-jnl>
%<!blk-com&!blk-tit&!blk-tita>      new.block
%<blk-tit>  new.sentence
      format.book.crossref output.nonnull
%<!dt-beg&!dt-end&!dt-jnl&pub-date>      format.date "year" output.check
    }
  if$
%<!pre-edn>  format.edition output
%<!dt-beg&!dt-end&!dt-jnl&!pub-date>  format.date "year" output.check
%<isbn>  format.isbn output
%<*!dt-beg&!dt-end&dt-jnl>
%<!pub-date>  year "year" output.check
%<!pub-date>  date.block
  add.blank
  format.pages "pages" output.check
%</!dt-beg&!dt-end&dt-jnl>
%<pp-last>  format.pages "pages" output.check
%<!blk-com&!blk-tit&!blk-tita>  new.block
  note output
%<*!dt-beg&dt-end&!pub-date>
%<!blk-com&!blk-tit&!blk-tita>  new.block 
  format.date "year" output.check
%</!dt-beg&dt-end&!pub-date>
  fin.entry
%<harnm>  write.url
}

FUNCTION {incollection}
{ output.bibitem
  format.authors "author" output.check
%<ay>  author format.key output
%<au-col>  author add.colon
%<dt-beg&!pub-date>  format.date "year" output.check
%<dt-beg&!pub-date>  date.block
%<!dt-beg&!blk-com&!blk-tit&!blk-tita>  new.block
%<*!jtit-x>
  format.title "title" output.check
%<blk-com&(tit-q|tit-qq)>  end.quote.title
%<!blk-com&!blk-tit&!blk-tita>  new.block
%<blk-tit>  new.sentence
%</!jtit-x>
  crossref missing$
    { format.in.ed.booktitle "booktitle" output.check
%<pre-pub>      format.publisher
      format.bvolume output
      format.number.series output
%<pre-edn>      format.edition output
%<dt-beg|dt-end|!dt-jnl>      format.chapter.pages output
%<!blk-com&!blk-tit&!blk-tita>      new.sentence
%<!pre-pub>      format.publisher 
%<!pre-edn>      format.edition output
%<!dt-beg&!dt-end&!dt-jnl&!pub-date>      format.date "year" output.check
    }
    { format.incoll.inproc.crossref output.nonnull
%<dt-beg|dt-end|!dt-jnl>      format.chapter.pages output
    }
  if$
%<isbn>  format.isbn output
%<*!dt-beg&!dt-end&dt-jnl>
%<!pub-date>  year "year" output.check
%<!pub-date>  date.block
  add.blank
  format.pages "pages" output.check
%</!dt-beg&!dt-end&dt-jnl>
%<pp-last>  format.pages "pages" output.check
%<!blk-com&!blk-tit&!blk-tita>  new.block
  note output
%<*!dt-beg&dt-end&!pub-date>
%<!blk-com&!blk-tit&!blk-tita>  new.block 
  format.date "year" output.check
%</!dt-beg&dt-end&!pub-date>
  fin.entry
%<harnm>  write.url
}

%    \end{macrocode}
%
% \begin{macro}{`inproceedings'}
% \changes{3.81}{1996 Sep 13}{Reorganize organization/publisher}
%    \begin{macrocode}
FUNCTION {inproceedings}
{ output.bibitem
  format.authors "author" output.check
%<ay>  author format.key output
%<au-col>  author add.colon
%<dt-beg&!pub-date>  format.date "year" output.check
%<dt-beg&!pub-date>  date.block
%<!dt-beg&!blk-com&!blk-tit&!blk-tita>  new.block
%<*!jtit-x>
  format.title "title" output.check
%<blk-com&(tit-q|tit-qq)>  end.quote.title
%<!blk-com&!blk-tit&!blk-tita>  new.block
%<blk-tit>  new.sentence
%</!jtit-x>
  crossref missing$
    { format.in.ed.booktitle "booktitle" output.check
%<*!pre-pub>
      format.bvolume output
      format.number.series output
%<(dt-beg|dt-end|!dt-jnl)&!pp-last>      format.pages output
%</!pre-pub>
%<!blk-com&!blk-tit&!blk-tita>      new.sentence
      publisher empty$
        { organization output 
          address output
%<pub-date>          format.date "year" output.check
        }
        { organization output
          format.publisher
        }
      if$
%<!dt-beg&!dt-end&!dt-jnl&!pub-date>      format.date "year" output.check
%<*pre-pub>
      format.bvolume output
      format.number.series output
%<(dt-beg|dt-end|!dt-jnl)|!pp-last>      format.pages output
%</pre-pub>
    }
    { format.incoll.inproc.crossref output.nonnull
%<dt-beg|dt-end|!dt-jnl>      format.pages output
    }
  if$
%<isbn>  format.isbn output
%<*!dt-beg&!dt-end&dt-jnl>
%<!pub-date>  year "year" output.check
%<!pub-date>  date.block
  add.blank
  format.pages "pages" output.check
%</!dt-beg&!dt-end&dt-jnl>
%<pp-last>  format.pages "pages" output.check
%<!blk-com&!blk-tit&!blk-tita>  new.block
  note output
%<*!dt-beg&dt-end&!pub-date>
%<!blk-com&!blk-tit&!blk-tita>  new.block 
  format.date "year" output.check
%</!dt-beg&dt-end&!pub-date>
  fin.entry
%<harnm>  write.url
}

%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
FUNCTION {conference} { inproceedings }

%<*ay>
FUNCTION {manual}
{ output.bibitem
  format.authors output
  author format.key output
%<au-col>  author add.colon
%<dt-beg>  format.date "year" output.check
%<dt-beg>  date.block
%<!dt-beg&!blk-com&!blk-tit&!blk-tita>  new.block
  format.btitle "title" output.check
%<blk-tit>  new.sentence
%<!blk-com&!blk-tit&!blk-tita>  organization address new.block.checkb
  organization output
  address output
  format.edition output
%<!dt-beg&!dt-end>  format.date "year" output.check
%<!blk-com&!blk-tit&!blk-tita>  new.block
  note output
%<*!dt-beg&dt-end>
%<!blk-com&!blk-tit&!blk-tita>  new.block 
  format.date "year" output.check
%</!dt-beg&dt-end>
  fin.entry
%<harnm>  write.url
}

%</ay>
%<*!ay>
FUNCTION {manual}
{ output.bibitem
  author empty$
    { organization empty$
        'skip$
        { organization output.nonnull
          address output
        }
      if$
    }
    { format.authors output.nonnull }
  if$
%<au-col>  author add.colon
%<ay&dt-beg>  format.date "year" output.check
%<!ay&dt-beg>  format.date output
%<dt-beg>  date.block
%<!dt-beg&!blk-com&!blk-tit&!blk-tita>  new.block
  format.btitle "title" output.check
%<blk-tit>  new.sentence
  author empty$
    { organization empty$
    {
%<!blk-com&!blk-tit&!blk-tita>          address new.block.checka
          address output
        }
        'skip$
      if$
    }
    {
%<!blk-com&!blk-tit&!blk-tita>      organization address new.block.checkb
      organization output
      address output
    }
  if$
  format.edition output
%<ay&!dt-beg&!dt-end>  format.date "year" output.check
%<!ay&!dt-beg&!dt-end>  format.date output
%<!blk-com&!blk-tit&!blk-tita>  new.block
  note output
%<*ay&!dt-beg&dt-end>
%<!blk-com&!blk-tit&!blk-tita>  new.block 
  format.date "year" output.check
%</ay&!dt-beg&dt-end>
%<*!ay&!dt-beg&dt-end>
%<!blk-com&!blk-tit&!blk-tita>  new.block 
  format.date output
%</!ay&!dt-beg&dt-end>
  fin.entry
%<harnm>  write.url
}

%</!ay>
%    \end{macrocode}
% \begin{macro}{`masterthesis'}
% \changes{2.0}{1994 Feb 7}{Add \texttt{thtit-a} to format thesis titles like
%         articles instead of books.}
% To format a master's thesis.
%    \begin{macrocode}
FUNCTION {mastersthesis}
{ output.bibitem
  format.authors "author" output.check
%<ay>  author format.key output
%<au-col>  author add.colon
%<dt-beg>  format.date "year" output.check
%<dt-beg>  date.block
%<!dt-beg&!blk-com&!blk-tit&!blk-tita>  new.block
%<!thtit-a>  format.btitle "title" output.check
%<thtit-a>  format.title "title" output.check
%<thtit-a&blk-com&(tit-q|tit-qq)>  end.quote.title
%<!blk-com&!blk-tit&!blk-tita>  new.block
%<blk-tit>  new.sentence
  bbl.mthesis format.thesis.type output.nonnull
  school "school" output.check
  address output
%<!dt-beg&!dt-end>  format.date "year" output.check
%<!blk-com&!blk-tit&!blk-tita>  new.block
  note output
%<*!dt-beg&dt-end>
%<!blk-com&!blk-tit&!blk-tita>  new.block 
  format.date "year" output.check
%</!dt-beg&dt-end>
  fin.entry
%<harnm>  write.url
}

%    \end{macrocode}
% \end{macro}
%    \begin{macrocode}
FUNCTION {misc}
{ output.bibitem
  format.authors output
%<ay>  author format.key output
%<au-col>  author add.colon
%<ay&dt-beg>  format.date "year" output.check
%<!ay&dt-beg>  format.date output
%<*ay>
%<dt-beg>  date.block
%<!dt-beg&!blk-com&!blk-tit&!blk-tita>  new.block
  format.title output
%<blk-com&(tit-q|tit-qq)>  end.quote.title
%<!blk-com&!blk-tit&!blk-tita>  new.block
%<blk-tit>  new.sentence
%</ay>
%<*!ay>
%<!blk-com&!blk-tit&!blk-tita>  title howpublished new.block.checkb
  format.title output
%<blk-com&(tit-q|tit-qq)>  end.quote.title
%<blk-tit>  new.sentence
%<!blk-com&!blk-tit&!blk-tita>  howpublished new.block.checka
%</!ay>
  howpublished output
%<ay&!dt-beg&!dt-end>  format.date "year" output.check
%<!ay&!dt-beg&!dt-end>  format.date output
%<!blk-com&!blk-tit&!blk-tita>  new.block
  note output
%<*ay&!dt-beg&dt-end>
%<!blk-com&!blk-tit&!blk-tita>  new.block 
  format.date "year" output.check
%</ay&!dt-beg&dt-end>
%<*!ay&!dt-beg&dt-end>
%<!blk-com&!blk-tit&!blk-tita>  new.block 
  format.date output
%</!ay&!dt-beg&dt-end>
  fin.entry
%<harnm>  write.url
%<!ay>  empty.misc.check
}

%    \end{macrocode}
% \begin{macro}{`phdthesis'}
% \changes{2.0}{1994 Feb 7}{Add \texttt{thtit-a} to format thesis titles like
%         articles instead of books.}
% To format a doctoral thesis.
%    \begin{macrocode}
FUNCTION {phdthesis}
{ output.bibitem
  format.authors "author" output.check
%<ay>  author format.key output
%<au-col>  author add.colon
%<dt-beg>  format.date "year" output.check
%<dt-beg>  date.block
%<!dt-beg&!blk-com&!blk-tit&!blk-tita>  new.block
%<!thtit-a>  format.btitle "title" output.check
%<thtit-a>  format.title "title" output.check
%<thtit-a&blk-com&(tit-q|tit-qq)>  end.quote.title
%<!blk-com&!blk-tit&!blk-tita>  new.block
%<blk-tit>  new.sentence
  bbl.phdthesis format.thesis.type output.nonnull
  school "school" output.check
  address output
%<!dt-beg&!dt-end>  format.date "year" output.check
%<!blk-com&!blk-tit&!blk-tita>  new.block
  note output
%<*!dt-beg&dt-end>
%<!blk-com&!blk-tit&!blk-tita>  new.block 
  format.date "year" output.check
%</!dt-beg&dt-end>
  fin.entry
%<harnm>  write.url
}

%    \end{macrocode}
% \end{macro}
%    \begin{macrocode}
%<*ay>
FUNCTION {proceedings}
{ output.bibitem
  format.editors output
  editor format.key output
%<au-col>  editor add.colon
%<dt-beg>  format.date "year" output.check
%<dt-beg>  date.block
%<!dt-beg&!blk-com&!blk-tit&!blk-tita>  new.block
  format.btitle "title" output.check
  format.bvolume output
  format.number.series output
  address output
%<!blk-com&!blk-tit&!blk-tita>  new.sentence
  organization output
  publisher output
%<!dt-beg&!dt-end>  format.date "year" output.check
%<isbn>  format.isbn output
%<!blk-com&!blk-tit&!blk-tita>  new.block
  note output
%<*!dt-beg&dt-end>
%<!blk-com&!blk-tit&!blk-tita>  new.block 
  format.date "year" output.check
%</!dt-beg&dt-end>
  fin.entry
%<harnm>  write.url
}

%</ay>
%<*!ay>
FUNCTION {proceedings}
{ output.bibitem
  editor empty$
    { organization output }
    { format.editors output.nonnull }
  if$
%<au-col>  editor add.colon
%<dt-beg>  format.date "year" output.check
%<dt-beg>  date.block
%<!dt-beg&!blk-com&!blk-tit&!blk-tita>  new.block
  format.btitle "title" output.check
  format.bvolume output
  format.number.series output
  address empty$
    { editor empty$
        { publisher new.sentence.checka }
        { organization publisher new.sentence.checkb
          organization output
        }
      if$
      publisher output
%<!dt-beg&!dt-end>      format.date "year" output.check
    }
    { address output.nonnull
%<!dt-beg&!dt-end>      format.date "year" output.check
%<!blk-com&!blk-tit&!blk-tita>      new.sentence
      editor empty$
        'skip$
        { organization output }
      if$
      publisher output
    }
  if$
%<!blk-com&!blk-tit&!blk-tita>  new.block
  note output
%<*!dt-beg&dt-end>
%<!blk-com&!blk-tit&!blk-tita>  new.block 
  format.date "year" output.check
%</!dt-beg&dt-end>
  fin.entry
%<harnm>  write.url
}

%</!ay>
%    \end{macrocode}
% 
% \begin{macro}{`techreport'}
% \changes{3.5}{1995 Oct 4}{Add option \texttt{trtit-b}}
%    \begin{macrocode}
FUNCTION {techreport}
{ output.bibitem
  format.authors "author" output.check
%<ay>  author format.key output
%<au-col>  author add.colon
%<dt-beg>  format.date "year" output.check
%<dt-beg>  date.block
%<!dt-beg&!blk-com&!blk-tit&!blk-tita>  new.block
%<trtit-b>  format.btitle "title" output.check
%<!trtit-b>  format.title "title" output.check
%<!trtit-b&blk-com&(tit-q|tit-qq)>  end.quote.title
%<!blk-com&!blk-tit&!blk-tita>  new.block
%<blk-tit>  new.sentence
  format.tr.number output.nonnull
  institution "institution" output.check
  address output
%<!dt-beg&!dt-end>  format.date "year" output.check
%<!blk-com&!blk-tit&!blk-tita>  new.block
  note output
%<*!dt-beg&dt-end>
%<!blk-com&!blk-tit&!blk-tita>  new.block 
  format.date "year" output.check
%</!dt-beg&dt-end>
  fin.entry
%<harnm>  write.url
}

%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
FUNCTION {unpublished}
{ output.bibitem
  format.authors "author" output.check
%<ay>  author format.key output
%<au-col>  author add.colon
%<ay&dt-beg>  format.date "year" output.check
%<!ay&dt-beg>  format.date output
%<dt-beg>  date.block
%<!dt-beg&!blk-com&!blk-tit&!blk-tita>  new.block
  format.title "title" output.check
%<blk-com&(tit-q|tit-qq)>  end.quote.title
%<!blk-com&!blk-tit&!blk-tita>  new.block
%<blk-tit>  new.sentence
  note "note" output.check
%<*ay&!dt-beg&dt-end>
%<!blk-com&!blk-tit&!blk-tita>  new.block 
  format.date "year" output.check
%</ay&!dt-beg&dt-end>
%<*!ay&!dt-beg&dt-end>
%<!blk-com&!blk-tit&!blk-tita>  new.block 
  format.date output
%</!ay&!dt-beg&dt-end>
  fin.entry
%<harnm>  write.url
}

FUNCTION {default.type} { misc }

READ

%    \end{macrocode}
%
% \begin{macro}{`sortify'}
% \changes{3.8}{1996 Feb 29}{Do not allow unsorted alphas}
% In \texttt{btxbst.doc}/\texttt{.mbs}, the \texttt{sortify} function is
% left out for unsorted alpha-style citations. This leads to an error, 
% because it is still used. So leave it in here too. \emph{In fact, do away
% with unsorted alpha style, since it is as useless as unsorted author--year
% listings.}
%    \begin{macrocode}
%<*ay|alph|!seq-no>
FUNCTION {sortify}
{ purify$
  "l" change.case$
}

%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
INTEGERS { len }

FUNCTION {chop.word}
{ 's :=
  'len :=
  s #1 len substring$ =
    { s len #1 + global.max$ substring$ }
    's
  if$
}

%    \end{macrocode}
%
% \begin{macro}{`format.lab.names'}
% \changes{3.8}{1996 Feb 29}{Add option \texttt{alph} for \texttt{alpha.bst}
%    style of labels}
% The function \texttt{format.lab.names} formats by author--year or the
% \texttt{alpha} style as in the original \texttt{alpha.bst}.
% Only major difference is that there should be no unsorted (\texttt{seq-no})
% versions of this. Patashnik was clearly very unhappy about accommodating
% such an animal, and in fact, his unsorted alpha style crashes \btx.
% I also provide the \texttt{vonx} option here to ignore the \textsl{von}
% part of the name.
%    \begin{macrocode}
%<*!ay&alph>
INTEGERS { et.al.char.used }

FUNCTION {initialize.et.al.char.used}
{ #0 'et.al.char.used :=
}

EXECUTE {initialize.et.al.char.used}

FUNCTION {format.lab.names}
{ 's :=
  s num.names$ 'numnames :=
  numnames #1 >
    { numnames #4 >
        { #3 'namesleft := }
        { numnames 'namesleft := }
      if$
      #1 'nameptr :=
      ""
        { namesleft #0 > }
        { nameptr numnames =
            { s nameptr "{ff }{vv }{ll}{ jj}" format.name$ "others" =
                { "{\etalchar{+}}" *
                  #1 'et.al.char.used :=
                }
%<!vonx>                { s nameptr "{v{}}{l{}}" format.name$ * }
%<vonx>                { s nameptr "{l{}}" format.name$ * }
              if$
            }
%<!vonx>            { s nameptr "{v{}}{l{}}" format.name$ * }
%<vonx>            { s nameptr "{l{}}" format.name$ * }
          if$
          nameptr #1 + 'nameptr :=
          namesleft #1 - 'namesleft :=
        }
      while$
      numnames #4 >
        { "{\etalchar{+}}" *
          #1 'et.al.char.used :=
        }
        'skip$
      if$
    }
%<!vonx>    { s #1 "{v{}}{l{}}" format.name$
%<vonx>    { s #1 "{l{}}" format.name$
      duplicate$ text.length$ #2 <
        { pop$ s #1 "{ll}" format.name$ #3 text.prefix$ }
        'skip$
      if$
    }
  if$
}

%</!ay&alph>
%<*ay>
FUNCTION {format.lab.names}
{ 's :=
  s #1 "{vv~}{ll}" format.name$
  s num.names$ duplicate$
  #2 >
%<!etal-it&!etal-rm>    { pop$ " et~al." * }
%<!etal-it&etal-rm>    { pop$ " " * "et~al." roman.cite * }
%<etal-it>    { pop$ " " * "et~al." emphasize * }
    { #2 <
        'skip$
        { s #2 "{ff }{vv }{ll}{ jj}" format.name$ "others" =
%<!etal-it&!etal-rm>            { " et~al." * }
%<!etal-it&etal-rm>            { " " * "et~al." roman.cite * }
%<etal-it>            { " " * "et~al." emphasize * }
%<*!harnm>
%<*!amper>
            { bbl.and 
%<and-rm>              roman.cite
              space.word * s #2 "{vv~}{ll}" format.name$ * }
%</!amper>
%<amper>            { " \& " * s #2 "{vv~}{ll}" format.name$ * }
%</!harnm>
%<harnm>            { " \harvardand\ " * s #2 "{vv~}{ll}" format.name$ * }
          if$
        }
      if$
    }
  if$
}

%</ay>
%    \end{macrocode}
% \end{macro}
%
% Have to be very careful with the options \texttt{ay}, \texttt{alph}, and
% \texttt{seq-no} here. The first two are actually mutually exclusive, and
% \texttt{ay} should dominate. The \texttt{seq-no} option only applies for
% numerical (\texttt{!ay}) but not alphabetic (\texttt{alph}) selections.
% This whole block of coding dealing with labels is only included for
% author--year or alphabetic or ordered numerical.
% That is, \texttt{ay} or \texttt{alph} or \texttt{!seq-no} is true.
%    \begin{macrocode}
%<*ay|alph>
FUNCTION {author.key.label}
{ author empty$
    { key empty$
        { cite$ #1 #3 substring$ }
%<ay>        'key 
%<!ay>        { key #3 text.prefix$ }
      if$
    }
    { author format.lab.names }
  if$
}

FUNCTION {author.editor.key.label}
{ author empty$
    { editor empty$
        { key empty$
            { cite$ #1 #3 substring$ }
%<ay>            'key 
%<!ay>            { key #3 text.prefix$ }
          if$
        }
        { editor format.lab.names }
      if$
    }
    { author format.lab.names }
  if$
}

%</ay|alph>
%<*!ay&alph>
FUNCTION {author.key.organization.label}
{ author empty$
    { key empty$
        { organization empty$
            { cite$ #1 #3 substring$ }
            { "The " #4 organization chop.word #3 text.prefix$ }
          if$
        }
        { key #3 text.prefix$ }
      if$
    }
    { author format.lab.names }
  if$
}

FUNCTION {editor.key.organization.label}
{ editor empty$
    { key empty$
        { organization empty$
            { cite$ #1 #3 substring$ }
            { "The " #4 organization chop.word #3 text.prefix$ }
          if$
        }
        { key #3 text.prefix$ }
      if$
    }
    { editor format.lab.names }
  if$
}

%</!ay&alph>
%<*ay>
FUNCTION {editor.key.label}
{ editor empty$
    { key empty$
        { cite$ #1 #3 substring$ }
        'key 
      if$
    }
    { editor format.lab.names }
  if$
}

%    \end{macrocode}
% \begin{macro}{`calc.short.authors'}
% \changes{3.3}{1995 Sep 4}{Add function to store short list of authors 
%     for later test}
%    \begin{macrocode}
FUNCTION {calc.short.authors}
{ type$ "book" =
  type$ "inbook" =
  or
    'author.editor.key.label
    { type$ "proceedings" =
        'editor.key.label
        'author.key.label
      if$
    }
  if$
%<lab-it>  emphasize
%<lab-bf&!lab-it>  bolden
%<lab-sc&!lab-it&!lab-bf>  scaps
  'short.list := 
}

%    \end{macrocode}
% \end{macro}
% \begin{macro}{`calc.label'}
% \changes{1.5(2.3)a}{1994 Oct 11}{Add option \texttt{note-yr}}
% \changes{3.0}{1995 Mar 3}{Add options \texttt{lab-bf} and \texttt{lab-sc}}
% \changes{3.3}{1995 Sep 4}{Use \texttt{calc.short.authors}}
% \changes{3.8}{1996 Feb 29}{Add \texttt{calc.label} from \texttt{alpha.bst}}
%    \begin{macrocode}
FUNCTION {calc.label}
{ calc.short.authors
  short.list
%<!(har|ast|cay|nmd|alk|cn)>  "("
%<har|ast|cay|nmd|alk|cn>  ", "
  *
  year duplicate$ empty$
     { pop$ "????" }
%<!note-yr>     { purify$ #-1 #4 substring$ }
%<note-yr>     'skip$
  if$
  *
  'label :=
}

%</ay>
%<*!ay&alph>
FUNCTION {calc.label}
{ type$ "book" =
  type$ "inbook" =
  or
    'author.editor.key.label
    { type$ "proceedings" =
        'editor.key.organization.label
        { type$ "manual" =
            'author.key.organization.label
            'author.key.label
          if$
        }
      if$
    }
  if$
  duplicate$
  year field.or.null purify$ #-1 #2 substring$
  *
  'label :=
  year field.or.null purify$ #-1 #4 substring$
  *
  sortify 'sort.label :=
}

%</!ay&alph>
%<*ay>
%    \end{macrocode}
% \end{macro}
% \begin{macro}{`calc.short.label'}
% \changes{3.3}{1995 Sep 4}{Use \texttt{calc.short.authors}}
%    \begin{macrocode}
%<*har|cay|nmd|ast|cn>
FUNCTION {calc.short.label}
{ calc.short.authors short.list
  'label :=
}

%</har|cay|nmd|ast|cn>
%</ay>
%    \end{macrocode}
% \end{macro}
% \begin{macro}{`sort.format.names'}
% \changes{1.7(2.5)}{1995 Feb 9}{Make ordering of `et al' works by year 
%    and authors and not just year}
% \changes{3.0}{1995 Feb 27}{Option \texttt{nm-revf} to act just as default}
% \changes{3.2}{1995 Jun 16}{Add option \texttt{vonx} so sorting ignores the
%   \emph{von} part of the name}
% \changes{3.5}{1995 Oct 24}{For limited authors, sort only on those present}
% \changes{3.5}{1995 Oct 24}{`Et al' considered author before all others}
%    \begin{macrocode}
FUNCTION {sort.format.names}
{ 's :=
  #1 'nameptr :=
  ""
  s num.names$ 'numnames :=
  numnames 'namesleft :=
    { namesleft #0 > }
    { s nameptr 
%<*!nm-init&!nm-rev&!nm-rev1&!nm-rv&!nm-rvx&!nm-rvv>
%<!vonx>      "{vv{ } }{ll{ }}{  ff{ }}{  jj{ }}" 
%<vonx>      "{ll{ }}{  ff{ }}{  jj{ }}" 
%</!nm-init&!nm-rev&!nm-rev1&!nm-rv&!nm-rvx&!nm-rvv>
%<*nm-init|nm-rev|nm-rev1|nm-rv|nm-rvx|nm-rvv>
%<!vonx>      "{vv{ } }{ll{ }}{  f{ }}{  jj{ }}" 
%<vonx>      "{ll{ }}{  f{ }}{  jj{ }}" 
%</nm-init|nm-rev|nm-rev1|nm-rv|nm-rvx|nm-rvv>
      format.name$ 't := 
      nameptr #1 >
        { 
%<*nmlm>
%<m1>          nameptr #2 =
%<m2>          nameptr #3 =
%<m3>          nameptr #4 =
%<m4>          nameptr #5 =
%<m5>          nameptr #6 =
%<x1>          numnames #1 > and
%<x2>          numnames #2 > and
%<x3>          numnames #3 > and
%<x4>          numnames #4 > and
%<x5>          numnames #5 > and
%<x6>          numnames #6 > and
%<x7>          numnames #7 > and
%<x8>          numnames #8 > and
%<x9>          numnames #9 > and
            { "others" 't :=
              #1 'namesleft := }
            'skip$
          if$
%</nmlm>
          "   "  *
          namesleft #1 = t "others" = and
            { "aaaaa" * }
%<*seq-lab|seq-key>
            { numnames #2 > nameptr #2 = and
                { "zz" * year field.or.null * "   " * }
                'skip$
              if$
              t sortify *
            }
%</seq-lab|seq-key>
%<!seq-lab&!seq-key>            { t sortify * }
          if$
        }
        { t sortify * }
      if$
      nameptr #1 + 'nameptr :=
      namesleft #1 - 'namesleft :=
    }
  while$
}

%    \end{macrocode}
% \end{macro}
%
%    \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$
}

FUNCTION {author.sort}
{ author empty$
    { key empty$
        { "to sort, need author or key in " cite$ * warning$
          ""
        }
        { key sortify }
      if$
    }
    { author sort.format.names }
  if$
}

FUNCTION {author.editor.sort}
{ author empty$
    { 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$
}

%<*ay>
FUNCTION {editor.sort}
{ editor empty$
    { key empty$
        { "to sort, need editor or key in " cite$ * warning$
          ""
        }
        { key sortify }
      if$
    }
    { editor sort.format.names }
  if$
}

%<*seq-no>
INTEGERS { seq.num }

FUNCTION {init.seq}
{ #0 'seq.num :=}

EXECUTE {init.seq}

FUNCTION {int.to.fix}
{ "000000000" swap$ int.to.str$ *
  #-1 #10 substring$
}

%</seq-no>
%    \end{macrocode}
% \begin{macro}{`presort'}
% \changes{3.81}{1996 Sep 16}{Add option \texttt{seq-no} to author--year}
% For unsorted author--year, make up the final sorting order in
% \texttt{sort.label} with the original sequence number, for unsorting later.
%    \begin{macrocode}
FUNCTION {presort}
{ calc.label
  label sortify
  "    "
  *
%<*!seq-no>
  type$ "book" =
  type$ "inbook" =
  or
    'author.editor.sort
    { type$ "proceedings" =
        'editor.sort
        'author.sort
      if$
    }
  if$
  #1 entry.max$ substring$      
%</!seq-no>
%<*seq-no>
  seq.num #1 + 'seq.num :=
  seq.num  int.to.fix 
%</seq-no>
  'sort.label :=                
  sort.label                    
  *
  "    "
  *
%<seq-yr>  "    " * year field.or.null *
%<*!seq-key&!seq-yr>
  title field.or.null
  sort.format.title
%</!seq-key&!seq-yr>
%<seq-key|seq-yr>  cite$
  *
  #1 entry.max$ substring$
  'sort.key$ :=
}

%    \end{macrocode}
% \end{macro}
%    \begin{macrocode}
%</ay>
%<*!ay>
FUNCTION {author.organization.sort}
{ author empty$
    { organization empty$
        { key empty$
            { "to sort, need author, organization, or key in " cite$ * warning$
              ""
            }
            { key sortify }
          if$
        }
        { "The " #4 organization chop.word sortify }
      if$
    }
    { author sort.format.names }
  if$
}

FUNCTION {editor.organization.sort}
{ editor empty$
    { organization empty$
        { key empty$
            { "to sort, need editor, organization, or key in " cite$ * warning$
              ""
            }
            { key sortify }
          if$
        }
        { "The " #4 organization chop.word sortify }
      if$
    }
    { editor sort.format.names }
  if$
}

FUNCTION {presort}
%<*alph>
{ calc.label
  sort.label
  "    "
  *
  type$ "book" =
%</alph>
%<!alph>{ type$ "book" =
  type$ "inbook" =
  or
    'author.editor.sort
    { type$ "proceedings" =
        'editor.organization.sort
        { type$ "manual" =
            'author.organization.sort
            'author.sort
          if$
        }
      if$
    }
  if$
%<alph>  *
  "    "
  *
  year field.or.null sortify
%<!seq-yr|alph>  *
  "    "
  *
%<seq-yr&!alph>  swap$ *
  title field.or.null
  sort.format.title
  *
  #1 entry.max$ substring$
  'sort.key$ :=
}

%</!ay>
ITERATE {presort}

SORT            

%</ay|alph|!seq-no>
%    \end{macrocode}
% \begin{macro}{`forward.pass'}
% \changes{3.4}{1995 Sep 5}{Include number of references in argument to
%     \texttt{thebibliography} environment}
% With version~6.0 of \texttt{natbib}, the author-year styles can also be
% used for numerical citations; then the \texttt{thebibliography} environment
% must have an argument indicating the length of the longest label. 
% Simply count the references and add this number as the argument.
%    \begin{macrocode}
%<*ay>
STRINGS { last.label next.extra }       

INTEGERS { last.extra.num number.label }             

FUNCTION {initialize.extra.label.stuff} 
{ #0 int.to.chr$ 'last.label :=
  "" 'next.extra :=
  #0 'last.extra.num :=
  #0 'number.label :=
}

FUNCTION {forward.pass}
{ last.label label =
    { last.extra.num #1 + 'last.extra.num :=
      last.extra.num int.to.chr$ 'extra.label :=
    }
    { "a" chr.to.int$ 'last.extra.num :=
      "" 'extra.label :=
      label 'last.label :=
    }
  if$
  number.label #1 + 'number.label :=
}

%</ay>
%<*!ay&alph>
STRINGS { longest.label last.sort.label next.extra }

INTEGERS { longest.label.width last.extra.num }

FUNCTION {initialize.longest.label}
{ "" 'longest.label :=
  #0 int.to.chr$ 'last.sort.label :=
  "" 'next.extra :=
  #0 'longest.label.width :=
  #0 'last.extra.num :=
}

FUNCTION {forward.pass}
{ last.sort.label sort.label =
    { last.extra.num #1 + 'last.extra.num :=
      last.extra.num int.to.chr$ 'extra.label :=
    }
    { "a" chr.to.int$ 'last.extra.num :=
      "" 'extra.label :=
      sort.label 'last.sort.label :=
    }
  if$
}

%</!ay&alph>
%    \end{macrocode}
% \end{macro}
% \begin{macro}{`reverse.pass'}
% \changes{3.3}{1995 Aug 7}{Put extra label in braces}
% The extra label is added in braces so that natbib can treat it as one unit.
% This allows extra labels to be more than one letter long. For non-NFSS
% emphasizing, this is no problem, since labels go in |{\em a}|, but for
% non-emphasizing and for NFSS, it caused troubles without the braces.
% The trouble arises with multiple citations in one |\cite| in which 
% authors and years are the same, and only the extra label is given for
% the next one. Note: |\emph{a}| is more than one letter long in this sense,
% so it is not just a problem for more than 26 papers with same authors and
% year.
%
% \changes{3.81}{1996 Jun 17}{Add \texttt{\char`\\natexlab}}
% The command |\natexlab| now encloses the extra label for \texttt{natbib}
% styles. This command normally just prints its argument, but for numerical
% citation mode, it swallows its argument. This allows the extra labels to 
% be suppressed for numerical citations where they are superfluous.
% The enclosing braces mentioned above must be included here to make the
% entire extra label text a single token for \texttt{natbib}.
%    \begin{macrocode}
%<*ay>
FUNCTION {reverse.pass}
{ next.extra "b" =
    { "a" 'extra.label := }
    'skip$
  if$
  extra.label 'next.extra :=
  extra.label 
%<xlab-it>  emphasize 
  duplicate$ empty$
    'skip$
    { "{\natexlab{" swap$ * "}}" * }
  if$
  'extra.label :=
%<!(har|ast|cay|nmd|cn)>  label extra.label * 'label :=
}

%</ay>
%<*!ay&alph>
FUNCTION {reverse.pass}
{ next.extra "b" =
    { "a" 'extra.label := }
    'skip$
  if$
  label extra.label * 'label :=
  label width$ longest.label.width >
    { label 'longest.label :=
      label width$ 'longest.label.width :=
    }
    'skip$
  if$
  extra.label 'next.extra :=
}

%</!ay&alph>
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
%<ay>EXECUTE {initialize.extra.label.stuff}
%<!ay&alph>EXECUTE {initialize.longest.label}
%<*ay|alph>

ITERATE {forward.pass}

REVERSE {reverse.pass}

%</ay|alph>
%<*ay>
FUNCTION {bib.sort.order}
{ sort.label
  "    "
  *
  year field.or.null sortify
%<seq-yr&!(seq-lab|seq-key)>  swap$
  *
  "    "
  *
%<*!seq-key&!seq-yr>
  title field.or.null
  sort.format.title
%</!seq-key&!seq-yr>
%<seq-key|seq-yr>  cite$
  *
  #1 entry.max$ substring$
  'sort.key$ :=
%<har|cay|nmd|cn|ast>  calc.short.label
}

ITERATE {bib.sort.order}

SORT            

%</ay>
%<*!ay&!alph>
STRINGS { longest.label }

INTEGERS { number.label longest.label.width }

FUNCTION {initialize.longest.label}
{ "" 'longest.label :=
  #1 'number.label :=
  #0 'longest.label.width :=
}

FUNCTION {longest.label.pass}
%<*!cite>
{ number.label int.to.str$ 'label :=
  number.label #1 + 'number.label :=
%</!cite>
%<cite>{ cite$ 'label := 
  label width$ longest.label.width >
    { label 'longest.label :=
      label width$ 'longest.label.width :=
    }
    'skip$
  if$
}

EXECUTE {initialize.longest.label}

ITERATE {longest.label.pass}

%</!ay&!alph>
%    \end{macrocode}
%
% \begin{macro}{`begin.bib'}
% \changes{2.0}{1994 Jan 31}{For \texttt{german}, add the definition of 
%    {\tt\protect\bslash qq} to replace double-quote character.}
% \changes{2.0}{1994 Jan 31}{For \texttt{babel}, read in file 
% \texttt{babelbst.tex} in \texttt{thebibliography} to define the word 
%  commands.}
% \changes{3.4}{1995 Sep 5}{Add number of references as argument}
% The function \texttt{begin.bib} writes  the initial text to the \texttt{.bbl}
% file. The most important matter here is that the \texttt{thebibliography}
% environment is invoked. 
%    \begin{macrocode}
FUNCTION {begin.bib}
%<*!ay&alph>
{ et.al.char.used
    { "\newcommand{\etalchar}[1]{$^{#1}$}" write$ newline$ }
    'skip$
  if$
  preamble$ empty$                              
%</!ay&alph>
%<ay|!alph>{ preamble$ empty$                              
    'skip$
    { preamble$ write$ newline$ }
  if$
%<ay>  "\begin{thebibliography}{" number.label int.to.str$ * "}" * 
%<!ay>  "\begin{thebibliography}{"  longest.label  * "}" * 
  write$ newline$
%<!tit-it&tit-q>  "\newcommand{\enquote}[1]{`#1'}"
%<!tit-it&!tit-q&tit-qq>  "\newcommand{\enquote}[1]{``#1''}"
%<!tit-it&(tit-q|tit-qq)>  write$ newline$
%<umlaut>  "\let\qq=\" quote$ * write$ newline$
%<*ay>
  "\expandafter\ifx\csname natexlab\endcsname\relax\def\natexlab#1{#1}\fi"
  write$ newline$
%</ay>
%<*babel>
  "\input{babelbst.tex}" write$ newline$
  "\newcommand{\Capitalize}[1]{\uppercase{#1}}" write$ newline$
  "\newcommand{\capitalize}[1]{\expandafter\Capitalize#1}" write$ newline$
%</babel>
}

EXECUTE {begin.bib}

%    \end{macrocode}
% \end{macro}
%    \begin{macrocode}
EXECUTE {init.state.consts}

ITERATE {call.type$}

FUNCTION {end.bib}
{ newline$
  "\end{thebibliography}" write$ newline$
}

EXECUTE {end.bib}
%</!head>
%</!options&!driver&!bblbst>
%    \end{macrocode}
% 
% \section{The File \texttt{babelbst.tex} for English}
% The following contains the definitions for the \texttt{babel} language
% selection as they apply to English. This file may be extracted with 
% \dtx{} and the option \texttt{bblbst}.
%    \begin{macrocode}
%<*bblbst>
 % This is babelbst.tex for English.
 % It should serve as a model for other languages.
 % Alternatively, store it under a different name (e.g. englbst.tex)
 % and then \input it with a command in babelbst.tex.
\def\bbland{and}
\def\bbleditors{editors}        \def\bbleds{eds.}
\def\bbleditor{editor}          \def\bbled{ed.}
\def\bbledby{edited by}
\def\bbledition{edition}        \def\bbledn{edn.}
\def\bblvolume{volume}          \def\bblvol{vol.}
\def\bblof{of}
\def\bblnumber{number}          \def\bblno{no.}
\def\bblin{in} 
\def\bblpages{pages}            \def\bblpp{pp.}
\def\bblpage{page}              \def\bblp{p.}
\def\bblchapter{chapter}        \def\bblchap{chap.}
\def\bbltechreport{Technical Report}
\def\bbltechrep{Tech. Rep.}
\def\bblmthesis{Master's thesis}
\def\bblphdthesis{Ph.D. thesis}
\def\bblfirst{First}            \def\bblfirsto{1st}
\def\bblsecond{Second}          \def\bblsecondo{2nd}
\def\bblthird{Third}            \def\bblthirdo{3rd}
\def\bblfourth{Fourth}          \def\bblfourtho{4th}
\def\bblfifth{Fifth}            \def\bblfiftho{5th}
\def\bblst{st}  \def\bblnd{nd}  \def\bblrd{rd}
\def\bblth{th}
\def\bbljan{January}  \def\bblfeb{February}  \def\bblmar{March}
\def\bblapr{April}    \def\bblmay{May}       \def\bbljun{June}
\def\bbljul{July}     \def\bblaug{August}    \def\bblsep{September}
\def\bbloct{October}  \def\bblnov{November}  \def\bbldec{December}
%</bblbst>
%    \end{macrocode}
% 
% \Finale

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.