Debian Codegraph @

texmf-dist/source/latex/subeqnarray/subeqnarray.dtx

raw
1 % \iffalse meta-comment
2 %
3 % Copyright 1998-2026 Johannes L. Braams. All rights reserved.
4 %
5 % This file is part of the subeqnarray package.
6 % ---------------------------------------------
7 %
8 % It may be distributed and/or modified under the
9 % conditions of the LaTeX Project Public License, either version 1.3c
10 % of this license or (at your option) any later version.
11 % The latest version of this license is in
12 % http://www.latex-project.org/lppl.txt
13 % and version 1.3c or later is part of all distributions of LaTeX
14 % version 2008 or later.
15 %
16 % This work has the LPPL maintenance status "maintained".
17 %
18 % The Current Maintainer of this work is Johannes Braams.
19 %
20 % The list of all files belonging to the supertabular package is
21 % given in the file `MANIFEST'.
22 %
23 % The list of derived (unpacked) files belonging to the distribution
24 % and covered by LPPL is defined by the unpacking scripts (with
25 % extension .ins) which are part of the distribution.
26 % \fi
27 %
28 % \CheckSum{264}
29 %
30 % \iffalse
31 %
32 % Subeqnarray package to use with LaTeX2e
33 %
34 %%
35 %% Error reports please to: J. Braams
36 %% TeXniek
37 %% Email: texniek at texniek.nl
38 %
39 % \section{Producing the documentation}
40 %
41 % A short driver is provided that can be extracted if necessary by
42 % the \textsf{DocStrip} program provided with \LaTeXe.
43 %<*dtx>
44 \ProvidesFile{subeqnarray.dtx}
45 %</dtx>
46 %<package>\NeedsTeXFormat{LaTeX2e}[1998/06/01]
47 %<package>\ProvidesPackage{subeqnarray}
48 %<sample>\ProvidesFile{subeqnarray-sample.tex}
49 %<driver>\ProvidesFile{subeqnarray.drv}
50 %\ProvidesFile{subeqnarray.dtx}
51 [2026/01/02 v2.1f subeqnarray package]
52 %<*driver>
53 \documentclass{ltxdoc}
54
55 \pagestyle{myheadings}
56 \EnableCrossrefs
57 \CodelineIndex
58 \RecordChanges
59 \newcommand\Lopt[1]{\textsf{#1}}
60 \makeatletter
61 \renewenvironment{theglossary}{%
62 \glossary@prologue%
63 \GlossaryParms \let\item\@idxitem \ignorespaces}%
64 {}
65 \makeatother
66 \begin{document}
67
68 \DocInput{subeqnarray.dtx}
69 \newpage
70 \PrintIndex
71 \PrintChanges
72 \end{document}
73 %</driver>
74 % \end{macrocode}
75 %\fi
76 %
77 % \GetFileInfo{subeqnarray.dtx}
78 % \title{Numbering individual lines of equation array's}
79 %
80 % \author{Johannes Braams\\
81 % \TeX niek\\
82 % The Netherlands\\
83 % Internet: \texttt{texniek at texniek.nl}}
84 %
85 % \date{\filedate}
86 %
87 % \markboth
88 % {subeqnarray package version \fileversion\space as of \filedate}
89 % {subeqnarray package version \fileversion\space as of \filedate}
90 %
91 % \maketitle
92 %
93 %
94 % This package defines the \texttt{subeqnarray} and
95 % \texttt{subeqnarray*} environments, which behave like the
96 % equivalent \texttt{eqnarray} and \texttt{eqnarray*} environments,
97 % except that the individual lines are numbered like 1a, 1b, 1c,
98 % etc.
99 %
100 % To refer to these numbers an extra label command |\slabel|
101 % has been defined.
102 %
103 % Many of this code was taken from \texttt{latex.tex} and modified
104 % for this purpose.
105 %
106 % \StopEventually{}
107 %
108 % \changes{1.1}{1988/12/22}{Fixed bug in subeqnarray* environment}
109 % \changes{2.0}{1993/11/02}{Added support for the leqno option}
110 % \changes{2.0}{1993/11/02}{Added support for the fleqn option}
111 % \changes{2.1}{1994/02/09}{Upgrade for LaTeX2e}
112 % \changes{v2.1b}{1999/03/03}{Changed licensing remarks to use LPPL}
113 % \changes{v2.1e}{2024/07/20}{Updated contact info}
114 % \changes{v2.1f}{2026/01/02}{Updated copyright info}
115 %
116 % \section{Initial Code}
117 %
118 % \begin{macro}{\c@subequation}
119 % We need to allocate a new counter for the \texttt{subequation}
120 % environment. It is reset by the \texttt{equation} counter.
121 % \begin{macrocode}
122 %<*package>
123 \newcounter{subequation}[equation]
124 % \end{macrocode}
125 % \end{macro}
126 %
127 % \begin{macro}{\thesubequation}
128 % The representation of the counter \texttt{subequation} includes
129 % the \texttt{equation} counter.
130 % \begin{macrocode}
131 \def\thesubequation{\theequation\alph{subequation}}
132 % \end{macrocode}
133 % \end{macro}
134 %
135 % \section{Option Handling}
136 %
137 % The standard \LaTeX\ options \Lopt{leqno} and \Lopt{fleqn} are
138 % recognised by this package.
139 % \begin{macrocode}
140 %
141 % When \Lopt{leqno} is used the equation numbers should appear on
142 % the left side of the equation. The numbers are generated by
143 % |\@subeqnnum| which needs a different definition to acheive this
144 % effect.
145 % \begin{macrocode}
146 \DeclareOption{leqno}{%
147 \def\@subeqnnum{\hbox to .01\p@{}\rlap{\reset@font\rmfamily
148 \hskip -\displaywidth(\thesubequation)}}}
149 % \end{macrocode}
150 % The default definition of |\@subeqnnum|.
151 % \begin{macrocode}
152 \DeclareOption{reqno}{%
153 \def\@subeqnnum{{\reset@font\rmfamily (\thesubequation)}}}
154 % \end{macrocode}
155 %
156 % When the option \Lopt{fleqn} is used, the equations have to be
157 % printed flush left, with an indent of |\mathindent|; the
158 % equations are seperated from the surrounding text by |\topsep|
159 % (plus |\partopsep| if necessary) and the width of the display is
160 % |\linewidth|.
161 % \begin{macrocode}
162 \DeclareOption{fleqn}{%
163 \def\subeqn@start{%
164 \tabskip\mathindent
165 \abovedisplayskip\topsep
166 \ifvmode\advance\abovedisplayskip\partopsep\fi
167 \belowdisplayskip\abovedisplayskip
168 \belowdisplayshortskip\abovedisplayskip
169 \abovedisplayshortskip\abovedisplayskip
170 $$\everycr{}\halign to \linewidth}}% $$
171 % \end{macrocode}
172 %
173 % The default will be to have displayed equations to the width of
174 % |\displaywidth|.
175 % \begin{macrocode}
176 \DeclareOption{deqn}{%
177 \def\subeqn@start{%
178 \tabskip\@centering
179 $$\everycr{}\halign to \displaywidth}}% $$
180 % \end{macrocode}
181 %
182 % We don't support any other options
183 % \begin{macrocode}
184 \DeclareOption*{\OptionNotUsed}
185 % \end{macrocode}
186 %
187 % \section{Executing Options}
188 %
189 % Make sure the |\@eqnnum| is defined by specifying \Lopt{reqno} as
190 % a default option. Specifying \Lopt{deqn} as a default option
191 % defines |\subeqn@start|.
192 % \begin{macrocode}
193 \ExecuteOptions{reqno,deqn}
194 % \end{macrocode}
195 %
196 % Now see if the user specified any options.
197 % \begin{macrocode}
198 \ProcessOptions
199 % \end{macrocode}
200 %
201 % \section{The main code}
202 %
203 % \begin{macro}{\slabel}
204 % A new label command to refer to subequations. It works
205 % like the |\label| command and was taken from \texttt{latex.ltx}.
206 %
207 % |\slabel{FOO}| writes the following on file |\@auxout|:
208 %
209 % |\newlabel{FOO}{{eval(\@currentlabel)}{eval(\thepage)}}|
210 %
211 % \begin{macrocode}
212 \newcommand\slabel[1]{%
213 \@bsphack
214 \if@filesw
215 {\let\thepage\relax
216 \def\protect{\noexpand\noexpand\noexpand}%
217 \edef\@tempa{\write\@auxout{\string
218 \newlabel{#1}{{\thesubequation}{\thepage}}}}%
219 \expandafter}\@tempa
220 \if@nobreak \ifvmode\nobreak\fi\fi
221 \fi\@esphack}
222 % \end{macrocode}
223 % \end{macro}
224 %
225 % \begin{environment}{subeqnarray}
226 % The \texttt{subeqnarray} environment steps the equation counter,
227 % sets the subequation counter equal to 1 and behaves much like the
228 % \texttt{eqnarray} environment. Note the |\@currentlabel| is
229 % defined to use the equation counter. This is done so that an
230 % entire array an be referred to using the value of the equation
231 % counter. Hence the need for the |\slabel| command.
232 %
233 % \begin{macrocode}
234 \newenvironment{subeqnarray}%
235 {\stepcounter{equation}%
236 \def\@currentlabel{\p@equation\theequation}%
237 \global\c@subequation\@ne
238 \global\@eqnswtrue\m@th
239 \global\@eqcnt\z@\let\\\@subeqncr
240 \subeqn@start
241 \bgroup\hskip\@centering
242 $\displaystyle\tabskip\z@skip{##}$\@eqnsel
243 &\global\@eqcnt\@ne \hskip \tw@\arraycolsep \hfil${##}$\hfil
244 &\global\@eqcnt\tw@ \hskip \tw@\arraycolsep
245 $\displaystyle{##}$\hfil \tabskip\@centering
246 &\global\@eqcnt\thr@@
247 \hbox to\z@\bgroup\hss##\egroup\tabskip\z@skip\cr}
248 {\@@subeqncr\egroup $$\global\@ignoretrue}
249 % \end{macrocode}
250 % \end{environment}
251 %
252 % \begin{macro}{\@subeqncr}
253 % These macros handle the user command |\\|; they are adapted from
254 % the ones used or the \texttt{eqnarray} environment.
255 %
256 % First the presence of a \texttt{*} detected and the right penalty
257 % selected.
258 % \begin{macrocode}
259 \def\@subeqncr{{\ifnum0=`}\fi\@ifstar{\global\@eqpen\@M
260 \@ysubeqncr}{\global\@eqpen\interdisplaylinepenalty \@ysubeqncr}}
261 % \end{macrocode}
262 %
263 % \begin{macro}{@ysubeqncr}
264 % This macro is called by |\@subeqncr| and checks if the user
265 % requested any extra vertical space. It calls |\@xsubeqncr| with
266 % the wanted amount of space as its argument.
267 % \begin{macrocode}
268 \def\@ysubeqncr{\@ifnextchar [{\@xsubeqncr}{\@xsubeqncr[\z@skip]}}
269 % \end{macrocode}
270 % \end{macro}
271 %
272 % \begin{macro}{\@xsubeqncr}
273 % This macro calls |\@@subeqncr| to put in extra |&|'s if needed,
274 % generating an error if the number of columns is too large. Then
275 % the penalty selected earlier and the white space requested are
276 % inserted.
277 % \begin{macrocode}
278 \def\@xsubeqncr[#1]{\ifnum0=`{\fi}\@@subeqncr
279 \noalign{\penalty\@eqpen\vskip\jot\vskip #1\relax}}
280 % \end{macrocode}
281 % \end{macro}
282 %
283 % \begin{macro}{\@@subeqncr}
284 % Check the number of columns, and insert extra |&| if needed. If
285 % there appear to be more than 3 columns an error is signalled.
286 % \begin{macrocode}
287 \def\@@subeqncr{\let\@tempa\relax
288 \ifcase\@eqcnt \def\@tempa{& & &}\or \def\@tempa{& &}
289 \or \def\@tempa{&}\else
290 \let\@tempa\@empty
291 \@latexerr{Too many columns in subeqnarray environment}\@ehc\fi
292 \@tempa \if@eqnsw\@subeqnnum\refstepcounter{subequation}\fi
293 \global\@eqnswtrue\global\@eqcnt\z@\cr}
294 % \end{macrocode}
295 % \end{macro}
296 % \end{macro}
297 %
298 % \begin{environment}{subeqnarray*}
299 % This environment is basically the same as the \texttt{eqnarray}
300 % environment, but it is provided just or completeness.
301 % \begin{macrocode}
302 \newenvironment{subeqnarray*}%
303 {\def\@subeqncr{\nonumber\@ssubeqncr}\subeqnarray}
304 {\global\advance\c@equation\m@ne\nonumber\endsubeqnarray}
305 % \end{macrocode}
306 % \end{environment}
307 %
308 % \begin{macro}{\@ssubeqncr}
309 % This is used in the \texttt{esubqnarray*} environment.
310 % \begin{macrocode}
311 \let\@ssubeqncr\@subeqncr
312 %</package>
313 % \end{macrocode}
314 % \end{macro}
315 %
316 % \section{An example of the use of this package}
317 %
318 % When you run the following document through \LaTeX\ you will see
319 % the differene between the \texttt{subeqnarray} and
320 % \texttt{eqnarray} environments.
321 % \begin{macrocode}
322 %<*sample>
323 \documentclass[fleqn]{article}
324 \usepackage{subeqnarray}
325 \begin{document}
326 \title{Sample subeqnarray}
327 \author{Johannes L. Braams}
328 \date{\today}
329 \maketitle
330
331 This document shows an example of the use of the \emph{subeqnarray}
332 environment. Here is one:
333 \begin{subeqnarray}
334 \label{eqw}
335 \slabel{eq0}
336 x & = & a \times b \\
337 \slabel{eq1}
338 & = & z + t\\
339 \slabel{eq2}
340 & = & z + t
341 \end{subeqnarray}
342 The first equation is number~\ref{eq0}, the last is~\ref{eq2}. The
343 equation as a whole can be referred to as equation~\ref{eqw}.
344
345 To show that equation numbers behave normally, here's an
346 \emph{eqnarray} environment.
347 \begin{eqnarray}
348 \label{eq10}
349 x & = & a \times b \\
350 \label{eq11}
351 & = & z + t\\
352 \label{eq12}
353 & = & z + t
354 \end{eqnarray}
355
356 These are equations~\ref{eq10},~\ref{eq11} and~\ref{eq12}.
357 \end{document}
358 %</sample>
359 % \end{macrocode}
360 %
361 % \Finale
362 \endinput
363 %