home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Education Sampler 1992 [NeXTSTEP]
/
Education_1992_Sampler.iso
/
Mathematics
/
TeX
/
TeXsis-2.15
/
TXSrefs.tex
(
.txt
)
< prev
next >
Wrap
LaTeX Document
|
1992-08-04
|
29KB
|
460 lines
%% 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{<tag>} <text> \endreference
% The <tag> 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 <tag>. It also saves the tag definition
% in \jobname.aux, and saves the reference <text> in the file \jobname.ref
% Of course, <text> is the desired
% reference text, e.g. "D.~Knuth, {\sl The TeXbook}". The final punctuation
% should NOT be typed in <text>; 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{<tag1>} <text1> \endreference
% \reference{<tag2>} <text2> \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{<tag>}. 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 <tag> is not defined,
% then \cite produces an error, which is flagged both in the printed document
% and on the log file. A \Ref{<tag>} macro (note the case) is also provided
% to print Ref.~<number> in the text. Other forms can be constructed if
% desired with \use{Ref.<tag>}; 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} <text> \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{<label>} cites a previously defined reference given
% by <label>. (There is only one user argument, #2 is for lookahead.)
\long\def\cite#1#2{% cite a previous reference in the text
\markittrue % make sure output is on
\reffollowsfalse % assume no ref. follows
\ifx#2\cite\reffollowstrue\fi % is next token another \cite?
\ifx#2\refrange\reffollowstrue\fi % or \refrange
\ifx#2\ref\reffollowstrue\fi % (or \ref, OLD TeXsis)
\ifx#2\reference\reffollowstrue\fi % or is it \reference? then set flag.
\make@refmark{#1}% % make reference mark in \@refmark
\add@refmark % add \@refmark to \@refmarklist
\flush@reflist{#2}% % flush \@refmarklist to output
#2}% % do the remaining arg #2
\let\ref=\cite % \ref is synonym (old TeXsis)
\def\@refmarklist{} % start with nothing in list
\gdef\refbef@re{F} % flag = no references before
% \make@refmark takes the reference label and put the reference number
% (if there is one) in \@refmark
\def\make@refmark#1{% make a reference mark
\testtag{Ref.#1}\ifundefined % is it undefined? (tag -> \tok)
\emsg{> UNDEFINED REFERENCE #1 ON PAGE \number\pageno.}% error message
\advance\@BadRefs by 1 % count undefined references
\xdef\@refmark{{\tenbf #1}}% % cite with label in boldface
\@errmark{REF?}% % and mark error in output
\else % no:
\xdef\@refmark{\csname\tok\endcsname}% cite with number
\fi} % end of \ifundefined
% \add@refmark adds \@refmark to the \@refmarklist
\def\add@refmark{% add reference mark to accumulating list
\if\refbef@re T\relax % any previous citations?
\xdef\@refmarklist{\@refmarklist,\@refmark}% yes: add on new one
\else %
\xdef\@refmarklist{\@refmark}% % no: just one mark
\gdef\refbef@re{T}% % but now set the flag
\fi}
% \flush@reflist flushes the \@refmarklist to the output.
% #1 is the lookahead token, used to see if we need to add space afterwards.
\long\def\flush@reflist#1{% flush list of references to output
\ifmarkit % is \markit set? Then write citation
\ifreffollows\else % Is there a following citation?
\citemark{\@refmarklist}% % no: print citation
\gdef\refbef@re{F}% % reset flag and
\gdef\@refmarklist{}% % empty \@refmarklist
\ifx#1\par\else\space@head{#1}\fi % insert possible space after
\fi\fi} % end \ifreffollows\ifmarkit
% \Ref{label} (note the case!) returns the reference number of a
% previously entered reference for use in text. If you don't like
% the way this looks you can change it to suit yourself.
\def\Ref#1{Ref.~\use{Ref.#1}}
% \refrange#1#2 cites a range of previously defined references like
% \cite. #3 is a lookahead.
\long\def\refrange#1#2#3{% cites a range of references
\reffollowsfalse % assume no ref. follows
\ifx#3\cite\reffollowstrue\fi % is next token another \cite?
\ifx#3\ref\reffollowstrue\fi % (or \ref, OLD TeXsis)
\ifx#3\reference\reffollowstrue\fi % or is it \reference? then set flag.
\ifx#3\refrange\reffollowstrue\fi % or \refrange
% --- construct reference mark in \@refmark
\make@refmark{#2}% % ref mark for 2nd ref
\xdef\@refmarktwo{\@refmark}% % save for later
\make@refmark{#1}% % ref mark for 1st ref
\xdef\@refmark{\@refmark-\@refmarktwo}% create range of references
\add@refmark % add to \@refmarklist
\flush@reflist{#3}% % flush output list
#3}% % do the remaining #3 args
%==================================================*
% The following macros are used in the reference text to print
% properly volume numbers for journals, titles of books, etc.
\def\NP{Nucl.\ Phys.}
\def\PL{Phys.\ Lett.}
\def\PR{Phys.\ Rev.}
\def\PRL{Phys.\ Rev.\ Lett.}
% \vol{volume of journal} is used for the volume number of a journal
% article. The number is underlined when printed. (Underscoring looks
% better than boldface on the laser printer.)
\def\vol#1{\undertext{#1}}
% \booktitle{title of book} prints book title in slanted type
\def\booktitle#1{{\sl #1}}
% some other useful shorthand
\def\etal{{\it et al.}}
\def\ie{{\it i.e.}}
\def\cf{{\it cf.}}
\def\ibid{{\it ibid.}}
%==================================================*
% LIST OF REFERENCES. \ListReferences gets the list of references
% from the .ref file and adds it to the document. \References is a
% synonym (from v.2.04). No heading is printed; the user should add
% one with \chapter, \section, or whatever is appropriate.
\def\ListReferences{\emsg{Reference List}% % announce in .LIS file
\p@nctwrite.\relax % write last "." for last ref
\@refwrite{\@comment>>> EOF \jobname.ref <<<}%% and EOF marker comment
\immediate\closeout\reflistout % then close the .ref file
\ifnum\@BadRefs>\z@ % any undefine references?
\emsg{>}\emsg{> There were \the\@BadRefs\ undefined references.}%
\emsg{> See the file \jobname.log for the citations, or try running}%
\emsg{> TeXsis again to resolve forward references.}\emsg{>}%
\fi %
\begingroup % now read in the .ref file
\catcode`@=11 % make @ a letter
\offparens % make sure )&) not active
\unobeylines % treat ^^M like whitespace
\setbox\tempbox\hbox{\the\refnum.\quad}% % size of largest ref number?
\refindent=\wd\tempbox % refindent to handle this
\leftskip=\refindent % set up reference indent
\parindent=\z@ % don't indent after breaking
\def\reference{\@noendref}% % in case of errors
\refFormat % user definable format info
\Input\jobname.ref \relax % read text from .ref file
\vskip 0pt % needed to close \leftskip!
\endgroup % close group
\emsg{}% % Newline line in log
}% % end of \References
\def\References{\ListReferences}% % synonym
% \refFormat is called just before the reference file is read in.
% It can contain instructions for formatting the reference list. For example,
% in two-column output it might be good to have it include a \raggedright.
\def\refFormat{\relax}%
\def\@noendref#1{% %
\emsg{> Whoops! \NX\reference{#1} was given before the}% %
\emsg{> \NX\endreference for the previous \NX\reference.}% %
\emsg{> I'll just ignore it and run the two together.}% %
}%
% \@refitem starts a new reference, with the number in the left margin
% For use by \ListReferences when printing reference list.
% \refindent is the indentation for the main text (not the number).
% \refskip is the skip between references (default is \smallskip).
\def\@refitem#1#2{\message{#1.}% #2 looks past ^^M for next arg
\refskip\noindent\hskip-\refindent % indent, but write number
\hbox to \refindent {\hss #1.\quad}% % unindented
#2}
\def\refskip{\smallskip}% % default skip
% \@refpunct gets the punctuation for the reference text and kills
% the space and carriage return before it.
\def\@refpunct#1{\unskip#1}% % remove space and print . or ;
% \p@nctwrite#1 writes punctuation #1 to .ref file only if \ifrefpunct
% is true. Use this to turn off automatic punctuation of references.
\def\p@nctwrite#1{%
\ifrefpunct % if switch is true
\@refwrite{\NX\@refpunct#1\NX\@refbreak}% % write #1 and line break
\else % else
\@refwrite{\NX\@refbreak}% % just write a break
\fi}
% \@refbreak causes a line break if \ifbreakrefs is true.
\def\@refbreak{\ifbreakrefs\par\fi}
%======================================================================*
% \journal simplifies typing journal references in technical papers
% by providing automatic formatting and automatic correct treatment of
% abbreviations. By default typing
% \journal Phys. Rev. Lett.;vol;page(year)
% produces
% Phys. Rev. Lett. vol, page (year)
% All periods in name are followed by a single space as if you had typed
% Phys.\ Rev.\ Lett.\ and the volume number is underlined.
% If you first type
% \Eurostyletrue
% then \journal produces
% Phys. Rev. Lett. vol (year) page
% appropriate to European journals. Note that the arguments to \journal
% are ALWAYS in the American order.
% \journal can be used to define macros for specific journals, but
% in this case all . MUST be typed as .\ because of the way that TeX
% uses \catcodes for characters.
%-----------------------------------------------------------------------
\newif\ifEurostyle \Eurostylefalse % European style journals
% When . is active instead of punctuation it gives no space
{\catcode`\.=\active % . is active
\gdef.{\hbox{\p@riod\null}}} % . is .\null for abbrev
\def\p@riod{.} % normal period
% Define main macro \journal. This turns on definition of . and
% turns off easy parens, then does work with \j@ounal.
\def\journal{% cite an article in a journal by volume, page and year
\bgroup % keep \catcode's local
\catcode`\.=\active % make . active
\offparens % turn off easy parens
\j@urnal}% % and do work
\offparens % make sure ( and ) not active!
\def\j@urnal#1;#2,#3(#4){% gets the \journal material
\ifEurostyle % choose style...
{#1} {\vol{#2}} (\@fullyear{#4}) #3\relax % European style
\else %
{#1} {\vol{#2}}, #3 (\@fullyear{#4})\relax % American style
\fi %
\egroup} % end group for . and ()
% \@fullyear takes one argument, which is considered to be a year.
% If it is less than 100 then it is an abreviation, so we add the
% current century to it if it is less than or equal to THIS year,
% otherwise we add the LAST century. This should survive into
% the next millenium. Thanks to Scott Hannahs for this macro.
\def\@fullyear#1{%
\begingroup % make calculations local
\count255=\year % get current century
\divide \count255 by 100 \multiply \count255 by 100
\count254=\year % next year in this century
\advance \count254 by -\count255 \advance \count254 by 1
\count253=#1\relax % citation year
\ifnum\count253<100 % year < 100 needs century
\ifnum \count253>\count254 % high year
\advance \count253 by -100\fi % means last century
\advance \count253 by \count255 % add centuries
\fi %
\number\count253 % display year
\endgroup % end local calculations
%>>> EOF TXSrefs.tex <<<