%% file: TXSrefs.tex TeXsis version 2.15 % $Revision: 15.3 $ : $Date: 92/06/19 10:53:28 $ : $Author: myers $ %======================================================================* % REFERENCES - (C) copyright 1986, 1992 by Eric Myers % These macros use TXStags to handle 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 % \reference{} \endreference % The can be almost anything, including a number. If it is *, 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 . It also saves the tag definition % in \jobname.aux, and saves the reference in the file \jobname.ref % Of course, is the desired % reference text, e.g. "D.~Knuth, {\sl The TeXbook}". The final punctuation % should NOT be typed in ; a . is added unless the next tag is *, % in which case a ; 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 with the macro \ListReferences % (or \References for backwards compatibility). To allow for multiple % references with the same number, \ListReferences adds a ; to the end of % a reference if the next tag is * and a . 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 is not 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. % Dependencies: TXStags.tex for reference labels %======================================================================* \message{References and Citations.} \catcode`@=11 % 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\ifsuperrefs \superrefstrue % print ref numbers as superscripts \newif\ifmarkit \markittrue % switch for "hidden" references \newif\ifnullname \nullnamefalse % switch for null or starred labels \newif\iftagit % switch for tagging references \newif\ifreffollows % switch for many \ref's \newif\ifrefpunct \refpuncttrue % automatic punctuation at end \def\refterminator{} % start with this null \newdimen\refindent \refindent=2em % indentation for references \newdimen\refpar \refpar=20pt % indentation for ref. paragraphs \newbox\tempbox % for getting \refindent %==================================================* % INITIALIZATION. \refinit performs first time reference initialization \newwrite\reflistout % output file for ref text \def\refinit{\ifrefswitch % is .ref ouput enabled? \immediate\openout\reflistout=\jobname.ref % y: open .ref file for output \else % no: \let\@refwrite=\@refwrong % disable output \let\@refNXwrite=\@refwrong % disable output \immediate\closeout\reflistout % and make sure output closed \fi % \gdef\refinit{\relax}% % disable \refinit % \@refwrite{text} writes text to .ref file, while % \@refNXwrite{text} writes the text to the file without expanding it. \def\@refwrite#1{\refinit % perform initialization, if needed \immediate\write\reflistout{#1}}% % write to .ref \def\@refNXwrite#1{\refinit % initialize if needed \unexpandedwrite\reflistout{#1}}% % do unexpanded write % Write to SYS$DUMMY=/dev/null (i.e., thin air) if output disabled \def\@refwrong#1{}% % 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 }% % (and will cite when done) \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*\fi % sets \nullnametrue if null or *'d \ifnullname\relax\else % unless name is null \global\advance\refnum by \@ne % increment \refnum \@lastrefnum=\refnum % and \@lastrefnum \edef\rnum{\the\refnum}% % \rnum is the ref number \tag{Ref.#1}{\rnum}% % tag the reference \ifnum\pageno>\z@ % if not on page 0, announce \begingroup % make these local \quoteoff\offparens % make ",(, ), characters, not active \immediate\write16{(\the\refnum) %% write comment to .LIS and terminal First reference to "#1" on page \the\pageno.}% \endgroup % " back to whatever it was \fi % end \ifnum \fi % end \ifnullname % \ifstar determines whether a tag begins with "*", and sets a flag \def\ifstar#1#2\fi{\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. #1 is the label. \def\@GetRefText#1{% % get and write reference text \ifnullname % is name null (set by \@tagref) \p@nctwrite;\relax % y: write ";" and line break \begingroup\quoteoff % turn off special " \@refwrite{\@comment Reference text for %% "#1" defined on page \number\pageno.}% \endgroup % let " be whatever it was \else % n: write "." and number \ifnum\refnum>1 % first reference? \p@nctwrite.\fi % no: write trailing . \begingroup\quoteoff\@parensoff % turn off special ",),( \@refwrite{\@comment }% % \@refwrite{\@comment (\the\refnum)}% write comment to .ref file \@refwrite{\@comment Reference text for %% "#1" defined on page \number\pageno.}% \endgroup % let " be whatever it was \@refwrite{\NX\@refitem{\the\refnum}}% write ref number to .ref \fi % % % Write reference to .ref file \begingroup % start group to write text \def\endreference{\NX\endreference}% % def these to nothing \def\reference{\NX\reference}% % so we can play with them \def\ref{\NX\ref}% % without using them \obeylines % so ^M seen by \@copyref \@copyref % copy text line to .ref file }% % \@copyref gets the next line of text and sends it to \ParseRefText % to scan for \endreference and act accordingly {\obeylines % to see end of line \gdef\@copyref#1 {\def\@arg{#1}\ifx\@arg\emtpy\relax\let\@nextline=\@copyref %% get next line \else\ParseRefText#1\endreference\endreference\endlist\fi %% PARSE line \@nextline}% %% next iteration }% % end \obeylines % \ParseRefText looks at the line for \endreference. If it is present, % then #1 is text before, #2 is text after, and #3 is \endreference. If it % is not present then #2 and #3 are null, and #1 is the line. \def\ParseRefText#1\endreference#2\endreference#3\endlist{% parse \reference \def\@arg{#1}\ifx\@arg\empty\relax % if #1 null, don't write it \else\begingroup % otherwise, \@refNXwrite{#1}% % write unexpanded line \endgroup % ^^M, \@quote reset \fi % \def\@arg{#3}\ifx\@arg\empty % \let\@nextline=\@copyref % if no \endreference, repeat \else\let\@nextline=\@endcopyref % otherwise, exit loop \gdef\@remainder{\@endreference #2}% % save rest of line for later \fi}% % and do \@nextline \def\@endcopyref{\endgroup % make \ref, etc... defs active again \@remainder % do \@endreference on rest of line }% % \@comment is for writing % to a file like the .ref file. It expands % to the letter '%' and a space {\catcode`\%=11 \gdef\@comment{% }} \def\@parensoff{\catcode`\(=11 \catcode`\)=11} % \@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\refrange\reffollowstrue\fi % or \refrange \ifx#1\ref\reffollowstrue\fi % (or \ref, OLD TeXsis) \ifx#1\reference\reffollowstrue % if \reference set flag \else % but nothing more \ifnum\@firstrefnum>\@lastrefnum\relax % If *'d \reference, \relax \else\ifmarkit % so can we write citation? % --- construct the reference mark for this reference or range in \@refmark \ifnum\@firstrefnum=\@lastrefnum % is there only one reference? \xdef\@refmark{\the\@lastrefnum}% % yes: write only one number \else % no: write a \xdef\@refmark{\the\@firstrefnum-\the\@lastrefnum}% range of numbers \fi % end \ifnum \global\@firstrefnum=\refnum % reset \@firstrefnum to be \global\advance\@firstrefnum by \@ne % \refnum + 1 \add@refmark % add \@refmark to \@refmarklist \fi\fi % end \ifnum and \ifmarkit \fi % end \ifx#1\reference \flush@reflist{#1}% % output ref mark list #1} % do the remaining #1 lookahead \def\endreference{% end the \reference text \emsg{> Whoops! \NX\endreference was called without first calling \NX\reference.}\@errmark{REF?}% % \emsg{> I'll just ignore it.}% % }% % \def\@refspace{\ } % \space@head#1 takes the lookahead token from \@endreference or % \cite and does nothing if it is punctuation. Otherwise it puts % in a \space. It does not put the token back on the list! (the % calling macro does that.) Note that in TeXsis ), ], and " can % be active characters that have macro definitions, so they must % be handled separately. {\quoteon \gdef\space@head#1{\relax % #1 is from look-ahead \def\sp@ce@head{\space}% % normally a space \ifcat.\NX#1\relax\def\sp@ce@head{\relax}\fi % no space if punct. \ifx)#1\def\sp@ce@head{\relax}\fi % no space if active ) \ifx]#1\def\sp@ce@head{\relax}\fi % no space if active ] \ifx"#1\def\sp@ce@head{\relax}\fi % no space if active " \sp@ce@head}% % space or nothing % \citemark{#1} creates the superscript reference number using #1 % as the text. It is called by \endreference, or may be called by the user % using \use to get the value of a tag. (NOTE: the tag is actually Ref.#1 % and not just #1, so say \use{Ref.label}) \def\citemark#1{% output the citation marks in the text \relax % \ifhmode\edef\@sf{% % save spacefactor \spacefactor\the\spacefactor}\/\fi % \ifsuperrefs % superscript references? $\relax{}^{\hbox{$\citestyle % small numbers #1\refterminator$}}$\relax % superscript \else {}~[{#1}]\relax\fi % [] style \@sf}% % restore spacefactor \def\citestyle{\scriptstyle} % default citation size % 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 \begingroup % make change to \citemark local \pageno=0 % not a real page \def\citemark##1{\relax}% % \citemark does nothing here \def\@refspace{\relax}} % no spaces!!! \def\endreferencelist{% end \referencelist \endgroup} % all as it was %==================================================* % CITATIONS. \cite{