ltmath.dtx

Johannes Braams  David Carlisle  Alan Jeffrey
Leslie Lamport  Frank Mittelbach  Chris Rowley

Rainer Schöpf

1995/10/16

¡*driver¿ ¡/driver¿

1 Math setup

This file contains a lot of the original plain TEX code, as well as the L^{A}TEX environments for math. It still needs sorting out.

1 ⟨∗2ekernel⟩

 2 \message{math definitions,}

1.1 Math commands based on plain TEX

1.1.1 The log-like functions

The standard operators:

 3 \def\log{\mathop{\operator@font log}\nolimits}
 4 \def\lg{\mathop{\operator@font lg}\nolimits}
 5 \def\ln{\mathop{\operator@font ln}\nolimits}
 6 \def\lim{\mathop{\operator@font lim}}
 7 \def\limsup{\mathop{\operator@font lim\,sup}}
 8 \def\liminf{\mathop{\operator@font lim\,inf}}
 9 \def\sin{\mathop{\operator@font sin}\nolimits}
10 \def\arcsin{\mathop{\operator@font arcsin}\nolimits}
11 \def\sinh{\mathop{\operator@font sinh}\nolimits}
12 \def\cos{\mathop{\operator@font cos}\nolimits}
13 \def\arccos{\mathop{\operator@font arccos}\nolimits}
14 \def\cosh{\mathop{\operator@font cosh}\nolimits}
15 \def\tan{\mathop{\operator@font tan}\nolimits}
16 \def\arctan{\mathop{\operator@font arctan}\nolimits}
17 \def\tanh{\mathop{\operator@font tanh}\nolimits}
18 \def\cot{\mathop{\operator@font cot}\nolimits}
19 \def\coth{\mathop{\operator@font coth}\nolimits}
20 \def\sec{\mathop{\operator@font sec}\nolimits}
21 \def\csc{\mathop{\operator@font csc}\nolimits}
22 \def\max{\mathop{\operator@font max}}

23 \def\min{\mathop{\operator@font min}}
24 \def\sup{\mathop{\operator@font sup}}
25 \def\inf{\mathop{\operator@font inf}}
26 \def\arg{\mathop{\operator@font arg}\nolimits}
27 \def\ker{\mathop{\operator@font ker}\nolimits}
28 \def\dim{\mathop{\operator@font dim}\nolimits}
29 \def\hom{\mathop{\operator@font hom}\nolimits}
30 \def\det{\mathop{\operator@font det}}
31 \def\exp{\mathop{\operator@font exp}\nolimits}
32 \def\Pr{\mathop{\operator@font Pr}}
33 \def\gcd{\mathop{\operator@font gcd}}
34 \def\deg{\mathop{\operator@font deg}\nolimits}

And some operators have to be done by hand:

35 \def\bmod{\nonscript\mskip-\medmuskip\mkern5mu
36 \mathbin{\operator@font mod}\penalty900\mkern5mu%
37 \nonscript\mskip-\medmuskip}
38 \def\pmod#1{\allowbreak\mkern18mu({\operator@font mod}\,\,#1)}

1.1.2 Biggggg

Variants on \big and friends for use with delimiters:

39 \def\bigl{\mathopen\big}
40 \def\bigm{\mathrel\big}
41 \def\bigr{\mathclose\big}
42 \def\Bigl{\mathopen\Big}
43 \def\Bigm{\mathrel\Big}
44 \def\Bigr{\mathclose\Big}
45 \def\biggl{\mathopen\bigg}
46 \def\biggm{\mathrel\bigg}
47 \def\biggr{\mathclose\bigg}
48 \def\Biggl{\mathopen\Bigg}
49 \def\Biggm{\mathrel\Bigg}
50 \def\Biggr{\mathclose\Bigg}

1.1.3 The UNSORTED Rest

The other math commands are lifted from plain TEX.

51 \newdimen\jot \jot=3pt
52 \newcount\interdisplaylinepenalty \interdisplaylinepenalty=100
53 \def\choose{\atopwithdelims()}
54 \def\brack{\atopwithdelims[]}
55 \def\brace{\atopwithdelims\{\}}
56 \def\mathpalette#1#2{\mathchoice{#1\displaystyle{#2}}%
57 {#1\textstyle{#2}}{#1\scriptstyle{#2}}{#1\scriptscriptstyle{#2}}}
58 \newbox\rootbox
59 \def\root#1\of{\setbox\rootbox\hbox{$\m@th\scriptscriptstyle{#1}$}
60 \mathpalette\r@@t}
61 \def\r@@t#1#2{\setbox\z@\hbox{$\m@th#1\sqrtsign{#2}$}

62 \dimen@\ht\z@ \advance\dimen@-\dp\z@
63 \mkern5mu\raise.6\dimen@\copy\rootbox \mkern-10mu \box\z@}
\phantom \mathstrut
64 \newif\ifv@ \newif\ifh@
65 \def\vphantom{\v@true\h@false\ph@nt}
66 \def\hphantom{\v@false\h@true\ph@nt}
67 \def\phantom{\v@true\h@true\ph@nt}
68 \def\ph@nt{%
69 \ifmmode
70  \expandafter\mathpalette\expandafter\mathph@nt
71 \else
72  \expandafter\makeph@nt
73 \fi}
74 \def\makeph@nt#1{%
75 \setbox\z@\hbox{\color@begingroup#1\color@endgroup}\finph@nt}
76 \def\mathph@nt#1#2{%
77 \setbox\z@\hbox{$\m@th#1{#2}$}\finph@nt}
78 \def\finph@nt{%
79 \setbox\tw@\null
80 \ifv@ \ht\tw@\ht\z@ \dp\tw@\dp\z@\fi
81 \ifh@ \wd\tw@\wd\z@\fi \box\tw@}
82 \def\mathstrut{\vphantom(}
\smash
83 \def\smash{%
84 \relax % \relax, in case this comes first in \halign
85 \ifmmode
86  \expandafter\mathpalette\expandafter\mathsm@sh
87 \else
88  \expandafter\makesm@sh
89 \fi}
90 \def\makesm@sh#1{%
91 \setbox\z@\hbox{\color@begingroup#1\color@endgroup}\finsm@sh}
92 \def\mathsm@sh#1#2{%
93 \setbox\z@\hbox{$\m@th#1{#2}$}\finsm@sh}
94 \def\finsm@sh{\ht\z@\z@ \dp\z@\z@ \box\z@}
\buildrel
95 \def\buildrel#1\over#2{\mathrel{\mathop{\kern\z@#2}\limits^{#1}}}
\cases
96 \def\cases#1{\left\{\,\vcenter{\normalbaselines\m@th
97  \ialign{$##\hfil$&\quad{##}\hfil\crcr#1\crcr}}\right.}
98 \def\matrix#1{\null\,\vcenter{\normalbaselines\m@th
99  \ialign{\hfil$##$\hfil&&\quad\hfil$##$\hfil\crcr
100  \mathstrut\crcr\noalign{\kern-\baselineskip}

101  #1\crcr\mathstrut\crcr\noalign{\kern-\baselineskip}}}\,}
102 \def\pmatrix#1{\left(\matrix{#1}\right)}
\bordermatrix
103 \def\bordermatrix#1{\begingroup \m@th
104 \@tempdima 8.75\p@
105 \setbox\z@\vbox{%
106  \def\cr{\crcr\noalign{\kern2\p@\global\let\cr\endline}}%
107  \ialign{$##$\hfil\kern2\p@\kern\@tempdima&\thinspace\hfil$##$\hfil
108  &&\quad\hfil$##$\hfil\crcr
109  \omit\strut\hfil\crcr\noalign{\kern-\baselineskip}%
110  #1\crcr\omit\strut\cr}}%
111 \setbox\tw@\vbox{\unvcopy\z@\global\setbox\@ne\lastbox}%
112 \setbox\tw@\hbox{\unhbox\@ne\unskip\global\setbox\@ne\lastbox}%
113 \setbox\tw@\hbox{$\kern\wd\@ne\kern-\@tempdima\left(\kern-\wd\@ne
114  \global\setbox\@ne\vbox{\box\@ne\kern2\p@}%
115  \vcenter{\kern-\ht\@ne\unvbox\z@\kern-\baselineskip}\,\right)$}%
116 \null\;\vbox{\kern\ht\@ne\box\tw@}\endgroup}
117 \def\openup{\afterassignment\@penup\dimen@=}
118 \def\@penup{\advance\lineskip\dimen@
119 \advance\baselineskip\dimen@
120 \advance\lineskiplimit\dimen@}
121 \newif\ifdt@p
122 \def\displ@y{\global\dt@ptrue\openup\jot\m@th
123 \everycr{\noalign{\ifdt@p \global\dt@pfalse \ifdim\prevdepth>-1000\p@
124  \vskip-\lineskiplimit \vskip\normallineskiplimit \fi
125  \else \penalty\interdisplaylinepenalty \fi}}}
126 \def\@lign{\tabskip\z@skip\everycr{}} % restore inside \displ@y
127 \def\displaylines#1{\displ@y \tabskip\z@skip
128 \halign{\hb@xt@\displaywidth{$\@lign\hfil\displaystyle##\hfil$}\crcr
129  #1\crcr}}
130 \let\sp=^\let\sb=_
131 %\def\,{\mskip\thinmuskip}      % already defined in ltspace
132 \def\>{\mskip\medmuskip}
133 \def\;{\mskip\thickmuskip}
134 \def\!{\mskip-\thinmuskip}
135 \def\*{\discretionary{\thinspace\the\textfont2\char2}{}{}}

\: Nickname for the medium space since \> is not available inside tabbing.

136 \let\:=\>
\prime@s
137 {\catcode`\'=\active \gdef'{^\bgroup\prim@s}}
138 \def\prim@s{%
139 \prime\futurelet\@let@token\pr@m@s}
140 \def\pr@m@s{%
141 \ifx'\@let@token

142  \expandafter\pr@@@s
143 \else
144  \ifx^\@let@token
145  \expandafter\expandafter\expandafter\pr@@@t
146  \else
147  \egroup
148  \fi
149 \fi}
150 \def\pr@@@s#1{\prim@s} \def\pr@@@t#1#2{#2\egroup}
151 {\catcode`\_=\active \gdef_{\_}} % _in math is
152  % either subscript or \_

1.2 Math Environments

{\( \atop \)} Produces $...$ with checks that \( isn’t used in math mode, and that \) is only used in math mode begun with \(.

153 \def\({\relax\ifmmode\@badmath\else$\fi}
154 \def\){\relax\ifmmode\ifinner$\else\@badmath\fi\else \@badmath\fi}

{\[ \atop \]} Produces $$...$$ with checks that \[ isn’t used in math mode, and that \] is only used in math mode begun with \].

155 \def\[{%
156 \relax\ifmmode
157  \@badmath
158 \else
159  \ifvmode
160  \nointerlineskip
161  \makebox[.6\linewidth]%
162  \fi
163  $$%%$$ BRACE MATCH HACK
164 \fi

165 }

166 \def\]{%
167 \relax\ifmmode
168  \ifinner
169  \@badmath
170  \else
171  $$%%$$ BRACE MATCH HACK
172  \fi
173 \else
174  \@badmath
175 \fi
176 \ignorespaces

177 }

math displaymath Disguises for \(...\) and \[...\].
178 \let\math=\(
179 \let\endmath=\)

180 \def\displaymath{\[}
181 \def\enddisplaymath{\]\global\@ignoretrue}

equation \c@equation Numbered equations, using the counter \c@equation. Note: The document style must define \theequation etc., and do the appropriate \@addtoreset. It should also redefine \@eqnnum if another format for the equation number is desired other than the standard (...), or to move the equation numbers to the flushleft. (See comment on the \def of \@eqnnum.)

182 \@definecounter{equation}
183 \def\equation{$$\refstepcounter{equation}}
184 \def\endequation{\eqno \hbox{\@eqnnum}$$\global\@ignoretrue}

\@eqnnum Produces the equation number for equation and eqnarray environments. The following definition is for flushright numbers; for flushleft numbers, see leqno.clo. The equation number is set in black roman type even if an eqnarray environment appears in an italic environment.

185 \def\@eqnnum{{\normalfont \normalcolor (\theequation)}}

\stackrel A disguise for plain TEX’s buildrel.

186 \def\stackrel#1#2{\mathrel{\mathop{#2}\limits^{#1}}}

\frac A disguise for plain TEX’s \over.

187 \def\frac#1#2{{\begingroup#1\endgroup\over#2}}

\sqrt \@sqrt Add an optional argument to plain’s \sqrt to give the nth root of an expression n \sqrt{e}.

188 \DeclareRobustCommand\sqrt{\@ifnextchar[\@sqrt\sqrtsign}
189 \def\@sqrt[#1]{\root #1\of}

eqnarray \@eqcnt \@eqpen \if@eqnsw \@eqnsel Here’s the eqnarray environment: Default is for left-hand side of equations to be flushright. To make them flushleft, \let\@eqnsel = \hfil.

190 \newcount\@eqcnt
191 \newcount\@eqpen
192 \newif\if@eqnsw\@eqnswtrue
193 \newskip\@centering
194 \@centering = 0pt plus 1000pt

To get a proper \@currentlabel we have to redefine it for the whole display. Note that we can’t use \refstepcounter as this results in \@currentlabel getting restored at the wrong and thus always writing the first label to the .aux file.

195 \def\eqnarray{%
196 \stepcounter{equation}%
197 \def\@currentlabel{\p@equation\theequation}%
198 \global\@eqnswtrue
199 \m@th
200 \global\@eqcnt\z@
201 \tabskip\@centering
202 \let\\\@eqncr

203 $$\everycr{}\halign to\displaywidth\bgroup
204  \hskip\@centering$\displaystyle\tabskip\z@skip{##}$\@eqnsel
205  &\global\@eqcnt\@ne\hskip \tw@\arraycolsep \hfil${##}$\hfil
206  &\global\@eqcnt\tw@ \hskip \tw@\arraycolsep
207  $\displaystyle{##}$\hfil\tabskip\@centering
208  &\global\@eqcnt\thr@@ \hb@xt@\z@\bgroup\hss##\egroup
209  \tabskip\z@skip
210  \cr

211 }

212 \def\endeqnarray{%
213  \@@eqncr
214  \egroup
215  \global\advance\c@equation\m@ne
216 $$\global\@ignoretrue

217 }

218 \let\@eqnsel=\relax

\nonumber Switches off equation numbering.

219 \def\nonumber{\global\@eqnswfalse}
\@eqncr \@xeqncr \@yeqncr
220 \def\@eqncr{%
221 {\ifnum0=`}\fi
222 \@ifstar{%
223  \global\@eqpen\@M\@yeqncr
224 }{%
225  \global\@eqpen\interdisplaylinepenalty \@yeqncr

226 }% 227 }

228 \def\@yeqncr{\@testopt\@xeqncr\z@skip}
229 \def\@xeqncr[#1]{%
230 \ifnum0=`{\fi}%
231 \@@eqncr
232 \noalign{\penalty\@eqpen\vskip\jot\vskip #1\relax}%

233 }

\@@eqncr
234 \def\@@eqncr{\let\reserved@a\relax
235  \ifcase\@eqcnt \def\reserved@a{& & &}\or \def\reserved@a{& &}%
236  \or \def\reserved@a{&}\else
237  \let\reserved@a\@empty
238  \@latex@error{Too many columns in eqnarray environment}\@ehc\fi
239  \reserved@a \if@eqnsw\@eqnnum\stepcounter{equation}\fi
240  \global\@eqnswtrue\global\@eqcnt\z@\cr}

eqnarray* \@seqncr Here’s the eqnarray* environment:

241 \let\@seqncr=\@eqncr
242 \@namedef{eqnarray*}{\def\@eqncr{\nonumber\@seqncr}\eqnarray}
243 \@namedef{endeqnarray*}{\nonumber\endeqnarray}

\lefteqn \lefteqn{FORMULA} typesets FORMULA in display math style flushleft in a box of width zero.

244 \def\lefteqn#1{\rlap{$\displaystyle #1$}}

\ensuremath In math mode, \ensuremath{text} is equivalent to text; in LR or paragraph mode, it is equivalent to $text$. \relax is not needed in front of the \ifmmode

as \protect will be \let to \relax.
245 \DeclareRobustCommand\ensuremath[1]{\ifmmode #1\else $#1$\fi}

246 ⟨/2ekernel⟩

1.3 External options to the standard document classes

1.3.1 Left equation numbering

\@eqnnum To put the equation number on the left side of an equation we have to use a little trick. The number is shifted \displaywidth to the left inside a box of (approximately) zero width. This fails when the quation is too wide, the equation number than may overprint the equation itself.

247 ⟨∗leqno⟩

248 \renewcommand\@eqnnum{\hb@xt@.01\p@{}%
249  \rlap{\normalfont\normalcolor
250  \hskip -\displaywidth(\theequation)}}

251 ⟨/leqno⟩

1.3.2 Flush left equations

To get the displayed math environments to print the contents flush left (with an indentation) we have to redefine all of L^{A}TEX 2ε’s displayed math environments.

\mathindent The amount of indentation of the equations is stored in a register.

252 ⟨∗fleqn⟩

253 \newdimen\mathindent

The setting of \mathindent has to be deferred until the class file has been processed, because \leftmargini is still 0pt wide at the moment fleqn.clo is read in.

254 \AtEndOfClass{\mathindent\leftmargini}

\[ Begin display math;

255 \renewcommand\[{\relax
256  \ifmmode\@badmath
257  \else
258  \begin{trivlist}%
259  \@beginparpenalty\predisplaypenalty
260  \@endparpenalty\postdisplaypenalty
261  \item[]\leavevmode
262  \hb@xt@\linewidth\bgroup $\m@th\displaystyle %$
263  \hskip\mathindent\bgroup
264  \fi}

\] end display math;

265 \renewcommand\]{\relax
266  \ifmmode
267  \egroup $\hfil% $
268  \egroup
269  \end{trivlist}%
270  \else \@badmath
271  \fi}

equation The equation environment

272 \renewenvironment{equation}%
273  {\@beginparpenalty\predisplaypenalty
274  \@endparpenalty\postdisplaypenalty
275  \refstepcounter{equation}%
276  \trivlist \item[]\leavevmode
277  \hb@xt@\linewidth\bgroup $\m@th% $
278  \displaystyle
279  \hskip\mathindent}%
280  {$\hfil % $
281  \displaywidth\linewidth\hbox{\@eqnnum}%
282  \egroup
283  \endtrivlist}

eqnarray The eqnarray environment

284 \renewenvironment{eqnarray}{%
285  \stepcounter{equation}%
286  \def\@currentlabel{\p@equation\theequation}%
287  \global\@eqnswtrue\m@th
288  \global\@eqcnt\z@
289  \tabskip\mathindent
290  \let\\=\@eqncr
291  \setlength\abovedisplayskip{\topsep}%
292  \ifvmode
293  \addtolength\abovedisplayskip{\partopsep}%
294  \fi

When the documentclass uses a non-zero \parskip setting the \topsep might have a negative value to compensate for that. Therefor we add \parskip to

 \abovedisplayskip.
295  \addtolength\abovedisplayskip{\parskip}%
296  \setlength\belowdisplayskip{\abovedisplayskip}%
297  \setlength\belowdisplayshortskip{\abovedisplayskip}%
298  \setlength\abovedisplayshortskip{\abovedisplayskip}%
299  $$\everycr{}\halign to\linewidth% $$
300  \bgroup
301  \hskip\@centering
302  $\displaystyle\tabskip\z@skip{##}$\@eqnsel&%
303  \global\@eqcnt\@ne \hskip \tw@\arraycolsep \hfil${##}$\hfil&%
304  \global\@eqcnt\tw@ \hskip \tw@\arraycolsep
305  $\displaystyle{##}$\hfil \tabskip\@centering&%

306  \global\@eqcnt\thr@@
307  \hb@xt@\z@\bgroup\hss##\egroup\tabskip\z@skip\cr}%
308  {\@@eqncr
309  \egroup
310  \global\advance\c@equation\m@ne$$% $$
311  \global\@ignoretrue

312 } 313 ⟨/fleqn⟩