% \iffalse
%
%% File: chembst.dtx Copyright (C) 2008 Stephan Schenk
%%       $Id: chembst.dtx,v 1.12 2008/09/17 19:07:16 schenk Exp $
%%
%% Stephan Schenk (mail@schenk-stephan.de)
%%
%% This program may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%%   http://www.latex-project.org/lppl.txt
%%
%% *****
%%
% This package consists of the files chembst.dtx and chembst.ins
%
% To typeset this documentation use
%
%   pdflatex chembst.dtx
%   makeindex -s gind.ist chembst.idx
%   makeindex -s gglo.ist -o chembst.gls chembst.glo
%   pdflatex chembst.dtx
%
%
% The following journals can be selected:
% - ChemCommun
% - ChemEurJ
% - InorgChem
% - JAmChemSoc
%
% The following additional selection rules exist:
% - cv
%       Create a style file for a curriculum vitae.
% - namesone
%       Truncate list of names to one and append et al.
%       Works only if more names than specified by *name options are present.
% - tennames
%       If a list contains more than ten names it is truncated.
%       See names* options
% - fifteennames
%       Same as tennames but with 16 names.
%
%
%
%<*driver>
\ProvidesFile{chembst.dtx}
  [2008/09/17 0.2.5 BibTeX style files for chemistry journals]
\documentclass{ltxdoc}
\GetFileInfo{chembst.dtx}
\CodelineIndex
\RecordChanges
%\OnlyDescription
\begin{document}
  \DocInput{\filename}
\end{document}
%</driver>
% \fi
%
% \CheckSum{175}
%
% \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         \~}
%
% ^^A Cheat on doc.sty since this BibTeX commands do not start with '\'
% \renewcommand*{\bslash}{}
% ^^A Suppress index entries for \DescribeMacro{}
% \makeatletter\let\SpecialUsageIndex=\@gobble\makeatother
%
% ^^A For some reason I don't understand right now the counter has to be
% ^^A set to 0. doc.dtx states that this is the default anyway.
% \setcounter{StandardModuleDepth}{0}
%
% \changes{0.2.5}{2008/09/17}{Minor documentation updates}
% \changes{0.2.4}{2008/03/18}{Removed number of pages from papers with EID in
%   all styles except 'cv'.}
% \changes{0.2.3}{2008/01/17}{Fixed some minor issues with ACS styles.}
% \changes{0.2.2}{2007/09/13}{JAmChemSoc now requires truncation of author list
%    after more than 15 names only.}
% \changes{0.2.2}{2007/09/13}{Added InorgChem.bst}
% \changes{0.2.0}{2006/07/27}{Renamed european.bst to ChemEurJ.bst}
% \changes{0.2.0}{2006/07/27}{Renamed american.bst to JAmChemSoc.bst}
% \changes{0.2.0}{2006/07/27}{Added support for Chem. Commun.}
% \changes{0.1.2}{2006/05/03}{Added support for a curriculum vitae}
% \changes{0.1.2}{2006/05/03}{Removed unused function add.blank}
% \changes{0.1.0}{2006/02/23}{Initial revision}
% \title{\BibTeX\ Style Files for Chemistry Journals\thanks{This file
%   describes version \fileversion\ and has been last revised \filedate.}}
% \author{Stephan Schenk\\mail (at) schenk-stephan.de}
% \maketitle
%
% \setcounter{tocdepth}{2}
% \tableofcontents
%
% \section{Introduction}
%
% This collection of bibtex style files started with a version intended for
% \emph{Chem.\ Eur.~J.} The base version of it was created using the
% marvelous |makebst| program by Patrick W.~Daly. Soon afterwards, a version for
% \emph{J.~Am.\ Chem.\ Soc.}\ was available, too. With changes to both files
% becoming more and more complex, everything was merged into a single
% |chembst.dtx| file to avoid maintaining several versions of the code. Using
% the |docstrip| utility, the different style files can now easily be generated
% by running |latex chembst.ins|.
% Currently, the following journals are supported:
% \begin{itemize}
%   \item \emph{Chem.\ Commun.}\ (|ChemCommun.bst|)
%   \item \emph{Inorg.\ Chem.}\ (|InorgChem.bst|), which can be used for
%     most of the journals published by the American Chemical Society
%   \item \emph{J.~Am.\ Chem.\ Soc.}\ (|JAmChemSoc.bst|)
%   \item \emph{Chem.\ Eur.~J.}\ (|ChemEurJ.bst|), which can be used for most of
%     the journals published by Wiley
% \end{itemize}
% Additionally, the following styles are also supported:
% \begin{itemize}
%   \item \emph{Curriculum vitae} (|cv.bst|), a style similar to \emph{Chem.\
%     Eur.~J.} that includes the title of an article
% \end{itemize}
%
%
%
% \section{Some notes}
%
% \subsection{crossref entries}
% \label{o::crossref}
%
% The crossref feature is described in detail in the |btxdoc.dvi| \BibTeX\
% documentation. Using crossref is a way to inherit information from a parent
% entry. As an example consider a database containing a @book entry for citing
% the whole book and a @inbook entry for citing some pages from that book.
% Naturally, the only difference between both entries is that @inbook contains
% a |pages| field. All the other information is stored redundantly.
%
% Using the crossref feature the @inbook entry can be as simple as
% \begin{verbatim}
%   @inbook{inbook_key,
%     crossref = {book_key},
%     pages = {1-5},
%   }
% \end{verbatim}
% All the other fields (author, publisher, year etc.) are inherited from the
% parent entry with the key |book_key|.
%
% If you do not cite the whole book in your document, i.\,e.\ the document does
% not contain |\cite{book_key}|, the following will happen. If |book_key| is
% not cross-referenced more than once\footnote{%
%   You can change that number by passing the argument |-min-crossrefs=number|
%   to bibtex.}
% everything will look perfectly like a ``normal'' @inbook entry. However, if
% |book_key| is cross-referenced more than once, the entry corresponding to the
% whole book will be added automatically to the bibliography and the @inbook
% entry will be formatted as A. Author in |\cite{book_key}|,
% pages 1-5.\footnote{%
%   In fact \cs{bibliographycite} is used. See section~\ref{o::customization}
%   for details.}
% If your document does contain |\cite{book_key}| you will always get the
% crossref format.
%
% This applies to entries of type @inbook, @incollection and @inproceedings.
%
%
%
% \subsection{JAmChemSoc.bst}
%
% The Journal of the American Chemical Society (ACS) now requires
% that for citations with more than 10 authors the list of authors is
% abbreviated by giving only the first author followed by \emph{et al.} The
% style file |JAmChemSoc.bst| automatically takes care of that. However, ACS
% also
% requires that for those citations the full list of authors should be given as
% Supporting Information. The style |JAmChemSoc_all.bst| can be used for this
% purpose, since it does not abbreviate the list of authors.
%
%
%
% \subsection{Customization}
% \label{o::customization}
%
% Defaults for several commands used in the |thebibliography| environment are
% defined at the beginning of the |.bbl| file. To override the default settings
% define the command before using the \mbox{\cs{bibliography}} command.
%
%
% \DescribeMacro{\url}
% The \cs{url} command is used to display urls. By default this only selects a
% typewriter font. However, it is strongly recommened, that you use the package
% |url.sty| which defines \cs{url} in a more sophisticated way. Due to some
% problems with multiline urls (spurious '\%' in formatted url) you should use
% some reasonable new version (3.2 works fine) of |url.sty|.
%
%
% \DescribeMacro{\urlprefix}
% Every \cs{url} is prefixed by \cs{urlprefix}. By default \cs{urlprefix} does
% nothing. This command is useful if you have to prepend every url with some
% text. For \emph{Angew.\ Chem.}, i.\,e., every url must be preceded by ``to be
% found under''. This can easily be achieved by giving
% \begin{verbatim}
%   \newcommand{\urlprefix}{to be found under }
% \end{verbatim}
%
%
% \DescribeMacro{\foreignlanguage}
% This command is used to temporary switch the language for the title of books
% etc. By default this does nothing but if you load |babel.sty| then the
% language will be changed.
%
%
% \DescribeMacro{\bibliographycite}
% This command is used for formatting crossref entries. It defaults to
% \cs{cite}. However, if you use |overcite.sty| you may not want superscripted
% citations in your bibliography. Then you can define \cs{bibliographycite} the
% following way
% \begin{verbatim}
%   \newcommand{\bibliographycite}[1]{[\citen{#1}]}}
% \end{verbatim}
%
%
% \DescribeMacro{\bbl*}
% Inside the |.bbl| file no text is hard coded and instead the appropriate
% \cs{bbl*} command is used. The text ``erratum'', i.\,e., is produced by
% \cs{bblerratum}. Thus one can easily change all the words in the bibliography
% by defining the appropriate commands.
% \begin{verbatim}
%   \newcommand{\bblerratum}{\emph{errat.}}
% \end{verbatim}
% for instance will give ``\emph{errat.}''. By redefining all necessary commands
% you can also change the language to some other language than the default
% english.
%
%
%
% \section{Description of important entry types}
%
% The entry types discussed in this section are those which are most commonly
% used in writing articles in chemistry. The types listed here refer to entries
% in the database (i.\,e.\ |*.bib|).
%
%
%
% \subsection{@article}
%
% This entry type is designed for an article in a journal.
% The entry type has been augmented with several additional fields. Other style
% files will simply ignore these fields. The following fields are recognized:
%
% \begin{description}
%   \item[author] The names of all authors
%   \item[journal] The name of the journal the article was published in
%   \item[year] The year the article has been published
%   \item[volume] The volume this article has been published in
%   \item[pages] The page numbers of the article
%   \item[eid] The electronic identifier of an article. Some journals, i.\,e.\
%     \emph{J.~Chem.\ Phys.} no longer have page numbers associated to an
%     article but only use the EID. If an EID is present |pages| will be
%     ignored.
%   \item[numpages] The number of pages of an article. This will only be used
%     together with an EID.
%   \item[germanpages] When citing articles from \emph{Angew.\ Chem.} one
%     should always give both the german and the english version. If this
%     field is present the style file assumes that this is a citation of
%     \emph{Angew.\ Chem.\ Int.\ Ed.} and automatically appends the correct
%     citation for \emph{Angew.\ Chem.} The year is always the same for
%     both versions and the german volume is easily calculated by adding 73
%     to the english volume. The page range of the german version is taken
%     from the |germanpages| field.
%   \item[erratumyear, erratumvolume, erratumpages, erratumeid,
%     erratumnumpages] If any of these fields is non-empty the information
%     will be used to append a correctly formatted citation of the erratum
%     to the regular citation.
%   \item[note] A free format text that will be appended at the very end of a
%     citation.
% \end{description}
%
%
%
% \subsection{@book}
%
% This entry type is designed for citing a whole book. If you want to cite only
% some chapters or pages of a book use @inbook or @incollection (see below).
% The following fields are recognized:
%
% \begin{description}
%   \item[author, editor] The names of all authors or editors. You can only use
%     one of author or editor, but not both.
%   \item[title] The title of the book
%   \item[language] The language of the title
%   \item[edition] The edition of the book
%   \item[volume] The volume of the book
%   \item[series] The series the book is part of
%   \item[publisher] The publisher of the book
%   \item[address] The publisher's address
%   \item[year] The year the book was published in
%   \item[note] A free format text that will be appended at the very end of the
%     citation.
% \end{description}
%
%
%
% \subsection{@inbook}
%
% This entry type is designed for citing chapters or pages of a book. The final
% format of the citation is the same as for @book except that the cited
% chapter(s) and/or pages are appended. For the crossref feature see
% section~\ref{o::crossref}. The same fields as for @book plus
% the following are recognized:
%
% \begin{description}
%   \item[chapter] The cited chapters
%   \item[pages] The cited pages
% \end{description}
%
%
%
% \subsection{@incollection}
%
% This entry is also designed for citing chapters or pages of a book and thus
% very similar to @inbook. However, there is one difference: the present entry
% is designed for chapter(s) written by some authors in a book edited by
% others. The final citation looks similar to A. Author, in book title, edited
% by E. Editor. The crossref feature is discussed in section~\ref{o::crossref}.
% The same fields as for @inbook (except |title|) plus the following are
% recognized.
%
% \begin{description}
%   \item[booktitle] The name of the book
% \end{description}
%
%
%
% \subsection{@masterthesis and @phdthesis}
%
% These entries are designed for citing a master's thesis or a PhD thesis. Both
% entries are very similar. The only difference is the thesis' name. The
% following fields are recognized:
%
% \begin{description}
%   \item[author] The author of the thesis
%   \item[school] The school or university where this thesis work was carried
%     out.
%   \item[address] The school's address
%   \item[year] The year the thesis was finished in.
%   \item[note] A free format text that will be appended at the very end of the
%     citation.
%   \item[url] An url where the thesis can be found.
% \end{description}
%
%
%
% \subsection{@program}
%
% This entry is designed for citing a program. This is a new entry type which
% is not contained in the standard \BibTeX\ styles. It allows greater
% flexibility compared to the @misc entry. The following fields are recognized:
%
% \begin{description}
%   \item[author] The program's authors
%   \item[title] The program name
%   \item[description] A short description of the program
%   \item[version] The version/release of the program
%   \item[year] The year the program was published in.
%   \item[publisher] The publisher of the program
%   \item[address] The publisher's address
%   \item[note] A free format text that will be appended at the very end of the
%     citation.
%   \item[url] An url where the program can be found.
% \end{description}
%
%
% \subsection{@misc}
%
% This entry is designed for everything that does not fit into one of the other
% entry categories. This is for instance useful to cite websites. The following
% fields are recognized:
%
% \begin{description}
%   \item[author] The author of the cited work
%   \item[title] The title of the cited work
%   \item[howpublished] A free format text describing how this work has been
%     published. This is usually empty.
%   \item[year] The year the cited work was published in.
%   \item[note] A free format text that will be appended at the very end of the
%     citation.
%   \item[url] An url where the cited work can be found.
% \end{description}
%
%
%
% \subsection{@unpublished}
%
% This entry is designed for unpublished results. The following fields are
% recognized:
%
% \begin{description}
%   \item[author] The author(s) of the unpublished work
%   \item[title] The title of the unpublished work
%   \item[year] The year the unpublished work was carried out.
%   \item[note] A free format text explaining what kind of unpublished work
%     this is (i.\,e.\ ``unpublished results'').
%   \item[url] An url where this work can be found.
% \end{description}
%
%
% \StopEventually{}
%
%
%
% \section{The implementation}
%
% Write the journal this style file is intended for to the file header.
%    \begin{macrocode}
%% This file is intended for use with:
%<ChemCommun>%%       Chem. Commun.
%<ChemEurJ>%%       Chem.-Eur. J.
%<InorgChem>%%       Inorg. Chem.
%<JAmChemSoc>%%       J. Am. Chem. Soc.
%<cv>%%       a curriculum vitae
%%
%    \end{macrocode}
%
%
%
% \subsection{Setup}
%
% \begin{macro}{ENTRY}
% Define all the fields an entry can contain.
%    \begin{macrocode}
ENTRY
  {
    address
    author
    booktitle
    chapter
    collaboration
    description
    edition
    editor
    eid
    erratumeid
    erratumgermanpages
    erratumnumpages
    erratumpages
    erratumvolume
    erratumyear
    germanpages
    howpublished
    institution
    journal
    key
    language
    month
    note
    number
    numpages
    organization
    pages
    publisher
    school
    series
    title
    type
    url
    version
    volume
    year
  }
  {}
  { label }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{INTEGERS}
% \changes{0.1.2}{2006/05/03}{Removed unused variables, added new.sentence}
% Define all integer variables.
%    \begin{macrocode}
INTEGERS {
  before.all
  i
  j
  longest.label.width
  mid.sentence
  multiresult
  nameptr
  namesleft
  new.sentence
  number.label
  numnames
  o
  output.state
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{STRINGS}
% Define all string variables.
%    \begin{macrocode}
STRINGS {
  bibinfo
  delimiter
  longest.label
  s
  t
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{bbl.*}
% Define all the functions for the \LaTeX\ code which returns the words used.
%    \begin{macrocode}
FUNCTION {bbl.and} { "\bbland{}" }
FUNCTION {bbl.chap} { "\bblchap{}" }
FUNCTION {bbl.chapter} { "\bblchapter{}" }
FUNCTION {bbl.edition} { "\bbledn{}" }
FUNCTION {bbl.editor} { "\bbled{}" }
FUNCTION {bbl.editors} { "\bbleds{}" }
FUNCTION {bbl.eidp} { "\bbleidp{}" }
FUNCTION {bbl.eidpp} { "\bbleidpp{}" }
FUNCTION {bbl.erratum} { "\bblerratum{}" }
FUNCTION {bbl.etal} { "\bbletal{}" }
FUNCTION {bbl.fifth} { "\bblfiftho{}" }
FUNCTION {bbl.first} { "\bblfirsto{}" }
FUNCTION {bbl.fourth} { "\bblfourtho{}" }
FUNCTION {bbl.in} { "\bblin{}" }
FUNCTION {bbl.mthesis} { "\bblmthesis{}" }
FUNCTION {bbl.nd} { "\bblnd{}" }
FUNCTION {bbl.nr} { "\bblno{}" }
FUNCTION {bbl.number} { "\bblno{}" }
FUNCTION {bbl.of} { "\bblof{}" }
FUNCTION {bbl.page}{ "\bblp{}" }
FUNCTION {bbl.pages} { "\bblpp{}" }
FUNCTION {bbl.phdthesis} { "\bblphdthesis{}" }
FUNCTION {bbl.rd} { "\bblrd{}" }
FUNCTION {bbl.second} { "\bblsecondo{}" }
FUNCTION {bbl.st} { "\bblst{}" }
FUNCTION {bbl.techrep} { "\bbltechrep{}" }
FUNCTION {bbl.th} { "\bblth{}" }
FUNCTION {bbl.third} { "\bblthirdo{}" }
FUNCTION {bbl.volume} { "\bblvol{}" }
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{}"}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{delimiter.*}
% Define some delimiters used to separate different parts of a citation.
%    \begin{macrocode}
FUNCTION {delimiter.blank} { " " }
FUNCTION {delimiter.colon} { ": " }
FUNCTION {delimiter.comma} { ", " }
FUNCTION {delimiter.semicolon} { "; " }
FUNCTION {delimiter.default}
{
%<ChemCommun|ChemEurJ|cv>  delimiter.comma
%<JAmChemSoc|InorgChem>  delimiter.semicolon
}
%    \end{macrocode}
% \end{macro}
%
%
%
% \subsection{Output related functions}
%
% \begin{macro}{output.bibitem}
% Write \cs{bibitem} and setup new citation.
%    \begin{macrocode}
FUNCTION {output.bibitem}
{
  newline$
  "\bibitem{" write$
  cite$ write$
  "}" write$
  newline$
  ""
  before.all 'output.state :=
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{output.internal}
% \changes{0.1.2}{2006/05/3}{Removed dead code (variable never got specific
%    value)}
% This function is finally called by all the other output functions. It first
% pops the delimiter from the stack. If the (now)
% top string is non-empty the function appends the delimiter to
% the (top-1) string and writes it. The old top string is pushed back on the
% stack at the very end thus leaving it untouched.
%    \begin{macrocode}
FUNCTION {output.internal}
{
  'delimiter :=
%    \end{macrocode}
% write only if top string is non-empty
%    \begin{macrocode}
  duplicate$ empty$
    'pop$
    {
%    \end{macrocode}
% backup top string
%    \begin{macrocode}
      's :=
      output.state mid.sentence =
        {
          delimiter *
          write$
        }
        {
          output.state before.all =
            'write$
            { add.period$ " " * write$ }
          if$
          mid.sentence 'output.state :=
        }
      if$
      s
    }
  if$
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{output.check.internal}
% The function first pops the delimiter from the stack. If the (now) top string
% is empty it issues a warning, otherwise it calls |output.internal| for
% writing.
%    \begin{macrocode}
FUNCTION {output.check.internal}
{
  'delimiter :=
  't :=
  duplicate$ empty$
    { pop$ "empty " t * " in " * cite$ * warning$ }
    { delimiter output.internal }
  if$
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{output}
% \begin{macro}{output.blank}
% \begin{macro}{output.comma}
% \begin{macro}{output.semicolon}
% These functions just push the appropriate delimiter on the stack and then
% call |output.internal|.
%    \begin{macrocode}
FUNCTION {output} { delimiter.default output.internal }
FUNCTION {output.blank} { delimiter.blank output.internal }
FUNCTION {output.comma} { delimiter.comma output.internal }
FUNCTION {output.semicolon} { delimiter.semicolon output.internal }
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{output.check}
% \begin{macro}{output.check.blank}
% \begin{macro}{output.check.comma}
% \begin{macro}{output.check.semicolon}
% These functions just push the appropriate delimiter and then call
% |output.check.internal|.
%    \begin{macrocode}
FUNCTION {output.check} { delimiter.default output.check.internal }
FUNCTION {output.check.blank} { delimiter.blank output.check.internal }
FUNCTION {output.check.comma} { delimiter.comma output.check.internal }
FUNCTION {output.check.semicolon} { delimiter.semicolon output.check.internal }
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
%
%
% \subsection{Operators}
%
% \begin{macro}{not}
% Define a logical |not|.
%    \begin{macrocode}
FUNCTION {not}
{
    { #0 }
    { #1 }
  if$
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{and}
% Define a logical |and|.
%    \begin{macrocode}
FUNCTION {and}
{
    'skip$
    { pop$ #0 }
  if$
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{or}
% Define a logical |or|.
%    \begin{macrocode}
FUNCTION {or}
{
    { pop$ #1 }
    'skip$
  if$
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{multiply}
% Define a function for multiplying two integers.
%    \begin{macrocode}
FUNCTION {multiply}
{
%    \end{macrocode}
% |i| is the multiplicator and will be used as a counter
%    \begin{macrocode}
  'i :=
%    \end{macrocode}
% |j| is the value to multiplicate by i, thus will be added i times
% to itself
%    \begin{macrocode}
  'j :=
  #0
  j #0 =
%    \end{macrocode}
% if |j==0|, nothing has to be done since the product will always be 0;
% |i==0| will be handled gracefully by while loop below
%    \begin{macrocode}
    'skip$
    {
%    \end{macrocode}
% now add |j| |i| times to the 0 on the stack
%    \begin{macrocode}
        { i }
        {
          j +
          i #1 - 'i :=
        }
      while$
    }
  if$
}
%    \end{macrocode}
% \end{macro}
%
%
%
% \subsection{Small helper functions}
%
% \begin{macro}{bibinfo.check}
% This function checks whether the top value is a missing field. If so it
% replaces the top value by an empty string, otherwise the top value is left
% unchanged.
%    \begin{macrocode}
FUNCTION {bibinfo.check}
{
  duplicate$ missing$
    { pop$ "" }
    'skip$
  if$
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{bibinfo.warn}
% This functions first checks whether a field is empty. If so it issues a
% warning. The topmost value is a description of the current field. If the
% field is missing, |bibinfo.warn| pushes an empty string, otherwise the value
% is left unchanged. The behaviour is very similar to |bibinfo.check|.
%    \begin{macrocode}
FUNCTION {bibinfo.warn}
{
  swap$
  duplicate$ missing$
    {
      swap$ "missing " swap$ * " in " * cite$ * warning$ pop$
      ""
    }
    { duplicate$ empty$
        {
          swap$ "empty " swap$ * " in " * cite$ * warning$
        }
        { swap$
          pop$
        }
      if$
    }
  if$
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{bolden}
% This function returns the \LaTeX\ code for boldening the top string.
%    \begin{macrocode}
FUNCTION {bolden}
{
  duplicate$ empty$
    { pop$ "" }
    { "\textbf{" swap$ * "}" * }
  if$
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{capitalize}
% This function capitalizes the first letter of a word.
%    \begin{macrocode}
FUNCTION {capitalize}
{
  "\capitalize" swap$ *
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{cat.internal}
% This function catenates two strings using the delimiter on top of the stack.
% The second string is at (top-1) position, the first at (top-2). If any of
% both strings is empty the function just returns the other string without any
% delimiter.
%    \begin{macrocode}
FUNCTION {cat.internal}
{
  'delimiter :=
  duplicate$ empty$
    'pop$
    {
      swap$
      duplicate$ empty$
        'skip$
        { delimiter * }
      if$
      swap$
      *
    }
  if$
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{cat.blank}
% \begin{macro}{cat.colon}
% \begin{macro}{cat.comma}
% \begin{macro}{cat.default}
% \begin{macro}{cat.semicolon}
% These functions just push the appropriate delimiter and call |cat.internal|.
%    \begin{macrocode}
FUNCTION {cat.blank} { delimiter.blank cat.internal }
FUNCTION {cat.colon} { delimiter.colon cat.internal }
FUNCTION {cat.comma} { delimiter.comma cat.internal }
FUNCTION {cat.default} { delimiter.default cat.internal }
FUNCTION {cat.semicolon} { delimiter.semicolon cat.internal }
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{eng.ord}
% This function formats an english ordinal by appending the appropriate string.
%    \begin{macrocode}
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$
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{is.num}
% This function checks whether the top character is a number.
%    \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}
% This function extracts a number (as string) from the top string.
%    \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}
% This functions converts the |edition| field into the appropriate ordinal.
%    \begin{macrocode}
FUNCTION {convert.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
                        { s eng.ord 't := }
                        { edition 't := }
                      if$
                    }
                  if$
                }
              if$
            }
          if$
        }
      if$
    }
  if$
  t
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{either.or.check}
% This function checks whether mutually exclusive fields are present at the
% same time.
%    \begin{macrocode}
FUNCTION {either.or.check}
{
  empty$
    'pop$
    { "can't use both " swap$ * " fields in " * cite$ * warning$ }
  if$
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{emphasize}
% This function returns the \LaTeX\ code for emphasizing the top string.
%    \begin{macrocode}
FUNCTION {emphasize}
{
  duplicate$ empty$
    { pop$ "" }
    { "\emph{" swap$ * "}" * }
  if$
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{fin.entry}
% This function finalizes a citation. It appends a dot and writes the last
% text chunk.
%    \begin{macrocode}
FUNCTION {fin.entry}
{
  add.period$
  write$ newline$
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{format.names}
% \changes{0.2.2}{2007/09/13}{Added fifteennames option}
% This function formats a list of names.
%    \begin{macrocode}
FUNCTION {format.names}
{
% bibinfo is the description of the names, i.e. author, editor
  'bibinfo :=
  duplicate$ empty$
    'skip$
    {
%    \end{macrocode}
% |s| is the full list of names
%    \begin{macrocode}
      's :=
%    \end{macrocode}
% |t| is the formatted name
%    \begin{macrocode}
      "" 't :=
%    \end{macrocode}
% |nameptr| is the index of the current name\\
% |numnames| is the total number of names\\
% |namesleft| is the number of names yet to format
%    \begin{macrocode}
      #1 'nameptr :=
      s num.names$ 'numnames :=
      numnames 'namesleft :=
        { namesleft #0 > }
        {
          s nameptr
%<ChemCommun|ChemEurJ|cv>          "{f.~}{vv~}{ll}{, jj}"
%<JAmChemSoc|InorgChem>          "{vv~}{ll}{, f.}{, jj}"
          format.name$
          bibinfo.check
          't :=
          nameptr #1 >
            {
%    \end{macrocode}
% The following code chunk checks whether the list of names should be
% abbreviated by et al.
%    \begin{macrocode}
              numnames #0
%<tennames>              #10 +
%<fifteennames>              #15 +
              >
%    \end{macrocode}
% If no appropriate |docstrip| option is given, the next expression will
% always be false (|nameptr| is always $>1$, see above). Thus the check is
% effectively disabled.
%    \begin{macrocode}
              nameptr #0
%<namesone>              #2 +
              =
              and
                {
%    \end{macrocode}
% list of names should be truncated, set formatted name to ``others''
%    \begin{macrocode}
                  "others" 't :=
                  #1 'namesleft :=
                }
                'skip$
              if$
              delimiter.default *
              namesleft #1 >
                { t * }
                {
%    \end{macrocode}
% check whether current name is ``others'', if so set formatted name
% to ``others''
%    \begin{macrocode}
                  s nameptr "{ll}" format.name$
                  duplicate$ "others" =
                    { 't := }
                    { pop$ }
                  if$
%    \end{macrocode}
% check whether formatted name is ``others'', if so print et al.
%    \begin{macrocode}
                  t "others" =
                    { bbl.etal * }
                    { t * }
                  if$
                }
              if$
            }
%    \end{macrocode}
% this is the first name
%    \begin{macrocode}
            't
          if$
          nameptr #1 + 'nameptr :=
          namesleft #1 - 'namesleft :=
        }
      while$
    }
  if$
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{get.bbl.editor}
% Return ``editors'' if |editor| contains more than one name, ``editor''
% otherwise.
%    \begin{macrocode}
FUNCTION {get.bbl.editor}
{
  editor num.names$ #1 >
    'bbl.editors
    'bbl.editor
  if$
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{get.bbl.erratum}
% Return the formatted string for ``erratum''.
%    \begin{macrocode}
FUNCTION {get.bbl.erratum}
{
  bbl.erratum
  ":" *
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{multi.page.check}
% Check whether the top string is only a single page or a range of pages.
%    \begin{macrocode}
FUNCTION {multi.page.check}
{
  't :=
  #0 'multiresult :=
    {
      multiresult not
      t empty$ not and
    }
    { t #1 #1 substring$
      duplicate$ "-" =
          swap$ duplicate$ "," =
          swap$ "+" =
          or or
        { #1 'multiresult := }
        { t #2 global.max$ substring$ 't := }
      if$
    }
  while$
  multiresult
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{get.bbl.page}
% Return a formatted prefix for pages.
%    \begin{macrocode}
FUNCTION {get.bbl.page}
{
  duplicate$ multi.page.check
    { bbl.pages }
    { bbl.page  }
  if$
%<ChemCommun|ChemEurJ|cv>  "." *
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{n.dashify}
% Replace a single ``|-|'' in a range of pages by ``|--|''.
%    \begin{macrocode}
FUNCTION {n.dashify}
{
  't :=
  ""
    { t empty$ not }
    {
      t #1 #1 substring$ "-" =
        {
          t #1 #2 substring$ "--" = not
            {
              "--" *
              t #2 global.max$ substring$ 't :=
            }
            {
%    \end{macrocode}
% there is more than one '|-|', therefore append all of them to the string
% on the stack
%    \begin{macrocode}
                { t #1 #1 substring$ "-" = }
                {
                  "-" *
                  t #2 global.max$ substring$ 't :=
                }
              while$
            }
          if$
        }
        {
%    \end{macrocode}
% the current char is not '|-|', therefore just append it
%    \begin{macrocode}
          t #1 #1 substring$ *
          t #2 global.max$ substring$ 't :=
        }
      if$
    }
  while$
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{select.language}
% \changes{0.1.3}{2006/07/27}{leave empty string on stack (replace pop\$ by
%   skip\$)}
% Return \LaTeX\ code for changing the language for the string
% on top of the stack.
%    \begin{macrocode}
FUNCTION {select.language}
{
  duplicate$ empty$
    'skip$
    {
      language empty$
        'skip$
        { "\foreignlanguage{" language * "}{" * swap$ * "}" * }
      if$
    }
  if$
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{space.word}
% This function puts spaces around a word.
%    \begin{macrocode}
FUNCTION {space.word}
{
  " " swap$ * " " *
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{str.to.int.warn}
% Print a warning if top string is not a representation of a valid integer
% (used by |str.to.int|).
%    \begin{macrocode}
FUNCTION {str.to.int.warn}
{
  "str.to.int: '" swap$ * "' is not a valid integer" * warning$
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{str.to.int}
% This function converts a string into an integer. A warning is issued if the
% string is not a valid representation of an integer.
%    \begin{macrocode}
FUNCTION {str.to.int}
{
  duplicate$ empty$
    {
      str.to.int.warn
      #0
    }
    {
%    \end{macrocode}
% assign the original string to |t| for parsing |t| from the end
%    \begin{macrocode}
      duplicate$ 't :=
%    \end{macrocode}
% check for sign
%    \begin{macrocode}
      t #1 #1 substring$ "-" =
        {
%    \end{macrocode}
% be sure that ``|-|'' is followed by at least one more character
%    \begin{macrocode}
          t #2 global.max$ substring$ 't :=
          t empty$
            {
              duplicate$ str.to.int.warn
              #0
            }
            { #-1 }
          if$
        }
        { #1 }
      if$
%    \end{macrocode}
% the top stack position contains now $-1$ or $1$ depending on sign\\
% |o| stores the offset for position inside the number
%    \begin{macrocode}
      #1 'o :=
%    \end{macrocode}
% push starting value on stack
%    \begin{macrocode}
      #0
        { t empty$ not}
        {
%    \end{macrocode}
% get last character
%    \begin{macrocode}
          t #-1 #1 substring$
          duplicate$ is.num
            {
%    \end{macrocode}
% character is in range [0--9], now multiply by offset and add to value already
% on stack
%    \begin{macrocode}
              chr.to.int$ #48 -
              o multiply
              +
%    \end{macrocode}
% remove last character from string, increment offset |o|
%    \begin{macrocode}
              t #-2 global.max$ substring$ 't :=
              o #10 multiply 'o :=
            }
            {
%    \end{macrocode}
% the last character was not a digit, therefore
% pop last character and sum
%    \begin{macrocode}
              pop$ pop$
%    \end{macrocode}
% swap sign and original string, duplicate string, print warning
%    \begin{macrocode}
              swap$ duplicate$ str.to.int.warn
%    \end{macrocode}
% swap original string and sign, push 0
%    \begin{macrocode}
              swap$ #0
%    \end{macrocode}
% break |while| loop
%    \begin{macrocode}
              "" 't :=
            }
          if$
        }
      while$
%    \end{macrocode}
% stack holds value and sign, multiply combines them
%    \begin{macrocode}
      multiply
%    \end{macrocode}
% pop copy of original string
%    \begin{macrocode}
      swap$ pop$
    }
  if$
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{tie.or.space.prefix}
% This function prepends a string with either a space or a ``|~|'' depending on
% the length of the string.
%    \begin{macrocode}
FUNCTION {tie.or.space.prefix}
{
  duplicate$ text.length$ #3 <
    { "~" }
    { " " }
  if$
  swap$
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{word.in}
% This function returns the word ``in'' followed by a space.
%    \begin{macrocode}
FUNCTION {word.in}
{
  bbl.in delimiter.blank *
}
%    \end{macrocode}
% \end{macro}
%
%
%
% \subsection{Field formatting functions}
%
% \begin{macro}{format.year.internal}
% This function applies all necessary formatting for a year on the stack.
%    \begin{macrocode}
FUNCTION {format.year.internal}
{
%<ChemEurJ|cv>  bolden
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{format.volume.internal}
% This function applies all necessary formating for a volume on the stack.
%    \begin{macrocode}
FUNCTION {format.volume.internal}
{
  duplicate$ empty$
    'skip$
    {
      bbl.volume
      swap$
      tie.or.space.prefix
%    \end{macrocode}
% stack (top-down): volume, tie/space, bbl.volume
%    \begin{macrocode}
      * *
    }
  if$
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{format.authors}
% This function formats the list of authors. If a |collaboration| field is
% present its contents is printed and the list of authors is appended in
% parentheses.
%    \begin{macrocode}
FUNCTION {format.authors}
{
  author "author" format.names
  duplicate$ empty$
    'skip$
    {
      collaboration bibinfo.check
      duplicate$ empty$
        'skip$
        { " (" * swap$ * ")" * }
      if$
      *
    }
  if$
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{format.booktitle}
% This function formats the title of a book and switches to an optional foreign
% language for this title.
%    \begin{macrocode}
FUNCTION {format.booktitle}
{
  booktitle bibinfo.check
  emphasize
  select.language
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{format.chapter}
% \changes{0.1.1}{2006/02/28}{added capitalize to bbl.chapter for JACS}
% This function formats a chapter. If a |type| field is present its contents is
% used as a prefix. If it is absent then the default (return value
% of |bbl.chapter|) will be % used.
%    \begin{macrocode}
FUNCTION {format.chapter}
{
  chapter bibinfo.check
  duplicate$ empty$
    'skip$
    {
      type bibinfo.check
      duplicate$ empty$
        { pop$ bbl.chapter }
        { "l" change.case$ }
      if$
%<JAmChemSoc|InorgChem>      capitalize
      swap$
%    \end{macrocode}
% stack (top-down): chapter, type/bbl.chapter
%    \begin{macrocode}
      tie.or.space.prefix
      * *
    }
  if$
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{format.date}
% This function formats the date of a citation. All currently supported styles
% only use the year. It is pushed onto the stack and |format.year.internal| is
% called to format it.
%    \begin{macrocode}
FUNCTION {format.date}
{
  year bibinfo.check
  format.year.internal
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{format.edition}
% This function formats the edition. It is converted into the appropriate
% english ordinal and the return value of |bbl.edition| will be appended.
%    \begin{macrocode}
FUNCTION {format.edition}
{
  edition bibinfo.check
  duplicate$ empty$
    'skip$
    {
      convert.edition
      output.state mid.sentence =
        { "l" }
        { "t" }
      if$ change.case$
      " " * bbl.edition *
%<ChemCommun|ChemEurJ|cv>      emphasize
    }
  if$
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{format.editors}
% \changes{0.2.3}{2008/01/17}{ACS does not print 'Eds.' if there are no
%   authors.}
% This function formats the list of editors.
%    \begin{macrocode}
FUNCTION {format.editors}
{
  editor "editor" format.names
  duplicate$ empty$
    'skip$
    {
%<JAmChemSoc|InorgChem>      author empty$
%<JAmChemSoc|InorgChem>        'skip$
%<JAmChemSoc|InorgChem>        {
%<JAmChemSoc|InorgChem>      "," *
      " " *
      get.bbl.editor
      capitalize
%<ChemCommun|ChemEurJ|cv>   "(" swap$ * ")" *
      *
%<JAmChemSoc|InorgChem>        }
%<JAmChemSoc|InorgChem>      if$
    }
  if$
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{format.in.booktitle}
% This function formats a booktitle an prepends it with ``in''.
%    \begin{macrocode}
FUNCTION {format.in.booktitle}
{
  format.booktitle
  duplicate$ empty$
    'skip$
    {
      word.in
%<JAmChemSoc|InorgChem>      capitalize
      swap$ *
    }
  if$
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{format.note}
% This function formats the |note| field of a citation. Since this is a free
% format field is content is used unchanged.
%    \begin{macrocode}
FUNCTION {format.note}
{
  note bibinfo.check
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{format.number.series}
% This function formats number and series if the |volume| field is empty.
%    \begin{macrocode}
FUNCTION {format.number.series}
{
  volume bibinfo.check
  duplicate$ empty$
    {
      number empty$
        { series bibinfo.check }
        {
          series empty$
            { number bibinfo.check }
            {
              output.state mid.sentence =
                { bbl.number }
                { bbl.number capitalize }
              if$
              number bibinfo.check tie.or.space.prefix * *
              word.in *
              series bibinfo.check *
            }
          if$
        }
      if$
    }
    'skip$
  if$
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{format.org.or.pub}
% This function formats an organization or publisher (on the stack) and its
% address.
%    \begin{macrocode}
FUNCTION {format.org.or.pub}
{
  't :=
  address empty$ t empty$ and
    { "" }
    {
      t
      address bibinfo.check
      duplicate$ empty$
        'pop$
        {
%<ChemCommun|ChemEurJ|cv>          cat.comma
%<JAmChemSoc|InorgChem>          cat.colon
        }
      if$
    }
  if$
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{format.organization.address}
% This function formats an organization and its address. It pushes
% the organization onto the stack and calls |format.org.or.pub|.
%    \begin{macrocode}
FUNCTION {format.organization.address}
{
  organization bibinfo.check
  format.org.or.pub
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{format.pages}
% This function formats a list of pages. The list is prepended with
% |bbl.page(s)|.
%    \begin{macrocode}
FUNCTION {format.pages}
{
  pages bibinfo.check
  duplicate$ empty$
    'skip$
    {
      n.dashify
      get.bbl.page
%    \end{macrocode}
% stack top-down: pages prefix, pages
%    \begin{macrocode}
      swap$
      tie.or.space.prefix *
      *
    }
  if$
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{format.publisher.address}
% This function formats a publisher and its address. It pushes
% the publisher onto the stack and calls |format.org.or.pub|.
%    \begin{macrocode}
FUNCTION {format.publisher.address}
{
  publisher "publisher" bibinfo.warn
  format.org.or.pub
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{format.thesis.type}
% This function formats the type of a thesis.
%    \begin{macrocode}
FUNCTION {format.thesis.type}
{
  type
  duplicate$ empty$
    'pop$
    {
      swap$ pop$
      "t" change.case$ bibinfo.check
    }
  if$
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{format.title}
% This function formats a title. It also switches the language temporarily.
%    \begin{macrocode}
FUNCTION {format.title}
{
  title bibinfo.check
  duplicate$ empty$
    'skip$
    {
      emphasize
      select.language
    }
  if$
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{format.tr.number}
% This function formats the number of a technical report.
%    \begin{macrocode}
FUNCTION {format.tr.number}
{
  number bibinfo.check
  type
  duplicate$ empty$
    { pop$ bbl.techrep }
    'skip$
  if$
  bibinfo.check
  swap$
  duplicate$ empty$
    { pop$ "t" change.case$ }
    { tie.or.space.prefix * * }
  if$
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{format.url}
% \changes{0.2.3}{2008/01/17}{Put URL into a new sentence.}
% This function formats an url. Each url is prefixed with \cs{urlprefix}. See
% section \ref{o::customization} for more information.
%    \begin{macrocode}
FUNCTION {format.url}
{
  url bibinfo.check
  duplicate$ empty$
    'skip$
    {
      "\urlprefix\url{" swap$ * "}" *
      new.sentence 'output.state :=
    }
  if$
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{format.volume}
% This function formats the |volume| field. It merely pushes the field's value
% onto the stack and calls |format.volume.internal| to format it.
%    \begin{macrocode}
FUNCTION {format.volume}
{
  volume bibinfo.check
  format.volume.internal
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{format.volume.and.series}
% This function will format the |volume| and |series|, but only if \emph{both}
% of them are not empty. Otherwise and empty string is returned.
%    \begin{macrocode}
FUNCTION {format.volume.and.series}
{
  volume empty$ series empty$ or
    { "" }
    {
      volume format.volume.internal
%    \end{macrocode}
% prepend "of"
%    \begin{macrocode}
      swap$ bbl.of space.word * swap$
      emphasize
      *
      "volume and number" number either.or.check
    }
  if$
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{format.volume.noseries}
% This function formats the volume. If the |series| field is non-empty an empty
% string is returned.
%    \begin{macrocode}
FUNCTION {format.volume.noseries}
{
  series empty$
    {
      volume bibinfo.check
      format.volume.internal
%<ChemCommun|ChemEurJ|cv>      emphasize
    }
    { "" }
  if$
}
%    \end{macrocode}
% \end{macro}
%
%
%
% \subsection{Functions related to cross-referenced entries}
%
% \begin{macro}{bibliography.cite}
% This function returns the string for citing the document the |crossref|
% field points to.
%    \begin{macrocode}
FUNCTION {bibliography.cite}
{
  "\bibliographycite{" swap$ * "}" *
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{format.crossref}
% This function formats the cross-reference.
%    \begin{macrocode}
FUNCTION {format.crossref}
{
  bbl.in " " *
%<JAmChemSoc|InorgChem>  capitalize
  crossref bibliography.cite *
}
%    \end{macrocode}
% \end{macro}
%
%
%
% \subsection{@article related funtions}
%
% \begin{macro}{format.article.cat.journal.year}
% \changes{0.2.0}{2006/07/27}{NEW}
% This function catenates the journal name and the year. It is used when
% formatting an erratum and/or articles in \emph{Angew.~Chem.}
%    \begin{macrocode}
FUNCTION {format.article.cat.journal.year}
{
%<ChemCommun>  cat.comma
%<ChemEurJ|cv|JAmChemSoc|InorgChem>  cat.blank
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{format.article.year.internal}
% This function provides all formatting required for an article which is not
% already done in |format.date.internal|.
%    \begin{macrocode}
FUNCTION {format.article.year.internal}
{
%<JAmChemSoc|InorgChem>  bolden
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{format.article.volume.internal}
% This function applies all necessary formatting to the volume an article is
% published in.
%    \begin{macrocode}
FUNCTION {format.article.volume.internal}
{
%<ChemCommun>  bolden
%<ChemEurJ|cv|JAmChemSoc|InorgChem>  emphasize
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{format.article.germanpages.volume.internal}
% This function is used while formatting citations of \emph{Angew.\ Chem.\
% Int.\ Ed.} It calculates the volume of the german edition from the volume of
% the english one (on the stack).
%    \begin{macrocode}
FUNCTION {format.article.germanpages.volume.internal}
{
  duplicate$ empty$
    'skip$
    {
      str.to.int
      duplicate$ #1 <
        {
          pop$
          "volume in " cite$ * " is not a positive integer value" * warning$
          ""
        }
        {
%    \end{macrocode}
% vol.~1 of the english edition corresponds to vol.~74 of the german one
%    \begin{macrocode}
          #73 +
          int.to.str$
          format.article.volume.internal
        }
      if$
    }
  if$
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{format.article.germanpages.pages.internal}
% This function applies all necessary formatting to pages of \emph{Angew.\
% Chem.}, the german edition of \emph{Angew.\ Chem.\ Engl.\ Ed.}
%    \begin{macrocode}
FUNCTION {format.article.germanpages.pages.internal}
{
  n.dashify
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{format.article.date}
% This function formats the date of an article.
%    \begin{macrocode}
FUNCTION {format.article.date}
{
  format.date
  format.article.year.internal
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{format.article.numpages}
% This function formats the number of pages of an article. The number of pages
% (|numpages| field) is only used in conjunction with an EID. The number of
% pages is assumed to be already on the stack.
%    \begin{macrocode}
FUNCTION {format.article.numpages}
{
  duplicate$ empty$
    'skip$
    {
      duplicate$ "1" =
        { "~" * bbl.eidp * }
        { "~" * bbl.eidpp * }
      if$
      "(" swap$ * ")" *
    }
  if$
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{format.article.eid}
% \changes{0.2.4}{2008/03/18}{Include number of pages only for style 'cv'}
% This function formats the EID of an article.
%    \begin{macrocode}
FUNCTION {format.article.eid}
{
  eid bibinfo.check
  duplicate$ empty$
    'pop$
    {
      cat.comma
%<cv>      numpages bibinfo.check
%<cv>      format.article.numpages
%<cv>      cat.blank
    }
  if$
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{format.article.journal}
% This function formats the journal an article was published in.
%    \begin{macrocode}
FUNCTION {format.article.journal}
{
  journal bibinfo.check
  duplicate$ empty$
    'skip$
    { emphasize }
  if$
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{format.article.germanpages.journalname}
% This function formats \emph{Angew.\ Chem.} as the name of the german version
% of \emph{Angew.\ Chem.\ Int.\ Ed.}
%    \begin{macrocode}
FUNCTION {format.article.germanpages.journalname}
{
  "Angew.\ Chem."
  emphasize
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{format.article.erratum.germanpages.pages}
% This function is used for an erratum in \emph{Angew.\ Chem.\ Int.\ Ed.} It
% formats the pages of the german version.
%    \begin{macrocode}
FUNCTION {format.article.erratum.germanpages.pages}
{
  erratumgermanpages bibinfo.check
  format.article.germanpages.pages.internal
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{format.article.erratum.year}
% This function formats the year an erratum was published.
%    \begin{macrocode}
FUNCTION {format.article.erratum.year}
{
  erratumyear bibinfo.check
  format.year.internal
  format.article.year.internal
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{format.article.erratum.germanpages.volume}
% This function is used for an erratum in \emph{Angew.\ Chem.\ Int.\ Ed.} It
% formats the erratum's volume in the german version.
%    \begin{macrocode}
FUNCTION {format.article.erratum.germanpages.volume}
{
  erratumvolume "erratumvolume" bibinfo.warn
  format.article.germanpages.volume.internal
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{format.article.erratum.germanpages}
% \changes{0.2.0}{2006/07/27}{Use format.article.cat.journal.year}
% This function formats the german version of an erratum published in
% \emph{Angew.\ Chem.\ Int.\ Ed.}
%    \begin{macrocode}
FUNCTION {format.article.erratum.germanpages}
{
  erratumgermanpages empty$
    { "" }
    {
      format.article.germanpages.journalname
      format.article.erratum.year format.article.cat.journal.year
      format.article.erratum.germanpages.volume cat.comma
      format.article.erratum.germanpages.pages cat.comma
    }
  if$
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{format.article.erratum.journal}
% This function formats the journal of an erratum. Normally this is the same
% journal the original article was published in.
%    \begin{macrocode}
FUNCTION {format.article.erratum.journal} { format.article.journal }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{format.article.erratum.pages}
% This function formats the pages of an erratum.
%    \begin{macrocode}
FUNCTION {format.article.erratum.pages}
{
  erratumpages bibinfo.check
  n.dashify
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{format.article.erratum.eid}
% This function formats the EID of an erratum.
%    \begin{macrocode}
FUNCTION {format.article.erratum.eid}
{
  erratumeid bibinfo.check
  erratumnumpages bibinfo.check format.article.numpages *
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{format.article.erratum.volume}
% This function formats the volume of an erratum.
%    \begin{macrocode}
FUNCTION {format.article.erratum.volume}
{
  erratumvolume bibinfo.check
  format.article.volume.internal
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{format.article.erratum}
% \changes{0.2.0}{2006/07/27}{Use format.article.cat.journal.year}
% This function formats an erratum of an article.
% The erratum will be formatted if one of  |erratumyear|, |erratumvolume|,
% |erratumpages| or |erratumeid| is present.
%    \begin{macrocode}
FUNCTION {format.article.erratum}
{
  erratumyear bibinfo.check empty$
      erratumvolume bibinfo.check empty$ and
      erratumpages bibinfo.check empty$ and
      erratumeid bibinfo.check empty$ and
    { "" }
    {
%    \end{macrocode}
% An erratum was detected.
% Since at least one field is present, ``erratum:'' can already be printed.
%    \begin{macrocode}
      get.bbl.erratum
      format.article.erratum.journal cat.blank
      format.article.erratum.year format.article.cat.journal.year
      format.article.erratum.volume cat.comma
      erratumeid empty$
        { format.article.erratum.pages }
        { format.article.erratum.eid }
      if$
      cat.comma
      format.article.erratum.germanpages cat.semicolon
    }
  if$
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{format.article.germanpages.pages}
% This function formats the pages of the german version of an article in
% \emph{Angew.\ Chem.\ Int.\ Ed.}
%    \begin{macrocode}
FUNCTION {format.article.germanpages.pages}
{
  germanpages bibinfo.check
  format.article.germanpages.pages.internal
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{format.article.germanpages.volume}
% This function formats the volume of the german version of an article in
% \emph{Angew.\ Chem.\ Int.\ Ed.} It pushes the volume of the english version
% onto the stack and calls |format.article.germanpages.volume.internal| which
% automatically calculates and formats the german volume.
%    \begin{macrocode}
FUNCTION {format.article.germanpages.volume}
{
  volume "volume" bibinfo.warn
  format.article.germanpages.volume.internal
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{format.article.germanpages.year}
% This function formats the year of the german version of an article in
% \emph{Angew.\ Chem.\ Int.\ Ed.} This is always the same as the english
% version.
%    \begin{macrocode}
FUNCTION {format.article.germanpages.year} { format.article.date }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{format.article.germanpages}
% \changes{0.2.0}{2006/07/27}{Use format.article.cat.journal.year}
% This function formats the german version of an article in \emph{Angew.\
% Chem.\ Int.\ Ed.}
%    \begin{macrocode}
FUNCTION {format.article.germanpages}
{
  germanpages empty$
    { "" }
    {
      format.article.germanpages.journalname
      format.article.germanpages.year format.article.cat.journal.year
      format.article.germanpages.volume cat.comma
      format.article.germanpages.pages cat.comma
    }
  if$
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{format.article.pages}
% This function formats the pages of an article.
%    \begin{macrocode}
FUNCTION {format.article.pages}
{
%    \end{macrocode}
% The stack contains whatever is the text directly preceding pages.
%    \begin{macrocode}
  pages
  duplicate$ empty$
    'pop$
    {
%    \end{macrocode}
% Check whether preceding string is empty.
%    \begin{macrocode}
      swap$
      duplicate$ empty$
%    \end{macrocode}
% If the preceding string is empty, pop it and the pages from stack and call
% |format.pages|. This means that |pages| is the only text so far (except
% bibitem).
%    \begin{macrocode}
        { pop$ pop$ format.pages }
%    \end{macrocode}
% The preceding string is not empty. Therefore format the pages and append
% them.
%    \begin{macrocode}
        {
          swap$
          n.dashify
          cat.comma
        }
      if$
    }
  if$
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{format.article.title}
% \changes{0.1.2}{2006/05/3}{NEW}
% This function formats the title of an article.
%    \begin{macrocode}
FUNCTION {format.article.title}
{
  title bibinfo.check
  duplicate$ empty$
    'skip$
    {
      new.sentence 'output.state :=
    }
  if$
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{format.article.volume.and.number}
% This function formats the volume an article was published in. Optionally it
% appends the issue to the volume.
%    \begin{macrocode}
FUNCTION {format.article.volume.and.number}
{
  volume bibinfo.check
  duplicate$ empty$
    'skip$
    { bibinfo.check }
  if$
  format.article.volume.internal
%<*number>
  number bibinfo.check
  duplicate$ empty$
    'skip$
    {
      swap$
      duplicate$ empty$
        { "there's a number but no volume in " cite$ * warning$ }
        'skip$
      if$
      swap$
      "(" swap$ * ")" *
    }
  if$
  *
%</number>
}
%    \end{macrocode}
% \end{macro}
%
%
%
% \subsection{@book related functions}
%
% \begin{macro}{format.book.authors}
% This function formats the authors of a book. If no authors were given, the
% editors are used instead.
%    \begin{macrocode}
FUNCTION {format.book.authors}
{
  author empty$
    { format.editors }
    {
      format.authors
      "author and editor" editor either.or.check
    }
  if$
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{format.book.editors}
% This function formats the editors of a book. If the book has no authors then
% the editors were already given as a substitute for the authors. In this case,
% nothing is printed, since the editors should not be given twice.
%    \begin{macrocode}
FUNCTION {format.book.editors}
{
  author empty$
    { "" }
    { format.editors }
  if$
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{format.book.volume.internal}
% This function formats the volume of a book.
%    \begin{macrocode}
FUNCTION {format.book.volume.internal}
{
  volume bibinfo.check
  duplicate$ empty$
    'skip$
    {
      tie.or.space.prefix *
      bbl.volume swap$ *
    }
  if$
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{format.book.volume.and.series}
% This function formats the volume of a book and the series it is part of. For
% this function to produce any non-empty output both |volume| and |series| must
% be non-empty. To format the volume without a series the
% |format.book.volume.noseries| function is used (see below).
%    \begin{macrocode}
FUNCTION {format.book.volume.and.series}
{
  series bibinfo.check
  duplicate$ empty$
    'skip$
    {
%<ChemCommun|ChemEurJ|cv>      emphasize
%    \end{macrocode}
% Now the formatted series is on the stack.
%    \begin{macrocode}
      format.book.volume.internal
%<ChemCommun|ChemEurJ|cv>      bbl.of space.word *
%    \end{macrocode}
% stack top-down: formatted volume; formatted series
%    \begin{macrocode}
%<ChemCommun|ChemEurJ|cv>      swap$ *
%<JAmChemSoc|InorgChem>      cat.comma
    }
  if$
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{format.book.volume.noseries}
% This function formats the volume of a book if the |series| field is empty.
%    \begin{macrocode}
FUNCTION {format.book.volume.noseries}
{
  series empty$ not
    { "" }
    {
      format.book.volume.internal
%<ChemCommun|ChemEurJ|cv>      emphasize
    }
  if$
}
%    \end{macrocode}
% \end{macro}
%
%
%
% \subsection{@misc related functions}
%
% \begin{macro}{misc.empty.check}
% This function checks whether fields of an |@misc| entry are empty and issues
% a warning.
%    \begin{macrocode}
FUNCTION {misc.empty.check}
{
  author empty$ title empty$ howpublished empty$
  month empty$ year empty$ note empty$ url empty$
  and and and and and and
    { "all relevant fields are empty in " cite$ * warning$ }
    'skip$
  if$
}
%    \end{macrocode}
% \end{macro}
%
%
%
% \subsection{@program related functions}
%
% \begin{macro}{format.program.description}
% This function formats the description of a program. It also temporarily
% switches the language.
%    \begin{macrocode}
FUNCTION {format.program.description}
{
  description bibinfo.check
  duplicate$ empty$
    'skip$
    { select.language }
  if$
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{format.program.publisher.address}
% This function formats the publisher of a program and its address.
%    \begin{macrocode}
FUNCTION {format.program.publisher.address}
{
  publisher bibinfo.check
  format.org.or.pub
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{format.program.title}
% This function formats the title of a program.
%    \begin{macrocode}
FUNCTION {format.program.title}
{
  title "title" bibinfo.warn
  duplicate$ empty$
    'skip$
    {
      "t" change.case$
      " " swap$ *
      capitalize
      emphasize
    }
  if$
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{format.program.version}
% This function formats the version of a program.
%    \begin{macrocode}
FUNCTION {format.program.version}
{
  version
}
%    \end{macrocode}
% \end{macro}
%
%
% \subsection{Entry types}
%
% \begin{macro}{article}
% \mbox{}
%    \begin{macrocode}
FUNCTION {article}
{
  output.bibitem
  format.authors "author"
%<ChemCommun|ChemEurJ|cv>  output.check
%<JAmChemSoc|InorgChem>  output.check.blank
%<cv>  format.article.title "title" output.check
%<cv>  new.sentence 'output.state :=
  format.article.journal "journal"
%<ChemCommun|ChemEurJ|cv>  output.check
%<JAmChemSoc|InorgChem>  output.check.blank
  format.article.date "year"
%    \end{macrocode}
% If you change the way journal name and publication year are catenated, do not
% forget to change |format.article.cat.journal.year|.
%    \begin{macrocode}
%<ChemCommun>  output.check
%<ChemEurJ|cv|JAmChemSoc|InorgChem>  output.check.blank
  format.article.volume.and.number output.comma
  eid empty$
    { format.article.pages }
    { format.article.eid }
  if$
  format.article.germanpages output.semicolon
  format.article.erratum output.semicolon
  format.note output
  fin.entry
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{book}
% \mbox{}
%    \begin{macrocode}
FUNCTION {book}
{
  output.bibitem
  format.book.authors "author and editor" output.check
  format.title "title"
%<ChemCommun|ChemEurJ|cv>  output.check.comma
%<JAmChemSoc|InorgChem>  output.check.blank
  format.edition
%<ChemCommun|ChemEurJ|cv>  output.blank
%<JAmChemSoc|InorgChem>  output.comma
%<JAmChemSoc|InorgChem>  format.book.editors output.semicolon
  format.book.volume.and.series output
%<ChemCommun|ChemEurJ|cv>  format.book.volume.noseries output
%<ChemCommun|ChemEurJ|cv>  format.book.editors output.comma
  format.publisher.address output
  format.date "year" output.check.comma
%<JAmChemSoc|InorgChem>  format.volume.noseries output.semicolon
  format.note output
  fin.entry
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{booklet}
% \mbox{}
%    \begin{macrocode}
FUNCTION {booklet}
{
  output.bibitem
  format.authors output
  format.title "title" output.check
  howpublished bibinfo.check output
  address bibinfo.check output
  format.date output
  format.note output
  fin.entry
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{inbook}
% \mbox{}
%    \begin{macrocode}
FUNCTION {inbook}
{
  output.bibitem
  format.book.authors "author and editor" output.check
  crossref missing$
    {
      format.title "title"
%<ChemCommun|ChemEurJ|cv>      output.check.comma
%<JAmChemSoc|InorgChem>      output.check.blank
      format.edition
%<ChemCommun|ChemEurJ|cv>      output.blank
%<JAmChemSoc|InorgChem>      output.comma
%<JAmChemSoc|InorgChem>      format.book.editors output.semicolon
      format.book.volume.and.series output
%<ChemCommun|ChemEurJ|cv>      format.book.volume.noseries output
%<ChemCommun|ChemEurJ|cv>      format.book.editors output.comma
      format.publisher.address output
      format.date "year" output.check.comma
%    \end{macrocode}
% The \emph{J.~Am.\ Chem.\ Soc.} requires ``; volume, chapter, pages''.
% To handle empty entries gracefully we cat them together and write the entire
% string afterwards.
%    \begin{macrocode}
%<JAmChemSoc|InorgChem>      format.volume.noseries
%<ChemCommun|ChemEurJ|cv>      ""
    }
    {
      format.crossref output.blank
%    \end{macrocode}
% Push an empty string since there will not be a volume.
%    \begin{macrocode}
      ""
    }
  if$
  format.chapter cat.comma
  format.pages cat.comma
  output
  format.note output
  fin.entry
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{incollection}
% \changes{0.2.1}{2007/02/28}{Added title for style cv}
% \mbox{}
%    \begin{macrocode}
FUNCTION {incollection}
{
  output.bibitem
  format.authors "author" output.check
%<cv>  format.title "title" output.check
  crossref missing$
    {
      format.in.booktitle "booktitle" output.check.blank
      format.edition
%<ChemCommun|ChemEurJ|cv>      output.blank
%<JAmChemSoc|InorgChem>      output.comma
%<JAmChemSoc|InorgChem>      format.book.editors output.semicolon
      format.book.volume.and.series output
%<ChemCommun|ChemEurJ|cv>      format.book.volume.noseries output
%<ChemCommun|ChemEurJ|cv>      format.book.editors output.comma
      format.publisher.address output
      format.date "year" output.check.comma
%    \end{macrocode}
% The \emph{J.~Am.\ Chem.\ Soc.} requires ``; volume, chapter, pages''.
% To handle empty entries gracefully we cat them together and write the entire
% string afterwards.
%    \begin{macrocode}
%<JAmChemSoc|InorgChem>      format.volume.noseries
%<ChemCommun|ChemEurJ|cv>      ""
    }
    {
      format.crossref output.blank
%    \end{macrocode}
% Push an empty string since there will not be a volume.
%    \begin{macrocode}
      ""
    }
  if$
  format.chapter cat.comma
  format.pages cat.comma
  output
  format.note output
  fin.entry
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{inproceedings}
% \changes{0.2.1}{2007/02/27}{Added title for style cv}
% \changes{0.2.1}{2007/02/28}{Fixed formating of volume and series}
% \mbox{}
%    \begin{macrocode}
FUNCTION {inproceedings}
{
  output.bibitem
  format.authors "author" output.check
%<cv>  format.title "title" output.check
  crossref missing$
    {
      format.in.booktitle "booktitle" output.check.blank
      publisher empty$
        { format.organization.address output }
        {
          organization bibinfo.check output
          format.publisher.address output
        }
      if$
      format.book.volume.and.series output
    }
    { format.crossref output.blank }
  if$
  format.pages "pages" output.check
  format.note output
  format.url output
  fin.entry
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{manual}
% \mbox{}
%    \begin{macrocode}
FUNCTION {manual}
{
  output.bibitem
  author empty$
    {
      organization bibinfo.check
      duplicate$ empty$
        'pop$
        {
          output
          address bibinfo.check output
        }
      if$
    }
    { format.authors output }
  if$
  format.title "title" output.check
  author empty$
    {
      organization empty$
        { address bibinfo.check output }
        'skip$
      if$
    }
    {
      organization bibinfo.check output
      address bibinfo.check output
    }
  if$
  format.edition output
  format.date output
  format.note output
  format.url output
  fin.entry
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{mastersthesis}
% \mbox{}
%    \begin{macrocode}
FUNCTION {mastersthesis}
{
  output.bibitem
  format.authors "author" output.check
  bbl.mthesis format.thesis.type output
  school "school" bibinfo.warn output
  address bibinfo.check output
  format.date "year" output.check
  format.note output
  format.url output
  fin.entry
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{misc}
% \mbox{}
%    \begin{macrocode}
FUNCTION {misc}
{
  output.bibitem
  format.authors output
  format.title output
  howpublished bibinfo.check output
  format.date output
  format.note output
  format.url output
  fin.entry
  misc.empty.check
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{phdthesis}
% \changes{0.2.1}{2007/02/27}{Added title for style cv}
% \mbox{}
%    \begin{macrocode}
FUNCTION {phdthesis}
{
  output.bibitem
  format.authors "author" output.check
%<cv>  format.title "title" output.check
  bbl.phdthesis format.thesis.type output
  school "school" bibinfo.warn output
  address bibinfo.check output
  format.date "year" output.check
  format.note output
  format.url output
  fin.entry
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{proceedings}
% \mbox{}
%    \begin{macrocode}
FUNCTION {proceedings}
{
  output.bibitem
  editor empty$
    { organization bibinfo.check output }
    { format.editors output }
  if$
  format.title "title" output.check
  format.volume output
  format.number.series output
  editor empty$
    {
      publisher empty$
        'skip$
        { format.publisher.address output }
      if$
    }
    {
      publisher empty$
        { format.organization.address output }
        {
          organization bibinfo.check output
          format.publisher.address output
        }
      if$
     }
  if$
%<ChemCommun|ChemEurJ|cv>  format.date "year" output.check
  format.note output
  format.url output
  fin.entry
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{program}
% \changes{0.2.3}{2008/01/17}{ACS does not like a delimiter after last author
%    name}
% \mbox{}
%    \begin{macrocode}
FUNCTION {program}
{
  output.bibitem
  format.authors output
  format.program.title "title"
%<ChemCommun|ChemEurJ|cv>  output.check
%<JAmChemSoc|InorgChem>  output.check.blank
  format.program.description output.comma
  format.program.version output
%<ChemCommun|ChemEurJ|cv>  format.date output
  format.program.publisher.address output
%<JAmChemSoc|InorgChem>  format.date output.comma
  format.note output
  format.url output
  fin.entry
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{techreport}
% \mbox{}
%    \begin{macrocode}
FUNCTION {techreport}
{
  output.bibitem
  format.authors "author" output.check
  format.title
  "title" output.check
  format.tr.number output
  institution "institution" bibinfo.warn output
  address bibinfo.check output
  format.date "year" output.check
  format.note output
  format.url output
  fin.entry
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{unpublished}
% \mbox{}
%    \begin{macrocode}
FUNCTION {unpublished}
{
  output.bibitem
  format.authors "author" output.check
  format.title "title" output
  format.date output
  format.note "note" output.check
  format.url output
  fin.entry
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{conference}
% |conference| is an alias for |inproceedings|.
%    \begin{macrocode}
FUNCTION {conference} { inproceedings }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{default.type}
% The default type is |misc|.
%    \begin{macrocode}
FUNCTION {default.type} { misc }
%    \end{macrocode}
% \end{macro}
%
%
%
% \subsection{Main program}
%
% \begin{macro}{begin.bib}
% This function starts the bibliography by opening the |thebibliography|
% environment.
%    \begin{macrocode}
FUNCTION {begin.bib}
{
  "\begin{thebibliography}{"  longest.label  * "}" * write$ newline$
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{end.bib}
% This function ends the bibliography by closing the |thebibliography|
% environment.
%    \begin{macrocode}
FUNCTION {end.bib}
{
  newline$
  "\end{thebibliography}" write$ newline$
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{initialize.longest.label}
% This function sets up the variables for the longest label.
%    \begin{macrocode}
FUNCTION {initialize.longest.label}
{
  "" 'longest.label :=
  #1 'number.label :=
  #0 'longest.label.width :=
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{init.consts}
% \changes{0.1.2}{2006/05/03}{Added new.sentence initialization}
% This function sets up some constant used while formatting the bibliography.
%    \begin{macrocode}
FUNCTION {init.consts}
{
  #0 'before.all :=
  #1 'mid.sentence :=
  #2 'new.sentence :=
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{longest.label.pass}
% This function is used to determine the length of the longest label.
% It checks whether the current label is longer than the current longest label.
% If so, it updates |longest.label.width|.
%    \begin{macrocode}
FUNCTION {longest.label.pass}
{
  number.label int.to.str$ 'label :=
  number.label #1 + 'number.label :=
  label width$ longest.label.width >
    {
      label 'longest.label :=
      label width$ 'longest.label.width :=
    }
    'skip$
  if$
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{write.babel.misc}
% This function writes the default definitions of some commands used in
% formatting a citation.
%    \begin{macrocode}
FUNCTION {write.babel.misc}
{
  "\providecommand{\bbland}{and}" write$ newline$
  "\providecommand{\bblchap}{chap.}" write$ newline$
  "\providecommand{\bblchapter}{chapter}" write$ newline$
  "\providecommand{\bbletal}{et~al.}" write$ newline$
  "\providecommand{\bbleditors}{editors}" write$ newline$
  "\providecommand{\bbleds}{eds.}" write$ newline$
  "\providecommand{\bbleditor}{editor}" write$ newline$
  "\providecommand{\bbled}{ed.}" write$ newline$
  "\providecommand{\bbledition}{edition}" write$ newline$
  "\providecommand{\bbledn}{ed.}" write$ newline$
  "\providecommand{\bbleidp}{page}" write$ newline$
  "\providecommand{\bbleidpp}{pages}" write$ newline$
  "\providecommand{\bblerratum}{erratum}" write$ newline$
  "\providecommand{\bblin}{in}" write$ newline$
  "\providecommand{\bblmthesis}{Master's thesis}" write$ newline$
  "\providecommand{\bblno}{no.}" write$ newline$
  "\providecommand{\bblnumber}{number}" write$ newline$
  "\providecommand{\bblof}{of}" write$ newline$
  "\providecommand{\bblpage}{page}" write$ newline$
  "\providecommand{\bblpages}{pages}" write$ newline$
  "\providecommand{\bblp}{p}" write$ newline$
  "\providecommand{\bblphdthesis}{Ph.D. thesis}" write$ newline$
  "\providecommand{\bblpp}{pp}" write$ newline$
  "\providecommand{\bbltechrep}{Tech. Rep.}" write$ newline$
  "\providecommand{\bbltechreport}{Technical Report}" write$ newline$
  "\providecommand{\bblvolume}{volume}" write$ newline$
  "\providecommand{\bblvol}{Vol.}" write$ newline$
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{write.babel.months}
% This function writes the default names of the months.
%    \begin{macrocode}
FUNCTION {write.babel.months}
{
  "\providecommand{\bbljan}{January}" write$ newline$
  "\providecommand{\bblfeb}{February}" write$ newline$
  "\providecommand{\bblmar}{March}" write$ newline$
  "\providecommand{\bblapr}{April}" write$ newline$
  "\providecommand{\bblmay}{May}" write$ newline$
  "\providecommand{\bbljun}{June}" write$ newline$
  "\providecommand{\bbljul}{July}" write$ newline$
  "\providecommand{\bblaug}{August}" write$ newline$
  "\providecommand{\bblsep}{September}" write$ newline$
  "\providecommand{\bbloct}{October}" write$ newline$
  "\providecommand{\bblnov}{November}" write$ newline$
  "\providecommand{\bbldec}{December}" write$ newline$
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{write.babel.ordinals}
% This function writes the default names of the ordinals.
%    \begin{macrocode}
FUNCTION {write.babel.ordinals}
{
  "\providecommand{\bblfirst}{First}" write$ newline$
  "\providecommand{\bblfirsto}{1st}" write$ newline$
  "\providecommand{\bblsecond}{Second}" write$ newline$
  "\providecommand{\bblsecondo}{2nd}" write$ newline$
  "\providecommand{\bblthird}{Third}" write$ newline$
  "\providecommand{\bblthirdo}{3rd}" write$ newline$
  "\providecommand{\bblfourth}{Fourth}" write$ newline$
  "\providecommand{\bblfourtho}{4th}" write$ newline$
  "\providecommand{\bblfifth}{Fifth}" write$ newline$
  "\providecommand{\bblfiftho}{5th}" write$ newline$
  "\providecommand{\bblst}{st}" write$ newline$
  "\providecommand{\bblnd}{nd}" write$ newline$
  "\providecommand{\bblrd}{rd}" write$ newline$
  "\providecommand{\bblth}{th}" write$ newline$
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{write.babel}
% This function writes the default of all words used for formatting a citation.
%    \begin{macrocode}
FUNCTION {write.babel}
{
  write.babel.misc
  write.babel.months
  write.babel.ordinals
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{write.commands}
% \changes{0.2.1}{2007/02/28}{Replaced newcommand by providecommand for
%    capitalize}
% This function writes the commands used in a citation.
%    \begin{macrocode}
FUNCTION {write.commands}
{
  "\providecommand{\url}[1]{\texttt{#1}}" write$ newline$
  "\providecommand{\urlprefix}{}" write$ newline$
  "\providecommand{\foreignlanguage}[2]{#2}" write$ newline$
  "\providecommand{\Capitalize}[1]{\uppercase{#1}}" write$ newline$
  "\providecommand{\capitalize}[1]{\expandafter\Capitalize#1}" write$ newline$
  "\providecommand{\bibliographycite}[1]{\cite{#1}}" write$ newline$
  write.babel
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{write.header}
% This function writes the header of the |.bbl| file. It does not, however,
% start the |thebibliography| environment. The contents of |@preamble| is
% always written first.
%    \begin{macrocode}
FUNCTION {write.header}
{
  preamble$ empty$
    'skip$
    { preamble$ write$ newline$ }
  if$
  write.commands
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{main}
% Read all required entries from the database. The entries are in citation
% order.
%    \begin{macrocode}
READ
%    \end{macrocode}
% Determine the length of the longest label.
%    \begin{macrocode}
EXECUTE {initialize.longest.label}
ITERATE {longest.label.pass}
%    \end{macrocode}
% Write the header to the file and open the |thebibliography| environment.
%    \begin{macrocode}
EXECUTE {init.consts}
EXECUTE {write.header}
EXECUTE {begin.bib}
%    \end{macrocode}
% Format all entries
%    \begin{macrocode}
ITERATE {call.type$}
%    \end{macrocode}
% Close the |thebibliography| environment.
%    \begin{macrocode}
EXECUTE {end.bib}
%    \end{macrocode}
% \end{macro}
%
%
%
% \Finale
% \PrintChanges
% \setcounter{IndexColumns}{2}
% \PrintIndex
