%  
%  \iffalse  
% 
%    The first part is a comment to the reader(s) of `deleq.dtx'.
%
%  deleq.dtx    Version 4.2, May 15, 1995
%  (c) 1994-95 by Mats Dahlgren  (matsd@physchem.kth.se)
%
%  Please see the information in file `deleq.ins' on how you 
%  may use and (re-)distribute this file.  Run LaTeX on the file 
%  `deleq.ins' to get a .sty-file, instructions, and an example.
%
%  This file may NOT be distributed if not accompanied by 'deleq.ins'.
%
%  \fi
%
%  \def\filename{deleq.dtx}
%  \def\fileversion{4.2}
%  \def\filedate{1995/05/15}\def\docdate{\filedate}
%  \MakeShortVerb{\|}
%  \date{\docdate}
%  \title{\LaTeX{} Macro for Partial Numbering of Equations}
%  \author{Mats Dahlgren\\ (\texttt{matsd@physchem.kth.se})} 
%  \maketitle
%  \begin{abstract}
%  To enable a more flexible equation numbering, especially 
%  ``partial'' equation numbers (`3a', `3b' \textit{etc.}), 
%  the |deleq| package has been developed.  It can produce 
%  partial equation numbers intermixed with ordinary 
%  equation numbers also in an |eqnarray|-like environment, 
%  the intermixing can occur within one environment.  
%  Furthermore, equation numbers can be recycled without 
%  disturbing the ordinary equation numbers.  The 
%  package also provides commands for putting commentatory 
%  text in an |eqnarray| environment without requiering the 
%  |amstex| package.\\ \small This file and the package:\
%  Copyright \copyright\ 1994-1995 by Mats Dahlgren.  All rights
%  reserved. 
%  \end{abstract}
%   
%  \section{Introduction}
%  |deleq| is a \LaTeX{} package which makes partial
%  numbering of equations possible.  It is meant to be used
%  when numbering such as 3a, 3b, \textit{etc.} is desired.
%  The default is to give an equation number like `3a'
%  without period and with the `a' typeset in roman font. 
%  It can be used in |article| as well as |book| and
%  |report| document classes.  The examples given below are
%  valid for the |article| class.  |deleq| is fully
%  compatible with the |leqno| documentclass option.
%  Equations can be numbered either 3, 3a, 3b, $\ldots$, or
%  2, 3a, 3b, $\ldots$. Also, equation numbers within
%  |eqnarray|-like environments can be numbered 3, 3a, 3b,
%  $\ldots$ or starting at 3a, which can follow both after
%  equation 2b or 3.  An |eqnarray|-like environment can have 
%  its first equation numbered 3b if the nearest previous
%  equation is 3a.  Within one |eqnarray|-like  environment, 
%  equations can be numbered 3a, 3b, 4, 4a, 4b, 5a, 5b,
%  \textit{etc.}, and also not numbered lines are possible
%  (`|\nonumber|' works with some limitations). 
%  Furthermore, equation numbers can
%  be ``recycled''.  If equation 3 is repeated after
%  equation 8, it can still have the numbering set to 3,
%  and be followed by (a new) equation 9.  ``Recycled''
%  equation numbers can receive partial numbers (3a, 3b,
%  $\ldots$); partially numbered equations can also be
%  ``recycled'' (but at this stage, the latter can not
%  receive new partial numbers neatly, it will come out
%  like `3ba' if eqution 3b is the ``recycled'' equation). 
%  Two commands are supplied which enable the user to write
%  commnetary tests in |eqnarray|-like environments without
%  interfering with the alignment. 
%   
%  \subsection{History}
%  |deleq.sty| was originally written for \LaTeX{} 2.09,
%  and contained several commands which became obsolete
%  with the introduction of \LaTeXe.  These commands have
%  been removed.  The first release for \LaTeXe{} was v.4.0, 
%  of Oct.~14, 1994. The previous release 
%  (v.4.1, Dec.~27, 1994) was the first which was compatible with the 
%  |docstrip| utility of Johannes Braams, Denys Duchier and 
%  Frank Mittelbach.  In the present release, v.4.2, new 
%  abilities to reference entire |deqarr| and |ddeqar| 
%  environments and enhanced abilities for recycled 
%  equation numbers have been introduced.  The command 
%  `|mthref{FOO}|' has been removed because it is now 
%  superflous.  
%   
%  |deleq.sty| version 4.2 has been tested with \LaTeXe{} 
%  of 1994/06/01 patch level 4 running 
%  \TeX{} 3.141 under UNIX and \LaTeXe{} of 1994/12/01 patch 
%  level 3 running \TeX{} 3.1415 under
%  OpenVMS.  Please send bug reports (see below),
%  corrections, additions, suggestions, \textit{etc.}\ to
%  me at \texttt{matsd@physchem.kth.se}.  With |deleq| v.4.1, the 
%  commentatory commands |\where| and |\rem| were included.
%  With |deleq| v.4.2 enhanced abilities to recycle equation 
%  numbers and making references to entire |deqarr| and |ddeqar| 
%  environments were introduced.  Furthermore, this 
%  documentation was revised and some internal commands 
%  compacted in v.4.2.  Version 3.02 is the last 
%  (non-supported) version for \LaTeX{}2.09. (Command names
%  are a mixture of \LaTeX , Swedish and a bit of the
%  author's fantasy$\ldots$) 
%   
%  \section{Known Problems}
%  \begin{itemize}
%  \item  Earlier versions (3.0) of |deleq.sty| had
%    problems with \LaTeXe   compatibility mode (reported by
%    Tom Scavo   (\texttt{trscavo@mailbox.syr.edu})).  These
%    problems are likely to remain.   There are also problems
%    with the font selections when using older   versions of
%    |deleq| than 4.0 in \LaTeXe{} native mode.  These error 
%    messages can be ignored, \LaTeXe{} will produce the
%    correct output   anyway.  There will not be any attempts
%    to correct this by the author   of |deleq| in the near
%    future. 
%  \item In \LaTeX{} 2.09, the use of |deleq.sty| version
%    3.0 sometimes caused the   |\em| command not to work
%    properly in a theorem-like environment   (reported by
%    Patrick Dan\`es (\texttt{danes@laas.fr})).  This appears
%    not to be   a problem in \LaTeXe{} with |deleq| version
%    4.0 and later. 
%  \item When using |\eqreqno|, |\deqreqno|, and |\ddeqreqno| 
%    on the last line in a |deqarr|, |ddeqar|, |eqnarray|, or 
%    |eqnarray*|, there will be an extra blank line with an 
%    equation number (not in the |*| form) at the end of the 
%    environment.  To avoid this problem, use 
%    |\eqreqno[-\jotbaseline]{FOO} \nonumber| instead of 
%    |\eqreqno{FOO}| (the analogues for |\deqreqno| and 
%    |\ddeqreqno| are obvious).
%  \end{itemize}
%   
%  \section{Userguide}
%  \subsection{Requirements}     
%  The file |deleq.sty| must be available in the user's
%  |TEXINPUTS| directories.
%  It requires \LaTeXe{} of 1994/06/01 (or newer).
%   
%  \subsection{Usage}
%  The package is included by stating\\
%  |  \usepackage{deleq}| \\
%  In the document preamble.
%  The documentclass option |leqno| is fully supported,
%  no other class or package options have any effect on 
%  |deleq|.
%   
%  \subsection{Environments}     
%  The package defines the following five environments:
%  \begin{description}
%  \item{\texttt{deqn}} is an equation environment for automatic 
%    numbering of the  first equation of type `3a'; 
%  \item{\texttt{ddeqn}} is an equation used for automatic numbering 
%    of the equations following the one in |deqn|, see also details
%    below; 
%  \item{\texttt{deqarr}} environment for automatic partial equation
%    numbering in |eqnarray|-like environment with 
%    |deqn| functionality for the first equation;
%  \item{\texttt{ddeqar}} similar to |deqarr| environment, but 
%    with |ddeqn| behaviour for the first equation, see details below;
%  \item{\texttt{deqrarr}} this is an `|eqnarray|'-like  environment 
%    specially designed for recycled equation  numbers.
%  \end{description}
%   
%  \subsection{Commands}         
%  The package defines the following fourteen user commands:\\
%  \hspace*{2mm}|\nydeqno|\\
%  \hspace*{2mm}|\heqno|\\
%  \hspace*{2mm}|\reqno{FOO}|\\
%  \hspace*{2mm}|\rndeqno{FOO}|\\
%  \hspace*{2mm}|\rdeqno{FOO}|\\
%  \hspace*{2mm}|\eqreqno[|\textit{len}|]{FOO}|\\
%  \hspace*{2mm}|\deqreqno[|\textit{len}|]{FOO}|\\
%  \hspace*{2mm}|\ddeqreqno[|\textit{len}|]{FOO}|\\
%  \hspace*{2mm}|\arrlabel{FOO}|\\
%  \hspace*{2mm}|\where|\\
%  \hspace*{2mm}|\rem{|\textit{text}|}|\\
%  \hspace*{2mm}|\nydeleqno|\\
%  \hspace*{2mm}|\deleqno|\\
%  \hspace*{2mm}|\jotbaseline|\\
%   
%  \subsection{Notice}
%  \begin{enumerate}
%  \item If you use |\nydeqno|, 
%    |\heqno|, |\reqno|, |\rndeqno|, |\rdeqno|, \linebreak 
%    |\deqreqno|, |\ddeqreqno|, |\nydeleqno|, or |\deleqno| in 
%    combination with |\label{FOO}|, |\label{FOO}| should
%    appear after the |deleq|-command;
%  \item If you change the appearance of equation numbers 
%    (\textit{e.g.}\ use
%    `[2]' instead of `(2)'),  |deleq|'s commands may not typeset
%    the partial equation numbers like your ordinary ones.
%  \item The use of |\arrlabel| may give unexpected results if 
%    any of the commands |\nydeqno| or |\heqno| is used in the 
%    same |deqarr| or |ddeqar| environment.
%  \end{enumerate}       
%   
%  \section{Syntax}
%  Here follows a more detailed description of the
%  different environments and commands. 
%  \begin{description}
%  \item{|\begin{deqn} ... \end{deqn}|}\\    
%  Typesets an equation just like 
%  |\begin{equation} ... \end{equation}| does, but gives it
%  a number such as `3a' instead of `3' (always `a').  It 
%  steps the main equation counter.
%  \item{|\begin{ddeqn} ... \end{ddeqn}|}\\    
%  Typesets an equation just like 
%  |\begin{equation} ... \end{equation}| does, but gives it
%  a number such as `3b', `3c', $\ldots$ instead of `3',
%  `4', $\ldots$ when following after another partially
%  numbered equation.  When following after an ordinarily
%  numbered equation (`3') it gives a partial equation
%  number with the last used ordinary equation number,
%  \textit{e.g.}\  `3a'.  Can be made to produce the result
%  of |deqn| environment by the use of |\nydeqno| (see 
%  below). 
%  \item{|\begin{deqarr} ... \end{deqarr}|}\\    
%  Typesets an equation array just like 
%  |\begin{eqnarray} ... \end{eqnarray}| does, but gives
%  the first numbered equation a number like `3a' instead
%  of `3' (always `a'), and the following `3b', `3c'
%  \textit{etc.}  The |\nonumber| command works just like
%  in the |eqnarray| environment on the partial equation 
%  counter.  Thus, if you use |\nonumber| on all lines in an 
%  |deqarr| environment (or on all lines before or between 
%  |\heqno| or |\nydeleqno|) the equation numbering in your 
%  document will be incorrect.  There is no warning issued by 
%  \LaTeX{} if this happends.  If you want blank lines and 
%  then a |\heqno|'ed equation followed by partially numbered 
%  equations, use the |ddeqar| environment instead.  The same 
%  is true for |\nydeqno|'ed equations.  
%  \item{|\begin{ddeqar} ... \end{ddeqar}|}\\    
%  Typesets an equation array just like 
%  |\begin{eqnarray} ... \end{eqnarray}| does, but gives
%  the equation numbers such as `3a' if following after an
%  equation numbered `3' (ordinary equation number) and
%  numbers such as `3c' if following after a partially
%  numbered equation `3b'. Can be made to produce the
%  result of |deqarr| environment by the use of |\nydeqno|.
%  The |\nonumber| command works just like in the
%  |deqarr| environment. 
%  \item{|\begin{deqrarr} ... \end{deqrarr}|}\\    
%  This environment is meant to host recycled equations and has 
%  |eqnarray| structure.  By default, it issues no equation 
%  number at all on a line which ends with |\\|.  The use of 
%  |\label{FOO}| within |deqrarr| returns the present partial 
%  equation number of recycled equations (just like with 
%  |\rndeqno| and |\rdeqno|).  Note that neither |\heqno| 
%  nor |\nydeleqno| gives any equation numbers at all in the 
%  |deqrarr| environment.  
%  \item{|\nydeqno|}\\
%  Used within |deqarr| and |ddeqar| environments to
%  step the main equation number by one and reset the 
%  partial equation number to `a'; thus, |\nydeqno| gives 
%  equation number `4a' when following after equation `3c'.
%  \item{|\heqno|}\\
%  Used within |deqarr| and |ddeqar| 
%  environments to step the main equation number by one and  
%  to produce an ordinary equation number; thus, gives 
%  equation number `4' when following equation `3c'. 
%  Equations following the |\heqno|-ed will be partially  
%  numbered with the |\heqno|-ed equation's number as the
%  main number, \textit{e.g.}\  `4a' (unless it has a |\nydeqno| 
%  command, which in this case would produce the equation 
%  number `5a').
%  \item{|\reqno{FOO}|}\\
%  Is used when repeating equations with its original 
%  number, ``recycling'' the eqaution numbers.
%  |\reqno| takes the argument |FOO|, which has to be defined
%  by a |\label{FOO}| in the original equation.  It can
%  only be used within |$$ ... $$|.  It does not affect the 
%  equation number counter, nor the partial equation number 
%  counter.  However, it resets the partial equation number
%  counter for the |\rndeqno|, |\rdeqno|, |\deqreqno|, and  
%  |\ddeqreqno| commands.  If used with a |\label{FOOO}| 
%  command, the |.aux|-file will only contain the page number 
%  of label |FOOO|. 
%  \item{|\rndeqno{FOO}|}\\
%  Adds a partial equation number to an old equation number,
%  specified by the |FOO| label.  If |FOO| refers to equation 
%  `4', |\rdeqno{FOO}| will result in equation number `4a'
%  (always `a').  It can only be used within 
%  |$$ ... $$|.  It does not affect the equation number counter,
%  nor the partial equation number counter.  However, it
%  resets the partial equation number counter for the 
%  |\rndeqno|, |\rdeqno|, |\deqreqno|, and |\ddeqreqno| commands.
%  The argument of |\rndeqno| follows the same rules as that of
%  |\reqno|.  When used with the |\label{FOOO}| command, a
%  reference to |FOOO| will only return the partial equation
%  number (and the page number).  To make a complete reference 
%  to an equation which has a |\rndeqno| command, say 
%  |\ref{FOO}\ref{FOOO}|. 
%  \item{|\rdeqno{FOO}|}\\
%  Same as |\rndeqno{FOO}| but without resetting any 
%  equation number counter and giving consecutive partial
%  equation numbers (`4b', `4c', \textit{etc.}).
%  \textbf{Note: } There is nothing preventing the
%  repeated use of |\rndeqno{FOO}| and |\rdeqno{FOO}| for
%  the same label |FOO|.  This will result in numbering such
%  as `3a' (if |FOO| refers to equation `3') occuring several
%  times. 
%  \item{|\eqreqno[|\textit{len}|]{FOO}|}\\
%  This command is the array-like version of |\reqno{FOO}| and 
%  is used in much the same way.  The optional argument \textit{len} 
%  is a length which is added between consecutive rows in the array-like 
%  structure.  When using |\eqreqno| no `|\\|' should be issued 
%  at the end of the line, it is embedded in the command.  This 
%  is giving a strange appearance if |\eqreqno| is used on the 
%  last line of the array-like sturcture, namely an extra blank 
%  line (with equation number).  To avoid this problem, specify 
%  a negative length for \textit{len}, preferably `|-\jotbaseline|' 
%  (se below), and issue a `|\nonumber|' afterwards.  
%  \item{|\deqreqno[|\textit{len}|]{FOO}|}\\
%  This is the `|\rndeqno|' version of `|\eqreqno|' and is used 
%  as the former with the latter's abilities at the end of a 
%  line.  
%  \item{|\ddeqreqno[|\textit{len}|]{FOO}|}\\
%  This is the `|\rdeqno|' version of `|\eqreqno|' and is used 
%  as the former with the latter's abilities at the end of a 
%  line.  
%  \item{|\arrlabel{FOO}|}\\
%  This command is a version of \LaTeX 's ordinary 
%  |\label{FOO}| command meant to be used in |deqarr| and 
%  |ddeqar| environments.  In these environments, a 
%  |\label{FOO}| command gives a reference to the specific 
%  equation, \textit{e.g.}\ 3b, whereas |\arrlabel{FOO}| in the 
%  same position gives a reference containing only the main 
%  equation number, 3 in this example.  For restrictions, see 
%  the section ``Notice'' above.  The four commands |\eqreqno|, 
%  |\deqreqno|, |\ddeqreqno|, and |\arrlabel| were created after 
%  inspiration from Larry Jones (\texttt{schnuff@mit.edu}).  
%  \item{|\where|}\\
%  The command |\where| typsets the text ``where'' (in 
%  the default LR-font) flush left on a seperate row in 
%  |eqnarray|, |deqarr|, |ddeqar|, and  |deqrarr| environments, 
%  and preserves the environment's alignment for rows to come. 
%  \item{|\rem{|\textit{text}|}|}\\
%  The command |\rem{|\textit{text}|}| typsets the text
%  ``\textit{text}'' (in the default LR-font) flush left on
%  a seperate row in |eqnarray|, |deqarr|, |ddeqar|, and |deqrarr| 
%  environments, and preserves the environment's alignment
%  for rows to come.  |\where| is equivalent to 
%  |\rem{where}|. 
%  \item{|\nydeleqno|}\\
%  Gives a new partial equation number when used within |$$ ... $$|.
%  Thus, writing |$$ ...| |\nydeleqno $$| is equivalent to 
%  writing |\begin{deqn} ... \end{deqn}|.
%  \item{|\deleqno|}\\
%  Gives a partial equation number when used within |$$ ... $$|.
%  Thus, writing |$$ ...| |\deleqno| |$$| is equivalent to 
%  writing |\begin{ddeqn} ... \end{ddeqn}|. 
%  \item{|\jotbaseline|}\\
%  This is a rubber length which is set to be the sum of 
%  |\baselinsekip| and |\jot| each time a |deqarr|, |ddeqar|, 
%  or a |deqrarr| environment is enterd.  It is meant to be 
%  used with the |\eqreqno| command and its relatives to 
%  eliminate the problems when these commands are used on the 
%  last line of the environment.  (The length |\baselineskip| + 
%  |\jot| is the length \LaTeX{} skips between two 
%  empty lines in an `|eqnarray|' environment and its 
%  derivates defined in |deleq|.)  
%  \end{description}
%   
%  \section{Example}
%  After running \LaTeX{} on |deleq.ins|, there is an 
%  example avaliable in the file |delex.tex|, 
%  which makes use of all the environments and commands 
%  defined in the |deleq| package.  Typset it and see with 
%  your own eyes what the results are!
%  
%  
%  \section{Sending a Bug Report}
%  |deleq| is most likely to contain bugs.
%  Reports of bugs in the package are most welcome.  
%  Before filing a bug report,
%  please take the following actions:
%  \begin{enumerate}
%  \item Ensure your problem is not due to your inputfile;
%  \item Ensure your problem is not due to 
%     your own package(s) or class(es);
%  \item Ensure your problem is not covered in the section 
%     ''Known Problems'' above;
%  \item  Try to locate the problem by writing a minimal 
%     \LaTeX{} input file which reproduces the problem.  
%     Include the command\\ 
%     |  \setcounter{errorcontextlines}{999}|\\ 
%     in your input;
%  \item Run your file through \LaTeX{};
%  \item Send a description of your problem, the input file 
%     and the log file via e-mail to:\\
%     \hspace*{5mm} \texttt{matsd@physchem.kth.se}.
%  \end{enumerate}
%  {\itshape Enjoy your \LaTeX!\raisebox{-\baselineskip}{mats d.}}
%  
%  \section{The Code} 
%  For the interested reader(s), here is a short description 
%  of the code. \par
% \iffalse
%<*paketkod>
% Part 1: Identification etc.
% \fi
%  First, the package is to identify itself.
%    \begin{macrocode} 
\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesPackage{deleq}[1995/05/15 v.4.2 Partial equation numbering]
\typeout{deleq version 4.2 (May 15, 1995) included.  (c) 1994-95 by Mats Dahlgren}
\def\deleqver{\texttt{deleq} version 4.2 (May~15, 1995)}
%    \end{macrocode}
% \iffalse
% Part 2: Counters and internal commands, etc.
% \fi
%  \par  Then, we need to define the counters used for the partial 
%  part of the equation number.  The counter |Deleq| is used for 
%  ``recycled'' equation numbers, hence no dependence on any other 
%  counter.  
%    \begin{macrocode}
\newcounter{deleq}[equation]
\newcounter{Deleq}
\newlength{\jotbaseline}
\renewcommand{\thedeleq}{\ensuremath{\theequation\mathrm{\alph{deleq}}}}
\renewcommand{\theDeleq}{\ensuremath{\mathrm{\alph{Deleq}}}}
\def\@deleqnnum{(\thedeleq)}
\def\@deleqrnum#1{(\ref{#1}\theDeleq)}   
\def\@eqrnum#1{(\ref{#1})}   
%    \end{macrocode}
%  The parts making up the |\\| command in the multiline environments 
%  are extremely similar to those used by the standard environments:
%    \begin{macrocode}
\def\@deqncr{{\ifnum0=`}\fi\@ifstar{\global\@eqpen\@M
    \@ydeqncr}{\global\@eqpen\interdisplaylinepenalty \@ydeqncr}} 
\def\@ydeqncr{\@ifnextchar [{\@xdeqncr}{\@xdeqncr[\z@]}} 
\def\@xdeqncr[#1]{\ifnum0=`{\fi}\@@deqncr
   \noalign{\penalty\@eqpen\vskip\jot\vskip #1\relax}}
\def\@@deqncr{\let\@tempa\relax
    \ifcase\@eqcnt \def\@tempa{& & &}\or \def\@tempa{& &}%
      \else \def\@tempa{&}\fi
     \@tempa \if@eqnsw\@deleqnnum\stepcounter{deleq}\fi
     \global\@eqnswtrue\global\@eqcnt\z@\cr}  
\newcommand{\@xeqrcr}[2]{\ifnum0=`{\fi}\@@eqrcr{#2}
   \noalign{\penalty\@eqpen\vskip\jot\vskip #1\relax}}
\def\@@eqrcr#1{\let\@tempa\relax
    \ifcase\@eqcnt \def\@tempa{& & &}\or \def\@tempa{& &}%
      \else \def\@tempa{&}\fi
     \@tempa \if@eqnsw\@eqrnum{#1}\fi
     \global\@eqnswtrue\global\@eqcnt\z@\cr} 
\newcommand{\@xdeqrcr}[2]{\ifnum0=`{\fi}\@@deqrcr{#2}
   \noalign{\penalty\@eqpen\vskip\jot\vskip #1\relax}}
\def\@@deqrcr#1{\let\@tempa\relax
    \ifcase\@eqcnt \def\@tempa{& & &}\or \def\@tempa{& &}%
      \else \def\@tempa{&}\fi
     \@tempa \if@eqnsw\@deleqrnum{#1}\fi
     \global\@eqnswtrue\global\@eqcnt\z@\cr} 
\def\@deqrarcr{{\ifnum0=`}\fi\@ifstar{\global\@eqpen\@M
    \@ydeqrarcr}{\global\@eqpen\interdisplaylinepenalty \@ydeqrarcr}}
\def\@ydeqrarcr{\@ifnextchar [{\@xdeqrarcr}{\@xdeqrarcr[\z@]}}
\def\@xdeqrarcr[#1]{\ifnum0=`{\fi}\@@deqrarcr
   \noalign{\penalty\@eqpen\vskip\jot\vskip #1\relax}}
\def\@@deqrarcr{\let\@tempa\relax
    \ifcase\@eqcnt \def\@tempa{& & &}\or \def\@tempa{& &}%
      \else \def\@tempa{&}\fi
     \@tempa \global\@eqnswtrue\global\@eqcnt\z@\cr}
%    \end{macrocode}
% \iffalse
% Part 3:  Commands:  \nydeleqno, \deleqno, \reqno, \rndeqno, \rdeqno,  
%                     \eqreqno, \deqreqno, \ddeqreqno, \arrlabel, 
%                     \nydeqno, and \heqno
% \fi
%  \par Here the definitions of the user commands are.
%    \begin{macrocode}
\newcommand{\nydeleqno}{\refstepcounter{equation}\refstepcounter{deleq}
  \let\@currentlabel\thedeleq \eqno (\thedeleq)}
\newcommand{\deleqno}{\refstepcounter{deleq} \let\@currentlabel\thedeleq 
  \eqno (\thedeleq)}
\newcommand{\reqno}[1]{\setcounter{Deleq}{-1}\refstepcounter{Deleq}
   \eqno (\ref{#1}) }
\newcommand{\rdeqno}[1]{\refstepcounter{Deleq}
   \eqno (\ref{#1}\theDeleq)}
\newcommand{\rndeqno}[1]{\setcounter{Deleq}{0}\refstepcounter{Deleq}
   \eqno (\ref{#1}\theDeleq)}
\newcommand{\eqreqno}[2][0pt]{{\ifnum0=`}\fi\@ifstar{\global\@eqpen\@M
    \@xeqrcr{#1}{#2}}{\global\@eqpen\interdisplaylinepenalty 
    \@xeqrcr{#1}{#2}}}
\newcommand{\deqreqno}[2][0pt]{\setcounter{Deleq}{0}\refstepcounter{Deleq}
    {\ifnum0=`}\fi\@ifstar{\global\@eqpen\@M
    \@xdeqrcr{#1}{#2}}{\global\@eqpen\interdisplaylinepenalty 
    \@xdeqrcr{#1}{#2}}}
\newcommand{\ddeqreqno}[2][0pt]{\refstepcounter{Deleq}
    {\ifnum0=`}\fi\@ifstar{\global\@eqpen\@M
    \@xdeqrcr{#1}{#2}}{\global\@eqpen\interdisplaylinepenalty 
    \@xdeqrcr{#1}{#2}}}
\newcommand{\arrlabel}[1]{\let\@currentlabel\theequation \label{#1}}
\newcommand{\nydeqno}{\stepcounter{equation}\stepcounter{deleq}}
\newcommand{\heqno}{\stepcounter{equation}}
%    \end{macrocode}
%  And the two commands |\where| and |\rem| follow suit:
%    \begin{macrocode}
\def\where{\let\@tempa\relax \def\@tempa{& & &}
     \@tempa {\hbox to .01\p@{}\rlap{\hskip -\displaywidth where}}\cr}
\def\rem#1{\let\@tempa\relax \def\@tempa{& & &}
     \@tempa {\hbox to .01\p@{}\rlap{\hskip -\displaywidth #1}}\cr}
%    \end{macrocode}
% \iffalse
% Part 4:  Environments: 'deqarr', 'ddeqar', 'deqn', 'ddeqn', and 'deqrarr'  
% \fi
%  \par The five environments are slight modifications of the 
%  corresponding \LaTeX{} standard environments.  The main difference 
%  lies in which counter(s) is stepped and which internals are used to 
%  finish off the lines.  Three of them have large parts in 
%  common, parts which are put in one macro `|\@dlqnv|':
%    \begin{macrocode}
\def\@dlqnv{\setlength{\jotbaseline}{\baselineskip}%
  \addtolength{\jotbaseline}{\jot}  \global\@eqnswtrue\m@th
  \global\@eqcnt\z@\tabskip\@centering
  $$\halign to\displaywidth\bgroup\@eqnsel\hskip\@centering
  $\displaystyle\tabskip\z@{##}$&\global\@eqcnt\@ne
  \hskip 2\arraycolsep \hfil${##}$\hfil
  &\global\@eqcnt\tw@ \hskip 2\arraycolsep $\displaystyle\tabskip\z@{##}$\hfil
   \tabskip\@centering&\llap{##}\tabskip\z@\cr}
\newenvironment{deqarr}{\stepcounter{equation}\stepcounter{deleq}
  \let\@currentlabel\thedeleq  \let\\\@deqncr  \@dlqnv}
{\@@deqncr\egroup
      \global\advance\c@deleq\m@ne$$\global\@ignoretrue}
\newenvironment{ddeqar}{\stepcounter{deleq}
  \let\@currentlabel\thedeleq  \let\\\@deqncr  \@dlqnv}
{\enddeqarr}
\newenvironment{deqn}{$$\refstepcounter{equation}\stepcounter{deleq} 
   \let\@currentlabel\thedeleq}
  {\eqno \hbox{\@deleqnnum} $$\global\@ignoretrue}
\newenvironment{ddeqn}{$$\refstepcounter{deleq} \let\@currentlabel\thedeleq}
  {\eqno \hbox{\@deleqnnum} $$\global\@ignoretrue}
\newenvironment{deqrarr}{\let\@currentlabel\theDeleq  
  \let\\\@deqrarcr   \@dlqnv}
{\@deqrarcr   \egroup  $$\global\@ignoretrue}
%    \end{macrocode}
% \iffalse
% Part 5:  'leqno' compatibility
% \fi
%  \par If the user wants the equation numbers to the left, we have to 
%  modify some of the commands and internals defined above.  This is 
%  done in a |\DeclareOption|-call:
%    \begin{macrocode}
\DeclareOption{leqno}{%
\renewcommand{\@deleqnnum}{\hbox to .01\p@{}\rlap{\reset@font\rmfamily
  \hskip -\displaywidth(\thedeleq)}}
\renewcommand{\nydeleqno}{\refstepcounter{equation}\refstepcounter{deleq}
  \let\@currentlabel\thedeleq \leqno (\thedeleq)}
\renewcommand{\deleqno}{\refstepcounter{deleq} \let\@currentlabel\thedeleq 
  \leqno (\thedeleq)}
\renewcommand{\reqno}[1]{\setcounter{Deleq}{-1}\refstepcounter{Deleq}
   \leqno (\ref{##1}) }
\renewcommand{\rdeqno}[1]{\refstepcounter{Deleq}
   \leqno (\ref{##1}\theDeleq)}
\renewcommand{\rndeqno}[1]{\setcounter{Deleq}{0}\refstepcounter{Deleq}
   \leqno (\ref{##1}\theDeleq)}
\renewcommand{\@eqrnum}[1]{\hbox to .01\p@{}\rlap{\reset@font\rmfamily
        \hskip -\displaywidth(\ref{##1})}}     
\renewcommand{\@deleqrnum}[1]{\hbox to .01\p@{}\rlap{\reset@font\rmfamily
        \hskip -\displaywidth(\ref{##1}\theDeleq)}}     
  }
%    \end{macrocode}
%  If other options were asked for, the package should inform the user 
%  that this has no effect on |deleq|.  Then, last, the option(s) 
%  is (are) processed.
%    \begin{macrocode}
\DeclareOption*{\typeout{`\CurrentOption '\space has no effect on deleq.}%
  \OptionNotUsed}
\ProcessOptions
%    \end{macrocode}
%  That is all.  Have a nice life!
% \iffalse
% END of it all!
%</paketkod>
%<*driver>
\documentclass[a4paper]{article}
\usepackage{doc}
\textwidth=150mm
\textheight=210mm
\topmargin=0mm
\oddsidemargin=5mm
\evensidemargin=5mm
\begin{document}
  \DocInput{deleq.dtx} 
  \PrintChanges
\end{document}
%</driver>
%<*exempelkod>
\documentclass[11pt]{article} %%% add `leqno' if you want left-aligned
\usepackage{deleq}            %%%                    equation numbers.
\oddsidemargin=0.5cm
\evensidemargin=0.5cm
\topmargin=-5mm           
\textheight=23.5cm
\textwidth=15.5cm
\begin{document}
  \begin{center}
  \Large Welcome to the \texttt{deleq} package!
  \end{center}
  
  This is a short document to demonstrate the use of the 
  \texttt{deleq} package and its commands.  It uses \deleqver .
  \texttt{deleq} was written by Mats Dahlgren
  (\texttt{matsd@physchem.kth.se}).  Suggestions for
  improvements and bug reports are most welcome, see the 
  documentation.  \texttt{deleq} is fully compatible with the
  \texttt{leqno} option. 
  
  We start this demonstration by a simple and well-known
  equation to get the equation number counter going: 
  \begin{equation}  
    \sin^2\alpha + \cos^2\alpha = 1  
  \end{equation}
  The first example will be to make use of the
  \texttt{deqn} environment to get a partially numbered
  equation: 
  \begin{deqn}  
    \sin (-\alpha) = - \sin \alpha  
  \end{deqn}
  This equation has its cosine companion, here written in
  the \texttt{ddeqn} environment: 
  \begin{ddeqn}  
    \cos (-\alpha) = \cos \alpha  
  \end{ddeqn}
  Not so exciting, so far. :--)
  
  In the next example we introduce the \texttt{deqarr}
  environment for writing equations: 
  \begin{deqarr}
    \sin ( \alpha + \beta ) & = 
      & \sin \alpha \cos \beta + \sin \beta \cos \alpha \\
    \sin ( \alpha - \beta ) & = 
      & \sin \alpha \cos \beta - \sin \beta \cos \alpha 
    \label{Demo1}
  \end{deqarr}
  where we also have put in the label \texttt{Demo1} in
  the second equation. Next, notice how the environment
  \texttt{ddeqar} uses the same main equation number as
  the previous equations: 
  \begin{ddeqar}
    \cos ( \alpha + \beta ) & = 
      & \cos \alpha \cos \beta - \sin \alpha \sin \beta 
      \arrlabel{Demo2} \\
    \cos ( \alpha - \beta ) & = 
      & \cos \alpha \cos \beta + \sin \alpha \sin \beta 
  \end{ddeqar}
  In the first of these equations, an \verb+\arrlabel+ command 
  with the label \texttt{Demo2} is included.  
  Now, we will make another \texttt{eqnarray}-like
  structure, again in the \texttt{ddeqar} environment: 
  \begin{ddeqar}
    \sin 2\alpha & = 
      & 2 \sin \alpha \cos \alpha \heqno \label{Demo3} \\
    \cos 2\alpha & = 
      & \cos ^2 \alpha - \sin ^2 \alpha \nydeqno \\
  \rem{or}
      & = & 2\cos ^2 \alpha - 1 
  \end{ddeqar}
  This example shows the use of \verb$\heqno$ in the first
  equation, which produces an ordinary equation number. 
  The first equation is also labelled, with the label
  \texttt{Demo3}.  The next equation's number was produced
  by the command \verb$\nydeqno$.  Also, notice the use of
  \verb+\rem{or}+, which results in the text ``or'' without
  changing the alignment.  To illustrate the use of 
  \verb+\arrlabel{Demo2}+ above, we here make a reference to it: 
  \ldots{} in equations \ref{Demo2} \ldots which was 
  created by typing 
  `\verb+\ldots{} in equations \ref{Demo2} \ldots+'.


  
  To step the equation number counter, we want the
  following equations typeset in ordinary
  \texttt{eqnarray} environment: 
  \begin{eqnarray}
    \tan ^2 \alpha & = 
      & \frac{\sin ^2 \alpha}{\cos ^2 \alpha} \label{Demo4} \\
    \tan \alpha & = 
      & \frac{\sin \alpha}{\cos \alpha} 
  \end{eqnarray}
  The upper equation was given the label \texttt{Demo4}.
  
  Now one of the ``recycling'' commands is to be
  demonstrated.  First of all, let's make an ordinary
  reference to equation~\ref{Demo3}, and then ``recycle'' it: 
  $$ \sin 2\alpha = 2 \sin \alpha \cos \alpha \reqno{Demo3} $$
  This was obtained with \verb#$$ ... $$# with the command
  \verb#\reqno{Demo3}# at the end.  Also partially
  numbered equations can be recycled with the
  \verb#\reqno{FOO}# command, as with
  equation~\ref{Demo1}: 
  $$ \sin ( \alpha - \beta ) = \sin \alpha \cos \beta - 
    \sin \beta \cos \alpha \reqno{Demo1} $$
  (However, the use of \verb#\rndeqno{FOO}# and
  \verb#\rdeqno{FOO}# will produce strange results with
  two (different) partial equation numbers if \texttt{FOO}
  refers to a partially numbered equation.) 
  
  The next equation was written with \verb#$$ ... $$# and
  a \verb#\deleqno# command at the end: 
  $$ \tan 2\alpha = \frac{2\tan \alpha}{1 - \tan ^2 \alpha} \deleqno $$
  Notice how the main equation number counter is still the
  same, despite that we now are outside of the
  \texttt{ddeqar} environment. Also, notice how the use of
  \verb#\reqno# above did not affect the equation number
  counter. The following equation is also set within
  \verb#$$ ... $$#, but it uses the command
  \verb#\nydeleqno# to produce an equation number with a
  new main number: 
  $$ \sin ^2 \alpha = 1 - \cos ^2 \alpha \nydeleqno $$
  
  Now we will elaborate a little on \verb#\rndeqno{FOO}#
  and \verb#\rdeqno{FOO}#. Let us use
  equation~\ref{Demo4}, and see what happens if we use the
  \verb#\rndeqno{FOO}# command: 
  $$ \tan ^2 \alpha = \frac{\sin ^2 \alpha}
    {\cos ^2 \alpha} \rndeqno{Demo4} $$
  which we rewrite:
  $$ \tan ^2 \alpha = \frac{\sin ^2 \alpha}
    {1 - \sin ^2 \alpha} \rdeqno{Demo4}  \label{Demo5} $$
  with \verb#\rdeqno{Demo4}# at the end.  This is great
  fun, so why not one more: 
  $$ \tan ^2 \alpha = \frac{1 - \cos ^2 \alpha}
    {\cos ^2 \alpha} \rdeqno{Demo4} $$ 
  Also, the middle form of equation~\ref{Demo4} got a
  label, \texttt{Demo5}. 
  
  There is still one equation to write.  This time we
  again use the \texttt{deqarr} environment: 
  \begin{deqarr}
  \cot \alpha & = & \frac{\cos \alpha}{\sin \alpha} \\
  \where
    & = & \frac{1}{\tan \alpha}
  \end{deqarr}
  This example also shows the use of the \verb+\where+ 
  command, which is a special case of the \verb+\rem+ command.
  Now, the interesting thing of referring to the recycled
  equations is ahead. If one writes \verb#\ref{Demo5}#,
  this is what \LaTeX\ will return:~\ref{Demo5}.  That is
  not too instructive, since the partial equation numbers
  are quite common in this document.  To make the complete
  reference, use \verb#\ref{Demo4}\ref{Demo5}#.  The
  reference~\ref{Demo4}\ref{Demo5} is much more
  comprehensible, right? (If you get bad line-breaks at
  such references, put them in an \verb#\mbox{...}#.) 

  Now we will show the use of the commands to recycle equation 
  numbers in \verb+eqnarray+-like structures.  These commands 
  are \verb+\eqreqno{FOO}+, \verb+\deqreqno{FOO}+, and 
  \verb+\ddeqreqno{FOO}+.  We start by repeating equation 
  \ref{Demo1} in an \verb+deqrarr+ environment:
  \begin{deqrarr}
    \sin ( \alpha - \beta ) & = 
      & \sin \alpha \cos \beta - \sin \beta \cos \alpha 
      \eqreqno{Demo1}
    \sin 2\alpha & = & 2 \sin\alpha \cos\alpha 
  \end{deqrarr}
  The second equation here shows how the alignment of the 
  equations is preserved.  Next, we can use the equation 
  \ref{Demo3} for some variations:
  \begin{deqrarr}
    \sin 2\alpha & = & 2 \sin\alpha \cos\alpha 
      \deqreqno{Demo3}
    \sin 4\alpha & = & 2 \sin 2\alpha \cos 2\alpha \\
      & = & 2\left( 2\sin\alpha \cos\alpha 
        \left( \cos^2 \alpha - \sin^2 \alpha\right)\right)
        \ddeqreqno{Demo3}
      & = & 4\left(\sin\alpha \cos\alpha 
        \left( \cos^2 \alpha - \sin^2 \alpha\right)\right)
        \ddeqreqno[-\jotbaseline]{Demo3} 
  \end{deqrarr}
  The features used here are \verb+\deqreqno{Demo3}+ 
  on the first line, \verb+\ddeqreqno{Demo3}+ on the 
  second line, and \verb+\deqreqno[-\jotbaseline]{Demo3}+ 
  on the third.  Note how the inclusion of 
  \verb+[-\jotbaseline]+ on the third line prevents 
  \LaTeX{} from inserting an extra blank line.  The 
  second line ends with `\verb+\\+', and has thus no 
  equation number at all.
  
  The last part shows how you may use \verb+\eqreqno+ and its 
  relatives in \verb+deqarr+ environment:  
  \begin{deqarr}
    \sin\alpha & = & \sin\alpha \cos 0 + \sin 0 \cos\alpha \\
    \sin 2\alpha & = & 2 \sin\alpha \cos\alpha \eqreqno{Demo3}
    \sin 3\alpha & = & \sin 2\alpha \cos\alpha + 
      \sin\alpha \cos 2\alpha \\
    \sin 4\alpha & = & 2 \sin 2\alpha \cos 2\alpha \\
    \sin 5\alpha & = & \sin 3\alpha \cos 2\alpha + 
      \sin 2\alpha \cos 3\alpha \ddeqreqno{Demo3}
    \sin 6\alpha & = & 2 \sin 3\alpha \cos 3\alpha 
  \end{deqarr}
  The interesting part here is an `\verb+\eqreqno{Demo3}+' at 
  the end of the second line and a `\verb+\ddeqreqno{Demo3}+' at 
  the end of the fifth line.  Notice how the partial 
  equation number counter in unaffected by the enetering of 
  the \verb+deqarr+ environment.

  Finally, the $\mathcal{END}$!  If you want your
  equations left-aligned, just specify the \texttt{leqno}
  option for the \texttt{documentclass} you are using.  It
  should work!  If you have any suggestions, corrections
  or contributions, please contact me. Enjoy \LaTeX ! 
  
  {\itshape mats d.}
\end{document}
%</exempelkod>  
% \fi
%
% \Finale
%
\endinput 
