2 % \iffalse meta-comment
4 % Copyright 1995, 2000, 2013 American Mathematical Society.
5 % Copyright 2016 LaTeX3 Project and American Mathematical Society.
7 % This work may be distributed and/or modified under the
8 % conditions of the LaTeX Project Public License, either version 1.3c
9 % of this license or (at your option) any later version.
10 % The latest version of this license is in
11 % http://www.latex-project.org/lppl.txt
12 % and version 1.3c or later is part of all distributions of LaTeX
13 % version 2005/12/01 or later.
15 % This work has the LPPL maintenance status `maintained'.
17 % The Current Maintainer of this work is the LaTeX3 Project.
23 \documentclass{amsdtx}
24 \def\MaintainedByLaTeXTeam#1{%
26 \fbox{\fbox{\begin{tabular}{@{}l@{}}%
27 This file is maintained by the \LaTeX{} Project team.\\%
28 Bug reports can be opened (category \texttt{#1}) at\\%
29 \url{http://latex-project.org/bugs.html}.\end{tabular}}}\end{center}}
34 \GetFileInfo{amsmath.sty}
36 \title{The \pkg{amsmath} package}
37 \author{Frank Mittelbach\and Rainer Sch\"opf\and Michael Downes\and
38 David M. Jones\and David Carlisle}
39 \date{Version \fileversion, \filedate}
40 \providecommand{\histnote}{}
41 \renewenvironment{histnote}{%
42 \trivlist\item[\hspace{\labelsep}\bfseries Historical Note:]%
46 \DocInput{amsmath.dtx}
52 % \MaintainedByLaTeXTeam{amslatex}
56 % \section{Introduction}
58 % A \latex/ package named \pkg{amstex} was created in 1988--1989 by
59 % adapting \fn{amstex.tex} for use within \latex/. The \pkg{amsmath}
60 % package is the successor of the \pkg{amstex} package. It was
61 % substantially overhauled to integrate it with \latex/2e, which
62 % arrived on the scene in 1994. It provides more or less the same
63 % features, but there are quite a few organizational differences as
64 % well as some new features and bug fixes. For example, the
65 % \pkg{amstex} package automatically loaded the \pkg{amsfonts}
66 % package, but the \pkg{amsmath} package does not. At the present
67 % time (November 1999) user-level documentation of the commands
68 % provided here is found in the AMSmath Users' Guide,
73 % Standard file identification.
75 \NeedsTeXFormat{LaTeX2e}% LaTeX 2.09 can't be used (nor non-LaTeX)
76 [1994/12/01]% LaTeX date must be December 1994 or later
77 \ProvidesPackage{amsmath}[2016/11/05 v2.16a AMS math features]
80 % \section{Catcode defenses}
82 % Some packages change the catcode of characters that are essential
83 % in low-level \tex/ syntax. Any package that does so does not
84 % qualify as a PWWO package (\qq{Plays Well With Others}) because it
85 % can cause other packages to fail if they are loaded later. \LaTeX{}
86 % is partly to blame for this because it fails to provide adequate
87 % built-in safeguards in the package loading mechanisms. In the
88 % absence of such safeguards, we will provide them here.
90 \edef\@temp{\catcode 96=\number\catcode 96 }
91 \catcode\string `\`=12
92 \def\do#1{\catcode\number`#1=\number\catcode`#1}
94 \noexpand\AtEndOfPackage{%
96 \do\"\do\'\do\(\do\)\do\*\do\+\do\,\do\-\do\.%
97 \do\/\do\<\do\=\do\>\do\[\do\]\do\^\do\_\relax
101 \def\do#1{\catcode\number`#1=12 }
102 \do\"\do\'\do\(\do\)\do\*\do\+\do\,\do\-\do\.
103 \do\/\do\<\do\=\do\>\do\[\do\]
104 \catcode`\^=7 \catcode`\_=8
107 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
108 % \section{Declare some options}
110 % Handling of limits on integrals, sums, operatornames.
112 \DeclareOption{intlimits}{\let\ilimits@\displaylimits}
113 \DeclareOption{nointlimits}{\let\ilimits@\nolimits}
114 \DeclareOption{sumlimits}{\let\slimits@\displaylimits}
115 \DeclareOption{nosumlimits}{\let\slimits@\nolimits}
116 \DeclareOption{namelimits}{\PassOptionsToPackage{namelimits}{amsopn}}
117 \DeclareOption{nonamelimits}{%
118 \PassOptionsToPackage{nonamelimits}{amsopn}}
121 % The following two switches might have been defined already by the
122 % documentclass, but it doesn't hurt to re-execute the \cs{newif}'s.
127 % Right or left placement of equation numbers.
129 \DeclareOption{leqno}{\tagsleft@true}
130 \DeclareOption{reqno}{\tagsleft@false}
131 \DeclareOption{centertags}{\ctagsplit@true}
132 \DeclareOption{tbtags}{\ctagsplit@false}
135 % The \opt{cmex10} option is an escape hatch for people who don't
136 % happen to have sizes 7--9 of the \fn{cmex} fonts available to them
137 % yet. (Strictly speaking they are considered part of a minimum
138 % \latex/ distribution now, i.e., all \LaTeXe{} users should have
139 % them, without needing to get the AMSFonts distrib.)
141 \DeclareOption{cmex10}{%
142 \ifnum\cmex@opt=\@ne \def\cmex@opt{0}%
143 \else \def\cmex@opt{10}\fi
146 % To help things work out better with various package loading orders
147 % of \pkg{amsmath} and \pkg{amsfonts}, we establish a variable to
148 % communicate the status of the cmex font definition. If the
149 % \pkg{amsfonts} package was loaded first this variable might be
150 % already defined, in which case we want to preserve its value.
152 \@ifundefined{cmex@opt}{\def\cmex@opt{7}}{}
155 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
156 % \section{Flush-left equations [DMJ]}
158 % The left margin of math enviroments is controlled by
159 % \cs{@mathmargin}. This can be set to \cs{@centering} to
160 % implement the default behaviour, i.e., centered equations, and to
161 % something else to implement the flushleft style.
163 % In theory, all that's needed to activate the flushleft mode
164 % in the AMS document classes is something like this:
166 % \DeclareOption{fleqn}{%
167 % \AtBeginDocument{\@mathmargin30pt\relax}%
170 % (In fact, unless the document class wants to specify the
171 % \cs{@mathmargin}, it doesn't need to do anything with the
172 % \opt{fleqn} option.)
177 \@mathmargin\@centering
179 \DeclareOption{fleqn}{%
182 \let\mathindent=\@mathmargin
184 \ifdim\@mathmargin= -1sp
185 \@mathmargin\leftmargini minus\leftmargini
191 % DMJ: This ensures that \cs{@mathmargin} is given some sort of
192 % sensible default if the class doesn't specify one, while still
193 % allowing a user to override the default value in their document
194 % preamble. (Incidentally, I'm initializing \cs{@mathmargin} to
195 % \cs{leftmargini} for compatibility with \fn{fleqn.clo}, but I'm
196 % not at all convinced that's the right thing to do.)
198 % The next question is what happens when amsmath is used with
199 % one of the standard classes. Unfortunately, \latex/ implements
200 % \opt{fleqn} somewhat clumsily; instead of paramaterizing the
201 % definitions of the math structures (as I've attempted to do
202 % here), \fn{fleqn.clo} declares a dimen \cn{mathindent} that is
203 % much like my \cs{@mathmargin} and then redefines \cn\[, \cn\],
204 % \cn{equation}, and \cn{eqnarray}. This means that things could
205 % get rather messy in 2.09 compatibility mode, since \fn{fleqn.clo}
206 % might be loaded after \fn{amsmath.sty}, which could cause a real
209 % [mjd,1999/07/07]: Let \cs{mathindent} = \cs{@mathmargin} as
210 % envisioned by DMJ. Compatibility-mode documents will all use the
211 % \pkg{amstex} package, not \pkg{amsmath}. There is a remote chance
212 % of a problem if someone makes an assignment to \cs{mathindent} in a
213 % way that implicitly assumes it is a dimen register (inasmuch as it
214 % has now become a skip register), and the string ``plus'' follows in
215 % the input stream, but if someone's document croaks in that way, I
216 % think they will just have to bite the bullet and fix it. The
217 % alternative is to penalize a lot of other users with a known
220 % \section{Spacing around \cn{aligned} and \cn{gathered}}
222 % [dpc, 2016] Option to control the space to the left of aligned and gathered.
224 % Previously \cn{aligned} and \cn{gathered} inserted a thin space on
225 % their left but not their right, there is no good reason for this
226 % that anyone can remember, it has just always been that way
227 % inherited from amstex. The usual advice to authors has bben to use
228 % |\!\begin{aligned}| to get better spacing.
232 % \opt{alignedleftspaceyes} to keep the behaviour of adding this space.
234 % \opt{alignedleftspaceno} to disable adding this space.
236 % \opt{alignedleftspaceyesifneg} the new default behaviour, do not add
237 % the space unless the environment is preceded by a negative skip or
238 % kern, so that |\!\begin{aligned}| works as before.
240 % \changes{v2.16a}{2016/11/05}{New options to control aligned spacing}
242 \DeclareOption{alignedleftspaceyes}{\def\alignedspace@left{\null\,}}
243 \DeclareOption{alignedleftspaceno}{\def\alignedspace@left{\null}}
244 \DeclareOption{alignedleftspaceyesifneg}{%
245 \def\alignedspace@left{%
246 \edef\@tempa{\expandafter\@car\the\lastskip\@nil}%
249 \edef\@tempa{\expandafter\@car\the\lastkern\@nil}%
264 nointlimits,sumlimits,namelimits,centertags,alignedleftspaceyesifneg}
266 % The \cs{par} after \cs{ProcessOptions} is to ensure the correct
267 % line number on screen if an error occurs during option processing;
268 % otherwise the lookahead for a \qc{\*} option would result in \tex/
269 % showing the following line instead.
275 \@ifpackagewith{amsmath}{?}{%
277 Documentation for the amsmath package is found in amsldoc.dvi^^J%
278 (or .pdf or .tex).^^J%
280 See also http://www.ams.org/tex/amslatex.html.^^J%
282 Note: Using the first edition of The LaTeX Companion (1994) without^^J%
283 errata as a guide for amsmath use is not recommended.^^J%
287 For additional information on amsmath, use the \lq ?\rq\space option.%
292 % Processing to handle the \opt{cmex10} option is a little tricky
293 % because of different possible loading orders for \pkg{amsmath} and
294 % \pkg{amsfonts}. The package \pkg{amsmath} sets the \cs{cmex@opt}
295 % flag to 7 or 10, and the package \pkg{amsfonts} sets the flag to 1
298 \ifnum\cmex@opt=7 \relax
299 \DeclareFontShape{OMX}{cmex}{m}{n}{%
300 <-8>cmex7<8>cmex8<9>cmex9%
301 <10><10.95><12><14.4><17.28><20.74><24.88>cmex10%
303 \expandafter\let\csname OMX/cmex/m/n/10\endcsname\relax
305 \ifnum\cmex@opt=\z@ % need to override cmex7 fontdef from amsfonts
307 % Force reloading of the OMX/cmex font definition file.
310 \fontencoding{OMX}\fontfamily{cmex}%
311 \expandafter\let\csname OMX+cmex\endcsname\relax
315 % The \fn{cmex10} font gets special preload handling in the building
316 % of the \latex/ format file, need an extra bit here to work around
319 \expandafter\let\csname OMX/cmex/m/n/10\endcsname\relax
325 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
326 % \section{Call some other packages}
328 % The \pkg{amstext} package provides the \cn{text} command. The
329 % \pkg{amsbsy} package provides \cn{boldsymbol} and \cn{pmb}. (Since
330 % 1997 it is usually better to use the \pkg{bm} package instead; but
331 % I think we have to keep \pkg{amsbsy} here for backward
332 % compatibility [mjd,1999/11/19].) The \pkg{amsopn} package provides
333 % \cn{DeclareMathOperator}.
335 \RequirePackage{amstext}[1995/01/25]
336 \RequirePackage{amsbsy}[1995/01/20]
337 \RequirePackage{amsopn}[1995/01/20]
340 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
341 % \section{Miscellaneous}
343 % \begin{macro}{\ams@newcommand}
344 % Where \pkg{stix} and \pkg{amsmath} define the same control
345 % sequences, we want to avoid inadvertently overriding \pkg{stix}'s
346 % definitions. If \pkg{stix} is loaded before \pkg{amsmath}, the
347 % following conditional takes care of the problem. There is
348 % similar code in the \pkg{stix} package in case \pkg{amsmath} is
351 \@ifpackageloaded{stix}{%
352 \let\ams@newcommand\providecommand
353 \let\ams@renewcommand\providecommand
354 \let\ams@def\providecommand
355 \let\ams@DeclareRobustCommand\providecommand
357 \let\ams@newcommand\newcommand
358 \let\ams@renewcommand\renewcommand
360 \let\ams@DeclareRobustCommand\DeclareRobustCommand
365 % \begin{macro}{\@amsmath@err}
366 % Defining this error function saves main mem.
368 \def\@amsmath@err{\PackageError{amsmath}}
372 % \begin{macro}{\AmS}
373 % The \cs{AmS} prefix can be used to construct the combination
376 \providecommand{\AmS}{{\protect\AmSfont
377 A\kern-.1667em\lower.5ex\hbox{M}\kern-.125emS}}
379 % In \cn{AmSfont} we call cmsy directly in lieu of trying to access
380 % it through the math fonts setup (e.g. |\the\textfont2|) because
381 % math fonts can't be relied on to be properly set up if we are not
382 % inside a math formula. This means that if this command is used in a
383 % document where CM fonts are not wanted, then a font substitution
384 % will need to be declared, e.g.:
386 % \DeclareFontShape{OMS}{cmsy}{m}{n}{ <-> sub * xxx/m/n }{}
388 % where |xxx| is some alternate font family.
389 % Taking the first letter of \cs{f@series} will produce |b| or |m|
390 % for the most common values (|b,bx,m|). It may produce nonsense for
391 % more unusual values of \cs{f@series}, so for safety's sake we have
392 % an additional \cs{if} test. We want to avoid setting the series to
393 % |bx| because in a standard \latex/ installation the combination
394 % |cmsy/bx/n| does not have a font definition, and the user
395 % would get a font substitution warning on screen.
397 \newcommand{\AmSfont}{%
398 \usefont{OMS}{cmsy}{\if\@xp\@car\f@series\@nil bb\else m\fi}{n}}
402 % \begin{macro}{\@mathmeasure}
403 % The function |\@mathmeasure| takes three arguments; the third arg
404 % is typeset as a math formula in an hbox, using arg |#2| as the
405 % mathstyle, and the result is left in the box named by the first
406 % arg. It is assumed that we are already in math mode, so we can turn
407 % off |\everymath| (in particular, |\check@mathfonts|).
409 \def\@mathmeasure#1#2#3{\setbox#1\hbox{\frozen@everymath\@emptytoks
414 % The \cs{inf@bad} constant is for testing overfull boxes.
416 \@ifundefined{inf@bad}{%
417 \newcount\inf@bad \inf@bad=1000000 \relax
421 %\subsection{Math spacing commands}
423 % \begin{macro}{\tmspace}
425 % \begin{macro}{\thinspace}
427 % \begin{macro}{\negthinspace}
429 % \begin{macro}{\medspace}
430 % \begin{macro}{\negmedspace}
432 % \begin{macro}{\thickspace}
433 % \begin{macro}{\negthickspace}
434 % Here we fill in some gaps in the set of spacing commands, and make them
435 % all work equally well in or out of math.
436 % We want all these commands to be robust but declaring them all with
437 % \cs{DeclareRobustCommand} uses up an control sequence name per
438 % command; to avoid this, we define a common command \cs{tmspace}
439 % (text-or-math space) which carries the robustness burden for all of
440 % them. The standard \cs{relax} before the \cs{ifmmode} is not
441 % necessary because of the \cs{protect} added by
442 % \cs{DeclareRobustCommand}.
444 \DeclareRobustCommand{\tmspace}[3]{%
445 \ifmmode\mskip#1#2\else\kern#1#3\fi\relax}
446 \renewcommand{\,}{\tmspace+\thinmuskip{.1667em}}
448 \renewcommand{\!}{\tmspace-\thinmuskip{.1667em}}
450 \renewcommand{\:}{\tmspace+\medmuskip{.2222em}}
452 \newcommand{\negmedspace}{\tmspace-\medmuskip{.2222em}}
453 \renewcommand{\;}{\tmspace+\thickmuskip{.2777em}}
455 \newcommand{\negthickspace}{\tmspace-\thickmuskip{.2777em}}
469 % \begin{macro}{\mspace}
470 % And while we're at it, why don't we provide an equivalent of
471 % \cn{hspace} for math mode use. This allows use of |mu| units in
472 % (for example) constructing compound math symbols.
474 \newcommand{\mspace}[1]{\mskip#1\relax}
478 % \subsection{Vertical bar symbols}
479 % \begin{macro}{\lvert}
480 % \begin{macro}{\rvert}
481 % \begin{macro}{\lVert}
482 % \begin{macro}{\rVert}
483 % Add left/right specific versions of \cn{vert}, \cn{Vert}. Don't
484 % assume the delimiter codes are the CM defaults.
486 \def\@tempa#1#2\@nil{%
487 \ifx\delimiter#1\@tempcnta#2\relax\else\@tempcnta\z@\fi
489 \@xp\@tempa\vert\@empty\@nil
491 \advance\@tempcnta "4000000
492 \xdef\lvert{\delimiter\number\@tempcnta\space }
493 \advance\@tempcnta "1000000
494 \xdef\rvert{\delimiter\number\@tempcnta\space }
496 \ifx\@@undefined\lvert
497 % Fall back to cmex encoding since we don't know what else to do.
498 \DeclareMathDelimiter{\lvert}
499 {\mathopen}{symbols}{"6A}{largesymbols}{"0C}
500 \DeclareMathDelimiter{\rvert}
501 {\mathclose}{symbols}{"6A}{largesymbols}{"0C}
504 \@xp\@tempa\Vert\@empty\@nil
506 \advance\@tempcnta "4000000
507 \xdef\lVert{\delimiter\number\@tempcnta\space }
508 \advance\@tempcnta "1000000
509 \xdef\rVert{\delimiter\number\@tempcnta\space }
511 \ifx\@@undefined\lVert
512 \DeclareMathDelimiter{\lVert}
513 {\mathopen}{symbols}{"6B}{largesymbols}{"0D}
514 \DeclareMathDelimiter{\rVert}
515 {\mathclose}{symbols}{"6B}{largesymbols}{"0D}
524 % \subsection{Fractions}
525 % Bury the generalized fraction primitives \cs{over}, \cs{atop},
526 % etc., because of their bizarre syntax, which is decidedly out of
527 % place in a \latex/ document.
529 \@saveprimitive\over\@@over
530 \@saveprimitive\atop\@@atop
531 \@saveprimitive\above\@@above
532 \@saveprimitive\overwithdelims\@@overwithdelims
533 \@saveprimitive\atopwithdelims\@@atopwithdelims
534 \@saveprimitive\abovewithdelims\@@abovewithdelims
537 % \begin{macro}{\primfrac}
538 % If someone insists on using \cs{over}, give a warning the first
539 % time and then resurrect the old definition. Laissez-faire policy.
541 \DeclareRobustCommand{\primfrac}[1]{%
542 \PackageWarning{amsmath}{%
543 Foreign command \@backslashchar#1;\MessageBreak
544 \protect\frac\space or \protect\genfrac\space should be used instead%
547 \global\@xp\let\csname#1\@xp\endcsname\csname @@#1\endcsname
553 \renewcommand{\over}{\primfrac{over}}
554 \renewcommand{\atop}{\primfrac{atop}}
555 \renewcommand{\above}{\primfrac{above}}
556 \renewcommand{\overwithdelims}{\primfrac{overwithdelims}}
557 \renewcommand{\atopwithdelims}{\primfrac{atopwithdelims}}
558 \renewcommand{\abovewithdelims}{\primfrac{abovewithdelims}}
561 % \cn{frac} calls \cn{@@over} directly instead of via \cn{genfrac}, for
562 % better speed because it is so common. \cn{tfrac} and \cn{dfrac} are
563 % abbreviations for some commonly needed mathstyle overrides. To
564 % conserve csnames we avoid making \cn{dfrac} and \cn{tfrac} robust
565 % (\cn{genfrac} is itself robust).
567 \DeclareRobustCommand{\frac}[2]{{\begingroup#1\endgroup\@@over#2}}
568 \newcommand{\dfrac}{\genfrac{}{}{}0}
569 \newcommand{\tfrac}{\genfrac{}{}{}1}
571 % The \cn{binom} command for binomial notation works like \cn{frac}
572 % and has similar variants. Note that we do not use \cs{z@} in
573 % \cn{dbinom} and \cn{tbinom} because they are not top-level robust
574 % like \cn{binom}, and so the \cs{z@} with the potentially
575 % problematic \qc{\@} character would become visible when writing one
576 % of those commands to a \fn{.toc} file.
578 \DeclareRobustCommand{\binom}{\genfrac()\z@{}}
579 \newcommand{\dbinom}{\genfrac(){0pt}0}
580 \newcommand{\tbinom}{\genfrac(){0pt}1}
583 % \begin{macro}{\genfrac}
584 % \changes{v2.16a}{2016/11/05}{New genfrac implementation for extended
586 % This command provides access to \tex/'s generalized fraction
587 % primitives. Args: \arg{1} left delim, \arg{2} right delim, \arg{3}
588 % line thickness, \arg{4} mathstyle override, \arg{5} numerator,
589 % \arg{6} denominator. But we only read the first four args at first,
590 % in order to give us a moment to select the proper generalized
591 % fraction primitive. Any of those four args could be empty, and when
592 % empty the obvious defaults are selected (no delimiters, default
593 % line thickness (normally .4pt), and no mathstyle override).
595 % the |withdelims| primitives do not work in xetex with OpenType
596 % fonts, and the relevant font dimen parameters are often not set
597 % in luatex as theer are no matching values in the OpenType Math
598 % table, so here we use variants that use the font parameters if
599 % they are set, but scale using |\left\right| rather than the
600 % |withdelims| primitives.
603 \ifx\directlua\@undefined
607 \ifx\XeTeXcharclass\@undefined
611 \DeclareRobustCommand{\genfrac}[4]{%
613 \edef\@tempb{\@nx\@genfrac\@mathstyle{#4}%
614 \csname @@\ifx @#3@over\else above\fi
615 \ifx\@tempa\@empty \else withdelims\fi\endcsname}
624 \def\genfrac@rule#1#2#3#4{%
625 \hbox{$\left#1\vcenter{\hrule \@width\z@
627 \ifdim\fontdimen#2#3\tw@=\z@
636 \def\genfrac@choice#1#2{%
638 {\delimitershortfall\z@\delimiterfactor\@m
639 \mathsurround\z@\nulldelimiterspace\z@
640 \ifx c#1\kern-\nulldelimiterspace\fi
642 {\genfrac@rule{#2}{20}\textfont{2.39}}%
643 {\genfrac@rule{#2}{21}\textfont{1}}%
644 {\genfrac@rule{#2}{21}\scriptfont{1.45}}%
645 {\genfrac@rule{#2}{21}\scriptscriptfont{1.35}}%
647 \ifx o#1\kern-\nulldelimiterspace\fi
653 \DeclareRobustCommand{\genfrac}[6]{{%
655 \genfrac@choice o{#1}%
656 {\begingroup#5\endgroup\ifx @#3@\@@over\else\@@above\fi#3\relax#6}%
657 \genfrac@choice c{#2}%
667 \def\genfrac@rule#1#2#3{%
668 \hbox{$\left#1\vcenter{\hrule \@width\z@
670 \ifdim\Umathfractiondelsize#2=\z@
673 \Umathfractiondelsize#2%
679 \def\genfrac@choice#1#2{%
681 {\delimitershortfall\z@\delimiterfactor\@m
682 \mathsurround\z@\nulldelimiterspace\z@
683 \ifx c#1\kern-\nulldelimiterspace\fi
685 {\genfrac@rule{#2}\displaystyle{2.39}}%
686 {\genfrac@rule{#2}\textstyle{1}}%
687 {\genfrac@rule{#2}\scriptstyle{1.45}}%
688 {\genfrac@rule{#2}\scriptscriptstyle{1.35}}%
690 \ifx o#1\kern-\nulldelimiterspace\fi
696 \DeclareRobustCommand{\genfrac}[6]{{%
698 \genfrac@choice o{#1}%
699 {\begingroup#5\endgroup\ifx @#3@\@@over\else\@@above\fi#3\relax#6}%
700 \genfrac@choice c{#2}%
708 % End of test for Lua\TeX/Xe\TeX.
710 % \cs{@genfrac} takes the preceding arguments and reads the
711 % numerator and denominator. Note that there's no convenient way to
712 % make the numerator and denominator \emph{contents}
713 % displaystyle, through this interface.
715 % Args: \arg{1} mathstyle, \arg{2} fraction primitive,
716 % \arg{3} delimiters and rule thickness,
717 % \arg{4} numerator, \arg{5} denominator.
719 \def\@genfrac#1#2#3#4#5{{#1{\begingroup#4\endgroup#2#3\relax#5}}}
723 % Empty mathstyle arg: no change; 0 = displaystyle, 1 = textstyle, 2
724 % = scriptstyle, 3 = scriptscriptstyle.
727 \ifx\@empty#1\@empty\relax
728 \else\ifcase#1\displaystyle % case 0
729 \or\textstyle\or\scriptstyle\else\scriptscriptstyle\fi\fi}
732 % \subsection{Sums and Integrals}
733 % Default value for sum limits is \cs{displaylimits}, see option
736 % We redefine all the cumulative operator symbols to use
737 % \cs{slimits@} so that switching between \cs{displaylimits} and
738 % \cs{nolimits} can be controlled by package options. Also add
739 % \cs{DOTSB} for the benefit of the dots lookahead. But we'd better
740 % make sure \cn{coprod} and the others are simple mathchars; if not,
741 % the attempted changes will probably fail miserably.
743 % \changes{v2.15}{2016/02/20}{Accept \cs{Umathchar}}
748 \edef\@tempa{\string\mathchar"}
749 \edef\@tempd{\string\Umathchar"}
750 \def\@tempb#1"#2\@nil{#1"}
751 \edef\@tempc{\expandafter\@tempb\meaning\coprod "\@nil}
752 \ifx\@tempc\@tempd\let\@tempc\@tempa\fi
756 \global\let\coprod@\coprod
757 \gdef\coprod{\DOTSB\coprod@\slimits@}
758 \global\let\bigvee@\bigvee
759 \gdef\bigvee{\DOTSB\bigvee@\slimits@}
760 \global\let\bigwedge@\bigwedge
761 \gdef\bigwedge{\DOTSB\bigwedge@\slimits@}
762 \global\let\biguplus@\biguplus
763 \gdef\biguplus{\DOTSB\biguplus@\slimits@}
764 \global\let\bigcap@\bigcap
765 \gdef\bigcap{\DOTSB\bigcap@\slimits@}
766 \global\let\bigcup@\bigcup
767 \gdef\bigcup{\DOTSB\bigcup@\slimits@}
768 \global\let\prod@\prod
769 \gdef\prod{\DOTSB\prod@\slimits@}
771 \gdef\sum{\DOTSB\sum@\slimits@}
772 \global\let\bigotimes@\bigotimes
773 \gdef\bigotimes{\DOTSB\bigotimes@\slimits@}
774 \global\let\bigoplus@\bigoplus
775 \gdef\bigoplus{\DOTSB\bigoplus@\slimits@}
776 \global\let\bigodot@\bigodot
777 \gdef\bigodot{\DOTSB\bigodot@\slimits@}
778 \global\let\bigsqcup@\bigsqcup
779 \gdef\bigsqcup{\DOTSB\bigsqcup@\slimits@}
784 % \subsection{Roots and radicals}
786 % \begin{macro}{\root}
787 % This root stuff needs syntax work and implementation work. Surely
788 % something more compact can be done?? [mjd, 1994/09/05]
790 \newcommand{\leftroot}{\@amsmath@err{\Invalid@@\leftroot}\@eha}
791 \newcommand{\uproot}{\@amsmath@err{\Invalid@@\uproot}\@eha}
794 \renewcommand{\root}{\relaxnext@
795 \DN@{\ifx\@let@token\uproot\let\next@\nextii@\else
796 \ifx\@let@token\leftroot\let\next@\nextiii@\else
797 \let\next@\plainroot@\fi\fi\next@}%
798 \def\nextii@\uproot##1{\uproot@##1\relax\FN@\nextiv@}%
799 \def\nextiv@{\ifx\@let@token\@sptoken\DN@. {\FN@\nextv@}\else
800 \DN@.{\FN@\nextv@}\fi\next@.}%
801 \def\nextv@{\ifx\@let@token\leftroot\let\next@\nextvi@\else
802 \let\next@\plainroot@\fi\next@}%
803 \def\nextvi@\leftroot##1{\leftroot@##1\relax\plainroot@}%
804 \def\nextiii@\leftroot##1{\leftroot@##1\relax\FN@\nextvii@}%
805 \def\nextvii@{\ifx\@let@token\@sptoken
806 \DN@. {\FN@\nextviii@}\else
807 \DN@.{\FN@\nextviii@}\fi\next@.}%
808 \def\nextviii@{\ifx\@let@token\uproot\let\next@\nextix@\else
809 \let\next@\plainroot@\fi\next@}%
810 \def\nextix@\uproot##1{\uproot@##1\relax\plainroot@}%
811 \bgroup\uproot@\z@\leftroot@\z@\FN@\next@}
812 \def\plainroot@#1\of#2{\setbox\rootbox\hbox{%
813 $\m@th\scriptscriptstyle{#1}$}%
814 \mathchoice{\r@@t\displaystyle{#2}}{\r@@t\textstyle{#2}}
815 {\r@@t\scriptstyle{#2}}{\r@@t\scriptscriptstyle{#2}}\egroup}
819 % \changes{v2.0}{1999/06/17}{Normalize @@sqrt to sqrtsign}
821 % Name change from \cs{@@sqrt} to \cs{sqrtsign} happened in the
822 % 1995/12/01 release of \latex/. If we were to assume that
823 % \cs{sqrtsign} is defined then someone with the 1995/06/01 release
824 % of \latex/ would have trouble using this package.
826 \@ifundefined{sqrtsign}{\let\sqrtsign\@@sqrt}{}
827 \def\r@@t#1#2{\setboxz@h{$\m@th#1\sqrtsign{#2}$}%
828 \dimen@\ht\z@\advance\dimen@-\dp\z@
829 \setbox\@ne\hbox{$\m@th#1\mskip\uproot@ mu$}%
830 \advance\dimen@ by1.667\wd\@ne
831 \mkern-\leftroot@ mu\mkern5mu\raise.6\dimen@\copy\rootbox
832 \mkern-10mu\mkern\leftroot@ mu\boxz@}
835 % \subsection{Et cetera}
837 % \changes{v2.0}{1999/06/18}{Leave Greek cap letters unaltered}
839 % Specific names for the variant italic cap Greek letters are not
840 % defined by \latex/. If no preceding package defined these, we will
843 \@ifundefined{varGamma}{%
844 \DeclareMathSymbol{\varGamma}{\mathord}{letters}{"00}
845 \DeclareMathSymbol{\varDelta}{\mathord}{letters}{"01}
846 \DeclareMathSymbol{\varTheta}{\mathord}{letters}{"02}
847 \DeclareMathSymbol{\varLambda}{\mathord}{letters}{"03}
848 \DeclareMathSymbol{\varXi}{\mathord}{letters}{"04}
849 \DeclareMathSymbol{\varPi}{\mathord}{letters}{"05}
850 \DeclareMathSymbol{\varSigma}{\mathord}{letters}{"06}
851 \DeclareMathSymbol{\varUpsilon}{\mathord}{letters}{"07}
852 \DeclareMathSymbol{\varPhi}{\mathord}{letters}{"08}
853 \DeclareMathSymbol{\varPsi}{\mathord}{letters}{"09}
854 \DeclareMathSymbol{\varOmega}{\mathord}{letters}{"0A}
858 % \begin{macro}{\overline}
859 % \amstex/ redefines \cn{overline} as shown here, for reasons that
860 % are probably less important in \latex/: Make it read its argument
861 % as a macro argument rather than a ``math field'' (\emph{The
862 % \tex/book}, Chapter 26), to avoid problems when something that is
863 % apparently a single symbol is actually a non-simple macro (e.g.,
864 % \cn{dag}) \emph{and} is given as a single-token argument without
867 \@saveprimitive\overline\@@overline
868 \DeclareRobustCommand{\overline}[1]{\@@overline{#1}}
872 % \begin{macro}{\boxed}
873 % The \cs{boxed} command is specifically intended to put a box around
874 % an equation or piece of an equation. (Not including the equation
875 % number.) This isn't trivial for end-users to do it properly
876 % with \cs{fbox} so we provide a command for them.
878 \newcommand{\boxed}[1]{\fbox{\m@th$\displaystyle#1$}}
882 % \begin{macro}{\implies}
883 % \begin{macro}{\impliedby}
885 \newcommand{\implies}{\DOTSB\;\Longrightarrow\;}
886 \newcommand{\impliedby}{\DOTSB\;\Longleftarrow\;}
891 % \begin{macro}{\And}
893 \def\And{\DOTSB\;\mathchar"3026 \;}
897 % \begin{macro}{\nobreakdash}
898 % The command \cn{nobreakdash} is designed only for use before a
899 % hyphen or dash (|-|, |--|, or |---|).
900 % Setting the hyphen in a box and then unboxing it means that the
901 % normal penalty will not be added after it---and if the penalty is
902 % not there a break will not be taken (unless an explicit penalty
903 % or glue follows, thus the final \verb=\nobreak=).
905 \newcommand{\nobreakdash}{\leavevmode
906 \toks@\@emptytoks \def\@tempa##1{\toks@\@xp{\the\toks@-}\FN@\next@}%
907 \DN@{\ifx\@let@token-\@xp\@tempa
908 \else\setboxz@h{\the\toks@\nobreak}\unhbox\z@\fi}%
914 % \begin{macro}{\colon}
915 % \cs{colon} is for a colon in math that resembles a text colon:
916 % small space on the left, larger space on the right. The \qc{\:}
917 % character by itself is treated as a \cs{mathrel} i.e. large, equal
918 % spacing on both sides.
920 \renewcommand{\colon}{\nobreak\mskip2mu\mathpunct{}\nonscript
921 \mkern-\thinmuskip{:}\mskip6muplus1mu\relax}
925 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
926 % \section{Ellipsis dots}
928 % We can't use \cs{newif} for \cs{ifgtest@} because we want
929 % to include \cs{global} in the definitions of
930 % \cs{gtest@true} and \cs{gtest@false}.
932 \let\ifgtest@\iffalse % initial value
933 \def\gtest@true{\global\let\ifgtest@\iftrue}
934 \def\gtest@false{\global\let\ifgtest@\iffalse}
938 {\uccode`7=`\\ \uccode`8=`m \uccode`9=`a \uccode`0=`t \uccode`!=`h
940 \gdef\math@#1#2#3#4#5#6\math@{\gtest@false\ifx 7#1\ifx 8#2%
941 \ifx 9#3\ifx 0#4\ifx !#5\xdef\meaning@{#6}\gtest@true
943 {\uccode`7=`c \uccode`8=`h \uccode`9=`\"
944 \uppercase{\gdef\mathch@#1#2#3#4#5#6\mathch@{\gtest@false
945 \ifx 7#1\ifx 8#2\ifx 9#5\gtest@true\xdef\meaning@{9#6}\fi\fi\fi}}}
947 % \changes{v2.15}{2016/02/20}{Accept \cs{Umathchar}}
949 {\uccode`(=`U \uccode`)=`m
950 \uppercase{\gdef\Umathch@#1#2#3#4"#5"#6\Umathch@{\gtest@false
951 \ifx(#2\ifx)#3\gtest@true
952 \ifcase"#5 \or\or\gdef\thedots@{\dotsb@}\or\gdef\thedots@{\dotsb@}\fi
956 % \changes{v2.15}{2016/02/20}{Decode the mathcode of character tokens for Unicode TeX}
957 % For Unicode TeXs, if the next token is a character token look up the (U)mathcode. Do not do this for classic TeX for compatibility reasons.
959 \ifx\Umathcharnumdef\@undefined
960 \gdef\thecharacter@#1\thecharacter@{}
962 {\uccode`(=`t \uccode`)=`c
963 \uppercase{\gdef\thecharacter@#1#2#3#4#5\thecharacter@{%
965 \@xp\getmathcode@\meaning@\getmathcode@
968 \def\getmathcode@#1 #2 #3#4\getmathcode@{%
969 \Umathcharnumdef\@tempa\Umathcodenum`#3\relax
970 \edef\meaning@{\meaning\@tempa}%
971 \@xp\Umathch@\meaning@\Umathch@
977 \def\getmathch@#1.#2\getmathch@{\classnum@#1 \divide\classnum@4096
978 \ifcase\number\classnum@\or\or\gdef\thedots@{\dotsb@}\or
979 \gdef\thedots@{\dotsb@}\fi}
980 {\uccode`4=`b \uccode`5=`i \uccode`6=`n
981 \uppercase{\gdef\mathbin@#1#2#3{\relaxnext@
982 \def\nextii@##1\mathbin@{\ifx\@sptoken\@let@token\gtest@true\fi}%
983 \gtest@false\DN@##1\mathbin@{}%
984 \ifx 4#1\ifx 5#2\ifx 6#3\DN@{\FN@\nextii@}\fi\fi\fi\next@}}}
985 {\uccode`4=`r \uccode`5=`e \uccode`6=`l
986 \uppercase{\gdef\mathrel@#1#2#3{\relaxnext@
987 \def\nextii@##1\mathrel@{\ifx\@sptoken\@let@token\gtest@true\fi}%
988 \gtest@false\DN@##1\mathrel@{}%
989 \ifx 4#1\ifx 5#2\ifx 6#3\DN@{\FN@\nextii@}\fi\fi\fi\next@}}}
990 {\uccode`5=`m \uccode`6=`a \uccode`7=`c
991 \uppercase{\gdef\macro@#1#2#3#4\macro@{\gtest@false
992 \ifx 5#1\ifx 6#2\ifx 7#3\gtest@true
993 \xdef\meaning@{\macro@@#4\macro@@}\fi\fi\fi}}}
994 \def\macro@@#1->#2\macro@@{#2}
996 {\uccode`6=`\\ \uccode`7=`D \uccode`8=`O \uccode`9=`T \uccode`0=`S
997 \uppercase{\gdef\DOTS@#1#2#3#4#5{\gtest@false\DN@##1\DOTS@{}%
998 \ifx 6#1\ifx 7#2\ifx 8#3\ifx 9#4\ifx 0#5\let\next@\DOTS@@
1001 {\uccode`3=`B \uccode`4=`I \uccode`5=`X
1002 \uppercase{\gdef\DOTS@@#1{\relaxnext@
1003 \def\nextii@##1\DOTS@{\ifx\@sptoken\@let@token\gtest@true\fi}%
1005 \ifx 3#1\global\DOTSCASE@\z@\else
1006 \ifx 4#1\global\DOTSCASE@\@ne\else
1007 \ifx 5#1\global\DOTSCASE@\tw@\else\DN@##1\DOTS@{}%
1009 {\uccode`5=`\\ \uccode`6=`n \uccode`7=`o \uccode`8=`t
1010 \uppercase{\gdef\not@#1#2#3#4{\relaxnext@
1011 \def\nextii@##1\not@{\ifx\@sptoken\@let@token\gtest@true\fi}%
1012 \gtest@false\DN@##1\not@{}%
1013 \ifx 5#1\ifx 6#2\ifx 7#3\ifx 8#4\DN@{\FN@\nextii@}\fi\fi\fi
1016 % \changes{v2.15}{2016/02/20}{macro added to strip \cs{long} during tests}
1019 \uppercase{\gdef\striplong@#1#2#3\relax{%
1020 \ifx9#2 \@xp\@xp\@xp\zap@to@space\fi}}}
1021 \def\zap@to@space#1 {}
1024 \def\keybin@{\gtest@true
1025 \ifx\@let@token+\else\ifx\@let@token=\else
1026 \ifx\@let@token<\else\ifx\@let@token>\else
1027 \ifx\@let@token-\else\ifx\@let@token*\else\ifx\@let@token:\else
1028 \gtest@false\fi\fi\fi\fi\fi\fi\fi}
1030 % Patch to ensure \cs{@ldots} is defined. (Name changed to
1031 % \cn{mathellipsis} in Dec 94 release of \latex/.)
1033 \@ifundefined{@ldots}{\def\@ldots{\mathellipsis}}{}
1035 % \begin{macro}{\ldots}
1036 % \begin{macro}{\dots}
1037 % Reiterate the standard definition of \cs{ldots} to keep it from
1038 % being clobbered by the redefinition of \cs{dots}.
1040 \DeclareRobustCommand{\ldots}{%
1041 \ifmmode \mathellipsis \else \textellipsis \fi
1043 \DeclareRobustCommand{\dots}{%
1044 \ifmmode \@xp\mdots@\else \@xp\textellipsis \fi
1050 \def\tdots@{\leavevmode\unskip\relaxnext@
1051 \DN@{$\m@th\@ldots\,
1052 \ifx\@let@token,\,$\else\ifx\@let@token.\,$\else
1053 \ifx\@let@token;\,$\else\ifx\@let@token:\,$\else
1054 \ifx\@let@token?\,$\else\ifx\@let@token!\,$\else
1055 $ \fi\fi\fi\fi\fi\fi}%
1057 \def\mdots@{\FN@\mdots@@}
1059 % \changes{v2.15}{2016/02/20}{Indent \cs{mdots@@} for readability and add additional tests}
1061 \def\mdots@@{\gdef\thedots@{\dotso@}%
1062 \ifx\@let@token\boldsymbol
1063 \gdef\thedots@\boldsymbol{\boldsymboldots@}%
1065 \ifx,\@let@token \gdef\thedots@{\dotsc}%
1068 \gdef\thedots@{\dotsb@}%
1071 \ifgtest@ % if \keybin@ test
1072 \gdef\thedots@{\dotsb@}%
1075 % \changes{v2.15d}{2016/06/28}{Add space token to prevent runaway argument error}
1077 \xdef\meaning@{\meaning\@let@token. .........}%
1079 % In previous versions \verb|\long| macros were not seen by the lokkahead.
1080 % That was bad as this file uses \verb|\(re)newcommand| for \verb|\implies| etc.
1082 \xdef\meaning@@{\@xp\striplong@\meaning@\relax\meaning@}%
1085 \@xp\math@\meaning@\math@
1086 \ifgtest@ % if \mathxxx test
1087 \@xp\mathch@\meaning@\mathch@
1088 \ifgtest@ % if \mathchar
1089 \@xp\getmathch@\meaning@\getmathch@
1090 \fi % end if \mathchar
1091 \else % \not \mathxxx
1093 % Test for \verb|\Umathchar| added.
1095 \@xp\Umathch@\meaning@"0"\Umathch@
1096 \ifgtest@ % if \Umathchar
1097 \else % else not \Umathcar
1100 \@xp\macro@\meaning@@\macro@
1101 \ifgtest@ % if macro test
1102 \@xp\not@\meaning@\not@
1103 \ifgtest@ % if macro starts \not test
1104 \gdef\thedots@{\dotsb@}%
1105 \else% else not \not
1106 \@xp\DOTS@\meaning@\DOTS@
1107 \ifgtest@ % \if DOTS
1108 \ifcase\number\DOTSCASE@ %ifcase dots
1109 \gdef\thedots@{\dotsb@}%
1110 \or\gdef\thedots@{\dotsi}\else
1111 \fi % endifcase dots
1112 \else % not macro starts \DOTS
1113 \@xp\math@\meaning@\math@
1114 \ifgtest@ % \if macro starts \mathxxxx
1115 \@xp\mathbin@\meaning@\mathbin@
1116 \ifgtest@ % if macro starts \mathbin
1117 \gdef\thedots@{\dotsb@}%
1118 \else % not macro starting \mathbin
1119 \@xp\mathrel@\meaning@\mathrel@
1120 \ifgtest@ % if macro starts \mathrel
1121 \gdef\thedots@{\dotsb@}%
1122 \fi % endif macro starts \mathrel (no else)
1123 \fi % endif macro starts \mathbin
1124 \fi % endif macro starts with \mathxxx (no else)
1125 \fi % endif macro starts \DOTS else
1126 \fi % end macro starting \not \ifgtest@ test (no else)
1128 % Additional test for a catcode 12 character.
1131 \@xp\thecharacter@\meaning@\thecharacter@
1134 \fi % end macro \ifgtest@ test (no else)
1135 \fi % end if \Umathchar test
1136 \fi % end \math@ \ifgtest@
1137 \fi % end \keybin@ \ifgtest@ test (no else)
1138 \fi % end if \not (no else)
1139 \fi % end if comma (no else)
1140 \fi % end if boldsymbol (no else)
1144 % The \qc{\=} character is necessary in the two \cs{let} assignments
1145 % in \cs{boldsymboldots@}, because the symbol we are making
1146 % bold might be an \qc{\=} sign.
1148 \def\boldsymboldots@#1{%
1149 \bold@true\let\@let@token=#1\let\delayed@=#1\mdots@@
1150 \boldsymbol#1\bold@false}
1153 % The definition of \cs{@cdots} is merely the \fn{plain.tex}
1154 % definition of \cs{cdots}.
1156 \ams@def\@cdots{\mathinner{\cdotp\cdotp\cdotp}}
1157 \newcommand{\dotsi}{\!\@cdots}
1161 % If any new right delimiters are defined, they would need to be
1162 % added to the definition of \cs{rightdelim@} in order for \cn{dots}
1163 % to work properly in all cases.
1165 \def\rightdelim@{\gtest@true
1166 \ifx\@let@token)\else
1167 \ifx\@let@token]\else
1168 \ifx\@let@token\rbrack\else
1169 \ifx\@let@token\}\else
1170 \ifx\@let@token\rbrace\else
1171 \ifx\@let@token\rangle\else
1172 \ifx\@let@token\rceil\else
1173 \ifx\@let@token\rfloor\else
1174 \ifx\@let@token\rgroup\else
1175 \ifx\@let@token\rmoustache\else
1176 \ifx\@let@token\right\else
1177 \ifx\@let@token\bigr\else
1178 \ifx\@let@token\biggr\else
1179 \ifx\@let@token\Bigr\else
1180 \ifx\@let@token\Biggr\else\gtest@false
1181 \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi}
1183 \rightdelim@\ifgtest@
1184 \else\ifx\@let@token$\gtest@true
1185 \else\xdef\meaning@{\meaning\@let@token..........}%
1186 \@xp\macro@\meaning@\macro@\ifgtest@
1187 \@xp\DOTS@\meaning@\DOTS@
1189 \ifnum\DOTSCASE@=\tw@\gtest@true\else\gtest@false
1192 \def\dotso@{\relaxnext@
1194 \let\@let@token\delayed@
1195 \def\nextii@{\extra@\@ldots\ifgtest@\,\fi}%
1197 \def\nextii@{\DN@{\extra@\@ldots\ifgtest@\,\fi}\FN@\next@}%
1201 % Why not save some tokens? (space vs. time).
1205 \ifx\@let@token,\else
1206 \ifx\@let@token;\else
1207 \ifx\@let@token.\else\extra@
1209 \let\next@#1\fi\fi\fi\fi\next@}
1212 % \begin{macro}{\cdots}
1213 % \begin{macro}{\dotsb}
1214 % \begin{macro}{\dotsm}
1215 % \begin{macro}{\dotso}
1216 % \begin{macro}{\dotsc}
1217 % The \cn{cdots} command.
1219 \ams@DeclareRobustCommand{\cdots}{\DN@{\extrap@\@cdots}\FN@\next@}
1222 \DeclareRobustCommand{\dotso}{\relax
1223 \ifmmode \DN@{\extrap@\@ldots}%
1224 \else \let\next@\tdots@\fi
1226 \DeclareRobustCommand{\dotsc}{%
1227 \DN@{\ifx\@let@token;\@ldots\,%
1228 \else \ifx\@let@token.\@ldots\,%
1229 \else \extra@\@ldots \ifgtest@\,\fi
1238 % \begin{macro}{\longrightarrow}
1239 % \begin{macro}{\Longrightarrow}
1240 % \begin{macro}{\longleftarrow}
1241 % \begin{macro}{\Longleftarrow}
1242 % \begin{macro}{\longleftrightarrow}
1243 % \begin{macro}{\Longleftrightarrow}
1244 % \begin{macro}{\mapsto}
1245 % \begin{macro}{\longmapsto}
1246 % \begin{macro}{\hookrightarrow}
1247 % \begin{macro}{\hookleftarrow}
1248 % \begin{macro}{\iff}
1251 \renewcommand{\longrightarrow}{%
1252 \DOTSB\protect\relbar\protect\joinrel\rightarrow}
1253 \renewcommand{\Longrightarrow}{%
1254 \DOTSB\protect\Relbar\protect\joinrel\Rightarrow}
1255 \renewcommand{\longleftarrow}{%
1256 \DOTSB\leftarrow\protect\joinrel\protect\relbar}
1257 \renewcommand{\Longleftarrow}{%
1258 \DOTSB\Leftarrow\protect\joinrel\protect\Relbar}
1259 \renewcommand{\longleftrightarrow}{\DOTSB\leftarrow\joinrel\rightarrow}
1260 \renewcommand{\Longleftrightarrow}{\DOTSB\Leftarrow\joinrel\Rightarrow}
1261 \renewcommand{\mapsto}{\DOTSB\mapstochar\rightarrow}
1262 \renewcommand{\longmapsto}{\DOTSB\mapstochar\longrightarrow}
1263 \renewcommand{\hookrightarrow}{\DOTSB\lhook\joinrel\rightarrow}
1264 \renewcommand{\hookleftarrow}{\DOTSB\leftarrow\joinrel\rhook}
1265 \renewcommand{\iff}{\DOTSB\;\Longleftrightarrow\;}
1278 % \begin{macro}{\doteq}
1279 % The \cn{doteq} command formerly used \cs{buildrel}; we avoid that
1280 % because it requires `\cn{over}' as part of its syntax. Use 0pt
1281 % instead of \cs{z@} for robustitude.
1283 \renewcommand{\doteq}{%
1284 \DOTSB\mathrel{\mathop{\kern0pt =}\limits^{\textstyle.}}}
1288 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1289 % \section{Integral signs}
1291 % \begin{macro}{\if@display}
1292 % The straightforward \cs{ifinner} test to see if the current math
1293 % context is non-display, fails if, for instance, we are typesetting
1294 % a multiline display within an \cs{halign}, with the pieces going
1295 % into constructions like
1297 % $\displaystyle...$
1299 % So we need a better test to find out if we are `in a display'. We
1300 % therefore create \cs{if@display}.
1304 \everydisplay\@xp{\the\everydisplay \@displaytrue}
1308 % \begin{macro}{\int}
1309 % \begin{macro}{\oint}
1310 % \begin{macro}{\iint}
1311 % \begin{macro}{\iiint}
1312 % \begin{macro}{\iiiint}
1313 % \begin{macro}{\idotsint}
1314 % Default value for integral limits is \cs{nolimits}, see the
1315 % definition of the `nointlimits' option.
1317 \renewcommand{\int}{\DOTSI\intop\ilimits@}
1318 \renewcommand{\oint}{\DOTSI\ointop\ilimits@}
1319 \def\intkern@{\mkern-6mu\mathchoice{\mkern-3mu}{}{}{}}
1320 \def\intdots@{\mathchoice{\@cdots}%
1321 {{\cdotp}\mkern1.5mu{\cdotp}\mkern1.5mu{\cdotp}}%
1322 {{\cdotp}\mkern1mu{\cdotp}\mkern1mu{\cdotp}}%
1323 {{\cdotp}\mkern1mu{\cdotp}\mkern1mu{\cdotp}}}
1325 \ams@newcommand{\iint}{\DOTSI\protect\MultiIntegral{2}}
1326 \ams@newcommand{\iiint}{\DOTSI\protect\MultiIntegral{3}}
1327 \ams@newcommand{\iiiint}{\DOTSI\protect\MultiIntegral{4}}
1328 \newcommand{\idotsint}{\DOTSI\protect\MultiIntegral{0}}
1337 % \begin{macro}{\MultiIntegral}
1338 % If the \cs{limits} option is applied, use \cs{mathop} and fudge
1339 % the left-hand space a bit to make the subscript visually centered.
1341 % \verb'#1' is the multiplicity.
1343 \newcommand{\MultiIntegral}[1]{%
1344 \edef\ints@c{\noexpand\intop
1345 \ifnum#1=\z@\noexpand\intdots@\else\noexpand\intkern@\fi
1346 \ifnum#1>\tw@\noexpand\intop\noexpand\intkern@\fi
1347 \ifnum#1>\thr@@\noexpand\intop\noexpand\intkern@\fi
1351 \futurelet\@let@token\ints@a
1358 \ifx\limits\@let@token \ints@b
1359 \else \ifx\displaylimits\@let@token \ints@b
1360 \else\ifx\ilimits@\displaylimits \ints@b
1368 \mkern-7mu\mathchoice{\mkern-2mu}{}{}{}%
1370 \mkern7mu\mathchoice{\mkern2mu}{}{}{}%
1371 \let\ilimits@\egroup
1375 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1376 % \section{Size dependent definitions}
1378 % We now define all stuff which has to change whenever a new math
1379 % size is to be activated. \latex/ provides a hook called
1380 % |\every@math@size| to support such a need. All assignments in the
1381 % |\every@math@size| hook that need to take outside effect should be
1384 % \subsection{Struts for math}
1386 % The various kinds of struts could use some analysis and perhaps
1389 % For example perhaps the \cn{bBigg} delimiters could use
1391 % 1.2\ht\strutbox (1.8, 2.4, 3.0)
1395 % 1.0\big@size (1.5, 2.0, 2.5)
1397 % since \cs{strut} is reset with every size change [mjd, 1994/10/07].
1398 % But this change would introduce the possibility of changed line
1399 % and page breaks in existing documents, so would need to be
1400 % handled with care.
1402 % \begin{macro}{\Mathstrut@}
1403 % \begin{macro}{\Mathstrutbox@}
1404 % \begin{macro}{\resetMathstrut@}
1405 % Here comes the code for Spivak's |\Mathstrut@|.
1407 \newbox\Mathstrutbox@
1408 \setbox\Mathstrutbox@=\hbox{}
1409 \def\Mathstrut@{\copy\Mathstrutbox@}
1411 % The setting of the height and depth of the |\Mathstrutbox@| is done
1412 % in the |\every@math@size| hook since it depends on the height of a
1413 % paren. As \cs{every@math@size} is triggered by |$| after a font
1414 % size change, we want to avoid using another math formula |$...$| to
1415 % measure the math paren height; instead we go through the mathcode
1416 % of the \qc{\(} character. We assume that the mathcode has a leading
1417 % hex digit 4 indicating `open delimiter'; this allows us to make a
1418 % relatively simple function to get the correct font and character
1421 % \changes{v2.15}{2016/02/20}{Modify \cs{resetMathstrut@} for Unicode \TeX}
1422 % \changes{v2.15b}{2016/03/10}{Modify \cs{resetMathstrut@} for classic \TeX\ to preserve box 0}
1423 % Original code assuming |\mathcode| is kept for 8bit \TeX. Unicode \TeX{}
1424 % uses |\Umathcharnumdef| which works for xetex and luatex, which use
1425 % different forms for |\mathchardef|. (New luatex always reports
1426 % definitions using |\Umathchardef| syntax even if |\mathchardef| used.)
1428 % The unicode version uses e-tex |\fontcharht| to avoid boxing which
1429 % could also be done for pdftex, but not done here.
1431 \ifx\Umathcharnumdef\@undefined
1435 \def\resetMathstrut@{%
1438 \mathchardef\@tempa\mathcode`\(\relax
1439 \def\@tempb##1"##2##3{\the\textfont"##3\char"}%
1440 \expandafter\@tempb\meaning\@tempa \relax
1443 \ht\Mathstrutbox@\the\ht\z@\relax
1444 \dp\Mathstrutbox@\the\dp\z@\relax}%
1445 \expandafter\endgroup\@tempa
1449 % xetex/luatex version
1450 % \changes{v2.15a}{2016/03/03}{missing percent added}
1452 \def\resetMathstrut@{%
1454 \Umathcharnumdef\@tempa\Umathcodenum`\(\relax
1455 \def\@tempb##1"##2"##3"##4\relax{%
1457 \ht\Mathstrutbox@=\fontcharht\textfont"##3 "##4\relax
1458 \dp\Mathstrutbox@=\fontchardp\textfont"##3 "##4\relax}%
1459 \expandafter\@tempb\meaning\@tempa \relax
1465 % These height and depth assignments are implicitly global.
1467 \addto@hook\every@math@size{\resetMathstrut@}
1473 % \begin{macro}{\strut@}
1474 % \begin{macro}{\strutbox@}
1475 % Next follows a special internal strut which is supposed to match
1476 % the height and the depth of a normal |\strut| minus
1477 % |\normallineskiplimit| according to M. Spivak.
1479 % This should really go into the definition of \cs{size@update}, and
1480 % then the box reset could be local; but \cs{size@update} doesn't
1481 % have any hook and is handled in such a way that it cannot even be
1482 % changed except by changing \cs{set@fontsize}. So instead we put
1483 % \cs{reset@strutbox@} into \cs{every@math@size} and make it global.
1484 % Then because of some complications in the way \cs{glb@settings} and
1485 % \cs{check@mathfonts} work, we have to re-invoke it at the beginning
1486 % of every environment that might use \cs{strut@}. Fortunately this
1487 % can be achieved (more or less) through the \cs{spread@equation}
1488 % hook. [mjd,2000/03/10]
1491 \def\strut@{\copy\strutbox@}
1492 \def\reset@strutbox@{%
1493 \global\setbox\strutbox@\hbox{%
1494 \lower.5\normallineskiplimit
1495 \vbox{\kern-\normallineskiplimit\copy\strutbox}}}
1496 \addto@hook\every@math@size{\reset@strutbox@}
1497 \AtBeginDocument{\reset@strutbox@}
1502 % \subsection{Big delimiters}
1504 % We are now going to redefine the plain \tex/ commands \cn{big},
1505 % \cn{bigl}, etc., to produce different results in different sizes.
1506 % Actually we only have to define \cn{big}, \cn{Big}, etc., since
1507 % they are used to construct the directional versions \cn{bigl},
1508 % \cn{bigr}, and the rest.
1510 % \begin{macro}{\big}
1511 % \begin{macro}{\Big}
1512 % \begin{macro}{\bigg}
1513 % \begin{macro}{\Bigg}
1514 % To save token space we put everything into the common macro
1515 % |\bBigg@|. The macros are now simply a call to |\bBigg@| with a
1516 % factor to determine the correct height of the delimiter as an
1517 % argument. This code should better go into a future version of
1518 % the \latex/ kernel; the macro |\n@space| is then superfluous (since
1519 % it is only used once) and should be removed to avoid wasting hash
1520 % table space unnecessarily.
1522 \renewcommand{\big}{\bBigg@\@ne}
1523 \renewcommand{\Big}{\bBigg@{1.5}}
1524 \renewcommand{\bigg}{\bBigg@\tw@}
1525 \renewcommand{\Bigg}{\bBigg@{2.5}}
1532 % \begin{macro}{\bBigg@}
1533 % Now we tackle the macro which has to do the real work. It
1534 % actually has two arguments, the factor and the wanted delimiter.
1538 % We start with an extra set of braces because we want
1539 % constructions like |\def\bigl{\mathopen\big}| to work without the
1540 % overhead of extra arguments.
1542 {\@mathmeasure\z@{\nulldelimiterspace\z@}%
1543 {\left#2\vcenter to#1\big@size{}\right.}%
1548 % \begin{macro}{\big@size}
1549 % |\big@size| needs to be set to 1.2 times the height of a math
1550 % paren. This height is already recorded in |\Mathstrutbox@|.
1552 \addto@hook\every@math@size{%
1553 \global\big@size 1.2\ht\Mathstrutbox@
1554 \global\advance\big@size 1.2\dp\Mathstrutbox@ }
1560 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1561 % \section{Math accents}
1563 % We want to change the leading digit of math accents to be
1564 % \cs{accentclass@} so that it can vary according to certain internal
1567 \def\accentclass@{7}
1568 \def\noaccents@{\def\accentclass@{0}}
1571 % There are a few \meta{math alphabet}s in the standard fonts where
1572 % we have to change the extra macros because the standard definitions
1573 % don't account for these accent problems. The first is for the
1574 % \cs{mathit} command.
1576 \DeclareFontEncoding{OML}{}{\noaccents@}
1578 % The next one corrects the \cs{cal} alphabet.
1580 \DeclareFontEncoding{OMS}{}{\noaccents@}
1583 % \begin{macro}{\dddot}
1584 % \begin{macro}{\ddddot}
1585 % Triple and quadruple dot accents.
1587 \ams@newcommand{\dddot}[1]{%
1588 {\mathop{#1}\limits^{\vbox to-1.4\ex@{\kern-\tw@\ex@
1589 \hbox{\normalfont ...}\vss}}}}
1590 \ams@newcommand{\ddddot}[1]{%
1591 {\mathop{#1}\limits^{\vbox to-1.4\ex@{\kern-\tw@\ex@
1592 \hbox{\normalfont....}\vss}}}}
1597 % The following code deals with support for compound accents.
1598 % By redefining \cs{set@mathaccent} we ensure that
1599 % \cn{DeclareMathAccent} will define accent commands to run our
1600 % \cs{mathaccentV} function instead of the primitive \cs{mathaccent}.
1602 \def\set@mathaccent#1#2#3#4{%
1603 \xdef#2{\@nx\protect\@nx\mathaccentV
1604 {\@xp\@gobble\string#2}\hexnumber@#1#4}%
1608 % \begin{macro}{\hat}
1609 % \begin{macro}{\check}
1610 % \begin{macro}{\tilde}
1611 % \begin{macro}{\acute}
1612 % \begin{macro}{\grave}
1613 % \begin{macro}{\dot}
1614 % \begin{macro}{\ddot}
1615 % \begin{macro}{\breve}
1616 % \begin{macro}{\bar}
1617 % \begin{macro}{\vec}
1618 % \begin{macro}{\mathring}
1619 % We redefine the standard math accent commands to
1620 % call \cs{mathaccentV}, using the mathgroup/encoding-number
1621 % information embedded in their previous definitions. If the
1622 % definition of an accent command does not have the expected form, we
1623 % leave the accent command alone, but give a warning. For widehat and
1624 % widetilde, we need to avoid clobbering the definitions done by the
1625 % \pkg{amsfonts} package. Arbitrating the contention between
1626 % \pkg{amsmath} and \pkg{amsfonts} to allow doubling a widetilde
1627 % accent looks tricky, so for the time being [mjd,1999/07/19] we just
1628 % leave \cn{widehat} and \cn{widetilde} alone. As a result, if the
1629 % \pkg{amsmath} package is loaded on top of a vanilla \latex/
1630 % documentclass, everything runs through with no warnings. If a
1631 % Lucida Math or other math fonts package is loaded in addition to
1632 % \pkg{amsmath}, there are greater difficulties, but those are
1633 % addressed elsewhere.
1636 % \changes{v2.15}{2016/02/20}{Detect \cs{Umathaccent} on package load}
1637 % Adjust the test made at package load to recognise
1638 % |\Umathaccent|. Although currently it is just used to give a
1639 % modified warning that the accents will not be redefined.
1641 % Note that the engines behave quite differently here, luatex
1642 % even without these definitions using the OpenType accent set up by
1643 % unicode-math stacks |\hat{hat{f}}| correctly but xetex acts like
1644 % classic tex and needs this adjustment. This difference is not
1645 % addressed here at all.
1647 % This test is just at package loading and has no affect on the
1648 % definitions used in 8bit TeX.
1650 \def\@tempa#1{\@xp\@tempb\meaning#1\@nil#1}
1651 \def\@tempb#1>#2#3 #4\@nil#5{%
1652 \@xp\ifx\csname#3\endcsname\mathaccent
1653 \@tempc#4?"7777\@nil#5%
1655 \@xp\ifx\csname#3\endcsname\Umathaccent
1658 \PackageWarningNoLine{amsmath}{%
1659 Unable to redefine math accent \string#5}%
1661 \def\@tempc#1"#2#3#4#5#6\@nil#7{%
1662 \chardef\@tempd="#3\relax\set@mathaccent\@tempd{#7}{#2}{#4#5}}
1663 \def\@tempd#1\@nil#2{%
1664 \PackageWarningNoLine{amsmath}{%
1665 Unable to redefine \string\Umathaccent\space\string#2}%
1679 \@ifundefined{mathring}{%
1680 \DeclareMathAccent{\mathring}{\mathalpha}{operators}{"17}
1699 % Regression testing of amsmath 2.0 showed that in some documents
1700 % there occurred fragments of the form
1704 % This is not at all correct syntax for the argument of a \latex/
1705 % command but it produced the intended result anyway because of the
1706 % internal syntax of the \cs{mathaccent} primitive. With
1707 % \cs{mathaccentV}, it will yield an error message. We therefore do a
1708 % special check for such syntax problems in order to make the error
1709 % message more informative. (dmj: ??????)
1711 \newcommand{\acc@check}{}
1712 \newcommand{\acc@error}{}
1713 \def\acc@check{\@ifnextchar\@empty\relax\acc@error}
1715 % We put most of the tokens in a separate macro so they do not get
1716 % scanned unless they are actually needed.
1720 Improper argument for math accent:\MessageBreak
1721 Extra braces must be added to prevent wrong output%
1726 % For \cs{mathaccentV} part of the processing is dependent on the
1727 % depth of nesting of math accent commands. We introduce a dedicated
1728 % counter for this instead of using chardef because we want to
1729 % increment/decrement it during processing, and incrementing a
1730 % chardef integer is more work.
1732 \newcount\macc@depth
1735 % Provide this function in case it is not already available.
1737 \long\def\@gobblethree#1#2#3{}
1740 % The \cs{mathaccentV} function first counts the number of nested
1741 % math accents by setting the argument in a throw-away box. (This is
1742 % not as risky as such an operation would normally be because the
1743 % argument is generally either a simple math symbol or a nested math
1744 % accent call with a simple math symbol at the bottom of the
1747 % There are two benefits from counting the nesting levels first
1748 % before doing anything else: (1) we can fall back to a simple
1749 % \cs{mathaccent} call if the nesting depth is 1, and (2) if the
1750 % nesting depth is greater than 1, we would like to be able to tell
1751 % when we have reached the lowest level, because at that point we
1752 % want to save the argument for later use and place an accent on top
1753 % of a phantom copy.
1755 % When we have multiple accents, they will be placed on top of the
1756 % invisible box, followed by some suitable kerns, then a visible copy
1757 % of the nucleus. To see why, let us look at what goes wrong with a
1758 % double application of the \cs{mathaccent} primitive. The standard
1759 % definition of \cs{hat} is \verb'\mathaccent"705E', so
1760 % \verb'\hat{\hat{F}}' expands to
1762 %\mathaccent"705E{\mathaccent"705E{F}}
1764 % The result of this operation is
1766 %\vbox(12.11111+0.0)x7.81946
1767 %.\hbox(6.94444+0.0)x0.0, shifted 1.40973
1768 %..\OT1/cmr/m/n/10 ^
1770 %.\vbox(9.47221+0.0)x7.81946
1771 %..\hbox(6.94444+0.0)x0.0, shifted 2.24309
1772 %...\OT1/cmr/m/n/10 ^
1774 %..\hbox(6.83331+0.0)x7.81946
1775 %...\OML/cmm/m/it/10 F
1777 % \tex/ starts by constructing a vbox with the hat character on top
1778 % of the F. Then it puts another hat character on top of the vbox;
1779 % but without skew information, because that is only applied by
1780 % \cs{mathaccent} when the base object is a simple symbol. So the
1781 % first accent is skewed to the correct position but all later
1782 % accents are not. By the way, the actual width of the F in the above
1783 % example is less than 7.81946; the box in which it is packed was
1784 % automatically lengthened by the width of the F's italic correction
1785 % (without actually putting in a kern for it).
1787 % To get the second accent shifted farther to the right we
1788 % artificially increase the width of the innermost box and add
1789 % a compensating kern afterward. Furthermore, to get proper placement
1790 % of a following subscript or superscript, we take the base symbol
1791 % out, leaving a phantom in its place, and print it by itself
1792 % following the kern. We then need to increase the kern amount to
1793 % move the base character backward under the accents again.
1794 % Here is what the results look like:
1796 %\vbox(12.11111+0.0)x9.48618
1797 %.\hbox(6.94444+0.0)x0.0, shifted 2.24309
1798 %..\OT1/cmr/m/n/10 ^
1800 %.\vbox(9.47221+0.0)x9.48618
1801 %..\hbox(6.94444+0.0)x0.0, shifted 2.24309
1802 %...\OT1/cmr/m/n/10 ^
1804 %..\hbox(6.83331+0.0)x9.48618
1805 %...\hbox(6.83331+0.0)x7.81946
1811 % Much of this implementation is based on code from the \pkg{accents}
1812 % package of Javier Bezos. I added the test to revert to a simple
1813 % \cs{mathaccent} when accents are not nested, and some other
1814 % refinements to reduce the number of kerns used (to conserve box
1815 % memory) and the number of cycles through \cs{mathchoice} (to make
1816 % things run a little faster). It was all rather difficult and my
1817 % first two attempts had serious bugs but I hope and believe that
1818 % this version will do better. [mjd,2000/03/15]
1820 % The \qq{V} in \cs{mathaccentV} is just an indication that it takes
1821 % five arguments. It is important that the name includes
1822 % \texttt{mathaccent}, otherwise \cs{DeclareMathAccent} will balk at
1823 % redefining one of our accent commands, for example when an
1824 % alternative math font package is loaded.
1826 \def\mathaccentV#1#2#3#4#5{%
1828 \gdef\macc@tmp{\macc@depth\@ne}%
1830 \let\mathaccentV\macc@test
1831 \let\use@mathgroup\@gobbletwo \let\select@group\@gobblethree
1832 \frozen@everymath{}$#5$%
1835 \ifnum\macc@depth=\@ne
1836 \global\let\macc@nucleus\@empty
1837 \mathaccent"\accentclass@
1844 \@xp\nonmatherr@\csname#1\endcsname
1850 \def\macc@test#1#2#3#4{\xdef\macc@tmp{\macc@tmp\advance\macc@depth\@ne}}
1858 \def\macc@nested#1#2#3#4{%
1860 \let\math@bgroup\@empty \let\math@egroup\macc@set@skewchar
1861 \mathsurround\z@ \frozen@everymath{\mathgroup\macc@group\relax}%
1862 \macc@set@skewchar\relax
1863 \let\mathaccentV\macc@nested@a
1864 \macc@nested@a\relax#1#2#3{#4}%
1870 \let\macc@palette\mathpalette
1874 \def\macc@nested@a#1#2#3#4#5{%
1876 % This test saves some work that would otherwise be always repeated
1877 % fourfold thanks to \cs{mathchoice}.
1879 \ifnum\macc@group=\mathgroup
1880 \else \macc@set@skewchar\relax \edef\macc@group{\the\mathgroup}%
1882 \mathchardef\macc@code "\accentclass@ #2#3#4\relax
1883 \macc@palette\macc@a{#5}%
1887 % The reason that \cs{macc@set@skewchar} takes an argument is so that
1888 % it can serve as a direct substitute for \cs{math@egroup}, in
1889 % addition to being used separately.
1891 % Setting a skewchar with this method works for symbols of variable
1892 % mathgroup (class 7, letters and numbers) but not necessarily for
1893 % special symbols like \cn{partial} or \cs{xi} whose mathgroup
1894 % doesn't change; fortunately the most commonly used ones come from
1895 % mathgroup one, which is the fall-back mathgroup for skewchar.
1897 \def\macc@set@skewchar#1{%
1899 \ifnum\mathgroup=\m@ne \let\@tempa\@ne
1901 \ifnum\skewchar\textfont\mathgroup=\m@ne \let\@tempa\@ne
1902 \else \let\@tempa\mathgroup
1905 \count@=\skewchar\textfont\@tempa
1906 \advance\count@"7100
1907 \edef\@tempa{\endgroup
1908 \mathchardef\noexpand\macc@skewchar=\number\count@\relax}%
1914 % Arg1 is math-style, arg2 is accent base object. We assume that math
1915 % style doesn't change within the nested group of accents; this means
1916 % we can set \cs{macc@style} only once and redefine \cs{macc@palette}
1917 % to use it, in order to run \cs{mathchoice} only once instead of
1918 % multiplying the calls exponentially as the nesting level increases.
1922 \let\macc@style#1\relax
1923 \def\macc@palette##1{##1\macc@style}%
1924 \advance\macc@depth\m@ne
1925 \ifnum\macc@depth=\z@
1926 \gdef\macc@nucleus{#2}%
1928 % Extra \cs{@empty} tokens are to prevent low-level \tex/ errors from
1929 % the potential syntactic error that \cs{acc@check} checks for.
1931 \setbox\z@\hbox{$#1#2\@empty{}\macc@skewchar$}%
1932 \setbox\tw@\hbox{$#1#2\@empty\macc@skewchar$}%
1933 \dimen@\tw@\wd\tw@ \advance\dimen@-\tw@\wd\z@
1934 \xdef\macc@kerna{\the\dimen@\relax}%
1935 \setbox4\hbox{$#1#2\acc@check\@empty$}%
1936 \global\setbox\@ne\hbox to\wd4{}%
1937 \ht\@ne\ht4 \dp\@ne\dp4
1938 \xdef\macc@kernb{\the\wd4\relax}%
1939 \mathaccent\macc@code{\box\@ne\kern\macc@kerna}%
1941 \mathaccent\macc@code{\let\macc@adjust\@empty #1#2\@empty}%
1950 \dimen@\macc@kerna\advance\dimen@\macc@kernb
1955 % The commands \cs{Hat}, \cs{Tilde}, \ldots, are supported as
1956 % synonyms of \cs{hat}, \cs{tilde}, \ldots, for backward
1971 % This error message about math mode is used several times so we make
1972 % an abbreviation for it.
1974 \def\nonmatherr@#1{\@amsmath@err{\protect
1975 #1 allowed only in math mode}\@ehd}
1978 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1979 % \section{Mods, continued fractions, etc.}
1981 % \begin{macro}{\bmod}
1982 % \begin{macro}{\pmod}
1983 % \begin{macro}{\pod}
1984 % \begin{macro}{\mod}
1985 % The commands \cn{bmod}, \cn{pmod}, \cn{pod}, \cn{mod} aren't
1986 % currently robust. [mjd, 1994/09/05]
1988 \renewcommand{\bmod}{\nonscript\mskip-\medmuskip\mkern5mu\mathbin
1989 {\operator@font mod}\penalty900
1990 \mkern5mu\nonscript\mskip-\medmuskip}
1991 \newcommand{\pod}[1]{\allowbreak
1992 \if@display\mkern18mu\else\mkern8mu\fi(#1)}
1993 \renewcommand{\pmod}[1]{\pod{{\operator@font mod}\mkern6mu#1}}
1994 \newcommand{\mod}[1]{\allowbreak\if@display\mkern18mu
1995 \else\mkern12mu\fi{\operator@font mod}\,\,#1}
2002 % \begin{macro}{\cfrac}
2003 % Continued fractions. The optional arg l or r controls horizontal
2004 % placement of the numerators. The |\kern-\nulldelimiterspace|
2005 % is needed in the definition if we want the right-hand sides of the
2006 % fraction rules to line up. The \cs{strut} keeps the numerator of
2007 % a subsidiary cfrac from coming too close to the fraction rule above
2010 \newcommand{\cfrac}[3][c]{{\displaystyle\frac{%
2011 \strut\ifx r#1\hfill\fi#2\ifx l#1\hfill\fi}{#3}}%
2012 \kern-\nulldelimiterspace}
2016 % \begin{macro}{\overset}
2017 % \begin{macro}{\underset}
2018 % \cn{overset} and \cn{underset} put symbols above, respectively
2019 % below, a symbol that is not a \cs{mathop} and therefore does not
2020 % naturally accept limits. \cs{binrel@@} uses information collected
2021 % by \cs{binrel@} to make the resulting construction be of type
2022 % mathrel or mathbin if the base symbol is either of those types.
2024 \newcommand{\overset}[2]{\binrel@{#2}%
2025 \binrel@@{\mathop{\kern\z@#2}\limits^{#1}}}
2029 \newcommand{\underset}[2]{\binrel@{#2}%
2030 \binrel@@{\mathop{\kern\z@#2}\limits_{#1}}}
2035 % \begin{macro}{\sideset}
2036 % \cn{sideset} allows placing `adscript' symbols at the four
2037 % corners of a \cs{mathop}, \emph{in addition to} limits. Left-side
2038 % adscripts go into arg \arg{1}, in the form |_{...}^{...}|, and
2039 % right-side adscripts go into arg \arg{2}.
2041 % As currently written [mjd, 1995/01/21] this is pretty haphazard.
2042 % In order to really make it work properly in full generality we'd
2043 % have to read and measure the top and bottom limits and use
2044 % mathchoice to always get the right mathstyle for each piece,
2047 \newcommand{\sideset}[3]{%
2048 \@mathmeasure\z@\displaystyle{#3}%
2050 % Use a global box assignment here since the depth override is
2051 % implicitly global. Then move the constructed box to a local box
2052 % register (2) to ensure it won't get destroyed during the next two
2053 % mathmeasure statements. This precaution may be more extreme than
2054 % necessary in practice.
2056 \global\setbox\@ne\vbox to\ht\z@{}\dp\@ne\dp\z@
2058 \@mathmeasure4\displaystyle{\copy\tw@#1}%
2059 \@mathmeasure6\displaystyle{#3\nolimits#2}%
2060 \dimen@-\wd6 \advance\dimen@\wd4 \advance\dimen@\wd\z@
2061 \hbox to\dimen@{}\mathop{\kern-\dimen@\box4\box6}%
2066 % \begin{macro}{\smash}
2067 % We add to the \cn{smash} command an optional argument
2068 % denoting the part of the formula to be smashed.
2070 \renewcommand{\smash}[1][tb]{%
2071 \def\mb@t{\ht}\def\mb@b{\dp}\def\mb@tb{\ht\z@\z@\dp}%
2072 \edef\finsm@sh{\csname mb@#1\endcsname\z@\z@ \box\z@}%
2073 \ifmmode \@xp\mathpalette\@xp\mathsm@sh
2074 \else \@xp\makesm@sh
2080 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2081 % \section{Extensible arrows}
2083 % The minus sign used in constructing these arrow fills is smashed so
2084 % that superscripts above the arrows won't be too high. This
2085 % primarily affects the \cn{xleftarrow} and \cn{xrightarrow} arrows.
2088 \mathchardef\std@minus\mathcode`\-\relax
2089 \mathchardef\std@equal\mathcode`\=\relax
2091 % In case some alternative math fonts are loaded later:
2094 \mathchardef\std@minus\mathcode`\-\relax
2095 \mathchardef\std@equal\mathcode`\=\relax
2099 % \begin{macro}{\relbar}
2100 % \begin{macro}{\Relbar}
2102 \ams@def\relbar{\mathrel{\mathpalette\mathsm@sh\std@minus}}
2103 \ams@def\Relbar{\mathrel\std@equal}
2109 \def\arrowfill@#1#2#3#4{%
2110 $\m@th\thickmuskip0mu\medmuskip\thickmuskip\thinmuskip\thickmuskip
2111 \relax#4#1\mkern-7mu%
2112 \cleaders\hbox{$#4\mkern-2mu#2\mkern-2mu$}\hfill
2115 \def\leftarrowfill@{\arrowfill@\leftarrow\relbar\relbar}
2116 \def\rightarrowfill@{\arrowfill@\relbar\relbar\rightarrow}
2117 \def\leftrightarrowfill@{\arrowfill@\leftarrow\relbar\rightarrow}
2118 \def\Leftarrowfill@{\arrowfill@\Leftarrow\Relbar\Relbar}
2119 \def\Rightarrowfill@{\arrowfill@\Relbar\Relbar\Rightarrow}
2120 \def\Leftrightarrowfill@{\arrowfill@\Leftarrow\Relbar\Rightarrow}
2124 \def\overarrow@#1#2#3{\vbox{\ialign{##\crcr#1#2\crcr
2125 \noalign{\nointerlineskip}$\m@th\hfil#2#3\hfil$\crcr}}}
2126 \ams@renewcommand{\overrightarrow}{%
2127 \mathpalette{\overarrow@\rightarrowfill@}}
2128 \ams@renewcommand{\overleftarrow}{%
2129 \mathpalette{\overarrow@\leftarrowfill@}}
2130 \ams@newcommand{\overleftrightarrow}{%
2131 \mathpalette{\overarrow@\leftrightarrowfill@}}
2135 \def\underarrow@#1#2#3{%
2136 \vtop{\ialign{##\crcr$\m@th\hfil#2#3\hfil$\crcr
2137 \noalign{\nointerlineskip\kern1.3\ex@}#1#2\crcr}}}
2138 \ams@newcommand{\underrightarrow}{%
2139 \mathpalette{\underarrow@\rightarrowfill@}}
2140 \ams@newcommand{\underleftarrow}{%
2141 \mathpalette{\underarrow@\leftarrowfill@}}
2142 \ams@newcommand{\underleftrightarrow}{%
2143 \mathpalette{\underarrow@\leftrightarrowfill@}}
2147 %\newcommand{\xrightarrow}[2][]{\ext@arrow 0359\rightarrowfill@{#1}{#2}}
2148 \def\ext@arrow#1#2#3#4#5#6#7{%
2151 % Measure the superscript and subscript.
2153 \setbox\z@\hbox{#5\displaystyle}%
2154 \setbox\tw@\vbox{\m@th
2155 \hbox{$\scriptstyle\mkern#3mu{#6}\mkern#4mu$}%
2156 \hbox{$\scriptstyle\mkern#3mu{#7}\mkern#4mu$}%
2159 \hbox to\wd\tw@{\unhbox\z@}}%
2161 % We don't want to place an empty subscript since that will produce
2162 % too much blank space below the arrow.
2165 \@ifnotempty{#7}{^{\if0#1\else\mkern#1mu\fi
2166 #7\if0#2\else\mkern#2mu\fi}}%
2167 \@ifnotempty{#6}{_{\if0#1\else\mkern#1mu\fi
2168 #6\if0#2\else\mkern#2mu\fi}}}%
2172 % Some extensible arrows to serve as mathrels and taking
2173 % sub/superscripts. These commands are robust because they take an
2174 % optional argument.
2176 \newcommand{\xrightarrow}[2][]{\ext@arrow 0359\rightarrowfill@{#1}{#2}}
2177 \newcommand{\xleftarrow}[2][]{\ext@arrow 3095\leftarrowfill@{#1}{#2}}
2180 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2181 % \section{Array-related environments}
2182 % \subsection{Remarks}
2184 % Because these environments can be nested within the equation
2185 % structures that allow \cn{tag}, there is some cross-influence in
2186 % the internal workings of the \cn{\\} command.
2188 % \subsection{The \env{subarray} environment and \cn{substack} command}
2190 % The \cn{substack} command can be used to set subscripts
2191 % and superscripts that consist of several lines. Usage:
2193 % X_{\substack{a=1\\b=2}}
2196 % \changes{v2.0}{1999/06/17}{Removed environment definitions: Sb, Sp}
2198 % \begin{environment}{subarray}
2199 % The \env{subarray} environment makes a small-size array suitable
2200 % for use in a subscript or superscript. At the moment the supported
2201 % arguments are not the full possibilities of \env{array} but only
2202 % |c| or |l| for centered or left-aligned. And only one column.
2204 \newenvironment{subarray}[1]{%
2206 % Note: The predecessors of \env{subarray} (\env{Sb} and \env{Sp},
2207 % inherited from \amstex/) used \cs{vbox} instead of \cs{vcenter}.
2208 % But when a multiline subscript is placed in \cs{limits} position
2209 % \cs{vcenter} is no worse than \cs{vbox}, and when it is placed
2210 % in the \cs{nolimits} position (e.g., for an integral), \cs{vcenter}
2211 % provides clearly better positioning than \cs{vbox}.
2215 % Use \cs{Let@} to set the proper meaning of the \cn{\\} and \cn{\\*}
2216 % commands. And restore the meaning of \cs{math@cr@@@} to \cs{cr}
2217 % (see above) in case \env{subarray} is used inside one of the more
2218 % complicated alignment macros where the meaning of \cs{math@cr@@@}
2219 % is different. Similarly, call \cs{default@tag} to ensure that a
2220 % line break here doesn't get an equation number!
2222 \Let@ \restore@math@cr \default@tag
2224 % Set the line spacing to be the same as \cs{atop} (when \cs{atop}
2225 % occurs in \cs{textstyle} or smaller), cf \textit{The \tex/book},
2228 \baselineskip\fontdimen10 \scriptfont\tw@
2229 \advance\baselineskip\fontdimen12 \scriptfont\tw@
2230 \lineskip\thr@@\fontdimen8 \scriptfont\thr@@
2231 \lineskiplimit\lineskip
2233 % Start the \cs{vbox} \cs{halign} structure that encloses the
2234 % contents. Notice that we never get \cs{scriptscriptstyle}. That
2235 % would require a \cs{mathchoice} (ugh).
2237 \ialign\bgroup\ifx c#1\hfil\fi
2238 $\m@th\scriptstyle##$\hfil\crcr
2245 % \begin{macro}{\substack}
2246 % The \cn{substack} command is just an abbreviation for the
2247 % most common use of \env{subarray}.
2249 \newcommand{\substack}[1]{\subarray{c}#1\endsubarray}
2253 % \subsection{Matrices}
2255 % \begin{environment}{smallmatrix}
2256 % \env{smallmatrix} is again an alignment, this time in a centered
2257 % box. The opening incantations are basically the same as those in
2258 % \cs{multilimits@}, followed by the alignment itself. A remark:
2259 % the baselineskip (|9\ex@|) used in \amstex/ is too large for
2260 % use in text with the usual baselineskip of $12$ or $13$ points; we
2261 % change it here to |6\ex@| and also adjust the \cs{lineskip}
2262 % and \cs{lineskiplimit} slightly to compensate. (MJD)
2264 \newenvironment{smallmatrix}{\null\,\vcenter\bgroup
2265 \Let@\restore@math@cr\default@tag
2266 \baselineskip6\ex@ \lineskip1.5\ex@ \lineskiplimit\lineskip
2267 \ialign\bgroup\hfil$\m@th\scriptstyle##$\hfil&&\thickspace\hfil
2268 $\m@th\scriptstyle##$\hfil\crcr
2270 \crcr\egroup\egroup\,%
2275 % \begin{environment}{matrix}
2276 % The \env{matrix} environment is just an \env{array} that provides
2277 % up to ten centered columns, so that users don't have to give the
2278 % col-spec argument explicitly---unless they want some of the columns
2279 % noncentered, that is. The maximum number of columns is actually not
2280 % fixed at ten but given by the counter |MatrixCols|, and can
2281 % therefore be increased by changing that counter.
2283 % The extra space of \cn{arraycolsep} that \env{array} adds on each
2284 % side is a waste so we remove it here (perhaps we should instead
2285 % remove it from \env{array} in general, but that's a harder task).
2287 % TODO: Think about re-implementing \cn{matrix} to get rid of the
2288 % \cs{c@MatrixCols} limit and have hard-wired preamble that doesn't
2289 % have to be rebuilt each time.
2291 % We must use \cn{renewenvironment} for \env{matrix} and
2292 % \env{pmatrix} because \latex/ doesn't kill the definitions found in
2293 % \fn{plain.tex}, even though it probably should because of their
2296 \renewenvironment{matrix}{%
2297 \matrix@check\matrix\env@matrix
2299 \endarray \hskip -\arraycolsep
2304 % \begin{macro}{\env@matrix}
2307 \def\env@matrix{\hskip -\arraycolsep
2308 \let\@ifnextchar\new@ifnextchar
2309 \array{*\c@MaxMatrixCols c}}
2313 % \begin{macro}{\c@MaxMatrixCols}
2315 \newcount\c@MaxMatrixCols \c@MaxMatrixCols=10
2319 % \begin{macro}{\matrix@check}
2320 % For various reasons, authors sometimes use the Plain \TeX{} form of
2321 % \cn{matrix} or \cn{pmatrix} in \LaTeX{} documents. If they later
2322 % add an invocation of the \pkg{amsmath} package to their document,
2323 % the Plain \TeX{} syntax would lead to rather unintelligible error
2324 % messages. The \cs{matrix@check} function does some checking to
2325 % forestall that problem.
2327 \def\matrix@check#1{%
2328 \@xp\ifx\csname\@currenvir\endcsname#1%
2329 \else\matrix@error#1%
2331 % This error recovery is not that good but is better than the
2332 % infinite loop that can result from calling \cs{array} without a
2333 % matching \cs{endarray}. (The array setup leaves \cs{par} empty.)
2341 % \begin{macro}{\matrix@error}
2344 \def\matrix@error#1{%
2346 Old form `\string#1' should be \string\begin{\@xp\@gobble\string#1}%
2348 `\string#1{...}' is old Plain-TeX syntax whose use is
2349 ill-advised in LaTeX.%
2356 \renewenvironment{pmatrix}{%
2358 \matrix@check\pmatrix\env@matrix
2362 \newenvironment{bmatrix}{\left[\env@matrix}{\endmatrix\right]}
2363 \newenvironment{Bmatrix}{%
2364 \left\lbrace\env@matrix
2366 \endmatrix\right\rbrace
2368 \newenvironment{vmatrix}{\left\lvert\env@matrix}{\endmatrix\right\rvert}
2369 \newenvironment{Vmatrix}{\left\lVert\env@matrix}{\endmatrix\right\rVert}
2377 \newcommand{\hdotsfor}[1]{%
2378 \ifx[#1\@xp\shdots@for\else\hdots@for\@ne{#1}\fi}
2379 \newmuskip\dotsspace@
2380 \def\shdots@for#1]{\hdots@for{#1}}
2381 \def\hdots@for#1#2{\multicolumn{#2}c%
2382 {\m@th\dotsspace@1.5mu\mkern-#1\dotsspace@
2383 \xleaders\hbox{$\m@th\mkern#1\dotsspace@.\mkern#1\dotsspace@$}%
2385 \mkern-#1\dotsspace@}%
2389 % \begin{environment}{cases}
2390 % The easiest way to produce the \env{cases} environment is to base
2391 % it on the \env{array} environment. We must use
2392 % \cn{renewenvironment} to override the definition of \cn{cases} that
2393 % \latex/ (unwisely) leaves in place from \fn{plain.tex}.
2395 \renewenvironment{cases}{%
2396 \matrix@check\cases\env@cases
2401 \let\@ifnextchar\new@ifnextchar
2403 \def\arraystretch{1.2}%
2404 \array{@{}l@{\quad}l@{}}%
2410 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2411 % \section{Equation sub-numbering}
2414 \newcounter{parentequation}% Counter for ``parent equation''.
2417 % We can't assume \cs{ignorespacesafterend} is defined since it was
2418 % not there in the earliest releases of \latex/ 2e. And we need to
2419 % include the \cs{global} for the same reason.
2421 \@ifundefined{ignorespacesafterend}{%
2422 \def\ignorespacesafterend{\global\@ignoretrue}%
2426 % \begin{environment}{subequations}
2428 \newenvironment{subequations}{%
2430 % Before sending down the `equation' counter to the subordinate
2431 % level, add 1 using standard \cn{refstepcounter}.
2433 \refstepcounter{equation}%
2435 % Define \cn{theparentequation} equivalent to current
2436 % \cn{theequation}. \cn{edef} is necessary to expand the current
2437 % value of the equation counter. This might in rare cases cause
2438 % something to blow up, in which case the user needs to add
2441 \protected@edef\theparentequation{\theequation}%
2442 \setcounter{parentequation}{\value{equation}}%
2444 % And set the equation counter to 0, so that the normal incrementing
2445 % processes in the various equation environments will produce the
2448 \setcounter{equation}{0}%
2449 \def\theequation{\theparentequation\alph{equation}}%
2452 \setcounter{equation}{\value{parentequation}}%
2453 \ignorespacesafterend
2458 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2459 % \section{Equation numbering}
2461 % In the multiline equation environments provided here, the task
2462 % of equation numbering is linked to the task of line breaking
2463 % in the sense that it is the \cn{\\} command that marks where an
2464 % equation number for the current line will be processed and added to
2467 % \begin{macro}{\numberwithin}
2468 % Provide a convenient way to specify that equations should be
2469 % numbered within sections.
2471 \newcommand{\numberwithin}[3][\arabic]{%
2472 \@ifundefined{c@#2}{\@nocounterr{#2}}{%
2473 \@ifundefined{c@#3}{\@nocnterr{#3}}{%
2474 \@addtoreset{#2}{#3}%
2475 \@xp\xdef\csname the#2\endcsname{%
2476 \@xp\@nx\csname the#3\endcsname .\@nx#1{#2}}}}%
2481 % \begin{macro}{\eqref}
2482 % To make references to equation numbers easier, we provide
2483 % \cn{eqref}. We almost don't need \cn{textup}, except that
2484 % \cs{tagform@} doesn't supply the italic correction.
2486 \newcommand{\eqref}[1]{\textup{\tagform@{\ref{#1}}}}
2490 % \subsection{Preliminary macros}
2492 % The following macros implement the \latex/ syntax for the
2493 % \cn{\\} command, i.e. the possibility to add an asterisk to
2494 % inhibit a page break, or an optional argument to denote additional
2495 % vertical space. They are modelled more or less after the
2496 % corresponding macros for \latex/'s \env{eqnarray} and \env{array}
2499 % [We can perhaps use the eqnarray mechanism if we change it so that
2500 % it also uses \cs{openup}.]
2502 % \begin{macro}{\dspbrk@lvl}
2503 % We begin by defining the \cs{dspbrk@lvl} counter. This counter
2504 % records the desirability of a break after the current row, as a
2505 % number between $0$ and $4$. Its default value is $-1$ meaning that
2506 % no explicit \cn{displaybreak} command was given, and the default
2507 % \cs{interdisplaylinepenalty} is to be used.
2509 \newcount\dspbrk@lvl
2514 % \begin{macro}{\interdisplaylinepenalty}
2515 % We set the \cs{interdisplaylinepenalty} to $10000$.
2517 \interdisplaylinepenalty\@M
2521 % \begin{macro}{\allowdisplaybreaks}
2522 % The \cn{allowdisplaybreaks} command. Since this is intended for use
2523 % outside displayed formulas (typically in the preamble), it does not
2524 % need to use \cs{new@ifnextchar}.
2526 \newcommand{\allowdisplaybreaks}[1][4]{%
2527 \interdisplaylinepenalty\getdsp@pen{#1}\relax
2532 % \begin{macro}{\getdsp@pen}
2533 % Modelled after \latex/'s \cs{@getpen}. We use higher numbers
2534 % than would normally be provided by \cs{@lowpenalty},
2535 % \cs{@medpenalty}, and \cs{@highpenalty}, since display
2536 % breaks are almost always less desirable.
2539 \ifcase #1\@M \or 9999 \or 6999 \or 2999 \or \z@\fi
2544 % \begin{macro}{\displaybreak}
2545 % \begin{macro}{\dspbrk@}
2546 % \begin{macro}{\dspbrk@context}
2547 % \begin{macro}{\nogood@displaybreak}
2548 % For breaks in a certain row of a alignment.
2550 \newcommand{\displaybreak}{\new@ifnextchar[\dspbrk@{\dspbrk@[4]}}
2551 \chardef\dspbrk@context=\sixt@@n
2558 \ifcase\dspbrk@context % case 0 --- OK
2559 \global\dspbrk@lvl #1\relax
2560 \or % case 1 --- inside a box
2561 \nogood@displaybreak
2562 \else % other cases --- outside of a display
2563 \@amsmath@err{\Invalid@@\displaybreak}\@eha
2569 % This is the value of \cn{displaybreak} when it occurs inside some
2570 % structure where it will not work.
2572 \def\nogood@displaybreak{%
2573 \@amsmath@err{\protect
2574 \displaybreak\space cannot be applied here}%
2575 {One of the enclosing environments creates an
2576 unbreakable box\MessageBreak
2577 (e.g., split, aligned, gathered, ...).}%
2585 % \begin{macro}{\math@cr}
2586 % The macro \cs{math@cr} ends a row inside one of the equation
2587 % environments, i.e., this is the internal name of the \cn{\\}
2588 % commands in these environments. As usual for this kind of macro
2589 % inside of alignments we insert a special brace into \tex/'s input
2590 % stream. The initial \cs{relax} is needed to trigger entry into the
2591 % \textit{u} template of the current column if the author ended the
2592 % current row with an empty column (i.e., the mathcr was immediately
2593 % preceded by an ampersand).
2595 \def\math@cr{\relax\iffalse{\fi\ifnum0=`}\fi
2597 % The first step is now to check whether an asterisk follows.
2598 % \cs{@eqpen} is used to hold the penalty value to be put on
2599 % the vertical list.
2600 % Then we call up \cs{math@cr@} which performs the next step.
2601 % If an asterisk is read page breaking is inhibited.
2603 \@ifstar{\global\@eqpen\@M\math@cr@}%
2605 % Otherwise we have to check the \cs{dspbrk@lvl} value.
2608 \ifnum\dspbrk@lvl <\z@ \interdisplaylinepenalty
2609 \else -\@getpen\dspbrk@lvl \fi
2614 % \begin{macro}{\math@cr@}
2615 % The purpose of \cs{math@cr@} is to check whether an optional
2616 % argument follows. If not it provides \cs{z@} as default
2619 \def\math@cr@{\new@ifnextchar[\math@cr@@{\math@cr@@[\z@]}}
2623 % \begin{macro}{\math@cr@@}
2624 % \cs{math@cr@@} closes the special brace opened in
2625 % \cs{math@cr}, and calls \cs{math@cr@@@} which is supposed
2626 % the `real' row ending command. The meaning of this macro depends
2627 % on the environment in which it is used.
2629 \def\math@cr@@[#1]{\ifnum0=`{\fi \iffalse}\fi\math@cr@@@
2631 % Finally we put the additional space onto the vertical list.
2633 \noalign{\vskip#1\relax}}
2637 % \begin{macro}{\Let@}
2638 % \cs{Let@} is called by all environments where \cn{\\}
2639 % ends a row of an alignment.
2641 \def\Let@{\let\\\math@cr}
2645 % \begin{macro}{\restore@math@cr}
2646 % We mentioned already that the exact meaning of \cs{math@cr@@@}
2647 % depends on the current environment. Since it is often a simple
2648 % \cs{cr} we provide \cs{restore@math@cr} to reset it.
2650 \def\restore@math@cr{\def\math@cr@@@{\cr}}
2652 % This is also the default case.
2658 % \begin{macro}{\intertext}
2659 % \begin{macro}{\intertext@}
2660 % The \cn{intertext} command is used for inserting text between the
2661 % rows of an alignment. It might better be done as an environment,
2662 % but the \cs{begingroup} from \cn{begin} would cause the
2663 % \cs{noalign} to fail.
2665 \newcommand{\intertext}{\@amsmath@err{\Invalid@@\intertext}\@eha}
2667 % \cs{intertext@} is called by all environments that allow the use of
2668 % the \cn{intertext} command.
2673 % If current mode is not vmode, the most likely reason is that the
2674 % writer forgot the \cn{\\} that is supposed to precede
2675 % \cn{intertext}. All right, then, let's try adding it our ownself.
2676 % But, to be slightly careful: \cn{\\} does a futurelet, and it's
2677 % slightly dangerous to allow a letted token to barge around loose in
2678 % our internal code when it has been let to a conditional token
2679 % like \cs{fi}. So let's interpose something in front of the \cs{fi}
2680 % for the futurelet to take instead. (And careful again: it has to be
2681 % something evanescent, not (e.g.) \cs{relax} which would cause the
2682 % next halign cell to fire up and keep \cs{noalign} from working.)
2684 \ifvmode\else\\\@empty\fi
2686 \penalty\postdisplaypenalty\vskip\belowdisplayskip
2687 \vbox{\normalbaselines
2689 % We need to do something extra if the outside environment is a list
2690 % environment. I don't see offhand an elegant way to test ``are we
2691 % inside any list environment'' that is both easy and reliable (for
2692 % example, checking for zero \cs{@totalleftmargin} wouldn't catch the
2693 % case where \cs{@totalleftmargin} is zero but \cs{linewidth} is less
2694 % than \cs{columnwidth}), so it seems to me checking \cs{linewidth}
2695 % is the best practical solution.
2696 % \changes{v2.15c}{2016/05/23}{\cs{ignorespaces} at the start of the argument}
2698 \ifdim\linewidth=\columnwidth
2699 \else \parshape\@ne \@totalleftmargin \linewidth
2701 \noindent\ignorespaces##1\par}%
2702 \penalty\predisplaypenalty\vskip\abovedisplayskip%
2710 % \subsection{Implementing tags and labels}
2712 % In this section we describe some of the macros needed to make the
2713 % \cn{tag} command work in various places. We start by defining a
2714 % help text to be used when a \cn{tag} command is used somewhere
2715 % it should not appear.
2717 % \begin{macro}{\tag@help}
2718 % This is the default error help text provided when \cn{tag}
2719 % generates an error message.
2720 % Note that \cs{newhelp} generates a control sequence name
2721 % from the string given as its argument so that a leading
2722 % backslash is provided automatically.
2725 {tag cannot be used at this point.\space
2726 If you don't understand why^^Jyou should consult
2727 the documentation.^^JBut don't worry: just continue, and I'll
2728 forget what happened.}
2732 % \begin{macro}{\gobble@tag}
2733 % This macro is to be used when \cn{tag} should silently
2734 % skip its argument.
2735 % It is made to handle the \qc{\*}-form of \cn{tag} as well.
2737 \def\gobble@tag{\@ifstar\@gobble\@gobble}
2741 % \begin{macro}{\invalid@tag}
2742 % \cs{invalid@tag} is a macro that should be used whenever
2743 % \cn{tag} appears in an illegal place.
2744 % It sets up \cs{tag@help} (as defined above) as help message,
2745 % prints its argument as error message, and skips \cn{tag}'s
2748 \def\invalid@tag#1{\@amsmath@err{#1}{\the\tag@help}\gobble@tag}
2752 % \begin{macro}{\dft@tag}
2753 % \begin{macro}{\default@tag}
2754 % \cs{dft@tag} provides a convenient way to disallow the
2755 % use of \cn{tag} at certain points.
2756 % One simply has to write
2760 % and the \cn{tag} command will produce an error message,
2761 % with a suitable error help text, and discard its argument.
2763 \def\dft@tag{\invalid@tag{\string\tag\space not allowed here}}
2765 % Since this is used several times we provide an abbreviation for
2768 \def\default@tag{\let\tag\dft@tag}
2770 % Since this is also the default, i.e.\ the \cn{tag} command
2771 % should not be used except in special places, we issue a
2772 % \cs{default@tag} command.
2779 % Now that we have taken care of the case that \cn{tag} is not
2780 % allowed we will provide some macros to process tags appropriately.
2781 % As the user documentation states, a \cn{tag} command (without
2782 % the asterisk typesets its argument according to the document
2783 % styles' conventions, whereas a \cn{tag*} command typesets its
2784 % argument exactly as given. We define therefore the following
2787 % \begin{macro}{\maketag@@}
2788 % \begin{macro}{\maketag@@@}
2789 % \begin{macro}{\tagform@}
2790 % \cn{tag} is supposed to call \cs{maketag@@} which checks
2791 % whether an asterisk follows. If this is the case it calls up
2792 % \cs{maketag@@@} which sets its argument `as is'. Otherwise
2793 % \cs{tagform@} is called to do the job. (This macro is to be
2794 % defined appropriately by the document style.)
2796 \def\maketag@@{\@ifstar\maketag@@@\tagform@}
2798 % We define \cs{maketag@@@} to use the normal font of the document
2799 % text (since this is the usual practice for numbering of document
2800 % elements) and to put a box around the tag. Furthermore we use
2801 % \cs{m@th} for exceptional cases where the tag involves a
2802 % superscript or some such math. (Probably from an explicit use of
2803 % \cs{tag*} rather than from the automatic numbering.)
2805 \def\maketag@@@#1{\hbox{\m@th\normalfont#1}}
2807 % We use the following default definition for \cs{tagform@}
2808 % that puts only parentheses around the tag.
2810 \def\tagform@#1{\maketag@@@{(\ignorespaces#1\unskip\@@italiccorr)}}
2816 % We need to insinuate \cs{tagform@} into \cs{@eqnnum} in case
2817 % \env{eqnarray} is used (probably in a document that was originally
2818 % written without use of the \pkg{amsmath} package).
2821 \def\@eqnnum{\hbox to1sp{}\rlap{\normalfont\normalcolor
2822 \hskip -\displaywidth\tagform@\theequation}}
2824 \def\@eqnnum{{\normalfont\normalcolor \tagform@\theequation}}
2828 % \begin{macro}{\thetag}
2829 % Sometimes one needs to set a literal tag according to the rules of
2830 % the document style. To achieve this we provide the \cn{thetag}
2831 % command. It typesets its argument by calling \cs{tagform@} on
2834 \newcommand{\thetag}{\leavevmode\tagform@}
2838 % \begin{macro}{\df@tag}
2839 % \begin{macro}{\make@df@tag}
2840 % \begin{macro}{\make@df@tag@@}
2841 % \begin{macro}{\make@df@tag@@@}
2842 % Sometimes it is necessary for a \cn{tag} command to store a tag
2843 % in a safe place and to process it later, e.g., for a tag in a row
2844 % of an alignment where the tag can only be typeset when the
2845 % \cn{\\} at the end of the row was seen. Such a tag is stored in
2846 % the macro \cs{df@tag} (for `deferred tag'). For this purpose we
2847 % provide the \cs{make@df@tag} macro. It is built very similar to
2848 % the \cs{maketag@@} macro above.
2851 \def\make@df@tag{\@ifstar\make@df@tag@@\make@df@tag@@@}
2853 % \cs{make@df@tag} sets \cs{@currentlabel} and defines
2854 % \cs{df@tag} appropriately.
2856 % To simplify the task of tracking \cs{tag} and \cs{label}
2857 % commands inside math display environments, we defer \cs{label}
2858 % commands until the tag is typeset, similar to the way that
2859 % \cs{tag}s themselves are deferred. This allows arbitrary
2860 % placement of \cs{label} and \cs{tag} commands and also means we
2861 % only increment the \cs{equation} counter when we really need to,
2862 % thus avoiding the \cs{setb@ck} nonsense that used to be required.
2865 \def\make@df@tag@@#1{%
2866 \gdef\df@tag{\maketag@@@{#1}\def\@currentlabel{#1}}}
2868 % Autogenerated number:
2870 \def\make@df@tag@@@#1{\gdef\df@tag{\tagform@{#1}%
2871 \toks@\@xp{\p@equation{#1}}\edef\@currentlabel{\the\toks@}}}
2878 % \begin{macro}{\ltx@label}
2879 % \begin{macro}{\label@in@display}
2880 % \begin{macro}{\df@label}
2881 % Next, we store the default definition of \cs{label} in
2882 % \cs{ltx@label} and then define a new version of \cs{label} for use
2883 % in math display environments. \cs{label@in@display} merely issues a
2884 % warning message if there is already a pending label (which will be
2885 % discarded) and then stores the label in \cs{df@label}.
2887 \let\ltx@label\label
2889 \def\label@in@display{%
2890 \ifx\df@label\@empty\else
2891 \@amsmath@err{Multiple \string\label's:
2892 label '\df@label' will be lost}\@eha
2897 % In case there is an enumerate inside a minipage inside an equation,
2898 % we need to reset \cn{label} to its normal value:
2900 \toks@\@xp{\@arrayparboxrestore \let\label\ltx@label}%
2901 \edef\@arrayboxrestore{\the\toks@}
2905 \let\df@label\@empty
2911 % \begin{macro}{\make@display@tag}
2912 % Now we define a macro to process \cs{tag} and \cs{label} commands
2913 % in various display environments. If the |@eqnsw| switch is set,
2914 % then we should supply an equation number; otherwise, if the
2915 % |@tag| switch is set, we should use the tag stored in
2916 % \cs{df@tag}. Finally, we process any pending \cs{label}s.
2918 % TODO: Arguably, \cs{make@display@tag} should issue a warning
2919 % message if there is a \cs{label} but neither a tag nor an
2920 % equation number. Also, it would probably be worthwhile to
2921 % explore whether \cs{iftag@} could be done away with and replaced
2922 % by checks to see if \cs{df@tag} is empty or not.
2924 \def\make@display@tag{%
2925 \if@eqnsw \incr@eqnum \print@eqnum
2926 \else \iftag@ \df@tag \global\let\df@tag\@empty \fi
2929 % Need to check the \cs{ifmeasuring@} flag otherwise the \cs{write}
2930 % node from \cn{label} might be discarded in a temp box and clearing
2931 % \cs{df@label} will keep it from being reiterated on the real
2936 \ifx\df@label\@empty
2938 \@xp\ltx@label\@xp{\df@label}%
2939 \global\let\df@label\@empty
2946 % Now we define the special versions of \cn{tag} used within the
2947 % \env{align} environments.
2949 % \begin{macro}{\tag@in@align}
2950 % The \cn{tag} command may only appear once in a row of
2951 % an alignment. Therefore we first check the switch |tag@|
2952 % that is set to false at the begin of every row.
2953 % If this switch is true a \cn{tag} was already given in this
2954 % row and we define \cs{next@} to expand to a call to
2960 \DN@{\invalid@tag{Multiple \string\tag}}%
2963 % Otherwise we set the |tag@| switch. But there is more to
2964 % be done: we must also prevent the automatic generation of a
2965 % tag. Therefore we also reset the |@eqnsw|.
2969 % Changed to \cs{nonumber}, since that seems to be all that's
2970 % required.---dmj, 1994/12/21
2974 % Within a row of an \env{align} environment the \cn{tag}
2975 % command must not typeset the tag immediately since its
2976 % position can be determined only later.
2977 % Therefore we use the \cs{make@df@tag} macro defined
2979 % Finally we call \cs{next@} to process the argument
2982 \let\next@\make@df@tag
2989 % \begin{macro}{\raisetag}
2990 % Usage: \cn{raisetag} \meta{dimen}
2992 % This will modify the vertical placement of the tag of the current
2993 % equation by \meta{dimen}. Note that according to the current uses
2994 % of \cs{raise@tag} in e.g., \cs{place@tag@gather}, no adjustment
2995 % occurs if the tag falls in its normal position; i.e., \cn{raisetag}
2996 % has no effect unless the tag has already been shifted off-line.
2999 \newcommand{\raisetag}[1]{\skip@#1\relax
3000 \xdef\raise@tag{\vskip\iftagsleft@\else-\fi\the\skip@\relax}%
3003 % \cn{raise@tag} will be reemptied at the beginning of each equation,
3004 % which might occur at a |\begin{xxx}| or \cn{\\}.
3006 \let\raise@tag\@empty
3010 % \begin{macro}{\notag}
3011 % For consistency we provide \cn{notag}, equivalent to
3012 % \cn{nonumber}. The alternative would have been to rename
3013 % \cn{tag} as \cn{number} to go along with \cn{nonumber},
3014 % but of course \cs{number} is a \tex/ primitive that should not
3017 \newcommand{\notag}{\nonumber}
3021 % \begin{macro}{\nonumber}
3022 % Need to add some additional code to \cn{nonumber} to deal with some
3023 % complications related to nested environments.
3025 \renewcommand{\nonumber}{%
3027 \ifx\incr@eqnum\@empty \addtocounter{equation}\m@ne \fi
3029 \let\print@eqnum\@empty \let\incr@eqnum\@empty
3035 \def\print@eqnum{\tagform@\theequation}
3036 \def\incr@eqnum{\refstepcounter{equation}\let\incr@eqnum\@empty}
3040 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3041 % \section{Multiline equation environments}
3043 % \subsection{Remarks}
3045 % In late 1994 David M. Jones did a thorough overhaul of these
3046 % environments so that the number placement and a few other aspects
3047 % are substantially improved over the original versions that were
3048 % ported essentially unchanged from \fn{amstex.tex} in 1989. Most of
3049 % the commentary in this section is DMJ's, and comments of any
3050 % significance that I added are marked by my initials and date
3051 % [mjd, 1995/01/11].
3053 % \subsection{Preliminaries}
3055 % \begin{macro}{\ifinalign@}
3056 % \begin{macro}{\ifingather@}
3057 % We define two switches that are set to true in certain
3058 % alignments: |inalign@| and |ingather@| inside of
3059 % the \env{align} and \env{gather} environments.
3060 % These switches are needed to control certain actions that
3061 % depend on the surrounding conditions, more specifically:
3062 % on the setting already done by the surrounding environments.
3068 % Removed the \cs{ifinany@} test [mjd,1999/06/28] since it was mainly
3069 % used for the purpose now handled by \cs{spread@equation}.
3070 % \changes{v1.2g}{1999/06/28}{Removed ifinany@}
3075 % \begin{macro}{\@arrayparboxrestore}
3076 % Here we must reset a few additional parameters.
3078 \@xp\def\@xp\@arrayparboxrestore\@xp{\@arrayparboxrestore
3079 \ingather@false\inalign@false \default@tag
3080 \let\spread@equation\@spread@equation
3081 \let\reset@equation\@empty
3082 \def\print@eqnum{\tagform@\theequation}%
3083 \def\incr@eqnum{\refstepcounter{equation}\let\incr@eqnum\@empty}%
3088 % \begin{macro}{\iftag@}
3089 % The switch |tag@| is set to false at the beginning of every
3090 % row and set to true by a \cn{tag} command.
3091 % This allows us to check whether there is more than one tag on
3098 % \begin{macro}{\ifst@rred}
3099 % The switch |st@rred| is set to true by all starred
3101 % and set to false by the unstarred versions.
3107 % \begin{macro}{\ifmeasuring@}
3108 % All display environments get typeset twice---once during a
3109 % ``measuring'' phase and then again during a ``production'' phase;
3110 % \cs{ifmeasuring@} will be used to determine which case we're in,
3111 % so we can take appropriate action.
3118 % \begin{macro}{\ifshifttag@}
3119 % \cs{ifshifttag@} is used by \env{gather} to communicate between
3120 % \cs{calc@shift@gather} and \cs{place@tag@gather} whether an
3121 % equation tag should be shifted to a separate line. It's also
3122 % used by \env{multline}.
3128 % \begin{macro}{\row@}
3134 % \begin{macro}{\column@}
3135 % The counter \cs{column@} is used by the alignment macros to
3136 % keep track of the current column.
3143 % \begin{macro}{\column@plus}
3144 % \cs{\column@plus} is a useful abbreviation.
3147 \global\advance\column@\@ne
3152 % \begin{macro}{\maxfields@}
3154 \newcount\maxfields@
3158 % \begin{macro}{\add@amp}
3159 % \begin{macro}{\add@amps}
3161 \def\add@amp#1{\if m#1&\@xp\add@amp\fi}
3164 \count@#1\advance\count@-\column@
3165 \edef\@tempa{\endgroup
3166 \@xp\add@amp\romannumeral\number\count@ 000q}%
3173 % \begin{macro}{\andhelp@}
3174 % The help text stored in \cs{andhelp@} is used for errors
3175 % generated by too many \qc{\&} characters in a row.
3178 {An extra & here is so disastrous that you should probably exit^^J
3183 % \begin{macro}{\eqnshift@}
3184 % \cs{eqnshift@} is used by \env{align} and \env{gather} as the
3185 % indentation of the lines of the environment from the left margin.
3191 % \begin{macro}{\alignsep@}
3197 % \begin{macro}{\tagshift@}
3203 % \begin{macro}{\mintagsep}
3204 % \cs{mintagsep} is the minimum allowable separation between an
3205 % equation and its tag. We set it to half a quad in
3206 % \cs{textfont}2, which is \tex/'s built-in value.
3208 \newcommand{\mintagsep}{.5\fontdimen6\textfont\tw@}
3212 % \begin{macro}{\minalignsep}
3213 % This should probably be a skip register [mjd,1999/06/18]
3215 \newcommand{\minalignsep}{10pt}
3219 % \begin{macro}{\tagwidth@}
3225 % \begin{macro}{\totwidth@}
3231 % \begin{macro}{\lineht@}
3232 % The dimen register \cs{lineht@} is used to keep track of the
3233 % height (or depth, if tags are on the right) of a row in an
3240 % \begin{macro}{\tag@width}
3241 % \begin{macro}{\savetaglength@}
3242 % \begin{macro}{\shift@tag}
3243 % \begin{macro}{\tag@shifts}
3246 \ifcase\@xp#1\tag@lengths\fi
3249 \def\savetaglength@{%
3252 \xdef\tag@lengths{\tag@lengths\or \the\wdz@}%
3257 \ifcase\@xp#1\tag@shifts\fi\relax
3260 \let\tag@shifts\@empty
3267 % \begin{macro}{\saveshift@}
3272 \xdef\tag@shifts{\or#1\tag@shifts}%
3278 % \begin{macro}{\spread@equation}
3279 % This does the line-spacing adjustment that is normally wanted for
3280 % displayed equations. We also call \cs{reset@strutbox@} here because
3281 % otherwise a preceding font size change might leave \cs{strutbox@}
3282 % with wrong contents. This is a less-than-ideal solution but
3283 % probably good enough for now, until the situation can be
3286 \def\spread@equation{\reset@strutbox@
3287 \openup\jot \let\spread@equation\@empty}
3288 \let\@spread@equation\spread@equation
3292 % \begin{macro}{\displ@y}
3293 % \begin{macro}{\displ@y@}
3294 % \begin{macro}{\@display@init}
3295 % \cs{displ@y} is from \fn{plain.tex}, with
3296 % \cs{interdisplaylinepenalty} changed to \cs{@eqpen}. Also we
3297 % transplanted most of its internal organs to \cs{@display@init} to
3298 % support \cs{displ@y@} and other possibilities. Don't try to make
3299 % sense of these naming conventions! They are a narrowly calculated
3300 % mishmash of Knuth/Spivak/Lamport/Mittelbach precedents. The reason
3301 % for not cleaning them up and forcing all names to a consistent
3302 % scheme is that then in principle we'd have to do it everywhere else
3303 % too. And we programmers are paranoid about the side effects of name
3306 \def\displ@y{\@display@init{}}
3307 \def\@display@init#1{%
3308 \global\dt@ptrue \spread@equation
3314 \vskip-\lineskiplimit
3315 \vskip\normallineskiplimit
3317 \penalty\@eqpen \global\dspbrk@lvl\m@ne
3323 % \cs{displ@y@} is nearly the same; it additionally sets the |tag@|
3324 % switch and the \cs{column@} and \cs{dspbrk@lvl} counters to their
3325 % default values. The argument is normally a bit of code to empty out
3326 % \cs{raise@tag}, but in \env{multline} we don't want that to happen
3329 \def\displ@y@{\@display@init{%
3330 \global\column@\z@ \global\dspbrk@lvl\m@ne
3331 \global\tag@false \global\let\raise@tag\@empty
3338 % \begin{macro}{\black@}
3339 % This macro is made to produce an overfull box message and
3340 % possibly (depending on the value of \cs{overfullrule})
3341 % a rule in the margin if the total width of an alignment
3342 % is larger than the value of \cs{displaywidth}.
3346 \ifdim#1>\displaywidth
3349 \vskip-\ht\strutbox@
3350 \vskip-\dp\strutbox@
3351 \vbox{\noindent\hbox to#1{\strut@\hfill}}%
3359 % \begin{macro}{\savecounters@}
3360 % \begin{macro}{\restorecounters@}
3361 % These are used during the measuring phase of the various display
3362 % math environments to save and restore the values of all \latex/
3363 % counters. We make these local to a group, so nested environments
3366 % Changed \cn{stepcounter} to |\csname c@...\endcsname| to avoid
3367 % overhead of ifundefined test [mjd, 1995/01/20].
3369 \def\savecounters@{%
3372 \global\csname c@##1\endcsname\the\csname c@##1\endcsname}%
3375 \let\@nx\restorecounters@\@nx\@empty
3378 \let\restorecounters@\@gtempa
3381 \let\restorecounters@\@empty
3386 % \begin{macro}{\savealignstate@}
3387 % \begin{macro}{\restorealignstate@}
3388 % These are used to save the values of various parameters that are
3389 % shared by \env{align} and \env{gather} when the former is used
3390 % inside the latter.
3392 \def\savealignstate@{%
3396 \global\totwidth@\the\totwidth@
3397 \global\row@\the\row@
3398 \gdef\@nx\tag@lengths{\tag@lengths}%
3399 \let\@nx\restorealignstate@\@nx\@empty
3402 \let\restorealignstate@\@gtempa
3405 \let\restorealignstate@\@empty
3410 % \begin{macro}{\savecolumn@}
3411 % \begin{macro}{\restorecolumn@}
3415 \edef\restorecolumn@{%
3416 \global\column@\number\column@
3417 \let\@nx\restorecolumn@\@nx\@empty
3420 \let\restorecolumn@\@empty
3425 % \subsection{Scanning the environment's body}
3427 % Several of the math alignment macros must scan their body twice:
3428 % once to determine how wide the columns are and then to actually
3429 % typeset them. This means that we must collect all text in this body
3430 % before calling the environment macros.
3432 % \begin{macro}{\@envbody}
3433 % We start by defining a token register to contain the body.
3439 % \begin{macro}{\addto@envbody}
3440 % Then we define a macro to add something (i.e.\ its argument) to the
3441 % token register \cs{@envbody}.
3443 \def\addto@envbody#1{\global\@envbody\@xp{\the\@envbody#1}}
3447 % \begin{macro}{\collect@body}
3448 % The macro \cs{collect@body} starts the scan for the |\end{...}|
3449 % command of the current environment. It takes a macro name as
3450 % argument. This macro is supposed to take the whole body of the
3451 % environment as its argument. For example, |\begin{align}| would
3452 % call |\collect@body\@align| if |@align#1{...}| is the macro that
3453 % sets the alignment with body \arg{1}.
3456 \def\collect@body#1{%
3457 \@envbody{\@xp#1\@xp{\the\@envbody}}%
3458 \edef\process@envbody{\the\@envbody\@nx\end{\@currenvir}}%
3459 \@envbody\@emptytoks \def\begin@stack{b}%
3462 % If we simply called \cs{collect@@body} directly,
3463 % the error message for a \cn{par} token (usually from a blank line)
3466 % ! Paragraph ended before \collect@@body was complete.
3468 % But we use a little finesse to get a more intelligible error
3471 % ! Paragraph ended before \multline* was complete.
3473 % In order to avoid using up csnames unnecessarily we use the actual
3474 % environment name as the name of the temporary function that is
3475 % \cs{let} to \cs{collect@@body}; but then in order to preserve the
3476 % theoretical possibility of nesting for environments that use
3477 % \cs{collect@body} (not currently required by any \pkg{amsmath}
3478 % environment [mjd,1999/06/23]), we do the \cs{let} inside a group.
3481 \@xp\let\csname\@currenvir\endcsname\collect@@body
3483 % This small twist eliminates the need for \cs{expandafter}'s in
3484 % \cs{collect@@body}.
3486 \edef\process@envbody{\@xp\@nx\csname\@currenvir\endcsname}%
3492 % \begin{macro}{\push@begins}
3493 % When adding a piece of the current environment's contents to
3494 % \cs{@envbody}, we scan it to check for additional \cn{begin}
3495 % tokens, and add a `b' to the stack for any that we find.
3497 \def\push@begins#1\begin#2{%
3498 \ifx\end#2\else b\@xp\push@begins\fi
3503 % \begin{macro}{\collect@@body}
3504 % \cs{collect@@body} takes two arguments: the first will consist of
3505 % all text up to the next \cn{end} command, the second will be the
3506 % \cn{end} command's argument. If there are any extra \cn{begin}
3507 % commands in the body text, a marker is pushed onto a stack by the
3508 % \cs{push@begins} function. Empty state for this stack means that we
3509 % have reached the \cn{end} that matches our original \cn{begin}.
3510 % Otherwise we need to include the \cn{end} and its argument in the
3511 % material that we are adding to our environment body accumulator.
3514 % In a former implementation, the error messages resulting from a
3515 % typo in the environment name were unsatisfactory, because it was
3516 % matching of the environment name that was used to determine the end
3517 % of our environment body, instead of counting begin-end pairs.
3518 % Thanks to Lars Hellstr\"{o}m for a suggestion that led to this
3519 % improvement. [mjd,1999/06/23]
3522 \def\collect@@body#1\end#2{%
3523 \edef\begin@stack{\push@begins#1\begin\end \@xp\@gobble\begin@stack}%
3524 \ifx\@empty\begin@stack
3529 \addto@envbody{#1\end{#2}}%
3531 \process@envbody % A little tricky! Note the grouping
3537 % \subsection{Simple aligning environments}
3539 % \begin{macro}{\math@cr@@@aligned}
3540 % From tabskip we get an extra space of minalignsep after every
3541 % second column; but when this falls at the right edge of the whole
3542 % aligned structure, we need to cancel that space.
3544 \def\math@cr@@@aligned{%
3545 \ifodd\column@ \let\next@\@empty
3546 \else \def\next@{&\kern-\alignsep@}%
3553 % \begin{macro}{\start@aligned}
3554 % The \env{aligned} and \env{alignedat} environments are identical
3555 % except that the latter takes a mandatory argument to specify the
3556 % number of align structures, while the former allows any number of
3557 % align structures automatically (the use of \env{alignedat} is
3558 % deprecated). So, they will be defined in terms of
3559 % \cs{start@aligned}, which will take two arguments. The first
3560 % argument specifies the placement of the environments; it is
3561 % either |c|, |t|, or |b|. The second is the number of align
3562 % structures; a value of~$-1$ means that an arbitrary number are
3565 \newcommand{\start@aligned}[2]{%
3567 \nonmatherr@{\begin{\@currenvir}}%
3569 \savecolumn@ % Assumption: called inside a group
3571 % The \cs{null} here is to keep the \cs{,} glue from causing the
3572 % invocation of the clause in \tex/'s built-in tag placement
3573 % algorithm that can cause an equation to be shifted all the way over
3577 \if #1t\vtop \else \if#1b \vbox \else \vcenter \fi \fi \bgroup
3579 \ifnum\maxfields@>\m@ne
3580 \multiply\maxfields@\tw@
3582 % Introduced new \cs{math@cr@@@} so we can provide standard error
3583 % message for too many \qc{\&}'s in \env{alignedat}.
3585 \let\math@cr@@@\math@cr@@@alignedat
3588 \let\math@cr@@@\math@cr@@@aligned
3589 \alignsep@\minalignsep
3592 % Reset the meaning of \cn{\\}.
3594 \Let@ \chardef\dspbrk@context\@ne
3596 % Restore the default definition of \cn{tag} (error message), in
3597 % case \env{aligned} is used inside, e.g., a \env{gather}
3598 % environment that accepts \cn{tag}.
3601 \spread@equation % no-op if already called
3603 % Finally we start the alignment itself. For \env{aligned} we add
3604 % \cs{minalignsep} after every second column to mimic the
3605 % behavior of \env{align}. For \env{alignedat} the user has to
3606 % specify interalign space explicitly.
3613 $\m@th\displaystyle{##}$%
3616 $\m@th\displaystyle{{}##}$%
3624 % \begin{macro}{\math@cr@@@alignedat}
3625 % \cs{math@cr@@@alignedat} checks to make sure the user hasn't put in
3626 % too many \qc{\&}s in \env{alignedat}. Since \env{alignedat}
3627 % doesn't use \cs{displ@y@}, we also reset \cs{column@} here. Note
3628 % than in \env{aligned}, \cs{column@} will increase without bound,
3629 % since it never gets reset, but this is harmless.
3631 \def\math@cr@@@alignedat{%
3632 \ifnum\column@>\maxfields@
3635 \@amsmath@err{Extra & on this line}%
3636 {\the\andhelp@}% "An extra & here is disastrous"
3645 % \begin{macro}{\alignsafe@testopt}
3646 % Testing for an optional argument can be really, really tricky in
3647 % certain complicated contexts. This we discovered by getting some
3648 % bug reports for uses of \env{aligned}. So here is a safer
3649 % form of \latex/'s \cs{@testopt} function.
3651 \def\alignsafe@testopt#1#2{%
3652 \relax\iffalse{\fi\ifnum`}=0\fi
3654 {\let\@let@token\relax \ifnum`{=\z@\fi\iffalse}\fi#1}%
3655 {\let\@let@token\relax \ifnum`{=\z@\fi\iffalse}\fi#1[#2]}%
3660 % \begin{environment}{aligned}
3661 % The \env{aligned} environment takes an optional argument that
3662 % indicates its vertical position in relation to surrounding
3663 % material: |t|, |c|, or |b| for top, center, or bottom.
3665 \newenvironment{aligned}{%
3666 \let\@testopt\alignsafe@testopt
3673 \newcommand{\aligned@a}[1][c]{\start@aligned{#1}\m@ne}
3677 % \begin{environment}{alignedat}
3678 % To get a top or bottom positioned \env{alignedat} structure, you
3679 % would write something like
3681 % \begin{alignedat}[t]{3}
3685 \newenvironment{alignedat}{%
3686 \let\@testopt\alignsafe@testopt
3691 \newcommand{\alignedat@a}[1][c]{\start@aligned{#1}}
3695 % \begin{environment}{gathered}
3696 % The \env{gathered} environment is for several lines that are
3697 % centered independently.
3699 \newenvironment{gathered}[1][c]{%
3701 \nonmatherr@{\begin{gathered}}%
3704 \if #1t\vtop \else \if#1b\vbox \else \vcenter \fi\fi \bgroup
3705 \Let@ \chardef\dspbrk@context\@ne \restore@math@cr
3708 \hfil\strut@$\m@th\displaystyle##$\hfil
3717 % \subsection{The \env{gather} environment}
3719 % \begin{macro}{\start@gather}
3721 \def\start@gather#1{%
3724 \DN@{\@namedef{end\@currenvir}{}\@gobble}%
3728 \ifst@rred \else \global\@eqnswtrue \fi
3736 % \begin{environment}{gather}
3737 % \begin{environment}{gather*}
3739 \newenvironment{gather}{%
3740 \start@gather\st@rredfalse
3742 \math@cr \black@\totwidth@ \egroup
3743 $$\ignorespacesafterend
3746 \newenvironment{gather*}{%
3747 \start@gather\st@rredtrue
3755 % \begin{macro}{\gather@}
3758 \ingather@true \let\split\insplit@
3759 \let\tag\tag@in@align \let\label\label@in@display
3760 \chardef\dspbrk@context\z@
3761 \intertext@ \displ@y@ \Let@
3762 \let\math@cr@@@\math@cr@@@gather
3764 \global\shifttag@false
3767 \halign to\displaywidth\bgroup
3769 \setboxz@h{$\m@th\displaystyle{##}$}%
3773 &\setboxz@h{\strut@{##}}%
3775 \tabskip \iftagsleft@ \gdisplaywidth@ \else \z@skip \span\fi
3782 % \begin{macro}{\gmeasure@}
3788 \global\let\tag@lengths\@empty
3791 \everycr{\noalign{\global\tag@false
3792 \global\let\raise@tag\@empty \global\column@\z@}}%
3795 \setboxz@h{$\m@th\displaystyle{##}$}%
3796 \ifdim\wdz@>\totwidth@
3797 \global\totwidth@\wdz@
3799 &\setboxz@h{\strut@{##}}%
3808 \global\advance\totwidth@\@mathmargin
3811 \ifdim\totwidth@>\displaywidth
3812 \global\let\gdisplaywidth@\totwidth@
3814 \global\let\gdisplaywidth@\displaywidth
3822 % \begin{macro}{\math@cr@@@gather}
3823 % Modified \cs{math@cr@@@gather} so that it always puts in the
3824 % final field, which needs to be done under the new method for
3825 % determining tag placement. This is probably more efficient
3829 \def\math@cr@@@gather{%
3830 \ifst@rred\nonumber\fi
3833 \ifst@rred\else\global\@eqnswtrue\fi
3835 % We advance \cs{row@} here, rather than at the beginning of the
3836 % preamble, because otherwise the \env{split} environment will
3837 % cause \cs{row@} to be advanced twice instead of once.
3839 \global\advance\row@\@ne
3845 % \begin{macro}{\calc@shift@gather}
3846 % \cs{calc@shift@gather} has must make two decisions: (1) whether the
3847 % equation tag for the current line should be put on a separate
3848 % line and (2) what the distance between the equation and the
3849 % equation tag should be. We implement \tex/'s built-in
3850 % tag-placement as well as possible, with one improvement: the
3851 % minimum separation between tag and equation is now a
3852 % user-settable parameter.
3854 % [1995/01/17] Added a check to make sure that the width of the tag
3855 % on the current line is $>0$ before testing to see if tagwidth +
3856 % linewidth + mintagsep $>$ displaywidth. Since an imbedded align
3857 % shows up as line with width \cn{displaywidth}, and even lines
3858 % without a tag get processed as if an empty tag were present, the
3859 % result was that the empty tag assigned to the line containing the
3860 % align was being shifted downwards, creating extra space after the
3863 \def\calc@shift@gather{%
3864 \dimen@\mintagsep\relax
3865 \tagwidth@\tag@width\row@\relax
3867 % If we're in \opt{fleqn} mode, there is no flexibility about
3868 % placement of the equation, so all we can do is see if there's
3869 % room for the tag in the given margin.
3872 \global\eqnshift@\@mathmargin
3873 \ifdim\tagwidth@>\z@
3874 \advance\dimen@\tagwidth@
3876 \ifdim\dimen@>\@mathmargin
3877 \global\shifttag@true
3880 \advance\dimen@\@mathmargin
3881 \advance\dimen@\wdz@
3882 \ifdim\dimen@>\displaywidth
3883 \global\shifttag@true
3888 \global\eqnshift@\displaywidth
3889 \global\advance\eqnshift@-\wdz@
3890 \ifdim\tagwidth@>\z@
3891 \multiply\dimen@\tw@
3892 \advance\dimen@\wdz@
3893 \advance\dimen@\tagwidth@
3894 \ifdim\dimen@>\displaywidth
3895 \global\shifttag@true
3897 \ifdim\eqnshift@<4\tagwidth@
3898 \global\advance\eqnshift@-\tagwidth@
3902 \global\divide\eqnshift@\tw@
3904 \global\eqnshift@-\eqnshift@
3905 \global\advance\eqnshift@\displaywidth
3906 \global\advance\eqnshift@-\wdz@
3908 \ifdim\eqnshift@<\z@
3909 \global\eqnshift@\z@
3916 % \begin{macro}{\place@tag@gather}
3917 % \begin{macro}{\set@gather@field}
3919 \def\place@tag@gather{%
3921 \kern-\gdisplaywidth@
3929 \global\shifttag@false
3934 \ifdim\totwidth@>\displaywidth
3936 \advance\dimen@-\displaywidth
3948 \global\shifttag@false
3955 \def\set@gather@field{%
3957 \global\lineht@\ht\z@
3959 \global\lineht@\dp\z@
3970 % \subsection{The \env{align} family of environments}
3972 % The \env{align}, \env{flalign}, \env{alignat}, \env{xalignat},
3973 % and \env{xxalignat} environments are virtually
3974 % identical, and thus will share much code. We'll refer to the
3975 % environments generically as ``\env{align}'' and will
3976 % distinguish between them explicitly
3977 % only when necessary.
3979 % \begin{macro}{\ifxxat@}
3980 % \begin{macro}{\ifcheckat@}
3981 % \begin{macro}{\xatlevel@}
3982 % The \cs{xatlevel@} macro will be used, informally speaking, to
3983 % distinguish between the \env{alignat} and \env{xalignat}, and
3984 % \env{xxalignat} environments.
3991 \let\xatlevel@\@empty
3997 % \begin{macro}{\start@align}
3998 % \cs{start@align} will be called by all of the \env{align}-like
3999 % environments. The first argument will be the \cs{xatlevel@},
4000 % i.e., 0, 1, or~2; the second argument will be either
4001 % \cs{st@rredtrue} or \cs{st@rredfalse}. The third argument will
4002 % be the number of aligned
4003 % structures in the environment (either as supplied by the user, or
4004 % $-1$ to indicate that checking shouldn't be done). After
4005 % performing the appropriate error detection and initialization,
4006 % \cs{start@align} calls \cs{align@}.
4008 % Note that the \cs{equation} counter is no longer stepped at the
4009 % beginning of these environments.
4011 % TODO: Implement \cs{shoveleft} and \cs{shoveright} for
4014 \def\start@align#1#2#3{%
4015 \let\xatlevel@#1% always \z@, \@ne, or \tw@
4017 \ifnum\maxfields@>\m@ne
4019 \ifnum\xatlevel@=\tw@
4022 \multiply\maxfields@\tw@
4027 \iffalse{\fi\ifnum0=`}\fi
4028 \DN@{\vcenter\bgroup\savealignstate@\align@#2}%
4032 \DN@{\align@recover}%
4035 \DN@{\@namedef{end\@currenvir}{}\@gobble}%
4047 % With version 1.2 of \pkg{amsmath}, it was possible to use
4048 % \env{align*} and relatives in certain wrong contexts without
4049 % getting an error, e.g.
4058 % For backward compatibility we therefore give only a warning for
4059 % this condition instead of a full error, and try to recover using
4060 % the \env{aligned} environment. The alignment of the material may be
4061 % adversely affected but it will at least remain readable.
4063 \def\align@recover#1#2#3{%
4066 Erroneous nesting of equation structures;\MessageBreak
4067 trying to recover with `aligned'%
4069 \begin{aligned}\relax#1\end{aligned}%
4074 % \begin{environment}{align}
4075 % \begin{environment}{align*}
4076 % \begin{environment}{flalign}
4077 % \begin{environment}{flalign*}
4078 % \begin{environment}{alignat}
4079 % \begin{environment}{alignat*}
4080 % \begin{environment}{xalignat}
4081 % \begin{environment}{xalignat*}
4082 % \begin{environment}{xxalignat}
4083 % The definitions of the various \env{align} environments are quite
4087 \newenvironment{alignat}{%
4088 \start@align\z@\st@rredfalse
4092 \newenvironment{alignat*}{%
4093 \start@align\z@\st@rredtrue
4097 \newenvironment{xalignat}{%
4098 \start@align\@ne\st@rredfalse
4102 \newenvironment{xalignat*}{%
4103 \start@align\@ne\st@rredtrue
4107 \newenvironment{xxalignat}{%
4108 \start@align\tw@\st@rredtrue
4112 \newenvironment{align}{%
4113 \start@align\@ne\st@rredfalse\m@ne
4115 \math@cr \black@\totwidth@
4121 \ifnum0=`{\fi\iffalse}\fi
4125 \ignorespacesafterend
4127 \newenvironment{align*}{%
4128 \start@align\@ne\st@rredtrue\m@ne
4132 \newenvironment{flalign}{%
4133 \start@align\tw@\st@rredfalse\m@ne
4137 \newenvironment{flalign*}{%
4138 \start@align\tw@\st@rredtrue\m@ne
4154 % \begin{macro}{\align@}
4155 % TODO: Some of these sets of initializations show up in multiple
4156 % places. It might be worth making an abbreviation for them.
4160 \inalign@true \intertext@ \Let@ \chardef\dspbrk@context\z@
4161 \ifingather@\else\displ@y@\fi
4162 \let\math@cr@@@\math@cr@@@align
4163 \ifxxat@\else \let\tag\tag@in@align \fi
4164 \let\label\label@in@display
4166 \ifst@rred\else \global\@eqnswtrue \fi
4171 \span\align@preamble\crcr
4177 % \begin{macro}{\math@cr@@@align}
4179 \def\math@cr@@@align{%
4180 \ifst@rred\nonumber\fi
4181 \if@eqnsw \global\tag@true \fi
4182 \global\advance\row@\@ne
4183 \add@amps\maxfields@
4187 \setboxz@h{\@lign\strut@{\make@display@tag}}%
4190 \ifst@rred\else\global\@eqnswtrue\fi
4197 % \begin{macro}{\math@cr@@@align@measure}
4199 \def\math@cr@@@align@measure{%
4201 \global\advance\row@\@ne
4202 \ifst@rred\nonumber\fi
4203 \if@eqnsw \global\tag@true \fi
4204 \ifnum\column@>\maxfields@
4208 \@amsmath@err{Extra & on this line}%
4209 {\the\andhelp@}% "An extra & here is disastrous"
4212 \global\maxfields@\column@
4215 \setboxz@h{\@lign\strut@{%
4217 \stepcounter{equation}%
4218 \tagform@\theequation
4224 \ifst@rred\else\global\@eqnswtrue\fi
4230 % \begin{macro}{\field@lengths}
4231 % \begin{macro}{\savefieldlength@}
4232 % \begin{macro}{\fieldlengths@}
4234 \let\field@lengths\@empty
4236 \def\savefieldlength@{%
4239 \xdef\field@lengths{%
4251 \def\fieldlengths@#1{%
4252 \ifcase\@xp#1\field@lengths\fi
4259 % \begin{macro}{\maxcolumn@widths}
4260 % \cs{maxcolumn@widths} will be used to hold the widths of the
4261 % fields of the \env{alignat} environment. The widths will be
4262 % separated by the token \cn{or}, making it easy to extract a given
4263 % width using \cn{ifcase}.
4265 \let\maxcolumn@widths\@empty
4269 % \begin{macro}{\maxcol@width}
4270 % \cs{maxcol@width} $n$ = maximum width of $n$th column of the current
4271 % \env{alignat} (i.e., the $n$th field of \cs{maxcolumn@widths}.)
4272 % It expands to a \<dimen>, so it can be used as the right-hand
4273 % side of a \<variable assignment> or \<arithmetic> statement.
4274 % It's argument can be any \<number>, \<integer variable> or macro
4275 % that expands to one of these. [Check to make sure this is true.]
4277 % This is subtler than it looks.
4279 \def\maxcol@width#1{%
4280 \ifcase\@xp#1\maxcolumn@widths\fi\relax
4285 % Now comes the real fun. A typical \env{align} environments looks
4286 % something like this, where the vertical bars mark the edges of
4287 % the fields of the underlying \cs{halign}:
4289 % \makeatletter\tabskip\@centering\offinterlineskip
4290 % \halign to\displaywidth{%^^A
4291 % &$\strut$\vrule\hfil$\m@th\displaystyle{\@lign#}$\vrule
4292 % \tabskip1pt&\vrule$\m@th\displaystyle{\@lign#}$\hfil\vrule
4293 % \tabskip\@centering\cr
4294 % \omit\small\hfil 1\hfil &\omit\small\hfil 2 &\omit\small\hfil
4295 % 3\hfil &\omit\small\hfil 4\hfil & \omit\small\hfil 5\hfil
4296 % &\omit\small\hfil 6\hfil\cr
4297 % \noalign{\vskip8pt\relax}
4298 % V_i + q_i v_j & =v_i , & X_i & = x_i - q_i x_j,
4299 % & U_i & = u_i,\qquad
4300 % \hbox{for $i\ne j$;} %&\omit\hfill \llap{(3)}
4302 % V_j & = v_j, & X_j & = x_j,
4303 % & U_j & = u_j + \sum_{i\ne j} q_i u_i. %&\omit\hfill \llap{(4)}
4306 % Note that each align structure consists of two fields, with no
4307 % space between them (a small space has been added here to
4308 % highlight the boundaries). Furthermore, the text inside the
4309 % odd-numbered fields is flushright, while the text inside the
4310 % even-numbered fields is flushleft. The equation tags (shown on
4311 % the right here) can be on either the right or the left. If there
4312 % is not room (in a sense to be defined shortly) for the tag on the
4313 % same line as the equation, the tag will be shifted to a separate
4316 % Each environment also has a certain number of ``flexible
4317 % spaces,'' meaning spaces whose width we are allowed to adjust to
4318 % take up the amount of ``free space'' in the line, meaning the
4319 % space not taken up by the equation tag and the fields of the
4320 % underlying \cs{halign}.
4322 % The flexible spaces come in two flavors: interalign spaces and
4323 % margin spaces. If there are $n$ align structures ($n=3$ in the
4324 % illustration above), there are $n-1$ interalign spaces, unless we
4325 % are in an \env{alignat} environment, in which case there are no
4326 % flexible interalign spaces.
4328 % The number of margin spaces is a little more complicated:
4329 % Normally, there are two, but if we're in \opt{fleqn} mode, there
4330 % is only one. Furthermore, if we're in an \env{xxalignat} or
4331 % \env{flalign} environment (corresponding to $\cs{xatlevel@} = 2$,
4332 % then there are no flexible margin spaces.
4334 % Calculating the interalign and margin spaces is done in two
4337 % First, the total amount of free space is divided uniformly among
4338 % all the flexible spaces, without regard for the lengths of the tags
4339 % on the various lines. For the non-\opt{fleqn} case, this
4340 % corresponds to centering the align structures between the margins.
4341 % Note that in \opt{fleqn} mode, the right margin is still allowed to
4342 % be larger than \cs{@mathmargin}. This introduces an element of
4343 % asymmetry into the appearance of the environment, but it has the
4344 % advantage of leaving more space for equation tags in the right
4345 % margin. If the right margin were constrained to be equal to the
4346 % left margin in this case, tags would need to be shifted to a
4347 % separate line more often than would be desirable.
4349 % Ordinarily, all flexible spaces will be given the same width.
4350 % However, this is not invariably true, since the interalign spaces
4351 % are constrained to be at least \cs{minalignsep} wide, while---in
4352 % the absence of equation tags, at least---the margin spaces are
4353 % allowed to shrink to zero. As we shall see in a minute, if there
4354 % are tags in the environment, then the margins are also bounded
4355 % below by \cs{mintagsep}.
4357 % Next, we examine each line of the environment that has a tag to
4358 % see if there is a gap of at least \cs{mintagsep} between the
4359 % equation and its tag. If there isn't, we attempt to center the
4360 % equation between the tag and the opposite margin, leaving a gap
4361 % of at least \cs{mintagsep} on either side, in order to preserve
4362 % some symmetry, i.e., we want the equation to \emph{look} like
4363 % it's centered between the margin and the tag, so we don't want
4364 % the margin space to be less than the gap between the tag and the
4365 % equation. (Arguably, it would be better to allow the margin
4366 % space to shrink to zero in this case in order to avoid shifting
4367 % the tag to a separate line at any cost, but that would require
4368 % all of our calculations to be a little more complicated and hence
4369 % a little slower.) Finally, if no values of the interalign spaces
4370 % and the margins (with the constraints outlined above) will
4371 % produce an acceptable distance between the equation and its tag,
4372 % then the tag will be shifted to a separate line.
4374 % \begin{macro}{\measure@}
4375 % \cs{measure@} collects the various bits of information that we'll
4376 % need to perform the calculations outlined above, namely, the
4377 % number of align structures in the environment, the natural
4378 % lengths of the fields on each row, the maximum widths of each
4379 % column, and the widths of the equation tags on each line. It
4380 % also calculates the number of flexible interalign and margin
4381 % spaces and computes the initial values of the parameters
4382 % \cs{eqnshift@} and \cs{alignsep@}, which correspond to the widths
4383 % of the margins and the interalign spaces, respectively.
4388 \global\eqnshift@\z@
4389 \global\alignsep@\z@
4390 \global\let\tag@lengths\@empty
4391 \global\let\field@lengths\@empty
4393 \global\setbox0\vbox{%
4394 \let\math@cr@@@\math@cr@@@align@measure
4395 \everycr{\noalign{\global\tag@false
4396 \global\let\raise@tag\@empty \global\column@\z@}}%
4400 \halign{\span\align@preamble\crcr
4404 \add@amps\maxfields@\cr
4409 % It's convenient to have \cs{maxfields@} rounded up to the nearest
4410 % even number, so that \cs{maxfields@} is precisely twice the
4411 % number of align structures.
4414 \global\advance\maxfields@\@ne
4417 % It doesn't make sense to have a single align structure in either
4418 % \env{flalign} or \env{xxalignat}. So, we check for that case now
4419 % and, if necessary, switch to an \env{align} or \env{alignat}.
4420 % Arguably, we should issue a warning message, but why bother?
4422 \ifnum\xatlevel@=\tw@
4423 \ifnum\maxfields@<\thr@@
4428 % |\box0| now contains the lines of the \cs{halign}. After the
4429 % following maneuver, |\box1| will contain the last line of the
4430 % \cs{halign}, which is what we're interested in. (Incidentally,
4431 % the penalty we're removing is the \cs{@eqpen} inserted by
4432 % \cs{math@cr}. Normally, this is \cs{interdisplaylinepenalty},
4433 % unless the user has overridden that with a \cs{displaybreak}
4437 \unvbox\z@ \unpenalty \global\setbox\@ne\lastbox
4440 % |\box1| begins with \cs{tabskip} glue and contains alternating
4441 % \cs{hbox}es (the fields whose widths we're trying to get) and
4442 % \cs{tabskip} glue [need better diagram]:
4444 % \hbox{\tabskip\hbox\tabskip...\hbox\tabskip}\end{verbatim}
4445 % In fact, all the \cs{tabskip} glue will be 0pt, because all the
4446 % \cs{tabskip}s in an \env{alignat} environment have a natural
4447 % width of 0pt, and the \cs{halign} has been set in its natural
4450 % One nice result of this is that we can read \cs{totwidth@} off
4451 % immediately, since it is just the width of |\box1|, plus
4452 % \cs{@mathmargin} if we're in \opt{fleqn} mode. (Actually, we
4453 % also have to take \cs{minalignsep} into account, but we'll do
4456 \global\totwidth@\wd\@ne
4457 \if@fleqn \global\advance\totwidth@\@mathmargin \fi
4459 % Now we initialize \cs{align@lengths} and start peeling the boxes
4460 % off, one by one, and adding their widths to \cs{align@lengths}.
4461 % We stop when we run out of boxes, i.e., when \cs{lastbox} returns
4462 % a void box. We're going to build a list using \cs{or} as a
4463 % delimiter, so we want to disable it temporarily.
4465 \global\let\maxcolumn@widths\@empty
4469 \global\setbox\@ne\hbox{%
4470 \unhbox\@ne \unskip \global\setbox\thr@@\lastbox
4473 \xdef\maxcolumn@widths{ \or \the\wd\thr@@ \maxcolumn@widths}%
4477 % Now we calculate the number of flexible spaces and the initial
4478 % values of \cs{eqnshift@} and \cs{alignsep@}.
4479 % We start by calculating $\cs{displaywidth}-\cs{totwidth@}$,
4480 % which gives us the total amount of ``free space'' in a row.
4482 \dimen@\displaywidth
4483 \advance\dimen@-\totwidth@
4485 % Next we calculate the number of columns of flexible spaces in the
4486 % display, which depends on whether we're in \opt{fleqn} mode and
4487 % in which particular environment we are in.
4489 % We use \cs{@tempcnta} to store the total number of flexible spaces
4490 % in the align and \cs{@tempcntb} for the number of interalign
4495 % In \env{alignat}, the interalign spaces are under user control,
4496 % not ours. So, we set \cs{alignsep@} and \cs{minalignsep} both
4497 % equal to 0pt. Later, when calculating a new value for
4498 % \cs{alignsep@}, we will only save the new value if it is less
4499 % than the current value of \cs{alignsep@} (i.e., \cs{alignsep@}
4500 % will never increase). Since the values we calculate will never
4501 % be negative, this will ensure that \cs{alignsep@} remains zero in
4504 \global\alignsep@\z@
4508 % In \opt{fleqn} mode, the left margin---and hence the right margin
4509 % in this case---is fixed. Otherwise, we divide the free space
4510 % equally between the two margins.
4514 \global\eqnshift@\@mathmargin
4517 \global\eqnshift@\dimen@
4518 \global\divide\eqnshift@\@tempcnta
4522 % In an \env{align} or \env{xalignat} environment with $n$ aligned
4523 % structures, there are $n-1$ interalign spaces and either 1 or~2
4524 % flexible margins, depending on whether we're in \opt{fleqn} mode
4527 \@tempcntb\maxfields@
4528 \divide\@tempcntb\tw@
4529 \@tempcnta\@tempcntb
4530 \advance\@tempcntb\m@ne
4532 % If we are in \opt{fleqn} mode, we fix the left margin and divide
4533 % the free space equally among the interalign spaces and the right
4537 \global\eqnshift@\@mathmargin
4538 \global\alignsep@\dimen@
4539 \global\divide\alignsep@\@tempcnta
4542 % Otherwise, we divide the free space equally among the interalign
4543 % spaces and both margins.
4545 \global\advance\@tempcnta\@ne
4546 \global\eqnshift@\dimen@
4547 \global\divide\eqnshift@\@tempcnta
4548 \global\alignsep@\eqnshift@
4552 % Finally, if we're in an \env{flalign} or \env{xxalignat}
4553 % environment, there are no flexible margins and $n-1$ flexible
4554 % interalign spaces.
4556 \@tempcntb\maxfields@
4557 \divide\@tempcntb\tw@
4558 \global\advance\@tempcntb\m@ne
4559 \global\@tempcnta\@tempcntb
4560 \global\eqnshift@\z@
4561 \global\alignsep@\dimen@
4563 % If we're in \opt{fleqn} mode, we need to add back the
4564 % \cs{@mathmargin} that was removed when \cs{dimen@} was originally
4568 \global\advance\alignsep@\@mathmargin\relax
4570 \global\divide\alignsep@\@tempcntb
4573 % Now we make sure \cs{alignsep@} isn't too small.
4575 \ifdim\alignsep@<\minalignsep\relax
4576 \global\alignsep@\minalignsep\relax
4577 \ifdim\eqnshift@>\z@
4579 \global\eqnshift@\displaywidth
4580 \global\advance\eqnshift@-\totwidth@
4581 \global\advance\eqnshift@-\@tempcntb\alignsep@
4582 \global\divide\eqnshift@\tw@
4586 \ifdim\eqnshift@<\z@
4587 \global\eqnshift@\z@
4591 % Next, we calculate the value of \cs{tagshift@}. This is the glue
4592 % that will be inserted in front of the equation tag to make sure
4593 % it lines up flush against the appropriate margin.
4595 \global\tagshift@\totwidth@
4596 \global\advance\tagshift@\@tempcntb\alignsep@
4598 \ifnum\xatlevel@=\tw@
4599 \global\advance\tagshift@-\@mathmargin\relax
4602 \global\advance\tagshift@\eqnshift@
4605 \global\advance\tagshift@-\displaywidth
4608 % Finally, we increase \cs{totwidth@} by an appropriate multiple of
4609 % \cs{minalignsep}. If the result is greater than
4610 % \cs{displaywidth}, it means that at least one line in the
4611 % \env{align} is overfull and we will issue an appropriate warning
4612 % message (via \cs{bl@ck}) at the end of the environment.
4614 \dimen@\minalignsep\relax
4615 \global\advance\totwidth@\@tempcntb\dimen@
4616 \ifdim\totwidth@>\displaywidth
4617 \global\let\displaywidth@\totwidth@
4619 \global\let\displaywidth@\displaywidth
4626 % The code for calculating the appropriate placement of equation
4627 % tags in the \env{align} environments is quite complicated and
4628 % varies wildly depending on the settings of the |tagsleft@| and
4629 % |@fleqn| switches. To minimize memory and hash space usage, we
4630 % only define the variant appropriate for the current setting of
4633 % It would be worthwhile to examine this code more closely someday
4634 % and see if it could be optimized any.
4636 % \paragraph{Tag placement when \cs{tagsleft@true},
4639 % We begin with the version of \cs{calc@shift@align} appropriate
4640 % for flush-left equations with tags on the left.
4642 % \begin{macro}{\calc@shift@align}
4643 % This is the simplest case. Since the left margin is fixed, in
4644 % general the only thing to do is check whether there is room for
4645 % the tag in the left margin. The only exception is that if
4646 % $\cs{eqnshift@} = 0\,\mathrm{pt}$---meaning that we're in a
4647 % \env{flalign} environment and this is the first line with a tag
4648 % that we've encountered---then we set $\cs{eqnshift@} =
4649 % \cs{@mathmargin}$ and recalculate \cs{alignsep@}. This is done
4650 % by \cs{x@calc@shift@lf}.
4652 \iftagsleft@\if@fleqn
4653 \def\calc@shift@align{%
4654 \global\let\tag@shifts\@empty
4657 % \cs{@tempdima} is initialized to $\cs{@mathmargin} -
4658 % \cs{mintagsep}$, which yields the maximum size of a tag that will
4659 % not be shifted to another line.
4661 \@tempdima\@mathmargin\relax
4662 \advance\@tempdima-\mintagsep\relax
4664 % Now we examine each row in turn. If the width of the tag on the
4665 % line is non-positive---meaning either that there is no tag or
4666 % else that the user has forced it to have zero width---we mark the
4667 % tag to remain unshifted. Otherwise, we call \cs{x@calc@shift@lf}
4668 % to determine whether any adjustments need to be made to
4669 % \cs{eqnshift@} and \cs{alignsep@}. Note the difference in
4670 % treatment of zero-width tags between this code and \tex/'s
4671 % built-in algorithm: here, a width of zero prohibits the tag from
4672 % being shifted, while in \tex/'s built-in algorithm, a width of
4673 % zero forces the tag to be shifted.
4677 \ifdim\tag@width\row@>\z@
4689 % \begin{macro}{\x@calc@shift@lf}
4690 % As mentioned above, \cs{x@calc@shift@lf} first checks to see if
4691 % the current left margin is set to 0 and, if so, resets it to
4692 % \cs{@mathmargin} and recalculates \cs{alignsep@}. Next, it
4693 % checks whether the length of the current tag exceeds the
4694 % previously calculated limit and, if so, marks the tag to be
4695 % shifted to a separate line.
4697 \def\x@calc@shift@lf{%
4698 \ifdim\eqnshift@=\z@
4699 \global\eqnshift@\@mathmargin\relax
4700 \alignsep@\displaywidth
4701 \advance\alignsep@-\totwidth@
4702 \global\divide\alignsep@\@tempcntb
4703 \ifdim\alignsep@<\minalignsep\relax
4704 \global\alignsep@\minalignsep\relax
4707 \ifdim\tag@width\row@>\@tempdima
4717 % \paragraph{Tag placement when \cs{tagsleft@false},
4720 % Next we consider the case when equations are flush-left, but tags
4721 % are on the right. This case is somewhat more complicated than
4722 % the previous one, since we can adjust the right margin by varying
4723 % the inter-align separatin. Thus, when a tag is found to be too
4724 % close to its equation, we first attempt to decrease
4725 % \cs{alignsep@} enough to move the equation off to an acceptable
4726 % distance. Only if that would require a value of \cs{alignsep@}
4727 % less than \cs{minalignsep} do we move the tag to a separate line.
4729 % \begin{macro}{\calc@shift@align}
4730 % This version of \cs{calc@shift@align} differs from the previous
4731 % version only in calling \cs{x@calc@shift@rf} rather than
4732 % \cs{x@calc@shift@lf}.
4734 \iftagsleft@\else\if@fleqn
4735 \def\calc@shift@align{%
4736 \global\let\tag@shifts\@empty
4740 \ifdim\tag@width\row@>\z@
4752 % \begin{macro}{\x@calc@shift@rf}
4753 % To start, we need to know two quantities: the number of align
4754 % structures in the current row and the ``effective length'' of the
4755 % row, defined as the distance from the left margin to the
4756 % right edge of the text assuming that \cs{eqnshift@} and
4757 % \cs{alignsep@} are both~0. To get the number of align
4758 % structures, we first count the number of columns by counting the
4759 % number of entries in the \cs{fieldlengths@} for the current row.
4760 % The effective length is calcuated by \cs{x@rcalc@width} and put
4761 % in the temporary register \cs{@tempdimc}, using \cs{@tempdimb} as
4762 % an auxiliary variable.
4764 \def\x@calc@shift@rf{%
4768 \edef\@tempb{\fieldlengths@\row@}%
4769 \@for\@tempa:=\@tempb\do{%
4770 \advance\column@\@ne
4775 % If there are $n$ columns in the current row, then there are
4776 % $\lfloor (n+1)/2 \rfloor$ align structures and $\lfloor (n-1)/2
4777 % \rfloor$ interalign spaces.
4779 \advance\column@\m@ne
4782 % If this is smaller than the maximum number of interalign spaces
4783 % in the environment, then we need to reduce \cs{@tempcnta} (the
4784 % total number of flexible spaces in the current line) by
4785 % $\cs{@tempcntb} - \cs{column@}$ and reset \cs{@tempcntb} to
4788 \ifnum\@tempcntb>\column@
4789 \advance\@tempcnta-\@tempcntb
4790 \advance\@tempcnta\column@
4794 % Next, we add the width of the tag and the (fixed) left margin to
4795 % the effective length calculated above. This can be used to
4796 % calculate how much ``free space'' there is in the current line
4797 % and thus how much leeway we have to increase the amount of space
4798 % between the tag and the equation.
4800 \tagwidth@\tag@width\row@\relax
4801 \@tempdima\eqnshift@
4802 \advance\@tempdima\@tempdimc\relax
4803 \advance\@tempdima\tagwidth@
4805 % The first thing to check is whether the tag should be shifted to
4806 % a separate line. To do this, we add the minimum interalign
4807 % separation and the \cs{mintagsep} to the value of \cs{@tempdima}
4808 % just calculated. This yields the minimum acceptable length of
4809 % the current line. If that is greater than \cs{displaywidth}, we
4810 % mark the tag to be calculated. Otherwise, we mark the tag to be
4811 % kept on the same line and then check to see if the \cs{alignsep@}
4812 % needs to be reduced to make room for the tag.
4814 \dimen@\minalignsep\relax
4815 \multiply\dimen@\@tempcntb
4816 \advance\dimen@\mintagsep\relax
4817 \advance\dimen@\@tempdima
4818 \ifdim\dimen@>\displaywidth
4823 % Now we perform essentially the same calculation, but using the
4824 % current value of \cs{alignsep@} instead of \cs{minalignsep}.
4825 % This gives the current length of the line. If this is greater
4826 % than \cs{displaywidth}, we recalculate \cs{alignsep@} to make
4829 \dimen@\alignsep@\relax
4830 \multiply\dimen@\@tempcntb
4831 \advance\dimen@\@tempdima
4832 \advance\dimen@\tagwidth@
4833 \ifdim\dimen@>\displaywidth
4834 \dimen@\displaywidth
4835 \advance\dimen@-\@tempdima
4836 \ifnum\xatlevel@=\tw@
4837 \advance\dimen@-\mintagsep\relax
4839 \divide\dimen@\@tempcnta
4840 \ifdim\dimen@<\minalignsep\relax
4841 \global\alignsep@\minalignsep\relax
4843 \global\alignsep@\dimen@
4853 % \paragraph{Tag placement when \cs{tagsleft@false},
4854 % \cs{@fleqnfalse}.}
4856 % This is similar to the previous case, except for the added
4857 % complication that both \cs{alignsep@} and \cs{eqnshift@} can
4858 % vary, which makes the computations correspondingly more
4861 % \begin{macro}{\calc@shift@align}
4863 \iftagsleft@\else\if@fleqn\else
4864 \def\calc@shift@align{%
4865 \global\let\tag@shifts\@empty
4869 \ifdim\tag@width\row@>\z@
4881 % \begin{macro}{\x@calc@shift@rc}
4883 \def\x@calc@shift@rc{%
4887 \edef\@tempb{\fieldlengths@\row@}%
4888 \@for\@tempa:=\@tempb\do{%
4889 \advance\column@\@ne
4893 \advance\column@\m@ne
4895 \ifnum\@tempcntb>\column@
4896 \advance\@tempcnta-\@tempcntb
4897 \advance\@tempcnta\column@
4900 \tagwidth@\tag@width\row@\relax
4901 \@tempdima\@tempdimc
4902 \advance\@tempdima\tagwidth@
4903 \dimen@\minalignsep\relax
4904 \multiply\dimen@\@tempcntb
4905 \advance\dimen@\mintagsep\relax
4906 \ifnum\xatlevel@=\tw@ \else
4907 \advance\dimen@\mintagsep\relax
4909 \advance\dimen@\@tempdima
4910 \ifdim\dimen@>\displaywidth
4915 \advance\dimen@\@tempdima
4916 \advance\dimen@\@tempcntb\alignsep@
4917 \advance\dimen@\tagwidth@
4918 \ifdim\dimen@>\displaywidth
4919 \dimen@\displaywidth
4920 \advance\dimen@-\@tempdima
4921 \ifnum\xatlevel@=\tw@
4922 \advance\dimen@-\mintagsep\relax
4924 \divide\dimen@\@tempcnta
4925 \ifdim\dimen@<\minalignsep\relax
4926 \global\alignsep@\minalignsep\relax
4927 \eqnshift@\displaywidth
4928 \advance\eqnshift@-\@tempdima
4929 \advance\eqnshift@-\@tempcntb\alignsep@
4930 \global\divide\eqnshift@\tw@
4932 \ifdim\dimen@<\eqnshift@
4934 \global\eqnshift@\z@
4936 \global\eqnshift@\dimen@
4939 \ifdim\dimen@<\alignsep@
4940 \global\alignsep@\dimen@
4951 % \begin{macro}{\x@rcalc@width}
4954 \def\x@rcalc@width{%
4956 \advance\@tempdimc\@tempdimb
4958 \advance\@tempdimc\maxcol@width\column@
4961 \advance\@tempdimc\@tempa\relax
4962 \@tempdimb\maxcol@width\column@
4963 \advance\@tempdimb-\@tempa\relax
4966 \advance\@tempdimb\maxcol@width\column@\relax
4973 % \paragraph{Tag placement when \cs{tagsleft@true},
4974 % \cs{@fleqnfalse}.}
4976 % \begin{macro}{\calc@shift@align}
4978 \iftagsleft@\if@fleqn\else
4979 \def\calc@shift@align{%
4980 \global\let\tag@shifts\@empty
4984 \ifdim\tag@width\row@>\z@
4996 % \begin{macro}{\x@calc@shift@lc}
4998 \def\x@calc@shift@lc{%
5001 % \cs{@tempdima} will (eventually) be set to the effective width of
5002 % the current row, defined as the distance from the leftmost point
5003 % of the current line to the end of the last field of the
5004 % \cs{halign}, ignoring any intervening \cs{tabskip}s, plus the
5005 % width of the current tag. That is, it will be the width of the
5006 % first non-empty field plus the sum of the maximum widths of all
5007 % following fields, plus the tag width.
5009 % \cs{@tempdimb} will be the ``indentation'' of leftmost end of
5010 % text, ignoring the \cs{tabskip} glue, i.e., it will be the sum of
5011 % the maximum widths of any fields to the left of the first
5012 % non-empty field, plus whatever empty space there is at the
5013 % beginning of the first non-empty field.
5015 \@tempdima\z@ % ``width of equation''
5016 \@tempdimb\z@ % ``indent of equation''
5017 \edef\@tempb{\fieldlengths@\row@}%
5018 \@for\@tempa:=\@tempb\do{%
5019 \advance\column@\@ne
5023 \tagwidth@\tag@width\row@\relax
5025 % \cs{@tempdima} is now easy to calculate, since it is just
5026 % $\cs{totwidth@} - \cs{@tempdimb} + \cs{tagwidth@}$.
5028 \@tempdima\totwidth@
5029 \advance\@tempdima-\@tempdimb
5030 \advance\@tempdima\tagwidth@
5032 % Next, we check to see whether there is room for both the equation
5033 % and the tag on the same line, by calculating the minimum
5034 % acceptable length of the current row and comparing that to
5035 % \cs{displaywidth}. Note that here we use \cs{@tempcntb}, i.e.,
5036 % the number of interalign spaces after the first non-empty align
5039 \dimen@\minalignsep\relax
5040 \multiply\dimen@\@tempcntb
5041 \advance\dimen@\mintagsep\relax
5042 \ifnum\xatlevel@=\tw@ \else
5043 \advance\dimen@\mintagsep\relax
5045 \advance\dimen@\@tempdima
5047 % If the minimum acceptable width of the current line is greater
5048 % than \cs{displaywidth}, we mark the current tag to be shifted to
5051 \ifdim\dimen@>\displaywidth
5055 % Otherwise, the tag can stay on the same line as the equation, but
5056 % we need to check whether it is too close to the equation. So, we
5057 % calculate the distance between the left margin and the left side
5058 % of the equation, using the current values of \cs{eqnshift@} and
5059 % \cs{alignsep@}. Note that we use \cs{count@} here, not
5060 % \cs{@tempcntb}, as above.
5064 \multiply\dimen@\count@
5065 \advance\dimen@\eqnshift@
5066 \advance\dimen@\@tempdimb
5068 % If the left margin is less than twice the tag width, we calculate
5069 % new values of \cs{eqnshift@} and \cs{alignsep@} to move the
5070 % equation further away from the tag. In particular, we center the
5071 % current line between its tag and the right margin. Note that
5072 % although we later will need to transform \cs{dimen@} into a value
5073 % suitable for use as \cs{eqnshift@}, for the time being it is more
5074 % useful to think of it as the space separating the tag from the
5077 \ifdim\dimen@<2\tagwidth@
5078 \dimen@\displaywidth
5079 \advance\dimen@-\@tempdima
5080 \ifnum\xatlevel@=\tw@
5081 \advance\dimen@-\mintagsep\relax
5084 % In certain circumstances we will get a divide-by-zero error here
5085 % unless we guard against it. Use of \cs{@tempcnta} is complicated,
5086 % sometimes it is assigned globally, sometimes locally. Need to sort
5087 % it out one of these days [mjd,2000/06/02].
5089 \ifnum\@tempcnta>\z@
5090 \divide\dimen@\@tempcnta
5094 % As usual, we check to make sure we don't set \cs{alignsep@}
5095 % smaller than \cs{minalignsep} and, in any case, that we don't
5096 % replace \cs{alignsep@} by a larger value.
5098 \ifdim\dimen@<\minalignsep\relax
5099 \global\alignsep@\minalignsep\relax
5100 \dimen@\displaywidth
5101 \advance\dimen@-\@tempdima
5102 \advance\dimen@-\@tempcntb\alignsep@
5103 \global\divide\dimen@\tw@
5105 \ifdim\dimen@<\alignsep@
5106 \global\alignsep@\dimen@
5110 % Next, we calculate an appropriate value of \cs{eqnshift@},
5111 % assuming that \cs{dimen@} is the desired separation between the
5112 % tag and equation of the current line. This means that we first
5113 % need to adjust \cs{dimen@} if we're in an \env{flalign}
5116 \ifnum\xatlevel@=\tw@
5117 \dimen@\mintagsep\relax
5120 % Now we calculate the value of \cs{eqnshift@} needed to produce a
5121 % separation of \cs{dimen@} between the equation tag and the
5122 % beginning of the equation. To do this, we need the following
5125 % \cs{eqnshift@} + n\cs{alignsep@} + \cs{@tempdimb}
5126 % = \cs{tagwidth@} + \cs{dimen@}
5128 % where $n = \cs{count@}$ is the number of interalign spaces before
5129 % the first non-empty field of the current line.
5131 \advance\dimen@\tagwidth@
5132 \advance\dimen@-\@tempdimb
5133 \advance\dimen@-\count@\alignsep@
5135 % The value of \cs{eqnshift@} just calculated is the minimum
5136 % acceptable value; thus, we save it only if it is larger than the
5139 \ifdim\dimen@>\eqnshift@
5140 \global\eqnshift@\dimen@
5149 % \begin{macro}{\x@lcalc@width}
5150 % This macro calculates the ``indentation'' of the current row, as
5151 % defined above under the description of \cs{x@calc@shift@lc}.
5152 % This macro is called for each field of the current line, with
5153 % \cs{@tempa} set to the width of the current field. Ideally, the
5154 % loop enclosing \cs{x@lcalc@width} would terminate as soon as
5155 % \cs{@tempa} is non-zero, but that would be a bit tricky to
5156 % arrange. Instead, we use \cs{@tempdima} as a flag to signal when
5157 % we've encountered the first non-empty field.
5160 \def\x@lcalc@width{%
5161 \ifdim\@tempdima = \z@
5163 % If the current field is empty (i.e., $\cs{@tempa} =
5164 % \mathrm{0\,pt}$, then we increment \cs{@tempdimb} by the width of
5165 % the current field). Otherwise, we set $\cs{@tempdima} =
5166 % \mathrm{1\,pt}$ as a signal value and increment \cs{@tempdimb} by
5167 % the width of whatever empty space there might be at the left of
5168 % the current field.
5173 \advance\@tempdimb \maxcol@width\column@
5174 \advance\@tempdimb-\@tempa
5177 % In addition, we need to adjust the values of \cs{@tempcnta} and
5178 % \cs{@tempcntb} to account for any empty align structures that
5179 % might occur at the beginning of the current line. More
5180 % specifically, we first set \cs{count@} equal to the number of
5181 % interalign spaces preceding the current field (namely, $\lfloor
5182 % (\cs{\column@}-1)/2 \rfloor$), and then subtract \cs{count@} from
5183 % both \cs{@tempcnta} and \cs{@tempcntb}. The rationale is that
5184 % for the purposes of adjusting the spacing between the tag and the
5185 % equation, the only flexible interalign spaces are those after
5186 % the first non-empty align structure, so we need to treat those
5187 % different from the ones before the first non-empty align
5191 \advance\count@\m@ne
5193 \advance\@tempcnta-\count@
5194 \advance\@tempcntb-\count@
5196 \advance\@tempdimb \maxcol@width\column@\relax
5204 % \begin{macro}{\place@tag}
5205 % \cs{place@tag} takes care of the placment of tags in the
5206 % \env{align} environments.
5211 \if1\shift@tag\row@\relax
5224 \if1\shift@tag\row@\relax
5226 % Added depth to correct vertical spacing of shifted
5227 % equation tags.---dmj, 1994/12/29
5245 % \begin{macro}{\align@preamble}
5247 \def\align@preamble{%
5250 \setboxz@h{\@lign$\m@th\displaystyle{##}$}%
5251 \ifmeasuring@\savefieldlength@\fi
5254 &\setboxz@h{\@lign$\m@th\displaystyle{{}##}$}%
5255 \ifmeasuring@\savefieldlength@\fi
5263 % \begin{macro}{\set@field}
5264 % \cs{set@field} increments the column counter, tracks the value of
5265 % \cs{lineht@} and finally inserts the box containing the contents
5266 % of the current field.
5271 \ifdim\ht\z@>\lineht@
5272 \global\lineht@\ht\z@
5275 \ifdim\dp\z@>\lineht@
5276 \global\lineht@\dp\z@
5285 % \subsection {The \env{split} environment}
5287 % \begin{macro}{\split@err}
5288 % A special error function for \env{split} to conserve main mem (at a
5289 % cost of string pool/hash size.
5293 \string\begin{split} won't work here%
5296 Did you forget a preceding \string\begin{equation}?^^J%
5297 If not, perhaps the `aligned' environment is what
5298 you want.\endcsname}%
5303 % \begin{environment}{split}
5304 % If the \env{split} environment occurs inside \env{align} or
5305 % \env{gather}, it can make use of the enclosing halign; if it is
5306 % called inside a simple equation, we add an implicit `gather'
5310 \newenvironment{split}{%
5313 \@xp\@xp\@xp\split@aligned
5315 \ifst@rred \else \global\@eqnswtrue \fi
5317 \else \let\endsplit\@empty \@xp\collect@body\@xp\split@err
5319 \collect@body\gather@split
5324 \iftagsleft@ \@xp\lendsplit@ \else \@xp\rendsplit@ \fi
5329 \let\split@tag\relax % init
5333 \def\gather@split#1#2#3{%
5334 \@xp\endgroup \reset@equation % math@cr will handle equation numbering
5336 \toks@\@xp{\df@tag}%
5338 \gdef\@nx\df@tag{\the\toks@}%
5339 \global\@nx\tag@true \@nx\nonumber
5341 \else \let\split@tag\@empty
5345 % The extra vcenter wrapper here is not really a good thing but
5346 % without it there are compatibility problems with old documents that
5347 % throw in some extra material between \verb'\begin{equation}' and
5348 % \verb'\begin{split}' (for example, \verb'\hspace{-1pc}' or
5349 % \verb'\left\{'). [mjd,1999/09/20]
5352 \gather@{\split@tag \begin{split}#1\end{split}}%
5353 \def\endmathdisplay@a{%
5354 \math@cr \black@ \totwidth@ \egroup
5362 % \begin{macro}{\insplit@}
5365 \global\setbox\z@\vbox\bgroup
5366 \Let@ \chardef\dspbrk@context\@ne \restore@math@cr
5367 \default@tag % disallow use of \tag here
5371 $\m@th\displaystyle{##}$%
5372 &$\m@th\displaystyle{{}##}$%
5373 \hfill % Why not \hfil?---dmj, 1994/12/28
5379 % \begin{macro}{\rendsplit@}
5380 % Moved the box maneuvers inside the \cs{ifinalign@}, since that is
5381 % the only place they are needed.---dmj, 1994/12/28
5383 % TODO: Explore interaction of tag-placement algorithm with
5384 % \env{split}. Is there any way for \env{split} to pass the
5385 % relevant information out to the enclosing \env{gather} or
5391 % Changed |\box9| into a \cs{vtop} here for better spacing.
5393 \global\setbox9 \vtop{%
5395 \global\setbox8 \lastbox
5401 \global\setbox\tw@\lastbox
5403 \global\setbox\thr@@\lastbox
5407 \hbox to\wd\thr@@{}%
5408 &\vcenter{\vbox{\moveleft\wd\thr@@\boxz@}}%
5411 \global\setbox7 \hbox{\unhbox\tw@\unskip}%
5413 % Added \cs{add@amps} to make sure we put the last line of the
5414 % \env{split} into the proper column of an \env{align} environment
5415 % with multiple align structures.---dmj, 1994/12/28
5417 % Special care has to be taken in this case because the \env{split}
5418 % turns into two lines of the \env{align} instead of just one. So,
5419 % we have to make sure that the first line produced by the
5420 % \env{split} doesn't upset our bookkeeping, hence we call
5421 % \cs{savetaglength@} to insert 0\,pt as the tag for this
5422 % pseudo-line, and we advance the \cs{row@} counter and reset
5423 % \cs{lineht@} afterwards. It would be nice if we could just
5424 % replace the \cs{crcr} by \cs{math@cr@@@}, but that would cause
5425 % problems with the tag processing.
5428 \global\@tempcnta\column@
5431 \global\advance\row@\@ne
5432 \vbox{\moveleft\wd\thr@@\box9}%
5434 \noalign{\global\lineht@\z@}%
5442 \gdef\split@{\vcenter{\boxz@}}%
5445 % Changed to just \cs{boxz@}, otherwise last line gets centered
5446 % rather than aligned properly with respect to the rest of the
5447 % lines. But this means that we can't see inside of the last line
5448 % to decide whether the tag needs to be moved. Will have to think
5449 % about this.---dmj, 1994/12/28
5455 % \hbox{\box\thr@@\box7}%
5464 % \begin{macro}{\lendsplit@}
5467 \global\setbox9\vtop{\unvcopy\z@}%
5470 % Moved following two boxes inside the \cs{ifinalign@}, since they
5471 % are only used in that case. In fact, if we just kept track of
5472 % the width of the first column, we could dispense with this
5473 % entirely. Surely that would be more efficient than all these box
5474 % copies.---dmj, 1994/12/28
5478 \global\setbox8\lastbox
5485 \global\setbox\thr@@\lastbox
5489 \hbox to\wd\thr@@{}%
5490 &\vcenter{\vbox{\moveleft\wd\thr@@\box9}}%
5494 \hbox to\wd\thr@@{}%
5495 &\vbox{\moveleft\wd\thr@@\box9}%
5500 \gdef\split@{\vcenter{\box9}}%
5502 \gdef\split@{\box9}%
5510 % With \pkg{amsmath} 1.2 it was possible to put things like
5511 % \verb'\left\{' between \verb'\begin{equation}' and
5512 % \verb'\begin{split}' without getting any error message. For
5513 % backward compatibility we try to avoid a fatal error in this case
5514 % and instead attempt recovery with \env{aligned}.
5516 \def\split@aligned#1#2{%
5517 \iffalse{\fi\ifnum0=`}\fi
5518 \collect@body\split@al@a}
5522 \def\split@al@a#1#2#3{%
5526 % If the \opt{fleqn} and \opt{tbtags} options are both in effect then
5527 % we will need to add an optional argument on the \env{aligned}
5530 \toks@{\begin{aligned}}%
5531 \if@fleqn \split@al@tagcheck \fi
5533 % The \cs{relax} here is to prevent \cs{@let@token} from being left
5534 % equal to an ampersand if that happens to be the first thing in the body.
5536 \the\toks@\relax#1\end{aligned}%
5537 \ifnum0=`{\fi\iffalse}\fi
5542 \def\split@al@tagcheck{%
5545 \iftagsleft@ \toks@\@xp{\the\toks@ [t]}%
5546 \else \toks@\@xp{\the\toks@ [b]}%
5553 \def\split@warning{%
5554 \PackageWarning{amsmath}{%
5555 Cannot use `split' here;\MessageBreak trying to recover with `aligned'}%
5559 % \subsection{The \env{multline} environment}
5561 % In the original \amstex/, \cn{multlinegap} is a macro with an
5562 % argument that resets an internal dimension (one with an \qc{\@}
5563 % character in its name). Here, to save control sequence names, we
5564 % define \cn{multlinegap} to be the dimension itself and the
5565 % documentation instructs users to use \cn{setlength} if they
5566 % need to change it.
5567 % \begin{macro}{\multlinegap}
5568 % \begin{macro}{\multlinetaggap}
5569 % Changed \cs{multlinegap} and \cs{multlinetaggap} to skip
5570 % registers. Also changed name to \cs{multlinetaggap} from
5571 % \cs{multlinetaggap@}.
5573 \newskip\multlinegap
5575 \newskip\multlinetaggap
5581 % \begin{macro}{\start@multline}
5583 \def\start@multline#1{%
5586 \DN@{\@namedef{end\@currenvir}{}\@gobble}%
5595 \let\next@\multline@
5602 % \begin{environment}{multline}
5603 % \begin{environment}{multline*}
5605 \newenvironment{multline}{%
5606 \start@multline\st@rredfalse
5608 \iftagsleft@ \@xp\lendmultline@ \else \@xp\rendmultline@ \fi
5609 \ignorespacesafterend
5614 \newenvironment{multline*}{\start@multline\st@rredtrue}{\endmultline}
5619 % \begin{macro}{\multline@}
5625 % For multline neither \cs{displ@y} no \cs{displ@y@} is quite right;
5626 % we want to advance the row number and (I suppose?) the
5627 % display-pagebreak level, but we only want to do tag-related stuff
5628 % once before the first line, not repeat it for every line. (Recall
5629 % that the arg of \cs{@display@init} goes into \cs{everycr}.)
5631 \@display@init{\global\advance\row@\@ne \global\dspbrk@lvl\m@ne}%
5632 \chardef\dspbrk@context\z@
5635 % The \env{multline} environment is somewhat unusual, in that
5636 % \cs{tag} and \cs{label} are enabled only during the measuring
5637 % phase and disabled during the production phase.
5638 % Here we disable \cs{tag} and \cs{label}; \cs{mmeasure@} will
5639 % re-enable them temporarily.
5641 \let\tag\tag@in@align
5642 \global\tag@false \global\let\raise@tag\@empty
5644 \let\tag\gobble@tag \let\label\@gobble
5645 \tabskip \if@fleqn \@mathmargin \else \z@skip \fi
5646 \totwidth@\displaywidth
5648 \advance\totwidth@-\@mathmargin
5651 \hbox to\totwidth@{%
5653 % In order to get the spacing of the last line right in fleqn
5654 % mode, we need to play a little game here. Normally the
5655 % stretchability of the \cs{hskip} here will be suppressed by the
5656 % \cs{hfil} at the end of the template, except inside the last line,
5657 % when that \cs{hfil} will be removed by the \cs{hfilneg} in
5658 % \cs{lendmultline@}.
5661 \hskip \@centering \relax
5666 $\m@th\displaystyle{}##\endmultline@math
5671 % In \opt{fleqn} mode, it's the \cs{tabskip} of \cs{@mathmargin}
5672 % that needs to be removed in the first line, not the \cs{hfil} at
5673 % the beginning of the template.
5677 \def\multline@indent{\hskip\@mathmargin}% put it back
5680 \def\multline@indent{\hskip\multlinegap}%
5696 % If the equation tag doesn't fit on the same line with the first
5697 % line of the display, we'll indent the first line by
5698 % \cn{multlinegap}. This is a change from \pkg{amstex}, where the
5699 % first line would have been flush against the left margin in this
5700 % case. A corresponding change will be made in \cs{rendmultline@}.
5704 \setbox\z@\hbox{\make@display@tag}%
5705 \dimen@\@mathmargin \advance\dimen@-\wd\z@
5706 \ifdim\dimen@<\multlinetaggap
5707 \dimen@\multlinetaggap
5709 \box\z@ \hskip\dimen@\relax
5722 % An extra level of indirection for the closing \verb'$' in multline
5723 % allows us to avoid getting an extra thinmuskip from a final
5724 % mathpunct in the equation contents, when equation numbers are on
5725 % the right. If we did not use this workaround, the sequence of
5726 % elements for a final comma would be, e.g.,
5728 % ... ,<hskip><box containing equation number>
5730 % which is equivalent to a sequence \verb'<mathpunct><mathord>' as
5731 % far as the automatic math spacing is concerned.
5733 \def\endmultline@math{$}
5737 % \begin{macro}{\lendmultline@}
5738 % Bug fix: changed \cs{crcr} to \cs{math@cr} so that \cs{@eqpen}
5739 % gets reset properly if \cs{displaybreak} is used on the
5740 % penultimate line of an \env{align}.
5742 \def\lendmultline@{%
5752 % \begin{macro}{\rendmultline@}
5754 \def\rendmultline@{%
5756 $\let\endmultline@math\relax
5760 % Added depth to correct vertical spacing of shifted equation
5761 % tags.---dmj, 1994/12/29
5769 \hbox{\strut@\make@display@tag}%
5772 \hskip\multlinetaggap
5780 % Use \cs{math@cr} rather than just \cs{crcr} so that \cs{@eqpen}
5781 % gets reset properly if \cs{displaybreak} is used.
5789 % \begin{macro}{\mmeasure@}
5795 % We use \cs{begin/endgroup} rather than |{}| in this definition of
5796 % \cn{label} because the latter would create an extra (wasteful of
5797 % main mem) null box in the current math list. [mjd, 1995/01/17]
5800 \begingroup\measuring@false\label@in@display{##1}\endgroup}%
5801 \def\math@cr@@@{\cr}%
5802 \let\shoveleft\@iden \let\shoveright\@iden
5806 \global\let\df@tag\@empty
5808 \setboxz@h{\@lign$\m@th\displaystyle{}##$}%
5811 \global\totwidth@\wdz@
5812 \global\lineht@\ht\z@
5815 \global\totwidth@\wdz@
5816 \global\lineht@\dp\z@
5823 \ifx\df@tag\@empty\else\global\tag@true\fi
5824 \if@eqnsw\global\tag@true\fi
5828 \stepcounter{equation}%
5829 \tagform@\theequation
5834 \global\tagwidth@\wdz@
5836 \advance\dimen@\tagwidth@
5837 \advance\dimen@\multlinetaggap
5840 \advance\dimen@\@mathmargin
5843 \ifdim\dimen@>\displaywidth
5844 \global\shifttag@true
5846 \global\shifttag@false
5855 % \begin{macro}{\shoveleft}
5856 % \begin{macro}{\shoveright}
5857 % \cs{shoveleft} and \cs{shoveright} need to do slightly different
5858 % things depending on whether tags are on the left or the right and
5859 % whether we're in \opt{fleqn} mode. For compactness of code, we
5860 % make the appropriate decisions at ``compile'' time rather than at
5863 % TODO: Investigate making \cs{shoveright} behave ``properly''(?) if
5864 % used on the first line of a \env{multline} and make \cs{shoveleft}
5865 % behave properly if used on the last line of a \env{multline}. But
5866 % in his \fn{amstex.doc} Spivak indicates those commands should never
5867 % be used on a first or last line. Perhaps better to leave the
5868 % question open unless/until real-life examples turn up.
5885 \hskip\multlinetaggap
5894 \def\shoveleft#1{#1}%
5898 \setboxz@h{$\m@th\displaystyle{}#1$}%
5899 \setbox\@ne\hbox{$\m@th\displaystyle#1$}%
5906 \hskip\multlinetaggap
5917 \setboxz@h{$\m@th\displaystyle{}#1$}%
5918 \setbox\@ne\hbox{$\m@th\displaystyle#1$}%
5931 % \subsection{The \env{equation} environment}
5933 % Rewritten from the ground up for version 2.0 to fix no-shrink and
5934 % no-shortskips bugs [mjd,2000/01/06].
5936 % Standard \latex/ provides three environments for one-line equations:
5937 % \cn{[}\cn{]}, \env{equation}, and \env{displaymath}. We add
5938 % \env{equation*} as a synonym for \env{displaymath}.
5940 \@saveprimitive\leqno\@@leqno
5941 \@saveprimitive\eqno\@@eqno
5942 \def\eqno{\@@eqno\let\eqno\relax\let\leqno\relax}
5943 \def\leqno{\@@leqno\let\leqno\relax\let\eqno\relax}
5946 \iftagsleft@ \let\veqno=\@@leqno \fi
5949 % Support for the \pkg{showkeys} package: provide no-op definitions
5950 % for a couple of SK functions, if they are not already defined. Then
5951 % we can just call them directly in our code without any extra fuss.
5952 % If the \pkg{showkeys} package is loaded later, our trivial
5953 % definitions will get overridden and everything works fine.
5955 \@ifundefined{SK@@label}{%
5956 \let\SK@@label\relax \let\SK@equationtrue\relax
5961 \let\reset@equation\@empty
5964 % Cf \cs{tag@in@align}. This is a bit of a mess though. Could use
5965 % some work. [mjd,1999/12/21]
5968 \def\tag@in@display#1#{\relax\tag@in@display@a{#1}}
5969 \def\tag@in@display@a#1#2{%
5971 \invalid@tag{Multiple \string\tag}\relax
5973 \global\tag@true \nonumber \reset@equation \st@rredtrue
5975 \gdef\alt@tag{\def\SK@tagform@{#2\@gobble}%
5976 \ifx\SK@@label\relax \let\tagform@\SK@tagform@ \fi
5980 \make@df@tag@@@{#2}%
5987 \let\restore@hfuzz\@empty
5991 \def\mathdisplay#1{%
5994 $$\def\@currenvir{#1}%
5996 % Allow use of \cn{displaybreak}.
5998 \let\dspbrk@context\z@
6000 % Although in some cases simpler label handling would seem to be
6001 % sufficient, always using \cs{label@in@display} makes it easier to
6002 % support the \pkg{showkeys} package.
6004 \let\tag\tag@in@display \let\label\label@in@display \SK@equationtrue
6005 \global\let\df@label\@empty \global\let\df@tag\@empty
6007 \let\mathdisplay@push\mathdisplay@@push
6008 \let\mathdisplay@pop\mathdisplay@@pop
6011 % Turn off overfull box messages temporarily\mdash otherwise there
6012 % would be unwanted extra ones emitted during our measuring
6015 \edef\restore@hfuzz{\hfuzz\the\hfuzz\relax}%
6018 % Initially set the equation body in a box of displaywidth. Then if
6019 % the box is not overfull, as we find by checking \cs{badness}, we
6020 % have acquired useful information for the subsequent processing.
6022 \setbox\z@\hbox to\displaywidth\bgroup
6023 \let\split@warning\relax \restore@hfuzz
6024 \everymath\@emptytoks \m@th $\displaystyle
6030 % Arg 1 is not currently used. I thought it might come in handy for
6033 \def\endmathdisplay#1{%
6034 \ifmmode \else \@badmath \fi
6038 % I guess the following code means this structure is non-reentrant.
6039 % But there is plenty of scope for tricky bugs here; suppressing them
6040 % by brute force at least makes it possible to get things working
6041 % correctly for normal use. [mjd,2000/01/06]
6043 \global\let\df@label\@empty \global\let\df@tag\@empty
6044 \global\tag@false \global\let\alt@tag\@empty
6050 \def\endmathdisplay@a{%
6051 \if@eqnsw \gdef\df@tag{\tagform@\theequation}\fi
6052 \if@fleqn \@xp\endmathdisplay@fleqn
6053 \else \ifx\df@tag\@empty \else \veqno \alt@tag \df@tag \fi
6054 \ifx\df@label\@empty \else \@xp\ltx@label\@xp{\df@label}\fi
6056 \ifnum\dspbrk@lvl>\m@ne
6057 \postdisplaypenalty -\@getpen\dspbrk@lvl
6058 \global\dspbrk@lvl\m@ne
6063 % A boolean variable: Was that last box overfull or not? A value of 0
6064 % means yes, it was overfull.
6069 % Special handling is needed for flush-left equations. We need to
6070 % measure the equation body (found in box 0 after we close it with
6071 % the \cs{egroup}). Then after a fairly normal test to see if it fits
6072 % within the available space, we need to consider overlapping into
6073 % the displayindent area if displayindent is nonzero (as in an
6074 % indented list). If there is an equation number we may have to shift
6075 % it by hand to a separate line when there is not enough room;
6076 % we can no longer take advantage of the automatic shifting provided
6077 % by the \cn{leqno}, \cn{eqno} primitives.
6079 % We initially add \cs{@mathmargin} glue at the end of box 0 to get
6080 % an accurate overfull test. If \cs{@mathmargin} contains any shrink
6081 % then we cannot reliably tell whether the box will be overfull or
6082 % not simply by doing hand calculations from the actual width of the
6083 % equation body. We have to actually set the box and find out what
6086 % On the other hand if we put the \cs{@mathmargin} glue at the
6087 % beginning of the box it's awkward to remove it afterwards. So we
6088 % first put it in at the end and later we will move it to the
6089 % beginning as needed.
6092 \def\endmathdisplay@fleqn{%
6093 $\hfil\hskip\@mathmargin\egroup
6095 % We need to save the information about whether box 0 was overfull in
6096 % a variable, otherwise it will disappear in the next setbox
6097 % operation. And we couldn't set the equation number box earlier than
6098 % now, because the body of the equation might have contained a
6099 % \cs{tag} command (well, it could have been done, but this way
6100 % we can reuse the tag-handling code from elsewhere).
6102 \ifnum\badness<\inf@bad \let\too@wide\@ne \else \let\too@wide\z@ \fi
6105 \setbox4\hbox{\df@tag
6106 \ifx\df@label\@empty \else \@xp\ltx@label\@xp{\df@label}\fi
6110 \ifx\df@tag\@empty U\else \iftagsleft@ L\else R\fi\fi
6115 % For an unnumbered flush-left equation we hope first that the
6116 % the contents fit within displaywidth. If not we need to fall back
6117 % on a more complicated reboxing operation.
6121 \ifodd\too@wide % not too wide: just need to swap the glue around
6122 \hbox to\displaywidth{\hskip\@mathmargin\unhbox\z@\unskip}%
6123 \else % M+B > displaywidth
6129 % Some notation: $M$ \cs{@mathmargin}, $B$ the width of the equation
6130 % body, $I$ \cs{displayindent}, $D$ \cs{displaywidth}, $N$ the width
6131 % of the equation number (aka the tag), $S$ \cs{mintagsep}, $C$
6132 % \cs{columnwidth}. If $M+B > \mbox{displaywidth}$, and if we assume
6133 % $M$ contains shrink, then the only solution left is to encroach
6134 % into the displayindent space.
6137 \hbox to\columnwidth{%
6138 \ifdim\displayindent>\z@
6139 \hskip\displayindent minus\displayindent
6141 \hskip\@mathmargin \unhbox\z@ \unskip
6143 \displayindent\z@ \displaywidth\columnwidth
6147 % Find out first if the tag fits in ideal position. If so we can just
6148 % plunk down box 2. Otherwise we need to do something more complicated.
6151 \setbox\tw@\hbox to\displaywidth{%
6152 \hskip\@mathmargin \unhcopy\z@\unskip\hfil\hskip\mintagsep\copy4
6155 \ifnum\badness<\inf@bad \box\tw@ \else \emdf@Ra \fi
6159 % We shift the equation number to line 2 if it does not fit within
6160 % \cs{displaywidth}. Note that we do not first attempt to let the
6161 % equation body shift leftward into the \cs{displayindent} space. If
6162 % that is desired it will have to be done by hand by adding negative
6163 % space at the beginning of the equation body. I don't expect this to
6164 % arise very often in practice since most of the time
6165 % \cs{displayindent} is zero anyway.
6168 \skip@\displayindent minus\displayindent
6169 \displayindent\z@ \displaywidth\columnwidth
6170 \spread@equation \everycr{}\tabskip\z@skip
6171 \halign{\hbox to\displaywidth{##}\cr
6173 \ifdim\skip@>\z@ \hskip\skip@ \fi
6174 \hskip\@mathmargin\unhbox\z@\unskip\hfil\cr
6175 \noalign{\raise@tag}%
6180 % Find out first if the tag fits in ideal position. If so we can just
6181 % plunk down box 2. Otherwise we need to do something more
6186 % Calculate the difference between $M$ and $N+S$. If the latter is
6187 % greater, we don't want to add any extra glue between the number and
6188 % the equation body. Otherwise the amount that we want to add is
6189 % \verb'x minus x' where $x=M-(N+S)$. I.e., the distribution of
6190 % spaces across the line is $N,S,x minus x,B,hfil$.
6192 \@tempdima\@mathmargin
6193 \advance\@tempdima-\wd4 \advance\@tempdima-\mintagsep
6194 \skip@\@tempdima minus\@tempdima
6195 \setbox\tw@\hbox to\displaywidth{%
6196 \copy4\hskip\mintagsep
6197 \ifdim\skip@>\z@ \hskip\skip@\fi
6201 \ifnum\badness<\inf@bad \box\tw@ \else \emdf@La \fi
6205 % If the equation body and equation number will not fit on the same
6206 % line, we put the number on line 1 and the body on line 2, with the
6207 % body positioned as for an unnumbered equation.
6210 \spread@equation \everycr{}\tabskip\z@skip
6211 \halign{\hbox to\displaywidth{##}\cr
6213 \noalign{\raise@tag}%
6214 \hskip\@mathmargin\unhbox\z@\unskip\hfil\cr}%
6218 % If someone has \verb'\[ \]' nested inside a minipage environment
6219 % nested inside a numbered equation, the mathdisplay variables that
6220 % are global will get out of whack unless we take extra care. So we
6221 % make a stack and push all the variables before entering mathdisplay
6222 % and pop them afterwards. But we can save a little work by not doing
6223 % this at the top level, only at inner levels.
6225 \newtoks\mathdisplay@stack
6226 \let\mathdisplay@push\@empty
6227 \def\mathdisplay@@push{%
6229 \toks@\@xp{\df@label}\@temptokena\@xp{\df@tag}%
6230 \toks8\@xp{\alt@tag}%
6232 \global\if@eqnsw\@nx\@eqnswtrue\else\@nx\@eqnswfalse\fi
6233 \global\iftag@\@nx\tag@false\else\@nx\tag@true\fi
6234 \gdef\@nx\df@label{\the\toks@}\gdef\@nx\df@tag{\the\@temptokena}%
6235 \gdef\@nx\alt@tag{\the\toks8}%
6236 \global\mathdisplay@stack{\the\mathdisplay@stack}%
6238 \global\mathdisplay@stack\@xp{\@tempa}
6244 \let\mathdisplay@pop\@empty
6245 \def\mathdisplay@@pop{\the\mathdisplay@stack}
6249 \renewenvironment{equation}{%
6252 \st@rredfalse \global\@eqnswtrue
6253 \mathdisplay{equation}%
6255 \endmathdisplay{equation}%
6257 \ignorespacesafterend
6262 \newenvironment{equation*}{%
6264 \st@rredtrue \global\@eqnswfalse
6265 \mathdisplay{equation*}%
6267 \endmathdisplay{equation*}%
6269 \ignorespacesafterend
6273 % Note: \latex/ defines the \env{displaymath} environment in
6274 % terms of \cn{[} and \cn{]}.
6276 \DeclareRobustCommand{\[}{\begin{equation*}}
6277 \DeclareRobustCommand{\]}{\end{equation*}}
6280 % The usual \cs{endinput} to ensure that random garbage at the end of
6281 % the file doesn't get copied by \fn{docstrip}.
6288 % Much of the code for the \pkg{amsmath} package had its orgin in
6289 % \fn{amstex.tex}, written by Michael Spivak. The initial work of
6290 % porting \fn{amstex.tex} to \fn{amstex.sty} was done in 1988--1989
6291 % by Frank Mittelbach and Rainer Sch\"opf. In 1994 David M. Jones
6292 % added the support for the \opt{fleqn} option and did extensive
6293 % improvements to the \env{align[at]} family of environments and to
6294 % the equation number handling in general. Michael Downes at the AMS
6295 % served as coordinator for the efforts of Mittelbach, Sch\"opf, and
6296 % Jones, and has contributed various bug fixes and additional
6297 % refinements over time.
6299 % Versions 1.0 and 1.1 of the package carried the name \pkg{amstex}
6300 % instead of \pkg{amsmath}, to indicate its origins; the name was
6301 % changed in 1994 to make it user-oriented rather than