Numbering individual lines of equation array’s

Johannes Braams PTT Research Sint Paulusstraat 4 2264 XZ Leidschendam The Netherlands

          Internet: J.L.Braams@research.ptt.nl

February 9, 1994

This package defines the subeqnarray and subeqnarray* environments, which behave like the equivalent eqnarray and eqnarray* environments, except that the individual lines are numbered like 1a, 1b, 1c, etc.

To refer to these numbers an extra label command \slabel has been defined. Many of this code was taken from latex.tex and modified for this purpose.

1 Identification

The first thing to do is identify this package to L^{A}TEX

1 %<*package>
2 \ProvidesPackage{subeqnarray}[\filedate\space subeqnarray package]

and write a note in the log file.

3 \wlog{Package `subeqnarray' version \fileversion\space<\filedate> (JLB)}
4 \wlog{English documentation\space\space\space<\docdate> (JLB)}

2 Initial Code

\c@subequation We need to allocate a new counter for the subequation environment. It is reset by the equation counter.

5 \newcounter{subequation}[equation]

\thesubequation The representation o the counter subequation includes the equation counter

6 \def\thesubequation{\theequation\alph{subequation}}

subeqnarray package version 2.1as of 1994/02/10 2

3 Option Handling

The standard L^{A}TEX options leqno and fleqn are recognised by this package.

 7 %
 8 %    When \Lopt{leqno} is used the equation numbers should appear on
 9 %    the left side of the equation. The numbers are generated by
10 %    |\@subeqnnum| which needs a different definition to acheive this
11 %    effect.
12 %    \begin{macrocode}
13 \DeclareOption{leqno}{%
14 \def\@subeqnnum{\hbox to .01\p@{}\rlap{\reset@font\rmfamily
15  \hskip -\displaywidth(\thesubequation)}}}

The default definition of \@subeqnnum.

16 \DeclareOption{reqno}{%
17 \def\@subeqnnum{{\reset@font\rmfamily (\thesubequation)}}}

When the option fleqn is used, the equations have to be printed flush left, with an indent of \mathindent; the equations are seperated from the surrounding text by \topsep (plus \partopsep if necessary) and the width of the display is \linewidth.

18 \DeclareOption{fleqn}{%
19 \def\subeqn@start{%
20  \tabskip\mathindent
21  \abovedisplayskip\topsep
22  \ifvmode\advance\abovedisplayskip\partopsep\fi
23  \belowdisplayskip\abovedisplayskip
24  \belowdisplayshortskip\abovedisplayskip
25  \abovedisplayshortskip\abovedisplayskip
26  $$\everycr{}\halign to \linewidth}}% $$

The default will be to have displayed equations to the width of \displaywidth.

27 \DeclareOption{deqn}{%
28 \def\subeqn@start{%
29  \tabskip\@centering
30  $$\everycr{}\halign to \displaywidth}}% $$

We don’t support any other options

31 \DeclareOption*{\OptionNotUsed}

4 Executing Options

Make sure the \@eqnnum is defined by specifying reqno as a default option. Specifying deqn as a default option defines \subeqn@start.

32 \ExecuteOptions{reqno,deqn}

Now see if the use specified any options.

33 \ProcessOptions

5 The main code

\slabel A new label command to refer to subequations. It works like the \label command

and was taken from latex.tex.

\slabel{FOO} writes the following on file \@auxout

   \newlabel{FOO}{{eval(\@currentlabel)}{eval(\thepage)}}
34 \newcommand\slabel[1]{%
35 \@bsphack
36 \if@filesw
37  {\let\thepage\relax
38  \def\protect{\noexpand\noexpand\noexpand}%
39  \edef\@tempa{\write\@auxout{\string
40  \newlabel{#1}{{\thesubequation}{\thepage}}}}%
41  \expandafter}\@tempa
42  \if@nobreak \ifvmode\nobreak\fi\fi
43 \fi\@esphack}

subeqnarray The subeqnarray environment steps the equation counter, sets the subequation counter equal to 1 and behaves much like the eqnarray environment. Note the \@currentlabel is defined to use the equation counter. This is done so that an entire array an be referred to using the value of the equation counter. Hence the need for the \slabel command.

44 \newenvironment{subeqnarray}%
45 {\stepcounter{equation}%
46  \def\@currentlabel{\p@equation\theequation}%
47  \global\c@subequation\@ne
48  \global\@eqnswtrue\m@th
49  \global\@eqcnt\z@\let\\\@subeqncr
50  \subeqn@start
51  \bgroup\hskip\@centering
52  $\displaystyle\tabskip\z@skip{##}$\@eqnsel
53  &\global\@eqcnt\@ne \hskip \tw@\arraycolsep \hfil${##}$\hfil
54  &\global\@eqcnt\tw@ \hskip \tw@\arraycolsep
55  $\displaystyle{##}$\hfil \tabskip\@centering
56  &\global\@eqcnt\thr@@
57  \hbox to\z@\bgroup\hss##\egroup\tabskip\z@skip\cr}
58 {\@@subeqncr\egroup $$\global\@ignoretrue}

\@subeqncr These macros handle the user command \\; they are adapted from the ones used or

the eqnarray environment.

First the presence of a * detected and the right penalty selected.

59 \def\@subeqncr{{\ifnum0=`}\fi\@ifstar{\global\@eqpen\@M
60  \@ysubeqncr}{\global\@eqpen\interdisplaylinepenalty \@ysubeqncr}}

@ysubeqncr This macro is called by \@subeqncr and checks if the user requested any extra vertical space. It calls \@xsubeqncr with the wanted amount of space as its argument.

61 \def\@ysubeqncr{\@ifnextchar [{\@xsubeqncr}{\@xsubeqncr[\z@skip]}}

\@xsubeqncr This macro calls \@@subeqncr to put in extra &’s if needed, generating an error if the number of columns is too large. Then the penalty selected earlier and the white space requested are inserted.

62 \def\@xsubeqncr[#1]{\ifnum0=`{\fi}\@@subeqncr
63 \noalign{\penalty\@eqpen\vskip\jot\vskip #1\relax}}

\@@subeqncr Ceck the number of columns, and insert extra & if needed. If there appear to be more than 3 columns an error is signalled.

64 \def\@@subeqncr{\let\@tempa\relax
65  \ifcase\@eqcnt \def\@tempa{& & &}\or \def\@tempa{& &}
66  \or \def\@tempa{&}\else
67  \let\@tempa\@empty
68  \@latexerr{Too many columns in subeqnarray environment}\@ehc\fi
69  \@tempa \if@eqnsw\@subeqnnum\refstepcounter{subequation}\fi
70  \global\@eqnswtrue\global\@eqcnt\z@\cr}

subeqnarray* This environment is basically the same as the eqnarray environment, but it is provided just or completeness.

71 \newenvironment{subeqnarray*}%
72 {\def\@subeqncr{\nonumber\@ssubeqncr}\subeqnarray}
73 {\global\advance\c@equation\m@ne\nonumber\endsubeqnarray}

\@ssubeqncr This is used in the esubqnarray* environment.

74 \let\@ssubeqncr\@subeqncr
75 %</package>
76 %<*sample>

6 An example of the use of this package

When you run the following document through L^{A}TEX you will see the differene between

the subeqnarray and eqnarray environments.
77 %<*sample>
78 \documentclass[fleqn]{article}
79 \usepackage{subeqnarray}
80 \begin{document}
81 This document shows an example of the use of the \emph{subeqnarray}
82 environment. Here is one:
83 \begin{subeqnarray}
84 \label{eqw}
85 \slabel{eq0}
86 x & = & a \times b \\
87 \slabel{eq1}
88 & = & z + t\\
89 \slabel{eq2}
90 & = & z + t
91 \end{subeqnarray}
92 The first equation is number~\ref{eq0}, the last is~\ref{eq2}. The

 93 equation as a whole can be referred to as equation~\ref{eqw}.

94

 95 To show that equation numbers behave normally, here's an
 96 \emph{eqnarray} environment.
 97 \begin{eqnarray}
 98 \label{eq10}
 99 x & = & a \times b \\
100 \label{eq11}
101 & = & z + t\\
102 \label{eq12}
103 & = & z + t
104 \end{eqnarray}

105

106 These are equations~\ref{eq10},~\ref{eq11} and~\ref{eq12}.
107 \end{document}
108 %</sample>

Index 6

Index

The italic numbers denote the pages where the corresponding entry is described, numbers underlined point to the definition, all others indicate the places where it is used.

Symbols

\@@subeqncr 58, 62, 64, \underline{64}

\@M . . . . . . . . . . . . . . 59 \@auxout . . . . . . . . . . 39 \@bsphack . . . . . . . . . 35

\@centering . . . 29, 51, 55
\@currentlabel . . . . . 46

\@ehc . . . . . . . . . . . . . 68 \@empty . . . . . . . . . . . 67 \@eqcnt . . . . . . . . . . .

49, 53, 54, 56, 65, 70 \@eqnsel . . . . . . . . . . 52

\@eqnswtrue . . . . . . 48, 70

\@eqpen . . . . . . 59, 60, 63 \@esphack . . . . . . . . . 43

\@ifnextchar . . . . . . . 61

\@ifstar . . . . . . . . . . 59

\@ignoretrue . . . . . . . 58
\@latexerr . . . . . . . . 68

\@ne . . . . . . . . . . . . 47, 53

\@ssubeqncr . . . 72, 74, \underline{74}
\@subeqncr . . . . . . . .

. . 49, 59, \underline{59}, 72, 74

\@subeqnnum 10, 14, 17, 69

\@tempa . 39, 41, 64–67, 69

\@xsubeqncr . . . 61, 62, \underline{62}
\@ysubeqncr . . . . . . 60, 61

\\ …. 49, 86, 88, 99, 101

A

\abovedisplayshortskip

. . . . . . . . . . . . . 25

\abovedisplayskip 21–25

\advance . . . . . . . . 22, 73 \alph . . . . . . . . . . . . . . 6

\arraycolsep . . . . . 53, 54

B

\begin …. 12, 80, 83, 97

\belowdisplayshortskip

. . . . . . . . . . . . . 24

\belowdisplayskip . . 23

\bgroup . . . . . . . . . 51, 57

C

                           \c@equation . . . . . . . . 73
                           \c@subequation . . . . \underline{5}, 47

\cr . . . . . . . . . . . . 57, 70

D

                           \DeclareOption . . . . .

. . 13, 16, 18, 27, 31 \def . . . . . . . . . 6, 14,

17, 19, 28, 38, 46, 59, 61, 62, 64–66, 72

                           \displaystyle . . . . 52, 55
                           \displaywidth . . . . 15, 30

\docdate . . . . . . . . . . . 4

                           \documentclass . . . . . 78

E \edef . . . . . . . . . . . . . 39 \egroup . . . . . . . . . 57, 58 \else . . . . . . . . . . . . . 66 \emph . . . . . . . . . . . 81, 96 \end . . . . . . . 91, 104, 107

                           \endsubeqnarray . . . . 73

environments:

                              subeqnarray* . . . . . \underline{4}
                              subeqnarray . . . . . . \underline{3}

\everycr . . . . . . . . 26, 30

                           \ExecuteOptions . . . . 32
                           \expandafter . . . . . . . 41

F \fi 22, 42, 43, 59, 62, 68, 69 \filedate . . . . . . . . 2, 3

                           \fileversion . . . . . . . . 3

G \global … 47–49, 53,

54, 56, 58–60, 70, 73

H \halign . . . . . . . . . 26, 30 \hbox . . . . . . . . . . . 14, 57 \hfil . . . . . . . . . . . 53, 55 \hskip …. 15, 51, 53, 54 \hss . . . . . . . . . . . . . . 57

I \if@eqnsw . . . . . . . . . 69

                                                      \if@filesw . . . . . . . . 36
                                                      \if@nobreak . . . . . . . . 42

\ifcase . . . . . . . . . . . 65 \ifnum . . . . . . . . . . 59, 62 \ifvmode . . . . . . . . 22, 42

                                                      \interdisplaylinepenalty

. . . . . . . . . . . . . 60

J \jot . . . . . . . . . . . . . . 63

L \label … 84, 98, 100, 102 \let …. 37, 49, 64, 67, 74

                                                      \linewidth . . . . . . . . 26

\Lopt . . . . . . . . . . . . . . 8

M \m@ne . . . . . . . . . . . . . 73 \m@th . . . . . . . . . . . . . 48

                                                      \mathindent . . . . . . . . 20

N

                                                      \newcommand . . . . . . . . 34
                                                      \newcounter . . . . . . . . . 5
                                                      \newenvironment . . 44, 71

\newlabel . . . . . . . . . 40 \noalign . . . . . . . . . . 63 \nobreak . . . . . . . . . . 42 \noexpand . . . . . . . . . 38 \nonumber . . . . . . . 72, 73

O

                                                      \OptionNotUsed . . . . . 31

\or . . . . . . . . . . . . 65, 66

P \p@ . . . . . . . . . . . . . . 14

                                                      \p@equation . . . . . . . . 46
                                                      \partopsep . . . . . . . . 22

\penalty . . . . . . . . . . 63

                                                      \ProcessOptions . . . . 33

\protect . . . . . . . . . . 38

                                                      \ProvidesPackage . . . . 2

Change History 7

R

\ref . . . . . . . . 92, 93, 106

\refstepcounter . . . . 69

\relax . . . . . . . 37, 63, 64

\reset@font . . . . . . 14, 17

\rlap . . . . . . . . . . . . . 14 \rmfamily . . . . . . . 14, 17

S

\slabel . 34, \underline{34}, 85, 87, 89 \space . . . . . . . . . . . . 2–4

\stepcounter . . . . . . . 45

\string . . . . . . . . . . . 39

\subeqn@start . 19, 28, 50
\subeqnarray . . . . . . . 72

(environment) . . . . . . . \underline{44}
* (environment) . . . . . \underline{71}

T \tabskip 20, 29, 52, 55, 57

                           \theequation . . . . . . 6, 46

\thepage . . . . . . . . 37, 40

                           \thesubequation . . . .

…. 6, \underline{6}, 15, 17, 40 \thr@@ . . . . . . . . . . . . 56 \times . . . . . . . . . . 86, 99 \topsep . . . . . . . . . . . 21 \tw@ . . . . . . . . . . . . 53, 54

U

                           \usepackage . . . . . . . . 79

V \vskip . . . . . . . . . . . . 63

W \wlog . . . . . . . . . . . . 3, 4 \write . . . . . . . . . . . . 39

Y

                                                      @ysubeqncr . . . . . . . . \underline{61}

Z \z@ . . . . . . . . . 49, 57, 70 \z@skip . . . . . . 52, 57, 61

Change History

1.1

"General": Fixed bug in subeqnarray* environment . . . . . . . . . . . . . . . . . . . . . . . 1 2.0

"General": Added support for the fleqn option . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Added support for the leqno option . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

2.1 "General": Upgrade for LaTeX2e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1