%%                              JNL.TEX
%%
%%                This is JNL.TEX Version 0.3 as of 6/12/85.
%%
%%      This is a set of TeX 82 macros designed to produce scientific
%%      papers with a minimum of fuss and using as much of plain.tex as
%%      possible.  The user need only know what is in the TeXbook, and
%%      the macros under ``user definitions'' below.  Also, the user
%%      definitions are intended to be as simple as possible, so that
%%      the user may change them as desired.


%%
%%  Font definitions suitable for the IMAGEN (Written by Tony Kennedy)
%%

%  Define a whole menagerie of pseudo-12pt fonts

\font\twelverm=cmr10 scaled 1200    \font\twelvei=cmmi10 scaled 1200
\font\twelvesy=cmsy10 scaled 1200   \font\twelveex=cmex10 scaled 1200
\font\twelvebf=cmbx10 scaled 1200   \font\twelvesl=cmsl10 scaled 1200
\font\twelvett=cmtt10 scaled 1200   \font\twelveit=cmti10 scaled 1200

\skewchar\twelvei='177   \skewchar\twelvesy='60

%  Define \...point macros to change fonts and spacings consistently

\def\twelvepoint{\normalbaselineskip=12.4pt
  \abovedisplayskip 12.4pt plus 3pt minus 9pt
  \belowdisplayskip 12.4pt plus 3pt minus 9pt
  \abovedisplayshortskip 0pt plus 3pt
  \belowdisplayshortskip 7.2pt plus 3pt minus 4pt
  \smallskipamount=3.6pt plus1.2pt minus1.2pt
  \medskipamount=7.2pt plus2.4pt minus2.4pt
  \bigskipamount=14.4pt plus4.8pt minus4.8pt
  \def\rm{\fam0\twelverm}          \def\it{\fam\itfam\twelveit}%
  \def\sl{\fam\slfam\twelvesl}     \def\bf{\fam\bffam\twelvebf}%
  \def\mit{\fam 1}                 \def\cal{\fam 2}%
  \def\tt{\twelvett}
  \textfont0=\twelverm   \scriptfont0=\tenrm   \scriptscriptfont0=\sevenrm
  \textfont1=\twelvei    \scriptfont1=\teni    \scriptscriptfont1=\seveni
  \textfont2=\twelvesy   \scriptfont2=\tensy   \scriptscriptfont2=\sevensy
  \textfont3=\twelveex   \scriptfont3=\twelveex  \scriptscriptfont3=\twelveex
  \textfont\itfam=\twelveit
  \textfont\slfam=\twelvesl
  \textfont\bffam=\twelvebf \scriptfont\bffam=\tenbf
  \scriptscriptfont\bffam=\sevenbf
  \normalbaselines\rm}

%       tenpoint

\def\tenpoint{\normalbaselineskip=12pt
  \abovedisplayskip 12pt plus 3pt minus 9pt
  \belowdisplayskip 12pt plus 3pt minus 9pt
  \abovedisplayshortskip 0pt plus 3pt
  \belowdisplayshortskip 7pt plus 3pt minus 4pt
  \smallskipamount=3pt plus1pt minus1pt
  \medskipamount=6pt plus2pt minus2pt
  \bigskipamount=12pt plus4pt minus4pt
  \def\rm{\fam0\tenrm}          \def\it{\fam\itfam\tenit}%
  \def\sl{\fam\slfam\tensl}     \def\bf{\fam\bffam\tenbf}%
  \def\smc{\tensmc}             \def\mit{\fam 1}%
  \def\cal{\fam 2}%
  \textfont0=\tenrm   \scriptfont0=\sevenrm   \scriptscriptfont0=\fiverm
  \textfont1=\teni    \scriptfont1=\seveni    \scriptscriptfont1=\fivei
  \textfont2=\tensy   \scriptfont2=\sevensy   \scriptscriptfont2=\fivesy
  \textfont3=\tenex   \scriptfont3=\tenex     \scriptscriptfont3=\tenex
  \textfont\itfam=\tenit
  \textfont\slfam=\tensl
  \textfont\bffam=\tenbf \scriptfont\bffam=\sevenbf
  \scriptscriptfont\bffam=\fivebf
  \normalbaselines\rm}

%%
%%      Various internal macros
%%

\def\beginlinemode{\endmode
  \begingroup\parskip=0pt \obeylines\def\\{\par}\def\endmode{\par\endgroup}}
\def\beginparmode{\endmode
  \begingroup \def\endmode{\par\endgroup}}
\let\endmode=\par
{\obeylines\gdef\
{}}
\def\singlespace{\baselineskip=\normalbaselineskip}
\def\oneandathirdspace{\baselineskip=\normalbaselineskip
  \multiply\baselineskip by 4 \divide\baselineskip by 3}
\def\oneandahalfspace{\baselineskip=\normalbaselineskip
  \multiply\baselineskip by 3 \divide\baselineskip by 2}
\def\doublespace{\baselineskip=\normalbaselineskip \multiply\baselineskip by 2}
\def\triplespace{\baselineskip=\normalbaselineskip \multiply\baselineskip by 3}
\newcount\firstpageno
\firstpageno=2
\footline={\ifnum\pageno<\firstpageno{\hfil}%
\else{\hfil\twelverm\folio\hfil}\fi}
\let\rawfootnote=\footnote              % We must set the footnote style
\def\footnote#1#2{{\rm\singlespace\parindent=0pt\rawfootnote{#1}{#2}}}
\def\raggedcenter{\leftskip=4em plus 12em \rightskip=\leftskip
  \parindent=0pt \parfillskip=0pt \spaceskip=.3333em \xspaceskip=.5em
  \pretolerance=9999 \tolerance=9999
  \hyphenpenalty=9999 \exhyphenpenalty=9999 }
\def\dateline{\rightline{\ifcase\month\or
  January\or February\or March\or April\or May\or June\or
  July\or August\or September\or October\or November\or December\fi
  \space\number\year}}
\def\received{\vskip 3pt plus 0.2fill
 \centerline{\sl (Received\space\ifcase\month\or
  January\or February\or March\or April\or May\or June\or
  July\or August\or September\or October\or November\or December\fi
  \qquad, \number\year)}}

%%
%%      Page layout, margins, font and spacing (feel free to change)
%%

\hsize=6.5truein
%\hoffset=1truein
\vsize=8.9truein
%\voffset=1truein
\parskip=\medskipamount
\twelvepoint            % selects twelvepoint fonts (cf. \tenpoint)
\doublespace            % selects double spacing for main part of paper (cf.
                        %       \singlespace, \oneandahalfspace)
\overfullrule=0pt       % delete the nasty little black boxes for overfull box

%%
%%      The user definitions for major parts of a paper (feel free to change)
%%

\def\preprintno#1{
 \rightline{\rm #1}}    % Preprint number at upper right of title page

\def\title                      %  Title on title page
  {\null\vskip 3pt plus 0.2fill
   \beginlinemode \doublespace \raggedcenter \bf}

\def\author                     %  Author(s) name(s)  on title page
  {\vskip 3pt plus 0.2fill \beginlinemode
   \singlespace \raggedcenter}

\def\affil                      % Affiliations (can intermix with \author)
  {\vskip 3pt plus 0.1fill \beginlinemode
   \oneandahalfspace \raggedcenter \sl}

\def\abstract                   % Begin abstract
  {\vskip 3pt plus 0.3fill \beginparmode
   \doublespace \narrower ABSTRACT: }

\def\endtitlepage               % End title page, begin body of paper
  {\endpage                     %       This subsumes \body
   \body}

\def\body                       % Begin text body;  can be used to end
  {\beginparmode}               % \title, \author, \affil, \abstract,
                                % \reference, or \figurecaption modes

\def\head#1{                    % Head;  NOTE enclose the text in {}
  \filbreak\vskip 0.5truein     %  e.g., \head{I. Introduction}
  {\immediate\write16{#1}
   \raggedcenter \uppercase{#1}\par}
   \nobreak\vskip 0.25truein\nobreak}

\def\subhead#1{                 % Subhead;  NOTE enclose the text in {}
  \vskip 0.25truein             % e.g., \subhead{A. History of the Problem}
  {\raggedcenter #1 \par}
   \nobreak\vskip 0.25truein\nobreak}

\def\refto#1{$|{#1}$}           % For references in text as superscript

\def\references                 % Begin references -- basic format is Phys Rev
  {\subhead{References}         % I.e., volume, page, year (space after commas)
   \beginparmode
   \frenchspacing \parindent=0pt \leftskip=1truecm
   \parskip=8pt plus 3pt \everypar{\hangindent=\parindent}}

\gdef\refis#1{\indent\hbox to 0pt{\hss#1.~}}    % Ref list numbers.

\gdef\journal#1, #2, #3, 1#4#5#6{               % Journal reference.  Comma set
    {\sl #1~}{\bf #2}, #3, (1#4#5#6)}           % off: name, vol, page, year

\def\refstylenp{                % Nucl Phys(or Phys Lett) ref style: V, Y, P
  \gdef\refto##1{ [##1]}                                % Reference in text []
  \gdef\refis##1{\indent\hbox to 0pt{\hss##1)~}}        % Ref list numbers)
  \gdef\journal##1, ##2, ##3, ##4 {                     % Journal reference
     {\sl ##1~}{\bf ##2~}(##3) ##4 }}

\def\refstyleprnp{              % Input like pr, output like np!!
  \gdef\refto##1{ [##1]}                                % Reference in text []
  \gdef\refis##1{\indent\hbox to 0pt{\hss##1)~}}        % Ref list numbers)
  \gdef\journal##1, ##2, ##3, 1##4##5##6{               % Journal reference
    {\sl ##1~}{\bf ##2~}(1##4##5##6) ##3}}

\def\pr{\journal Phys. Rev., }

\def\pra{\journal Phys. Rev. A, }

\def\prb{\journal Phys. Rev. B, }

\def\prc{\journal Phys. Rev. C, }

\def\prd{\journal Phys. Rev. D, }

\def\prl{\journal Phys. Rev. Lett., }

\def\jmp{\journal J. Math. Phys., }

\def\rmp{\journal Rev. Mod. Phys., }

\def\cmp{\journal Comm. Math. Phys., }

\def\np{\journal Nucl. Phys., }

\def\pl{\journal Phys. Lett., }

\def\endreferences{\body}

\def\figurecaptions             % Begin figure captions
  { \beginparmode
   \subhead{Figure Captions}
%  \parskip=24pt plus 3pt \everypar={\hangindent=4em}
}

\def\endfigurecaptions{\body}

\def\endpage                    %  Eject a page
  {\vfill\eject}

\def\endpaper                   %  Ways to say goodbye
  {\endmode\vfill\supereject}
\def\endjnl
  {\endpaper}
\def\endit
  {\endpaper\end}



%%
%%      Various little user definitions
%%

\def\ref#1{Ref. #1}                     %       for inline references
\def\Ref#1{Ref. #1}                     %       ditto
\def\fig#1{Fig. #1}
\def\Equation#1{Equation (#1)}          % For citation of equation numbers
\def\Equations#1{Equations (#1)}        %       ditto
\def\Eq#1{Eq. (#1)}                     %       ditto
\def\eq#1{Eq. (#1)}                     %       ditto
\def\Eqs#1{Eqs. (#1)}                   %       ditto
\def\eqs#1{Eqs. (#1)}                   %       ditto
\def\frac#1#2{{\textstyle{#1 \over #2}}}
\def\half{{\textstyle{ 1\over 2}}}
\def\eg{{\it e.g.,\ }}
\def\Eg{{\it E.g.,\ }}
\def\ie{{\it i.e.,\ }}
\def\Ie{{\it I.e.,\ }}
\def\etal{{\it et al.}}
\def\etc{{\it etc.}}
\def\via{{\it via}}
\def\sla{\raise.15ex\hbox{$/$}\kern-.57em}
\def\leaderfill{\leaders\hbox to 1em{\hss.\hss}\hfill}
\def\twiddle{\lower.9ex\rlap{$\kern-.1em\scriptstyle\sim$}}
\def\bigtwiddle{\lower1.ex\rlap{$\sim$}}
\def\gtwid{\mathrel{\raise.3ex\hbox{$>$\kern-.75em\lower1ex\hbox{$\sim$}}}}
\def\ltwid{\mathrel{\raise.3ex\hbox{$<$\kern-.75em\lower1ex\hbox{$\sim$}}}}
\def\square{\kern1pt\vbox{\hrule height 1.2pt\hbox{\vrule width 1.2pt\hskip 3pt
   \vbox{\vskip 6pt}\hskip 3pt\vrule width 0.6pt}\hrule height 0.6pt}\kern1pt}
\def\ucsb{Department of Physics\\University of California\\
Santa Barbara CA 93106-9530}
\def\ucsd{Department of Physics\\University of California\\
La Jolla, CA 92093}
\def\begintable{\offinterlineskip\hrule}
\def\tablespace{height 2pt&\omit&&\omit&&\omit&\cr}
\def\tablerule{\tablespace\noalign{\hrule}\tablespace}
\def\endtable{\hrule}
\def\prim{{\scriptscriptstyle{\prime}}}
\def\comp{{\rm C}\llap{\vrule height7.1pt width1pt depth-.4pt\phantom t}}
\def\fint{\rlap{$\biggl\rfloor$}\biggl\lceil}
\def\slash#1{\rlap{$#1$}\thinspace /}
\def\m@th{\mathsurround=0pt }
\def\leftrightarrowfill{$\m@th \mathord\leftarrow \mkern-6mu
 \cleaders\hbox{$\mkern-2mu \mathord- \mkern-2mu$}\hfill
 \mkern-6mu \mathord\rightarrow$}
\def\overleftrightarrow#1{\vbox{\ialign{##\crcr
     \leftrightarrowfill\crcr\noalign{\kern-1pt\nointerlineskip}
     $\hfil\displaystyle{#1}\hfil$\crcr}}}

%% *********** New stuff follows *******************

\font\titlefont=cmr10 scaled\magstep3
\def\uof{Department of Physics\\University of Florida\\
Gainesville, FL 32608}
\def\grant{This research was supported in part by the
Institute for Fundamental Theory and by DOE contract
DE-FG05-86-ER40272.}

\def\oneandfourfifthsspace{\baselineskip=\normalbaselineskip
  \multiply\baselineskip by 9 \divide\baselineskip by 5}

\def\martinstyletitle                      %  Title on title page
  {\null\vskip 3pt plus 0.2fill
   \beginlinemode \doublespace \raggedcenter \titlefont}

\font\twelvesc=cmcsc10 scaled 1200

\def\author                     %  Author(s) name(s)  on title page
  {\vskip 3pt plus 0.2fill \beginlinemode
   \singlespace \raggedcenter\twelvesc}






%%
%%      AmSTeX compatability definitions
%%
%%      To run a TeX file originally intended for AmSTeX, only small changes
%%      should be necessary (I hope).  Use the line \input jnl at the start.
%%      Remove the lines \input amstex, \documentstyle{itpjnl} at the
%%      beginning;  also remove all the page layout stuff (\parindent=1cm,
%%      \hsize=5.28125in etc.)  The page layout is now done automatically.
%%      Also OMIT the qualifier \magnification=1200 when you IMPRINT the
%%      .dvi file.  (\TagsOnRight is harmless, you can take it out or leave
%%      it in.)  I believe most AmSTeX will work with no change.  One problem
%%      is \footnote, which is a little different in that it now needs to
%%      have an explicit asterisk *  (or whatever) included, like this:
%%              \footnote*{Text winds up at bottom of page.}
%%      This is discussed on p. 116 of the TeXbook.  IGNORE the AmSTeX
%%      documentation (if you can call it that);  refer to the TeXbook.
%%
%%      Note that many commands in AmSTeX have their equivalents in the
%%      TeXbook, perhaps with different names and slightly differing
%%      usage. E.g., the old \align in AmSTeX is replaced by \eqalign
%%      (p. 190) and \aligntag is replaced by \eqalignno (p. 192).
%%      \align and \aligntag still work, but I recommend that you use
%%      \eqalign and \eqalignno in documents run under jnl.
%%
%%      See me if you have any problems  -- Doug.
%%

\def\TagsOnRight{}
\def\topmatter{}
\def\endtitle{\body}
\def\endauthor{\body}
\def\endaffil{\body}

\def\heading                            % Heading
  {\vskip 0.5truein plus 0.1truein      % e.g., \heading I. NOTES \endheading
   \beginparmode \def\\{\par} \parskip=0pt \singlespace \raggedcenter}

\def\endheading
  {\par\nobreak\vskip 0.25truein\nobreak\beginparmode}

\def\subheading                         % Subheading
  {\vskip 0.25truein plus 0.1truein     % e.g., \subheading{A. The Problem}
   \beginlinemode \singlespace \parskip=0pt \def\\{\par}\raggedcenter}

\def\endsubheading
  {\par\nobreak\vskip 0.25truein\nobreak\beginparmode}

\def\tag#1$${\eqno(#1)$$}

\def\align#1$${\eqalign{#1}$$}

\def\endalign{\cr}

\def\aligntag#1$${\gdef\tag##1\\{&(##1)\cr}\eqalignno{#1\\}$$
  \gdef\tag##1$${\eqno(##1)$$}}

\def\endaligntag{}

\def\binom#1#2{{#1 \choose #2}}

\def\stack#1#2{{#1 \atop #2}}

\def\overset #1\to#2{{\mathop{#2}\limits^{#1}}}
\def\underset#1\to#2{{\let\next=#1\mathpalette\undersetpalette#2}}
\def\undersetpalette#1#2{\vtop{\baselineskip0pt
\ialign{$\mathsurround=0pt #1\hfil##\hfil$\crcr#2\crcr\next\crcr}}}

\def\enddocument{\endit}

%%
%%      Various little user definitions
%%

\def\ref#1{Ref.~#1}                     %       for inline references
\def\Ref#1{Ref.~#1}                     %       ditto
\def\[#1]{[\cite{#1}]}
\def\cite#1{{#1}}
%%\def\Equation#1{Equation~(#1)}                % For citation of equation numb
%%\def\Equations#1{Equations~(#1)}      %       ditto
%%\def\Eq#1{Eq.~(#1)}                   %       ditto
%%\def\Eqs#1{Eqs.~(#1)}                 %       ditto
\def\(#1){(\call{#1})}
\def\call#1{{#1}}
\def\taghead#1{}
\def\frac#1#2{{#1 \over #2}}
\def\half{{\frac 12}}
\def\third{{\frac 13}}
\def\fourth{{\frac 14}}
\def\12{{1\over2}}
\def\eg{{\it e.g.,\ }}
\def\Eg{{\it E.g.,\ }}
\def\ie{{\it i.e.,\ }}
\def\Ie{{\it I.e.,\ }}
\def\etal{{\it et al.\ }}
\def\etc{{\it etc.\ }}
\def\via{{\it via\ }}
\def\cf{{\sl cf.\ }}
\def\sla{\raise.15ex\hbox{$/$}\kern-.57em}
\def\leaderfill{\leaders\hbox to 1em{\hss.\hss}\hfill}
\def\twiddle{\lower.9ex\rlap{$\kern-.1em\scriptstyle\sim$}}
\def\bigtwiddle{\lower1.ex\rlap{$\sim$}}
\def\gtwid{\mathrel{\raise.3ex\hbox{$>$\kern-.75em\lower1ex\hbox{$\sim$}}}}
\def\ltwid{\mathrel{\raise.3ex\hbox{$<$\kern-.75em\lower1ex\hbox{$\sim$}}}}
\def\square{\kern1pt\vbox{\hrule height 1.2pt\hbox{\vrule width 1.2pt\hskip 3pt
   \vbox{\vskip 6pt}\hskip 3pt\vrule width 0.6pt}\hrule height 0.6pt}\kern1pt}
\def\tdot#1{\mathord{\mathop{#1}\limits^{\kern2pt\ldots}}}
\def\super#1{$^{#1}$}
\def\pmb#1{\setbox0=\hbox{#1}%
  \kern-.025em\copy0\kern-\wd0
  \kern  .05em\copy0\kern-\wd0
  \kern-.025em\raise.0433em\box0 }
\def\qed{\vrule height 1.2ex width 0.5em}
\def\const{{\rm const}}
\def\itp{Institute for Theoretical Physics}
\def\itpucsb{\itp\\University of California\\Santa Barbara, %
California 93106-9530}
\def\itpgrant{This research was supported in part by the National
Science Foundation under Grant No.~PHY82-17853,
supplemented by funds from the National Aeronautics and Space
Administration, at the University of California at Santa Barbara.}






%%		EQNORDER.TEX			11/05/85	Doug E.
%%
%%	This macro package is intended for use with JNL.
%%	It will automatically order and sort the equations in a paper
%%	by order of appearance.  To use, say \input eqnorder
%%	after \input jnl (and after all definitions of \eqno etc.,
%%	but before any use of \eqno etc.  Use \() to cite equations
%%	in the text.  Use \eqno() or \tag to put the numbers on displayed
%%	equations; or use &() with \eqalignno{} as explained in the TeXBOOK.
%%
%%      EQNORDER depends on the macro \() to refer to equations in the
%%	text; use it as Equation \() or Eq. \() or Eqs. \(), etc.
%%	EQNORDER also contains a macro \call{} which can be used to refer
%%	equations; e.g., ``Equation \call{19} blah...'' will produce
%% 	output ``Equation 19 blah''.  Multiple citations must be separated
%%	by commas.  E.g., \(24,26,27) and \call{3,7} are legal.  A sequence
%%	of equation numbers can be referred to by, e.g., \(3-7) which means
%%	the same as (3,4,5,6,7).
%%
%%	Equation ``numbers'' can actually be any alphanumeric string;
%%	e.g., equation \tag Schroedinger $$ can be referred to by
%%	\(Schroedinger).  In fact, if you expect to renumber the equations,
%%	it is actually easier and less confusing to tag them with names
%%	rather than numbers.
%%
%%	There is one big rule:  You cannot refer to an equation before you
%%	display it.  There is a limited loophole:  You can refer to the
%%	first, second or third equation number just below where you are
%%	as \(+1), \(+2), or \(+3).  In the same way, the equation number
%%	just above can be called \(0), and the three preceding numbers
%%	\(-1), \(-2), \(-3).
%%
%%	TeX keeps the equation number as a count \tagnumber.  \tagnumber
%%	is initially 0, and it is incremented by 1 just BEFORE it is used
%%	to tag a displayed equation.  You are free to reset \tagnumber,
%%	which you can do just by writing e.g. \tagnumber=23.
%%
%%	If you label a displayed equation with a null number, \tag $$
%%	or \eqno() or &(), an incremented \tagnumber will be generated for
%%	the equation, but the only way to refer to that equation is
%%	via the \(+n) or \(0) or \(-n) notation.
%%
%%	In long papers, the author often numbers the equations anew
%%	in each section in the style \tag 6.1 $$, \tag 6.2 $$, and so
%%	forth;  the equations are then referred to by \(6.1) etc.
%%	One reason for doing this is to minimize chaos when equations
%%	have to be renumbered --- but this is what EQNORDER already does!
%%	If you still want to use such a style, just declare \taghead{6.}
%%	for example at the beginning of Section 6.  The effect of \taghead
%%	is to reset \tagnumber to 0, and to save the argument of \taghead
%%	to so that it can be put in front of each equation number in the
%%	output.
%%
%%	Sometimes a sequence of displayed equations is labelled with
%%	the same number (e.g., 25) and then sublabeled a,b,c,d...  Use
%%	the form \tag 25 a$$, \tag 25 b$$,... or \eqno(25 a)$$,
%%	\eqno(25 b)$$,... to put the numbers on such a sequence;  note
%%	the space.  Such equations can be referred to in the text either
%%	as \(25) or \(25 a).  Also such constructions as \(25 a,25 b,26)
%%	are legal.  Again, note carefully the position of the space.  The
%%	effect of the space is to mark the end of the equation number that
%%	TeX keeps track of;  the following string (a or b or ...) is just
%%	put out without modification.  Thus constructions like \tag 25 ' $$
%%	and \tag 25 '' $$ are legal.
%%
%%	If you have your own pet macros to call equations such as, e.g.,
%%	\def\eqnpet#1{($#1$))}, you can bring it to the attention of
%%	REFORDER so all \eqnpet's will be properly calld simply by
%%	declaring ``\callall\eqnpet'' after \eqnpet is defined and
%%	after \input eqnorder.  This has the effect of redefining the macro
%%	as e.g., \def\eqnpet#1{($\call{#1}$)}.  (Such \callall'ed macros
%%	must have exactly one argument #1, as in \eqnpet.)

\catcode`@=11
\newcount\tagnumber\tagnumber=0

\immediate\newwrite\eqnfile
\newif\if@qnfile\@qnfilefalse
\def\write@qn#1{}
\def\writenew@qn#1{}
\def\w@rnwrite#1{\write@qn{#1}\message{#1}}
\def\@rrwrite#1{\write@qn{#1}\errmessage{#1}}

\def\taghead#1{\gdef\t@ghead{#1}\global\tagnumber=0}
\def\t@ghead{}

\expandafter\def\csname @qnnum-3\endcsname
  {{\t@ghead\advance\tagnumber by -3\relax\number\tagnumber}}
\expandafter\def\csname @qnnum-2\endcsname
  {{\t@ghead\advance\tagnumber by -2\relax\number\tagnumber}}
\expandafter\def\csname @qnnum-1\endcsname
  {{\t@ghead\advance\tagnumber by -1\relax\number\tagnumber}}
\expandafter\def\csname @qnnum0\endcsname
  {\t@ghead\number\tagnumber}
\expandafter\def\csname @qnnum+1\endcsname
  {{\t@ghead\advance\tagnumber by 1\relax\number\tagnumber}}
\expandafter\def\csname @qnnum+2\endcsname
  {{\t@ghead\advance\tagnumber by 2\relax\number\tagnumber}}
\expandafter\def\csname @qnnum+3\endcsname
  {{\t@ghead\advance\tagnumber by 3\relax\number\tagnumber}}

\def\equationfile{%
  \@qnfiletrue\immediate\openout\eqnfile=\jobname.eqn%
  \def\write@qn##1{\if@qnfile\immediate\write\eqnfile{##1}\fi}
  \def\writenew@qn##1{\if@qnfile\immediate\write\eqnfile
    {\noexpand\tag{##1} = (\t@ghead\number\tagnumber)}\fi}
}

\def\callall#1{\xdef#1##1{#1{\noexpand\call{##1}}}}
\def\call#1{\each@rg\callr@nge{#1}}

\def\each@rg#1#2{{\let\thecsname=#1\expandafter\first@rg#2,\end,}}
\def\first@rg#1,{\thecsname{#1}\apply@rg}
\def\apply@rg#1,{\ifx\end#1\let\next=\relax%
\else,\thecsname{#1}\let\next=\apply@rg\fi\next}

\def\callr@nge#1{\calldor@nge#1-\end-}
\def\callr@ngeat#1\end-{#1}
\def\calldor@nge#1-#2-{\ifx\end#2\@qneatspace#1 %
  \else\calll@@p{#1}{#2}\callr@ngeat\fi}
\def\calll@@p#1#2{\ifnum#1>#2{\@rrwrite{Equation range #1-#2\space is bad.}
\errhelp{If you call a series of equations by the notation M-N, then M and
N must be integers, and N must be greater than or equal to M.}}\else %
{\count0=#1\count1=#2\advance\count1 by1\relax\expandafter\@qncall\the\count0,%
  \loop\advance\count0 by1\relax%
    \ifnum\count0<\count1,\expandafter\@qncall\the\count0,%
  \repeat}\fi}

\def\@qneatspace#1#2 {\@qncall#1#2,}
\def\@qncall#1,{\ifunc@lled{#1}{\def\next{#1}\ifx\next\empty\else
  \w@rnwrite{Equation number \noexpand\(>>#1<<) has not been defined yet.}
  >>#1<<\fi}\else\csname @qnnum#1\endcsname\fi}

\let\eqnono=\eqno
\def\eqno(#1){\tag#1}
\def\tag#1$${\eqnono(\displayt@g#1 )$$}

\def\aligntag#1\endaligntag
  $${\gdef\tag##1\\{&(##1 )\cr}\eqalignno{#1\\}$$
  \gdef\tag##1$${\eqnono(\displayt@g##1 )$$}}

\let\eqalignnono=\eqalignno

\def\eqalignno#1{\displ@y \tabskip\centering
  \halign to\displaywidth{\hfil$\displaystyle{##}$\tabskip\z@skip
    &$\displaystyle{{}##}$\hfil\tabskip\centering
    &\llap{$\displayt@gpar##$}\tabskip\z@skip\crcr
    #1\crcr}}

\def\displayt@gpar(#1){(\displayt@g#1 )}

\def\displayt@g#1 {\rm\ifunc@lled{#1}\global\advance\tagnumber by1
        {\def\next{#1}\ifx\next\empty\else\expandafter
        \xdef\csname @qnnum#1\endcsname{\t@ghead\number\tagnumber}\fi}%
  \writenew@qn{#1}\t@ghead\number\tagnumber\else
        {\edef\next{\t@ghead\number\tagnumber}%
        \expandafter\ifx\csname @qnnum#1\endcsname\next\else
        \w@rnwrite{Equation \noexpand\tag{#1} is a duplicate number.}\fi}%
  \csname @qnnum#1\endcsname\fi}

\def\ifunc@lled#1{\expandafter\ifx\csname @qnnum#1\endcsname\relax}

\let\@qnend=\end\gdef\end{\if@qnfile
\immediate\write16{Equation numbers written on []\jobname.EQN.}\fi\@qnend}

\catcode`@=12

%% DEBUG
%%\def\see#1 {\expandafter\show\csname#1\endcsname}



%%		REFORDER.TEX			6/7/85	Doug E.
%%					(mods:	3/25/87 R.G.Palmer)
%%
%%	This macro package is intended for use with JNL.
%%	It will automatically order and sort the references in a paper
%%	by order of first citation.(!!)  To use, say \input reforder
%%	after \input jnl (and after all definitions of \refto etc.,
%%	in particular after any use of the \refstyleXX macros),
%%	but before any use of \refto etc.  Use \refto{} (or \ref{} and
%%	\Ref{}) to cite references in the text.  Use \refis{} to supply
%%	the references,  SKIP A LINE after each reference.  Open the
%%	reference listing with \references and close it with \endreferences.
%%
%%	REFORDER depends on the
%%	JNL macros \refto{}, \ref{}, \Ref{} to identify citation of references.
%%	REFORDER also contains a macro \cite{} which can be used to cite
%%	references; e.g., ``Reference \cite{19} blah...'' will produce
%% 	output ``Reference 19 blah''.  Multiple citations can be separated
%%	by commas.  E.g., \refto{24,26,27} and \cite{3,7}
%%	are legal.  Also legal is \refto{3-7}, which expands to mean the same
%%	as \refto{3,4,5,6,7}.  Reference ``numbers'' can in general be any
%%	alphanumeric string; e.g. BjorkenAndDrell is perfectly OK used in
%%	the form\ref{BjorkenAndDrell};  such strings should contain no blanks.
%%
%%	If you have your own pet macros to cite references such as, e.g.,
%%	\def\referpet#1{$^(#1)$)}, you can bring it to the attention of
%%	REFORDER so all \referpet's will be properly cited simply by
%%	declaring ``\citeall\referpet'' once near the beginning, after
%%	\referpet is defined and
%%	after \input reforder.  This has the effect of redefining the macro
%%	as e.g., \def\referpet#1{$^(\cite{#1})$}.  (Such \citeall'ed macros
%%	must have exactly one argument #1, as in \referpet.)  See e.g.,
%%	the end of this file where \refto, \ref and \Ref are \citeall'ed.
%%
%%	REFORDER depends on the macro \refis{} to supply each reference.
%%      \refis{} can be used to supply a reference anywhere in the paper
%%	after its first citation.  The macro \endreferences actually triggers
%%	sorting and listing of references.  Skip a line after a reference
%%	listing (or, alternatively, end each listing in \par).
%%
%%	Use \ignoreuncited after \input reforder if you wish to ignore
%%	references that are supplied but not cited.  This is particularly
%%	useful if you maintain a master file of references (each supplied
%%	with \refis{}) but only use a subset of these in a given paper.
%%      Include your reference file (with \input) between \references
%%      and \endreferences.
%%
%%	Use \referencefile after \input reforder if you want an ordered
%%      source listing of the references in file <name>.ref
%%
%%	The \reftorange macro can be used to produce a superscript
%%	reference range, like $^{10-15}$.  (The \refto macro always
%%	lists the references one by one, even for e.g. \refto{10-15}).
%%	Use e.g. \reftorange{10}{11-14}{15} -- the references in the
%%	middle group are cited but only 10-15 appears in the text.
%%      Note that \reftorange does NOT check for increasing order.

\catcode`@=11
\newcount\r@fcount \r@fcount=0
\newcount\r@fcurr
\immediate\newwrite\reffile
\newif\ifr@ffile\r@ffilefalse
\def\w@rnwrite#1{\ifr@ffile\immediate\write\reffile{#1}\fi\message{#1}}

\def\writer@f#1>>{}
\def\referencefile{%			  Stuff to write .REF file
  \r@ffiletrue\immediate\openout\reffile=\jobname.ref%
  \def\writer@f##1>>{\ifr@ffile\immediate\write\reffile%
    {\noexpand\refis{##1} = \csname r@fnum##1\endcsname = %
     \expandafter\expandafter\expandafter\strip@t\expandafter%
     \meaning\csname r@ftext\csname r@fnum##1\endcsname\endcsname}\fi}%
  \def\strip@t##1>>{}}
\let\referencelist=\referencefile

\def\citeall#1{\xdef#1##1{#1{\noexpand\cite{##1}}}}
\def\cite#1{\each@rg\citer@nge{#1}}	% Variable No. of args, separated by

\def\each@rg#1#2{{\let\thecsname=#1\expandafter\first@rg#2,\end,}}
\def\first@rg#1,{\thecsname{#1}\apply@rg}	% each@ag is a general purpose
\def\apply@rg#1,{\ifx\end#1\let\next=\relax%	  variable no. of arg. macro.
\else,\thecsname{#1}\let\next=\apply@rg\fi\next}% args separated by commas

\def\citer@nge#1{\citedor@nge#1-\end-}	% Check for M-N range (M and N numbers)
\def\citer@ngeat#1\end-{#1}
\def\citedor@nge#1-#2-{\ifx\end#2\r@featspace#1 % Single argument
  \else\citel@@p{#1}{#2}\citer@ngeat\fi}	% M-N range of arguments
\def\citel@@p#1#2{\ifnum#1>#2{\errmessage{Reference range #1-#2\space is bad.}%
    \errhelp{If you cite a series of references by the notation M-N, then M and
    N must be integers, and N must be greater than or equal to M.}}\else%
 {\count0=#1\count1=#2\advance\count1 by1\relax\expandafter\r@fcite\the\count0,
  \loop\advance\count0 by1\relax%	  Loop from M to N
    \ifnum\count0<\count1,\expandafter\r@fcite\the\count0,%
  \repeat}\fi}

\def\r@featspace#1#2 {\r@fcite#1#2,}	% Eat spaces at beginning or end of arg
\def\r@fcite#1,{\ifuncit@d{#1}%		  Cite individual reference
    \newr@f{#1}%
    \expandafter\gdef\csname r@ftext\number\r@fcount\endcsname%
                     {\message{Reference #1 to be supplied.}%
                      \writer@f#1>>#1 to be supplied.\par}%
 \fi%
 \csname r@fnum#1\endcsname}
\def\ifuncit@d#1{\expandafter\ifx\csname r@fnum#1\endcsname\relax}%
\def\newr@f#1{\global\advance\r@fcount by1%
    \expandafter\xdef\csname r@fnum#1\endcsname{\number\r@fcount}}

\let\r@fis=\refis			% Save old \refis, redefine
\def\refis#1#2#3\par{\ifuncit@d{#1}%      Use two params #2 #3 to strip blank
   \newr@f{#1}%
   \w@rnwrite{Reference #1=\number\r@fcount\space is not cited up to now.}\fi%
  \expandafter\gdef\csname r@ftext\csname r@fnum#1\endcsname\endcsname%
  {\writer@f#1>>#2#3\par}}

\def\ignoreuncited{%   redefine \refis if ignoring uncited references
   \def\refis##1##2##3\par{\ifuncit@d{##1}%
    \else\expandafter\gdef\csname r@ftext\csname r@fnum##1\endcsname\endcsname%
     {\writer@f##1>>##2##3\par}\fi}}

\def\r@ferr{\endreferences\errmessage{I was expecting to see
\noexpand\endreferences before now;  I have inserted it here.}}
\let\r@ferences=\references
\def\references{\r@ferences\def\endmode{\r@ferr\par\endgroup}}

\let\endr@ferences=\endreferences
\def\endreferences{\r@fcurr=0%		  Save old \endreferences, redefine
  {\loop\ifnum\r@fcurr<\r@fcount%	  Loop over refnum and produce text
    \advance\r@fcurr by 1\relax\expandafter\r@fis\expandafter{\number\r@fcurr}%
    \csname r@ftext\number\r@fcurr\endcsname%
  \repeat}\gdef\r@ferr{}\endr@ferences}

% Save old \endpaper, redefine it to write parting message.

\let\r@fend=\endpaper\gdef\endpaper{\ifr@ffile
\immediate\write16{Cross References written on []\jobname.REF.}\fi\r@fend}

\catcode`@=12

\def\reftorange#1#2#3{$^{\cite{#1}-\setbox0=\hbox{\cite{#2}}\cite{#3}}$}

\citeall\refto		% These macros will generate citations
\citeall\ref		%
\citeall\Ref		%

