%% TXSrefs.tex - Citations and References - TeXsis version 2.18 %% @(#) $Id: TXSrefs.tex,v 18.8 2000/05/16 22:46:08 myers Exp $ %======================================================================* % TeXsis - TeX Macros for Physicists -- Citations and References % % These macros take care of citations and references with automatic % numbering. The references can either be typed in the body of the document % or collected at the beginning. In either case a new reference is defined % by saying % \reference{} \endreference % % The can be almost anything, including a number. If it begins % with "*" then the reference number is not incremented; this allows % multiple references with the same number. Otherwise, \reference causes % the next available reference number to be assigned to the . It also % saves the tag definition in \jobname.aux, and saves the reference % in the file \jobname.ref. The final punctuation should NOT be % typed in ; a period is added unless the next tag begins with "*", % in which case a semicolon is added. % % If \reference ... \endreference is typed in the body of the document, % the reference number is printed. The default format is a superscript, but % this can be changed: % \superrefstrue ==> superscript reference numbers % \superrefsfalse ==> reference numbers in [] % \endreference actually looks ahead at the next token; if it is another % \reference, then a range is printed instead of separate numbers. % % \referencelist ... \endreferencelist can be used to type all of the % references at the beginning of the document, with the format % \referencelist % \reference{} \endreference % \reference{} \endreference % ... % \endreferencelist % While it is natural with this format to make the tag equal to the actual % reference number, this is not required. % % Subsequent references to a previously defined reference are obtained % with \cite{}. Again this has a look-ahead feature so that several % consecutive \cite's give the reference numbers separated by commas. If the % references are typed at the beginning with \referencelist, then all % references in the text are made with \cite. If the is not defined, % then \cite produces an error, which is flagged both in the printed document % and on the log file. A \Ref{} macro (note the case) is also provided % to print Ref.~ in the text. Other forms can be constructed if % desired with \use{Ref.}; see the definition of \Ref. % % The list of references is printed by saying \ListReferences (or % \References for backwards compatibility). To allow for multiple % references with the same number, \ListReferences adds a semicolon to % the end of a reference if the next tag begins with "*" and a period % otherwise. Hence the final punctuation should not be typed in the % reference text. Note that \ListReferencese does not print a heading, % which should be inserted using \chapter, \section, or the appropriate % plain TeX commands. % % If \texsis has not been called, then the reference text will be % written to the screen, and \ListReferences will fail to print the % appropriate text. If \auxswitchfalse is used, then the AUX file will % not be written, and the tag definitions will appear on the screen % (surrounded by \csname ... \endcsname). This causes no harm unless the % checkpoint/restart feature is used, in which case the earlier tag % definitions will not be remembered. %======================================================================* % (C) Copyright 1986, 1992, 1995, 1997, 1999 by Eric Myers and Frank Paige. % This file is a part of TeXsis. Distribution and/or modifications % are allowed under the terms of the LaTeX Project Public License (LPPL). % See the file COPYING or ftp://ftp.texsis.org/texsis/LPPL %======================================================================* \message{References and Citations.} \catcode`@=11 % @ is a letter here for hidden names \catcode`\"=12 \catcode`\(=12 \catcode`\)=12 % Counters, switches and I/O: \newcount\refnum \refnum=\z@ % counter for reference numbers \newcount\@firstrefnum \@firstrefnum=1 % first of a series of refs \newcount\@lastrefnum \@lastrefnum=1 % last of a series of refs \newcount\@BadRefs \@BadRefs=0 % count undefined references \newif\ifrefswitch \refswitchtrue % output references by default \newif\ifbreakrefs \breakrefstrue % line break between refs? \newif\ifrefpunct \refpuncttrue % automatic punctuation at end? \newif\ifmarkit \markittrue % flag for "hidden" references \newif\ifnullname % flag for null or "*" labels \newif\iftagit % flag for tagging references \newif\ifreffollows % flag for many \ref's \def\refterminator{} % could be ) after a superscript \def\RefLabel{} % used in hyperlink tags % Indentation of references in the list is controled by \refindent % If it is negative then it's automatically reset to the right values \newdimen\refindent \refindent= -100pt % \@comment is for writing % to a file like the .ref file. It expands % to the letter '%' and a space {\catcode`\%=11 \gdef\@comment{% }} \newcount\CiteType \CiteType=1 % type of citation style %%\newif\ifsuperrefs \superrefstrue % OBSOLETE! Use these: \def\superrefstrue{\CiteType=1} % Superscript citation marks \def\superrefsfalse{\CiteType=2} % In-line citation marks %==================================================* % INITIALIZATION. \refinit performs first time reference initialization \newwrite\reflistout % output file for ref text \newread\reflistin % input file for .ref file \def\@refinit{% Initialize reference file \immediate\closeout\reflistout % and make sure output closed \ifrefswitch % is .ref ouput enabled? \@FileInit\reflistout=\jobname.ref[List of References]%% yes: initialize \else % no: disable output \let\@refwrite=\@refwrong \let\@refNXwrite=\@refwrong \fi \gdef\refinit{\relax}} % and disable \refinit % \refReset resets the counters so that more references can be % created after \ListReferences has been called; For example, if % you listed the references for one chapter and want to begin collecting % references for the next chapter. \def\refReset{% reset reference/citation counters \global\refnum=\z@ % counter for reference numbers \global\@firstrefnum=1 % first of a series of refs \global\@lastrefnum=1 % last of a series of refs \global\@BadRefs=0 % count undefined references \gdef\refinit{\@refinit}} % re-enable \refinit \refReset % Make it so % \@refwrite{text} writes text to .ref file, while % \@refNXwrite{text} writes the text to the file without expanding it. \def\@refwrite#1{\refinit\immediate\write\reflistout{#1}} \def\@refNXwrite#1{\refinit\unexpandedwrite\reflistout{#1}} \def\@refwrong#1{}% do nothing (sorry for the pun) %==================================================* % REFERENCE TEXT. % \reference{lable} \endreference defines a new reference entry \long\def\reference#1{% cite a new reference, with reference text \markittrue % enable citation in output \@tagref{#1}% % get next number and tag it \@GetRefText{#1}} % write ref text to .ref file \long\def\addreference#1{% \reference without citation \markitfalse % don't cite in output \@tagref{#1}% % get a number and tag it \@GetRefText{#1}} % write ref text to .ref file \def\hiddenreference{\addreference}% backward compatability (v.2.02) % \@tagref{label} assigns the next reference number to the label, % unless the name begins with * or is null \def\@tagref#1{% assign a reference number to a tag \stripblanks #1\endlist % remove blanks. Result --> \tok \XA\ifstar\tok*\relax % sets \nullnametrue if null or *'d \ifnullname\relax\else % unless name is null \def\RefLabel{#1}% % save label name %% \ifnum\CiteType=4 % Footnotes references: coordinate \ifnum\footnum>\refnum % ... \footnum and \refnum \global\refnum=\footnum \global\@firstrefnum=\refnum \global\advance\@firstrefnum by \@ne \fi \fi %% \global\advance\refnum by \@ne % increment the \refnum \global\@lastrefnum=\refnum % and the \@lastrefnum \edef\rnum{\the\refnum}% % \rnum is the ref number \tag{Ref.#1}{\rnum}% % tag the reference number \ifnum\CiteType>0 % announce unless silent \reference \immediate\write16{(\the\refnum) %% write comment to .LIS and terminal First reference to "#1" on page \the\pageno.}\fi \fi} % end \ifnullname % \ifstar determines whether a tag begins with "*", and sets a flag \def\ifstar#1#2\relax{\ifx*#1\relax\nullnametrue\else\nullnamefalse\fi} % \@GetRefText gets the reference text as everything up to the next % \endreference and writes it to the .ref file, at least for citation % styles which save the list to the end. #1 is the label. % #2 is lookahead past possible line end before \seeCR \def\@GetRefText#1#2{% % get and write reference text \ifnum\CiteType=4\else % footnotes rather than ref list? \ifnullname % Is name null (set by \@tagref)? \p@nctwrite{; }% % punctuation for continuation \@refwrite{\@comment ... Reference text for %% "#1" defined on page \number\pageno.}% \@refwrite{\@refbreak}% % and a possible line break \else % No: just begin another... \ifnum\refnum>1\p@nctwrite{. }\fi %!% trailing period, unless first one \@refwrite{\@comment }% % \@refwrite{\@comment (\the\refnum) Reference text for %% "#1" defined on page \number\pageno.}% \@refwrite{\string\@refitem{\the\refnum}{#1}}% write label info \fi \fi %% \begingroup % start group to write text \def\endreference{\NX\endreference}% disable these in references \def\reference{\NX\reference}\def\ref{\NX\ref}% \seeCR\newlinechar=`\^^M % so ^^M seen by \@copyref \@copyref#2} % copy text line to .ref file % \@copyref copies the text up to the \endreference to the .ref % file and then performs the \endreference \def\@copyref#1\endreference{% copy reference text to .ref file \endgroup % end \seeCR \ifnum\CiteType=4 % footnotes rather than ref list? \ifnum\footnum<\refnum\global\footnum=\refnum\fi % sync w/ \footnum \Vfootnote{\ifnullname\relax\else {\CiteStyle{\the\refnum}}\fi} %% That space is needed! Why? {\hangindent=\parindent\hangafter=1\seeCR #1\@refpunct.}% \else % write text to .ref file \@refNXwrite{#1\@endrefitem}% \fi % \@endreference} % do \endreference stuff... \def\@endrefitem#1{#1} % for future expansion... % \@endreference is post processing (what user thinks is \endreference). % \@endreference checks to see if another \reference follows. If not, it puts % the citation mark in the output \long\def\@endreference#1{% end a \reference and look ahead at next token \reffollowsfalse % assume no cit'ns follow \ifx#1\cite\reffollowstrue\fi % is next token another \cite? \ifx#1\citerange\reffollowstrue\fi % or \citerange \ifx#1\refrange\reffollowstrue\fi % or \refrange \ifx#1\ref\reffollowstrue\fi % (or \ref, OLD TeXsis) \ifx#1\reference\reffollowstrue % \reference follows? \ifnum\CiteType=3 % citation for [named] references \xdef\@refmark{\linkto{Ref.\RefLabel}{\RefLabel}}\add@refmark\fi \ifnum\CiteType=6 % citation for (named) references \xdef\@refmark{\linkto{Ref.\RefLabel}{\RefLabel}}\add@refmark\fi \else % not a \reference, so dump citations \ifnum\@firstrefnum>\@lastrefnum\relax % If *'d \reference be quiet \else % % % Construct the reference mark for this reference or range in \@refmark % \ifnum\CiteType=3 % [named] reference \xdef\@refmark{\linkto{Ref.\RefLabel}{\RefLabel}}% \else\ifnum\CiteType=6 % (named) reference \xdef\@refmark{\linkto{Ref.\RefLabel}{\RefLabel}}% \else % \ifnum\@firstrefnum=\@lastrefnum % is there only one reference? \xdef\@refmark{\linkto{Ref.\the\@lastrefnum}{\the\@lastrefnum}}% \else % no: write a range of numbers \xdef\@refmark{\linkto{Ref.\the\@firstrefnum}{\the\@firstrefnum}-% \linkto{Ref.\the\@lastrefnum}{\the\@lastrefnum}}% \fi % end \ifnum\@firstrefnum= \fi\fi % endif 3 or 5 %% \global\@firstrefnum=\refnum % reset \@firstrefnum to be ... \global\advance\@firstrefnum by \@ne% \refnum + 1 \add@refmark % add \@refmark to \@refmarklist \fi % end \ifnum\@firstrefnum \fi % end \ifx#1\reference \flush@reflist{#1}}% % output ref mark list \def\endreference{% end the \reference text \emsg{> Whoops! \string\endreference was called without first calling \string\reference.}\@errmark{REF?}% \emsg{> I'll just ignore it.}% }% \def\@refspace{\ } % \citemark{#1} creates the citation mark, in a format determined % by \CiteType. The possible choices are: % 0 = no mark (silently adds the reference to list) % 1 = superscript reference numbers % 2 = reference numbers in the text in [brackets] % 3 = citation in the text by name-date (using the label) in [brackets] % 4 = supercript reference numbers for references as FOOTNOTES % 5 = reference numbers in the text in (parens) % 6 = citation in the text by name-date (using the label) in (parens) \def\citemark#1{% output the citation marks in the text \relax\let\@sf\empty % \ifhmode\edef\@sf{\spacefactor\the\spacefactor}\/\fi % save spacefactor \ifcase\CiteType\relax % 0: no citation mark \or % 1: superscript numbers $\relax{}^{\hbox{$\scriptstyle\CiteStyle{#1\refterminator}$}}$\relax \or {}~[{\CiteStyle{#1}}]\relax % 2: [] style in-line \or {}~[{\CiteStyle{#1}}]\relax % 3: [] style in-line \or % 4: superscript numbers, $\relax{}^{\hbox{$\scriptstyle\CiteStyle{#1\refterminator}$}}$\relax % \or {}~({\CiteStyle{#1}})\relax % 5: () style in-line \or {}~({\CiteStyle{#1}})\relax % 6: () style in-line \else\relax\fi % else: nothing \@sf}% % restore spacefactor \def\CiteStyle{\relax} % default citation type size/style % Turn off \citemark output. For typing a list of references all % together at the begining of a document. \def\referencelist{% begin a list of references at front of document \ifnum\CiteType=4 % footnotes rather than ref list? \emsg{> Warning: \string\referencelist is not compatible with %% footnoted reference citations.}\fi \begingroup \pageno=0\CiteType=0} % disable citations \def\endreferencelist{% end \referencelist \endgroup} % all as it was %==================================================* % CITATIONS. % % New way of controlling citation style is by \CiteType. % The possible choices are: % 0 = no mark (silently adds the reference to list) % 1 = superscript reference numbers % 2 = reference numbers in the text in [brackets] % 3 = citation in the text by label as key, in [brackets] % 4 = supercript reference numbers for references as FOOTNOTES % 5 = reference numbers in the text in (parens) % 6 = citation in the text by label as key, in (parens) \def\CiteBySuperscript{\CiteType=1} % superscript number \def\CiteByNumber{\CiteType=2} % reference number in [brackets] \def\CiteByTag{\CiteType=3} % tag in [brackets] \def\CiteByLabel{\CiteType=3} % synonym \def\CiteByFootnote{\CiteType=4} % superscript number, text as footnote \def\CiteByWhatever{\CiteType=5} % reference number in (parens) \def\CiteByAuthor{\CiteType=6} % tag in (parens) % \cite{