%%
%% This is file `opcit.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% opcit.dtx  (with options: `package')
%% Part of the `opcit' project: bibliographical references as footnotes.
%% 
%% Copyright 2006 Federico Garcia
%% 
\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesPackage{opcit}[2006/09/20 Footnote references (Federico Garcia) Version 2]
\RequirePackage{xspace}
\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
\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
\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}
\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
\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
\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}
\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}%
    }
\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}
\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}
\endinput
%%
%% End of file `opcit.sty'.
