% \iffalse meta-comment
%
% opcit - bibliographical references as footnotes.
% Copyright 2002 Federico Garcia (feg8@pitt.edu, fedegarcia@hotmail.com)
% -------------------------------------------
% 
%
% This program can be redistributed and/or modified under the terms
% of the LaTeX Project Public License distributed from CTAN archives
% in the directory macros/latex/base/lppl.txt; either version 1 of
% the License, or (at your option) any later version.
%
%
%<*driver>
% \fi
\ProvidesFile{opcit.dtx}[2002/12/25 v1.1 Footnote references]
% \iffalse
\documentclass{ltxdoc}
\GetFileInfo{opcit.dtx}
\title{\texttt{opcit} (version 2.0)\\a package for footnote-style bibliographical references}
\date{\filedate{}}
 \author{Federico Garcia\\\texttt{feg8@pitt.edu}}
\begin{document}
\maketitle
 \DocInput{\filename}
\end{document}
%</driver>
% \fi
%
%\tableofcontents
%
%\section{New features in version 2}
%
%Users of |opcit| that are familiar with the package will be interested in the following new features:
%
%\begin{itemize}
%\item The bug that used to forbid constructions like |\cite[pp| has been fixed, so you no longer need to type |\cite[p{}p| or |\cite[p\relax p|.
%\item The bibliography style has been fully recoded, and it is more complete now.
%\item Cross-referencing has been implemented, both between bibliographical entries (so that an article in a book makes reference to the book) and between footnotes (so that `\emph{op.~cit.}' is a hyperlink to the footnote where the work was first cited, or alternatively a reference can be made to the footnote number).
%\item A way to omit information in the footnotes (but still list it in the final list) is now available. Using this you can avoid the annoying repetition potential to |@INCOLLECTION| entries, like `\dots\ pages 1--20, p.~13'.
%\item |opcit| now checks whether the optional argument to an \emph{Idem}-citation is identical to the last one, in whose case omits it. This prevents things like two consecutive footnotes both saying `\emph{Idem}, p.~13'. Also, appearance of `\emph{Idem}' only happens if it was the immediately previous footnote that referred to the work.
%\item Global and local mechanisms are provided for turning off either or both `\emph{Idem}' or `\emph{op.~cit.}'\ (substituting |hereafter|'s).
%\end{itemize}
%
%These new features are implemented as options to the package. This means that the previous way to load the package, with a custom \textsc{Bib}\TeX\ style as an option, has changed. See section~\ref{loading} below.
%
%\bigskip
%\noindent This second release of |opcit| owes its existence to both the encouragement and the suggestions I got from John~Scott, the first |opcit| user I knew of (that wasn't an acquaintance of mine).
%
%\section{Introduction}
%
%The basic bibliography styles of \LaTeXe\ and \textsc{Bib}\TeX, with labels between [~and~], are very foreign to the common uses of humanities-writing. In recent times, the category of bibliographical styles known as `author-date' seems to have gained acceptance and become the standard way to refer to a final list of references. This category of styles has been successfully implemented in \LaTeX\ and \textsc{Bib}\TeX, for example in formidable packages such as |natbib|, |achicago|, and |harvard|. 
%
%However, certain disciplines still use the `old way' of footnote-referencing, above all in journal articles, which do not have a final list of `References' to which a key can refer. Author-year styles have the significant drawback that the labels interfere with the flow of the discourse, both in writing and in reading; and, as Susan~King and Oren~Patashnik point out in their `Editorial note' in the |apalike.bst| file, the main reason to use them (that changes to the bibliography does not mean ``changing numbers in both references and text") is rendered meaningless by computerized typography. The `footnote category' of bibliographical styles has not been directly addressed by \LaTeX\ package-writers before |opcit|.
%
%Actually, there \emph{is} a package intended to place the bibliography as footnotes, namely |footbib|.\footnote{By Eric Domenjoud, 1995.} In this package, the labels appear as superscripts---$^{[1]}$---and the information about the source is appended to the bottom of the page. This style is a kind of `hybrid' between footnote and label styles: the numbering of the citations is independent from the footnotes, and if other footnotes (not bibliography ones) appear, they appear separated from the citations.
%
%The system provided by |opcit| makes the references footnotes in the full sense. As is customary in this kind of style, it keeps track of the sources already been cited, in order to avoid multiple copies of the same, potentially long, footnote. So, for `post-citations' (a later citation of a work already cited), it makes automatic use of conventions such as \emph{Idem} and \emph{op.~cit.}---which gives the package its name---or allows the user to set `hereafters' to repeatedly refer to the same publication. 
%
%\bigskip
%\noindent What I regret most about this package is that I was not able to make it `|bst|-independent,' i.e., able to run with any \textsc{Bib}\TeX\ style that the user could possibly want to use. (This, for example, is one of the good things about |footbib|.) The main reason why this was not possible is that |bst| files are designed to print the information in a list, not as footnotes, inserting, for example, periods instead of commas, and giving the author names with last-name first. 
%
%The \textsc{Bib}\TeX\ style I provide in this version is much more complete than that in the first one. However, I have maintained the premise that new styles can be created by the users. To that end, I have greatly expanded the comments to the code of |opcit.bst| below, so its adaptation is easier. As usual, any modification is welcome as long as the file name is changed. Also, if you are creating a new style, I would like to (collaborate and) consider it for inclusion in the |opcit| distribution.
%
%\section{Use}
%
%\subsection{Loading the package}\label{loading}
%
%As usual, you have to load the package with 
%
%|\usepackage[|\meta{options}|]{opcit}|
%
%\noindent The \meta{options}, all new to the second version, are:
%\begin{center}\begin{tabular}{lp{9cm}}\hline
%|custombst| & Allows the user to issue a \verb"\bibliographystyle" command to change the \textsc{Bib}\TeX used by default.\\
%|nocustombst| & To use the default style. This is of course the default option.\\\hline
%|hyperref| & Makes the expression `\emph{op.~cit.}' (or the one set by the user) a hyperlink to the first citation of the reference. Default if the \texttt{hyperref} package has been loaded before |opcit|; otherwise, it is not default.\\
%|nohyperref| & No hyperlinks. Default when package \texttt{hyperref} is not loaded.\\\hline
%|omitting| & Omits certain information, such as pages, volume, series, etc., from the footnotes (you can of course control what is omitted and what is not). Selected by default.\\
%|noomitting| & Turns off the omission mechanism altogether.\\\hline
%|idemcheck| & Checks for identical \emph{Idem}-citations, omitting the optional argument. Selected by default.\\
%|noidemcheck| & Turns off the check.\\\hline
%\end{tabular}\end{center}
%
%See below for detailed information on the effects of these options.
%
%\subsection{Citations}
%\DescribeMacro{\cite}
%The user keeps citing with |\cite|. Thus, |\cite{texbook}| will produce the footnote `\footnote{Donald E. Knuth, \emph{The \TeX book} (Reading, Mass.: Addison Wesley, 1986).}'. The optional argument has the usual meaning, so for example, |\cite[p.~100]{taruskin}| creates `\footnote{Richard Taruskin, \emph{Defining Russia musically: Historical and Hermeneutical Essays} (Princeton: Princeton University Press, 1997), p.~100.}'.
%
%Note that |opcit| adds a period at the end of the footnotes; however, if the user adds it (for example, in |\cite[Introduction.]{gellner}|), it will not: `\footnote{Ernest Gellner, \emph{Thought and change} (Chicago: University of Chicago Press, 1964), introduction.}'. It will also avoid it after `?' or `!'; in general, after any character with a |\sfcode| equal to the one of the period. (This is lost in |\frenchspacing| and similar situations, where |opcit| has no way to `see' the period, and will \emph{always} add one.)
%
%A |\cite| command can also occur within the argument of a |\footnote|. In that case, the information on the source is added to the text of the footnote, with \emph{no} period added.\footnote{This is because it is assumed that the user will always `close' the footnote with a final period. Issuing here \texttt{\textbackslash cite\{martinb\}}, which produces Jes\'us Mart\'{\i}n-Barbero, \emph{Communication, culture, and hegemony: From media to mediations} (London: SAGE Publications, 1993), I do not want |opcit| to add a period.}
%
%The starred \DescribeMacro{\cite*}version of |\cite| omits the author's name from the footnote. So: Gellner expanded one of the ideas presented from his mentioned book in a later study.|\cite*{gellner2}|\footnote{\emph{Nations and Nationalism} (Ithaca: Cornell University Press, 1983).}
%
%\subsection{Post-citations}
%Post-citations---later citations of an already cited work---behave differently. For example, a new citation of the \TeX book through |\cite{texbook}| will not render the whole footnote text again, but rather `\footnote{Knuth, \emph{op.~cit.}}'. The author name has been reduced to the last-name, and the rest of the information is replaced by `\emph{op.~cit.}' Again, the period is appropriately handled: no period is added to the one at the end of this expression. But in the case of |\cite[p.~101]{taruskin}|, it is added: `\footnote{Taruskin, \emph{op.~cit.}, p.~101.}'. You can also use |\cite*| to hide the author's name for \emph{op.~cit.}-citations.
%
%This is not good when there are several works by the same author, in whose case |opcit| has no way to know which one is meant at each point. This is handled with the `hereafter' mechanism (section~\ref{hereafter}).
%
%\bigskip
%\noindent Another kind of situation arises when the same work is cited \emph{consecutively}. In that case, the corresponding footnote(s) will say `\emph{Idem}'. In principle, this will be followed by the optional argument, if any. \marginpar{\raggedleft\textsf{New Feature}}However, if two \emph{Idem}-citations have the same optional argument, the second time it will \emph{not} be typeset. \DescribeMacro{nocheckidem}(This can be turned off with the |nocheckidem| option.) In any case, a final period will be added if needed. 
%
%Thus, a further citation here of Taruskin's book (the one that was cited last in the previous paragraph), through |\cite[p.~xxi]{taruskin}|, renders `\footnote{\emph{Idem}, p.~xxi.}'. If the same command (|\cite[p.~xxi]{taruskin}|) is issued again, the footnote will be `\footnote{\emph{Idem}.}', with no `p.~xxi' in it.
%
%Since an \emph{Idem}-citation will always hide the author's name, use of |\cite*| in those situations has has no special effect.
%
%\bigskip
%\noindent As a reader,\marginpar{\raggedleft\textsf{New feature}} I have had the annoying experience of needing to find a reference for which the footnote to the page says only `Barto\v s: \emph{op.~cit.}' You are forced carefully to look through all the previous footnotes in search of the whole information. It was thus very nice to come across a book\footnote{Jamie C. Kassler: \emph{Music, Science, Philosophy: Models in the Universe of Thought} (Aldershot, Burlington, Singapore and Sydney: Ashgate, 2001).} with footnote references, but in which any post-citations indicated the footnote in which the work was first cited---something like `(note 14).' I then decided to implement this in |opcit|.
%
%\DescribeMacro{\bibref}So, command |\bibref{|\meta{key}|}| produces the number in which the \meta{key} reference was |\cite|'d for the first time. (If the reference has not been |\cite|'d before, however, there will be an error message.) You can use |\bibref| anywhere, in the main text, as the optional argument to a |\cite|, or in a footnote. For example, you can post-cite the \TeX Book with |\cite[note~\bibref]{texbook}|, or |\footnote{\cite{texbook} (see footnote \bibref above).}|, etc. In the first case you would get `\footnote{Knuth, \emph{op.~cit.}, note 2.}'. 
%
%\DescribeMacro{hyperref}The footnote number printed by |\bibref| (either a manual or an automatic one) will be a hyperlink if the |hyperref| option is in place. In fact, this option provides satisfactory cross-referencing with hyperlinks: the `\emph{op.~cit.}' expression itself will be a hyperlink if this option is chosen.
%
%The |hyperref| option is in force by default if the |hyperref| package has been loaded (before |opcit|). If the package is loaded, but hyperlinks for citations are not desired, they can be turned off with the |nohyperref| option to |opcit|.
%
%\subsubsection{Extra control}\label{extra}
%
%\DescribeMacro{\resetcites}In long documents, for example books with chapters, it might be desirable to reset the citations so that they are again fully cited in the footnotes (even if they were already cited, say, in a previous chapter). This is done with the command |\resetcites|. It affects all the entries in the bibliography database.
%
%\DescribeMacro{\cited}The contrary procedure---to make the next citation of a work a post-citation, with \emph{op.~cit.} instead of the full information---is possible for individual entries: |\cited{|\meta{key1}|,|\meta{key2}|,|\dots|}| will make |opcit| pretend that the entries in the argument were already cited. This is particularly useful with cross references among entries (see section~\ref{crossrefs}).
%
%\subsection{Customization}
%The user can change \DescribeMacro{\opcittext}\DescribeMacro{\idemtext}the expressions `\emph{op.~cit.}' and `\emph{Idem}' by |\renewcommand|'ing the |\opcittext| and |\idemtext| commands, respectively.
%
%\subsection{The `herafter' mechanism}\label{hereafter}
%
%\DescribeMacro{hereafter = ""}When two or more works by the same author are |\cite|'d, the \emph{op.~cit.}\ mechanism is not reliable. The user should then provide a `\texttt{hereafter}' value for each work by the same author in the \texttt{bib} file. Then, |opcit| will use the value of this entry in the place of \emph{op.~cit.} 
%
%For example, if Gellner's mentioned books had \texttt{hereafter} entries of |"T{\&}C"| and |"N{\&}N"|, respectively, the commands |\cite{gellner}| and |\cite{gellner2}| would produce `\footnote{Gellner: \emph{T\&C}.}' and `\footnote{Gellner: \emph{N\&N}.}' (of course, from the second time these works are cited on). Note that the strings were emphasized. The starred version |\cite*| still hides the author's name, and the `\emph{Idem}' mechanism will apply if any of the works is |\cite|'d for the second time in a row.
%
%If no \texttt{hereafter} entry is found (and there are several references by the same author), a warning will be issued, and the deliberately unacceptable expression \emph{?Op.?Cit.?} substituted. 
%
%The value of \texttt{hereafter}, that replaces `\emph{op.~cit.},' will be a hyperlink if the |hyperref| option is on.
%
%\DescribeMacro{\hereafter}
%The |\hereafter| command typesets the \texttt{hereafter} string of the last |\cite|'d work, so that we can say something like 
%
%\begin{verbatim}
%\footnote{See \cite{gellner}; hereafter I will refer to this text as 
%\hereafter.}
%\end{verbatim}
%
%This mechanism can be used also for single works of a particular author. The result of |\hereafter| is \emph{not} a hyperlink.
%
%\subsection{Omitting text from the footnotes}\label{omits}
%
%Sometimes\marginpar{\raggedleft\textsf{New Feature}} it is desirable to omit some part of the bibliographical information from the footnotes, keeping it on the final references list. \DescribeMacro{\toomit}This is now allowed by |opcit| through the command |\toomit|. You use it in the |.bib| file, like this:
%
%\begin{verbatim}
%address = "Aldershot\toomit{, Burlington, Singapore and Sydney}",
%\end{verbatim}
%
%\noindent The effect is that the argument of |\toomit| will be typeset in the final references list, but not in the footnotes.
%
%Typical cases when this is useful are:
%\begin{itemize}
%\item Long addresses (example above).
%\item Long titles: {\ttfamily title = "The Prisoner of Zenda|\toomit{|: being the story of three months in the life of an English gentleman|}|"}.
%\item Some translated titles: {\ttfamily title = "Music and Discourse|\toomit{| [Musicologie g|{\'e}|n|{\'e}|rale et s|{\'e}|miologie]|}|"}.
%\end{itemize}
%
%A special case of omission concerns page numbers for articles in journals or books. Since the page numbers for articles usually go at the end of the reference, they could clash with the optional argument to |\cite| (something like a `pages~1--20, p.~13'). This cannot be fixed with |\toomit|, because the particle `pages' is added by \textsc{Bib}\TeX, so it's not susceptible of |\toomit|. The same is true of the \texttt{volume}, the \texttt{series}, and \texttt{number} of a |@BOOK| entry, among others. 
%
%The solution is that |opcit| omits these fields altogether from the footnotes (they still appear in the final bibliography list). 
%
%This is the default behavior, but it can be overriden. \DescribeMacro{\with}The |\with{|\meta{field}|}| command forces the \meta{field} of the next reference to appear, even if it would by default be omitted. So, for example, to get a footnote that does include the pages of an article, you type |\with{pages}\cite{foo}|. Similarly, the \texttt{volume} of a book can be `de-omitted' by typing |\with{volume}\cite{foobook}|.
%
%Several |\with| commands can go in succession. For example, if you want the page numbers of the article from a collected edition, \emph{and} the volume of the book that contains, you can say |\with{pages}\with{volume}\cite{book}|.
%
%The scope of |\with| is only the next |\cite| (each |\cite| sets all default omissions back on). On the other hand, nothing happens if a |\cite| does not have the \meta{field} that was requested with |\with|. 
%
%
%A more sophisticated version of |\toomit| allows the user to use |\with| in connection with it. |\toomit[|\meta{category}|]{|\meta{text}|}| will by default omit the \meta{text} (from the footnotes), but it could be forced typing |\with[|\meta{category}|]|. Note that the \meta{category} is not a \textsc{Bib}\TeX\ field.
%
%For example,
%\begin{verbatim}
%title = "Music and discourse: Toward a semiology of 
%   music\toomit[translation]{\ [Musicologie 
%   g{\'e}n{\'e}ral et s{\'e}miologie]}"
%\end{verbatim}
%
%\noindent the translation will by default be omitted in the footnote, but there will be a |\with{translation}| that will include it.
%
%\DescribeMacro{noomitting}You can turn off the omissions by specifying the |noomitting| option to the package. In that case, the commands |\toomit| and |\with| have no effect.
%
%
%\subsection{The final references list}
%
%The command |\bibliography| has the usual effect of producing a final section (or chapter) for `References.' According to the \textsc{Bib}\TeX\ style used, the format of the entries is different in the references list from the footnotes. 
%
%\marginpar{\raggedleft\textsf{New Feature}}Frequently, a document with bibliographical references in footnote style does not include a final references list. \DescribeMacro{\nobibliography}But the user has to tell |opcit| where to find the \textsc{Bib}\TeX\ database, which is done by the |\bibliography| command. So there is now a |\nobibliography| that works just like |\bibliography| but produces no list. The command takes the file name(s) of the database(s) as its argument.
%
%Bear in mind that if you use |\nobibliography| instead of |\bibliography|, some information that is by default omitted from the footnotes (see section~\ref{omits}) might be completely lost. |opcit| emits a warning of this in the \texttt{log} file. 
%
%\section{The \textsc{Bib}\TeX\ style}\label{bstyle}
%
%The  \textsc{Bib}\TeX\ style (|opcit.bst|) that comes with this version~2 of |opcit| is fairly complete, but this does not mean that it can handle every conceivable combination of different pieces of information in any bibliographical reference. I have provided the standard entry types, and the fields are also about the same as in standard styles (with the notable addition of |hereafter|, discussed in section~\ref{hereafter}). So I repeat the \emph{caveat} of Oren~Patashnik: be creative in the use of entries and fields, and you will be able to achieve pretty much anything.\footnote{It is never a bad idea to read Patashnik's ``\textsc{Bib}\TeX ing'' (February 8, 1988),  file \texttt{btxdoc.dvi} in \LaTeX\ standard distribution.}
%
%For example: rather than providing a field for |translation|, which would imply provision of a host of additional fields---|datetranslated|, |original|, |translator|, \dots---and would not be used very often, I have relied on the user's judicious use of fields like |note| and |howpublished|. The following conventions are true of all entry types without exception:
%\begin{itemize}
%\item \texttt{howpublished} is printed \emph{immediately after} \texttt{edition}. 
%\item \texttt{note} is printed \emph{at the end of an entry}. It is also omitted from the footnotes (but can be retrieved with |\with{note}|).
%\end{itemize}
%
%\subsection{Cross referencing}\label{crossrefs}
%
%\DescribeMacro{crossref = ""}Cross referencing through the |crossref| field has been fully implemented in version~2. Its exact behavior depends on whether a reference is being cited in a footnote, or it appears in the final list.
%
%Consider, for example, the entry
%
%\begin{verbatim}
%@INCOLLECTION{derrida,
%  title = "Deconstruction and actuality",
%  author = "Jacques Derrida",
%  crossref = "postmodern",
%  pages="75--78"
%  }
%\end{verbatim}
%
%If there is a |\cite{derrida}| in the document, the result will be equivalent to having typed: {\ttfamily|\footnote{|Jacques Derrida, ``Deconstruction and actuality,'' in |\cite{postmodern}.}|}
%
%The last |\cite| is added automatically by \texttt{opcit}, as a result of the \texttt{crossref} field. Its output will be either a full citation of the book, or an `\emph{op.~cit.}'\ expression, depending on whether the book has already been cited or not.
%
%The citation that results from the |crossref| field will by default \emph{not} count as the first citation of that entry (``\texttt{postmodern}'' in the example). This means that a later citation of this same entry (be it by itself or within another cross reference) will expand the full information again. The command |\cited| (section~\ref{extra}) can be used to override this and make future citations of the cross reference be of the \emph{op.~cit.} type.
%
% In addition, \emph{Idem} is disabled for it. However, post-citations of the main reference (``\texttt{derrida}'') are not affected at all by the cross~reference mechanism, and will use the regular `\emph{op.~cit.}' or `\emph{Idem}' expressions. 
%
%\bigskip\noindent
%In the final references list, the effect of the |crossref| field is more familiar: the entry will get the information for the missing fields from the entry that is being cross-referenced, just as in a standard \textsc{Bib}\TeX\ style.
%
%\subsection{Other tools}
%
%The new field |hereafter| has already been explained (section~\ref{hereafter}), as well as the use of |\toomit| (section~\ref{omits}). Other features will be introduced in this section.
%
%\DescribeMacro{\bibpunctuation}The |\bibpunctuation| command expands into a comma in the footnotes, but into a period in the final references list. It is internally used by |opcit.bst| to separate the different pieces of information within an entry, and the user can use it just as well.
%
%Use of |\bibpunctuation| is likely to need complement for the capitalization of what follows. After a comma, things should start lowercase; after a period, uppercase. This ambiguous case has been conceived for |opcit| as the `bibliography-case,' and implemented in the command \marginpar{\raggedleft\textsf{New Feature}}\DescribeMacro{\bibcase}|\bibcase|. You can insert it anywhere and it will make the first letter of the following word either lower- or uppercase. For example, |opcit.bst| inserts |\bibcase| before the particle `in' of an |@INCOLLECTION| entry. Applying braces, like in |\bibcase{paideia}|, would capitalize or de-capitalize the whole argument.
%
%\DescribeMacro{\bibcite}If you have to know it all, the implementation of |crossref| described in the previous section is made through the |\bibcite| command. It takes two arguments: the label to cite within the citation, and the whole information to be typeset in the final list. You can directly use this command in any field.
%
%\subsection{The entry types}
%
%The |opcit| \textsc{Bib}\TeX\ style accepts the same entry types as the standard styles. Below you find examples of each of the entry types in both footnote and final-list layout, as well as explicit lists of omitted fields (see section~\ref{omits}).
%
%\subsubsection{Book}
%Omitted fields: \texttt{volume} and \texttt{series} (recovered by |\with{volume}|); \texttt{number} and \texttt{series} (|\with{number}|); \texttt{note} (|\with{note}|).
%
%\noindent\hrulefill\ 1\ \hrulefill
%
%\begin{verbatim}
%@BOOK{berlinsky,
%    author="David Berlinsky",
%    title="Newton's Gift\toomit{: How Sir Isaac Newton
%        Unlocked the System of the World}",
%    publisher="Simon {\&} Schuster",
%    address="New~York and London",
%    year="2000"}
%\end{verbatim}
%The first footnote for this entry would read: 
%\begin{quotation}\small\noindent
%David Berlinsky, \emph{Newton's Gift} (New York and London: Simon \& Schuster, 2000).
%\end{quotation}
%In the final reference list, the entry looks like:
%\begin{quotation}\noindent
%\makebox[2.5em][r]{Berlinsky}, David. \emph{Newton's Gift: How Sir Isaac Newton Unlocked the System of the World}. New York and London: Simon \& Schuster, 2000.
%\end{quotation}
%
%\noindent\hrulefill\ 2\ \hrulefill
%
%\begin{verbatim}
%@BOOK{tac,
%    author="Ernest Gellner",
%    title="Thought and Change",
%    series="``The Nature of Human Society'' Series (ed.\ 
%      Julian Pitt-Rivers and Ernest Gellner) Press",
%    number="1",
%    year="1964",
%    address="Chicago",
%    publisher="University of Chicago"}
%\end{verbatim}
%Footnote layout:
%\begin{quotation}\small\noindent
%Ernest Gellner, \emph{Thought and Change} (Chicago: University of Chicago Press, 1964).
%\end{quotation}
%For the final-list of this and the rest of the examples see page~\pageref{examples} (footnote-layout is illustrated in the main text).
%
%\noindent\hrulefill\ 3\ \hrulefill
%
%\begin{verbatim}
%@BOOK{walker,
%    title="The Final Years 1861--1886",
%    volume="3",
%    series="Franz Liszt",
%    author="Alan Walker",
%    publisher="Alfred A. Knopf",
%    address="New York",
%    year="1996"}
%\end{verbatim}
%Footnote layout:
%\begin{quotation}\small\noindent
%Alan Walker, \emph{The Final Years 1861--1886} (New York: Alfred A. Kopf, 1996).
%\end{quotation}
%\noindent This is a case in which you might prefer typing |\with{volume}\cite{walker}|, with the following effect:
%\begin{quotation}\small\noindent
%Alan Walker, \emph{The Final Years 1861--1886}, volume 3 of \emph{Franz Liszt} (New York: Alfred A. Kopf, 1996).
%\end{quotation}
%
%\subsubsection{Article}
%
%Omitted fields: \texttt{pages}, \texttt{month}, \texttt{note}.
%
%\noindent\hrulefill\ 1\ \hrulefill
%
%\begin{verbatim}
%@ARTICLE{sheldon,
%    author="David A. Sheldon",
%    title="The Galant Style Revisited and Re-Evaluated",
%    journal="Acta Musicologica",
%    volume="47",
%    number="2",
%    year="1975",
%    pages="240--70"}
%\end{verbatim}
%Footnote layout:
%\begin{quotation}\small\noindent David A. Sheldon, ``The Galant Style Revisited and Re-Evaluated,'' \emph{Acta Musicologica} 47/2 (1975).\end{quotation}
%
%\noindent\hrulefill\ 2\ \hrulefill
%
%\begin{verbatim}
%@ARTICLE{nattiez,
%    author="{Jean-Jacques} Nattiez and Isabelle Schulte-Technoff",
%    title="L'etnomusicologia: strutturalismo o culturalismo?\toomit{ 
%        Intervista con Jean-Jacques Nattiez di Isabelle Schulte-Technoff}",
%    journal="Musica/Realt{\`a}",
%    volume="61",
%    pages="109--131",
%    year="2000",
%    month="March"}
%\end{verbatim}
%Footnote layout:
%\begin{quotation}\small\noindent Jean-Jacques Nattiez and Isabelle Schulte-Technoff, ``L'etnomusicologia: strutturalismo o culturalismo?,'' \emph{Musica/Realt\`a} 61 (2000).\end{quotation}
%
%\noindent Or, alternatively, |\with{month}\with{pages}\cite{nattiez}| produces:
%\begin{quotation}\small\noindent Jean-Jacques Nattiez and Isabelle Schulte-Technoff, ``L'etnomusicologia: strutturalismo o culturalismo?,'' \emph{Musica/Realt\`a} 61 (March 2000): 109--131.\end{quotation}
%
%\subsubsection{Incollection}
%For articles in an edited book. For use with \textsc{Bib}\TeX\ cross-reference (\texttt{crossref}) see examples 2ff.
%
%Omitted fields: \texttt{pages}, \texttt{chapter}, \texttt{note}.
%
%\noindent\hrulefill\ 1\ \hrulefill
%
%\begin{verbatim}
%@INCOLLECTION{laudan,
%    title="Explaining the Success of Science\toomit{: Beyond 
%         Epistemic Realism and Relativism}",
%    author="Larry Laudan",
%    booktitle="Science and the Quest for Reality",
%    editor="Alfred I. Tauber",
%    address="London",
%    publisher="MacMillan Press Ltd.",
%    pages="137--161",
%    year="1997"}
%\end{verbatim}
%Footnote layout:
%\begin{quotation}\small\noindent Larry Laudan, ``Explaining the Success of Science,'' in Alfred I. Tauber (ed.), \emph{Science and the Quest for Reality} (London: MacMillan Press Ltd., 1997).\end{quotation}
%
%\bigskip\noindent\hrulefill\ 2\ \hrulefill
%
%Given the following entry:
%\begin{verbatim}
%@BOOK{grove,
%   booktitle="Grove Music Online",
%   editor="L. Macy",
%   url="http://www.grovemusic.com/"}
%\end{verbatim}
%another entry can make reference to it:
%\begin{verbatim}
%@INCOLLECTION{weber,
%    title="Weber, Gottfried",
%    author="Janna K. Saslaw",
%    crossref="grove",
%    urldate="October 5, 2005"}
%\end{verbatim}
%Then, citation of the latter in the footnotes will |\cite| the former. The layout of this `nested' |\cite| will depend on the kind of entry it is (usually a book), and might also be \emph{op.~cit.}, if it has already been cited. In this case the result is:
%\begin{quotation}\small\noindent Janna K. Saslaw, ``Weber, Gottfried,'' in L. Macy (ed.), \emph{Grove Music Online},
%\texttt{http://www.grovemusic.com/} (accessed October 5, 2005).\end{quotation}
%
%\subsubsection{Inbook}
%For individual chapters or articles from books by a single author.
%
%Omitted fields: \texttt{pages}, \texttt{chapter}, \texttt{note}.
%
%\noindent\hrulefill\ 1\ \hrulefill
%\begin{verbatim}
%@INBOOK{stuff,
%   title="The Stuff of Change",
%   booktitle="Thought and Change",
%   pages="126--146",
%   chapter="6",
%   crossref="tac"}
%\end{verbatim}
%This entry makes reference to the first example of \texttt{@BOOK} to create the following footnote:
%\begin{quotation}\small\noindent Ernest Gellner, ``The Stuff of Change,'' chapter 6 of \emph{op.~cit.}\end{quotation}
%This would work best if the book entry had a field for \texttt{hereafter}, creating something like ``chapter 6 of \emph{Thought and Change}.'' On the other hand, |\with{pages}| adds ``\dots chapter 6 (pages 126--146) of\dots''
%
%\bigskip\noindent\hrulefill\ 2\ \hrulefill
%   
%\begin{verbatim}
%@INBOOK{attemborough,
%    author="David Attenborough",
%    title="The Infinite Variety",
%    type="Episode",
%    chapter="1",
%    booktitle="Life on Earth\toomit{ \upshape (videorecording)}",
%    publisher="BBC",
%    year="1979"}
%\end{verbatim}
%Footnote layout:
%\begin{quotation}\small\noindent David Attemborough, ``The Infinite Variety,'' episode~1 of \emph{Life on Earth} (BBC, 1979).\end{quotation}
%\subsubsection{PHDthesis}
%
%Omitted fields: \texttt{note}.
%
%\begin{verbatim}
%@PHDTHESIS{saslaw,
%    author="Janna K. Saslaw",
%    title="Gottfried Weber and the Concept of Mehrdeutigkeit",
%    school="Columbia University",
%    year="1992"}
%\end{verbatim}
%Footnote layout:
%\begin{quotation}\small\noindent Janna K. Saslaw, \emph{Gottfried Weber and the Concept of Mehrdeutigkeit} (Ph.\,D.\ diss.), Columbia University, 1992.\end{quotation}
%
%\subsubsection{Mastersthesis}
%
%Analogous to \texttt{phdthesis}, but with `M.\,A. thesis' instead of `Ph.\,D. diss.'
%
%\subsubsection{Proceedings}
%
%Essentially equivalent to |@BOOK|. One difference is the possible presence of |organization| (which only gets typeset if |editor| is missing); another is that there is no |edition|.
%
%\subsubsection{Booklet}
%
%This entry type behaves exactly as |@BOOK|. 
%
%\subsubsection{Inproceedings}
%
%|@INPROCEEDINGS| is to |@PROCEEDINGS| what |@INCOLLECTION| is to |@BOOK|: there is no |edition|, and |organization| can replace |editor|. Otherwise the behavior is similar.
%
%\subsection{Modifying the bibliography style}\label{bsts}
%
%This section makes explicit the conventions that a \textsc{Bib}\TeX\ style (a \texttt{bst} file) should follow in order to support and be supported by |opcit|.
%
%The basic form of a |opcit|-supported |\bibitem| is:
%
%|\bibitem{|\meta{label}|}|
%
%|\biblastnames{|\meta{last name(s)}|}|
%
%\meta{\dots additional declarations\dots}
%
%|\opcitstart |\meta{name(s)}|\bibpunctuation \newblock|
%
%\meta{remaining info}
%
%|\opcitends|
%
%\smallskip
%As long as this scheme is strictly followed, |opcit| will run.\footnote{This can be easily achieved in the style by suitably modifying the |{bibstart}| and |{fin.entry}| functions.} 
%
%The style has therefore to have a method of finding out only the last name(s) of author/editor, to be passed to |opcit| as the argument to |\biblastname|. This is independent from the actual formatting of the names (that happens right before the first |\bibpunctuation|).
%
%Other conventions are probably always needed, but not syntactically required:
%\begin{itemize}
%\item Instead of periods or commas, the style should append |\bibpunctuation| commands (this command is converted into commas in the footnotes, into periods in the references list).
%\item |\bibcase| commands should be added at strategic points (the particle `in' for \texttt{@INCOLLECTION}s, and in general everything that comes after a |\bibpunctuation|). 
%\item \DescribeMacro{\sameauthors}If the style substitutes a line for repeated author(s)' name(s), |opcit| needs a way to know the `real' author. This is achieved by the style not typesetting the line by itself, but rather appending a |\sameauthors| command (defined by |opcit| as a rule of length |\sameauthorsrule|). 
%\item \DescribeMacro{\bibhereafter}The style should provide for handling of the |hereafter| field: its contents (if any) should be passed on to |opcit| as the argument to |\bibhereafter|, as part of the \meta{additional declarations}. 
%\end{itemize}
%
%Another kind of tools are those that are not hard-wired in |opcit|, but whose use is more or less mandatory with footnote-style referencing. For example, it is customary that the author's name appears, in the footnotes, as first-last name (`Ernest~Gellner'), and as last-first (`Gellner, Ernest') in the final list. This is more a feature of the |bst| than of |opcit| itself, so it is supposed to be implemented there. As a result, it should be implemented in any \textsc{Bib}\TeX\ intended for use with |opcit|.
%
%This is done by making the |bst| itself define and use its own commands, advisably at the beginning of the |bbl| file, usually in the |{begin.bib}| function. 
%
%Typically, these definitions will make use of |opcit|'s \DescribeMacro{\newBibCommand}|\newBibCommand|:
%
%|\newBibCommand{|\meta{command name}|}{|\meta{footnote-style}|{|\meta{list-style}|}|
%
%This means that the new command will expand to the first meaning when encountered in footnotes, and to the second when in the final list. Use of arguments with |\newBibCommand| is surprisingly intuitive, and is illustrated in the items below.
%
%|opcit.bst| defines five tools in this way:
%\begin{itemize}
%\item|\bibparenthesis| should parenthesize its argument when in footnotes, but typeset it (after a period) in the final list. This is used for the publisher and the year of books: `(London: Penguin, 1989)' but `. London: Penguin, 1989'. This command is defined with 
%
%\hfill|\newBibCommand{\bibparenthesis[1]}{ (#1)}{. \newblock #1}|.
% 
%Later, the |{make.address.publisher.year}| function of the |bst| makes use of this command.
%\item |\newBibCommand{\SwapNames[2]}{#1 #2}{#2, #1}| implements the ordering of names. The author/editor name then is issued as, for example, |\SwapNames{Ernest}{Gellner}|.
%\item |\bibincite| and |\bibincitestar| are the commands used by the |bst| file to implement cross references between entries. In their definition, they use internal |opcit| commands. I would recommend to copy them from |opcit.bst|, and in any case simply to \emph{add} stuff to them. Leave the |\recover@last| alone, unless you know what you are doing!
%
%\item |\GobbleOrNot| is used to gobble (or not) the punctuation mark when a period ends the previous text. For example, the middle initial in `Donald E. Knuth' would clash with |\bibpunctuation| in the final reference list: `Knuth, Donald~E..\ \emph{The \TeX book}.' But the period has to be included in the footnote (Donald E. Knuth, \emph{The \TeX book}'). Similarly, the particle `Ph.\,D.\ diss.' has to gobble the following period in the final list, but not the closing parenthesis in the footnotes. Thus, |\GobbleOrNot| is defined as
%
%\hfill|\newBibCommand{\GobbleOrNot}{\relax}{\newblock\@gobble}|
%\end{itemize}
%
%\newcommand\bibparenthesis[1]{. \newblock #1}
%\newcommand\bibincite[2]{#2}
%\newcommand\bibincitestar[2]{#2}
%\newcommand\SwapNames[2]{#2, #1}
%\newcommand\GobbleOrNot{\newblock\@gobble}
%\def\biblastnames#1{}\let\opcitstart\relax\def\bibpunctuation{.}\def\bibcase#1{\uppercase{#1}}\let\toomit\relax
%\makeatletter
%\renewenvironment{thebibliography}[1]
%     {\section*{The final list (examples)}
%      \list{}%
%           {\setlength\labelwidth{\z@}%
%            \leftmargin\bibindent
%            \itemindent -\bibindent
%            \parsep \z@
%            \@openbib@code
%            \usecounter{enumiv}%
%            \let\p@enumiv\@empty
%            \renewcommand\theenumiv{\@arabic\c@enumiv}}%
%      \sloppy
%      \clubpenalty4000
%      \@clubpenalty \clubpenalty
%      \widowpenalty4000%
%      \sfcode`\.\@m}
%     {\def\@noitemerr
%       {\@latex@warning{Empty `thebibliography' environment}}%
%      \endlist}
%\makeatother
%\let\opcitend\relax\def\sameauthors{\rule{23pt}{0.4pt}}
%\begin{thebibliography}{}\label{examples}
%
%\bibitem{attemborough}
%\biblastnames{Attenborough}
%\opcitstart \SwapNames{David}{Attenborough}\bibpunctuation
%\newblock ``The Infinite Variety\bibpunctuation''
%\newblock \bibcase Episode 1 of {\em Life on Earth\toomit{ \upshape
%  (videorecording)}}\bibparenthesis{BBC, 1979}\opcitend
%
%\bibitem{berlinsky}
%\biblastnames{Berlinsky}
%\opcitstart \SwapNames{David}{Berlinsky}\bibpunctuation
%\newblock {\em Newton's Gift\toomit{: How Sir Isaac Newton Unlocked the System
%  of the World}}\bibparenthesis{New~York and London: Simon {\&} Schuster,
%  2000}\opcitend
%
%\bibitem{stuff}
%\biblastnames{Gellner}
%\opcitstart \SwapNames{Ernest}{Gellner}\bibpunctuation
%\newblock ``The Stuff of Change\bibpunctuation''
%\newblock \bibcase chapter 6\toomit[pages]{ (pages 126--146)} of
%  \bibincitestar{tac}{{\em Thought and Change}}\opcitend
%
%\bibitem{tac}
%\biblastnames{Gellner}
%\opcitstart \sameauthors\bibpunctuation
%\newblock {\em Thought and Change}\toomit[number]{\bibpunctuation\bibcase
%  \bibcase number~1 in ``The Nature of Human Society'' Series (ed.\ Julian
%  Pitt-Rivers and Ernest Gellner) Press}\bibparenthesis{Chicago: University of
%  Chicago, 1964}\opcitend
%
%\bibitem{laudan}
%\biblastnames{Laudan}
%\opcitstart \SwapNames{Larry}{Laudan}\bibpunctuation
%\newblock ``Explaining the Success of Science\toomit{: Beyond Epistemic Realism
%  and Relativism}\bibpunctuation''
%\newblock \bibcase in {Alfred~I. Tauber (ed.), {\em Science and the Quest for
%  Reality}\bibparenthesis{London: MacMillan Press Ltd.,
%  1997}}\toomit[pages]{\bibcase :  137--161}\opcitend
%
%\bibitem{nattiez}
%\biblastnames{Nattiez and Schulte-Technoff}
%\opcitstart \SwapNames{{Jean-Jacques}}{Nattiez} and Isabelle
%  Schulte-Technoff\bibpunctuation
%\newblock ``L'etnomusicologia: strutturalismo o culturalismo?\toomit{
%  Intervista con Jean-Jacques Nattiez di Isabelle
%  Schulte-Technoff}\bibpunctuation''
%\newblock {\em Musica/Realt{\`a}} 61 (\toomit[month]{March
%  }2000)\toomit[pages]{\bibcase :  109--131}\opcitend
%
%\bibitem{weber}
%\biblastnames{Saslaw}
%\opcitstart \SwapNames{Janna~K.}{Saslaw}\GobbleOrNot\bibpunctuation
%\newblock ``Weber, Gottfried\bibpunctuation''
%\newblock \bibcase in \bibincite{grove}{L. Macy (ed.), {\em Grove Music
%  Online}\bibpunctuation
%\newblock \texttt{http://www.grovemusic.com/} (accessed October 5, 2005)}\opcitend
%
%\bibitem{saslaw}
%\biblastnames{Saslaw}
%\opcitstart \sameauthors\bibpunctuation
%\newblock {\em Gottfried Weber and the Concept of
%  Mehrdeutigkeit}\bibparenthesis{Ph.\,D.\ diss\GobbleOrNot.}\bibpunctuation
%\newblock Columbia University\bibpunctuation
%\newblock 1992\opcitend
%
%\bibitem{sheldon}
%\biblastnames{Sheldon}
%\opcitstart \SwapNames{David~A.}{Sheldon}\GobbleOrNot\bibpunctuation
%\newblock ``The Galant Style Revisited and Re-Evaluated\bibpunctuation''
%\newblock {\em Acta Musicologica} 47/2 (1975)\toomit[pages]{\bibcase :
%  240--70}\opcitend
%
%\bibitem{walker}
%\biblastnames{Walker}
%\opcitstart \SwapNames{Alan}{Walker}\bibpunctuation
%\newblock {\em The Final Years
%  1861--1886}\toomit[volume]{\bibpunctuation\bibcase \bibcase volume~3 of {\em
%  Franz Liszt}}\bibparenthesis{New York: Alfred A. Knopf, 1996}\opcitend
%
%\end{thebibliography}
%
%\clearpage
%\section{Implementation}
%
%\subsection*{Identification}
%    \begin{macrocode}
%<*package>
\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesPackage{opcit}[2006/09/20 Footnote references (Federico Garcia) Version 2]
\RequirePackage{xspace}
%    \end{macrocode}
%
%\subsection*{Declarations}
%    \begin{macrocode}
\newif\ifopcit@bbl\opcit@bblfalse
\newif\ifopcit@footnote\opcit@footnotefalse
\newif\ifperi@d\peri@dfalse
\newif\ifhyper@opcit
\newif\if@omitting
\newif\if@idem
\newif\ifcheck@idem
\newif\ifcheck@@idem
\newif\if@opcit
\newif\ifcustom@bst
\newcount\@lastcite
\newlength{\sameauthorsrule}\setlength{\sameauthorsrule}{23pt}
\newtoks\opcit@redefs
\newtoks\opcit@defs
\newcommand*{\last@cited}{)OpcitFirst(}
\newcommand*{\opcittext}{\textit{op.\,cit.}}
\newcommand*{\idemtext}{\textit{Idem}}
\newcommand*{\sameauthors}{\rule{\sameauthorsrule}{.4pt}}
\newcommand*\opcitwarning[1]{\PackageWarning{noopcit option is called for, 
   but `#1' has no hereafter.}}
\newcommand*\opcit@noreferror[1]{\PackageError{key `#1' has not been cited.}
    {\string\bibref can be used only after the first citation of a work. 
    (You might also have mistyped the key.) Go on, but there won't be a
    cross reference here.}\textbf{??}}
\let\@quoteornot\relax
%    \end{macrocode}
%
%\subsection*{Options}
%
%    \begin{macrocode}
\DeclareOption{hyperref}{\hyper@opcittrue}
\DeclareOption{nohyperref}{\hyper@opcitfalse}
\DeclareOption{omitting}{\@omittingtrue}
\DeclareOption{noomitting}{\@omittingfalse}
\DeclareOption{noidem}{\@idemfalse}
\DeclareOption{idem}{\@idemtrue}
\DeclareOption{checkidem}{\check@idemtrue}
\DeclareOption{nocheckidem}{\check@idemfalse}
\DeclareOption{opcit}{\@opcittrue}
\DeclareOption{noopcit}{\@opcitfalse}
\DeclareOption{nocustombst}{\newcommand\opcit@bst{\bibliographystyle{opcit}}}
\DeclareOption{custombst}{\let\opcit@bst\relax}
\@ifpackageloaded{hyperref}
    {\ExecuteOptions{omitting,checkidem,nocustombst,idem,opcit,hyperref}}
    {\ExecuteOptions{omitting,checkidem,nocustombst,idem,opcit}}
\ProcessOptions
\ifhyper@opcit\RequirePackage{hyperref}\fi
\opcit@bst
%    \end{macrocode}
%
%\subsection{The macros}
%
%The basic idea behind the working of |opcit| is that the \texttt{bbl} file produced by \textsc{Bib}\TeX\ is read at the beginning of the document, not to produce the list of references, but to define the (internal) commands that will expand into the footnote references. For example, the entry \texttt{texbook} defines the commands |\@texbook|, |\texbook@star|, |\texbook@author|, and so on. These commands contain the actual text to be written in the footnotes.
%
%The |\cite| command itself is redefined, based on circumstances, to execute the appropriate control sequence each time. At the beginning, |\cite{texbook}| means basically |\footnote{\@texbook}|. But it also redefines |\@texbook| so that the next time it is used it will expand to `Knuth, \emph{op.~cit.}'
%
%Before reading the |bbl| file, however, we have to define the `communication commands' that enable the latter to pass information on to |opcit|.
%
%\subsubsection{Communication commands}
%Punctuation marks are to be added only if the last character was not a period, a question or an exclamation mark (which have a |\sfcode| of 2000).
%
%    \begin{macrocode}
\newcommand{\newBibCommand}[3]{%
    \newcommand#1{#2}%
    \opcit@redefs\expandafter{\the\opcit@redefs%
        \renewcommand#1{#3}}}
\let\opcitstart\relax
\newBibCommand{\opcitend}{\relax}{\ifnum\spacefactor=\sfcode`?\else\unskip.\fi}
\newBibCommand{\bibpunctuation}{,\xspace}{%
    \ifnum\spacefactor=\sfcode`?\else\unskip.\fi\xspace}
\newBibCommand{\biblastnames[1]}{%
    \global\@namedef{\@curr@bibitem @authors}{#1}}{\relax}
\newBibCommand{\bibhereafter[1]}{%
    \global\expandafter\edef\csname\@curr@bibitem @hereafter\endcsname{%
    \ifhyper@opcit
        \noexpand\hyperlink{\@curr@bibitem @key}{#1}\else#1\fi}}{\relax}
\newBibCommand{\bibcase[1]}{\lowercase{#1}}{\uppercase{#1}}
\newBibCommand\QuoteOrNot{\gdef\@quoteornot{''\global\let\@quoteornot\relax}}{\relax}
%    \end{macrocode}
%
%\subsubsection{Omitting mechanism}
%
%Here we use a feature of |\@nameuse|: an undefined command called by this method will not be an error, but a |\relax|. Thus, when a |\with{|\meta{field}|}| redefines |\omit@field| to be |\@gobble|, the result of |\toomit| (in the footnotes) will be either |\@gobble\@gobble| or |\relax\@gobble|. In either case, |\with| has to take care of re-omitting (adding its argument to a list, eventually gone over by |\finalize@cite|).
%    \begin{macrocode}
\if@omitting
    \newBibCommand{\toomit[2][omitted]}{%
        \@nameuse{omit@#1}\@gobble{#2}}{#2}%    
        \newcommand\with[1]{%                   
            \global\expandafter\let\csname omit@#1\endcsname\@gobble
            \edef\@reomit{\@reomit,#1}}
    \newcommand\@reomit{omitted}%
\else
    \newcommand\toomit[2][omitted]{#2}
    \let\with\@gobble
\fi
%    \end{macrocode}
%
%\subsubsection{Reading the \texttt{bbl}}
%
%After having set up the communication, the \texttt{bbl} file is read (if it exists). This is done within a group, for |thebibliography| and |\bibitem| are redefined (the former as nothing). At the moment, the communication commands have their `footnote meaning,' the first part of their definition (the second part has been stored in |\opcit@redefs|, to be redeemed later on).
%
%In |\bibitem|, |#1| is the label for the |\cite| command; |#2| is a series of declarations written out to the |bbl| file by the \textsc{Bib}\TeX\ style (one of them, required, is the command |\biblastnames|, whose argument contains only the last name(s) of the author(s)). |#3| is the full author(s)' name(s), that appears the first time the work is |\cite|'d. Finally, |#4| is the rest of the information for the entry.
%
%    \begin{macrocode}
\bgroup
    \renewcommand{\newBibCommand}[3]{%
        \newcommand#1{#2}%
        \global\opcit@defs\expandafter{\the\opcit@defs
            \newBibCommand{#1}{#2}{#3}}}
    \renewenvironment{thebibliography}[1]{\relax}{\relax}
    \def\toomit{\noexpand\toomit}%
    \def\QuoteOrNot{\noexpand\QuoteOrNot}%
    \long\def\bibitem#1#2\opcitstart #3\bibpunctuation \newblock#4\opcitend{%
        \ifx#3\sameauthors\else\def\@lastauthors{#3}\fi
        \global\expandafter\edef\csname#1@author\endcsname{\@lastauthors}%
        \global\def\@curr@bibitem{#1}%
        \global\expandafter\edef\csname #1@first\endcsname{%
            \noexpand\opcit@noreferror{#1}}%
        \global\@namedef{#1@star}{%
            \global\expandafter\edef\csname #1@first\endcsname{\thefootnote}%
            \ifhyper@opcit\hypertarget{#1@key}{}\fi
            #4}%
        \global\def\hereafter{\@nameuse{#1@hereafter}}%
        \global\expandafter\def\csname @#1\endcsname{%
            \@nameuse{#1@author}, \@nameuse{#1@star}}%
        \bibhereafter{\if@opcit\noexpand\opcittext\else\opcitwarning{#1}\fi}%
        #2}
    \InputIfFileExists{\jobname.bbl}{\global\opcit@bbltrue}%
        {\global\opcit@bblfalse\PackageWarningNoLine{opcit}{%
            No \jobname.bbl file. There will be no footnote references}}
\egroup
\the\opcit@defs
\ifopcit@bbl
    \renewcommand{\cite}{\@ifstar{\opcit@cite@star}{\opcit@cite}}%
\fi
%    \end{macrocode}
%
%The last construction ensures that if a |bbl| was not found, \LaTeX\ will still understand |\cite|.
%
%This reading of the |bbl| happens at the beginning of the job, but it can also happen by the user's request (to reset the cites to the full information), with |\resetcites|. Here goes that. I can't remember why exactly---it has something to do with argument expansion---but this cannot be done by defining a common command for both macros.
%
%    \begin{macrocode}
\newcommand*\resetcites{%
   \bgroup
      \renewcommand{\newBibCommand}[3]{%
         \newcommand##1{##2}%
         \global\opcit@defs\expandafter{\the\opcit@defs
               \newBibCommand{##1}{##2}{##3}}}
      \renewenvironment{thebibliography}[1]{\relax}{\relax}
      \def\toomit{\noexpand\toomit}%
      \def\QuoteOrNot{\noexpand\QuoteOrNot}%
      \long\def\bibitem##1##2\opcitstart ##3\bibpunctuation \newblock##4\opcitend{%
         \ifx##3\sameauthors\else\def\@lastauthors{##3}\fi
         \global\expandafter\edef\csname##1@author\endcsname{\@lastauthors}%
         \global\def\@curr@bibitem{##1}%
         \global\expandafter\edef\csname ##1@first\endcsname{%
            \noexpand\opcit@noreferror{##1}}%
         \global\@namedef{##1@star}{%
               \global\expandafter\edef\csname ##1@first\endcsname{\thefootnote}%
               \ifhyper@opcit\hypertarget{##1@key}{}\fi
               ##4}%
         \global\def\hereafter{\@nameuse{##1@hereafter}}%
         \global\expandafter\def\csname @##1\endcsname{%
            \@nameuse{##1@author}, \@nameuse{##1@star}}%
         \bibhereafter{\if@opcit\noexpand\opcittext\else\opcitwarning{##1}\fi}%
         ##2}
      \let\newcommand\renewcommand
      \InputIfFileExists{\jobname.bbl}{\global\opcit@bbltrue}%
         {\global\opcit@bblfalse\PackageWarningNoLine{opcit}{%
               No \jobname.bbl file. There will be no footnote references}}
   \egroup}
%    \end{macrocode}
%
%\subsubsection{The \cs{cite}s}
%
%When |opcit| reads the |bbl| file, a series of commands are defined for each bibliographical entry. The most important are (for the entry |foo|):
%
%\begin{itemize}
%\item|\foo@author| has the full author name(s). It is used only the first time |foo| is |\cite|'d.
%\item|\foo@authors| contains the last name(s), to be used in post-citations.
%\item|\foo@star| contains the rest of the information for the entry. (The name of this command responds to |\cite*| being a |\cite| without author.)
%\item|\foo@hereafter| equals |\opcittext| by default, but is changed by a |\bibhereafter| in the |bbl| file.
%\item|\@foo| expands initially to |\foo@author, \foo@star|---i.e., authors (full name) followed by info.
%\end{itemize}
%
%This information is used by |\cite| and |\cite*| (redefined earlier as |\opcit@cite|). Before expanding into the actual information, they check if they appear in a footnote.\footnote{This requires the document class to set \cs{interfootnotelinepenalty} different from \cs{interlinepenalty}.} If not, they call a |\footnote|, appending a period at the end if necessary. Then, |\cite| calls |\@foo|, while |\cite*| calls |\foo@star|. 
%
%Then they call the redefinition routine |\renew@cites| (section~\ref{renew}). The main task of this latter is to substitute |\foo@authors| (only last names) for the original |\foo@author| (full names), and redefine |\foo@star| (which was the rest of the information) as |\foo@hereafter| (which is either |\opcittext| or the user's |hereafter| field). (However, this simple main task is obscured in the code by the \emph{Idem} mechanism.)
%
%    \begin{macrocode}
\newcommand{\opcit@cite}[2][\@empty]{\nocite{#2}%
    \ifnum\interlinepenalty=\interfootnotelinepenalty\opcit@footnotetrue
        \else\opcit@footnotefalse\expandafter\footnote\fi
    {\@nameuse{@#2}%
    \check@for@period{\@nameuse{@#2}}%
    \finalize@cite{#1}{#2}}}
\newcommand{\opcit@cite@star}[2][\@empty]{\nocite{#2}%
    \ifnum\interlinepenalty=\interfootnotelinepenalty\opcit@footnotetrue
        \else\opcit@footnotefalse\expandafter\footnote\fi
    {\@nameuse{#2@star}%
    \check@for@period{\@nameuse{#2@star}}%
    \finalize@cite{#1}{#2}}}
\newcommand\finalize@cite[2]{%
    \global\@lastcite=\c@footnote\relax
    \ifx\@empty#1\else
        \ifcheck@@idem
            \check@for@period{\idemtext}%
            \def\this@opt{#1}%
            \ifx\last@opt\this@opt\else
                \check@for@period{#1},\@quoteornot\ #1%
            \fi
        \else\check@for@period{#1},\@quoteornot\ #1%
        \fi
    \fi
    \ifopcit@footnote\peri@dtrue\fi
    \ifperi@d\else.\@quoteornot\fi
    \global\def\last@opt{#1}%
    \check@@idemfalse
    \if@omitting
        \@for\@tempcsa :=\@reomit \do
            {\global\expandafter\let\csname omit@\@tempcsa\endcsname\relax}%
        \global\def\@reomit{omitted}%
    \fi
    \renew@cites{#2}%
    }
%    \end{macrocode}
%
%The first lines of |\finalize@cite| are part of the mechanism to catch identical optional arguments to two |\cites| in a row. It is a function whose methods are scattered here and there in the code, but it is simple enough if anyone ever needs to follow it.
%
%\subsubsection{Redefinition routine}\label{renew}
%
% The redefinition routine is in charge of catching two identical |\cite|'s in a row, in which case it typesets |\idemtext|. But the main task is to reduce |\foo@star| (the information other than author of the entry |foo|) to |\foo@hereafter|.
%
%    \begin{macrocode}
\newcommand{\renew@cites}[1]{%
    \recover@last%
    \global\def\last@cited{#1}%
    \cited{#1}%
    \ifopcit@footnote\else\if@idem
        \global\@namedef{@#1}{\@idem{@#1}}%
        \global\@namedef{#1@star}{\@idem{@#1}}%
    \fi\fi
    \global\def\hereafter{\textit{\@nameuse{#1@hereafter}}}}%
\newcommand*\cited[1]{\@for\@tempcsa :=#1 \do{%
    \global\@namedef{@#1}{\@nameuse{#1@authors},~\@nameuse{#1@hereafter}}%
    \global\@namedef{#1@star}{\@nameuse{#1@hereafter}}}}%
\newcommand\recover@last{%
    \global\expandafter\edef\csname @\last@cited\endcsname{%
        \noexpand\@nameuse{\last@cited @authors},%
        ~{\noexpand\@nameuse{\last@cited @hereafter}}}%
    \global\expandafter\edef\csname\last@cited @star\endcsname{%
        {\noexpand\@nameuse{\last@cited @hereafter}}}%
    }
\newcommand\@idem[1]{\advance\@lastcite1\relax
    \ifnum\@lastcite=\c@footnote
        \idemtext\ifcheck@idem\check@@idemtrue\fi
    \else
        \check@@idemfalse\recover@last\@nameuse{#1}%
    \fi}
%    \end{macrocode}
%
%\subsection*{Additional functions and user commands}
%
%    \begin{macrocode}
\def\check@for@period#1{{\normalsfcodes\setbox0\hbox{#1%
    \ifnum\spacefactor=\sfcode`.\global\peri@dtrue\else
    \global\peri@dfalse\fi}}}
\ifhyper@opcit
    \newcommand*\bibref[1]{\hyperlink{#1@key}{\@nameuse{#1@first}}}
\else
    \newcommand*\bibref[1]{\@nameuse{#1@first}}
\fi
\newcommand\nobibliography[1]{\if@filesw 
    \immediate\write\@auxout{\string\bibdata{#1}}\fi
    \if@omitting\PackageWarningNoLine{opcit}{No final references list, 
        there might be information within \string\toomit\space commands that will be lost}\fi}
\let\opcit@bibliography\bibliography
\renewcommand{\bibliography}{%
    \renewcommand\newBibCommand[3]{\relax}%
    \the\opcit@redefs\opcit@bibliography}
\newcommand{\thebib@renew}{}
\@ifundefined{chapter}{%
    \renewcommand{\thebib@renew}{\section*{\refname}\@mkboth{\refname}{\refname}}}{%
    \renewcommand{\thebib@renew}{\chapter*{\bibname}\@mkboth{\bibname}{\bibname}}}%
\renewenvironment{thebibliography}[1]
     {\thebib@renew%
      \the\opcit@redefs%
      \list{}%
           {\setlength\labelwidth{\z@}%
            \leftmargin\bibindent
            \itemindent -\bibindent
            \parsep \z@
            \@openbib@code
            \usecounter{enumiv}%
            \let\p@enumiv\@empty
            \renewcommand\theenumiv{\@arabic\c@enumiv}}%
      \sloppy
      \clubpenalty4000
      \@clubpenalty \clubpenalty
      \widowpenalty4000%
      \sfcode`\.\@m}
     {\def\@noitemerr
       {\@latex@warning{Empty `thebibliography' environment}}%
      \endlist}
%    \end{macrocode}
%</package>
%\section{The \texttt{opcit.bst} bibliography style}
%
%I have had no time to fully document this bibliography style, or even to purify it and make it most economical\dots
%    \begin{macrocode}
%<*bst>
ENTRY
  { address
    author
    booktitle
    chapter
    edition
    editor
    hereafter
    howpublished
    institution
    journal
    key
    month
    note
    number
    organization
    pages
    publisher
    school
    series
    title
    type
    url
    urldate
    volume
    year
  }
  {}
  { label }

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

STRINGS { s t last.authors quotes }

FUNCTION {init.state.consts}
{ #0 'period.state :=
  #0 'before.all :=
  "" 'last.authors :=
  "" 'quotes :=
}

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

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

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

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

FUNCTION {emphasize}
{ duplicate$ empty$
    { pop$ "" }
    { "{\em " swap$ * "}" * }
  if$
}

INTEGERS { nameptr namesleft numnames }

FUNCTION{format.names}
{ 's :=
  #1 'nameptr :=
  s num.names$ 'numnames :=
  numnames 'namesleft :=
    { namesleft #0 > }
    { s nameptr "{ff }{vv~}{ll}{,~jj}" format.name$ 't :=
      nameptr #1 >
        { namesleft #1 >
            { ", " * t * }
            { numnames #2 >
                { "," * }
                'skip$
            if$
            t "others" =
                { " et~al." * }
                { " and " * t * }
            if$
            }
          if$
        }
        't
     if$
     nameptr #1 + 'nameptr :=
     namesleft #1 - 'namesleft :=
   }
   while$
}

FUNCTION {format.swap.names}
{ 's :=
  s num.names$ 'numnames :=
  "\SwapNames{" s #1 "{ff}" format.name$ 
  duplicate$ #-1 #1 substring$ 
  "." =
    { #1 'period.state := }
    'skip$ 
  if$
  * "}{" * 
  s #1 "{vv~}{ll}" format.name$ * "}" *
  s #1 "{, jj}" format.name$ * 
  numnames #3 >
    { " et~al." * #1 'period.state := }
    { numnames #1 > 
        { #2 'nameptr :=
            numnames #1 - 'namesleft :=
                { namesleft #0 > }
                { s nameptr "{ff~}{vv~}{ll}{, jj}" format.name$ 't :=
                    namesleft #1 >
                        { ", " * t * }
                        { " and " * t * }
                    if$
                    nameptr #1 + 'nameptr :=
                    namesleft #1 - 'namesleft :=
                }
                while$
        }
        'skip$
      if$
    }
  if$
}

FUNCTION {format.authors}
{   author empty$
    { ""
      "" 'last.authors :=
    }
    { author format.names
      last.authors =
        { "\sameauthors" }
        { before.all output.state =
            { author format.swap.names }
            { author format.names }
          if$ }
      if$
      author format.names 'last.authors :=
    }
  if$
}

FUNCTION {format.editors}
{ editor empty$
    { "" }
    { before.all output.state =
        { editor format.swap.names }
        { editor format.names }
      if$
    }
  if$
}

FUNCTION {format.editors.ed}
{ editor empty$
    { "" }
    { before.all output.state =
        { editor format.swap.names }
        { editor format.names }
      if$
      editor num.names$ #1 > 
        { " (eds.)" * }
        { " (ed.)" * }
      if$
      #0 'period.state :=
    }
  if$
}

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$
}

FUNCTION {format.date}
{ year empty$
    { month empty$
        { "" }
        { "there's a month but no year in " cite$ * warning$
          "\toomit[month]{" month * " }" *
        }
      if$
    }
    { month empty$
        'year
        { "\toomit[month]{" month * " }" * year * }
      if$
    }
  if$
}

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

FUNCTION{either.warning}
{   empty$
        'pop$
        { "can't use both " swap$ * " fields in " * cite$  * warning$ }
    if$
}
FUNCTION {format.bvolume}
{ volume empty$
    { "" }
    { "\bibcase volume" volume tie.or.space.connect
      series empty$
        'skip$
        { " of " * series emphasize * }
      if$
      "volume and number" number either.warning
    }
  if$
}

FUNCTION {format.number.series}
{ volume empty$
    { number empty$
        { series empty$
            { "" }
            { ", series " * series * "" }
          if$ 
        }
        { "\bibcase number"
          number tie.or.space.connect
          series empty$
            { "there's a number but no series in " cite$ * warning$ }
            { " in " * series * }
          if$
        }
      if$
    }
    { "" }
  if$
}

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
}

FUNCTION {format.pages}
{ pages empty$
    { "" }
    { pages multi.page.check
        { "\toomit[pages]{\bibcase " swap$ * pages n.dashify tie.or.space.connect "}" * }
        { "\toomit[pages]{\bibcase " swap$ * pages tie.or.space.connect "}" * }
      if$
    }
  if$
}

FUNCTION {format.vol.num.date.pages}
{ volume empty$
    'skip$
    { volume }
  if$
  number empty$
    'skip$
    { "/" number * 
      volume empty$
        { "there's a number but no volume in " cite$ * warning$ }
        { * }
      if$
    }
  if$
  " (" * format.date * ")" *
  pages empty$
    'skip$
    { duplicate$ empty$
        { pop$ "" format.pages * }
        { ": " format.pages * }
      if$
    }
  if$
}

FUNCTION {format.chapter.pages}
{ chapter empty$
    { pages empty$
        { "" }
        { ": " format.pages }
      if$
    }
    { "\newblock\bibpunctuation "
      type empty$
        { "\bibcase chapter" * }
        { type "l" change.case$ * }
      if$
      chapter tie.or.space.connect
      pages empty$
    'skip$
    { ", pages " * format.pages * }
      if$
    }
  if$
}

FUNCTION{get.lastnames}
{ 's :=
  s num.names$ 'numnames :=
  s #1 "{vv~}{ll}" format.name$ 
  numnames #3 >
    { " et~al." * }
    { numnames #1 > 
        { #2 'nameptr :=
            numnames #1 - 'namesleft :=
                { namesleft #0 > }
                { s nameptr "{vv~}{ll}" format.name$ 't :=
                    namesleft #1 >
                        { ", " * t * }
                        { " and " * t * }
                    if$
                    nameptr #1 + 'nameptr :=
                    namesleft #1 - 'namesleft :=
                }
                while$
        }
        'skip$
      if$
    }
  if$
}

FUNCTION {make.address.publisher.year}
{   "" 
    address empty$
        'skip$
        { address * }
    if$
    publisher empty$
        'skip$
        { address empty$
            { publisher * }
            { ": " * publisher * }
        if$
        }
    if$
    format.date duplicate$ "" =
        'pop$
        { swap$ duplicate$ "" =
            { * }
            { swap$ ", " swap$ *  * }
        if$}
    if$
    duplicate$ "" =
        'skip$
        { "\bibparenthesis{" swap$ * "}" * }
    if$
}

FUNCTION {make.url}
{   "\url{" url * "}" * 
    urldate empty$
        { "there is url but no urldate in " cite$ * warning$ }
        { " (accessed " * urldate * ")" * }
    if$
}
    
FUNCTION {output.bibitem}
{ newline$
  "\bibitem{" write$
  cite$ "}" * write$
  ""
  newline$
  "\biblastnames{" write$
  author empty$
    { editor empty$ 
        { organization empty$
            { "no last names in " cite$ * warning$ }
            { organization }
            if$
        }
        { editor get.lastnames 
          editor num.names$ #1 >
            { " (eds.)" * }
            { " (ed.)" * }
          if$
        }
      if$
    }
    { author get.lastnames }
    if$
  "}" * write$
  before.all 'output.state :=
}

FUNCTION{output.start}
{   hereafter empty$
        'skip$
        { "\bibhereafter{{\noexpand\em " write$ hereafter "}}" * write$ }
        if$
    newline$
    "\opcitstart " write$
}

FUNCTION{output.as.block}
{   duplicate$ "" =
        'pop$
        { period.state #1 =
            { "\GobbleOrNot" #0 'period.state := }
            { "" }
          if$
          "\bibpunctuation" * quotes * write$ newline$ "\newblock " swap$ * write$ 
          #1 'output.state :=
        }
    if$
    "" 'quotes :=
}

FUNCTION{output.omitted}
{  't :=
   duplicate$ "" =
      { pop$ }
      { "\toomit[" t * "]{\bibpunctuation\bibcase " * swap$ * "}" * write$ }
   if$
}

FUNCTION {fin.entry}
{  write$ 
   note empty$ {""} {note} if$ "note" output.omitted
   "\opcitend" write$
   newline$
}

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

FUNCTION{empty.chapter.and.pages.warning}
{  't := 
   chapter empty$
      { pages empty$
         { pop$ "empty " t * " in " * cite$ * warning$ "" }
         'skip$
        if$
      }
      'skip$
   if$

}

FUNCTION{book}
{   output.bibitem
    output.start
    author empty$
        { format.editors.ed "author and editor" empty.warning write$ }
        { format.authors "author and editor" editor either.warning write$ }
    if$
    title emphasize "title" empty.warning output.as.block
    edition empty$
        'skip$
        { "\bibcase " edition * " edition" * output.as.block }
    if$ 
    howpublished missing$
        'skip$
        { "\bibcase " howpublished * output.as.block }
    if$
    format.bvolume "volume" output.omitted
    format.number.series "number" output.omitted
    make.address.publisher.year write$
    url empty$ 
        'skip$
        { make.url output.as.block }
    if$
    fin.entry
}

FUNCTION{article}
{   output.bibitem
    output.start
    format.authors "author" empty.warning write$
    "``" title * "title" empty.warning output.as.block "''" 'quotes := 
    howpublished empty$ 
        'skip$
        { "\bibpunctuation'' \newblock\toomit[howpublished]{\bibcase 
            " howpublished  * write$ 
          "}" 'quotes :=
        }
    if$
    journal emphasize "journal" empty.warning 
    " " * format.vol.num.date.pages "year" empty.warning * output.as.block
    url empty$ 
        'skip$
        { make.url output.as.block }
    if$
    fin.entry
}

FUNCTION {incollection}
{ output.bibitem
  output.start
  format.authors "author" empty.warning write$
  "``" title * "title" empty.warning output.as.block "''" 'quotes :=
  "\bibcase in " output.as.block
  crossref empty$ 
    'skip$
    { "\bibincite{" crossref * "}" * write$ }
  if$  
  "{" write$
  editor empty$
    'skip$
    { format.editors.ed ", " * write$ } 
  if$
  booktitle emphasize "booktitle" empty.warning write$
  edition empty$
    'skip$
    { "\bibcase " edition * " edition" * output.as.block }
  if$
  make.address.publisher.year write$
  url empty$ 
      'skip$
      { make.url output.as.block }
  if$
  "}" write$
  format.chapter.pages write$
  fin.entry
}
    
FUNCTION {inbook}
{ output.bibitem
  output.start
  author empty$
      { format.editors.ed "author and editor" empty.warning write$ }
      { format.authors "author and editor" editor either.warning write$ }
  if$
  "``" title * "title" empty.warning output.as.block "''" 'quotes :=
  chapter empty$
    'skip$
    { type empty$
      { "\bibcase chapter "  chapter *  }
      { "\bibcase " type * " " * chapter * }
      if$
    } 
  if$
  pages empty$
      'skip$
      { chapter empty$
        { "\bibcase pages" pages n.dashify tie.or.space.connect }
        { "\toomit[pages]{ (pages" * pages n.dashify tie.or.space.connect ")}" * }
        if$
      }
  if$ 
  "chapter and pages" empty.warning 
  " of " * 
  crossref empty$ 
    { booktitle emphasize * "booktitle" empty.warning 
      edition empty$
         'skip$
         { ", " * edition "l" change.case$ * " edition" * }
      if$
      howpublished missing$
        'skip$
        { ", " * howpublished * }
      if$
      output.as.block
      make.address.publisher.year write$ 
    }
    { "\bibincitestar{" * crossref * "}{" * booktitle emphasize * "}" * output.as.block }
  if$
  fin.entry 
}

FUNCTION{phdthesis}
{ output.bibitem
  output.start
  format.authors "author" empty.warning write$
  title emphasize "title" empty.warning 
  "\bibparenthesis{Ph.\,D.\ diss\GobbleOrNot.}" * output.as.block
  address empty$
    { "" }
    { address ": " * }
  if$
  school "school" empty.warning * output.as.block
  month empty$
    { "" }
    { month " " * }
  if$
  year "year" empty.warning * output.as.block
  fin.entry
}

FUNCTION{mastersthesis}
{ output.bibitem
  output.start
  format.authors "author" empty.warning write$
  title emphasize "title" empty.warning 
  "\bibparenthesis{M.\,A.\ thesis}" * output.as.block
  address empty$
    { "" }
    { address ": " * }
  if$
  school "school" empty.warning * output.as.block
  month empty$
    { "" }
    { month " " * }
  if$
  year "year" empty.warning * output.as.block
  fin.entry
}

FUNCTION{proceedings}
{   output.bibitem
    output.start
    editor empty$
        { organization "editor and organization" empty.warning write$ }
        { format.editors.ed "editor" empty.warning write$ }
    if$
    title emphasize "title" empty.warning output.as.block
    format.bvolume "volume" output.omitted
    format.number.series "number" output.omitted
    make.address.publisher.year write$
    fin.entry
}  
  
FUNCTION {booklet}
{ book }
  
FUNCTION {inproceedings}
{ output.bibitem
  output.start
  format.authors "author" empty.warning write$
  "``" title * "title" empty.warning output.as.block "''" 'quotes :=
  "\bibcase in " output.as.block
  crossref empty$ 
    'skip$
    { "\bibincite{" crossref * "}" * write$ }
  if$  
  "{" booktitle emphasize * "booktitle" empty.warning write$
  editor empty$
    { organization "editor and organization" empty.warning output.as.block }
    { ", edited by " format.editors * write$ }
  if$
  make.address.publisher.year write$
  "}" write$
  format.chapter.pages write$
  fin.entry
}
  
  
FUNCTION {misc}
{ output.bibitem
  output.start
  format.authors "author" empty.warning write$
  title output.as.block
  howpublished missing$
    'skip$
    { howpublished output.as.block }
  if$
  format.date output.as.block
  fin.entry
}

FUNCTION {default.type} { misc }

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"}

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"}

READ

FUNCTION {sortify}
{ purify$
  "l" change.case$
}

INTEGERS { len }

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

FUNCTION {sort.format.names}
{ 's :=
  #1 'nameptr :=
  ""
  s num.names$ 'numnames :=
  numnames 'namesleft :=
    { namesleft #0 > }
    { nameptr #1 >
        { " " * }
        'skip$
      if$
      s nameptr "{vv{ } }{ll{ }}{  ff{ }}{  jj{ }}" format.name$ 't :=
      nameptr numnames = t "others" = and
        { "et al" * }
        { t sortify * }
      if$
      nameptr #1 + 'nameptr :=
      namesleft #1 - 'namesleft :=
    }
  while$
}

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$
}

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}
{ type$ "book" =
  type$ "inbook" =
  or
    'author.editor.sort
    { type$ "proceedings" =
    'editor.organization.sort
    { type$ "manual" =
        'author.organization.sort
        'author.sort
      if$
    }
      if$
    }
  if$
  "    "
  *
  year field.or.null sortify
  *
  "    "
  *
  title field.or.null
  sort.format.title
  *
  #1 entry.max$ substring$
  'sort.key$ :=
}
FUNCTION {begin.bib}
{ preamble$ empty$
    'skip$
    { preamble$ write$ newline$ }
  if$
  "\newBibCommand{\bibparenthesis[1]}{ (#1)}{. \newblock #1}" write$ newline$
  "\newBibCommand{\bibincite[2]}{\recover@last\@nameuse{@#1}}{#2}" write$ newline$
  "\newBibCommand{\bibincitestar[2]}{\recover@last " write$ newline$
  "     \@nameuse{#1@star}}{#2}" write$ newline$
  "\newBibCommand{\SwapNames[2]}{#1 #2}{#2, #1}" write$ newline$
  "\newBibCommand{\GobbleOrNot}{\relax}{\newblock\@gobble}" write$ newline$
  "\begin{thebibliography}{}"   write$ newline$
}
ITERATE {presort}

SORT

EXECUTE {begin.bib}

EXECUTE {init.state.consts}

ITERATE {call.type$}

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

EXECUTE {end.bib}
%</bst>
%    \end{macrocode}
