%% Copyright (C) 1994, 1995 Ren� Seindal (rene@seindal.dk)

% This files may be distributed under the terms of the LaTeX Project Public
% License as distributed from CTAN archives in macros/latex/base/lppl.txt;
% either version 1.0 or, at your option, any later version.

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{inlinebib}[1994/12/06\space Inline bibliography style]
\ProcessOptions

  %% No labels in the final list of litterature.

\let\@biblabel\@gobble


  %% This is called for each bibitem without option in the bbl file.
  %% The inlinebib style does not use bibitems with optional
  %% arguments.  The arguments are: #1 = key, #2 = basic entry, #3 =
  %% notes for last reference list only, #4 = short entry for successive
  %% citations.  The period that ends an entry in the list is never
  %% present in the inline reference.   Punctuations should be added
  %% manually. 

\long\def\@bibitem#1 #2 \note #3 \short #4 \end{\par\if@filesw
	{\def\protect##1{\string ##1\space}%
	 \let\newblock\@empty
	 \immediate\write\@auxout{\string
		\bibcite{#1}{\string\@bibcall{#1}{#2}{#4}}}}\fi
	{\let\cite\shortcite #2#3}}
%	{\let\cite\shortcite #2}}



  %% This is called from the aux file at the start of the job.

\long\def\bibcite#1#2{\global\@namedef{b@#1}{#2}}




  %% Set globally true iff an immediate following period should be
  %% gobbled, because the citation ends in a period, e.g., from a
  %% trailing "cit." or "ibid." and there is no optional part.

\newif\if@gobbleperiod
\newif\if@withpages


  %% Separate the first and the following citations of a reference, and
  %% handle successive identical citations of the same reference.  Each
  %% macro b@LABEL is defined as \@bibcall{LABEL}{FULLCITE}{SHORTCITE}.
  %% The actual definition of b@LABELis not changed after the first
  %% citation, since it provokes messages of "Labels may have changed"
  %% from LaTeX.

\def\@lastcite{}
\def\noibid{\gdef\@lastcite{}}

\long\def\@bibcall#1#2#3{\global\@gobbleperiodfalse
	\@ifundefined{B@#1}%
		{{#2}\global\@namedef{B@#1}{}}%
		{\@bibsecond{#1}{#3}}%
	\gdef\@lastcite{#1}%
}

\long\def\@bibsecond#1#2{%
	\def\@tempa{#1}%
	\ifx\@tempa\@lastcite {\em ibid.}\else {#2} cit.\fi
	\if@withpages \else \global\@gobbleperiodtrue \fi
}

  %% Called for each normal \cite call.  This version does not allow
  %% multiple citations in one call, as it makes little sense.  The
  %% labels are much too long.

\def\cite{\protect\@pcite}
\def\@pcite{\@ifnextchar [{\@withpagestrue\@citex}{\@withpagesfalse\@citex[]}}

\def\@citex[#1]#2{\if@filesw\immediate\write\@auxout{\string\citation{#2}}\fi
	\@ifundefined{b@#2}%
		{{\reset@font\bf ?}\@warning
			{Citation `#2' on page \thepage \space undefined}}%
		{\@cite{\@nameuse{b@#2}}{#1}}%
	\let\next\relax
	\if@gobbleperiod \let\next\check@period \fi
	\next
}


  %% Produces the actual inline citation, no bracketes around it.

\def\@cite#1#2{{#1\if@withpages , #2\fi}}


  %% Remove a following period.

\def\check@period{\futurelet\next\check@peri@d}
\def\check@peri@d{\ifx\next .\let\next\eat@period
	\else \let\next\relax \fi \next}
\def\eat@period.{}





  %% Forced full citation

\def\fullycite{\protect\@pfcite}
\def\@pfcite{\@ifnextchar [{\@withpagestrue\@fcitex}{\@withpagesfalse\@fcitex[]}}
 
\def\@fcitex[#1]#2{\expandafter\let\csname B@#2\endcsname\undefined
  \@citex[#1]{#2}}

  %% Forced short citation, with no "cit." suffix or "ibid."
  %% substitutions.

\def\shortcite{\protect\@pscite}
\def\@pscite{\@ifnextchar [{\@withpagestrue\@scitex}{\@withpagesfalse\@scitex[]}}
 
\def\@scitex[#1]#2{\if@filesw\immediate\write\@auxout{\string\citation{#2}}\fi
  \@ifundefined{b@#2}{{\reset@font\bf ?}\@warning
       {Citation `#2' on page \thepage \space undefined}}%
  {\long\def\@bibcall##1##2##3{##3}%
   \@cite{\@nameuse{b@#2}}{#1}}}



  %% Force full citations of the specified list of references.

\def\fullcitenext#1{{\@tfor
	\@tempa :=#1\do{\expandafter\global\expandafter
		\let\csname B@\@tempa\endcsname\undefined}}}

  %% Force short citations of the specified list of references.

\def\shortcitenext#1{{\@for
	\@tempa :=#1\do{\expandafter\global\expandafter
		\let\csname B@\@tempa\endcsname\@empty}}}




  %% This is to allow for an introduction to the bibliography

\let\bibc@mment\@empty
\long\def\bibliographycomment#1{%
	\def\bibc@mment{\let\bibc@mment\@empty #1\par\bigskip}%
}



  %% Copied from report.sty, changed to avoid unwanted left margin and
  %% add bibliography comment.

\def\thebibliography#1{\chapter*{\bibname\@mkboth
  {\uppercase{\bibname}}{\uppercase{\bibname}}}\bibc@mment
  \small
  \def\newblock{\hskip .11em plus.33em minus.07em}%
  \sloppy\clubpenalty4000\widowpenalty4000
  \sfcode`\.=\@m
  \parindent\z@\relax
  \parskip\medskipamount
}

\def\endthebibliography{\par\medskip}
