-
-
Notifications
You must be signed in to change notification settings - Fork 305
Expand file tree
/
Copy pathamsmath.dtx
More file actions
6732 lines (6722 loc) · 229 KB
/
amsmath.dtx
File metadata and controls
6732 lines (6722 loc) · 229 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
%
% \iffalse meta-comment
%
% Copyright (C) 1995, 2000, 2013 American Mathematical Society.
% Copyright (C) 2016-2026 LaTeX Project and American Mathematical Society.
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3c
% of this license or (at your option) any later version.
% The latest version of this license is in
% https://www.latex-project.org/lppl.txt
% and version 1.3c or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
%
% The Current Maintainer of this work is the LaTeX Project.
%
% \fi
%
%\iffalse
%<*driver>
\documentclass{amsdtx}
\def\MaintainedByLaTeXTeam#1{%
\begin{center}%
\fbox{\fbox{\begin{tabular}{@{}l@{}}%
This file is maintained by the \LaTeX{} Project team.\\%
Bug reports can be opened (category \texttt{#1}) at\\%
\url{https://latex-project.org/bugs/}.\end{tabular}}}\end{center}}
\raggedbottom
\let\savedarg\arg
\usepackage{amsmath}
\let\arg\savedarg
\GetFileInfo{amsmath.sty}
\begin{document}
\title{The \pkg{amsmath} package}
\author{Frank Mittelbach\and Rainer Sch\"opf\and Michael Downes\and
David M. Jones\and David Carlisle}
\date{Version \fileversion, \filedate}
\providecommand{\histnote}{}
\renewenvironment{histnote}{%
\trivlist\item[\hspace{\labelsep}\bfseries Historical Note:]%
}{%
\endtrivlist
}
\DocInput{amsmath.dtx}
\end{document}
%</driver>
%\fi
%
% \maketitle
% \MaintainedByLaTeXTeam{amslatex}
%
% \MakeShortVerb\|
%
% \section{Introduction}
%
% A \latex/ package named \pkg{amstex} was created in 1988--1989 by
% adapting \fn{amstex.tex} for use within \latex/. The \pkg{amsmath}
% package is the successor of the \pkg{amstex} package. It was
% substantially overhauled to integrate it with \latex/2e, which
% arrived on the scene in 1994. It provides more or less the same
% features, but there are quite a few organizational differences as
% well as some new features and bug fixes. For example, the
% \pkg{amstex} package automatically loaded the \pkg{amsfonts}
% package, but the \pkg{amsmath} package does not. At the present
% time (November 1999) user-level documentation of the commands
% provided here is found in the AMSmath Users' Guide,
% \fn{amsldoc.tex}.
%
% \MaybeStop{}
%
% Standard file identification.
% \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}% LaTeX 2.09 can't be used (nor non-LaTeX)
[1994/12/01]% LaTeX date must be December 1994 or later
% \end{macrocode}
%
% Providing a rollback to earlier version(s). Anything prior to
% 2018 we attempt to fulfill by using the version from 2018.
% \begin{macrocode}
\DeclareRelease{}{1994-06-01}{amsmath-2018-12-01.sty}
\DeclareRelease{}{2018-12-01}{amsmath-2018-12-01.sty}
\DeclareCurrentRelease{}{2019-04-01}
% \end{macrocode}
%
% \begin{macrocode}
\ProvidesPackage{amsmath}[2025/11/03 v2.18a AMS math features]
% \end{macrocode}
%
% \section{Catcode defenses}
%
% Some packages change the catcode of characters that are essential
% in low-level \tex/ syntax. Any package that does so does not
% qualify as a PWWO package (\qq{Plays Well With Others}) because it
% can cause other packages to fail if they are loaded later. \LaTeX{}
% is partly to blame for this because it fails to provide adequate
% built-in safeguards in the package loading mechanisms. In the
% absence of such safeguards, we will provide them here.
% \begin{macrocode}
\edef\@temp{\catcode 96=\number\catcode 96 }
\catcode\string `\`=12
\def\do#1{\catcode\number`#1=\number\catcode`#1}
\edef\@temp{%
\noexpand\AtEndOfPackage{%
\@temp
\do\"\do\'\do\(\do\)\do\*\do\+\do\,\do\-\do\.%
\do\/\do\<\do\=\do\>\do\[\do\]\do\^\do\_\relax
}%
}
\@temp
\def\do#1{\catcode\number`#1=12 }
\do\"\do\'\do\(\do\)\do\*\do\+\do\,\do\-\do\.
\do\/\do\<\do\=\do\>\do\[\do\]
\catcode`\^=7 \catcode`\_=8
% \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \section{Declare some options}
%
% Handling of limits on integrals, sums, operatornames.
% \begin{macrocode}
\DeclareOption{intlimits}{\let\ilimits@\displaylimits}
\DeclareOption{nointlimits}{\let\ilimits@\nolimits}
\DeclareOption{sumlimits}{\let\slimits@\displaylimits}
\DeclareOption{nosumlimits}{\let\slimits@\nolimits}
\DeclareOption{namelimits}{\PassOptionsToPackage{namelimits}{amsopn}}
\DeclareOption{nonamelimits}{%
\PassOptionsToPackage{nonamelimits}{amsopn}}
% \end{macrocode}
%
% The following two switches might have been defined already by the
% documentclass, but it doesn't hurt to re-execute the \cs{newif}'s.
% \begin{macrocode}
\newif\ifctagsplit@
\newif\iftagsleft@
% \end{macrocode}
% Right or left placement of equation numbers.
% \begin{macrocode}
\DeclareOption{leqno}{\tagsleft@true}
\DeclareOption{reqno}{\tagsleft@false}
\DeclareOption{centertags}{\ctagsplit@true}
\DeclareOption{tbtags}{\ctagsplit@false}
% \end{macrocode}
%
% The \opt{cmex10} option is an escape hatch for people who don't
% happen to have sizes 7--9 of the \fn{cmex} fonts available to them
% yet. (Strictly speaking they are considered part of a minimum
% \latex/ distribution now, i.e., all \LaTeXe{} users should have
% them, without needing to get the AMSFonts distrib.)
% \begin{macrocode}
\DeclareOption{cmex10}{%
\ifnum\cmex@opt=\@ne \def\cmex@opt{0}%
\else \def\cmex@opt{10}\fi
}
% \end{macrocode}
% To help things work out better with various package loading orders
% of \pkg{amsmath} and \pkg{amsfonts}, we establish a variable to
% communicate the status of the cmex font definition. If the
% \pkg{amsfonts} package was loaded first this variable might be
% already defined, in which case we want to preserve its value.
% \begin{macrocode}
\@ifundefined{cmex@opt}{\def\cmex@opt{7}}{}
% \end{macrocode}
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \section{Flush-left equations [DMJ]}
%
% The left margin of math environments is controlled by
% \cs{@mathmargin}. This can be set to \cs{@centering} to
% implement the default behaviour, i.e., centered equations, and to
% something else to implement the flushleft style.
%
% In theory, all that's needed to activate the flushleft mode
% in the AMS document classes is something like this:
% \begin{verbatim}
% \DeclareOption{fleqn}{%
% \AtBeginDocument{\@mathmargin30pt\relax}%
% }
% \end{verbatim}
% (In fact, unless the document class wants to specify the
% \cs{@mathmargin}, it doesn't need to do anything with the
% \opt{fleqn} option.)
% \begin{macrocode}
\newif\if@fleqn
%
\newskip\@mathmargin
\@mathmargin\@centering
%
\DeclareOption{fleqn}{%
\@fleqntrue
\@mathmargin = -1sp
\let\mathindent=\@mathmargin
\AtBeginDocument{%
\ifdim\@mathmargin= -1sp
\@mathmargin\leftmargini minus\leftmargini
\fi
}%
}
% \end{macrocode}
%
% DMJ: This ensures that \cs{@mathmargin} is given some sort of
% sensible default if the class doesn't specify one, while still
% allowing a user to override the default value in their document
% preamble. (Incidentally, I'm initializing \cs{@mathmargin} to
% \cs{leftmargini} for compatibility with \fn{fleqn.clo}, but I'm
% not at all convinced that's the right thing to do.)
%
% The next question is what happens when amsmath is used with
% one of the standard classes. Unfortunately, \latex/ implements
% \opt{fleqn} somewhat clumsily; instead of parameterizing the
% definitions of the math structures (as I've attempted to do
% here), \fn{fleqn.clo} declares a dimen \cn{mathindent} that is
% much like my \cs{@mathmargin} and then redefines \cn\[, \cn\],
% \cn{equation}, and \cn{eqnarray}. This means that things could
% get rather messy in 2.09 compatibility mode, since \fn{fleqn.clo}
% might be loaded after \fn{amsmath.sty}, which could cause a real
% mess.
%
% [mjd,1999/07/07]: Let \cs{mathindent} = \cs{@mathmargin} as
% envisioned by DMJ. Compatibility-mode documents will all use the
% \pkg{amstex} package, not \pkg{amsmath}. There is a remote chance
% of a problem if someone makes an assignment to \cs{mathindent} in a
% way that implicitly assumes it is a dimen register (inasmuch as it
% has now become a skip register), and the string ``plus'' follows in
% the input stream, but if someone's document croaks in that way, I
% think they will just have to bite the bullet and fix it. The
% alternative is to penalize a lot of other users with a known
% handicap.
%
% \section{Spacing around \cn{aligned} and \cn{gathered}}
%
% [dpc, 2016] Option to control the space to the left of aligned and gathered.
%
% Previously \cn{aligned} and \cn{gathered} inserted a thin space on
% their left but not their right, there is no good reason for this
% that anyone can remember, it has just always been that way
% inherited from amstex. The usual advice to authors has been to use
% |\!\begin{aligned}| to get better spacing.
%
% Here introduce:
%
% \opt{alignedleftspaceyes} to keep the behaviour of adding this space.
%
% \opt{alignedleftspaceno} to disable adding this space.
%
% \opt{alignedleftspaceyesifneg} the new default behaviour, do not add
% the space unless the environment is preceded by a negative skip or
% kern, so that |\!\begin{aligned}| works as before.
%
% \changes{v2.16a}{2016/11/05}{New options to control aligned spacing}
% \begin{macrocode}
\DeclareOption{alignedleftspaceyes}{\def\alignedspace@left{\null\,}}
\DeclareOption{alignedleftspaceno}{\def\alignedspace@left{\null}}
\DeclareOption{alignedleftspaceyesifneg}{%
\def\alignedspace@left{%
\edef\@tempa{\expandafter\@car\the\lastskip\@nil}%
\if-\@tempa\null\,%
\else
\edef\@tempa{\expandafter\@car\the\lastkern\@nil}%
\if-\@tempa\null\,%
\else\null
\fi
\fi}%
}
% \end{macrocode}
%
%
% \begin{macrocode}
\DeclareOption{?}{}
% \end{macrocode}
%
% \begin{macrocode}
\ExecuteOptions{%
nointlimits,sumlimits,namelimits,centertags,alignedleftspaceyesifneg}
% \end{macrocode}
% The \cs{par} after \cs{ProcessOptions} is to ensure the correct
% line number on screen if an error occurs during option processing;
% otherwise the lookahead for a \qc{\*} option would result in \tex/
% showing the following line instead.
% \begin{macrocode}
\ProcessOptions\par
% \end{macrocode}
%
% \begin{macrocode}
\@ifpackagewith{amsmath}{?}{%
\typeout{^^J%
Documentation for the amsmath package is found in amsldoc.dvi^^J%
(or .pdf or .tex).^^J%
^^J%
See also https://www.ams.org/tex/amslatex.html.^^J%
^^J%
Note: Using the first edition of The LaTeX Companion (1994) without^^J%
errata as a guide for amsmath use is not recommended.^^J%
}%
}{%
\typeout{%
For additional information on amsmath, use the \lq ?\rq\space option.%
}%
}
% \end{macrocode}
%
% Processing to handle the \opt{cmex10} option is a little tricky
% because of different possible loading orders for \pkg{amsmath}
% and \pkg{amsfonts}. The package \pkg{amsmath} sets the
% \cs{cmex@opt} flag to 0, 7 or 10, and in the past the package
% \pkg{amsfonts} did set the flag to 1 or 0. These days it always
% sets it to 10. The situation is a bit unsettled but we don't own
% \pkg{amsfonts}.
% \changes{v2.17d}{2019/12/01}{docu update, no code change (gh/200)}
% \begin{macrocode}
\ifnum\cmex@opt=7 \relax
\DeclareFontShape{OMX}{cmex}{m}{n}{%
<-8>cmex7<8>cmex8<9>cmex9%
<10><10.95><12><14.4><17.28><20.74><24.88>cmex10%
}{}%
\expandafter\let\csname OMX/cmex/m/n/10\endcsname\relax
\else
\ifnum\cmex@opt=\z@ % need to override cmex7 fontdef from amsfonts
% \end{macrocode}
% Force reloading of the OMX/cmex font definition file.
% \begin{macrocode}
\begingroup
\fontencoding{OMX}\fontfamily{cmex}%
\expandafter\let\csname OMX+cmex\endcsname\relax
\try@load@fontshape
\endgroup
% \end{macrocode}
% The \fn{cmex10} font gets special preload handling in the building
% of the \latex/ format file, need an extra bit here to work around
% that.
% \begin{macrocode}
\expandafter\let\csname OMX/cmex/m/n/10\endcsname\relax
\def\cmex@opt{10}%
\fi
\fi
% \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \section{Call some other packages}
%
% The \pkg{amstext} package provides the \cn{text} command. The
% \pkg{amsbsy} package provides \cn{boldsymbol} and \cn{pmb}. (Since
% 1997 it is usually better to use the \pkg{bm} package instead; but
% I think we have to keep \pkg{amsbsy} here for backward
% compatibility [mjd,1999/11/19].) The \pkg{amsopn} package provides
% \cn{DeclareMathOperator}.
% \begin{macrocode}
\RequirePackage{amstext}[1995/01/25]
%\RequirePackage{amsgen}[1995/01/25] % already loaded by amstext
\RequirePackage{amsbsy}[1995/01/20]
\RequirePackage{amsopn}[1995/01/20]
% \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \section{Miscellaneous}
%
% \begin{macro}{\ams@newcommand}
% Where \pkg{stix} and \pkg{amsmath} define the same control
% sequences, we want to avoid inadvertently overriding \pkg{stix}'s
% definitions. If \pkg{stix} is loaded before \pkg{amsmath}, the
% following conditional takes care of the problem. There is
% similar code in the \pkg{stix} package in case \pkg{amsmath} is
% loaded first.
% \begin{macrocode}
\@ifpackageloaded{stix}{%
\let\ams@newcommand\providecommand
\let\ams@renewcommand\providecommand
\let\ams@def\providecommand
\let\ams@DeclareRobustCommand\providecommand
}{%
\let\ams@newcommand\newcommand
\let\ams@renewcommand\renewcommand
\let\ams@def\def
\let\ams@DeclareRobustCommand\DeclareRobustCommand
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@amsmath@err}
% Defining this error function saves main mem.
% \begin{macrocode}
\def\@amsmath@err{\PackageError{amsmath}}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\AmS}
% The \cs{AmS} prefix can be used to construct the combination
% |\AmS-\LaTeX|.
% \begin{macrocode}
\providecommand{\AmS}{{\protect\AmSfont
A\kern-.1667em\lower.5ex\hbox{M}\kern-.125emS}}
% \end{macrocode}
% In \cn{AmSfont} we call cmsy directly in lieu of trying to access
% it through the math fonts setup (e.g. |\the\textfont2|) because
% math fonts can't be relied on to be properly set up if we are not
% inside a math formula. This means that if this command is used in a
% document where CM fonts are not wanted, then a font substitution
% will need to be declared, e.g.:
% \begin{verbatim}
% \DeclareFontShape{OMS}{cmsy}{m}{n}{ <-> sub * xxx/m/n }{}
% \end{verbatim}
% where |xxx| is some alternate font family.
% Taking the first letter of \cs{f@series} will produce |b| or |m|
% for the most common values (|b,bx,m|). It may produce nonsense for
% more unusual values of \cs{f@series}, so for safety's sake we have
% an additional \cs{if} test. We want to avoid setting the series to
% |bx| because in a standard \latex/ installation the combination
% |cmsy/bx/n| does not have a font definition, and the user
% would get a font substitution warning on screen.
% \begin{macrocode}
\newcommand{\AmSfont}{%
\usefont{OMS}{cmsy}{\if\@xp\@car\f@series\@nil bb\else m\fi}{n}}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@mathmeasure}
% The function |\@mathmeasure| takes three arguments; the third arg
% is typeset as a math formula in an hbox, using arg |#2| as the
% mathstyle, and the result is left in the box named by the first
% arg. It is assumed that we are already in math mode, so we can turn
% off |\everymath| (in particular, |\check@mathfonts|).
%
% As of 2018/12 release we don't turn off |\evermath| as this
% optimization can be harmful.
% \changes{v2.17b}{2018/12/01}{Don't drop \cs{frozen@everymath}}
% \begin{macrocode}
\ifx\leavevmode@ifvmode\@undefined % kernel is < 2018/12
\def\@mathmeasure#1#2#3{\setbox#1\hbox{\frozen@everymath\@emptytoks
\m@th$#2#3$}}
\else
\def\@mathmeasure#1#2#3{\setbox#1\hbox{%
\m@th$#2#3$}}
\fi
% \end{macrocode}
% \end{macro}
%
% The \cs{inf@bad} constant is for testing overfull boxes.
% \begin{macrocode}
\@ifundefined{inf@bad}{%
\newcount\inf@bad \inf@bad=1000000 \relax
}{}
% \end{macrocode}
%
%\subsection{Math spacing commands}
%
% \begin{macro}{\tmspace}
% \begin{macro}{\,}
% \begin{macro}{\thinspace}
% \begin{macro}{\!}
% \begin{macro}{\negthinspace}
% \begin{macro}{\:}
% \begin{macro}{\medspace}
% \begin{macro}{\negmedspace}
% \begin{macro}{\;}
% \begin{macro}{\thickspace}
% \begin{macro}{\negthickspace}
% Here we fill in some gaps in the set of spacing commands, and make them
% all work equally well in or out of math.
% We want all these commands to be robust but declaring them all with
% \cs{DeclareRobustCommand} uses up an control sequence name per
% command; to avoid this, we define a common command \cs{tmspace}
% (text-or-math space) which carries the robustness burden for all of
% them. The standard \cs{relax} before the \cs{ifmmode} is not
% necessary because of the \cs{protect} added by
% \cs{DeclareRobustCommand}.
% \changes{v2.17b}{2018/12/01}{Start LR-mode for \cs{thinspace} and
% friends if necessary (github/49)}
%
% We start by undefining a number of commands (which in a current
% \LaTeX{} kernel will be defined, so that the
% \cs{DeclareRobustCommand} declarations below do not add a
% ``Command redefined'' info into the log.
% \begin{macrocode}
\let\tmspace\@undefined
\let\,\@undefined
\let\!\@undefined
\let\:\@undefined
\let\negmedspace\@undefined
\let\negthickspace\@undefined
% \end{macrocode}
%
%
% \changes{v2.17g}{2020/03/07}{Math/text spacing commands are now in
% the \LaTeX{} kernel and are made robust (gh/303)}
% \begin{macrocode}
\ifx\leavevmode@ifvmode\@undefined
\DeclareRobustCommand\tmspace[3]{%
\ifmmode\mskip#1#2\else\kern#1#3\fi\relax}
\else
\DeclareRobustCommand\tmspace[3]{%
\ifmmode\mskip#1#2\else\leavevmode@ifvmode\kern#1#3\fi\relax}
\fi
\DeclareRobustCommand\,{\tmspace+\thinmuskip{.1667em}}
\let\thinspace\,
\DeclareRobustCommand\!{\tmspace-\thinmuskip{.1667em}}
\let\negthinspace\!
\DeclareRobustCommand\:{\tmspace+\medmuskip{.2222em}}
\let\medspace\:
\DeclareRobustCommand\negmedspace{\tmspace-\medmuskip{.2222em}}
\renewcommand\;{\tmspace+\thickmuskip{.2777em}}
\let\thickspace\;
\DeclareRobustCommand\negthickspace{\tmspace-\thickmuskip{.2777em}}
% \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\mspace}
% And while we're at it, why don't we provide an equivalent of
% \cn{hspace} for math mode use. This allows use of |mu| units in
% (for example) constructing compound math symbols.
% \begin{macrocode}
\newcommand{\mspace}[1]{\mskip#1\relax}
% \end{macrocode}
% \end{macro}
%
% \subsection{Vertical bar symbols}
% \begin{macro}{\lvert}
% \begin{macro}{\rvert}
% \begin{macro}{\lVert}
% \begin{macro}{\rVert}
% Add left/right specific versions of \cn{vert}, \cn{Vert}. Don't
% assume the delimiter codes are the CM defaults.
% \begin{macrocode}
\def\@tempa#1#2\@nil{%
\ifx\delimiter#1\@tempcnta#2\relax\else\@tempcnta\z@\fi
}
\@xp\@tempa\vert\@empty\@nil
\ifnum\@tempcnta>\z@
\advance\@tempcnta "4000000
% \end{macrocode}
% Use \cs{protected} on the new delimiters.
% \changes{v2.17e}{2020/01/20}{Make delimiters robust (gh/251))}
% \begin{macrocode}
\protected\xdef\lvert{\delimiter\number\@tempcnta\space }
\advance\@tempcnta "1000000
\protected\xdef\rvert{\delimiter\number\@tempcnta\space }
\else
\ifx\@@undefined\lvert
% Fall back to cmex encoding since we don't know what else to do.
\DeclareMathDelimiter{\lvert}
{\mathopen}{symbols}{"6A}{largesymbols}{"0C}
\DeclareMathDelimiter{\rvert}
{\mathclose}{symbols}{"6A}{largesymbols}{"0C}
\fi
\fi
\@xp\@tempa\Vert\@empty\@nil
\ifnum\@tempcnta>\z@
\advance\@tempcnta "4000000
\protected\xdef\lVert{\delimiter\number\@tempcnta\space }
\advance\@tempcnta "1000000
\protected\xdef\rVert{\delimiter\number\@tempcnta\space }
\else
\ifx\@@undefined\lVert
\DeclareMathDelimiter{\lVert}
{\mathopen}{symbols}{"6B}{largesymbols}{"0D}
\DeclareMathDelimiter{\rVert}
{\mathclose}{symbols}{"6B}{largesymbols}{"0D}
\fi
\fi
% \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \subsection{Fractions}
% Bury the generalized fraction primitives \cs{over}, \cs{atop},
% etc., because of their bizarre syntax, which is decidedly out of
% place in a \latex/ document.
% \begin{macrocode}
\@saveprimitive\over\@@over
\@saveprimitive\atop\@@atop
\@saveprimitive\above\@@above
\@saveprimitive\overwithdelims\@@overwithdelims
\@saveprimitive\atopwithdelims\@@atopwithdelims
\@saveprimitive\abovewithdelims\@@abovewithdelims
% \end{macrocode}
%
% \begin{macro}{\primfrac}
% If someone insists on using \cs{over}, give a warning the first
% time and then resurrect the old definition. Laissez-faire policy.
% \begin{macrocode}
\DeclareRobustCommand{\primfrac}[1]{%
\PackageWarning{amsmath}{%
Foreign command \@backslashchar#1;\MessageBreak
\protect\frac\space or \protect\genfrac\space should be used instead%
\MessageBreak
}
\global\@xp\let\csname#1\@xp\endcsname\csname @@#1\endcsname
\csname#1\endcsname
}
% \end{macrocode}
% \end{macro}
% \begin{macrocode}
\renewcommand{\over}{\primfrac{over}}
\renewcommand{\atop}{\primfrac{atop}}
\renewcommand{\above}{\primfrac{above}}
\renewcommand{\overwithdelims}{\primfrac{overwithdelims}}
\renewcommand{\atopwithdelims}{\primfrac{atopwithdelims}}
\renewcommand{\abovewithdelims}{\primfrac{abovewithdelims}}
% \end{macrocode}
%
% \cn{frac} calls \cn{@@over} directly instead of via \cn{genfrac}, for
% better speed because it is so common. \cn{tfrac} and \cn{dfrac} are
% abbreviations for some commonly needed mathstyle overrides. To
% conserve csnames we avoid making \cn{dfrac} and \cn{tfrac} robust
% (\cn{genfrac} is itself robust).
% \changes{v2.17i}{2020/09/23}{added \cs{Ustack} for luatex (moved patch from lualatex-math)}
% \changes{v2.17n}{2022/04/08}{Make fraction commands robust (gh/123)}
% \begin{macrocode}
%
\ifx\directlua\@undefined
\DeclareRobustCommand{\frac}[2]{{\begingroup#1\endgroup\@@over#2}}
\else
\DeclareRobustCommand{\frac}[2]{{\Ustack{\begingroup#1\endgroup\@@over#2}}}
\fi
\DeclareRobustCommand{\dfrac}{\genfrac{}{}{}0}
\DeclareRobustCommand{\tfrac}{\genfrac{}{}{}1}
% \end{macrocode}
% The \cn{binom} command for binomial notation works like \cn{frac}
% and has similar variants. Note that we do not use \cs{z@} in
% \cn{dbinom} and \cn{tbinom} because they are not top-level robust
% like \cn{binom}, and so the \cs{z@} with the potentially
% problematic \qc{\@} character would become visible when writing one
% of those commands to a \fn{.toc} file.
% \changes{v2.17n}{2022/04/08}{Make binom commands robust (gh/123)}
% \begin{macrocode}
\DeclareRobustCommand{\binom}{\genfrac()\z@{}}
\DeclareRobustCommand{\dbinom}{\genfrac(){0pt}0}
\DeclareRobustCommand{\tbinom}{\genfrac(){0pt}1}
% \end{macrocode}
%
% \begin{macro}{\genfrac}
% \changes{v2.16a}{2016/11/05}{New genfrac implementation for extended
% TeXs}
% This command provides access to \tex/'s generalized fraction
% primitives. Args: \arg{1} left delim, \arg{2} right delim, \arg{3}
% line thickness, \arg{4} mathstyle override, \arg{5} numerator,
% \arg{6} denominator. But we only read the first four args at first,
% in order to give us a moment to select the proper generalized
% fraction primitive. Any of those four args could be empty, and when
% empty the obvious defaults are selected (no delimiters, default
% line thickness (normally .4pt), and no mathstyle override).
%
% the |withdelims| primitives do not work in xetex with OpenType
% fonts, and the relevant font dimen parameters are often not set
% in luatex as there are no matching values in the OpenType Math
% table, so here we use variants that use the font parameters if
% they are set, but scale using |\left\right| rather than the
% |withdelims| primitives.
%
% \begin{macrocode}
\ifx\directlua\@undefined
% \end{macrocode}
%
% \begin{macrocode}
\ifx\XeTeXcharclass\@undefined
% \end{macrocode}
% Classic version
% \begin{macrocode}
\DeclareRobustCommand{\genfrac}[4]{%
\def\@tempa{#1#2}%
\edef\@tempb{\@nx\@genfrac\@mathstyle{#4}%
\csname @@\ifx @#3@over\else above\fi
\ifx\@tempa\@empty \else withdelims\fi\endcsname}
\@tempb{#1#2#3}}
% \end{macrocode}
%
% \begin{macrocode}
\else
% \end{macrocode}
% XeTeX version
% \begin{macrocode}
\def\genfrac@rule#1#2#3#4{%
\hbox{$\left#1\vcenter{\hrule \@width\z@
\@height
\ifdim\fontdimen#2#3\tw@=\z@
#4\fontdimen6#3\tw@
\else
\fontdimen#2#3\tw@
\fi
}\right.$}}
% \end{macrocode}
%
% \begin{macrocode}
\def\genfrac@choice#1#2{%
\ifx @#2@\else
% \end{macrocode}
% \changes{v2.17a}{2017/09/02}{move \cs{nulldelimiterspace} correction}
% \begin{macrocode}
\ifx c#1\kern-\nulldelimiterspace\fi
{\delimitershortfall\z@\delimiterfactor\@m
\mathsurround\z@\nulldelimiterspace\z@
\mathchoice
{\genfrac@rule{#2}{20}\textfont{2.39}}%
{\genfrac@rule{#2}{21}\textfont{1}}%
{\genfrac@rule{#2}{21}\scriptfont{1.45}}%
{\genfrac@rule{#2}{21}\scriptscriptfont{1.35}}%
}%
\ifx o#1\kern-\nulldelimiterspace\fi
\fi
}
% \end{macrocode}
%
% \begin{macrocode}
\DeclareRobustCommand{\genfrac}[6]{{%
\@mathstyle{#4}%
\genfrac@choice o{#1}%
{\begingroup#5\endgroup\ifx @#3@\@@over\else\@@above\fi#3\relax#6}%
\genfrac@choice c{#2}%
}}
% \end{macrocode}
%
% \begin{macrocode}
\fi
\else
% \end{macrocode}
% LuaTeX version
% \begin{macrocode}
\def\genfrac@rule#1#2#3{%
\hbox{$\left#1\vcenter{\hrule \@width\z@
\@height
\ifdim\Umathfractiondelsize#2=\z@
#3\fontdimen6#3\tw@
\else
\Umathfractiondelsize#2%
\fi
}\right.$}}
% \end{macrocode}
%
% \begin{macrocode}
\def\genfrac@choice#1#2{%
\ifx @#2@\else
% \end{macrocode}
% \changes{v2.17a}{2017/09/02}{move \cs{nulldelimiterspace} correction}
% \begin{macrocode}
\ifx c#1\kern-\nulldelimiterspace\fi
{\delimitershortfall\z@\delimiterfactor\@m
\mathsurround\z@\nulldelimiterspace\z@
\mathchoice
{\genfrac@rule{#2}\displaystyle{2.39}}%
{\genfrac@rule{#2}\textstyle{1}}%
{\genfrac@rule{#2}\scriptstyle{1.45}}%
{\genfrac@rule{#2}\scriptscriptstyle{1.35}}%
}%
\ifx o#1\kern-\nulldelimiterspace\fi
\fi
}
% \end{macrocode}
% \changes{v2.17i}{2020/09/23}{added \cs{Ustack} (moved patch from lualatex-math)}
% \begin{macrocode}
\DeclareRobustCommand{\genfrac}[6]{{%
\@mathstyle{#4}%
\genfrac@choice o{#1}%
{\Ustack {\begingroup#5\endgroup\ifx @#3@\@@over\else\@@above\fi#3\relax#6}}%
\genfrac@choice c{#2}%
}}
% \end{macrocode}
%
% \begin{macrocode}
\fi
% \end{macrocode}
%
% End of test for Lua\TeX/Xe\TeX.
%
% \cs{@genfrac} takes the preceding arguments and reads the
% numerator and denominator. Note that there's no convenient way to
% make the numerator and denominator \emph{contents}
% displaystyle, through this interface.
%
% Args: \arg{1} mathstyle, \arg{2} fraction primitive,
% \arg{3} delimiters and rule thickness,
% \arg{4} numerator, \arg{5} denominator.
% \begin{macrocode}
\def\@genfrac#1#2#3#4#5{{#1{\begingroup#4\endgroup#2#3\relax#5}}}
% \end{macrocode}
% \end{macro}
%
% Empty mathstyle arg: no change; 0 = displaystyle, 1 = textstyle, 2
% = scriptstyle, 3 = scriptscriptstyle.
% \begin{macrocode}
\def\@mathstyle#1{%
\ifx\@empty#1\@empty\relax
\else\ifcase#1\displaystyle % case 0
\or\textstyle\or\scriptstyle\else\scriptscriptstyle\fi\fi}
% \end{macrocode}
%
% \subsection{Sums and Integrals}
% Default value for sum limits is \cs{displaylimits}, see option
% `nosumlimits'.
%
% We redefine all the cumulative operator symbols to use
% \cs{slimits@} so that switching between \cs{displaylimits} and
% \cs{nolimits} can be controlled by package options. Also add
% \cs{DOTSB} for the benefit of the dots lookahead. But we'd better
% make sure \cn{coprod} and the others are simple mathchars; if not,
% the attempted changes will probably fail miserably.
%
% \changes{v2.15}{2016/02/20}{Accept \cs{Umathchar}}
% \begin{macrocode}
\begingroup
% \end{macrocode}
% \begin{macrocode}
\edef\@tempa{\string\mathchar"}
\edef\@tempd{\string\Umathchar"}
\def\@tempb#1"#2\@nil{#1"}
\edef\@tempc{\expandafter\@tempb\meaning\coprod "\@nil}
\ifx\@tempc\@tempd\let\@tempc\@tempa\fi
% \end{macrocode}
% \begin{macrocode}
\ifx\@tempa\@tempc
\global\let\coprod@\coprod
\gdef\coprod{\DOTSB\coprod@\slimits@}
\global\let\bigvee@\bigvee
\gdef\bigvee{\DOTSB\bigvee@\slimits@}
\global\let\bigwedge@\bigwedge
\gdef\bigwedge{\DOTSB\bigwedge@\slimits@}
\global\let\biguplus@\biguplus
\gdef\biguplus{\DOTSB\biguplus@\slimits@}
\global\let\bigcap@\bigcap
\gdef\bigcap{\DOTSB\bigcap@\slimits@}
\global\let\bigcup@\bigcup
\gdef\bigcup{\DOTSB\bigcup@\slimits@}
\global\let\prod@\prod
\gdef\prod{\DOTSB\prod@\slimits@}
\global\let\sum@\sum
\gdef\sum{\DOTSB\sum@\slimits@}
\global\let\bigotimes@\bigotimes
\gdef\bigotimes{\DOTSB\bigotimes@\slimits@}
\global\let\bigoplus@\bigoplus
\gdef\bigoplus{\DOTSB\bigoplus@\slimits@}
\global\let\bigodot@\bigodot
\gdef\bigodot{\DOTSB\bigodot@\slimits@}
\global\let\bigsqcup@\bigsqcup
\gdef\bigsqcup{\DOTSB\bigsqcup@\slimits@}
\fi
\endgroup
% \end{macrocode}
%
% \subsection{Roots and radicals}
%
% \begin{macro}{\root}
% This root stuff needs syntax work and implementation work. Surely
% something more compact can be done?? [mjd, 1994/09/05]
% \begin{macrocode}
\newcommand{\leftroot}{\@amsmath@err{\Invalid@@\leftroot}\@eha}
\newcommand{\uproot}{\@amsmath@err{\Invalid@@\uproot}\@eha}
\newcount\uproot@
\newcount\leftroot@
\renewcommand{\root}{\relaxnext@
\DN@{\ifx\@let@token\uproot\let\next@\nextii@\else
\ifx\@let@token\leftroot\let\next@\nextiii@\else
\let\next@\plainroot@\fi\fi\next@}%
\def\nextii@\uproot##1{\uproot@##1\relax\FN@\nextiv@}%
\def\nextiv@{\ifx\@let@token\@sptoken\DN@. {\FN@\nextv@}\else
\DN@.{\FN@\nextv@}\fi\next@.}%
\def\nextv@{\ifx\@let@token\leftroot\let\next@\nextvi@\else
\let\next@\plainroot@\fi\next@}%
\def\nextvi@\leftroot##1{\leftroot@##1\relax\plainroot@}%
\def\nextiii@\leftroot##1{\leftroot@##1\relax\FN@\nextvii@}%
\def\nextvii@{\ifx\@let@token\@sptoken
\DN@. {\FN@\nextviii@}\else
\DN@.{\FN@\nextviii@}\fi\next@.}%
\def\nextviii@{\ifx\@let@token\uproot\let\next@\nextix@\else
\let\next@\plainroot@\fi\next@}%
\def\nextix@\uproot##1{\uproot@##1\relax\plainroot@}%
\bgroup\uproot@\z@\leftroot@\z@\FN@\next@}
\def\plainroot@#1\of#2{\setbox\rootbox\hbox{%
$\m@th\scriptscriptstyle{#1}$}%
\mathchoice{\r@@t\displaystyle{#2}}{\r@@t\textstyle{#2}}
{\r@@t\scriptstyle{#2}}{\r@@t\scriptscriptstyle{#2}}\egroup}
% \end{macrocode}
% \end{macro}
%
% \changes{v2.0}{1999/06/17}{Normalize @@sqrt to sqrtsign}
% Name change from \cs{@@sqrt} to \cs{sqrtsign} happened in the
% 1995/12/01 release of \latex/. If we were to assume that
% \cs{sqrtsign} is defined then someone with the 1995/06/01 release
% of \latex/ would have trouble using this package.
% \begin{macrocode}
\@ifundefined{sqrtsign}{\let\sqrtsign\@@sqrt}{}
\def\r@@t#1#2{\setboxz@h{$\m@th#1\sqrtsign{#2}$}%
\dimen@\ht\z@\advance\dimen@-\dp\z@
\setbox\@ne\hbox{$\m@th#1\mskip\uproot@ mu$}%
\advance\dimen@ by1.667\wd\@ne
\mkern-\leftroot@ mu\mkern5mu\raise.6\dimen@\copy\rootbox
\mkern-10mu\mkern\leftroot@ mu\boxz@}
% \end{macrocode}
%
% \subsection{Et cetera}
%
% \changes{v2.0}{1999/06/18}{Leave Greek cap letters unaltered}
%
% Specific names for the variant italic cap Greek letters are not
% defined by \latex/. If no preceding package defined these, we will
% define them now.
% \begin{macrocode}
\@ifundefined{varGamma}{%
\DeclareMathSymbol{\varGamma}{\mathord}{letters}{"00}
\DeclareMathSymbol{\varDelta}{\mathord}{letters}{"01}
\DeclareMathSymbol{\varTheta}{\mathord}{letters}{"02}
\DeclareMathSymbol{\varLambda}{\mathord}{letters}{"03}
\DeclareMathSymbol{\varXi}{\mathord}{letters}{"04}
\DeclareMathSymbol{\varPi}{\mathord}{letters}{"05}
\DeclareMathSymbol{\varSigma}{\mathord}{letters}{"06}
\DeclareMathSymbol{\varUpsilon}{\mathord}{letters}{"07}
\DeclareMathSymbol{\varPhi}{\mathord}{letters}{"08}
\DeclareMathSymbol{\varPsi}{\mathord}{letters}{"09}
\DeclareMathSymbol{\varOmega}{\mathord}{letters}{"0A}
}{}
% \end{macrocode}
%
% \begin{macro}{\overline}
% \amstex/ redefines \cn{overline} as shown here, for reasons that
% are probably less important in \latex/: Make it read its argument
% as a macro argument rather than a ``math field'' (\emph{The
% \tex/book}, Chapter 26), to avoid problems when something that is
% apparently a single symbol is actually a non-simple macro (e.g.,
% \cn{dag}) \emph{and} is given as a single-token argument without
% enclosing braces.
% \begin{macrocode}
\@saveprimitive\overline\@@overline
\DeclareRobustCommand{\overline}[1]{\@@overline{#1}}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\boxed}
% The \cs{boxed} command is specifically intended to put a box around
% an equation or piece of an equation. (Not including the equation
% number.) This isn't trivial for end-users to do it properly
% with \cs{fbox} so we provide a command for them.
% \changes{v2.17n}{2022/04/08}{Make \cs{boxed} command robust (gh/123)}
% \begin{macrocode}
\DeclareRobustCommand{\boxed}[1]{\fbox{\m@th$\displaystyle#1$}}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\implies}
% \begin{macro}{\impliedby}
% \begin{macrocode}
\newcommand{\implies}{\DOTSB\;\Longrightarrow\;}
\newcommand{\impliedby}{\DOTSB\;\Longleftarrow\;}
% \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\And}
% \begin{macrocode}
\def\And{\DOTSB\;\mathchar"3026 \;}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\nobreakdash}
% The command \cn{nobreakdash} is designed only for use before a
% hyphen or dash (|-|, |--|, or |---|).
% Setting the hyphen in a box and then unboxing it means that the
% normal penalty will not be added after it---and if the penalty is
% not there a break will not be taken (unless an explicit penalty
% or glue follows, thus the final \verb=\nobreak=).
% \begin{macrocode}
\newcommand{\nobreakdash}{\leavevmode
\toks@\@emptytoks \def\@tempa##1{\toks@\@xp{\the\toks@-}\FN@\next@}%
\DN@{\ifx\@let@token-\@xp\@tempa
\else\setboxz@h{\the\toks@\nobreak}\unhbox\z@\fi}%
\FN@\next@
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\colon}
% \cs{colon} is for a colon in math that resembles a text colon:
% small space on the left, larger space on the right. The \qc{\:}
% character by itself is treated as a \cs{mathrel} i.e. large, equal
% spacing on both sides.
% \changes{v2.17n}{2022/04/08}{Make \cs{colon} command robust (gh/123)}
% \begin{macrocode}
\DeclareRobustCommand{\colon}{\nobreak\mskip2mu\mathpunct{}\nonscript
\mkern-\thinmuskip{:}\mskip6muplus1mu\relax}
% \end{macrocode}
% \end{macro}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \section{Ellipsis dots}
%
% We can't use \cs{newif} for \cs{ifgtest@} because we want
% to include \cs{global} in the definitions of
% \cs{gtest@true} and \cs{gtest@false}.
% \begin{macrocode}
\let\ifgtest@\iffalse % initial value