Debian Codegraph @

texmf-dist/doc/amstex/base/amstex.txt

raw
1 AMSTEX.DOC (FOR AMSTEX.TEX VERSION 2.0)
2 COPYRIGHT (C) 1989 BY MICHAEL SPIVAK
3
4 THIS COPYRIGHTED MATERIAL MAY BE REPRODUCED, EITHER IN PRINTED FORM,
5 OR AS A COMPUTER FILE, WHICH MAY THEN BE PLACED ON ANY COMPUTER OR
6 COMPUTER NETWORK, PROVIDED THAT THE FIRST TWO LINES OF THIS FILE, AS
7 WELL AS THIS PARAGRAPH, ARE ALSO REPRODUCED. IT MAY NOT BE SOLD,
8 EXCEPT FOR A NOMINAL FEE NOT TO EXCEED $5.00 PER COPY; CHARGES FOR
9 SHIPPING MAY BE ADDED, BUT ADDITIONAL CHARGES FOR PACKAGING,
10 HANDLING, ETC., ARE EXPRESSLY FORBIDDEN.
11
12
13 This is the documentation for AmS-TeX, specifically the file
14 AMSTEX.TEX.
15
16
17 **********************************************************************
18 Comments of the form %1, %2, etc., accompany the %1, etc., that occur
19 within the file AMSTEX.TEX in the definition of the construction in
20 question.
21 **********************************************************************
22
23
24 **********************************************************************
25 Some explanations given earlier in the file will be required at later
26 points. Such material is often set off by lines of *'s, like this.
27 TB refers to The TeXbook.
28 **********************************************************************
29
30
31 \def\fmtname ...
32 ----------------
33 We record the format name in \fmtname, overriding the definition that
34 comes from plain. But we store the format version for plain in
35 \plainfmtversion, in case someone needs to look at that, and record
36 the version of AmS-TeX in \fmtversion.
37
38
39 **********************************************************************
40 \catcode`\@=11
41 --------------
42 We make @ a letter, so that we can make private control sequences,
43 which we won't have to worry about users wanting to define
44 themselves. The private control sequences from plain, like \p@,
45 \@ne, etc., are also used extensively. Most of the time optional =
46 signs are omitted. (Note, however, that in a test like \ifnum< >=< >
47 the = is NOT optional.)
48 **********************************************************************
49
50
51 \ifx\amstexloaded@
52 ------------------
53 We have to prevent AMSTEX.TEX from being read in twice; see TB,
54 p. 382 (and the definition of \/). The code didn't fit on one line;
55 it was imperative that the \endinput...\fi was all on one line,
56 however.
57
58
59 \W@, \CR@
60 ---------
61 \W@ writes to screen and log file.
62
63 \CR@, the copyright notice, is defined as a sequence of \W@'s. We
64 use \fmtversion so that the first line doesn't have to be changed.
65
66
67 \CR@
68 ----
69 Then we print the copyright notice.
70
71
72 \everyjob{\CR@}
73 ---------------
74 Then we make sure it's printed even if a format file is made.
75
76
77 **********************************************************************
78 \toksdef\toks@@
79 ---------------
80 We will need a second scratch token, in addition to \toks@ (TB,
81 p. 346); \toks@@ is set to \toks2, rather than \toks1, in accordance
82 with rule (3) on that page.
83 **********************************************************************
84
85
86 \rightappend@ is \rightappend from TB, p. 378.
87
88
89 \def\alloclist@
90 ----------------
91 We modify the allocation routines from TB, Appendix B, so that
92 nothing is written to the log file. But we collect all information
93 that might go there, so that it can be written later if
94 \showallocations appears in the input file. \alloclist@ will be the
95 list of things that previously went to the log file, in the form of
96 TB, p. 378.
97
98
99 \showallocations writes each thing in \alloclist@, and sets a flag
100 \ifalloc@ for any later things to be written.
101
102
103 \alloc@ is redefined from TB, p. 347. Near the end, it will be redefined
104 once again. We \edef\next@ to be the token list that we want added to
105 \alloclist@ by \rightappend@, so that \the\allocationnumber will be
106 expanded out to the actual number.
107
108
109 **********************************************************************
110 We will be using the scratch tokens \next, \next@, \nextii@,
111 \nextiii@, etc. In order to keep the number down, many definitions
112 will, for example, define \nextiv@ back in terms of \next@, \nextii@,
113 etc. There is only one problem that we have to guard against:
114 Sometimes our definitions have clauses like \def\next@{ ... \next
115 ...}. The definitions of \next@ won't be made until these
116 definitions are invoked, and at that time \next might be \outer (!!)
117 because some previous \futurelet may have \let\next be something that
118 is \outer; this error will only be encountered at that time, not when
119 the definitions are read by AmS-TeX, because \next isn't outer when
120 AmS-TeX is making the definition! So we could end up with a pretty
121 incomprehensible error message at some point when AmS-TeX is being
122 used. Similarly, an outer \next might cause a problem if it is used
123 in some \if... construction, since outer control sequences aren't
124 allowed while TeX is skipping conditional text. To guard against
125 this, we will, first of all, always reserve \next for \futurelet
126 constructions. That is why \next@ is used instead of \next in our
127 redefinition of \alloc@. Later we will mention the other thing we
128 have to do to guard against the problem.
129 **********************************************************************
130
131
132 \newcount\count@@, \newcount\count@@@
133 -------------------------------------
134 We will need two more counters. Since \count@, \count@@, and
135 \count@@@ will all be used only for local assignments, we don't
136 bother with rule (3) of TB, p. 346.
137
138
139 \FN@, \DN@, \DNii@, \RIfM@, \RIfMIfI@, \setboxz@h, \wdz@,
140 \boxz@, \setbox@ne, \wd@ne
141 ---------------------------------------------------------
142 These definitions abbreviate combinations that occur sufficiently
143 often to make it worthwhile using up control sequence names.
144
145
146 \iterate, from plain, is redefined using the method of Kabelschacht,
147 see TUGboat, Volume 8, No. 2, p. 184.
148
149
150 **********************************************************************
151 It is assumed that the user of this documentation already understands
152 why it is often necessary to use constructions like
153
154 \if...\def\next{\csa}\else\def\next{\csb}\fi\next
155
156 instead of simply \if...\csa\else\csb\fi.
157
158 Kabelschacht's method also replaces this by the construction
159
160 \if...\expandafter\csa\else\expandafter\csb\fi.
161
162 We will call this the ``K-method''. The K-method will often be used
163 without explicit mention; however, it is not always valid or
164 practicable, as we will mention later.
165 **********************************************************************
166
167
168 ^^J is made the \newlinechar for help messages, and also for use in
169 the definition of \comment later on.
170
171
172 \err@ is the standard form for AmS-TeX error messages.
173
174
175 \newhelp\defaulthelp@
176 ---------------------
177 We make a standard default help, equivalent to the usual second level
178 help message you get with TeX (so that there won't be an error
179 message from TeX saying that it doesn't know how to give help).
180
181
182 \Err@ is the standard form for AmS-TeX error messages with default
183 help.
184
185
186 \eat@ is used to gobble tokens.
187
188
189 \in@ tests whether string #2 contains token #1; see TB, p. 379,
190 setting a flag \ifin@.
191
192
193 **********************************************************************
194 \def\space@
195 -----------
196 We frequently need a token that is \let equal a space. The % after
197 `\space@. ' insures that the space isn't deleted.
198 **********************************************************************
199
200
201 \athelp@
202 --------
203 Now comes the mechanism by which @<token> will be defined, when @ is
204 made active, at the end. \athelp@ is a help message.
205
206
207 {\catcode`\@=\active
208 --------------------
209 Now we have to define how @ will work when it will be active. This
210 whole mechanism occurs within a group in which @ is active, so most
211 \defs are \gdefs.
212
213
214 \lccode`\Z=`\@, \lccode`\I=`\I
215 ------------------------------
216 We want any auxiliary control sequences that are mentioned in this
217 process to have the letter @ as part of their name, even though
218 @ is now active, so we have to use the \lowercase trick: we set
219 the \lccode of Z to be @, name such control sequences as
220 \csname...Z\endcsname, and then \lowercase the whole thing. This
221 often requires \expandafter. For example, we have to say
222
223 \expandafter\gdef\csname ...\endcsname,
224 not
225 \gdef\csname...\endcsname.
226
227 Finally, we also set the \lccode of I to I, since I appears in some
228 error messages that we will be defining in this process, and we don't
229 want this I changed to lowercase!
230
231 Things are so complicated here, that we won't even contemplate using
232 the K-method!
233
234 %1 The very first thing we want to do is make @ mean
235 \futurelet\next\at@ (and then we will define \at@ in terms of
236 \next). Trying to say all that with \csname seems a hopeless
237 muddle, so we first create \futureletnextat@ to stand for that.
238
239 %2 \at@ will call \at@@ if the next token is a letter or number, but
240 \at@@@ if it is a control sequence (we allow @\Vert, for example)
241 and \at@@@@, which will be an error message, otherwise.
242
243 %3 \at@@ <token> will be the control sequence `\<token>@at' (created
244 by \atdef@) if this control sequence has actually been created,
245 otherwise an error message with the \athelp@ help message.
246
247 %4 \at@@@\cs will be the control sequence `\\cs@@at' (created by
248 \atdef@@) or an error message.
249
250 %5 \at@@@@ is an error message, which also swallows up the next
251 input.
252
253 %6 The last right brace in this line matches the left brace in
254 `{\catcode`\@=\active'. The previous right brace closes the
255 `\lowercase{'.
256
257
258 \atdef@<token> creates the control sequence `\<token>@at'; we don't
259 test for whether this already exists, since \atdef@ isn't for the
260 user.
261
262
263 \atdef@@\cs creates the control sequence `\\cs@@at'. \atdef@@ can
264 also be used with active characters.
265
266
267 \newhelp\defahelp@, \newhelpf\defbhelp@
268 ---------------------------------------
269 Next comes the mechanism for \define. \defahelp@ is the help message
270 when the wrong syntax is used; \defbhelp@ is the help message when an
271 already defined control sequence appears after the \define.
272
273
274 \define gives an error message if it isn't followed by a control
275 sequence, and we add the tokens \def\nextii@@ so that what follows
276 gets swallowed up into the definition of \nextii@. We are using the
277 K-method here, hence \expandafter\define@@ in line %1 and
278 \expandafter\def\expandafter\nextii@ in line %2. Note that this
279 method clearly becomes impractical when many tokens are present in
280 one of the cases.
281
282
283 \def\undefined@@@@@@@@@@, \def\preloaded@@@@@@@@@@, \def\next@@@@@@@@@@
284 -----------------------------------------------------------------------
285 We want \define@@#1 to detect whether #1 has already been \def'd.
286 The idea is to use \csname\expandafter\eat@\string#1\endcsname to
287 reproduce #1; since \csname...\endcsname is given the value \relax if
288 it produces an undefined control sequence, using an \ifx test between
289 \relax and this new control sequence tells us whether it already
290 exists. But that won't work for \relax, nor for the control
291 sequences \undefined and \preloaded, which we want to remain
292 undefined. Moreover, we don't want the user to be able to
293 \define\next, since this scratch token is often redefined by various
294 macros. So first we test for \relax, and then for \undefined,
295 \preloaded, or \next. For the latter, we first define
296 \undefined@@@@@@@@@@, \preloaded@@@@@@@@@@, and \next@@@@@@@@@@ as {};
297 these are the only control sequences with 10 @'s (in fact, there are
298 none with even 5 @'s, but we might as well be on the safe side). Then
299 we use \csname to construct a new control sequence `#1@@@@@@@@@@' and
300 test this with \ifx against \preloaded@@@@@@@@@@; we will get true
301 only for \preloaded, \undefined, and \next.
302
303 One of the nice features of all this is that a control sequence \cs
304 becomes undefined, and thus available to be \define'd, simply by saying
305 \let\cs\undefined.
306
307 There is one additional subtle point. The final test recreates #1 with
308 \csname...\endcsname, and causes \def#1 to be invoked if this is \relax.
309 But when \csname...\endcsname creates a new control sequence and gives it
310 the value \relax, it does this GLOBALLY; more precisely, it makes it equal
311 to an internal control sequence that always has the value of \relax, see
312 TeX, The Program, pp. 156 and 93. If \define is being used within a group,
313 we want #1 to be undefined once this group is over, so we add
314 \global\let#1\undefined before we invoke the \def#1.
315
316 We don't use the K-method here, since things are already so complicated.
317
318 %1 Give error message if #1 is relax.
319 %2 Give error message if #1 is \undefined, \preloaded, or \next.
320 %3 Do \def#1 if #1 is previously undefined, otherwise give error message.
321
322
323 \redefine, \predefine, should be obvious. Note that
324 \predefine\cs{...} works, since the braces get removed by TeX.
325
326
327 \undefine was added recently. It seems even better than \redefine: to
328 redefine an already defined control sequence \cs, you just have to
329 say \undefine\cs to first make it undefined.
330
331
332 \captionwidth@ is used to store the default width for captions.
333 It is made 1.5 inches less than \hsize. If a style file resets
334 \hsize, it should use \pagewidth, to automatically reset
335 \captionwidth@.
336
337
338 \pagewidth,...,\vcorrection
339 ---------------------------
340 \pagewidth resets \captionwidth@ automatically. \relax added for safety.
341
342
343 \tie is a synonym for ~ but is defined slightly differently, because
344 spaces are automatically ignored after \tie, but not after ~ , which
345 is defined a little later on.
346
347
348 \graveaccent, ..., \underscore are substitute names for some control
349 symbols.
350
351 \B, \D are AmS-TeX substitutes for \= and \. (\. will be redefined
352 later and \= will later be made undefined).
353
354
355 \let\ic@\/, \def\/
356 ------------------
357 We want \/ to ignore spaces before it. It is this definition that
358 makes it necessary to prevent AMSTEX.TEX from being read in twice.
359
360
361 \textfonti, and later \textfontii, are introduced not for purposes of
362 abbreviation, but because their values will sometimes be reset by
363 \text.
364
365
366 \t is redefined using \textfonti. It is also made a control sequence
367 with two arguments for consistency (now a space is allowed before the
368 second letter).
369
370
371 ~ differs from in plain; spaces are allowed on either side.
372
373
374 \. gives a non-end-of-sentence period by specifically setting
375 \spacefactor.
376
377
378 \atdef@ is used to make @; and @: and @? have desired values. (But @, and
379 @! are defined later, since they differ in math mode.) Just in case
380 these are ever used at the beginning of a paragraph (unlikely, of
381 course!), we put \leavevmode at the beginning.
382
383 If some macro package makes ! active [for French punctuation,
384 say], then \atdef@@! would have to be used instead of \atdef@!.
385
386
387 \@ is defined directly as \char64 , since we will have @ active at
388 the end (64 takes fewer tokens than '100).
389
390
391 **********************************************************************
392 \def\relaxnext@
393 ---------------
394 The construction \let\next\relax, abbreviated \relaxnext@, is needed
395 whenever we have a definition, like the ones to follow, where we have
396 a \futurelet\next, or \ifx\next, or anything else involving \next,
397 within a \def that is itself within a \def. As discussed before,
398 this could lead to havoc if \next happened to be \outer, so we add
399 \relaxnext@ at the beginning to protect ourselves.
400 **********************************************************************
401
402
403 \atdef@-
404 --------
405 We want @-, @-- and @--- to create \hbox{-} or \hbox{--} or
406 \hbox{---}, respectively, using as many \futurelet's as needed to
407 find out how many -'s there are (TeX won't hyphenate around boxes).
408
409 **********************************************************************
410 It would be more transparent to write the succeeding definitions as:
411
412 \atdef@-{\leavevmode\futurelet\next\hyphen@}
413 \def\hyphen@{\relaxnext@\ifx\next-\def\next@-{\futurelet\next
414 \hyphen@@}%
415 \else\def\next@{\leavevmode\hbox{-}}\fi\next@}
416 \def\hyphen@@{\ifx\next-\def\next@-{\leavevmode\hbox{---}}\else
417 \def\next@{\leavevmode\hbox{--}}\fi\next@}
418
419 But this uses up two new control sequences, \hyphen@ and \hyphen@@,
420 and such constructions appear frequently, so we save control sequence
421 names by using a `compressed format': the same names \next@,
422 \nextii@, etc., are used within different constructions, and
423 redefined within each construction. This makes things go a little
424 slower, since \next@, etc., have to be redefined all the time, but
425 seems worth it, especially since most such constructions are major
426 formatting ones that introduce a lot of space anyway. Notice that
427 the `first' clause \futurelet\next\next@ has to be made last, after
428 all the subsidiary definitions have been made.
429
430 In this situation, where the symbol - is made part of the syntax for
431 one of \next@'s (to swallow up this -), the K-method would not work.
432 **********************************************************************
433
434
435 \srdr@ ...
436 ----------
437 The kerns to put between single right-double right quotes, etc., are
438 recorded in control sequences, so that they can easily be changed for
439 different fonts.
440
441 These values are used in defining @", which has to look ahead to see
442 if it is followed by ' or '' or ` or `` . Also \lq or \rq might be
443 used instead of ` or '. Finally, we also have to skip over any space
444 that follows @".
445
446 **********************************************************************
447 AmS-TeX always does this by using a \futurelet to find out if the
448 next token is a space (testing with \ifx\next\space@), and calling
449 either `\next@. ' or `\next@.' The . after the \next@ makes the
450 space `visible' to TeX.
451 **********************************************************************
452
453 Compressed format is used in \atdef@". The K-method would be
454 hopelessly complicated.
455
456
457 \flushpar doesn't confuse the user by having no effect if it doesn't
458 happen to be used after a paragraph has ended.
459
460
461 \textfontii has been mentioned previously, with \textfonti.
462
463
464 \lbrace@, \rbrace@ are defined directly as delimiters, so that we can
465 have \{ and \} work in math mode or outside it.
466
467
468 \{, \} outside of math mode specify the actual font the character
469 comes from (but as \textfontii, so it can be changed by \text), and
470 we also let the \spacefactor work correctly with them. The \@sf
471 construction is taken from TB, p. 363. The \relax after \@sf is
472 needed (a digit might follow \}).
473
474
475 \lbrace, \rbrace are made synonyms for the new \} and \{.
476
477
478 \AmSTeX is now defined using \textfontii instead of math mode.
479
480
481 \vmodeerr@, \mathmodeerr@ are two error messages that we will use
482 frequently, with various arguments. For example, \vmodeerr@\linebreak
483 gives an error message about not using \linebreak between paragraphs.
484
485
486 \linebreak gives error messages unless in horizontal mode; we add an
487 \unkern in case a \kern appeared at the end of previous text (for
488 example, an \enspace at the end of a \proclaim).
489
490
491 \slash differs from in plain; a space before it is ignored.
492
493
494 **********************************************************************
495 \saveskip@ is used to record previous space, given by \lastskip,
496 before we \unskip to get rid of it (and then put it back with
497 \saveskip@). We only \hskip\saveskip@ if \saveskip@ is non-zero,
498 because a zero skip does change things---it allows breaks. Notice
499 that \saveskip@\lastskip is an abbreviation for \saveskip@=\lastskip.
500 Abbreviations of this sort are always used, and should be borne in
501 mind.
502 **********************************************************************
503
504
505 \allowlinebreak uses \saveskip@.
506
507
508 \refskip@ plays no role now; but after \Refs, in AMSPPT.STY, there
509 will be reasons to have \refskip@ in \nolinebreak.
510
511
512 \nolinebreak also uses \saveskip@.
513
514
515 \newline allows \newline\par not to give an Underfull \hbox message,
516 but it probably wasn't worth it to do this, since you can still
517 manage to get the message if you do something weird enough, like
518 \newline\newline\par. The \null keeps the \hfill from disappearing
519 at the break. Compressed format is used. Within the definition of
520 \next@, the K-method is used (for a conditional within a
521 conditional). Although this works, the K-method doesn't work in
522 general in the multi-case situation.
523
524
525 \dmatherr@, ..., \nonmatherr@ are error messages that are used
526 frequently.
527
528
529 \mathbreak, ..., \allowmathbreak are for breaks in math mode, which
530 have been arranged to require different commands than for breaks
531 outside it. The main reason for this arrangement was that LaTeX-like
532 features, like [...] to indicate desirability of a break, might
533 later be implemented for breaks outside of math. But AmS-TeX
534 definitely shies away from such use of brackets in math mode, since
535 brackets are so frequently used as text in math mode, so one
536 would want different commands (and different additional syntax to
537 indicate desirability) for math breaks.
538
539
540 \pagebreak means \removelastskip\break between paragraphs,
541 \vadjust{\break} within paragraphs (to break after current line), and
542 \postdisplaypenalty-10000 in display math (see TB, p. 189). The
543 \removelastskip is needed in case there is already a \vskip, say from
544 an \endproclaim.
545
546
547 \nopagebreak is similar.
548
549
550 \vnonvmodeerr@ is another useful error message.
551
552
553 \vnonvmode@#1#2 does #1 if in vertical mode, otherwise #2, except
554 that we are considered to be in vertical mode if a \par comes next.
555 This is because users will naturally consider certain constructions
556 to be `between' paragraphs if they stick them at the end of the
557 paragraph, just as they count as between paragraphs if they go at the
558 beginning. Compressed format is used in the definition.
559
560
561 \newpage, ..., \bigpagebreak all use \vnonvmode@.
562
563
564 \NoBlackBoxes, \BlackBoxes use capitals, to tell user they are global.
565
566
567
568 **********************************************************************
569 \Invalid@, \Invalid@@
570 ---------------------
571 Many control sequences in AmS-TeX, like \caption and \captionwidth,
572 don't have real meanings themselves, but are only indicators for
573 other control sequences to take appropriate action. \Invalid@ is
574 used to make their meaning an error message when they are encountered
575 at unexpected times. This is more than a mere convenience for the
576 user, however. If \caption, for example, were actually undefined,
577 the \ifx test involving \caption could fail for unexpected reasons,
578 including the misspelling of \caption in the input file.
579
580 Although things like \Invalid@\caption take up little room in the
581 input file, they would expand to a lot if the error message was
582 always spelled out, so we abbreviate most of the error message with
583 \Invalid@@.
584 **********************************************************************
585
586
587 \smallcaptionwidth@ is the caption width that will actually be used.
588 (It may be smaller than \captionwidth@ if the caption is not that wide.)
589
590
591 \topspace and \midspace are defined together, like \topinsert and
592 \midinsert of plain, using a flag \ifmid@. The definition is made in
593 terms of \ins@, which is similar to plain's \@ins.
594
595
596 \captionfont@ is the font used for captions; it is inserted here so
597 that style files that want a different font for captions can simply
598 redefine \captionfont@, instead of redefining \ins@, which follows.
599
600
601 \ins@ saves its argument as \thespace@, and looks ahead (skipping
602 spaces) for \caption, with its argument saved as \thecaption@, and
603 then for \captionwidth, with its argument saved as
604 \smallcaptionwidth@ (initially set to \captionwidth@). An additional
605 complication occurs because we have to skip over spaces after the }
606 at the end of \caption{...} or \captionwidth{...}. The caption is
607 set in a box, and centered within \smallcaptionwidth@ if smaller than
608 this amount, otherwise reset into a paragraph of this \hsize. The
609 \allowbreak is specifically introduced because we have no reason not
610 to allow a break before the insert, and this \allowbreak may help TeX
611 to find the best placement. [Cf. TB, p. 116: ``There is a slight
612 .... processing text ahead of the current page. You may want to say
613 `\goodbreak' just before \midinsert.'' The point is that \allowbreak
614 in the definition is much better, because it causes TeX to see if a
615 page break is feasible, so a break will definitely be taken if it has
616 already processed too much for the current page.] Compressed format is
617 used.
618
619
620 \def\newcodes@ ...
621 ------------------
622 Next comes the mechanism for \comment ... \endcomment. There are
623 probably some unnecessary things here, left over from the old TeX,
624 since we now use \futurelet, rather than a macro argument, to see
625 what's coming, but it works, so why fool with it.
626
627
628 Now we start on math constructions.
629
630
631 \def\pr@m@s ...
632 ---------------
633 \pr@m@s is changed from plain (TB, p. 357), because we don't want the
634 '^ mechanism to work (since you can't get ^' to work similarly). We
635 also surround the prime character with empty boxes to make sure there
636 is no extra kerning around it---this character does kern with
637 characters on the symbol font, because it is the \skewchar for its
638 font and the kern contains information for the math accents (TB, pp.
639 351 and 443). The whole construction is put inside another group, so
640 that ^\prime will still work.
641
642
643 \let\dsize ...
644 --------------
645 Now we set up AmS-TeX alternate names, and also allow \, and \! and
646 \; to be used both in math mode and in text. There is an important
647 reason for doing this, besides mere convenience: \, or \; might be
648 used within a \format...\\ line for a \matrix (see below) to specify
649 spacing. Although the user would naturally think that this spacing
650 is in math mode, it actually isn't! We also make plain's \thinspace
651 and \negthinspace the same as \, and \! respectively, for maximum
652 consistency. Since plain's \> is almost never used we make it
653 undefined (at the end), and provide \medspace instead. So we also
654 add \negmedspace and \thickspace and \negthickspace.
655
656
657 @, and @! will be 1/10 of \, and \! in math mode.
658
659
660 @. is special in math mode, because it leaves a blank space where a
661 horizontal arrow should go in commutative diagrams (see \CD below).
662
663
664 \and, \implies, \impliedby are similar to plain's \iff; the \DOTSB
665 are added so that \dots will know they are binary operators (see
666 \dots, later).
667
668
669 \frac, ..., \tfrac should be obvious.
670
671
672 \ex@ is a dimension that is essentially 1 point, but that will change
673 properly with changes of fonts. For cmr10, .2326ex is 1pt.
674
675
676 \thickness is one of the syntax pieces \thickfrac looks for.
677
678
679 \thickfrac, if followed by \thickness{<number>}, should make a
680 fraction made with \above <number>\ex@. Otherwise, we want to use
681 \above 1\ex@ (i.e., 1 point) for the thickness.
682
683
684 \fracwithdelims, \thickfracwithdelims are strictly analogous.
685
686
687 \binom, ..., \tbinom should be obvious.
688
689
690 \: is for constructions like f:A --> B. Spacing was specified by AMS.
691 The symbol before the \: could be a \mathbin or \mathrel (e.g.,
692 +\:R\times R\to R or <\:R\times R\to\{T,F\}), or even a \mathop
693 (e.g., \sum\:2^R\to R). In all cases, it should be replaced by a
694 \mathord, so far as the spacing in this formula is concerned. There
695 is naturally no way that we can get back to the symbol preceding \:
696 so we first put in a \mathpunct{}. The spacing between a \mathop or
697 \mathrel and a \mathpunct is 0, and when a \mathbin precedes a
698 \mathpunct, it is changed to a \mathord, so the spacing is again 0.
699 Then, since the spacing between the \mathpunct{} and the \mathord {:}
700 that we want to add is \nonscript\mskip\thinmuskip, we want to
701 subtract this space before the {:}.
702
703
704 \snug deletes the \mathsurround space, so that $n$\snug- won't have
705 space between the n and the - even if \mathsurround is non-zero.
706
707
708 \topsmash and \botsmash are needed in addition to just \smash from
709 plain. We use a procedure similar to that used in plain for
710 \phantom, which has the variants \hphantom and \vphantom (TB, p.
711 360); we use much of the plain mechanism for \smash (TB, p. 360),
712 using flags \iftop@, \ifbot@, mainly changing \finsm@sh. We also
713 add \leavevmode before the \box\z@, in case this comes at the
714 beginning of a paragraph.
715
716
717 \def\LimitsOnSums ...
718 ---------------------
719 Now we come to the modifications for the big operators like \sum. In
720 each case we introduce a subsidiary name for the operator, and then
721 the definition has this name followed by \slimits@, which will be
722 equivalent to either \displaylimits or \nolimits, depending on the
723 style. We also introduce \LimitsOnSums and \NoLimitsOnSums to allow
724 the user to set the value of \slimits@. The default is \LimitsOnSums.
725 The \DOTSB are added for the sake of \dots, as explained later.
726
727
728 \def\LimitsOnInts ...
729 ---------------------
730 \int and \oint are treated similarly, using \ilimits@, except that
731 \intop and \ointop are already available from plain, to have
732 \ilimits@ after them. We introduce \LimitsOnInts and \NoLimitsOnInts
733 to allow the user to set the value of \ilimits@. The default is
734 \NoLimitsOnInts. We also use \DOTSI, which is explained later.
735
736
737 \def\intic@ ...
738 ---------------
739 Next come multiple integrals. The main problem here is the proper
740 positioning of a limit when limits are set above and below. For
741 example, with \iint (double integral sign), the lower limit should be
742 centered between the bottoms of the two integral signs, not centered
743 in the whole region they make up. In such cases we basically need
744
745 \hskip-.5em\mathop{\hskip.5em\intop\intop}\limits
746
747 ---the \hskip.5em on the left of the two integral signs places the
748 center of this symbol in the right place, and the \hskip-.5em
749 corrects for it. (For a different font than cmex10, .5em might have
750 to be changed.)
751
752 A different correction is needed when we are not in \displaystyle, so
753 \intic@, the proper correction, is defined as a \mathchoice. The
754 negative amounts are stored in \negintic@, another \mathchoice, since
755 it seems nearly impossible to get out the negatives of dimensions
756 stored in a \mathchoice.
757
758 We also need to move the integral signs closer together, by an amount
759 stored in \intkern@, also a \mathchoice.
760
761 Finally, the dots to be used in \idotsint (two integral signs
762 separated by dots) are defined in \intdots@, again a \mathchoice.
763 This uses \plaincdots@, defined later, which is basically \cdots as
764 in plain (\cdots itself will be redefined later also).
765
766
767 \newcount\intno@ ...
768 --------------------
769 To define all multiple integrals together, we store the number of
770 integral signs in \intno@ (with \intno@ arbitrarily set to 0 for
771 \idotsint), and then use \ints@ after a \futurelet construction,
772 which is needed to see if \limits or \nolimits happened to have been
773 typed after the control sequence.
774
775
776 \def\ints@
777 ----------
778 \ints@ first calls \findlimits@, which uses \iflimits@ to record
779 whether or not limits should be used. Limits are used if the next
780 token is \limits, or if \ilimits@ is set to \displaylimits and we are
781 in displaystyle and the next token is not \nolimits. We also use
782 \iflimtoken@ to record whether or not the next token was either
783 \limits or \nolimits---we need this information, since we will have
784 to \eat@ the \limits or \nolimits token if it occurs.
785
786
787 \multint@ and \multintlimits@ produce the basic symbol---the proper
788 number of integral signs, dots and spacing---based on \intno@.
789
790 %1 If we are making \intdotsint, put in the dots.
791 %2 Otherwise, put in kern before next integral sign.
792 %3 If \intno@ >= 3, add second kern and int.
793 %4 If \intno@ =4, add third kern and int.
794 %5 Then add final int sign.
795
796 \multintlimits@ uses \intop, because the result will be put inside a
797 \mathop later.
798
799
800 \ints@@, finally, uses \multint@ or a construction involving
801 \multinlimits@ for the final result, which also depends on the value
802 of \iflimtoken@.
803
804 %1 If there was a \limits or \nolimits afterwards:
805 %2 when we are using limits, use a special construction,
806 %3 but when we're not, use the simple construction;
807 %4 and then discard the \limits or \nolimits token.
808 %5 Otherwise, do the same thing, but don't discard the next token.
809
810
811 \def\LimitsOnNames ...
812 ----------------------
813 We also have \nlimits@ to tell whether limits should be used on
814 operator names, like \max and \min. We introduce \LimitsOnNames and
815 \NoLimitsOnNames. The default is \LimitsOnNames.
816
817
818 \def\nolimits@
819 --------------
820 Certain operator names, like \sin, should NEVER have limits, even if
821 \limits has been typed afterwards, so instead of \nolimits we use
822 \nolimits@, which replaces a \limits token that follows with
823 \nolimits. Compressed format is used in that definition.
824
825
826 \def\newmcodes@
827 ---------------
828 When we make a new operator, with \operatorname or
829 \operatornamewithlimits, we want ' and * and - and / to be treated as
830 ordinary text, not as math symbols. The same is true for . and :
831 except that we would like a little space after them, so we have
832 \newmcodes@ to temporarily change the \mathcode's of these symbols.
833
834
835 \operatorname and \operatornamewithlimits both make \mathop's, using
836 the new \mathocode's from \newmcodes@. \operatorname has \nolimits@
837 at the end, to defeat any \limits typed after it, while
838 \operatornamewithlimits simply has \nlimits@, which will be set
839 either to \displaylimits or \nolimits@, depending on the style. The
840 \kern 0pt is added because the argument might be just one symbol, and
841 TeX's rules (TB, p. 443) imply that this symbol would be centered
842 vertically around the axis.
843
844 In all cases we use \fam\z@ instead of plain's \rm, since we will
845 later change the meaning of \rm.
846
847
848 \qopname@ and \qopnamewl@ are quick constructions, used to redefine
849 \sin, \cos, etc., to have either \nlimits@ or \nolimits@ after them.
850
851
852 \def\arccos, ..., \def\tanh redefine things using \qopname@ and
853 \qopnamewl@.
854
855 \inflim and \projlim are new; they are not in plain.
856
857
858 \varinjlim, ..., \varlimsup are more complicated. Adjustments for
859 \varinjlim, \varprojlim and \varliminf were made by eye. We don't
860 bother about making these change size in subscripts, since they
861 should never be used that way---the symbols would be too cramped to
862 see. Notice that the \rm before the lim is NOT being used in math mode,
863 so it is OK.
864
865
866 \newdimen\buffer@ ...
867 ---------------------
868 \ChangeBuffer allows the user to change \fontdimen13 \tenex. Since
869 changes to \fontdimen's are global, the only way to allow the user to
870 restore the original value, with \ResetBuffer, is to keep it in an
871 inaccessible place, \buffer@. We also want \buffer as a place to
872 store the current value of \fontdimen13 \tenex, since it is used in
873 \shave and its relatives; the user is also supposed to be able to
874 access \buffer, so it has no @.
875
876
877 \def\shave ...
878 --------------
879 To shave the buffer space off the top and bottom of a symbol like
880 \sum_{i=1}^n, we reset it with \fontdimen13 \tenex = 0pt, make a
881 \mathop of this new symbol, and then reset \fontdimen13 to current
882 value, stored in \buffer. To shave off the top buffer space only, we
883 \topsmash the symbol, which leaves the bottom buffer space alone, add
884 \vphantom{\shave{#1}} to get the right height, and make a \mathop of
885 the whole thing.
886
887 %1 We need \m@th from plain to shut off any \mathsurround. \m@th is
888 used similarly in many places, without further comment.
889
890 \Invalid@\\
891 -----------
892 The \Sp...\endSp and \Sb...\endSb constructions, for multiline
893 limits, is the first of many constructions based on \halign where we
894 want to use \\ for line breaks, instead of the usual TeX primitive
895 \cr.
896
897 **********************************************************************
898 \def\Let@
899 ---------
900 This involves a TeXnical trick. In such constructions, we want to
901 say \let\\=\cr. [Note that we want a \let here, and not simply
902 \def\\{\cr}, because there is a big difference between a control
903 sequence defined to be \cr, and \cr itself or something \let=\cr: a
904 \cr (or & or \span) is immediately intercepted by TeX's scanner even
905 when it is not expanding macros (TB, p. 248), while something defined
906 as \cr will not indicate the end of a row until macros are expanded
907 out. We will mention later one of the problems this can cause.]
908
909 But if we happen to use \let\\=\cr within another such construction,
910 as we certainly will want to do, then \\ will already be equivalent
911 to \cr, and because of the way TeX parses things in an \halign, this
912 \\ will immediately be used to stop the scanning of the element,
913 leaving \let all by itself somewhere, and horrible error messages.
914 As explained in TB, p. 386, the construction
915
916 \iffalse{\fi\let\\=\cr\iffalse}\fi
917
918 circumvents this difficulty, because the { } hide the \let\\=\cr from
919 the \halign, yet doesn't actually put it inside a group. Of course we
920 need \relax first, in case this occurs at the beginning of an \halign
921 (TB, p. 240). Since this is used so often, we have a special
922 abbreviation for it.
923 **********************************************************************
924
925
926 \Invalid@\vspace, \def\vspace@
927 ------------------------------
928 We want \vspace to be used only within certain constructions (all
929 based on \halign). So we make it invalid in general, and let these
930 constructions give the proper definition of \vspace. Since this
931 happens so often, we abbreviate the definition of \vspace. We add
932 \crcr before the \noalign in case the user forgets the \\.
933
934
935 \def\multilimits@, ..., \def\endSp
936 ----------------------------------
937 \Sb...\endSb and \Sp...\endSp will translate to ^{...} and _{...} for
938 the very same construction {...}, which we call \multilimits@.
939
940 This \multilimits@ construction is similar to many other
941 constructions, like those for \matrix, \align, etc. We begin with
942 \bgroup, which is almost like {, except that the matching \egroup,
943 which is almost like }, needn't be in the same definition, but can
944 actually be contributed by the \endSb or \endSp; then we define
945 \vspace for use within this construction, and then we properly make
946 \\ the same as \cr.
947
948 Then comes something special. We want to get the same result from
949 \Sb i\\ j\endSb as we would get with _{\scriptstyle i\atop
950 \scriptstyle j}. The rules for making an \atop are somewhat
951 complicated. They are stated in TB, p. 444, rule 15. For \atop, we
952 have the parameters u=\fontdimen10 of the relevant math italic font,
953 \scriptfont2; v=\fontdimen12 \scriptfont2; and phi=3\fontdimen8 of
954 the corresponding symbol font, \scriptfont3. \atop is normally set
955 with the numerator moved up by u and the denominator moved down by v,
956 i.e., with \baselineskip=u+v. But if this makes them less than phi
957 apart, they are set phi apart. This will be obtained by making
958 \lineskiplimit and \lineskip equal to phi.
959
960
961 \def\spreadlines
962 ----------------
963 \Sp and \Sb are special sorts of alignments, but now we start the
964 main ones. First of all, we want \spreadlines to be like \openup,
965 except for consistency we want it to work as a macro taking an
966 argument, rather than using the TeX assignment syntax. Also we want
967 it to be used only in display mathematics; this means, in particular,
968 that its effect will always be local to the display in which it
969 appears.
970
971
972 \def\Mathstrut@...
973 ------------------
974 \Mathstrut@ is like \mathstrut, but only for \textstyle, the style we
975 will be using it for in all our alignments. Whenever you trace
976 through macros that involve \mathstrut, you get screens full of
977 uninteresting stuff; it got so depressing that I decided to make
978 \Mathstrut@ instead. We first make \Mathstrutbox@ an empty box, but
979 with height and depth set to that of a ( in math mode.
980
981
982 \newdimen\spreadmlines@ ...
983 ---------------------------
984 In plain TeX, \matrix uses \normalbaselines to overrule any \openup's
985 that have been used. We want to have a more general way of adjusting
986 the spacing in a \matrix also. So we use \spreadmlines@ to store the
987 desired amount to \openup in a \matrix. Like \spreadlines,
988 \spreadmatrixlines should be used only in displayed mathematics; thus
989 it will be local to the display in which it appears.
990
991
992 \matrix is very much like \multilimits@, used before. However, now
993 there are two \bgroups, corresponding to the {'s for \vcenter{ and
994 \halign{; and \endmatrix contributes two \egroups. The combination
995 \normalbaselines\openup\spreadmlines@ means that the \baselineskip is
996 the normal one, unless \spreadmlines has been used (within the
997 display the \matrix appears in) to change things. The effect of
998 \Mathstrut@\crcr\noalign{\kern-\baselineskip} in \matrix is to insure
999 that the first row is as tall as \Mathstrut@, and the one in
1000 \endmatrix makes the last row as deep. The purpose of this is to make
1001 sure that the height or depth of a matrix won't depend, for example,
1002 on whether the first row has tall letters, like A, or only short
1003 ones, like x --- so two similar matrices will usually line up right
1004 in formulas like <matrix1> = <matrix2>.
1005
1006 There are two other new features. First, we put \, around the
1007 \vcenter; this looks better, especially with delimiters. The second
1008 feature is the \null before the first \, This is because of the rule
1009 regarding numbered formulas on TB, p. 189---if a very wide \matrix is
1010 used in a formula with a \tag, we don't want TeX to assume that we
1011 put glue before the \matrix in order to control its positioning with
1012 respect to that tag!
1013
1014
1015 \format...\\ is the construction that is used to allow a different
1016 preamble to be used in the \matrix. In all other AmS-TeX
1017 constructions, where such optional syntax is used, we use a
1018 \futurelet to see if this syntax is present. But it would be fatal
1019 to
1020
1021 \def\matrix{\futurelet\next\matrix@}
1022
1023 because the \matrix might be used within another \matrix, and a \let
1024 within an \halign can cause havoc. This is hinted at in the
1025 next-to-last paragraph of TB, p. 248, although the viewpoint is
1026 different. The real problem arises when you have a \matrix
1027 containing another \matrix that happens to begin with & (because the
1028 first entry is blank). Just what does happen is complicated and
1029 interesting, but there's no point going into it here, since we are
1030 not going to be using a \futurelet. What we do instead is simply let
1031 \format end the \matrix (giving an empty matrix), and then start a
1032 new \matrix, with the appropriate preamble.
1033
1034 **********************************************************************
1035 However, at this point we have to pull another TeXnical trick,
1036 somewhat like the one for \Let@, but different (see TB, p. 385). The
1037 construction
1038
1039 \iffalse{\fi\ifnum`}=0 \fi
1040
1041 has balanced braces, so can appear within a \def. The same is true of
1042
1043 \ifnum`{=0 \fi\iffalse}\fi.
1044
1045 As far as \halign is concerned, however, the first begins a group and
1046 the second ends one, so \format ... \\ looks to \halign like
1047
1048 \crcr\egroup [begin a new group] \format@ ...\\
1049
1050 and thus as
1051
1052 \crcr\egroup [begin a new group]
1053 make definitions [end the group] ...
1054
1055 This is important, since otherwise the \\ will be interpreted as \cr
1056 if the \matrix is inside another \matrix, leading to havoc.
1057 **********************************************************************
1058
1059
1060 \newtoks\hashtoks@, ..., \def\format@
1061 -------------------------------------
1062 Having circumvented this difficulty, the idea is that \l&\r\\, for
1063 example, should be interpreted as $#$\hfil&\hfil$#$. Since #'s can
1064 usually appear only in special constructions, we want them to pop up
1065 as tokens, so we make a new token \hashtoks@ whose value is #. Then,
1066 if we define \preamble@ to be \l&\r, and define \l as
1067 {$\the\hashtoks@$\hfil}, etc., we can \edef\Preamble@{\preamble@} and
1068 \Preamble@ will have the desired result.
1069
1070 Once the desired preamble is stored in \Preamble@, we still have to
1071 say \span\Preamble@ to have it be expanded (TB, p. 238, last two
1072 paragraphs). Notice that the \span\Preamble@ construction works when
1073 it is being used within a \def, even though we have single #'s
1074 instead of ##'s (normally an \halign within a \def needs ##'s instead
1075 of #'s). By the way, \show\hashtoks@ will actually give the result
1076 `##', but this is due to TeX's convention for printing token lists,
1077 see TB, p. 205, Exercise 20.7.
1078
1079
1080 \smallmatrix is a lot simpler, since we don't allow \spreadmlines,
1081 but essentially use \baselineskip=9pt (suitably adjusted using \ex@),
1082 don't worry about correcting the height of the first line or the
1083 depth of the last (since \smallmatrix'es aren't meant to be used
1084 together in formulas), and don't allow \format.
1085
1086
1087 \pmatrix, etc., are trivial.
1088
1089
1090 \hdots, for use within a \matrix, is plain's \ldots (which we change
1091 later).
1092
1093
1094 \newmuskip\dotsspace@
1095 ---------------------
1096 The spacing in the \spacehdots...\for... macro will be a new mu-unit
1097 \dotsspace@, which we set to 1.5mu.
1098
1099
1100 \def\strip@, ..., \def\hdotsfor
1101 -------------------------------
1102 \spacehdots#1\for#2 macro should normally be used as
1103
1104 \spacehdots<number1>\for<number2>
1105
1106 but it's quite conceivable that someone will type
1107
1108 \spacehdots{<number>}\for...
1109
1110 even though the braces are unnecessary; in such a case TeX will
1111 actually consider the first argument to be {<number>}. So we don't
1112 want to specify the spacing simply as \mkern#1\dotsspace@, since this
1113 will be a syntactical error if #1 has braces around it. The macro
1114 \strip@ solves this problem. When argument #1 of \spacehdots is
1115 passed to \strip@, the braces are removed, but the space that
1116 delimits the argument is explicitly added. So if #1 is `3' or `{3}'
1117 or `{3 }' then we end up with `\strip@3 ' or possibly
1118 `\strip@3|_||_|' so we finally get `3\dotsspace@' or `3 \dotsspace@'.
1119
1120
1121 \multispan@ is just like \multispan from plain (TB, p. 243), except
1122 that we have an \unskip so that & \spaceinnerhdots ... will ignore
1123 the space after the &.
1124
1125
1126 \spaceinnerhdots needs the \strip@ trick for #2 also, since braces in
1127 \mscount={<number>} would be an error.
1128
1129
1130 \cases is easy since it is just made up of a \matrix, with a particular
1131 \format; we also want to \spreadmlines@\jot, and we put this inside a
1132 group, so that it will effect only the \cases, not another \matrix in the
1133 display.
1134
1135
1136 \newif\ifinany@
1137 ---------------
1138 The line spacing in \aligned, \alignedat, \gathered, and \split is
1139 different from that in \matrix, because we want to \openup\jot. The
1140 problem, however, is that any of these might occur within one of the
1141 constructions \align, \alignat, \xalignat, \xxalignat, \gather,
1142 \multline, which already \openup\jot. So we need a flag, \ifinany@, to
1143 tell whether the construction is in any of these.
1144
1145
1146 \newif\ifinalign@
1147 -----------------
1148 For the purpose of deciding whether to \openup\jot, we also need a
1149 flag, \ifinalign@, to tell \split whether or not it is in an \align.
1150
1151
1152 \newif\ifingather@
1153 ------------------
1154 Finally, because we allow a very special construction where \align
1155 appears in \gather (but within curly braces), we also need a flag,
1156 \ifingather@, to tell \align whether or not it is in a \gather.
1157
1158
1159 \strut@ is used as a quicker alternative for \strut, just as
1160 \Mathstrut@ was introduced as a shorter alternative to \mathstrut.
1161 We use \copy\strutbox@ rather than \unhcopy\strutbox@, because we
1162 will be using \strut@ in situations where we don't have to worry
1163 about entering horizontal mode. The dimensions of \strutbox@
1164 are determined by taking the baselineskip (we assume 12pt)
1165 and subtracting the lineskiplimit (1pt, set in AMSPPT.STY).
1166
1167
1168 \topaligned, \botaligned, and \aligned are practically the same, the
1169 first being a \vtop, the second a \vbox, and the third a \vcenter.
1170
1171
1172 \aligned@ is similar to \matrix, except we \openup\jot if we are not
1173 in a construction that sets \inany@true. Note that we put \strut@ in
1174 every line, since this is actually easier than putting it in only the
1175 first and last lines, and won't make any difference because of the
1176 \openup\jot. The main purpose of the \strut@'s in all the following
1177 constructions is so that when some of them are placed vertically
1178 above others (as they will be by certain other constructions) the
1179 spacing will still be correct. (Actually, the spacing won't always
1180 be exactly correct, if some lines contain extra tall or deep
1181 characters, but the discrepancies will be small, and in these cases
1182 one often has to add some extra spacing by hand anyway.)
1183
1184
1185 \alignedat is similar to \aligned, except that the preamble depends
1186 on the argument; we use \doat@ to produce this preamble, as
1187 \preamble@@, which we then reproduce, using \span\preamble@@.
1188
1189
1190 \newcount\atcount@, \def\doat@
1191 ------------------------------
1192 \doat@, with argument n, first makes the token list \toks@ be
1193
1194 \hfil\strut@$\displaystyle{\the\hashtoks@}$&
1195 $\displaystyle{{}\the\hashtoks@}$\hfil
1196
1197 and then adds another n-1 copies of
1198
1199 &\hfil$\displaystyle{\the\hashtoks@}$&
1200 $\displaystyle{{}\the\hashtoks@}$\hfil
1201
1202 (the \strut@ isn't needed for these copies, only for the first one),
1203 using the method of TB, p. 373. This involves a \loop, and we use
1204 the counter \atcount@ to keep track of the number of iterations. If
1205 we then \xdef\preamble@{\the\toks@}, the resulting \preamble@ isn't
1206 yet the desired result, since we have \the\hashtoks@ appearing
1207 everywhere that # should appear, so we \xdef\preamble@@{\preamble@}
1208 to get the right result in \preamble@@.
1209
1210 %1 Initialize \toks@.
1211 %2 Set \atcount@ to 1 less than #1.
1212 %3 Add \atcount@ copies of the other tokens.
1213
1214
1215 \gathered is much easier.
1216
1217
1218 This completes the aligned constructions that are treated as
1219 individual symbols, but leaves things like \align, in which each
1220 formula can have a \tag. So first we have to deal with \tag itself.
1221
1222
1223 \newif\iftagsleft@ ...
1224 ----------------------
1225 Basically, \tag is supposed to mean \leqno or \eqno, depending on
1226 whether the flag \iftagsleft@ has been set. \TagsOnLeft sets
1227 \tagsleft@true, \TagsOnRight sets \tagsleft@false. The default is
1228 \TagsOnLeft. It seems reasonable to make these global, so their
1229 names have capitals in them.
1230
1231
1232 \newif\ifmathtags@ ...
1233 ----------------------
1234 \tag has another slight problem, because \eqno and \leqno treat their
1235 arguments as math formulas, which isn't convenient when - is used as
1236 a hyphen; normally, it is better to have the argument treated as
1237 text. We will allow the argument to be treated both ways, depending
1238 on the flag \ifmathtags@. \TagsAsMath sets \mathtags@true, while
1239 \TagsAsText sets \mathtags@false, with the default being
1240 \TagsAsText. Again it seems reasonable to make these global, so
1241 their names have capitals in them.
1242
1243
1244 \tagform@ describes the formatting of tags desired by the style (more
1245 precisely the formatting desired when tags are treated as text). The
1246 default is to put tags in parentheses.
1247
1248 [NOTE: TeX puts an \eqno or \leqno on a separate line unless the space
1249 between the tag and the formula is at least as wide as the tag
1250 itself, i.e., the formula plus a box twice the width of the tag
1251 should fit on the line. By diddling with \tagform@, this rule could
1252 be changed. For example, if the rule is that the space between the
1253 tag and the formula should be at least 1em (seems to be used by
1254 Cambridge University Press) we could
1255
1256 \def\tagform@#1{\setbox0\hbox{\rm(\ignorespaces#1\unskip)}%
1257 \dimen0=\wd0 \advance\dimen0 1em \divide\dimen0 by 2
1258 \wd0=\dimen0 \box0 }
1259
1260 Then twice the width of \tagform@{#1} would be the `real' width of
1261 the tag plus 1em.]
1262
1263
1264 \thetag allows a fastidious user who wants to refer to `equation (3)',
1265 without being sure whether the style will use this particular format,
1266 to do so by typing `equation \thetag3'; the definition of \thetag has
1267 \leavevmode at the beginning, since \tagform@ is often an \hbox, and
1268 might begin a paragraph.
1269
1270
1271 \def\tag, \def\maketag@, ...
1272 ----------------------------
1273 Finally, given a displayed formula $$ .... \tag ...$$, \tag has to be
1274 replaced by \leqno or \eqno, and ... has to be replaced by the proper
1275 formatting for this expression. The argument ... is everything from
1276 \tag to $$.
1277
1278 \maketag@#1\maketag@ is basically just \tagform@{#1} (if tags are
1279 treated as text), but we also provide a mechanism for overriding the
1280 default formatting, by typing \tag "..." to get ... as the tag,
1281 exactly as typed. (This fits in with the scheme used in AMSPPT.STY
1282 for `literal' arguments to \footnote and \item in \roster's.)
1283 Compressed format isn't used since \tag's are used so often.
1284
1285 %1 Let \tag be \leqno or \eqno.
1286 %2 Replace #1 by \maketag@#1\maketag@.
1287 %3 Finish off the displayed formula.
1288
1289 %1 Here #2 is a possible space after the second " symbol; this
1290 possible space is the reason for using the syntax where the
1291 argument is delimited by a second \maketag@.
1292
1293
1294 \interdisplaylinepenalty from plain is used as a counter to store
1295 penalties for page breaks in alignments, but is initially set to
1296 10000, thus completely inhibiting such breaks.
1297
1298
1299 \allowdisplaybreaks should be used only within a displayed formula to
1300 set \interdisplaylinepenalty to 0 (perhaps a value like plain's 100
1301 would be better).
1302
1303
1304 \Invalid@\allowdisplaybreak, ..., \def\displaybreak@
1305 ----------------------------------------------------
1306 We also want to use \allowdisplaybreak and \displaybreak to allow or
1307 force a break after a particular line of an alignment, but we want
1308 these control symbols to make sense only within these alignments, so
1309 we handle them like \vspace, etc.
1310
1311
1312 \Invalid@\intertext, \def\intertext@
1313 ------------------------------------
1314 We want \intertext to produce \noalign'ed text, and again want this
1315 to make sense only with these alignments. The problem here is that
1316 when more than one line of text is produced, the height of the \vbox
1317 will be so large that only \lineskip glue would be used, not the
1318 proper amount to make the baseline of the first line of the \vbox the
1319 proper distance from the previous line. So instead of
1320 \vbox{\noindent##1} we use
1321
1322 \vbox{\null\noindent##1}
1323
1324 Within this \vbox, the glue between the \null and the \noindent'ed
1325 paragraph will be just enough to make the space between the \null and
1326 the top line of the \vbox be \baselineskip. So we just have to put
1327 the \vbox on the list preceded by \nointerlineskip, to suppress any
1328 extra space.
1329
1330
1331 \centering@ is like plain's \centering, except that no shrinking of
1332 glue will be allowed, because we will regard such cases as overfull
1333 boxes that will either give error messages or be treated specially.
1334
1335
1336 \def\align
1337 ----------
1338 $$\align... will essentially be an
1339
1340 $$\halign to\displaywidth{...
1341
1342 unlike $$\aligned... which is essentially
1343
1344 $$\vcenter{\halign{ ... .
1345
1346 Since the construction \halign to\displaywidth... without $$ at the
1347 beginning is actually allowed in TeX, but is quite different, we want
1348 to guard against errors by having \align give an error message if it
1349 is not being used within a displayed formula. However, we do allow
1350 the special construction {\align...\endalign} within a \gather. So
1351 we have \align give one construction in a \gather, but \align@ in
1352 display math mode, and an error message otherwise.
1353
1354 **********************************************************************
1355 There is a special problem with \align, which has \endalign as part
1356 of its syntax, and so will all similar constructions. Basically,
1357 \align@ is supposed to call one control sequence, originally called
1358 \lalign@, if tags are on the left, another control sequence,
1359 originally called \ralign@, if tags are on the right, and yet a third
1360 control sequence, originally called \galign@, when it is in a
1361 \gather. Moreover, orginally these choices were made by setting
1362 \let\next@\lalign@, etc., and calling \next@. But if the user typed
1363 $$\align ... $$ without the \endalign, then at the end of the
1364 paragraph there would be an error message
1365
1366 ! Paragraph ended before \next@ was complete.
1367
1368 which is totally incomprehensible (and the same for all such
1369 constructions). So, first of all, in such cases we use \def\next@
1370 instead of \let\next@. Moreover, we want the control sequence
1371 appearing in the error message to be known to the user. We will use
1372
1373 \csname align \endcsname
1374
1375 as a substitute for \lalign@, which shows up on the screen as \align
1376 with only one extra space, and
1377
1378 \csname align \space\endcsname
1379
1380 as a substitute for \ralign@, which shows up with two extra spaces.
1381 For the special case of \align with \gather, we use
1382
1383 \csname align (in \expandafter\eat@\string\\gather)\endcsname
1384
1385 which just shows up as
1386
1387 \align (in \gather)
1388
1389 (This happens to bomb in the special case
1390
1391 $$\gather {\align }\endgather$$
1392
1393 with nothing on either side of the {\align}, but seems to work in
1394 most reasonable cases.)
1395 **********************************************************************
1396
1397 In the definition of \align we \let\next@\align@, since \align@ will
1398 then call the other control sequences.
1399
1400
1401 \newhelp\andhelp@, ..., \def\align@
1402 -----------------------------------
1403 \align@ will set the flags \ifinalign@ and \ifinany@, and properly
1404 define \vspace, \allowdisplaybreak, \displaybreak, and \intertext.
1405 It will reduce to \align|_| when tags are on the left, otherwise
1406 \align|_||_|. These latter will essentially be \halign's, with two
1407 &'s per line; a line `lhs & =rhs \tag 3' will really be `lhs & =rhs &
1408 3'.
1409
1410 In the special case of `lhs \tag 3', however, this line must become
1411 `lhs && 3'. So we will use a counter \and@ to record the number of
1412 &'s in the current line, and define \tag in terms of this number
1413 (\everycr will be used to set \and@ back to 0 at the beginning of
1414 each line).
1415
1416 Moreover, if the user types `lhs &= rhs &= rhs', with or without a
1417 following \tag, then we want a more informative error message than
1418 `Misplaced alignment tab'. So we will let \tag set a flag \iftag@
1419 (with \everycr setting \tag@false), and have the tag part of the
1420 preamble give an error message if the flag hasn't been set. An extra
1421 & in a row will usually lead to chaos, and there's no point relying
1422 on TeX's decision to change the & to \cr; so we make the message
1423 strong, and add a help message, reiterating this.
1424
1425 It is important to note that because we are \def'ing \tag to be
1426 something, and not simply \let'ing \tag=&, TeX's scanning mechanism
1427 would generally not properly intercept these hidden &'s as needed.
1428 Fortunately, that isn't a problem in this case, because the first two
1429 parts of the preambles for \measure@ and \align|_| and \align|_||_|
1430 do not involve # as an argument to a macro; so TeX isn't swallowing
1431 tokens blindly as it reads in the first two elements of each row of
1432 the \halign.
1433
1434
1435 \def\Tag@, ..., \def\measure@
1436 -----------------------------
1437 A whole new level of complication for \align is introduced by the
1438 fact that we want a tag automatically to be set on a separate line if
1439 it needs to be. There is no way to figure this out on a line-by-line
1440 basis, because the position of a line is influenced by all the other
1441 lines. So we will first `\measure@' our \align, to obtain three
1442 quantities: \maxlwidth@, the maximum length of the left hand side of
1443 all lines; \maxrwidth@, the maximum length of the right hand side of
1444 all lines; and \totwidth@ = \maxlwidth@ + \maxrwidth@.
1445
1446 As we proceed through the lines, \lwidth@ and \rwidth@ will be used
1447 for the left hand length and right hand length of the current line.
1448 We apply \measure@ to everything up to the \endalign.
1449
1450 Since \measure@ is used before anything else, we must catch the error
1451 of an extra & at that point. For convenience later on (in defining
1452 \alignat and \xalignat), we abbreviate the construction that
1453 supplies the error message, as \Tag@.
1454
1455 %1 Initialize widths and \and@ to 0pt.
1456 %2 We just set a box, which we will not use.
1457 %3 We set \tag@false and reset \and@ to 0 at each \\ (which is
1458 \let=\cr); \global needed since \noalign material is in
1459 restricted vertical mode.
1460
1461 %4 Each left hand side is just set in \displaystyle. \@lign is required
1462 to make sure that if any such formula involves an \halign, the current
1463 \everycr won't affect it.
1464
1465 %5 Store width of entry in \lwidth@; \global needed since each entry
1466 is essentially in its own group.
1467
1468 %6 \maxlwidth@ is always largest of the \lwidth@'s found so far.
1469
1470 %7 \and@ will be 1 at next entry.
1471
1472 %8 \@lign needed here, as in %4.
1473
1474 %9 Treat the right hand side similarly, getting maximum in
1475 \maxrwidth@.
1476
1477 %10 \and@ will be 2 at next entry.
1478
1479 %11 The second &, if it is supplied by \tag, will simply throw away
1480 the tag. But if it wasn't supplied by \tag, it will give an
1481 error message.
1482
1483 %11 Finally, make \totwidth@ = \maxlwidth@ + \maxrwidth@.
1484
1485
1486 **********************************************************************
1487 WARNING: Because \align processes its argument twice, you have to be
1488 careful if you are using an ad hoc construction in the form of a \box
1489 that just been set. This box must be used as \copy, rather than as
1490 \box, or it will be emptied out by the time \measure@ has gotten
1491 through with it!
1492 **********************************************************************
1493
1494
1495 \displ@y@ is just like plain's \displ@y, except that it also sets
1496 \and@ to 0 and \tag@false at each \cr (we need the \tag@false for
1497 certain later constructions, even though \align no longer needs it).
1498
1499
1500 \def\black@
1501 -----------
1502 Alignments do not show an overfull black box on any of their overfull
1503 rows (TB, p. 303). Since \align is just an \halign, this means that
1504 no black boxes would be shown when a row is overfull. To alleviate
1505 this problem, we at least arrange for a black box to show up at the
1506 last line of the alignment, by adding \black@\totwidth@ at the end.
1507 \black@#1, with any argument #1, simply backs up a line, and then
1508 adds some extra non-aligned empty material, which is specified as
1509
1510 \vbox{\noindent\hbox to#1{\strut@\hfill}}.
1511
1512 This makes a \vbox that contains a paragraph starting (and containing
1513 only) a box of width #1 and height and depth of \strut@; if #1 >
1514 \hsize, then this paragraph has an overfull box in it, which will
1515 produce the desired black line, of height and depth of \strut@
1516 (unless \NoBlackBoxes has been specified). However, we will add this
1517 box only if #1 > \displaywidth (which could conceivably be larger
1518 than \hsize).
1519
1520 %1 Save \prevdepth in \dimen@, and then inhibit interline glue with
1521 \nointerlineskip (which just sets \prevdepth=-1000pt).
1522
1523 %2 Back up enough to put in line with height of \strut@.
1524
1525 %3 Put in the overfull \vbox.
1526
1527 %4 Restore \prevdepth.
1528
1529
1530 \expandafter\def\csname align \space ...
1531 ----------------------------------------
1532 Since \align|_||_| is created with \csname ... \endcsname, we have to
1533 use an \expandafter\def construction. \align|_||_| produces the
1534 \align when tags are on the right. We first \measure@ to find
1535 \maxrwidth@ and \totwidth@. Our display will be centered within a
1536 region of width \displaywidth,
1537
1538
1539 <---------------------------\displaywidth------------------------>
1540 | xxxxxxxxxxxxxx = yyyyyyyyy |
1541 | xxxxxx = yyyyyyyyyyyyyyyyy |
1542 | xxxxxxxxx = yyyyy<------------L------------>|
1543 |
1544 <------------\totwidth@---------->
1545
1546 <--left margin-> <-right margin->
1547
1548
1549 so the left and right margins will each be
1550
1551 1/2(\displaywidth-\totwidth@).
1552
1553 The tag for a line (say line 3 in the above picture) can go on that
1554 line if the length L is at least twice as big as the tag's length.
1555 We have
1556
1557 L = (right margin) + \maxrwidth@ - (\rwidth@ for this line).
1558
1559 So we need
1560
1561 1/2(\displaywidth-\totwidth@)+\maxrwidth@-(\rwidth@ for the line)
1562 >= (twice tag length).
1563
1564 When the tag has to be put on a separate line, we basically just
1565 replace the tag by a two-line box with an empty first line and the
1566 tag on the second line.
1567
1568 [NOTE: Diddling with \tagform@ (and hence with \maketag@) will
1569 change the rules for the tags here just as with \tag itself.]
1570
1571 [NOTE: Since \align computes \lwidth@ and \rwidth@ at each line, it
1572 is easy to add commands that use knowledge of these widths. For
1573 example, suppose that one wants formulas like
1574
1575 a = xxxxxxxxxxxxxxxxxxxxxxxxxxxx
1576 + yyyyyyyyyyyyyyy
1577
1578 where the y...y is set flush right with the x...x instead of being
1579 indented some fixed amount. To type this as
1580
1581 \align a & = xxxxxxxxxxxxxxxxxxxxxxxxxxxx \\
1582 & \flushright {+yyyyyyyyyyyyyyy} \\
1583
1584 we could introduce a new dimension \prevrwidth@ to store the \rwidth@
1585 of the previous line and let \flushright#1 mean
1586
1587 \hbox to\prevrwidth@{\hfil#1}}
1588
1589 (To get this to work correctly, we would probably need to add
1590
1591 \global\prevrwidth@\rwidth@
1592
1593 to the \everycr{\noalign{...}} clause.)]
1594
1595 %1 \measure@, set \and@=0.
1596
1597 %2 Use \displ@y@, except if in a \gather just set \and@=0 at each
1598 \cr.
1599
1600 %3 Left hand formulas in the \halign to\displaywidth will have
1601 \tabskip\centering@ glue before them to push them to the right.
1602
1603 %4 \@lign required so that an \halign in a left hand formula will
1604 not have the \tabskip\centering@ affect it.
1605
1606 %5 As we go through the lines once again, we set \lwidth@ to the
1607 length of the current left hand side, as before, except now we
1608 also print this left hand side (\box0 ).
1609
1610 %6 Tabskip glue is zero between the two sides.
1611
1612 %7 \@lign needed here, as in %4.
1613
1614 %8 We set \rwidth@ to the length of the current right hand side,
1615 but now also print right hand side.
1616
1617 %9 Right hand formulas have \tabskip\centering@ glue after them to
1618 push them to the left.
1619
1620 %10 First we store the \tag in \box0. \@lign required in case the tag
1621 involves an \halign!
1622
1623 %11 Let dimen0 = 1/2(\displaywidth-\totwidth@)+\maxrwidth@ - \rwidth@.
1624
1625 %12 If not enough space for tag on this line, we \llap a two-line box
1626 with first line empty, and tag on the second line.
1627
1628 %13 If there is enough space we just \llap the tag.
1629
1630 %14 \tabskip glue is 0 after the tag.
1631
1632 %15 Now do all the lines.
1633
1634 %16 Finally, add black box if \totwidth@ > \displaywidth.
1635
1636
1637 \newdimen\lineht@, \expandafter\def\csname align \endcsname ...
1638 ---------------------------------------------------------------
1639 \align|_| is similar, except that our calculations for whether the
1640 tag fits will involve \maxlwidth@ and \lwidth@. Moreover, when the
1641 tag has to be set on a separate line, we need to replace it by a
1642 two-line box with the tag on the first line and an empty second line.
1643 This empty second line has to have the same height as the line to
1644 which the tag applies, so we need a dimension \lineht@ to store this
1645 height in.
1646
1647 %1 \displaywidth@ is max of \totwidth@ and \displaywidth.
1648
1649 %2 Record height of left hand side in \lineht@.
1650
1651 %3 Update \lineht@ to height of right hand side, if it's bigger.
1652
1653 %4 The \kern-\displaywidth@ moves the tag back over to the left (to
1654 the left margin of the page, unless \totwidth@ is greater than
1655 \displaywidth@ [so that our display is actually overfull], in
1656 which case it is moved to the left margin of the display).
1657
1658
1659 \expandafter\def\csname align (in ...
1660 -------------------------------------
1661 In the case where \align was in a \gather, it reduced to a control
1662 sequence called
1663
1664 \align (in \gather)
1665
1666 We simply make this a \vcenter{\align@...} (where \align@ will reduce
1667 to\align|_| or \align|_||_|).
1668
1669
1670 \Invalid@\endalign
1671 ------------------
1672 Notice that \endalign is quite different from \endaligned, because
1673 the latter actually ends a group, whereas \endalign is just used as
1674 the delimiter for the argument of \align. This could cause great
1675 difficulties if we needed \align ... \endalign within a group that
1676 has other \\ constructions. Fortunately, the only such case is
1677 \align ... \endalign within a \gather, and we simply insist that
1678 braces are used around the \align ... \endalign in this case. But we
1679 ought to do something more than just leaving \endalign undefined.
1680
1681
1682 \newif\ifxat@
1683 -------------
1684 \alignat and \xalignat have much in common, so we will write their
1685 definitions similarly, using \ifxat@ as a flag to do things
1686 differently for the \xalignat.
1687
1688
1689 \alignat first checks to make sure we are in display math mode, and
1690 then calls \alignat|_| (created by \csname...\endcsname), which uses
1691 \endalignat as part of its syntax. In the case of \alignat, the test
1692 for tags on the left or right is made afterwards, so we don't need
1693 separate names for the two possibilities.
1694
1695
1696 \newif\ifmeasuring@, \newbox\savealignat@
1697 -----------------------------------------
1698 In `\alignat|_| n' the argument n determines how many &'s are allowed
1699 per line, namely 2n (2n - 1, plus 1 for the \tag). This in turn
1700 determines how many &'s have to be added when a \tag appears in a
1701 line with fewer &'s, and when an error message should be given: if
1702 \tag appears in a column where \and@ has value k, then we need to add
1703 2n-k &'s; if we have k > 2n, then the \tag part of the preamble
1704 should give an error message.
1705
1706 We won't try to set tags on separate lines automatically, but we do
1707 want to produce a black box if lines are too long, so we still need
1708 to measure things. Instead of separately calling a \measure@ type of
1709 argument, we will use a flag \ifmeasuring@ to determine if we are
1710 measuring or actually typesetting the alignment; the appropriate
1711 preamble will be made by \attag@, which will depend on \ifmeasuring@
1712 (and on \ifxat@). When measuring, we will save the result in the box
1713 \savealignat@.
1714
1715
1716 \expandafter\def\csname alignat \endcsname ...
1717 ----------------------------------------------
1718
1719 %1 #1 is the number after \alignat, #2 is everything else.
1720 %2 First we are just measuring.
1721 %3 We make the proper preamble with \attag@.
1722 %4 Then we are actually typesetting.
1723 %5 We make a new preamble with \attag@.
1724 %6 Then we typeset all the lines.
1725 %7 Finally we add a black box if necessary.
1726
1727
1728 \endalignat, like \endalign, has no definition of its own.
1729
1730
1731 \xalignat, like \alignat, first checks to see that we are in display
1732 math mode, and then calls \xalignat|_|, since it has \endxalignat as
1733 part of its syntax.
1734
1735
1736 \xalignat|_| is exactly the same as that for \alignat|_|, except that
1737 we have \xat@true (which will influence \attag@, when building the
1738 preambles).
1739
1740
1741 \attag@ finally builds the preamble. Although the process is similar
1742 to that used for building the preamble for \alignedat, it is
1743 complicated by the fact that we have to include \maketag@ and \Tag@
1744 among the tokens and make sure that they aren't expanded out when we
1745 do our \xdef's.
1746
1747 %1 Store \maketag@ in \Maketag@ and \Tag@ in \TAG@.
1748
1749 %2 Insure that \maketag@ and \Tag@ won't be expanded.
1750
1751 %3 The preamble will be written in terms of \llap@ and \rlap@, which
1752 are simply \llap and \rlap when we are typesetting, but when we
1753 are measuring will be a box twice the width of the tag.
1754
1755 %4 \toks@ will be the first part of the \preamble; it acts slightly
1756 different for \xalignat|_| and \alignat|_|.
1757
1758 %5 \toks@@ will be the final part of the \preamble; it differs
1759 significantly for \xalignat|_| and \alignat|_|.
1760
1761 %6 We use a \loop to add on pieces of the preamble to \toks@.
1762
1763 %7 Then we add on the last part.
1764
1765 %8 Then we do one more \xdef, as with \alignedat.
1766
1767 %9 Finally, we restore the meaning of \maketag@ and \Tag@.
1768
1769
1770 \endxalignat also has no definition.
1771
1772
1773 \xxalignat is simpler, because we don't have to worry about tags at
1774 all. First we make \xxalignat call \xxalignat|_|, since it uses
1775 \endxxalignat as part of its syntax, in display math, but gives an
1776 error message otherwise.
1777
1778
1779 \xxalignat|_| is similar to \alignat|_| and \xalignat|_|, except we
1780 don't bother about measuring things, since we don't have to worry
1781 about tags.
1782
1783
1784 \xxattag@ is used to make the preamble, rather than \attag@.
1785
1786
1787 \endxxalignat also has no definition.
1788
1789
1790 \newdimen\gwidth@, \newdimen\gmaxwidth@
1791 ---------------------------------------
1792 \gather is naturally easier than \align, but we still have the
1793 problem of putting the \tag on a separate line, so we still have to
1794 measure things. But we need only the one quantity \gmaxwidth@, the
1795 maximum width of all the formulas; \gwidth@ is the width of each line
1796 as it is measured.
1797
1798
1799 \gmeasure@ is analogous to \measure@ for \align@.
1800
1801
1802 \gather gives an error message if we are not in display math mode,
1803 and otherwise calls either \gather|_| or \gather|_||_|, since both
1804 use \endgather as part of their syntax.
1805
1806
1807 \gather|_||_| is analogous to \align|_||_|.
1808
1809
1810 \gather|_| is analogous to \align|_|, using the \glineht@ instead of
1811 \lineht@.
1812
1813
1814 \newif\ifctagsplit@ ...
1815 -----------------------
1816 It seems more elegant if a \split ... \endsplit formula has its tag
1817 either at the left of the top line or the right of the bottom line,
1818 but we will allow the tag to be centered, depending on the flag
1819 \ifctagsplit@. We provided \CenteredTagsOnSplits and
1820 \TopOrBottomTagsOnSplits to allow the user to set the flag. The
1821 default is \TopOrBottomTagsOnSplits.
1822
1823
1824 \split will be \outsplit@ if it is not in some other alignment, but
1825 if it is in some other alignment it will be \insplit@, which is the
1826 interesting thing. We don't need to worry about the
1827 \csname...\endcsname trick here because \split doesn't actually use
1828 \endsplit as part of its syntax. The K-method wouldn't work in this
1829 multi-case situation.
1830
1831
1832 \insplit@ just starts setting \box0 as \vbox{\halign{... with the
1833 proper format.
1834
1835
1836 \endpslit then finishes \box0 and calls either \lendsplit@ or
1837 \rendsplit@.
1838
1839
1840 \def\rendsplit@
1841 ---------------
1842 For tags on the right, we need to get out the last line of the
1843 \insplit@, which is a \vbox made up of the various lines of the split
1844 formula, with glue between them. If TG represents various tabskip
1845 glues (which all happen to be 0pt) and HF represents various glues
1846 added by the \hfil's in the preambles, this box looks like
1847
1848 ....
1849 ....
1850 \hbox{TG\hbox{HF lhs}TG\hbox{rhs HF}TG}
1851 <interline glue>
1852 \hbox{TG\hbox{HF lhs}TG\hbox{rhs HF}TG}
1853
1854
1855 %1 \box9 now has everything in \box0 except the last line, which is
1856 now \box8, and the interline glue that preceded the last box,
1857 which is removed by \unskip. \box8 is now of the form
1858
1859 \box8 = \hbox{\TG\hbox{HF lhs}TG\hbox{rhs HF}TG}.
1860
1861 #2 In \box1 we \unhcopy8. \unskip removes the last TG. Then \box2
1862 becomes \hbox{rhs HF} (\box 2 is saved by \global). The next
1863 \unskip removes the middle TG. Then \box3 (also saved by \global)
1864 becomes \hbox{TG{HF lhs}}. Notice that the width of \box3 is the
1865 same as the width of the whole left part of the split (the TG is
1866 0, but the HF fills out all lines to the same width, [even though
1867 lhs is actually usually empty in a split]).
1868
1869 %3 Finally, \box7 is now the right side of the last line, set to its
1870 natural width (the HF glue at the end having been removed by
1871 \unskip).
1872
1873 Now we will define \split@ to be the proper repositioning of
1874 elements.
1875
1876 %4 Suppose our \split is within an \align, and we want tags centered
1877 on the \split.
1878
1879 %5 Then we make \split@ be one more line of the form LHS & RHS, where
1880 RHS is a \vcenter of the whole split (\box0 ) except moved left by
1881 width of \box3, which is the width of the whole left hand side.
1882 This means that the symbols that the \split were aligned along
1883 will now align with all the other symbols in the \align. We also
1884 make LHS an empty box with the same width as the whole left hand
1885 side, so that \split will still have the proper width.
1886
1887 %6 Otherwise, we want the tag on the last line, so we have \split@
1888 add two lines: one having \box 9 (everything in the \split except
1889 the last line and interline glue) on the right, except moved over
1890 to the left the right amount, the width of \box3; and another
1891 having \box3 on the left and on the right \box7, which is the
1892 proper right side (cut down to its natural width). The proper
1893 interline glue will then be added back between these two lines.
1894
1895 %7 If we're not in an \align, so don't need to worry about lining up
1896 with other things, we do similar, but simpler, things, without
1897 worrying about moving things over.
1898
1899 %8 And finally, having defined \split@ correctly, we insert it.
1900
1901
1902 \def\lendsplit@
1903 ---------------
1904 For tags on the left we have to proceed somewhat differently. We
1905 can't conveniently obtain the first line, but we can begin by making
1906 a \vtop out of our \vbox:
1907
1908 %1 \box9 is just like \box0, except baseline is that of first line.
1909
1910 %2 Now \box8 is last line.
1911
1912 %3 Now \box3 is as before (but \box2 hasn't been saved, because we
1913 don't need to find the natural width of the last right side).
1914 \box1 is just a scratch box, so can be used twice like this.
1915
1916 Now we define \split@.
1917
1918 %4 Suppose our \split is within an \align, and we want tags centered
1919 on the \split.
1920
1921 %5 Then we make \split@ be one more line of the form LHS & RHS, where
1922 RHS is a \vcenter of the whole split, except with a new baseline
1923 (\box9 ) and moved left the right amount, and LHS an empty box as
1924 before.
1925
1926 %6 Otherwise, we want the tag on the first line, as before.
1927
1928
1929 \outsplit@ is just reduced to \insplit@.
1930
1931
1932 \newdimen\multlinegap@
1933 ----------------------
1934 Finally, we come to \multline. We store the gap between the margins
1935 and the left and right sides of the \multline in a dimension
1936 \multlinegap@.
1937
1938
1939 \newdimen\multlinetaggap@
1940 -------------------------
1941 For \multline we use the rule that there must be at least
1942 \multlinetaggap@ space between the formula and the tag. (This seems
1943 more reasonable than the usual rule, since the formula doesn't have
1944 to be centered.)
1945
1946
1947 \MultlineGap globally changes \multlinegap@.
1948
1949
1950 \multlinegap can only be used in a displayed formula, and then
1951 affects only this formula.
1952
1953
1954 \nomultlinegap is an abbreviation for \multlinegap{0pt}.
1955
1956
1957 \multline first checks to see that we are in display math mode, and
1958 calls \multline@ if we are. There is no point using the
1959 \csname...\endcsname trick here, because eventually we use the syntax
1960 \endmultline$$, so if the \endmultline is missing, at the end of the
1961 paragraph we just get an error message about a missing $ sign.
1962
1963
1964 \newif\iftagin@, \def\tagin@
1965 ----------------------------
1966 \multline@ has to be processed differently depending on whether or
1967 not the displayed formula it appears in has a \tag. We use a flag
1968 \iftagin@ to tell us, and test with \tagin@.
1969
1970
1971 \multline@ first does the \tagin@ test and then calls either
1972 \multline@l or \multline@r.
1973
1974
1975 \newdimen\mwidth@, \def\rmmeasure@
1976 ----------------------------------
1977 When tags go on the right, we will need to measure the last line of
1978 the \multline, and store its width in \mwidth@. This is easily done
1979 with \rmmeasure@; we set \mwidth@ to the width of each line, so that
1980 its final value is just the width of the last line.
1981
1982 %1 Don't worry about what \shoveleft and \shoveright really are,
1983 since we only care about the result of the last line, which
1984 shouldn't have either.
1985
1986
1987 \newdimen\mlineht@, ..., \def\lmmeasure@
1988 ----------------------------------------
1989 When tags go on the left, however, we will need to measure the FIRST
1990 line of the \multline, again storing its width in \mwidth@ (we will
1991 also need to store its height, in \mlineht@). This is more
1992 complicated, and we actually need two new flags, \ifzerocr@ and
1993 \ifonecr@, to keep things under control.
1994
1995 %1 After the first \cr, which is the one that follows the preamble,
1996 we have \zerocr@false and \onecr@true. Then after the first \\ in
1997 the \multline, we always have \onecr@false (and also
1998 \zerocr@false). So \onecr@true holds only for the first line of
1999 the \multline.
2000
2001
2002 \newbox\mtagbox@, ..., \newdimen\rtwidth@
2003 -----------------------------------------
2004 We will need to store the tag in a box \mtagbox@. And \ltwidth@ and
2005 \rtwidth@ are dimensions where we will store the widths of this box,
2006 for use with \shoveleft and \shoveright; however, \ltwidth@ will be
2007 made 0pt when a tag on the left can't go on the same line as the
2008 formula (since in this case we want \shoveleft to shove all the way
2009 to the left), and similarly for \rtwidth@.
2010
2011
2012 \multline@l calls \lmultline@@ if there is a \tag, and \lmultline@@@
2013 otherwise. In the latter case, it first sets \mtagbox@ to \null, and
2014 makes \ltwidth@ and \rtwidth@ be 0pt.
2015
2016
2017 \lmultline@@ sets other values for \mtagbox@, \ltwidth@, and
2018 \rtwidth@ when there's a \tag, and then simply calls \lmultline@@@.
2019
2020 %1 \mtagbox@ is a box with the tag in it.
2021
2022 %2 \dimen@ is
2023
2024 (width of first line) + (width of tag) + \multlinetaggap@.
2025
2026 %3 \ltwidth@ is just the width of the tag, unless the tag won't fit
2027 on the line (determined by \dimen@>\displaywidth), in which case
2028 it is 0pt (because the tag won't really be there!).
2029
2030
2031 \lmultline@@@ mainly has to define \shoveright and \shoveleft.
2032 \shoveright is simple: the \hfilneg cancels the \hfil normally on the
2033 right, but we add \hskip\multlinegap@, so that the line will come out
2034 the same distance from the right margin as the last line. \shoveleft
2035 is more complicated. First of all, we put \hfilneg at the beginning,
2036 to cancel the \hfil. Then, if \ltwidth@ isn't 0pt (so that the tag
2037 is actually on the line), we \hskip the width of this tag plus the
2038 \multlinetaggap@ (the total space from the margin to the beginning of
2039 the first line); but if \ltwidth@ is 0pt, so that the tag is on a
2040 separate line, we just \hskip the \multlinegap@. Unfortunately, this
2041 doesn't quite do it, because the formula that we are applying
2042 \shoveleft to might begin + A + B + ... for example. Our preamble
2043 for the \multline involves $\displaystyle{}#$, so that the initial +
2044 sign will have a medium space between it and the A. But there is
2045 also a medium space BEFORE the + sign, so the + sign will not really
2046 line up correctly on the left. To get around this, we set our
2047 formula with {} before it in \box0 and without the {} before it in
2048 \box1. When a symbol like + begins the formula, the difference
2049 between the width of \box0 and the width of \box1 will be two of
2050 these thick spaces, so we exactly cancel out any extra space with
2051 \hskip.5\wd1 \hskip-.5\wd0.
2052
2053 %1 First define \shoveright and \shoveleft.
2054
2055 %2 We begin the \multline with a separate line starting with
2056 \hfilneg, to cancel the \hfil.
2057
2058 %3 Suppose first that there is a tag.
2059
2060 %4 Moreover, suppose it will fit on the first line.
2061
2062 %5 Then we put in the tag, and skip the proper gap.
2063
2064 %6 But if it won't fit on the first line, we manufacture a box
2065 containing the tag on top and an empty box the height of the first
2066 line on the bottom.
2067
2068 %7 If there isn't a tag, we just skip the \multlinegap@.
2069
2070
2071 \multline@r works just like \multline@l.
2072
2073
2074 \rmultline@@ works just like \lmultline@@.
2075
2076
2077 \rmultline@@@ works like \lmultline@@@, except that now we don't
2078 have to worry about the tag yet, which will be taken care of by the
2079 \endmultline. However, now the definition of \shoveright is a little
2080 more complicated to take into account whether or not the tag goes on
2081 the same line as the last line; the definition of \shoveleft is
2082 simpler, but we still have to do the same trick to take care of
2083 formulas like + A + ... .
2084
2085
2086 \endmultline works slightly differently for tags on the left and tags
2087 on the right, so we have it call either \lendmultline@ or
2088 \rendmultline@.
2089
2090
2091 \lendmultline@ is trivial.
2092
2093
2094 \rendmultline@ has to put in the tag.
2095
2096 %1 Suppose there is a tag.
2097
2098 %2 Suppose, moreover, that it will fit on the last line.
2099
2100 %3 Then we skip the proper gap before the tag, and put in the tag.
2101
2102 %4 But if it won't fit on the last line, we manufacture a box
2103 containing an empty box on the first line, and the tag on the
2104 bottom line.
2105
2106 %5 If there isn't a tag, we just skip the \multlinegap@, before
2107 adding the \hfilneg.
2108
2109
2110 \bmod, ..., \mod are easier. \bmod is exactly as in plain, but with
2111 \fam\z@ instead of \rm. And \pmod is also based on plain, except
2112 that more space seems to look better in displays. \pod is the same
2113 as \pmod, but without the word `mod', and \mod is similar, except
2114 without the parentheses, and slightly different spacing.
2115
2116
2117 \newcount\cfraccount@, ..., \def\rcfrac
2118 -----------------------------------------
2119 Next come continued fractions. TeX's \over construction
2120
2121 {...\over\displaystyle ... +
2122 {\strut ... \over\displaystyle ... ...}}...}
2123
2124 is admirably suited for a recursive definition, since each new level
2125 contributes one left brace, with all the right braces occurring at
2126 the end; we just have to keep track, in a counter \cfraccount@, of
2127 how many levels we have entered. However, it doesn't look good if TeX
2128 puts the usual \nulldelimiterspace around each of the subfractions,
2129 so we will actually have one more level around each subfraction, with
2130 \nulldelimiterspace subtracted inside it. Thus, each \cfrac will
2131 contribute two \bgroup's.
2132
2133 We also have to make \\ mean \over\displaystyle inside the \cfrac. In
2134 case the \cfrac appears in some other construction where \\ has been
2135 \let=\cr, we use the usual \iffalse{\fi...\iffalse}\fi trick to
2136 enclose this definition. \lcfrac is just like \cfrac, except that the
2137 next \\ will put \hfill before the \over (hence at the end of the
2138 next numerator); and \rcfrac puts in the \hfill before the numerator.
2139
2140
2141 \def\gloop@, \def\endcfrac
2142 --------------------------
2143 Finally, \endcfrac puts in pairs of }'s, with
2144 \hskip-\nulldelimiterspace between them. A \loop...\repeat type of
2145 construction is meant to be used here, in which we decrease
2146 \cfraccount@ by 1 at each step. But there is a complication, because
2147 \loop uses \def\body to keep track of things, and after each
2148 iteration we are two levels up, so that \body is no longer defined
2149 (it might even be some old definition of \body!). So we have to use
2150 \gloop@, which is just like \loop, except that it uses \gdef\body.
2151
2152
2153 \def\binrel@
2154 ------------
2155 For \overset and \underset, we want a way to check whether a symbol S
2156 is either a binary operator or a binary relation, since \overset and
2157 \underset are supposed to preserve this. The idea is to compare the
2158 formula $S$ (with \mathsurround=0pt) and the formula ${}S{}$. To
2159 make the comparison both independent of the present values of
2160 \thinmuskip, etc., and easy, we set the formulas with
2161 \thinmuskip=0pt, \medmuskip=1mu, \thickmuskip=-1mu.
2162
2163 The spacing between the \mathord {} and a binary operator is
2164 \medmuskip, between {} and a binary relation is \thickmuskip and
2165 between {} and anything else is either 0 or a \thinmuskip. So, S must
2166 be a binary operator if the formula gets wider, and a binary relation
2167 if the formula gets narrower. Instead of saving the results of the
2168 test in control sequences, we just make \box2 have the width of {}S{}
2169 minus the width of S, and check on the width of \box2, since this
2170 test will always be done right at the beginning of any construction.
2171
2172
2173 \overset and \underset are essentially as in plain, except we make
2174 the result a binary operator or relation if it started as one; we
2175 also add the \kern\z@ as in \operatorname, in case only a single
2176 letter is involved.
2177
2178
2179 \oversetbrace and \undersetbrace are simply convenient abbreviations.
2180
2181
2182 \def\sideset
2183 ------------
2184 In a construction like \sideset ^+ \and ^* \to \sum, the final symbol
2185 will look like {\vphantom{\sum}}^+ {\sum}^* --- with the \vphantom
2186 used to get the prescript ^+ at the right height. To get the limits
2187 in the right place, we need a construction like that used for
2188 multiple integrals: \hskip-<...>\mathop{\hskip<...>{\vphantom } }
2189 where the correction <...> is the width of {\sum}^* which we set in
2190 \box2, minus the width of \sum with the prescript, which we set in
2191 \box1.
2192
2193
2194 \rightarrowfill@, ..., \def\leftrightarrowfill@ depend on the math
2195 style, to modify \overrightarrow and \overleftarrow from plain so
2196 that they work in all styles, using \mathpalette. The \smash- is
2197 used because the height of the minus sign happens to be the height of
2198 the plus sign (thus, larger than you'd like).
2199
2200
2201 \overrightarrow, ..., \underleftrightarrow are now defined, using
2202 \overrightarrow@, ..., \underleftrightarrow@ for use with
2203 \mathpalette.
2204
2205
2206 Now we come to \dots, which is probably the most complicated thing in
2207 all of AmS-TeX!
2208
2209 We would like \dots to know what to do on the basis of the next
2210 token, which we can get with a \futurelet. (It turns out that we
2211 don't happen to encounter any problems if we have \dots & within a
2212 \matrix, etc. This can be explained only by serendipity.) If that
2213 next token is a comma, then we will use \dotsc. If it is the token
2214 \not, then the \not presumably cancels a binary operator, so we will
2215 use \dotsb@ [\dotsb@ is essentially \dotsb, except that \dotsb will
2216 look ahead to see if extra space should be left because the next
2217 symbol might be a right delimiter]. If the next token is +, =, <, >,
2218 -, * or : then we again want to use \dotsb@.
2219
2220 Otherwise, however, it's not clear what to do with the token. For
2221 example, we can't simply make a formula containing only that token,
2222 since it might be something like \matrix that doesn't make any sense
2223 by itself (we don't have this problem with \underset and \overset,
2224 since they are actually applied to arguments, which must be
2225 meaningful formulas).
2226
2227 The only hope at this point is actually to look at the next token in
2228 detail, using \meaning!!
2229
2230 When we look at \meaning<token> we might get
2231
2232 \mathchar"... or macro...->...
2233
2234 (Remember, however, that all the characters here will have type 12.)
2235
2236 If we get \mathchar"... the number ... is of the form xnnn, where x
2237 gives the ``class'', with 2 for a binary operator and 3 for a binary
2238 relation. So if we set a counter to the number and divide by 4096,
2239 the value will be 2 and 3 for binary operators and relations,
2240 respectively.
2241
2242 If we get macro...->... then we don't want to go berserk and actually
2243 try to figure the macro out, but if the definition begins with \not
2244 we should use \dotsb (remember that \ne, for example, is a macro that
2245 expands to \not=). Moreover, we ought to use \dotsb if the definition
2246 begins with \mathbin or \mathrel.
2247
2248 In addition, if we test to see whether the definition begins with
2249 \DOTSB we can use \DOTSB as a signal that we are using a binary
2250 operator (and the user can add this to a definition also). Later we
2251 will add \DOTSB to certain of plain's definitions, since this will be
2252 the only reasonable way to see that they represent binary operators
2253 or relations. For example, \longrightarrow begins with \relbar, and
2254 \Longrightarrow with \Relbar. We have simply added \DOTSB in front
2255 of both. \DOTSB has also been added previously to the various big
2256 operators, so that \dotsb will be used before them.
2257
2258 Similarly, \DOTSI will indicate that \dotsi should be used, for dots
2259 before an integral sign.
2260
2261 Once \dots has figured out whether to use centered or low dots, it
2262 will still try to figure out whether some extra space should be left,
2263 because the next symbol is a right delimiter. Here we will find
2264 \DOTSX useful, to be put into a macro definition to indicate that it
2265 represents a right delimiter.
2266
2267
2268 \let\DOTSI\relax, ..., \let\DOTSX\relax
2269 ---------------------------------------
2270 Initially, these are all simply \relax.
2271
2272
2273 \newif\ifmath@, {\uccode ...
2274 ----------------------------
2275 First we make a flag to tell that \meaning begins with \math, where
2276 \ m a t h are all of type 12. To do this we have to use the \uccode
2277 trick, temporarily setting the \uccode of various numbers and of !
2278 (all of which are type 12) to \ m a t and h, so that when we
2279 \uppercase them we will get type 12 \ m a t and h. We will use
2280 \math@___\math@ to test ___ and set \ifmath@ true if the first five
2281 symbols are \ m a t and h, storing what remains in \meaning@. We are
2282 going to be applying constructions like \math@, which takes at least
2283 5 arguments, to the unknown ___ and then sometimes yet another
2284 construction taking at least 5 arguments, so, as will appear later,
2285 we will always add ten periods (any other symbol would do as well) to
2286 ___ before we begin the whole testing process.
2287
2288 (This construction assumes that ! is of type 12. If some macro
2289 pacakge changes this [for French punctuation, say], then the ! should
2290 be replaced by some other symbol that is guaranteed to be of type
2291 12.)
2292
2293
2294 \newif\ifmathch@, {\uccode ...
2295 ------------------------------
2296 When something begins with `\math', we will further test to see if it
2297 is followed by ch??" (we don't bother testing the ? characters, since
2298 no other result of \meaning could be like this). The test is of the
2299 form \mathch@___\mathch@, setting \ifmathch@ true if it passes, and
2300 then storing the " and what comes after in a new \meaning@.
2301
2302
2303 \newcount\classnum@, \def\getmathch@
2304 ------------------------------------
2305 Next we define a control sequence to test whether the "____
2306 combination we've picked up begins with 2 or 3, by computations with
2307 the hex number `"____' Since we've added periods, we must be careful
2308 to pick up only the number before the first period. At this point we
2309 no longer store the result, but directly define \thedots@ [the main
2310 thing that \dots is trying to produce] to be \dotsb@ if we do have 2
2311 or 3.
2312
2313
2314 \newif\ifmathbin@, {\uccode ...
2315 -------------------------------
2316 When we test whether a macro meaning begins with \mathbin or
2317 \mathchar we will first use the above \math@ test to see if it begins
2318 with \math. Then we will have to test if it is followed by `bin'.
2319 But we actually have to test whether it is followed by `bin|_|'
2320 (since someone might have defined a new control sequence beginning
2321 \mathbin...). Spaces created by \meaning still have their usual type
2322 10, so we will use \space@ for this part of the test, picking up the
2323 token after `bin' with a \futurelet. Compressed format is used here.
2324 The final result of the test is flagged by \ifmathbin@.
2325
2326
2327 \newif\ifmathrel@, {\uccode ...
2328 -------------------------------
2329 Similarly, we test for \mathrel.
2330
2331
2332 \newif\ifmacro@, {\uccode ..., \def\macro@@
2333 --------------------------------------------
2334 To test whether \meaning begins with `macro', we just test for the
2335 `mac', since no other possible result of \meaning could begin like
2336 this. The test sets \ifmacro@ and stores the result in (a new)
2337 \meaning@, which uses \macro@@ to isolate the part after the ->,
2338 i.e., the actual macro definition.
2339
2340
2341 \newif\ifDOTS@, \newcount\DOTSCASE@, {\uccode ...
2342 -------------------------------------------------
2343 To test whether a macro definition begins with \DOTSB or \DOTSI or
2344 \DOTSX we first test for the \DOTS, with \DOTS@...\DOTS@. If it
2345 doesn't we just set \ifDOTS@ false, otherwise we further test for the
2346 `B|_|' or `I|_|' or `X|_|', setting \ifDOTS@ true if the test is
2347 passed, and setting a counter \DOTSCASE@ equal to 0, 1 or 2 in these
2348 cases.
2349
2350
2351 \newif\ifnot@, {\uccode ...
2352 ---------------------------
2353 This is the test for whether something starts with \not.
2354
2355
2356 \newif\ifkeybin@, \def\keybin@
2357 ------------------------------
2358 We abbreviate the process of checking for all the possible binary
2359 operators and relations that can be entered from the keyboard.
2360
2361
2362 \def\dots
2363 ---------
2364 Finally, we're ready to define \dots ! which is different in text and
2365 math.
2366
2367
2368 \def\tdots@
2369 -----------
2370 In text, we want to ignore spaces before \dots, and we want to leave
2371 an extra thin space if the next token, which we get with a
2372 \futurelet, is a , or . or ; or : or ? or ! Otherwise (another letter
2373 or symbol comes next) we want to leave an ordinary space.
2374
2375
2376 \def\mdots@, \def\mdots@@
2377 -------------------------
2378 Finally, in math mode we want \mdots@, which uses \futurelet to get
2379 the next token. Compressed format isn't used here, because things
2380 are confusing enough already.
2381
2382 The main aim of \mdots@@ is to define \thedots@, which will be used
2383 at the very end. We begin by defining \thedots@ to be \dotso@ (the
2384 dots before ordinary symbols), and then modifying it under the stress
2385 of various tests. The order has been chosen so that the more
2386 complicated tests come near the end.
2387
2388 Notice that the \xdef\meaning@{\meaning\next..........} is allowed,
2389 even if \next happens to be outer.
2390
2391 %1 By default, we use \dotso@.
2392
2393 %2 If \boldkey (explained below) happens to come next, then we simply
2394 want to swallow up the \boldkey and use \boldkeydots@ instead.
2395
2396 %3 Similarly, if \boldsymbol happens to come next, then we simply want
2397 to swallop up the \boldsymbol and use \boldsymboldots@ instead.
2398
2399 %4 Otherwise, if , comes next we use \dotsc.
2400
2401 %5 If \not comes next we use \dotsb@.
2402
2403 %6 If +, =, etc., comes next we use \dotsb@.
2404
2405 %7 Otherwise we want to look at \meaning applied to the next token;
2406 we get this by \xdef\meaning@{\meaning\next..........} where the
2407 extra periods are added for reasons explained above. We also
2408 make another copy, \meaning@@, for later use.
2409
2410 %8 If \meaning@ begins `\math', we further test for ch??"; if this
2411 test is passed we use \getmathch@ to define \thedots@.
2412
2413 %9 Otherwise we see if we have a macro. We test on \meaning@@,
2414 since the previous test has already changed \meaning@.
2415
2416 %10 Suppose we do have a macro (so that \meaning@ is now the part
2417 after ->).
2418
2419 %11 We see if the macro begins with \not. If it does, \thedots@
2420 is \dotsb@.
2421
2422 %12 Otherwise, we see if the macro begins with `\DOTSB' or `\DOTSI'
2423 or `\DOTSX', and if so, we set \thedots@ to \dotsb@ for \DOTSB
2424 and \dotsi for \DOTSI.
2425
2426 %13 Otherwise we still have to see if the macro definition begins
2427 with \mathbin or \mathrel. Once again, we see if it starts with
2428 \math, storing the remainder in the new value of \meaning@.
2429
2430 %14 If it does we see if it really begins \mathbin and choose \dotsb@
2431 if it does (the test doesn't change the value of \meaning@).
2432
2433 %15 Otherwise we also see if it really begins \mathrel, and choose
2434 \dotsb@ if it does.
2435
2436
2437 Now that we've gotten to \thedots@, which is either \dotsc or \dotsi
2438 or \dotso@ or \dotsb@ or \boldkeydots@ or \boldsymboldots@, we have
2439 to define these.
2440
2441
2442 \plainldots@, \plaincdots@ are used to store away plain's definitions
2443 of \ldots and \cdots.
2444
2445
2446 \dotsi and \dotsb@ are simple.
2447
2448
2449 \newif\ifextra@, ..., \def\rightdelim@
2450 --------------------------------------
2451 But \dotso@ is supposed to leave extra space if followed by a right
2452 delimiter, so it is more complicated.
2453
2454 We use \ifextra@ to say if extra space should be left, after results
2455 of a test on \next, which a \futurelet will let equal the next token.
2456 For simplicity, first we simply test if the next token is an obvious
2457 right delimiter, storing the result in \ifrightdelim@, and then we
2458 make the real test.
2459
2460 %1 \rightdelim@ is true if
2461 %2 \next is ) ] \rbrack ...
2462 %3 or \Biggr, but false otherwise.
2463
2464
2465 \extra@ is the real test to set \ifextra@.
2466
2467 %1 \ifextra@ is true if the \rightdelim@ test is passed.
2468
2469 %2 It is also true if a $ sign comes next.
2470
2471 %3 Otherwise we look at \meaning again.
2472
2473 %4 Suppose we have a macro.
2474
2475 %5 Then if it starts with \DOTSX, \ifextra@ is again true.
2476
2477
2478 \newif\ifbold@, \dotso@
2479 -----------------------
2480 \dotso@, the most common result of \mdots@, has to act specially
2481 if it was called by \boldkeydots@ or \boldsymboldots@, which
2482 will be signalled by the flag \ifbold@.
2483
2484 In the standard case, where \ifbold@ is false, we just want to
2485 use a \futurelet to get the next symbol, use \extra@ to test
2486 this symbol for a right delimiter, and then use \plainldots@,
2487 followed by \, if the next symbol is a right delimiter. If this
2488 were the only case to consider, we could use the definition
2489
2490 \def\dotso@{%
2491 \DN@{\extra@\plainldots@\ifextra@\,\fi}%
2492 \FN@\next@}
2493
2494 But when \ifbold@ is true, the next symbol will already have been
2495 scanned by \boldkeydots@ or \boldsymboldots@, and stored in
2496 \delayed@. In this case, we don't want to use a \futurelet, but
2497 simply want to apply \extra@ with \next being \delayed@.
2498
2499 So when \ifbold@ is true we \let\next\delayed@ and then define
2500 \nextii@ to be this combination, but if \ifbold@ is false we define
2501 \nextii@ to be the whole combination \DN@{\extra@...}\FN@\next@}, and
2502 then we call \nextii@.
2503
2504
2505 \def\extrap@
2506 ------------
2507
2508 We still haven't defined \dotsc, which will actually be the last kind
2509 of dots we define, and there's also \dotsb and \dotso (as opposed to
2510 \dotsb@ and \dotso@) and similarly \ldots and \cdots.
2511
2512 \dotsb, \dotso, \ldots, and \cdots are slightly different from
2513 \dotso@ and \dotsb@, because they might be used before , or . or :
2514 especially at the end of a displayed formula that ends with
2515 punctuation, since that punctuation would have to appear before the
2516 $$ signs. So we want extra space here also.
2517
2518 We use \extrap@, which takes as argument another (dot producing)
2519 macro. It is used as an abbreviation for a construction that puts an
2520 extra thin space before a , or . or ; as well as something that
2521 passes the \extra@ test.
2522
2523
2524 \ldots and \cdots use \extrap@, and of course must have low and
2525 centered dots, respectively.
2526
2527
2528 \dotso is just \ldots, and \dotsb is just \cdots, although other
2529 styles could change that. Similarly, \dotsm is \dotsb in this style.
2530
2531
2532 \dotsc, however, is a little special because we DON'T want extra space
2533 if it's followed by a comma---someone might have typed \dotsc,
2534 instead of simply \dots---so we have to explicitly check for only
2535 a ; or .
2536
2537
2538 \cdot should be treated as an ordinary symbol by \dots. We can
2539 arrange for this by using the fact that \dots doesn't check a macro
2540 definition for \mathchar!
2541
2542
2543 \longrightarrow, ..., \iff need to have \DOTSB added to their plain
2544 definitions.
2545
2546
2547 \dddot, ..., \spvec have nothing special. A lot of adjustment was
2548 done by eye.
2549
2550
2551 \textonlyfont@ is just a control sequence to allow us conveniently to
2552 redefine \rm, \it, \sl, \bf, \smc, etc.
2553
2554
2555 \oldnos will be used instead of \oldstyle, which doesn't fit in this
2556 scheme; in fact, \cal and \oldstyle and \mit will be made
2557 \undefined at the end. \oldnos is just a control sequence with an
2558 argument; as a convenience, it doesn't leave extra spaces around
2559 commas that might occur in the number.
2560
2561
2562 \text in text is basically just an \hbox, but allowed to begin a
2563 paragraph; in math it will be \text@, which is much more complicated.
2564 Actually, \text should also reset \mathsurround if this has a non-zero
2565 value, just in case \text is used within a math formula that appears in
2566 some construction where \m@th has been used.
2567
2568
2569 \def\mathhexbox@, ..., \def\P
2570 -----------------------------
2571 Once \text@ is defined, it will be possible to create symbols that
2572 can be used in either math mode or in text mode without $ signs,
2573 because \text{$...$} will always change sizes right. With this in
2574 mind, we redefine \dag, etc., from plain so that they change sizes
2575 automatically. \mathhexbox@ is the obvious modification of plain's
2576 \mathhexbox. An extra set of braces is inserted, so that ^\dag, etc.,
2577 will work.
2578
2579
2580 \newif\iffirstchoice@, ..., \def\text@
2581 ---------------------------------
2582 \text@ will be a \mathchoice; in each case we will simply set an
2583 \hbox, but we will specify the style that we want for our math
2584 formulas and also which fonts we want for \rm, etc. This involves a
2585 few details, but there is also a detail of another sort that needs to
2586 be attended to.
2587
2588 Conceivably, someone could use \footnotemark (which is actually
2589 defined in AMSPPT.STY, rather than in AMSTEX.TEX) within \text (so
2590 that, together with \footnotetext, a footnote could be set on some
2591 text within a displayed formula). \footnotemark increases the
2592 counter \footmarkcount@, and since a \mathchoice is set four times,
2593 \footmarkcount@ would be increased by 4, instead of by 1. To get
2594 around this, we let the flag \iffirstchoice@ normally be true but set
2595 it to be false in all but the first part of the \mathchoice for
2596 \text@, and in AMSPPT.STY we only advance the counter \footmarkcount@
2597 when \iffirstchoice@ is true.
2598
2599 Aside from this, we will use \everymath to set the style at each
2600 size, and the control sequence \textdef@@ will be used to select the
2601 proper text fonts; depending on its argument, T, S or s, it will
2602 choose the \textfont or \scriptfont or \scriptscriptfont for each
2603 family of fonts. We also redefine \textfonti and \textfontii to be
2604 the proper size of families 1 and 2, for any text macros that use
2605 these. (At present that includes \{ and \} in text, which are fairly
2606 important, as well as \t and \AmSTeX.)
2607
2608
2609 \textdef@@ simply uses \textdef@ for each of the families, \rm, \bf,
2610 \sl, \it we need. If another family is added that should work
2611 properly in \text, the appropriate clause should be added here.
2612
2613
2614 \def\rmfam{0}, \def\textdef@
2615 ----------------------------
2616 \textdef@ works under the assumption that \bf has a corresponding
2617 \bffam, \sl a corresponding \slfam, etc., all with names obtained by
2618 adding `fam' to the font change name. We therefore have to define
2619 \rmfam to be 0. If a new font, say \bfit, is introduced,
2620 \newfam\bfitfam should be used to create a new family with the
2621 corresponding name.
2622
2623 To get the name of the family, e.g., \bffam, from the name \bf of the
2624 font, \textdef@ uses
2625
2626 \csname\expandafter\eat@\string\bf fam\endcsname.
2627
2628 Then it redefines the font name \bf to be the \textfont for \bffam if
2629 the first argument is T, or the \scriptfont for \bffam if it is S,
2630 etc. The \relax is needed because \bffam is just a number, after the
2631 \edef.
2632
2633
2634 \scriptfont\itfam ...
2635 ---------------------
2636 Any family that will be used with \text@ should have some assignment
2637 for its \scriptfont and \scriptscriptfont; otherwise there will be
2638 error messages even if only text or display size is being used,
2639 because a \mathchoice actually sets all four possibilities.
2640 \sevenit, etc., are not defined in plain. If \sevenit, etc., are
2641 available, then they can be used here, or in amsppt.sty.
2642
2643
2644 \foldedtext, \topfoldedtext, and \botfoldedtext, like \smash and
2645 \phantom, use one basic definition, with flags \iftopfolded@ and
2646 \ifbotfolded@.
2647
2648
2649 \foldedwidth is syntax that has to be looked for. We don't store the
2650 \foldedwidth, which is .3\hsize by default, anywhere special, but use
2651 it as soon as we get it.
2652
2653
2654 \def\bold ...
2655 -------------
2656 Next come the control sequences for changing fonts in math mode. The
2657 reason for defining \bold@ in terms of \bold@@, instead of directly,
2658 is that later on we will sometimes want to change the definition to
2659 eliminate the extra set of braces, and this is easily done by saying
2660 \let\bold@=\bold@@. \relax is added after \fam\bffam, etc., because
2661 these families are just numbers.
2662
2663
2664 \Cal@@ has \noaccents@ for reasons that will appear later.
2665
2666
2667
2668 \mathchardef\Gamma ...
2669 ----------------------
2670 We make the upper case Greek letters ordinary symbols instead of
2671 variables, because we don't change them with font change
2672 instructions.
2673
2674
2675 \mathchardef\varGamma ...
2676 -------------------------
2677 The variant upper case Greek letters are exactly the same, except "00
2678 is replaced by "01, since they are on the math italic font, which is
2679 family 1.
2680
2681
2682
2683 \newif\ifmsamloaded@ ...
2684 ------------------------
2685 Originally, \loadmsam, \loadmsbm, and \loadeufm were created because
2686 the msam, msbm and eufm fonts are not available to everyone, so
2687 instead of loading them directly, we defined control sequences to
2688 load them; we also needed to set flags so that AMSPPT.STY will know
2689 whether to load in the corresponding fonts for the eightpoint size.
2690
2691 Now, \loadmsam, \loadmsbm, and \loadeufm are considered part of
2692 AmS-TeX, but we keep the same structure, since other font families
2693 are treated this way.
2694
2695 We will later have a list, \fontlist@, in the form of TB, p. 378,
2696 that is supposed to list all the fonts used. To make sure that any
2697 fonts loaded are added to this list, instead of \font we use \font@,
2698 which is defined later. When we load in fonts for a family we also
2699 want to use \newfam to create the family name, but \newfam is \outer,
2700 so we would need an inner version, or the code itself. But there is
2701 another problem here; we want the allocations we make to use the
2702 present definition of \alloc@, for proper use of \showallocations. So
2703 we use \alloc@@ for the present meaning, and then write the code for
2704 \newfam in terms of \alloc@@.
2705
2706
2707 \def\hexnumber@ ...
2708 -------------------
2709 We will need to use various family numbers in \mathchar and
2710 \mathchardef's. But we need the hexadecimal values if any family is
2711 greater than 9, so we use \hexnumber@ to get it. An \ifcase is most
2712 efficient here.
2713
2714 In addition to the family number of new families that we will load,
2715 we will also need to use the family number of the family \bffam, so
2716 we use \bffam@ to stand for its hexadecimal number. We \edef\bffam@,
2717 rather than \def'ing it, so that if someone is loading in AMSTEX.TEX,
2718 instead of using a format file, succeeding definitions will take less
2719 time.
2720
2721 \loadmsam and \loadmsbm set flags to say they are loaded, declare the
2722 necessary fonts, create the corresponding new families, assign the
2723 fonts to these families, and create \msam@ and \msbm@ for the
2724 hexadecimal numbers of these families.
2725
2726 In addition, once the msam fonts are loaded we will let
2727 \dashrightarrow, ..., \dasharrow (which use \dabar@), and \ulcorner,
2728 ..., \maltese be defined, because they are defined specially. All
2729 other symbols can be handled by \newsymbol, explained below.
2730
2731 Similarly, we will redefine plain's \widehat and \widetilde to take
2732 advantage of wider symbols in the msbm fonts, but these will not be
2733 used unless the msbm fonts are loaded.
2734
2735
2736 \newsymbol
2737 ----------
2738 We don't want \loadmsam or \loadmsbm to introduce names for all the
2739 symbols, since this will use up too many control sequence names
2740 needlessly. Instead we let \newsymbol be used in the form
2741
2742 \newsymbol\nleqslant 230A
2743
2744 or, more generally,
2745
2746 \newsymbol\cs 230A
2747
2748 where \cs is the user's choice of a control sequence, and the
2749 4-character ``ID'' 230A should be listed along with the ``standard''
2750 name \nleqslant in the list of symbols. The first character of this
2751 ID will be 1 for symbols on the msam fonts, and 2 for symbols on the
2752 msbm fonts.
2753
2754 For \newsymbol we first \define the control sequence to be empty, to
2755 get an error message if it is already defined. Then we let \next@ be
2756 \relax, but change \next@ to \msamfam@ if #2 is 1 and the msam fonts
2757 are loaded or to \msbmfam@ if #2 is 2 and the msbm fonts are loaded.
2758 Then, if \next@ is still \relax we give error messages; otherwise we
2759 do a \mathchardef, using the values of \next@.
2760
2761
2762 \UseAMSsymbols
2763 --------------
2764 For people who want to use the AMS's names, \UseAMSSymbols will
2765 \input the file amssym.tex.
2766
2767 This file begins with \catcode`\@=11 (so that it can use the tests
2768 \ifmsamloaded@, \ifmsbmloaded@). If these families are loaded, it
2769 uses \newsymbol with the standard names for all the symbols on the
2770 fonts. However, it does this within a group where \globaldefs=1 so
2771 that these names will be globally made, even if \UseAMSsymbols is,
2772 for some reason, used within a group. We must \undefine
2773 \rightleftharpoons, \angle, and \hbar before using them with
2774 \newsymbol, since they are already defined.
2775
2776 At the end, the file makes @ \active again.
2777
2778 If the families aren't loaded we give error messages, and we also
2779 first add \catcode`\@\active, so that @ will be certain to be active.
2780
2781
2782 If the \msbfam is loaded, we can use \Bbb, just like the other font
2783 change instructions; like \Cal, it has \noaccents@, which will be
2784 explained later.
2785
2786
2787 Though defined here, \loadmsam, \loadmsbm and \loadeufm must actually
2788 appear later, after \font@ has been defined.
2789
2790
2791 \frak has been added for changing to the \eufmfam in math mode.
2792 Similarly, any other added families of fonts should be treated like
2793 this, if their characters are basically just specified by typing
2794 letters.
2795
2796 \goth is just a convenient alternative for \frak.
2797
2798
2799 \ifcmmibloaded@ ...
2800 -------------------
2801 Next comes the mechanism for loading the two families of bold fonts,
2802 cmmib and cmbsy. We will have a single control sequence \loadbold
2803 for loading both, but separate flags for telling when each family is
2804 loaded (so that users who know what they are doing and who decide to
2805 load only one family [or only certain sizes of a family] can still
2806 use subsequent control sequences).
2807
2808 \mathchari@, \mathcharii@ simply give \mathchar's if the first,
2809 respectively second, family of bold symbols is loaded, otherwise
2810 error messages.
2811
2812
2813 \boldkey
2814 --------
2815 \boldkey basically has to test all the various possiblities for
2816 ``keys'' that come after it.
2817
2818 We can test for a letter by using \ifcat\noexpand#1A; in this case we
2819 just use #1 in \fam\cmmibfam if it is loaded, and give an error
2820 message otherwise.
2821
2822 Otherwise, we first test individually for ! ( ) + : ; = ? [ ] and
2823 use the appropriate symbol on the \bf fonts.
2824
2825 After this test, we test individually for , - . / < > * | and use
2826 the appropriate symbol on the appropriate bold fonts, specifying them
2827 with \mathchari@ or \mathcharii@, to get error messages if the fonts
2828 aren't loaded.
2829
2830 Finally, we test for the digits 0, ..., 9, and simply replace them
2831 with \bold0, ..., \bold9, already defined (\boldkey isn't supposed to
2832 be used with digits, but if it is we might as well revert to \bold).
2833
2834
2835 \def\boldsymbol ...
2836 -------------------
2837 \boldsymbol is much more complicated, since we will have to look at
2838 \meaning.
2839
2840 We begin by defining \next@ to be an error message; it will be
2841 changed to \relax whenever we reach a case where \boldsymbol can be
2842 used. (Eventually, alternate error messages may be defined.)
2843
2844 Again, we first test for letters, and use \fam\cmmibfam in this case,
2845 unless this family isn't loaded, in which case we just give a special
2846 error message (and let \next@ be \relax, so that the original error
2847 message isn't given).
2848
2849 Then we do some of the same manipulations with \meaning#1 as in
2850 \dots. If we had a \mathchar, we will use \boldsymbol@@ on the value
2851 of \meaning@ (instead of the \getmathch@...\getmathch@ from \dots).
2852
2853 Some of the things we want to use with \boldsymbol are defined as
2854 delimiters, so if we don't have a \mathchar, we have to use \macro@
2855 from \dots, together with a new construction \delim@, defined below,
2856 to see if this is the case, and if so, we will use \delim@@ with
2857 \meaning@.
2858
2859 Finally, if none of these tests are passed, we will still use a final
2860 test, \boldsymbol@, for certain exceptional symbols.
2861
2862
2863 \mathhexboxii@ is just \mathhexbox@ for the cmbsy family, but an
2864 error message if this family isn't loaded.
2865
2866 \boldsymbol@, the final check, just examines individual possiblities,
2867 and defines the result in terms of \mathcharii@ or \mathhexboxii@ or
2868 \bffam@, in the case of \lbrack and \rbrack (if they are used instead
2869 of [ and ], which would be used with \boldkey.)
2870
2871
2872 \boldsymbol@@#1.#2\boldsymbol@@ is going to be applied
2873 where #2 are the remaining .'s from \meaning@, and #1 is
2874 the hexadecimal number after the \mathchar.
2875
2876 %1. We set both \classnum@ and \count@@@ to #1.
2877
2878 %2. We divide \classnum@ by 4096 to get the first hexadecimal
2879 digit (first from the left), and set \count@ to this value.
2880
2881 %3. Then we multiply \count@ by 4096, and subtract from the
2882 original value, \count@@@, so that \count@@@ now has the
2883 value of last three hexadecimal digits. We also set
2884 \count@@ to this value.
2885
2886 %4. Then we divide the new \count@@@ by 256 to get the second
2887 hexadecimal digit, which we store in \count@.
2888
2889 %5. Then we multiply the second hexadecimal digit, \count@@@,
2890 by 256 and subtract from \count@@, which still has the
2891 value of the last three hexadecimal digits, so that
2892 \count@@ now has the value of the last two hexadecimal
2893 digits.
2894
2895 %6. Then we divide \count@@@ by 256 again, so that it has the
2896 value of the second hexadecimal digit.
2897
2898 %7. Finally, we multiply \classnum@, the first hexadecimal
2899 digit, by 4096 again and add \count@@, the last two
2900 hexadecimal digits to it. So if the hexadecimal digit was
2901 "abcd, \classnum@ is now "a0cd, and \count@@@ = b.
2902
2903 %8. Now, if \count@@@ = 0, so that our symbol came from family
2904 0 (i.e., the roman fonts, which should mean that our symbol
2905 was one of \Gamma, ..., \Omega), we want to use the
2906 corresponding symbol in the \bf family, which means that it
2907 is \mathchar"axcd, where x is the number for \bffam, so we
2908 get this by adding 256 times the hexadecimal number \bffam@
2909 to \classnum@, and then using \mathchar\number\classnum@.
2910
2911 %9. On the other hand, if \count@@@ = 1, so that our symbol
2912 came from family 1 (i.e., the math italic fonts), then we
2913 want to use the corresponding symbol in the cmmib family,
2914 so we add 256 times the hexadecimal number \cmmibfam@ to
2915 \classnum@ and use \mathchar\number\classnum@, except that
2916 we give an error message if these fonts aren't loaded.
2917
2918 %10. Similarly if \count@@@=2 (in which case our symbol came
2919 from family 2 (i.e., the math symbol fonts).
2920
2921
2922 \newif\ifdelim@ ...
2923 -------------------
2924 \delim@#1\delim@ sees if #1 starts with \ d e l; if so, it makes
2925 \ifdelim@ true and sets \meaning@ to be the rest.
2926
2927 When \delim@@#1"#2#3#4#5#6\delim@@ is used, #2 will be the type of
2928 delimiter, #3 will be the font family the symbol occurs on, "#4#5
2929 will be the location of the symbol on the font, and #6 will be
2930 everything else (i.e., the large variant, if there is one). If #3
2931 isn't the second family, we stick with the original error message
2932 that \boldsymbol can't be used with this symbol; otherwise we let
2933 \next@ be \relax, so that we won't get this error message, and then
2934 either produce the symbol, with \mathcharii@#2#4#5, or else give an
2935 error message if the family isn't loaded.
2936
2937
2938 \vert, \Vert (and \|) and \backslash have to be redefined so that the
2939 initial hexadecimal digit 0 is specifically added, in order for the
2940 definition of \delim@@ to work (plain simply leaves out the 0).
2941
2942
2943 \boldkeydots@#1 and \boldsymboldots@#1 are called if \dots is
2944 followed by \boldkey or \boldysmbol.
2945
2946 In both cases, we first make \ifbold@ true, and then set \next to be
2947 #1. The value of \next will be used by \mdots@@ to decide whether to
2948 use \dotso@, etc. If \dotso@ is used, then we need to reset \next to
2949 #1, for use by \ifextra@, so we first store #1 in \delayed@, and
2950 include \let\next\delayed@ in the definition of \dotso@. After the
2951 dots are put in by \mdots@@, we then put in the right symbol with
2952 \boldkey#1 or \boldysmbol#1, and finally set \ifbold@ to be false
2953 again.
2954
2955 On subtle point: in \boldkeydots@, the = after \let\next and
2956 \let\delayed@ are required, because #1 might be = , in which case it
2957 would disappear, so that \next would be set to \let, or \delayed@ to
2958 \mdots@@, etc., resulting in no end of mischief.
2959
2960
2961 \newif\ifeufbloaded@ ... \newif\ifeurbloaded@ ...
2962 -------------------------------------------------
2963 The next five sets of definitions make it easy to load the rest of
2964 the Euler fonts, one at a time, when needed. The user should take
2965 care not to try to load too many at once, as TeX's limit of 16
2966 families cannot be changed.
2967
2968
2969 \def\accentclass@, ..., \makeacc@\bar
2970 -----------------------------------
2971 We change the definition of \hat, etc., so that constructions like
2972 \bold{\hat A} will use the bold \hat symbol. But we want \Cal{\hat A}
2973 and \Bbb{\hat A} to use the usual \hat symbol, since these fonts
2974 don't have accent characters. That is why we added \noaccents@ to
2975 the definitions. The strategy is to change \hat from
2976 \mathaccent"705E to \mathaccent"\accentclass@05E, where \accentclass@ is
2977 usually 7, but is redefined as 0 when \noaccents@ is in force. To
2978 save space we use \makeacc@ to produce these definitions.
2979
2980
2981 \vec is different, as the accent itself is on only one font
2982 (\textfont1).
2983
2984
2985 \newcount\skewcharcount@, ..., \def\theskewchar@
2986 ------------------------------------------------
2987 Now come definitions of \Hat, etc., which will get double accents
2988 correctly positioned. After \dots, these are the most complicated
2989 things in AmS-TeX.
2990
2991 TeX properly places single accents over letters in math mode by using
2992 the kern, s, between the letter, L, and the \skewchar for its font
2993 (TB, p. 443); we have to emulate this procedure. The results of the
2994 instructions in Rule 12 on p. 443 can be obtained by replacing L by
2995 {L\hskip 2s}, putting (i.e., centering) the accent over this box, and
2996 then adding \hskip-2s.
2997
2998 This means, first of all, that we have to find the \skewchar of the
2999 font. The \skewchar is -1 or '177 for the fonts in plain, but might
3000 be anything; however, we assume that the \skewchar for all the fonts
3001 in any particular family are the same. Moreover, we assume that the
3002 kerns are proportional in different size fonts within a family, so
3003 that the kern in the \textfont for the family is all we need to know.
3004 (This seems to give quite adequate results for the Computer Modern
3005 fonts.)
3006
3007 The control sequence \theskewchar@ globally sets \skewcharcount@ to
3008 the \skewchar for the family if it is between 0 and 127, and to -1
3009 otherwise. We use \global because \theskewchar@ will be used within
3010 an \hbox. If the \skewchar is between 0 and 127, \theskewchar@ will
3011 also produce the \skewchar character for the font. This character can
3012 be obtained as \mathchar.... where .... is (the \skewchar for the
3013 family) + (256 times the family number) + (4096 times the class),
3014 where we should take the class to be 7 (variable), so that \mathchar
3015 will select whatever family we are in.
3016
3017 TeX always sets \fam to -1 at the beginning of a formula. This means
3018 that we should assume that our character is in family 1 (where the
3019 ordinary letters lie), unless \fam has a different value between 0
3020 and 15.
3021
3022 %1 First assume that \fam=-1, so that our letter is in family 1, and
3023 set \familycount@ to 1, and set \skewcharcount@ to the \skewchar
3024 for family 1.
3025
3026 %2 But if \fam has a legal value, between 0 and 15, so that our
3027 letter is in this \fam, set \familycount@ to this value, and
3028 \skewcharcount@ to the \skewchar for this \fam.
3029
3030 %3 If \skewcharcount isn't between 0 and 127, just set
3031 \skewcharcount@ to -1. Otherwise add 256 times \familycount@ to
3032 the \skewchar, and then add 28672 (= 7 x 4096), and produce this
3033 \mathchar.
3034
3035
3036 \newcount\pointcount@, \def\getpoints@
3037 --------------------------------------
3038 The construction \getpoints@...\getpoints@ will be applied to things
3039 like \the\dimen0. If \the\dimen0 is 23.456pt, \pointcount@ will be
3040 set to 23, the integer number of points in \dimen0. The use of . in
3041 the syntax for \getpoints@ is OK, since constructions like
3042 \the\dimen0 always produce the decimal point.
3043
3044
3045 \newdimen\accentdimen@, ..., \def\dimentomu@
3046 --------------------------------------------
3047 Eventually, we will use \theskewchar@ to store the kern between our
3048 letter and the \skewchar in a dimension register \accentdimen@. We
3049 will use the control sequence \dimentomu@ to convert this to mu's and
3050 store the number of mu's in a counter \accentmu@, so that we can use
3051 \accentmu@ mu to get a kern that varies appropriately with the style
3052 of the formula.
3053
3054 Essentially, we want to multiply the number of points by 1.8, since
3055 there are 18 mu in 10 points. Since we are going to deal in whole
3056 numbers, we will actually multiply by 1800 and divide by 1000. In
3057 the definition below, multiplying \accentdimen@ by 100 first lets
3058 \getpoints return a good value.
3059
3060
3061 \def\Makeacc@
3062 -------------
3063 Finally, we are ready to produce \Hat, etc., with \mathaccent@, the main
3064 thing left for us to define. As with ordinary accents, we use a
3065 control sequence to abbreviate the constructions, and incorporate
3066 \accentclass@ to take care of the case where letters come from a font
3067 that doesn't have accent characters.
3068
3069
3070 \unbracefonts@ temporarily changes the meanings of \rom, \bold, etc.,
3071 so that the extra pair of braces isn't included.
3072
3073
3074 \def\mathaccent@
3075 ----------------
3076
3077 %1 First we store the current family in \thefam@; as usual, it is set
3078 to 1 if it is -1, i.e., if \fam hasn't been changed yet.
3079
3080 %2 We initialize \accentdimen@ to 0pt; it may have been changed by a
3081 previous \Hat, etc.
3082
3083 %3 Now we set the formula #2 in the current family (and in
3084 \textstyle). \unbracefonts@ isn't really important here, but we
3085 put it in for consistency, since it will be needed in a
3086 corresponding box later on.
3087
3088 Although we initialized \accentdimen@ to 0pt, it may have changed,
3089 because #2 might already involve a \Hat, etc. In fact, we will
3090 later arrange explicitly for this to happen in such a case.
3091
3092 %4 If \accentdimen@ hasn't changed, the accent is simple.
3093
3094 %5 But we will globally make \accentdimen@ different from 0pt, so
3095 that a \Hat applied to this new accented character will be treated
3096 differently, via the clause after the final \else in this
3097 definition. Moreover, we will globally set \accentmu@ to the
3098 number that we want to be used for this new accented character:
3099
3100 %5a \box1 is the formula #2 followed by the \skewchar for the font
3101 (or by nothing, if the \skewchar isn't between 0 and 127).
3102 Here \unbracefonts@ is needed if #2 is something like \bold X:
3103 we don't want the extra braces around the \fam\bffam X,
3104 because we want \fam to be \bffam when \theskewchar@ does its
3105 thing.
3106
3107 %5b \box2 is the \skewchar alone (or nothing). It is in the right
3108 family, because \skewcharcount@ was most recently globally set
3109 in box 1.
3110
3111 %5c \accentdimen@ is now the kern between #2 and the \skewchar.
3112
3113 %5d We double it, change to mu's, and add 1 for good measure.
3114
3115 %6 If we're in the case where \accentdimen@ was changed, we use the
3116 value of \accentmu@ that was created to properly position the
3117 accent. We make the whole result an ordinary symbol, and add an
3118 empty group so that things like \Hat{\Hat A}^2 will work OK.
3119
3120
3121 \Makeacc@ ...
3122 -------------
3123 Now we make all these accents.
3124
3125
3126 \Vec is special, as with \vec.
3127
3128
3129 \def\newbox@, \def\accentedsymbol
3130 ---------------------------------
3131 We want \accentedsymbol to create a \newbox to store the symbol.
3132 Since \newbox is \outer, we need an inner version (we can't simply
3133 use the code, because we are going to be using it after
3134 \expandafter).
3135
3136 The \newbox created by \accentedsymbol\Ahathat{\Hat{\Hat A}} will
3137 just be called \Ahathat@box, which we create with
3138 \csname...\endcsname.
3139
3140
3141 \def\sqrt ...
3142 -------------
3143 \radical, \underline and \overline are like ^ and _ : they operate on
3144 the next <math field> rather than on the next macro argument (TB, p.
3145 291). So, for example, \underline\noteq becomes \underline\not=
3146 which underlines only the \not, and \underline\notin gives mysterious
3147 error messages. To avoid this, we redefine \sqrt, \underline and
3148 \overline as control sequences with arguments.
3149
3150
3151 \Invalid@\leftroot, .., \def\plainroot@
3152 ---------------------------------------
3153 \root will have both \leftroot and \uproot as possible parts of its
3154 syntax. The definition is messy because we allow them to occur in
3155 either order. We also have to worry about skipping over spaces after
3156 a right brace after \leftroot{...} or \rightroot{...}. The net
3157 result of all the mess is simply to assign values to the counters
3158 \uproot@ and \leftroot@.
3159
3160 \root actually begins working with the code on the last line: it
3161 starts a group (to keep the values of \uproot@ and \leftroot@ local,
3162 for \root's within \root's), initially sets \uproot@ and \leftroot@
3163 to 0, and after \uproot@ and \leftroot@ have been properly assigned,
3164 it calls \plainroot@, which is almost exactly the same as plain's
3165 \root, except the \mathchoice involving \r@@t has to be written out,
3166 rather than using \mathpalette, in order to get the final \egroup in
3167 the right place.
3168
3169 And \r@@t is like plain's \r@@t, except that we add corrections for
3170 the values of \uproot@ and \leftroot@. For \leftroot@ we simply
3171 change the \mkern-10mu between the root and the main quantity by
3172 \mkern-10mu\mkern\leftroot@ (i.e., we leave more room between them,
3173 since \leftroot@ is the amount to move the root to the left); we have
3174 to correct for this extra shift with \mkern-\leftroot@ mu at the
3175 beginning.
3176
3177 \uproot@ is handled a little differently, since mu is a unit for
3178 horizontal distances, not vertical ones. We set a box of width
3179 w=\mskip\uproot@ mu, and increase \dimen@, the amount involved in
3180 raising the root, by 10/6 w. (Then, since we raise by .6\dimen@, the
3181 extra amount we are raising is w.)
3182
3183
3184 \boxed makes a box with rules of width .4\ex@ (so .4pt at 10 points),
3185 and we want its baseline to be the baseline of the original formula.
3186 The \vbox on lines 3--5 of the definition surrounds \box0, the
3187 original formula in \displaystyle, with three points of space and the
3188 rules on all sides. It is now too high by 3pts + .4\ex@ + depth of
3189 \box0 (since the construction \vbox{\vskip3\ex@\box\z@\vskip3\ex@}
3190 produced a box of depth 0). So we lower by that total amount.
3191
3192
3193 \let\amspersand@\relax
3194 ----------------------
3195 Now come commutative diagrams. The diagrams themselves aren't much
3196 of a problem, and the interesting things are the arrows within them.
3197 It is pleasant that one can avoid using & in commutative diagrams, by
3198 having the arrows put the &'s in themselves; the only problem is that
3199 the same construction used for horizontal arrows in commutative
3200 diagrams is also supposed to work for individual arrows in math mode.
3201 The way to do this is to have the macros contain \ampersand@ in the
3202 right places, where \ampersand@ is usually \relax, but can be changed
3203 to & within a commutative diagram.
3204
3205
3206 \newdimen\minaw@ ...
3207 --------------------
3208 We also want the arrow constructions to give different lengths for
3209 arrows within commutative diagrams and for individual arrows in math
3210 mode (except that in either case the arrows will get longer, if
3211 necessary, when they have formulas above and/or below them). We
3212 store the minimum length for individual arrows in math mode in
3213 \minaw@, and the minimum length for arrows in a commutative diagram
3214 in \minCDaw@.
3215
3216 \minaw@ is made 11.11128\ex@ (i.e., 11.11128pt). I can't remember
3217 where I got this from! Probably the dimension of some symbol.
3218 \minCDaw is made 2.5pc.
3219
3220
3221 \minCDarrowwidth allows user to change the minimum length, provided
3222 we are in a displayed formula.
3223
3224
3225 \CD and \endCD are similar to \matrix and \endmatrix. Of course,
3226 there are no category code changes, nor any extra space (and so no
3227 \null), and we make the baselineskip bigger. But we also want to
3228 \let\ampersand@=&, so that the arrow macros will produce the &'s. As
3229 with \Let@, we have to hide this within \iffalse{\fi...\iffalse}\fi.
3230 We also set a flag, \ifCD@, to tell the arrow macros they are in a
3231 \CD (and hence should have longer length).
3232
3233
3234 \endCD just supplies the necessary \cr and }'s.
3235
3236
3237 \newdimen\bigaw@
3238 ----------------
3239 Now we are ready for the arrows themselves. We store the actual
3240 length that an arrow will be in \bigaw@. Since the arrows are of the
3241 form @>>>, etc., we use \atdef@ to define them.
3242
3243
3244 @>#1>#2>#3>
3245 -----------
3246
3247 %1 Arrow starts with & in a \CD.
3248
3249 %2 \box0 has formula above the arrow, with suitable spacing around
3250 it (\;\; at end to clear arrow head).
3251
3252 %3 \box1 has formula below the arrow, with suitable spacing.
3253
3254 %4 \box2 is just the part below, because we will do things
3255 differently if there is no formula below.
3256
3257 %5 If we are in a \CD, \bigaw@ is initially \minCDaw@, otherwise
3258 \minaw@.
3259
3260 %6 If formula above or below the arrow is bigger than \bigaw@,
3261 change \bigaw@ to the maximum of these widths.
3262
3263 %7 Extra space goes before the arrow in a \CD.
3264
3265 %8 If there is something to go below the arrow, make an arrow of the
3266 right length, with \rightarrowfill, make it a \mathop, so we can
3267 use \limits to put the formulas above and below (the positioning
3268 this provides isn't ideal, so it would probably be better to use
3269 a more explicit construction here), and then make the resulting
3270 arrow a \mathrel.
3271
3272 %9 If nothing goes below, don't bother with the lower limit (so that
3273 unnecessary space below isn't produced).
3274
3275 %10 Extra space goes after the arrow in a \CD.
3276
3277 %11 Arrow ends with & in a \CD.
3278
3279
3280 @<#1<#2<#3< is exactly analogous.
3281
3282
3283 @)#1)#2)#3), @(#1(#2(#3( are for foreign keyboards that don't have
3284 < and > available (because they are used for { and }, which are
3285 instead \AA and \aa).
3286
3287
3288 @A#1A#2A, @V#1V#2V
3289 ------------------
3290 Vertical arrows don't need to bother with \ampersand@, since they are
3291 only used in \CD's. Notice that the space after \atdef@ is necessary,
3292 although space after @ in @A... and @V... won't be necessary later!
3293
3294
3295 @= is special, and used only in a \CD.
3296
3297
3298 @| is also used only in a \CD.
3299
3300
3301 \atdef@@\vert
3302 -------------
3303 We have to allow @\vert as a synonym, but this needs \atdef@@ instead.
3304
3305
3306 \pretend...\haswidth... is just a lot of syntax for a simple
3307 construction.
3308
3309
3310 \pmb is basically as in TB, p. 386, except that in math mode we use
3311 \mathpalette\pmb@, so that the symbol will change size. In addition,
3312 we want \pmb to keep binary relations and operators of the same type.
3313 We already have \binrel@, to start testing if something is of one of
3314 these two types, and we define \binrel@@ to complete things by making
3315 a \mathbin or \mathrel of the result.
3316
3317 The final detail involves the amount to move the three copies that we
3318 are going to superimpose on each other. We want to use mu's rather
3319 than points or ems. Since 1em=18mu, we have .025em= .45mu, so we use
3320 -.45mu instead of .025em, and -.9mu instead of .05em. And since
3321 .0544em =.7794mu, we set a box with this width, and raise by that
3322 width (we store the width in the dimen register \pmbraise@ to be sure
3323 that \box4 doesn't happen to get used somewhere in between).
3324
3325 We use \box3 in the definition of \pmb@ because \binrel@, used later,
3326 involves \box0 and \box1.
3327
3328
3329 \documentstyle is similar to LaTeX.
3330
3331
3332 \font\dummyft@ ...
3333 ------------------
3334 For syntax checking, we need the dummy font (TB, p. 401). Since the
3335 dummy.tfm's available don't seem to have all the \fontdimen's they
3336 need, we explicitly set them right.
3337
3338
3339 \def\fontlist@
3340 --------------
3341 We need a list of all the fonts that are used, in the form of TB,
3342 p. 378, so that we can set them all to \dummyft@. First we list all
3343 the fonts already used.
3344
3345
3346 \font@ is to be used instead of \font, so that when new fonts are
3347 loaded in they will be added to the list.
3348
3349
3350 At this point we can add
3351
3352 \loadmsam
3353 \loadmsbm
3354 \loadeufm
3355
3356
3357 \dodummy@ sets all fonts to \dummyft@
3358
3359
3360 \def\nopages@
3361 -------------
3362 We will want to say \newtoks\output (TB, p. 401) within this control
3363 sequence. Since \newtoks is \outer, we will simply use the code
3364 instead.
3365
3366
3367 \ifsyntax@ is used to record the fact that \syntax was used. This
3368 might be needed by AMSPPT.STY.
3369
3370
3371 \newcount\countxviii@, \def\syntax
3372 ----------------------------------
3373 To get syntax checking we also have to set \textfont0=\dummyft@, etc.
3374 We have to do this for all families, and the number of families is
3375 stored in \count18. The counter \countxviii@ is used to start with
3376 this value, and decrease in a \loop.
3377
3378 %1 For syntax checking, we set \syntax@true, for use by AMSPPT.STY,
3379 set all fonts to \dummyft@, with \dodummy@, set all \textfont's,
3380 etc., to \dummyft@, using the \loop construction, and then do
3381 everything else.
3382
3383
3384 \S@, \G@ and \P@ are used to check if S, G or P (or lowercase
3385 versions) were typed at the keyboard.
3386
3387
3388 \printoptions is a \loop that keeps insisting on an answer until S or
3389 s or G or g or P or p was typed at the keyboard. S chooses \syntax,
3390 G chooses \galleys, P just processes things as usual.
3391
3392 %1 This converts the answer to uppercase (TB, p. 331).
3393
3394
3395 \def\alloc@
3396 -----------
3397 We now change \alloc@, since there are no further allocations in the
3398 file (or in AMSPPT.STY) that might have to be kept out of the log
3399 file. The new definition will write things in the log file only if
3400 \showallocations is used, so that \ifalloc@ is true.
3401
3402
3403 \document doesn't really do much in AmS-TeX---it was just put in to
3404 correspond to LaTeX. But at this point we might as well clear out
3405 \alloclist@ and \fontlist@, since anything in them will have been
3406 acted on by now.
3407
3408
3409 \enddocument, similarly, is just \bye, though AMSPPT.STY will make it
3410 considerably more complicated.
3411
3412
3413 \plainproclaim, \plainfootnote store plain's \proclaim and \footnote,
3414 which have different syntax from \proclaim and \footnote in
3415 AMSPPT.STY.
3416
3417
3418 \proclaim and \footnote themselves are made undefined, until a style
3419 file, like AMSPPT.STY, defines them.
3420
3421
3422 \= is also made undefined, since \B has been provided, and goes
3423 better with \b [to correspond to \D and \d, where \d had to be added
3424 since \. was redefined].
3425
3426
3427 \cal, \mit and \oldstyle are made undefined also, since this method
3428 of changing fonts is not used in AmS-TeX.
3429
3430
3431 The last thing is to make @ active.
3432
3433
3434 **********************************************************************
3435
3436 HERE IS A SUMMARY OF ALL PLACES WHERE SPECIFIC VALUES USED IN THIS FILE
3437 MIGHT NEED TO BE REPLACED, BECAUSE OF DIFFERENT FONTS, STYLES, ETC.
3438
3439 \sdrd@, \drsr@, \sldl@, \dlsl@
3440 \captionwidth@
3441 \ex@
3442 spacing for \:
3443 \initic@, \negintic@, and possibly \intkern@
3444 spacing for \varinjlim, \varprojlim, \varliminf
3445 \baselineskip and \lineskip for \smallmatrix
3446 possibly \dotsspace@
3447 format for \cases
3448 \strutbox@
3449 \tagform@
3450 value of \interdisplaylinepenalty set by \allowdisplaybreaks
3451 \multlinegap@
3452 \multlinetaggap@ (and perhaps rule for setting tag separately on a
3453 \multline)
3454 spacing for \bmod, \pmod, \pod, \mod
3455 \kern's for \overrightarrow, etc.
3456 \dotso, \dotsb, \dotsm, \dotsc
3457 spacing in \dddot, etc.
3458 \mathsurround within the definition of \text@@ (\text outside of math),
3459 in case it is set to a non-zero value in general.
3460 \textdef@@
3461 \scriptfont\itfam, etc.
3462 \minaw@ and \minCDaw@
3463 \baselineskip, \lineskip, and \lineskiplimit in \CD
3464 the positioning of labels above and below arrows
3465 the size of the symbols given by @= and @|
3466 activation of \loadmsam, etc.
3467
3468 **********************************************************************