| 1 |
% |
| 2 |
% \iffalse meta-comment |
| 3 |
% |
| 4 |
% Copyright (C) 1995, 2000, 2013 American Mathematical Society. |
| 5 |
% Copyright (C) 2016-2025 LaTeX Project and American Mathematical Society. |
| 6 |
% |
| 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 |
% https://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. |
| 14 |
% |
| 15 |
% This work has the LPPL maintenance status `maintained'. |
| 16 |
% |
| 17 |
% The Current Maintainer of this work is the LaTeX Project. |
| 18 |
% |
| 19 |
% \fi |
| 20 |
% |
| 21 |
%\iffalse |
| 22 |
%<*driver> |
| 23 |
\documentclass{amsdtx} |
| 24 |
\def\MaintainedByLaTeXTeam#1{% |
| 25 |
\begin{center}% |
| 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{https://latex-project.org/bugs/}.\end{tabular}}}\end{center}} |
| 30 |
\raggedbottom |
| 31 |
\let\savedarg\arg |
| 32 |
\usepackage{amsmath} |
| 33 |
\let\arg\savedarg |
| 34 |
\GetFileInfo{amsmath.sty} |
| 35 |
\begin{document} |
| 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:]% |
| 43 |
}{% |
| 44 |
\endtrivlist |
| 45 |
} |
| 46 |
\DocInput{amsmath.dtx} |
| 47 |
\end{document} |
| 48 |
%</driver> |
| 49 |
%\fi |
| 50 |
% |
| 51 |
% \maketitle |
| 52 |
% \MaintainedByLaTeXTeam{amslatex} |
| 53 |
% |
| 54 |
% \MakeShortVerb\| |
| 55 |
% |
| 56 |
% \section{Introduction} |
| 57 |
% |
| 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, |
| 69 |
% \fn{amsldoc.tex}. |
| 70 |
% |
| 71 |
% \MaybeStop{} |
| 72 |
% |
| 73 |
% Standard file identification. |
| 74 |
% \begin{macrocode} |
| 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 |
% \end{macrocode} |
| 78 |
% |
| 79 |
% Providing a rollback to earlier version(s). Anything prior to |
| 80 |
% 2018 we attempt to fulfill by using the version from 2018. |
| 81 |
% \begin{macrocode} |
| 82 |
\DeclareRelease{}{1994-06-01}{amsmath-2018-12-01.sty} |
| 83 |
\DeclareRelease{}{2018-12-01}{amsmath-2018-12-01.sty} |
| 84 |
\DeclareCurrentRelease{}{2019-04-01} |
| 85 |
% \end{macrocode} |
| 86 |
% |
| 87 |
% \begin{macrocode} |
| 88 |
\ProvidesPackage{amsmath}[2025/07/09 v2.17z AMS math features] |
| 89 |
% \end{macrocode} |
| 90 |
% |
| 91 |
% \section{Catcode defenses} |
| 92 |
% |
| 93 |
% Some packages change the catcode of characters that are essential |
| 94 |
% in low-level \tex/ syntax. Any package that does so does not |
| 95 |
% qualify as a PWWO package (\qq{Plays Well With Others}) because it |
| 96 |
% can cause other packages to fail if they are loaded later. \LaTeX{} |
| 97 |
% is partly to blame for this because it fails to provide adequate |
| 98 |
% built-in safeguards in the package loading mechanisms. In the |
| 99 |
% absence of such safeguards, we will provide them here. |
| 100 |
% \begin{macrocode} |
| 101 |
\edef\@temp{\catcode 96=\number\catcode 96 } |
| 102 |
\catcode\string `\`=12 |
| 103 |
\def\do#1{\catcode\number`#1=\number\catcode`#1} |
| 104 |
\edef\@temp{% |
| 105 |
\noexpand\AtEndOfPackage{% |
| 106 |
\@temp |
| 107 |
\do\"\do\'\do\(\do\)\do\*\do\+\do\,\do\-\do\.% |
| 108 |
\do\/\do\<\do\=\do\>\do\[\do\]\do\^\do\_\relax |
| 109 |
}% |
| 110 |
} |
| 111 |
\@temp |
| 112 |
\def\do#1{\catcode\number`#1=12 } |
| 113 |
\do\"\do\'\do\(\do\)\do\*\do\+\do\,\do\-\do\. |
| 114 |
\do\/\do\<\do\=\do\>\do\[\do\] |
| 115 |
\catcode`\^=7 \catcode`\_=8 |
| 116 |
% \end{macrocode} |
| 117 |
% |
| 118 |
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 119 |
% \section{Declare some options} |
| 120 |
% |
| 121 |
% Handling of limits on integrals, sums, operatornames. |
| 122 |
% \begin{macrocode} |
| 123 |
\DeclareOption{intlimits}{\let\ilimits@\displaylimits} |
| 124 |
\DeclareOption{nointlimits}{\let\ilimits@\nolimits} |
| 125 |
\DeclareOption{sumlimits}{\let\slimits@\displaylimits} |
| 126 |
\DeclareOption{nosumlimits}{\let\slimits@\nolimits} |
| 127 |
\DeclareOption{namelimits}{\PassOptionsToPackage{namelimits}{amsopn}} |
| 128 |
\DeclareOption{nonamelimits}{% |
| 129 |
\PassOptionsToPackage{nonamelimits}{amsopn}} |
| 130 |
% \end{macrocode} |
| 131 |
% |
| 132 |
% The following two switches might have been defined already by the |
| 133 |
% documentclass, but it doesn't hurt to re-execute the \cs{newif}'s. |
| 134 |
% \begin{macrocode} |
| 135 |
\newif\ifctagsplit@ |
| 136 |
\newif\iftagsleft@ |
| 137 |
% \end{macrocode} |
| 138 |
% Right or left placement of equation numbers. |
| 139 |
% \begin{macrocode} |
| 140 |
\DeclareOption{leqno}{\tagsleft@true} |
| 141 |
\DeclareOption{reqno}{\tagsleft@false} |
| 142 |
\DeclareOption{centertags}{\ctagsplit@true} |
| 143 |
\DeclareOption{tbtags}{\ctagsplit@false} |
| 144 |
% \end{macrocode} |
| 145 |
% |
| 146 |
% The \opt{cmex10} option is an escape hatch for people who don't |
| 147 |
% happen to have sizes 7--9 of the \fn{cmex} fonts available to them |
| 148 |
% yet. (Strictly speaking they are considered part of a minimum |
| 149 |
% \latex/ distribution now, i.e., all \LaTeXe{} users should have |
| 150 |
% them, without needing to get the AMSFonts distrib.) |
| 151 |
% \begin{macrocode} |
| 152 |
\DeclareOption{cmex10}{% |
| 153 |
\ifnum\cmex@opt=\@ne \def\cmex@opt{0}% |
| 154 |
\else \def\cmex@opt{10}\fi |
| 155 |
} |
| 156 |
% \end{macrocode} |
| 157 |
% To help things work out better with various package loading orders |
| 158 |
% of \pkg{amsmath} and \pkg{amsfonts}, we establish a variable to |
| 159 |
% communicate the status of the cmex font definition. If the |
| 160 |
% \pkg{amsfonts} package was loaded first this variable might be |
| 161 |
% already defined, in which case we want to preserve its value. |
| 162 |
% \begin{macrocode} |
| 163 |
\@ifundefined{cmex@opt}{\def\cmex@opt{7}}{} |
| 164 |
% \end{macrocode} |
| 165 |
% |
| 166 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 167 |
% \section{Flush-left equations [DMJ]} |
| 168 |
% |
| 169 |
% The left margin of math environments is controlled by |
| 170 |
% \cs{@mathmargin}. This can be set to \cs{@centering} to |
| 171 |
% implement the default behaviour, i.e., centered equations, and to |
| 172 |
% something else to implement the flushleft style. |
| 173 |
% |
| 174 |
% In theory, all that's needed to activate the flushleft mode |
| 175 |
% in the AMS document classes is something like this: |
| 176 |
% \begin{verbatim} |
| 177 |
% \DeclareOption{fleqn}{% |
| 178 |
% \AtBeginDocument{\@mathmargin30pt\relax}% |
| 179 |
% } |
| 180 |
% \end{verbatim} |
| 181 |
% (In fact, unless the document class wants to specify the |
| 182 |
% \cs{@mathmargin}, it doesn't need to do anything with the |
| 183 |
% \opt{fleqn} option.) |
| 184 |
% \begin{macrocode} |
| 185 |
\newif\if@fleqn |
| 186 |
% |
| 187 |
\newskip\@mathmargin |
| 188 |
\@mathmargin\@centering |
| 189 |
% |
| 190 |
\DeclareOption{fleqn}{% |
| 191 |
\@fleqntrue |
| 192 |
\@mathmargin = -1sp |
| 193 |
\let\mathindent=\@mathmargin |
| 194 |
\AtBeginDocument{% |
| 195 |
\ifdim\@mathmargin= -1sp |
| 196 |
\@mathmargin\leftmargini minus\leftmargini |
| 197 |
\fi |
| 198 |
}% |
| 199 |
} |
| 200 |
% \end{macrocode} |
| 201 |
% |
| 202 |
% DMJ: This ensures that \cs{@mathmargin} is given some sort of |
| 203 |
% sensible default if the class doesn't specify one, while still |
| 204 |
% allowing a user to override the default value in their document |
| 205 |
% preamble. (Incidentally, I'm initializing \cs{@mathmargin} to |
| 206 |
% \cs{leftmargini} for compatibility with \fn{fleqn.clo}, but I'm |
| 207 |
% not at all convinced that's the right thing to do.) |
| 208 |
% |
| 209 |
% The next question is what happens when amsmath is used with |
| 210 |
% one of the standard classes. Unfortunately, \latex/ implements |
| 211 |
% \opt{fleqn} somewhat clumsily; instead of parameterizing the |
| 212 |
% definitions of the math structures (as I've attempted to do |
| 213 |
% here), \fn{fleqn.clo} declares a dimen \cn{mathindent} that is |
| 214 |
% much like my \cs{@mathmargin} and then redefines \cn\[, \cn\], |
| 215 |
% \cn{equation}, and \cn{eqnarray}. This means that things could |
| 216 |
% get rather messy in 2.09 compatibility mode, since \fn{fleqn.clo} |
| 217 |
% might be loaded after \fn{amsmath.sty}, which could cause a real |
| 218 |
% mess. |
| 219 |
% |
| 220 |
% [mjd,1999/07/07]: Let \cs{mathindent} = \cs{@mathmargin} as |
| 221 |
% envisioned by DMJ. Compatibility-mode documents will all use the |
| 222 |
% \pkg{amstex} package, not \pkg{amsmath}. There is a remote chance |
| 223 |
% of a problem if someone makes an assignment to \cs{mathindent} in a |
| 224 |
% way that implicitly assumes it is a dimen register (inasmuch as it |
| 225 |
% has now become a skip register), and the string ``plus'' follows in |
| 226 |
% the input stream, but if someone's document croaks in that way, I |
| 227 |
% think they will just have to bite the bullet and fix it. The |
| 228 |
% alternative is to penalize a lot of other users with a known |
| 229 |
% handicap. |
| 230 |
% |
| 231 |
% \section{Spacing around \cn{aligned} and \cn{gathered}} |
| 232 |
% |
| 233 |
% [dpc, 2016] Option to control the space to the left of aligned and gathered. |
| 234 |
% |
| 235 |
% Previously \cn{aligned} and \cn{gathered} inserted a thin space on |
| 236 |
% their left but not their right, there is no good reason for this |
| 237 |
% that anyone can remember, it has just always been that way |
| 238 |
% inherited from amstex. The usual advice to authors has been to use |
| 239 |
% |\!\begin{aligned}| to get better spacing. |
| 240 |
% |
| 241 |
% Here introduce: |
| 242 |
% |
| 243 |
% \opt{alignedleftspaceyes} to keep the behaviour of adding this space. |
| 244 |
% |
| 245 |
% \opt{alignedleftspaceno} to disable adding this space. |
| 246 |
% |
| 247 |
% \opt{alignedleftspaceyesifneg} the new default behaviour, do not add |
| 248 |
% the space unless the environment is preceded by a negative skip or |
| 249 |
% kern, so that |\!\begin{aligned}| works as before. |
| 250 |
% |
| 251 |
% \changes{v2.16a}{2016/11/05}{New options to control aligned spacing} |
| 252 |
% \begin{macrocode} |
| 253 |
\DeclareOption{alignedleftspaceyes}{\def\alignedspace@left{\null\,}} |
| 254 |
\DeclareOption{alignedleftspaceno}{\def\alignedspace@left{\null}} |
| 255 |
\DeclareOption{alignedleftspaceyesifneg}{% |
| 256 |
\def\alignedspace@left{% |
| 257 |
\edef\@tempa{\expandafter\@car\the\lastskip\@nil}% |
| 258 |
\if-\@tempa\null\,% |
| 259 |
\else |
| 260 |
\edef\@tempa{\expandafter\@car\the\lastkern\@nil}% |
| 261 |
\if-\@tempa\null\,% |
| 262 |
\else\null |
| 263 |
\fi |
| 264 |
\fi}% |
| 265 |
} |
| 266 |
% \end{macrocode} |
| 267 |
% |
| 268 |
% |
| 269 |
% \begin{macrocode} |
| 270 |
\DeclareOption{?}{} |
| 271 |
% \end{macrocode} |
| 272 |
% |
| 273 |
% \begin{macrocode} |
| 274 |
\ExecuteOptions{% |
| 275 |
nointlimits,sumlimits,namelimits,centertags,alignedleftspaceyesifneg} |
| 276 |
% \end{macrocode} |
| 277 |
% The \cs{par} after \cs{ProcessOptions} is to ensure the correct |
| 278 |
% line number on screen if an error occurs during option processing; |
| 279 |
% otherwise the lookahead for a \qc{\*} option would result in \tex/ |
| 280 |
% showing the following line instead. |
| 281 |
% \begin{macrocode} |
| 282 |
\ProcessOptions\par |
| 283 |
% \end{macrocode} |
| 284 |
% |
| 285 |
% \begin{macrocode} |
| 286 |
\@ifpackagewith{amsmath}{?}{% |
| 287 |
\typeout{^^J% |
| 288 |
Documentation for the amsmath package is found in amsldoc.dvi^^J% |
| 289 |
(or .pdf or .tex).^^J% |
| 290 |
^^J% |
| 291 |
See also https://www.ams.org/tex/amslatex.html.^^J% |
| 292 |
^^J% |
| 293 |
Note: Using the first edition of The LaTeX Companion (1994) without^^J% |
| 294 |
errata as a guide for amsmath use is not recommended.^^J% |
| 295 |
}% |
| 296 |
}{% |
| 297 |
\typeout{% |
| 298 |
For additional information on amsmath, use the \lq ?\rq\space option.% |
| 299 |
}% |
| 300 |
} |
| 301 |
% \end{macrocode} |
| 302 |
% |
| 303 |
% Processing to handle the \opt{cmex10} option is a little tricky |
| 304 |
% because of different possible loading orders for \pkg{amsmath} |
| 305 |
% and \pkg{amsfonts}. The package \pkg{amsmath} sets the |
| 306 |
% \cs{cmex@opt} flag to 0, 7 or 10, and in the past the package |
| 307 |
% \pkg{amsfonts} did set the flag to 1 or 0. These days it always |
| 308 |
% sets it to 10. The situation is a bit unsettled but we don't own |
| 309 |
% \pkg{amsfonts}. |
| 310 |
% \changes{v2.17d}{2019/12/01}{docu update, no code change (gh/200)} |
| 311 |
% \begin{macrocode} |
| 312 |
\ifnum\cmex@opt=7 \relax |
| 313 |
\DeclareFontShape{OMX}{cmex}{m}{n}{% |
| 314 |
<-8>cmex7<8>cmex8<9>cmex9% |
| 315 |
<10><10.95><12><14.4><17.28><20.74><24.88>cmex10% |
| 316 |
}{}% |
| 317 |
\expandafter\let\csname OMX/cmex/m/n/10\endcsname\relax |
| 318 |
\else |
| 319 |
\ifnum\cmex@opt=\z@ % need to override cmex7 fontdef from amsfonts |
| 320 |
% \end{macrocode} |
| 321 |
% Force reloading of the OMX/cmex font definition file. |
| 322 |
% \begin{macrocode} |
| 323 |
\begingroup |
| 324 |
\fontencoding{OMX}\fontfamily{cmex}% |
| 325 |
\expandafter\let\csname OMX+cmex\endcsname\relax |
| 326 |
\try@load@fontshape |
| 327 |
\endgroup |
| 328 |
% \end{macrocode} |
| 329 |
% The \fn{cmex10} font gets special preload handling in the building |
| 330 |
% of the \latex/ format file, need an extra bit here to work around |
| 331 |
% that. |
| 332 |
% \begin{macrocode} |
| 333 |
\expandafter\let\csname OMX/cmex/m/n/10\endcsname\relax |
| 334 |
\def\cmex@opt{10}% |
| 335 |
\fi |
| 336 |
\fi |
| 337 |
% \end{macrocode} |
| 338 |
% |
| 339 |
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 340 |
% \section{Call some other packages} |
| 341 |
% |
| 342 |
% The \pkg{amstext} package provides the \cn{text} command. The |
| 343 |
% \pkg{amsbsy} package provides \cn{boldsymbol} and \cn{pmb}. (Since |
| 344 |
% 1997 it is usually better to use the \pkg{bm} package instead; but |
| 345 |
% I think we have to keep \pkg{amsbsy} here for backward |
| 346 |
% compatibility [mjd,1999/11/19].) The \pkg{amsopn} package provides |
| 347 |
% \cn{DeclareMathOperator}. |
| 348 |
% \begin{macrocode} |
| 349 |
\RequirePackage{amstext}[1995/01/25] |
| 350 |
%\RequirePackage{amsgen}[1995/01/25] % already loaded by amstext |
| 351 |
\RequirePackage{amsbsy}[1995/01/20] |
| 352 |
\RequirePackage{amsopn}[1995/01/20] |
| 353 |
% \end{macrocode} |
| 354 |
% |
| 355 |
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 356 |
% \section{Miscellaneous} |
| 357 |
% |
| 358 |
% \begin{macro}{\ams@newcommand} |
| 359 |
% Where \pkg{stix} and \pkg{amsmath} define the same control |
| 360 |
% sequences, we want to avoid inadvertently overriding \pkg{stix}'s |
| 361 |
% definitions. If \pkg{stix} is loaded before \pkg{amsmath}, the |
| 362 |
% following conditional takes care of the problem. There is |
| 363 |
% similar code in the \pkg{stix} package in case \pkg{amsmath} is |
| 364 |
% loaded first. |
| 365 |
% \begin{macrocode} |
| 366 |
\@ifpackageloaded{stix}{% |
| 367 |
\let\ams@newcommand\providecommand |
| 368 |
\let\ams@renewcommand\providecommand |
| 369 |
\let\ams@def\providecommand |
| 370 |
\let\ams@DeclareRobustCommand\providecommand |
| 371 |
}{% |
| 372 |
\let\ams@newcommand\newcommand |
| 373 |
\let\ams@renewcommand\renewcommand |
| 374 |
\let\ams@def\def |
| 375 |
\let\ams@DeclareRobustCommand\DeclareRobustCommand |
| 376 |
} |
| 377 |
% \end{macrocode} |
| 378 |
% \end{macro} |
| 379 |
% |
| 380 |
% \begin{macro}{\@amsmath@err} |
| 381 |
% Defining this error function saves main mem. |
| 382 |
% \begin{macrocode} |
| 383 |
\def\@amsmath@err{\PackageError{amsmath}} |
| 384 |
% \end{macrocode} |
| 385 |
% \end{macro} |
| 386 |
% |
| 387 |
% \begin{macro}{\AmS} |
| 388 |
% The \cs{AmS} prefix can be used to construct the combination |
| 389 |
% |\AmS-\LaTeX|. |
| 390 |
% \begin{macrocode} |
| 391 |
\providecommand{\AmS}{{\protect\AmSfont |
| 392 |
A\kern-.1667em\lower.5ex\hbox{M}\kern-.125emS}} |
| 393 |
% \end{macrocode} |
| 394 |
% In \cn{AmSfont} we call cmsy directly in lieu of trying to access |
| 395 |
% it through the math fonts setup (e.g. |\the\textfont2|) because |
| 396 |
% math fonts can't be relied on to be properly set up if we are not |
| 397 |
% inside a math formula. This means that if this command is used in a |
| 398 |
% document where CM fonts are not wanted, then a font substitution |
| 399 |
% will need to be declared, e.g.: |
| 400 |
% \begin{verbatim} |
| 401 |
% \DeclareFontShape{OMS}{cmsy}{m}{n}{ <-> sub * xxx/m/n }{} |
| 402 |
% \end{verbatim} |
| 403 |
% where |xxx| is some alternate font family. |
| 404 |
% Taking the first letter of \cs{f@series} will produce |b| or |m| |
| 405 |
% for the most common values (|b,bx,m|). It may produce nonsense for |
| 406 |
% more unusual values of \cs{f@series}, so for safety's sake we have |
| 407 |
% an additional \cs{if} test. We want to avoid setting the series to |
| 408 |
% |bx| because in a standard \latex/ installation the combination |
| 409 |
% |cmsy/bx/n| does not have a font definition, and the user |
| 410 |
% would get a font substitution warning on screen. |
| 411 |
% \begin{macrocode} |
| 412 |
\newcommand{\AmSfont}{% |
| 413 |
\usefont{OMS}{cmsy}{\if\@xp\@car\f@series\@nil bb\else m\fi}{n}} |
| 414 |
% \end{macrocode} |
| 415 |
% \end{macro} |
| 416 |
% |
| 417 |
% \begin{macro}{\@mathmeasure} |
| 418 |
% The function |\@mathmeasure| takes three arguments; the third arg |
| 419 |
% is typeset as a math formula in an hbox, using arg |#2| as the |
| 420 |
% mathstyle, and the result is left in the box named by the first |
| 421 |
% arg. It is assumed that we are already in math mode, so we can turn |
| 422 |
% off |\everymath| (in particular, |\check@mathfonts|). |
| 423 |
% |
| 424 |
% As of 2018/12 release we don't turn off |\evermath| as this |
| 425 |
% optimization can be harmful. |
| 426 |
% \changes{v2.17b}{2018/12/01}{Don't drop \cs{frozen@everymath}} |
| 427 |
% \begin{macrocode} |
| 428 |
\ifx\leavevmode@ifvmode\@undefined % kernel is < 2018/12 |
| 429 |
\def\@mathmeasure#1#2#3{\setbox#1\hbox{\frozen@everymath\@emptytoks |
| 430 |
\m@th$#2#3$}} |
| 431 |
\else |
| 432 |
\def\@mathmeasure#1#2#3{\setbox#1\hbox{% |
| 433 |
\m@th$#2#3$}} |
| 434 |
\fi |
| 435 |
% \end{macrocode} |
| 436 |
% \end{macro} |
| 437 |
% |
| 438 |
% The \cs{inf@bad} constant is for testing overfull boxes. |
| 439 |
% \begin{macrocode} |
| 440 |
\@ifundefined{inf@bad}{% |
| 441 |
\newcount\inf@bad \inf@bad=1000000 \relax |
| 442 |
}{} |
| 443 |
% \end{macrocode} |
| 444 |
% |
| 445 |
%\subsection{Math spacing commands} |
| 446 |
% |
| 447 |
% \begin{macro}{\tmspace} |
| 448 |
% \begin{macro}{\,} |
| 449 |
% \begin{macro}{\thinspace} |
| 450 |
% \begin{macro}{\!} |
| 451 |
% \begin{macro}{\negthinspace} |
| 452 |
% \begin{macro}{\:} |
| 453 |
% \begin{macro}{\medspace} |
| 454 |
% \begin{macro}{\negmedspace} |
| 455 |
% \begin{macro}{\;} |
| 456 |
% \begin{macro}{\thickspace} |
| 457 |
% \begin{macro}{\negthickspace} |
| 458 |
% Here we fill in some gaps in the set of spacing commands, and make them |
| 459 |
% all work equally well in or out of math. |
| 460 |
% We want all these commands to be robust but declaring them all with |
| 461 |
% \cs{DeclareRobustCommand} uses up an control sequence name per |
| 462 |
% command; to avoid this, we define a common command \cs{tmspace} |
| 463 |
% (text-or-math space) which carries the robustness burden for all of |
| 464 |
% them. The standard \cs{relax} before the \cs{ifmmode} is not |
| 465 |
% necessary because of the \cs{protect} added by |
| 466 |
% \cs{DeclareRobustCommand}. |
| 467 |
% \changes{v2.17b}{2018/12/01}{Start LR-mode for \cs{thinspace} and |
| 468 |
% friends if necessary (github/49)} |
| 469 |
% |
| 470 |
% We start by undefining a number of commands (which in a current |
| 471 |
% \LaTeX{} kernel will be defined, so that the |
| 472 |
% \cs{DeclareRobustCommand} declarations below do not add a |
| 473 |
% ``Command redefined'' info into the log. |
| 474 |
% \begin{macrocode} |
| 475 |
\let\tmspace\@undefined |
| 476 |
\let\,\@undefined |
| 477 |
\let\!\@undefined |
| 478 |
\let\:\@undefined |
| 479 |
\let\negmedspace\@undefined |
| 480 |
\let\negthickspace\@undefined |
| 481 |
% \end{macrocode} |
| 482 |
% |
| 483 |
% |
| 484 |
% \changes{v2.17g}{2020/03/07}{Math/text spacing commands are now in |
| 485 |
% the \LaTeX{} kernel and are made robust (gh/303)} |
| 486 |
% \begin{macrocode} |
| 487 |
\ifx\leavevmode@ifvmode\@undefined |
| 488 |
\DeclareRobustCommand\tmspace[3]{% |
| 489 |
\ifmmode\mskip#1#2\else\kern#1#3\fi\relax} |
| 490 |
\else |
| 491 |
\DeclareRobustCommand\tmspace[3]{% |
| 492 |
\ifmmode\mskip#1#2\else\leavevmode@ifvmode\kern#1#3\fi\relax} |
| 493 |
\fi |
| 494 |
\DeclareRobustCommand\,{\tmspace+\thinmuskip{.1667em}} |
| 495 |
\let\thinspace\, |
| 496 |
\DeclareRobustCommand\!{\tmspace-\thinmuskip{.1667em}} |
| 497 |
\let\negthinspace\! |
| 498 |
\DeclareRobustCommand\:{\tmspace+\medmuskip{.2222em}} |
| 499 |
\let\medspace\: |
| 500 |
\DeclareRobustCommand\negmedspace{\tmspace-\medmuskip{.2222em}} |
| 501 |
\renewcommand\;{\tmspace+\thickmuskip{.2777em}} |
| 502 |
\let\thickspace\; |
| 503 |
\DeclareRobustCommand\negthickspace{\tmspace-\thickmuskip{.2777em}} |
| 504 |
% \end{macrocode} |
| 505 |
% \end{macro} |
| 506 |
% \end{macro} |
| 507 |
% \end{macro} |
| 508 |
% \end{macro} |
| 509 |
% \end{macro} |
| 510 |
% \end{macro} |
| 511 |
% \end{macro} |
| 512 |
% \end{macro} |
| 513 |
% \end{macro} |
| 514 |
% \end{macro} |
| 515 |
% \end{macro} |
| 516 |
% |
| 517 |
% \begin{macro}{\mspace} |
| 518 |
% And while we're at it, why don't we provide an equivalent of |
| 519 |
% \cn{hspace} for math mode use. This allows use of |mu| units in |
| 520 |
% (for example) constructing compound math symbols. |
| 521 |
% \begin{macrocode} |
| 522 |
\newcommand{\mspace}[1]{\mskip#1\relax} |
| 523 |
% \end{macrocode} |
| 524 |
% \end{macro} |
| 525 |
% |
| 526 |
% \subsection{Vertical bar symbols} |
| 527 |
% \begin{macro}{\lvert} |
| 528 |
% \begin{macro}{\rvert} |
| 529 |
% \begin{macro}{\lVert} |
| 530 |
% \begin{macro}{\rVert} |
| 531 |
% Add left/right specific versions of \cn{vert}, \cn{Vert}. Don't |
| 532 |
% assume the delimiter codes are the CM defaults. |
| 533 |
% \begin{macrocode} |
| 534 |
\def\@tempa#1#2\@nil{% |
| 535 |
\ifx\delimiter#1\@tempcnta#2\relax\else\@tempcnta\z@\fi |
| 536 |
} |
| 537 |
\@xp\@tempa\vert\@empty\@nil |
| 538 |
\ifnum\@tempcnta>\z@ |
| 539 |
\advance\@tempcnta "4000000 |
| 540 |
% \end{macrocode} |
| 541 |
% Use \cs{protected} on the new delimiters. |
| 542 |
% \changes{v2.17e}{2020/01/20}{Make delimiters robust (gh/251))} |
| 543 |
% \begin{macrocode} |
| 544 |
\protected\xdef\lvert{\delimiter\number\@tempcnta\space } |
| 545 |
\advance\@tempcnta "1000000 |
| 546 |
\protected\xdef\rvert{\delimiter\number\@tempcnta\space } |
| 547 |
\else |
| 548 |
\ifx\@@undefined\lvert |
| 549 |
% Fall back to cmex encoding since we don't know what else to do. |
| 550 |
\DeclareMathDelimiter{\lvert} |
| 551 |
{\mathopen}{symbols}{"6A}{largesymbols}{"0C} |
| 552 |
\DeclareMathDelimiter{\rvert} |
| 553 |
{\mathclose}{symbols}{"6A}{largesymbols}{"0C} |
| 554 |
\fi |
| 555 |
\fi |
| 556 |
\@xp\@tempa\Vert\@empty\@nil |
| 557 |
\ifnum\@tempcnta>\z@ |
| 558 |
\advance\@tempcnta "4000000 |
| 559 |
\protected\xdef\lVert{\delimiter\number\@tempcnta\space } |
| 560 |
\advance\@tempcnta "1000000 |
| 561 |
\protected\xdef\rVert{\delimiter\number\@tempcnta\space } |
| 562 |
\else |
| 563 |
\ifx\@@undefined\lVert |
| 564 |
\DeclareMathDelimiter{\lVert} |
| 565 |
{\mathopen}{symbols}{"6B}{largesymbols}{"0D} |
| 566 |
\DeclareMathDelimiter{\rVert} |
| 567 |
{\mathclose}{symbols}{"6B}{largesymbols}{"0D} |
| 568 |
\fi |
| 569 |
\fi |
| 570 |
% \end{macrocode} |
| 571 |
% \end{macro} |
| 572 |
% \end{macro} |
| 573 |
% \end{macro} |
| 574 |
% \end{macro} |
| 575 |
% |
| 576 |
% \subsection{Fractions} |
| 577 |
% Bury the generalized fraction primitives \cs{over}, \cs{atop}, |
| 578 |
% etc., because of their bizarre syntax, which is decidedly out of |
| 579 |
% place in a \latex/ document. |
| 580 |
% \begin{macrocode} |
| 581 |
\@saveprimitive\over\@@over |
| 582 |
\@saveprimitive\atop\@@atop |
| 583 |
\@saveprimitive\above\@@above |
| 584 |
\@saveprimitive\overwithdelims\@@overwithdelims |
| 585 |
\@saveprimitive\atopwithdelims\@@atopwithdelims |
| 586 |
\@saveprimitive\abovewithdelims\@@abovewithdelims |
| 587 |
% \end{macrocode} |
| 588 |
% |
| 589 |
% \begin{macro}{\primfrac} |
| 590 |
% If someone insists on using \cs{over}, give a warning the first |
| 591 |
% time and then resurrect the old definition. Laissez-faire policy. |
| 592 |
% \begin{macrocode} |
| 593 |
\DeclareRobustCommand{\primfrac}[1]{% |
| 594 |
\PackageWarning{amsmath}{% |
| 595 |
Foreign command \@backslashchar#1;\MessageBreak |
| 596 |
\protect\frac\space or \protect\genfrac\space should be used instead% |
| 597 |
\MessageBreak |
| 598 |
} |
| 599 |
\global\@xp\let\csname#1\@xp\endcsname\csname @@#1\endcsname |
| 600 |
\csname#1\endcsname |
| 601 |
} |
| 602 |
% \end{macrocode} |
| 603 |
% \end{macro} |
| 604 |
% \begin{macrocode} |
| 605 |
\renewcommand{\over}{\primfrac{over}} |
| 606 |
\renewcommand{\atop}{\primfrac{atop}} |
| 607 |
\renewcommand{\above}{\primfrac{above}} |
| 608 |
\renewcommand{\overwithdelims}{\primfrac{overwithdelims}} |
| 609 |
\renewcommand{\atopwithdelims}{\primfrac{atopwithdelims}} |
| 610 |
\renewcommand{\abovewithdelims}{\primfrac{abovewithdelims}} |
| 611 |
% \end{macrocode} |
| 612 |
% |
| 613 |
% \cn{frac} calls \cn{@@over} directly instead of via \cn{genfrac}, for |
| 614 |
% better speed because it is so common. \cn{tfrac} and \cn{dfrac} are |
| 615 |
% abbreviations for some commonly needed mathstyle overrides. To |
| 616 |
% conserve csnames we avoid making \cn{dfrac} and \cn{tfrac} robust |
| 617 |
% (\cn{genfrac} is itself robust). |
| 618 |
% \changes{v2.17i}{2020/09/23}{added \cs{Ustack} for luatex (moved patch from lualatex-math)} |
| 619 |
% \changes{v2.17n}{2022/04/08}{Make fraction commands robust (gh/123)} |
| 620 |
% \begin{macrocode} |
| 621 |
% |
| 622 |
\ifx\directlua\@undefined |
| 623 |
\DeclareRobustCommand{\frac}[2]{{\begingroup#1\endgroup\@@over#2}} |
| 624 |
\else |
| 625 |
\DeclareRobustCommand{\frac}[2]{{\Ustack{\begingroup#1\endgroup\@@over#2}}} |
| 626 |
\fi |
| 627 |
\DeclareRobustCommand{\dfrac}{\genfrac{}{}{}0} |
| 628 |
\DeclareRobustCommand{\tfrac}{\genfrac{}{}{}1} |
| 629 |
% \end{macrocode} |
| 630 |
% The \cn{binom} command for binomial notation works like \cn{frac} |
| 631 |
% and has similar variants. Note that we do not use \cs{z@} in |
| 632 |
% \cn{dbinom} and \cn{tbinom} because they are not top-level robust |
| 633 |
% like \cn{binom}, and so the \cs{z@} with the potentially |
| 634 |
% problematic \qc{\@} character would become visible when writing one |
| 635 |
% of those commands to a \fn{.toc} file. |
| 636 |
% \changes{v2.17n}{2022/04/08}{Make binom commands robust (gh/123)} |
| 637 |
% \begin{macrocode} |
| 638 |
\DeclareRobustCommand{\binom}{\genfrac()\z@{}} |
| 639 |
\DeclareRobustCommand{\dbinom}{\genfrac(){0pt}0} |
| 640 |
\DeclareRobustCommand{\tbinom}{\genfrac(){0pt}1} |
| 641 |
% \end{macrocode} |
| 642 |
% |
| 643 |
% \begin{macro}{\genfrac} |
| 644 |
% \changes{v2.16a}{2016/11/05}{New genfrac implementation for extended |
| 645 |
% TeXs} |
| 646 |
% This command provides access to \tex/'s generalized fraction |
| 647 |
% primitives. Args: \arg{1} left delim, \arg{2} right delim, \arg{3} |
| 648 |
% line thickness, \arg{4} mathstyle override, \arg{5} numerator, |
| 649 |
% \arg{6} denominator. But we only read the first four args at first, |
| 650 |
% in order to give us a moment to select the proper generalized |
| 651 |
% fraction primitive. Any of those four args could be empty, and when |
| 652 |
% empty the obvious defaults are selected (no delimiters, default |
| 653 |
% line thickness (normally .4pt), and no mathstyle override). |
| 654 |
% |
| 655 |
% the |withdelims| primitives do not work in xetex with OpenType |
| 656 |
% fonts, and the relevant font dimen parameters are often not set |
| 657 |
% in luatex as there are no matching values in the OpenType Math |
| 658 |
% table, so here we use variants that use the font parameters if |
| 659 |
% they are set, but scale using |\left\right| rather than the |
| 660 |
% |withdelims| primitives. |
| 661 |
% |
| 662 |
% \begin{macrocode} |
| 663 |
\ifx\directlua\@undefined |
| 664 |
% \end{macrocode} |
| 665 |
% |
| 666 |
% \begin{macrocode} |
| 667 |
\ifx\XeTeXcharclass\@undefined |
| 668 |
% \end{macrocode} |
| 669 |
% Classic version |
| 670 |
% \begin{macrocode} |
| 671 |
\DeclareRobustCommand{\genfrac}[4]{% |
| 672 |
\def\@tempa{#1#2}% |
| 673 |
\edef\@tempb{\@nx\@genfrac\@mathstyle{#4}% |
| 674 |
\csname @@\ifx @#3@over\else above\fi |
| 675 |
\ifx\@tempa\@empty \else withdelims\fi\endcsname} |
| 676 |
\@tempb{#1#2#3}} |
| 677 |
% \end{macrocode} |
| 678 |
% |
| 679 |
% \begin{macrocode} |
| 680 |
\else |
| 681 |
% \end{macrocode} |
| 682 |
% XeTeX version |
| 683 |
% \begin{macrocode} |
| 684 |
\def\genfrac@rule#1#2#3#4{% |
| 685 |
\hbox{$\left#1\vcenter{\hrule \@width\z@ |
| 686 |
\@height |
| 687 |
\ifdim\fontdimen#2#3\tw@=\z@ |
| 688 |
#4\fontdimen6#3\tw@ |
| 689 |
\else |
| 690 |
\fontdimen#2#3\tw@ |
| 691 |
\fi |
| 692 |
}\right.$}} |
| 693 |
% \end{macrocode} |
| 694 |
% |
| 695 |
% \begin{macrocode} |
| 696 |
\def\genfrac@choice#1#2{% |
| 697 |
\ifx @#2@\else |
| 698 |
% \end{macrocode} |
| 699 |
% \changes{v2.17a}{2017/09/02}{move \cs{nulldelimiterspace} correction} |
| 700 |
% \begin{macrocode} |
| 701 |
\ifx c#1\kern-\nulldelimiterspace\fi |
| 702 |
{\delimitershortfall\z@\delimiterfactor\@m |
| 703 |
\mathsurround\z@\nulldelimiterspace\z@ |
| 704 |
\mathchoice |
| 705 |
{\genfrac@rule{#2}{20}\textfont{2.39}}% |
| 706 |
{\genfrac@rule{#2}{21}\textfont{1}}% |
| 707 |
{\genfrac@rule{#2}{21}\scriptfont{1.45}}% |
| 708 |
{\genfrac@rule{#2}{21}\scriptscriptfont{1.35}}% |
| 709 |
}% |
| 710 |
\ifx o#1\kern-\nulldelimiterspace\fi |
| 711 |
\fi |
| 712 |
} |
| 713 |
% \end{macrocode} |
| 714 |
% |
| 715 |
% \begin{macrocode} |
| 716 |
\DeclareRobustCommand{\genfrac}[6]{{% |
| 717 |
\@mathstyle{#4}% |
| 718 |
\genfrac@choice o{#1}% |
| 719 |
{\begingroup#5\endgroup\ifx @#3@\@@over\else\@@above\fi#3\relax#6}% |
| 720 |
\genfrac@choice c{#2}% |
| 721 |
}} |
| 722 |
% \end{macrocode} |
| 723 |
% |
| 724 |
% \begin{macrocode} |
| 725 |
\fi |
| 726 |
\else |
| 727 |
% \end{macrocode} |
| 728 |
% LuaTeX version |
| 729 |
% \begin{macrocode} |
| 730 |
\def\genfrac@rule#1#2#3{% |
| 731 |
\hbox{$\left#1\vcenter{\hrule \@width\z@ |
| 732 |
\@height |
| 733 |
\ifdim\Umathfractiondelsize#2=\z@ |
| 734 |
#3\fontdimen6#3\tw@ |
| 735 |
\else |
| 736 |
\Umathfractiondelsize#2% |
| 737 |
\fi |
| 738 |
}\right.$}} |
| 739 |
% \end{macrocode} |
| 740 |
% |
| 741 |
% \begin{macrocode} |
| 742 |
\def\genfrac@choice#1#2{% |
| 743 |
\ifx @#2@\else |
| 744 |
% \end{macrocode} |
| 745 |
% \changes{v2.17a}{2017/09/02}{move \cs{nulldelimiterspace} correction} |
| 746 |
% \begin{macrocode} |
| 747 |
\ifx c#1\kern-\nulldelimiterspace\fi |
| 748 |
{\delimitershortfall\z@\delimiterfactor\@m |
| 749 |
\mathsurround\z@\nulldelimiterspace\z@ |
| 750 |
\mathchoice |
| 751 |
{\genfrac@rule{#2}\displaystyle{2.39}}% |
| 752 |
{\genfrac@rule{#2}\textstyle{1}}% |
| 753 |
{\genfrac@rule{#2}\scriptstyle{1.45}}% |
| 754 |
{\genfrac@rule{#2}\scriptscriptstyle{1.35}}% |
| 755 |
}% |
| 756 |
\ifx o#1\kern-\nulldelimiterspace\fi |
| 757 |
\fi |
| 758 |
} |
| 759 |
% \end{macrocode} |
| 760 |
% \changes{v2.17i}{2020/09/23}{added \cs{Ustack} (moved patch from lualatex-math)} |
| 761 |
% \begin{macrocode} |
| 762 |
\DeclareRobustCommand{\genfrac}[6]{{% |
| 763 |
\@mathstyle{#4}% |
| 764 |
\genfrac@choice o{#1}% |
| 765 |
{\Ustack {\begingroup#5\endgroup\ifx @#3@\@@over\else\@@above\fi#3\relax#6}}% |
| 766 |
\genfrac@choice c{#2}% |
| 767 |
}} |
| 768 |
% \end{macrocode} |
| 769 |
% |
| 770 |
% \begin{macrocode} |
| 771 |
\fi |
| 772 |
% \end{macrocode} |
| 773 |
% |
| 774 |
% End of test for Lua\TeX/Xe\TeX. |
| 775 |
% |
| 776 |
% \cs{@genfrac} takes the preceding arguments and reads the |
| 777 |
% numerator and denominator. Note that there's no convenient way to |
| 778 |
% make the numerator and denominator \emph{contents} |
| 779 |
% displaystyle, through this interface. |
| 780 |
% |
| 781 |
% Args: \arg{1} mathstyle, \arg{2} fraction primitive, |
| 782 |
% \arg{3} delimiters and rule thickness, |
| 783 |
% \arg{4} numerator, \arg{5} denominator. |
| 784 |
% \begin{macrocode} |
| 785 |
\def\@genfrac#1#2#3#4#5{{#1{\begingroup#4\endgroup#2#3\relax#5}}} |
| 786 |
% \end{macrocode} |
| 787 |
% \end{macro} |
| 788 |
% |
| 789 |
% Empty mathstyle arg: no change; 0 = displaystyle, 1 = textstyle, 2 |
| 790 |
% = scriptstyle, 3 = scriptscriptstyle. |
| 791 |
% \begin{macrocode} |
| 792 |
\def\@mathstyle#1{% |
| 793 |
\ifx\@empty#1\@empty\relax |
| 794 |
\else\ifcase#1\displaystyle % case 0 |
| 795 |
\or\textstyle\or\scriptstyle\else\scriptscriptstyle\fi\fi} |
| 796 |
% \end{macrocode} |
| 797 |
% |
| 798 |
% \subsection{Sums and Integrals} |
| 799 |
% Default value for sum limits is \cs{displaylimits}, see option |
| 800 |
% `nosumlimits'. |
| 801 |
% |
| 802 |
% We redefine all the cumulative operator symbols to use |
| 803 |
% \cs{slimits@} so that switching between \cs{displaylimits} and |
| 804 |
% \cs{nolimits} can be controlled by package options. Also add |
| 805 |
% \cs{DOTSB} for the benefit of the dots lookahead. But we'd better |
| 806 |
% make sure \cn{coprod} and the others are simple mathchars; if not, |
| 807 |
% the attempted changes will probably fail miserably. |
| 808 |
% |
| 809 |
% \changes{v2.15}{2016/02/20}{Accept \cs{Umathchar}} |
| 810 |
% \begin{macrocode} |
| 811 |
\begingroup |
| 812 |
% \end{macrocode} |
| 813 |
% \begin{macrocode} |
| 814 |
\edef\@tempa{\string\mathchar"} |
| 815 |
\edef\@tempd{\string\Umathchar"} |
| 816 |
\def\@tempb#1"#2\@nil{#1"} |
| 817 |
\edef\@tempc{\expandafter\@tempb\meaning\coprod "\@nil} |
| 818 |
\ifx\@tempc\@tempd\let\@tempc\@tempa\fi |
| 819 |
% \end{macrocode} |
| 820 |
% \begin{macrocode} |
| 821 |
\ifx\@tempa\@tempc |
| 822 |
\global\let\coprod@\coprod |
| 823 |
\gdef\coprod{\DOTSB\coprod@\slimits@} |
| 824 |
\global\let\bigvee@\bigvee |
| 825 |
\gdef\bigvee{\DOTSB\bigvee@\slimits@} |
| 826 |
\global\let\bigwedge@\bigwedge |
| 827 |
\gdef\bigwedge{\DOTSB\bigwedge@\slimits@} |
| 828 |
\global\let\biguplus@\biguplus |
| 829 |
\gdef\biguplus{\DOTSB\biguplus@\slimits@} |
| 830 |
\global\let\bigcap@\bigcap |
| 831 |
\gdef\bigcap{\DOTSB\bigcap@\slimits@} |
| 832 |
\global\let\bigcup@\bigcup |
| 833 |
\gdef\bigcup{\DOTSB\bigcup@\slimits@} |
| 834 |
\global\let\prod@\prod |
| 835 |
\gdef\prod{\DOTSB\prod@\slimits@} |
| 836 |
\global\let\sum@\sum |
| 837 |
\gdef\sum{\DOTSB\sum@\slimits@} |
| 838 |
\global\let\bigotimes@\bigotimes |
| 839 |
\gdef\bigotimes{\DOTSB\bigotimes@\slimits@} |
| 840 |
\global\let\bigoplus@\bigoplus |
| 841 |
\gdef\bigoplus{\DOTSB\bigoplus@\slimits@} |
| 842 |
\global\let\bigodot@\bigodot |
| 843 |
\gdef\bigodot{\DOTSB\bigodot@\slimits@} |
| 844 |
\global\let\bigsqcup@\bigsqcup |
| 845 |
\gdef\bigsqcup{\DOTSB\bigsqcup@\slimits@} |
| 846 |
\fi |
| 847 |
\endgroup |
| 848 |
% \end{macrocode} |
| 849 |
% |
| 850 |
% \subsection{Roots and radicals} |
| 851 |
% |
| 852 |
% \begin{macro}{\root} |
| 853 |
% This root stuff needs syntax work and implementation work. Surely |
| 854 |
% something more compact can be done?? [mjd, 1994/09/05] |
| 855 |
% \begin{macrocode} |
| 856 |
\newcommand{\leftroot}{\@amsmath@err{\Invalid@@\leftroot}\@eha} |
| 857 |
\newcommand{\uproot}{\@amsmath@err{\Invalid@@\uproot}\@eha} |
| 858 |
\newcount\uproot@ |
| 859 |
\newcount\leftroot@ |
| 860 |
\renewcommand{\root}{\relaxnext@ |
| 861 |
\DN@{\ifx\@let@token\uproot\let\next@\nextii@\else |
| 862 |
\ifx\@let@token\leftroot\let\next@\nextiii@\else |
| 863 |
\let\next@\plainroot@\fi\fi\next@}% |
| 864 |
\def\nextii@\uproot##1{\uproot@##1\relax\FN@\nextiv@}% |
| 865 |
\def\nextiv@{\ifx\@let@token\@sptoken\DN@. {\FN@\nextv@}\else |
| 866 |
\DN@.{\FN@\nextv@}\fi\next@.}% |
| 867 |
\def\nextv@{\ifx\@let@token\leftroot\let\next@\nextvi@\else |
| 868 |
\let\next@\plainroot@\fi\next@}% |
| 869 |
\def\nextvi@\leftroot##1{\leftroot@##1\relax\plainroot@}% |
| 870 |
\def\nextiii@\leftroot##1{\leftroot@##1\relax\FN@\nextvii@}% |
| 871 |
\def\nextvii@{\ifx\@let@token\@sptoken |
| 872 |
\DN@. {\FN@\nextviii@}\else |
| 873 |
\DN@.{\FN@\nextviii@}\fi\next@.}% |
| 874 |
\def\nextviii@{\ifx\@let@token\uproot\let\next@\nextix@\else |
| 875 |
\let\next@\plainroot@\fi\next@}% |
| 876 |
\def\nextix@\uproot##1{\uproot@##1\relax\plainroot@}% |
| 877 |
\bgroup\uproot@\z@\leftroot@\z@\FN@\next@} |
| 878 |
\def\plainroot@#1\of#2{\setbox\rootbox\hbox{% |
| 879 |
$\m@th\scriptscriptstyle{#1}$}% |
| 880 |
\mathchoice{\r@@t\displaystyle{#2}}{\r@@t\textstyle{#2}} |
| 881 |
{\r@@t\scriptstyle{#2}}{\r@@t\scriptscriptstyle{#2}}\egroup} |
| 882 |
% \end{macrocode} |
| 883 |
% \end{macro} |
| 884 |
% |
| 885 |
% \changes{v2.0}{1999/06/17}{Normalize @@sqrt to sqrtsign} |
| 886 |
|
| 887 |
% Name change from \cs{@@sqrt} to \cs{sqrtsign} happened in the |
| 888 |
% 1995/12/01 release of \latex/. If we were to assume that |
| 889 |
% \cs{sqrtsign} is defined then someone with the 1995/06/01 release |
| 890 |
% of \latex/ would have trouble using this package. |
| 891 |
% \begin{macrocode} |
| 892 |
\@ifundefined{sqrtsign}{\let\sqrtsign\@@sqrt}{} |
| 893 |
\def\r@@t#1#2{\setboxz@h{$\m@th#1\sqrtsign{#2}$}% |
| 894 |
\dimen@\ht\z@\advance\dimen@-\dp\z@ |
| 895 |
\setbox\@ne\hbox{$\m@th#1\mskip\uproot@ mu$}% |
| 896 |
\advance\dimen@ by1.667\wd\@ne |
| 897 |
\mkern-\leftroot@ mu\mkern5mu\raise.6\dimen@\copy\rootbox |
| 898 |
\mkern-10mu\mkern\leftroot@ mu\boxz@} |
| 899 |
% \end{macrocode} |
| 900 |
% |
| 901 |
% \subsection{Et cetera} |
| 902 |
% |
| 903 |
% \changes{v2.0}{1999/06/18}{Leave Greek cap letters unaltered} |
| 904 |
% |
| 905 |
% Specific names for the variant italic cap Greek letters are not |
| 906 |
% defined by \latex/. If no preceding package defined these, we will |
| 907 |
% define them now. |
| 908 |
% \begin{macrocode} |
| 909 |
\@ifundefined{varGamma}{% |
| 910 |
\DeclareMathSymbol{\varGamma}{\mathord}{letters}{"00} |
| 911 |
\DeclareMathSymbol{\varDelta}{\mathord}{letters}{"01} |
| 912 |
\DeclareMathSymbol{\varTheta}{\mathord}{letters}{"02} |
| 913 |
\DeclareMathSymbol{\varLambda}{\mathord}{letters}{"03} |
| 914 |
\DeclareMathSymbol{\varXi}{\mathord}{letters}{"04} |
| 915 |
\DeclareMathSymbol{\varPi}{\mathord}{letters}{"05} |
| 916 |
\DeclareMathSymbol{\varSigma}{\mathord}{letters}{"06} |
| 917 |
\DeclareMathSymbol{\varUpsilon}{\mathord}{letters}{"07} |
| 918 |
\DeclareMathSymbol{\varPhi}{\mathord}{letters}{"08} |
| 919 |
\DeclareMathSymbol{\varPsi}{\mathord}{letters}{"09} |
| 920 |
\DeclareMathSymbol{\varOmega}{\mathord}{letters}{"0A} |
| 921 |
}{} |
| 922 |
% \end{macrocode} |
| 923 |
% |
| 924 |
% \begin{macro}{\overline} |
| 925 |
% \amstex/ redefines \cn{overline} as shown here, for reasons that |
| 926 |
% are probably less important in \latex/: Make it read its argument |
| 927 |
% as a macro argument rather than a ``math field'' (\emph{The |
| 928 |
% \tex/book}, Chapter 26), to avoid problems when something that is |
| 929 |
% apparently a single symbol is actually a non-simple macro (e.g., |
| 930 |
% \cn{dag}) \emph{and} is given as a single-token argument without |
| 931 |
% enclosing braces. |
| 932 |
% \begin{macrocode} |
| 933 |
\@saveprimitive\overline\@@overline |
| 934 |
\DeclareRobustCommand{\overline}[1]{\@@overline{#1}} |
| 935 |
% \end{macrocode} |
| 936 |
% \end{macro} |
| 937 |
% |
| 938 |
% \begin{macro}{\boxed} |
| 939 |
% The \cs{boxed} command is specifically intended to put a box around |
| 940 |
% an equation or piece of an equation. (Not including the equation |
| 941 |
% number.) This isn't trivial for end-users to do it properly |
| 942 |
% with \cs{fbox} so we provide a command for them. |
| 943 |
% \changes{v2.17n}{2022/04/08}{Make \cs{boxed} command robust (gh/123)} |
| 944 |
% \begin{macrocode} |
| 945 |
\DeclareRobustCommand{\boxed}[1]{\fbox{\m@th$\displaystyle#1$}} |
| 946 |
% \end{macrocode} |
| 947 |
% \end{macro} |
| 948 |
% |
| 949 |
% \begin{macro}{\implies} |
| 950 |
% \begin{macro}{\impliedby} |
| 951 |
% \begin{macrocode} |
| 952 |
\newcommand{\implies}{\DOTSB\;\Longrightarrow\;} |
| 953 |
\newcommand{\impliedby}{\DOTSB\;\Longleftarrow\;} |
| 954 |
% \end{macrocode} |
| 955 |
% \end{macro} |
| 956 |
% \end{macro} |
| 957 |
% |
| 958 |
% \begin{macro}{\And} |
| 959 |
% \begin{macrocode} |
| 960 |
\def\And{\DOTSB\;\mathchar"3026 \;} |
| 961 |
% \end{macrocode} |
| 962 |
% \end{macro} |
| 963 |
% |
| 964 |
% \begin{macro}{\nobreakdash} |
| 965 |
% The command \cn{nobreakdash} is designed only for use before a |
| 966 |
% hyphen or dash (|-|, |--|, or |---|). |
| 967 |
% Setting the hyphen in a box and then unboxing it means that the |
| 968 |
% normal penalty will not be added after it---and if the penalty is |
| 969 |
% not there a break will not be taken (unless an explicit penalty |
| 970 |
% or glue follows, thus the final \verb=\nobreak=). |
| 971 |
% \begin{macrocode} |
| 972 |
\newcommand{\nobreakdash}{\leavevmode |
| 973 |
\toks@\@emptytoks \def\@tempa##1{\toks@\@xp{\the\toks@-}\FN@\next@}% |
| 974 |
\DN@{\ifx\@let@token-\@xp\@tempa |
| 975 |
\else\setboxz@h{\the\toks@\nobreak}\unhbox\z@\fi}% |
| 976 |
\FN@\next@ |
| 977 |
} |
| 978 |
% \end{macrocode} |
| 979 |
% \end{macro} |
| 980 |
% |
| 981 |
% \begin{macro}{\colon} |
| 982 |
% \cs{colon} is for a colon in math that resembles a text colon: |
| 983 |
% small space on the left, larger space on the right. The \qc{\:} |
| 984 |
% character by itself is treated as a \cs{mathrel} i.e. large, equal |
| 985 |
% spacing on both sides. |
| 986 |
% \changes{v2.17n}{2022/04/08}{Make \cs{colon} command robust (gh/123)} |
| 987 |
% \begin{macrocode} |
| 988 |
\DeclareRobustCommand{\colon}{\nobreak\mskip2mu\mathpunct{}\nonscript |
| 989 |
\mkern-\thinmuskip{:}\mskip6muplus1mu\relax} |
| 990 |
% \end{macrocode} |
| 991 |
% \end{macro} |
| 992 |
% |
| 993 |
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 994 |
% \section{Ellipsis dots} |
| 995 |
% |
| 996 |
% We can't use \cs{newif} for \cs{ifgtest@} because we want |
| 997 |
% to include \cs{global} in the definitions of |
| 998 |
% \cs{gtest@true} and \cs{gtest@false}. |
| 999 |
% \begin{macrocode} |
| 1000 |
\let\ifgtest@\iffalse % initial value |
| 1001 |
\def\gtest@true{\global\let\ifgtest@\iftrue} |
| 1002 |
\def\gtest@false{\global\let\ifgtest@\iffalse} |
| 1003 |
\let\DOTSI\relax |
| 1004 |
\let\DOTSB\relax |
| 1005 |
\let\DOTSX\relax |
| 1006 |
{\uccode`7=`\\ \uccode`8=`m \uccode`9=`a \uccode`0=`t \uccode`!=`h |
| 1007 |
\uppercase{% |
| 1008 |
\gdef\math@#1#2#3#4#5#6\math@{\gtest@false\ifx 7#1\ifx 8#2% |
| 1009 |
\ifx 9#3\ifx 0#4\ifx !#5\xdef\meaning@{#6}\gtest@true |
| 1010 |
\fi\fi\fi\fi\fi}}} |
| 1011 |
{\uccode`7=`c \uccode`8=`h \uccode`9=`\" |
| 1012 |
\uppercase{\gdef\mathch@#1#2#3#4#5#6\mathch@{\gtest@false |
| 1013 |
\ifx 7#1\ifx 8#2\ifx 9#5\gtest@true\xdef\meaning@{9#6}\fi\fi\fi}}} |
| 1014 |
% \end{macrocode} |
| 1015 |
% \changes{v2.15}{2016/02/20}{Accept \cs{Umathchar}} |
| 1016 |
% \begin{macrocode} |
| 1017 |
{\uccode`(=`U \uccode`)=`m |
| 1018 |
\uppercase{\gdef\Umathch@#1#2#3#4"#5"#6\Umathch@{\gtest@false |
| 1019 |
\ifx(#2\ifx)#3\gtest@true |
| 1020 |
\ifcase"#5 \or\or\gdef\thedots@{\dotsb@}\or\gdef\thedots@{\dotsb@}\fi |
| 1021 |
\fi\fi |
| 1022 |
}}} |
| 1023 |
% \end{macrocode} |
| 1024 |
% \changes{v2.15}{2016/02/20}{Decode the mathcode of character tokens for Unicode TeX} |
| 1025 |
% 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. |
| 1026 |
% \begin{macrocode} |
| 1027 |
\ifx\Umathcharnumdef\@undefined |
| 1028 |
\gdef\thecharacter@#1\thecharacter@{} |
| 1029 |
\else |
| 1030 |
{\uccode`(=`t \uccode`)=`c |
| 1031 |
\uppercase{\gdef\thecharacter@#1#2#3#4#5\thecharacter@{% |
| 1032 |
\ifx(#1\ifx)#4% |
| 1033 |
\@xp\getmathcode@\meaning@\getmathcode@ |
| 1034 |
\fi\fi |
| 1035 |
}}} |
| 1036 |
\def\getmathcode@#1 #2 #3#4\getmathcode@{% |
| 1037 |
\Umathcharnumdef\@tempa\Umathcodenum`#3\relax |
| 1038 |
\edef\meaning@{\meaning\@tempa}% |
| 1039 |
\@xp\Umathch@\meaning@\Umathch@ |
| 1040 |
} |
| 1041 |
\fi |
| 1042 |
% \end{macrocode} |
| 1043 |
% \begin{macrocode} |
| 1044 |
\newcount\classnum@ |
| 1045 |
\def\getmathch@#1.#2\getmathch@{\classnum@#1 \divide\classnum@4096 |
| 1046 |
\ifcase\number\classnum@\or\or\gdef\thedots@{\dotsb@}\or |
| 1047 |
\gdef\thedots@{\dotsb@}\fi} |
| 1048 |
{\uccode`4=`b \uccode`5=`i \uccode`6=`n |
| 1049 |
\uppercase{\gdef\mathbin@#1#2#3{\relaxnext@ |
| 1050 |
\def\nextii@##1\mathbin@{\ifx\@sptoken\@let@token\gtest@true\fi}% |
| 1051 |
\gtest@false\DN@##1\mathbin@{}% |
| 1052 |
\ifx 4#1\ifx 5#2\ifx 6#3\DN@{\FN@\nextii@}\fi\fi\fi\next@}}} |
| 1053 |
{\uccode`4=`r \uccode`5=`e \uccode`6=`l |
| 1054 |
\uppercase{\gdef\mathrel@#1#2#3{\relaxnext@ |
| 1055 |
\def\nextii@##1\mathrel@{\ifx\@sptoken\@let@token\gtest@true\fi}% |
| 1056 |
\gtest@false\DN@##1\mathrel@{}% |
| 1057 |
\ifx 4#1\ifx 5#2\ifx 6#3\DN@{\FN@\nextii@}\fi\fi\fi\next@}}} |
| 1058 |
{\uccode`5=`m \uccode`6=`a \uccode`7=`c |
| 1059 |
\uppercase{\gdef\macro@#1#2#3#4\macro@{\gtest@false |
| 1060 |
\ifx 5#1\ifx 6#2\ifx 7#3\gtest@true |
| 1061 |
\xdef\meaning@{\macro@@#4\macro@@}\fi\fi\fi}}} |
| 1062 |
\def\macro@@#1->#2\macro@@{#2} |
| 1063 |
\newcount\DOTSCASE@ |
| 1064 |
{\uccode`6=`\\ \uccode`7=`D \uccode`8=`O \uccode`9=`T \uccode`0=`S |
| 1065 |
\uppercase{\gdef\DOTS@#1#2#3#4#5{\gtest@false\DN@##1\DOTS@{}% |
| 1066 |
\ifx 6#1\ifx 7#2\ifx 8#3\ifx 9#4\ifx 0#5\let\next@\DOTS@@ |
| 1067 |
\fi\fi\fi\fi\fi |
| 1068 |
\next@}}} |
| 1069 |
{\uccode`3=`B \uccode`4=`I \uccode`5=`X |
| 1070 |
\uppercase{\gdef\DOTS@@#1{\relaxnext@ |
| 1071 |
\def\nextii@##1\DOTS@{\ifx\@sptoken\@let@token\gtest@true\fi}% |
| 1072 |
\DN@{\FN@\nextii@}% |
| 1073 |
\ifx 3#1\global\DOTSCASE@\z@\else |
| 1074 |
\ifx 4#1\global\DOTSCASE@\@ne\else |
| 1075 |
\ifx 5#1\global\DOTSCASE@\tw@\else\DN@##1\DOTS@{}% |
| 1076 |
\fi\fi\fi\next@}}} |
| 1077 |
{\uccode`5=`\\ \uccode`6=`n \uccode`7=`o \uccode`8=`t |
| 1078 |
\uppercase{\gdef\not@#1#2#3#4{\relaxnext@ |
| 1079 |
\def\nextii@##1\not@{\ifx\@sptoken\@let@token\gtest@true\fi}% |
| 1080 |
\gtest@false\DN@##1\not@{}% |
| 1081 |
\ifx 5#1\ifx 6#2\ifx 7#3\ifx 8#4\DN@{\FN@\nextii@}\fi\fi\fi |
| 1082 |
\fi\next@}}} |
| 1083 |
% \end{macrocode} |
| 1084 |
% \changes{v2.15}{2016/02/20}{macro added to strip \cs{long} during tests} |
| 1085 |
% \begin{macrocode} |
| 1086 |
{\uccode`9=`\l % |
| 1087 |
\uppercase{\gdef\striplong@#1#2#3\relax{% |
| 1088 |
\ifx9#2 \@xp\@xp\@xp\zap@to@space\fi}}} |
| 1089 |
\def\zap@to@space#1 {} |
| 1090 |
% \end{macrocode} |
| 1091 |
% \begin{macrocode} |
| 1092 |
\def\keybin@{\gtest@true |
| 1093 |
\ifx\@let@token+\else\ifx\@let@token=\else |
| 1094 |
\ifx\@let@token<\else\ifx\@let@token>\else |
| 1095 |
\ifx\@let@token-\else\ifx\@let@token*\else\ifx\@let@token:\else |
| 1096 |
\gtest@false\fi\fi\fi\fi\fi\fi\fi} |
| 1097 |
% \end{macrocode} |
| 1098 |
% Patch to ensure \cs{@ldots} is defined. (Name changed to |
| 1099 |
% \cn{mathellipsis} in Dec 94 release of \latex/.) |
| 1100 |
% \begin{macrocode} |
| 1101 |
\@ifundefined{@ldots}{\def\@ldots{\mathellipsis}}{} |
| 1102 |
% \end{macrocode} |
| 1103 |
% \begin{macro}{\ldots} |
| 1104 |
% \begin{macro}{\dots} |
| 1105 |
% Reiterate the standard definition of \cs{ldots} to keep it from |
| 1106 |
% being clobbered by the redefinition of \cs{dots}. |
| 1107 |
% \begin{macrocode} |
| 1108 |
\DeclareRobustCommand{\ldots}{% |
| 1109 |
\ifmmode \mathellipsis \else \textellipsis \fi |
| 1110 |
} |
| 1111 |
\DeclareRobustCommand{\dots}{% |
| 1112 |
\ifmmode \@xp\mdots@\else \@xp\textellipsis \fi |
| 1113 |
} |
| 1114 |
% \end{macrocode} |
| 1115 |
% \end{macro} |
| 1116 |
% \end{macro} |
| 1117 |
% \begin{macrocode} |
| 1118 |
\def\tdots@{\leavevmode\unskip\relaxnext@ |
| 1119 |
\DN@{$\m@th\@ldots\, |
| 1120 |
\ifx\@let@token,\,$\else\ifx\@let@token.\,$\else |
| 1121 |
\ifx\@let@token;\,$\else\ifx\@let@token:\,$\else |
| 1122 |
\ifx\@let@token?\,$\else\ifx\@let@token!\,$\else |
| 1123 |
$ \fi\fi\fi\fi\fi\fi}% |
| 1124 |
\ \FN@\next@} |
| 1125 |
\def\mdots@{\FN@\mdots@@} |
| 1126 |
% \end{macrocode} |
| 1127 |
% \changes{v2.15}{2016/02/20}{Indent \cs{mdots@@} for readability and add additional tests} |
| 1128 |
% \begin{macrocode} |
| 1129 |
\def\mdots@@{\gdef\thedots@{\dotso@}% |
| 1130 |
\ifx\@let@token\boldsymbol |
| 1131 |
\gdef\thedots@\boldsymbol{\boldsymboldots@}% |
| 1132 |
\else |
| 1133 |
\ifx,\@let@token \gdef\thedots@{\dotsc}% |
| 1134 |
\else |
| 1135 |
\ifx\not\@let@token |
| 1136 |
\gdef\thedots@{\dotsb@}% |
| 1137 |
\else |
| 1138 |
\keybin@ |
| 1139 |
\ifgtest@ % if \keybin@ test |
| 1140 |
\gdef\thedots@{\dotsb@}% |
| 1141 |
\else |
| 1142 |
% \end{macrocode} |
| 1143 |
% \changes{v2.15d}{2016/06/28}{Add space token to prevent runaway argument error} |
| 1144 |
% \begin{macrocode} |
| 1145 |
\xdef\meaning@{\meaning\@let@token. .........}% |
| 1146 |
% \end{macrocode} |
| 1147 |
% In previous versions \verb|\long| macros were not seen by the lokkahead. |
| 1148 |
% That was bad as this file uses \verb|\(re)newcommand| for \verb|\implies| etc. |
| 1149 |
% \begin{macrocode} |
| 1150 |
\xdef\meaning@@{\@xp\striplong@\meaning@\relax\meaning@}% |
| 1151 |
% \end{macrocode} |
| 1152 |
% \begin{macrocode} |
| 1153 |
\@xp\math@\meaning@\math@ |
| 1154 |
\ifgtest@ % if \mathxxx test |
| 1155 |
\@xp\mathch@\meaning@\mathch@ |
| 1156 |
\ifgtest@ % if \mathchar |
| 1157 |
\@xp\getmathch@\meaning@\getmathch@ |
| 1158 |
\fi % end if \mathchar |
| 1159 |
\else % \not \mathxxx |
| 1160 |
% \end{macrocode} |
| 1161 |
% Test for \verb|\Umathchar| added. |
| 1162 |
% \begin{macrocode} |
| 1163 |
\@xp\Umathch@\meaning@"0"\Umathch@ |
| 1164 |
\ifgtest@ % if \Umathchar |
| 1165 |
\else % else not \Umathchar |
| 1166 |
% \end{macrocode} |
| 1167 |
% \begin{macrocode} |
| 1168 |
\@xp\macro@\meaning@@\macro@ |
| 1169 |
\ifgtest@ % if macro test |
| 1170 |
\@xp\not@\meaning@\not@ |
| 1171 |
\ifgtest@ % if macro starts \not test |
| 1172 |
\gdef\thedots@{\dotsb@}% |
| 1173 |
\else% else not \not |
| 1174 |
\@xp\DOTS@\meaning@\DOTS@ |
| 1175 |
\ifgtest@ % \if DOTS |
| 1176 |
\ifcase\number\DOTSCASE@ %ifcase dots |
| 1177 |
\gdef\thedots@{\dotsb@}% |
| 1178 |
\or\gdef\thedots@{\dotsi}\else |
| 1179 |
\fi % endifcase dots |
| 1180 |
\else % not macro starts \DOTS |
| 1181 |
\@xp\math@\meaning@\math@ |
| 1182 |
\ifgtest@ % \if macro starts \mathxxxx |
| 1183 |
\@xp\mathbin@\meaning@\mathbin@ |
| 1184 |
\ifgtest@ % if macro starts \mathbin |
| 1185 |
\gdef\thedots@{\dotsb@}% |
| 1186 |
\else % not macro starting \mathbin |
| 1187 |
\@xp\mathrel@\meaning@\mathrel@ |
| 1188 |
\ifgtest@ % if macro starts \mathrel |
| 1189 |
\gdef\thedots@{\dotsb@}% |
| 1190 |
\fi % endif macro starts \mathrel (no else) |
| 1191 |
\fi % endif macro starts \mathbin |
| 1192 |
\fi % endif macro starts with \mathxxx (no else) |
| 1193 |
\fi % endif macro starts \DOTS else |
| 1194 |
\fi % end macro starting \not \ifgtest@ test (no else) |
| 1195 |
% \end{macrocode} |
| 1196 |
% Additional test for a catcode 12 character. |
| 1197 |
% \begin{macrocode} |
| 1198 |
\else |
| 1199 |
\@xp\thecharacter@\meaning@\thecharacter@ |
| 1200 |
% \end{macrocode} |
| 1201 |
% \begin{macrocode} |
| 1202 |
\fi % end macro \ifgtest@ test (no else) |
| 1203 |
\fi % end if \Umathchar test |
| 1204 |
\fi % end \math@ \ifgtest@ |
| 1205 |
\fi % end \keybin@ \ifgtest@ test (no else) |
| 1206 |
\fi % end if \not (no else) |
| 1207 |
\fi % end if comma (no else) |
| 1208 |
\fi % end if boldsymbol (no else) |
| 1209 |
\thedots@} |
| 1210 |
% \end{macrocode} |
| 1211 |
% |
| 1212 |
% The \qc{\=} character is necessary in the two \cs{let} assignments |
| 1213 |
% in \cs{boldsymboldots@}, because the symbol we are making |
| 1214 |
% bold might be an \qc{\=} sign. |
| 1215 |
% \begin{macrocode} |
| 1216 |
\def\boldsymboldots@#1{% |
| 1217 |
\bold@true\let\@let@token=#1\let\delayed@=#1\mdots@@ |
| 1218 |
\boldsymbol#1\bold@false} |
| 1219 |
% \end{macrocode} |
| 1220 |
% |
| 1221 |
% The definition of \cs{@cdots} is merely the \fn{plain.tex} |
| 1222 |
% definition of \cs{cdots}. |
| 1223 |
% \begin{macrocode} |
| 1224 |
\ams@def\@cdots{\mathinner{\cdotp\cdotp\cdotp}} |
| 1225 |
\newcommand{\dotsi}{\!\@cdots} |
| 1226 |
\let\dotsb@\@cdots |
| 1227 |
% \end{macrocode} |
| 1228 |
% |
| 1229 |
% If any new right delimiters are defined, they would need to be |
| 1230 |
% added to the definition of \cs{rightdelim@} in order for \cn{dots} |
| 1231 |
% to work properly in all cases. |
| 1232 |
% \begin{macrocode} |
| 1233 |
\def\rightdelim@{\gtest@true |
| 1234 |
\ifx\@let@token)\else |
| 1235 |
\ifx\@let@token]\else |
| 1236 |
\ifx\@let@token\rbrack\else |
| 1237 |
\ifx\@let@token\}\else |
| 1238 |
\ifx\@let@token\rbrace\else |
| 1239 |
\ifx\@let@token\rangle\else |
| 1240 |
\ifx\@let@token\rceil\else |
| 1241 |
\ifx\@let@token\rfloor\else |
| 1242 |
\ifx\@let@token\rgroup\else |
| 1243 |
\ifx\@let@token\rmoustache\else |
| 1244 |
\ifx\@let@token\right\else |
| 1245 |
\ifx\@let@token\bigr\else |
| 1246 |
\ifx\@let@token\biggr\else |
| 1247 |
\ifx\@let@token\Bigr\else |
| 1248 |
\ifx\@let@token\Biggr\else\gtest@false |
| 1249 |
\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi} |
| 1250 |
\def\extra@{% |
| 1251 |
\rightdelim@\ifgtest@ |
| 1252 |
\else\ifx\@let@token$\gtest@true |
| 1253 |
\else\xdef\meaning@{\meaning\@let@token..........}% |
| 1254 |
\@xp\macro@\meaning@\macro@\ifgtest@ |
| 1255 |
\@xp\DOTS@\meaning@\DOTS@ |
| 1256 |
\ifgtest@ |
| 1257 |
\ifnum\DOTSCASE@=\tw@\gtest@true\else\gtest@false |
| 1258 |
\fi\fi\fi\fi\fi} |
| 1259 |
\newif\ifbold@ |
| 1260 |
\def\dotso@{\relaxnext@ |
| 1261 |
\ifbold@ |
| 1262 |
\let\@let@token\delayed@ |
| 1263 |
\def\nextii@{\extra@\@ldots\ifgtest@\,\fi}% |
| 1264 |
\else |
| 1265 |
\def\nextii@{\DN@{\extra@\@ldots\ifgtest@\,\fi}\FN@\next@}% |
| 1266 |
\fi |
| 1267 |
\nextii@} |
| 1268 |
% \end{macrocode} |
| 1269 |
% Why not save some tokens? (space vs. time). |
| 1270 |
% \begin{macrocode} |
| 1271 |
\def\extrap@#1{% |
| 1272 |
\DN@{#1\,}% |
| 1273 |
\ifx\@let@token,\else |
| 1274 |
\ifx\@let@token;\else |
| 1275 |
\ifx\@let@token.\else\extra@ |
| 1276 |
\ifgtest@\else |
| 1277 |
\let\next@#1\fi\fi\fi\fi\next@} |
| 1278 |
% \end{macrocode} |
| 1279 |
% |
| 1280 |
% \begin{macro}{\cdots} |
| 1281 |
% \begin{macro}{\dotsb} |
| 1282 |
% \begin{macro}{\dotsm} |
| 1283 |
% \begin{macro}{\dotso} |
| 1284 |
% \begin{macro}{\dotsc} |
| 1285 |
% The \cn{cdots} command. |
| 1286 |
% \begin{macrocode} |
| 1287 |
\ams@DeclareRobustCommand{\cdots}{\DN@{\extrap@\@cdots}\FN@\next@} |
| 1288 |
\let\dotsb\cdots |
| 1289 |
\let\dotsm\cdots |
| 1290 |
\DeclareRobustCommand{\dotso}{\relax |
| 1291 |
\ifmmode \DN@{\extrap@\@ldots}% |
| 1292 |
\else \let\next@\tdots@\fi |
| 1293 |
\FN@\next@} |
| 1294 |
\DeclareRobustCommand{\dotsc}{% |
| 1295 |
\DN@{\ifx\@let@token;\@ldots\,% |
| 1296 |
\else \ifx\@let@token.\@ldots\,% |
| 1297 |
\else \extra@\@ldots \ifgtest@\,\fi |
| 1298 |
\fi\fi}% |
| 1299 |
\FN@\next@} |
| 1300 |
% \end{macrocode} |
| 1301 |
% \end{macro} |
| 1302 |
% \end{macro} |
| 1303 |
% \end{macro} |
| 1304 |
% \end{macro} |
| 1305 |
% \end{macro} |
| 1306 |
% \begin{macro}{\longrightarrow} |
| 1307 |
% \begin{macro}{\Longrightarrow} |
| 1308 |
% \begin{macro}{\longleftarrow} |
| 1309 |
% \begin{macro}{\Longleftarrow} |
| 1310 |
% \begin{macro}{\longleftrightarrow} |
| 1311 |
% \begin{macro}{\Longleftrightarrow} |
| 1312 |
% \begin{macro}{\mapsto} |
| 1313 |
% \begin{macro}{\longmapsto} |
| 1314 |
% \begin{macro}{\hookrightarrow} |
| 1315 |
% \begin{macro}{\hookleftarrow} |
| 1316 |
% \begin{macro}{\iff} |
| 1317 |
% Various arrows. |
| 1318 |
% \begin{macrocode} |
| 1319 |
\renewcommand{\longrightarrow}{% |
| 1320 |
\DOTSB\protect\relbar\protect\joinrel\rightarrow} |
| 1321 |
\renewcommand{\Longrightarrow}{% |
| 1322 |
\DOTSB\protect\Relbar\protect\joinrel\Rightarrow} |
| 1323 |
\renewcommand{\longleftarrow}{% |
| 1324 |
\DOTSB\leftarrow\protect\joinrel\protect\relbar} |
| 1325 |
\renewcommand{\Longleftarrow}{% |
| 1326 |
\DOTSB\Leftarrow\protect\joinrel\protect\Relbar} |
| 1327 |
\renewcommand{\longleftrightarrow}{\DOTSB\leftarrow\joinrel\rightarrow} |
| 1328 |
\renewcommand{\Longleftrightarrow}{\DOTSB\Leftarrow\joinrel\Rightarrow} |
| 1329 |
\renewcommand{\mapsto}{\DOTSB\mapstochar\rightarrow} |
| 1330 |
\renewcommand{\longmapsto}{\DOTSB\mapstochar\longrightarrow} |
| 1331 |
\renewcommand{\hookrightarrow}{\DOTSB\lhook\joinrel\rightarrow} |
| 1332 |
\renewcommand{\hookleftarrow}{\DOTSB\leftarrow\joinrel\rhook} |
| 1333 |
\renewcommand{\iff}{\DOTSB\;\Longleftrightarrow\;} |
| 1334 |
% \end{macrocode} |
| 1335 |
% \end{macro} |
| 1336 |
% \end{macro} |
| 1337 |
% \end{macro} |
| 1338 |
% \end{macro} |
| 1339 |
% \end{macro} |
| 1340 |
% \end{macro} |
| 1341 |
% \end{macro} |
| 1342 |
% \end{macro} |
| 1343 |
% \end{macro} |
| 1344 |
% \end{macro} |
| 1345 |
% \end{macro} |
| 1346 |
% \begin{macro}{\doteq} |
| 1347 |
% The \cn{doteq} command formerly used \cs{buildrel}; we avoid that |
| 1348 |
% because it requires `\cn{over}' as part of its syntax. Use 0pt |
| 1349 |
% instead of \cs{z@} for robustitude. |
| 1350 |
% \begin{macrocode} |
| 1351 |
\renewcommand{\doteq}{% |
| 1352 |
\DOTSB\mathrel{\mathop{\kern0pt =}\limits^{\textstyle.}}} |
| 1353 |
% \end{macrocode} |
| 1354 |
% \end{macro} |
| 1355 |
% |
| 1356 |
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1357 |
% \section{Integral signs} |
| 1358 |
% |
| 1359 |
% \begin{macro}{\if@display} |
| 1360 |
% The straightforward \cs{ifinner} test to see if the current math |
| 1361 |
% context is non-display, fails if, for instance, we are typesetting |
| 1362 |
% a multiline display within an \cs{halign}, with the pieces going |
| 1363 |
% into constructions like |
| 1364 |
% \begin{verbatim} |
| 1365 |
% $\displaystyle...$ |
| 1366 |
% \end{verbatim} |
| 1367 |
% So we need a better test to find out if we are `in a display'. We |
| 1368 |
% therefore create \cs{if@display}. |
| 1369 |
% |
| 1370 |
% \begin{macrocode} |
| 1371 |
\newif\if@display |
| 1372 |
\everydisplay\@xp{\the\everydisplay \@displaytrue} |
| 1373 |
% \end{macrocode} |
| 1374 |
% \end{macro} |
| 1375 |
% |
| 1376 |
% \begin{macro}{\int} |
| 1377 |
% \begin{macro}{\oint} |
| 1378 |
% \begin{macro}{\iint} |
| 1379 |
% \begin{macro}{\iiint} |
| 1380 |
% \begin{macro}{\iiiint} |
| 1381 |
% \begin{macro}{\idotsint} |
| 1382 |
% Default value for integral limits is \cs{nolimits}, see the |
| 1383 |
% definition of the `nointlimits' option. |
| 1384 |
% \begin{macrocode} |
| 1385 |
\renewcommand{\int}{\DOTSI\intop\ilimits@} |
| 1386 |
\renewcommand{\oint}{\DOTSI\ointop\ilimits@} |
| 1387 |
\def\intkern@{\mkern-6mu\mathchoice{\mkern-3mu}{}{}{}} |
| 1388 |
\def\intdots@{\mathchoice{\@cdots}% |
| 1389 |
{{\cdotp}\mkern1.5mu{\cdotp}\mkern1.5mu{\cdotp}}% |
| 1390 |
{{\cdotp}\mkern1mu{\cdotp}\mkern1mu{\cdotp}}% |
| 1391 |
{{\cdotp}\mkern1mu{\cdotp}\mkern1mu{\cdotp}}} |
| 1392 |
% |
| 1393 |
\ams@newcommand{\iint}{\DOTSI\MultiIntegral{2}} |
| 1394 |
\ams@newcommand{\iiint}{\DOTSI\MultiIntegral{3}} |
| 1395 |
\ams@newcommand{\iiiint}{\DOTSI\MultiIntegral{4}} |
| 1396 |
\newcommand{\idotsint}{\DOTSI\MultiIntegral{0}} |
| 1397 |
% \end{macrocode} |
| 1398 |
% \end{macro} |
| 1399 |
% \end{macro} |
| 1400 |
% \end{macro} |
| 1401 |
% \end{macro} |
| 1402 |
% \end{macro} |
| 1403 |
% \end{macro} |
| 1404 |
% |
| 1405 |
% \begin{macro}{\MultiIntegral} |
| 1406 |
% If the \cs{limits} option is applied, use \cs{mathop} and fudge |
| 1407 |
% the left-hand space a bit to make the subscript visually centered. |
| 1408 |
% |
| 1409 |
% \verb'#1' is the multiplicity. |
| 1410 |
% \changes{v2.17n}{2022/04/08}{Make \cs{MultiIntegral} command robust (gh/123)} |
| 1411 |
% \begin{macrocode} |
| 1412 |
\DeclareRobustCommand{\MultiIntegral}[1]{% |
| 1413 |
\edef\ints@c{\noexpand\intop |
| 1414 |
\ifnum#1=\z@\noexpand\intdots@\else\noexpand\intkern@\fi |
| 1415 |
\ifnum#1>\tw@\noexpand\intop\noexpand\intkern@\fi |
| 1416 |
\ifnum#1>\thr@@\noexpand\intop\noexpand\intkern@\fi |
| 1417 |
\noexpand\intop |
| 1418 |
\noexpand\ilimits@ |
| 1419 |
}% |
| 1420 |
\futurelet\@let@token\ints@a |
| 1421 |
} |
| 1422 |
% \end{macrocode} |
| 1423 |
% \end{macro} |
| 1424 |
% |
| 1425 |
% \begin{macrocode} |
| 1426 |
\def\ints@a{% |
| 1427 |
\ifx\limits\@let@token \ints@b |
| 1428 |
\else \ifx\displaylimits\@let@token \ints@b |
| 1429 |
\else\ifx\ilimits@\displaylimits \ints@b |
| 1430 |
\fi\fi\fi |
| 1431 |
\ints@c |
| 1432 |
} |
| 1433 |
% \end{macrocode} |
| 1434 |
% |
| 1435 |
% \begin{macrocode} |
| 1436 |
\def\ints@b{% |
| 1437 |
\mkern-7mu\mathchoice{\mkern-2mu}{}{}{}% |
| 1438 |
\mathop\bgroup |
| 1439 |
\mkern7mu\mathchoice{\mkern2mu}{}{}{}% |
| 1440 |
\let\ilimits@\egroup |
| 1441 |
}% |
| 1442 |
% \end{macrocode} |
| 1443 |
% |
| 1444 |
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1445 |
% \section{Size dependent definitions} |
| 1446 |
% |
| 1447 |
% We now define all stuff which has to change whenever a new math |
| 1448 |
% size is to be activated. \latex/ provides a hook called |
| 1449 |
% |\every@math@size| to support such a need. All assignments in the |
| 1450 |
% |\every@math@size| hook that need to take outside effect should be |
| 1451 |
% global. |
| 1452 |
% |
| 1453 |
% \subsection{Struts for math} |
| 1454 |
% |
| 1455 |
% The various kinds of struts could use some analysis and perhaps |
| 1456 |
% consolidation. |
| 1457 |
% |
| 1458 |
% For example perhaps the \cn{bBigg} delimiters could use |
| 1459 |
% \begin{verbatim} |
| 1460 |
% 1.2\ht\strutbox (1.8, 2.4, 3.0) |
| 1461 |
% \end{verbatim} |
| 1462 |
% instead of |
| 1463 |
% \begin{verbatim} |
| 1464 |
% 1.0\big@size (1.5, 2.0, 2.5) |
| 1465 |
% \end{verbatim} |
| 1466 |
% since \cs{strut} is reset with every size change [mjd, 1994/10/07]. |
| 1467 |
% But this change would introduce the possibility of changed line |
| 1468 |
% and page breaks in existing documents, so would need to be |
| 1469 |
% handled with care. |
| 1470 |
% |
| 1471 |
% \begin{macro}{\Mathstrut@} |
| 1472 |
% \begin{macro}{\Mathstrutbox@} |
| 1473 |
% \begin{macro}{\resetMathstrut@} |
| 1474 |
% Here comes the code for Spivak's |\Mathstrut@|. |
| 1475 |
% \begin{macrocode} |
| 1476 |
\newbox\Mathstrutbox@ |
| 1477 |
\setbox\Mathstrutbox@=\hbox{} |
| 1478 |
\def\Mathstrut@{\copy\Mathstrutbox@} |
| 1479 |
% \end{macrocode} |
| 1480 |
% The setting of the height and depth of the |\Mathstrutbox@| is done |
| 1481 |
% in the |\every@math@size| hook since it depends on the height of a |
| 1482 |
% paren. As \cs{every@math@size} is triggered by |$| after a font |
| 1483 |
% size change, we want to avoid using another math formula |$...$| to |
| 1484 |
% measure the math paren height; instead we go through the mathcode |
| 1485 |
% of the \qc{\(} character. We assume that the mathcode has a leading |
| 1486 |
% hex digit 4 indicating `open delimiter'; this allows us to make a |
| 1487 |
% relatively simple function to get the correct font and character |
| 1488 |
% position. |
| 1489 |
% |
| 1490 |
% \changes{v2.15}{2016/02/20}{Modify \cs{resetMathstrut@} for Unicode \TeX} |
| 1491 |
% \changes{v2.15b}{2016/03/10}{Modify \cs{resetMathstrut@} for classic \TeX\ to preserve box 0} |
| 1492 |
% Original code assuming |\mathcode| is kept for 8bit \TeX. Unicode \TeX{} |
| 1493 |
% uses |\Umathcharnumdef| which works for xetex and luatex, which use |
| 1494 |
% different forms for |\mathchardef|. (New luatex always reports |
| 1495 |
% definitions using |\Umathchardef| syntax even if |\mathchardef| used.) |
| 1496 |
% |
| 1497 |
% The unicode version uses e-tex |\fontcharht| to avoid boxing which |
| 1498 |
% could also be done for pdftex, but not done here. |
| 1499 |
% \begin{macrocode} |
| 1500 |
\ifx\Umathcharnumdef\@undefined |
| 1501 |
% \end{macrocode} |
| 1502 |
% Original code |
| 1503 |
% \begin{macrocode} |
| 1504 |
\def\resetMathstrut@{% |
| 1505 |
\begingroup |
| 1506 |
\setbox\z@\hbox{% |
| 1507 |
\mathchardef\@tempa\mathcode`\(\relax |
| 1508 |
\def\@tempb##1"##2##3{\the\textfont"##3\char"}% |
| 1509 |
\expandafter\@tempb\meaning\@tempa \relax |
| 1510 |
}% |
| 1511 |
\edef\@tempa{% |
| 1512 |
\ht\Mathstrutbox@\the\ht\z@\relax |
| 1513 |
\dp\Mathstrutbox@\the\dp\z@\relax}% |
| 1514 |
\expandafter\endgroup\@tempa |
| 1515 |
} |
| 1516 |
\else |
| 1517 |
% \end{macrocode} |
| 1518 |
% xetex/luatex version |
| 1519 |
% \changes{v2.15a}{2016/03/03}{missing percent added} |
| 1520 |
% \begin{macrocode} |
| 1521 |
\def\resetMathstrut@{% |
| 1522 |
\begingroup |
| 1523 |
\Umathcharnumdef\@tempa\Umathcodenum`\(\relax |
| 1524 |
\def\@tempb##1"##2"##3"##4\relax{% |
| 1525 |
\endgroup |
| 1526 |
\ht\Mathstrutbox@=\fontcharht\textfont"##3 "##4\relax |
| 1527 |
\dp\Mathstrutbox@=\fontchardp\textfont"##3 "##4\relax}% |
| 1528 |
\expandafter\@tempb\meaning\@tempa \relax |
| 1529 |
} |
| 1530 |
% \end{macrocode} |
| 1531 |
% \begin{macrocode} |
| 1532 |
\fi |
| 1533 |
% \end{macrocode} |
| 1534 |
% These height and depth assignments are implicitly global. |
| 1535 |
% \begin{macrocode} |
| 1536 |
\addto@hook\every@math@size{\resetMathstrut@} |
| 1537 |
% \end{macrocode} |
| 1538 |
% \end{macro} |
| 1539 |
% \end{macro} |
| 1540 |
% \end{macro} |
| 1541 |
% |
| 1542 |
% \begin{macro}{\strut@} |
| 1543 |
% \begin{macro}{\strutbox@} |
| 1544 |
% Next follows a special internal strut which is supposed to match |
| 1545 |
% the height and the depth of a normal |\strut| minus |
| 1546 |
% |\normallineskiplimit| according to M. Spivak. |
| 1547 |
% |
| 1548 |
% This should really go into the definition of \cs{size@update}, and |
| 1549 |
% then the box reset could be local; but \cs{size@update} doesn't |
| 1550 |
% have any hook and is handled in such a way that it cannot even be |
| 1551 |
% changed except by changing \cs{set@fontsize}. So instead we put |
| 1552 |
% \cs{reset@strutbox@} into \cs{every@math@size} and make it global. |
| 1553 |
% Then because of some complications in the way \cs{glb@settings} and |
| 1554 |
% \cs{check@mathfonts} work, we have to re-invoke it at the beginning |
| 1555 |
% of every environment that might use \cs{strut@}. Fortunately this |
| 1556 |
% can be achieved (more or less) through the \cs{spread@equation} |
| 1557 |
% hook. [mjd,2000/03/10] |
| 1558 |
% \begin{macrocode} |
| 1559 |
\newbox\strutbox@ |
| 1560 |
\def\strut@{\copy\strutbox@} |
| 1561 |
\def\reset@strutbox@{% |
| 1562 |
\global\setbox\strutbox@\hbox{% |
| 1563 |
\lower.5\normallineskiplimit |
| 1564 |
\vbox{\kern-\normallineskiplimit\copy\strutbox}}} |
| 1565 |
\addto@hook\every@math@size{\reset@strutbox@} |
| 1566 |
\AtBeginDocument{\reset@strutbox@} |
| 1567 |
% \end{macrocode} |
| 1568 |
% \end{macro} |
| 1569 |
% \end{macro} |
| 1570 |
% |
| 1571 |
% \subsection{Big delimiters} |
| 1572 |
% |
| 1573 |
% We are now going to redefine the plain \tex/ commands \cn{big}, |
| 1574 |
% \cn{bigl}, etc., to produce different results in different sizes. |
| 1575 |
% Actually we only have to define \cn{big}, \cn{Big}, etc., since |
| 1576 |
% they are used to construct the directional versions \cn{bigl}, |
| 1577 |
% \cn{bigr}, and the rest. |
| 1578 |
% |
| 1579 |
% \begin{macro}{\big} |
| 1580 |
% \begin{macro}{\Big} |
| 1581 |
% \begin{macro}{\bigg} |
| 1582 |
% \begin{macro}{\Bigg} |
| 1583 |
% To save token space we put everything into the common macro |
| 1584 |
% |\bBigg@|. The macros are now simply a call to |\bBigg@| with a |
| 1585 |
% factor to determine the correct height of the delimiter as an |
| 1586 |
% argument. This code should better go into a future version of |
| 1587 |
% the \latex/ kernel; the macro |\n@space| is then superfluous (since |
| 1588 |
% it is only used once) and should be removed to avoid wasting hash |
| 1589 |
% table space unnecessarily. |
| 1590 |
% \changes{v2.17n}{2022/04/08}{Make biggg commands robust (gh/123)} |
| 1591 |
% \begin{macrocode} |
| 1592 |
\DeclareRobustCommand{\big}{\bBigg@\@ne} |
| 1593 |
\DeclareRobustCommand{\Big}{\bBigg@{1.5}} |
| 1594 |
\DeclareRobustCommand{\bigg}{\bBigg@\tw@} |
| 1595 |
\DeclareRobustCommand{\Bigg}{\bBigg@{2.5}} |
| 1596 |
% \end{macrocode} |
| 1597 |
% \end{macro} |
| 1598 |
% \end{macro} |
| 1599 |
% \end{macro} |
| 1600 |
% \end{macro} |
| 1601 |
% |
| 1602 |
% \begin{macro}{\bBigg@} |
| 1603 |
% Now we tackle the macro which has to do the real work. It |
| 1604 |
% actually has two arguments, the factor and the wanted delimiter. |
| 1605 |
% \changes{v2.17b}{2018/12/01}{Start LR-mode for \cs{bigl} and |
| 1606 |
% friends if necessary (github/49)} |
| 1607 |
% \begin{macrocode} |
| 1608 |
\ifx\leavevmode@ifvmode\@undefined |
| 1609 |
\def\bBigg@#1#2{% |
| 1610 |
% \end{macrocode} |
| 1611 |
% We start with an extra set of braces because we want |
| 1612 |
% constructions like |\def\bigl{\mathopen\big}| to work without the |
| 1613 |
% overhead of extra arguments. |
| 1614 |
% \begin{macrocode} |
| 1615 |
{\@mathmeasure\z@{\nulldelimiterspace\z@}% |
| 1616 |
{\left#2\vcenter to#1\big@size{}\right.}% |
| 1617 |
\box\z@}} |
| 1618 |
\else |
| 1619 |
\def\bBigg@#1#2{\leavevmode@ifvmode |
| 1620 |
{\@mathmeasure\z@{\nulldelimiterspace\z@}% |
| 1621 |
{\left#2\vcenter to#1\big@size{}\right.}% |
| 1622 |
\box\z@}} |
| 1623 |
\fi |
| 1624 |
% \end{macrocode} |
| 1625 |
% \end{macro} |
| 1626 |
% |
| 1627 |
% \begin{macro}{\big@size} |
| 1628 |
% |\big@size| needs to be set to 1.2 times the height of a math |
| 1629 |
% paren. This height is already recorded in |\Mathstrutbox@|. |
| 1630 |
% \begin{macrocode} |
| 1631 |
\addto@hook\every@math@size{% |
| 1632 |
\global\big@size 1.2\ht\Mathstrutbox@ |
| 1633 |
\global\advance\big@size 1.2\dp\Mathstrutbox@ } |
| 1634 |
\newdimen\big@size |
| 1635 |
% \end{macrocode} |
| 1636 |
% \end{macro} |
| 1637 |
% |
| 1638 |
% |
| 1639 |
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1640 |
% \section{Math accents} |
| 1641 |
% |
| 1642 |
% We want to change the leading digit of math accents to be |
| 1643 |
% \cs{accentclass@} so that it can vary according to certain internal |
| 1644 |
% purposes. |
| 1645 |
% \begin{macrocode} |
| 1646 |
\def\accentclass@{7} |
| 1647 |
\def\noaccents@{\def\accentclass@{0}} |
| 1648 |
% \end{macrocode} |
| 1649 |
% |
| 1650 |
% There are a few \meta{math alphabet}s in the standard fonts where |
| 1651 |
% we have to change the extra macros because the standard definitions |
| 1652 |
% don't account for these accent problems. The first is for the |
| 1653 |
% \cs{mathit} command. |
| 1654 |
% \begin{macrocode} |
| 1655 |
\DeclareFontEncoding{OML}{}{\noaccents@} |
| 1656 |
% \end{macrocode} |
| 1657 |
% The next one corrects the \cs{cal} alphabet. |
| 1658 |
% \begin{macrocode} |
| 1659 |
\DeclareFontEncoding{OMS}{}{\noaccents@} |
| 1660 |
% \end{macrocode} |
| 1661 |
% |
| 1662 |
% \begin{macro}{\dddot} |
| 1663 |
% \begin{macro}{\ddddot} |
| 1664 |
% Triple and quadruple dot accents. |
| 1665 |
% \changes{v2.17f}{2020/02/20}{Add a kern so that a single char is not |
| 1666 |
% vertically shifted and move the dots slightly to the right (gh/126)} |
| 1667 |
% \begin{macrocode} |
| 1668 |
\ams@newcommand{\dddot}[1]{% |
| 1669 |
{\mathop{\kern\z@#1}\limits^{\vbox to-1.4\ex@{\kern-\tw@\ex@ |
| 1670 |
\hbox{\,\normalfont...}\vss}}}} |
| 1671 |
\ams@newcommand{\ddddot}[1]{% |
| 1672 |
{\mathop{\kern\z@#1}\limits^{\vbox to-1.4\ex@{\kern-\tw@\ex@ |
| 1673 |
\hbox{\,\normalfont....}\vss}}}} |
| 1674 |
% \end{macrocode} |
| 1675 |
% |
| 1676 |
% We make the commands robust only at the end of the preamble as |
| 1677 |
% \pkg{amsmath} interacts with \pkg{stix} (which should also move |
| 1678 |
% to robust commands). |
| 1679 |
% \changes{v2.17n}{2022/04/08}{Make dddot commands robust (gh/123)} |
| 1680 |
% \begin{macrocode} |
| 1681 |
\AtBeginDocument{% |
| 1682 |
\MakeRobust\dddot |
| 1683 |
\MakeRobust\ddddot |
| 1684 |
} |
| 1685 |
% \end{macrocode} |
| 1686 |
% \end{macro} |
| 1687 |
% \end{macro} |
| 1688 |
% |
| 1689 |
% The following code deals with support for compound accents. |
| 1690 |
% By redefining \cs{set@mathaccent} we ensure that |
| 1691 |
% \cn{DeclareMathAccent} will define accent commands to run our |
| 1692 |
% \cs{mathaccentV} function instead of the primitive \cs{mathaccent}. |
| 1693 |
% \changes{v2.17d}{2019/11/16}{Added \cs{MakeRobust} to match kernel |
| 1694 |
% change (gh/216)} |
| 1695 |
% \begin{macrocode} |
| 1696 |
\def\set@mathaccent#1#2#3#4{% |
| 1697 |
% \end{macrocode} |
| 1698 |
% Now that the redefinitions done inside amsmath of the basic accents |
| 1699 |
% are all robust we can drop the \cs{protect} here. |
| 1700 |
% \begin{macrocode} |
| 1701 |
\xdef#2{% |
| 1702 |
% \@nx\protect |
| 1703 |
\@nx\mathaccentV |
| 1704 |
{\@xp\@gobble\string#2}\hexnumber@#1#4}% |
| 1705 |
\MakeRobust#2% |
| 1706 |
} |
| 1707 |
% \end{macrocode} |
| 1708 |
% |
| 1709 |
% \begin{macro}{\hat} |
| 1710 |
% \begin{macro}{\check} |
| 1711 |
% \begin{macro}{\tilde} |
| 1712 |
% \begin{macro}{\acute} |
| 1713 |
% \begin{macro}{\grave} |
| 1714 |
% \begin{macro}{\dot} |
| 1715 |
% \begin{macro}{\ddot} |
| 1716 |
% \begin{macro}{\breve} |
| 1717 |
% \begin{macro}{\bar} |
| 1718 |
% \begin{macro}{\vec} |
| 1719 |
% \begin{macro}{\mathring} |
| 1720 |
% We redefine the standard math accent commands to |
| 1721 |
% call \cs{mathaccentV}, using the mathgroup/encoding-number |
| 1722 |
% information embedded in their previous definitions. If the |
| 1723 |
% definition of an accent command does not have the expected form, we |
| 1724 |
% leave the accent command alone, but give a warning. For widehat and |
| 1725 |
% widetilde, we need to avoid clobbering the definitions done by the |
| 1726 |
% \pkg{amsfonts} package. Arbitrating the contention between |
| 1727 |
% \pkg{amsmath} and \pkg{amsfonts} to allow doubling a widetilde |
| 1728 |
% accent looks tricky, so for the time being [mjd,1999/07/19] we just |
| 1729 |
% leave \cn{widehat} and \cn{widetilde} alone. As a result, if the |
| 1730 |
% \pkg{amsmath} package is loaded on top of a vanilla \latex/ |
| 1731 |
% documentclass, everything runs through with no warnings. If a |
| 1732 |
% Lucida Math or other math fonts package is loaded in addition to |
| 1733 |
% \pkg{amsmath}, there are greater difficulties, but those are |
| 1734 |
% addressed elsewhere. |
| 1735 |
% |
| 1736 |
% |
| 1737 |
% \changes{v2.15}{2016/02/20}{Detect \cs{Umathaccent} on package load} |
| 1738 |
% Adjust the test made at package load to recognise |
| 1739 |
% |\Umathaccent|. Although currently it is just used to give a |
| 1740 |
% modified warning that the accents will not be redefined. |
| 1741 |
% |
| 1742 |
% Note that the engines behave quite differently here, luatex |
| 1743 |
% even without these definitions using the OpenType accent set up by |
| 1744 |
% unicode-math stacks |\hat{hat{f}}| correctly but xetex acts like |
| 1745 |
% classic tex and needs this adjustment. This difference is not |
| 1746 |
% addressed here at all. |
| 1747 |
% |
| 1748 |
% This test is just at package loading and has no affect on the |
| 1749 |
% definitions used in 8bit TeX. |
| 1750 |
% \begin{macrocode} |
| 1751 |
%\def\@tempa#1{\@xp\@tempb\meaning#1\@nil#1} |
| 1752 |
% \end{macrocode} |
| 1753 |
% The extended definition below tests if the accent is already |
| 1754 |
% robust (as newer \LaTeX{} kernels do this by default) and if so |
| 1755 |
% picks up the robust definition. However, as of |
| 1756 |
% now it still redefines it to be non-robust. |
| 1757 |
% \begin{macrocode} |
| 1758 |
\def\@tempa#1{% |
| 1759 |
\@ifundefined{\@xp\@gobble\string#1\space}% |
| 1760 |
{\@xp\@tempb\meaning#1\@nil#1}% |
| 1761 |
{\@xp\@xp\@xp\@tempb\@xp\meaning |
| 1762 |
\csname\@xp\@gobble\string#1\space\endcsname\@nil#1}% |
| 1763 |
} |
| 1764 |
\def\@tempb#1>#2#3 #4\@nil#5{% |
| 1765 |
\@xp\ifx\csname#3\endcsname\mathaccent |
| 1766 |
\@tempc#4?"7777\@nil#5% |
| 1767 |
\else |
| 1768 |
\@xp\ifx\csname#3\endcsname\Umathaccent |
| 1769 |
\@tempd#4\@nil#5% |
| 1770 |
\else |
| 1771 |
\PackageWarningNoLine{amsmath}{% |
| 1772 |
Unable to redefine math accent \string#5}% |
| 1773 |
\fi\fi} |
| 1774 |
\def\@tempc#1"#2#3#4#5#6\@nil#7{% |
| 1775 |
% \end{macrocode} |
| 1776 |
% Drop the inner part of the robust accent so that it can be recreated |
| 1777 |
% without a warning. |
| 1778 |
% \changes{v2.17d}{2019/11/16}{Make temporarily fragile to match kernel |
| 1779 |
% change (gh/216)} |
| 1780 |
% \begin{macrocode} |
| 1781 |
\@xp\let\csname\@xp\@gobble\string#7\space\endcsname\@undefined |
| 1782 |
\chardef\@tempd="#3\relax\set@mathaccent\@tempd{#7}{#2}{#4#5}} |
| 1783 |
\def\@tempd#1\@nil#2{% |
| 1784 |
\PackageWarningNoLine{amsmath}{% |
| 1785 |
Unable to redefine \string\Umathaccent\space\string#2}% |
| 1786 |
} |
| 1787 |
% \end{macrocode} |
| 1788 |
% \begin{macrocode} |
| 1789 |
\@tempa{\hat} |
| 1790 |
\@tempa{\check} |
| 1791 |
\@tempa{\tilde} |
| 1792 |
\@tempa{\acute} |
| 1793 |
\@tempa{\grave} |
| 1794 |
\@tempa{\dot} |
| 1795 |
\@tempa{\ddot} |
| 1796 |
\@tempa{\breve} |
| 1797 |
\@tempa{\bar} |
| 1798 |
\@tempa{\vec} |
| 1799 |
\@ifundefined{mathring}{% |
| 1800 |
\DeclareMathAccent{\mathring}{\mathalpha}{operators}{"17} |
| 1801 |
}{% |
| 1802 |
\@tempa{\mathring} |
| 1803 |
} |
| 1804 |
%%\@tempa\widetilde |
| 1805 |
%%\@tempa\widehat |
| 1806 |
% \end{macrocode} |
| 1807 |
% \end{macro} |
| 1808 |
% \end{macro} |
| 1809 |
% \end{macro} |
| 1810 |
% \end{macro} |
| 1811 |
% \end{macro} |
| 1812 |
% \end{macro} |
| 1813 |
% \end{macro} |
| 1814 |
% \end{macro} |
| 1815 |
% \end{macro} |
| 1816 |
% \end{macro} |
| 1817 |
% \end{macro} |
| 1818 |
% |
| 1819 |
% Regression testing of amsmath 2.0 showed that in some documents |
| 1820 |
% there occurred fragments of the form |
| 1821 |
% \begin{verbatim} |
| 1822 |
% \hat\mathcal{G} |
| 1823 |
% \end{verbatim} |
| 1824 |
% This is not at all correct syntax for the argument of a \latex/ |
| 1825 |
% command but it produced the intended result anyway because of the |
| 1826 |
% internal syntax of the \cs{mathaccent} primitive. With |
| 1827 |
% \cs{mathaccentV}, it will yield an error message. We therefore do a |
| 1828 |
% special check for such syntax problems in order to make the error |
| 1829 |
% message more informative. (dmj: ??????) |
| 1830 |
% \begin{macrocode} |
| 1831 |
\newcommand{\acc@check}{} |
| 1832 |
\newcommand{\acc@error}{} |
| 1833 |
\def\acc@check{\@ifnextchar\@empty\relax\acc@error} |
| 1834 |
% \end{macrocode} |
| 1835 |
% We put most of the tokens in a separate macro so they do not get |
| 1836 |
% scanned unless they are actually needed. |
| 1837 |
% \begin{macrocode} |
| 1838 |
\def\acc@error{% |
| 1839 |
\@amsmath@err{% |
| 1840 |
Improper argument for math accent:\MessageBreak |
| 1841 |
Extra braces must be added to prevent wrong output% |
| 1842 |
}\@ehc |
| 1843 |
} |
| 1844 |
% \end{macrocode} |
| 1845 |
% |
| 1846 |
% For \cs{mathaccentV} part of the processing is dependent on the |
| 1847 |
% depth of nesting of math accent commands. We introduce a dedicated |
| 1848 |
% counter for this instead of using chardef because we want to |
| 1849 |
% increment/decrement it during processing, and incrementing a |
| 1850 |
% chardef integer is more work. |
| 1851 |
% \begin{macrocode} |
| 1852 |
\newcount\macc@depth |
| 1853 |
% \end{macrocode} |
| 1854 |
% |
| 1855 |
% Provide this function in case it is not already available. |
| 1856 |
% \begin{macrocode} |
| 1857 |
\long\def\@gobblethree#1#2#3{} |
| 1858 |
% \end{macrocode} |
| 1859 |
% |
| 1860 |
% The \cs{mathaccentV} function first counts the number of nested |
| 1861 |
% math accents by setting the argument in a throw-away box. (This is |
| 1862 |
% not as risky as such an operation would normally be because the |
| 1863 |
% argument is generally either a simple math symbol or a nested math |
| 1864 |
% accent call with a simple math symbol at the bottom of the |
| 1865 |
% nesting.) |
| 1866 |
% |
| 1867 |
% There are two benefits from counting the nesting levels first |
| 1868 |
% before doing anything else: (1) we can fall back to a simple |
| 1869 |
% \cs{mathaccent} call if the nesting depth is 1, and (2) if the |
| 1870 |
% nesting depth is greater than 1, we would like to be able to tell |
| 1871 |
% when we have reached the lowest level, because at that point we |
| 1872 |
% want to save the argument for later use and place an accent on top |
| 1873 |
% of a phantom copy. |
| 1874 |
% |
| 1875 |
% When we have multiple accents, they will be placed on top of the |
| 1876 |
% invisible box, followed by some suitable kerns, then a visible copy |
| 1877 |
% of the nucleus. To see why, let us look at what goes wrong with a |
| 1878 |
% double application of the \cs{mathaccent} primitive. The standard |
| 1879 |
% definition of \cs{hat} is \verb'\mathaccent"705E', so |
| 1880 |
% \verb'\hat{\hat{F}}' expands to |
| 1881 |
%\begin{verbatim} |
| 1882 |
%\mathaccent"705E{\mathaccent"705E{F}} |
| 1883 |
%\end{verbatim} |
| 1884 |
% The result of this operation is |
| 1885 |
%\begin{verbatim} |
| 1886 |
%\vbox(12.11111+0.0)x7.81946 |
| 1887 |
%.\hbox(6.94444+0.0)x0.0, shifted 1.40973 |
| 1888 |
%..\OT1/cmr/m/n/10 ^ |
| 1889 |
%.\kern-4.30554 |
| 1890 |
%.\vbox(9.47221+0.0)x7.81946 |
| 1891 |
%..\hbox(6.94444+0.0)x0.0, shifted 2.24309 |
| 1892 |
%...\OT1/cmr/m/n/10 ^ |
| 1893 |
%..\kern-4.30554 |
| 1894 |
%..\hbox(6.83331+0.0)x7.81946 |
| 1895 |
%...\OML/cmm/m/it/10 F |
| 1896 |
%\end{verbatim} |
| 1897 |
% \tex/ starts by constructing a vbox with the hat character on top |
| 1898 |
% of the F. Then it puts another hat character on top of the vbox; |
| 1899 |
% but without skew information, because that is only applied by |
| 1900 |
% \cs{mathaccent} when the base object is a simple symbol. So the |
| 1901 |
% first accent is skewed to the correct position but all later |
| 1902 |
% accents are not. By the way, the actual width of the F in the above |
| 1903 |
% example is less than 7.81946; the box in which it is packed was |
| 1904 |
% automatically lengthened by the width of the F's italic correction |
| 1905 |
% (without actually putting in a kern for it). |
| 1906 |
% |
| 1907 |
% To get the second accent shifted farther to the right we |
| 1908 |
% artificially increase the width of the innermost box and add |
| 1909 |
% a compensating kern afterward. Furthermore, to get proper placement |
| 1910 |
% of a following subscript or superscript, we take the base symbol |
| 1911 |
% out, leaving a phantom in its place, and print it by itself |
| 1912 |
% following the kern. We then need to increase the kern amount to |
| 1913 |
% move the base character backward under the accents again. |
| 1914 |
% Here is what the results look like: |
| 1915 |
%\begin{verbatim} |
| 1916 |
%\vbox(12.11111+0.0)x9.48618 |
| 1917 |
%.\hbox(6.94444+0.0)x0.0, shifted 2.24309 |
| 1918 |
%..\OT1/cmr/m/n/10 ^ |
| 1919 |
%.\kern-4.30554 |
| 1920 |
%.\vbox(9.47221+0.0)x9.48618 |
| 1921 |
%..\hbox(6.94444+0.0)x0.0, shifted 2.24309 |
| 1922 |
%...\OT1/cmr/m/n/10 ^ |
| 1923 |
%..\kern-4.30554 |
| 1924 |
%..\hbox(6.83331+0.0)x9.48618 |
| 1925 |
%...\hbox(6.83331+0.0)x7.81946 |
| 1926 |
%...\kern 1.66672 |
| 1927 |
%\kern -9.48618 |
| 1928 |
%\OML/cmm/m/it/10 F |
| 1929 |
%\end{verbatim} |
| 1930 |
% |
| 1931 |
% Much of this implementation is based on code from the \pkg{accents} |
| 1932 |
% package of Javier Bezos. I added the test to revert to a simple |
| 1933 |
% \cs{mathaccent} when accents are not nested, and some other |
| 1934 |
% refinements to reduce the number of kerns used (to conserve box |
| 1935 |
% memory) and the number of cycles through \cs{mathchoice} (to make |
| 1936 |
% things run a little faster). It was all rather difficult and my |
| 1937 |
% first two attempts had serious bugs but I hope and believe that |
| 1938 |
% this version will do better. [mjd,2000/03/15] |
| 1939 |
% |
| 1940 |
% The \qq{V} in \cs{mathaccentV} is just an indication that it takes |
| 1941 |
% five arguments. It is important that the name includes |
| 1942 |
% \texttt{mathaccent}, otherwise \cs{DeclareMathAccent} will balk at |
| 1943 |
% redefining one of our accent commands, for example when an |
| 1944 |
% alternative math font package is loaded. |
| 1945 |
% \begin{macrocode} |
| 1946 |
\def\mathaccentV#1#2#3#4#5{% |
| 1947 |
\ifmmode |
| 1948 |
\gdef\macc@tmp{\macc@depth\@ne}% |
| 1949 |
\setbox\z@\hbox{% |
| 1950 |
\let\mathaccentV\macc@test |
| 1951 |
\let\use@mathgroup\@gobbletwo \let\select@group\@gobblethree |
| 1952 |
\frozen@everymath{}$#5$% |
| 1953 |
}% |
| 1954 |
\macc@tmp |
| 1955 |
\ifnum\macc@depth=\@ne |
| 1956 |
\global\let\macc@nucleus\@empty |
| 1957 |
\mathaccent"\accentclass@ |
| 1958 |
\else |
| 1959 |
\@xp\macc@nested |
| 1960 |
\fi |
| 1961 |
#2#3#4{#5}% |
| 1962 |
\macc@nucleus |
| 1963 |
\else |
| 1964 |
\@xp\nonmatherr@\csname#1\endcsname |
| 1965 |
\fi |
| 1966 |
} |
| 1967 |
% \end{macrocode} |
| 1968 |
% |
| 1969 |
% \begin{macrocode} |
| 1970 |
\def\macc@test#1#2#3#4{\xdef\macc@tmp{\macc@tmp\advance\macc@depth\@ne}} |
| 1971 |
% \end{macrocode} |
| 1972 |
% |
| 1973 |
% \begin{macrocode} |
| 1974 |
\def\macc@group{-1} |
| 1975 |
% \end{macrocode} |
| 1976 |
% |
| 1977 |
% \begin{macrocode} |
| 1978 |
\def\macc@nested#1#2#3#4{% |
| 1979 |
\begingroup |
| 1980 |
\let\math@bgroup\@empty \let\math@egroup\macc@set@skewchar |
| 1981 |
\mathsurround\z@ \frozen@everymath{\mathgroup\macc@group\relax}% |
| 1982 |
\macc@set@skewchar\relax |
| 1983 |
\let\mathaccentV\macc@nested@a |
| 1984 |
\macc@nested@a\relax#1#2#3{#4}% |
| 1985 |
\endgroup |
| 1986 |
} |
| 1987 |
% \end{macrocode} |
| 1988 |
% |
| 1989 |
% \begin{macrocode} |
| 1990 |
\let\macc@palette\mathpalette |
| 1991 |
% \end{macrocode} |
| 1992 |
% |
| 1993 |
% \begin{macrocode} |
| 1994 |
\def\macc@nested@a#1#2#3#4#5{% |
| 1995 |
% \end{macrocode} |
| 1996 |
% This test saves some work that would otherwise be always repeated |
| 1997 |
% fourfold thanks to \cs{mathchoice}. |
| 1998 |
% \begin{macrocode} |
| 1999 |
\ifnum\macc@group=\mathgroup |
| 2000 |
\else \macc@set@skewchar\relax \edef\macc@group{\the\mathgroup}% |
| 2001 |
\fi |
| 2002 |
\mathchardef\macc@code "\accentclass@ #2#3#4\relax |
| 2003 |
\macc@palette\macc@a{#5}% |
| 2004 |
} |
| 2005 |
% \end{macrocode} |
| 2006 |
% |
| 2007 |
% The reason that \cs{macc@set@skewchar} takes an argument is so that |
| 2008 |
% it can serve as a direct substitute for \cs{math@egroup}, in |
| 2009 |
% addition to being used separately. |
| 2010 |
% |
| 2011 |
% Setting a skewchar with this method works for symbols of variable |
| 2012 |
% mathgroup (class 7, letters and numbers) but not necessarily for |
| 2013 |
% special symbols like \cn{partial} or \cs{xi} whose mathgroup |
| 2014 |
% doesn't change; fortunately the most commonly used ones come from |
| 2015 |
% mathgroup one, which is the fall-back mathgroup for skewchar. |
| 2016 |
% \begin{macrocode} |
| 2017 |
\def\macc@set@skewchar#1{% |
| 2018 |
\begingroup |
| 2019 |
\ifnum\mathgroup=\m@ne \let\@tempa\@ne |
| 2020 |
\else |
| 2021 |
\ifnum\skewchar\textfont\mathgroup=\m@ne \let\@tempa\@ne |
| 2022 |
\else \let\@tempa\mathgroup |
| 2023 |
\fi |
| 2024 |
\fi |
| 2025 |
\count@=\skewchar\textfont\@tempa |
| 2026 |
\advance\count@"7100 |
| 2027 |
\edef\@tempa{\endgroup |
| 2028 |
\mathchardef\noexpand\macc@skewchar=\number\count@\relax}% |
| 2029 |
\@tempa |
| 2030 |
#1% |
| 2031 |
} |
| 2032 |
% \end{macrocode} |
| 2033 |
% |
| 2034 |
% Arg1 is math-style, arg2 is accent base object. We assume that math |
| 2035 |
% style doesn't change within the nested group of accents; this means |
| 2036 |
% we can set \cs{macc@style} only once and redefine \cs{macc@palette} |
| 2037 |
% to use it, in order to run \cs{mathchoice} only once instead of |
| 2038 |
% multiplying the calls exponentially as the nesting level increases. |
| 2039 |
% \begin{macrocode} |
| 2040 |
\def\macc@a#1#2{% |
| 2041 |
\begingroup |
| 2042 |
\let\macc@style#1\relax |
| 2043 |
\def\macc@palette##1{##1\macc@style}% |
| 2044 |
\advance\macc@depth\m@ne |
| 2045 |
\ifnum\macc@depth=\z@ |
| 2046 |
\gdef\macc@nucleus{#2}% |
| 2047 |
% \end{macrocode} |
| 2048 |
% Extra \cs{@empty} tokens are to prevent low-level \tex/ errors from |
| 2049 |
% the potential syntactic error that \cs{acc@check} checks for. |
| 2050 |
% \begin{macrocode} |
| 2051 |
\setbox\z@\hbox{$#1#2\@empty{}\macc@skewchar$}% |
| 2052 |
\setbox\tw@\hbox{$#1#2\@empty\macc@skewchar$}% |
| 2053 |
\dimen@\tw@\wd\tw@ \advance\dimen@-\tw@\wd\z@ |
| 2054 |
\xdef\macc@kerna{\the\dimen@\relax}% |
| 2055 |
\setbox4\hbox{$#1#2\acc@check\@empty$}% |
| 2056 |
\global\setbox\@ne\hbox to\wd4{}% |
| 2057 |
\ht\@ne\ht4 \dp\@ne\dp4 |
| 2058 |
\xdef\macc@kernb{\the\wd4\relax}% |
| 2059 |
\mathaccent\macc@code{\box\@ne\kern\macc@kerna}% |
| 2060 |
\else |
| 2061 |
\mathaccent\macc@code{\let\macc@adjust\@empty #1#2\@empty}% |
| 2062 |
\macc@adjust |
| 2063 |
\fi |
| 2064 |
\endgroup |
| 2065 |
} |
| 2066 |
% \end{macrocode} |
| 2067 |
% |
| 2068 |
% \begin{macrocode} |
| 2069 |
\def\macc@adjust{% |
| 2070 |
\dimen@\macc@kerna\advance\dimen@\macc@kernb |
| 2071 |
\kern-\dimen@ |
| 2072 |
} |
| 2073 |
% \end{macrocode} |
| 2074 |
% |
| 2075 |
% The commands \cs{Hat}, \cs{Tilde}, \ldots, are supported as |
| 2076 |
% synonyms of \cs{hat}, \cs{tilde}, \ldots, for backward |
| 2077 |
% compatibility. |
| 2078 |
% \begin{macrocode} |
| 2079 |
\def\Hat{\hat} |
| 2080 |
\def\Check{\check} |
| 2081 |
\def\Tilde{\tilde} |
| 2082 |
\def\Acute{\acute} |
| 2083 |
\def\Grave{\grave} |
| 2084 |
\def\Dot{\dot} |
| 2085 |
\def\Ddot{\ddot} |
| 2086 |
\def\Breve{\breve} |
| 2087 |
\def\Bar{\bar} |
| 2088 |
\def\Vec{\vec} |
| 2089 |
% \end{macrocode} |
| 2090 |
% |
| 2091 |
% This error message about math mode is used several times so we make |
| 2092 |
% an abbreviation for it. |
| 2093 |
% \begin{macrocode} |
| 2094 |
\def\nonmatherr@#1{\@amsmath@err{\protect |
| 2095 |
#1 allowed only in math mode}\@ehd} |
| 2096 |
% \end{macrocode} |
| 2097 |
% |
| 2098 |
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2099 |
% \section{Mods, continued fractions, etc.} |
| 2100 |
% |
| 2101 |
% \begin{macro}{\bmod} |
| 2102 |
% \begin{macro}{\pmod} |
| 2103 |
% \begin{macro}{\pod} |
| 2104 |
% \begin{macro}{\mod} |
| 2105 |
% The commands \cn{bmod}, \cn{pmod}, \cn{pod}, \cn{mod} aren't |
| 2106 |
% currently robust. [mjd, 1994/09/05] |
| 2107 |
% Now they are |
| 2108 |
% \changes{v2.17n}{2022/04/08}{Make mod commands robust (gh/123)} |
| 2109 |
% \begin{macrocode} |
| 2110 |
\DeclareRobustCommand{\bmod}{\nonscript\mskip-\medmuskip\mkern5mu\mathbin |
| 2111 |
{\operator@font mod}\penalty900 |
| 2112 |
\mkern5mu\nonscript\mskip-\medmuskip} |
| 2113 |
\DeclareRobustCommand{\pod}[1]{\allowbreak |
| 2114 |
\if@display\mkern18mu\else\mkern8mu\fi(#1)} |
| 2115 |
\DeclareRobustCommand{\pmod}[1]{\pod{{\operator@font mod}\mkern6mu#1}} |
| 2116 |
\DeclareRobustCommand{\mod}[1]{\allowbreak\if@display\mkern18mu |
| 2117 |
\else\mkern12mu\fi{\operator@font mod}\,\,#1} |
| 2118 |
% \end{macrocode} |
| 2119 |
% \end{macro} |
| 2120 |
% \end{macro} |
| 2121 |
% \end{macro} |
| 2122 |
% \end{macro} |
| 2123 |
% |
| 2124 |
% \begin{macro}{\cfrac} |
| 2125 |
% Continued fractions. The optional arg l or r controls horizontal |
| 2126 |
% placement of the numerators. The |\kern-\nulldelimiterspace| |
| 2127 |
% is needed in the definition if we want the right-hand sides of the |
| 2128 |
% fraction rules to line up. The \cs{strut} keeps the numerator of |
| 2129 |
% a subsidiary cfrac from coming too close to the fraction rule above |
| 2130 |
% it. |
| 2131 |
% \changes{v2.17n}{2022/04/08}{Make \cs{cfrac} command robust (gh/123)} |
| 2132 |
% \begin{macrocode} |
| 2133 |
\DeclareRobustCommand{\cfrac}[3][c]{{\displaystyle\frac{% |
| 2134 |
\strut\ifx r#1\hfill\fi#2\ifx l#1\hfill\fi}{#3}}% |
| 2135 |
\kern-\nulldelimiterspace} |
| 2136 |
% \end{macrocode} |
| 2137 |
% \end{macro} |
| 2138 |
% |
| 2139 |
% \begin{macro}{\overset} |
| 2140 |
% \begin{macro}{\underset} |
| 2141 |
% \cn{overset} and \cn{underset} put symbols above, respectively |
| 2142 |
% below, a symbol that is not a \cs{mathop} and therefore does not |
| 2143 |
% naturally accept limits. \cs{binrel@@} uses information collected |
| 2144 |
% by \cs{binrel@} to make the resulting construction be of type |
| 2145 |
% mathrel or mathbin if the base symbol is either of those types. |
| 2146 |
% \changes{v2.17n}{2022/04/08}{Make \cs{overset}, \cs{underset} and |
| 2147 |
% \cs{overunderset} commands robust (gh/123)} |
| 2148 |
% \begin{macrocode} |
| 2149 |
\DeclareRobustCommand{\overset}[2]{\binrel@{#2}% |
| 2150 |
\binrel@@{\mathop{\kern\z@#2}\limits^{#1}}} |
| 2151 |
% \end{macrocode} |
| 2152 |
% |
| 2153 |
% \begin{macrocode} |
| 2154 |
\DeclareRobustCommand{\underset}[2]{\binrel@{#2}% |
| 2155 |
\binrel@@{\mathop{\kern\z@#2}\limits_{#1}}} |
| 2156 |
% \end{macrocode} |
| 2157 |
% \end{macro} |
| 2158 |
% \end{macro} |
| 2159 |
% |
| 2160 |
% |
| 2161 |
% \begin{macro}{\overunderset} |
| 2162 |
% This is the combination of the previous two commands which is |
| 2163 |
% something that is sometimes needed. |
| 2164 |
% \changes{v2.17c}{2019/04/01}{New command \cs{overunderset}} |
| 2165 |
% \begin{macrocode} |
| 2166 |
\DeclareRobustCommand{\overunderset}[3]{\binrel@{#3}% |
| 2167 |
\binrel@@{\mathop{\kern\z@#3}\limits^{#1}_{#2}}} |
| 2168 |
% \end{macrocode} |
| 2169 |
% \end{macro} |
| 2170 |
% |
| 2171 |
% \begin{macro}{\sideset} |
| 2172 |
% \cn{sideset} allows placing `adscript' symbols at the four |
| 2173 |
% corners of a \cs{mathop}, \emph{in addition to} limits. Left-side |
| 2174 |
% adscripts go into arg \arg{1}, in the form |_{...}^{...}|, and |
| 2175 |
% right-side adscripts go into arg \arg{2}. |
| 2176 |
% |
| 2177 |
% As currently written [mjd, 1995/01/21] this is pretty haphazard. |
| 2178 |
% In order to really make it work properly in full generality we'd |
| 2179 |
% have to read and measure the top and bottom limits and use |
| 2180 |
% mathchoice to always get the right mathstyle for each piece, |
| 2181 |
% etc., etc. |
| 2182 |
% \changes{v2.17n}{2022/04/08}{Make \cs{sideset} command robust (gh/123)} |
| 2183 |
% \begin{macrocode} |
| 2184 |
\DeclareRobustCommand{\sideset}[3]{% |
| 2185 |
\@mathmeasure\z@\displaystyle{#3}% |
| 2186 |
% \end{macrocode} |
| 2187 |
% Use a global box assignment here since the depth override is |
| 2188 |
% implicitly global. Then move the constructed box to a local box |
| 2189 |
% register (2) to ensure it won't get destroyed during the next two |
| 2190 |
% mathmeasure statements. This precaution may be more extreme than |
| 2191 |
% necessary in practice. |
| 2192 |
% \begin{macrocode} |
| 2193 |
\global\setbox\@ne\vbox to\ht\z@{}\dp\@ne\dp\z@ |
| 2194 |
\setbox\tw@\box\@ne |
| 2195 |
\@mathmeasure4\displaystyle{\copy\tw@#1}% |
| 2196 |
\@mathmeasure6\displaystyle{#3\nolimits#2}% |
| 2197 |
\dimen@-\wd6 \advance\dimen@\wd4 \advance\dimen@\wd\z@ |
| 2198 |
\hbox to\dimen@{}\mathop{\kern-\dimen@\box4\box6}% |
| 2199 |
} |
| 2200 |
% \end{macrocode} |
| 2201 |
% \end{macro} |
| 2202 |
% |
| 2203 |
% \begin{macro}{\smash} |
| 2204 |
% We add to the \cn{smash} command an optional argument |
| 2205 |
% denoting the part of the formula to be smashed. |
| 2206 |
% \changes{v2.17b}{2018/12/01}{Start LR-mode for \cs{smash} |
| 2207 |
% if necessary (github/49)} |
| 2208 |
% \changes{v2.17n}{2022/04/08}{Make \cs{smash} command robust (gh/123)} |
| 2209 |
% \begin{macrocode} |
| 2210 |
\ifx\leavevmode@ifvmode\@undefined |
| 2211 |
\DeclareRobustCommand{\smash}[1][tb]{% |
| 2212 |
\def\mb@t{\ht}\def\mb@b{\dp}\def\mb@tb{\ht\z@\z@\dp}% |
| 2213 |
\edef\finsm@sh{\csname mb@#1\endcsname\z@\z@\box\z@}% |
| 2214 |
\ifmmode \@xp\mathpalette\@xp\mathsm@sh |
| 2215 |
\else \@xp\makesm@sh |
| 2216 |
\fi |
| 2217 |
} |
| 2218 |
\else |
| 2219 |
\DeclareRobustCommand{\smash}[1][tb]{% |
| 2220 |
\def\mb@t{\ht}\def\mb@b{\dp}\def\mb@tb{\ht\z@\z@\dp}% |
| 2221 |
\edef\finsm@sh{\csname mb@#1\endcsname\z@\z@ \leavevmode@ifvmode\box\z@}% |
| 2222 |
\ifmmode \@xp\mathpalette\@xp\mathsm@sh |
| 2223 |
\else \@xp\makesm@sh |
| 2224 |
\fi |
| 2225 |
} |
| 2226 |
\fi |
| 2227 |
% \end{macrocode} |
| 2228 |
% \end{macro} |
| 2229 |
% |
| 2230 |
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2231 |
% \section{Extensible arrows} |
| 2232 |
% |
| 2233 |
% The minus sign used in constructing these arrow fills is smashed so |
| 2234 |
% that superscripts above the arrows won't be too high. This |
| 2235 |
% primarily affects the \cn{xleftarrow} and \cn{xrightarrow} arrows. |
| 2236 |
% \changes{v2.17h}{2020/08/24}{detect unicode engines and use their commands} |
| 2237 |
% \begin{macrocode} |
| 2238 |
\@ifundefined{Umathcode} |
| 2239 |
{% |
| 2240 |
\mathchardef\std@minus\mathcode`\-\relax |
| 2241 |
\mathchardef\std@equal\mathcode`\=\relax |
| 2242 |
} |
| 2243 |
{% |
| 2244 |
\Umathcharnumdef\std@minus\Umathcodenum`\-\relax |
| 2245 |
\Umathcharnumdef\std@equal\Umathcodenum`\=\relax |
| 2246 |
} |
| 2247 |
% \end{macrocode} |
| 2248 |
% In case some alternative math fonts are loaded later: |
| 2249 |
% \begin{macrocode} |
| 2250 |
\@ifundefined{Umathcode} |
| 2251 |
{% |
| 2252 |
\AtBeginDocument{% |
| 2253 |
\mathchardef\std@minus\mathcode`\-\relax |
| 2254 |
\mathchardef\std@equal\mathcode`\=\relax |
| 2255 |
}% |
| 2256 |
} |
| 2257 |
{% |
| 2258 |
\AtBeginDocument{% |
| 2259 |
\Umathcharnumdef\std@minus\Umathcodenum`\-\relax |
| 2260 |
\Umathcharnumdef\std@equal\Umathcodenum`\=\relax |
| 2261 |
}% |
| 2262 |
} |
| 2263 |
% \end{macrocode} |
| 2264 |
% |
| 2265 |
% \begin{macro}{\relbar} |
| 2266 |
% \begin{macro}{\Relbar} |
| 2267 |
% \changes{v2.17n}{2022/04/08}{Make commands robust (gh/123)} |
| 2268 |
% \begin{macrocode} |
| 2269 |
\ams@DeclareRobustCommand\relbar{\mathrel{\mathpalette\mathsm@sh\std@minus}} |
| 2270 |
\ams@DeclareRobustCommand\Relbar{\mathrel\std@equal} |
| 2271 |
% \end{macrocode} |
| 2272 |
% \end{macro} |
| 2273 |
% \end{macro} |
| 2274 |
% |
| 2275 |
% \begin{macrocode} |
| 2276 |
\def\arrowfill@#1#2#3#4{% |
| 2277 |
$\m@th\thickmuskip0mu\medmuskip\thickmuskip\thinmuskip\thickmuskip |
| 2278 |
\relax#4#1\mkern-7mu% |
| 2279 |
\cleaders\hbox{$#4\mkern-2mu#2\mkern-2mu$}\hfill |
| 2280 |
\mkern-7mu#3$% |
| 2281 |
} |
| 2282 |
\def\leftarrowfill@{\arrowfill@\leftarrow\relbar\relbar} |
| 2283 |
\def\rightarrowfill@{\arrowfill@\relbar\relbar\rightarrow} |
| 2284 |
\def\leftrightarrowfill@{\arrowfill@\leftarrow\relbar\rightarrow} |
| 2285 |
\def\Leftarrowfill@{\arrowfill@\Leftarrow\Relbar\Relbar} |
| 2286 |
\def\Rightarrowfill@{\arrowfill@\Relbar\Relbar\Rightarrow} |
| 2287 |
\def\Leftrightarrowfill@{\arrowfill@\Leftarrow\Relbar\Rightarrow} |
| 2288 |
% \end{macrocode} |
| 2289 |
% |
| 2290 |
% \begin{macrocode} |
| 2291 |
\def\overarrow@#1#2#3{\vbox{\ialign{##\crcr#1#2\crcr |
| 2292 |
\noalign{\nointerlineskip}$\m@th\hfil#2#3\hfil$\crcr}}} |
| 2293 |
\ams@renewcommand{\overrightarrow}{% |
| 2294 |
\mathpalette{\overarrow@\rightarrowfill@}} |
| 2295 |
\ams@renewcommand{\overleftarrow}{% |
| 2296 |
\mathpalette{\overarrow@\leftarrowfill@}} |
| 2297 |
\ams@newcommand{\overleftrightarrow}{% |
| 2298 |
\mathpalette{\overarrow@\leftrightarrowfill@}} |
| 2299 |
% \end{macrocode} |
| 2300 |
% Again we delay making commands robut for \pkg{stix}. |
| 2301 |
% \changes{v2.17n}{2022/04/08}{Make commands robust (gh/123)} |
| 2302 |
% \begin{macrocode} |
| 2303 |
\AtBeginDocument{% |
| 2304 |
\expandafter\let\csname overleftarrow \endcsname\@undefined |
| 2305 |
\expandafter\let\csname overrightarrow \endcsname\@undefined |
| 2306 |
\MakeRobust\overrightarrow |
| 2307 |
\MakeRobust\overleftarrow |
| 2308 |
\MakeRobust\overleftrightarrow |
| 2309 |
} |
| 2310 |
% \end{macrocode} |
| 2311 |
% |
| 2312 |
% \begin{macrocode} |
| 2313 |
\def\underarrow@#1#2#3{% |
| 2314 |
\vtop{\ialign{##\crcr$\m@th\hfil#2#3\hfil$\crcr |
| 2315 |
\noalign{\nointerlineskip\kern1.3\ex@}#1#2\crcr}}} |
| 2316 |
\ams@newcommand{\underrightarrow}{% |
| 2317 |
\mathpalette{\underarrow@\rightarrowfill@}} |
| 2318 |
\ams@newcommand{\underleftarrow}{% |
| 2319 |
\mathpalette{\underarrow@\leftarrowfill@}} |
| 2320 |
\ams@newcommand{\underleftrightarrow}{% |
| 2321 |
\mathpalette{\underarrow@\leftrightarrowfill@}} |
| 2322 |
% \end{macrocode} |
| 2323 |
% |
| 2324 |
% |
| 2325 |
% \changes{v2.17n}{2022/04/08}{Make commands robust (gh/123)} |
| 2326 |
% \begin{macrocode} |
| 2327 |
\AtBeginDocument{% |
| 2328 |
\MakeRobust\underrightarrow |
| 2329 |
\MakeRobust\underleftarrow |
| 2330 |
\MakeRobust\underleftrightarrow |
| 2331 |
} |
| 2332 |
% \end{macrocode} |
| 2333 |
% |
| 2334 |
% \changes{v2.17n}{2022/04/08}{Make commands robust (gh/123)} |
| 2335 |
% \begin{macrocode} |
| 2336 |
%\DeclareRobustCommand{\xrightarrow}[2][]{\ext@arrow 0359\rightarrowfill@{#1}{#2}} |
| 2337 |
\def\ext@arrow#1#2#3#4#5#6#7{% |
| 2338 |
\mathrel{\mathop{% |
| 2339 |
% \end{macrocode} |
| 2340 |
% Measure the superscript and subscript. |
| 2341 |
% \begin{macrocode} |
| 2342 |
\setbox\z@\hbox{#5\displaystyle}% |
| 2343 |
\setbox\tw@\vbox{\m@th |
| 2344 |
\hbox{$\scriptstyle\mkern#3mu{#6}\mkern#4mu$}% |
| 2345 |
\hbox{$\scriptstyle\mkern#3mu{#7}\mkern#4mu$}% |
| 2346 |
\copy\z@ |
| 2347 |
}% |
| 2348 |
\hbox to\wd\tw@{\unhbox\z@}}% |
| 2349 |
% \end{macrocode} |
| 2350 |
% We don't want to place an empty subscript since that will produce |
| 2351 |
% too much blank space below the arrow. |
| 2352 |
% \begin{macrocode} |
| 2353 |
\limits |
| 2354 |
\@ifnotempty{#7}{^{\if0#1\else\mkern#1mu\fi |
| 2355 |
#7\if0#2\else\mkern#2mu\fi}}% |
| 2356 |
\@ifnotempty{#6}{_{\if0#1\else\mkern#1mu\fi |
| 2357 |
#6\if0#2\else\mkern#2mu\fi}}}% |
| 2358 |
} |
| 2359 |
% \end{macrocode} |
| 2360 |
% |
| 2361 |
% Some extensible arrows to serve as mathrels and taking |
| 2362 |
% sub/superscripts. These commands are robust because they take an |
| 2363 |
% optional argument. |
| 2364 |
% \begin{macrocode} |
| 2365 |
\DeclareRobustCommand{\xrightarrow}[2][]{\ext@arrow 0359\rightarrowfill@{#1}{#2}} |
| 2366 |
\DeclareRobustCommand{\xleftarrow}[2][]{\ext@arrow 3095\leftarrowfill@{#1}{#2}} |
| 2367 |
% \end{macrocode} |
| 2368 |
% |
| 2369 |
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2370 |
% \section{Array-related environments} |
| 2371 |
% \subsection{Remarks} |
| 2372 |
% |
| 2373 |
% Because these environments can be nested within the equation |
| 2374 |
% structures that allow \cn{tag}, there is some cross-influence in |
| 2375 |
% the internal workings of the \cn{\\} command. |
| 2376 |
% |
| 2377 |
% \subsection{The \env{subarray} environment and \cn{substack} command} |
| 2378 |
% |
| 2379 |
% The \cn{substack} command can be used to set subscripts |
| 2380 |
% and superscripts that consist of several lines. Usage: |
| 2381 |
% \begin{verbatim} |
| 2382 |
% X_{\substack{a=1\\b=2}} |
| 2383 |
% \end{verbatim} |
| 2384 |
% |
| 2385 |
% \changes{v2.0}{1999/06/17}{Removed environment definitions: Sb, Sp} |
| 2386 |
% |
| 2387 |
% \begin{environment}{subarray} |
| 2388 |
% The \env{subarray} environment makes a small-size array suitable |
| 2389 |
% for use in a subscript or superscript. At the moment the supported |
| 2390 |
% arguments are not the full possibilities of \env{array} but only |
| 2391 |
% |c| or |l| for centered or left-aligned. And only one column. |
| 2392 |
% \changes{v2.17i}{2020/09/23}{moved to version from lualatex-math for luatex} |
| 2393 |
% \begin{macrocode} |
| 2394 |
\ifx\directlua\@undefined |
| 2395 |
\newenvironment{subarray}[1]{% |
| 2396 |
% \end{macrocode} |
| 2397 |
% Note: The predecessors of \env{subarray} (\env{Sb} and \env{Sp}, |
| 2398 |
% inherited from \amstex/) used \cs{vbox} instead of \cs{vcenter}. |
| 2399 |
% But when a multiline subscript is placed in \cs{limits} position |
| 2400 |
% \cs{vcenter} is no worse than \cs{vbox}, and when it is placed |
| 2401 |
% in the \cs{nolimits} position (e.g., for an integral), \cs{vcenter} |
| 2402 |
% provides clearly better positioning than \cs{vbox}. |
| 2403 |
% \begin{macrocode} |
| 2404 |
\vcenter\bgroup |
| 2405 |
% \end{macrocode} |
| 2406 |
% Use \cs{Let@} to set the proper meaning of the \cn{\\} and \cn{\\*} |
| 2407 |
% commands. And restore the meaning of \cs{math@cr@@@} to \cs{cr} |
| 2408 |
% (see above) in case \env{subarray} is used inside one of the more |
| 2409 |
% complicated alignment macros where the meaning of \cs{math@cr@@@} |
| 2410 |
% is different. Similarly, call \cs{default@tag} to ensure that a |
| 2411 |
% line break here doesn't get an equation number! |
| 2412 |
% \begin{macrocode} |
| 2413 |
\Let@ \restore@math@cr \default@tag |
| 2414 |
% \end{macrocode} |
| 2415 |
% Set the line spacing to be the same as \cs{atop} (when \cs{atop} |
| 2416 |
% occurs in \cs{textstyle} or smaller), cf \textit{The \tex/book}, |
| 2417 |
% Appendix G. |
| 2418 |
% \begin{macrocode} |
| 2419 |
\baselineskip\fontdimen10 \scriptfont\tw@ |
| 2420 |
\advance\baselineskip\fontdimen12 \scriptfont\tw@ |
| 2421 |
\lineskip\thr@@\fontdimen8 \scriptfont\thr@@ |
| 2422 |
\lineskiplimit\lineskip |
| 2423 |
% \end{macrocode} |
| 2424 |
% Start the \cs{vbox} \cs{halign} structure that encloses the |
| 2425 |
% contents. Notice that we never get \cs{scriptscriptstyle}. That |
| 2426 |
% would require a \cs{mathchoice} (ugh). |
| 2427 |
% \begin{macrocode} |
| 2428 |
\ialign\bgroup\ifx c#1\hfil\fi |
| 2429 |
$\m@th\scriptstyle##$\hfil\crcr |
| 2430 |
}{% |
| 2431 |
\crcr\egroup\egroup |
| 2432 |
} |
| 2433 |
\else |
| 2434 |
\newenvironment{subarray}[1]{% |
| 2435 |
\vcenter\bgroup |
| 2436 |
\Let@ \restore@math@cr \default@tag |
| 2437 |
\baselineskip \Umathstacknumup \scriptstyle |
| 2438 |
\advance\baselineskip \Umathstackdenomdown \scriptstyle |
| 2439 |
\lineskip \Umathstackvgap \scriptstyle |
| 2440 |
\lineskiplimit \lineskip |
| 2441 |
\ialign\bgroup\ifx c#1\hfil\fi |
| 2442 |
\Ustartmath |
| 2443 |
\m@th\scriptstyle## |
| 2444 |
\Ustopmath |
| 2445 |
\hfil\crcr |
| 2446 |
}{% |
| 2447 |
\crcr\egroup\egroup |
| 2448 |
} |
| 2449 |
\fi |
| 2450 |
% \end{macrocode} |
| 2451 |
% \end{environment} |
| 2452 |
% |
| 2453 |
% \begin{macro}{\substack} |
| 2454 |
% The \cn{substack} command is just an abbreviation for the |
| 2455 |
% most common use of \env{subarray}. |
| 2456 |
% \changes{v2.17n}{2022/04/08}{Make command robust (gh/123)} |
| 2457 |
% \begin{macrocode} |
| 2458 |
\DeclareRobustCommand{\substack}[1]{\subarray{c}#1\endsubarray} |
| 2459 |
% \end{macrocode} |
| 2460 |
% \end{macro} |
| 2461 |
% |
| 2462 |
% \subsection{Matrices} |
| 2463 |
% |
| 2464 |
% \begin{environment}{smallmatrix} |
| 2465 |
% \env{smallmatrix} is again an alignment, this time in a centered |
| 2466 |
% box. The opening incantations are basically the same as those in |
| 2467 |
% \cs{multilimits@}, followed by the alignment itself. A remark: |
| 2468 |
% the baselineskip (|9\ex@|) used in \amstex/ is too large for |
| 2469 |
% use in text with the usual baselineskip of $12$ or $13$ points; we |
| 2470 |
% change it here to |6\ex@| and also adjust the \cs{lineskip} |
| 2471 |
% and \cs{lineskiplimit} slightly to compensate. (MJD) |
| 2472 |
% \begin{macrocode} |
| 2473 |
\newenvironment{smallmatrix}{\null\,\vcenter\bgroup |
| 2474 |
\Let@\restore@math@cr\default@tag |
| 2475 |
\baselineskip6\ex@ \lineskip1.5\ex@ \lineskiplimit\lineskip |
| 2476 |
\ialign\bgroup\hfil$\m@th\scriptstyle##$\hfil&&\thickspace\hfil |
| 2477 |
$\m@th\scriptstyle##$\hfil\crcr |
| 2478 |
}{% |
| 2479 |
\crcr\egroup\egroup\,% |
| 2480 |
} |
| 2481 |
% \end{macrocode} |
| 2482 |
% \end{environment} |
| 2483 |
% |
| 2484 |
% \begin{environment}{matrix} |
| 2485 |
% The \env{matrix} environment is just an \env{array} that provides |
| 2486 |
% up to ten centered columns, so that users don't have to give the |
| 2487 |
% col-spec argument explicitly---unless they want some of the columns |
| 2488 |
% noncentered, that is. The maximum number of columns is actually not |
| 2489 |
% fixed at ten but given by the counter |MatrixCols|, and can |
| 2490 |
% therefore be increased by changing that counter. |
| 2491 |
% |
| 2492 |
% The extra space of \cn{arraycolsep} that \env{array} adds on each |
| 2493 |
% side is a waste so we remove it here (perhaps we should instead |
| 2494 |
% remove it from \env{array} in general, but that's a harder task). |
| 2495 |
% |
| 2496 |
% TODO: Think about re-implementing \cn{matrix} to get rid of the |
| 2497 |
% \cs{c@MatrixCols} limit and have hard-wired preamble that doesn't |
| 2498 |
% have to be rebuilt each time. |
| 2499 |
% |
| 2500 |
% We must use \cn{renewenvironment} for \env{matrix} and |
| 2501 |
% \env{pmatrix} because \latex/ doesn't kill the definitions found in |
| 2502 |
% \fn{plain.tex}, even though it probably should because of their |
| 2503 |
% foreign syntax. |
| 2504 |
% \begin{macrocode} |
| 2505 |
\renewenvironment{matrix}{% |
| 2506 |
\matrix@check\matrix\env@matrix |
| 2507 |
}{% |
| 2508 |
\endarray \hskip -\arraycolsep |
| 2509 |
} |
| 2510 |
% \end{macrocode} |
| 2511 |
% \end{environment} |
| 2512 |
% |
| 2513 |
% \begin{macro}{\env@matrix} |
| 2514 |
% |
| 2515 |
% \begin{macrocode} |
| 2516 |
\def\env@matrix{\hskip -\arraycolsep |
| 2517 |
\let\@ifnextchar\new@ifnextchar |
| 2518 |
\array{*\c@MaxMatrixCols c}} |
| 2519 |
% \end{macrocode} |
| 2520 |
% \end{macro} |
| 2521 |
% |
| 2522 |
% \begin{macro}{\c@MaxMatrixCols} |
| 2523 |
% \begin{macrocode} |
| 2524 |
\newcount\c@MaxMatrixCols \c@MaxMatrixCols=10 |
| 2525 |
% \end{macrocode} |
| 2526 |
% \end{macro} |
| 2527 |
% |
| 2528 |
% \begin{macro}{\matrix@check} |
| 2529 |
% For various reasons, authors sometimes use the Plain \TeX{} form of |
| 2530 |
% \cn{matrix} or \cn{pmatrix} in \LaTeX{} documents. If they later |
| 2531 |
% add an invocation of the \pkg{amsmath} package to their document, |
| 2532 |
% the Plain \TeX{} syntax would lead to rather unintelligible error |
| 2533 |
% messages. The \cs{matrix@check} function does some checking to |
| 2534 |
% forestall that problem. |
| 2535 |
% \begin{macrocode} |
| 2536 |
\def\matrix@check#1{% |
| 2537 |
\@xp\ifx\csname\@currenvir\endcsname#1% |
| 2538 |
\else\matrix@error#1% |
| 2539 |
% \end{macrocode} |
| 2540 |
% This error recovery is not that good but is better than the |
| 2541 |
% infinite loop that can result from calling \cs{array} without a |
| 2542 |
% matching \cs{endarray}. (The array setup leaves \cs{par} empty.) |
| 2543 |
% \begin{macrocode} |
| 2544 |
\@xp\@gobble |
| 2545 |
\fi |
| 2546 |
} |
| 2547 |
% \end{macrocode} |
| 2548 |
% \end{macro} |
| 2549 |
% |
| 2550 |
% \begin{macro}{\matrix@error} |
| 2551 |
% |
| 2552 |
% \begin{macrocode} |
| 2553 |
\def\matrix@error#1{% |
| 2554 |
\@amsmath@err{% |
| 2555 |
Old form `\string#1' should be \string\begin{\@xp\@gobble\string#1}% |
| 2556 |
}{% |
| 2557 |
`\string#1{...}' is old Plain-TeX syntax whose use is |
| 2558 |
ill-advised in LaTeX.% |
| 2559 |
}% |
| 2560 |
} |
| 2561 |
% \end{macrocode} |
| 2562 |
% \end{macro} |
| 2563 |
% |
| 2564 |
% \begin{macrocode} |
| 2565 |
\renewenvironment{pmatrix}{% |
| 2566 |
\left(% |
| 2567 |
\matrix@check\pmatrix\env@matrix |
| 2568 |
}{ |
| 2569 |
\endmatrix\right)% |
| 2570 |
} |
| 2571 |
\newenvironment{bmatrix}{\left[\env@matrix}{\endmatrix\right]} |
| 2572 |
\newenvironment{Bmatrix}{% |
| 2573 |
\left\lbrace\env@matrix |
| 2574 |
}{% |
| 2575 |
\endmatrix\right\rbrace |
| 2576 |
} |
| 2577 |
\newenvironment{vmatrix}{\left\lvert\env@matrix}{\endmatrix\right\rvert} |
| 2578 |
\newenvironment{Vmatrix}{\left\lVert\env@matrix}{\endmatrix\right\rVert} |
| 2579 |
% \end{macrocode} |
| 2580 |
% |
| 2581 |
% \begin{macrocode} |
| 2582 |
\let\hdots\@ldots |
| 2583 |
% \end{macrocode} |
| 2584 |
% |
| 2585 |
% \begin{macrocode} |
| 2586 |
\newcommand{\hdotsfor}[1]{% |
| 2587 |
\ifx[#1\@xp\shdots@for\else\hdots@for\@ne{#1}\fi} |
| 2588 |
\newmuskip\dotsspace@ |
| 2589 |
\def\shdots@for#1]{\hdots@for{#1}} |
| 2590 |
\def\hdots@for#1#2{\multicolumn{#2}c% |
| 2591 |
{\m@th\[email protected]\mkern-#1\dotsspace@ |
| 2592 |
\xleaders\hbox{$\m@th\mkern#1\dotsspace@.\mkern#1\dotsspace@$}% |
| 2593 |
\hfill |
| 2594 |
\mkern-#1\dotsspace@}% |
| 2595 |
} |
| 2596 |
% \end{macrocode} |
| 2597 |
% |
| 2598 |
% \begin{environment}{cases} |
| 2599 |
% The easiest way to produce the \env{cases} environment is to base |
| 2600 |
% it on the \env{array} environment. We must use |
| 2601 |
% \cn{renewenvironment} to override the definition of \cn{cases} that |
| 2602 |
% \latex/ (unwisely) leaves in place from \fn{plain.tex}. |
| 2603 |
% \begin{macrocode} |
| 2604 |
\renewenvironment{cases}{% |
| 2605 |
\matrix@check\cases\env@cases |
| 2606 |
}{% |
| 2607 |
\endarray\right.% |
| 2608 |
} |
| 2609 |
\def\env@cases{% |
| 2610 |
\let\@ifnextchar\new@ifnextchar |
| 2611 |
\left\lbrace |
| 2612 |
\def\arraystretch{1.2}% |
| 2613 |
\array{@{}l@{\quad}l@{}}% |
| 2614 |
} |
| 2615 |
% \end{macrocode} |
| 2616 |
% \end{environment} |
| 2617 |
% |
| 2618 |
% |
| 2619 |
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2620 |
% \section{Equation sub-numbering} |
| 2621 |
% |
| 2622 |
% \begin{macrocode} |
| 2623 |
\newcounter{parentequation}% Counter for ``parent equation''. |
| 2624 |
% \end{macrocode} |
| 2625 |
% |
| 2626 |
% We can't assume \cs{ignorespacesafterend} is defined since it was |
| 2627 |
% not there in the earliest releases of \latex/ 2e. And we need to |
| 2628 |
% include the \cs{global} for the same reason. |
| 2629 |
% \begin{macrocode} |
| 2630 |
\@ifundefined{ignorespacesafterend}{% |
| 2631 |
\def\ignorespacesafterend{\global\@ignoretrue}% |
| 2632 |
}{} |
| 2633 |
% \end{macrocode} |
| 2634 |
% |
| 2635 |
% \begin{environment}{subequations} |
| 2636 |
% \begin{macrocode} |
| 2637 |
\newenvironment{subequations}{% |
| 2638 |
% \end{macrocode} |
| 2639 |
% Before sending down the `equation' counter to the subordinate |
| 2640 |
% level, add 1 using standard \cn{refstepcounter}. |
| 2641 |
% \begin{macrocode} |
| 2642 |
\refstepcounter{equation}% |
| 2643 |
% \end{macrocode} |
| 2644 |
% Define \cn{theparentequation} equivalent to current |
| 2645 |
% \cn{theequation}. \cn{edef} is necessary to expand the current |
| 2646 |
% value of the equation counter. This might in rare cases cause |
| 2647 |
% something to blow up, in which case the user needs to add |
| 2648 |
% \cn{protect}. |
| 2649 |
% \begin{macrocode} |
| 2650 |
\protected@edef\theparentequation{\theequation}% |
| 2651 |
\setcounter{parentequation}{\value{equation}}% |
| 2652 |
% \end{macrocode} |
| 2653 |
% And set the equation counter to 0, so that the normal incrementing |
| 2654 |
% processes in the various equation environments will produce the |
| 2655 |
% desired results. |
| 2656 |
% \begin{macrocode} |
| 2657 |
\setcounter{equation}{0}% |
| 2658 |
\def\theequation{\theparentequation\alph{equation}}% |
| 2659 |
\ignorespaces |
| 2660 |
}{% |
| 2661 |
\setcounter{equation}{\value{parentequation}}% |
| 2662 |
\ignorespacesafterend |
| 2663 |
} |
| 2664 |
% \end{macrocode} |
| 2665 |
% \end{environment} |
| 2666 |
% |
| 2667 |
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2668 |
% \section{Equation numbering} |
| 2669 |
% |
| 2670 |
% In the multiline equation environments provided here, the task |
| 2671 |
% of equation numbering is linked to the task of line breaking |
| 2672 |
% in the sense that it is the \cn{\\} command that marks where an |
| 2673 |
% equation number for the current line will be processed and added to |
| 2674 |
% the page. |
| 2675 |
% |
| 2676 |
% \begin{macro}{\numberwithin} |
| 2677 |
% Provide a convenient way to specify that equations should be |
| 2678 |
% numbered within sections. The \LaTeX{} kernel contains a similar command |
| 2679 |
% \cs{counterwithin} (with a slightly extended syntax) that can be used |
| 2680 |
% as a drop-in replacement for \cs{numberwithin}. |
| 2681 |
% \changes{v2.17n}{2022/04/08}{Make command robust (gh/123)} |
| 2682 |
% \begin{macrocode} |
| 2683 |
%\DeclareRobustCommand{\numberwithin}[3][\arabic]{% |
| 2684 |
% \@ifundefined{c@#2}{\@nocounterr{#2}}{% |
| 2685 |
% \@ifundefined{c@#3}{\@nocnterr{#3}}{% |
| 2686 |
% \@addtoreset{#2}{#3}% |
| 2687 |
% \@xp\xdef\csname the#2\endcsname{% |
| 2688 |
% \@xp\@nx\csname the#3\endcsname .\@nx#1{#2}}}}% |
| 2689 |
%} |
| 2690 |
% \end{macrocode} |
| 2691 |
% We are now using the \LaTeX{} kernel command and just make an |
| 2692 |
% alias for legacy documents. This also repairs a bug in the error |
| 2693 |
% message that the old \cs{numberwithin} definition showed. |
| 2694 |
% \changes{v2.17v}{2025/02/25}{Use \cs{counterwithin} for |
| 2695 |
% \cs{numberwithin} (gh/1673)} |
| 2696 |
% \begin{macrocode} |
| 2697 |
\DeclareCommandCopy\numberwithin\counterwithin |
| 2698 |
% \end{macrocode} |
| 2699 |
% \end{macro} |
| 2700 |
% |
| 2701 |
% \begin{macro}{\eqref} |
| 2702 |
% To make references to equation numbers easier, we provide |
| 2703 |
% \cn{eqref}. We almost don't need \cn{textup}, except that |
| 2704 |
% \cs{tagform@} doesn't supply the italic correction. |
| 2705 |
% \changes{v2.17n}{2022/04/08}{Make command robust (gh/123)} |
| 2706 |
% \begin{macrocode} |
| 2707 |
\DeclareRobustCommand{\eqref}[1]{\textup{\tagform@{\ref{#1}}}} |
| 2708 |
% \end{macrocode} |
| 2709 |
% \end{macro} |
| 2710 |
% |
| 2711 |
% \subsection{Preliminary macros} |
| 2712 |
% |
| 2713 |
% The following macros implement the \latex/ syntax for the |
| 2714 |
% \cn{\\} command, i.e. the possibility to add an asterisk to |
| 2715 |
% inhibit a page break, or an optional argument to denote additional |
| 2716 |
% vertical space. They are modelled more or less after the |
| 2717 |
% corresponding macros for \latex/'s \env{eqnarray} and \env{array} |
| 2718 |
% environments. |
| 2719 |
% |
| 2720 |
% [We can perhaps use the eqnarray mechanism if we change it so that |
| 2721 |
% it also uses \cs{openup}.] |
| 2722 |
% |
| 2723 |
% \begin{macro}{\dspbrk@lvl} |
| 2724 |
% We begin by defining the \cs{dspbrk@lvl} counter. This counter |
| 2725 |
% records the desirability of a break after the current row, as a |
| 2726 |
% number between $0$ and $4$. Its default value is $-1$ meaning that |
| 2727 |
% no explicit \cn{displaybreak} command was given, and the default |
| 2728 |
% \cs{interdisplaylinepenalty} is to be used. |
| 2729 |
% \begin{macrocode} |
| 2730 |
\newcount\dspbrk@lvl |
| 2731 |
\dspbrk@lvl=-1 |
| 2732 |
% \end{macrocode} |
| 2733 |
% \end{macro} |
| 2734 |
% |
| 2735 |
% \begin{macro}{\interdisplaylinepenalty} |
| 2736 |
% We set the \cs{interdisplaylinepenalty} to $10000$. |
| 2737 |
% \begin{macrocode} |
| 2738 |
\interdisplaylinepenalty\@M |
| 2739 |
% \end{macrocode} |
| 2740 |
% \end{macro} |
| 2741 |
% |
| 2742 |
% \begin{macro}{\allowdisplaybreaks} |
| 2743 |
% The \cn{allowdisplaybreaks} command. Since this is intended for use |
| 2744 |
% outside displayed formulas (typically in the preamble), it does not |
| 2745 |
% need to use \cs{new@ifnextchar}. |
| 2746 |
% \changes{v2.17n}{2022/04/08}{Make command robust (gh/123)} |
| 2747 |
% \begin{macrocode} |
| 2748 |
\DeclareRobustCommand{\allowdisplaybreaks}[1][4]{% |
| 2749 |
\interdisplaylinepenalty\getdsp@pen{#1}\relax |
| 2750 |
} |
| 2751 |
% \end{macrocode} |
| 2752 |
% \end{macro} |
| 2753 |
% |
| 2754 |
% \begin{macro}{\getdsp@pen} |
| 2755 |
% Modelled after \latex/'s \cs{@getpen}. We use higher numbers |
| 2756 |
% than would normally be provided by \cs{@lowpenalty}, |
| 2757 |
% \cs{@medpenalty}, and \cs{@highpenalty}, since display |
| 2758 |
% breaks are almost always less desirable. |
| 2759 |
% \begin{macrocode} |
| 2760 |
\def\getdsp@pen#1{% |
| 2761 |
\ifcase #1\@M \or 9999 \or 6999 \or 2999 \or \z@\fi |
| 2762 |
} |
| 2763 |
% \end{macrocode} |
| 2764 |
% \end{macro} |
| 2765 |
% |
| 2766 |
% \begin{macro}{\displaybreak} |
| 2767 |
% \begin{macro}{\dspbrk@} |
| 2768 |
% \begin{macro}{\dspbrk@context} |
| 2769 |
% \begin{macro}{\nogood@displaybreak} |
| 2770 |
% For breaks in a certain row of a alignment. |
| 2771 |
% \changes{v2.17n}{2022/04/08}{Make command robust (gh/123)} |
| 2772 |
% \begin{macrocode} |
| 2773 |
\DeclareRobustCommand{\displaybreak}{\new@ifnextchar[\dspbrk@{\dspbrk@[4]}} |
| 2774 |
\chardef\dspbrk@context=\sixt@@n |
| 2775 |
% \end{macrocode} |
| 2776 |
% |
| 2777 |
% \begin{macrocode} |
| 2778 |
\def\dspbrk@[#1]{% |
| 2779 |
\ifmeasuring@ |
| 2780 |
\else |
| 2781 |
\ifcase\dspbrk@context % case 0 --- OK |
| 2782 |
\global\dspbrk@lvl #1\relax |
| 2783 |
\or % case 1 --- inside a box |
| 2784 |
\nogood@displaybreak |
| 2785 |
\else % other cases --- outside of a display |
| 2786 |
\@amsmath@err{\Invalid@@\displaybreak}\@eha |
| 2787 |
\fi |
| 2788 |
\fi |
| 2789 |
} |
| 2790 |
% \end{macrocode} |
| 2791 |
% |
| 2792 |
% This is the value of \cn{displaybreak} when it occurs inside some |
| 2793 |
% structure where it will not work. |
| 2794 |
% \begin{macrocode} |
| 2795 |
\def\nogood@displaybreak{% |
| 2796 |
\@amsmath@err{\protect |
| 2797 |
\displaybreak\space cannot be applied here}% |
| 2798 |
{One of the enclosing environments creates an |
| 2799 |
unbreakable box\MessageBreak |
| 2800 |
(e.g., split, aligned, gathered, ...).}% |
| 2801 |
} |
| 2802 |
% \end{macrocode} |
| 2803 |
% \end{macro} |
| 2804 |
% \end{macro} |
| 2805 |
% \end{macro} |
| 2806 |
% \end{macro} |
| 2807 |
% |
| 2808 |
% \begin{macro}{\math@cr} |
| 2809 |
% The macro \cs{math@cr} ends a row inside one of the equation |
| 2810 |
% environments, i.e., this is the internal name of the \cn{\\} |
| 2811 |
% commands in these environments. As usual for this kind of macro |
| 2812 |
% inside of alignments we insert a special brace into \tex/'s input |
| 2813 |
% stream. The initial \cs{relax} is needed to trigger entry into the |
| 2814 |
% \textit{u} template of the current column if the author ended the |
| 2815 |
% current row with an empty column (i.e., the mathcr was immediately |
| 2816 |
% preceded by an ampersand). |
| 2817 |
% \changes{v2.17j}{2021/04/20}{Use \cs{protected} for \cs{\bslash} variant (gh/548)} |
| 2818 |
% \begin{macrocode} |
| 2819 |
\protected\def\math@cr{\relax\iffalse{\fi\ifnum0=`}\fi |
| 2820 |
% \end{macrocode} |
| 2821 |
% The first step is now to check whether an asterisk follows. |
| 2822 |
% \cs{@eqpen} is used to hold the penalty value to be put on |
| 2823 |
% the vertical list. |
| 2824 |
% Then we call up \cs{math@cr@} which performs the next step. |
| 2825 |
% If an asterisk is read page breaking is inhibited. |
| 2826 |
% \begin{macrocode} |
| 2827 |
\@ifstar{\global\@eqpen\@M\math@cr@}% |
| 2828 |
% \end{macrocode} |
| 2829 |
% Otherwise we have to check the \cs{dspbrk@lvl} value. |
| 2830 |
% \begin{macrocode} |
| 2831 |
{\global\@eqpen |
| 2832 |
\ifnum\dspbrk@lvl <\z@ \interdisplaylinepenalty |
| 2833 |
\else -\@getpen\dspbrk@lvl \fi |
| 2834 |
\math@cr@}} |
| 2835 |
% \end{macrocode} |
| 2836 |
% \end{macro} |
| 2837 |
% |
| 2838 |
% \begin{macro}{\math@cr@} |
| 2839 |
% The purpose of \cs{math@cr@} is to check whether an optional |
| 2840 |
% argument follows. If not it provides \cs{z@} as default |
| 2841 |
% value. |
| 2842 |
% \begin{macrocode} |
| 2843 |
\def\math@cr@{\new@ifnextchar[\math@cr@@{\math@cr@@[\z@]}} |
| 2844 |
% \end{macrocode} |
| 2845 |
% \end{macro} |
| 2846 |
% |
| 2847 |
% \begin{macro}{\math@cr@@} |
| 2848 |
% \cs{math@cr@@} closes the special brace opened in |
| 2849 |
% \cs{math@cr}, and calls \cs{math@cr@@@} which is supposed |
| 2850 |
% the `real' row ending command. The meaning of this macro depends |
| 2851 |
% on the environment in which it is used. |
| 2852 |
% \begin{macrocode} |
| 2853 |
\def\math@cr@@[#1]{\ifnum0=`{\fi \iffalse}\fi\math@cr@@@ |
| 2854 |
% \end{macrocode} |
| 2855 |
% Finally we put the additional space onto the vertical list. |
| 2856 |
% \begin{macrocode} |
| 2857 |
\noalign{\vskip#1\relax}} |
| 2858 |
% \end{macrocode} |
| 2859 |
% \end{macro} |
| 2860 |
% |
| 2861 |
% \begin{macro}{\Let@} |
| 2862 |
% \cs{Let@} is called by all environments where \cn{\\} |
| 2863 |
% ends a row of an alignment. |
| 2864 |
% \begin{macrocode} |
| 2865 |
\def\Let@{\let\\\math@cr} |
| 2866 |
% \end{macrocode} |
| 2867 |
% \end{macro} |
| 2868 |
% |
| 2869 |
% \begin{macro}{\restore@math@cr} |
| 2870 |
% We mentioned already that the exact meaning of \cs{math@cr@@@} |
| 2871 |
% depends on the current environment. Since it is often a simple |
| 2872 |
% \cs{cr} we provide \cs{restore@math@cr} to reset it. |
| 2873 |
% \begin{macrocode} |
| 2874 |
\def\restore@math@cr{\def\math@cr@@@{\cr}} |
| 2875 |
% \end{macrocode} |
| 2876 |
% This is also the default case. |
| 2877 |
% \begin{macrocode} |
| 2878 |
\restore@math@cr |
| 2879 |
% \end{macrocode} |
| 2880 |
% \end{macro} |
| 2881 |
% |
| 2882 |
% \begin{macro}{\intertext} |
| 2883 |
% \begin{macro}{\intertext@} |
| 2884 |
% The \cn{intertext} command is used for inserting text between the |
| 2885 |
% rows of an alignment. It might better be done as an environment, |
| 2886 |
% but the \cs{begingroup} from \cn{begin} would cause the |
| 2887 |
% \cs{noalign} to fail. |
| 2888 |
% \begin{macrocode} |
| 2889 |
\newcommand{\intertext}{\@amsmath@err{\Invalid@@\intertext}\@eha} |
| 2890 |
% \end{macrocode} |
| 2891 |
% \cs{intertext@} is called by all environments that allow the use of |
| 2892 |
% the \cn{intertext} command. |
| 2893 |
% \begin{macrocode} |
| 2894 |
\def\intertext@{% |
| 2895 |
\def\intertext##1{% |
| 2896 |
% \end{macrocode} |
| 2897 |
% If current mode is not vmode, the most likely reason is that the |
| 2898 |
% writer forgot the \cn{\\} that is supposed to precede |
| 2899 |
% \cn{intertext}. All right, then, let's try adding it our ownself. |
| 2900 |
% But, to be slightly careful: \cn{\\} does a futurelet, and it's |
| 2901 |
% slightly dangerous to allow a letted token to barge around loose in |
| 2902 |
% our internal code when it has been let to a conditional token |
| 2903 |
% like \cs{fi}. So let's interpose something in front of the \cs{fi} |
| 2904 |
% for the futurelet to take instead. (And careful again: it has to be |
| 2905 |
% something evanescent, not (e.g.) \cs{relax} which would cause the |
| 2906 |
% next halign cell to fire up and keep \cs{noalign} from working.) |
| 2907 |
% \begin{macrocode} |
| 2908 |
\ifvmode\else\\\@empty\fi |
| 2909 |
\noalign{% |
| 2910 |
\penalty\postdisplaypenalty\vskip\belowdisplayskip |
| 2911 |
\vbox{\normalbaselines |
| 2912 |
% \end{macrocode} |
| 2913 |
% We need to do something extra if the outside environment is a list |
| 2914 |
% environment. I don't see offhand an elegant way to test ``are we |
| 2915 |
% inside any list environment'' that is both easy and reliable (for |
| 2916 |
% example, checking for zero \cs{@totalleftmargin} wouldn't catch the |
| 2917 |
% case where \cs{@totalleftmargin} is zero but \cs{linewidth} is less |
| 2918 |
% than \cs{columnwidth}), so it seems to me checking \cs{linewidth} |
| 2919 |
% is the best practical solution. |
| 2920 |
% \changes{v2.15c}{2016/05/23}{\cs{ignorespaces} at the start of the argument} |
| 2921 |
% \begin{macrocode} |
| 2922 |
\ifdim\linewidth=\columnwidth |
| 2923 |
\else \parshape\@ne \@totalleftmargin \linewidth |
| 2924 |
\fi |
| 2925 |
\noindent\ignorespaces##1\par}% |
| 2926 |
\penalty\predisplaypenalty\vskip\abovedisplayskip% |
| 2927 |
}% |
| 2928 |
}} |
| 2929 |
% \end{macrocode} |
| 2930 |
% \end{macro} |
| 2931 |
% \end{macro} |
| 2932 |
% |
| 2933 |
% |
| 2934 |
% \subsection{Implementing tags and labels} |
| 2935 |
% |
| 2936 |
% In this section we describe some of the macros needed to make the |
| 2937 |
% \cn{tag} command work in various places. We start by defining a |
| 2938 |
% help text to be used when a \cn{tag} command is used somewhere |
| 2939 |
% it should not appear. |
| 2940 |
% |
| 2941 |
% \begin{macro}{\tag@help} |
| 2942 |
% This is the default error help text provided when \cn{tag} |
| 2943 |
% generates an error message. |
| 2944 |
% Note that \cs{newhelp} generates a control sequence name |
| 2945 |
% from the string given as its argument so that a leading |
| 2946 |
% backslash is provided automatically. |
| 2947 |
% \begin{macrocode} |
| 2948 |
\newhelp\tag@help |
| 2949 |
{tag cannot be used at this point.\space |
| 2950 |
If you don't understand why^^Jyou should consult |
| 2951 |
the documentation.^^JBut don't worry: just continue, and I'll |
| 2952 |
forget what happened.} |
| 2953 |
% \end{macrocode} |
| 2954 |
% \end{macro} |
| 2955 |
% |
| 2956 |
% \begin{macro}{\gobble@tag} |
| 2957 |
% This macro is to be used when \cn{tag} should silently |
| 2958 |
% skip its argument. |
| 2959 |
% It is made to handle the \qc{\*}-form of \cn{tag} as well. |
| 2960 |
% \begin{macrocode} |
| 2961 |
\def\gobble@tag{\@ifstar\@gobble\@gobble} |
| 2962 |
% \end{macrocode} |
| 2963 |
% \end{macro} |
| 2964 |
% |
| 2965 |
% \begin{macro}{\invalid@tag} |
| 2966 |
% \cs{invalid@tag} is a macro that should be used whenever |
| 2967 |
% \cn{tag} appears in an illegal place. |
| 2968 |
% It sets up \cs{tag@help} (as defined above) as help message, |
| 2969 |
% prints its argument as error message, and skips \cn{tag}'s |
| 2970 |
% argument. |
| 2971 |
% \begin{macrocode} |
| 2972 |
\def\invalid@tag#1{\@amsmath@err{#1}{\the\tag@help}\gobble@tag} |
| 2973 |
% \end{macrocode} |
| 2974 |
% \end{macro} |
| 2975 |
% |
| 2976 |
% \begin{macro}{\dft@tag} |
| 2977 |
% \begin{macro}{\default@tag} |
| 2978 |
% \cs{dft@tag} provides a convenient way to disallow the |
| 2979 |
% use of \cn{tag} at certain points. |
| 2980 |
% One simply has to write |
| 2981 |
% \begin{verbatim} |
| 2982 |
%\let\tag\dft@tag |
| 2983 |
% \end{verbatim} |
| 2984 |
% and the \cn{tag} command will produce an error message, |
| 2985 |
% with a suitable error help text, and discard its argument. |
| 2986 |
% \begin{macrocode} |
| 2987 |
\def\dft@tag{\invalid@tag{\string\tag\space not allowed here}} |
| 2988 |
% \end{macrocode} |
| 2989 |
% Since this is used several times we provide an abbreviation for |
| 2990 |
% it. |
| 2991 |
% \begin{macrocode} |
| 2992 |
\def\default@tag{\let\tag\dft@tag} |
| 2993 |
% \end{macrocode} |
| 2994 |
% Since this is also the default, i.e.\ the \cn{tag} command |
| 2995 |
% should not be used except in special places, we issue a |
| 2996 |
% \cs{default@tag} command. |
| 2997 |
% \begin{macrocode} |
| 2998 |
\default@tag |
| 2999 |
% \end{macrocode} |
| 3000 |
% \end{macro} |
| 3001 |
% \end{macro} |
| 3002 |
% |
| 3003 |
% Now that we have taken care of the case that \cn{tag} is not |
| 3004 |
% allowed we will provide some macros to process tags appropriately. |
| 3005 |
% As the user documentation states, a \cn{tag} command (without |
| 3006 |
% the asterisk typesets its argument according to the document |
| 3007 |
% styles' conventions, whereas a \cn{tag*} command typesets its |
| 3008 |
% argument exactly as given. We define therefore the following |
| 3009 |
% interface: |
| 3010 |
% |
| 3011 |
% \begin{macro}{\maketag@@} |
| 3012 |
% \begin{macro}{\maketag@@@} |
| 3013 |
% \begin{macro}{\tagform@} |
| 3014 |
% \cn{tag} is supposed to call \cs{maketag@@} which checks |
| 3015 |
% whether an asterisk follows. If this is the case it calls up |
| 3016 |
% \cs{maketag@@@} which sets its argument `as is'. Otherwise |
| 3017 |
% \cs{tagform@} is called to do the job. (This macro is to be |
| 3018 |
% defined appropriately by the document style.) |
| 3019 |
% \begin{macrocode} |
| 3020 |
\def\maketag@@{\@ifstar\maketag@@@\tagform@} |
| 3021 |
% \end{macrocode} |
| 3022 |
% We define \cs{maketag@@@} to use the normal font of the document |
| 3023 |
% text (since this is the usual practice for numbering of document |
| 3024 |
% elements) and to put a box around the tag. Furthermore we use |
| 3025 |
% \cs{m@th} for exceptional cases where the tag involves a |
| 3026 |
% superscript or some such math. (Probably from an explicit use of |
| 3027 |
% \cs{tag*} rather than from the automatic numbering.) |
| 3028 |
% \begin{macrocode} |
| 3029 |
\def\maketag@@@#1{\hbox{\m@th\normalfont#1}} |
| 3030 |
% \end{macrocode} |
| 3031 |
% We use the following default definition for \cs{tagform@} |
| 3032 |
% that puts only parentheses around the tag. |
| 3033 |
% \begin{macrocode} |
| 3034 |
\def\tagform@#1{\maketag@@@{(\ignorespaces#1\unskip\@@italiccorr)}} |
| 3035 |
% \end{macrocode} |
| 3036 |
% \end{macro} |
| 3037 |
% \end{macro} |
| 3038 |
% \end{macro} |
| 3039 |
% |
| 3040 |
% We need to insinuate \cs{tagform@} into \cs{@eqnnum} in case |
| 3041 |
% \env{eqnarray} is used (probably in a document that was originally |
| 3042 |
% written without use of the \pkg{amsmath} package). |
| 3043 |
% \begin{macrocode} |
| 3044 |
\iftagsleft@ |
| 3045 |
\def\@eqnnum{\hbox to1sp{}\rlap{\normalfont\normalcolor |
| 3046 |
\hskip -\displaywidth\tagform@\theequation}} |
| 3047 |
\else |
| 3048 |
\def\@eqnnum{{\normalfont\normalcolor \tagform@\theequation}} |
| 3049 |
\fi |
| 3050 |
% \end{macrocode} |
| 3051 |
% |
| 3052 |
% \begin{macro}{\thetag} |
| 3053 |
% Sometimes one needs to set a literal tag according to the rules of |
| 3054 |
% the document style. To achieve this we provide the \cn{thetag} |
| 3055 |
% command. It typesets its argument by calling \cs{tagform@} on |
| 3056 |
% it. |
| 3057 |
% \begin{macrocode} |
| 3058 |
\newcommand{\thetag}{\leavevmode\tagform@} |
| 3059 |
% \end{macrocode} |
| 3060 |
% \end{macro} |
| 3061 |
% |
| 3062 |
% \begin{macro}{\df@tag} |
| 3063 |
% \begin{macro}{\make@df@tag} |
| 3064 |
% \begin{macro}{\make@df@tag@@} |
| 3065 |
% \begin{macro}{\make@df@tag@@@} |
| 3066 |
% Sometimes it is necessary for a \cn{tag} command to store a tag |
| 3067 |
% in a safe place and to process it later, e.g., for a tag in a row |
| 3068 |
% of an alignment where the tag can only be typeset when the |
| 3069 |
% \cn{\\} at the end of the row was seen. Such a tag is stored in |
| 3070 |
% the macro \cs{df@tag} (for `deferred tag'). For this purpose we |
| 3071 |
% provide the \cs{make@df@tag} macro. It is built very similar to |
| 3072 |
% the \cs{maketag@@} macro above. |
| 3073 |
% \begin{macrocode} |
| 3074 |
\let\df@tag\@empty |
| 3075 |
\def\make@df@tag{% |
| 3076 |
% \end{macrocode} |
| 3077 |
% We set \cs{@currentcounter} here so that it applies to both branches. |
| 3078 |
%\changes{v2.17l}{2021/10/15}{Explicitly set \cs{@currentcounter} (gh/687)} |
| 3079 |
% \begin{macrocode} |
| 3080 |
\def\@currentcounter{equation}% |
| 3081 |
\@ifstar\make@df@tag@@\make@df@tag@@@} |
| 3082 |
% \end{macrocode} |
| 3083 |
% \cs{make@df@tag} sets \cs{@currentlabel} and defines |
| 3084 |
% \cs{df@tag} appropriately. |
| 3085 |
% |
| 3086 |
% To simplify the task of tracking \cs{tag} and \cs{label} |
| 3087 |
% commands inside math display environments, we defer \cs{label} |
| 3088 |
% commands until the tag is typeset, similar to the way that |
| 3089 |
% \cs{tag}s themselves are deferred. This allows arbitrary |
| 3090 |
% placement of \cs{label} and \cs{tag} commands and also means we |
| 3091 |
% only increment the \cs{equation} counter when we really need to, |
| 3092 |
% thus avoiding the \cs{setb@ck} nonsense that used to be required. |
| 3093 |
% |
| 3094 |
% \begin{macrocode} |
| 3095 |
\def\make@df@tag@@#1{% |
| 3096 |
\gdef\df@tag{\maketag@@@{#1}\def\@currentlabel{#1}}} |
| 3097 |
% \end{macrocode} |
| 3098 |
% Autogenerated number: |
| 3099 |
% \begin{macrocode} |
| 3100 |
\def\make@df@tag@@@#1{\gdef\df@tag{\tagform@{#1}% |
| 3101 |
\toks@\@xp{\p@equation{#1}}\edef\@currentlabel{\the\toks@}}} |
| 3102 |
% \end{macrocode} |
| 3103 |
% \end{macro} |
| 3104 |
% \end{macro} |
| 3105 |
% \end{macro} |
| 3106 |
% \end{macro} |
| 3107 |
% |
| 3108 |
% \begin{macro}{\ltx@label} |
| 3109 |
% \begin{macro}{\label@in@display} |
| 3110 |
% \begin{macro}{\df@label} |
| 3111 |
% Next, we store the default definition of \cs{label} in |
| 3112 |
% \cs{ltx@label} and then define a new version of \cs{label} for use |
| 3113 |
% in math display environments. \cs{label@in@display} merely issues a |
| 3114 |
% warning message if there is already a pending label (which will be |
| 3115 |
% discarded) and then stores the label in \cs{df@label}. |
| 3116 |
% Delay saving the label in case other packages adjust the definition. |
| 3117 |
% \begin{macrocode} |
| 3118 |
\AddToHook{begindocument/end}{\let\ltx@label\label} |
| 3119 |
% \end{macrocode} |
| 3120 |
% In the output routine the label should do nothing. |
| 3121 |
% \changes{v2.17z}{2025/07/09}{Suppress \cs{ltx@label} in output routine (gh/1815)} |
| 3122 |
% \begin{macrocode} |
| 3123 |
\AddToHook{build/page/reset}{\let \ltx@label \@gobble@with@sphack@om} |
| 3124 |
% \end{macrocode} |
| 3125 |
% |
| 3126 |
% \begin{macrocode} |
| 3127 |
\def\label@in@display{% |
| 3128 |
\ifx\df@label\@empty\else |
| 3129 |
\@amsmath@err{Multiple \string\label's: |
| 3130 |
label '\df@label' will be lost}\@eha |
| 3131 |
\fi |
| 3132 |
\gdef\df@label |
| 3133 |
} |
| 3134 |
% \end{macrocode} |
| 3135 |
% In case there is an enumerate inside a minipage inside an equation, |
| 3136 |
% we need to reset \cn{label} to its normal value: |
| 3137 |
% \changes{v2.17u}{2025/01/11}{Correct 30 years old typo: |
| 3138 |
% \cs{@arrayparboxrestore} needs changing not |
| 3139 |
% \cs{@arrayboxrestore} (gh/1608)} |
| 3140 |
% \begin{macrocode} |
| 3141 |
\toks@\@xp{\@arrayparboxrestore \let\label\ltx@label}% |
| 3142 |
\edef\@arrayparboxrestore{\the\toks@} |
| 3143 |
% \end{macrocode} |
| 3144 |
% |
| 3145 |
% \begin{macrocode} |
| 3146 |
\let\df@label\@empty |
| 3147 |
% \end{macrocode} |
| 3148 |
% \end{macro} |
| 3149 |
% \end{macro} |
| 3150 |
% \end{macro} |
| 3151 |
% |
| 3152 |
% \begin{macro}{\make@display@tag} |
| 3153 |
% Now we define a macro to process \cs{tag} and \cs{label} commands |
| 3154 |
% in various display environments. If the |@eqnsw| switch is set, |
| 3155 |
% then we should supply an equation number; otherwise, if the |
| 3156 |
% |@tag| switch is set, we should use the tag stored in |
| 3157 |
% \cs{df@tag}. Finally, we process any pending \cs{label}s. |
| 3158 |
% |
| 3159 |
% TODO: Arguably, \cs{make@display@tag} should issue a warning |
| 3160 |
% message if there is a \cs{label} but neither a tag nor an |
| 3161 |
% equation number. Also, it would probably be worthwhile to |
| 3162 |
% explore whether \cs{iftag@} could be done away with and replaced |
| 3163 |
% by checks to see if \cs{df@tag} is empty or not. |
| 3164 |
% \begin{macrocode} |
| 3165 |
\def\make@display@tag{% |
| 3166 |
\if@eqnsw \incr@eqnum \print@eqnum |
| 3167 |
\else \iftag@ \df@tag \global\let\df@tag\@empty \fi |
| 3168 |
\fi |
| 3169 |
% \end{macrocode} |
| 3170 |
% Need to check the \cs{ifmeasuring@} flag otherwise the \cs{write} |
| 3171 |
% node from \cn{label} might be discarded in a temp box and clearing |
| 3172 |
% \cs{df@label} will keep it from being reiterated on the real |
| 3173 |
% typesetting pass. |
| 3174 |
% \begin{macrocode} |
| 3175 |
\ifmeasuring@ |
| 3176 |
\else |
| 3177 |
\ifx\df@label\@empty |
| 3178 |
\else |
| 3179 |
\@xp\ltx@label\@xp{\df@label}% |
| 3180 |
\global\let\df@label\@empty |
| 3181 |
\fi |
| 3182 |
\fi |
| 3183 |
} |
| 3184 |
% \end{macrocode} |
| 3185 |
% \end{macro} |
| 3186 |
% |
| 3187 |
% Now we define the special versions of \cn{tag} used within the |
| 3188 |
% \env{align} environments. |
| 3189 |
% |
| 3190 |
% \begin{macro}{\tag@in@align} |
| 3191 |
% The \cn{tag} command may only appear once in a row of |
| 3192 |
% an alignment. Therefore we first check the switch |tag@| |
| 3193 |
% that is set to false at the begin of every row. |
| 3194 |
% If this switch is true a \cn{tag} was already given in this |
| 3195 |
% row and we define \cs{next@} to expand to a call to |
| 3196 |
% \cs{invalid@tag}. |
| 3197 |
% \begin{macrocode} |
| 3198 |
\def\tag@in@align{% |
| 3199 |
\relax |
| 3200 |
\iftag@ |
| 3201 |
\DN@{\invalid@tag{Multiple \string\tag}}% |
| 3202 |
\else |
| 3203 |
% \end{macrocode} |
| 3204 |
% Otherwise we set the |tag@| switch. But there is more to |
| 3205 |
% be done: we must also prevent the automatic generation of a |
| 3206 |
% tag. Therefore we also reset the |@eqnsw|. |
| 3207 |
% \begin{macrocode} |
| 3208 |
\global\tag@true |
| 3209 |
% \end{macrocode} |
| 3210 |
% Changed to \cs{nonumber}, since that seems to be all that's |
| 3211 |
% required.---dmj, 1994/12/21 |
| 3212 |
% \begin{macrocode} |
| 3213 |
\nonumber |
| 3214 |
% \end{macrocode} |
| 3215 |
% Within a row of an \env{align} environment the \cn{tag} |
| 3216 |
% command must not typeset the tag immediately since its |
| 3217 |
% position can be determined only later. |
| 3218 |
% Therefore we use the \cs{make@df@tag} macro defined |
| 3219 |
% earlier. |
| 3220 |
% Finally we call \cs{next@} to process the argument |
| 3221 |
% that follows. |
| 3222 |
% \begin{macrocode} |
| 3223 |
\let\next@\make@df@tag |
| 3224 |
\fi |
| 3225 |
\next@ |
| 3226 |
} |
| 3227 |
% \end{macrocode} |
| 3228 |
% \end{macro} |
| 3229 |
% |
| 3230 |
% \begin{macro}{\raisetag} |
| 3231 |
% Usage: \cn{raisetag} \meta{dimen} |
| 3232 |
% |
| 3233 |
% This will modify the vertical placement of the tag of the current |
| 3234 |
% equation by \meta{dimen}. Note that according to the current uses |
| 3235 |
% of \cs{raise@tag} in e.g., \cs{place@tag@gather}, no adjustment |
| 3236 |
% occurs if the tag falls in its normal position; i.e., \cn{raisetag} |
| 3237 |
% has no effect unless the tag has already been shifted off-line. |
| 3238 |
% |
| 3239 |
% \begin{macrocode} |
| 3240 |
\newcommand{\raisetag}[1]{\skip@#1\relax |
| 3241 |
\xdef\raise@tag{\vskip\iftagsleft@\else-\fi\the\skip@\relax}% |
| 3242 |
} |
| 3243 |
% \end{macrocode} |
| 3244 |
% \cn{raise@tag} will be reemptied at the beginning of each equation, |
| 3245 |
% which might occur at a |\begin{xxx}| or \cn{\\}. |
| 3246 |
% \begin{macrocode} |
| 3247 |
\let\raise@tag\@empty |
| 3248 |
% \end{macrocode} |
| 3249 |
% \end{macro} |
| 3250 |
% |
| 3251 |
% \begin{macro}{\notag} |
| 3252 |
% For consistency we provide \cn{notag}, equivalent to |
| 3253 |
% \cn{nonumber}. The alternative would have been to rename |
| 3254 |
% \cn{tag} as \cn{number} to go along with \cn{nonumber}, |
| 3255 |
% but of course \cs{number} is a \tex/ primitive that should not |
| 3256 |
% be redefined. |
| 3257 |
% \begin{macrocode} |
| 3258 |
\newcommand{\notag}{\nonumber} |
| 3259 |
% \end{macrocode} |
| 3260 |
% \end{macro} |
| 3261 |
% |
| 3262 |
% \begin{macro}{\nonumber} |
| 3263 |
% Need to add some additional code to \cn{nonumber} to deal with some |
| 3264 |
% complications related to nested environments. |
| 3265 |
% \begin{macrocode} |
| 3266 |
\renewcommand{\nonumber}{% |
| 3267 |
\if@eqnsw |
| 3268 |
\ifx\incr@eqnum\@empty \addtocounter{equation}\m@ne \fi |
| 3269 |
\fi |
| 3270 |
\let\print@eqnum\@empty \let\incr@eqnum\@empty |
| 3271 |
\global\@eqnswfalse |
| 3272 |
} |
| 3273 |
% \end{macrocode} |
| 3274 |
% |
| 3275 |
% \begin{macrocode} |
| 3276 |
\def\print@eqnum{\tagform@\theequation} |
| 3277 |
\def\incr@eqnum{\refstepcounter{equation}\let\incr@eqnum\@empty} |
| 3278 |
% \end{macrocode} |
| 3279 |
% \end{macro} |
| 3280 |
% |
| 3281 |
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3282 |
% \section{Multiline equation environments} |
| 3283 |
% |
| 3284 |
% \subsection{Remarks} |
| 3285 |
% |
| 3286 |
% In late 1994 David M. Jones did a thorough overhaul of these |
| 3287 |
% environments so that the number placement and a few other aspects |
| 3288 |
% are substantially improved over the original versions that were |
| 3289 |
% ported essentially unchanged from \fn{amstex.tex} in 1989. Most of |
| 3290 |
% the commentary in this section is DMJ's, and comments of any |
| 3291 |
% significance that I added are marked by my initials and date |
| 3292 |
% [mjd, 1995/01/11]. |
| 3293 |
% |
| 3294 |
% \subsection{Preliminaries} |
| 3295 |
% |
| 3296 |
% |
| 3297 |
% |
| 3298 |
% \begin{macro}{\dollardollar@begin,\dollardollar@end} |
| 3299 |
% \changes{v2.17w}{2025/03/08}{Macro added for tagging support} |
| 3300 |
% To support tagging \LaTeX{} needs some control at the end of a |
| 3301 |
% display math formula. It therefore implements two commands that hide |
| 3302 |
% the \verb=$$=. The tagging code can then redefine those to gain |
| 3303 |
% control at the right moment without the need for further |
| 3304 |
% adjustment by a package author. Here we provide them, just in |
| 3305 |
% case this version of the package is used with an older format. |
| 3306 |
% \begin{macrocode} |
| 3307 |
\providecommand\dollardollar@begin{$$} |
| 3308 |
\providecommand\dollardollar@end{$$} |
| 3309 |
% \end{macrocode} |
| 3310 |
% \end{macro} |
| 3311 |
% |
| 3312 |
% |
| 3313 |
% |
| 3314 |
% \begin{macro}{\ifinalign@} |
| 3315 |
% \begin{macro}{\ifingather@} |
| 3316 |
% We define two switches that are set to true in certain |
| 3317 |
% alignments: |inalign@| and |ingather@| inside of |
| 3318 |
% the \env{align} and \env{gather} environments. |
| 3319 |
% These switches are needed to control certain actions that |
| 3320 |
% depend on the surrounding conditions, more specifically: |
| 3321 |
% on the setting already done by the surrounding environments. |
| 3322 |
% \begin{macrocode} |
| 3323 |
\newif\ifinalign@ |
| 3324 |
\newif\ifingather@ |
| 3325 |
% \end{macrocode} |
| 3326 |
% \begin{histnote} |
| 3327 |
% Removed the \cs{ifinany@} test [mjd,1999/06/28] since it was mainly |
| 3328 |
% used for the purpose now handled by \cs{spread@equation}. |
| 3329 |
% \changes{v1.2g}{1999/06/28}{Removed ifinany@} |
| 3330 |
% \end{histnote} |
| 3331 |
% \end{macro} |
| 3332 |
% \end{macro} |
| 3333 |
% |
| 3334 |
% \begin{macro}{\@arrayparboxrestore} |
| 3335 |
% Here we must reset a few additional parameters. |
| 3336 |
% \begin{macrocode} |
| 3337 |
\@xp\def\@xp\@arrayparboxrestore\@xp{\@arrayparboxrestore |
| 3338 |
\ingather@false\inalign@false \default@tag |
| 3339 |
\let\spread@equation\@spread@equation |
| 3340 |
\let\reset@equation\@empty |
| 3341 |
\def\print@eqnum{\tagform@\theequation}% |
| 3342 |
\def\incr@eqnum{\refstepcounter{equation}\let\incr@eqnum\@empty}% |
| 3343 |
} |
| 3344 |
% \end{macrocode} |
| 3345 |
% \end{macro} |
| 3346 |
% |
| 3347 |
% \begin{macro}{\iftag@} |
| 3348 |
% The switch |tag@| is set to false at the beginning of every |
| 3349 |
% row and set to true by a \cn{tag} command. |
| 3350 |
% This allows us to check whether there is more than one tag on |
| 3351 |
% a row. |
| 3352 |
% \begin{macrocode} |
| 3353 |
\newif\iftag@ |
| 3354 |
% \end{macrocode} |
| 3355 |
% \end{macro} |
| 3356 |
% |
| 3357 |
% \begin{macro}{\ifst@rred} |
| 3358 |
% The switch |st@rred| is set to true by all starred environments |
| 3359 |
% and set to false by the unstarred versions. |
| 3360 |
% One exception is the \env{xxalignat} environment where this is set |
| 3361 |
% to true. |
| 3362 |
% \begin{macrocode} |
| 3363 |
\newif\ifst@rred |
| 3364 |
% \end{macrocode} |
| 3365 |
% \end{macro} |
| 3366 |
% |
| 3367 |
% \begin{macro}{\ifmeasuring@} |
| 3368 |
% All display environments get typeset twice---once during a |
| 3369 |
% ``measuring'' phase and then again during a ``production'' phase; |
| 3370 |
% \cs{ifmeasuring@} will be used to determine which case we're in, |
| 3371 |
% so we can take appropriate action. |
| 3372 |
% |
| 3373 |
% \begin{macrocode} |
| 3374 |
\newif\ifmeasuring@ |
| 3375 |
% \end{macrocode} |
| 3376 |
% \end{macro} |
| 3377 |
% |
| 3378 |
% \begin{macro}{\ifshifttag@} |
| 3379 |
% \cs{ifshifttag@} is used by \env{gather} to communicate between |
| 3380 |
% \cs{calc@shift@gather} and \cs{place@tag@gather} whether an |
| 3381 |
% equation tag should be shifted to a separate line. It's also |
| 3382 |
% used by \env{multline}. |
| 3383 |
% \begin{macrocode} |
| 3384 |
\newif\ifshifttag@ |
| 3385 |
% \end{macrocode} |
| 3386 |
% \end{macro} |
| 3387 |
% |
| 3388 |
% \begin{macro}{\row@} |
| 3389 |
% \begin{macrocode} |
| 3390 |
\newcount\row@ |
| 3391 |
% \end{macrocode} |
| 3392 |
% \end{macro} |
| 3393 |
% |
| 3394 |
% \begin{macro}{\column@} |
| 3395 |
% The counter \cs{column@} is used by the alignment macros to |
| 3396 |
% keep track of the current column. |
| 3397 |
% |
| 3398 |
% \begin{macrocode} |
| 3399 |
\newcount\column@ |
| 3400 |
% \end{macrocode} |
| 3401 |
% \end{macro} |
| 3402 |
% |
| 3403 |
% \begin{macro}{\column@plus} |
| 3404 |
% \cs{column@plus} is a useful abbreviation. |
| 3405 |
% \begin{macrocode} |
| 3406 |
\def\column@plus{% |
| 3407 |
\global\advance\column@\@ne |
| 3408 |
} |
| 3409 |
% \end{macrocode} |
| 3410 |
% \end{macro} |
| 3411 |
% |
| 3412 |
% \begin{macro}{\maxfields@} |
| 3413 |
% \begin{macrocode} |
| 3414 |
\newcount\maxfields@ |
| 3415 |
% \end{macrocode} |
| 3416 |
% \end{macro} |
| 3417 |
% |
| 3418 |
% \begin{macro}{\add@amp} |
| 3419 |
% \begin{macro}{\add@amps} |
| 3420 |
% \begin{macrocode} |
| 3421 |
\def\add@amp#1{\if m#1&\@xp\add@amp\fi} |
| 3422 |
\def\add@amps#1{% |
| 3423 |
\begingroup |
| 3424 |
\count@#1\advance\count@-\column@ |
| 3425 |
\edef\@tempa{\endgroup |
| 3426 |
\@xp\add@amp\romannumeral\number\count@ 000q}% |
| 3427 |
\@tempa |
| 3428 |
} |
| 3429 |
% \end{macrocode} |
| 3430 |
% \end{macro} |
| 3431 |
% \end{macro} |
| 3432 |
% |
| 3433 |
% \begin{macro}{\andhelp@} |
| 3434 |
% The help text stored in \cs{andhelp@} is used for errors |
| 3435 |
% generated by too many \qc{\&} characters in a row. |
| 3436 |
% \begin{macrocode} |
| 3437 |
\newhelp\andhelp@ |
| 3438 |
{An extra & here is so disastrous that you should probably exit^^J |
| 3439 |
and fix things up.} |
| 3440 |
% \end{macrocode} |
| 3441 |
% \end{macro} |
| 3442 |
% |
| 3443 |
% \begin{macro}{\eqnshift@} |
| 3444 |
% \cs{eqnshift@} is used by \env{align} and \env{gather} as the |
| 3445 |
% indentation of the lines of the environment from the left margin. |
| 3446 |
% \begin{macrocode} |
| 3447 |
\newdimen\eqnshift@ |
| 3448 |
% \end{macrocode} |
| 3449 |
% \end{macro} |
| 3450 |
% |
| 3451 |
% \begin{macro}{\alignsep@} |
| 3452 |
% \begin{macrocode} |
| 3453 |
\newdimen\alignsep@ |
| 3454 |
% \end{macrocode} |
| 3455 |
% \end{macro} |
| 3456 |
% |
| 3457 |
% \begin{macro}{\tagshift@} |
| 3458 |
% \begin{macrocode} |
| 3459 |
\newdimen\tagshift@ |
| 3460 |
% \end{macrocode} |
| 3461 |
% \end{macro} |
| 3462 |
% |
| 3463 |
% \begin{macro}{\mintagsep} |
| 3464 |
% \cs{mintagsep} is the minimum allowable separation between an |
| 3465 |
% equation and its tag. We set it to half a quad in |
| 3466 |
% \cs{textfont}2, which is \tex/'s built-in value. |
| 3467 |
% \begin{macrocode} |
| 3468 |
\newcommand{\mintagsep}{.5\fontdimen6\textfont\tw@} |
| 3469 |
% \end{macrocode} |
| 3470 |
% \end{macro} |
| 3471 |
% |
| 3472 |
% \begin{macro}{\minalignsep} |
| 3473 |
% This should probably be a skip register [mjd,1999/06/18] |
| 3474 |
% \begin{macrocode} |
| 3475 |
\newcommand{\minalignsep}{10pt} |
| 3476 |
% \end{macrocode} |
| 3477 |
% \end{macro} |
| 3478 |
% |
| 3479 |
% \begin{macro}{\tagwidth@} |
| 3480 |
% \begin{macrocode} |
| 3481 |
\newdimen\tagwidth@ |
| 3482 |
% \end{macrocode} |
| 3483 |
% \end{macro} |
| 3484 |
% |
| 3485 |
% \begin{macro}{\totwidth@} |
| 3486 |
% \begin{macrocode} |
| 3487 |
\newdimen\totwidth@ |
| 3488 |
% \end{macrocode} |
| 3489 |
% \end{macro} |
| 3490 |
% |
| 3491 |
% \begin{macro}{\lineht@} |
| 3492 |
% The dimen register \cs{lineht@} is used to keep track of the |
| 3493 |
% height (or depth, if tags are on the right) of a row in an |
| 3494 |
% alignment. |
| 3495 |
% \begin{macrocode} |
| 3496 |
\newdimen\lineht@ |
| 3497 |
% \end{macrocode} |
| 3498 |
% \end{macro} |
| 3499 |
% |
| 3500 |
% \begin{macro}{\tag@width} |
| 3501 |
% \begin{macro}{\savetaglength@} |
| 3502 |
% \begin{macro}{\shift@tag} |
| 3503 |
% \begin{macro}{\tag@shifts} |
| 3504 |
% \begin{macrocode} |
| 3505 |
\def\tag@width#1{% |
| 3506 |
\ifcase\@xp#1\tag@lengths\fi |
| 3507 |
} |
| 3508 |
|
| 3509 |
\def\savetaglength@{% |
| 3510 |
\begingroup |
| 3511 |
\let\or\relax |
| 3512 |
\xdef\tag@lengths{\tag@lengths\or \the\wdz@}% |
| 3513 |
\endgroup |
| 3514 |
} |
| 3515 |
|
| 3516 |
\def\shift@tag#1{% |
| 3517 |
\ifcase\@xp#1\tag@shifts\fi\relax |
| 3518 |
} |
| 3519 |
|
| 3520 |
\let\tag@shifts\@empty |
| 3521 |
% \end{macrocode} |
| 3522 |
% \end{macro} |
| 3523 |
% \end{macro} |
| 3524 |
% \end{macro} |
| 3525 |
% \end{macro} |
| 3526 |
% |
| 3527 |
% \begin{macro}{\saveshift@} |
| 3528 |
% \begin{macrocode} |
| 3529 |
\def\saveshift@#1{% |
| 3530 |
\begingroup |
| 3531 |
\let\or\relax |
| 3532 |
\xdef\tag@shifts{\or#1\tag@shifts}% |
| 3533 |
\endgroup |
| 3534 |
} |
| 3535 |
% \end{macrocode} |
| 3536 |
% \end{macro} |
| 3537 |
% |
| 3538 |
% \begin{macro}{\spread@equation} |
| 3539 |
% This does the line-spacing adjustment that is normally wanted for |
| 3540 |
% displayed equations. We also call \cs{reset@strutbox@} here because |
| 3541 |
% otherwise a preceding font size change might leave \cs{strutbox@} |
| 3542 |
% with wrong contents. This is a less-than-ideal solution but |
| 3543 |
% probably good enough for now, until the situation can be |
| 3544 |
% overhauled. |
| 3545 |
% \begin{macrocode} |
| 3546 |
\def\spread@equation{\reset@strutbox@ |
| 3547 |
\openup\jot \let\spread@equation\@empty} |
| 3548 |
\let\@spread@equation\spread@equation |
| 3549 |
% \end{macrocode} |
| 3550 |
% \end{macro} |
| 3551 |
% |
| 3552 |
% \begin{macro}{\displ@y} |
| 3553 |
% \begin{macro}{\displ@y@} |
| 3554 |
% \begin{macro}{\@display@init} |
| 3555 |
% \cs{displ@y} is from \fn{plain.tex}, with |
| 3556 |
% \cs{interdisplaylinepenalty} changed to \cs{@eqpen}. Also we |
| 3557 |
% transplanted most of its internal organs to \cs{@display@init} to |
| 3558 |
% support \cs{displ@y@} and other possibilities. Don't try to make |
| 3559 |
% sense of these naming conventions! They are a narrowly calculated |
| 3560 |
% mishmash of Knuth/Spivak/Lamport/Mittelbach precedents. The reason |
| 3561 |
% for not cleaning them up and forcing all names to a consistent |
| 3562 |
% scheme is that then in principle we'd have to do it everywhere else |
| 3563 |
% too. And we programmers are paranoid about the side effects of name |
| 3564 |
% changes. |
| 3565 |
% \begin{macrocode} |
| 3566 |
\def\displ@y{\@display@init{}} |
| 3567 |
\def\@display@init#1{% |
| 3568 |
% \end{macrocode} |
| 3569 |
% Reset \cs{lineht@} to avoid that this is incorrectly picked |
| 3570 |
% up from a previous environment. |
| 3571 |
% \changes{v2.17x}{2025/05/18}{Reset \cs{lineht@} in the right place (gh/1289)} |
| 3572 |
% \begin{macrocode} |
| 3573 |
\global\lineht@\z@ |
| 3574 |
\global\dt@ptrue \spread@equation |
| 3575 |
\everycr{% |
| 3576 |
\noalign{% |
| 3577 |
#1% |
| 3578 |
\ifdt@p |
| 3579 |
\global\dt@pfalse |
| 3580 |
\vskip-\lineskiplimit |
| 3581 |
\vskip\normallineskiplimit |
| 3582 |
\else |
| 3583 |
\penalty\@eqpen \global\dspbrk@lvl\m@ne |
| 3584 |
\fi |
| 3585 |
}% |
| 3586 |
}% |
| 3587 |
} |
| 3588 |
% \end{macrocode} |
| 3589 |
% \cs{displ@y@} is nearly the same; it additionally sets the |tag@| |
| 3590 |
% switch and the \cs{column@} and \cs{dspbrk@lvl} counters to their |
| 3591 |
% default values. The argument is normally a bit of code to empty out |
| 3592 |
% \cs{raise@tag}, but in \env{multline} we don't want that to happen |
| 3593 |
% in \cs{everycr}. |
| 3594 |
% \begin{macrocode} |
| 3595 |
\def\displ@y@{\@display@init{% |
| 3596 |
\global\column@\z@ \global\dspbrk@lvl\m@ne |
| 3597 |
\global\tag@false \global\let\raise@tag\@empty |
| 3598 |
}} |
| 3599 |
% \end{macrocode} |
| 3600 |
% \end{macro} |
| 3601 |
% \end{macro} |
| 3602 |
% \end{macro} |
| 3603 |
% |
| 3604 |
% \begin{macro}{\black@} |
| 3605 |
% \changes{v2.17a}{2017/09/02}{Add fixed width box so overfull warning |
| 3606 |
% generated in centred environments in lists} |
| 3607 |
% This macro is made to produce an overfull box message and |
| 3608 |
% possibly (depending on the value of \cs{overfullrule}) |
| 3609 |
% a rule in the margin if the total width of an alignment |
| 3610 |
% is larger than the value of \cs{displaywidth}. |
| 3611 |
% \begin{macrocode} |
| 3612 |
\def\black@#1{% |
| 3613 |
\noalign{% |
| 3614 |
\ifdim#1>\displaywidth |
| 3615 |
\dimen@\prevdepth |
| 3616 |
\nointerlineskip |
| 3617 |
\vskip-\ht\strutbox@ |
| 3618 |
\vskip-\dp\strutbox@ |
| 3619 |
\vbox{\noindent\hbox to\displaywidth{% |
| 3620 |
\hbox to#1{\strut@\hfill}}}% |
| 3621 |
\prevdepth\dimen@ |
| 3622 |
\fi |
| 3623 |
}% |
| 3624 |
} |
| 3625 |
% \end{macrocode} |
| 3626 |
% \end{macro} |
| 3627 |
% |
| 3628 |
% \begin{macro}{\savecounters@} |
| 3629 |
% \begin{macro}{\restorecounters@} |
| 3630 |
% These are used during the measuring phase of the various display |
| 3631 |
% math environments to save and restore the values of all \latex/ |
| 3632 |
% counters. We make these local to a group, so nested environments |
| 3633 |
% works. |
| 3634 |
% |
| 3635 |
% Changed \cn{stepcounter} to |\csname c@...\endcsname| to avoid |
| 3636 |
% overhead of ifundefined test [mjd, 1995/01/20]. |
| 3637 |
% \begin{macrocode} |
| 3638 |
\def\savecounters@{% |
| 3639 |
\begingroup |
| 3640 |
\def\@elt##1{% |
| 3641 |
\global\csname c@##1\endcsname\the\csname c@##1\endcsname}% |
| 3642 |
\xdef\@gtempa{% |
| 3643 |
\cl@@ckpt |
| 3644 |
\let\@nx\restorecounters@\@nx\@empty |
| 3645 |
}% |
| 3646 |
\endgroup |
| 3647 |
\let\restorecounters@\@gtempa |
| 3648 |
} |
| 3649 |
% |
| 3650 |
\let\restorecounters@\@empty |
| 3651 |
% \end{macrocode} |
| 3652 |
% \end{macro} |
| 3653 |
% \end{macro} |
| 3654 |
% |
| 3655 |
% \begin{macro}{\savealignstate@} |
| 3656 |
% \begin{macro}{\restorealignstate@} |
| 3657 |
% These are used to save the values of various parameters that are |
| 3658 |
% shared by \env{align} and \env{gather} when the former is used |
| 3659 |
% inside the latter. |
| 3660 |
% \begin{macrocode} |
| 3661 |
\def\savealignstate@{% |
| 3662 |
\begingroup |
| 3663 |
\let\or\relax |
| 3664 |
\xdef\@gtempa{% |
| 3665 |
\global\totwidth@\the\totwidth@ |
| 3666 |
\global\row@\the\row@ |
| 3667 |
\gdef\@nx\tag@lengths{\tag@lengths}% |
| 3668 |
\let\@nx\restorealignstate@\@nx\@empty |
| 3669 |
}% |
| 3670 |
\endgroup |
| 3671 |
\let\restorealignstate@\@gtempa |
| 3672 |
} |
| 3673 |
|
| 3674 |
\let\restorealignstate@\@empty |
| 3675 |
% \end{macrocode} |
| 3676 |
% \end{macro} |
| 3677 |
% \end{macro} |
| 3678 |
% |
| 3679 |
% \begin{macro}{\savecolumn@} |
| 3680 |
% \begin{macro}{\restorecolumn@} |
| 3681 |
% |
| 3682 |
% \begin{macrocode} |
| 3683 |
\def\savecolumn@{% |
| 3684 |
\edef\restorecolumn@{% |
| 3685 |
\global\column@\number\column@ |
| 3686 |
\let\@nx\restorecolumn@\@nx\@empty |
| 3687 |
}% |
| 3688 |
} |
| 3689 |
\let\restorecolumn@\@empty |
| 3690 |
% \end{macrocode} |
| 3691 |
% \end{macro} |
| 3692 |
% \end{macro} |
| 3693 |
% |
| 3694 |
% \subsection{Scanning the environment's body} |
| 3695 |
% |
| 3696 |
% Several of the math alignment macros must scan their body twice: |
| 3697 |
% once to determine how wide the columns are and then to actually |
| 3698 |
% typeset them. This means that we must collect all text in this body |
| 3699 |
% before calling the environment macros. |
| 3700 |
% |
| 3701 |
% \begin{macro}{\@envbody} |
| 3702 |
% We start by defining a token register to contain the body. |
| 3703 |
% \begin{macrocode} |
| 3704 |
\newtoks\@envbody |
| 3705 |
% \end{macrocode} |
| 3706 |
% \end{macro} |
| 3707 |
% |
| 3708 |
% \begin{macro}{\addto@envbody} |
| 3709 |
% Then we define a macro to add something (i.e.\ its argument) to the |
| 3710 |
% token register \cs{@envbody}. |
| 3711 |
% \begin{macrocode} |
| 3712 |
\def\addto@envbody#1{\global\@envbody\@xp{\the\@envbody#1}} |
| 3713 |
% \end{macrocode} |
| 3714 |
% \end{macro} |
| 3715 |
% |
| 3716 |
% \begin{macro}{\collect@body} |
| 3717 |
% The macro \cs{collect@body} starts the scan for the |\end{...}| |
| 3718 |
% command of the current environment. It takes a macro name as |
| 3719 |
% argument. This macro is supposed to take the whole body of the |
| 3720 |
% environment as its argument. For example, |\begin{align}| would |
| 3721 |
% call |\collect@body\@align| if |@align#1{...}| is the macro that |
| 3722 |
% sets the alignment with body \arg{1}. |
| 3723 |
% |
| 3724 |
% \begin{macrocode} |
| 3725 |
\def\collect@body#1{% |
| 3726 |
\@envbody{\@xp#1\@xp{\the\@envbody}}% |
| 3727 |
\edef\process@envbody{\the\@envbody\@nx\end{\@currenvir}}% |
| 3728 |
\@envbody\@emptytoks \def\begin@stack{b}% |
| 3729 |
% \end{macrocode} |
| 3730 |
% |
| 3731 |
% If we simply called \cs{collect@@body} directly, |
| 3732 |
% the error message for a \cn{par} token (usually from a blank line) |
| 3733 |
% would be |
| 3734 |
% \begin{verbatim} |
| 3735 |
% ! Paragraph ended before \collect@@body was complete. |
| 3736 |
% \end{verbatim} |
| 3737 |
% But we use a little finesse to get a more intelligible error |
| 3738 |
% message: |
| 3739 |
% \begin{verbatim} |
| 3740 |
% ! Paragraph ended before \multline* was complete. |
| 3741 |
% \end{verbatim} |
| 3742 |
% In order to avoid using up csnames unnecessarily we use the actual |
| 3743 |
% environment name as the name of the temporary function that is |
| 3744 |
% \cs{let} to \cs{collect@@body}; but then in order to preserve the |
| 3745 |
% theoretical possibility of nesting for environments that use |
| 3746 |
% \cs{collect@body} (not currently required by any \pkg{amsmath} |
| 3747 |
% environment [mjd,1999/06/23]), we do the \cs{let} inside a group. |
| 3748 |
% \begin{macrocode} |
| 3749 |
\begingroup |
| 3750 |
\@xp\let\csname\@currenvir\endcsname\collect@@body |
| 3751 |
% \end{macrocode} |
| 3752 |
% This small twist eliminates the need for \cs{expandafter}'s in |
| 3753 |
% \cs{collect@@body}. |
| 3754 |
% \begin{macrocode} |
| 3755 |
\edef\process@envbody{\@xp\@nx\csname\@currenvir\endcsname}% |
| 3756 |
\process@envbody |
| 3757 |
} |
| 3758 |
% \end{macrocode} |
| 3759 |
% \end{macro} |
| 3760 |
% |
| 3761 |
% \begin{macro}{\push@begins} |
| 3762 |
% When adding a piece of the current environment's contents to |
| 3763 |
% \cs{@envbody}, we scan it to check for additional \cn{begin} |
| 3764 |
% tokens, and add a `b' to the stack for any that we find. |
| 3765 |
% \begin{macrocode} |
| 3766 |
\def\push@begins#1\begin#2{% |
| 3767 |
\ifx\end#2\else b\@xp\push@begins\fi |
| 3768 |
} |
| 3769 |
% \end{macrocode} |
| 3770 |
% \end{macro} |
| 3771 |
% |
| 3772 |
% \begin{macro}{\collect@@body} |
| 3773 |
% \cs{collect@@body} takes two arguments: the first will consist of |
| 3774 |
% all text up to the next \cn{end} command, the second will be the |
| 3775 |
% \cn{end} command's argument. If there are any extra \cn{begin} |
| 3776 |
% commands in the body text, a marker is pushed onto a stack by the |
| 3777 |
% \cs{push@begins} function. Empty state for this stack means that we |
| 3778 |
% have reached the \cn{end} that matches our original \cn{begin}. |
| 3779 |
% Otherwise we need to include the \cn{end} and its argument in the |
| 3780 |
% material that we are adding to our environment body accumulator. |
| 3781 |
% |
| 3782 |
% \begin{histnote} |
| 3783 |
% In a former implementation, the error messages resulting from a |
| 3784 |
% typo in the environment name were unsatisfactory, because it was |
| 3785 |
% matching of the environment name that was used to determine the end |
| 3786 |
% of our environment body, instead of counting begin-end pairs. |
| 3787 |
% Thanks to Lars Hellstr\"{o}m for a suggestion that led to this |
| 3788 |
% improvement. [mjd,1999/06/23] |
| 3789 |
% \end{histnote} |
| 3790 |
% \begin{macrocode} |
| 3791 |
\def\collect@@body#1\end#2{% |
| 3792 |
\edef\begin@stack{\push@begins#1\begin\end \@xp\@gobble\begin@stack}% |
| 3793 |
\ifx\@empty\begin@stack |
| 3794 |
\endgroup |
| 3795 |
\@checkend{#2}% |
| 3796 |
\addto@envbody{#1}% |
| 3797 |
\else |
| 3798 |
\addto@envbody{#1\end{#2}}% |
| 3799 |
\fi |
| 3800 |
\process@envbody % A little tricky! Note the grouping |
| 3801 |
} |
| 3802 |
% \end{macrocode} |
| 3803 |
% \end{macro} |
| 3804 |
% |
| 3805 |
% |
| 3806 |
% \subsection{Simple aligning environments} |
| 3807 |
% |
| 3808 |
% \begin{macro}{\math@cr@@@aligned} |
| 3809 |
% From tabskip we get an extra space of minalignsep after every |
| 3810 |
% second column; but when this falls at the right edge of the whole |
| 3811 |
% aligned structure, we need to cancel that space. |
| 3812 |
% \begin{macrocode} |
| 3813 |
\def\math@cr@@@aligned{% |
| 3814 |
\ifodd\column@ \let\next@\@empty |
| 3815 |
\else \def\next@{&\kern-\alignsep@}% |
| 3816 |
\fi |
| 3817 |
\next@ \cr |
| 3818 |
} |
| 3819 |
% \end{macrocode} |
| 3820 |
% \end{macro} |
| 3821 |
% |
| 3822 |
% |
| 3823 |
% |
| 3824 |
% \begin{macro}{\ams@start@box} |
| 3825 |
% This macro tests the optional positioning argument (in |
| 3826 |
% \texttt{gathered} or \texttt{aligned}. It explicitly tests for the |
| 3827 |
% value \texttt{b}, \texttt{c} and \texttt{t} and if the value is |
| 3828 |
% different, then we assume that it is a bracket group that belongs |
| 3829 |
% to the formula instead of being an misspelled optional argument. |
| 3830 |
% (In earlier versions of the code anything other than \texttt{b} |
| 3831 |
% or \texttt{t} was interpreted as \texttt{c} and the data was |
| 3832 |
% otherwise dropped.) |
| 3833 |
% \changes{v2.17g}{2020/03/10}{Explicitly test for b/t/c and return |
| 3834 |
% optional argument is different (gh/5)} |
| 3835 |
% \begin{macrocode} |
| 3836 |
\def\ams@start@box#1{% |
| 3837 |
% \end{macrocode} |
| 3838 |
% As we may pick up an arbitrary part of the formula by mistake, we |
| 3839 |
% need to be very careful with the testing to avoid low-level |
| 3840 |
% errors. This is why we use \cs{detokenize}. But we also need to |
| 3841 |
% expand the argument (if possible) in case the position value is |
| 3842 |
% hidden inside a macro. We therefore apply the \cs{romannumeral} |
| 3843 |
% trick (known as f-expansion in \texttt{expl3}) in its old form. |
| 3844 |
% The code assumes that |
| 3845 |
% the default is correctly set up (which in this case is \texttt{c}). |
| 3846 |
% \begin{macrocode} |
| 3847 |
\edef\reserved@a{\csname ams@pos@\expandafter\detokenize |
| 3848 |
\expandafter{\romannumeral-`\0#1}\endcsname}% |
| 3849 |
\expandafter\ifx\reserved@a\relax |
| 3850 |
% \end{macrocode} |
| 3851 |
% If the argument is neither \texttt{b}, \texttt{c} or \texttt{t} |
| 3852 |
% we save it in \cs{ams@return@opt@arg}, so it can later be |
| 3853 |
% returned as part of the environment body. We could at this point |
| 3854 |
% also issue a warning that bracket group was found at the start of |
| 3855 |
% the formula and that it is safer to add a \cs{relax} before it. |
| 3856 |
% \begin{macrocode} |
| 3857 |
\PackageWarning{amsmath}{% |
| 3858 |
Bracket group \detokenize{[#1]} at formula start!\MessageBreak |
| 3859 |
It could be a misspelled positional argument.\MessageBreak |
| 3860 |
If it belongs to the formula add a \relax in\MessageBreak |
| 3861 |
front to hide it}% |
| 3862 |
\def\ams@return@opt@arg{[#1]}\vcenter |
| 3863 |
% \end{macrocode} |
| 3864 |
% If the argument was identified then we clear |
| 3865 |
% \cs{ams@return@opt@arg} (just in case somebod ever nests these |
| 3866 |
% environment. |
| 3867 |
% \begin{macrocode} |
| 3868 |
\else |
| 3869 |
\let\ams@return@opt@arg\@empty\reserved@a |
| 3870 |
\fi |
| 3871 |
} |
| 3872 |
% \end{macrocode} |
| 3873 |
% |
| 3874 |
% \begin{macro}{\ams@pos@t} |
| 3875 |
% \begin{macro}{\ams@pos@b} |
| 3876 |
% \begin{macro}{\ams@pos@c} |
| 3877 |
% |
| 3878 |
% \begin{macrocode} |
| 3879 |
\def\ams@pos@t{\vtop} |
| 3880 |
\def\ams@pos@b{\vbox} |
| 3881 |
\def\ams@pos@c{\vcenter} |
| 3882 |
% \end{macrocode} |
| 3883 |
% And we accept an empty argument as a way to get the default (as |
| 3884 |
% that was the case before as well, albeit by mistake in some sense). |
| 3885 |
% \begin{macrocode} |
| 3886 |
\let\ams@pos@\ams@pos@c |
| 3887 |
% \end{macrocode} |
| 3888 |
% \end{macro} |
| 3889 |
% \end{macro} |
| 3890 |
% \end{macro} |
| 3891 |
% \end{macro} |
| 3892 |
% |
| 3893 |
% \begin{macro}{\start@aligned} |
| 3894 |
% The \env{aligned} and \env{alignedat} environments are identical |
| 3895 |
% except that the latter takes a mandatory argument to specify the |
| 3896 |
% number of align structures, while the former allows any number of |
| 3897 |
% align structures automatically (the use of \env{alignedat} is |
| 3898 |
% deprecated). So, they will be defined in terms of |
| 3899 |
% \cs{start@aligned}, which will take two arguments. The first |
| 3900 |
% argument specifies the placement of the environments; it is |
| 3901 |
% either |c|, |t|, or |b|. The second is the number of align |
| 3902 |
% structures; a value of~$-1$ means that an arbitrary number are |
| 3903 |
% allowed. |
| 3904 |
% \begin{macrocode} |
| 3905 |
\newcommand{\start@aligned}[2]{% |
| 3906 |
\RIfM@\else |
| 3907 |
\nonmatherr@{\begin{\@currenvir}}% |
| 3908 |
\fi |
| 3909 |
\savecolumn@ % Assumption: called inside a group |
| 3910 |
% \end{macrocode} |
| 3911 |
% The \cs{null} here is to keep the \cs{,} glue from causing the |
| 3912 |
% invocation of the clause in \tex/'s built-in tag placement |
| 3913 |
% algorithm that can cause an equation to be shifted all the way over |
| 3914 |
% to the margin. |
| 3915 |
% \begin{macrocode} |
| 3916 |
\alignedspace@left |
| 3917 |
% \end{macrocode} |
| 3918 |
% Select the right kind of box based on the optional argument \verb=#1=. |
| 3919 |
% \begin{macrocode} |
| 3920 |
\ams@start@box{#1}\bgroup |
| 3921 |
\maxfields@#2\relax |
| 3922 |
\ifnum\maxfields@>\m@ne |
| 3923 |
\multiply\maxfields@\tw@ |
| 3924 |
% \end{macrocode} |
| 3925 |
% Introduced new \cs{math@cr@@@} so we can provide standard error |
| 3926 |
% message for too many \qc{\&}'s in \env{alignedat}. |
| 3927 |
% \begin{macrocode} |
| 3928 |
\let\math@cr@@@\math@cr@@@alignedat |
| 3929 |
\alignsep@\z@skip |
| 3930 |
\else |
| 3931 |
\let\math@cr@@@\math@cr@@@aligned |
| 3932 |
\alignsep@\minalignsep |
| 3933 |
\fi |
| 3934 |
% \end{macrocode} |
| 3935 |
% Reset the meaning of \cn{\\}. |
| 3936 |
% \begin{macrocode} |
| 3937 |
\Let@ \chardef\dspbrk@context\@ne |
| 3938 |
% \end{macrocode} |
| 3939 |
% Restore the default definition of \cn{tag} (error message), in |
| 3940 |
% case \env{aligned} is used inside, e.g., a \env{gather} |
| 3941 |
% environment that accepts \cn{tag}. |
| 3942 |
% \begin{macrocode} |
| 3943 |
\default@tag |
| 3944 |
\spread@equation % no-op if already called |
| 3945 |
% \end{macrocode} |
| 3946 |
% Finally we start the alignment itself. For \env{aligned} we add |
| 3947 |
% \cs{minalignsep} after every second column to mimic the |
| 3948 |
% behavior of \env{align}. For \env{alignedat} the user has to |
| 3949 |
% specify interalign space explicitly. |
| 3950 |
% \begin{macrocode} |
| 3951 |
\global\column@\z@ |
| 3952 |
\ialign\bgroup |
| 3953 |
&\column@plus |
| 3954 |
\hfil |
| 3955 |
\strut@ |
| 3956 |
$\m@th\displaystyle{##}$% |
| 3957 |
\tabskip\z@skip |
| 3958 |
&\column@plus |
| 3959 |
$\m@th\displaystyle{{}##}$% |
| 3960 |
\hfil |
| 3961 |
\tabskip\alignsep@ |
| 3962 |
\crcr |
| 3963 |
% \end{macrocode} |
| 3964 |
% If we picked up a bracket group by mistake here is the place to |
| 3965 |
% return it for processing. |
| 3966 |
% \changes{v2.17g}{2020/03/10}{Explicitly test for b/t/c and return |
| 3967 |
% optional argument is different (gh/5)} |
| 3968 |
% \begin{macrocode} |
| 3969 |
\ams@return@opt@arg |
| 3970 |
} |
| 3971 |
% \end{macrocode} |
| 3972 |
% \end{macro} |
| 3973 |
% |
| 3974 |
% \begin{macro}{\math@cr@@@alignedat} |
| 3975 |
% \cs{math@cr@@@alignedat} checks to make sure the user hasn't put in |
| 3976 |
% too many \qc{\&}s in \env{alignedat}. Since \env{alignedat} |
| 3977 |
% doesn't use \cs{displ@y@}, we also reset \cs{column@} here. Note |
| 3978 |
% than in \env{aligned}, \cs{column@} will increase without bound, |
| 3979 |
% since it never gets reset, but this is harmless. |
| 3980 |
% \begin{macrocode} |
| 3981 |
\def\math@cr@@@alignedat{% |
| 3982 |
\ifnum\column@>\maxfields@ |
| 3983 |
\begingroup |
| 3984 |
\measuring@false |
| 3985 |
\@amsmath@err{Extra & on this line}% |
| 3986 |
{\the\andhelp@}% "An extra & here is disastrous" |
| 3987 |
\endgroup |
| 3988 |
\fi |
| 3989 |
\global\column@\z@ |
| 3990 |
\cr |
| 3991 |
} |
| 3992 |
% \end{macrocode} |
| 3993 |
% \end{macro} |
| 3994 |
% |
| 3995 |
% \begin{macro}{\alignsafe@testopt} |
| 3996 |
% Testing for an optional argument can be really, really tricky in |
| 3997 |
% certain complicated contexts. This we discovered by getting some |
| 3998 |
% bug reports for uses of \env{aligned}. So here is a safer |
| 3999 |
% form of \latex/'s \cs{@testopt} function. |
| 4000 |
% \begin{macrocode} |
| 4001 |
\def\alignsafe@testopt#1#2{% |
| 4002 |
\relax\iffalse{\fi\ifnum`}=0\fi |
| 4003 |
\@ifnextchar[% |
| 4004 |
{\let\@let@token\relax \ifnum`{=\z@\fi\iffalse}\fi#1}% |
| 4005 |
{\let\@let@token\relax \ifnum`{=\z@\fi\iffalse}\fi#1[#2]}% |
| 4006 |
} |
| 4007 |
% \end{macrocode} |
| 4008 |
% \end{macro} |
| 4009 |
% |
| 4010 |
% \begin{environment}{aligned} |
| 4011 |
% The \env{aligned} environment takes an optional argument that |
| 4012 |
% indicates its vertical position in relation to surrounding |
| 4013 |
% material: |t|, |c|, or |b| for top, center, or bottom. |
| 4014 |
% \begin{macrocode} |
| 4015 |
\newenvironment{aligned}{% |
| 4016 |
\let\@testopt\alignsafe@testopt |
| 4017 |
\aligned@a |
| 4018 |
}{% |
| 4019 |
\crcr\egroup |
| 4020 |
\restorecolumn@ |
| 4021 |
\egroup |
| 4022 |
} |
| 4023 |
\newcommand{\aligned@a}[1][c]{\start@aligned{#1}\m@ne} |
| 4024 |
% \end{macrocode} |
| 4025 |
% \end{environment} |
| 4026 |
% |
| 4027 |
% \begin{environment}{alignedat} |
| 4028 |
% To get a top or bottom positioned \env{alignedat} structure, you |
| 4029 |
% would write something like |
| 4030 |
% \begin{verbatim} |
| 4031 |
% \begin{alignedat}[t]{3} |
| 4032 |
% \end{verbatim} |
| 4033 |
% |
| 4034 |
% \begin{macrocode} |
| 4035 |
\newenvironment{alignedat}{% |
| 4036 |
\let\@testopt\alignsafe@testopt |
| 4037 |
\alignedat@a |
| 4038 |
}{% |
| 4039 |
\endaligned |
| 4040 |
} |
| 4041 |
\newcommand{\alignedat@a}[1][c]{\start@aligned{#1}} |
| 4042 |
% \end{macrocode} |
| 4043 |
% \end{environment} |
| 4044 |
% |
| 4045 |
% \begin{environment}{gathered} |
| 4046 |
% The \env{gathered} environment is for several lines that are |
| 4047 |
% centered independently. |
| 4048 |
% \begin{macrocode} |
| 4049 |
\newenvironment{gathered}[1][c]{% |
| 4050 |
\RIfM@\else |
| 4051 |
\nonmatherr@{\begin{gathered}}% |
| 4052 |
\fi |
| 4053 |
\alignedspace@left |
| 4054 |
% \end{macrocode} |
| 4055 |
% Select the right kind of box based on the optional argument \verb=#1=. |
| 4056 |
% \begin{macrocode} |
| 4057 |
\ams@start@box{#1}\bgroup |
| 4058 |
\Let@ \chardef\dspbrk@context\@ne \restore@math@cr |
| 4059 |
\spread@equation |
| 4060 |
\ialign\bgroup |
| 4061 |
\hfil\strut@$\m@th\displaystyle##$\hfil |
| 4062 |
\crcr |
| 4063 |
% \end{macrocode} |
| 4064 |
% And put a mistaking picked up bracket group back: |
| 4065 |
% \changes{v2.17g}{2020/03/10}{Explicitly test for b/t/c and return |
| 4066 |
% optional argument is different (gh/5)} |
| 4067 |
% \begin{macrocode} |
| 4068 |
\ams@return@opt@arg |
| 4069 |
}{% |
| 4070 |
\endaligned |
| 4071 |
} |
| 4072 |
% \end{macrocode} |
| 4073 |
% \end{environment} |
| 4074 |
% |
| 4075 |
% |
| 4076 |
% \subsection{The \env{gather} environment} |
| 4077 |
% |
| 4078 |
% \begin{macro}{\start@gather} |
| 4079 |
% \changes{v2.17w}{2025/03/08}{Use \cs{dollardollar@begin} and |
| 4080 |
% \cs{dollardollar@end} instead of \texttt{\$\$} for tagging support} |
| 4081 |
% \begin{macrocode} |
| 4082 |
\def\start@gather#1{% |
| 4083 |
\RIfM@ |
| 4084 |
\nomath@env |
| 4085 |
\DN@{\@namedef{end\@currenvir}{}\@gobble}% |
| 4086 |
\else |
| 4087 |
\dollardollar@begin |
| 4088 |
#1% |
| 4089 |
\ifst@rred \else \global\@eqnswtrue \fi |
| 4090 |
\let\next@\gather@ |
| 4091 |
\fi |
| 4092 |
\collect@body\next@ |
| 4093 |
} |
| 4094 |
% \end{macrocode} |
| 4095 |
% \end{macro} |
| 4096 |
% |
| 4097 |
% \begin{environment}{gather} |
| 4098 |
% \begin{environment}{gather*} |
| 4099 |
% \begin{macrocode} |
| 4100 |
\newenvironment{gather}{% |
| 4101 |
% \changes{v2.17w}{2025/03/08}{Use \cs{dollardollar@begin} and |
| 4102 |
% \cs{dollardollar@end} instead of \texttt{\$\$} for tagging support} |
| 4103 |
\start@gather\st@rredfalse |
| 4104 |
}{% |
| 4105 |
\math@cr \black@\totwidth@ \egroup |
| 4106 |
\dollardollar@end\ignorespacesafterend |
| 4107 |
} |
| 4108 |
|
| 4109 |
\newenvironment{gather*}{% |
| 4110 |
\start@gather\st@rredtrue |
| 4111 |
}{% |
| 4112 |
\endgather |
| 4113 |
} |
| 4114 |
% \end{macrocode} |
| 4115 |
% \end{environment} |
| 4116 |
% \end{environment} |
| 4117 |
% |
| 4118 |
% \begin{macro}{\gather@} |
| 4119 |
% \begin{macrocode} |
| 4120 |
\def\gather@#1{% |
| 4121 |
\ingather@true \let\split\insplit@ |
| 4122 |
\let\tag\tag@in@align \let\label\label@in@display |
| 4123 |
\chardef\dspbrk@context\z@ |
| 4124 |
\intertext@ \displ@y@ \Let@ |
| 4125 |
\let\math@cr@@@\math@cr@@@gather |
| 4126 |
\gmeasure@{#1}% |
| 4127 |
\global\shifttag@false |
| 4128 |
\tabskip\z@skip |
| 4129 |
\global\row@\@ne |
| 4130 |
\halign to\displaywidth\bgroup |
| 4131 |
\strut@ |
| 4132 |
\setboxz@h{$\m@th\displaystyle{##}$}% |
| 4133 |
\calc@shift@gather |
| 4134 |
\set@gather@field |
| 4135 |
\tabskip\@centering |
| 4136 |
&\setboxz@h{\strut@{##}}% |
| 4137 |
\place@tag@gather |
| 4138 |
\tabskip \iftagsleft@ \gdisplaywidth@ \else \z@skip \span\fi |
| 4139 |
\crcr |
| 4140 |
#1% |
| 4141 |
} |
| 4142 |
% \end{macrocode} |
| 4143 |
% \end{macro} |
| 4144 |
% |
| 4145 |
% \begin{macro}{\gmeasure@} |
| 4146 |
% \begin{macrocode} |
| 4147 |
\def\gmeasure@#1{% |
| 4148 |
\begingroup |
| 4149 |
\measuring@true |
| 4150 |
\totwidth@\z@ |
| 4151 |
\global\let\tag@lengths\@empty |
| 4152 |
\savecounters@ |
| 4153 |
\setbox\@ne\vbox{% |
| 4154 |
\everycr{\noalign{\global\tag@false |
| 4155 |
\global\let\raise@tag\@empty \global\column@\z@}}% |
| 4156 |
\let\label\@gobble |
| 4157 |
\halign{% |
| 4158 |
\setboxz@h{$\m@th\displaystyle{##}$}% |
| 4159 |
\ifdim\wdz@>\totwidth@ |
| 4160 |
\global\totwidth@\wdz@ |
| 4161 |
\fi |
| 4162 |
&\setboxz@h{\strut@{##}}% |
| 4163 |
\savetaglength@ |
| 4164 |
\crcr |
| 4165 |
#1% |
| 4166 |
\math@cr@@@ |
| 4167 |
}% |
| 4168 |
}% |
| 4169 |
\restorecounters@ |
| 4170 |
\if@fleqn |
| 4171 |
\global\advance\totwidth@\@mathmargin |
| 4172 |
\fi |
| 4173 |
\iftagsleft@ |
| 4174 |
\ifdim\totwidth@>\displaywidth |
| 4175 |
\global\let\gdisplaywidth@\totwidth@ |
| 4176 |
\else |
| 4177 |
\global\let\gdisplaywidth@\displaywidth |
| 4178 |
\fi |
| 4179 |
\fi |
| 4180 |
\endgroup |
| 4181 |
} |
| 4182 |
% \end{macrocode} |
| 4183 |
% \end{macro} |
| 4184 |
% |
| 4185 |
% \begin{macro}{\math@cr@@@gather} |
| 4186 |
% Modified \cs{math@cr@@@gather} so that it always puts in the |
| 4187 |
% final field, which needs to be done under the new method for |
| 4188 |
% determining tag placement. This is probably more efficient |
| 4189 |
% anyway. |
| 4190 |
% |
| 4191 |
% \begin{macrocode} |
| 4192 |
\def\math@cr@@@gather{% |
| 4193 |
\ifst@rred\nonumber\fi |
| 4194 |
&\relax |
| 4195 |
\make@display@tag |
| 4196 |
\ifst@rred\else\global\@eqnswtrue\fi |
| 4197 |
% \end{macrocode} |
| 4198 |
% We advance \cs{row@} here, rather than at the beginning of the |
| 4199 |
% preamble, because otherwise the \env{split} environment will |
| 4200 |
% cause \cs{row@} to be advanced twice instead of once. |
| 4201 |
% \begin{macrocode} |
| 4202 |
\global\advance\row@\@ne |
| 4203 |
\cr |
| 4204 |
} |
| 4205 |
% \end{macrocode} |
| 4206 |
% \end{macro} |
| 4207 |
% |
| 4208 |
% \begin{macro}{\calc@shift@gather} |
| 4209 |
% \cs{calc@shift@gather} has must make two decisions: (1) whether the |
| 4210 |
% equation tag for the current line should be put on a separate |
| 4211 |
% line and (2) what the distance between the equation and the |
| 4212 |
% equation tag should be. We implement \tex/'s built-in |
| 4213 |
% tag-placement as well as possible, with one improvement: the |
| 4214 |
% minimum separation between tag and equation is now a |
| 4215 |
% user-settable parameter. |
| 4216 |
% |
| 4217 |
% [1995/01/17] Added a check to make sure that the width of the tag |
| 4218 |
% on the current line is $>0$ before testing to see if tagwidth + |
| 4219 |
% linewidth + mintagsep $>$ displaywidth. Since an imbedded align |
| 4220 |
% shows up as line with width \cn{displaywidth}, and even lines |
| 4221 |
% without a tag get processed as if an empty tag were present, the |
| 4222 |
% result was that the empty tag assigned to the line containing the |
| 4223 |
% align was being shifted downwards, creating extra space after the |
| 4224 |
% align. |
| 4225 |
% \begin{macrocode} |
| 4226 |
\def\calc@shift@gather{% |
| 4227 |
\dimen@\mintagsep\relax |
| 4228 |
\tagwidth@\tag@width\row@\relax |
| 4229 |
% \end{macrocode} |
| 4230 |
% If we're in \opt{fleqn} mode, there is no flexibility about |
| 4231 |
% placement of the equation, so all we can do is see if there's |
| 4232 |
% room for the tag in the given margin. |
| 4233 |
% \begin{macrocode} |
| 4234 |
\if@fleqn |
| 4235 |
\global\eqnshift@\@mathmargin |
| 4236 |
\ifdim\tagwidth@>\z@ |
| 4237 |
\advance\dimen@\tagwidth@ |
| 4238 |
\iftagsleft@ |
| 4239 |
\ifdim\dimen@>\@mathmargin |
| 4240 |
\global\shifttag@true |
| 4241 |
\fi |
| 4242 |
\else |
| 4243 |
\advance\dimen@\@mathmargin |
| 4244 |
\advance\dimen@\wdz@ |
| 4245 |
\ifdim\dimen@>\displaywidth |
| 4246 |
\global\shifttag@true |
| 4247 |
\fi |
| 4248 |
\fi |
| 4249 |
\fi |
| 4250 |
\else |
| 4251 |
\global\eqnshift@\displaywidth |
| 4252 |
\global\advance\eqnshift@-\wdz@ |
| 4253 |
\ifdim\tagwidth@>\z@ |
| 4254 |
\multiply\dimen@\tw@ |
| 4255 |
\advance\dimen@\wdz@ |
| 4256 |
\advance\dimen@\tagwidth@ |
| 4257 |
\ifdim\dimen@>\displaywidth |
| 4258 |
\global\shifttag@true |
| 4259 |
\else |
| 4260 |
\ifdim\eqnshift@<4\tagwidth@ |
| 4261 |
\global\advance\eqnshift@-\tagwidth@ |
| 4262 |
\fi |
| 4263 |
\fi |
| 4264 |
\fi |
| 4265 |
\global\divide\eqnshift@\tw@ |
| 4266 |
\iftagsleft@ |
| 4267 |
\global\eqnshift@-\eqnshift@ |
| 4268 |
\global\advance\eqnshift@\displaywidth |
| 4269 |
\global\advance\eqnshift@-\wdz@ |
| 4270 |
\fi |
| 4271 |
\ifdim\eqnshift@<\z@ |
| 4272 |
\global\eqnshift@\z@ |
| 4273 |
\fi |
| 4274 |
\fi |
| 4275 |
} |
| 4276 |
% \end{macrocode} |
| 4277 |
% \end{macro} |
| 4278 |
% |
| 4279 |
% \begin{macro}{\place@tag@gather} |
| 4280 |
% \begin{macro}{\set@gather@field} |
| 4281 |
% \begin{macrocode} |
| 4282 |
\def\place@tag@gather{% |
| 4283 |
\iftagsleft@ |
| 4284 |
\kern-\gdisplaywidth@ |
| 4285 |
\ifshifttag@ |
| 4286 |
\rlap{\vbox{% |
| 4287 |
\normalbaselines |
| 4288 |
\boxz@ |
| 4289 |
\vbox to\lineht@{}% |
| 4290 |
\raise@tag |
| 4291 |
}}% |
| 4292 |
\global\shifttag@false |
| 4293 |
\else |
| 4294 |
\rlap{\boxz@}% |
| 4295 |
\fi |
| 4296 |
\else |
| 4297 |
\ifdim\totwidth@>\displaywidth |
| 4298 |
\dimen@\totwidth@ |
| 4299 |
\advance\dimen@-\displaywidth |
| 4300 |
\kern-\dimen@ |
| 4301 |
\fi |
| 4302 |
\ifshifttag@ |
| 4303 |
\llap{\vtop{% |
| 4304 |
\raise@tag |
| 4305 |
\normalbaselines |
| 4306 |
\setbox\@ne\null |
| 4307 |
\dp\@ne\lineht@ |
| 4308 |
\box\@ne |
| 4309 |
\boxz@ |
| 4310 |
}}% |
| 4311 |
\global\shifttag@false |
| 4312 |
\else |
| 4313 |
\llap{\boxz@}% |
| 4314 |
\fi |
| 4315 |
\fi |
| 4316 |
} |
| 4317 |
% |
| 4318 |
\def\set@gather@field{% |
| 4319 |
\iftagsleft@ |
| 4320 |
\global\lineht@\ht\z@ |
| 4321 |
\else |
| 4322 |
\global\lineht@\dp\z@ |
| 4323 |
\fi |
| 4324 |
\kern\eqnshift@ |
| 4325 |
\boxz@ |
| 4326 |
\hfil |
| 4327 |
} |
| 4328 |
% \end{macrocode} |
| 4329 |
% \end{macro} |
| 4330 |
% \end{macro} |
| 4331 |
% |
| 4332 |
% |
| 4333 |
% \subsection{The \env{align} family of environments} |
| 4334 |
% |
| 4335 |
% The \env{align}, \env{flalign}, \env{alignat}, \env{xalignat}, |
| 4336 |
% and \env{xxalignat} environments are virtually |
| 4337 |
% identical, and thus will share much code. We'll refer to the |
| 4338 |
% environments generically as ``\env{align}'' and will |
| 4339 |
% distinguish between them explicitly |
| 4340 |
% only when necessary. |
| 4341 |
% |
| 4342 |
% \begin{macro}{\ifxxat@} |
| 4343 |
% \begin{macro}{\ifcheckat@} |
| 4344 |
% \begin{macro}{\xatlevel@} |
| 4345 |
% The \cs{xatlevel@} macro will be used, informally speaking, to |
| 4346 |
% distinguish between the \env{alignat} and \env{xalignat}, and |
| 4347 |
% \env{xxalignat} environments. |
| 4348 |
% |
| 4349 |
% \begin{macrocode} |
| 4350 |
\newif\ifxxat@ |
| 4351 |
|
| 4352 |
\newif\ifcheckat@ |
| 4353 |
|
| 4354 |
\let\xatlevel@\@empty |
| 4355 |
% \end{macrocode} |
| 4356 |
% \end{macro} |
| 4357 |
% \end{macro} |
| 4358 |
% \end{macro} |
| 4359 |
% |
| 4360 |
% \begin{macro}{\start@align} |
| 4361 |
% \cs{start@align} will be called by all of the \env{align}-like |
| 4362 |
% environments. The first argument will be the \cs{xatlevel@}, |
| 4363 |
% i.e., 0, 1, or~2; the second argument will be either |
| 4364 |
% \cs{st@rredtrue} or \cs{st@rredfalse}. The third argument will |
| 4365 |
% be the number of aligned |
| 4366 |
% structures in the environment (either as supplied by the user, or |
| 4367 |
% $-1$ to indicate that checking shouldn't be done). After |
| 4368 |
% performing the appropriate error detection and initialization, |
| 4369 |
% \cs{start@align} calls \cs{align@}. |
| 4370 |
% |
| 4371 |
% Note that the \cs{equation} counter is no longer stepped at the |
| 4372 |
% beginning of these environments. |
| 4373 |
% |
| 4374 |
% TODO: Implement \cs{shoveleft} and \cs{shoveright} for |
| 4375 |
% \env{align}. |
| 4376 |
% \changes{v2.17w}{2025/03/08}{Use \cs{dollardollar@begin} and |
| 4377 |
% \cs{dollardollar@end} instead of \texttt{\$\$} for tagging support} |
| 4378 |
% \begin{macrocode} |
| 4379 |
\def\start@align#1#2#3{% |
| 4380 |
\let\xatlevel@#1% always \z@, \@ne, or \tw@ |
| 4381 |
\maxfields@#3\relax |
| 4382 |
\ifnum\maxfields@>\m@ne |
| 4383 |
\checkat@true |
| 4384 |
\ifnum\xatlevel@=\tw@ |
| 4385 |
\xxat@true |
| 4386 |
\fi |
| 4387 |
\multiply\maxfields@\tw@ |
| 4388 |
\else |
| 4389 |
\checkat@false |
| 4390 |
\fi |
| 4391 |
\ifingather@ |
| 4392 |
\iffalse{\fi\ifnum0=`}\fi |
| 4393 |
\DN@{\vcenter\bgroup\savealignstate@\align@#2}% |
| 4394 |
\else |
| 4395 |
\ifmmode |
| 4396 |
\if@display |
| 4397 |
\DN@{\align@recover}% |
| 4398 |
\else |
| 4399 |
\nomath@env |
| 4400 |
\DN@{\@namedef{end\@currenvir}{}\@gobble}% |
| 4401 |
\fi |
| 4402 |
\else |
| 4403 |
\dollardollar@begin |
| 4404 |
\let\split\insplit@ |
| 4405 |
\DN@{\align@#2}% |
| 4406 |
\fi |
| 4407 |
\fi |
| 4408 |
\collect@body\next@ |
| 4409 |
} |
| 4410 |
% \end{macrocode} |
| 4411 |
% |
| 4412 |
% With version 1.2 of \pkg{amsmath}, it was possible to use |
| 4413 |
% \env{align*} and relatives in certain wrong contexts without |
| 4414 |
% getting an error, e.g. |
| 4415 |
% \begin{verbatim} |
| 4416 |
% \begin{equation*} |
| 4417 |
% \begin{align*} |
| 4418 |
% ... |
| 4419 |
% \end{align*} |
| 4420 |
% \end{equation*} |
| 4421 |
% \end{verbatim} |
| 4422 |
% |
| 4423 |
% For backward compatibility we therefore give only a warning for |
| 4424 |
% this condition instead of a full error, and try to recover using |
| 4425 |
% the \env{aligned} environment. The alignment of the material may be |
| 4426 |
% adversely affected but it will at least remain readable. |
| 4427 |
% \begin{macrocode} |
| 4428 |
\def\align@recover#1#2#3{% |
| 4429 |
\endgroup |
| 4430 |
\@amsmath@err{% |
| 4431 |
Erroneous nesting of equation structures;\MessageBreak |
| 4432 |
trying to recover with `aligned'% |
| 4433 |
}\@ehc |
| 4434 |
\begin{aligned}\relax#1\end{aligned}% |
| 4435 |
} |
| 4436 |
% \end{macrocode} |
| 4437 |
% \end{macro} |
| 4438 |
% |
| 4439 |
% \begin{environment}{align} |
| 4440 |
% \begin{environment}{align*} |
| 4441 |
% \begin{environment}{flalign} |
| 4442 |
% \begin{environment}{flalign*} |
| 4443 |
% \begin{environment}{alignat} |
| 4444 |
% \begin{environment}{alignat*} |
| 4445 |
% \begin{environment}{xalignat} |
| 4446 |
% \begin{environment}{xalignat*} |
| 4447 |
% \begin{environment}{xxalignat} |
| 4448 |
% The definitions of the various \env{align} environments are quite |
| 4449 |
% straight-forward. |
| 4450 |
% |
| 4451 |
% \begin{macrocode} |
| 4452 |
\newenvironment{alignat}{% |
| 4453 |
\start@align\z@\st@rredfalse |
| 4454 |
}{% |
| 4455 |
\endalign |
| 4456 |
} |
| 4457 |
\newenvironment{alignat*}{% |
| 4458 |
\start@align\z@\st@rredtrue |
| 4459 |
}{% |
| 4460 |
\endalign |
| 4461 |
} |
| 4462 |
\newenvironment{xalignat}{% |
| 4463 |
\start@align\@ne\st@rredfalse |
| 4464 |
}{% |
| 4465 |
\endalign |
| 4466 |
} |
| 4467 |
\newenvironment{xalignat*}{% |
| 4468 |
\start@align\@ne\st@rredtrue |
| 4469 |
}{% |
| 4470 |
\endalign |
| 4471 |
} |
| 4472 |
\newenvironment{xxalignat}{% |
| 4473 |
\start@align\tw@\st@rredtrue |
| 4474 |
}{% |
| 4475 |
\endalign |
| 4476 |
} |
| 4477 |
% \end{macrocode} |
| 4478 |
% |
| 4479 |
% \changes{v2.17w}{2025/03/08}{Use \cs{dollardollar@begin} and |
| 4480 |
% \cs{dollardollar@end} instead of \texttt{\$\$} for tagging support} |
| 4481 |
% \begin{macrocode} |
| 4482 |
\newenvironment{align}{% |
| 4483 |
\start@align\@ne\st@rredfalse\m@ne |
| 4484 |
}{% |
| 4485 |
\math@cr \black@\totwidth@ |
| 4486 |
\egroup |
| 4487 |
\ifingather@ |
| 4488 |
\restorealignstate@ |
| 4489 |
\egroup |
| 4490 |
\nonumber |
| 4491 |
\ifnum0=`{\fi\iffalse}\fi |
| 4492 |
\else |
| 4493 |
\dollardollar@end |
| 4494 |
\fi |
| 4495 |
\ignorespacesafterend |
| 4496 |
} |
| 4497 |
\newenvironment{align*}{% |
| 4498 |
\start@align\@ne\st@rredtrue\m@ne |
| 4499 |
}{% |
| 4500 |
\endalign |
| 4501 |
} |
| 4502 |
\newenvironment{flalign}{% |
| 4503 |
\start@align\tw@\st@rredfalse\m@ne |
| 4504 |
}{% |
| 4505 |
\endalign |
| 4506 |
} |
| 4507 |
\newenvironment{flalign*}{% |
| 4508 |
\start@align\tw@\st@rredtrue\m@ne |
| 4509 |
}{% |
| 4510 |
\endalign |
| 4511 |
} |
| 4512 |
% \end{macrocode} |
| 4513 |
% \end{environment} |
| 4514 |
% \end{environment} |
| 4515 |
% \end{environment} |
| 4516 |
% \end{environment} |
| 4517 |
% \end{environment} |
| 4518 |
% \end{environment} |
| 4519 |
% \end{environment} |
| 4520 |
% \end{environment} |
| 4521 |
% \end{environment} |
| 4522 |
% |
| 4523 |
% |
| 4524 |
% \begin{macro}{\align@} |
| 4525 |
% TODO: Some of these sets of initializations show up in multiple |
| 4526 |
% places. It might be worth making an abbreviation for them. |
| 4527 |
% |
| 4528 |
% \begin{macrocode} |
| 4529 |
\def\align@#1#2{% |
| 4530 |
\inalign@true \intertext@ \Let@ \chardef\dspbrk@context\z@ |
| 4531 |
\ifingather@\else\displ@y@\fi |
| 4532 |
\let\math@cr@@@\math@cr@@@align |
| 4533 |
\ifxxat@\else \let\tag\tag@in@align \fi |
| 4534 |
\let\label\label@in@display |
| 4535 |
#1% set st@r |
| 4536 |
\ifst@rred\else \global\@eqnswtrue \fi |
| 4537 |
\measure@{#2}% |
| 4538 |
\global\row@\z@ |
| 4539 |
\tabskip\eqnshift@ |
| 4540 |
\halign\bgroup |
| 4541 |
\span\align@preamble\crcr |
| 4542 |
#2% |
| 4543 |
} |
| 4544 |
% \end{macrocode} |
| 4545 |
% \end{macro} |
| 4546 |
% |
| 4547 |
% \begin{macro}{\math@cr@@@align} |
| 4548 |
% \begin{macrocode} |
| 4549 |
\def\math@cr@@@align{% |
| 4550 |
\ifst@rred\nonumber\fi |
| 4551 |
\if@eqnsw \global\tag@true \fi |
| 4552 |
\global\advance\row@\@ne |
| 4553 |
\add@amps\maxfields@ |
| 4554 |
\omit |
| 4555 |
\kern-\alignsep@ |
| 4556 |
\iftag@ |
| 4557 |
\setboxz@h{\@lign\strut@{\make@display@tag}}% |
| 4558 |
\place@tag |
| 4559 |
\fi |
| 4560 |
\ifst@rred\else\global\@eqnswtrue\fi |
| 4561 |
\global\lineht@\z@ |
| 4562 |
\cr |
| 4563 |
} |
| 4564 |
% \end{macrocode} |
| 4565 |
% \end{macro} |
| 4566 |
% |
| 4567 |
% \begin{macro}{\math@cr@@@align@measure} |
| 4568 |
% \begin{macrocode} |
| 4569 |
\def\math@cr@@@align@measure{% |
| 4570 |
&\omit |
| 4571 |
\global\advance\row@\@ne |
| 4572 |
\ifst@rred\nonumber\fi |
| 4573 |
\if@eqnsw \global\tag@true \fi |
| 4574 |
\ifnum\column@>\maxfields@ |
| 4575 |
\ifcheckat@ |
| 4576 |
\begingroup |
| 4577 |
\measuring@false |
| 4578 |
\@amsmath@err{Extra & on this line}% |
| 4579 |
{\the\andhelp@}% "An extra & here is disastrous" |
| 4580 |
\endgroup |
| 4581 |
\else |
| 4582 |
\global\maxfields@\column@ |
| 4583 |
\fi |
| 4584 |
\fi |
| 4585 |
\setboxz@h{\@lign\strut@{% |
| 4586 |
\if@eqnsw |
| 4587 |
\stepcounter{equation}% |
| 4588 |
\tagform@\theequation |
| 4589 |
\else |
| 4590 |
\iftag@\df@tag\fi |
| 4591 |
\fi |
| 4592 |
}}% |
| 4593 |
\savetaglength@ |
| 4594 |
\ifst@rred\else\global\@eqnswtrue\fi |
| 4595 |
\cr |
| 4596 |
} |
| 4597 |
% \end{macrocode} |
| 4598 |
% \end{macro} |
| 4599 |
% |
| 4600 |
% \begin{macro}{\field@lengths} |
| 4601 |
% \begin{macro}{\savefieldlength@} |
| 4602 |
% \begin{macro}{\fieldlengths@} |
| 4603 |
% \begin{macrocode} |
| 4604 |
\let\field@lengths\@empty |
| 4605 |
|
| 4606 |
\def\savefieldlength@{% |
| 4607 |
\begingroup |
| 4608 |
\let\or\relax |
| 4609 |
\xdef\field@lengths{% |
| 4610 |
\field@lengths |
| 4611 |
\ifnum\column@=0 |
| 4612 |
\or |
| 4613 |
\else |
| 4614 |
,% |
| 4615 |
\fi |
| 4616 |
\the\wdz@ |
| 4617 |
}% |
| 4618 |
\endgroup |
| 4619 |
} |
| 4620 |
|
| 4621 |
\def\fieldlengths@#1{% |
| 4622 |
\ifcase\@xp#1\field@lengths\fi |
| 4623 |
} |
| 4624 |
% \end{macrocode} |
| 4625 |
% \end{macro} |
| 4626 |
% \end{macro} |
| 4627 |
% \end{macro} |
| 4628 |
% |
| 4629 |
% \begin{macro}{\maxcolumn@widths} |
| 4630 |
% \cs{maxcolumn@widths} will be used to hold the widths of the |
| 4631 |
% fields of the \env{alignat} environment. The widths will be |
| 4632 |
% separated by the token \cn{or}, making it easy to extract a given |
| 4633 |
% width using \cn{ifcase}. |
| 4634 |
% \begin{macrocode} |
| 4635 |
\let\maxcolumn@widths\@empty |
| 4636 |
% \end{macrocode} |
| 4637 |
% \end{macro} |
| 4638 |
% |
| 4639 |
% \begin{macro}{\maxcol@width} |
| 4640 |
% \cs{maxcol@width} $n$ = maximum width of $n$th column of the current |
| 4641 |
% \env{alignat} (i.e., the $n$th field of \cs{maxcolumn@widths}.) |
| 4642 |
% It expands to a \<dimen>, so it can be used as the right-hand |
| 4643 |
% side of a \<variable assignment> or \<arithmetic> statement. |
| 4644 |
% Its argument can be any \<number>, \<integer variable> or macro |
| 4645 |
% that expands to one of these. [Check to make sure this is true.] |
| 4646 |
% |
| 4647 |
% This is subtler than it looks. |
| 4648 |
% \begin{macrocode} |
| 4649 |
\def\maxcol@width#1{% |
| 4650 |
\ifcase\@xp#1\maxcolumn@widths\fi\relax |
| 4651 |
} |
| 4652 |
% \end{macrocode} |
| 4653 |
% \end{macro} |
| 4654 |
% |
| 4655 |
% Now comes the real fun. A typical \env{align} environments looks |
| 4656 |
% something like this, where the vertical bars mark the edges of |
| 4657 |
% the fields of the underlying \cs{halign}: |
| 4658 |
% \[ |
| 4659 |
% \makeatletter\tabskip\@centering\offinterlineskip |
| 4660 |
% \halign to\displaywidth{%^^A |
| 4661 |
% &$\strut$\vrule\hfil$\m@th\displaystyle{\@lign#}$\vrule |
| 4662 |
% \tabskip1pt&\vrule$\m@th\displaystyle{\@lign#}$\hfil\vrule |
| 4663 |
% \tabskip\@centering\cr |
| 4664 |
% \omit\small\hfil 1\hfil &\omit\small\hfil 2 &\omit\small\hfil |
| 4665 |
% 3\hfil &\omit\small\hfil 4\hfil & \omit\small\hfil 5\hfil |
| 4666 |
% &\omit\small\hfil 6\hfil\cr |
| 4667 |
% \noalign{\vskip8pt\relax} |
| 4668 |
% V_i + q_i v_j & =v_i , & X_i & = x_i - q_i x_j, |
| 4669 |
% & U_i & = u_i,\qquad |
| 4670 |
% \hbox{for $i\ne j$;} %&\omit\hfill \llap{(3)} |
| 4671 |
% \cr |
| 4672 |
% V_j & = v_j, & X_j & = x_j, |
| 4673 |
% & U_j & = u_j + \sum_{i\ne j} q_i u_i. %&\omit\hfill \llap{(4)} |
| 4674 |
% \cr} |
| 4675 |
% \] |
| 4676 |
% Note that each align structure consists of two fields, with no |
| 4677 |
% space between them (a small space has been added here to |
| 4678 |
% highlight the boundaries). Furthermore, the text inside the |
| 4679 |
% odd-numbered fields is flushright, while the text inside the |
| 4680 |
% even-numbered fields is flushleft. The equation tags (shown on |
| 4681 |
% the right here) can be on either the right or the left. If there |
| 4682 |
% is not room (in a sense to be defined shortly) for the tag on the |
| 4683 |
% same line as the equation, the tag will be shifted to a separate |
| 4684 |
% line. |
| 4685 |
% |
| 4686 |
% Each environment also has a certain number of ``flexible |
| 4687 |
% spaces,'' meaning spaces whose width we are allowed to adjust to |
| 4688 |
% take up the amount of ``free space'' in the line, meaning the |
| 4689 |
% space not taken up by the equation tag and the fields of the |
| 4690 |
% underlying \cs{halign}. |
| 4691 |
% |
| 4692 |
% The flexible spaces come in two flavors: interalign spaces and |
| 4693 |
% margin spaces. If there are $n$ align structures ($n=3$ in the |
| 4694 |
% illustration above), there are $n-1$ interalign spaces, unless we |
| 4695 |
% are in an \env{alignat} environment, in which case there are no |
| 4696 |
% flexible interalign spaces. |
| 4697 |
% |
| 4698 |
% The number of margin spaces is a little more complicated: |
| 4699 |
% Normally, there are two, but if we're in \opt{fleqn} mode, there |
| 4700 |
% is only one. Furthermore, if we're in an \env{xxalignat} or |
| 4701 |
% \env{flalign} environment (corresponding to $\cs{xatlevel@} = 2$, |
| 4702 |
% then there are no flexible margin spaces. |
| 4703 |
% |
| 4704 |
% Calculating the interalign and margin spaces is done in two |
| 4705 |
% stages. |
| 4706 |
% |
| 4707 |
% First, the total amount of free space is divided uniformly among |
| 4708 |
% all the flexible spaces, without regard for the lengths of the tags |
| 4709 |
% on the various lines. For the non-\opt{fleqn} case, this |
| 4710 |
% corresponds to centering the align structures between the margins. |
| 4711 |
% Note that in \opt{fleqn} mode, the right margin is still allowed to |
| 4712 |
% be larger than \cs{@mathmargin}. This introduces an element of |
| 4713 |
% asymmetry into the appearance of the environment, but it has the |
| 4714 |
% advantage of leaving more space for equation tags in the right |
| 4715 |
% margin. If the right margin were constrained to be equal to the |
| 4716 |
% left margin in this case, tags would need to be shifted to a |
| 4717 |
% separate line more often than would be desirable. |
| 4718 |
% |
| 4719 |
% Ordinarily, all flexible spaces will be given the same width. |
| 4720 |
% However, this is not invariably true, since the interalign spaces |
| 4721 |
% are constrained to be at least \cs{minalignsep} wide, while---in |
| 4722 |
% the absence of equation tags, at least---the margin spaces are |
| 4723 |
% allowed to shrink to zero. As we shall see in a minute, if there |
| 4724 |
% are tags in the environment, then the margins are also bounded |
| 4725 |
% below by \cs{mintagsep}. |
| 4726 |
% |
| 4727 |
% Next, we examine each line of the environment that has a tag to |
| 4728 |
% see if there is a gap of at least \cs{mintagsep} between the |
| 4729 |
% equation and its tag. If there isn't, we attempt to center the |
| 4730 |
% equation between the tag and the opposite margin, leaving a gap |
| 4731 |
% of at least \cs{mintagsep} on either side, in order to preserve |
| 4732 |
% some symmetry, i.e., we want the equation to \emph{look} like |
| 4733 |
% it's centered between the margin and the tag, so we don't want |
| 4734 |
% the margin space to be less than the gap between the tag and the |
| 4735 |
% equation. (Arguably, it would be better to allow the margin |
| 4736 |
% space to shrink to zero in this case in order to avoid shifting |
| 4737 |
% the tag to a separate line at any cost, but that would require |
| 4738 |
% all of our calculations to be a little more complicated and hence |
| 4739 |
% a little slower.) Finally, if no values of the interalign spaces |
| 4740 |
% and the margins (with the constraints outlined above) will |
| 4741 |
% produce an acceptable distance between the equation and its tag, |
| 4742 |
% then the tag will be shifted to a separate line. |
| 4743 |
% |
| 4744 |
% \begin{macro}{\measure@} |
| 4745 |
% \cs{measure@} collects the various bits of information that we'll |
| 4746 |
% need to perform the calculations outlined above, namely, the |
| 4747 |
% number of align structures in the environment, the natural |
| 4748 |
% lengths of the fields on each row, the maximum widths of each |
| 4749 |
% column, and the widths of the equation tags on each line. It |
| 4750 |
% also calculates the number of flexible interalign and margin |
| 4751 |
% spaces and computes the initial values of the parameters |
| 4752 |
% \cs{eqnshift@} and \cs{alignsep@}, which correspond to the widths |
| 4753 |
% of the margins and the interalign spaces, respectively. |
| 4754 |
% \begin{macrocode} |
| 4755 |
\def\measure@#1{% |
| 4756 |
\begingroup |
| 4757 |
\measuring@true |
| 4758 |
\global\eqnshift@\z@ |
| 4759 |
\global\alignsep@\z@ |
| 4760 |
\global\let\tag@lengths\@empty |
| 4761 |
\global\let\field@lengths\@empty |
| 4762 |
\savecounters@ |
| 4763 |
\global\setbox0\vbox{% |
| 4764 |
\let\math@cr@@@\math@cr@@@align@measure |
| 4765 |
\everycr{\noalign{\global\tag@false |
| 4766 |
\global\let\raise@tag\@empty \global\column@\z@}}% |
| 4767 |
\let\label\@gobble |
| 4768 |
\global\row@\z@ |
| 4769 |
\tabskip\z@ |
| 4770 |
\halign{\span\align@preamble\crcr |
| 4771 |
#1% |
| 4772 |
\math@cr@@@ |
| 4773 |
\global\column@\z@ |
| 4774 |
\add@amps\maxfields@\cr |
| 4775 |
}% |
| 4776 |
}% |
| 4777 |
\restorecounters@ |
| 4778 |
% \end{macrocode} |
| 4779 |
% It's convenient to have \cs{maxfields@} rounded up to the nearest |
| 4780 |
% even number, so that \cs{maxfields@} is precisely twice the |
| 4781 |
% number of align structures. |
| 4782 |
% \begin{macrocode} |
| 4783 |
\ifodd\maxfields@ |
| 4784 |
\global\advance\maxfields@\@ne |
| 4785 |
\fi |
| 4786 |
% \end{macrocode} |
| 4787 |
% It doesn't make sense to have a single align structure in either |
| 4788 |
% \env{flalign} or \env{xxalignat}. So, we check for that case now |
| 4789 |
% and, if necessary, switch to an \env{align} or \env{alignat}. |
| 4790 |
% Arguably, we should issue a warning message, but why bother? |
| 4791 |
% \begin{macrocode} |
| 4792 |
\ifnum\xatlevel@=\tw@ |
| 4793 |
\ifnum\maxfields@<\thr@@ |
| 4794 |
\let\xatlevel@\z@ |
| 4795 |
\fi |
| 4796 |
\fi |
| 4797 |
% \end{macrocode} |
| 4798 |
% |\box0| now contains the lines of the \cs{halign}. After the |
| 4799 |
% following maneuver, |\box1| will contain the last line of the |
| 4800 |
% \cs{halign}, which is what we're interested in. (Incidentally, |
| 4801 |
% the penalty we're removing is the \cs{@eqpen} inserted by |
| 4802 |
% \cs{math@cr}. Normally, this is \cs{interdisplaylinepenalty}, |
| 4803 |
% unless the user has overridden that with a \cs{displaybreak} |
| 4804 |
% command.) |
| 4805 |
% \begin{macrocode} |
| 4806 |
\setbox\z@\vbox{% |
| 4807 |
\unvbox\z@ \unpenalty \global\setbox\@ne\lastbox |
| 4808 |
}% |
| 4809 |
% \end{macrocode} |
| 4810 |
% |\box1| begins with \cs{tabskip} glue and contains alternating |
| 4811 |
% \cs{hbox}es (the fields whose widths we're trying to get) and |
| 4812 |
% \cs{tabskip} glue [need better diagram]: |
| 4813 |
% \begin{verbatim} |
| 4814 |
% \hbox{\tabskip\hbox\tabskip...\hbox\tabskip}\end{verbatim} |
| 4815 |
% In fact, all the \cs{tabskip} glue will be 0pt, because all the |
| 4816 |
% \cs{tabskip}s in an \env{alignat} environment have a natural |
| 4817 |
% width of 0pt, and the \cs{halign} has been set in its natural |
| 4818 |
% width. |
| 4819 |
% |
| 4820 |
% One nice result of this is that we can read \cs{totwidth@} off |
| 4821 |
% immediately, since it is just the width of |\box1|, plus |
| 4822 |
% \cs{@mathmargin} if we're in \opt{fleqn} mode. (Actually, we |
| 4823 |
% also have to take \cs{minalignsep} into account, but we'll do |
| 4824 |
% that later): |
| 4825 |
% \begin{macrocode} |
| 4826 |
\global\totwidth@\wd\@ne |
| 4827 |
\if@fleqn \global\advance\totwidth@\@mathmargin \fi |
| 4828 |
% \end{macrocode} |
| 4829 |
% Now we initialize \cs{align@lengths} and start peeling the boxes |
| 4830 |
% off, one by one, and adding their widths to \cs{align@lengths}. |
| 4831 |
% We stop when we run out of boxes, i.e., when \cs{lastbox} returns |
| 4832 |
% a void box. We're going to build a list using \cs{or} as a |
| 4833 |
% delimiter, so we want to disable it temporarily. |
| 4834 |
% \begin{macrocode} |
| 4835 |
\global\let\maxcolumn@widths\@empty |
| 4836 |
\begingroup |
| 4837 |
\let\or\relax |
| 4838 |
\loop |
| 4839 |
\global\setbox\@ne\hbox{% |
| 4840 |
\unhbox\@ne \unskip \global\setbox\thr@@\lastbox |
| 4841 |
}% |
| 4842 |
\ifhbox\thr@@ |
| 4843 |
\xdef\maxcolumn@widths{ \or \the\wd\thr@@ \maxcolumn@widths}% |
| 4844 |
\repeat |
| 4845 |
\endgroup |
| 4846 |
% \end{macrocode} |
| 4847 |
% Now we calculate the number of flexible spaces and the initial |
| 4848 |
% values of \cs{eqnshift@} and \cs{alignsep@}. |
| 4849 |
% We start by calculating $\cs{displaywidth}-\cs{totwidth@}$, |
| 4850 |
% which gives us the total amount of ``free space'' in a row. |
| 4851 |
% \begin{macrocode} |
| 4852 |
\dimen@\displaywidth |
| 4853 |
\advance\dimen@-\totwidth@ |
| 4854 |
% \end{macrocode} |
| 4855 |
% Next we calculate the number of columns of flexible spaces in the |
| 4856 |
% display, which depends on whether we're in \opt{fleqn} mode and |
| 4857 |
% in which particular environment we are in. |
| 4858 |
% |
| 4859 |
% We use \cs{@tempcnta} to store the total number of flexible spaces |
| 4860 |
% in the align and \cs{@tempcntb} for the number of interalign |
| 4861 |
% spaces. |
| 4862 |
% \begin{macrocode} |
| 4863 |
\ifcase\xatlevel@ |
| 4864 |
% \end{macrocode} |
| 4865 |
% In \env{alignat}, the interalign spaces are under user control, |
| 4866 |
% not ours. So, we set \cs{alignsep@} and \cs{minalignsep} both |
| 4867 |
% equal to 0pt. Later, when calculating a new value for |
| 4868 |
% \cs{alignsep@}, we will only save the new value if it is less |
| 4869 |
% than the current value of \cs{alignsep@} (i.e., \cs{alignsep@} |
| 4870 |
% will never increase). Since the values we calculate will never |
| 4871 |
% be negative, this will ensure that \cs{alignsep@} remains zero in |
| 4872 |
% \env{alignat}. |
| 4873 |
% \begin{macrocode} |
| 4874 |
\global\alignsep@\z@ |
| 4875 |
\let\minalignsep\z@ |
| 4876 |
\@tempcntb\z@ |
| 4877 |
% \end{macrocode} |
| 4878 |
% In \opt{fleqn} mode, the left margin---and hence the right margin |
| 4879 |
% in this case---is fixed. Otherwise, we divide the free space |
| 4880 |
% equally between the two margins. |
| 4881 |
% \begin{macrocode} |
| 4882 |
\if@fleqn |
| 4883 |
\@tempcnta\@ne |
| 4884 |
\global\eqnshift@\@mathmargin |
| 4885 |
\else |
| 4886 |
\@tempcnta\tw@ |
| 4887 |
\global\eqnshift@\dimen@ |
| 4888 |
\global\divide\eqnshift@\@tempcnta |
| 4889 |
\fi |
| 4890 |
\or |
| 4891 |
% \end{macrocode} |
| 4892 |
% In an \env{align} or \env{xalignat} environment with $n$ aligned |
| 4893 |
% structures, there are $n-1$ interalign spaces and either 1 or~2 |
| 4894 |
% flexible margins, depending on whether we're in \opt{fleqn} mode |
| 4895 |
% or not. |
| 4896 |
% \begin{macrocode} |
| 4897 |
\@tempcntb\maxfields@ |
| 4898 |
\divide\@tempcntb\tw@ |
| 4899 |
\@tempcnta\@tempcntb |
| 4900 |
\advance\@tempcntb\m@ne |
| 4901 |
% \end{macrocode} |
| 4902 |
% If we are in \opt{fleqn} mode, we fix the left margin and divide |
| 4903 |
% the free space equally among the interalign spaces and the right |
| 4904 |
% margin. |
| 4905 |
% \begin{macrocode} |
| 4906 |
\if@fleqn |
| 4907 |
\global\eqnshift@\@mathmargin |
| 4908 |
\global\alignsep@\dimen@ |
| 4909 |
\global\divide\alignsep@\@tempcnta |
| 4910 |
\else |
| 4911 |
% \end{macrocode} |
| 4912 |
% Otherwise, we divide the free space equally among the interalign |
| 4913 |
% spaces and both margins. |
| 4914 |
% \begin{macrocode} |
| 4915 |
\global\advance\@tempcnta\@ne |
| 4916 |
\global\eqnshift@\dimen@ |
| 4917 |
\global\divide\eqnshift@\@tempcnta |
| 4918 |
\global\alignsep@\eqnshift@ |
| 4919 |
\fi |
| 4920 |
\or |
| 4921 |
% \end{macrocode} |
| 4922 |
% Finally, if we're in an \env{flalign} or \env{xxalignat} |
| 4923 |
% environment, there are no flexible margins and $n-1$ flexible |
| 4924 |
% interalign spaces. |
| 4925 |
% \begin{macrocode} |
| 4926 |
\@tempcntb\maxfields@ |
| 4927 |
\divide\@tempcntb\tw@ |
| 4928 |
\global\advance\@tempcntb\m@ne |
| 4929 |
\global\@tempcnta\@tempcntb |
| 4930 |
\global\eqnshift@\z@ |
| 4931 |
\global\alignsep@\dimen@ |
| 4932 |
% \end{macrocode} |
| 4933 |
% If we're in \opt{fleqn} mode, we need to add back the |
| 4934 |
% \cs{@mathmargin} that was removed when \cs{dimen@} was originally |
| 4935 |
% calculated above. |
| 4936 |
% \begin{macrocode} |
| 4937 |
\if@fleqn |
| 4938 |
\global\advance\alignsep@\@mathmargin\relax |
| 4939 |
\fi |
| 4940 |
\global\divide\alignsep@\@tempcntb |
| 4941 |
\fi |
| 4942 |
% \end{macrocode} |
| 4943 |
% Now we make sure \cs{alignsep@} isn't too small. |
| 4944 |
% \begin{macrocode} |
| 4945 |
\ifdim\alignsep@<\minalignsep\relax |
| 4946 |
\global\alignsep@\minalignsep\relax |
| 4947 |
\ifdim\eqnshift@>\z@ |
| 4948 |
\if@fleqn\else |
| 4949 |
\global\eqnshift@\displaywidth |
| 4950 |
\global\advance\eqnshift@-\totwidth@ |
| 4951 |
\global\advance\eqnshift@-\@tempcntb\alignsep@ |
| 4952 |
\global\divide\eqnshift@\tw@ |
| 4953 |
\fi |
| 4954 |
\fi |
| 4955 |
\fi |
| 4956 |
\ifdim\eqnshift@<\z@ |
| 4957 |
\global\eqnshift@\z@ |
| 4958 |
\fi |
| 4959 |
\calc@shift@align |
| 4960 |
% \end{macrocode} |
| 4961 |
% Next, we calculate the value of \cs{tagshift@}. This is the glue |
| 4962 |
% that will be inserted in front of the equation tag to make sure |
| 4963 |
% it lines up flush against the appropriate margin. |
| 4964 |
% \begin{macrocode} |
| 4965 |
\global\tagshift@\totwidth@ |
| 4966 |
\global\advance\tagshift@\@tempcntb\alignsep@ |
| 4967 |
\if@fleqn |
| 4968 |
\ifnum\xatlevel@=\tw@ |
| 4969 |
\global\advance\tagshift@-\@mathmargin\relax |
| 4970 |
\fi |
| 4971 |
\else |
| 4972 |
\global\advance\tagshift@\eqnshift@ |
| 4973 |
\fi |
| 4974 |
\iftagsleft@ \else |
| 4975 |
\global\advance\tagshift@-\displaywidth |
| 4976 |
\fi |
| 4977 |
% \end{macrocode} |
| 4978 |
% Finally, we increase \cs{totwidth@} by an appropriate multiple of |
| 4979 |
% \cs{minalignsep}. If the result is greater than |
| 4980 |
% \cs{displaywidth}, it means that at least one line in the |
| 4981 |
% \env{align} is overfull and we will issue an appropriate warning |
| 4982 |
% message (via \cs{bl@ck}) at the end of the environment. |
| 4983 |
% \begin{macrocode} |
| 4984 |
\dimen@\minalignsep\relax |
| 4985 |
\global\advance\totwidth@\@tempcntb\dimen@ |
| 4986 |
\ifdim\totwidth@>\displaywidth |
| 4987 |
\global\let\displaywidth@\totwidth@ |
| 4988 |
\else |
| 4989 |
\global\let\displaywidth@\displaywidth |
| 4990 |
\fi |
| 4991 |
\endgroup |
| 4992 |
} |
| 4993 |
% \end{macrocode} |
| 4994 |
% \end{macro} |
| 4995 |
% |
| 4996 |
% The code for calculating the appropriate placement of equation |
| 4997 |
% tags in the \env{align} environments is quite complicated and |
| 4998 |
% varies wildly depending on the settings of the |tagsleft@| and |
| 4999 |
% |@fleqn| switches. To minimize memory and hash space usage, we |
| 5000 |
% only define the variant appropriate for the current setting of |
| 5001 |
% those switches. |
| 5002 |
% |
| 5003 |
% It would be worthwhile to examine this code more closely someday |
| 5004 |
% and see if it could be optimized any. |
| 5005 |
% |
| 5006 |
% \paragraph{Tag placement when \cs{tagsleft@true}, |
| 5007 |
% \cs{@fleqntrue}.} |
| 5008 |
% |
| 5009 |
% We begin with the version of \cs{calc@shift@align} appropriate |
| 5010 |
% for flush-left equations with tags on the left. |
| 5011 |
% |
| 5012 |
% \begin{macro}{\calc@shift@align} |
| 5013 |
% This is the simplest case. Since the left margin is fixed, in |
| 5014 |
% general the only thing to do is check whether there is room for |
| 5015 |
% the tag in the left margin. The only exception is that if |
| 5016 |
% $\cs{eqnshift@} = 0\,\mathrm{pt}$---meaning that we're in a |
| 5017 |
% \env{flalign} environment and this is the first line with a tag |
| 5018 |
% that we've encountered---then we set $\cs{eqnshift@} = |
| 5019 |
% \cs{@mathmargin}$ and recalculate \cs{alignsep@}. This is done |
| 5020 |
% by \cs{x@calc@shift@lf}. |
| 5021 |
% \begin{macrocode} |
| 5022 |
\iftagsleft@\if@fleqn |
| 5023 |
\def\calc@shift@align{% |
| 5024 |
\global\let\tag@shifts\@empty |
| 5025 |
\begingroup |
| 5026 |
% \end{macrocode} |
| 5027 |
% \cs{@tempdima} is initialized to $\cs{@mathmargin} - |
| 5028 |
% \cs{mintagsep}$, which yields the maximum size of a tag that will |
| 5029 |
% not be shifted to another line. |
| 5030 |
% \begin{macrocode} |
| 5031 |
\@tempdima\@mathmargin\relax |
| 5032 |
\advance\@tempdima-\mintagsep\relax |
| 5033 |
% \end{macrocode} |
| 5034 |
% Now we examine each row in turn. If the width of the tag on the |
| 5035 |
% line is non-positive---meaning either that there is no tag or |
| 5036 |
% else that the user has forced it to have zero width---we mark the |
| 5037 |
% tag to remain unshifted. Otherwise, we call \cs{x@calc@shift@lf} |
| 5038 |
% to determine whether any adjustments need to be made to |
| 5039 |
% \cs{eqnshift@} and \cs{alignsep@}. Note the difference in |
| 5040 |
% treatment of zero-width tags between this code and \tex/'s |
| 5041 |
% built-in algorithm: here, a width of zero prohibits the tag from |
| 5042 |
% being shifted, while in \tex/'s built-in algorithm, a width of |
| 5043 |
% zero forces the tag to be shifted. |
| 5044 |
% \begin{macrocode} |
| 5045 |
\loop |
| 5046 |
\ifnum\row@>0 |
| 5047 |
\ifdim\tag@width\row@>\z@ |
| 5048 |
\x@calc@shift@lf |
| 5049 |
\else |
| 5050 |
\saveshift@0% |
| 5051 |
\fi |
| 5052 |
\advance\row@\m@ne |
| 5053 |
\repeat |
| 5054 |
\endgroup |
| 5055 |
} |
| 5056 |
% \end{macrocode} |
| 5057 |
% \end{macro} |
| 5058 |
% |
| 5059 |
% \begin{macro}{\x@calc@shift@lf} |
| 5060 |
% As mentioned above, \cs{x@calc@shift@lf} first checks to see if |
| 5061 |
% the current left margin is set to 0 and, if so, resets it to |
| 5062 |
% \cs{@mathmargin} and recalculates \cs{alignsep@}. Next, it |
| 5063 |
% checks whether the length of the current tag exceeds the |
| 5064 |
% previously calculated limit and, if so, marks the tag to be |
| 5065 |
% shifted to a separate line. |
| 5066 |
% \begin{macrocode} |
| 5067 |
\def\x@calc@shift@lf{% |
| 5068 |
\ifdim\eqnshift@=\z@ |
| 5069 |
\global\eqnshift@\@mathmargin\relax |
| 5070 |
\alignsep@\displaywidth |
| 5071 |
\advance\alignsep@-\totwidth@ |
| 5072 |
\global\divide\alignsep@\@tempcntb |
| 5073 |
\ifdim\alignsep@<\minalignsep\relax |
| 5074 |
\global\alignsep@\minalignsep\relax |
| 5075 |
\fi |
| 5076 |
\fi |
| 5077 |
\ifdim\tag@width\row@>\@tempdima |
| 5078 |
\saveshift@1% |
| 5079 |
\else |
| 5080 |
\saveshift@0% |
| 5081 |
\fi |
| 5082 |
} |
| 5083 |
\fi\fi |
| 5084 |
% \end{macrocode} |
| 5085 |
% \end{macro} |
| 5086 |
% |
| 5087 |
% \paragraph{Tag placement when \cs{tagsleft@false}, |
| 5088 |
% \cs{@fleqntrue}.} |
| 5089 |
% |
| 5090 |
% Next we consider the case when equations are flush-left, but tags |
| 5091 |
% are on the right. This case is somewhat more complicated than |
| 5092 |
% the previous one, since we can adjust the right margin by varying |
| 5093 |
% the inter-align separation. Thus, when a tag is found to be too |
| 5094 |
% close to its equation, we first attempt to decrease |
| 5095 |
% \cs{alignsep@} enough to move the equation off to an acceptable |
| 5096 |
% distance. Only if that would require a value of \cs{alignsep@} |
| 5097 |
% less than \cs{minalignsep} do we move the tag to a separate line. |
| 5098 |
% |
| 5099 |
% \begin{macro}{\calc@shift@align} |
| 5100 |
% This version of \cs{calc@shift@align} differs from the previous |
| 5101 |
% version only in calling \cs{x@calc@shift@rf} rather than |
| 5102 |
% \cs{x@calc@shift@lf}. |
| 5103 |
% \begin{macrocode} |
| 5104 |
\iftagsleft@\else\if@fleqn |
| 5105 |
\def\calc@shift@align{% |
| 5106 |
\global\let\tag@shifts\@empty |
| 5107 |
\begingroup |
| 5108 |
\loop |
| 5109 |
\ifnum\row@>0 |
| 5110 |
\ifdim\tag@width\row@>\z@ |
| 5111 |
\x@calc@shift@rf |
| 5112 |
\else |
| 5113 |
\saveshift@0% |
| 5114 |
\fi |
| 5115 |
\advance\row@\m@ne |
| 5116 |
\repeat |
| 5117 |
\endgroup |
| 5118 |
} |
| 5119 |
% \end{macrocode} |
| 5120 |
% \end{macro} |
| 5121 |
% |
| 5122 |
% \begin{macro}{\x@calc@shift@rf} |
| 5123 |
% To start, we need to know two quantities: the number of align |
| 5124 |
% structures in the current row and the ``effective length'' of the |
| 5125 |
% row, defined as the distance from the left margin to the |
| 5126 |
% right edge of the text assuming that \cs{eqnshift@} and |
| 5127 |
% \cs{alignsep@} are both~0. To get the number of align |
| 5128 |
% structures, we first count the number of columns by counting the |
| 5129 |
% number of entries in the \cs{fieldlengths@} for the current row. |
| 5130 |
% The effective length is calculated by \cs{x@rcalc@width} and put |
| 5131 |
% in the temporary register \cs{@tempdimc}, using \cs{@tempdimb} as |
| 5132 |
% an auxiliary variable. |
| 5133 |
% \begin{macrocode} |
| 5134 |
\def\x@calc@shift@rf{% |
| 5135 |
\column@\z@ |
| 5136 |
\@tempdimb\z@ |
| 5137 |
\@tempdimc\z@ |
| 5138 |
\edef\@tempb{\fieldlengths@\row@}% |
| 5139 |
\@for\@tempa:=\@tempb\do{% |
| 5140 |
\advance\column@\@ne |
| 5141 |
\x@rcalc@width |
| 5142 |
}% |
| 5143 |
\begingroup |
| 5144 |
% \end{macrocode} |
| 5145 |
% If there are $n$ columns in the current row, then there are |
| 5146 |
% $\lfloor (n+1)/2 \rfloor$ align structures and $\lfloor (n-1)/2 |
| 5147 |
% \rfloor$ interalign spaces. |
| 5148 |
% \begin{macrocode} |
| 5149 |
\advance\column@\m@ne |
| 5150 |
\divide\column@\tw@ |
| 5151 |
% \end{macrocode} |
| 5152 |
% If this is smaller than the maximum number of interalign spaces |
| 5153 |
% in the environment, then we need to reduce \cs{@tempcnta} (the |
| 5154 |
% total number of flexible spaces in the current line) by |
| 5155 |
% $\cs{@tempcntb} - \cs{column@}$ and reset \cs{@tempcntb} to |
| 5156 |
% \cs{column@}. |
| 5157 |
% \begin{macrocode} |
| 5158 |
\ifnum\@tempcntb>\column@ |
| 5159 |
\advance\@tempcnta-\@tempcntb |
| 5160 |
\advance\@tempcnta\column@ |
| 5161 |
\@tempcntb\column@ |
| 5162 |
\fi |
| 5163 |
% \end{macrocode} |
| 5164 |
% Next, we add the width of the tag and the (fixed) left margin to |
| 5165 |
% the effective length calculated above. This can be used to |
| 5166 |
% calculate how much ``free space'' there is in the current line |
| 5167 |
% and thus how much leeway we have to increase the amount of space |
| 5168 |
% between the tag and the equation. |
| 5169 |
% \begin{macrocode} |
| 5170 |
\tagwidth@\tag@width\row@\relax |
| 5171 |
\@tempdima\eqnshift@ |
| 5172 |
\advance\@tempdima\@tempdimc\relax |
| 5173 |
\advance\@tempdima\tagwidth@ |
| 5174 |
% \end{macrocode} |
| 5175 |
% The first thing to check is whether the tag should be shifted to |
| 5176 |
% a separate line. To do this, we add the minimum interalign |
| 5177 |
% separation and the \cs{mintagsep} to the value of \cs{@tempdima} |
| 5178 |
% just calculated. This yields the minimum acceptable length of |
| 5179 |
% the current line. If that is greater than \cs{displaywidth}, we |
| 5180 |
% mark the tag to be calculated. Otherwise, we mark the tag to be |
| 5181 |
% kept on the same line and then check to see if the \cs{alignsep@} |
| 5182 |
% needs to be reduced to make room for the tag. |
| 5183 |
% \begin{macrocode} |
| 5184 |
\dimen@\minalignsep\relax |
| 5185 |
\multiply\dimen@\@tempcntb |
| 5186 |
\advance\dimen@\mintagsep\relax |
| 5187 |
\advance\dimen@\@tempdima |
| 5188 |
\ifdim\dimen@>\displaywidth |
| 5189 |
\saveshift@1% |
| 5190 |
\else |
| 5191 |
\saveshift@0% |
| 5192 |
% \end{macrocode} |
| 5193 |
% Now we perform essentially the same calculation, but using the |
| 5194 |
% current value of \cs{alignsep@} instead of \cs{minalignsep}. |
| 5195 |
% This gives the current length of the line. If this is greater |
| 5196 |
% than \cs{displaywidth}, we recalculate \cs{alignsep@} to make |
| 5197 |
% room for the tag. |
| 5198 |
% \begin{macrocode} |
| 5199 |
\dimen@\alignsep@\relax |
| 5200 |
\multiply\dimen@\@tempcntb |
| 5201 |
\advance\dimen@\@tempdima |
| 5202 |
\advance\dimen@\tagwidth@ |
| 5203 |
\ifdim\dimen@>\displaywidth |
| 5204 |
\dimen@\displaywidth |
| 5205 |
\advance\dimen@-\@tempdima |
| 5206 |
\ifnum\xatlevel@=\tw@ |
| 5207 |
\advance\dimen@-\mintagsep\relax |
| 5208 |
\fi |
| 5209 |
\divide\dimen@\@tempcnta |
| 5210 |
\ifdim\dimen@<\minalignsep\relax |
| 5211 |
\global\alignsep@\minalignsep\relax |
| 5212 |
\else |
| 5213 |
\global\alignsep@\dimen@ |
| 5214 |
\fi |
| 5215 |
\fi |
| 5216 |
\fi |
| 5217 |
\endgroup |
| 5218 |
} |
| 5219 |
\fi\fi |
| 5220 |
% \end{macrocode} |
| 5221 |
% \end{macro} |
| 5222 |
% |
| 5223 |
% \paragraph{Tag placement when \cs{tagsleft@false}, |
| 5224 |
% \cs{@fleqnfalse}.} |
| 5225 |
% |
| 5226 |
% This is similar to the previous case, except for the added |
| 5227 |
% complication that both \cs{alignsep@} and \cs{eqnshift@} can |
| 5228 |
% vary, which makes the computations correspondingly more |
| 5229 |
% complicated. |
| 5230 |
% |
| 5231 |
% \begin{macro}{\calc@shift@align} |
| 5232 |
% \begin{macrocode} |
| 5233 |
\iftagsleft@\else\if@fleqn\else |
| 5234 |
\def\calc@shift@align{% |
| 5235 |
\global\let\tag@shifts\@empty |
| 5236 |
\begingroup |
| 5237 |
\loop |
| 5238 |
\ifnum\row@>0 |
| 5239 |
\ifdim\tag@width\row@>\z@ |
| 5240 |
\x@calc@shift@rc |
| 5241 |
\else |
| 5242 |
\saveshift@0% |
| 5243 |
\fi |
| 5244 |
\advance\row@\m@ne |
| 5245 |
\repeat |
| 5246 |
\endgroup |
| 5247 |
} |
| 5248 |
% \end{macrocode} |
| 5249 |
% \end{macro} |
| 5250 |
% |
| 5251 |
% \begin{macro}{\x@calc@shift@rc} |
| 5252 |
% \begin{macrocode} |
| 5253 |
\def\x@calc@shift@rc{% |
| 5254 |
\column@\z@ |
| 5255 |
\@tempdimb\z@ |
| 5256 |
\@tempdimc\z@ |
| 5257 |
\edef\@tempb{\fieldlengths@\row@}% |
| 5258 |
\@for\@tempa:=\@tempb\do{% |
| 5259 |
\advance\column@\@ne |
| 5260 |
\x@rcalc@width |
| 5261 |
}% |
| 5262 |
\begingroup |
| 5263 |
\advance\column@\m@ne |
| 5264 |
\divide\column@\tw@ |
| 5265 |
\ifnum\@tempcntb>\column@ |
| 5266 |
\advance\@tempcnta-\@tempcntb |
| 5267 |
\advance\@tempcnta\column@ |
| 5268 |
\@tempcntb\column@ |
| 5269 |
\fi |
| 5270 |
\tagwidth@\tag@width\row@\relax |
| 5271 |
\@tempdima\@tempdimc |
| 5272 |
\advance\@tempdima\tagwidth@ |
| 5273 |
\dimen@\minalignsep\relax |
| 5274 |
\multiply\dimen@\@tempcntb |
| 5275 |
\advance\dimen@\mintagsep\relax |
| 5276 |
\ifnum\xatlevel@=\tw@ \else |
| 5277 |
\advance\dimen@\mintagsep\relax |
| 5278 |
\fi |
| 5279 |
\advance\dimen@\@tempdima |
| 5280 |
\ifdim\dimen@>\displaywidth |
| 5281 |
\saveshift@1% |
| 5282 |
\else |
| 5283 |
\saveshift@0% |
| 5284 |
\dimen@\eqnshift@ |
| 5285 |
\advance\dimen@\@tempdima |
| 5286 |
\advance\dimen@\@tempcntb\alignsep@ |
| 5287 |
\advance\dimen@\tagwidth@ |
| 5288 |
\ifdim\dimen@>\displaywidth |
| 5289 |
\dimen@\displaywidth |
| 5290 |
\advance\dimen@-\@tempdima |
| 5291 |
\ifnum\xatlevel@=\tw@ |
| 5292 |
\advance\dimen@-\mintagsep\relax |
| 5293 |
\fi |
| 5294 |
\divide\dimen@\@tempcnta |
| 5295 |
\ifdim\dimen@<\minalignsep\relax |
| 5296 |
\global\alignsep@\minalignsep\relax |
| 5297 |
\eqnshift@\displaywidth |
| 5298 |
\advance\eqnshift@-\@tempdima |
| 5299 |
\advance\eqnshift@-\@tempcntb\alignsep@ |
| 5300 |
\global\divide\eqnshift@\tw@ |
| 5301 |
\else |
| 5302 |
\ifdim\dimen@<\eqnshift@ |
| 5303 |
\ifdim\dimen@<\z@ |
| 5304 |
\global\eqnshift@\z@ |
| 5305 |
\else |
| 5306 |
\global\eqnshift@\dimen@ |
| 5307 |
\fi |
| 5308 |
\fi |
| 5309 |
\ifdim\dimen@<\alignsep@ |
| 5310 |
\global\alignsep@\dimen@ |
| 5311 |
\fi |
| 5312 |
\fi |
| 5313 |
\fi |
| 5314 |
\fi |
| 5315 |
\endgroup |
| 5316 |
} |
| 5317 |
\fi\fi |
| 5318 |
% \end{macrocode} |
| 5319 |
% \end{macro} |
| 5320 |
% |
| 5321 |
% \begin{macro}{\x@rcalc@width} |
| 5322 |
% \begin{macrocode} |
| 5323 |
\iftagsleft@\else |
| 5324 |
\def\x@rcalc@width{% |
| 5325 |
\ifdim\@tempa > \z@ |
| 5326 |
\advance\@tempdimc\@tempdimb |
| 5327 |
\ifodd\column@ |
| 5328 |
\advance\@tempdimc\maxcol@width\column@ |
| 5329 |
\@tempdimb\z@ |
| 5330 |
\else |
| 5331 |
\advance\@tempdimc\@tempa\relax |
| 5332 |
\@tempdimb\maxcol@width\column@ |
| 5333 |
\advance\@tempdimb-\@tempa\relax |
| 5334 |
\fi |
| 5335 |
\else |
| 5336 |
\advance\@tempdimb\maxcol@width\column@\relax |
| 5337 |
\fi |
| 5338 |
} |
| 5339 |
\fi |
| 5340 |
% \end{macrocode} |
| 5341 |
% \end{macro} |
| 5342 |
% |
| 5343 |
% \paragraph{Tag placement when \cs{tagsleft@true}, |
| 5344 |
% \cs{@fleqnfalse}.} |
| 5345 |
% |
| 5346 |
% \begin{macro}{\calc@shift@align} |
| 5347 |
% \begin{macrocode} |
| 5348 |
\iftagsleft@\if@fleqn\else |
| 5349 |
\def\calc@shift@align{% |
| 5350 |
\global\let\tag@shifts\@empty |
| 5351 |
\begingroup |
| 5352 |
\loop |
| 5353 |
\ifnum\row@>\z@ |
| 5354 |
\ifdim\tag@width\row@>\z@ |
| 5355 |
\x@calc@shift@lc |
| 5356 |
\else |
| 5357 |
\saveshift@0% |
| 5358 |
\fi |
| 5359 |
\advance\row@\m@ne |
| 5360 |
\repeat |
| 5361 |
\endgroup |
| 5362 |
} |
| 5363 |
% \end{macrocode} |
| 5364 |
% \end{macro} |
| 5365 |
% |
| 5366 |
% \begin{macro}{\x@calc@shift@lc} |
| 5367 |
% \begin{macrocode} |
| 5368 |
\def\x@calc@shift@lc{% |
| 5369 |
\column@\z@ |
| 5370 |
% \end{macrocode} |
| 5371 |
% \cs{@tempdima} will (eventually) be set to the effective width of |
| 5372 |
% the current row, defined as the distance from the leftmost point |
| 5373 |
% of the current line to the end of the last field of the |
| 5374 |
% \cs{halign}, ignoring any intervening \cs{tabskip}s, plus the |
| 5375 |
% width of the current tag. That is, it will be the width of the |
| 5376 |
% first non-empty field plus the sum of the maximum widths of all |
| 5377 |
% following fields, plus the tag width. |
| 5378 |
% |
| 5379 |
% \cs{@tempdimb} will be the ``indentation'' of leftmost end of |
| 5380 |
% text, ignoring the \cs{tabskip} glue, i.e., it will be the sum of |
| 5381 |
% the maximum widths of any fields to the left of the first |
| 5382 |
% non-empty field, plus whatever empty space there is at the |
| 5383 |
% beginning of the first non-empty field. |
| 5384 |
% \begin{macrocode} |
| 5385 |
\@tempdima\z@ % ``width of equation'' |
| 5386 |
\@tempdimb\z@ % ``indent of equation'' |
| 5387 |
\edef\@tempb{\fieldlengths@\row@}% |
| 5388 |
\@for\@tempa:=\@tempb\do{% |
| 5389 |
\advance\column@\@ne |
| 5390 |
\x@lcalc@width |
| 5391 |
}% |
| 5392 |
\begingroup |
| 5393 |
\tagwidth@\tag@width\row@\relax |
| 5394 |
% \end{macrocode} |
| 5395 |
% \cs{@tempdima} is now easy to calculate, since it is just |
| 5396 |
% $\cs{totwidth@} - \cs{@tempdimb} + \cs{tagwidth@}$. |
| 5397 |
% \begin{macrocode} |
| 5398 |
\@tempdima\totwidth@ |
| 5399 |
\advance\@tempdima-\@tempdimb |
| 5400 |
\advance\@tempdima\tagwidth@ |
| 5401 |
% \end{macrocode} |
| 5402 |
% Next, we check to see whether there is room for both the equation |
| 5403 |
% and the tag on the same line, by calculating the minimum |
| 5404 |
% acceptable length of the current row and comparing that to |
| 5405 |
% \cs{displaywidth}. Note that here we use \cs{@tempcntb}, i.e., |
| 5406 |
% the number of interalign spaces after the first non-empty align |
| 5407 |
% structure. |
| 5408 |
% \begin{macrocode} |
| 5409 |
\dimen@\minalignsep\relax |
| 5410 |
\multiply\dimen@\@tempcntb |
| 5411 |
\advance\dimen@\mintagsep\relax |
| 5412 |
\ifnum\xatlevel@=\tw@ \else |
| 5413 |
\advance\dimen@\mintagsep\relax |
| 5414 |
\fi |
| 5415 |
\advance\dimen@\@tempdima |
| 5416 |
% \end{macrocode} |
| 5417 |
% If the minimum acceptable width of the current line is greater |
| 5418 |
% than \cs{displaywidth}, we mark the current tag to be shifted to |
| 5419 |
% a separate line. |
| 5420 |
% \begin{macrocode} |
| 5421 |
\ifdim\dimen@>\displaywidth |
| 5422 |
\saveshift@1% |
| 5423 |
\else |
| 5424 |
% \end{macrocode} |
| 5425 |
% Otherwise, the tag can stay on the same line as the equation, but |
| 5426 |
% we need to check whether it is too close to the equation. So, we |
| 5427 |
% calculate the distance between the left margin and the left side |
| 5428 |
% of the equation, using the current values of \cs{eqnshift@} and |
| 5429 |
% \cs{alignsep@}. Note that we use \cs{count@} here, not |
| 5430 |
% \cs{@tempcntb}, as above. |
| 5431 |
% \begin{macrocode} |
| 5432 |
\saveshift@0% |
| 5433 |
\dimen@\alignsep@ |
| 5434 |
\multiply\dimen@\count@ |
| 5435 |
\advance\dimen@\eqnshift@ |
| 5436 |
\advance\dimen@\@tempdimb |
| 5437 |
% \end{macrocode} |
| 5438 |
% If the left margin is less than twice the tag width, we calculate |
| 5439 |
% new values of \cs{eqnshift@} and \cs{alignsep@} to move the |
| 5440 |
% equation further away from the tag. In particular, we center the |
| 5441 |
% current line between its tag and the right margin. Note that |
| 5442 |
% although we later will need to transform \cs{dimen@} into a value |
| 5443 |
% suitable for use as \cs{eqnshift@}, for the time being it is more |
| 5444 |
% useful to think of it as the space separating the tag from the |
| 5445 |
% equation. |
| 5446 |
% \begin{macrocode} |
| 5447 |
\ifdim\dimen@<2\tagwidth@ |
| 5448 |
\dimen@\displaywidth |
| 5449 |
\advance\dimen@-\@tempdima |
| 5450 |
\ifnum\xatlevel@=\tw@ |
| 5451 |
\advance\dimen@-\mintagsep\relax |
| 5452 |
\fi |
| 5453 |
% \end{macrocode} |
| 5454 |
% In certain circumstances we will get a divide-by-zero error here |
| 5455 |
% unless we guard against it. Use of \cs{@tempcnta} is complicated, |
| 5456 |
% sometimes it is assigned globally, sometimes locally. Need to sort |
| 5457 |
% it out one of these days [mjd,2000/06/02]. |
| 5458 |
% \begin{macrocode} |
| 5459 |
\ifnum\@tempcnta>\z@ |
| 5460 |
\divide\dimen@\@tempcnta |
| 5461 |
\else \dimen@\z@ |
| 5462 |
\fi |
| 5463 |
% \end{macrocode} |
| 5464 |
% As usual, we check to make sure we don't set \cs{alignsep@} |
| 5465 |
% smaller than \cs{minalignsep} and, in any case, that we don't |
| 5466 |
% replace \cs{alignsep@} by a larger value. |
| 5467 |
% \begin{macrocode} |
| 5468 |
\ifdim\dimen@<\minalignsep\relax |
| 5469 |
\global\alignsep@\minalignsep\relax |
| 5470 |
\dimen@\displaywidth |
| 5471 |
\advance\dimen@-\@tempdima |
| 5472 |
\advance\dimen@-\@tempcntb\alignsep@ |
| 5473 |
\global\divide\dimen@\tw@ |
| 5474 |
\else |
| 5475 |
\ifdim\dimen@<\alignsep@ |
| 5476 |
\global\alignsep@\dimen@ |
| 5477 |
\fi |
| 5478 |
\fi |
| 5479 |
% \end{macrocode} |
| 5480 |
% Next, we calculate an appropriate value of \cs{eqnshift@}, |
| 5481 |
% assuming that \cs{dimen@} is the desired separation between the |
| 5482 |
% tag and equation of the current line. This means that we first |
| 5483 |
% need to adjust \cs{dimen@} if we're in an \env{flalign} |
| 5484 |
% environment. |
| 5485 |
% \begin{macrocode} |
| 5486 |
\ifnum\xatlevel@=\tw@ |
| 5487 |
\dimen@\mintagsep\relax |
| 5488 |
\fi |
| 5489 |
% \end{macrocode} |
| 5490 |
% Now we calculate the value of \cs{eqnshift@} needed to produce a |
| 5491 |
% separation of \cs{dimen@} between the equation tag and the |
| 5492 |
% beginning of the equation. To do this, we need the following |
| 5493 |
% equation to hold: |
| 5494 |
% \[ |
| 5495 |
% \cs{eqnshift@} + n\cs{alignsep@} + \cs{@tempdimb} |
| 5496 |
% = \cs{tagwidth@} + \cs{dimen@} |
| 5497 |
% \] |
| 5498 |
% where $n = \cs{count@}$ is the number of interalign spaces before |
| 5499 |
% the first non-empty field of the current line. |
| 5500 |
% \begin{macrocode} |
| 5501 |
\advance\dimen@\tagwidth@ |
| 5502 |
\advance\dimen@-\@tempdimb |
| 5503 |
\advance\dimen@-\count@\alignsep@ |
| 5504 |
% \end{macrocode} |
| 5505 |
% The value of \cs{eqnshift@} just calculated is the minimum |
| 5506 |
% acceptable value; thus, we save it only if it is larger than the |
| 5507 |
% current value. |
| 5508 |
% \begin{macrocode} |
| 5509 |
\ifdim\dimen@>\eqnshift@ |
| 5510 |
\global\eqnshift@\dimen@ |
| 5511 |
\fi |
| 5512 |
\fi |
| 5513 |
\fi |
| 5514 |
\endgroup |
| 5515 |
} |
| 5516 |
% \end{macrocode} |
| 5517 |
% \end{macro} |
| 5518 |
% |
| 5519 |
% \begin{macro}{\x@lcalc@width} |
| 5520 |
% This macro calculates the ``indentation'' of the current row, as |
| 5521 |
% defined above under the description of \cs{x@calc@shift@lc}. |
| 5522 |
% This macro is called for each field of the current line, with |
| 5523 |
% \cs{@tempa} set to the width of the current field. Ideally, the |
| 5524 |
% loop enclosing \cs{x@lcalc@width} would terminate as soon as |
| 5525 |
% \cs{@tempa} is non-zero, but that would be a bit tricky to |
| 5526 |
% arrange. Instead, we use \cs{@tempdima} as a flag to signal when |
| 5527 |
% we've encountered the first non-empty field. |
| 5528 |
% |
| 5529 |
% \begin{macrocode} |
| 5530 |
\def\x@lcalc@width{% |
| 5531 |
\ifdim\@tempdima = \z@ |
| 5532 |
% \end{macrocode} |
| 5533 |
% If the current field is empty (i.e., $\cs{@tempa} = |
| 5534 |
% \mathrm{0\,pt}$, then we increment \cs{@tempdimb} by the width of |
| 5535 |
% the current field). Otherwise, we set $\cs{@tempdima} = |
| 5536 |
% \mathrm{1\,pt}$ as a signal value and increment \cs{@tempdimb} by |
| 5537 |
% the width of whatever empty space there might be at the left of |
| 5538 |
% the current field. |
| 5539 |
% \begin{macrocode} |
| 5540 |
\ifdim\@tempa > \z@ |
| 5541 |
\@tempdima\p@ |
| 5542 |
\ifodd\column@ |
| 5543 |
\advance\@tempdimb \maxcol@width\column@ |
| 5544 |
\advance\@tempdimb-\@tempa |
| 5545 |
\fi |
| 5546 |
% \end{macrocode} |
| 5547 |
% In addition, we need to adjust the values of \cs{@tempcnta} and |
| 5548 |
% \cs{@tempcntb} to account for any empty align structures that |
| 5549 |
% might occur at the beginning of the current line. More |
| 5550 |
% specifically, we first set \cs{count@} equal to the number of |
| 5551 |
% interalign spaces preceding the current field (namely, $\lfloor |
| 5552 |
% (\cs{column@}-1)/2 \rfloor$), and then subtract \cs{count@} from |
| 5553 |
% both \cs{@tempcnta} and \cs{@tempcntb}. The rationale is that |
| 5554 |
% for the purposes of adjusting the spacing between the tag and the |
| 5555 |
% equation, the only flexible interalign spaces are those after |
| 5556 |
% the first non-empty align structure, so we need to treat those |
| 5557 |
% different from the ones before the first non-empty align |
| 5558 |
% structure. |
| 5559 |
% \begin{macrocode} |
| 5560 |
\count@\column@ |
| 5561 |
\advance\count@\m@ne |
| 5562 |
\divide\count@\tw@ |
| 5563 |
\advance\@tempcnta-\count@ |
| 5564 |
\advance\@tempcntb-\count@ |
| 5565 |
\else |
| 5566 |
\advance\@tempdimb \maxcol@width\column@\relax |
| 5567 |
\fi |
| 5568 |
\fi |
| 5569 |
} |
| 5570 |
\fi\fi |
| 5571 |
% \end{macrocode} |
| 5572 |
% \end{macro} |
| 5573 |
% |
| 5574 |
% \begin{macro}{\place@tag} |
| 5575 |
% \cs{place@tag} takes care of the placement of tags in the |
| 5576 |
% \env{align} environments. |
| 5577 |
% \begin{macrocode} |
| 5578 |
\def\place@tag{% |
| 5579 |
\iftagsleft@ |
| 5580 |
\kern-\tagshift@ |
| 5581 |
\if1\shift@tag\row@\relax |
| 5582 |
\rlap{\vbox{% |
| 5583 |
\normalbaselines |
| 5584 |
\boxz@ |
| 5585 |
\vbox to\lineht@{}% |
| 5586 |
\raise@tag |
| 5587 |
}}% |
| 5588 |
\else |
| 5589 |
\rlap{\boxz@}% |
| 5590 |
\fi |
| 5591 |
\kern\displaywidth@ |
| 5592 |
\else |
| 5593 |
\kern-\tagshift@ |
| 5594 |
\if1\shift@tag\row@\relax |
| 5595 |
% \end{macrocode} |
| 5596 |
% Added depth to correct vertical spacing of shifted |
| 5597 |
% equation tags.---dmj, 1994/12/29 |
| 5598 |
% \begin{macrocode} |
| 5599 |
\llap{\vtop{% |
| 5600 |
\raise@tag |
| 5601 |
\normalbaselines |
| 5602 |
\setbox\@ne\null |
| 5603 |
\dp\@ne\lineht@ |
| 5604 |
\box\@ne |
| 5605 |
\boxz@ |
| 5606 |
}}% |
| 5607 |
\else |
| 5608 |
\llap{\boxz@}% |
| 5609 |
\fi |
| 5610 |
\fi |
| 5611 |
} |
| 5612 |
% \end{macrocode} |
| 5613 |
% \end{macro} |
| 5614 |
% |
| 5615 |
% \begin{macro}{\align@preamble} |
| 5616 |
% \begin{macrocode} |
| 5617 |
\def\align@preamble{% |
| 5618 |
&\hfil |
| 5619 |
\strut@ |
| 5620 |
\setboxz@h{\@lign$\m@th\displaystyle{##}$}% |
| 5621 |
\ifmeasuring@\savefieldlength@\fi |
| 5622 |
\set@field |
| 5623 |
\tabskip\z@skip |
| 5624 |
&\setboxz@h{\@lign$\m@th\displaystyle{{}##}$}% |
| 5625 |
\ifmeasuring@\savefieldlength@\fi |
| 5626 |
\set@field |
| 5627 |
\hfil |
| 5628 |
\tabskip\alignsep@ |
| 5629 |
} |
| 5630 |
% \end{macrocode} |
| 5631 |
% \end{macro} |
| 5632 |
% |
| 5633 |
% \begin{macro}{\set@field} |
| 5634 |
% \cs{set@field} increments the column counter, tracks the value of |
| 5635 |
% \cs{lineht@} and finally inserts the box containing the contents |
| 5636 |
% of the current field. |
| 5637 |
% \begin{macrocode} |
| 5638 |
\def\set@field{% |
| 5639 |
\column@plus |
| 5640 |
\iftagsleft@ |
| 5641 |
\ifdim\ht\z@>\lineht@ |
| 5642 |
\global\lineht@\ht\z@ |
| 5643 |
\fi |
| 5644 |
\else |
| 5645 |
\ifdim\dp\z@>\lineht@ |
| 5646 |
\global\lineht@\dp\z@ |
| 5647 |
\fi |
| 5648 |
\fi |
| 5649 |
\boxz@ |
| 5650 |
} |
| 5651 |
% \end{macrocode} |
| 5652 |
% \end{macro} |
| 5653 |
% |
| 5654 |
% |
| 5655 |
% \subsection {The \env{split} environment} |
| 5656 |
% |
| 5657 |
% \begin{macro}{\split@err} |
| 5658 |
% A special error function for \env{split} to conserve main mem (at a |
| 5659 |
% cost of string pool/hash size. |
| 5660 |
% \begin{macrocode} |
| 5661 |
\edef\split@err#1{% |
| 5662 |
\@nx\@amsmath@err{% |
| 5663 |
\string\begin{split} won't work here% |
| 5664 |
}{% |
| 5665 |
\@xp\@nx\csname |
| 5666 |
Did you forget a preceding \string\begin{equation}?^^J% |
| 5667 |
If not, perhaps the `aligned' environment is what |
| 5668 |
you want.\endcsname}% |
| 5669 |
} |
| 5670 |
% \end{macrocode} |
| 5671 |
% \end{macro} |
| 5672 |
% |
| 5673 |
% \begin{environment}{split} |
| 5674 |
% If the \env{split} environment occurs inside \env{align} or |
| 5675 |
% \env{gather}, it can make use of the enclosing halign; if it is |
| 5676 |
% called inside a simple equation, we add an implicit `gather' |
| 5677 |
% container. |
| 5678 |
% |
| 5679 |
% \begin{macrocode} |
| 5680 |
\newenvironment{split}{% |
| 5681 |
\if@display |
| 5682 |
\ifinner |
| 5683 |
\@xp\@xp\@xp\split@aligned |
| 5684 |
\else |
| 5685 |
\ifst@rred \else \global\@eqnswtrue \fi |
| 5686 |
\fi |
| 5687 |
\else \let\endsplit\@empty \@xp\collect@body\@xp\split@err |
| 5688 |
\fi |
| 5689 |
\collect@body\gather@split |
| 5690 |
}{% |
| 5691 |
\crcr |
| 5692 |
\egroup |
| 5693 |
\egroup |
| 5694 |
\iftagsleft@ \@xp\lendsplit@ \else \@xp\rendsplit@ \fi |
| 5695 |
} |
| 5696 |
% \end{macrocode} |
| 5697 |
% |
| 5698 |
% \begin{macrocode} |
| 5699 |
\let\split@tag\relax % init |
| 5700 |
% \end{macrocode} |
| 5701 |
% |
| 5702 |
% \begin{macrocode} |
| 5703 |
\def\gather@split#1#2#3{% |
| 5704 |
\@xp\endgroup \reset@equation % math@cr will handle equation numbering |
| 5705 |
\iftag@ |
| 5706 |
\toks@\@xp{\df@tag}% |
| 5707 |
\edef\split@tag{% |
| 5708 |
\gdef\@nx\df@tag{\the\toks@}% |
| 5709 |
\global\@nx\tag@true \@nx\nonumber |
| 5710 |
}% |
| 5711 |
\else \let\split@tag\@empty |
| 5712 |
\fi |
| 5713 |
\spread@equation |
| 5714 |
% \end{macrocode} |
| 5715 |
% The extra vcenter wrapper here is not really a good thing but |
| 5716 |
% without it there are compatibility problems with old documents that |
| 5717 |
% throw in some extra material between \verb'\begin{equation}' and |
| 5718 |
% \verb'\begin{split}' (for example, \verb'\hspace{-1pc}' or |
| 5719 |
% \verb'\left\{'). [mjd,1999/09/20] |
| 5720 |
% \begin{macrocode} |
| 5721 |
\vcenter\bgroup |
| 5722 |
\gather@{\split@tag \begin{split}#1\end{split}}% |
| 5723 |
\def\endmathdisplay@a{% |
| 5724 |
\math@cr \black@ \totwidth@ \egroup |
| 5725 |
\egroup |
| 5726 |
}% |
| 5727 |
} |
| 5728 |
% \end{macrocode} |
| 5729 |
% |
| 5730 |
% \end{environment} |
| 5731 |
% |
| 5732 |
% \begin{macro}{\insplit@} |
| 5733 |
% \begin{macrocode} |
| 5734 |
\def\insplit@{% |
| 5735 |
\global\setbox\z@\vbox\bgroup |
| 5736 |
\Let@ \chardef\dspbrk@context\@ne \restore@math@cr |
| 5737 |
\default@tag % disallow use of \tag here |
| 5738 |
\ialign\bgroup |
| 5739 |
\hfil |
| 5740 |
\strut@ |
| 5741 |
$\m@th\displaystyle{##}$% |
| 5742 |
&$\m@th\displaystyle{{}##}$% |
| 5743 |
\hfill % Why not \hfil?---dmj, 1994/12/28 |
| 5744 |
\crcr |
| 5745 |
} |
| 5746 |
% \end{macrocode} |
| 5747 |
% \end{macro} |
| 5748 |
% |
| 5749 |
% \begin{macro}{\rendsplit@} |
| 5750 |
% Moved the box maneuvers inside the \cs{ifinalign@}, since that is |
| 5751 |
% the only place they are needed.---dmj, 1994/12/28 |
| 5752 |
% |
| 5753 |
% TODO: Explore interaction of tag-placement algorithm with |
| 5754 |
% \env{split}. Is there any way for \env{split} to pass the |
| 5755 |
% relevant information out to the enclosing \env{gather} or |
| 5756 |
% \env{align}? |
| 5757 |
% \begin{macrocode} |
| 5758 |
\def\rendsplit@{% |
| 5759 |
\ifinalign@ |
| 5760 |
% \end{macrocode} |
| 5761 |
% Changed |\box9| into a \cs{vtop} here for better spacing. |
| 5762 |
% \begin{macrocode} |
| 5763 |
\global\setbox9 \vtop{% |
| 5764 |
\unvcopy\z@ |
| 5765 |
\global\setbox8 \lastbox |
| 5766 |
\unskip |
| 5767 |
}% |
| 5768 |
\setbox\@ne\hbox{% |
| 5769 |
\unhcopy8 |
| 5770 |
\unskip |
| 5771 |
\global\setbox\tw@\lastbox |
| 5772 |
\unskip |
| 5773 |
\global\setbox\thr@@\lastbox |
| 5774 |
}% |
| 5775 |
\ifctagsplit@ |
| 5776 |
\gdef\split@{% |
| 5777 |
\hbox to\wd\thr@@{}% |
| 5778 |
&\vcenter{\vbox{\moveleft\wd\thr@@\boxz@}}% |
| 5779 |
}% |
| 5780 |
\else |
| 5781 |
\global\setbox7 \hbox{\unhbox\tw@\unskip}% |
| 5782 |
% \end{macrocode} |
| 5783 |
% Added \cs{add@amps} to make sure we put the last line of the |
| 5784 |
% \env{split} into the proper column of an \env{align} environment |
| 5785 |
% with multiple align structures.---dmj, 1994/12/28 |
| 5786 |
% |
| 5787 |
% Special care has to be taken in this case because the \env{split} |
| 5788 |
% turns into two lines of the \env{align} instead of just one. So, |
| 5789 |
% we have to make sure that the first line produced by the |
| 5790 |
% \env{split} doesn't upset our bookkeeping, hence we call |
| 5791 |
% \cs{savetaglength@} to insert 0\,pt as the tag for this |
| 5792 |
% pseudo-line, and we advance the \cs{row@} counter and reset |
| 5793 |
% \cs{lineht@} afterwards. It would be nice if we could just |
| 5794 |
% replace the \cs{crcr} by \cs{math@cr@@@}, but that would cause |
| 5795 |
% problems with the tag processing. |
| 5796 |
% \begin{macrocode} |
| 5797 |
\gdef\split@{% |
| 5798 |
\global\@tempcnta\column@ |
| 5799 |
&\setboxz@h{}% |
| 5800 |
\savetaglength@ |
| 5801 |
\global\advance\row@\@ne |
| 5802 |
\vbox{\moveleft\wd\thr@@\box9}% |
| 5803 |
\crcr |
| 5804 |
\noalign{\global\lineht@\z@}% |
| 5805 |
\add@amps\@tempcnta |
| 5806 |
\box\thr@@ |
| 5807 |
&\box7 |
| 5808 |
}% |
| 5809 |
\fi |
| 5810 |
\else |
| 5811 |
\ifctagsplit@ |
| 5812 |
\gdef\split@{\vcenter{\boxz@}}% |
| 5813 |
\else |
| 5814 |
% \end{macrocode} |
| 5815 |
% Changed to just \cs{boxz@}, otherwise last line gets centered |
| 5816 |
% rather than aligned properly with respect to the rest of the |
| 5817 |
% lines. But this means that we can't see inside of the last line |
| 5818 |
% to decide whether the tag needs to be moved. Will have to think |
| 5819 |
% about this.---dmj, 1994/12/28 |
| 5820 |
% \begin{macrocode} |
| 5821 |
\gdef\split@{% |
| 5822 |
\boxz@ |
| 5823 |
% \box9 |
| 5824 |
% \crcr |
| 5825 |
% \hbox{\box\thr@@\box7}% |
| 5826 |
}% |
| 5827 |
\fi |
| 5828 |
\fi |
| 5829 |
\aftergroup\split@ |
| 5830 |
} |
| 5831 |
% \end{macrocode} |
| 5832 |
% \end{macro} |
| 5833 |
% |
| 5834 |
% \begin{macro}{\lendsplit@} |
| 5835 |
% \begin{macrocode} |
| 5836 |
\def\lendsplit@{% |
| 5837 |
\global\setbox9\vtop{\unvcopy\z@}% |
| 5838 |
\ifinalign@ |
| 5839 |
% \end{macrocode} |
| 5840 |
% Moved following two boxes inside the \cs{ifinalign@}, since they |
| 5841 |
% are only used in that case. In fact, if we just kept track of |
| 5842 |
% the width of the first column, we could dispense with this |
| 5843 |
% entirely. Surely that would be more efficient than all these box |
| 5844 |
% copies.---dmj, 1994/12/28 |
| 5845 |
% \begin{macrocode} |
| 5846 |
\setbox\@ne\vbox{% |
| 5847 |
\unvcopy\z@ |
| 5848 |
\global\setbox8\lastbox |
| 5849 |
}% |
| 5850 |
\setbox\@ne\hbox{% |
| 5851 |
\unhcopy8% |
| 5852 |
\unskip |
| 5853 |
\setbox\tw@\lastbox |
| 5854 |
\unskip |
| 5855 |
\global\setbox\thr@@\lastbox |
| 5856 |
}% |
| 5857 |
\ifctagsplit@ |
| 5858 |
\gdef\split@{% |
| 5859 |
\hbox to\wd\thr@@{}% |
| 5860 |
&\vcenter{\vbox{\moveleft\wd\thr@@\box9}}% |
| 5861 |
}% |
| 5862 |
\else |
| 5863 |
\gdef\split@{% |
| 5864 |
\hbox to\wd\thr@@{}% |
| 5865 |
&\vbox{\moveleft\wd\thr@@\box9}% |
| 5866 |
}% |
| 5867 |
\fi |
| 5868 |
\else |
| 5869 |
\ifctagsplit@ |
| 5870 |
\gdef\split@{\vcenter{\box9}}% |
| 5871 |
\else |
| 5872 |
\gdef\split@{\box9}% |
| 5873 |
\fi |
| 5874 |
\fi |
| 5875 |
\aftergroup\split@ |
| 5876 |
} |
| 5877 |
% \end{macrocode} |
| 5878 |
% \end{macro} |
| 5879 |
% |
| 5880 |
% With \pkg{amsmath} 1.2 it was possible to put things like |
| 5881 |
% \verb'\left\{' between \verb'\begin{equation}' and |
| 5882 |
% \verb'\begin{split}' without getting any error message. For |
| 5883 |
% backward compatibility we try to avoid a fatal error in this case |
| 5884 |
% and instead attempt recovery with \env{aligned}. |
| 5885 |
% \begin{macrocode} |
| 5886 |
\def\split@aligned#1#2{% |
| 5887 |
\iffalse{\fi\ifnum0=`}\fi |
| 5888 |
\collect@body\split@al@a} |
| 5889 |
% \end{macrocode} |
| 5890 |
% |
| 5891 |
% \begin{macrocode} |
| 5892 |
\def\split@al@a#1#2#3{% |
| 5893 |
\split@warning |
| 5894 |
\endgroup |
| 5895 |
% \end{macrocode} |
| 5896 |
% If the \opt{fleqn} and \opt{tbtags} options are both in effect then |
| 5897 |
% we will need to add an optional argument on the \env{aligned} |
| 5898 |
% environment. |
| 5899 |
% \begin{macrocode} |
| 5900 |
\toks@{\begin{aligned}}% |
| 5901 |
\if@fleqn \split@al@tagcheck \fi |
| 5902 |
% \end{macrocode} |
| 5903 |
% The \cs{relax} here is to prevent \cs{@let@token} from being left |
| 5904 |
% equal to an ampersand if that happens to be the first thing in the body. |
| 5905 |
% \begin{macrocode} |
| 5906 |
\the\toks@\relax#1\end{aligned}% |
| 5907 |
\ifnum0=`{\fi\iffalse}\fi |
| 5908 |
} |
| 5909 |
% \end{macrocode} |
| 5910 |
% |
| 5911 |
% \begin{macrocode} |
| 5912 |
\def\split@al@tagcheck{% |
| 5913 |
\ifctagsplit@ |
| 5914 |
\else |
| 5915 |
\iftagsleft@ \toks@\@xp{\the\toks@ [t]}% |
| 5916 |
\else \toks@\@xp{\the\toks@ [b]}% |
| 5917 |
\fi |
| 5918 |
\fi |
| 5919 |
} |
| 5920 |
% \end{macrocode} |
| 5921 |
% |
| 5922 |
% \begin{macrocode} |
| 5923 |
\def\split@warning{% |
| 5924 |
\PackageWarning{amsmath}{% |
| 5925 |
Cannot use `split' here;\MessageBreak trying to recover with `aligned'}% |
| 5926 |
} |
| 5927 |
% \end{macrocode} |
| 5928 |
% |
| 5929 |
% \subsection{The \env{multline} environment} |
| 5930 |
% |
| 5931 |
% In the original \amstex/, \cn{multlinegap} is a macro with an |
| 5932 |
% argument that resets an internal dimension (one with an \qc{\@} |
| 5933 |
% character in its name). Here, to save control sequence names, we |
| 5934 |
% define \cn{multlinegap} to be the dimension itself and the |
| 5935 |
% documentation instructs users to use \cn{setlength} if they |
| 5936 |
% need to change it. |
| 5937 |
% \begin{macro}{\multlinegap} |
| 5938 |
% \begin{macro}{\multlinetaggap} |
| 5939 |
% Changed \cs{multlinegap} and \cs{multlinetaggap} to skip |
| 5940 |
% registers. Also changed name to \cs{multlinetaggap} from |
| 5941 |
% \cs{multlinetaggap@}. |
| 5942 |
% \begin{macrocode} |
| 5943 |
\newskip\multlinegap |
| 5944 |
\multlinegap10pt |
| 5945 |
\newskip\multlinetaggap |
| 5946 |
\multlinetaggap10pt |
| 5947 |
% \end{macrocode} |
| 5948 |
% \end{macro} |
| 5949 |
% \end{macro} |
| 5950 |
% |
| 5951 |
% \begin{macro}{\start@multline} |
| 5952 |
% \changes{v2.17w}{2025/03/08}{Use \cs{dollardollar@begin} and |
| 5953 |
% \cs{dollardollar@end} instead of \texttt{\$\$} for tagging support} |
| 5954 |
% \begin{macrocode} |
| 5955 |
\def\start@multline#1{% |
| 5956 |
\RIfM@ |
| 5957 |
\nomath@env |
| 5958 |
\DN@{\@namedef{end\@currenvir}{}\@gobble}% |
| 5959 |
\else |
| 5960 |
\dollardollar@begin |
| 5961 |
#1% |
| 5962 |
\ifst@rred |
| 5963 |
\nonumber |
| 5964 |
\else |
| 5965 |
\global\@eqnswtrue |
| 5966 |
\fi |
| 5967 |
\let\next@\multline@ |
| 5968 |
\fi |
| 5969 |
\collect@body\next@ |
| 5970 |
} |
| 5971 |
% \end{macrocode} |
| 5972 |
% \end{macro} |
| 5973 |
% |
| 5974 |
% \begin{environment}{multline} |
| 5975 |
% \begin{environment}{multline*} |
| 5976 |
% \begin{macrocode} |
| 5977 |
\newenvironment{multline}{% |
| 5978 |
\start@multline\st@rredfalse |
| 5979 |
}{% |
| 5980 |
\iftagsleft@ \@xp\lendmultline@ \else \@xp\rendmultline@ \fi |
| 5981 |
\ignorespacesafterend |
| 5982 |
} |
| 5983 |
% \end{macrocode} |
| 5984 |
% |
| 5985 |
% \begin{macrocode} |
| 5986 |
\newenvironment{multline*}{\start@multline\st@rredtrue}{\endmultline} |
| 5987 |
% \end{macrocode} |
| 5988 |
% \end{environment} |
| 5989 |
% \end{environment} |
| 5990 |
% |
| 5991 |
% \begin{macro}{\multline@} |
| 5992 |
% \begin{macrocode} |
| 5993 |
\def\multline@#1{% |
| 5994 |
\Let@ |
| 5995 |
% \end{macrocode} |
| 5996 |
% |
| 5997 |
% For multline neither \cs{displ@y} no \cs{displ@y@} is quite right; |
| 5998 |
% we want to advance the row number and (I suppose?) the |
| 5999 |
% display-pagebreak level, but we only want to do tag-related stuff |
| 6000 |
% once before the first line, not repeat it for every line. (Recall |
| 6001 |
% that the arg of \cs{@display@init} goes into \cs{everycr}.) |
| 6002 |
% \begin{macrocode} |
| 6003 |
\@display@init{\global\advance\row@\@ne \global\dspbrk@lvl\m@ne}% |
| 6004 |
\chardef\dspbrk@context\z@ |
| 6005 |
\restore@math@cr |
| 6006 |
% \end{macrocode} |
| 6007 |
% The \env{multline} environment is somewhat unusual, in that |
| 6008 |
% \cs{tag} and \cs{label} are enabled only during the measuring |
| 6009 |
% phase and disabled during the production phase. |
| 6010 |
% Here we disable \cs{tag} and \cs{label}; \cs{mmeasure@} will |
| 6011 |
% re-enable them temporarily. |
| 6012 |
% \begin{macrocode} |
| 6013 |
\let\tag\tag@in@align |
| 6014 |
\global\tag@false \global\let\raise@tag\@empty |
| 6015 |
\mmeasure@{#1}% |
| 6016 |
\let\tag\gobble@tag \let\label\@gobble |
| 6017 |
\tabskip \if@fleqn \@mathmargin \else \z@skip \fi |
| 6018 |
\totwidth@\displaywidth |
| 6019 |
\if@fleqn |
| 6020 |
\advance\totwidth@-\@mathmargin |
| 6021 |
\fi |
| 6022 |
\halign\bgroup |
| 6023 |
\hbox to\totwidth@{% |
| 6024 |
% \end{macrocode} |
| 6025 |
% In order to get the spacing of the last line right in fleqn |
| 6026 |
% mode, we need to play a little game here. Normally the |
| 6027 |
% stretchability of the \cs{hskip} here will be suppressed by the |
| 6028 |
% \cs{hfil} at the end of the template, except inside the last line, |
| 6029 |
% when that \cs{hfil} will be removed by the \cs{hfilneg} in |
| 6030 |
% \cs{lendmultline@}. |
| 6031 |
% \begin{macrocode} |
| 6032 |
\if@fleqn |
| 6033 |
\hskip \@centering \relax |
| 6034 |
\else |
| 6035 |
\hfil |
| 6036 |
\fi |
| 6037 |
\strut@ |
| 6038 |
$\m@th\displaystyle{}##\endmultline@math |
| 6039 |
\hfil |
| 6040 |
}% |
| 6041 |
\crcr |
| 6042 |
% \end{macrocode} |
| 6043 |
% In \opt{fleqn} mode, it's the \cs{tabskip} of \cs{@mathmargin} |
| 6044 |
% that needs to be removed in the first line, not the \cs{hfil} at |
| 6045 |
% the beginning of the template. |
| 6046 |
% \begin{macrocode} |
| 6047 |
\if@fleqn |
| 6048 |
\hskip-\@mathmargin |
| 6049 |
\def\multline@indent{\hskip\@mathmargin}% put it back |
| 6050 |
\else |
| 6051 |
\hfilneg |
| 6052 |
\def\multline@indent{\hskip\multlinegap}% |
| 6053 |
\fi |
| 6054 |
\iftagsleft@ |
| 6055 |
\iftag@ |
| 6056 |
\begingroup |
| 6057 |
\ifshifttag@ |
| 6058 |
\rlap{\vbox{% |
| 6059 |
\normalbaselines |
| 6060 |
\hbox{% |
| 6061 |
\strut@ |
| 6062 |
\make@display@tag |
| 6063 |
}% |
| 6064 |
\vbox to\lineht@{}% |
| 6065 |
\raise@tag |
| 6066 |
}}% |
| 6067 |
% \end{macrocode} |
| 6068 |
% If the equation tag doesn't fit on the same line with the first |
| 6069 |
% line of the display, we'll indent the first line by |
| 6070 |
% \cn{multlinegap}. This is a change from \pkg{amstex}, where the |
| 6071 |
% first line would have been flush against the left margin in this |
| 6072 |
% case. A corresponding change will be made in \cs{rendmultline@}. |
| 6073 |
% \begin{macrocode} |
| 6074 |
\multline@indent |
| 6075 |
\else |
| 6076 |
\setbox\z@\hbox{\make@display@tag}% |
| 6077 |
\dimen@\@mathmargin \advance\dimen@-\wd\z@ |
| 6078 |
\ifdim\dimen@<\multlinetaggap |
| 6079 |
\dimen@\multlinetaggap |
| 6080 |
\fi |
| 6081 |
\box\z@ \hskip\dimen@\relax |
| 6082 |
\fi |
| 6083 |
\endgroup |
| 6084 |
\else |
| 6085 |
\multline@indent |
| 6086 |
\fi |
| 6087 |
\else |
| 6088 |
\multline@indent |
| 6089 |
\fi |
| 6090 |
#1% |
| 6091 |
} |
| 6092 |
% \end{macrocode} |
| 6093 |
% |
| 6094 |
% An extra level of indirection for the closing \verb'$' in multline |
| 6095 |
% allows us to avoid getting an extra thinmuskip from a final |
| 6096 |
% mathpunct in the equation contents, when equation numbers are on |
| 6097 |
% the right. If we did not use this workaround, the sequence of |
| 6098 |
% elements for a final comma would be, e.g., |
| 6099 |
% \begin{verbatim} |
| 6100 |
% ... ,<hskip><box containing equation number> |
| 6101 |
% \end{verbatim} |
| 6102 |
% which is equivalent to a sequence \verb'<mathpunct><mathord>' as |
| 6103 |
% far as the automatic math spacing is concerned. |
| 6104 |
% \begin{macrocode} |
| 6105 |
\def\endmultline@math{$} |
| 6106 |
% \end{macrocode} |
| 6107 |
% \end{macro} |
| 6108 |
% |
| 6109 |
% \begin{macro}{\lendmultline@} |
| 6110 |
% Bug fix: changed \cs{crcr} to \cs{math@cr} so that \cs{@eqpen} |
| 6111 |
% gets reset properly if \cs{displaybreak} is used on the |
| 6112 |
% penultimate line of an \env{align}. |
| 6113 |
% \changes{v2.17w}{2025/03/08}{Use \cs{dollardollar@begin} and |
| 6114 |
% \cs{dollardollar@end} instead of \texttt{\$\$} for tagging support} |
| 6115 |
% \begin{macrocode} |
| 6116 |
\def\lendmultline@{% |
| 6117 |
\hfilneg |
| 6118 |
\hskip\multlinegap |
| 6119 |
\math@cr |
| 6120 |
\egroup |
| 6121 |
\dollardollar@end |
| 6122 |
} |
| 6123 |
% \end{macrocode} |
| 6124 |
% \end{macro} |
| 6125 |
% |
| 6126 |
% \begin{macro}{\rendmultline@} |
| 6127 |
% \begin{macrocode} |
| 6128 |
\def\rendmultline@{% |
| 6129 |
\iftag@ |
| 6130 |
$\let\endmultline@math\relax |
| 6131 |
\ifshifttag@ |
| 6132 |
\hskip\multlinegap |
| 6133 |
% \end{macrocode} |
| 6134 |
% Added depth to correct vertical spacing of shifted equation |
| 6135 |
% tags.---dmj, 1994/12/29 |
| 6136 |
% \begin{macrocode} |
| 6137 |
\llap{\vtop{% |
| 6138 |
\raise@tag |
| 6139 |
\normalbaselines |
| 6140 |
\setbox\@ne\null |
| 6141 |
\dp\@ne\lineht@ |
| 6142 |
\box\@ne |
| 6143 |
\hbox{\strut@\make@display@tag}% |
| 6144 |
}}% |
| 6145 |
\else |
| 6146 |
\hskip\multlinetaggap |
| 6147 |
\make@display@tag |
| 6148 |
\fi |
| 6149 |
\else |
| 6150 |
\hskip\multlinegap |
| 6151 |
\fi |
| 6152 |
\hfilneg |
| 6153 |
% \end{macrocode} |
| 6154 |
% Use \cs{math@cr} rather than just \cs{crcr} so that \cs{@eqpen} |
| 6155 |
% gets reset properly if \cs{displaybreak} is used. |
| 6156 |
% \changes{v2.17w}{2025/03/08}{Use \cs{dollardollar@begin} and |
| 6157 |
% \cs{dollardollar@end} instead of \texttt{\$\$} for tagging support} |
| 6158 |
% \begin{macrocode} |
| 6159 |
\math@cr |
| 6160 |
\egroup\dollardollar@end |
| 6161 |
} |
| 6162 |
% \end{macrocode} |
| 6163 |
% \end{macro} |
| 6164 |
% |
| 6165 |
% \begin{macro}{\mmeasure@} |
| 6166 |
% \begin{macrocode} |
| 6167 |
\def\mmeasure@#1{% |
| 6168 |
\begingroup |
| 6169 |
\measuring@true |
| 6170 |
% \end{macrocode} |
| 6171 |
% We use \cs{begin/endgroup} rather than |{}| in this definition of |
| 6172 |
% \cn{label} because the latter would create an extra (wasteful of |
| 6173 |
% main mem) null box in the current math list. [mjd, 1995/01/17] |
| 6174 |
% \begin{macrocode} |
| 6175 |
\def\label##1{% |
| 6176 |
\begingroup\measuring@false\label@in@display{##1}\endgroup}% |
| 6177 |
\def\math@cr@@@{\cr}% |
| 6178 |
\let\shoveleft\@iden \let\shoveright\@iden |
| 6179 |
\savecounters@ |
| 6180 |
\global\row@\z@ |
| 6181 |
\setbox\@ne\vbox{% |
| 6182 |
\global\let\df@tag\@empty |
| 6183 |
\halign{% |
| 6184 |
\setboxz@h{\@lign$\m@th\displaystyle{}##$}% |
| 6185 |
\iftagsleft@ |
| 6186 |
\ifnum\row@=\@ne |
| 6187 |
\global\totwidth@\wdz@ |
| 6188 |
\global\lineht@\ht\z@ |
| 6189 |
\fi |
| 6190 |
\else |
| 6191 |
\global\totwidth@\wdz@ |
| 6192 |
\global\lineht@\dp\z@ |
| 6193 |
\fi |
| 6194 |
\crcr |
| 6195 |
#1% |
| 6196 |
\crcr |
| 6197 |
}% |
| 6198 |
}% |
| 6199 |
\ifx\df@tag\@empty\else\global\tag@true\fi |
| 6200 |
\if@eqnsw\global\tag@true\fi |
| 6201 |
\iftag@ |
| 6202 |
\setboxz@h{% |
| 6203 |
\if@eqnsw |
| 6204 |
\stepcounter{equation}% |
| 6205 |
\tagform@\theequation |
| 6206 |
\else |
| 6207 |
\df@tag |
| 6208 |
\fi |
| 6209 |
}% |
| 6210 |
\global\tagwidth@\wdz@ |
| 6211 |
\dimen@\totwidth@ |
| 6212 |
\advance\dimen@\tagwidth@ |
| 6213 |
\advance\dimen@\multlinetaggap |
| 6214 |
\iftagsleft@\else |
| 6215 |
\if@fleqn |
| 6216 |
\advance\dimen@\@mathmargin |
| 6217 |
\fi |
| 6218 |
\fi |
| 6219 |
\ifdim\dimen@>\displaywidth |
| 6220 |
\global\shifttag@true |
| 6221 |
\else |
| 6222 |
\global\shifttag@false |
| 6223 |
\fi |
| 6224 |
\fi |
| 6225 |
\restorecounters@ |
| 6226 |
\endgroup |
| 6227 |
} |
| 6228 |
% \end{macrocode} |
| 6229 |
% \end{macro} |
| 6230 |
% |
| 6231 |
% \begin{macro}{\shoveleft} |
| 6232 |
% \begin{macro}{\shoveright} |
| 6233 |
% \cs{shoveleft} and \cs{shoveright} need to do slightly different |
| 6234 |
% things depending on whether tags are on the left or the right and |
| 6235 |
% whether we're in \opt{fleqn} mode. For compactness of code, we |
| 6236 |
% make the appropriate decisions at ``compile'' time rather than at |
| 6237 |
% load time. |
| 6238 |
% |
| 6239 |
% TODO: Investigate making \cs{shoveright} behave ``properly''(?) if |
| 6240 |
% used on the first line of a \env{multline} and make \cs{shoveleft} |
| 6241 |
% behave properly if used on the last line of a \env{multline}. But |
| 6242 |
% in his \fn{amstex.doc} Spivak indicates those commands should never |
| 6243 |
% be used on a first or last line. Perhaps better to leave the |
| 6244 |
% question open unless/until real-life examples turn up. |
| 6245 |
% \changes{v2.17m}{2022/02/03}{Make \cs{shoveright} robust (if def is not trivial)} |
| 6246 |
% \begin{macrocode} |
| 6247 |
\iftagsleft@ |
| 6248 |
\protected\def\shoveright#1{% |
| 6249 |
#1% |
| 6250 |
\hfilneg |
| 6251 |
\hskip\multlinegap |
| 6252 |
} |
| 6253 |
\else |
| 6254 |
\protected\def\shoveright#1{% |
| 6255 |
#1% |
| 6256 |
\hfilneg |
| 6257 |
\iftag@ |
| 6258 |
\ifshifttag@ |
| 6259 |
\hskip\multlinegap |
| 6260 |
\else |
| 6261 |
\hskip\tagwidth@ |
| 6262 |
\hskip\multlinetaggap |
| 6263 |
\fi |
| 6264 |
\else |
| 6265 |
\hskip\multlinegap |
| 6266 |
\fi |
| 6267 |
} |
| 6268 |
\fi |
| 6269 |
% \end{macrocode} |
| 6270 |
% \changes{v2.17m}{2022/02/03}{Make \cs{shoveleft} robust (if def is not trivial)} |
| 6271 |
% \begin{macrocode} |
| 6272 |
\if@fleqn |
| 6273 |
\def\shoveleft#1{#1}% |
| 6274 |
\else |
| 6275 |
\iftagsleft@ |
| 6276 |
\protected\def\shoveleft#1{% |
| 6277 |
\setboxz@h{$\m@th\displaystyle{}#1$}% |
| 6278 |
\setbox\@ne\hbox{$\m@th\displaystyle#1$}% |
| 6279 |
\hfilneg |
| 6280 |
\iftag@ |
| 6281 |
\ifshifttag@ |
| 6282 |
\hskip\multlinegap |
| 6283 |
\else |
| 6284 |
\hskip\tagwidth@ |
| 6285 |
\hskip\multlinetaggap |
| 6286 |
\fi |
| 6287 |
\else |
| 6288 |
\hskip\multlinegap |
| 6289 |
\fi |
| 6290 |
\hskip.5\wd\@ne |
| 6291 |
% \end{macrocode} |
| 6292 |
% \changes{v2.17m}{2022/02/03}{Added missing \cs{relax} for (gh/716)} |
| 6293 |
% \begin{macrocode} |
| 6294 |
\hskip-.5\wdz@ \relax |
| 6295 |
#1% |
| 6296 |
} |
| 6297 |
\else |
| 6298 |
\protected\def\shoveleft#1{% |
| 6299 |
\setboxz@h{$\m@th\displaystyle{}#1$}% |
| 6300 |
\setbox\@ne\hbox{$\m@th\displaystyle#1$}% |
| 6301 |
\hfilneg |
| 6302 |
\hskip\multlinegap |
| 6303 |
\hskip.5\wd\@ne |
| 6304 |
% \end{macrocode} |
| 6305 |
% \changes{v2.17m}{2022/02/03}{Added missing \cs{relax} for (gh/716)} |
| 6306 |
% \begin{macrocode} |
| 6307 |
\hskip-.5\wdz@ \relax |
| 6308 |
#1% |
| 6309 |
} |
| 6310 |
\fi |
| 6311 |
\fi |
| 6312 |
% \end{macrocode} |
| 6313 |
% \end{macro} |
| 6314 |
% \end{macro} |
| 6315 |
% |
| 6316 |
% \subsection{The \env{equation} environment} |
| 6317 |
% |
| 6318 |
% Rewritten from the ground up for version 2.0 to fix no-shrink and |
| 6319 |
% no-shortskips bugs [mjd,2000/01/06]. |
| 6320 |
% |
| 6321 |
% Standard \latex/ provides three environments for one-line equations: |
| 6322 |
% \cn{[}\cn{]}, \env{equation}, and \env{displaymath}. We add |
| 6323 |
% \env{equation*} as a synonym for \env{displaymath}. |
| 6324 |
% \changes{v2.17o}{2023/05/13}{Do not error if \cs{eqno} not primitive (gh/1059)} |
| 6325 |
% \begin{macrocode} |
| 6326 |
\let\@@eqno\eqno |
| 6327 |
\let\@@leqno\leqno |
| 6328 |
\def\eqno{\@@eqno\let\eqno\relax\let\leqno\relax} |
| 6329 |
\def\leqno{\@@leqno\let\leqno\relax\let\eqno\relax} |
| 6330 |
% |
| 6331 |
\let\veqno=\@@eqno |
| 6332 |
\iftagsleft@ \let\veqno=\@@leqno \fi |
| 6333 |
% \end{macrocode} |
| 6334 |
% |
| 6335 |
% Support for the \pkg{showkeys} package: provide no-op definitions |
| 6336 |
% for a couple of SK functions, if they are not already defined. Then |
| 6337 |
% we can just call them directly in our code without any extra fuss. |
| 6338 |
% If the \pkg{showkeys} package is loaded later, our trivial |
| 6339 |
% definitions will get overridden and everything works fine. |
| 6340 |
% \begin{macrocode} |
| 6341 |
\@ifundefined{SK@@label}{% |
| 6342 |
\let\SK@@label\relax \let\SK@equationtrue\relax |
| 6343 |
}{} |
| 6344 |
% \end{macrocode} |
| 6345 |
% |
| 6346 |
% \begin{macrocode} |
| 6347 |
\let\reset@equation\@empty |
| 6348 |
% \end{macrocode} |
| 6349 |
% |
| 6350 |
% Cf \cs{tag@in@align}. This is a bit of a mess though. Could use |
| 6351 |
% some work. [mjd,1999/12/21] |
| 6352 |
% \begin{macrocode} |
| 6353 |
\let\alt@tag\@empty |
| 6354 |
\def\tag@in@display#1#{\relax\tag@in@display@a{#1}} |
| 6355 |
\def\tag@in@display@a#1#2{% |
| 6356 |
\iftag@ |
| 6357 |
\invalid@tag{Multiple \string\tag}\relax |
| 6358 |
\else |
| 6359 |
\global\tag@true \nonumber \reset@equation \st@rredtrue |
| 6360 |
\if *\string#1% |
| 6361 |
\gdef\alt@tag{\def\SK@tagform@{#2\@gobble}% |
| 6362 |
\ifx\SK@@label\relax \let\tagform@\SK@tagform@ \fi |
| 6363 |
}% |
| 6364 |
\make@df@tag@@{#2}% |
| 6365 |
\else |
| 6366 |
\make@df@tag@@@{#2}% |
| 6367 |
\fi |
| 6368 |
\fi |
| 6369 |
} |
| 6370 |
% \end{macrocode} |
| 6371 |
% |
| 6372 |
% \begin{macrocode} |
| 6373 |
\let\restore@hfuzz\@empty |
| 6374 |
% \end{macrocode} |
| 6375 |
% |
| 6376 |
% \changes{v2.17w}{2025/03/08}{Use \cs{dollardollar@begin} and |
| 6377 |
% \cs{dollardollar@end} instead of \texttt{\$\$} for tagging support} |
| 6378 |
% \begin{macrocode} |
| 6379 |
\def\mathdisplay#1{% |
| 6380 |
\ifmmode \@badmath |
| 6381 |
\else |
| 6382 |
\dollardollar@begin\def\@currenvir{#1}% |
| 6383 |
% \end{macrocode} |
| 6384 |
% Allow use of \cn{displaybreak}. |
| 6385 |
% \begin{macrocode} |
| 6386 |
\let\dspbrk@context\z@ |
| 6387 |
% \end{macrocode} |
| 6388 |
% Although in some cases simpler label handling would seem to be |
| 6389 |
% sufficient, always using \cs{label@in@display} makes it easier to |
| 6390 |
% support the \pkg{showkeys} package. |
| 6391 |
% \begin{macrocode} |
| 6392 |
\let\tag\tag@in@display \let\label\label@in@display \SK@equationtrue |
| 6393 |
\global\let\df@label\@empty \global\let\df@tag\@empty |
| 6394 |
\global\tag@false |
| 6395 |
\let\mathdisplay@push\mathdisplay@@push |
| 6396 |
\let\mathdisplay@pop\mathdisplay@@pop |
| 6397 |
\if@fleqn |
| 6398 |
% \end{macrocode} |
| 6399 |
% Turn off overfull box messages temporarily\mdash otherwise there |
| 6400 |
% would be unwanted extra ones emitted during our measuring |
| 6401 |
% operations. |
| 6402 |
% \begin{macrocode} |
| 6403 |
\edef\restore@hfuzz{\hfuzz\the\hfuzz\relax}% |
| 6404 |
\hfuzz\maxdimen |
| 6405 |
% \end{macrocode} |
| 6406 |
% Initially set the equation body in a box of displaywidth. Then if |
| 6407 |
% the box is not overfull, as we find by checking \cs{badness}, we |
| 6408 |
% have acquired useful information for the subsequent processing. |
| 6409 |
% \begin{macrocode} |
| 6410 |
\setbox\z@\hbox to\displaywidth\bgroup |
| 6411 |
\let\split@warning\relax \restore@hfuzz |
| 6412 |
\everymath\@emptytoks \m@th $\displaystyle |
| 6413 |
\fi |
| 6414 |
\fi |
| 6415 |
} |
| 6416 |
% \end{macrocode} |
| 6417 |
% |
| 6418 |
% Arg 1 is not currently used. I thought it might come in handy for |
| 6419 |
% error messages. |
| 6420 |
% \changes{v2.17w}{2025/03/08}{Use \cs{dollardollar@begin} and |
| 6421 |
% \cs{dollardollar@end} instead of \texttt{\$\$} for tagging support} |
| 6422 |
% \begin{macrocode} |
| 6423 |
\def\endmathdisplay#1{% |
| 6424 |
\ifmmode \else \@badmath \fi |
| 6425 |
\endmathdisplay@a |
| 6426 |
\dollardollar@end |
| 6427 |
% \end{macrocode} |
| 6428 |
% I guess the following code means this structure is non-reentrant. |
| 6429 |
% But there is plenty of scope for tricky bugs here; suppressing them |
| 6430 |
% by brute force at least makes it possible to get things working |
| 6431 |
% correctly for normal use. [mjd,2000/01/06] |
| 6432 |
% \begin{macrocode} |
| 6433 |
\global\let\df@label\@empty \global\let\df@tag\@empty |
| 6434 |
\global\tag@false \global\let\alt@tag\@empty |
| 6435 |
\global\@eqnswfalse |
| 6436 |
} |
| 6437 |
% \end{macrocode} |
| 6438 |
% |
| 6439 |
% \begin{macrocode} |
| 6440 |
\def\endmathdisplay@a{% |
| 6441 |
\if@eqnsw \gdef\df@tag{\tagform@\theequation}\fi |
| 6442 |
\if@fleqn \@xp\endmathdisplay@fleqn |
| 6443 |
\else \ifx\df@tag\@empty \else \veqno \alt@tag \df@tag \fi |
| 6444 |
\ifx\df@label\@empty \else \@xp\ltx@label\@xp{\df@label}\fi |
| 6445 |
\fi |
| 6446 |
\ifnum\dspbrk@lvl>\m@ne |
| 6447 |
\postdisplaypenalty -\@getpen\dspbrk@lvl |
| 6448 |
\global\dspbrk@lvl\m@ne |
| 6449 |
\fi |
| 6450 |
} |
| 6451 |
% \end{macrocode} |
| 6452 |
% |
| 6453 |
% A boolean variable: Was that last box overfull or not? A value of 0 |
| 6454 |
% means yes, it was overfull. |
| 6455 |
% \begin{macrocode} |
| 6456 |
\let\too@wide\@ne |
| 6457 |
% \end{macrocode} |
| 6458 |
% |
| 6459 |
% Special handling is needed for flush-left equations. We need to |
| 6460 |
% measure the equation body (found in box 0 after we close it with |
| 6461 |
% the \cs{egroup}). Then after a fairly normal test to see if it fits |
| 6462 |
% within the available space, we need to consider overlapping into |
| 6463 |
% the displayindent area if displayindent is nonzero (as in an |
| 6464 |
% indented list). If there is an equation number we may have to shift |
| 6465 |
% it by hand to a separate line when there is not enough room; |
| 6466 |
% we can no longer take advantage of the automatic shifting provided |
| 6467 |
% by the \cn{leqno}, \cn{eqno} primitives. |
| 6468 |
% |
| 6469 |
% We initially add \cs{@mathmargin} glue at the end of box 0 to get |
| 6470 |
% an accurate overfull test. If \cs{@mathmargin} contains any shrink |
| 6471 |
% then we cannot reliably tell whether the box will be overfull or |
| 6472 |
% not simply by doing hand calculations from the actual width of the |
| 6473 |
% equation body. We have to actually set the box and find out what |
| 6474 |
% happens. |
| 6475 |
% |
| 6476 |
% On the other hand if we put the \cs{@mathmargin} glue at the |
| 6477 |
% beginning of the box it's awkward to remove it afterwards. So we |
| 6478 |
% first put it in at the end and later we will move it to the |
| 6479 |
% beginning as needed. |
| 6480 |
% |
| 6481 |
% \begin{macrocode} |
| 6482 |
\def\endmathdisplay@fleqn{% |
| 6483 |
$\hfil\hskip\@mathmargin\egroup |
| 6484 |
% \end{macrocode} |
| 6485 |
% We need to save the information about whether box 0 was overfull in |
| 6486 |
% a variable, otherwise it will disappear in the next setbox |
| 6487 |
% operation. And we couldn't set the equation number box earlier than |
| 6488 |
% now, because the body of the equation might have contained a |
| 6489 |
% \cs{tag} command (well, it could have been done, but this way |
| 6490 |
% we can reuse the tag-handling code from elsewhere). |
| 6491 |
% \begin{macrocode} |
| 6492 |
\ifnum\badness<\inf@bad \let\too@wide\@ne \else \let\too@wide\z@ \fi |
| 6493 |
\ifx\@empty\df@tag |
| 6494 |
\else |
| 6495 |
\setbox4\hbox{\df@tag |
| 6496 |
\ifx\df@label\@empty \else \@xp\ltx@label\@xp{\df@label}\fi |
| 6497 |
}% |
| 6498 |
\fi |
| 6499 |
\csname emdf@% |
| 6500 |
\ifx\df@tag\@empty U\else \iftagsleft@ L\else R\fi\fi |
| 6501 |
\endcsname |
| 6502 |
} |
| 6503 |
% \end{macrocode} |
| 6504 |
% |
| 6505 |
% For an unnumbered flush-left equation we hope first that the |
| 6506 |
% the contents fit within displaywidth. If not we need to fall back |
| 6507 |
% on a more complicated reboxing operation. |
| 6508 |
% \begin{macrocode} |
| 6509 |
\def\emdf@U{% |
| 6510 |
\restore@hfuzz |
| 6511 |
\ifodd\too@wide % not too wide: just need to swap the glue around |
| 6512 |
\hbox to\displaywidth{\hskip\@mathmargin\unhbox\z@\unskip}% |
| 6513 |
\else % M+B > displaywidth |
| 6514 |
\emdf@Ua |
| 6515 |
\fi |
| 6516 |
} |
| 6517 |
% \end{macrocode} |
| 6518 |
% |
| 6519 |
% Some notation: $M$ \cs{@mathmargin}, $B$ the width of the equation |
| 6520 |
% body, $I$ \cs{displayindent}, $D$ \cs{displaywidth}, $N$ the width |
| 6521 |
% of the equation number (aka the tag), $S$ \cs{mintagsep}, $C$ |
| 6522 |
% \cs{columnwidth}. If $M+B > \mbox{displaywidth}$, and if we assume |
| 6523 |
% $M$ contains shrink, then the only solution left is to encroach |
| 6524 |
% into the displayindent space. |
| 6525 |
% \begin{macrocode} |
| 6526 |
\def\emdf@Ua{% |
| 6527 |
\hbox to\columnwidth{% |
| 6528 |
\ifdim\displayindent>\z@ |
| 6529 |
\hskip\displayindent minus\displayindent |
| 6530 |
\fi |
| 6531 |
\hskip\@mathmargin \unhbox\z@ \unskip |
| 6532 |
}% |
| 6533 |
\displayindent\z@ \displaywidth\columnwidth |
| 6534 |
} |
| 6535 |
% \end{macrocode} |
| 6536 |
% |
| 6537 |
% Find out first if the tag fits in ideal position. If so we can just |
| 6538 |
% plunk down box 2. Otherwise we need to do something more complicated. |
| 6539 |
% \begin{macrocode} |
| 6540 |
\def\emdf@R{% |
| 6541 |
\setbox\tw@\hbox to\displaywidth{% |
| 6542 |
\hskip\@mathmargin \unhcopy\z@\unskip\hfil\hskip\mintagsep\copy4 |
| 6543 |
}% |
| 6544 |
\restore@hfuzz |
| 6545 |
\ifnum\badness<\inf@bad \box\tw@ \else \emdf@Ra \fi |
| 6546 |
} |
| 6547 |
% \end{macrocode} |
| 6548 |
% |
| 6549 |
% We shift the equation number to line 2 if it does not fit within |
| 6550 |
% \cs{displaywidth}. Note that we do not first attempt to let the |
| 6551 |
% equation body shift leftward into the \cs{displayindent} space. If |
| 6552 |
% that is desired it will have to be done by hand by adding negative |
| 6553 |
% space at the beginning of the equation body. I don't expect this to |
| 6554 |
% arise very often in practice since most of the time |
| 6555 |
% \cs{displayindent} is zero anyway. |
| 6556 |
% \begin{macrocode} |
| 6557 |
\def\emdf@Ra{% |
| 6558 |
\skip@\displayindent minus\displayindent |
| 6559 |
\displayindent\z@ \displaywidth\columnwidth |
| 6560 |
\spread@equation \everycr{}\tabskip\z@skip |
| 6561 |
\halign{\hbox to\displaywidth{##}\cr |
| 6562 |
\relax |
| 6563 |
\ifdim\skip@>\z@ \hskip\skip@ \fi |
| 6564 |
\hskip\@mathmargin\unhbox\z@\unskip\hfil\cr |
| 6565 |
\noalign{\raise@tag}% |
| 6566 |
\hfil\box4 \cr}% |
| 6567 |
} |
| 6568 |
% \end{macrocode} |
| 6569 |
% |
| 6570 |
% Find out first if the tag fits in ideal position. If so we can just |
| 6571 |
% plunk down box 2. Otherwise we need to do something more |
| 6572 |
% complicated. |
| 6573 |
% \begin{macrocode} |
| 6574 |
\def\emdf@L{% |
| 6575 |
% \end{macrocode} |
| 6576 |
% Calculate the difference between $M$ and $N+S$. If the latter is |
| 6577 |
% greater, we don't want to add any extra glue between the number and |
| 6578 |
% the equation body. Otherwise the amount that we want to add is |
| 6579 |
% \verb'x minus x' where $x=M-(N+S)$. I.e., the distribution of |
| 6580 |
% spaces across the line is $N,S,x minus x,B,hfil$. |
| 6581 |
% \begin{macrocode} |
| 6582 |
\@tempdima\@mathmargin |
| 6583 |
\advance\@tempdima-\wd4 \advance\@tempdima-\mintagsep |
| 6584 |
\skip@\@tempdima minus\@tempdima |
| 6585 |
\setbox\tw@\hbox to\displaywidth{% |
| 6586 |
\copy4\hskip\mintagsep |
| 6587 |
\ifdim\skip@>\z@ \hskip\skip@\fi |
| 6588 |
\unhcopy\z@\unskip |
| 6589 |
}% |
| 6590 |
\restore@hfuzz |
| 6591 |
\ifnum\badness<\inf@bad \box\tw@ \else \emdf@La \fi |
| 6592 |
} |
| 6593 |
% \end{macrocode} |
| 6594 |
% |
| 6595 |
% If the equation body and equation number will not fit on the same |
| 6596 |
% line, we put the number on line 1 and the body on line 2, with the |
| 6597 |
% body positioned as for an unnumbered equation. |
| 6598 |
% \begin{macrocode} |
| 6599 |
\def\emdf@La{% |
| 6600 |
\spread@equation \everycr{}\tabskip\z@skip |
| 6601 |
\halign{\hbox to\displaywidth{##}\cr |
| 6602 |
\box4 \hfil \cr |
| 6603 |
\noalign{\raise@tag}% |
| 6604 |
\hskip\@mathmargin\unhbox\z@\unskip\hfil\cr}% |
| 6605 |
} |
| 6606 |
% \end{macrocode} |
| 6607 |
% |
| 6608 |
% If someone has \verb'\[ \]' nested inside a minipage environment |
| 6609 |
% nested inside a numbered equation, the mathdisplay variables that |
| 6610 |
% are global will get out of whack unless we take extra care. So we |
| 6611 |
% make a stack and push all the variables before entering mathdisplay |
| 6612 |
% and pop them afterwards. But we can save a little work by not doing |
| 6613 |
% this at the top level, only at inner levels. |
| 6614 |
% \begin{macrocode} |
| 6615 |
\newtoks\mathdisplay@stack |
| 6616 |
\let\mathdisplay@push\@empty |
| 6617 |
\def\mathdisplay@@push{% |
| 6618 |
\begingroup |
| 6619 |
\toks@\@xp{\df@label}\@temptokena\@xp{\df@tag}% |
| 6620 |
\toks8\@xp{\alt@tag}% |
| 6621 |
\edef\@tempa{% |
| 6622 |
\global\if@eqnsw\@nx\@eqnswtrue\else\@nx\@eqnswfalse\fi |
| 6623 |
\global\iftag@\@nx\tag@false\else\@nx\tag@true\fi |
| 6624 |
\gdef\@nx\df@label{\the\toks@}\gdef\@nx\df@tag{\the\@temptokena}% |
| 6625 |
\gdef\@nx\alt@tag{\the\toks8}% |
| 6626 |
\global\mathdisplay@stack{\the\mathdisplay@stack}% |
| 6627 |
}% |
| 6628 |
\global\mathdisplay@stack\@xp{\@tempa} |
| 6629 |
\endgroup |
| 6630 |
} |
| 6631 |
% \end{macrocode} |
| 6632 |
% |
| 6633 |
% \begin{macrocode} |
| 6634 |
\let\mathdisplay@pop\@empty |
| 6635 |
\def\mathdisplay@@pop{\the\mathdisplay@stack} |
| 6636 |
% \end{macrocode} |
| 6637 |
%\changes{v2.17k}{2021/08/24}{Move the counter inside the equation and guard |
| 6638 |
% with a mathopen for better compatibility with hyperref, issue gh/652} |
| 6639 |
% As with hyperref incrementing the counter creates a box to raise the anchor |
| 6640 |
% it should be in a place where is doesn't affect spacing. |
| 6641 |
% Currently the code from hyperref is used to avoid this problem: |
| 6642 |
% If fleqn isn't active the counter is set inside the equation and the potential |
| 6643 |
% box guarded by a mathopen to avoid side effects on following unary symbols. |
| 6644 |
% If fleqn is activated it has to be outside to avoid problems with labels. |
| 6645 |
% This solution is temporary and not necessarily the best. |
| 6646 |
% \begin{macrocode} |
| 6647 |
\if@fleqn |
| 6648 |
\renewenvironment{equation}{% |
| 6649 |
\incr@eqnum |
| 6650 |
\mathdisplay@push |
| 6651 |
\st@rredfalse \global\@eqnswtrue |
| 6652 |
\mathdisplay{equation}% |
| 6653 |
}{% |
| 6654 |
\endmathdisplay{equation}% |
| 6655 |
\mathdisplay@pop |
| 6656 |
\ignorespacesafterend |
| 6657 |
} |
| 6658 |
\else |
| 6659 |
\renewenvironment{equation}{% |
| 6660 |
\mathdisplay@push |
| 6661 |
\st@rredfalse \global\@eqnswtrue |
| 6662 |
\mathdisplay{equation}% |
| 6663 |
\incr@eqnum\mathopen{}% |
| 6664 |
}{% |
| 6665 |
\endmathdisplay{equation}% |
| 6666 |
\mathdisplay@pop |
| 6667 |
\ignorespacesafterend |
| 6668 |
} |
| 6669 |
\fi |
| 6670 |
% \end{macrocode} |
| 6671 |
% |
| 6672 |
% \begin{macrocode} |
| 6673 |
\newenvironment{equation*}{% |
| 6674 |
\mathdisplay@push |
| 6675 |
\st@rredtrue \global\@eqnswfalse |
| 6676 |
\mathdisplay{equation*}% |
| 6677 |
}{% |
| 6678 |
\endmathdisplay{equation*}% |
| 6679 |
\mathdisplay@pop |
| 6680 |
\ignorespacesafterend |
| 6681 |
} |
| 6682 |
% \end{macrocode} |
| 6683 |
% |
| 6684 |
% Note: \latex/ defines the \env{displaymath} environment in |
| 6685 |
% terms of \cn{[} and \cn{]}. |
| 6686 |
% \begin{macrocode} |
| 6687 |
\DeclareRobustCommand{\[}{\begin{equation*}} |
| 6688 |
\DeclareRobustCommand{\]}{\end{equation*}} |
| 6689 |
% \end{macrocode} |
| 6690 |
% |
| 6691 |
% The usual \cs{endinput} to ensure that random garbage at the end of |
| 6692 |
% the file doesn't get copied by \fn{docstrip}. |
| 6693 |
% \begin{macrocode} |
| 6694 |
\endinput |
| 6695 |
% \end{macrocode} |
| 6696 |
% |
| 6697 |
% \section{Credits} |
| 6698 |
% |
| 6699 |
% Much of the code for the \pkg{amsmath} package had its origin in |
| 6700 |
% \fn{amstex.tex}, written by Michael Spivak. The initial work of |
| 6701 |
% porting \fn{amstex.tex} to \fn{amstex.sty} was done in 1988--1989 |
| 6702 |
% by Frank Mittelbach and Rainer Sch\"opf. In 1994 David M. Jones |
| 6703 |
% added the support for the \opt{fleqn} option and did extensive |
| 6704 |
% improvements to the \env{align[at]} family of environments and to |
| 6705 |
% the equation number handling in general. Michael Downes at the AMS |
| 6706 |
% served as coordinator for the efforts of Mittelbach, Sch\"opf, and |
| 6707 |
% Jones, and has contributed various bug fixes and additional |
| 6708 |
% refinements over time. |
| 6709 |
% |
| 6710 |
% Versions 1.0 and 1.1 of the package carried the name \pkg{amstex} |
| 6711 |
% instead of \pkg{amsmath}, to indicate its origins; the name was |
| 6712 |
% changed in 1994 to make it user-oriented rather than |
| 6713 |
% history-oriented. |
| 6714 |
% |
| 6715 |
\endinput |