%     D R F T C I T E . S T Y
%
%     version 3.2  (Apr 1993)
%
%     Print the tags instead of the numbers for \cite.
%     See also CITE.STY and OVERCITE.STY.
%
%     Copyright (C) 1989,1991,1992,1993 by Donald Arseneau
%     These macros may be freely transmitted, reproduced, or modified for
%     non-commercial purposes provided that this notice is left intact.
%
%  Use the label instead of the number for citations, as if you had used
%  \bibitem[name]{name}{....}, but write the proper citation number to
%  the aux file. Ignore spaces before the \cite, inserting an ordinary
%  interword space.  Also ignore spaces after commas in the input list
%  This style is particularly useful for draft (draught) versions of
%  documents that will eventually use cite.sty or overcite.sty.
%
%  This also keeps track of the order of first-citations in the text for
%  easy sorting (in lieu of BibTeX).  To omit this counting, declare
%  \nocitecount before the first \cite; or, for a more permanent removal,
%  comment-out the lines ending with %%o below, and omit everything following
%  the line that begins with %%o.
%
%  Drftcite keeps track of what references were cited, and issues warnings
%  for bibliography items that were never cited in the text.
%
%  The characters <>|_{}\ are not present in the roman fonts, so if you
%  use them in identifiers, they will have to be typeset in typewriter style.
%  To do this, un-comment two lines in the definition of \@citeverb.
%
%  `Citation...undefined' warnings are only given once per undefined
%  citation tag.  In the text, missing numbers are represented with a
%  bold `tag?' at the first occurrence, and with a normal `tag?' thenceforth.
%
%  This version of drftcite can co-exist with chapterbib.sty (version 1.1
%  or later).  In the \documentstyle options chapterbib must be listed
%  BEFORE drftcite.
% ........................
%
%  Pull out the code that writes the aux file citation and gives the name.
%  \citen can be used by itself to give citation name without the other
%  formatting; e.g., "See also ref.~\citen{junk}" gives "See also ref. junk".
%
\def\citen{\protect\@p@citen}
%
\def\@p@citen#1{%
\edef\@tempa{\@ignspaftercomma,#1, \@end, }% ignore spaces in parameter list.
\edef\@tempa{\expandafter\@ignendcommas\@tempa\@end}%
\if@filesw \immediate \write \@auxout {\string \citation {\@tempa}}\fi
\def\@citea{}%
\@for \@citeb:=\@tempa\do {\@citea
  \@ifundefined {b@\@citeb\@extra@b@citeb}%
    {{\bf \@citeverb{\@citeb}?}%
     \@warning {Citation `\@citeb' on page \thepage\space undefined}%
     \global\@namedef{b@\@citeb\@extra@b@citeb}{?}% remove this line to ...
    }% else, defined                          % ... repeat warnings
    {\@citeverb{\@citeb}}%
  \def\@citea{, }%
  \@advancecitecount%%o
  }}
%
% for ignoring spaces in the input:
\def\@ignspaftercomma#1, {\ifx\@end#1\@empty\else
   #1,\expandafter\@ignspaftercomma\fi}
\def\@ignendcommas,#1,\@end{#1}
%
% Make \cite robust. \@p@cite is the default \cite.
%
\def\cite{\protect\@p@cite}

\def\@p@cite{\@ifnextchar [{\@tempswatrue\@citex}{\@tempswafalse\@citex[]}}

%  Make \@citex refer to \citen:
%     Replacement for \@citex.  (Put a single space before the output)
%
\def\@citex[#1]#2{\leavevmode\unskip
   \ \@cite{\citen{#2}}{#1}\spacefactor\@m}%
%
%  Give the citation tag as the label (even if another label is specified)
%
\def\@lbibitem[#1]#2{\item[\@biblabel{%
   \@ifundefined{DCN@#2}{\@warning {Reference `#2' on page \thepage
   \space was never cited}}{}%
   \DC@llap{$^{\@nameuse{DCN@#2}}$\ \ }%%o
   \@citeverb{#2}}\hfill]\if@filesw
   {\def\protect##1{\string ##1\space}%
   \immediate\write\@auxout{\string\bibcite{#2}{#1}}}\fi\ignorespaces}

\def\@bibitem#1{\refstepcounter{\@listctr}\@lbibitem[\the\value{\@listctr}]{#1}}

% The following is an ad hoc patch to allow this style to work with chapterbib.
% Both styles need to redefine \@bibitem (and \bibcite).

\@ifundefined{the@ipfilectr}%
{\let\cbib@gobble\@gobbletwo}% undefined: no chapterbib: do nothing
{% defined: chapterbib: define special \@lbibitem
 \def\cbib@gobble#1#2#3{}% special bibcite has three parameters
 \def\@lbibitem[#1]#2{\item[\@biblabel{%
   \@ifundefined{DCN@#2}{\@warning {Reference `#2' in file `\@nameuse
     {ipfile@\the@ipfilectr}' on page \thepage\space was never cited}}{}%
   \DC@llap{$^{\@nameuse{DCN@#2}}$\ \ }%%o
   \@citeverb{#2}}\hfill]\if@filesw
   {\def\protect##1{\string ##1\space}%
   \immediate\write\@auxout{\string\bibcite{#2}{#1}{\the@ipfilectr}}}\fi
 \ignorespaces}% note third parameter to \bibcite!
}

%  make the special characters in the citation tag printable
%
\def\@citeverb#1{%
%% {\tt % un-comment this line and the "}" below to get characters <>_|{}
   \expandafter \expandafter \expandafter \@gobble  %  do \csname, \string, ...
   \expandafter \string\csname#1\endcsname}%        %  \@gobble, in that order.
%% }% un-comment this line and the "{\tt" above to get characters <>_|{}
%

%   \@extra@b@citeb is a hook for other style files to further specify
%   citations; for example, to number by chapter.
\@ifundefined{@extra@b@citeb}{\def\@extra@b@citeb{}}{}
%  in case no fancy bib package (chapterbib) defines this

%  How to turn off the counting:
\def\nocitecount{\def\@advancecitecount{\namedef{DCN@\@citeb}{}}%
  \let\DC@llap\@gobble}
\nocitecount % in case what follows gets removed
%
%
%%o ---------------
%%o  all the remainder deals with counting, so if you NEVER want the
%%o  citations counted, put \endinput here or comment-out all the rest
%%o ---------------
%
\let\DC@llap=\llap
%
%     count the citations as they appear in the text
%
\newcount\@HighCite \global\@HighCite\z@
%
\def\@advancecitecount{\@ifundefined {DCN@\@citeb}%
  {\global\advance\@HighCite\@ne
  \expandafter\xdef\csname DCN@\@citeb\endcsname{\the\@HighCite}}%
  {}}
%
%  The remainder handles input files skipped by \includeonly.  It adds code to
%  LaTeX's \include to re-read the .aux file checking the \citation commands.
%
%
%  For included files that are skipped (not listed by \includeonly)
%  input the .aux file ignoring all commands but \citation, which
%  does \@advancecitecount (keeps count of the citations).
%
\begingroup
\toks0={\ifx\DC@llap\llap % do counting only if wanted
  \begingroup
  \@ifundefined{cp@#1}{}% don't do if .aux file not there!
   {\let\setcounter\relax % don't expand cp@#1 completely
    \let\@draftauxcite\@gobble % don't repeat on repeated \include
    \expandafter\xdef\csname cp@#1\endcsname % add my stuff to \cp@#1
      {\csname cp@#1\endcsname \noexpand\@draftauxcite{#1}}%
  }\endgroup
\fi}
\toks1=\expandafter{\include{#1}}
\xdef\@gtempa{\def\noexpand\include##1{\the\toks0 \the\toks1 }}
\endgroup
\@gtempa
%
\def\@draftauxcite#1{\begingroup % disable everything but \citation
  \let\bibcite\cbib@gobble \let\newlabel\@gobbletwo \let\@writefile\@gobbletwo
  \let\bibdata\@gobble \let\bibstyle\@gobble % already \@gobble normally
  \def\citation##1{\@for\@citeb:=##1\do {\@advancecitecount}}%
  \makeatletter\@input{#1.aux}\endgroup}
%
%  [This file is named "drftcite" because "draftcite" is too long a name for
%   some computers.  Sorry to those who use the spelling "draught."  I could
%   have abbreviated the name by selecting the shared letters in "draft" and
%   "draught," but "dratcite" somehow conveys the wrong meaning.]
%
% Version 1991: Ignore spaces after commas in the parameter list. Create
% \nocitecount to turn off counting the order of citations.
% Version 3.1 (1992): protect \cite and \citen. (There is no version 3.0)
% Version 3.2 (1993): Supress repetitions of warning messages.  Include
% \@extra@b@citeb hook plus ugly hacks to work with chapterbib.sty. Use
% different redefinition of \include which fixes bug when \cp@FOO was not
% defined.
%
% Send problem reports to asnd@Reg.triumf.ca
%
% Test integrity of file:
% brackets:  round, square, curly, angle:   () [] {} <>
% backslash, slash, vertical, at, dollar, and: \ / | @ $ &
% hat, grave, acute (apostrophe), quote, tilde, under:   ^ ` ' " ~ _
