Plan 9 from Bell Labs’s /usr/web/sources/contrib/steve/root/sys/lib/texmf/tex/latex/cite/overcite.sty

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


%     O V E R C I T E . S T Y
%
%     version 3.6  (June 1996)
%
%     Compressed, sorted lists of superscript numerical citations.
%     see also CITE.STY and DRFTCITE.STY
%
%     Copyright (C) 1989-1996 by Donald Arseneau
%     These macros may be freely transmitted, reproduced, or modified
%     provided that this notice is left intact.
%
%     Instructions follow \endinput.
%  ------------------------------------
%   Handle optional variations:  [verbose,nospace,space,ref,nosort],
%   \citeform,\citeleft,\citeright,\citemid,\citepunct
%
%   Set defaults:

%   [ on the left.  Option [ref] does: [Ref. 12, note]
\@ifundefined{citeleft}{\let\citeleft=[}{}

%   ] on the right:
\@ifundefined{citeright}{\let\citeright=]}{}

%   , (comma space) before note
\@ifundefined{citemid}{\def\citemid{,\penalty\@medpenalty\ }}{}

%   , (comma thin-space) between entries; [nospace] eliminates the space
\@ifundefined{citepunct}{
   \def\citepunct{,\penalty\@m\hskip.13emplus.1emminus.1em}%
  }{}

%   Each number left as-is:
\@ifundefined{citeform}{\def\citeform{}}{}

%   Do not repeat warnings.  [verbose] reverses
\let\oc@verbo\relax

\@ifundefined{DeclareOption}{}%
{ \toks@={\def\oc@verbo#1#2#3#4{}}
  \DeclareOption{verbose}{\the\toks@}
  \DeclareOption{nospace}{\def\citepunct{,\penalty\@m}}
  \DeclareOption{space}{\def\citepunct{,\penalty\@highpenalty\ }}
  \DeclareOption{ref}{\def\citeleft{[Ref.\penalty\@M\ }}
  \DeclareOption{nosort}{\def\@addto@cite@list
   {\edef\@cite@list{\@cite@list \@celt{\@B@citeB}}}}
  \DeclareOption{sort}{\let\@cite@list\relax}% default!
  \ProvidesPackage{overcite}[1995/03/17 \space  v 3.6]
  \ProcessOptions
}

%----------------------
% \citen uses \nocite to ignore spaces after commas, and write the aux file
% \citation. \citen then loops over the citation tags, using \@make@cite@list
% to make a sorted list of numbers.  Finally, \citen executes \@citelist to
% compress ranges of numbers and print the list. \citen can be used by itself
% to give citation numbers without the brackets and other formatting; e.g.,
% "See also ref.~\citen{junk}."
%
\edef\citen{\noexpand\protect \expandafter\noexpand\csname citen \endcsname}

\@namedef{citen }#1{%
\nocite{#1}% ignores spaces, writes to .aux file, returns #1 in \@tempa!!
\@tempcntb\m@ne    % \@tempcntb tracks highest number
\let\@h@ld\relax   % nothing held from list yet
\let\@citea\@empty % no punctuation preceding first
\let\@celt\delimiter % an unexpandable, but identifiable, token
\def\@cite@list{}% % empty list to start
\@for \@citeb:=\@tempa \do{\@make@cite@list}% make a sorted list of numbers
% After sorted citelist is made, execute it to compress citation ranges.
\@tempcnta\m@ne    % no previous number
\let\@celt\@compress@cite \@cite@list % output number list with compression
\@h@ld}% output anything held over

% Aliases:
\let\citenum\citen
\let\citeonline\citen

% For each citation, check if it is defined and if it is a number.
% if a number: insert it in the sorted \@cite@list
% otherwise: output it immediately.
%
\begingroup \catcode`\_=8 % Just in case it was changed
\toks@={
\def\@make@cite@list{%
 \expandafter\let \expandafter\@B@citeB
          \csname b@\@citeb\@extra@b@citeb \endcsname
 \ifx\@B@citeB\relax % undefined: output ? and warning
    \@citea {\bf{?}}\let\@citea\citepunct \G@refundefinedtrue
    \@warning {Citation `\@citeb' on page \thepage\space undefined}%
    \oc@verbo \global\@namedef{b@\@citeb\@extra@b@citeb}{?}%
 \else %  defined               % remove previous line to repeat warnings
    \ifcat _\ifnum\z@<0\@B@citeB _\else A\fi % a positive number, put in list
       \@addto@cite@list
    \else % citation is not a number, output immediately
       \@citea \citeform{\@B@citeB}%
       \let\@citea\citepunct
 \fi\fi}
}
\expandafter \endgroup \the\toks@  % restore _ catcode

% Regular definition for adding entry to cite list, with sorting

\@ifundefined{@addto@cite@list}{% sort option either declared or defaulted
  \def\@addto@cite@list{\@tempcnta\@B@citeB \relax
     \ifnum \@tempcnta>\@tempcntb % new highest, add to end (efficiently)
        \edef\@cite@list{\@cite@list \@celt{\@B@citeB}}%
        \@tempcntb\@tempcnta
     \else % arbitrary number: insert appropriately
        \edef\@cite@list{\expandafter\@sort@celt \@cite@list \@gobble @}%
     \fi}
%
% \@sort@celt inserts number (\@tempcnta) into list of \@celt{num} (#1{#2})
% \@celt must not be expandable; list should end with two vanishing tokens.
%
  \def\@sort@celt#1#2{\ifx \@celt #1% parameters are \@celt {num}
       \ifnum #2<\@tempcnta % number goes later in list
          \@celt{#2}%
          \expandafter\expandafter\expandafter\@sort@celt % continue
       \else % number goes here
          \@celt{\number\@tempcnta}\@celt{#2}% stop comparing
    \fi\fi}
}% end sort option definitions
{}% nosort definition is done in options processing

% Check if each number follows previous and can be put in a range
%
\def\@compress@cite#1{%  % This is executed for each number
  \advance\@tempcnta\@ne % Now \@tempcnta is one more than the previous number
  \ifnum #1=\@tempcnta   % Number follows previous--hold on to it
     \ifx\@h@ld\relax    % first pair of successives
        \edef\@h@ld{\@citea \noexpand\citeform{#1}}%
     \else               % compressible list of successives
        \def\@h@ld{\hbox{--}\penalty\@m \citeform{#1}}%
     \fi % (using \hbox avoids easy \exhyphenpenalty breaks)
  \else   %  non-successor -- dump what's held and do this one
     \@h@ld \@citea \citeform{#1}\let\@h@ld\relax
  \fi \@tempcnta#1\let\@citea\citepunct
}

% Make \cite robust and choose superscript or normal
%
\edef\cite{\noexpand\protect\expandafter\noexpand\csname cite \endcsname}

\@namedef{cite }{\@ifnextchar[{\@tempswatrue\@citew}{\@tempswafalse\@citex}}

% \cite command has optional note, so do on line. Put highpenalty before; if
% no preceding space, or if preceding punctuation, then force interword space
%
\def\@citew[#1]#2{\leavevmode
  \@tempskipa\lastskip \edef\@tempa{\the\@tempskipa}\unskip
  \ifnum\lastpenalty=\z@ \penalty\@highpenalty \fi
  \ifx\@tempa\@zero@skip \spacefactor1001 \fi % if no space before, set flag
  \ifnum\spacefactor>\@m \ \else \hskip\@tempskipa \fi
  \citeleft{\citen{#2}\citemid{#1}%
  \spacefactor\@m % punctuation in note doesn't affect outside
  }\citeright}

%  No note, so superscript, but check for punctuation first.
%
\def\@citex#1{\begingroup \leavevmode \@tempcnta\@m \unskip
  \/% this allows the last word to be hyphenated, and it looks better.
  \def\@tempa{\@cite{\citen{#1}}\spacefactor\@tempcnta\endgroup}%
  \futurelet\@tempb\@citey}%
%% to not move punctuation, replace previous line with:
%%  \@tempa}%

%  Move trailing punctuation before the citation:
%
\def\@citey{\let\@tempc\@tempa
   % Watch for double periods and suppress them
   \ifx\@tempb.\ifnum\spacefactor>2999 \let\@tempb\relax\fi\let\@tempc\@citez
   % Move other punctuation
   \else\ifx\@tempb,\let\@tempc\@citez
   \else\ifx\@tempb:\let\@tempc\@citez % add other punctuation as necessary,
   \else\ifx\@tempb;\let\@tempc\@citez % with balancing \fi s
   \fi\fi\fi\fi
   \@tempc}%

% Place punctuation (except periods) before citation, and remember spacefactor
% of that punctuation
%
\def\@citez#1{\@tempcnta\sfcode`#1\@tempb\futurelet\@tempb\@citey}%

%  Replacement for \@cite which defines the formatting normally done
%  around the citation list.  This uses superscripts with no brackets.
%  HOWEVER, trailing punctuation has already been moved over.  The
%  format for cites with note is given by \@citew.  Redefine \@cite
%  and/or \@citew to get different appearance.
%
\def\@cite#1{$\m@th^{\hbox{\@ove@rcfont#1}}$}

\@ifundefined{selectfont}{% original LaTeX
   \def\@ove@rcfont{\the\scriptfont\z@ \def\bf{\the\scriptfont\bffam}}
  }{% NFSS
  \@ifundefined{fontsize}{% \fontsize undefined: strange NFSS
    \def\@ove@rcfont{\the\scriptfont\z@}\let\bf\relax % hope this works
    }{% `normal' NFSS/LaTeX2e:
    \def\@ove@rcfont{\csname S@\f@size\endcsname
        \fontsize{\sf@size}{\baselineskip}\selectfont}
 }}

\edef\@zero@skip{\the\z@skip}

% \nocite: This is changed to ignore *ALL* spaces and be robust.  The
% parameter list, with spaces removed, is `returned' in \@tempa, which
% is used by \citen.
%
\edef\nocite{\noexpand\protect\expandafter\noexpand\csname nocite \endcsname}

\@namedef{nocite }#1{%
\edef\@tempa{\@ignsp#1 \! }% remove *ALL* spaces from parameter list
\if@filesw \immediate \write \@auxout {\string \citation {\@tempa}}\fi}

% for ignoring *ALL* spaces in the input.  This presumes there are no
% \outer tokens and no \if-\fi constructs in the parameter.  Spaces inside
% braces are retained.
%
\def\@ignsp#1 {\ifx\!#1\@empty\else #1\expandafter\@ignsp\fi}

\let\nocitecount\relax  % in case \nocitecount was used for drftcite

\@ifundefined{@extra@b@citeb}{\def\@extra@b@citeb{}}{}
%  in case no fancy bib package (chapterbib) defines this

\@ifundefined{G@refundefinedtrue}{\let\G@refundefinedtrue\relax}{}

\endinput
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


                   OVERCITE.STY

Modify LaTeX's normal citation mechanism to:

o Display citations as superscript numbers, with a comma and a small space
  between each number, and with three or more consecutive numbers compressed
  into a range like 3-7.

o By default, sort citation numbers into ascending order; print non-numbers
  before numbers.  All numbers should be greater than zero.  (The [nosort]
  package option turns off sorting.)

o If an optional note is given, typeset the whole list of citations at regular
  size as if cite.sty was in effect.  (See cite.sty).

o Use THE SAME INPUT FORMAT as for ordinary citations; this style will ignore
  spaces before the citation, and move trailing punctuation to before the
  citation.  For example, "...information \cite{source};" ignores the space
  before \cite and puts the semicolon before the number, just as if you typed
  "...information;$^{12}$"

o The punctuation that will migrate before the superscript is .,;:.  Perhaps
  ! and ? should too, but they weren't listed in the APS style manual I looked
  at.  Quotes were listed, but they should never have to migrate because both
  on-line and superscript versions put quotes before the citation.  This gives
  one difficulty --- punctuation following quotes won't migrate inside the
  quotation.  For example,  "``Transition State Theory''\cite{Eyring}." gives
  "``Transition State Theory''.$^8$", but you may want the period inside the
  quotes, thus: ``Transition State Theory.''$^8$.

o Doubling of periods (.., ?., !.) is checked for and suppressed. The spacing
  after the citation is set according to the final punctuation mark moved.
  There is a problem with double periods after a capitalized abbreviation
  or directly after \@ : Both of "N.A.S.A. \cite{space}." and "et al.\@
  \cite{many}." will give doubled periods.  These can be fixed as follows:
  "N.A.S.A\@. \cite{space}." and "et al.\ \cite{many}.". These work properly
  for both cite.sty and overcite.sty, but the NASA example gives the wrong
  spacing when there is no citation.  Sorry.  Use \  after abbreviations like
  et al. to get the right spacing within a sentence whether or not a citation
  follows.

o Define \citen to get just the numbers without the brackets or superscript
  and extra formatting.  Aliases are \citenum and \citeonline for easy
  conversion to other citation packages.

o `Citation...undefined' warnings are only given once per undefined citation
  tag.  In the text, missing numbers are represented with a bold `?' at the
  first occurrence, and with a normal `?' thenceforth.  The package option
  [verbose] restores the usual repeated warnings.

o Make \nocite, \cite, and \citen all ignore spaces in the input tags.

Although each \cite command sorts its numbers, better compression into
ranges can usually be achieved by carefully selecting the order of the
\bibitem entries, or the order of initial citations when using BibTeX.
Having the entries pre-sorted will also save processing time, especially
for long lists of numbers.

Customization:
~~~~~~~~~~~~~~
There are several commands that you may redefine to change the formatting
of citation lists:

command       function                   default
----------    -----------------------    ----------------------------
\citeform     re-formats every entry     nothing
\citepunct    printed between numbers    comma + penalty + thin space
\citeleft     left delimiter of list     [
\citeright    right delimeter of list    ]
\citemid      printed before note        comma + space

The left/mid/right commands only affect the formatting of citations with
optional notes: \cite[xxx]{yyy}.  You may use \renewcommand to change any
of these.  Remember, these commands are extensions made by this package;
they are not regular LaTeX.

Under LaTeX2e, there are five options for \usepackage{overcite}:
 [verbose] causes warnings for undefined citations to be repeated each time
           they are used.
 [ref]     uses the format `[Ref.~12, optional note]' when \cite[]{} appears.
 [nospace] eliminates the spaces after commas in the number list.
 [space]   uses a full inter-word space with no penalty after the commas
 [nosort]  prevents sorting of the numbers (default is to sort).

These and other variations can be achieved using \renewcommand.
Some examples:

\renewcommand\citeform[1]{\romannumeral 0#1}} % roman numerals ^{i,vi}
\renewcommand\citeform[1]{(#1)} % parenthesized numbers ^{(1)-(5)}
\renewcommand\citeform{\thechapter.}  % by chapter: ^{2.18-2.21}
\renewcommand\citepunct{,} % no space and no breaks at commas
\renewcommand\citemid{; }  % semicolon before optional note
\renewcommand\citeleft{(}  % parentheses around list
\renewcommand\citeright{)} % parentheses around list

The appearance of the whole citation list is governed by \@cite, (for no
note) and \@citew (when a note is given).  For more extensive changes to the
formatting, redefine \@cite and/or \@citew.  For example, to get brackets
even in the superscripts, do:

\makeatletter \def\@cite#1{$\m@th^{\hbox{\@ove@rcfont[#1]}}$} \makeatother

Related Note:  overcite.sty does not affect the numbering format of
the bibliography; the "[12]" style is still the default.  To get
superscripts in the bibliography (at any time) you can include

   \renewcommand\@biblabel[1]{$^{#1}$}

in your personal style file, or include

   \makeatletter \renewcommand\@biblabel[1]{$^{#1}$} \makeatother

directly in your document.  If this does not work, your LaTeX and/or
document style are very outdated.

\@extra@b@citeb is a hook for other style files to further specify
citations; for example, to number by chapter (see chapterbib.sty).

See also cite.sty for enhanced [5-9] type citations, and drftcite.sty
for draft (draught) mode citations.

ROBUST!

% Version 1991: Ignore spaces after commas in the parameter list. Move most of
% \citen into \@cmpresscites for speed. Give the proper \spacefactor afterwards.
% Version 1992: make \citepunct hold the punctuation between numbers (for ease
% of changing).  Add \/ to allow hyphenation of previous word, and look better
% in italics.
% 1992a: Make it work with NFSS.  (Thank you C. Hamlin and Rainer Schoepf)
%
% Version 3.0 (1992):  Rewrite, including sorting.  Make entries like "4th"
% be treated properly as text.
% 3.1: Bug fixes (Joerg-Martin Schwarz also convinced me to use \ifcat)
% 3.2: NFSS support was wrong--added \reset@font.  Suppress repetitions of
%      warnings.  Include \@extra@b@citeb hook.
% 3.3: Handle LaTeX2e options. Introduce various customization hooks.
% 3.4: Heuristics to avoid removing \hspace glue before on-line \cite.
%      Make \nocite ignore spaces in list, simplify. Aliases for \citen.
%      Compatability with amsmath (which defines \over).
% 3.5: Replace \reset@font with \selectfont so italics are preserved
%      Include \G@refundefinedtrue.  Fix cite-with-note bug (Lars Engebretsen).
% 3.6: Add nosort option.
%
% Send problem reports to [email protected]

Test file integrity:  ASCII 32-57, 58-126:  !"#$%&'()*+,-./0123456789
:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].