Debian Codegraph @

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

raw
1 % \iffalse meta-comment
2 %
3 % Copyright (C) 1997-2003 by Michael J. Downes
4 % Copyright (C) 2007-2008 by Morten Hoegholm
5 % Copyright (C) 2007-2014 by Lars Madsen
6 % Copyright (C) 2007-2020 by Will Robertson
7 % Copyright (C) 2010-2017 by Joseph Wright
8 % Copyright (C) 2020-2020 by Ulrike Fischer
9 %
10 % This work may be distributed and/or modified under the
11 % conditions of the LaTeX Project Public License, either
12 % version 1.3 of this license or (at your option) any later
13 % version. The latest version of this license is in
14 % http://www.latex-project.org/lppl.txt
15 % and version 1.3 or later is part of all distributions of
16 % LaTeX version 2005/12/01 or later.
17 %
18 % This work has the LPPL maintenance status "maintained".
19 %
20 % The Current Maintainer of this work is Will Robertson.
21 %
22 % This work consists of the main source file breqn.dtx
23 % and the derived files
24 % breqn.sty, breqn.pdf, breqn.ins.
25 %
26 % Distribution:
27 % CTAN:macros/latex/contrib/mh/breqn.dtx
28 % CTAN:macros/latex/contrib/mh/breqn.pdf
29 %
30 % Unpacking:
31 % tex breqnbundle.ins
32 %
33 % Documentation:
34 % The class ltxdoc loads the configuration file ltxdoc.cfg
35 % if available. Here you can specify further options, e.g.
36 % use A4 as paper format:
37 % \PassOptionsToClass{a4paper}{article}
38 %
39 % Programm calls to get the documentation (example):
40 % pdflatex breqn.dtx
41 % makeindex -s gind.ist breqn.idx
42 % pdflatex breqn.dtx
43 % makeindex -s gind.ist breqn.idx
44 % pdflatex breqn.dtx
45 %
46 % Installation:
47 % TDS:tex/latex/breqn/breqn.sty
48 % TDS:doc/latex/breqn/breqn.pdf
49 % TDS:source/latex/breqn/breqn.dtx
50 %
51 %<*driver>
52 \NeedsTeXFormat{LaTeX2e}
53 \documentclass{ltxdoc}
54 \CodelineIndex
55 \EnableCrossrefs
56 \setcounter{IndexColumns}{2}
57 \usepackage{color,verbatim,xspace,varioref,listings,amsmath,trace}
58
59 \usepackage{geometry}
60
61 \def\partname{Part}
62
63 \definecolor{hilite}{rgb}{0.2,0.4,0.7}
64 \def\theCodelineNo{\textcolor{hilite}{\sffamily\tiny\arabic{CodelineNo}}}
65
66 \lstloadlanguages{[AlLaTeX]TeX}
67
68 \lstnewenvironment{literalcode}
69 {\lstset{gobble=2,columns=fullflexible,basicstyle=\color{hilite}\ttfamily}}
70 {}
71 \makeatletter
72
73 {\catcode`\%=12
74 \long\gdef\@gobble@percent@space#1{\ifx
75 #1%\expandafter\@gobble\else\expandafter#1\fi}}
76
77 \AtBeginDocument{\def\verbatim@processline{\expandafter\check@percent
78 \the\verbatim@line\par}}
79 \newwrite\tmp@out
80 \newcounter{xio}
81 \newenvironment{xio}{% example input and output
82 \par\addvspace\bigskipamount
83 \hbox{\itshape
84 \refstepcounter{xio}\kern-\p@ Example \thexio}\@nobreaktrue
85 \immediate\openout\tmp@out\jobname.tmp \relax
86 \begingroup
87 \let\do\@makeother\dospecials\catcode`\^^M\active
88 \def\verbatim@processline{
89 \immediate\write\tmp@out{\expandafter\@gobble@percent@space
90 \the\verbatim@line}}%
91 \verbatim@start
92 }{%
93 \immediate\closeout\tmp@out
94 \@verbatim\frenchspacing\@vobeyspaces
95 \@@input \jobname.tmp \relax
96 \endgroup
97 \par\medskip
98 \noindent\ignorespaces
99 \@@input \jobname.tmp \relax
100 \par\medskip
101 }
102
103 \providecommand*\pkg[1]{\textsf{#1}}
104 \providecommand*\cls[1]{\textsf{#1}}
105 \providecommand*\opt[1]{\texttt{#1}}
106 \providecommand*\env[1]{\texttt{#1}}
107 \providecommand*\fn[1]{\texttt{#1}}
108
109 \providecommand*\cn[1]{\cs{#1}}
110 \providecommand*\csarg[1]{\texttt{\char`\{#1\char`\}}}
111
112 \providecommand*\tex{\TeX\xspace}
113 \providecommand*\latex{\LaTeX\xspace}
114 \providecommand*\dbldollars{\texttt{\detokenize{$$}}}%$$
115 \providecommand*\arg{}
116 \edef\arg{\expandafter\@gobble\string\#}
117
118 \newenvironment{aside}{\begin{quote}\bfseries}{\end{quote}}
119 \newenvironment{dn}{\begin{quote}\bfseries}{\end{quote}}
120
121 \newcommand\dash{\textemdash}
122 \newcommand\dbslash[1]{\texttt{\string\\}}
123 \newcommand\thepkg{the \pkg{breqn} package\xspace}
124
125 \providecommand*\texbook{\textsl{The \protect\TeX{}book}\xspace}
126
127 \providecommand*\dotsc{\ldots}
128 \providecommand*\eqref[1]{(\ref{#1})}
129
130 \providecommand*\qq[1]{\textquotedblleft#1\textquotedblright}
131 \providecommand*\quoted[1]{\textquoteleft#1\textquoteright}
132 \providecommand*\dquoted[1]{\textquotedblleft#1\textquotedblright}
133
134 \providecommand*\ie{i.e.,\xspace}
135 \providecommand*\eg{e.g.,\xspace}
136 \providecommand*\etc{etc.\xspace}
137 \providecommand*\cf{cf.\xspace}
138
139 \providecommand*\ndash{\unskip\textendash\ignorespaces}
140 \providecommand*\mdash{\unskip\textemdash\ignorespaces}
141
142 \makeatother
143
144 \usepackage{breqn}
145
146 \begin{document}
147 \DocInput{breqn.dtx}
148 \end{document}
149 %</driver>
150 % \fi
151 %
152 %
153 % \title{The \pkg{breqn} package}
154 % \def\fileversion{0.98l}
155 % \def\filedate{2021/10/28}
156 % \date{\pkg{breqn} bundle: \filedate\space\fileversion}
157 % \author{Authors: Michael J. Downes, Morten H\o gholm\\ Maintained by Morten H\o gholm, Will Robertson\\ Feedback: \texttt{https://github.com/wspr/breqn/issues}}
158 %
159 % \maketitle
160 % \begin{abstract}
161 % The \pkg{breqn} package facilitates automatic line-breaking of
162 % displayed math expressions.
163 % \end{abstract}
164 %
165 %
166 % \tableofcontents
167 %
168 %
169 % \part{User's guide}
170 %
171 % \section{A bit of history}
172 %
173 % Originally \pkg{breqn}, \pkg{flexisym}, and \pkg{mathstyle} were
174 % created by Michael J.~Downes from the American Mathematical Society
175 % during the 1990's up to late 2002. Sadly---and much to the shock of
176 % the \TeX\ world---Michael passed away in early 2003 at the age of
177 % only~44.
178 %
179 % The American Mathematical Society kindly allowed Morten H\o gholm to
180 % assume maintainership of this part of his work and we wish to
181 % express our gratitude to them and to Barbara Beeton in particular for
182 % providing the files needed.
183 %
184 % MH brought Michael's work to a wider audience, thereby allowing users to create
185 % more \emph{masterpieces of the publishing art} as we think he would
186 % have wanted.
187 %
188 % Following the July 2008 breqn release, \pkg{breqn} was left in the hands
189 % of a maintenance team, while MH moved on with other projects.
190 %
191 % \section{Package loading}
192 %
193 % The \pkg{breqn} package automatically loads \pkg{amsmath} to avoid loading order conflicts.
194 % It also automatically loads \pkg{flexisym} and \pkg{mathstyle}, but in some cases these
195 % packages need to be loaded separately. The canonical order for package loading is:
196 % \begin{verbatim}
197 % \usepackage{amsmath}
198 % \usepackage{flexisym}
199 % \usepackage{breqn}
200 % \end{verbatim}
201 %
202 % The recommended way of loading the \pkg{breqn} package is to load it
203 % \emph{before} other packages dealing with math symbols, \ie, before
204 % \pkg{amssymb}, or packages such as \pkg{mathpazo} or \pkg{mathptmx}.
205 % However, this can sometimes lead to macro definition clashes, and in such cases
206 % you may need to juggle the loading order to make it work.
207 %
208 % \subsection{Options for \pkg{flexisym}}
209 %
210 % The \pkg{flexisym} package (described in section \vref{flexisym}) is
211 % required by \pkg{breqn} and ensures the math symbols are set up
212 % correctly. By default \pkg{breqn} loads it with support for Computer
213 % Modern but if you use a different math package requiring slightly
214 % different definitions, \pkg{flexisym} must be explicitly loaded before \pkg{breqn} as shown above.
215 % Below is an example of how you enable \pkg{breqn} to work with the widely
216 % used \pkg{mathpazo} package.
217 % \begin{verbatim}
218 %\usepackage{mathpazo}
219 %\usepackage[mathpazo]{flexisym}
220 %\usepackage{breqn}
221 % \end{verbatim}
222 % Currently, the packages \pkg{mathpazo} and \pkg{mathptmx} are
223 % supported. Despair not: Chances are that the package will work using
224 % the default settings. If you find that a particular math font
225 % package doesn't work then please see implementation in
226 % \fn{flexisym.dtx} for how to create a support file---it is easier
227 % than one might think. Contributions welcome.
228 %
229 %
230 % \section{Introduction}
231 %
232 % The \pkg{breqn} package for \LaTeX\ provides solutions to a number of
233 % common difficulties in writing displayed equations and getting
234 % high-quality output. For example, it is a well-known inconvenience that
235 % if an equation must be broken into more than one line, \cs{left} \dots\
236 % \cs{right} constructs cannot span lines. The \pkg{breqn} package makes
237 % them work as one would expect whether or not there is an intervening
238 % line break.
239 %
240 % The single most ambitious goal of the \pkg{breqn} package, however, is
241 % to support automatic linebreaking of displayed equations. Such
242 % linebreaking cannot be done without substantial changes under the hood
243 % in the way math formulas are processed. For this reason, especially in
244 % the alpha release, users should proceed with care and keep an eye out
245 % for unexpected glitches or side effects.
246 %
247 % \section{Principal features}
248 % The principal features of the \pkg{breqn} package are:
249 % \begin{description}
250 %
251 % \item[semantically oriented structure] The way in which compound
252 % displayed formulas are subdivided matches the logical structure more
253 % closely than, say, the standard \env{eqnarray} environment. Separate
254 % equations in a group of equations are written as separate environments
255 % instead of being bounded merely by \dbslash/ commands. Among other
256 % things, this clears up a common problem of wrong math symbol spacing at
257 % the beginning of continuation lines. It also makes it possible to
258 % specify different vertical space values for the space between lines of a
259 % long, broken equation and the space between separate equations in a
260 % group of equations.
261 %
262 % \item[automatic line breaking] Overlong equations will be broken
263 % automatically to the prevailing column width, and continuation lines
264 % will be indented following standard conventions.
265 %
266 % \item[line breaks within delimiters] Line breaks within \cs{left} \dots\
267 % \cs{right} delimiters work in a natural way. Line breaks can be
268 % forbidden below a given depth of delimiter nesting through a package
269 % option.
270 %
271 % \item[mixed math and text] Display equations that contain mixed
272 % math and text, or even text only, are handled naturally by means of a
273 % \env{dseries} environment that starts out in text mode instead of math
274 % mode.
275 %
276 % \item[ending punctuation] The punctuation at the end of a displayed
277 % equation can be handled in a natural way that makes it easier to promote
278 % or demote formulas from\slash to inline math, and to apply special
279 % effects such as adding space before the punctuation.
280 %
281 % \item[flexible numbering] Equation numbering is handled in a natural
282 % way, with all the flexibility of the \pkg{amsmath} package and with no
283 % need for a special \cs{nonumber} command.
284 %
285 % \item[special effects] It is easy to apply special effects to individual
286 % displays, e.g., changing the type size or adding a frame.
287 %
288 % \item[using available space] Horizontal shrink is made use of
289 % whenever feasible. With most other equation macros it is frozen when it
290 % occurs between \cs{left} \dots\ \cs{right} delimiters, or in any sort of
291 % multiline structure, so that some expressions require two lines that would
292 % otherwise fit on one.
293 %
294 % \item[high-quality spacing] The \cs{abovedisplayshortskip} is used when
295 % applicable (other equation macros fail to apply it in equations of more
296 % than one line).
297 %
298 % \item[abbreviations] Unlike the \pkg{amsmath} equation environments, the
299 % \pkg{breqn} environments can be called through user-defined abbreviations
300 % such as \cs{beq} \dots\ \cs{eeq}.
301 %
302 % \end{description}
303 %
304 % \section{Shortcomings of the package}
305 % The principal known deficiencies of the \pkg{breqn} package are:
306 %
307 % \subsection{Incompatibilities} As it pushes the envelope
308 % of what is possible within the context of \LaTeXe, \thepkg will tend
309 % to break other packages when used in combination with them, or to fail
310 % itself, when there are any areas of internal overlap; successful use may
311 % in some cases depend on package loading order.
312 %
313 %
314 %
315 % \subsection{Indention of delimited fragments} When line breaks within
316 % delimiters are involved, the automatic indention of continuation lines
317 % is likely to be unsatisfactory and need manual adjustment. I don't see
318 % any easy way to provide a general solution for this, though I have some
319 % ideas on how to attain partial improvements.
320 %
321 % \subsection{Math symbol subversion}
322 % In order for automatic line breaking to work, the operation of all the
323 % math symbols of class 2, 3, 4, and 5 must be altered (relations, binary
324 % operators, opening delimiters, closing delimiters). This is done by an
325 % auxiliary package \pkg{flexisym}. As long as you stick to the advertised
326 % \LaTeX\ interface for defining math symbols (\cs{DeclareMathSymbol}),
327 % things should work OK most of the time. Any more complex math symbol
328 % setup is quite likely to quarrel with the \pkg{flexisym} package.
329 % See Section~\vref{flexisym} for further information.
330 %
331 % \subsection{Subscripts and superscripts}
332 %
333 % Because of the changes to math symbols of class 2--5, writing certain
334 % combinations such as \verb'^+' or \verb'_\pm' or \verb'^\geq' without
335 % braces would lead to error messages; (The problem described here
336 % already exists in standard \LaTeX\ to a lesser extent, as you may know
337 % if you ever tried \verb'^\neq' or \verb'^\cong'; and indeed there are
338 % no examples in the \LaTeX\ book to indicate any sanction for omitting
339 % braces around a subscript or superscript.)
340 %
341 % The \pkg{flexisym} package therefore calls, as of version 0.92, another
342 % package called \pkg{mathstyle} which turns \verb'^' and \verb'_' into
343 % active characters. This is something that I believe is desirable in any
344 % case, in the long run, because having a proper mathstyle variable
345 % eliminates some enormous burdens that affect almost any
346 % nontrivial math macros, as well as many other things where the
347 % connection is not immediately obvious, e.g., the \LaTeX\ facilities for
348 % loading fonts on demand.
349 %
350 % Not that this doesn't introduce new and interesting problems of its
351 % own---for example, you don't want to put usepackage statements
352 % after flexisym for any package that refers to, e.g., \verb'^^J' or
353 % \verb'^^M'
354 % internally (too bad that the \LaTeX\ package loading code does not
355 % include automatic defenses to ensure normal catcodes in the interior of
356 % a package; but it only handles the \verb'@' character).
357 %
358 % But I took a random AMS journal article, with normal end-user kind of
359 % \LaTeX\ writing, did some straightforward substitutions to change all
360 % the equations into dmath environments, and ran it with active math
361 % sub/sup: everything worked OK. This suggests to me that it can work in
362 % the real world, without an impossible amount of compatibility work.
363 %
364 % \section{Incomplete}
365 % In addition, in the \textbf{alpha release [1997/10/30]} the following
366 % gaps remain to be filled in:
367 % \begin{description}
368 % \item[documentation]
369 % The documentation could use amplification, especially more
370 % illustrations, and I have undoubtedly overlooked more than a few errors.
371 %
372 % \item[group alignment] The algorithm for doing alignment
373 % of mathrel symbols across equations in a \env{dgroup} environment
374 % needs work. Currently the standard and \opt{noalign} alternatives
375 % produce the same output.
376 %
377 % \item[single group number] When a \env{dgroup} has a group number and
378 % the individual equations are unnumbered, the handling and placement of
379 % the group number aren't right.
380 %
381 % \item[group frame] Framing a group doesn't work, you might be able to
382 % get frames on the individual equations at best.
383 %
384 % \item[group brace] The \opt{brace} option for \env{dgroup} is intended
385 % to produce a large brace encompassing the whole group. This hasn't been
386 % implemented yet.
387 %
388 % \item[darray environment] The \env{darray} environment is unfinished.
389 %
390 % \item[dseries environment] The syntax and usage for the \env{dseries}
391 % environment are in doubt and may change.
392 %
393 % \item[failure arrangements] When none of the line-breaking passes for a
394 % \env{dmath} environment succeeds\dash i.e., at least one line is
395 % overfull\dash the final arrangement is usually rather poor. A better
396 % fall-back arrangement in the failure case is needed.
397 %
398 % \end{description}
399 %
400 % \section{Package options}
401 %
402 % Many of the package options for \thepkg are the same as options of the
403 % \env{dmath} or \env{dgroup} environments, and some of them require an
404 % argument, which is something that cannot be done through the normal
405 % package option mechanism. Therefore most of the \pkg{breqn} package
406 % options are designed to be set with the \cs{breqnsetup} command after the
407 % package is loaded. For example, to load the package and set the
408 % maximum delimiter nesting depth for line breaks to~1:
409 % \begin{verbatim}
410 % \usepackage{breqn}
411 % \breqnsetup{breakdepth={1}}
412 % \end{verbatim}
413 %
414 % See the discussion of environment options, Section~\vref{envopts}, for
415 % more information.
416 %
417 % Debugging information is no longer available as a package
418 % option. Instead, the tracing information has been added in a fashion
419 % so that it can be enabled as a docstrip option:
420 % \begin{verbatim}
421 % \generate{\file{breqn.sty}{\from{breqn.dtx}{package,trace}}}
422 % \end{verbatim}
423 %
424 %
425 % \section{Environments and commands}
426 % \subsection{Environments}
427 % All of the following environments take an optional argument for
428 % applying local effects such as changing the typesize or adding a
429 % frame to an individual equation.
430 %
431 % \begin{description}
432 % \item[\env{dmath}] Like \env{equation} but supports line breaking and variant
433 % numbers.
434 %
435 % \item[\env{dmath*}] Unnumbered; like \env{displaymath} but supports line
436 % breaking
437 %
438 % \item[\env{dseries}] Like \env{equation} but starts out in text mode;
439 % intended for series of mathematical expressions of the form `A, B, and
440 % C'. As a special feature, if you use
441 % \begin{verbatim}
442 % \begin{math} ... \end{math}
443 % \end{verbatim}
444 % for each expression in the series, a suitable amount of inter-expression
445 % space will be automatically added. This is a small step in the direction of
446 % facilitating conversion of display math to inline math, and vice versa: If
447 % you write a display as
448 % \begin{verbatim}
449 % \begin{dseries}
450 % \begin{math}A\end{math},
451 % \begin{math}B\end{math},
452 % and
453 % \begin{math}C\end{math}.
454 % \end{dseries}
455 % \end{verbatim}
456 % then conversion to inline form is simply a matter of removing the
457 % \verb'\begin{dseries}' and \verb'\end{dseries}' lines; the contents of the
458 % display need no alterations.
459 %
460 % It would be nice to provide the same feature for \verb'$' notation but
461 % there is no easy way to do that because the \verb'$' function has no
462 % entry point to allow changing what happens before math mode is entered.
463 % Making it work would therefore require turning \verb'$' into an active
464 % character, something that I hesitate to do in a \LaTeXe\ context.
465 %
466 % \item[\env{dseries*}] Unnumbered variant of \env{dseries}
467 %
468 % \item[\env{dgroup}] Like the \env{align} environment of \pkg{amsmath},
469 % but with each constituent equation wrapped in a \env{dmath},
470 % \env{dmath*}, \env{dseries}, or \env{dseries*} environment instead of being
471 % separated by \dbslash/. The equations are numbered with a group number.
472 % When the constituent environments are the numbered forms (\env{dmath} or
473 % \env{dseries}) they automatically switch to `subequations'-style
474 % numbering, i.e., something like (3a), (3b), (3c), \dots, depending on
475 % the current form of non-grouped equation numbers. See also
476 % \env{dgroup*}.
477 %
478 % \item[\env{dgroup*}] Unnumbered variant of \env{dgroup}. If the
479 % constituent environments are the numbered forms, they get normal
480 % individual equation numbers, i.e., something like (3), (4), (5), \dots~.
481 %
482 % \item[\env{darray}] Similar to \env{eqnarray} but with an argument like
483 % \env{array} for giving column specs. Automatic line breaking is not
484 % done here.
485 %
486 % \item[\env{darray*}] Unnumbered variant of \env{darray}, rather like
487 % \env{array} except in using \cs{displaystyle} for all column
488 % entries.
489 %
490 % \item[\env{dsuspend}] Suspend the current display in order to print
491 % some text, without loss of the alignment. There is also a command
492 % form of the same thing, \cs{intertext}.
493 % \end{description}
494 %
495 % \subsection{Commands}
496 %
497 % The commands provided by \thepkg are:
498 % \begin{description}
499 % \item[\cs{condition}] This command is used for
500 % a part of a display which functions as a condition on the main
501 % assertion. For example:
502 % \begin{verbatim}
503 % \begin{dmath}
504 % f(x)=\frac{1}{x} \condition{for $x\neq 0$}
505 % \end{dmath}.
506 % \end{verbatim}
507 % \begin{dmath}
508 % f(x)=\frac{1}{x} \condition{for $x\neq 0$}
509 % \end{dmath}.
510 % The \cs{condition} command automatically switches to text mode (so that
511 % interword spaces function the way they should), puts in a comma, and
512 % adds an appropriate amount of space. To facilitate promotion\slash
513 % demotion of formulas, \cs{condition} \qq{does the right thing} if used
514 % outside of display math.
515 %
516 % To substitute a different punctuation mark instead of the default comma,
517 % supply it as an optional argument for the \cs{condition} command:
518 % \begin{verbatim}
519 % \condition[;]{...}
520 % \end{verbatim}
521 % (Thus, to get no punctuation: \verb'\condition[]{...}'.)
522 %
523 % For conditions that contain no text, you can use the starred form of the
524 % command, which means to stay in math mode:
525 % \begin{verbatim}
526 % \begin{dmath}
527 % f(x)=\frac{1}{x} \condition*{x\neq 0}
528 % \end{dmath}.
529 %
530 % If your material contains a lot of conditions like these, you might like
531 % to define shorter abbreviations, e.g.,
532 % \begin{verbatim}
533 % \newcommand{\mc}{\condition*}% math condition
534 % \newcommand{\tc}{\condition}% text condition
535 % \end{verbatim}
536 % But \thepkg refrains from predefining such abbreviations in order that
537 % they may be left to the individual author's taste.
538 %
539 % \item[\cs{hiderel}] In a compound equation it is sometimes desired to
540 % use a later relation symbol as the alignment point, rather than the
541 % first one. To do this, mark all the relation symbols up to the desired
542 % one with \cs{hiderel}:
543 % \begin{verbatim}
544 % T(n) \hiderel{\leq} T(2^n) \leq c(3^n - 2^n) ...
545 % \end{verbatim}
546 % \end{description}
547 %
548 % \section{Various environment options}\label{envopts}
549 %
550 % The following options are recognized for the \env{dmath}, \env{dgroup},
551 % \env{darray}, and \env{dseries} environments; some of the options do not
552 % make sense for all of the environments, but if an option is used where
553 % not applicable it is silently ignored rather than treated as an error.
554 % \changes{v0.98b}{2010/08/27}{replaced relindent with indentstep}
555 %
556 % \begin{verbatim}
557 % \begin{dmath}[style={\small}]
558 % \begin{dmath}[number={BV}]
559 % \begin{dmath}[labelprefix={eq:}]
560 % \begin{dmath}[label={xyz}]
561 % \begin{dmath}[indentstep={2em}]
562 % \begin{dmath}[compact]
563 % \begin{dmath}[spread={1pt}]
564 % \begin{dmath}[frame]
565 % \begin{dmath}[frame={1pt},framesep={2pt}]
566 % \begin{dmath}[breakdepth={0}]
567 % \end{verbatim}
568 %
569 % Use the \opt{style} option to change the type size of an individual
570 % equation. This option can also serve as a catch-all option for
571 % altering the equation style in other ways; the contents are simply
572 % executed directly within the context of the equation.
573 %
574 % Use the \opt{number} option if you want the number for a particular
575 % equation to fall outside of the usual sequence. If this option is used
576 % the equation counter is not incremented. If for some reason you need to
577 % increment the counter and change the number at the same time, use the
578 % \opt{style} option in addition to the \opt{number} option:
579 % \begin{verbatim}
580 % style={\refstepcounter{equation}}
581 % \end{verbatim}
582 %
583 % Use of the normal \cs{label} command instead of the \opt{label} option
584 % works, I think, most of the time (untested). \opt{labelprefix} prepends
585 % its argument to the label (only useful as a global option, really),
586 % and must be called before \opt{label}.
587 %
588 % \changes{v0.98b}{2010/08/27}{replaced relindent with indentstep}
589 % Use the \opt{indentstep} option to specify something other than the
590 % default amount for the indention of relation symbols. The default is
591 % 8pt.
592 %
593 % Use the \opt{compact} option in compound equations to inhibit line
594 % breaks at relation symbols. By default a line break will be taken before
595 % each relation symbol except the first one. With the \opt{compact} option
596 % \LaTeX\ will try to fit as much material as possible on each line, but
597 % breaks at relation symbols will still be preferred over breaks at binary
598 % operator symbols.
599 %
600 % Use the \opt{spread} option to increase (or decrease) the amount of
601 % interline space in an equation. See the example given above.
602 %
603 % Use the \opt{frame} option to produce a frame around the body of the
604 % equation. The thickness of the frame can optionally be specified by
605 % giving it as an argument of the option. The default thickness is
606 % \cs{fboxrule}.
607 %
608 % Use the \opt{framesep} option to change the amount of space separating
609 % the frame from what it encloses. The default space is \cs{fboxsep}.
610 %
611 % Use the \opt{breakdepth} option to change the level of delimiter nesting
612 % to which line breaks are allowed. To prohibit line breaks within
613 % delimiters, set this to 0:
614 % \begin{verbatim}
615 % \begin{dmath}[breakdepth={0}]
616 % \end{verbatim}
617 % The default value for breakdepth is 2. Even when breaks are allowed
618 % inside delimiters, they are marked as less desirable than breaks outside
619 % delimiters. Most of the time a break will not be taken within delimiters
620 % until the alternatives have been exhausted.
621 %
622 % Options for the \env{dgroup} environment: all of the above, and also
623 % \begin{verbatim}
624 % \begin{dgroup}[noalign]
625 % \begin{dgroup}[brace]
626 % \end{verbatim}
627 %
628 % By default the equations in a \env{dgroup} are mutually aligned on their
629 % relation symbols ($=$, $<$, $\geq$, and the like). With the
630 % \opt{noalign} option each equation is placed individually without
631 % reference to the others.
632 %
633 % The \opt{brace} option means to place a large brace encompassing the
634 % whole group on the same side as the equation number.
635 %
636 % Options for the \env{darray} environment: all of the above (where
637 % sensible), and also
638 % \begin{verbatim}
639 % \begin{darray}[cols={lcr@{\hspace{2em}}lcr}]
640 % \end{verbatim}
641 % The value of the \opt{cols} option for the darray environment should be
642 % a series of column specs as for the \env{array} environment, with the
643 % following differences:
644 % \begin{itemize}
645 % \item For l, c, and r what you get is not text, but math, and
646 % displaystyle math at that. To get text you must use a 'p' column
647 % specifier, or put an \cs{mbox} in each of the individual cells.
648 %
649 % \item Vertical rules don't connect across lines.
650 % \end{itemize}
651 %
652 % \section{The \pkg{flexisym} package}\label{flexisym}
653 %
654 % The \pkg{flexisym} package does some radical changes in the setup for
655 % math symbols to allow their definitions to change dynamically throughout
656 % a document. The \pkg{breqn} package uses this to make symbols of classes
657 % 2, 3, 4, 5 run special functions inside an environment such as
658 % \env{dmath} that provide the necessary support for automatic line
659 % breaking.
660 %
661 % The method used to effect these changes is to change the definitions of
662 % \cs{DeclareMathSymbol} and \cs{DeclareMathDelimiter}, and then
663 % re-execute the standard set of \LaTeX\ math symbol definitions.
664 % Consequently, additional mathrel and mathbin symbols defined by other
665 % packages will get proper line-breaking behavior if the other package is
666 % loaded after the \pkg{flexisym} package and the symbols are defined
667 % through the standard interface.
668 %
669 %
670 %
671 % \section{Caution! Warning!}
672 % Things to keep in mind when writing documents with \thepkg:
673 % \begin{itemize}
674 %
675 % \item The notation $:=$ must be written with the command \cs{coloneq}.
676 % Otherwise the $:$ and the $=$ will be treated as two separate relation
677 % symbols with an \qq{empty RHS} between them, and they will be printed
678 % on separate lines.
679 %
680 % \item Watch out for constructions like \verb'^+' where a single binary
681 % operator or binary relation symbol is subscripted or superscripted. When
682 % the \pkg{breqn} or \pkg{flexisym} package is used, braces are mandatory
683 % in such constructions: \verb'^{+}'. This applies for both display and
684 % in-line math.
685 %
686 % \item If you want \LaTeX\ to make intelligent decisions about line
687 % breaks when vert bars are involved, use proper pairing versions of the
688 % vert-bar symbols according to context: \verb'\lvert n\rvert' instead of
689 % \verb'|n|'. With the nondirectional \verb'|' there is no way for \LaTeX\
690 % to reliably deduce which potential breakpoints are inside delimiters
691 % (more highly discouraged) and which are not.
692 %
693 % \item If you use the \pkg{german} package or some other package that
694 % turns double quote \verb'"' into a special character, you may encounter
695 % some problems with named math symbols of type mathbin, mathrel,
696 % mathopen, or mathclose in moving arguments. For example, \cs{leq} in a
697 % section title will be written to the \fn{.aux} file as something like
698 % \verb'\mathchar "3214'. This situation probably ought to be improved,
699 % but for now use \cs{protect}.
700 %
701 % \item Watch out for the \texttt{[} character at the beginning of a
702 % \env{dmath} or similar environment, if it is supposed to be interpreted
703 % as mathematical content rather than the start of the environment's
704 % optional argument.
705 %
706 % This is OK:
707 % \begin{verbatim}
708 % \begin{dmath}
709 % [\lambda,1]...
710 % \end{dmath}
711 % \end{verbatim}
712 % This will not work as expected:
713 % \begin{verbatim}
714 % \begin{dmath}[\lambda,1]...\end{dmath}
715 % \end{verbatim}
716 %
717 % \item Watch out for unpaired delimiter symbols (in display math only):
718 % \begin{verbatim}
719 % ( ) [ ] \langle \rangle \{ \} \lvert \rvert ...
720 % \end{verbatim}
721 % If an open delimiter is used without a close delimiter, or vice versa,
722 % it is normally harmless but may adversely affect line breaking. This is only
723 % for symbols that have a natural left or right directionality. Unpaired
724 % \cs{vert} and so on are fine.
725 %
726 % When a null delimiter is used as the other member of the pair
727 % (\verb'\left.' or \verb'\right.') this warning doesn't apply.
728 %
729 % \item If you inadvertently apply \cs{left} or \cs{right} to something
730 % that is not a delimiter, the error messages are likely to be a bit
731 % more confusing than usual. The normal \LaTeX\ response to an error such
732 % as
733 % \begin{verbatim}
734 % \left +
735 % \end{verbatim}
736 % is an immediate message
737 % \begin{verbatim}
738 % ! Missing delimiter (. inserted).
739 % \end{verbatim}
740 % When \thepkg is in use, \LaTeX\ will fail to realize anything is wrong
741 % until it hits the end of the math formula, or a closing delimiter
742 % without a matching opening delimiter, and then the first message is an
743 % apparently pointless
744 % \begin{verbatim}
745 % ! Missing \endgroup inserted.
746 % \end{verbatim}
747 %
748 % \end{itemize}
749 %
750 % \section{Examples}
751 %
752 % \renewcommand\theequation{\thesection.\arabic{equation}}
753 % % Knuth, SNA p74
754 % \begin{xio}
755 % Replace $j$ by $h-j$ and by $k-j$ in these sums to get [cf.~(26)]
756 % \begin{dmath}[label={sna74}]
757 % \frac{1}{6} \left(\sigma(k,h,0) +\frac{3(h-1)}{h}\right)
758 % +\frac{1}{6} \left(\sigma(h,k,0) +\frac{3(k-1)}{k}\right)
759 % =\frac{1}{6} \left(\frac{h}{k} +\frac{k}{h} +\frac{1}{hk}\right)
760 % +\frac{1}{2} -\frac{1}{2h} -\frac{1}{2k},
761 % \end{dmath}
762 % which is equivalent to the desired result.
763 % \end{xio}
764 %
765 % % Knuth, SNA 4.6.2, p387
766 % \begin{xio}
767 % \newcommand\mx[1]{\begin{math}#1\end{math}}% math expression
768 % %
769 % Now every column which has no circled entry is completely zero;
770 % so when $k=6$ and $k=7$ the algorithm outputs two more vectors,
771 % namely
772 % \begin{dseries}[frame]
773 % \mx{v^{[2]} =(0,5,5,0,9,5,1,0)},
774 % \mx{v^{[3]} =(0,9,11,9,10,12,0,1)}.
775 % \end{dseries}
776 % From the form of the matrix $A$ after $k=5$, it is evident that
777 % these vectors satisfy the equation $vA =(0,\dotsc,0)$.
778 % \end{xio}
779 %
780 % \begin{xio}
781 % \begin{dmath*}
782 % T(n) \hiderel{\leq} T(2^{\lceil\lg n\rceil})
783 % \leq c(3^{\lceil\lg n\rceil}
784 % -2^{\lceil\lg n\rceil})
785 % <3c\cdot3^{\lg n}
786 % =3c\,n^{\lg3}
787 % \end{dmath*}.
788 % \end{xio}
789 %
790 % \begin{xio}
791 % The reduced minimal Gr\"obner basis for $I^q_3$ consists of
792 % \begin{dgroup*}
793 % \begin{dmath*}
794 % H_1^3 = x_1 + x_2 + x_3
795 % \end{dmath*},
796 % \begin{dmath*}
797 % H_2^2 = x_1^2 + x_1 x_2 + x_2^2 - q_1 - q_2
798 % \end{dmath*},
799 % \begin{dsuspend}
800 % and
801 % \end{dsuspend}
802 % \begin{dmath*}
803 % H_3^1 = x_1^3 - 2x_1 q_1 - x_2 q_1
804 % \end{dmath*}.
805 % \end{dgroup*}
806 % \end{xio}
807 %
808 %
809 %
810 %\section{Technical notes on tag placement}
811 %
812 %The method used by the breqn package to place the equation number is
813 %rather more complicated than you might think, and the whole reason is
814 %to allow the number to stay properly centered on the total height even
815 %when the height fluctuates due to stretching or shrinking of the page.
816 %
817 %
818 %Consider the following equation:
819 %\begin{dmath}[number={3.15}]
820 % N_{0} \simeq \left( \frac{\nu}{\lVert u\rVert_{H^{i}}} \right)
821 % \lvert I\rvert^{-1/2}
822 %\end{dmath}
823 %It will have only one line, if the column width is not too narrow.
824 %
825 %Scrutinizing the vertical list will shed light on some of the basic properties
826 %shared by all breqn equations. After that we will look at what would happen if
827 %two or more lines were needed. The numbers added on the left in the following
828 %\cs{showlists} output mark the points of interest.
829 %\begin{verbatim}
830 %[1] \penalty 10000
831 % \glue(\abovedisplayskip) 0.0
832 % \penalty 10000
833 % \glue(\belowdisplayskip) 0.0
834 %[2] \glue 4.0 plus 4.0
835 % \glue(\lineskip) 1.0
836 %[3] \vbox(16.53902+0.0)x0.0, glue set 16.53902fil
837 % .\glue 0.0 plus 1.0fil minus 1.0fil
838 % \penalty 10000
839 %[4] \glue -8.51945
840 %[5] \hbox(7.5+2.5)x25.55563
841 % .\OT1/cmr/m/n/10 (
842 % .\OT1/cmr/m/n/10 3
843 % .\OT1/cmr/m/n/10 .
844 % .\OT1/cmr/m/n/10 1
845 % .\OT1/cmr/m/n/10 5
846 % .\kern 0.0
847 % .\OT1/cmr/m/n/10 )
848 % \penalty 10000
849 %[6] \glue(\parskip) -18.01956
850 %[7] \hbox(16.53902+9.50012)x360.0, glue set 1.78647
851 %\end{verbatim}
852 %\begin{enumerate}
853 %\item These four lines are a hidden display structure from \TeX's
854 % primitive \texttt{\$\$} mechanism. It is used only to get the value
855 % of \cs{predisplaysize} so that we can later calculate by hand
856 % whether to use the short display skips or the regular ones. (The
857 % reason that we have to do it by hand traces back to the fact that
858 % \TeX\ 3.x does not allow unhboxing in math mode.) The penalties come
859 % from \cs{predisplaypenalty} and \cs{postdisplaypenalty}, which were
860 % locally set to 10000 to ensure there would be no unintended page
861 % breaks at these glue nodes.
862 %
863 %\item These two glue nodes are the ones that would normally have been
864 % produced at the top of a display; the first one is the above-display
865 % skip node (though we had to put it in by hand with \cs{vskip}) and
866 % the second one is the usual baselineskip/lineskip node.
867 %
868 %\item This is a dummy copy of the equation's first line, which is
869 % thrown in here to get the proper value of baselineskip (or lineskip
870 % in this case). Why do we need this? Because this ensures that we get
871 % the top spacing right before we fiddle with the glue nodes
872 % surrounding the equation number. And if the equation has a frame,
873 % this box is a good place to add it from.
874 %
875 %\item This is a special glue node that brings us to the right vertical
876 % position for adding the equation number. Its value is calculated
877 % from the variables that you would expect, given the presence of the
878 % dummy first line above the num- ber: starting position of the
879 % equation, height of first line, total height of equation body. If
880 % the equation body had more than one line, with stretchable glue
881 % between the lines, half of the stretch would be added in this glue
882 % node.
883 %
884 %\item The hbox containing the equation number.
885 %
886 %\item Backspace to bring the equation body to the right starting point. We use
887 % \cs{parskip} to put this glue in place because we're going to get a
888 % parskip node here in any case when we add the equation body with (in
889 % essence). If we didn't do this we'd get two glue nodes instead of
890 % one, to no purpose.
891 %
892 %\cs{\noindent} \cs{unhbox}\cs{EQ@box}.
893 %
894 %
895 %\item And lastly we see here the first line of the equation body,
896 % which appears to have height 16.5pt and depth 9.5pt.
897 %\end{enumerate}
898 %
899 %For comparison, the vertical list produced from the above equation in
900 %standard \LaTeX\ would look like this, if the same values of
901 %columnwidth and abovedisplayskip are used:
902 %\begin{verbatim}
903 %[1] \penalty 10000
904 %[2] \glue(\abovedisplayskip) 4.0 plus 4.0
905 % \glue(\lineskip) 1.0
906 % \hbox(16.53902+9.50012)x232.94844
907 %[3] .\hbox(7.5+2.5)x25.55563
908 % ..\hbox(7.5+2.5)x25.55563
909 % ...\OT1/cmr/m/n/10 (
910 % ...\OT1/cmr/m/n/10 3
911 % ...\OT1/cmr/m/n/10 .
912 % ...\OT1/cmr/m/n/10 1
913 % ...\OT1/cmr/m/n/10 5
914 % ...\kern 0.0
915 % ...\OT1/cmr/m/n/10 )
916 % .\kern101.49591
917 %[4] .\hbox(16.53902+9.50012)x105.8969
918 % ...
919 %[5] \penalty 0
920 %[6] \glue(\belowdisplayskip) 4.0 plus 4.0
921 % \glue(\lineskip) 1.0
922 % \hbox(6.94444+1.94444)x345.0, glue set 62.1106fil
923 %\end{verbatim}
924 %
925 %\begin{enumerate}
926 % \item \cs{predisplaypenalty}
927 % \item \cs{abovedisplayskip}
928 % \item equation number box
929 % \item equation body
930 % \item \cs{postdisplaypenaltly}
931 % \item \cs{belowdisplayskip}
932 %\end{enumerate}
933 %
934 %
935 % \section{Technical notes on Equation Layouts}
936 % \textbf{MJD [1998/12/28]}
937 %
938 % \providecommand{\qq}[1]{\textquotedblleft#1\textquotedblright}
939 % \providecommand{\mdash}{\textemdash}
940 % \providecommand{\ndash}{\textendash}
941 %
942 % \newcommand{\ititle}[1]{\textit{#1}}
943 %
944 % \newcommand{\LR}[2][.4]{%
945 % \framebox[#1\displaywidth]{$\displaystyle{}#2$}%
946 % }
947 %
948 % \newcommand{\LHS}[1]{\LR[\relifactor]{#1}}
949 %
950 % \newdimen\relindent \newdimen\rhswd
951 %
952 % \newcommand{\dwline}{%
953 % \hbox to\curdw{\vrule height1ex
954 % \leaders\hrule height.55ex depth-.45ex\hfil
955 % \tiny \space display width
956 % \leaders\hrule height.55ex depth-.45ex\hfil
957 % \vrule height1ex}%
958 % }
959 %
960 % \newenvironment{layout}[1][.15]{%
961 % \noindent
962 % $$\edef\curdw{\the\displaywidth}%
963 % \def\relifactor{#1}%
964 % \gdef\layoutcr{\cr}\def\\{\layoutcr}%
965 % \binoppenalty 10000 \relpenalty 10000
966 % \setbox8\vbox\bgroup
967 % \advance\baselineskip .35\baselineskip
968 % \advance\lineskip .35\baselineskip \lineskiplimit\lineskip
969 % \relindent=#1\displaywidth
970 % \rhswd=\displaywidth \advance\rhswd-\relindent
971 % \global\row 0 \gdef\rhsskew{}%
972 % \halign\bgroup \global\advance\row 1 $\hfil\displaystyle{}##$&%
973 % \ifnum\row>1 \rhsskew \fi $\displaystyle{}##\hfil$\cr
974 % }{%
975 % \crcr\egroup\egroup
976 % \vcenter{\halign{\hfil##\hfil\cr
977 % \hbox{\hss\dwline\hss}\cr\noalign{\vskip.6\baselineskip}\box8 \cr}}%
978 % $$\relax
979 % \ignorespacesafterend
980 % }
981 %
982 % \newcommand{\stagger}{\omit\span\gdef\layoutcr{\cr\omit\span}}
983 %
984 % \newcount\row
985 %
986 % \newcommand{\rhsskew}{}
987 % \newcommand{\skewleft}[1]{\gdef\rhsskew{\kern-#1\relax}}
988 %
989 %
990 % \subsection{Misc examples}
991 %
992 % Let us consider which of these have 50\% or more of wasted whitespace
993 % \emph{within the bounding box of the visible material}.
994 % \begin{layout}[.4]
995 % \LHS{L}&=\LR[.35]{R_{1}}\\
996 % &=\LR[.25]{R_{1}}
997 % \end{layout}
998 %
999 % \subsection{Ladder and step layouts}
1000 %
1001 % \subsubsection{Straight ladder layout}
1002 % This is distinguished by a relatively short LHS and one or more RHS's of
1003 % any length.
1004 % \begin{layout}
1005 % \LHS{L} &= \LR[.5]{R_{1}}\\
1006 % &=\LR[.3]{R_{2}}\\
1007 % &=\LR[.25]{R_{3}}\\
1008 % &\qquad\ldots
1009 % \end{layout}
1010 % The simplest kind of equation that fits on one line and has only one RHS
1011 % may be viewed as a trivial subcase of the straight ladder layout:
1012 % \begin{layout}
1013 % \LHS{L} &= \LR[.5]{R}
1014 % \end{layout}
1015 % If some of the RHS's are too wide to fit on a single line they may be
1016 % broken at binary operator symbols such as plus or minus. This is still
1017 % classified as a straight ladder layout if none of the fragments intrude
1018 % into the LHS column, because the underlying parshape is the same.
1019 % \begin{layout}
1020 % \LHS{L} &= \LR[.4]{R_{1a}}\\
1021 % &\quad +\LR[.6]{R_{1b}}\\
1022 % &=\LR[.3]{R_{2}}\\
1023 % &=\LR[.25]{R_{3a}}\\
1024 % &\quad +\LR[.45]{R_{3b}}\\
1025 % &\quad +\LR[.54]{R_{3c}}\\
1026 % &\qquad\ldots
1027 % \end{layout}
1028 %
1029 % \subsubsection{Skew ladder layout}
1030 % \begin{layout}[.5]
1031 % \skewleft{.35\displaywidth}
1032 % \LHS{L}&= \LR[.3]{R_{1}}\\
1033 % &=\LR[.6]{R_{2}}\\
1034 % &=\LR[.25]{R_{3}}\\
1035 % &\qquad\ldots
1036 % \end{layout}
1037 % In a skew ladder layout, the combined LHS width plus width of $R_{1}$
1038 % does not exceed the available width, but one of the other RHS's is so
1039 % wide that aligning its relation symbol with the others cannot be done
1040 % without making it run over the right margin: $\mbox{width}(L) +
1041 % \mbox{width}_{\mathrm{max}}(R_{i})>\mbox{width}_{\mathrm{avail}}$. In
1042 % that case we next try aligning all but the first relation symbol,
1043 % allowing all the $R_{i}$ after $R_1$ to shift leftward.
1044 %
1045 % \subsubsection{Drop ladder layout}
1046 % \begin{layout}[.6]
1047 % \makebox[.15\displaywidth][l]{\LHS{L}}\\
1048 % &= \LR[.6]{R_{1}}\\
1049 % &=\LR[.3]{R_{2}}\\
1050 % &=\LR[.25]{R_{3}}\\
1051 % &\qquad\ldots
1052 % \end{layout}
1053 % The drop ladder layout is similar to the skew ladder layout but with the
1054 % width of $R_1$ too large for it to fit on the same line as the LHS. Then
1055 % we move $R_1$ down to a separate line and try again to align all the
1056 % relation symbols. Note that this layout consumes more vertical space
1057 % than the skew ladder layout.
1058 %
1059 % \subsubsection{Step layout}
1060 % \begin{layout}[.6]
1061 % \stagger
1062 % \LHS{R_{a}}\\
1063 % \qquad + \LR[.7]{R_{b}}\\
1064 % \qquad\qquad + \LR[.6]{R_{c}}\\
1065 % \qquad\qquad\qquad + \LR[.45]{R_{d}}\\
1066 % \qquad\qquad\qquad\qquad\ldots
1067 % \end{layout}
1068 % The chief characteristic of the step layout is that there is no relation
1069 % symbol, so that the available line breaks are (usually) all at binary
1070 % operator symbols. Let $w_1$ and $w_l$ be the widths of the first and
1071 % last fragments. We postulate that the ideal presentation is as follows:
1072 % Choose a small stairstep indent $I$ (let's say 1 or 2 em). We want the
1073 % last fragment to be offset at least $I$ from the start of the first
1074 % fragment, and to end at least $I$ past the end of the first fragment. If
1075 % there are only two lines these requirements determine a target width
1076 % $w_T=\max(w_1+I,w_l+I)$. If there are more than two lines ($l>2$) then
1077 % use $w_T = \max(w_1 + (l-1)I, w_l+I, w_{\mathrm{avail}}$ and reset $I$
1078 % to $w_T/(l-1)$ if $w_T = w_{\mathrm{avail}}$.
1079 %
1080 % Furthermore, we would like the material to be distributed as evenly as
1081 % possible over all the lines rather than leave the last line exceedingly
1082 % short. If the total width is $1.1(\mbox{width}_{\mathrm{avail}})$, we
1083 % don't want to have .9 of that on line 1 and .2 of it on line 2:
1084 % \begin{layout}[.9]
1085 % \stagger
1086 % \LHS{R_{a}\hfil+\hfil R_{b}\hfil+\hfil R_{c}}\\
1087 % \qquad + \LR[.1]{R_{d}}
1088 % \end{layout}
1089 % Better to split it as evenly as possible, if the available breakpoints
1090 % permit.
1091 % \begin{layout}[.5]
1092 % \stagger
1093 % \LHS{R_{a}\hfil+\hfil R_{b}}\\
1094 % \qquad + \LR[.5]{R_{c}\hfil+\hfil R_d}
1095 % \end{layout}
1096 % A degenerate step layout may arise if an unbreakable fragment of
1097 % the equation is so wide that indenting it to its appointed starting
1098 % point would cause it to run over the right margin. In that case, we want
1099 % to shift the fragment leftward just enough to bring it within the right
1100 % margin:
1101 % \begin{layout}[.6]
1102 % \stagger
1103 % \LHS{L_{a}}\\
1104 % \quad + \LR[.8]{L_{b}}\\
1105 % \qquad + \LR[.7]{L_{c}}\\
1106 % \; + \LR[.87]{L_{d}}\\
1107 % \qquad\ldots
1108 % \end{layout}
1109 % And then we may want to regularize the indents as in the drop ladder
1110 % layout. Let's call this a dropped step layout:
1111 % \begin{layout}[.6]
1112 % \stagger
1113 % \LHS{L_{a}}\\
1114 % \quad + \LR[.8]{L_{b}}\\
1115 % \quad + \LR[.7]{L_{c}}\\
1116 % \quad + \LR[.87]{L_{d}}\\
1117 % \qquad\ldots
1118 % \end{layout}
1119 %
1120 % \subsection{Strategy}
1121 %
1122 % Here is the basic procedure for deciding which equation layout to use,
1123 % before complications like equation numbers and delimiter clearance come
1124 % into the picture. Let $A$ be the available width, $w_{\mathrm{total}}$
1125 % the total width of the equation contents, $w(L)$ the width of the
1126 % left-hand side, $w_{\max}(R)$ the max width of the right-hand sides, $I$
1127 % the standard indent for step layout, and $O$ the standard offset for
1128 % binary operators if a break occurs in the middle of an RHS. Also let
1129 % $t_L$ and $t_R$ represent certain thresholds for the width of the LHS or
1130 % the RHS at which a layout decision may change, as explained below.
1131 %
1132 % \begin{small}
1133 % \begin{enumerate}
1134 % \renewcommand{\labelenumi}{(\theenumi)}
1135 % \item \ititle{Does everything fit on one line?}\label{i:LR}
1136 % $w_{\mathrm{total}}\leq A$?
1137 %
1138 % Yes: print the equation on a single line (done).
1139 %
1140 % No: Check whether the equation has both LHS and RHS (\ref{i:lhs-check}).
1141 %
1142 % \item \ititle{Is there a left-hand side?}\label{i:lhs-check}
1143 % Are there any relation symbols in the equation?
1144 %
1145 % Yes: Try a ladder layout (\ref{i:ladder}).
1146 %
1147 % No: Try a step layout (\ref{i:step}).
1148 %
1149 % \item\ititle{Does the LHS leave room to fit the widest RHS?}\label{i:ladder}
1150 % $w(L)+w_{\max}(R)<A$?
1151 %
1152 % Yes: Use a straight ladder layout (\ref{i:straight-ladder}).
1153 %
1154 % No: Check the width of the LHS (\ref{i:check-lhs}).
1155 %
1156 % \item\ititle{Is the LHS relatively short?}\label{i:check-lhs}
1157 % $w(L)\leq t_L$? (where $t_L$ is typically $0.4A$).
1158 %
1159 % Yes: Subdividing one or more of the RHS's may permit us to use a
1160 % straight ladder layout (\ref{i:straight-ladder}).
1161 %
1162 % No: The straight ladder layout is unlikely to work.
1163 % Try a skew or drop ladder layout (\ref{i:skew-drop}).
1164 %
1165 % \item\ititle{Straight ladder layout}\label{i:straight-ladder}
1166 % Set up a straight ladder parshape [0pt $A$ $w(L)$ $A-w(L)$] and run
1167 % a trial break. If the combined width of the LHS plus the longest RHS is
1168 % no greater than $A$ then we should get a satisfactory layout with all
1169 % line breaks occurring at major division points (relation symbols).
1170 % Otherwise, we hope, some additional line breaks at minor division points
1171 % will allow everything to fit within the text column.
1172 %
1173 % \ititle{Line breaks OK?}
1174 %
1175 % \begingroup \hbadness=9999
1176 % Yes: The straight ladder layout succeeded
1177 % (done).\par\endgroup
1178 %
1179 % No: Try a skew or drop ladder layout (\ref{i:skew-drop}).
1180 %
1181 % \item\ititle{Do the LHS and the first RHS fit on one
1182 % line?}\label{i:skew-drop} $w(L)+w(R_1) \leq A$?
1183 %
1184 % Yes: Try a skew ladder layout (\ref{i:skew}).
1185 %
1186 % No: Try a drop ladder layout (\ref{i:drop}).
1187 %
1188 % \item\ititle{Skew ladder layout}\label{i:skew}
1189 % Set up a parshape [0pt $A$ $I$ $A-I$] and run a trial break.
1190 %
1191 % \ititle{Line breaks OK?}
1192 %
1193 % Yes: Skew ladder layout succeeded (done).
1194 %
1195 % No: One of the unbreakable fragments of the $R_i$ ($i>1$) is wider than
1196 % $A-I$; try an almost-columnar layout (\ref{i:almost-columnar}).
1197 %
1198 % \item\ititle{Drop ladder layout}\label{i:drop}
1199 % Set up a parshape [0pt $w(L)$ $I$ $A-I$] and run a trial break.
1200 % This is the same parshape as for a skew ladder layout except that the
1201 % width of the first line is limited to the LHS width, so that the RHS is
1202 % forced to drop down to the next line.
1203 %
1204 % \ititle{Line breaks OK?}
1205 %
1206 % Yes: Drop ladder layout succeeded (done).
1207 %
1208 % No: One of the unbreakable fragments of the $R_i$ ($i>1$) is wider than
1209 % $A-I$; try an almost-columnar layout (\ref{i:almost-columnar}).
1210 %
1211 % \item\ititle{Almost-columnar layout}\label{i:almost-columnar}
1212 % This presupposes a trial break that yielded a series of expressions or
1213 % fragments, one per line. Let $w(F)$ denote the width of the first
1214 % fragment and $w(R_i)$ the widths of the remaining fragments.
1215 % Set up a parshape [0pt $w(F)$ $A-w_{\max}(R_i)$ $w_{\max}(R_i)$]: in other
1216 % words, set the first line flush left and the longest line flush right
1217 % and all other lines indented to the same position as the longest line.
1218 % But as a matter of fact there is one other refinement for extreme cases:
1219 % if $w_{\max}(R_i)>A$ then the parshape can be simplified without loss to
1220 % [0pt $w(F)$ 0pt $A$]\mdash for that is the net effect of substituting
1221 % $\min(A,w_{\max})$ in stead of $w_{\max}$.
1222 % (Done.)
1223 %
1224 % \item\ititle{Step layout}\label{i:step} Set target width $w_T$ to $A -
1225 % 2I$. Set parshape to [0pt $w_T$ $I$ $w_T -I$ $2I$ $w_T -2I$ \ldots\
1226 % $(l-1)I$ $w_T - (l-1)I$], where $l=\lceil w_{\mathrm{total}}/A\rceil$
1227 % is the expected number of lines that will be required. Trial break
1228 % with that parshape in order to find out the width of the last line.
1229 %
1230 % \ititle{Indents OK?}
1231 %
1232 % Yes: Step layout succeeded (done).
1233 %
1234 % No: One of the fragments is too wide to fit in
1235 % the allotted line width, after subtracting the indent specified by the
1236 % parshape. Try a dropped step layout (\ref{i:drop-step})
1237 %
1238 % \item\ititle{Dropped step layout}\label{i:drop-step} Set up a parshape
1239 % [0pt $A$ $I$ $A-I$] and run a trial break. Note that this is actually
1240 % the same parshape as for a skew ladder layout.
1241 %
1242 % \ititle{Line breaks OK?}
1243 %
1244 % Yes: Dropped step layout succeeded (done).
1245 %
1246 % No: One of the unbreakable fragments of the $R_i$ ($i>1$) is wider than
1247 % $A-I$; as a last resort try an almost-columnar layout (\ref{i:almost-columnar}).
1248 %
1249 % \end{enumerate}
1250 % \par\end{small}
1251 %
1252 % \section{To do}
1253 %
1254 % \begin{itemize}
1255 % \item Handling of QED
1256 % \item Space between \verb'\end{dmath}' and following punctuation will
1257 % prevent the punctuation from being drawn into the equation.
1258 % \item Overriding the equation layout
1259 % \item Overriding the placement of the equation number
1260 % \item \qq{alignid} option for more widely separated equations where
1261 % shared alignment is desired (requires two passes)
1262 % \item Or maybe provide an \qq{alignwidths} option where you give
1263 % lhs/rhs width in terms of ems? And get feedback later on discrepancies
1264 % with the actual measured contents?
1265 % \item \cs{intertext} not needed within dgroup! But currently there are
1266 % limitations on floating objects within dgroup.
1267 % \item \verb'align={1}' or 2, 3, 4 expressing various levels of demand
1268 % for group-wide alignment. Level 4 means force alignment even if some
1269 % lines then have to run over the right margin! Level 1, the default,
1270 % means first break LHS-RHS equations as if it occurred by itself, then
1271 % move them left or right within the current line width to align them if
1272 % possible. Levels 2 and 3 mean try harder to align but give up if
1273 % overfull lines result.
1274 % \item Need an \cs{hshift} command to help with alignment of
1275 % lines broken at a discretionary times sign. Also useful for adjusting
1276 % inside-delimiter breaks.
1277 % \end{itemize}
1278 %
1279 % \StopEventually{}
1280 % \clearpage
1281 % \newgeometry{left=4cm}
1282 % \part{Implementation}
1283 %
1284 %
1285 % The package version here is Michael's v0.90 updated by Bruce
1286 % Miller. Michael's changes between v0.90 and his last v0.94 will be
1287 % incorporated where applicable.
1288 %
1289 %
1290 % The original sources of \pkg{breqn} and related files exist in a
1291 % non-dtx format devised by Michael Downes himself.
1292 % Lars Madsen has kindly written a Perl script for transforming the
1293 % original source files into near-perfect dtx state, requiring only
1294 % very little hand tuning. Without his help it would have been nigh
1295 % impossible to incorporate the original sources with Michael's
1296 % comments. A big, big thank you to him.
1297 %
1298 %
1299 %
1300 % \section{Introduction}
1301 % The \pkg{breqn} package provides environments
1302 % \env{dmath}, \env{dseries}, and \env{dgroup} for
1303 % displayed equations with \emph{automatic line breaking},
1304 % including automatic indention of relation symbols and binary operator
1305 % symbols at the beginning of broken lines. These environments
1306 % automatically pull in following punctuation so that it can be written in
1307 % a natural way. The \pkg{breqn} package also provides a
1308 % \env{darray} environment similar to the \env{array}
1309 % environment but using \cs{displaystyle} for all the array cells and
1310 % providing better interline spacing (because the vertical ruling
1311 % feature of \env{array} is dropped).
1312 % These are all autonumbered environments like \env{equation}
1313 % and have starred forms that don't add a number. For a more
1314 % comprehensive and detailed description of the features and intended
1315 % usage of the \pkg{breqn} package see \fn{breqndoc.tex}.
1316 %
1317 %
1318 %
1319 %
1320 % \section{Strategy}
1321 % Features of particular note are the ability to have
1322 % linebreaks even within a \cs{left} \ndash \cs{right} pair of
1323 % delimiters, and the automatic alignment on relations and binary
1324 % operators of a split equation. To make \env{dmath} handle
1325 % all this, we begin by setting the body of the equation in a special
1326 % paragraph form with strategic line breaks whose purpose is not to
1327 % produce line breaks in the final printed output but rather to mark
1328 % significant points in the equation and give us entry points for
1329 % unpacking \cn{left} \ndash \cn{right} boxes.
1330 % After the initial typesetting, we take the resulting stack of line
1331 % fragments and, working backward, splice them into a new, single-line
1332 % paragraph; this will eventually be poured into a custom parshape, after
1333 % we do some measuring to calculate what that parshape should be.
1334 % This streamlined horizontal list may contain embedded material
1335 % from user commands intended to alter line breaks, horizontal alignment,
1336 % and interline spacing; such material requires special handling.
1337 %
1338 % To make the `shortskip' possibility work even for
1339 % multiline equations, we must plug in a dummy \tex display to give us
1340 % the value of \cs{predisplaysize}, and calculate for ourselves when
1341 % to apply the short skips.
1342 %
1343 % In order to measure the equation body and do various
1344 % enervating calculations on whether the equation number will fit and so
1345 % on, we have to set it in a box. Among other things, this means
1346 % that we can't unhbox it inside \dbldollars \dots \dbldollars , or
1347 % even \verb"$" \dots \verb"$": \tex doesn't allow you to
1348 % \cs{unhbox} in math mode. But we do want to unhbox it rather
1349 % than just call \cs{box}, otherwise we can't take advantage of
1350 % available shrink from \cs{medmuskip} to make equations shrink to
1351 % fit in the available width. So even for simple one-line equations
1352 % we are forced to fake a whole display without going through \tex 's
1353 % primitive display mechanism (except for using it to get
1354 % \cs{predisplaysize} as mentioned above).
1355 %
1356 %
1357 % In the case of a framed equation body, the current implementation is
1358 % to set the frame in a separate box, of width zero and height zero,
1359 % pinned to the upper left corner of the equation body, and then print the
1360 % equation body on top of it.
1361 % For attaching an equation number it would be much simpler to wrap
1362 % the equation body in the frame and from then on treat the body as a
1363 % single box instead of multiple line boxes.
1364 % But I had a notion that it might be possible some day to support
1365 % vertical stretching of the frame.
1366 %
1367 %
1368 %
1369 %
1370 % \section{Prelim}
1371 %
1372 % \begin{macrocode}
1373 %<*package>
1374 \NeedsTeXFormat{LaTeX2e}
1375 % \end{macrocode}
1376 %
1377 % Declare package name and date.
1378 % \begin{macrocode}
1379 \RequirePackage{expl3}
1380 \ProvidesExplPackage{breqn}{2021/10/28}{0.98l}{Breaking equations}
1381 % \end{macrocode}
1382 % Regrettably, \pkg{breqn} is internally a mess, so we have to take
1383 % some odd steps.
1384 % \begin{macrocode}
1385 \ExplSyntaxOff
1386 % \end{macrocode}
1387 %
1388 %
1389 % \section{Package options}
1390 %
1391 % First we need to get the catcodes sorted out.
1392 % \begin{macrocode}
1393 \edef\breqnpopcats{%
1394 \catcode\number`\"=\number\catcode`\"
1395 \relax}
1396 \AtEndOfPackage{\breqnpopcats}%
1397 \catcode`\^=7 \catcode`\_=8 \catcode`\"=12 \relax
1398 \DeclareOption{mathstyleoff}{%
1399 \PassOptionsToPackage{mathstyleoff}{flexisym}%
1400 }
1401 % \end{macrocode}
1402 % Process options.
1403 % \begin{macrocode}
1404 \ProcessOptions\relax
1405 % \end{macrocode}
1406 %
1407 %
1408 %
1409 %
1410 % \section{Required packages}
1411 %
1412 % Although breqn can be loaded without amsmath, there's not much point, and explicitly
1413 % loading amsmath here prevents loading-order issues later.
1414 % \begin{macrocode}
1415 \RequirePackage{amsmath}
1416 % \end{macrocode}
1417 %
1418 % Similarly, if graphicx is loaded atbegindocument there is a catcode clash, so load it here too.
1419 % (see test file 00-clash-1.lvt)
1420 % \begin{macrocode}
1421 \RequirePackage{graphicx}
1422 % \end{macrocode}
1423 %
1424 % The \pkg{flexisym} package makes it possible to attach
1425 % extra actions to math symbols, in particular mathbin, mathrel, mathopen,
1426 % and mathclose symbols.
1427 % Normally it would suffice to call \cs{RequirePackage} without
1428 % any extra testing, but the nature of the package is such that it is
1429 % likely to be called earlier with different (no) options.
1430 % Then is it really helpful to be always warning the user about
1431 % \quoted{Incompatible Package Options!}?
1432 % I don't think so.
1433 % \begin{macrocode}
1434 \@ifpackageloaded{flexisym}{}{%
1435 \RequirePackage{flexisym}[2009/08/07]
1436 \edef\breqnpopcats{\breqnpopcats
1437 \catcode\number`\^=\number\catcode`\^
1438 \catcode\number`\_=\number\catcode`\_
1439 }%
1440 \catcode`\^=7 \catcode`\_=8 \catcode`\"=12 \relax
1441 }
1442 % \end{macrocode}
1443 % The \pkg{keyval} package for handling equation options and
1444 % \pkg{calc} to ease writing computations.
1445 % \begin{macrocode}
1446 \RequirePackage{keyval,calc}\relax
1447 % \end{macrocode}
1448 %
1449 %
1450 % \begin{macro}{\breqnsetup}
1451 % \begin{macrocode}
1452 \newcommand{\breqnsetup}[1]{\setkeys{breqn}{#1}}
1453 % \end{macrocode}
1454 % \end{macro}
1455 %
1456 %
1457 %
1458 %
1459 % \section{Some useful tools}
1460 %
1461 %
1462 %
1463 % \begin{macro}{\MaybeRawNoindent}
1464 % Breqn does a lot of low-level paragraph stuff which iesn't
1465 % supposed to execute paragraph hooks, so with a newer \LaTeX{} it
1466 % needs to run the versions that prevent the hooks from executing.
1467 % \begin{macrocode}
1468 \providecommand\IfFormatAtLeastTF{\@ifl@t@r\fmtversion}
1469 % \end{macrocode}
1470 %
1471 % \begin{macrocode}
1472 \IfFormatAtLeastTF{2021/06/01}
1473 {%
1474 \def\MaybeRawNoindent{\ifvmode\expandafter\RawNoindent\fi}%
1475 }%
1476 {%
1477 \let\MaybeRawNoindent\noindent
1478 \let\RawParEnd\@@par
1479 }
1480 % \end{macrocode}
1481 % \end{macro}
1482 %
1483 %
1484 %
1485 % \begin{macro}{\@nx}
1486 % \begin{macro}{\@xp}
1487 % The comparative brevity of \cs{@nx} and \cs{@xp} is
1488 % valuable not so much for typing convenience as for reducing visual
1489 % clutter in code sections that require a lot of expansion control.
1490 % \begin{macrocode}
1491 \let\@nx\noexpand
1492 \let\@xp\expandafter
1493 % \end{macrocode}
1494 % \end{macro}
1495 % \end{macro}
1496 %
1497 %
1498 % \begin{macro}{\@emptytoks}
1499 % Constant empty token register, analogous to \cs{@empty}.
1500 % \begin{macrocode}
1501 \@ifundefined{@emptytoks}{\newtoks\@emptytoks}{}
1502 % \end{macrocode}
1503 % \end{macro}
1504 %
1505 %
1506 % \begin{macro}{\f@ur}
1507 % Constants 0\ndash 3 are provided in plain \tex , but not 4.
1508 % \begin{macrocode}
1509 \chardef\f@ur=4
1510 % \end{macrocode}
1511 % \end{macro}
1512 %
1513 %
1514 % \begin{macro}{\inf@bad}
1515 % \cs{inf@bad} is for testing box badness.
1516 % \begin{macrocode}
1517 \newcount\inf@bad \inf@bad=1000000
1518 % \end{macrocode}
1519 % \end{macro}
1520 %
1521 %
1522 % \begin{macro}{\maxint}
1523 %
1524 % We want to use \cs{maxint} rather than coerced
1525 % \cs{maxdimen} for \cs{linepenalty} in one place.
1526 % \begin{macrocode}
1527 \newcount\maxint \maxint=2147483647
1528 % \end{macrocode}
1529 % \end{macro}
1530 %
1531 %
1532 % \begin{macro}{\int@a}
1533 % \begin{macro}{\int@b}
1534 % \begin{macro}{\int@b}
1535 %
1536 % Provide some shorter aliases for various scratch registers.
1537 % \begin{macrocode}
1538 \let\int@a=\@tempcnta
1539 \let\int@b=\@tempcntb
1540 \let\int@c=\count@
1541 % \end{macrocode}
1542 % \end{macro}
1543 % \end{macro}
1544 % \end{macro}
1545 %
1546 %
1547 % \begin{macro}{\dim@a}
1548 % \begin{macro}{\dim@b}
1549 % \begin{macro}{\dim@c}
1550 % \begin{macro}{\dim@d}
1551 % \begin{macro}{\dim@e}
1552 % \begin{macro}{\dim@A}
1553 %
1554 % Same for dimen registers.
1555 % \begin{macrocode}
1556 \let\dim@a\@tempdima
1557 \let\dim@b\@tempdimb
1558 \let\dim@c\@tempdimc
1559 \let\dim@d\dimen@
1560 \let\dim@e\dimen@ii
1561 \let\dim@A\dimen@i
1562 % \end{macrocode}
1563 % \end{macro}
1564 % \end{macro}
1565 % \end{macro}
1566 % \end{macro}
1567 % \end{macro}
1568 % \end{macro}
1569 %
1570 %
1571 % \begin{macro}{\skip@a}
1572 % \begin{macro}{\skip@b}
1573 % \begin{macro}{\skip@c}
1574 %
1575 % Same for skip registers.
1576 % \begin{macrocode}
1577 \let\skip@a\@tempskipa
1578 \let\skip@b\@tempskipb
1579 \let\skip@c\skip@
1580 % \end{macrocode}
1581 % \end{macro}
1582 % \end{macro}
1583 % \end{macro}
1584 %
1585 %
1586 % \begin{macro}{\toks@a}
1587 % \begin{macro}{\toks@b}
1588 % \begin{macro}{\toks@c}
1589 % \begin{macro}{\toks@d}
1590 % \begin{macro}{\toks@e}
1591 % \begin{macro}{\toks@f}
1592 %
1593 % Same for token registers.
1594 % \begin{macrocode}
1595 \let\toks@a\@temptokena
1596 \let\toks@b\toks@
1597 \toksdef\toks@c=2
1598 \toksdef\toks@d=4
1599 \toksdef\toks@e=6
1600 \toksdef\toks@f=8
1601 % \end{macrocode}
1602 % \end{macro}
1603 % \end{macro}
1604 % \end{macro}
1605 % \end{macro}
1606 % \end{macro}
1607 % \end{macro}
1608 %
1609 %
1610 % \begin{macro}{\abs@num}
1611 % We need an absolute value function for comparing
1612 % penalties.
1613 % \begin{macrocode}
1614 \def\abs@num#1{\ifnum#1<\z@-\fi#1}
1615 % \end{macrocode}
1616 % \end{macro}
1617 %
1618 %
1619 % \begin{macro}{\@ifnext}
1620 % \begin{macro}{\@ifnexta}
1621 % The \cs{@ifnext} function is a variation of
1622 % \cs{@ifnextchar} that doesn't skip over intervening whitespace.
1623 % We use it for the optional arg of \dbslash inside
1624 % \env{dmath} \etc because we don't want
1625 % unwary users to be tripped up by an unexpected attempt on \latex 's part
1626 % to interpret a bit of math as an optional arg:
1627 % \begin{literalcode}
1628 % \begin{equation}
1629 % ...\\
1630 % [z,w]...
1631 % \end{equation}
1632 % \end{literalcode}
1633 % .
1634 % \begin{macrocode}
1635 \def\@ifnext#1#2#3{%
1636 \let\@tempd= #1\def\@tempa{#2}\def\@tempb{#3}%
1637 \futurelet\@tempc\@ifnexta
1638 }
1639 % \end{macrocode}
1640 % Switch to \cs{@tempa} iff the next token matches.
1641 % \begin{macrocode}
1642 \def\@ifnexta{\ifx\@tempc\@tempd \let\@tempb\@tempa \fi \@tempb}
1643 % \end{macrocode}
1644 % \end{macro}
1645 % \end{macro}
1646 %
1647 %
1648 % \begin{macro}{\breqn@ifstar}
1649 % Similarly let's remove space-skipping from \cs{@ifstar}
1650 % because in some rare case of \dbslash inside an equation, followed by
1651 % a space and a \verb"*" where the \verb"*" is intended as the math
1652 % binary operator, it would be a disservice to gobble the star as an
1653 % option of the \dbslash command. In all other contexts the chance
1654 % of having a space \emph{before} the star is extremely small: either
1655 % the command is a control word which will get no space token after it in
1656 % any case because of \tex 's tokenization rules; or it is a control
1657 % symbol such as \dbslash \verb"*" which is exceedingly unlikely to be
1658 % written as \dbslash \verb"*" by any one who really wants the
1659 % \verb"*" to act as a modifier for the \dbslash command.
1660 % \begin{macrocode}
1661 \def\breqn@ifstar#1#2{%
1662 \let\@tempd*\def\@tempa*{#1}\def\@tempb{#2}%
1663 \futurelet\@tempc\@ifnexta
1664 }
1665 % \end{macrocode}
1666 % \end{macro}
1667 %
1668 %
1669 % \begin{macro}{\breqn@optarg}
1670 % Utility function for reading an optional arg
1671 % \emph{without} skipping over any intervening spaces.
1672 % \begin{macrocode}
1673 \def\breqn@optarg#1#2{\@ifnext[{#1}{#1[#2]}}
1674 % \end{macrocode}
1675 % \end{macro}
1676 %
1677 %
1678 % \begin{macro}{\@True}
1679 % \begin{macro}{\@False}
1680 % \begin{macro}{\@Not}
1681 % \begin{macro}{\@And}
1682 % After \verb"\let\foo\@True" the test
1683 % \begin{literalcode}
1684 % \if\foo
1685 % \end{literalcode}
1686 % evaluates to true. Would rather avoid \cs{newif} because it
1687 % uses three csnames per Boolean variable; this uses only one.
1688 % \begin{macrocode}
1689 \def\@True{00}
1690 \def\@False{01}
1691 \def\@Not#1{0\ifcase#11 \or\@xp 1\else \@xp 0\fi}
1692 \def\@And#1#2{0\ifcase#1#2 \@xp 0\else \@xp 1\fi}
1693 \def\@Or#1#2{0\ifnum#1#2<101 \@xp 0\else \@xp 1\fi}
1694 % \end{macrocode}
1695 % \end{macro}
1696 % \end{macro}
1697 % \end{macro}
1698 % \end{macro}
1699 %
1700 %
1701 %
1702 % \begin{macrocode}
1703 \def\theb@@le#1{\if#1 True\else False\fi}
1704 % \end{macrocode}
1705 % \begin{macro}{\freeze@glue}
1706 %
1707 % Remove the stretch and shrink from a glue register.
1708 % \begin{macrocode}
1709 \def\freeze@glue#1{#11#1\relax}
1710 % \end{macrocode}
1711 % \end{macro}
1712 % \begin{macro}{\z@rule}
1713 % \begin{macro}{\keep@glue}
1714 % Note well
1715 % the intentional absence of \cs{relax} at the end of the replacement
1716 % text of \cs{z@rule}; use it with care.
1717 % \begin{macrocode}
1718 \def\z@rule{\vrule\@width\z@}% no \relax ! use with care
1719 % \end{macrocode}
1720 % Different ways to keep a bit of glue from disappearing at the
1721 % beginning of a line after line breaking:
1722 % \begin{itemize}
1723 % \item Zero-thickness rule
1724 % \item Null character
1725 % \item \cs{vadjust}\verb"{}" (\texbook , Exercise ??)
1726 % \end{itemize}
1727 % The null character idea would be nice except it
1728 % creates a mathord which then screws up math spacing for \eg a following
1729 % unary minus sign. (the vrule \emph{is} transparent to
1730 % the math spacing). The vadjust is the cheapest in terms of box
1731 % memory\mdash it vanishes after the pass through \tex 's
1732 % paragrapher.
1733 % It is what I would have used, except that the equation contents get
1734 % run through two paragraphing passes, once for breaking up LR boxes and
1735 % once for the real typesetting.
1736 % If \cs{keep@glue} were done with an empty vadjust, it would
1737 % disappear after the first pass and\mdash in particular\mdash the
1738 % pre-bin-op adjustment for relation symbols would disappear at a line break.
1739 % \begin{macrocode}
1740 \def\keep@glue{\z@rule\relax}
1741 % \end{macrocode}
1742 % \end{macro}
1743 % \end{macro}
1744 %
1745 %
1746 % \begin{macro}{\replicate}
1747 %
1748 % This is a fully expandable way of making N copies of a token
1749 % list.
1750 % Based on a post of David Kastrup to comp.text.tex circa January
1751 % 1999.
1752 % The extra application of \cs{number} is needed for maximal
1753 % robustness in case the repeat count N is given in some weird \tex form
1754 % such as \verb|"E9| or \verb|\count9|.
1755 % \begin{macrocode}
1756 % usage: \message{H\replicate{5}{i h}ow de doo dee!}
1757 \begingroup \catcode`\&=11
1758 \gdef\replicate#1{%
1759 \csname &\expandafter\replicate@a\romannumeral\number\number#1 000q\endcsname
1760 }
1761 \endgroup
1762 % \end{macrocode}
1763 % \end{macro}
1764 %
1765 %
1766 % \begin{macro}{\replicate@a}
1767 % \begin{macrocode}
1768 \long\def\replicate@a#1#2\endcsname#3{#1\endcsname{#3}#2}
1769 % \end{macrocode}
1770 % \end{macro}
1771 %
1772 %
1773 % \begin{macro}{\8m}% fix
1774 % \begin{macrocode}
1775 \begingroup \catcode`\&=11
1776 \long\gdef\&m#1#2{#1\csname &#2\endcsname{#1}}
1777 \endgroup
1778 % \end{macrocode}
1779 % \end{macro}
1780 %
1781 %
1782 % \begin{macro}{\8q}% fix
1783 % \begin{macrocode}
1784 \@xp\let\csname\string &q\endcsname\@gobble
1785 % \end{macrocode}
1786 % \end{macro}
1787 %
1788 % \begin{macro}{\mathchars@reset}
1789 %
1790 % Need to patch up this function from flexisym a little, to better
1791 % handle certain constructed symbols like \cs{neq}.
1792 % \begin{macrocode}
1793 \ExplSyntaxOn
1794 \g@addto@macro\mathchars@reset{%
1795 %\let\@symRel\@secondoftwo \let\@symBin\@secondoftwo
1796 %\let\@symDeL\@secondoftwo \let\@symDeR\@secondoftwo
1797 %\let\@symDeB\@secondoftwo
1798 \cs_set_eq:NN \math_csym_Rel:Nn \use_ii:nn
1799 \cs_set_eq:NN \math_csym_Bin:Nn \use_ii:nn
1800 \cs_set_eq:NN \math_csym_DeL:Nn \use_ii:nn
1801 \cs_set_eq:NN \math_csym_DeR:Nn \use_ii:nn
1802 \cs_set_eq:NN \math_csym_DeB:Nn \use_ii:nn
1803 }
1804 \ExplSyntaxOff
1805 % \end{macrocode}
1806 % \end{macro}
1807 %
1808 %
1809 % \begin{macro}{\@saveprimitive}
1810 % If some preceding package redefined one of the
1811 % primitives that we must change, we had better do some checking to make
1812 % sure that we are able to save the primitive meaning for internal use.
1813 % This is handled by the \cs{@saveprimitive} function. We
1814 % follow the example of \cs{@@input} where the primitive meaning is
1815 % stored in an internal control sequence with a \verb"@@" prefix.
1816 % Primitive control sequences can be distinguished by the fact that
1817 % \cs{string} and \cs{meaning} return the same information.
1818 % Well, not quite all: \cs{nullfont} and \cs{topmark}
1819 % and the other \cs{...mark} primitives being the exceptions.
1820 % \begin{macrocode}
1821 \providecommand{\@saveprimitive}[2]{%
1822 \begingroup
1823 \edef\@tempa{\string#1}\edef\@tempb{\meaning#1}%
1824 \ifx\@tempa\@tempb \global\let#2#1%
1825 \else
1826 % \end{macrocode}%
1827 % If [arg1] is no longer primitive, then we are in trouble unless
1828 % [arg2] was already given the desired primitive meaning somewhere
1829 % else.
1830 % \begin{macrocode}
1831 \edef\@tempb{\meaning#2}%
1832 \ifx\@tempa\@tempb
1833 \else \@saveprimitive@a#1#2%
1834 \fi
1835 \fi
1836 \endgroup
1837 }
1838 % \end{macrocode}
1839 % Aux function, check for the special cases.
1840 % Most of the time this branch will be skipped so we can
1841 % stuff a lot of work into it without worrying about speed costs.
1842 % \begin{macrocode}
1843 \providecommand\@saveprimitive@a[2]{%
1844 \begingroup
1845 \def\@tempb##1#1##2{\edef\@tempb{##2}\@car{}}%
1846 \@tempb\nullfont{select font nullfont}%
1847 \topmark{\string\topmark:}%
1848 \firstmark{\string\firstmark:}%
1849 \botmark{\string\botmark:}%
1850 \splitfirstmark{\string\splitfirstmark:}%
1851 \splitbotmark{\string\splitbotmark:}%
1852 #1{\string#1}%
1853 \@nil % for the \@car
1854 \edef\@tempa{\expandafter\strip@prefix\meaning\@tempb}%
1855 \edef\@tempb{\meaning#1}%
1856 \ifx\@tempa\@tempb \global\let#2#1%
1857 \else
1858 \PackageError{breqn}%
1859 {Unable to properly define \string#2; primitive
1860 \noexpand#1no longer primitive}\@eha
1861 \fi
1862 \fi
1863 \endgroup
1864 }
1865 % \end{macrocode}
1866 % \end{macro}
1867 %
1868 %
1869 % \begin{macro}{\@@math}
1870 % \begin{macro}{\@@endmath}
1871 % \begin{macro}{\@@display}
1872 % \begin{macro}{\@@enddisplay}
1873 % Move the math-start and math-end functions into control
1874 % sequences. If I were redesigning \tex I guess I'd put these
1875 % functions into primitive control words instead of linking them to a
1876 % catcode. That way \tex would not have to do the special
1877 % lookahead at a \verb"$" to see if there's another one coming up.
1878 % Of course that's related to the question of how to provide user
1879 % shorthand for common constructions: \tex , or an editing interface of
1880 % some sort.
1881 % \begin{macrocode}
1882 \begingroup \catcode`\$=\thr@@ % just to make sure
1883 \global\let\@@math=$ \gdef\@@display{$$}% $$$
1884 \endgroup
1885 \let\@@endmath=\@@math
1886 \let\@@enddisplay=\@@display
1887 % \end{macrocode}
1888 % \end{macro}
1889 % \end{macro}
1890 % \end{macro}
1891 % \end{macro}
1892 %
1893 %
1894 % \begin{macro}{\@@insert}
1895 % \begin{macro}{\@@mark}
1896 % \begin{macro}{\@@vadjust}
1897 % Save the primitives \cs{vadjust}, \cs{insert},
1898 % \cs{mark} because we will want to change them locally during
1899 % equation measuring to keep them from getting in the way of our vertical
1900 % decomposition procedures. We follow the example of
1901 % \cs{@@input}, \cs{@@end}, \cs{@@par} where the primitive
1902 % meaning is stored in an internal control sequence with a \verb"@@"
1903 % prefix.
1904 % \begin{macrocode}
1905 \@saveprimitive\vadjust\@@vadjust
1906 \@saveprimitive\insert\@@insert
1907 \@saveprimitive\mark\@@mark
1908 % \end{macrocode}
1909 % \end{macro}
1910 % \end{macro}
1911 % \end{macro}
1912 %
1913 %
1914 %
1915 %
1916 % \section{Debugging}
1917 % Debugging help.
1918 % \begin{macrocode}
1919 %<*trace>
1920 \errorcontextlines=2000\relax
1921 \typeout{BREQN DEBUGGING MODE ACTIVE}
1922 % \end{macrocode}
1923 %
1924 % \begin{macro}{\breqn@debugmsg}
1925 % Print a debugging message.
1926 % \begin{macrocode}
1927 \long\def\breqn@debugmsg#1{\GenericWarning{||}{||=\space#1}}
1928 % \end{macrocode}
1929 % \end{macro}
1930 %
1931 % \begin{macro}{\debugwr}
1932 % Sometimes the newline behavior of \cs{message} is
1933 % unsatisfactory; this provides an alternative.
1934 % \begin{macrocode}
1935 \def\debugwr#1{\immediate\write\sixt@@n{||= #1}}
1936 % \end{macrocode}
1937 % \end{macro}
1938 %
1939 %
1940 % \begin{macro}{\debug@box}
1941 % Record the contents of a box in the log file, without stopping.
1942 % \begin{macrocode}
1943 \def\debug@box#1{%
1944 \batchmode{\showboxbreadth\maxdimen\showboxdepth99\showbox#1}%
1945 \errorstopmode
1946 }
1947 % \end{macrocode}
1948 % \end{macro}
1949 %
1950 %
1951 % \begin{macro}{\eqinfo}
1952 % Show lots of info about the material before launching into the
1953 % trials.
1954 % \begin{macrocode}
1955 \def\eqinfo{%
1956 \debug@box\EQ@copy
1957 \wlog{!! EQ@copy: \the\wd\EQ@copy\space x
1958 \the\ht\EQ@copy+\the\dp\EQ@copy
1959 }%
1960 }
1961 % \end{macrocode}
1962 % \end{macro}
1963 %
1964 %
1965 % \begin{macro}{\debug@para}
1966 % Check params that affect line breaking.
1967 % \begin{macrocode}
1968 \def\debug@para{%
1969 \debugwr{\hsize\the\hsize, \parfillskip\the\parfillskip}%
1970 \breqn@debugmsg{\leftskip\the\leftskip, \rightskip\the\rightskip}%
1971 \breqn@debugmsg{\linepenalty\the\linepenalty, \adjdemerits\the\adjdemerits}%
1972 \breqn@debugmsg{\pretolerance\the\pretolerance, \tolerance\the\tolerance,
1973 \parindent\the\parindent}%
1974 }
1975 % \end{macrocode}
1976 % \end{macro}
1977 %
1978 %
1979 % \begin{macrocode}
1980 %</trace>
1981 % \end{macrocode}
1982 %
1983 %
1984 %
1985 %
1986 % \section{The \cs{listwidth} variable}
1987 % The dimen variable \cs{listwidth} is \cs{linewidth}
1988 % plus \cs{leftmargin} plus \cs{rightmargin}, which is typically
1989 % less than \cs{hsize} if the list depth is greater than one.
1990 % In case a future package will provide this variable, define it only
1991 % if not yet defined.
1992 % \begin{macrocode}
1993 \@ifundefined{listwidth}{\newdimen\listwidth}{}
1994 \listwidth=\z@
1995 % \end{macrocode}
1996 %
1997 %
1998 %
1999 %
2000 % \section{Parameters}
2001 %
2002 % Here follows a list of parameters needed.
2003 %
2004 % \begin{macro}{\eqfontsize}
2005 % \begin{macro}{\eqcolor}
2006 % \begin{macro}{\eqmargin}
2007 % \begin{macro}{\eqindent}
2008 % \begin{macro}{\eqbinoffset}
2009 % \begin{macro}{\eqnumside}
2010 % \begin{macro}{\eqnumplace}
2011 % \begin{macro}{\eqnumsep}
2012 % \begin{macro}{\eqnumfont}
2013 % \begin{macro}{\eqnumform}
2014 % \begin{macro}{\eqnumsize}
2015 % \begin{macro}{\eqnumcolor}
2016 % \begin{macro}{\eqlinespacing}
2017 % \begin{macro}{\eqlineskip}
2018 % \begin{macro}{\eqlineskiplimit}
2019 % \begin{macro}{\eqstyle}
2020 % \begin{macro}{\eqinterlinepenalty}
2021 % \begin{macro}{\intereqpenalty}
2022 % \begin{macro}{\intereqskip}
2023 %
2024 % Note: avoid M, m, P, p because they look like they might be the
2025 % start of a keyword \quoted{minus} or \quoted{plus}. Then
2026 % \tex looks further to see if the next letter is i or l. And if
2027 % the next thing is an undefined macro, the attempt to expand the macro
2028 % results in an error message.
2029 % \begin{macrocode}
2030 \def\eqfontsize{} % Inherit from context [NOT USED?]
2031 \def\eqcolor{black} % Default to black [NOT USED?]
2032 \newdimen\eqnumsep \eqnumsep=10pt % Min space between equ number and body
2033 \newdimen\eqmargin \eqmargin=8pt % For `multline' gap emulation
2034 % \end{macrocode}
2035 % The \cs{eqindent} and \cs{eqnumside} variables need to
2036 % have their values initialized from context, actually. But
2037 % that takes a bit of work, which is postponed till later.
2038 % \begin{macrocode}
2039 \def\eqindent{C}% % C or I, centered or indented
2040 \def\eqnumside{R}% % R or L, right or left
2041 \def\eqnumplace{M}% % M or T or B, middle top or bottom
2042 % \end{macrocode}
2043 % Typesetting the equation number is done thus:
2044 % \begin{literalcode}
2045 % {\eqnumcolor \eqnumsize \eqnumfont{\eqnumform{\eq@number}}}
2046 % \end{literalcode}
2047 % .
2048 % \begin{macrocode}
2049 %d\eqnumfont{\upshape}% % Upright even when surrounding text is slanted
2050 \def\eqnumfont{}% % Null for easier debugging [mjd,1997/09/26]
2051 \def\eqnumform#1{(#1\@@italiccorr)} % Add parens
2052 \def\eqnumsize{} % Allow numbers to have different typesize ...
2053 % \end{macrocode}
2054 % Tricky questions on \cs{eqnumsize}. Should the default
2055 % be \cs{normalsize}? Then the user can scale down the
2056 % equation body with \cs{small} and not affect the equation
2057 % number. Or should the default be empty? Then in large
2058 % sections of smaller text, like the dangerous bend stuff in
2059 % \emph{\TeX book}, the equation number size will keep in synch
2060 % with the context.
2061 % Maybe need an \cs{eqbodysize} param as well to allow separating
2062 % the two cases.
2063 % \begin{macrocode}
2064 \def\eqnumcolor{} % ... or color than eq body e.g. \color{blue}
2065 \newlength\eqlinespacing \eqlinespacing=14pt plus2pt % Base-to-base space between lines
2066 \newlength\eqlineskip \eqlineskip=3pt plus2pt % Min space if eqlinespacing too small
2067 \newdimen\eqlineskiplimit \eqlineskiplimit=2pt % Threshold for switching to eqlineskip
2068 % \end{macrocode}
2069 % The value of \cs{eqbinoffset} should include a negative shrink
2070 % component that cancels the shrink component of medmuskip, otherwise
2071 % there can be a noticeable variation in the indent of adjacent lines if
2072 % one is shrunken a lot and the other isn't.
2073 % \begin{macrocode}
2074 \newmuskip \eqbinoffset \eqbinoffset=15mu minus-3mu % Offset from mathrel alignment pt for mathbins
2075 \newmuskip\eqdelimoffset \eqdelimoffset=2mu % Additional offset for break inside delims
2076 \newdimen\eqindentstep \eqindentstep=8pt % Indent used when LHS wd is n/a or too large
2077 \newtoks\eqstyle % Customization hook
2078 \newcount\eqbreakdepth \eqbreakdepth=2 % Allow breaks within delimiters to this depth
2079 \newcount \eqinterlinepenalty \eqinterlinepenalty=10000 % No page breaks between equation lines
2080 \newcount \intereqpenalty \intereqpenalty=1000 % Pagebreak penalty between equations [BRM: Was \@M]
2081 \newlength \intereqskip \intereqskip=3pt plus2pt % Additional vert space between equations
2082 \newcount\prerelpenalty \prerelpenalty=-\@M % Linebreak penalty before mathrel symbols
2083 \newcount\prebinoppenalty \prebinoppenalty=888 % Linebreak penalty before mathbins
2084 % \end{macrocode}
2085 % When breaking equations we never right-justify, so a stretch
2086 % component of the muskip is never helpful and sometimes it is definitely
2087 % undesirable. Note that thick\slash medmuskips frozen inside a
2088 % fraction or radical may turn out noticeably larger than neighboring
2089 % unfrozen ones. Nonetheless I think this way is the best
2090 % compromise short of a new \tex that can make those built-up objects
2091 % shrink horizontally in proportion; the alternative is to pretty much
2092 % eliminate the shrink possibility completely in displays.
2093 % \begin{macrocode}
2094 \newmuskip \Dmedmuskip \Dmedmuskip=4mu minus 3mu % medmuskip in displays
2095 \newmuskip \Dthickmuskip \Dthickmuskip=5mu minus 2mu % thickmuskip in displays
2096 % \end{macrocode}
2097 % \end{macro}
2098 % \end{macro}
2099 % \end{macro}
2100 % \end{macro}
2101 % \end{macro}
2102 % \end{macro}
2103 % \end{macro}
2104 % \end{macro}
2105 % \end{macro}
2106 % \end{macro}
2107 % \end{macro}
2108 % \end{macro}
2109 % \end{macro}
2110 % \end{macro}
2111 % \end{macro}
2112 % \end{macro}
2113 % \end{macro}
2114 % \end{macro}
2115 % \end{macro}
2116 %
2117 % And now some internal variables. 1997/10/22: some of
2118 % these are dead branches that need to be pruned.
2119 %
2120 % MH: Started cleaning up a bit. No more funny loops.
2121 % \begin{macrocode}
2122 \def\eq@number{} % Internal variable
2123 \newlength\eqleftskip \eqleftskip=\@centering % Space on the left [NOT USED?]
2124 \newlength\eqrightskip \eqrightskip=\@centering % Space on the right [NOT USED?]
2125 \newlength\eq@vspan \eq@vspan=\z@skip % Glue used to vcenter the eq number
2126 \newmuskip\eq@binoffset \eq@binoffset=\eqbinoffset % Roughly, \eqbinoffset + \eqdelimoffset
2127 \newsavebox\EQ@box % Storage for equation body
2128 \newsavebox\EQ@copy % For eq body sans vadjust/insert/mark material
2129 \newsavebox\EQ@numbox % For equation number
2130 \newdimen\eq@wdNum % width of number + separation [NEW]
2131 \newsavebox\GRP@numbox % For group number [NEW]
2132 \newdimen\grp@wdNum % width of number + separation [NEW]
2133 %%B\EQ@vimbox % Vadjust, insert, or mark material
2134 %%B\EQ@vimcopy % Spare copy of same
2135 %%B\eq@impinging % Temporary box for measuring number placement
2136 \newcount \eq@lines % Internal counter, actual number of lines
2137 \newcount \eq@curline % Loop counter
2138 \newcount \eq@badness % Used in testing for overfull lines
2139 \newcount \EQ@vims % For bookkeeping
2140 \def\@eq@numbertrue{\let\eq@hasNumber\@True}%
2141 \def\@eq@numberfalse{\let\eq@hasNumber\@False}%
2142 \let\eq@hasNumber\@False
2143 % \end{macrocode}
2144 % Here for the dimens, it would be advisable to do some more careful
2145 % management to conserve dimen registers. First of all, most of the
2146 % dimen registers are needed in the measuring phase, which is a tightly
2147 % contained step that happens after the contents of the equation have been
2148 % typeset into a box and before any external functions have a chance to
2149 % regain control\mdash \eg , the output routine.
2150 % Therefore it is possible to make use of the the dimen registers 0--9,
2151 % reserved by convention for scratch use, without fear of conflict with
2152 % other macros. But I don't want to use them directly with the
2153 % available names:
2154 % \begin{literalcode}
2155 % \dimen@ \dimen@i \dimen@ii \dimen3 \dimen4 ... \dimen9
2156 % \end{literalcode}
2157 % . It would be much more useful to have names for these registers
2158 % indicative of way they are used.
2159 %
2160 % Another source whence dimen registers could be borrowed is the
2161 % \pkg{amsmath} package, which allocates six registers for
2162 % equation-measuring purposes. We can reuse them under different
2163 % names since the \pkg{amsmath} functions and our functions will
2164 % never be used simultaneously.
2165 % \begin{literalcode}
2166 % \eqnshift@ \alignsep@ \tagshift@ \tagwidth@ \totwidth@ \lineht@
2167 % \end{literalcode}
2168 % \begin{macrocode}
2169 \newdimen\eq@dp % Depth of last line
2170 \newdimen\eq@wdL % Width of the left-hand-side
2171 \newdimen\eq@wdT % Total width for framing
2172 \newdimen\eq@wdMin % Width of narrowest line in equation
2173 \newdimen\grp@wdL % Max width of LHS's in a group
2174 \newdimen\grp@wdR % Max RHS of all equations in a group
2175 \newdimen\grp@wdT
2176 \newdimen\eq@wdRmax
2177 \newdimen\eq@firstht % Height of first line
2178 % \end{macrocode}
2179 % BRM: measure the condition too.
2180 % \begin{macrocode}
2181 \newdimen\eq@wdCond
2182 \newdimen\eq@indentstep % Indent amount when LHS is not present
2183 \newdimen\eq@linewidth % Width actually used for display
2184 \newdimen\grp@linewidth % Max eq@linewidth over a group
2185 % \end{macrocode}
2186 % Maybe \cs{eq@hshift} could share the same register as
2187 % \cs{mathindent} [mjd,1997/10/22].
2188 % \begin{macrocode}
2189 \newdimen\eq@hshift
2190 \let\eq@isIntertext\@False
2191 % \end{macrocode}
2192 % Init \cs{eq@indentstep} to a nonzero value so that we can
2193 % detect and refrain from clobbering a user setting of zero.
2194 % And \cs{eq@sidespace} to \cs{maxdimen} because
2195 % that is the right init before computing a min.
2196 % \begin{macrocode}
2197 \eq@indentstep=\maxdimen
2198 \newdimen\eq@given@sidespace
2199 % \end{macrocode}
2200 %
2201 % \begin{macro}{\eq@overrun}
2202 % MH: Appears to be unused.
2203 %
2204 % Not a dimen register; don't need to advance it.
2205 % \begin{macrocode}
2206 \def\eq@overrun{0pt}
2207 % \end{macrocode}
2208 % \end{macro}
2209 %
2210 %
2211 % To initialize \cs{eqnumside} and \cs{eqindent} properly,
2212 % we may need to grub around a bit in \cs{@filelist}. However,
2213 % if the \pkg{amsmath} package was used, we can use its option
2214 % data. More trouble: if a documentclass sends an option of
2215 % \opt{leqno} to \pkg{amsmath} by default, and it gets
2216 % overridden by the user with a \opt{reqno} documentclass option,
2217 % then \pkg{amsmath} believes itself to have received
2218 % \emph{both} options.
2219 % \begin{macrocode}
2220 \@ifpackagewith{amsmath}{leqno}{%
2221 \@ifpackagewith{amsmath}{reqno}{}{\def\eqnumside{L}}%
2222 }{%
2223 % \end{macrocode}
2224 % If the \pkg{amsmath} package was not used, the next
2225 % method for testing the \opt{leqno} option is to see if
2226 % \fn{leqno.clo} is present in \cs{@filelist}.
2227 % \begin{macrocode}
2228 \def\@tempa#1,leqno.clo,#2#3\@nil{%
2229 \ifx @#2\relax\else \def\eqnumside{L}\fi
2230 }%
2231 \@xp\@tempa\@filelist,leqno.clo,@\@nil
2232 % \end{macrocode}
2233 % Even that test may fail in the case of \cls{amsart} if it does
2234 % not load \pkg{amsmath}. Then we have to look whether
2235 % \cs{iftagsleft@} is defined, and if so whether it is true.
2236 % This is tricky if you want to be careful about conditional nesting
2237 % and don't want to put anything in the hash table unnecessarily.
2238 % \begin{macrocode}
2239 \if L\eqnumside
2240 \else
2241 \@ifundefined{iftagsleft@}{}{%
2242 \edef\eqnumside{%
2243 \if TT\csname fi\endcsname\csname iftagsleft@\endcsname
2244 L\else R\fi
2245 }%
2246 }
2247 \fi
2248 }
2249 % \end{macrocode}
2250 % A similar sequence of tests handles the \quoted{fleqn or not fleqn}
2251 % question for the \cls{article} and \cls{amsart}
2252 % documentclasses.
2253 % \begin{macrocode}
2254 \@ifpackagewith{amsmath}{fleqn}{%
2255 \def\eqindent{I}%
2256 }{%
2257 \def\@tempa#1,fleqn.clo,#2#3\@nil{%
2258 \ifx @#2\relax\else \def\eqindent{I}\fi
2259 }%
2260 \@xp\@tempa\@filelist,fleqn.clo,@\@nil
2261 \if I\eqindent
2262 \else
2263 \@ifundefined{if@fleqn}{}{%
2264 \edef\eqindent{%
2265 \if TT\csname fi\endcsname\csname if@fleqn\endcsname
2266 I\else C\fi
2267 }%
2268 }%
2269 \fi
2270 }
2271 % \end{macrocode}
2272 % BRM: This conditional implies we must use ALL indented or ALL centered?
2273 % \begin{macrocode}
2274 %\if I\eqindent
2275 \@ifundefined{mathindent}{%
2276 \newdimen\mathindent
2277 }{%
2278 \@ifundefined{@mathmargin}{}{%
2279 \mathindent\@mathmargin
2280 }%
2281 }
2282 %\fi
2283 % \end{macrocode}
2284 %
2285 %
2286 %
2287 %
2288 % \section{Measuring equation components}
2289 % Measure the left-hand side of an equation. This
2290 % function is called by mathrel symbols. For the first mathrel we
2291 % want to discourage a line break more than for following mathrels; so
2292 % \cs{mark@lhs} gobbles the following \cs{rel@break} and
2293 % substitutes a higher penalty.
2294 % \begin{aside}
2295 % Maybe the LHS should be kept in a separate box.
2296 % \end{aside}
2297 %
2298 %
2299 %
2300 % \begin{macro}{\EQ@hasLHS}
2301 %
2302 % Boolean: does this equation have a \dquoted{left-hand side}?
2303 % \begin{macrocode}
2304 \let\EQ@hasLHS=\@False
2305 % \end{macrocode}
2306 % \end{macro}
2307 %
2308 %
2309 % \begin{macro}{\EQ@QED}
2310 %
2311 % If nonempty: the qed material that should be incorporated into this
2312 % equation after the final punctuation.
2313 % \begin{macrocode}
2314 \let\EQ@QED=\@empty
2315 % \end{macrocode}
2316 % \end{macro}
2317 %
2318 %
2319 % \begin{macro}{\mark@lhs}
2320 %
2321 % \begin{macrocode}
2322 \def\mark@lhs#1{%
2323 \ifnum\lr@level<\@ne
2324 \let\mark@lhs\relax
2325 \global\let\EQ@hasLHS=\@True
2326 \global\let\EQ@prebin@space\EQ@prebin@space@a
2327 \mark@lhs@a
2328 % \end{macrocode}
2329 % But the penalty for the first mathrel should still be lower than a
2330 % binoppenalty. If not, when the LHS contains a binop, the split
2331 % will occur inside the LHS rather than at the mathrel.
2332 % On the other hand if we end up with a multline sort of equation
2333 % layout where the RHS is very short, the break before the relation symbol
2334 % should be made \emph{less} desirable than the breakpoints inside
2335 % the LHS.
2336 % Since a lower penalty takes precedence over a higher one, we start
2337 % by putting in the highest relpenalty; during subsequent measuring if we
2338 % find that that RHS is not excessively short then we put in an extra
2339 % \dquoted{normal} relpenalty when rejoining the LHS and RHS.
2340 % \begin{macrocode}
2341 \penalty9999 % instead of normal \rel@break
2342 % else no penalty = forbid break
2343 \fi
2344 }
2345 % \end{macrocode}
2346 % \end{macro}
2347 %
2348 %
2349 % \begin{macro}{\mark@lhs@a}
2350 %
2351 % Temporarily add an extra thickmuskip to the LHS; it will be removed
2352 % later. This is necessary to compensate for the disappearance of
2353 % the thickmuskip glue preceding a mathrel if a line break is taken at
2354 % that point. Otherwise we would have to make our definition of
2355 % mathrel symbols more complicated, like the one for mathbins. The
2356 % penalty of $2$ put in with vadjust is a flag for
2357 % \cs{eq@repack} to suggest that the box containing this line should
2358 % be measured to find the value of \cs{eq@wdL}. The
2359 % second vadjust ensures that the normal prerelpenalty and thickmuskip
2360 % will not get lost at the line break during this preliminary pass.
2361 %
2362 % BRM: I originally thought the \verb"\mskip\thickmuskip" was messing
2363 % up summation limits in LHS. But I may have fixed that problem by
2364 % fixing other things\ldots
2365 % \begin{macrocode}
2366 \def\mark@lhs@a{%
2367 \mskip\thickmuskip \@@vadjust{\penalty\tw@}\penalty-\@Mi\@@vadjust{}%
2368 }
2369 % \end{macrocode}
2370 % \end{macro}
2371 %
2372 %
2373 % \begin{macro}{\hiderel}
2374 % If you want the LHS to extend past the first mathrel symbol to a
2375 % following one, mark the first one with \cs{hiderel}:
2376 % \begin{literalcode}
2377 % a \hiderel{=} b = c...
2378 % \end{literalcode}
2379 % .
2380 % \begin{aside}
2381 % I'm not sure now why I didn't use \cs{begingroup}
2382 % \cs{endgroup} here \begin{dn}
2383 % mjd,1999/01/21
2384 % \end{dn}
2385 % .
2386 % \end{aside}
2387 %
2388 % \begin{macrocode}
2389 \newcommand\hiderel[1]{\mathrel{\advance\lr@level\@ne#1}}
2390 % \end{macrocode}
2391 % \end{macro}
2392 %
2393 %
2394 % \begin{macro}{\m@@Bin}
2395 % \begin{macro}{\m@@Rel}
2396 % \begin{macro}{\bin@break}
2397 % \begin{macro}{\rel@break}
2398 % \begin{macro}{\bin@mark}
2399 % \begin{macro}{\rel@mark}
2400 % \begin{macro}{\d@@Bin}
2401 % \begin{macro}{\d@@Rel}
2402 %
2403 % \cf \pkg{flexisym} handling of mathbins and mathrels. These
2404 % are alternate definitions of \cs{m@Bin} and \cs{m@Rel},
2405 % activated by \cs{display@setup}.
2406 % \begin{macrocode}
2407 %%%%\let\m@@Bin\m@Bin
2408 %%%%%\let\m@@Rel\m@Rel
2409 \let\EQ@prebin@space\relax
2410 \def\EQ@prebin@space@a{\mskip-\eq@binoffset \keep@glue \mskip\eq@binoffset}
2411 \def\bin@break{\ifnum\lastpenalty=\z@\penalty\prebinoppenalty\fi
2412 \EQ@prebin@space}
2413 \def\rel@break{%
2414 \ifnum\abs@num\lastpenalty <\abs@num\prerelpenalty
2415 \penalty\prerelpenalty
2416 \fi
2417 }
2418 \ExplSyntaxOn
2419 %%%\def\d@@Bin{\bin@break \m@@Bin}
2420 %%%%\def\d@@Rel{\mark@lhs \rel@break \m@@Rel}
2421 \cs_set:Npn \math_dsym_Bin:Nn {\bin@break\math_bsym_Bin:Nn}
2422 \cs_set:Npn \math_dsym_Rel:Nn {\mark@lhs \rel@break \math_bsym_Rel:Nn }
2423 \ExplSyntaxOff
2424 % \end{macrocode}
2425 % The difficulty of dealing properly with the subscripts and
2426 % superscripts sometimes appended to mathbins and mathrels is one of the
2427 % reasons that we do not attempt to handle the mathrels as a separate
2428 % \quoted{column} a la \env{eqnarray}.
2429 %
2430 % \end{macro}
2431 % \end{macro}
2432 % \end{macro}
2433 % \end{macro}
2434 % \end{macro}
2435 % \end{macro}
2436 % \end{macro}
2437 % \end{macro}
2438 %
2439 %
2440 % \begin{macro}{\m@@symRel}
2441 % \begin{macro}{\d@@symRel}
2442 % \begin{macro}{\m@@symBin}
2443 % \begin{macro}{\d@@symBin}
2444 % \begin{macro}{\m@@symDel}
2445 % \begin{macro}{\d@@symDel}
2446 % \begin{macro}{\m@@symDeR}
2447 % \begin{macro}{\d@@symDeR}
2448 % \begin{macro}{\m@@symDeB}
2449 % \begin{macro}{\d@@symDeB}
2450 % \begin{macro}{\m@@symDeA}
2451 % \begin{macro}{\d@@symDeA}
2452 %
2453 % More of the same.
2454 % \begin{macrocode}
2455 \ExplSyntaxOn
2456 %%\let\m@@symRel\@symRel
2457 %%%\def\d@@symRel{\mark@lhs \rel@break \m@@symRel}
2458
2459 \cs_set_protected:Npn \math_dcsym_Bin:Nn {\bin@break \math_bcsym_Bin:Nn}
2460 \cs_set_protected:Npn \math_dcsym_Rel:Nn { \mark@lhs \rel@break \math_bcsym_Rel:Nn}
2461
2462
2463 %%\let\m@@symBin\@symBin \def\d@@symBin{\bin@break \m@@symBin}
2464 %%\let\m@@symDel\@symDel
2465 %%\let\m@@symDeR\@symDeR
2466 %%\let\m@@symDeB\@symDeB
2467 %%\let\m@@symDeA\@symDeA
2468
2469 % \end{macrocode}
2470 % \end{macro}
2471 % \end{macro}
2472 % \end{macro}
2473 % \end{macro}
2474 % \end{macro}
2475 % \end{macro}
2476 % \end{macro}
2477 % \end{macro}
2478 % \end{macro}
2479 % \end{macro}
2480 % \end{macro}
2481 % \end{macro}
2482 %
2483 %
2484 % \begin{macro}{\display@setup}
2485 % \begin{macro}{\everydisplay}
2486 % Setup. Note that \latex reserves the primitive
2487 % \cs{everydisplay} under the name \cs{frozen@everydisplay}.
2488 % BRM: Disable this! It also affects non-breqn math!!!!
2489 % \begin{macrocode}
2490 %\global\everydisplay\expandafter{\the\everydisplay \display@setup}
2491 % \end{macrocode}
2492 % Change some math symbol function calls.
2493 % \begin{macrocode}
2494 \def\display@setup{%
2495 \medmuskip\Dmedmuskip \thickmuskip\Dthickmuskip
2496 \math_setup_display_symbols:
2497 %%\let\m@Bin\d@@Bin \let\m@Rel\d@@Rel
2498 %%\let\@symRel\d@@symRel \let\@symBin\d@@symBin
2499 %%\let\m@DeL\d@@DeL \let\m@DeR\d@@DeR \let\m@DeB\d@@DeB
2500 %%\let\m@DeA\d@@DeA
2501 %%\let\@symDeL\d@@symDeL \let\@symDeR\d@@symDeR
2502 %%\let\@symDeB\d@@symDeB \let\@symDeA\d@@symDeA
2503 \let\left\eq@left \let\right\eq@right \global\lr@level\z@
2504 \global\eq@wdCond\z@ %BRM: new
2505 % \end{macrocode}
2506 % If we have an embedded array environment (for example), we
2507 % don't want to have each math cell within the array resetting
2508 % \cs{lr@level} globally to 0\mdash not good!
2509 % And in general I think it is safe to say that whenever we have a
2510 % subordinate level of boxing we want to revert to a normal math setup.
2511 % \begin{macrocode}
2512 \everyhbox{\everyhbox\@emptytoks
2513 \let\display@setup\relax \textmath@setup \let\textmath@setup\relax
2514 }%
2515 \everyvbox{\everyvbox\@emptytoks
2516 \let\display@setup\relax \textmath@setup \let\textmath@setup\relax
2517 }%
2518 }
2519 % \end{macrocode}
2520 % The \cs{textmath@setup} function is needed for embedded inline
2521 % math inside text inside a display.
2522 %
2523 % BRM: DS Experiment: Variant of \cs{display@setup} for use within
2524 % dseries environmnents
2525 % \begin{macrocode}
2526 \def\dseries@display@setup{%
2527 \medmuskip\Dmedmuskip \thickmuskip\Dthickmuskip
2528 \math_setup_display_symbols:
2529 %%%% \let\m@Bin\d@@Bin
2530 %%%\let\m@Rel\d@@Rel
2531 %%% \let\@symRel\d@@symRel
2532 %%% \let\@symBin\d@@symBin
2533 %%% \let\m@DeL\d@@DeL \let\m@DeR\d@@DeR \let\m@DeB\d@@DeB
2534 %%% \let\m@DeA\d@@DeA
2535 %%% \let\@symDeL\d@@symDeL \let\@symDeR\d@@symDeR
2536 %%% \let\@symDeB\d@@symDeB \let\@symDeA\d@@symDeA
2537 \let\left\eq@left \let\right\eq@right \global\lr@level\z@
2538 \everyhbox{\everyhbox\@emptytoks
2539 \let\display@setup\relax \textmath@setup \let\textmath@setup\relax
2540 }%
2541 \everyvbox{\everyvbox\@emptytoks
2542 \let\display@setup\relax \textmath@setup \let\textmath@setup\relax
2543 }%
2544 \displaystyle
2545 }
2546 % \end{macrocode}
2547 %
2548 % \begin{macrocode}
2549 \def\textmath@setup{%
2550 \math_setup_inline_symbols:
2551 %%%% \let\m@Bin\m@@Bin \let\m@Rel\m@@Rel
2552 %%%% \let\@symRel\m@@symRel \let\@symBin\m@@symBin
2553 %%%% \let\m@DeL\m@@DeL \let\m@DeR\m@@DeR \let\m@DeB\m@@DeB
2554 %%%% \let\m@DeA\m@@DeA
2555 %%%% \let\@symDeL\m@@symDeL \let\@symDeR\m@@symDeR
2556 %%%% \let\@symDeB\m@@symDeB \let\@symDeA\m@@symDeA
2557 \let\left\@@left \let\right\@@right
2558 }
2559
2560 \ExplSyntaxOff
2561 % \end{macrocode}
2562 % \end{macro}
2563 % \end{macro}
2564 %
2565 % \begin{macro}{\if@display}
2566 % \begin{macro}{\everydisplay}
2567 % The test \cs{ifinner} is unreliable for distinguishing
2568 % whether we are in a displayed formula or an inline formula: any display
2569 % more complex than a simple one-line equation typically involves the use
2570 % of \verb"$" \cs{displaystyle} \dots \verb"$" instead of
2571 % \dbldollars \dots \dbldollars . So we provide a more reliable
2572 % test. But it might have been provided already by the
2573 % \pkg{amsmath} package.
2574 % \begin{macrocode}
2575 \@ifundefined{@displaytrue}{%
2576 \@xp\newif\csname if@display\endcsname
2577 \everydisplay\@xp{\the\everydisplay \@displaytrue}%
2578 }{}
2579 % \end{macrocode}
2580 %
2581 % \begin{aside}
2582 % Is there any reason to maintain separate
2583 % \cs{everydisplay} and \cn{eqstyle}?
2584 %
2585 % \end{aside}
2586 %
2587 %
2588 % \end{macro}
2589 % \end{macro}
2590 %
2591 %
2592 %
2593 %
2594 % \section{The \env{dmath} and \env{dmath*} environments}
2595 %
2596 % Options for the \env{dmath} and \env{dmath*}
2597 % environments.
2598 % \begin{literalcode}
2599 % \begin{dmath}[label={eq:xyz}]
2600 % \begin{dmath}[labelprefix={eq:},label={xyz}]
2601 % \end{literalcode}
2602 % WSPR: added the option for a label prefix, designed to be used in the preamble like so:
2603 % \begin{literalcode}
2604 % \breqnsetup{labelprefix={eq:}}
2605 % \end{literalcode}
2606 % \begin{macrocode}
2607 \define@key{breqn}{label}{%
2608 \edef\next@label{\noexpand\label{\next@label@pre#1}}%
2609 \let\next@label@pre\@empty}
2610 \define@key{breqn}{labelprefix}{\def\next@label@pre{#1}}
2611 \global\let\next@label\@empty
2612 \global\let\next@label@pre\@empty
2613 % \end{macrocode}
2614 % Allow a variant number.
2615 % \begin{literalcode}
2616 % \begin{dmath}[number={\nref{foo}\textprime}]
2617 % \end{literalcode}
2618 % \begin{macrocode}
2619 \define@key{breqn}{number}{\def\eq@number{#1}%
2620 \let\@currentlabel\eq@number
2621 }
2622 % \end{macrocode}
2623 % \begin{literalcode}
2624 % \begin{dmath}[shiftnumber]
2625 % \begin{dmath}[holdnumber]
2626 % \end{literalcode}
2627 % Holding or shifting the number.
2628 % \begin{macrocode}
2629 \define@key{breqn}{shiftnumber}{\let\eq@shiftnumber\@True}
2630 \define@key{breqn}{holdnumber}{\let\eq@holdnumber\@True}
2631 % \end{macrocode}
2632 % \begin{literalcode}
2633 % \begin{dmath}[density={.5}]
2634 % \end{literalcode}
2635 % \begin{macrocode}
2636 \define@key{breqn}{density}{\def\eq@density@factor{#1}}
2637 % \end{macrocode}
2638 % \begin{literalcode}
2639 % \begin{dmath}[indentstep={1em}]
2640 % \end{literalcode}
2641 % To change the amount of indent for post-initial lines. Note:
2642 % for lines that begin with a mathbin symbol there is a fixed amount of
2643 % indent already built in (\cs{eqbinoffset}) and it cannot be
2644 % reduced through this option. The indentstep amount is the indent
2645 % used for lines that begin with a mathrel symbol.
2646 % \begin{macrocode}
2647 \define@key{breqn}{indentstep}{\eqindentstep#1\relax}
2648 % \end{macrocode}
2649 % \begin{literalcode}
2650 % \begin{dmath}[compact]
2651 % \begin{dmath}[compact=-2000]
2652 % \end{literalcode}
2653 % To make mathrels stay inline to the extent possible, use the compact
2654 % option.
2655 % Can give a numeric value in the range $-10000 \dots 10000$
2656 % to adjust the behavior.
2657 % $-10000$: always break at a rel symbol; $10000$: never
2658 % break at a rel symbol.
2659 % \begin{macrocode}
2660 \define@key{breqn}{compact}[-99]{\prerelpenalty=#1\relax}
2661 % \end{macrocode}
2662 % \begin{literalcode}
2663 % \begin{dmath}[layout={S}]%
2664 % \end{literalcode}
2665 % Specify a particular layout.
2666 % We take care to ensure that \cs{eq@layout} ends up containing
2667 % one and only one letter.
2668 % \begin{macrocode}
2669 \define@key{breqn}{layout}[?]{%
2670 \edef\eq@layout{\@car#1?\@nil}%
2671 }
2672 % \end{macrocode}
2673 % \begin{literalcode}
2674 % \begin{dmath}[spread={1pt}]
2675 % \end{literalcode}
2676 % To change the interline spacing in a particular equation.
2677 % \begin{macrocode}
2678 \define@key{breqn}{spread}{%
2679 \addtolength\eqlinespacing{#1}%
2680 \addtolength\eqlineskip{#1}%
2681 \eqlineskiplimit\eqlineskip
2682 }
2683 % \end{macrocode}
2684 % To change the amount of space on the side for \dquoted{multline} layout.
2685 % \begin{macrocode}
2686 \define@key{breqn}{sidespace}{%
2687 \setlength\eq@given@sidespace{#1}%
2688 }
2689 % \end{macrocode}
2690 % \begin{literalcode}
2691 % \begin{dmath}[style={\small}]
2692 % \end{literalcode}
2693 % The \opt{style} option is mainly intended for changing the
2694 % type size of an equation but as a matter of fact you could put arbitrary
2695 % \latex code here \mdash thus the option name is \quoted{style} rather
2696 % than just \quoted{typesize}. In order for this option to work when
2697 % setting options globally, we need to put the code in
2698 % \cs{eqstyle} rather than execute it directly.
2699 % \begin{macrocode}
2700 \define@key{breqn}{style}{\eqstyle\@xp{\the\eqstyle #1}}
2701 % \end{macrocode}
2702 % \begin{literalcode}
2703 % \begin{dmath}[shortskiplimit={1em}]
2704 % \end{literalcode}
2705 % If the line immediately preceeding a display has length $l$, the
2706 % first line of the display is indented $i$, and a shortskip limit $s$
2707 % is set, then the spacing above the display is equal to
2708 % \cs{abovedisplayshortskip} if $l+s < i $ and \cs{abovedisplayskip}
2709 % otherwise. The default shortskip limit is 2\,em which is what \TeX\
2710 % hardcodes but this parameter overrides that.
2711 % \begin{macrocode}
2712 \define@key{breqn}{shortskiplimit}{\def\eq@shortskiplimit{#1}}
2713 \def\eq@shortskiplimit{2em}
2714 % \end{macrocode}
2715 %
2716 % \begin{literalcode}
2717 % \begin{dmath}[frame]
2718 % \end{literalcode}
2719 % The \opt{frame} option merely puts a framebox around the body
2720 % of the equation. To change the thickness of the frame, give the
2721 % thickness as the argument of the option. For greater control, you
2722 % can change the appearance of the frame by redefining
2723 % \cs{eqframe}. It must be a command taking two arguments, the
2724 % width and height of the equation body. The top left corner of the
2725 % box produced by \cs{eqframe} will be pinned to the top-left corner
2726 % of the equation body.
2727 % \begin{macrocode}
2728 \define@key{breqn}{frame}[\fboxrule]{\def\eq@frame{T}%
2729 \dim@a#1\relax\edef\eq@framewd{\the\dim@a}%
2730 % \end{macrocode}
2731 % Until such time as we provide a frame implementation that allows the
2732 % frame to stretch and shrink, we'd better remove any stretch/shrink from
2733 % the interline glue in this case.
2734 % \begin{macrocode}
2735 \freeze@glue\eqlinespacing \freeze@glue\eqlineskip
2736 }
2737 \define@key{breqn}{fullframe}[]{\def\eq@frame{U}%
2738 \freeze@glue\eqlinespacing \freeze@glue\eqlineskip
2739 }
2740 \def\eq@frame{F} % no frame
2741 \def\eq@framewd{\fboxrule}
2742 % \end{macrocode}
2743 % Wishful thinking?
2744 % \begin{literalcode}
2745 % \begin{dmath}[frame={width={2pt},color={blue},sep={2pt}}]
2746 % \end{literalcode}
2747 % To change the space between the frame and the equation there is a
2748 % framesep option.
2749 % \begin{macrocode}
2750 \define@key{breqn}{framesep}[\fboxsep]{%
2751 \if\eq@frame F\def\eq@frame{T}\fi
2752 \dim@a#1\relax \edef\eq@framesep{\the\dim@a}%
2753 \freeze@glue\eqlinespacing \freeze@glue\eqlineskip
2754 }
2755 \def\eq@framesep{\fboxsep}
2756 % \end{macrocode}
2757 % \begin{literalcode}
2758 % \begin{dmath}[background={red}]
2759 % \end{literalcode}
2760 % Foreground and background colors for the equation. By default
2761 % the background area that is colored is the size of the equation, plus
2762 % fboxsep. If you need anything fancier for the background, you'd
2763 % better do it by defining \cs{eqframe} in terms of
2764 % \cs{colorbox} or \cs{fcolorbox}.
2765 % \begin{macrocode}
2766 \define@key{breqn}{background}{\def\eq@background{#1}%
2767 \freeze@glue\eqlinespacing \freeze@glue\eqlineskip
2768 }
2769 % \end{macrocode}
2770 % \begin{literalcode}
2771 % \begin{dmath}[color={purple}]
2772 % \end{literalcode}
2773 % \begin{macrocode}
2774 \define@key{breqn}{color}{\def\eq@foreground{#1}}
2775 % \end{macrocode}
2776 % \begin{literalcode}
2777 % \begin{dmath}[center]
2778 % \begin{dmath}[nocenter]
2779 % \end{literalcode}
2780 % The \opt{center} option means add leftskip stretch to make the
2781 % individual lines be centered; this is the default for
2782 % \env{dseries}.
2783 % \begin{macrocode}
2784 \define@key{breqn}{center}[]{\let\eq@centerlines\@True}
2785 \define@key{breqn}{nocenter}[]{\let\eq@centerlines\@False}
2786 \let\eq@centerlines\@False
2787 % \end{macrocode}
2788 % \begin{literalcode}
2789 % \begin{dgroup}[noalign]
2790 % \end{literalcode}
2791 % Equation groups normally have alignment of the primary relation
2792 % symbols across the whole group. The \opt{noalign} option
2793 % switches that behavior.
2794 % \begin{macrocode}
2795 \define@key{breqn}{noalign}[]{\let\grp@aligned\@False}
2796 \let\grp@aligned\@True % default
2797 % \end{macrocode}
2798 % \begin{literalcode}
2799 % \begin{dgroup}[breakdepth={2}]
2800 % \end{literalcode}
2801 % Break depth of 2 means that breaks are allowed at mathbin symbols
2802 % inside two pairs of delimiters, but not three.
2803 % \begin{macrocode}
2804 \define@key{breqn}{breakdepth}{\eqbreakdepth#1\relax}
2805 % \end{macrocode}
2806 % \begin{literalcode}
2807 % \begin{darray}[cols={lcrlcr}]
2808 % \end{literalcode}
2809 % The \opt{cols} option only makes sense for the
2810 % \env{darray} environment but we liberally allow all the options to
2811 % be used with all the environments and just ignore any unsensible ones
2812 % that happen to come along.
2813 % \begin{macrocode}
2814 \define@key{breqn}{cols}{\global\let\@preamble\@empty
2815 \darray@mkpream#1\@percentchar
2816 }
2817 % \end{macrocode}
2818 %
2819 % FORMAT STATUS%
2820 % \begin{verbatim}
2821 % \def\eq@frame{T}%
2822 % CLM works tolerably
2823 % \def\eqindent{C}\def\eqnumside{L}\def\eqnumplace{M}
2824 % CLT works tolerably
2825 % \def\eqindent{C}\def\eqnumside{L}\def\eqnumplace{T}
2826 % ILM
2827 % \def\eqindent{I}\def\eqnumside{L}\def\eqnumplace{M}\mathindent40\p@
2828 % ILT
2829 % \def\eqindent{I}\def\eqnumside{L}\def\eqnumplace{T}\mathindent40\p@
2830 % Indended w/left number
2831 % work ok if mathindent is larger than number width,
2832 % but then equations must fit into smaller space.
2833 % Is shiftnumber allowed to put eqn at left, instead of indent?
2834 % CRM
2835 % \def\eqindent{C}\def\eqnumside{R}\def\eqnumplace{M}
2836 % CRB
2837 % \def\eqindent{C}\def\eqnumside{R}\def\eqnumplace{B}
2838 % IRM
2839 % \def\eqindent{I}\def\eqnumside{R}\def\eqnumplace{M}\mathindent10\p@
2840 % IRB
2841 % \def\eqindent{I}\def\eqnumside{R}\def\eqnumplace{B}\mathindent10\p@
2842 % \end{verbatim}
2843 %
2844 % The main environments.
2845 %
2846 %BRM: The following incorporates several changes:
2847 % 1) modifications supplied by MJD to fix the eaten \cs{paragraph} problem.
2848 % 2) Added \cs{display@setup} here, rather than globally.
2849 %
2850 % \begin{macro}{\@dmath@start@hook}
2851 % \begin{macro}{\@dgroup@start@hook}
2852 % \begin{macrocode}
2853 \let\@dmath@start@hook\@empty
2854 \let\@dgroup@start@hook\@empty
2855 % \end{macrocode}
2856 % \end{macro}
2857 % \end{macro}
2858 %
2859 % \begin{macro}{\dmath}
2860 % \begin{macro}{\enddmath}
2861 % For the \env{dmath} environment we don't want the standard
2862 % optional arg processing because of the way it skips over whitespace,
2863 % including newline, while looking for the \verb"[" char; which is not good
2864 % for math material. So we call \cs{@optarg} instead.
2865 % \begin{macrocode}
2866 \newenvironment{dmath}{%
2867 \@dmath@start@hook
2868 \let\eq@hasNumber\@True \breqn@optarg\@dmath{}}{}
2869 \def\@dmath[#1]{%
2870 %<trace> \breqn@debugmsg{=== DMATH ==================================================}%
2871 \everydisplay\expandafter{\the\everydisplay \display@setup}%
2872 \if@noskipsec \leavevmode \fi
2873 \if@inlabel \leavevmode \global\@inlabelfalse \fi
2874 \if\eq@group\else\eq@prelim\fi
2875 \setkeys{breqn}{#1}%
2876 \the\eqstyle
2877 % \end{macrocode}
2878 % The equation number might have been overridden in \verb|#1|.
2879 % \begin{macrocode}
2880 \eq@setnumber
2881 % \end{macrocode}
2882 % Start up the displayed equation by reading the contents into a
2883 % box register. Enclose this phase in an extra group so that
2884 % modified \cs{hsize} and other params will be auto-restored
2885 % afterwards.
2886 % \begin{macrocode}
2887 \begingroup
2888 \eq@setup@a
2889 \eq@startup
2890 }
2891 % \end{macrocode}
2892 % Before it finishes off the box holding the equation body,
2893 % \cs{enddmath} needs to look ahead for punctuation (and
2894 % \cs{qed}?).
2895 % \begin{macrocode}
2896 \def\enddmath#1{%
2897 \check@punct@or@qed
2898 }
2899 \def\end@dmath{%
2900 \gdef\EQ@setwdL{}% Occasionally undefined ???
2901 \eq@capture
2902 \endgroup
2903 \EQ@setwdL
2904 % \end{macrocode}
2905 % Measure (a copy of) the equation body to find the minimum width
2906 % required to get acceptable line breaks, how many lines will be required
2907 % at that width, and whether the equation number needs to be shifted to
2908 % avoid overlapping. This information will then be used by
2909 % \cs{eq@finish} to do the typesetting of the real equation body.
2910 % \begin{macrocode}
2911 \eq@measure
2912 % \end{macrocode}
2913 % Piece together the equation from its constituents, recognizing
2914 % current constraints. If we are in an equation group, this might
2915 % just save the material on a stack for later processing.
2916 % \begin{macrocode}
2917 \if\eq@group \grp@push \else \eq@finish\fi
2918 }
2919 % \end{macrocode}
2920 % \end{macro}
2921 % \end{macro}
2922 %
2923 % \begin{macro}{\dmath*}
2924 % \begin{macro}{\enddmath*}
2925 % Ah yes, now the lovely \env{dmath*} environment.
2926 % \begin{macrocode}
2927 \newenvironment{dmath*}{%
2928 \@dmath@start@hook
2929 \let\eq@hasNumber\@False \breqn@optarg\@dmath{}%
2930 }{}
2931 \@namedef{end@dmath*}{\end@dmath}
2932 \@namedef{enddmath*}#1{\check@punct@or@qed}
2933 % \end{macrocode}
2934 % \end{macro}
2935 % \end{macro}
2936 %
2937 %
2938 % \begin{macro}{\eq@prelim}
2939 % If \cs{everypar} has a non-null value, it's probably
2940 % some code from \cs{@afterheading} that sets \cs{clubpenalty}
2941 % and\slash or removes the parindent box. Both of those actions
2942 % are irrelevant and interfering for our purposes and need to be deflected
2943 % for the time being.
2944 % If an equation appears at the very beginning of a list item
2945 % (possibly from a trivlist such as \env{proof}), we need to
2946 % trigger the item label.
2947 % \begin{macrocode}
2948 \def\eq@prelim{%
2949 \if@inlabel \indent \par \fi
2950 \if@nobreak \global\@nobreakfalse \predisplaypenalty\@M \fi
2951 \everypar\@emptytoks
2952 % \end{macrocode}
2953 % If for some reason \env{dmath} is called between paragraphs,
2954 % \cn{noindent} is better than \cn{leavevmode}, which would produce
2955 % an indent box and an empty line to hold it. If we are in a list
2956 % environment, \cn{par} is defined as \verb"{\@@par}" to preserve
2957 % \cs{parshape}.
2958 % \begin{macrocode}
2959 \noindent
2960 \eq@nulldisplay
2961 \par %% \eq@saveparinfo %% needs work
2962 \let\intertext\breqn@intertext
2963 }
2964 % \end{macrocode}
2965 % \end{macro}
2966 % \begin{macro}{\breqn@parshape@warning}
2967 % Warning message extracted to a separate function to streamline the
2968 % calling function.
2969 % \begin{macrocode}
2970 \def\breqn@parshape@warning{%
2971 \PackageWarning{breqn}{%
2972 Complex paragraph shape cannot be followed by this equation}%
2973 }
2974 % \end{macrocode}
2975 % \end{macro}
2976 %
2977 %
2978 % \begin{macro}{\eq@prevshape}
2979 % Storage; see \cs{eq@saveparinfo}.
2980 % \begin{macrocode}
2981 \let\eq@prevshape\@empty
2982 % \end{macrocode}
2983 % \end{macro}
2984 %
2985 %
2986 % \begin{macro}{\eq@saveparinfo}
2987 % Save the number of lines and parshape info for the text preceding
2988 % the equation.
2989 % \begin{macrocode}
2990 \def\eq@saveparinfo{%
2991 \count@\prevgraf \advance\count@-\thr@@ % for the null display
2992 \edef\eq@prevshape{\prevgraf\the\count@\space}%
2993 \ifcase\parshape
2994 % case 0: no action required
2995 \or \edef\eq@prevshape{\eq@prevshape
2996 \parshape\@ne\displayindent\displaywidth\relax
2997 }%
2998 % \end{macrocode}
2999 % Maybe best to set \cs{eq@prevshape} the same in the else case
3000 % also. Better than nothing.
3001 % \begin{macrocode}
3002 \else
3003 \breqn@parshape@warning
3004 \fi
3005 }
3006 % \end{macrocode}
3007 % \end{macro}
3008 %
3009 %
3010 % \begin{macro}{\eq@setnumber}
3011 % If the current equation number is not explicitly given, then
3012 % use an auto-generated number, unless the no-number switch has been
3013 % thrown (\env{dmath*}).
3014 % \cs{theequation} is the number form to be used for all equations,
3015 % \cs{eq@number} is the actual value for the current equation
3016 % (might be an exception to the usual sequence).
3017 % \begin{macrocode}
3018 \def\eq@setnumber{%
3019 \eq@wdNum\z@
3020 \if\eq@hasNumber
3021 \ifx\eq@number\@empty
3022 \stepcounter{equation}\let\eq@number\theequation
3023 \fi
3024 % \fi
3025 % \end{macrocode}
3026 % This sets up numbox, etc, even if unnumbered?????
3027 % \begin{macrocode}
3028 \ifx\eq@number\@empty
3029 \else
3030 % \end{macrocode}
3031 % Put the number in a box so we can use its measurements in our
3032 % number-placement calculations. The extra braces around
3033 % \cs{eqnumform} make it possible for \cs{eqnumfont} to have
3034 % either an \cs{itshape} (recommended) or a \cs{textit}
3035 % value.
3036 % \begin{macrocode}
3037 %<trace> \breqn@debugmsg{Number \eq@number}%
3038 \set@label{equation}\eq@number
3039 \global\sbox\EQ@numbox{%
3040 \next@label \global\let\next@label\@empty
3041 \eqnumcolor\eqnumsize\eqnumfont{\eqnumform{\eq@number}}%
3042 }%
3043 \global\eq@wdNum\wd\EQ@numbox\global\advance\eq@wdNum\eqnumsep
3044 % \let\eq@hasNumber\@True % locally true
3045 \fi
3046 \fi
3047 }
3048 % \end{macrocode}
3049 % \end{macro}
3050 %
3051 % \begin{macro}{\eq@finish}
3052 % The information available at this point from preliminary
3053 % measuring includes the number of lines required, the width of the
3054 % equation number, the total height of the equation body, and (most
3055 % important) the parshape spec that was used in determining height and
3056 % number of lines.
3057 %
3058 % Invoke the equation formatter for the requested centering/indentation
3059 % having worked out the best parshape.
3060 % BRM: This portion is extensively refactored to get common operations
3061 % together (so corrections get consistently applied).
3062 %
3063 % MH: I've destroyed Bruce's nice refactoring a bit to get the
3064 % abovedisplayskips correct for both groups of equations and single
3065 % \env{dmath} environments. I will have to redo that later.
3066 % \begin{macrocode}
3067 \newcount\eq@final@linecount
3068 \let\eq@GRP@first@dmath\@True
3069 \def\eq@finish{%
3070 \begingroup
3071 %<trace> \breqn@debugmsg{Formatting equation}%
3072 %<trace> \debug@showmeasurements
3073 \if F\eq@frame\else
3074 \freeze@glue\eqlinespacing \freeze@glue\eqlineskip
3075 \fi
3076 % \eq@topspace{\vskip\parskip}% Set top spacing
3077 \csname eq@\eqindent @setsides\endcsname % Compute \leftskip,\rightskip
3078 \adjust@parshape\eq@parshape% Final adjustment of parshape for left|right skips
3079 % \end{macrocode}
3080 % If we are in an a group of equations we don't want to calculate the
3081 % top space for the first one as that will be delayed until later when
3082 % the space for the group is calculated. However, we do need to store
3083 % the leftskip used here as that will be used later on for calculating
3084 % the top space.
3085 % \begin{macrocode}
3086 \if\eq@group
3087 \if\eq@GRP@first@dmath
3088 \global\let\eq@GRP@first@dmath\@False
3089 \xdef\dmath@first@leftskip{\leftskip=\the\leftskip\relax}%
3090 %<trace> \breqn@debugmsg{Stored\space\dmath@first@leftskip}
3091 \else
3092 \eq@topspace{\vskip\parskip}% Set top spacing
3093 \fi
3094 \else
3095 \eq@topspace{\vskip\parskip}% Set top spacing
3096 \fi
3097 %<trace> \debug@showformat
3098 % \end{macrocode}
3099 % We now know the final line count of the display. If it is a
3100 % single-line display, we want to know as that greatly simplifies the
3101 % equation tag placement (until such a time where this algorithm has
3102 % been straightened out).
3103 % \begin{macrocode}
3104 \afterassignment\remove@to@nnil
3105 \eq@final@linecount=\expandafter\@gobble\eq@parshape\@nnil
3106 % \end{macrocode}
3107 % Now, invoke the appropriate typesetter according to number placement
3108 % \begin{macrocode}
3109 \if\eq@hasNumber
3110 \if\eq@shiftnumber
3111 \csname eq@typeset@\eqnumside Shifted\endcsname
3112 \else
3113 % \end{macrocode}
3114 % If there is only one line and the tag doesn't have to be shifted, we
3115 % call a special procedure to put the tag correctly.
3116 % \begin{macrocode}
3117 \ifnum\eq@final@linecount=\@ne
3118 \csname eq@typeset@\eqnumside @single\endcsname
3119 \else
3120 \csname eq@typeset@\eqnumside\eqnumplace\endcsname
3121 \fi
3122 \fi
3123 \else
3124 \eq@typeset@Unnumbered
3125 \fi
3126 \endgroup
3127 \eq@botspace
3128 }
3129 % \end{macrocode}
3130 % \end{macro}
3131 %
3132 %
3133 % These are temporary until the tag position algorithm gets
3134 % rewritten. At least the tag is positioned correctly for single-line
3135 % displays. The horizontal frame position is not correct but the
3136 % problem lies elsewhere.
3137 % \begin{macrocode}
3138 \def\eq@typeset@L@single{%
3139 \nobreak
3140 \eq@params\eq@parshape
3141 \nointerlineskip
3142 % \noindent
3143 \MaybeRawNoindent
3144 \add@grp@label
3145 \rlap{\kern-\leftskip\box\EQ@numbox}%
3146 \if F\eq@frame
3147 \else
3148 \rlap{\raise\eq@firstht\hbox to\z@{\eq@addframe\hss}}%
3149 \fi
3150 \eq@dump@box\unhbox\EQ@box
3151 %\@@par
3152 \RawParEnd
3153 }
3154 \def\eq@typeset@R@single{%
3155 \nobreak
3156 \eq@params\eq@parshape
3157 \nointerlineskip
3158 % \noindent
3159 \MaybeRawNoindent
3160 \add@grp@label
3161 \if F\eq@frame
3162 \else
3163 \rlap{\raise\eq@firstht\hbox to\z@{\eq@addframe\hss}}%
3164 \fi
3165 \rlap{\kern-\leftskip\kern\linewidth\kern-\wd\EQ@numbox\copy\EQ@numbox}%
3166 \eq@dump@box\unhbox\EQ@box
3167 %\@@par
3168 \RawParEnd
3169 }
3170 % \end{macrocode}
3171 %
3172 %
3173 %
3174 % \section{Special processing for end-of-equation}
3175 %
3176 % At the end of a displayed equation environment we need to peek ahead
3177 % for two things: following punction such as period or command that
3178 % should be pulled in for inclusion at the end of the equation; and
3179 % possibly also an \verb"\end{proof}" with an implied \dquoted{qed}
3180 % symbol that is traditionally included at the end of the display rather
3181 % than typeset on a separate line.
3182 % We could require that the users type \cs{qed} explicitly at the
3183 % end of the display when they want to have the display take notice of it.
3184 % But the reason for doing that would only be to save work for the
3185 % programmer; the most natural document markup would allow an inline
3186 % equation and a displayed equation at the end of a proof to differ only
3187 % in the environment name:
3188 % \begin{literalcode}
3189 % ... \begin{math} ... \end{math}.
3190 % \end{proof}
3191 % \end{literalcode}
3192 % versus
3193 % \begin{literalcode}
3194 % ...
3195 % \begin{dmath}
3196 % ...
3197 % \end{dmath}.
3198 % \end{proof}
3199 % \end{literalcode}
3200 % .
3201 % The technical difficulties involved in supporting this markup within
3202 % \latex2e are, admittedly, nontrivial.
3203 % Nonetheless, let's see how far we can go.
3204 %
3205 %
3206 % The variations that we will support are only the most
3207 % straightforward ones:
3208 % \begin{literalcode}
3209 % \end{dmath}.
3210 % \end{proof}
3211 % \end{literalcode}
3212 % or
3213 % \begin{literalcode}
3214 % \end{dmath}.
3215 % Perhaps a comment
3216 % \end{proof}
3217 % \end{literalcode}
3218 % .
3219 % If there is anything more complicated than a space after the
3220 % period we will not attempt to scan any further for a possible
3221 % \verb"\end{proof}".
3222 % This includes material such as:
3223 % \begin{literalcode}
3224 % \begin{figure}...\end{figure}%
3225 % \footnote{...}
3226 % \renewcommand{\foo}{...}
3227 % \par
3228 % \end{literalcode}
3229 % or even a blank line\mdash because in \latex a blank line is
3230 % equivalent to \cs{par} and the meaning of \cs{par} is
3231 % \dquoted{end-paragraph}; in my opinion if explicit end-of-paragraph
3232 % markup is given before the end of an element, it has to be respected,
3233 % and the preceding paragraph has to be fully finished off before
3234 % proceeding further, even inside an element like \dquoted{proof} whose
3235 % end-element formatting requires integration with the end of the
3236 % paragraph text.
3237 % And \tex nically speaking, a \cs{par} token that comes from a
3238 % blank line and one that comes from the sequence of characters
3239 % \verb"\" \verb"p" \verb"a" \verb"r" are equally explicit.
3240 % I hope to add support for \cs{footnote} in the future, as it
3241 % seems to be a legitimate markup possibility in that context from a
3242 % purely logical point of view, but there are additional technical
3243 % complications if one wants to handle it in full generality
3244 % \begin{dn}
3245 % mjd,1999/02/08
3246 % \end{dn}
3247 % .
3248 %
3249 %
3250 % \begin{macro}{\peek@branch}
3251 % This is a generalized \dquoted{look at next token and choose some action
3252 % based on it} function.
3253 % \begin{macrocode}
3254 \def\peek@branch#1#2{%
3255 \let\peek@b#1\let\peek@space#2\futurelet\@let@token\peek@a
3256 }
3257 \def\peek@skipping@spaces#1{\peek@branch#1\peek@skip@space}
3258 \def\peek@a{%
3259 \ifx\@let@token\@sptoken \expandafter\peek@space
3260 \else \expandafter\peek@b\fi
3261 }
3262 \lowercase{\def\peek@skip@space} {\futurelet\@let@token\peek@a}%
3263 % \end{macrocode}
3264 % \end{macro}
3265 %
3266 %
3267 % \begin{macro}{\check@punct}
3268 % \changes{v0.96a}{2007/12/17}{Insert \cs{finish@end} if no special
3269 % case is found.}
3270 % For this one we need to recognize and grab for inclusion any of the
3271 % following tokens: \verb",;.!?", both catcode 12 (standard \latex
3272 % value) and catcode 13 (as might hold when the Babel package is
3273 % being used).
3274 % We do not support a space preceding the punctuation since that would
3275 % be considered simply invalid markup if a display-math environment were
3276 % demoted to in-line math; and we want to keep their markup as parallel as
3277 % possible.
3278 % If punctuation does not follow, then the \cs{check@qed} branch
3279 % is not applicable.
3280 % \begin{macrocode}
3281 \def\check@punct{\futurelet\@let@token\check@punct@a}
3282 \def\check@punct@a{%
3283 \edef\@tempa{%
3284 \ifx\@let@token\@sptoken\@nx\finish@end
3285 \else\ifx\@let@token ,\@nx\check@qed
3286 \else\ifx\@let@token .\@nx\check@qed
3287 \else\check@punct@b % check the less common possibilities
3288 \fi\fi\fi
3289 }%
3290 \@tempa
3291 }
3292 \begingroup
3293 \toks@a{%
3294 \ifx\@let@token ;\@nx\check@qed
3295 \else\ifx\@let@token ?\@nx\check@qed
3296 \else\ifx\@let@token !\@nx\check@qed
3297 }
3298 \toks@c{\fi\fi\fi}% matching with \toks@a
3299 \catcode`\.=\active \catcode`\,=\active \catcode`\;=\active
3300 \catcode`\?=\active \catcode`\!=\active
3301 \toks@b{%
3302 \else\ifx\@let@token ,\@nx\check@qed
3303 \else\ifx\@let@token .\@nx\check@qed
3304 \else\ifx\@let@token ;\@nx\check@qed
3305 \else\ifx\@let@token ?\@nx\check@qed
3306 \else\ifx\@let@token !\@nx\check@qed
3307 \else\@nx\finish@end
3308 \fi\fi\fi\fi\fi
3309 }
3310 \xdef\check@punct@b{%
3311 \the\toks@a\the\toks@b\the\toks@c
3312 }
3313 \endgroup
3314 % \end{macrocode}
3315 %
3316 % \begin{macrocode}
3317 \let\found@punct\@empty
3318 \def\check@qed#1{%
3319 \gdef\found@punct{#1}%
3320 \peek@skipping@spaces\check@qed@a
3321 }
3322 \def\check@qed@a{%
3323 \ifx\end\@let@token \@xp\check@qed@b
3324 \else \@xp\finish@end
3325 \fi
3326 }
3327 % \end{macrocode}
3328 % For each environment ENV that takes an implied qed at the end, the
3329 % control sequence ENVqed must be defined; and it must include suitable
3330 % code to yield the desired results in a displayed equation.
3331 % \begin{macrocode}
3332 \def\check@qed@b#1#2{%
3333 \@ifundefined{#2qed}{}{%
3334 \toks@\@xp{\found@punct\csname#2qed\endcsname}%
3335 \xdef\found@punct{\the\toks@}%
3336 }%
3337 \finish@end
3338 \end{#2}%
3339 }
3340 % \end{macrocode}
3341 % \end{macro}
3342 %
3343 %
3344 % \begin{macro}{\latex@end}
3345 % \begin{macro}{\finish@end}
3346 % The lookahead for punctuation following a display requires
3347 % mucking about with the normal operation of \cn{end}. Although
3348 % this is not exactly something to be done lightly, on the other hand this
3349 % whole package is so over-the-top anyway, what's a little more
3350 % going to hurt? And rationalizing this aspect of
3351 % equation markup is a worthy cause. Here is the usual
3352 % definition of \cs{end}.
3353 % \begin{literalcode}
3354 % \def\end#1{
3355 % \csname end#1\endcsname \@checkend{#1}%
3356 % \expandafter\endgroup\if@endpe\@doendpe\fi
3357 % \if@ignore \global\@ignorefalse \ignorespaces \fi
3358 % }
3359 % \end{literalcode}
3360 % We can improve the chances of this code surviving through future
3361 % minor changes in the fundamental definition of \cs{end} by taking a
3362 % little care in saving the original meaning.
3363 % \begin{macrocode}
3364 \def\@tempa#1\endcsname#2\@nil{\def\latex@end##1{#2}}
3365 \ifcsname end \endcsname
3366 % 2019: \end was made robust
3367 \expandafter\expandafter\expandafter\@tempa\csname end \endcsname{#1}\@nil
3368 \@namedef{end }#1{\csname end#1\endcsname \latex@end{#1}}%
3369 \else
3370 % pre-2019: the old approach
3371 \expandafter\@tempa\end{#1}\@nil
3372 \def\end#1{\csname end#1\endcsname \latex@end{#1}}%
3373 \fi
3374 % \end{macrocode}
3375 % Why don't we call \cs{CheckCommand} here? Because that
3376 % doesn't help end users much; it works better to use it during package
3377 % testing by the maintainer.
3378 %
3379 % Note to self: I always forget how this redefinition works. Here's a summary.
3380 % The approach is:
3381 % \begin{verbatim}
3382 % \def\enddmath#1{\check@punct@or@qed}
3383 % \end{verbatim}
3384 % When hitting the end of the dmath environment we then have:
3385 % \begin{verbatim}
3386 % \csname end#1\endcsname \latex@end{#1}
3387 % \enddmath \latex@end{dmath}
3388 % \check@punct@or@qed {dmath} % <- \enddmath absorbs one arg
3389 % \xdef\found@punct{\@empty}\def\finish@end{\csname end@dmath\endcsname\latex@end{dmath}}\check@punct
3390 % \end{verbatim}
3391 % At which point \verb|\check@punct| is `past' the end of the environment and can look ahead.
3392 %
3393 %
3394 % If a particular environment needs to call a different end action, the
3395 % end command of the environment should be defined to gobble two args and
3396 % then call a function like \cs{check@punct@or@qed}.
3397 % \begin{macrocode}
3398 \def\check@punct@or@qed#1{%
3399 \xdef\found@punct{\@empty}% BRM: punctuation was being remembered past this eqn.
3400 % WSPR: err, why isn't that just \global\let\found@punct\@empty ?
3401 \def\finish@end{\csname end@#1\endcsname\latex@end{#1}}%
3402 \check@punct
3403 }
3404 % \end{macrocode}
3405 % \end{macro}
3406 % \end{macro}
3407 %
3408 % \begin{macro}{\eqpunct}
3409 % User-settable function for handling
3410 % the punctuation at the end of an equation. You could, for example,
3411 % define it to just discard the punctuation.
3412 % \begin{macrocode}
3413 \newcommand\eqpunct[1]{\thinspace#1}
3414 % \end{macrocode}
3415 % \end{macro}
3416 %
3417 % \begin{macro}{\set@label}
3418 % \cs{set@label} just sets \cs{@currentlabel} but it
3419 % takes the counter as an argument, in the hope that \latex will some
3420 % day provide an improved labeling system that includes type info on the
3421 % labels.
3422 % \begin{macrocode}
3423 \providecommand\set@label[2]{\protected@edef\@currentlabel{#2}}
3424 % \end{macrocode}
3425 % \end{macro}
3426 %
3427 % \begin{macro}{\eq@topspace}
3428 % \begin{macro}{\eq@botspace}
3429 % The action of \cs{eq@topspace} is complicated by the
3430 % need to test whether the \quoted{short} versions of the display skips
3431 % should be used. This can be done only after the final parshape
3432 % and indent have been determined, so the calls of this function are
3433 % buried relatively deeply in the code by comparison to the calls of
3434 % \cs{eq@botspace}. This also allows us to optimize
3435 % slightly by setting the above-skip with \cs{parskip} instead of
3436 % \cs{vskip}. \verb|#1| is either \cs{noindent} or
3437 % \verb"\vskip\parskip".
3438 %
3439 % BRM: Hmm; we need to do *@setspace BEFORE this for small skips to work!
3440 % \begin{macrocode}
3441 \def\eq@topspace#1{%
3442 \begingroup
3443 \global\let\EQ@shortskips\@False
3444 % \end{macrocode}
3445 % If we are in \env{dgroup} or \env{dgroup*} and not before the top
3446 % one, we just insert \cs{intereqskip}. Otherwise we must check for
3447 % shortskip.
3448 % \begin{macrocode}
3449 \if\@And{\eq@group}{\@Not\eq@GRP@first@dmath}%
3450 %<trace>\breqn@debugmsg{Between lines}%
3451 \parskip\intereqskip \penalty\intereqpenalty
3452 %<trace>\breqn@debugmsg{parskip=\the\parskip}%
3453 \else
3454 \eq@check@shortskip
3455 \if\EQ@shortskips
3456 \parskip\abovedisplayshortskip
3457 \aftergroup\belowdisplayskip\aftergroup\belowdisplayshortskip
3458 % \end{macrocode}
3459 % BRM: Not exactly \TeX's approach, but seems right\ldots
3460 % \begin{macrocode}
3461 \ifdim\predisplaysize>\z@\nointerlineskip\fi
3462 \else
3463 \parskip\abovedisplayskip
3464 \fi
3465 \fi
3466 \if F\eq@frame
3467 \else
3468 \addtolength\parskip{\eq@framesep+\eq@framewd}%
3469 \fi
3470 %<*trace>
3471 \breqn@debugmsg{Topspace: \theb@@le\EQ@shortskips, \parskip=\the\parskip,
3472 \predisplaysize=\the\predisplaysize}%
3473 %</trace>
3474 #1%
3475 \endgroup
3476 }
3477 % \end{macrocode}
3478 % \begin{macro}{\eq@check@shortskip}
3479 % \changes{v0.96a}{2007/12/17}{Insert \cs{finish@end} if no special
3480 % case is found.}
3481 % \changes{v0.97a}{2007/12/22}{Use design parameter and fix
3482 % shortskips properly.}
3483 % \begin{macrocode}
3484 \def\eq@check@shortskip {%
3485 \global\let\EQ@shortskips\@False
3486 \setlength\dim@a{\abovedisplayskip+\ht\EQ@numbox}%
3487 % \end{macrocode}
3488 % Here we work around the hardwired standard TeX value and use the
3489 % designer parameter instead.
3490 % \begin{macrocode}
3491 \ifdim\leftskip<\predisplaysize
3492 \else
3493 % \end{macrocode}
3494 % If the display was preceeded by a blank line, \cs{predisplaysize} is
3495 % $-\cs{maxdimen}$ and so we should insert a fairly large skip to
3496 % separate paragraphs, i.e., no short skip. Perhaps this should be a
3497 % third parameter \cs{abovedisplayparskip}.
3498 % \begin{macrocode}
3499 \ifdim -\maxdimen=\predisplaysize
3500 \else
3501 \if R\eqnumside
3502 \global\let\EQ@shortskips\@True
3503 \else
3504 \if\eq@shiftnumber
3505 \else
3506 \if T\eqnumplace
3507 \ifdim\dim@a<\eq@firstht
3508 \global\let\EQ@shortskips\@True
3509 \fi
3510 \else
3511 \setlength\dim@b{\eq@vspan/2}%
3512 \ifdim\dim@a<\dim@b
3513 \global\let\EQ@shortskips\@True
3514 \fi
3515 \fi
3516 \fi
3517 \fi
3518 \fi
3519 \fi
3520 }
3521 % \end{macrocode}
3522 % \end{macro}
3523 %
3524 % At the end of an equation, need to put in a pagebreak penalty
3525 % and some vertical space. Also set some flags to remove parindent
3526 % and extra word space if the current paragraph text continues without an
3527 % intervening \cs{par}.
3528 % \begin{macrocode}
3529 \def\eq@botspace{%
3530 \penalty\postdisplaypenalty
3531 % \end{macrocode}
3532 % Earlier calculations will have set \cs{belowdisplayskip} locally
3533 % to \cs{belowdisplayshortskip} if applicable. So we can just use
3534 % it here.
3535 % \begin{macrocode}
3536 \if F\eq@frame
3537 \else
3538 \addtolength\belowdisplayskip{\eq@framesep+\eq@framewd}%
3539 \fi
3540 \vskip\belowdisplayskip
3541 \@endpetrue % kill parindent if current paragraph continues
3542 \global\@ignoretrue % ignore following spaces
3543 \eq@resume@parshape
3544 }
3545 % \end{macrocode}
3546 % \end{macro}
3547 % \end{macro}
3548 %
3549 % \begin{macro}{\eq@resume@parshape}
3550 % This should calculate the total height of the equation,
3551 % including space above and below, and set prevgraf to the number it would
3552 % be if that height were taken up by normally-spaced normal-height
3553 % lines. We also need to restore parshape if it had a non-null
3554 % value before the equation. Not implemented yet.
3555 % \begin{macrocode}
3556 \def\eq@resume@parshape{}
3557 % \end{macrocode}
3558 % \end{macro}
3559 %
3560 % \section{Preprocessing the equation body}
3561 % \begin{macro}{\eq@startup}
3562 % Here is the function that initially collects the equation
3563 % material in a box.
3564 %
3565 % \begin{macrocode}
3566 \def\eq@startup{%
3567 \global\let\EQ@hasLHS\@False
3568 \setbox\z@\vbox\bgroup
3569 % \noindent
3570 \MaybeRawNoindent % no matching \RawParEnd (implicit at box end)
3571 \@@math \displaystyle
3572 \penalty-\@Mi
3573 }
3574 % \end{macrocode}
3575 %
3576 % This setup defines the environment for the first typesetting
3577 % pass, note the \cs{hsize} value for example.
3578 % \begin{macrocode}
3579 \def\eq@setup@a{%
3580 \everymath\everydisplay
3581 %\let\@newline\eq@newline % future possibility?
3582 \let\\\eq@newline
3583 \let\insert\eq@insert \let\mark\eq@mark \let\vadjust\eq@vadjust
3584 \hsize\maxdimen \pretolerance\@M
3585 % \end{macrocode}
3586 % Here it is better not to use \cs{@flushglue} (0pt
3587 % plus1fil) for \cs{rightskip}, or else a negative penalty
3588 % (such as $-99$ for \cs{prerelpenalty}) will tempt
3589 % \tex to use more line breaks than necessary in the first typesetting
3590 % pass. Ideal values for \cs{rightskip} and
3591 % \cs{linepenalty} are unclear to me, but they are rather sensitively
3592 % interdependent. Choice of 10000 pt for rightskip is derived by
3593 % saying, let's use a value smaller than 1 fil and smaller than
3594 % \cs{hsize}, but more than half of \cs{hsize} so that if a line
3595 % is nearly empty, the glue stretch factor will always be less than 2.0
3596 % and so the badness will be less than 100 and so \tex will not issue
3597 % badness warnings.
3598 % \begin{macrocode}
3599 \linepenalty\@m
3600 \rightskip\z@\@plus\@M\p@ \leftskip\z@skip \parfillskip\z@skip
3601 \clubpenalty\@ne \widowpenalty\z@ \interlinepenalty\z@
3602 % \end{macrocode}
3603 % After a relation symbol is discovered, binop symbols should start
3604 % including a special offset space.
3605 % But until then \cs{EQ@prebin@space} is a no-op.
3606 % \begin{macrocode}
3607 \global\let\EQ@prebin@space\relax
3608 % \end{macrocode}
3609 % Set binoppenalty and relpenalty high to prohibit line breaks
3610 % after mathbins and mathrels. As a matter of fact, the penalties are
3611 % then omitted by \tex , since bare glue without a penalty is
3612 % \emph{not} a valid breakpoint if it occurs within
3613 % mathon\ndash mathoff items.
3614 % \begin{macrocode}
3615 \binoppenalty\@M \relpenalty\@M
3616 }
3617 % \end{macrocode}
3618 % \end{macro}
3619 %
3620 %
3621 % \begin{figure}
3622 % \centering
3623 % The contents of an equation after the initial typesetting pass,
3624 % as shown by \cs{showlists}. This is the material on which the
3625 % \cs{eq@repack} function operates. The equation was
3626 % \begin{literalcode}
3627 % a=b +\left(\frac{c\sp 2}{2} -d\right) +(e -f) +g
3628 % \end{literalcode}
3629 % . The contents are shown in four parts in this figure and the next
3630 % three. The first part contains two line boxes, one for the mathon
3631 % node and one for the LHS.
3632 % \begin{literalcode}
3633 % \hbox(0.0+0.0)x16383.99998, glue set 1.6384
3634 % .\mathon
3635 % .\penalty -10000
3636 % .\glue(\rightskip) 0.0 plus 10000.0
3637 % \penalty 1
3638 % \glue(\baselineskip) 7.69446
3639 % \hbox(4.30554+0.0)x16383.99998, glue set 1.63759
3640 % .\OML/cmm/m/it/10 a
3641 % .\glue 2.77771 minus 1.11108
3642 % .\penalty -10001
3643 % .\glue(\rightskip) 0.0 plus 10000.0
3644 % \penalty 2
3645 % \glue(\lineskip) 1.0
3646 % ...
3647 % \end{literalcode}
3648 % \caption{Preliminary equation contents, part 1}
3649 % \end{figure}
3650 % \begin{figure}\centering
3651 % This is the first part of the RHS, up to the
3652 % \cs{right}, where a line break has been forced so that we can break
3653 % open the left-right box.
3654 % \begin{literalcode}
3655 % ...
3656 % \penalty 2
3657 % \glue(\lineskip) 1.0
3658 % \hbox(14.9051+9.50012)x16383.99998, glue set 1.63107
3659 % .\penalty -99
3660 % .\glue(\thickmuskip) 2.77771 minus 1.11108
3661 % .\OT1/cmr/m/n/10 =
3662 % .\glue(\thickmuskip) 2.77771 minus 1.11108
3663 % .\OML/cmm/m/it/10 b
3664 % .\penalty 888
3665 % .\glue -10.5553
3666 % .\rule(*+*)x0.0
3667 % .\penalty 10000
3668 % .\glue 10.5553
3669 % .\glue(\medmuskip) 2.22217 minus 1.66663
3670 % .\OT1/cmr/m/n/10 +
3671 % .\glue(\medmuskip) 2.22217 minus 1.66663
3672 % .\hbox(14.9051+9.50012)x43.36298
3673 % ..\hbox(0.39998+23.60025)x7.36115, shifted -14.10013
3674 % ...\OMX/cmex/m/n/5 \hat \hat R
3675 % ..\hbox(14.9051+6.85951)x11.21368
3676 % ...\hbox(14.9051+6.85951)x11.21368
3677 % ... [fraction contents, elided]
3678 % ..\penalty 5332
3679 % ..\glue -10.5553
3680 % ..\rule(*+*)x0.0
3681 % ..\penalty 10000
3682 % ..\glue 10.5553
3683 % ..\glue(\medmuskip) 2.22217 minus 1.66663
3684 % ..\OMS/cmsy/m/n/10 \hat \hat @
3685 % ..\glue(\medmuskip) 2.22217 minus 1.66663
3686 % ..\OML/cmm/m/it/10 d
3687 % ..\hbox(0.39998+23.60025)x7.36115, shifted -14.10013
3688 % ...\OMX/cmex/m/n/5 \hat \hat S
3689 % .\penalty -10000
3690 % .\glue(\rightskip) 0.0 plus 10000.0
3691 % \penalty 3
3692 % \glue(\lineskip) 1.0
3693 % ...
3694 % \end{literalcode}
3695 % \caption{Preliminary equation contents, part 2}
3696 % \end{figure}
3697 %
3698 % \begin{figure}
3699 % \centering
3700 % This is the remainder of the RHS after the post-\cs{right}
3701 % split.
3702 % \begin{literalcode}
3703 % ...
3704 % \penalty 3
3705 % \glue(\lineskip) 1.0
3706 % \hbox(7.5+2.5)x16383.99998, glue set 1.63239
3707 % .\penalty 888
3708 % .\glue -10.5553
3709 % .\rule(*+*)x0.0
3710 % .\penalty 10000
3711 % .\glue 10.5553
3712 % .\glue(\medmuskip) 2.22217 minus 1.66663
3713 % .\OT1/cmr/m/n/10 +
3714 % .\glue(\medmuskip) 2.22217 minus 1.66663
3715 % .\OT1/cmr/m/n/10 (
3716 % .\OML/cmm/m/it/10 e
3717 % .\penalty 5332
3718 % .\glue -10.5553
3719 % .\rule(*+*)x0.0
3720 % .\penalty 10000
3721 % .\glue 10.5553
3722 % .\glue(\medmuskip) 2.22217 minus 1.66663
3723 % .\OMS/cmsy/m/n/10 \hat \hat @
3724 % .\glue(\medmuskip) 2.22217 minus 1.66663
3725 % .\OML/cmm/m/it/10 f
3726 % .\kern1.0764
3727 % .\OT1/cmr/m/n/10 )
3728 % .\penalty 888
3729 % .\glue -10.5553
3730 % .\rule(*+*)x0.0
3731 % .\penalty 10000
3732 % .\glue 10.5553
3733 % .\glue(\medmuskip) 2.22217 minus 1.66663
3734 % .\OT1/cmr/m/n/10 +
3735 % .\glue(\medmuskip) 2.22217 minus 1.66663
3736 % .\OML/cmm/m/it/10 g
3737 % .\kern0.35878
3738 % .\penalty -10000
3739 % .\glue(\rightskip) 0.0 plus 10000.0
3740 % \glue(\baselineskip) 9.5
3741 % ...
3742 % \end{literalcode}
3743 % \caption{Preliminary equation contents, part 3}
3744 % \end{figure}
3745 %
3746 % \begin{figure}
3747 % \centering
3748 % This is the mathoff fragment.
3749 % \begin{literalcode}
3750 % ...
3751 % \glue(\baselineskip) 9.5
3752 % \hbox(0.0+0.0)x16383.99998, glue set 1.6384
3753 % .\mathoff
3754 % .\penalty 10000
3755 % .\glue(\parfillskip) 0.0
3756 % .\glue(\rightskip) 0.0 plus 10000.0
3757 % \end{literalcode}
3758 % \caption{Preliminary equation contents, part 4}
3759 % \end{figure}
3760 %
3761 % \begin{macro}{\eq@capture}
3762 % \begin{macro}{\eq@punct}
3763 % If an equation ends with a \cs{right} delim, the last thing
3764 % on the math list will be a force-break penalty. Then don't
3765 % redundantly add another forcing penalty. (question: when does a
3766 % penalty after a linebreak not disappear? Answer: when you have
3767 % two forced break penalties in a row). Ending punctuation, if
3768 % any, goes into the last box with the mathoff kern. If the math list
3769 % ends with a slanted letter, then there will be an italic correction
3770 % added after it by \tex . Should we remove it? I guess
3771 % so.
3772 %
3773 %
3774 % \subsection{Capturing the equation}
3775 %
3776 % BRM: There's a problem here (or with \cs{ss@scan}). If the LHS has
3777 % \cs{left} \cs{right} pairs, \cs{ss@scan} gets involved. It seems to produce
3778 % a separate box marked w/\cs{penalty} 3. But it appears that \cs{eq@repack}
3779 % is only expecting a single box for the LHS; when it measures that
3780 % box it's missing the (typically larger) bracketted section,
3781 % so the LHS is measured => 0pt (or very small).
3782 % I'm not entirely clear what Michael had in mind for this case;
3783 % whether it's an oversight, or whether I've introduced some other bug.
3784 % At any rate, my solution is to measure the RHS (accumulated in \cs{EQ@box}),
3785 % at the time of the relation, and subtract that from the total size.
3786 % \begin{macrocode}
3787 \newdimen\eq@wdR\eq@wdR\z@%BRM
3788 \def\eq@capture{%
3789 \ifnum\lastpenalty>-\@M \penalty-\@Mi \fi
3790 % \end{macrocode}
3791 % We want to keep the mathoff kern from vanishing at the line break,
3792 % so that we can reuse it later.
3793 % \begin{macrocode}
3794 \keep@glue\@@endmath
3795 \eq@addpunct
3796 \@@par
3797 \eq@wdL\z@
3798 % \end{macrocode}
3799 % First snip the last box, which contains the mathoff node, and put it
3800 % into \cs{EQ@box}. Then when we call \cs{eq@repack} it
3801 % will recurse properly.
3802 % \begin{macrocode}
3803 \setbox\tw@\lastbox
3804 \global\setbox\EQ@box\hbox{\unhbox\tw@\unskip\unskip\unpenalty}%
3805 \unskip\unpenalty
3806 \global\setbox\EQ@copy\copy\EQ@box
3807 %% \global\setbox\EQ@vimcopy\copy\EQ@vimbox
3808 \clubpenalty\z@
3809 %\batchmode\showboxbreadth\maxdimen\showboxdepth99\showlists\errorstopmode
3810 \eq@wdR\z@%BRM: eq@wdL patch
3811 \eq@repack % recursive
3812 % \end{macrocode}
3813 % Finally, add the mathon item to \cs{EQ@box} and \cs{EQ@copy}.
3814 % \begin{macrocode}
3815 \setbox\tw@\lastbox
3816 \global\setbox\EQ@box\hbox{\unhcopy\tw@\unskip\unpenalty \unhbox\EQ@box}%
3817 \global\setbox\EQ@copy\hbox{\unhbox\tw@\unskip\unpenalty \unhbox\EQ@copy}%
3818 %\batchmode\showbox\EQ@copy \showthe\eq@wdL\errorstopmode
3819 \ifdim\eq@wdR>\z@% BRM: eq@wdL patch
3820 \setlength\dim@a{\wd\EQ@box-\eq@wdR
3821 % Apparently missing a \thickmuskip = 5mu = 5/18em=0.27777777777.. ?
3822 + 0.2777777777777em}% FUDGE??!?!?!
3823 \ifdim\dim@a>\eq@wdL
3824 %<*trace>
3825 \breqn@debugmsg{Correcting LHS from \the\eq@wdL\space to
3826 \the\dim@a = \the\wd\EQ@box - \the\eq@wdR}%
3827 %</trace>
3828 \eq@wdL\dim@a
3829 \xdef\EQ@setwdL{\eq@wdL\the\eq@wdL\relax}%
3830 \fi
3831 \fi
3832 %<*trace>
3833 \breqn@debugmsg{Capture: total length=\the\wd\EQ@box \MessageBreak
3834 ==== has LHS=\theb@@le\EQ@hasLHS, \eq@wdL=\the\eq@wdL, \eq@wdR=\the\eq@wdR,
3835 \MessageBreak
3836 ==== \eq@wdCond=\the\eq@wdCond}%
3837 %</trace>
3838 \egroup % end vbox started earlier
3839 %<*trace>
3840 %\debugwr{EQ@box}\debug@box\EQ@box
3841 %\debugwr{EQ@copy}\debug@box\EQ@copy
3842 %</trace>
3843 }
3844 % \end{macrocode}
3845 % Now we have two copies of the equation, one in \cs{EQ@box},
3846 % and one in \cs{EQ@copy} with inconvenient stuff like inserts and
3847 % marks omitted.
3848 %
3849 % \cs{eq@addpunct} is for tacking on text punctuation at the end
3850 % of a display, if any was captured by the \quoted{gp} lookahead.
3851 % \begin{macrocode}
3852 \def\eq@addpunct{%
3853 \ifx\found@punct\@empty
3854 \else \eqpunct{\found@punct}%
3855 \fi
3856 % BRM: Added; the punctuation kept getting carried to following environs
3857 \xdef\found@punct{\@empty}%
3858 \EQ@afterspace
3859 }
3860 % \end{macrocode}
3861 % Needed for the \env{dseries} environment, among other things.
3862 % \begin{macrocode}
3863 \global\let\EQ@afterspace\@empty
3864 % \end{macrocode}
3865 % \end{macro}
3866 % \end{macro}
3867 %
3868 % \begin{macro}{\eq@repack}
3869 % The \cs{eq@repack} function looks at the information at hand
3870 % and proceeds accordingly.
3871 %
3872 % TeX Note: this scans BACKWARDS from the end of the math.
3873 % \begin{macrocode}
3874 \def\eq@repack{%
3875 % A previous penalty of 3 on the vertical list means that we need
3876 % to break open a left-right box.
3877 % \begin{macrocode}
3878 \ifcase\lastpenalty
3879 % case 0: normal case
3880 \setbox\tw@\lastbox
3881 \eq@repacka\EQ@copy \eq@repacka\EQ@box
3882 \unskip
3883 \or % case 1: finished recursing
3884 % \end{macrocode}
3885 % Grab the mathon object since we need it to inhibit line breaking at
3886 % bare glue nodes later.
3887 % \begin{macrocode}
3888 \unpenalty
3889 \setbox\tw@\lastbox
3890 \eq@repacka\EQ@copy \eq@repacka\EQ@box
3891 \@xp\@gobble
3892 \or % case 2: save box width = LHS width
3893 % \end{macrocode}
3894 % Don't need to set \cs{EQ@hasLHS} here because it was set earlier
3895 % if applicable.
3896 % \begin{macrocode}
3897 \unpenalty
3898 \setbox\tw@\lastbox
3899 \setbox\z@\copy\tw@ \setbox\z@\hbox{\unhbox\z@\unskip\unpenalty}%
3900 \addtolength\eq@wdL{\wd\z@}
3901 \setlength\eq@wdR{\wd\EQ@box}% BRM: eq@wdL patch
3902 \xdef\EQ@setwdL{\eq@wdL\the\eq@wdL\relax}%
3903 % \end{macrocode}
3904 % At this point, box 2 typically ends with
3905 % \begin{literalcode}
3906 % .\mi10 a
3907 % .\glue 2.77771 plus 2.77771
3908 % .\penalty -10001
3909 % .\glue(\rightskip) 0.0 plus 10000.0
3910 % \end{literalcode}
3911 % and we want to ensure that the thickmuskip glue gets removed.
3912 % And we now arrange for \cs{EQ@copy} and \cs{EQ@box} to
3913 % keep the LHS in a separate subbox; this is so that we can introduce a
3914 % different penalty before the first relation symbol if necessary,
3915 % depending on the layout decisions that are made later.
3916 % \begin{macrocode}
3917 \global\setbox\EQ@copy\hbox{%
3918 \hbox{\unhcopy\tw@\unskip\unpenalty\unskip}%
3919 \box\EQ@copy
3920 }%
3921 \global\setbox\EQ@box\hbox{%
3922 \hbox{\unhbox\tw@\unskip\unpenalty\unskip}%
3923 \box\EQ@box
3924 }%
3925 \unskip
3926 \or % case 3: unpack left-right box
3927 \unpenalty
3928 \eq@lrunpack
3929 \else
3930 \breqn@repack@err
3931 \fi
3932 \eq@repack % RECURSE
3933 }
3934 % \end{macrocode}
3935 % Error message extracted to streamline calling function.
3936 % \begin{macrocode}
3937 \def\breqn@repack@err{%
3938 \PackageError{breqn}{eq@repack penalty neq 0,1,2,3}\relax
3939 }
3940 % \end{macrocode}
3941 % \end{macro}
3942 %
3943 %
3944 % \begin{macro}{\eq@repacka}
3945 % We need to transfer each line into two separate boxes, one
3946 % containing everything and one that omits stuff like \cs{insert}s
3947 % that would interfere with measuring.
3948 % \begin{macrocode}
3949 \def\eq@repacka#1{%
3950 \global\setbox#1\hbox{\unhcopy\tw@ \unskip
3951 \count@-\lastpenalty
3952 \ifnum\count@<\@M \else \advance\count@-\@M \fi
3953 \unpenalty
3954 % \end{macrocode}
3955 % If creating the measure copy, ignore all cases above case 3 by
3956 % folding them into case 1.
3957 % \begin{macrocode}
3958 \ifx\EQ@copy#1\ifnum\count@>\thr@@ \count@\@ne\fi\fi
3959 \ifcase\count@
3960 % case 0, normal line break
3961 \penalty-\@M % put back the linebreak penalty
3962 \or % case 1, do nothing (end of equation)
3963 \relax
3964 \or % case 2, no-op (obsolete case)
3965 \or % case 3, transfer vspace and/or penalty
3966 \ifx#1\EQ@box \eq@revspace \else \eq@revspaceb \fi
3967 \or % case 4, put back an insert
3968 \eq@reinsert
3969 \or % case 5, put back a mark
3970 \eq@remark
3971 \or % case 6, put back a vadjust
3972 \eq@readjust
3973 \else % some other break penalty
3974 \penalty-\count@
3975 \fi
3976 \unhbox#1}%
3977 }
3978 % \end{macrocode}
3979 % \end{macro}
3980 %
3981 %
3982 % \begin{macro}{\eq@nulldisplay}
3983 % Throw in a null display in order to get predisplaysize \etc .
3984 % My original approach here was to start the null display, then measure
3985 % the equation, and set a phantom of the equation's first line before
3986 % ending the null display. That would allow finding out if \tex used
3987 % the short displayskips instead of the normal ones. But because of
3988 % some complications with grouping and the desirability of omitting
3989 % unnecessary invisible material on the vertical list, it seems better to
3990 % just collect information about the display (getting \cs{prevdepth}
3991 % requires \cs{halign}) and manually perform our own version of
3992 % \TeX's shortskip calculations. This approach also gives greater
3993 % control, \eg , the threshold amount of horizontal space between
3994 % predisplaysize and the equation's left edge that determines when the
3995 % short skips kick in becomes a designer-settable parameter rather than
3996 % hardwired into \TeX .
3997 % \begin{macrocode}
3998 \def\eq@nulldisplay{%
3999 \begingroup \frozen@everydisplay\@emptytoks
4000 \@@display
4001 \predisplaypenalty\@M \postdisplaypenalty\@M
4002 \abovedisplayskip\z@skip \abovedisplayshortskip\z@skip
4003 \belowdisplayskip\z@skip \belowdisplayshortskip\z@skip
4004 \xdef\EQ@displayinfo{%
4005 \prevgraf\the\prevgraf \predisplaysize\the\predisplaysize
4006 \displaywidth\the\displaywidth \displayindent\the\displayindent
4007 \listwidth\the\linewidth
4008 % \end{macrocode}
4009 % Not sure how best to test whether leftmargin should be
4010 % added. Let's do this for now [mjd,1997/10/08].
4011 % \begin{macrocode}
4012 \ifdim\displayindent>\z@
4013 \advance\listwidth\the\leftmargin
4014 \advance\listwidth\the\rightmargin
4015 \fi
4016 \relax}%
4017 % \end{macrocode}
4018 % An \cs{halign} containing only one \cs{cr} (for the
4019 % preamble) puts no box on the vertical list, which means that no
4020 % \cs{baselineskip} will be added (so we didn't need to set it to
4021 % zero) and the previous value of prevdepth carries through. Those
4022 % properties do not hold for an empty simple equation without
4023 % \cs{halign}.
4024 % \begin{macrocode}
4025 \halign{##\cr}%
4026 \@@enddisplay
4027 \par
4028 \endgroup
4029 \EQ@displayinfo
4030 }
4031 % \end{macrocode}
4032 % \end{macro}
4033 %
4034 %
4035 % \begin{macro}{\eq@newline}
4036 % \begin{macro}{\eq@newlinea}
4037 % \begin{macro}{\eq@newlineb}
4038 % Here we use \cs{@ifnext} so that in a sequence like
4039 % \begin{literalcode}
4040 % ...\\
4041 % [a,b]
4042 % \end{literalcode}
4043 % \latex does not attempt to interpret the \verb"[a,b]" as a
4044 % vertical space amount. We would have used \cs{eq@break} in the
4045 % definition of \cs{eq@newlineb} except that it puts in a
4046 % \cs{keep@glue} object which is not such a good idea if a mathbin
4047 % symbol follows \mdash the indent of the mathbin will be wrong because
4048 % the leading negative glue will not disappear as it should at the line
4049 % break.
4050 % \begin{macrocode}
4051 \def\eq@newline{%
4052 \breqn@ifstar{\eq@newlinea\@M}{\eq@newlinea\eqinterlinepenalty}}
4053 \def\eq@newlinea#1{%
4054 \@ifnext[{\eq@newlineb{#1}}{\eq@newlineb{#1}[\maxdimen]}}
4055 \def\eq@newlineb#1[#2]{\penalty-\@M}
4056 % \end{macrocode}
4057 % \end{macro}
4058 % \end{macro}
4059 % \end{macro}
4060 %
4061 %
4062 % \begin{macro}{\eq@revspace}
4063 % \begin{macro}{\eq@revspaceb}
4064 % When \cs{eq@revspace} (re-vspace) is called, we are the
4065 % end of an equation line; we need to remove the existing penalty of
4066 % $-10002$ in order to put a vadjust object in front of it, then put
4067 % back the penalty so that the line break will still take place in the
4068 % final result.
4069 % \begin{macrocode}
4070 \def\eq@revspace{%
4071 \global\setbox\EQ@vimbox\vbox{\unvbox\EQ@vimbox
4072 \unpenalty
4073 \global\setbox\@ne\lastbox}%
4074 \@@vadjust{\unvbox\@ne}%
4075 \penalty-\@M
4076 }
4077 % \end{macrocode}
4078 % The b version is used for the \cs{EQ@copy} box.
4079 % \begin{macrocode}
4080 \def\eq@revspaceb{%
4081 \global\setbox\EQ@vimcopy\vbox{\unvbox\EQ@vimcopy
4082 \unpenalty
4083 \global\setbox\@ne\lastbox}%
4084 \@@vadjust{\unvbox\@ne}%
4085 \penalty-\@M
4086 }
4087 % \end{macrocode}
4088 % \end{macro}
4089 % \end{macro}
4090 %
4091 %
4092 % \begin{macro}{\eq@break}
4093 % The function \cs{eq@break} does a preliminary linebreak with
4094 % a flag penalty.
4095 % \begin{macrocode}
4096 \def\eq@break#1{\penalty-1000#1 \keep@glue}
4097 % \end{macrocode}
4098 % \end{macro}
4099 %
4100 %
4101 %
4102 %
4103 % \section{Choosing optimal line breaks}
4104 % The question of what line width to use when breaking an
4105 % equation into several lines is best examined in the light of an extreme
4106 % example. Suppose we have a two-column layout and a displayed
4107 % equation falls inside a second-level list with nonzero leftmargin and
4108 % rightmargin. Then we want to try in succession a number of
4109 % different possibilities. In each case if the next possibility is
4110 % no wider than the previous one, skip ahead to the one after.
4111 % \begin{enumerate}
4112 % \item First try linewidth(2), the linewidth for the current
4113 % level-2 list.
4114 %
4115 %
4116 % \item If we cannot find adequate linebreaks at that width, next try
4117 % listwidth(2), the sum of leftmargin, linewidth, and rightmargin for
4118 % the current list.
4119 %
4120 %
4121 % \item If we cannot find linebreaks at that width, next try linewidth
4122 % (1) (skipping this step if it is no larger then
4123 % listwidth(2)).
4124 %
4125 %
4126 % \item If we cannot find linebreaks at that width, next try
4127 % listwidth(1).
4128 %
4129 %
4130 % \item If we cannot find linebreaks at that width, next try column
4131 % width.
4132 %
4133 %
4134 % \item If we cannot find linebreaks at that width, next try text
4135 % width.
4136 %
4137 %
4138 % \item If we cannot find linebreaks at that width, next try equation
4139 % width, if it exceeds text width (\ie , if the style allows equations
4140 % to extend into the margins).
4141 %
4142 %
4143 % \end{enumerate}
4144 %
4145 %
4146 % \begin{figure}
4147 % \centering
4148 % needs work
4149 % \caption{first-approximation parshape for equations}\label{f:parshape-1}
4150 % \end{figure}
4151 %
4152 % At any given line width, we run through a series of parshape
4153 % trials and, essentially, use the first one that gives decent line
4154 % breaks.
4155 % But the process is a bit more complicated in fact.
4156 % In order to do a really good job of setting up the parshapes, we
4157 % need to know how many lines the equation will require.
4158 % And of course the number of lines needed depends on the parshape!
4159 % So as our very first trial we run a simple first-approximation
4160 % parshape (Figure~\vref{f:parshape-1}) whose
4161 % main purpose is to get an estimate on the number of lines that will be
4162 % needed; it chooses a uniform indent for all lines after the first one
4163 % and does not take any account of the equation number.
4164 % A substantial majority of equations only require one line anyway,
4165 % and for them this first trial will succeed.
4166 % In the one-line case if there is an equation number and it doesn't
4167 % fit on the same line as the equation body, we don't go on to other
4168 % trials because breaking up the equation body will not gain us
4169 % anything\mdash we know that we'll have to use two lines in any case
4170 % \mdash so we might as well keep the equation body together on one line
4171 % and shift the number to a separate line.
4172 %
4173 % If we learn from the first trial that the equation body
4174 % requires more than one line, the next parshape trial involves adjusting
4175 % the previous parshape to leave room for the equation number, if
4176 % present. If no number is present, again no further trials are
4177 % needed.
4178 %
4179 % Some remarks about parshape handling. The \tex
4180 % primitive doesn't store the line specs anywhere, \verb"\the\parshape"
4181 % only returns the number of line specs. This makes it well nigh
4182 % impossible for different packages that use \cs{parshape} to work
4183 % together. Not that it would be terribly easy for the package
4184 % authors to make inter-package collaboration work, if it were
4185 % possible. If we optimistically conjecture that
4186 % someone some day may take on such a task, then the thing to do,
4187 % obviously, is provide a parshape interface that includes a record of all
4188 % the line specs. For that we designate a macro \cs{@parshape}
4189 % which includes not only the line specs, but also the line count and even
4190 % the leading \cs{parshape} token.
4191 % This allows it to be directly executed without an auxiliary if-empty
4192 % test. It should include a trailing \cs{relax} when it has a
4193 % nonempty value.
4194 % \begin{macrocode}
4195 \let\@parshape\@empty
4196 % \end{macrocode}
4197 %
4198 %
4199 % The function \cs{eq@measure} runs line-breaking trials
4200 % on the copy of the equation body that is stored in the box register
4201 % \cs{EQ@copy}, trying various possible layouts in order of
4202 % preference until we get successful line breaks, where \quoted{successful}
4203 % means there were no overfull lines. The result of the trials is,
4204 % first, a parshape spec that can be used for typesetting the real
4205 % equation body in \cs{EQ@box}, and second, some information that
4206 % depends on the line breaks such as the depth of the last line, the
4207 % height of the first line, and positioning information for the equation
4208 % number. The two main variables in the equation layout are the line
4209 % width and the placement of the equation number, if one is present.
4210 %
4211 %
4212 % \begin{macro}{\eq@measure}
4213 % Run linebreak trials on the equation contents and measure the
4214 % results.
4215 % \begin{macrocode}
4216 \def\eq@measure{%
4217 % \end{macrocode}
4218 % If an override value is given for indentstep in the env options, use
4219 % it.
4220 % \begin{macrocode}
4221 \ifdim\eq@indentstep=\maxdimen \eq@indentstep\eqindentstep \fi
4222 % \end{macrocode}
4223 % If \cs{eq@linewidth} is nonzero at this point, it means that
4224 % the user specified a particular target width for this equation.
4225 % In that case we override the normal list of trial widths.
4226 % \begin{macrocode}
4227 \ifdim\eq@linewidth=\z@ \else \edef\eq@linewidths{{\the\eq@linewidth}}\fi
4228 \begingroup \eq@params
4229 \leftskip\z@skip
4230 % \end{macrocode}
4231 % Even if \cs{hfuzz} is greater than zero a box whose contents
4232 % exceed the target width by less then hfuzz still has a reported badness
4233 % value of 1000000 (infinitely bad). Because we use inf-bad
4234 % to test whether a particular trial succeeds or fails, we want to make
4235 % such boxes return a smaller badness. To this end we include an
4236 % \cs{hfuzz} allowance in \cs{rightskip}. In fact,
4237 % \cs{eq@params} ensures that \cs{hfuzz} for equations is at
4238 % least 1pt.
4239 % \begin{macrocode}
4240 \rightskip\z@\@plus\columnwidth\@minus\hfuzz
4241 % \eqinfo
4242 \global\EQ@continue{\eq@trial}%
4243 \eq@trial % uses \eq@linewidths
4244 \eq@failout % will be a no-op if the trial succeeded
4245 \endgroup
4246 % \end{macrocode}
4247 % \quoted{local} parameter settings are passed outside the endgroup through
4248 % \cs{EQ@trial}.
4249 % \begin{macrocode}
4250 \EQ@trial
4251 }
4252 % \end{macrocode}
4253 % \end{macro}
4254 % \begin{macrocode}
4255 %<*trace>
4256 \def\debug@showmeasurements{%
4257 \breqn@debugmsg{=> \number\eq@lines\space lines}%
4258 \begingroup
4259 \def\breqn@elt##1X##2{\MessageBreak==== \space\space##1/##2}%
4260 \let\breqn@endelt\@empty
4261 \breqn@debugmsg{=> trial info:\eq@measurements}%
4262 \breqn@debugmsg{=> bounding box: \the\eq@wdT x\the\eq@vspan, badness=\the\eq@badness}%
4263 \let\breqn@elt\relax \let\breqn@endelt\relax
4264 \endgroup
4265 }
4266 \def\debug@showmeasurements{%
4267 \begingroup
4268 \def\breqn@elt##1X##2{\MessageBreak==== ##1/##2}%
4269 \let\breqn@endelt\@empty
4270 \breqn@debugmsg{===> Measurements: \number\eq@lines\space lines
4271 \eq@measurements
4272 \MessageBreak
4273 ==== bounding box: \the\eq@wdT x\the\eq@vspan, badness=\the\eq@badness
4274 \MessageBreak
4275 ==== \leftskip=\the\leftskip, \rightskip=\the\rightskip}%
4276 \endgroup
4277 }
4278 %</trace>
4279 % \end{macrocode}
4280 %
4281 % Layout Trials Driver
4282 % Basically, trying different sequences of parshapes.
4283 %
4284 %
4285 % \begin{macro}{\EQ@trial}
4286 % Init.
4287 % \begin{macrocode}
4288 \let\EQ@trial\@empty
4289 % \end{macrocode}
4290 % \end{macro}
4291 %
4292 %
4293 % \begin{macro}{\EQ@continue}
4294 % This is a token register used to carry trial info past a
4295 % group boundary with only one global assignment.
4296 % \begin{macrocode}
4297 \newtoks\EQ@continue
4298 % \end{macrocode}
4299 % \end{macro}
4300 %
4301 %
4302 % \begin{macro}{\EQ@widths}
4303 % This is used for storing the actual line-width info of the equation
4304 % contents after breaking.
4305 % \begin{macrocode}
4306 \let\EQ@widths\@empty
4307 % \end{macrocode}
4308 % \end{macro}
4309 % \begin{macro}{\EQ@fallback}
4310 % \begin{macrocode}
4311 \let\EQ@fallback\@empty
4312 % \end{macrocode}
4313 % \end{macro}
4314 % \begin{macro}{\eq@linewidths}
4315 % This is the list of target widths for line breaking.
4316 %
4317 %========================================
4318 % BRM: Odd; I don't think I've seen this use anything but \cs{displaywidth}...
4319 % \begin{macrocode}
4320 \def\eq@linewidths{\displaywidth\linewidth\columnwidth}
4321 % \end{macrocode}
4322 % \end{macro}
4323 %
4324 %
4325 % \begin{macro}{\eq@trial}
4326 % The \cs{eq@trial} function tries each candidate
4327 % line width in \cs{eq@linewidths} until an equation layout is found
4328 % that yields satisfactory line breaks.
4329 % \begin{macrocode}
4330 \def\eq@trial{%
4331 \ifx\@empty\eq@linewidths
4332 \global\EQ@continue{}%
4333 \else
4334 \iffalse{\fi \@xp\eq@trial@a \eq@linewidths}%
4335 \fi
4336 \the\EQ@continue
4337 }
4338 % \end{macrocode}
4339 % \end{macro}
4340 %
4341 %
4342 % \begin{macro}{\eq@trial@a}
4343 % The \cs{eq@trial@a} function reads the leading line
4344 % width from \cs{eq@linewidths}; if the new line width is greater
4345 % than the previous one, start running trials with it; otherwise do
4346 % nothing with it.
4347 % Finally, run a peculiar \cs{edef} that leaves
4348 % \cs{eq@linewidths} redefined to be the tail of the list.
4349 % If we succeed in finding satisfactory line breaks
4350 % for the equation, we will reset \cs{EQ@continue} in such a
4351 % way that it will terminate the current trials.
4352 % An obvious branch here would be to check whether the width of
4353 % \cs{EQ@copy} is less than \cs{eq@linewidth} and go immediately
4354 % to the one-line case if so.
4355 % However, if the equation contains more than one RHS, by
4356 % default each additional RHS starts on a new line\mdash \ie , we want
4357 % the ladder layout anyway.
4358 % So we choose the initial trial on an assumption of multiple lines
4359 % and leave the one-line case to fall out naturally at a later point.
4360 % \begin{macrocode}
4361 \def\eq@trial@a#1{%
4362 \dim@c#1\relax
4363 \if T\eq@frame \eq@frame@adjust\dim@c \fi
4364 \ifdim\dim@c>\eq@linewidth
4365 \eq@linewidth\dim@c
4366 %<trace> \breqn@debugmsg{Choose Shape for width(#1)=\the\eq@linewidth}%
4367 \let\eq@trial@b\eq@trial@d
4368 \csname eq@try@layout@\eq@layout\endcsname
4369 %<trace> \else
4370 %<trace> \breqn@debugmsg{Next width (#1) is shorter; skip it}%
4371 \fi
4372 \edef\eq@linewidths{\iffalse}\fi
4373 }
4374 \def\eq@frame@adjust#1{%
4375 %\addtolength#1{-2\eq@framewd-2\eq@framesep}%
4376 \dim@a\eq@framewd \advance\dim@a\eq@framesep
4377 \advance#1-2\dim@a
4378 }
4379 % \end{macrocode}
4380 % \end{macro}
4381 %========================================
4382 % Note curious control structure.
4383 % Try to understand interaction of \cs{EQ@fallback}, \cs{EQ@continue},
4384 % \cs{eq@failout}
4385 % \begin{macrocode}
4386 \def\eq@trial@succeed{%
4387 \aftergroup\@gobbletwo % cancel the \EQ@fallback code; see \eq@trial@c (?)
4388 \global\EQ@continue{\eq@trial@done}%
4389 }
4390 % \end{macrocode}
4391 % \begin{macro}{\eq@trial@done}
4392 % Success.
4393 % \begin{macrocode}
4394 \def\eq@trial@done{%
4395 %<trace> \breqn@debugmsg{End trial: Success!}%
4396 \let\eq@failout\relax
4397 }
4398 % \end{macrocode}
4399 % \end{macro}
4400 %
4401 % \begin{macro}{\eq@trial@init}
4402 % This is called from \cs{eq@trial@b} to initialize or
4403 % re-initialize certain variables as needed when running one or more
4404 % trials at a given line width.
4405 % By default assume success, skip the fallback code.
4406 % \begin{macrocode}
4407 \def\eq@trial@init{\global\let\EQ@fallback\eq@nextlayout}
4408 % \end{macrocode}
4409 % \end{macro}
4410 % \begin{macro}{\eq@nextlayout}
4411 %
4412 % In the fallback case cancel the current group to avoid unnecessary
4413 % group nesting (with associated save-stack cost, \etc ).
4414 % \begin{macrocode}
4415 \def\eq@nextlayout#1{%
4416 \endgroup
4417 %<trace> \breqn@debugmsg{Nope ... that ain't gonna work.}%
4418 \begingroup #1%
4419 }
4420 % \end{macrocode}
4421 % \end{macro}
4422 % \begin{macro}{\eq@failout}
4423 %
4424 % .
4425 % \begin{macrocode}
4426 \def\eq@failout{%
4427 %<trace>\breqn@debugmsg{End trial: failout}%
4428 \global\let\EQ@trial\EQ@last@trial
4429 }
4430 % \end{macrocode}
4431 % \end{macro}
4432 % \begin{macro}{\eq@trial@save}
4433 %
4434 % Save the parameters of the current trial.
4435 % \begin{macrocode}
4436 \def\eq@trial@save#1{%
4437 %<*trace>
4438 % \begingroup \def\breqn@elt##1X##2{\MessageBreak==== \space\space##1/##2}\let\breqn@endelt\@empty\breqn@debugmsg{=> trial info:\eq@measurements}%
4439 % \breqn@debugmsg{=> bounding box: \the\eq@wdT x\the\eq@vspan, badness=\the\eq@badness\MessageBreak}%
4440 % \let\breqn@elt\relax \let\breqn@endelt\relax
4441 % \endgroup
4442 %</trace>
4443 \xdef#1{%
4444 \eq@linewidth\the\eq@linewidth
4445 % save info about the fit
4446 \eq@lines\the\eq@lines \eq@badness\the\eq@badness \def\@nx\eq@badline{\eq@badline}%
4447 % save size info
4448 \eq@wdT\the\eq@wdT \eq@wdMin\the\eq@wdMin
4449 \eq@vspan\the\eq@vspan \eq@dp\the\eq@dp \eq@firstht\the\eq@firstht
4450 % save info about the LHS
4451 \eq@wdL\the\eq@wdL \def\@nx\EQ@hasLHS{\EQ@hasLHS}%
4452 % save info about the numbering
4453 \def\@nx\eq@hasNumber{\eq@hasNumber}%
4454 % save info about the chosen layout
4455 \def\@nx\eq@layout{\eq@layout}%
4456 \def\@nx\eq@parshape{\@parshape}%
4457 \def\@nx\eq@measurements{\eq@measurements}%
4458 \def\@nx\adjust@rel@penalty{\adjust@rel@penalty}%
4459 \def\@nx\eq@shiftnumber{\eq@shiftnumber}%
4460 \def\@nx\eq@isIntertext{\@False}%
4461 }%
4462 }
4463 % \end{macrocode}
4464 % \end{macro}
4465 % \begin{macro}{\eq@trial@b}
4466 %
4467 % By default this just runs \cs{eq@trial@c}; \cf
4468 % \cs{eq@trial@d}.
4469 % \begin{macrocode}
4470 \def\eq@trial@b{\eq@trial@c}
4471 % \end{macrocode}
4472 % \end{macro}
4473 %
4474 %
4475 % \begin{macro}{\eq@trial@c}
4476 %
4477 % Run the equation contents through the current parshape.
4478 % \begin{macrocode}
4479 \def\eq@trial@c#1#2{%
4480 %<trace> \breqn@debugmsg{Trying layout "#1" with\MessageBreak==== parshape\space\@xp\@gobble\@parshape}%
4481 \begingroup
4482 \eq@trial@init
4483 \def\eq@layout{#1}%
4484 \setbox\z@\vbox{%
4485 \hfuzz\maxdimen
4486 \eq@trial@p % run the given parshape
4487 \if\@Not{\eq@badline}%
4488 \eq@trial@save\EQ@trial
4489 % \end{macrocode}
4490 % If there is a number, try the same parshape again with adjustments
4491 % to make room for the number.
4492 %
4493 % This is an awkward place for this:
4494 % It only allows trying to fit the number w/the SAME layout shape!
4495 % \begin{macrocode}
4496 \if\eq@hasNumber\eq@retry@with@number\fi
4497 \if L\eq@layout \eq@check@density
4498 \else
4499 \if\@Not{\eq@badline}%
4500 \eq@trial@succeed
4501 \fi
4502 \fi
4503 \else
4504 \eq@trial@save\EQ@last@trial
4505 \fi
4506 }%
4507 \EQ@fallback{#2}%
4508 \endgroup
4509 }
4510 % \end{macrocode}
4511 % \end{macro}
4512 % \begin{macro}{\eq@trial@d}
4513 % \begin{macrocode}
4514 \def\eq@trial@d#1#2{\eq@trial@c{#1}{}}
4515 % \end{macrocode}
4516 % \end{macro}
4517 %
4518 % \begin{macro}{\eq@check@density}
4519 % \begin{macrocode}
4520 \def\eq@check@density{%
4521 %<trace> \breqn@debugmsg{Checking density for layout L}%
4522 \if\@Or{\@Not\EQ@hasLHS}{\eq@shortLHS}%
4523 %<trace> \breqn@debugmsg{Density check: No LHS, or is short; OK}%
4524 \eq@trial@succeed
4525 \else\if\eq@dense@enough
4526 \eq@trial@succeed
4527 \fi\fi
4528 }
4529 % \end{macrocode}
4530 % \end{macro}
4531 %
4532 % \begin{macro}{\eq@shortLHS}
4533 % Test to see if we need to apply the \cs{eq@dense@enough} test.
4534 % \begin{macrocode}
4535 \def\eq@shortLHS{\ifdim\eq@wdL>.44\eq@wdT 1\else 0\fi 0}
4536 % \end{macrocode}
4537 % \end{macro}
4538 %
4539 %\verb|\def\eq@shortLHS{\@False}|
4540 %========================================
4541 % \begin{macro}{\eq@trial@p}
4542 % Run a trial with the current \cs{@parshape} and measure it.
4543 % \begin{macrocode}
4544 \def\eq@trial@p{%
4545 \@parshape %
4546 \eq@dump@box\unhcopy\EQ@copy
4547 {\@@par}% leave \parshape readable
4548 \eq@lines\prevgraf
4549 \eq@fix@lastline
4550 \let\eq@badline\@False
4551 \if i\eq@layout \ifnum\eq@lines>\@ne \let\eq@badline\@True \fi\fi
4552 \eq@curline\eq@lines % loop counter for eq@measure@lines
4553 \let\eq@measurements\@empty
4554 \eq@ml@record@indents
4555 \eq@measure@lines
4556 \eq@recalc
4557 %<trace> \debug@showmeasurements
4558 }
4559 % \end{macrocode}
4560 % \end{macro}
4561 %
4562 %
4563 % \begin{macro}{\adjust@rel@penalty}
4564 % Normally this is a no-op.
4565 % \begin{macrocode}
4566 \let\adjust@rel@penalty\@empty
4567 % \end{macrocode}
4568 % \end{macro}
4569 %
4570 % \begin{macro}{\eq@fix@lastline}
4571 % Remove parfillskip from the last line box.
4572 % \begin{macrocode}
4573 \def\eq@fix@lastline{%
4574 \setbox\tw@\lastbox \dim@b\wd\tw@
4575 \eq@dp\dp\tw@
4576 % \end{macrocode}
4577 % Remove \cs{parfillskip} but retain \cs{rightskip}.
4578 % Need to keep the original line width for later shrink testing.
4579 % \begin{macrocode}
4580 \nointerlineskip\hbox to\dim@b{\unhbox\tw@
4581 \skip@c\lastskip \unskip\unskip\hskip\skip@c
4582 }%
4583 }
4584 % \end{macrocode}
4585 % \end{macro}
4586 %
4587 % \begin{macro}{\eq@recalc}
4588 % Calculate \cs{eq@wdT} et cetera.
4589 % \begin{macrocode}
4590 \def\eq@recalc{%
4591 \eq@wdT\z@ \eq@wdMin\maxdimen \eq@vspan\z@skip \eq@badness\z@
4592 \let\breqn@elt\eq@recalc@a \eq@measurements \let\breqn@elt\relax
4593 }
4594 % \end{macrocode}
4595 % \end{macro}
4596 %
4597 %
4598 % \begin{macro}{\eq@recalc@a}
4599 % \begin{macrocode}
4600 \def\eq@recalc@a#1x#2+#3\breqn@endelt{%
4601 \eq@firstht#2\relax
4602 \let\breqn@elt\eq@recalc@b
4603 \breqn@elt#1x#2+#3\breqn@endelt
4604 }
4605 % \end{macrocode}
4606 % \end{macro}
4607 %
4608 %
4609 % \begin{macro}{\eq@recalc@b}
4610 % \begin{macrocode}
4611 \def\eq@recalc@b#1X#2,#3x#4+#5@#6\breqn@endelt{%
4612 \setlength\dim@a{#2+#3}%
4613 \ifdim\dim@a>\eq@wdT \eq@wdT\dim@a \fi
4614 \ifdim\dim@a<\eq@wdMin \eq@wdMin\dim@a \fi
4615 \eq@dp#5\relax
4616 \addtolength\eq@vspan{#1+#4+\eq@dp}%
4617 % \end{macrocode}
4618 % Record the max badness of all the lines in \cs{eq@badness}.
4619 % \begin{macrocode}
4620 \ifnum#6>\eq@badness \eq@badness#6\relax\fi
4621 }
4622 % \end{macrocode}
4623 % \end{macro}
4624 %
4625 % \begin{macro}{\eq@layout}
4626 % A value of \verb"?" for \cs{eq@layout} means that we should
4627 % deduce which layout to use by looking at the size of the components.
4628 % Any other value means we have a user-specified override on the
4629 % layout.
4630 %
4631 % Layout Definitions.
4632 % Based on initial equation measurements, we can choose a sequence of
4633 % candidate parshapes that the equation might fit into.
4634 % We accept the first shape that `works', else fall to next one.
4635 % [The sequence is hardcoded in the \cs{eq@try@layout@}<shape>
4636 % Would it be useful be more flexible? (eg. try layouts LDA, in order...)]
4637 % \begin{macrocode}
4638 \def\eq@layout{?}
4639 % \end{macrocode}
4640 % \end{macro}
4641 %
4642 %
4643 % \begin{macro}{\eq@try@layout@?}
4644 % This is a branching function used to choose a suitable layout if
4645 % the user didn't specify one in particular.
4646 %
4647 % Default layout:
4648 % Try Single line layout first, else try Multiline layouts
4649 % \begin{macrocode}
4650 \@namedef{eq@try@layout@?}{%
4651 \let\eq@trial@b\eq@trial@c
4652 \edef\@parshape{\parshape 1 0pt \the\eq@linewidth\relax}%
4653 % \eq@trial@b{i}{\eq@try@layout@multi}%
4654 \setlength\dim@a{\wd\EQ@copy-2em}% Fudge; can't shrink more than this?
4655 % if we're in a numbered group, try hard to fit within the numbers
4656 \dim@b\eq@linewidth
4657 \if\eq@shiftnumber\else\if\eq@group
4658 \if\eq@hasNumber\addtolength\dim@b{-\wd\EQ@numbox-\eqnumsep}%
4659 \else\if\grp@hasNumber\addtolength\dim@b{-\wd\GRP@numbox-\eqnumsep}%
4660 \fi\fi\fi\fi
4661 \ifdim\dim@a<\dim@b% Do we even have a chance of fitting to one line?
4662 %<trace> \breqn@debugmsg{Choose Shape: (\the\wd\EQ@copy) may fit in \the\dim@b}%
4663 % \end{macrocode}
4664 % BRM: assuming it might fit, don't push too hard
4665 % \begin{macrocode}
4666 \setlength\dim@b{\columnwidth-\dim@a+\eq@wdCond}%
4667 \rightskip\z@\@plus\dim@b\@minus\hfuzz
4668 \eq@trial@b{i}{\eq@try@layout@multi}%
4669 \else
4670 %<*trace>
4671 \breqn@debugmsg{Choose Shape: Too long (\the\wd\EQ@copy) for one line
4672 (free width=\the\dim@b)}%
4673 %</trace>
4674 \eq@try@layout@multi
4675 \fi
4676 }
4677 % \end{macrocode}
4678 % Layout Multiline layout:
4679 % If no LHS, try Stepped(S) layout
4680 % Else try Stepped(S), Ladder(L), Drop-ladder(D) or Stepladder(l), depending on LHS length.
4681 % \begin{macrocode}
4682 \def\eq@try@layout@multi{%
4683 \if\EQ@hasLHS
4684 \ifdim\eq@wdL>\eq@linewidth
4685 %<trace> \breqn@debugmsg{Choose Shape: LHS \the\eq@wdL > linewidth}%
4686 % \end{macrocode}
4687 % Find the total width of the RHS.
4688 % If it is relatively short, a step layout is the thing to try.
4689 % \begin{macrocode}
4690 \setlength\dim@a{\wd\EQ@copy-\eq@wdL}%
4691 \ifdim\dim@a<.25\eq@linewidth \eq@try@layout@S
4692 \else \eq@try@layout@l
4693 \fi
4694 % BRM: Originally .7: Extreme for L since rhs has to wrap within the remaining 30+%!
4695 \else\ifdim\eq@wdL>.50\eq@linewidth
4696 %<*trace>
4697 \breqn@debugmsg{Choose Shape: LHS (\the\eq@wdL) > .50 linewidth (linewidth=\the\eq@linewidth)}%
4698 %</trace>
4699 \eq@try@layout@D
4700 \else
4701 %<trace> \breqn@debugmsg{Choose Shape: LHS (\the\eq@wdL) not extraordinarily wide}%
4702 \eq@try@layout@L
4703 \fi\fi
4704 \else
4705 %<trace> \breqn@debugmsg{Choose Shape: No LHS here}%
4706 % \end{macrocode}
4707 % Try one-line layout first, then step layout.
4708 % \begin{macrocode}
4709 \eq@try@layout@S % (already checked case i)
4710 \fi
4711 }
4712 % \end{macrocode}
4713 % \end{macro}
4714 %
4715 % \begin{macro}{\eq@try@layout@D}
4716 % Change the penalty before the first mathrel symbol to encourage a
4717 % break there.
4718 %
4719 % Layout D=Drop-Ladder Layout, for wide LHS.
4720 % \begin{literalcode}
4721 % LOOOOOOOONG LHS
4722 % = RHS
4723 % = ...
4724 % \end{literalcode}
4725 % If fails, try Almost-Columnar layout
4726 % \begin{macrocode}
4727 \def\eq@try@layout@D{%
4728 \setlength\dim@a{\eq@linewidth -\eq@indentstep}%
4729 \edef\@parshape{\parshape 2
4730 0pt \the\eq@wdL\space \the\eq@indentstep\space \the\dim@a\relax
4731 }%
4732 \def\adjust@rel@penalty{\penalty-99 }%
4733 \eq@trial@b{D}{\eq@try@layout@A}%
4734 }
4735 % \end{macrocode}
4736 % \end{macro}
4737 % \begin{macro}{\eq@try@layout@L}
4738 % Try a straight ladder layout.
4739 % Preliminary filtering ensures that \cs{eq@wdL} is less than 70%
4740 % of the current line width.
4741 % \begin{literalcode}
4742 % Layout L=Ladder layout
4743 % LHS = RHS
4744 % = RHS
4745 % ...
4746 % \end{literalcode}
4747 % If fails, try Drop-ladder layout.
4748 % NOTE: This is great for some cases (multi relations?), but
4749 % tends to break really badly when it fails....
4750 % \begin{macrocode}
4751 \def\eq@try@layout@L{%
4752 \setlength\dim@b{\eq@linewidth-\eq@wdL}%
4753 \edef\@parshape{\parshape 2 0pt \the\eq@linewidth\space
4754 \the\eq@wdL\space \the\dim@b\relax
4755 }%
4756 \eq@trial@b{L}{\eq@try@layout@D}%
4757 }
4758 % \end{macrocode}
4759 % \end{macro}
4760 %
4761 % \begin{macro}{\eq@try@layout@S}
4762 % In the \dquoted{stepped} layout there is no LHS, or LHS
4763 % is greater than the line width and RHS is small.
4764 % Then we want to split up the equation into lines of roughly equal
4765 % width and stagger them downwards to the right, leaving a small amount of
4766 % whitespace on both sides.
4767 % But also, if there is an equation number, we want to try first a
4768 % layout that leaves room for the number.
4769 % Otherwise it would nearly always be the case that the number would
4770 % get thrown on a separate line.
4771 %
4772 % Layout S=Stepped layout, typically no LHS or very long, variations on
4773 % \begin{literalcode}
4774 % STUFF ....
4775 % + MORE STUFF ...
4776 % + MORE STUFF ...
4777 % \end{literalcode}
4778 % If fails, try Almost-Columnar layout
4779 % \begin{macrocode}
4780 \def\eq@try@layout@S{%
4781 \setlength\dim@b{\eq@linewidth-2\eqmargin}% \advance\dim@b-1em%
4782 % \end{macrocode}
4783 % About how many lines will we need if dim@b is the line width?
4784 % \begin{macrocode}
4785 \int@a\wd\EQ@copy \divide\int@a\dim@b
4786 % \end{macrocode}
4787 % Adjust the target width by number of lines times indentstep.
4788 % We don't need to decrement \cs{int@a} because \tex
4789 % division is integer division with truncation.
4790 % \begin{macrocode}
4791 \addtolength\dim@b{-\int@a\eq@indentstep}%
4792 % \end{macrocode}
4793 % Adjust for equation number.
4794 % But try not to leave too little room for the equation body.
4795 % \begin{macrocode}
4796 \if\eq@hasNumber
4797 \ifdim\dim@b>15em%
4798 % \advance\dim@b-\eqnumsep \advance\dim@b-\wd\EQ@numbox
4799 \addtolength\dim@b{-\eq@wdNum}%
4800 \fi
4801 \fi
4802 % \end{macrocode}
4803 % Now some hand-waving to set up the parshape.
4804 % \begin{macrocode}
4805 \int@b\z@
4806 \def\@tempa{\dim}%
4807 \edef\@parshape{\parshape 2 0pt \the\dim@b\space
4808 \the\eqmargin\space\the\dim@b\relax}%
4809 \eq@trial@b{S}{\eq@try@layout@A}%
4810 }
4811 % \end{macrocode}
4812 % \end{macro}
4813 %
4814 % \begin{macro}{\eq@try@layout@l}
4815 % This is the \dquoted{step-ladder} layout: similar to the drop-ladder
4816 % layout but the LHS is too wide and needs to be broken up.
4817 %
4818 % Layout l = Stepladder
4819 % Similar to Drop-Ladder, but LHS is long and needs to be broken up.
4820 % If fails, try Almost-Columnar layout
4821 % \begin{macrocode}
4822 \def\eq@try@layout@l{%
4823 \setlength\dim@a{\eq@linewidth -\eq@indentstep}%
4824 \int@a\eq@wdL \divide\int@a\dim@a
4825 \advance\int@a\tw@
4826 \edef\@parshape{\parshape \number\int@a\space
4827 0pt \the\eq@linewidth
4828 }%
4829 \advance\int@a-\tw@
4830 \setlength\dim@b{2\eq@indentstep}%
4831 \setlength\dim@c{\eq@linewidth -\dim@b}%
4832 \edef\@parshape{\@parshape
4833 \replicate{\int@a}{\space\the\eq@indentstep\space\the\dim@a}%
4834 \space\the\dim@b\space\the\dim@c\relax
4835 }%
4836 \eq@trial@b{l}{\eq@try@layout@A}%
4837 }
4838 % \end{macrocode}
4839 % \end{macro}
4840 %
4841 % \begin{macro}{\eq@try@layout@A}
4842 % In the \dquoted{almost-columnar} layout, which is the layout of last
4843 % resort, we let all lines run to the full width and leave the adjusting
4844 % of the indents to later.
4845 %
4846 % Layout A = Almost-Columnar layout.
4847 % Pretty much straight full width, more of a last-resort.
4848 % If fails, give up.
4849 % \begin{macrocode}
4850 \def\eq@try@layout@A{%
4851 \edef\@parshape{\parshape 1 0pt \the\eq@linewidth\relax}%
4852 \if\EQ@hasLHS \def\adjust@rel@penalty{\penalty-99 }\fi
4853 \eq@trial@b{A}{}%
4854 }
4855 % \end{macrocode}
4856 % \end{macro}
4857 %
4858 % \begin{macro}{\eq@shiftnumber}
4859 % MH: Should be moved to a section where all keys are set to defaults.
4860 % \begin{macrocode}
4861 \let\eq@shiftnumber\@False
4862 % \end{macrocode}
4863 % \end{macro}
4864 %
4865 % \begin{macro}{\eq@retry@with@number@a}
4866 % Number placement adjustments
4867 % \begin{macrocode}
4868 \def\eq@retry@with@number{%
4869 \if\eq@shiftnumber
4870 %<trace> \breqn@debugmsg{Place number: Shifted number requested}%
4871 \else
4872 % \end{macrocode}
4873 % Condition and right numbers? We're just going to have to shift.
4874 % \begin{macrocode}
4875 \ifdim\eq@wdCond>\z@\if R\eqnumside
4876 %<trace> \breqn@debugmsg{Place number: Condition w/Right number => Shift number}%
4877 \let\eq@shiftnumber\@True
4878 \fi\fi
4879 % \end{macrocode}
4880 % Compute free space.
4881 % \begin{macrocode}
4882 % \dim@b\eqnumsep\advance\dim@b\wd\EQ@numbox
4883 \dim@b\eq@wdNum
4884 \if L\eqnumside
4885 \ifdim\@totalleftmargin>\dim@b\dim@b\@totalleftmargin\fi
4886 \else
4887 \addtolength\dim@b{\@totalleftmargin}%
4888 \fi
4889 \setlength\dim@a{\eq@linewidth-\dim@b}%\advance\dim@a1em\relax% Allowance for shrink?
4890 % \end{macrocode}
4891 % Set up test against 1-line case only if not in a group
4892 % \begin{macrocode}
4893 \int@a\@ne\if\eq@group\int@a\maxint\fi
4894 % \end{macrocode}
4895 % Now check for cases.
4896 % \begin{macrocode}
4897 \if\eq@shiftnumber % Already know we need to shift
4898 \else\ifdim\eq@wdT<\dim@a % Fits!
4899 % \end{macrocode}
4900 % left \& right skips will be done later, and parshape adjusted if
4901 % needed.
4902 % \begin{macrocode}
4903 %<trace> \breqn@debugmsg{Place number: eqn and number fit together}%
4904 % \else\ifnum\eq@lines=\int@a % Shift, if single line, unless inside a dgroup.
4905 % \end{macrocode}
4906 % NOTE: this is too strong for dgroup!
4907 % \begin{macrocode}
4908 %<*trace>
4909 % \breqn@debugmsg{Place number: single line too long with number => Shift number \the\int@a}%
4910 %</trace>
4911 % \let\eq@shiftnumber\@True
4912 \else
4913 % \end{macrocode}
4914 % % Retry: use leftskip for space for number(for now; whether
4915 % % right/left) \& adjust parshape
4916 % \begin{macrocode}
4917 % \leftskip\wd\EQ@numbox\advance\leftskip\eqnumsep
4918 \setlength\leftskip{\eq@wdNum}%
4919 \setlength\rightskip{\z@\@plus\dim@a}%
4920 \adjust@parshape\@parshape
4921 %<*trace>
4922 \breqn@debugmsg{Place number: Try with \leftskip=\the\leftskip, \rightskip=\the\rightskip,
4923 \MessageBreak==== parshape\space\@xp\@gobble\@parshape}%
4924 %</trace>
4925 \nointerlineskip
4926 \edef\eq@prev@lines{\the\eq@lines}%
4927 \edef\eq@prev@badness{\the\eq@badness}% BRM
4928 \eq@trial@p
4929 \int@a\eq@prev@badness\relax\advance\int@a 50\relax%?
4930 \int@b\eq@prev@lines \if\eq@group\advance\int@b\@ne\fi% Allow 1 extra line in group
4931 \ifnum\eq@lines>\int@b % \eq@prev@lines
4932 %<trace> \breqn@debugmsg{Adjustment causes more breaks => Shift number}%
4933 \let\eq@shiftnumber\@True
4934 \else\if\eq@badline
4935 %<trace> \breqn@debugmsg{Adjustment causes bad lines (\the\eq@badness) => Shift}%
4936 \let\eq@shiftnumber\@True
4937 \else\ifnum\eq@badness>\int@a % BRM: New case
4938 %<*trace>
4939 \breqn@debugmsg{Adjustment is badder than previous
4940 (\the\eq@badness >> \eq@prev@badness) => Shift}%
4941 %</trace>
4942 \let\eq@shiftnumber\@True
4943 \else
4944 %<trace> \breqn@debugmsg{Adjustment succeeded}%
4945 \fi\fi%\fi
4946 \fi\fi\fi
4947 % \end{macrocode}
4948 % If we got shifted, restore parshape, etc,
4949 % \begin{macrocode}
4950 \if\eq@shiftnumber
4951 \EQ@trial% Restore parshape & other params,
4952 \leftskip\z@\let\eq@shiftnumber\@True % But set shift & leftskip
4953 \edef\@parshape{\eq@parshape}% And copy saved parshape back to `working copy' !?!?
4954 \fi
4955 \eq@trial@save\EQ@trial % Either way, save the trial state.
4956 \fi
4957 }
4958 % \end{macrocode}
4959 % \end{macro}
4960 %
4961 % \begin{macro}{\adjust@parshape}
4962 % Varies depending on the layout.
4963 %
4964 % Adjust a parshape variable for a given set of left\textbar right skips.
4965 % Note that the fixed part of the left\textbar right skips effectively
4966 % comes out of the parshape widths (NOT in addition to it).
4967 % We also must trim the widths so that the sum of skips, indents
4968 % and widths add up to no more than the \cs{eq@linewidth}.
4969 % \begin{macrocode}
4970 \def\adjust@parshape#1{%
4971 \@xp\adjust@parshape@a#1\relax
4972 \edef#1{\temp@a}%
4973 }
4974 % \end{macrocode}
4975 % \end{macro}
4976 %
4977 %
4978 % \begin{macro}{\adjust@parshape@a}
4979 % \begin{macro}{\adjust@parshape@b}
4980 % \begin{macrocode}
4981 \def\adjust@parshape@a#1 #2\relax{%
4982 \setlength\dim@a{\leftskip+\rightskip}%
4983 \edef\temp@a{#1}%
4984 \adjust@parshape@b#2 @ @ \relax
4985 }
4986 \def\adjust@parshape@b#1 #2 {%
4987 \ifx @#1\edef\temp@a{\temp@a\relax}%
4988 \@xp\@gobble
4989 \else
4990 \dim@b#1\relax
4991 \dim@c#2\relax
4992 \addtolength\dim@c{\dim@a+\dim@b}%
4993 \ifdim\dim@c>\eq@linewidth\setlength\dim@c{\eq@linewidth}\fi
4994 \addtolength\dim@c{-\dim@b}%
4995 \edef\temp@a{\temp@a\space\the\dim@b\space\the\dim@c}%
4996 \fi
4997 \adjust@parshape@b
4998 }
4999 % \end{macrocode}
5000 % \end{macro}
5001 % \end{macro}
5002 %
5003 % \begin{macro}{\eq@ml@record@indents}
5004 % Plunk the parshape's indent values into an array for easy access
5005 % when constructing \cs{eq@measurements}.
5006 % \begin{macrocode}
5007 \def\eq@ml@record@indents{%
5008 \int@a\z@
5009 \def\@tempa{%
5010 \advance\int@a\@ne
5011 \@xp\edef\csname eq@i\number\int@a\endcsname{\the\dim@a}%
5012 \ifnum\int@a<\int@b \afterassignment\@tempb \fi
5013 \dim@a
5014 }%
5015 \def\@tempb{\afterassignment\@tempa \dim@a}%
5016 \def\@tempc##1##2 {\int@b##2\afterassignment\@tempa\dim@a}%
5017 \@xp\@tempc\@parshape
5018 }
5019 % \end{macrocode}
5020 % \end{macro}
5021 %
5022 % \begin{macro}{\breqn@endelt}
5023 % This is a scan marker.
5024 % It should get a non-expandable definition.
5025 % It could be \cs{relax}, but let's try a chardef instead.
5026 % \begin{macrocode}
5027 \chardef\breqn@endelt=`\?
5028 % \end{macrocode}
5029 % \end{macro}
5030 %
5031 %
5032 % \begin{macro}{\eq@measurements}
5033 % This is similar to a parshape spec but for each line we record more
5034 % info: space above, indent, width x height + dp, and badness.
5035 % \begin{macrocode}
5036 \let\breqn@elt\relax
5037 \let\breqn@endelt\relax
5038 \def\eq@measurements{%
5039 \breqn@elt 4.5pt/5.0pt,66.0ptx6.8pt+2.4pt@27\breqn@endelt
5040 ...
5041 }
5042 % \end{macrocode}
5043 % \end{macro}
5044 %
5045 %
5046 % \begin{macro}{\eq@measure@lines}
5047 % Loop through the list of boxes to measure things like total
5048 % height (including interline stretch), \etc . We check the
5049 % actual width of the current line against the natural width \mdash
5050 % after removing rightskip \mdash in case the former is
5051 % \emph{less} than the latter because of shrinkage. In that
5052 % case we do not want to use the natural width for RHS-max-width because
5053 % it might unnecessarily exceed the right margin.
5054 % \begin{macrocode}
5055 \def\eq@measure@lines{%
5056 \let\eq@ml@continue\eq@measure@lines
5057 \setbox\tw@\lastbox \dim@b\wd\tw@ % find target width of line
5058 \setbox\z@\hbox to\dim@b{\unhbox\tw@}% check for overfull
5059 \eq@badness\badness
5060 \ifnum\eq@badness<\inf@bad \else \let\eq@badline\@True \fi
5061 \eq@ml@a \eq@ml@continue
5062 }
5063 % \end{macrocode}
5064 % \end{macro}
5065 %
5066 %
5067 % \begin{macro}{\eq@ml@a}
5068 %
5069 % \begin{macrocode}
5070 \def\eq@ml@a{%
5071 \setbox\tw@\hbox{\unhbox\z@ \unskip}% find natural width
5072 %<*trace>
5073 \ifnum\eq@badness<\inf@bad\else\breqn@debugmsg{!?! Overfull: \the\wd\tw@ >\the\dim@b}\fi
5074 %</trace>
5075 % \end{macrocode}
5076 % Is actual width less than natural width?
5077 % \begin{macrocode}
5078 \ifdim\dim@b<\wd\tw@ \setlength\dim@a{\dim@b}% shrunken line
5079 \else \setlength\dim@a{\wd\tw@}% OK to use natural width
5080 \fi
5081 \addtolength\dim@a{-\leftskip}% BRM: Deduct the skip if we're retrying w/number
5082 % \end{macrocode}
5083 % If there's no aboveskip, assume we've reached the top of the
5084 % equation.
5085 % \begin{macrocode}
5086 \skip@a\lastskip \unskip \unpenalty
5087 \ifdim\skip@a=\z@
5088 \let\eq@ml@continue\relax % end the recursion
5089 \else
5090 % Sum repeated vskips if present
5091 \def\@tempa{%
5092 \ifdim \lastskip=\z@
5093 \else \addtolength\skip@a{\lastskip}\unskip\unpenalty \@xp\@tempa
5094 \fi
5095 }%
5096 \fi
5097 \edef\eq@measurements{\breqn@elt
5098 \the\skip@a\space X% extra space to facilitate extracting only the
5099 % dimen part later
5100 \csname eq@i%
5101 \ifnum\eq@curline<\parshape \number\eq@curline
5102 \else\number\parshape
5103 \fi
5104 \endcsname,\the\dim@a x\the\ht\tw@+\the\dp\tw@ @\the\eq@badness\breqn@endelt
5105 \eq@measurements
5106 }%
5107 \advance\eq@curline\m@ne
5108 \ifnum\eq@curline=\z@ \let\eq@ml@continue\relax\fi
5109 }
5110 % \end{macrocode}
5111 % \end{macro}
5112 %
5113 %
5114 % \begin{macro}{\eq@ml@vspace}
5115 %
5116 % Handle an embedded vspace.
5117 % \begin{macrocode}
5118 \def\eq@ml@vspace{%
5119 \global\advance\eq@vspan\lastskip \unskip\unpenalty
5120 \ifdim\lastskip=\z@ \else \@xp\eq@ml@vspace \fi
5121 }
5122 % \end{macrocode}
5123 % \end{macro}
5124 %
5125 %
5126 % \begin{macro}{\eq@dense@enough}
5127 %
5128 % \begin{macrocode}
5129 \def\eq@dense@enough{%
5130 \ifnum\eq@lines<\thr@@
5131 %<trace> \breqn@debugmsg{Density check: less than 3 lines; OK}%
5132 \@True
5133 \else
5134 \ifdim\eq@wdL >.7\eq@wdT
5135 %<trace> \breqn@debugmsg{Density check: LHS too long; NOT OK}%
5136 \@False
5137 \else \@xp\@xp\@xp\eq@dense@enough@a
5138 \fi
5139 \fi
5140 }
5141 % \end{macrocode}
5142 % \end{macro}
5143 %
5144 %
5145 % \begin{macro}{\true@true@true}
5146 % \begin{macro}{\true@false@true}
5147 % \begin{macro}{\false@true@false}
5148 % \begin{macro}{\false@false@false}
5149 % \begin{macrocode}
5150 \def\true@true@true {\fi\fi\iftrue \iftrue \iftrue }
5151 \def\true@false@true {\fi\fi\iftrue \iffalse\iftrue }
5152 \def\false@true@false {\fi\fi\iffalse\iftrue \iffalse}
5153 \def\false@false@false{\fi\fi\iffalse\iffalse\iffalse}
5154 % \end{macrocode}
5155 % \end{macro}
5156 % \end{macro}
5157 % \end{macro}
5158 % \end{macro}
5159 %
5160 %
5161 % \begin{macro}{\eq@density@factor}
5162 %
5163 % This number specifies, for the ladder layout, how much of the
5164 % equation's bounding box should contain visible material rather than
5165 % whitespace.
5166 % If the amount of visible material drops below this value, then we
5167 % switch to the drop-ladder layout.
5168 % The optimality of this factor is highly dependent on the equation
5169 % contents; .475 was chosen as the default just because it worked well
5170 % with the sample equation, designed to be as average as possible, that I
5171 % used for testing.
5172 % \begin{macrocode}
5173 \def\eq@density@factor{.475}
5174 % \end{macrocode}
5175 % \end{macro}
5176 %
5177 %
5178 % \begin{macro}{\eq@dense@enough@a}
5179 %
5180 % Calculate whether there is more
5181 % visible material than whitespace within the equation's bounding box.
5182 % Sum up the actual line widths and compare to the total
5183 % \dquoted{area} of the bounding box.
5184 % But if we have an extremely large number of lines, fall back to an
5185 % approximate calculation that is more conservative about the danger of
5186 % exceeding \cs{maxdimen}.
5187 % \begin{macrocode}
5188 \def\eq@dense@enough@a{%
5189 \@True \fi
5190 \ifnum\eq@lines>\sixt@@n
5191 \eq@dense@enough@b
5192 \else
5193 \dim@b\z@ \let\breqn@elt\eq@delt \eq@measurements
5194 \dim@c\eq@density@factor\eq@wdT \multiply\dim@c\eq@lines
5195 %<trace> \breqn@debugmsg{Density check: black \the\dim@b/\eq@density@factor total \the\dim@c}%
5196 \ifdim\dim@b>\dim@c \true@false@true \else \false@false@false \fi
5197 \fi
5198 }
5199 % \end{macrocode}
5200 % \end{macro}
5201 %
5202 %
5203 % \begin{macro}{\eq@delt}
5204 % Args are space-above, indent, width, height, depth, badness.
5205 % \begin{macrocode}
5206 \def\eq@delt#1X#2,#3x#4+#5@#6\breqn@endelt{\addtolength\dim@b{#3}}%
5207 % \end{macrocode}
5208 % \end{macro}
5209 %
5210 %
5211 % \begin{macro}{\eq@dense@enough@b}
5212 % This is an approximate calculation used to keep from going over
5213 % \cs{maxdimen} if the number of lines in our trial break is large
5214 % enough to make that a threat.
5215 % If l, t, n represent left-side-width, total-width, and number of
5216 % lines, the formula is
5217 % \begin{literalcode}
5218 % l/t < .4n/(.9n-1)
5219 % \end{literalcode}
5220 % or equivalently, since rational arithmetic is awkward in \tex :
5221 % b
5222 % \begin{literalcode}
5223 % l/t < 4n/(9n-10)
5224 % \end{literalcode}
5225 % .
5226 % \begin{macrocode}
5227 \def\eq@dense@enough@b{%
5228 \int@b\eq@wdT \divide\int@b\p@
5229 \dim@b\eq@wdL \divide\dim@b\int@b
5230 \dim@c\eq@lines\p@ \multiply\dim@c\f@ur
5231 \int@b\eq@lines \multiply\int@b 9 \advance\int@b -10%
5232 \divide\dim@c\int@b
5233 %<trace> \breqn@debugmsg{Density check: l/t \the\dim@b\space< \the\dim@c\space 4n/(9n-10)?}%
5234 \ifdim\dim@b<\dim@c \true@true@true \else \false@true@false \fi
5235 }
5236 % \end{macrocode}
5237 % \end{macro}
5238 %
5239 % \begin{macro}{\eq@parshape}
5240 % \begin{macrocode}
5241 \let\eq@parshape\@empty
5242 % \end{macrocode}
5243 % \end{macro}
5244 %
5245 %
5246 % \begin{macro}{\eq@params}
5247 % The interline spacing and penalties in \cs{eq@params}
5248 % are used during both preliminary line breaking and final typesetting.
5249 % \begin{macrocode}
5250 \def\eq@params{%
5251 \baselineskip\eqlinespacing
5252 \lineskip\eqlineskip \lineskiplimit\eqlineskiplimit
5253 % \end{macrocode}
5254 % Forbid absolutely a pagebreak that separates the first line or last
5255 % line of a multiline equation from the rest of it. Or in other
5256 % words: no equation of three lines or less will be broken at the bottom
5257 % of a page; instead it will be moved whole to the top of the next
5258 % page. If you really really need a page break that splits the
5259 % first or last line from the rest of the equation, you can always fall
5260 % back to\cs{pagebreak}, I suppose.
5261 %
5262 % \begin{macrocode}
5263 \clubpenalty\@M \widowpenalty\@M \interlinepenalty\eqinterlinepenalty
5264 \linepenalty199 \exhyphenpenalty5000 % was 9999: make breaks at, eg. \* a bit easier.
5265 % \end{macrocode}
5266 % For equations, hfuzz should be at least 1pt.
5267 % But we have to fake it a little because we are running the equation
5268 % through \tex 's paragrapher.
5269 % In our trials we use minus 1pt in the rightskip rather than hfuzz;
5270 % and we must do the same during final breaking of the equation, otherwise
5271 % in borderline cases \tex will use two lines instead of one when our
5272 % trial indicated that one line would be enough.
5273 % \begin{macrocode}
5274 \ifdim\hfuzz<\p@ \hfuzz\p@ \fi
5275 %\hfuzz=2pt
5276 % \ifdim\hfuzz<2pt\relax \hfuzz2pt \fi
5277 \parfillskip\z@skip
5278 % \hfuzz\z@
5279 % \end{macrocode}
5280 % Make sure we skip \tex 's preliminary line-breaking pass to save
5281 % processing time.
5282 % \begin{macrocode}
5283 \tolerance9999 \pretolerance\m@ne
5284 }
5285 % \end{macrocode}
5286 % \end{macro}
5287 %
5288 %
5289 %
5290 %
5291 % \section{Equation layout options}
5292 % Using the notation C centered, I indented (applied to
5293 % the equation body), T top, B bottom, M
5294 % middle, L left, R right (applied to the equation number),
5295 % the commonly used equation types are C, CRM, CRB, CLM, CLT,
5296 % I, IRM, IRB, ILM, ILT. In other words, CLM stands for Centered equation
5297 % body with Left-hand Middle-placed equation number, and IRB stands for
5298 % Indented equation with Right-hand Bottom-placed equation number.
5299 %
5300 % Here are some general thoughts on how to place an equation
5301 % tag. Currently it does not work as desired: the L option positions
5302 % the tag app. 10 lines below the math expression, the RM doesn't
5303 % position the tag on the baseline for single-line math
5304 % expressions. Therefore I am going to first write what I think is
5305 % supposed to happen and then implement it.
5306 %
5307 % Below is a small list where especially the two three specifications
5308 % should be quite obvious, I just don't want to forget anything and it
5309 % is important to the implementation.
5310 % \begin{description}
5311 % \item[Definition 1] If a display consists of exactly one line, the
5312 % tag should always be placed on the same baseline as the math
5313 % expression.
5314 % \end{description}
5315 % The remaining comments refer to multi-line displays.
5316 % \begin{description}
5317 % \item[Definition 2] If a tag is to be positioned at the top (T), it
5318 % should be placed such that the baseline of the tag aligns with the
5319 % baseline of the top line of the display.
5320 %
5321 % \item[Definition 3] If a tag is to be positioned at the bottom (B),
5322 % it should be placed such that the baseline of the tag aligns with
5323 % the baseline of the bottom line of the display.
5324 %
5325 % \item[Definition 4] If a tag is to be positioned vertically centered
5326 % (M), it should be placed such that the baseline of the tag is
5327 % positioned exactly halfway between the baseline of the top line of
5328 % the display and the baseline of the bottom line of the display.
5329 % \end{description}
5330 %
5331 % Definitions 1--3 are almost axiomatic in their
5332 % simplicity. Definition~4 is different because I saw at least two
5333 % possibilities for which area to span:
5334 % \begin{itemize}
5335 % \item Calculate distance from top of top line to the bottom of the
5336 % bottom line, position the vertical center of the tag exactly
5337 % halfway between those two extremes.
5338 %
5339 % \item Calculate the distance from the baseline of the top line to
5340 % the baseline of the bottom line, position the baseline of the tag
5341 % exactly halfway between these two extremes.
5342 % \end{itemize}
5343 % Additional combinations of these methods are possible but make
5344 % little sense in my opinion. I have two reasons for choosing the
5345 % latter of these possibilities: Firstly, two expressions looking
5346 % completely identical with the exception of a superscript in the
5347 % first line or a subscript in the last line will have the tag
5348 % positioned identically. Secondly, then M means halfway between T and
5349 % B positions which makes good sense and then also automatically
5350 % fulfills Definition~1.
5351 %
5352 % From an implementation perspective, these definitions should also
5353 % make it possible to fix a deficiency in the current implementation,
5354 % namely that the tag does not influence the height of a display, even
5355 % if the display is a single line. This means that two single-line
5356 % expressions in a \env{dgroup} can be closer together than
5357 % \cs{intereqskip} if the math expressions are (vertically) smaller
5358 % than the tag.
5359 %
5360 % \section{Centered Right-Number Equations}
5361 %
5362 % \begin{macro}{\eq@dump@box}
5363 % \arg1 might be \cs{unhbox} or \cs{unhcopy}; \arg2 is
5364 % the box name.
5365 % \begin{macrocode}
5366 \def\eq@dump@box#1#2{%
5367 %\debug@box#1%
5368 % \noindent
5369 \MaybeRawNoindent % did not find the end yet
5370 #1#2\setbox\f@ur\lastbox \setbox\tw@\lastbox
5371 % \end{macrocode}
5372 % If the LHS contains shrinkable glue, in an L layout the alignment
5373 % could be thrown off if the first line is shrunk noticeably.
5374 % For the time being, disable shrinking on the left-hand side.
5375 % The proper solution requires more work \begin{dn}
5376 % mjd,1999/03/17
5377 % \end{dn}
5378 % .
5379 % \begin{macrocode}
5380 \if L\eq@layout \box\tw@ \else\unhbox\tw@\fi
5381 \adjust@rel@penalty \unhbox\f@ur
5382 }
5383 % \end{macrocode}
5384 % \end{macro}
5385 %
5386 % Various typesetting bits, invoked from \cs{eq@finish}
5387 % BRM: This has been extensively refactored from the original breqn,
5388 % initially to get left\textbar right skips and parshape used consistently,
5389 % ultimately to get most things handled the same way, in the same order.
5390 %
5391 % Given that left and right skips have been set,
5392 % typeset the frame, number and equation with the
5393 % given number side and placement
5394 %
5395 % \begin{macrocode}
5396 \def\eq@typeset@Unnumbered{%
5397 \eq@typeset@frame
5398 \eq@typeset@equation
5399 }
5400 \def\eq@typeset@LM{%
5401 \setlength\dim@a{(\eq@vspan+\ht\EQ@numbox-\dp\EQ@numbox)/2}%
5402 \eq@typeset@leftnumber
5403 \eq@typeset@frame
5404 \eq@typeset@equation
5405 }
5406 % \end{macrocode}
5407 % Typeset equation and left-top number (and shifted)
5408 % \begin{macrocode}
5409 \def\eq@typeset@LT{%
5410 \dim@a\eq@firstht
5411 \eq@typeset@leftnumber
5412 \eq@typeset@frame
5413 \eq@typeset@equation
5414 }
5415 % \end{macrocode}
5416 % Typeset equation and left shifted number
5417 % \begin{macrocode}
5418 \def\eq@typeset@LShifted{%
5419 % place number
5420 \copy\EQ@numbox \penalty\@M
5421 \dim@a\eqlineskip
5422 \if F\eq@frame\else
5423 \setlength\dim@a{\eq@framesep+\eq@framewd}%
5424 \fi
5425 \kern\dim@a
5426 \eq@typeset@frame
5427 \eq@typeset@equation
5428 }
5429 % \end{macrocode}
5430 % Typeset equation and right middle number
5431 % \begin{macrocode}
5432 \def\eq@typeset@RM{%
5433 \setlength\dim@a{(\eq@vspan+\ht\EQ@numbox-\dp\EQ@numbox)/2}%
5434 \eq@typeset@rightnumber
5435 \eq@typeset@frame
5436 \eq@typeset@equation
5437 }
5438 % \end{macrocode}
5439 % Typeset equation and right bottom number
5440 % \begin{macrocode}
5441 \def\eq@typeset@RB{%
5442 % NOTE: is \eq@dp useful here
5443 \setlength\dim@a{\eq@vspan-\ht\EQ@numbox-\dp\EQ@numbox}%
5444 \eq@typeset@rightnumber
5445 \eq@typeset@frame
5446 \eq@typeset@equation
5447 }
5448 % \end{macrocode}
5449 % Typeset equation and right shifted number
5450 % \begin{macrocode}
5451 \def\eq@typeset@RShifted{%
5452 % place number
5453 \eq@typeset@frame
5454 \eq@typeset@equation
5455 \penalty\@M
5456 \dim@a\eqlineskip
5457 \if F\eq@frame\else
5458 \addtolength\dim@a{\eq@framesep+\eq@framewd}%
5459 \fi
5460 \parskip\dim@a
5461 \hbox to\hsize{\hfil\copy\EQ@numbox}\@@par%
5462 }
5463 % \end{macrocode}
5464 %
5465 % Debugging aid to show all relevant formatting info for a given eqn.
5466 % \begin{macrocode}
5467 %<*trace>
5468 \def\debug@showformat{%
5469 \breqn@debugmsg{Formatting Layout:\eq@layout\space Center/indent: \eqindent\space
5470 Number placement \eqnumside\eqnumplace:
5471 \MessageBreak==== \eq@linewidth=\the\eq@linewidth, \@totalleftmargin=\the\@totalleftmargin,
5472 \MessageBreak==== Centered Lines=\theb@@le\eq@centerlines, Shift Number=\theb@@le\eq@shiftnumber,
5473 \MessageBreak==== \eq@wdT=\the\eq@wdT, \eq@wdMin=\the\eq@wdMin,
5474 \MessageBreak==== LHS=\theb@@le\EQ@hasLHS: \eq@wdL=\the\eq@wdL,
5475 \MessageBreak==== \eq@firstht=\the\eq@firstht, \eq@vspan=\the\eq@vspan
5476 \MessageBreak==== \eq@wdNum=\the\eq@wdNum
5477 \MessageBreak==== \eq@wdCond=\the\eq@wdCond, \conditionsep=\the\conditionsep,
5478 \MessageBreak==== \leftskip=\the\leftskip, \rightskip=\the\rightskip,
5479 \MessageBreak==== \abovedisplayskip=\the\abovedisplayskip,
5480 \MessageBreak==== \belowdisplayskip=\the\belowdisplayskip
5481 \MessageBreak==== parshape=\eq@parshape}%
5482 }
5483 %</trace>
5484 % \end{macrocode}
5485 %
5486 % Set left \& right skips for centered equations,
5487 % making allowances for numbers (if any, right, left) and constraint.
5488 %
5489 % Amazingly, I've managed to collect all the positioning logic for
5490 % centered equations in one place, so it's more manageable.
5491 % Unfortunately, by the time it does all it needs to do,
5492 % it has evolved I'm (re)using so many temp variables, it's becoming
5493 % unmanageble!
5494 %
5495 % \begin{macrocode}
5496 \def\eq@C@setsides{%
5497 % \dim@c = space for number, if any, and not shifted.
5498 \dim@c\z@
5499 \if\eq@hasNumber\if\eq@shiftnumber\else
5500 \dim@c\eq@wdNum
5501 \fi\fi
5502 % \dim@e = space for condition(on right), if any and formula is only a single line.(to center nicely)
5503 % but only count it as being right-aligned if we're not framing, since the frame must enclose it.
5504 \dim@e\z@
5505 \if F\eq@frame
5506 \ifnum\eq@lines=\@ne\ifdim\eq@wdCond>\z@
5507 \setlength\dim@e{\eq@wdCond+\conditionsep}%
5508 \fi\fi\fi
5509 % \dim@b = minimum needed on left max(totalleftmargin, left number space)
5510 \dim@b\z@
5511 \if L\eqnumside\ifdim\dim@b<\dim@c
5512 \dim@b\dim@c
5513 \fi\fi
5514 \ifdim\dim@b<\@totalleftmargin
5515 \dim@b\z@
5516 \else
5517 \addtolength\dim@b{-\@totalleftmargin}%
5518 \fi
5519 % \dim@d = minimum needed on right max(condition, right number space)
5520 \dim@d\dim@e
5521 \if R\eqnumside\ifdim\dim@d<\dim@c
5522 \dim@d\dim@c
5523 \fi\fi
5524 % \dim@a = left margin; initially half available space
5525 % \dim@c = right margin; ditto
5526 \setlength\dim@a{(\eq@linewidth-\eq@wdT+\dim@e+\@totalleftmargin)/2}%
5527 \dim@c=\dim@a
5528 % If too far to the left
5529 \ifdim\dim@a<\dim@b
5530 \addtolength\dim@c{\dim@a-\dim@b}%
5531 \ifdim\dim@c<\z@\dim@c=\z@\fi
5532 \dim@a=\dim@b
5533 % Or if too far to the right
5534 \else\ifdim\dim@c<\dim@d
5535 \addtolength\dim@a{\dim@c-\dim@d}%
5536 \ifdim\dim@a<\z@\dim@a=\z@\fi
5537 \dim@c=\dim@d
5538 \fi\fi
5539 % Now, \dim@d,\dim@e is the left & right glue to center each line for centerlines
5540 \setlength\dim@e{\eq@wdT-\eq@wdMin}\dim@d=\z@
5541 % \end{macrocode}
5542 % NOTE: Need some work here centering when there's a condition
5543 % \begin{macrocode}
5544 % \advance\dim@e-\eq@wdT\multiply\dim@e-1\relax
5545 % \if\eq@wdMin<\dim@e\dim@e\eq@wdMin\fi
5546 % \multiply\dim@e-1\relax\advance\dim@e\eq@wdT
5547 \dim@d\z@
5548 \if\eq@centerlines
5549 \divide\dim@e2\relax
5550 \dim@d=\dim@e
5551 \fi
5552 \setlength\leftskip{\dim@a\@plus\dim@d}%
5553 \addtolength\dim@e{\dim@c}%
5554 \setlength\rightskip{\z@\@plus\dim@e}%\@minus5\p@
5555 % Special case: if framing, reduce the stretchiness of the formula (eg. condition)
5556 % Or if we have a right number, FORCE space for it
5557 \dim@b\z@
5558 \if F\eq@frame\else
5559 \dim@b\dim@c
5560 \fi
5561 \if\@And{\eq@hasNumber}{\@Not{\eq@shiftnumber}}%
5562 \if R\eqnumside
5563 \dim@c\eq@wdNum
5564 \ifdim\dim@c>\dim@b
5565 \dim@b\dim@c
5566 \fi
5567 \fi
5568 \fi
5569 % If either of those cases requires hard rightskip, move that part from glue.
5570 \ifdim\dim@b>\z@
5571 \addtolength\dim@e{-\dim@c}%
5572 \rightskip\dim@b\@plus\dim@e%\@minus5\p@
5573 \fi
5574 % And peculiar further special case: in indented environs, width isn't where it would seem
5575 \ifdim\eq@wdCond>\z@
5576 \addtolength\rightskip{-\@totalleftmargin}%
5577 \fi
5578 \parfillskip\z@skip
5579 }
5580 % \end{macrocode}
5581 %
5582 % Set the left and right side spacing for indented equations
5583 % Some things handled by eq@C@setsides that probably apply here????
5584 % \begin{itemize}
5585 % \item centerlines
5586 % \item \cs{@totalleftmargin}: SHOULD we move farther right?
5587 % \end{itemize}
5588 % Leftskip is normally just the requested indentation
5589 % \begin{macrocode}
5590 \def\eq@I@setsides{%
5591 \leftskip\mathindent
5592 % \end{macrocode}
5593 % But move left, if shifted number presumably because of clashed w/ number?
5594 % \begin{macrocode}
5595 \if\eq@shiftnumber
5596 \setlength\dim@a{\eq@linewidth-\eq@wdT-\mathindent}%
5597 \ifdim\dim@a<\z@
5598 \leftskip=\z@ % Or something minimal?
5599 \fi
5600 \fi
5601 % \end{macrocode}
5602 % Push gently from right.
5603 % \begin{macrocode}
5604 \dim@a=\z@
5605 \setlength\dim@b{\eq@linewidth-\leftskip-\eq@wdMin}%
5606 % \end{macrocode}
5607 % Special case: if framing be much more rigid(?)
5608 % \begin{macrocode}
5609 \if F\eq@frame
5610 \else
5611 \setlength\dim@a{\eq@linewidth-\leftskip-\eq@wdT}
5612 \addtolength\dim@b{-\dim@a}%
5613 \fi
5614 % Or force the space for right number, if needed
5615 % \begin{macrocode}
5616 \if\@And{\eq@hasNumber}{\@Not{\eq@shiftnumber}}%
5617 \if R\eqnumside
5618 \dim@c=\eq@wdNum
5619 \if\dim@c>\dim@a
5620 \addtolength\dim@b{-\dim@c}%
5621 \dim@a=\dim@c
5622 \fi
5623 \fi
5624 \fi
5625 \setlength\rightskip{\dim@a\@plus\dim@b \@minus\hfuzz }%\hfuzz\z@
5626 \parfillskip\z@skip
5627 }
5628 % \end{macrocode}
5629 % \paragraph{Typesetting pieces: frame, equation and number (if any)}
5630 % \cs{dim@a} should contain the downward displacement of number's baseline
5631 % \begin{macrocode}
5632 \def\eq@typeset@leftnumber{%
5633 \setlength\skip@c{\dim@a-\ht\EQ@numbox}%
5634 \vglue\skip@c% NON discardable
5635 \copy\EQ@numbox \penalty\@M
5636 \kern-\dim@a
5637 }
5638 \def\eq@typeset@rightnumber{%
5639 \setlength\skip@c{\dim@a-\ht\EQ@numbox}%
5640 \vglue\skip@c% NON discardable
5641 \hbox to \hsize{\hfil\copy\EQ@numbox}\penalty\@M
5642 \kern-\dim@a
5643 }
5644 \def\eq@typeset@equation{%
5645 \nobreak
5646 \eq@params\eq@parshape
5647 \nointerlineskip
5648 % \noindent
5649 \MaybeRawNoindent
5650 \add@grp@label
5651 \eq@dump@box\unhbox\EQ@box
5652 % \@@par
5653 \RawParEnd
5654 }
5655 % \end{macrocode}
5656 %
5657 % \section{Framing an equation}
5658 % \begin{macro}{\eqframe}
5659 % The \cs{eqframe} function is called in vertical mode
5660 % with the reference point at the top left corner of the equation, including
5661 % any allowance for \cs{fboxsep}. Its arguments are the width
5662 % and height of the equation body, plus fboxsep.
5663 % \changes{v0.95}{2007/12/03}{Made \cs{eqframe} obey the key settings
5664 % for frame and framesep.}
5665 % \begin{macrocode}
5666 \newcommand\eqframe[2]{%
5667 \begingroup
5668 \fboxrule=\eq@framewd\relax\fboxsep=\eq@framesep\relax
5669 \framebox{\z@rule\@height#2\kern#1}%
5670 \endgroup
5671 }
5672 % \end{macrocode}
5673 % \end{macro}
5674 % The frame is not typeset at the correct horizontal position. Will
5675 % fix later.
5676 % \begin{macrocode}
5677 \def\eq@addframe{%
5678 \hbox to\z@{%
5679 \setlength\dim@a{\eq@framesep+\eq@framewd}%
5680 \kern-\dim@a
5681 \vbox to\z@{\kern-\dim@a
5682 \hbox{\eqframe{\eq@wdT}{\eq@vspan}}%
5683 \vss
5684 }%
5685 \hss
5686 }%
5687 }
5688 \def\eq@typeset@frame{%
5689 \if F\eq@frame\else
5690 % Tricky: put before \noindent, so it's not affected by glue in \leftskip
5691 \nobreak\nointerlineskip
5692 \vbox to\eq@firstht{\moveright\leftskip\hbox to\z@{\eq@addframe\hss}\vss}%
5693 \kern-\eq@firstht
5694 \fi
5695 }
5696 % \end{macrocode}
5697 %
5698 % \section{Delimiter handling}
5699 % The special handling of delimiters is rather complex, but
5700 % everything is driven by two motives: to mark line breaks inside
5701 % delimiters as less desirable than line breaks elsewhere, and to make it
5702 % possible to break open left-right boxes so that line breaks between
5703 % \cs{left} and \cs{right} delimiters are not absolutely
5704 % prohibited. To control the extent to which line breaks will be
5705 % allowed inside delimiters, set \cs{eqbreakdepth} to the maximum
5706 % nesting depth. Depth 0 means never break inside delimiters.
5707 %
5708 % Note: \cs{eqbreakdepth} is not implemented as a \latex
5709 % counter because changes done by \cs{setcounter} \etc are always
5710 % global.
5711 %
5712 % It would be natural to use grouping in the implementation
5713 % \mdash at an open delimiter, start a group and increase mathbin
5714 % penalties; at a close delimiter, close the group. But this gives us
5715 % trouble in situations like the \env{array} environment, where a
5716 % close delimiter might fall in a different cell of the \cs{halign}
5717 % than the open delimiter.
5718 % Ok then, here's what we want the various possibilities to
5719 % expand to. Note that \cs{right} and \cs{biggr} are
5720 % being unnaturally applied to a naturally open-type delimiter.
5721 % \begin{literalcode}
5722 % ( -> \delimiter"4... \after@open
5723 % \left( ->
5724 % \@@left \delimiter"4... \after@open
5725 % \right( ->
5726 % \@@right \delimiter"4... \after@close
5727 % \biggl( ->
5728 % \mathopen{\@@left \delimiter... \vrule...\@@right.}
5729 % \after@open
5730 % \biggr( ->
5731 % \mathclose{\@@left \delimiter... \vrule...\@@right.}
5732 % \after@close
5733 % \bigg\vert ->
5734 % \mathord{\@@left \delimiter... \vrule...\@@right.}
5735 % \biggm\vert ->
5736 % \mathrel{\@@left \delimiter... \vrule...\@@right.}
5737 % \end{literalcode}
5738 %
5739 % First save the primitive meanings of \cs{left} and
5740 % \cs{right}.
5741 % \begin{macrocode}
5742 \@saveprimitive\left\@@left
5743 \@saveprimitive\right\@@right
5744 % \end{macrocode}
5745 %
5746 % The variable \cs{lr@level} is used by the first mathrel in
5747 % an equation to tell whether it is at top level: yes? break and measure
5748 % the LHS, no? keep going.
5749 % \begin{macrocode}
5750 \newcount\lr@level
5751 % \end{macrocode}
5752 %
5753 % It would be nice to have better error checking here if the
5754 % argument is not a delimiter symbol at all.
5755 %
5756 % Ah, a small problem when renaming commands. In the original version,
5757 % |\delimiter| is hijacked in order to remove the |\after@bidir| (or
5758 % open or close) instruction following the delimiter declaration.
5759 % \begin{macrocode}
5760 \ExplSyntaxOn
5761 \def\eq@left{%
5762 \@ifnext .{\eq@nullleft}{\begingroup \let\math_delimiter:NNnNn \eq@left@a}%
5763 }
5764 \def\eq@right{%
5765 \@ifnext .{\eq@nullright}{\begingroup \let \math_delimiter:NNnNn \eq@right@a}%
5766 }
5767 % \end{macrocode}
5768 % The arguments are: \arg1 delim symbol, \arg2 .
5769 % \begin{macrocode}
5770 %\def\eq@left@a#1 #2{\endgroup\@@left\delimiter#1\space \after@open}
5771 \def\eq@left@a#1#2#3#4#5#6{\endgroup
5772 \@@left \math_delimiter:NNnNn #1#2{#3}#4{#5}\after@open}
5773 \def\eq@right@a#1#2#3#4#5#6{\endgroup
5774 \@@right \math_delimiter:NNnNn #1#2{#3}#4{#5}\after@close \ss@scan{#1#2{#3}#4{#5}}%
5775 }
5776 \ExplSyntaxOff
5777 % \end{macrocode}
5778 % The null versions.
5779 % \begin{macrocode}
5780 \def\eq@nullleft#1{\@@left#1\after@open}
5781 \def\eq@nullright#1{\@@right#1\after@close}
5782 % \end{macrocode}
5783 %
5784 % Here is the normal operation of \cs{biggl}, for example.
5785 % \begin{literalcode}
5786 % \biggl ->\mathopen \bigg
5787 % {\mathopen}
5788 %
5789 % \bigg #1->{\hbox {$\left #1\vbox to14.5\p@ {}\right .\n@space $}}
5790 % #1<-(
5791 % \end{literalcode}
5792 % ^^AFor paren matching: )
5793 % Like \cs{left}, \cs{biggl} coerces its delimiter to be of
5794 % mathopen type even if its natural inclination is towards closing.
5795 %
5796 % The function \cs{delim@reset} makes delimiter characters
5797 % work just about the same as they would in normal \latex .
5798 % \begin{macrocode}
5799 \def\delim@reset{%
5800 \let\after@open\relax \let\after@close\relax
5801 \let\left\@@left \let\right\@@right
5802 }
5803 % \end{macrocode}
5804 % If the \pkg{amsmath} or \pkg{exscale} package is loaded, it
5805 % will have defined \cs{bBigg@}; if not, the macros \cs{big} and
5806 % variants will have hard-coded point sizes as inherited through the ages
5807 % from \fn{plain.tex}. In this case we can kluge a little by
5808 % setting \cs{big@size} to \cs{p@}, so that our definition of
5809 % \cs{bBigg@} will work equally well with the different multipliers.
5810 % \begin{macrocode}
5811 \@ifundefined{bBigg@}{% not defined
5812 \let\big@size\p@
5813 \def\big{\bBigg@{8.5}}\def\Big{\bBigg@{11.5}}%
5814 \def\bigg{\bBigg@{14.5}}\def\Bigg{\bBigg@{17.5}}%
5815 \def\biggg{\bBigg@{20.5}}\def\Biggg{\bBigg@{23.5}}%
5816 }{}
5817 \def\bBigg@#1#2{%
5818 {\delim@reset
5819 \left#2%
5820 \vrule\@height#1\big@size\@width-\nulldelimiterspace
5821 \right.
5822 }%
5823 }
5824 % \end{macrocode}
5825 % .
5826 % \begin{macrocode}
5827 \def\bigl#1{\mathopen\big{#1}\after@open}
5828 \def\Bigl#1{\mathopen\Big{#1}\after@open}
5829 \def\biggl#1{\mathopen\bigg{#1}\after@open}
5830 \def\Biggl#1{\mathopen\Bigg{#1}\after@open}
5831 \def\bigggl#1{\mathopen\biggg{#1}\after@open}
5832 \def\Bigggl#1{\mathopen\Biggg{#1}\after@open}
5833
5834 \def\bigr#1{\mathclose\big{#1}\after@close}
5835 \def\Bigr#1{\mathclose\Big{#1}\after@close}
5836 \def\biggr#1{\mathclose\bigg{#1}\after@close}
5837 \def\Biggr#1{\mathclose\Bigg{#1}\after@close}
5838 \def\bigggr#1{\mathclose\biggg{#1}\after@close}
5839 \def\Bigggr#1{\mathclose\Biggg{#1}\after@close}
5840
5841 %% No change needed, I think. [mjd,1998/12/04]
5842 %%\def\bigm{\mathrel\big}
5843 %%\def\Bigm{\mathrel\Big}
5844 %%\def\biggm{\mathrel\bigg}
5845 %%\def\Biggm{\mathrel\Bigg}
5846 %%\def\bigggm{\mathrel\biggg}
5847 %%\def\Bigggm{\mathrel\Biggg}
5848 % \end{macrocode}
5849 %
5850 %
5851 % \begin{macro}{\m@@DeL} \begin{macro}{\d@@DeL}
5852 % \begin{macro}{\m@@DeR} \begin{macro}{\d@@DeR}
5853 % \begin{macro}{\m@@DeB} \begin{macro}{\d@@DeB}
5854 % Original definition of \cs{m@DeL} from
5855 % \pkg{flexisym} is as follows. \cs{m@DeR} and
5856 % \cs{m@DeB} are the same except for the math class number.
5857 % \begin{literalcode}
5858 % \def\m@DeL#1#2#3{%
5859 % \delimiter"4\@xp\delim@a\csname sd@#1#2#3\endcsname #1#2#3 }
5860 % \end{literalcode}
5861 %
5862 % Save the existing meanings of \cs{m@De[LRB]}.
5863 %
5864 % Define display variants of DeL, DeR, DeB
5865 % \begin{macrocode}
5866 \ExplSyntaxOn
5867 \cs_set:Npn \math_dsym_DeL:Nn #1#2{\math_bsym_DeL:Nn #1{#2}\after@open}
5868 \cs_set:Npn \math_dsym_DeR:Nn #1#2{\math_bsym_DeR:Nn #1{#2}\after@close}
5869 \cs_set:Npn \math_dsym_DeB:Nn #1#2{\math_bsym_DeB:Nn #1{#2}\after@bidir}
5870
5871 %%%%%
5872 %%%%%\let\m@@DeL\m@DeL \let\m@@DeR\m@DeR \let\m@@DeB\m@DeB
5873 %%%%%\def\d@@DeL#1#2#3{%
5874 %%%%% \delimiter"4\@xp\delim@a\csname sd@#1#2#3\endcsname #1#2#3 \after@open
5875 %%%%%}
5876 %%%%%\def\d@@DeR#1#2#3{%
5877 %%%%% \delimiter"5\@xp\delim@a\csname sd@#1#2#3\endcsname #1#2#3 \after@close
5878 %%%%%}
5879 %%%%%\def\d@@DeB#1#2#3{%
5880 %%%%% \delimiter"0\@xp\delim@a\csname sd@#1#2#3\endcsname #1#2#3 \after@bidir
5881 %%%%%}
5882 % \end{macrocode}
5883 %%BRM: These weren't defined, but apparently should be.
5884 % Are these the right values???
5885 % \begin{macrocode}
5886 %%%%%%\let\m@@DeA\m@DeA\let\d@@DeA\m@DeA%
5887 % \end{macrocode}
5888 % \end{macro}
5889 % \end{macro}
5890 % \end{macro}
5891 % \end{macro}
5892 % \end{macro}
5893 % \end{macro}
5894 %
5895 % \begin{macro}{\after@open}
5896 % \begin{macro}{\after@close}
5897 % \begin{macro}{\after@bidir}
5898 % \begin{macro}{\zero@bop}
5899 % \begin{macro}{\bop@incr}
5900 % \cs{after@open} and \cs{after@close} are carefully
5901 % written to avoid the use of grouping and to run as fast as possible.
5902 % \cs{zero@bop} is the value used for \cs{prebinoppenalty} at
5903 % delimiter level 0, while \cs{bop@incr} is added for each level of
5904 % nesting. The standard values provide that breaks will be prohibited
5905 % within delimiters below nesting level 2.
5906 % \begin{macrocode}
5907 \let\after@bidir\@empty
5908 \mathchardef\zero@bop=888 \relax
5909 \mathchardef\bop@incr=4444 \relax
5910 \def\after@open{%
5911 \global\advance\lr@level\@ne
5912 \prebinoppenalty\bop@incr \multiply\prebinoppenalty\lr@level
5913 \advance\prebinoppenalty\zero@bop
5914 \ifnum\eqbreakdepth<\lr@level
5915 \cs_set_eq:NN \math_sym_Bin:Nn \math_isym_Bin:Nn %%%%%%\let\m@Bin\m@@Bin
5916 % \end{macrocode}
5917 % Inside delimiters, add some fillglue before binops so that a broken off
5918 % portion will get thrown flush right. Also shift it slightly
5919 % further to the right to ensure that it clears the opening delimiter.
5920 % \begin{macrocode}
5921 \else
5922 \eq@binoffset=\eqbinoffset
5923 \advance\eq@binoffset\lr@level\eqdelimoffset plus1fill\relax
5924 \def\dt@fill@cancel{\hskip\z@ minus1fill\relax}%
5925 \fi
5926 \penalty\@M % BRM: discourage break after an open fence?
5927 }
5928 \def\after@close{%
5929 \global\advance\lr@level\m@ne
5930 \prebinoppenalty\bop@incr \multiply\prebinoppenalty\lr@level
5931 \advance\prebinoppenalty\zero@bop
5932 \ifnum\eqbreakdepth<\lr@level
5933 \else \cs_set_eq:NN \math_sym_Bin:Nn \math_dsym_Bin:Nn %%%%%%\let\m@Bin\d@@Bin
5934 \fi
5935 % \end{macrocode}
5936 % When we get back to level 0, no delimiters, remove the stretch
5937 % component of \cs{eqbinoffset}.
5938 % \begin{macrocode}
5939 \ifnum\lr@level<\@ne \eq@binoffset=\eqbinoffset\relax \fi
5940 }
5941
5942 \ExplSyntaxOff
5943
5944 % \end{macrocode}
5945 % \end{macro}
5946 % \end{macro}
5947 % \end{macro}
5948 % \end{macro}
5949 % \end{macro}
5950 %
5951 %
5952 % \begin{macro}{\subsup@flag}
5953 % \begin{macro}{\ss@scan}
5954 % \cs{ss@scan} is called after a \cs{right} delimiter and
5955 % looks ahead for sub and superscript tokens.
5956 % If sub and/or superscripts are present, we adjust the line-ending
5957 % penalty to distinguish the various cases (sub, sup, or both).
5958 % This facilitates the later work of excising the sub/sup box and
5959 % reattaching it with proper shifting.
5960 %
5961 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5962 % Sub/Superscript measurement
5963 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5964 % BRM: There's possibly a problem here.
5965 % When \cs{ss@scan} gets invoked after a \cs{left}...\cs{right} pair in the LHS
5966 % during \cs{eq@measure}, it produces an extra box (marked with \cs{penalty} 3);
5967 % Apparently \cs{eq@repack} expects only one for the LHS.
5968 % The end result is \cs{eq@wdL} => 0.0pt !!! (or at least very small)
5969 % \begin{macrocode}
5970 \let\subsup@flag=\count@
5971 \def\ss@delim@a@new#1#2#3#4#5{\xdef\right@delim@code{\number"#4#5}}
5972 % \end{macrocode}
5973 % The argument of \cs{ss@scan} is an expanded form of a
5974 % right-delimiter macro.
5975 % We want to use the last three digits in the expansion
5976 % to define \cs{right@delim@code}.
5977 % The assignment to a temp register is just a way to scan away the
5978 % leading digits that we don't care about.
5979 % \begin{macrocode}
5980 \def\ss@scan#1{%
5981 % \end{macrocode}
5982 % This part of the code.
5983 % \begin{macrocode}
5984 \begingroup
5985 \ss@delim@a@new #1%
5986 \endgroup
5987 \subsup@flag\@M \afterassignment\ss@scan@a \let\@let@token=}
5988 \def\ss@scan@a{%
5989 \let\breqn@next\ss@scan@b
5990 \ifx\@let@token\sb \advance\subsup@flag\@ne\else
5991 \ifx\@let@token\@@subscript \advance\subsup@flag\@ne\else
5992 \ifx\@let@token\@@subscript@other \advance\subsup@flag\@ne\else
5993 \ifx\@let@token\sp \advance\subsup@flag\tw@\else
5994 \ifx\@let@token\@@superscript \advance\subsup@flag\tw@\else
5995 \ifx\@let@token\@@superscript@other \advance\subsup@flag\tw@\else
5996 \ss@finish
5997 \let\breqn@next\relax
5998 \fi\fi\fi\fi\fi\fi
5999 \breqn@next\@let@token
6000 }
6001 % \end{macrocode}
6002 %
6003 % \begin{macrocode}
6004 \ExplSyntaxOn
6005 \def\ss@scan@b#1#2{#1{%
6006 % \end{macrocode}
6007 % hack! coff!
6008 % \begin{macrocode}
6009 %%%%%\let\m@Bin\m@@Bin \let\m@Rel\m@@Rel
6010 \cs_set_eq:NN \math_sym_Bin:Nn \math_isym_Bin:Nn
6011 \cs_set_eq:NN \math_sym_Rel:Nn \math_isym_Rel:Nn
6012 #2}\afterassignment\ss@scan@a \let\@let@token=}%
6013 \ExplSyntaxOff
6014 % \end{macrocode}
6015 % We need to keep following glue from disappearing
6016 % \mdash \eg , a thickmuskip or medmuskip from a following mathrel or
6017 % mathbin symbol.
6018 % \begin{macrocode}
6019 \def\ss@finish{%
6020 \@@vadjust{\penalty\thr@@}%
6021 \penalty\right@delim@code \penalty-\subsup@flag \keep@glue
6022 }
6023 % \end{macrocode}
6024 % \end{macro}
6025 % \end{macro}
6026 %
6027 %
6028 % \begin{macro}{\eq@lrunpack}
6029 % For \cs{eq@lrunpack} we need to break open a left-right box and
6030 % reset it just in case it contains any more special breaks. After
6031 % it is unpacked the recursion of \cs{eq@repack} will continue,
6032 % acting on the newly created lines.
6033 % \begin{macrocode}
6034 \def\eq@lrunpack{\setbox\z@\lastbox
6035 % \end{macrocode}
6036 % We remove the preceding glue item and deactivate
6037 % baselineskip for the next line, otherwise we would end up with
6038 % three items of glue (counting parskip) at this point instead of
6039 % the single one expected by our recursive repacking
6040 % procedure.
6041 % \begin{macrocode}
6042 \unskip \nointerlineskip
6043 % \end{macrocode}
6044 % Then we open box 0, take the left-right box at the right end of
6045 % it, and break that open. If the line-ending penalty is greater than
6046 % 10000, it means a sub and/or superscript is present on the right
6047 % delimiter and the box containing them must be taken off first.
6048 % \begin{macrocode}
6049 % \noindent
6050 \MaybeRawNoindent
6051 \unhbox\z@ \unskip
6052 \subsup@flag-\lastpenalty \unpenalty
6053 \xdef\right@delim@code{\number\lastpenalty}%
6054 \unpenalty
6055 \ifnum\subsup@flag>\@M
6056 \advance\subsup@flag-\@M
6057 \setbox\tw@\lastbox
6058 \else \setbox\tw@\box\voidb@x
6059 \fi
6060 \setbox\z@\lastbox
6061 \ifvoid\tw@ \unhbox\z@
6062 \else \lrss@reattach % uses \subsup@flag, box\z@, box\tw@
6063 \fi
6064 % \end{macrocode}
6065 % The reason for adding a null last line here is that the last
6066 % line will contain parfillskip in addition to rightskip, and a final
6067 % penalty of $10000$ instead of $-1000N$
6068 % ($1\leq N\leq 9$), which would interfere with the usual
6069 % processing. Setting a null last line and discarding it dodges
6070 % this complication. The penalty value $-10001$ is a no-op case
6071 % in the case statement of \cs{eq@repacka}.
6072 % \begin{macrocode}
6073 \penalty-\@Mi\z@rule
6074 % \@@par
6075 \RawParEnd
6076 \setbox\z@\lastbox \unskip\unpenalty
6077 %%{\showboxbreadth\maxdimen\showboxdepth99\showlists}%
6078 }
6079 % \end{macrocode}
6080 % \end{macro}
6081 %
6082 %
6083 % \begin{macro}{\lrss@reattach}
6084 %
6085 % Well, for a small self-contained computation, carefully
6086 % hand-allocated dimens should be safe enough. But let the
6087 % maintainer beware! This code cannot be arbitrarily transplanted
6088 % or shaken up without regard to grouping and interaction with other
6089 % hand-allocated dimens.
6090 % \begin{macrocode}
6091 \dimendef\sub@depth=8 \dimendef\sup@base=6
6092 \dimendef\prelim@sub@depth=4 \dimendef\prelim@sup@base=2
6093 \def\sym@xheight{\fontdimen5\textfont\tw@}
6094 \def\sup@base@one{\fontdimen13\textfont\tw@}
6095 \def\sub@base@one{\fontdimen16\textfont\tw@}
6096 \def\sub@base@two{\fontdimen17\textfont\tw@}
6097 % \end{macrocode}
6098 % Note that only \cs{sup@drop} and \cs{sub@drop} come from
6099 % the next smaller math style.
6100 % \begin{macrocode}
6101 \def\sup@drop{\fontdimen18\scriptfont\tw@}
6102 \def\sub@drop{\fontdimen19\scriptfont\tw@}
6103 % \end{macrocode}
6104 % Provide a mnemonic name for the math axis fontdimen, if it's not
6105 % already defined.
6106 % \begin{macrocode}
6107 \providecommand{\mathaxis}{\fontdimen22\textfont\tw@}
6108 % \end{macrocode}
6109 %
6110 % Assumes box 2 contains the sub/sup and box 0 contains the left-right
6111 % box. This is just a repeat of the algorithm in \fn{tex.web},
6112 % with some modest simplifications from knowing that this is only going to
6113 % be called at top level in a displayed equation, thus always mathstyle =
6114 % uncramped displaystyle.
6115 % \begin{macrocode}
6116 \def\lrss@reattach{%
6117 \begingroup
6118 % "The TeXbook" Appendix G step 18:
6119 \setlength\prelim@sup@base{\ht\z@-\sup@drop}%
6120 \setlength\prelim@sub@depth{\dp\z@ +\sub@drop}%
6121 \unhbox\z@
6122 \ifcase\subsup@flag % case 0: this can't happen
6123 \or \lr@subscript % case 1: subscript only
6124 \or \lr@superscript % case 2: superscript only
6125 \else \lr@subsup % case 3: sub and superscript both
6126 \fi
6127 \endgroup
6128 }
6129 % \end{macrocode}
6130 % \begin{macrocode}
6131 \def\lr@subscript{%
6132 \sub@depth\sub@base@one
6133 \ifdim\prelim@sub@depth>\sub@depth \sub@depth\prelim@sub@depth\fi
6134 \setlength\dim@a{\ht\tw@ -.8\sym@xheight}%
6135 \ifdim\dim@a>\sub@depth \sub@depth=\dim@a \fi
6136 \twang@adjust\sub@depth
6137 \lower\sub@depth\box\tw@
6138 }
6139 % \end{macrocode}
6140 %
6141 % \begin{macrocode}
6142 \def\lr@superscript{%
6143 \sup@base\sup@base@one
6144 \ifdim\prelim@sup@base>\sup@base \sup@base\prelim@sup@base\fi
6145 \setlength\dim@a{\dp\tw@ -.25\sym@xheight}%
6146 \ifdim\dim@a>\sup@base \sup@base\dim@a \fi
6147 \twang@adjust\sup@base
6148 \raise\sup@base\box\tw@
6149 }
6150 % \end{macrocode}
6151 %
6152 % \begin{macrocode}
6153 \def\lr@subsup{%
6154 \sub@depth\sub@base@two
6155 \ifdim\prelim@sub@depth>\sub@depth \sub@depth\prelim@sub@depth \fi
6156 \twang@adjust\sub@depth
6157 \lower\sub@depth\box\tw@
6158 }
6159 % \end{macrocode}
6160 %
6161 % For delimiters that curve top and bottom, the twang factor allows
6162 % horizontal shifting of the sub and superscripts so they don't
6163 % fall too far away (or too close for that matter). This is
6164 % accomplished by arranging for (\eg ) \verb"\right\rangle" to leave
6165 % a penalty $N$ in the math list before the subsup penalty that triggers
6166 % \cs{lrss@reattach}, where $N$ is the mathcode of
6167 % \cs{rangle} (ignoring \dquoted{small} variant).
6168 % \begin{macrocode}
6169 \def\twang@adjust#1{%
6170 \begingroup
6171 \@ifundefined{twang@\right@delim@code}{}{%
6172 \setlength\dim@d{#1-\mathaxis}%
6173 % put an upper limit on the adjustment
6174 \ifdim\dim@d>1em \dim@d 1em \fi
6175 \kern\csname twang@\right@delim@code\endcsname\dim@d
6176 }%
6177 \endgroup
6178 }
6179 % \end{macrocode}
6180 % The method used to apply a \dquoted{twang} adjustment is just an
6181 % approximate solution to a complicated problem.
6182 % We make the following assumptions that hold true, approximately,
6183 % for the most common kinds of delimiters:
6184 % \begin{enumerate}
6185 % \item
6186 % The right delimiter is symmetrical top to bottom.
6187 %
6188 %
6189 % \item There is an upper limit on the size of the adjustment.
6190 %
6191 %
6192 % \item When we have a superscript, the amount of left-skew that we
6193 % want to apply is linearly proportional to the distance of the bottom
6194 % left corner of the superscript from the math axis, with the ratio
6195 % depending on the shape of the delimiter symbol.
6196 %
6197 %
6198 % \end{enumerate}
6199 % .
6200 % By symmetry, Assumption 3 is true also for subscripts (upper left
6201 % corner).
6202 % Assumption 2 is more obviously true for parens and braces, where the
6203 % largest super-extended versions consist of truly vertical parts with
6204 % slight bending on the ends, than it is for a \cs{rangle}.
6205 % But suppose for the sake of expediency that it is
6206 % approximately true for rangle symbols also.
6207 %
6208 %
6209 % Here are some passable twang factors for the most common types of
6210 % delimiters in \fn{cmex10}, as determined by rough measurements from
6211 % magnified printouts.
6212 % \begin{literalcode}
6213 % vert bar, double vert: 0
6214 % square bracket: -.1
6215 % curly brace: -.25
6216 % parenthesis: -.33
6217 % rangle: -.4
6218 % \end{literalcode}
6219 % Let's provide a non-private command for changing the twang factor of
6220 % a given symbol.
6221 % \begin{macrocode}
6222 \newcommand{\DeclareTwang}[2]{%
6223 \ifcat.\@nx#1\begingroup
6224 \lccode`\~=`#1\lowercase{\endgroup \DeclareTwang{~}}{#2}%
6225 \else
6226 \@xp\decl@twang#1?\@nil{#2}%
6227 \fi
6228 }
6229 % \end{macrocode}
6230 % Note that this is dependent on a fixed interpretation of the
6231 % mathgroup number \arg4 .
6232 % \begin{macrocode}
6233 \def\decl@twang#1#2#3#4#5#6#7\@nil#8{%
6234 \@namedef{twang@\number"#4#5#6}{#8}%
6235 }
6236 \DeclareTwang{\rangle}{-.4}
6237 \DeclareTwang{)}{-.33}
6238 \DeclareTwang{\rbrace}{-.25}
6239 % \end{macrocode}
6240 % \end{macro}
6241 %
6242 %
6243 %
6244 % \section{Series of expressions}
6245 % The \env{dseries} environment is for a display
6246 % containing a series of expressions of the form \quoted{A, B} or \quoted{A and
6247 % B} or \quoted{A, B, and C} and so on. Typically the expressions
6248 % are separated by a double quad of space. If the expressions in a
6249 % series don't all fit in a single line, they are continued onto extra
6250 % lines in a ragged-center format.
6251 % \begin{macrocode}
6252 \newenvironment{dseries}{\let\eq@hasNumber\@True \breqn@optarg\@dseries{}}{}%
6253 \def\enddseries#1{\check@punct@or@qed}%
6254 % \end{macrocode}
6255 %
6256 % And the unnumbered version of same.
6257 % \begin{macrocode}
6258 \newenvironment{dseries*}{\let\eq@hasNumber\@False \breqn@optarg\@dseries{}}{}%
6259 \@namedef{enddseries*}#1{\check@punct@or@qed}%
6260 \@namedef{end@dseries*}{\end@dseries}%
6261 \def\@dseries[#1]{%
6262 % \end{macrocode}
6263 % Turn off the special breaking behavior of mathrels \etc for math
6264 % formulas embedded in a \env{dseries} environment.
6265 %
6266 %BRM: DS Expermient: Use alternative display setup.
6267 % \begin{macrocode}
6268 % \def\display@setup{\displaystyle}%
6269 \let\display@setup\dseries@display@setup
6270 % Question: should this be the default for dseries???
6271 % \let\eq@centerlines\@True
6272 \global\eq@wdCond\z@
6273 % \end{macrocode}
6274 % BRM: use special layout for dseries
6275 % \begin{macrocode}
6276 % \@dmath[#1]%
6277 \@dmath[layout={M},#1]%
6278 \mathsurround\z@\@@math \penalty\@Mi
6279 \let\endmath\ends@math
6280 \def\premath{%
6281 % \end{macrocode}
6282 % BRM: Tricky to cleanup space OR add space ONLY BETWEEN math!
6283 % FMi: improvement to measure against current font.
6284 % \begin{macrocode}
6285 \ifdim\lastskip<\fontdimen2\font \unskip
6286 \else\ifnum\lastpenalty<\@M \dquad\fi\fi
6287 }%
6288 % \end{macrocode}
6289 %BRM: Tricky; if a subformula breaks, we'd like to start the next on new line!
6290 % \begin{macrocode}
6291 \def\postmath{\unpenalty\eq@addpunct \penalty\intermath@penalty \dquad \@ignoretrue}%
6292 \ignorespaces
6293 }
6294 \def\end@dseries{%
6295 \unskip\unpenalty
6296 \@@endmath \mathsurround\z@ \end@dmath
6297 }
6298 % \end{macrocode}
6299 % BRM: Try this layout for dseries: Essentially layout i, but w/o
6300 % limit to 1 line. And no fallback!
6301 % \begin{macrocode}
6302 \def\eq@try@layout@M{%
6303 \edef\@parshape{\parshape 1 0pt \the\eq@linewidth\relax}%
6304 \eq@trial@b{M}{}%
6305 }
6306 % \end{macrocode}
6307 % BRM: Tricky to get right value here.
6308 % Prefer breaks between formula if we've got to break at all.
6309 % \begin{macrocode}
6310 %\def\intermath@penalty{-201}%
6311 \def\intermath@penalty{-221}%
6312 % \end{macrocode}
6313 % BRM: A bit tighter than it was ( 1em minus.25em )
6314 % \begin{macrocode}
6315 %\newcommand\dquad{\hskip0.4em}
6316 \newcommand\dquad{\hskip0.6em minus.3em}
6317 \newcommand\premath{}\newcommand\postmath{}
6318 % \end{macrocode}
6319 %
6320 % Change the \env{math} environment to add
6321 % \cs{premath} and \cs{postmath}. They are no-ops except
6322 % inside a \env{dseries} environment.
6323 %
6324 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6325 % Redefinition of math environment to take advantage of dseries env.
6326 % \begin{macrocode}
6327 \renewenvironment{math}{%
6328 \leavevmode \premath
6329 \ifmmode\@badmath\else\@@math\fi
6330 }{%
6331 \ifmmode\@@endmath\else\@badmath\fi
6332 }
6333 \def\ends@math#1{\check@punct@or@qed}
6334 \def\end@math{%
6335 \ifmmode\@@endmath\else\@badmath\fi
6336 \postmath
6337 }
6338 % \end{macrocode}
6339 %
6340 %
6341 %
6342 %
6343 % \section{Equation groups}
6344 % For many equation groups the strategy is easy: just center each
6345 % equation individually following the normal rules for a single
6346 % equation. In some groups, each equation gets its own number; in
6347 % others, a single number applies to the whole group (and may need to be
6348 % vertically centered on the height of the group). In still other
6349 % groups, the equations share a parent number but get individual equation
6350 % numbers consisting of parent number plus a letter.
6351 %
6352 % If the main relation symbols in a group of equations are to be
6353 % aligned, then the final alignment computations cannot be done until the
6354 % end of the group \mdash \ie , the horizontal positioning of the first
6355 % $n - 1$ equations cannot be done immediately. Yet because of
6356 % the automatic line breaking, we cannot calculate an initial value of
6357 % RHS-max over the whole group unless we do a trial run on each equation
6358 % first to find an RHS-max for that equation. Once we know RHS-group-max
6359 % and LHS-group-max we must redo the trial set of each equation because
6360 % they may affect the line breaks. If the second trial for an
6361 % equation fails (one of its lines exceeds the available width), but
6362 % the first one succeeded, fall back to the first trial, \ie let that
6363 % equation fall out of alignment with the rest of the group.
6364 %
6365 %
6366 % All right then, here is the general idea of the whole algorithm for
6367 % group alignment.
6368 % To start with, ignore the possibility of equation numbers so that
6369 % our equation group has the form:
6370 % \begin{literalcode}
6371 % LHS[1] RHS[1,1] RHS[1,2] ... RHS[1,n[1]]
6372 % LHS[2] RHS[2,1] RHS[2,2] ... RHS[2,n[2]]
6373 % ...
6374 % LHS[3] RHS[3,1] RHS[3,2] ... RHS[3,n[3]]
6375 % \end{literalcode}
6376 % The number of RHS's might not be the same for all of the
6377 % equations.
6378 % First, accumulate all of the equation contents in a queue, checking
6379 % along the way to find the maximum width of all the LHS's and the maximum
6380 % width of all the RHS's.
6381 % Call these widths maxwd\_L and maxwd\_R.
6382 % Clearly if maxwd\_L + maxwd\_R is less than or equal to the available
6383 % equation width then aligning all of the equations is going to be simple.
6384 %
6385 %
6386 % Otherwise we are going to have to break at least one of the RHS's
6387 % and/or at least one of the LHS's.
6388 % The first thing to try is using maxwd\_L for the LHS's and breaking
6389 % all the RHS's as needed to fit in the remaining space.
6390 % However, this might be a really dumb strategy if one or more of the
6391 % LHS's is extraordinarily wide.
6392 % So before trying that we check whether maxwd\_L exceeds some
6393 % threshold width beyond which it would be unsensible not to break the LHS.
6394 % Such as, max(one-third of the available width; six ems), or
6395 % something like that.
6396 % Or how about this?
6397 % Compare the average LHS width and RHS width and divide up the available
6398 % width in the same ratio for line breaking purposes.
6399 %
6400 %
6401 % BRM: Fairly broad changes; it mostly didn't work before (for me).
6402 %
6403 % \begin{description}
6404 % \item[\cs{begin}\csarg{dgroup} produces a `numbered' group]
6405 % The number is the next equation number.
6406 % There are 2 cases:
6407 % \begin{itemize}
6408 % \item If ANY contained equations are numbered (|\begin{dmath}|),
6409 % then they will be subnumbered: eg 1.1a
6410 % and the group number is not otherwise displayed.
6411 % \item If ALL contained equations are unnumbered (|\begin{dmath*}|)
6412 % then the group, as a whole, gets a number displayed,
6413 % using the same number placement as for equations.
6414 % \end{itemize}
6415 % \item[\cs{begin}\csarg{dgroup*} produces an unnumbered group.]
6416 % Contained equations are numbered, or not, as normal.
6417 % But note that in the mixed case, it's too late to
6418 % force the unnumbered eqns to \cs{retry@with@number}
6419 % We'll just do a simple check of dimensions, after the fact,
6420 % and force a shiftnumber if we're stuck.
6421 %
6422 % NOTE: Does this work for dseries, as well? (alignment?)
6423 %
6424 % NOTE: Does \cs{label} attach to the expected thing?
6425 %
6426 % \item[For number placement] We use shiftnumber placement on ALL equations
6427 % if ANY equations need it, or if an unnumbered equation is too
6428 % wide to be aligned, given that the group or other eqns are numbered.
6429 % [does this latter case interract with the chosen alignment?]
6430 %
6431 % \item[For Alignment]
6432 % As currently coded, it tries to align on relations, by default.
6433 % If LHS's are not all present, or too long, it switches to left-justify.
6434 % Maybe there are other cases that should switch?
6435 % Should there be a case for centered?
6436 %
6437 % NOTE: Should there be some options to choose alignment?
6438 % \end{description}
6439 %
6440 % \begin{macro}{\eq@group}
6441 % \begin{macro}{\GRP@top}
6442 %
6443 % \begin{macrocode}
6444 \let\eq@group\@False
6445 \let\grp@shiftnumber\@False
6446 \let\grp@hasNumber\@False
6447 \let\grp@eqs@numbered\@False
6448 \let\grp@aligned\@True
6449 % \end{macrocode}
6450 % \end{macro}
6451 % \end{macro}
6452 %
6453 %
6454 % Definition of the \env{dgroup} environment.
6455 % \begin{macrocode}
6456 \newenvironment{dgroup}{%
6457 \@dgroup@start@hook
6458 \let\grp@hasNumber\@True\breqn@optarg\@dgroup{}%
6459 }{%
6460 \end@dgroup
6461 }
6462 % \end{macrocode}
6463 % And the.
6464 % \begin{macrocode}
6465 \newtoks\GRP@queue
6466 \newenvironment{dgroup*}{%
6467 \let\grp@hasNumber\@False\breqn@optarg\@dgroup{}%
6468 }{%
6469 \end@dgroup
6470 }
6471 \def\@dgroup[#1]{%
6472 %<trace> \breqn@debugmsg{=== DGROUP ==================================================}%
6473 \let\eq@group\@True \global\let\eq@GRP@first@dmath\@True
6474 \global\GRP@queue\@emptytoks \global\setbox\GRP@box\box\voidb@x
6475 \global\let\GRP@label\@empty
6476 \global\grp@wdL\z@\global\grp@wdR\z@\global\grp@wdT\z@
6477 \global\grp@linewidth\z@\global\grp@wdNum\z@
6478 \global\let\grp@eqs@numbered\@False
6479 \global\let\grp@aligned\@True
6480 \global\let\grp@shiftnumber\@False
6481 \eq@prelim
6482 \setkeys{breqn}{#1}%
6483 \if\grp@hasNumber \grp@setnumber \fi
6484 }
6485 \def\end@dgroup{%
6486 \EQ@displayinfo \grp@finish
6487 \if\grp@hasNumber\grp@resetnumber\fi
6488 }
6489 % \end{macrocode}
6490 % If the \pkg{amsmath} package is not loaded the parentequation
6491 % counter will not be defined.
6492 % \begin{macrocode}
6493 \@ifundefined{c@parentequation}{\newcounter{parentequation}}{}
6494 % \end{macrocode}
6495 % Init.
6496 % \begin{macrocode}
6497 \global\let\GRP@label\@empty
6498 \def\add@grp@label{%
6499 \ifx\@empty\GRP@label
6500 \else \GRP@label \global\let\GRP@label\@empty
6501 \fi
6502 }
6503 % \end{macrocode}
6504 % Before sending down the `equation' counter to the subordinate level,
6505 % set the current number in \cs{EQ@numbox}. The
6506 % \cs{eq@setnumber} function does everything we need here. If
6507 % the child equations are unnumbered, \cs{EQ@numbox} will retain the
6508 % group number at the end of the group.
6509 % \begin{macrocode}
6510 \def\grp@setnumber{%
6511 \global\let\GRP@label\next@label \global\let\next@label\@empty
6512 % Trick \eq@setnumber to doing our work for us.
6513 \let\eq@hasNumber\@True
6514 \eq@setnumber
6515 % \end{macrocode}
6516 % Define \cn{theparentequation} equivalent to current
6517 % \cn{theequation}. \cn{edef} is necessary to expand the
6518 % current value of the equation counter. This might in rare cases
6519 % cause something to blow up, in which case the user needs to add
6520 % \cn{protect}.
6521 % \begin{macrocode}
6522 \global\sbox\GRP@numbox{\unhbox\EQ@numbox}%
6523 \grp@wdNum\eq@wdNum
6524 \let\eq@hasNumber\@False
6525 \let\eq@number\@empty
6526 \eq@wdNum\z@
6527 %
6528 \protected@edef\theparentequation{\theequation}%
6529 \setcounter{parentequation}{\value{equation}}%
6530 % \end{macrocode}
6531 % And set the equation counter to 0, so that the normal incrementing
6532 % processes will produce the desired results if the child equations are
6533 % numbered.
6534 % \begin{macrocode}
6535 \setcounter{equation}{0}%
6536 \def\theequation{\theparentequation\alph{equation}}%
6537 %<trace> \breqn@debugmsg{Group Number \theequation}%
6538 }
6539 % \end{macrocode}
6540 % At the end of a group, need to reset the equation counter.
6541 % \begin{macrocode}
6542 \def\grp@resetnumber{%
6543 \setcounter{equation}{\value{parentequation}}%
6544 }
6545 \newbox\GRP@box
6546 \newbox\GRP@wholebox
6547 % \end{macrocode}
6548 % Save data for this equation in the group
6549 % \begin{itemize}
6550 % \item push the trial data onto end of \cs{GRP@queue}.
6551 % \item push an hbox onto the front of \cs{GRP@box} containing:
6552 % \cs{EQ@box}, \cs{EQ@copy}, \cs{penalty} 1 and \cs{EQ@numbox}.
6553 % \end{itemize}
6554 % \begin{macro}{\grp@push}
6555 %
6556 % For putting the equation on a queue.
6557 % \begin{macrocode}
6558 \def\grp@push{%
6559 \global\GRP@queue\@xp\@xp\@xp{\@xp\the\@xp\GRP@queue
6560 \@xp\breqn@elt\@xp{\EQ@trial}%
6561 }%
6562 \global\setbox\GRP@box\vbox{%
6563 \hbox{\box\EQ@box\box\EQ@copy\penalty\@ne\copy\EQ@numbox}%
6564 \unvbox\GRP@box
6565 }%
6566 \EQ@trial
6567 \if\eq@isIntertext\else
6568 \ifdim\eq@wdL>\grp@wdL \global\grp@wdL\eq@wdL \fi
6569 \ifdim\eq@wdT>\grp@wdT \global\grp@wdT\eq@wdT \fi
6570 \setlength\dim@a{\eq@wdT-\eq@wdL}%
6571 \ifdim\dim@a>\grp@wdR \global\grp@wdR\dim@a \fi
6572 \ifdim\eq@linewidth>\grp@linewidth \global\grp@linewidth\eq@linewidth\fi
6573 \if\eq@hasNumber
6574 \global\let\grp@eqs@numbered\@True
6575 \ifdim\eq@wdNum>\grp@wdNum\global\grp@wdNum\eq@wdNum\fi
6576 \fi
6577 \if\EQ@hasLHS\else\global\let\grp@aligned\@False\fi
6578 \if D\eq@layout \global\let\grp@aligned\@False\fi % Layout D (usually) puts rel on 2nd line.
6579 \if\eq@shiftnumber\global\let\grp@shiftnumber\@True\fi % One eq shifted forces all.
6580 \fi
6581 }
6582 % \end{macrocode}
6583 % \end{macro}
6584 % \begin{macro}{\grp@finish}
6585 %
6586 % Set accumulated equations from a \env{dgroup} environment.
6587 %
6588 % BRM: Questionable patch!!
6589 % When processing the \cs{GRP@queue}, put it into a \cs{vbox}, then \cs{unvbox} it.
6590 % This since there's a bizarre problem when the \cs{output} routine
6591 % gets invoked at an inopportune moment: All the not-yet-processed
6592 % \cs{GRP@queue} ends up in the \cs{@freelist} and bad name clashes happen.
6593 % Of course, it could be due to some other problem entirely!!!
6594 % \begin{macrocode}
6595 \def\grp@finish{%
6596 % \debug@box\GRP@box
6597 % \breqn@debugmsg{\GRP@queue: \the\GRP@queue}%
6598 % \end{macrocode}
6599 % == Now that we know the collective measurements, make final decision
6600 % about alignment \& shifting. Check if alignment is still possible
6601 % \begin{macrocode}
6602 \setlength\dim@a{\grp@wdL+\grp@wdR-4em}% Allowance for shrink?
6603 \if\grp@aligned
6604 \ifdim\dim@a>\grp@linewidth
6605 \global\let\grp@aligned\@False
6606 \fi
6607 \fi
6608 % \end{macrocode}
6609 % If we're adding an unshifted group number that equations didn't know
6610 % about, re-check shifting
6611 % \begin{macrocode}
6612 \addtolength\dim@a{\grp@wdNum }% Effective length
6613 \if\grp@shiftnumber
6614 \else
6615 \if\@And{\grp@hasNumber}{\@Not\grp@eqs@numbered}
6616 \ifdim\dim@a>\grp@linewidth
6617 \global\let\grp@shiftnumber\@True
6618 \fi
6619 \fi
6620 \fi
6621 % \end{macrocode}
6622 % If we can still align, total width is sum of maximum LHS \& RHS
6623 % \begin{macrocode}
6624 \if\grp@aligned
6625 \global\grp@wdT\grp@wdL
6626 \global\advance\grp@wdT\grp@wdR
6627 \fi
6628 %<*trace>
6629 \breqn@debugmsg{======= DGROUP Formatting
6630 \MessageBreak==== \grp@wdL=\the\grp@wdL, \grp@wdR=\the\grp@wdR
6631 \MessageBreak==== Shift Number=\theb@@le\grp@shiftnumber, Eqns. numbered=\theb@@le\grp@eqs@numbered
6632 \MessageBreak==== Aligned=\theb@@le\grp@aligned
6633 \MessageBreak==== \grp@wdNum=\the\grp@wdNum}%
6634 %</trace>
6635 % \end{macrocode}
6636 % BRM: Originally this stuff was dumped directly, without capturing it
6637 % in a \cs{vbox}
6638 % \begin{macrocode}
6639 \setbox\GRP@wholebox\vbox{%
6640 \let\breqn@elt\eqgrp@elt
6641 \the\GRP@queue
6642 }%
6643 % \end{macrocode}
6644 % If we're placing a group number (not individual eqn numbers)
6645 % NOTE: For now, just code up LM number
6646 % NOTE: Come back and handle other cases.
6647 % NOTE: Vertical spacing is off, perhaps because of inter eqn. glue
6648 %
6649 % A bit of a hack to get the top spacing correct. Fix this logic
6650 % properly some day. Also, we do the calculation in a group for
6651 % maximum safety.
6652 % \begin{macrocode}
6653 \global\let\eq@GRP@first@dmath\@True
6654 \begingroup
6655 \dmath@first@leftskip
6656 \eq@topspace{\vskip\parskip}%
6657 \endgroup
6658 \if\@And{\grp@hasNumber}{\@Not{\grp@eqs@numbered}}%
6659 % \eq@topspace{\vskip\parskip}%
6660 \if\grp@shiftnumber
6661 \copy\GRP@numbox \penalty\@M
6662 \kern\eqlineskip
6663 \else
6664 \setlength\dim@a{%
6665 (\ht\GRP@wholebox+\dp\GRP@wholebox+\ht\GRP@numbox-\dp\GRP@numbox)/2}%
6666 \setlength\skip@c{\dim@a-\ht\GRP@numbox}%
6667 \vglue\skip@c% NON discardable
6668 \copy\GRP@numbox \penalty\@M
6669 %<*trace>
6670 \breqn@debugmsg{GROUP NUMBER: preskip:\the\skip@c, postkern:\the\dim@a, height:\the\ht\GRP@wholebox,
6671 \MessageBreak==== box height:\the\ht\GRP@numbox, box depth:\the\dp\GRP@numbox}%
6672 %</trace>
6673 \kern-\dim@a
6674 \kern-\abovedisplayskip % To cancel the topspace above the first eqn.
6675 \fi
6676 \fi
6677 %<*trace>
6678 %\debug@box\GRP@wholebox
6679 %</trace>
6680 \unvbox\GRP@wholebox
6681 \let\breqn@elt\relax
6682 % \end{macrocode}
6683 % We'd need to handle shifted, right number here, too!!!
6684 % \begin{macrocode}
6685 \eq@botspace % not needed unless bottom number?
6686 }
6687 % \end{macrocode}
6688 % \end{macro}
6689 %
6690 % \begin{macro}{\eqgrp@elt}
6691 %
6692 % Mission is to typeset the next equation from the group queue.
6693 %
6694 % The arg is an \cs{EQ@trial}
6695 % \begin{macrocode}
6696 \def\eqgrp@elt#1{%
6697 \global\setbox\GRP@box\vbox{%
6698 \unvbox\GRP@box
6699 \setbox\z@\lastbox
6700 \setbox\tw@\hbox{\unhbox\z@
6701 \ifnum\lastpenalty=\@ne
6702 \else
6703 \global\setbox\EQ@numbox\lastbox
6704 \fi
6705 \unpenalty
6706 \global\setbox\EQ@copy\lastbox
6707 \global\setbox\EQ@box\lastbox
6708 }%
6709 }%
6710 \begingroup \let\eq@botspace\relax
6711 #1%
6712 \if\eq@isIntertext
6713 \vskip\belowdisplayskip
6714 \unvbox\EQ@copy
6715 \else
6716 \grp@override
6717 \eq@finish
6718 \fi
6719 \endgroup
6720 }
6721 % \end{macrocode}
6722 % \end{macro}
6723 % Override the \cs{eq@trial} data as needed for this equation in this group
6724 % NOTE: w/ numbering variations (see above), we may need to tell
6725 % \cs{eq@finish} to allocate space for a number, but not actually have one
6726 % \begin{macrocode}
6727 \def\grp@override{%
6728 % \end{macrocode}
6729 % For aligned (possibly becomes an option?)
6730 % For now ASSUMING we started out as CLM!!!
6731 % \begin{macrocode}
6732 \def\eqindent{I}%
6733 % \end{macrocode}
6734 % compute nominal left for centering the group
6735 % \begin{macrocode}
6736 \setlength\dim@a{(\grp@linewidth-\grp@wdT)/2}%
6737 % \end{macrocode}
6738 % Make sure L+R not too wide; should already have unset alignment
6739 % \begin{macrocode}
6740 \ifdim\dim@a<\z@\dim@a=\z@\fi
6741 \dim@b\if L\eqnumside\grp@wdNum\else\z@\fi
6742 % \end{macrocode}
6743 % make sure room for number on left, if needed.
6744 % \begin{macrocode}
6745 \if\grp@shiftnumber\else
6746 \ifdim\dim@b>\dim@a\dim@a\dim@b\fi
6747 \fi
6748 \if\grp@aligned
6749 \addtolength\dim@a{\grp@wdL-\eq@wdL}%
6750 \fi
6751 \mathindent\dim@a
6752 \ifdim\dim@b>\dim@a
6753 \let\eq@shiftnumber\@True
6754 \fi
6755 % \end{macrocode}
6756 % Could set |\def\eqnumplace{T}| (or even (m) if indentation is enough).
6757 %
6758 % NOTE: Work out how this should interact with the various formats!!!
6759 % NOTE: should recognize the case where the LHS's are a bit Wild,
6760 % and then do simple left align (not on relation)
6761 % \begin{macrocode}
6762 }
6763 % \end{macrocode}
6764 %
6765 %
6766 %
6767 % \section{The \env{darray} environment}
6768 % There are two potential applications for darray. One
6769 % is like eqnarray where the natural structure of the material crosses the
6770 % table cell boundaries, and math operator spacing needs to be preserved
6771 % across cell boundaries. And there is also the feature of
6772 % attaching an equation number to each row. The other application
6773 % is like a regular array but with automatic displaystyle math in each
6774 % cell and better interline spacing to accommodate outsize cell
6775 % contents. In this case it is difficult to keep the vert ruling
6776 % capabilities of the standard \env{array} environment without
6777 % redoing the implementation along the lines of Arseneau's
6778 % \pkg{tabls} package. Because the vert ruling feature is at
6779 % cross purposes with the feature of allowing interline stretch and page
6780 % breaks within a multiline array of equations, the \env{darray}
6781 % environment is targeted primarily as an alternative to
6782 % \env{eqnarray}, and does not support vertical ruling.
6783 %
6784 % Overall strategy for \env{darray} is to use
6785 % \cs{halign} for the body. In the case of a group, use a
6786 % single halign for the whole group!
6787 % \begin{aside}
6788 % What about intertext?
6789 % \end{aside}
6790 %
6791 % That's the most reliable way
6792 % to get accurate column widths. Don't spread the halign to the
6793 % column width, just use the natural width. Then, if we repack the
6794 % contents of the halign into \cs{EQ@box} and \cs{EQ@copy}, as
6795 % done for dmath, and twiddle a bit with the widths of the first and last
6796 % cell in each row, we can use the same algorithms for centering and
6797 % equation number placement as dmath! As well as handling footnotes
6798 % and vadjust objects the same way.
6799 %
6800 % We can't just use \cs{arraycolsep} for \env{darray}, if
6801 % we want to be able to change it without screwing up interior arrays.
6802 % So let's make a new colsep variable. The initial value is
6803 % \quoted{2em, but let it shrink if necessary}.
6804 % \begin{macrocode}
6805 \newskip\darraycolsep \darraycolsep 20pt plus1fil minus12pt
6806 % \end{macrocode}
6807 % Let's make a nice big default setup with eighteen columns, split up
6808 % into six sets of lcr like \env{eqnarray}.
6809 % \begin{macrocode}
6810 \newcount\cur@row \newcount\cur@col
6811 \def\@tempa#1#2#3{%
6812 \cur@col#1 \hfil
6813 \setbox\z@\hbox{$\displaystyle####\m@th$}\@nx\col@box
6814 \tabskip\z@skip
6815 &\cur@col#2 \hfil
6816 \setbox\z@\hbox{$\displaystyle\mathord{}####\mathord{}\m@th$}\@nx\col@box
6817 \hfil
6818 &\cur@col#3 \setbox\z@\hbox{$\displaystyle####\m@th$}\@nx\col@box
6819 \hfil\tabskip\darraycolsep
6820 }
6821 \xdef\darray@preamble{%
6822 \@tempa 123&\@tempa 456&\@tempa 789%
6823 &\@tempa{10}{11}{12}&\@tempa{13}{14}{15}&\@tempa{16}{17}{18}%
6824 \cr
6825 }
6826 \@ifundefined{Mathstrut@}{\let\Mathstrut@\strut}{}
6827 \def\darray@cr{\Mathstrut@\cr}
6828 \def\col@box{%
6829 %<*trace>
6830 %\breqn@debugmsg{Col \number\cur@row,\number\cur@col: \the\wd\z@\space x \the\ht\z@+\the\dp\z@}%
6831 %</trace>
6832 \unhbox\z@
6833 }
6834 \newenvironment{darray}{\breqn@optarg\@darray{}}{}
6835 \def\@darray[#1]{%
6836 %<trace> \breqn@debugmsg{=== DARRAY ==================================================}%
6837 \if\eq@group\else\eq@prelim\fi
6838 % \end{macrocode}
6839 % Init the halign preamble to empty, then unless the \quoted{cols} key is
6840 % used to provide a non-null preamble just use the
6841 % default darray preamble which is a multiple lcr.
6842 % \begin{macrocode}
6843 \global\let\@preamble\@empty
6844 \setkeys{breqn}{#1}%
6845 \the\eqstyle \eq@setnumber
6846 \ifx\@preamble\@empty \global\let\@preamble\darray@preamble \fi
6847 \check@mathfonts
6848 % \let\check@mathfonts\relax % tempting, but too risky
6849 \@xp\let\csname\string\ \endcsname\darray@cr
6850 \setbox\z@\vbox\bgroup
6851 \everycr{\noalign{\global\advance\cur@row\@ne}}%
6852 \tabskip\z@skip \cur@col\z@
6853 \global\cur@row\z@
6854 \penalty\@ne % flag for \dar@repack
6855 \halign\@xp\bgroup\@preamble
6856 }
6857 % \end{macrocode}
6858 % Assimilate following punctuation.
6859 % \begin{macrocode}
6860 \def\enddarray#1{\check@punct@or@qed}
6861 \def\end@darray{%
6862 \ifvmode\else \eq@addpunct \Mathstrut@\fi\crcr \egroup
6863 \dar@capture
6864 \egroup
6865 }
6866 % \end{macrocode}
6867 %
6868 % The \cs{dar@capture} function steps back through the
6869 % list of row boxes and grinds them up in the best possible way.
6870 % \begin{macrocode}
6871 \def\dar@capture{%
6872 %% \showboxbreadth\maxdimen\showboxdepth99\showlists
6873 \eq@wdL\z@ \eq@wdRmax\z@
6874 \dar@repack
6875 }
6876 % \end{macrocode}
6877 %
6878 % The \cs{dar@repack} function is a variation of
6879 % \cs{eq@repack}.
6880 % \begin{macrocode}
6881 \def\dar@repack{%
6882 \unpenalty
6883 \setbox\tw@\lastbox
6884 %\batchmode{\showboxbreadth\maxdimen\showboxdepth99\showbox\tw@}\errorstopmode
6885 \global\setbox\EQ@box\hbox{%
6886 \hbox{\unhcopy\tw@\unskip}\penalty-\@M \unhbox\EQ@box}%
6887 \global\setbox\EQ@copy\hbox{%
6888 \hbox{\unhbox\tw@\unskip}\penalty-\@M \unhbox\EQ@copy}%
6889 \unskip
6890 \ifcase\lastpenalty \else\@xp\@gobble\fi
6891 \dar@repack
6892 }
6893 % \end{macrocode}
6894 %
6895 %
6896 %
6897 %
6898 % \section{Miscellaneous}
6899 % The \cs{condition} command. With
6900 % the star form, set the argument in math mode instead of text mode.
6901 % In a series of conditions, use less space between members of the
6902 % series than between the conditions and the main equation body.
6903 %
6904 % WSPR: tidied/fixed things up as it made sense to me but might have
6905 % broken something else!
6906 % \begin{macrocode}
6907 \newskip\conditionsep \conditionsep=10pt minus5pt%
6908 \newcommand{\conditionpunct}{,}
6909 % \end{macrocode}
6910 % \begin{macro}{\condition}
6911 % \begin{macrocode}
6912 \newcommand\condition{%
6913 \begingroup\@tempswatrue
6914 \breqn@ifstar{\@tempswafalse \condition@a}{\condition@a}}
6915 % \end{macrocode}
6916 % \end{macro}
6917 % \begin{macro}{\condition@a}
6918 % \begin{macrocode}
6919 \newcommand\condition@a[2][\conditionpunct]{%
6920 \unpenalty\unskip\unpenalty\unskip % BRM Added
6921 \hbox{#1}%
6922 \penalty -201\relax\hbox{}% Penalty to allow breaks here.
6923 \hskip\conditionsep
6924 \setbox\z@\if@tempswa\hbox{#2}\else\hbox{$\textmath@setup #2$}\fi
6925 % \end{macrocode}
6926 % BRM's layout is achieved with this line commented out but it has the nasty side-effect of shifting the equation number to the next line:
6927 % \begin{macrocode}
6928 % \global\eq@wdCond\wd\z@
6929 \usebox\z@
6930 \endgroup}
6931 % \end{macrocode}
6932 % \end{macro}
6933 %
6934 % The \env{dsuspend} environment. First the old one that didn't work.
6935 % \begin{macrocode}
6936 \newenvironment{XXXXdsuspend}{%
6937 \global\setbox\EQ@box\vbox\bgroup \@parboxrestore
6938 % \end{macrocode}
6939 % If we are inside a list environment, \cs{displayindent} and
6940 % \cs{displaywidth} give us \cs{@totalleftmargin} and
6941 % \cs{linewidth}.
6942 % \begin{macrocode}
6943 \parshape 1 \displayindent \displaywidth\relax
6944 \hsize=\columnwidth \noindent\ignorespaces
6945 }{%
6946 \par\egroup
6947 % \end{macrocode}
6948 % Let's try giving \cs{EQ@box} the correct height for the first
6949 % line and \cs{EQ@copy} the depth of the last line.
6950 % \begin{macrocode}
6951 \global\setbox\GRP@box\vbox{%
6952 \vbox{\copy\EQ@box\vtop{\unvbox\EQ@box}}%
6953 \unvbox\GRP@box
6954 }%
6955 % \end{macrocode}
6956 % Need to add a dummy element to \cs{GRP@queue}.
6957 % \begin{macrocode}
6958 \global\GRP@queue\@xp{\the\GRP@queue
6959 \breqn@elt{\gdef\EQ@trial{}}%
6960 }%
6961 }
6962 % \end{macrocode}
6963 % And then the one that does work.
6964 % \begin{macrocode}
6965 \newenvironment{dsuspend}{%
6966 \global\setbox\EQ@box\vbox\bgroup \@parboxrestore
6967 \parshape 1 \displayindent \displaywidth\relax
6968 \hsize=\columnwidth \noindent\ignorespaces
6969 }{%
6970 \par\egroup
6971 \global\setbox\GRP@box\vbox{%
6972 \hbox{\copy\EQ@box\vtop{\unvbox\EQ@box}}%
6973 \unvbox\GRP@box
6974 }%
6975 \global\GRP@queue\@xp{\the\GRP@queue
6976 % \breqn@elt{\gdef\EQ@trial{\let\eq@isIntertext\@True}}%
6977 \breqn@elt{\let\eq@isIntertext\@True}%
6978 }%
6979 }
6980 % \end{macrocode}
6981 % Allow \cn{intertext} as a short form of the \env{dsuspend}
6982 % environment; it's more convenient to write, but it doesn't support
6983 % embedded verbatim because it reads the material as a macro argument.
6984 % To support simultaneous use of \pkg{amsmath} and
6985 % \pkg{breqn}, the user command \cs{intertext} is left alone
6986 % until we enter a \pkg{breqn} environment.
6987 % \begin{macrocode}
6988 \newcommand\breqn@intertext[1]{\dsuspend#1\enddsuspend}
6989 % \end{macrocode}
6990 %
6991 %
6992 % \begin{macro}{\*}
6993 % \begin{macro}{\discretionarytimes}
6994 % Discretionary times sign. Standard \latex definition
6995 % serves only for inline math. Should the thin space be
6996 % included? Not sure.
6997 % \begin{macrocode}
6998 \renewcommand{\*}{%
6999 \if@display
7000 % \end{macrocode}
7001 % Since \cs{eq@binoffset} is mu-glue, we can't use it directly
7002 % with \cs{kern} but have to measure it separately in a box.
7003 % \begin{macrocode}
7004 \setbox\z@\hbox{\mathsurround\z@$\mkern\eq@binoffset$}%
7005 \discretionary{}{%
7006 \kern\the\wd\z@ \textchar\discretionarytimes
7007 }{}%
7008 \thinspace
7009 \else
7010 \discretionary{\thinspace\textchar\discretionarytimes}{}{}%
7011 \fi
7012 }
7013 % \end{macrocode}
7014 % This is only the symbol; it can be changed to some other symbol if
7015 % desired.
7016 % \begin{macrocode}
7017 \newcommand{\discretionarytimes}{\times}
7018 % \end{macrocode}
7019 % \end{macro}
7020 % \end{macro}
7021 %
7022 %
7023 % \begin{macro}{\nref}
7024 %
7025 % This is like \cs{ref} but doesn't apply font changes or other
7026 % guff if the reference is undefined.
7027 % And it is fully expandable for use as a label value.
7028 % \begin{aside}
7029 %
7030 % Can break with Babel if author uses active characters in label key;
7031 % need to address that \begin{dn}
7032 % mjd,1999/01/21
7033 % \end{dn}
7034 % .
7035 % \end{aside}
7036 %
7037 % \begin{macrocode}
7038 \def\nref#1{\@xp\@nref\csname r@#1\endcsname}
7039 \def\@nref#1#2{\ifx\relax#1??\else \@xp\@firstoftwo#1\fi}
7040 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7041 % \end{macrocode}
7042 % \end{macro}
7043 %
7044 %
7045 % \section{Compatibility}
7046 %
7047 % \paragraph{lineno} (or at the very least, allow documents to compile!)
7048 % \begin{macrocode}
7049 \AtBeginDocument{%
7050 \@ifpackageloaded{lineno}{%
7051 \g@addto@macro\@dmath@start@hook{\nolinenumbers}%
7052 \g@addto@macro\@dgroup@start@hook{\nolinenumbers}%
7053 }{}%
7054 }
7055 % \end{macrocode}
7056 %
7057 %
7058 %
7059 % \section{Wrap-up}
7060 % The usual endinput.
7061 % \begin{macrocode}
7062 %</package>
7063 % \end{macrocode}
7064 %
7065 %
7066 %
7067 %
7068 % \section{To do}
7069 % \begin{enumerate}
7070 % \item Alignment for equation groups.
7071 %
7072 %
7073 % \item
7074 % Use dpc's code for package options in keyval form.
7075 %
7076 % \item
7077 % Encapsulate \dquoted{break math} into a subroutine taking suitable
7078 % arguments.
7079 %
7080 % \item
7081 % Need a density check for layout S when linewidth is very small.
7082 %
7083 % \item
7084 % Make \verb":=" trigger a warning about using \cs{coloneq}
7085 % instead.
7086 %
7087 % \item Ill-centered multiline equation (three-line case) in
7088 % test008.
7089 %
7090 % \item Attaching a single group number.
7091 %
7092 %
7093 % \item
7094 % Make sure to dump out box registers after done using them.
7095 %
7096 % \item Do the implementation for \cs{eq@resume@parshape}.
7097 %
7098 %
7099 % \item Check on stackrel and buildrel and relbar and ???.
7100 %
7101 %
7102 % \item Test math symbols at the beginning of array cells.
7103 %
7104 % \item Test \dbslash cmd in and out of delims.
7105 %
7106 % \item Framing the equation body: the parshape and number placement
7107 % need adjusting when a frame is present.
7108 %
7109 %
7110 % \item Cascading line widths in list env.
7111 %
7112 %
7113 % \item Noalign option for dmath = multline arrangement?
7114 %
7115 %
7116 % \item Nocompact option, suggested 1998/05/19 by Andrew
7117 % Swann.
7118 %
7119 %
7120 % \item \cs{delbreak} cmd to add discretionary space at a break
7121 % within delimiters.
7122 %
7123 %
7124 % \item Reduce above/below skip when the number is shifted.
7125 %
7126 %
7127 % \item Need a \cs{middelim} command for marking a delimiter symbol
7128 % as nondirectional if it has an innate directionality \verb"()[]" \etc .
7129 %
7130 %
7131 % \item
7132 % \cs{xrightarrow} from amsmath won't participate in line
7133 % breaking unless something extra is done.
7134 % Make \cs{BreakingRel} and \cs{BreakingBin} functions?
7135 %
7136 % \item Placement of number in an indented quotation or
7137 % abstract.
7138 %
7139 % \item If $LHSwd > 2em$, it might be a good idea to try with
7140 % eq@indentstep = 2em before shifting the number. Currently this
7141 % doesn't happen if the first trial pass (without the number)
7142 % succeeds with $indentstep = LHSwd > 2em$.
7143 %
7144 %
7145 % \item Read past \verb"\end{enumerate}" when checking
7146 % for \verb"\end{proof}"?
7147 %
7148 % \item
7149 % Look into using a \dquoted{qed-list} of environment names instead of
7150 % checking the existence of \cs{proofqed}.
7151 %
7152 % \item Pick up the vadjust\slash footnote\slash mark handling.
7153 %
7154 %
7155 % \item Forcing\slash prohibiting page breaks after\slash before
7156 % an equation.
7157 %
7158 %
7159 % \item Adding a spanner brace on the left and individual numbers on
7160 % the right (indy-numbered cases).
7161 %
7162 %
7163 % \item Provide \cs{shiftnumber}, \cs{holdnumber} to
7164 % override the decision.
7165 %
7166 % \item Provide a mechanism for adjusting the vertical position of
7167 % the number. Here a version-specific selection macro would be
7168 % useful.
7169 % \begin{literalcode}
7170 % \begin{dmath}[
7171 % style={\foredition{1}{\raisenumber{13pt}}}
7172 % ]
7173 % \end{literalcode}
7174 %
7175 %
7176 % \item
7177 % Add an alignleft option for an equation group to mean, break and
7178 % align to a ladder layout as usual within the equations, but for the
7179 % group alignment used the leftmost point (for equations that don't
7180 % have an LHS, this makes no difference).
7181 %
7182 % \item
7183 % Test with Arseneau's wrapfig for parshape\slash everypar
7184 % interaction.
7185 %
7186 %
7187 % \item Fix up the macro/def elements.
7188 %
7189 % \item Convert the literal examples in section \quoted{Equation types and
7190 % forms} to typeset form.
7191 %
7192 %
7193 % \item Compile comparison-examples: \eg , a standard equation
7194 % env with big left-right objects that don't shrink, versus how shrinking
7195 % can allow it to fit.
7196 %
7197 %
7198 % \item Frame the \dquoted{figures} since they are mostly
7199 % text.
7200 %
7201 % \end{enumerate}
7202 %
7203 %
7204 %
7205 % Possible enhancements:
7206 % \begin{enumerate}
7207 % \item Provide a \opt{pull} option meaning to pull the first
7208 % and last lines out to the margin, like the \env{multline}
7209 % environment of the \pkg{amsmath} package. Maybe this should
7210 % get an optional argument, actually, to specify the amount of space left
7211 % at the margin.
7212 %
7213 % \item With the draft option, one would like to see the equation
7214 % labels in the left margin. Need to check with the
7215 % \pkg{showkeys} package.
7216 %
7217 %
7218 % \item Options for break preferences: if there's not enough room, do
7219 % we first shift the number, or first try to break up the equation
7220 % body?. In an aligned group, does sticking to the group alignment
7221 % take precedence over minimizing the number of line breaks needed for
7222 % individual equations?. And the general preferences probably need
7223 % to be overridable for individual instances.
7224 %
7225 % \item Extend suppress-breaks-inside-delimiters support to inline
7226 % math (suggestion of Michael Doob).
7227 %
7228 % \item Use belowdisplayshortskip above a dsuspend fragment if the
7229 % fragment is only one line and short enough compared to the equation line
7230 % above it.
7231 %
7232 %
7233 % \item Add \cs{eqfuzz} distinct from \cs{hfuzz}.
7234 % Make use of it in the measuring phase.
7235 %
7236 %
7237 % \item Provision for putting in a \quoted{continued} note.
7238 %
7239 % \item Conserve box mem: modify frac, sub, sup, overline, underline,
7240 % sqrt, to turn off \cs{bin@break} and (less urgently)
7241 % \cs{rel@break}.
7242 %
7243 %
7244 % \item More explicit support for Russian typesetting conventions (cf
7245 % Grinchuk article).
7246 %
7247 %
7248 % \item With package option \opt{refnumbers},
7249 % leave unnumbered all uncited equations, even if they are not done with
7250 % the star form (Bertolazzi's easyeqn idea).
7251 %
7252 % \item In an equation group, use a vertical bracket with the
7253 % equation number to mark the lines contained in that equation.
7254 %
7255 %
7256 % \item For a two-line multline thingamabob, try to
7257 % make sure that the lines overlap in the middle by 2 em or whatever
7258 % (settable design variable).
7259 %
7260 % \item Provide a separate vertical column for the principal mathrel
7261 % symbols and center them within the column if they aren't all the same
7262 % width. Maybe an option for \env{dmath}: relwidth=x, so that two
7263 % passes are not required to get the max width of all the mathrels.
7264 % Or, no, just require it to be an halign or provide a macro to be
7265 % applied to all the shorter rels:
7266 % \begin{literalcode}
7267 % lhs \widerel{19pt}{=} ...
7268 % \xrightarrow{foo} ...
7269 % \end{literalcode}
7270 %
7271 %
7272 % \item try to use vadjust for keepglue
7273 %
7274 % \end{enumerate}
7275 %
7276 % \PrintIndex
7277 %
7278 % \Finale
7279