% citenotes.sty:  the citation parts of from AIP.sty
% might want to use letternotes for footnotes.
% (2) Superscript reference numbers in citation and bibliography.  You
% should put the references in the logically correct place, e.g., "...  as
% is given by Landau \cite{landau}.  Next sentence ..."  \cite takes care
% of removing the preceding spaces and putting the reference after the
% punctuation (e.g, "...  Landau.$^7$ ...").

% (3) Three or more consecutive reference numbers are represented as a
% range.  Thus 1,3,4,5,6,8,9 is printed as 1,3--6,8,9.  No sorting is
% performed; i.e., 1,3,2 is printed as such.

% (4) \citenum and \citea give you more control over the appearance of
% the citations.  \citenum emits the plain citation number without
% ornament as in "...  as shown in Ref.~\citenum{foo}.".  \citea puts it's
% argument into the ornamentation for citations.  Thus \cite{foo} is
% equivalent to \citea{\citenum{foo}}.
\def\thebibliography#1{\par\clearpage\section*{References\@mkboth
  {REFERENCES}{REFERENCES}}\list
  {$\m@th^{\arabic{enumi}}$}{\settowidth\labelwidth{$\m@th^{#1}$}%
    \labelsep0pt\leftmargin\parindent
    \itemindent-\leftmargin\advance\itemindent\labelwidth
    \usecounter{enumi}}
    \def\newblock{\hskip .11em plus .33em minus -.07em}
    \sloppy
    \sfcode`\.=1000\relax}

% Superscript citations -- skip optional arg to \cite
% Move citation after period and comma.
\def\@cite#1#2{\unskip\nobreak\relax
    \def\@tempa{$\m@th^{\hbox{\the\scriptfont0 #1}}$}%
    \futurelet\@tempc\@citexx}
\def\@citexx{\ifx.\@tempc\let\@tempd=\@citepunct\else
    \ifx,\@tempc\let\@tempd=\@citepunct\else
    \let\@tempd=\@tempa\fi\fi\@tempd}
\def\@citepunct{\@tempc\edef\@sf{\spacefactor=\the\spacefactor\relax}\@tempa
    \@sf\@gobble}

% \citenum emits the plain citation number without ornament
% \citea puts it's argument into the ornamentation for citations
% thus \cite{foo} is equivalent to \citea{\citenum{foo}}
\def\citenum#1{{\def\@cite##1##2{##1}\cite{#1}}}
\def\citea#1{\@cite{#1}{}}

% Collapse citation numbers to ranges.  Non-numeric and undefined labels
% are handled.  No sorting is done.  E.g., 1,3,2,3,4,5,foo,1,2,3,?,4,5
% gives 1,3,2-5,foo,1-3,?,4,5
\newcount\@tempcntc
\def\@citex[#1]#2{\if@filesw\immediate\write\@auxout{\string\citation{#2}}\fi
  \@tempcnta\z@\@tempcntb\m@ne\def\@citea{}\@cite{\@for\@citeb:=#2\do
    {\@ifundefined
       {b@\@citeb}{\@citeo\@tempcntb\m@ne\@citea\def\@citea{,}{\bf ?}\@warning
       {Citation `\@citeb' on page \thepage \space undefined}}%
    {\setbox\z@\hbox{\global\@tempcntc0\csname b@\@citeb\endcsname\relax}%
     \ifnum\@tempcntc=\z@ \@citeo\@tempcntb\m@ne
       \@citea\def\@citea{,}\hbox{\csname b@\@citeb\endcsname}%
     \else
      \advance\@tempcntb\@ne
      \ifnum\@tempcntb=\@tempcntc
      \else\advance\@tempcntb\m@ne\@citeo
      \@tempcnta\@tempcntc\@tempcntb\@tempcntc\fi\fi}}\@citeo}{#1}}
\def\@citeo{\ifnum\@tempcnta>\@tempcntb\else\@citea\def\@citea{,}%
  \ifnum\@tempcnta=\@tempcntb\the\@tempcnta\else
   {\advance\@tempcnta\@ne\ifnum\@tempcnta=\@tempcntb \else \def\@citea{--}\fi
    \advance\@tempcnta\m@ne\the\@tempcnta\@citea\the\@tempcntb}\fi\fi}
