-
Notifications
You must be signed in to change notification settings - Fork 7
/
mathtools.dtx
7068 lines (6998 loc) · 247 KB
/
mathtools.dtx
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) 2004-2011 by Morten Hoegholm
% Copyright (C) 2012-2019 by Lars Madsen
% Copyright (C) 2020- by Lars Madsen, The LaTeX3 team
%
% 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
% http://www.latex-project.org/lppl.txt
% and version 1.3c or later is part of all distributions of
% LaTeX version 2008/05/05 or later.
%
% This work has the LPPL maintenance status "maintained".
%
% This Current Maintainer of this work is
% Lars Madsen
%
% This work consists of the main source file mathtools.dtx
% and the derived files
% mathtools.sty, mathtools.pdf, mathtools.ins, mathtools.drv.
%
% Distribution:
% CTAN:macros/latex/contrib/mh/mathtools.dtx
% CTAN:macros/latex/contrib/mh/mathtools.pdf
%
% Unpacking:
% (a) If mathtools.ins is present:
% tex mathtools.ins
% (b) Without mathtools.ins:
% tex mathtools.dtx
% (c) If you insist on using LaTeX
% latex \let\install=y\input{mathtools.dtx}
% (quote the arguments according to the demands of your shell)
%
% Documentation:
% (a) If mathtools.drv is present:
% latex mathtools.drv
% (b) Without mathtools.drv:
% latex mathtools.dtx; ...
% The class ltxdoc loads the configuration file ltxdoc.cfg
% if available. Here you can specify further options, e.g.
% use A4 as paper format:
% \PassOptionsToClass{a4paper}{article}
%
% Programm calls to get the documentation (example):
% pdflatex mathtools.dtx
% makeindex -s gind.ist mathtools.idx
% pdflatex mathtools.dtx
% makeindex -s gind.ist mathtools.idx
% pdflatex mathtools.dtx
%
% Installation:
% TDS:tex/latex/mh/mathtools.sty
% TDS:doc/latex/mh/mathtools.pdf
% TDS:source/latex/mh/mathtools.dtx
%
%<*ignore>
\begingroup
\def\x{LaTeX2e}
\expandafter\endgroup
\ifcase 0\ifx\install y1\fi\expandafter
\ifx\csname processbatchFile\endcsname\relax\else1\fi
\ifx\fmtname\x\else 1\fi\relax
\else\csname fi\endcsname
%</ignore>
%<*install>
\input docstrip.tex
\Msg{************************************************************************}
\Msg{* Installation}
\Msg{* Package: mathtools 2024/10/04 v1.31}
\Msg{************************************************************************}
\keepsilent
\askforoverwritefalse
\preamble
This is a generated file.
Copyright (C) 2002-2011 by Morten Hoegholm
Copyright (C) 2012-2019 by Lars Madsen
Copyright (C) 2020- by Lars Madsen, the LaTeX3 project
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
http://www.latex-project.org/lppl.txt
and version 1.3c or later is part of all distributions of
LaTeX version 2008/05/04 or later.
This work has the LPPL maintenance status "maintained".
This Current Maintainer of this work is
Lars Madsen and the LaTeX3 project
This work consists of the main source file mathtools.dtx
and the derived files
mathtools.sty, mathtools.pdf, mathtools.ins, mathtools.drv.
\endpreamble
\generate{%
\file{mathtools.ins}{\from{mathtools.dtx}{install}}%
\file{mathtools.drv}{\from{mathtools.dtx}{driver}}%
\usedir{tex/latex/mh}%
\file{mathtools.sty}{\from{mathtools.dtx}{package}}%
}
\obeyspaces
\Msg{************************************************************************}
\Msg{*}
\Msg{* To finish the installation you have to move the following}
\Msg{* file into a directory searched by TeX:}
\Msg{*}
\Msg{* mathtools.sty}
\Msg{*}
\Msg{* To produce the documentation run the file `mathtools.drv'}
\Msg{* through LaTeX.}
\Msg{*}
\Msg{* Happy TeXing!}
\Msg{*}
\Msg{************************************************************************}
\endbatchfile
%</install>
%<*ignore>
\fi
%</ignore>
%<*driver>
\NeedsTeXFormat{LaTeX2e}
\ProvidesFile{mathtools.drv}%
[2024/10/04 v1.31 mathematical typesetting tools]
\documentclass{ltxdoc}
\IfFileExists{fourier.sty}{\usepackage{fourier}}{}
\addtolength\marginparwidth{-25pt}
\usepackage{mathtools}
\setcounter{IndexColumns}{2}
\providecommand*\pkg[1]{\textsf{#1}}
\providecommand*\env[1]{\texttt{#1}}
\providecommand*\email[1]{\href{mailto:#1}{\texttt{#1}}}
\providecommand*\mode[1]{\texttt{[#1]}}
\providecommand*\file[1]{\texttt{#1}}
\usepackage{xcolor,varioref,amssymb}
\makeatletter
\newcommand*\thinfbox[2][black]{\fboxsep0pt\textcolor{#1}{\rulebox{{\normalcolor#2}}}}
\newcommand*\thinboxed[2][black]{\thinfbox[#1]{\ensuremath{\displaystyle#2}}}
\newcommand*\rulebox[1]{%
\sbox\z@{\ensuremath{\displaystyle#1}}%
\@tempdima\dp\z@
\hbox{%
\lower\@tempdima\hbox{%
\vbox{\hrule height\fboxrule\box\z@\hrule height\fboxrule}%
}%
}%
}
\newenvironment{codesyntax}
{\par\small\addvspace{4.5ex plus 1ex}%
\vskip -\parskip
\noindent
\begin{tabular}{|l|}\hline\ignorespaces}%
{\\\hline\end{tabular}\nobreak\par\nobreak
\vspace{2.3ex}\vskip -\parskip\noindent\ignorespacesafterend}
\makeatletter
\newcommand*\FeatureRequest[2]{%
\hskip1sp
\marginpar{%
\parbox[b]{\marginparwidth}{\small\sffamily\raggedright
\strut Feature request by\\#1\\#2%
}
}%
}
\newcommand*\ProvidedBy[2]{%
\hskip1sp
\marginpar{%
\parbox[b]{\marginparwidth}{\small\sffamily\raggedright
\strut Feature provided by\\#1\\#2%
}
}%
}
\newcommand*\SuggestedBy[2]{%
\hskip1sp
\marginpar{%
\parbox[b]{\marginparwidth}{\small\sffamily\raggedright
\strut Suggested by\\#1\\#2%
}
}%
}
\newcommand*\cttPosting[2]{%
\hskip1sp
\marginpar{%
\parbox[b]{\marginparwidth}{\small\sffamily\raggedright
\strut Posted on \texttt{comp.text.tex} \\#1\\#2%
}%
}%
}
\newcommand*\tsxPosting[2]{%
\hskip1sp
\marginpar{%
\parbox[b]{\marginparwidth}{\small\sffamily\raggedright
\strut Posted on \texttt{\small tex.stackexchange.com} \\#1\\#2%
}%
}%
}
\newcommand*\tsxchatPosting[3][Requested on]{%
\hskip1sp
\marginpar{%
\parbox[b]{\marginparwidth}{\small\sffamily\raggedright
\strut #1 \texttt{\scriptsize tex.stackexchange.com chat} \\#2\\#3%
}%
}%
}
\newcommand*\CommentAdded[1]{%
\hskip1sp
\marginpar{%
\parbox[b]{\marginparwidth}{\small\sffamily\raggedright
\strut Comment added\\#1%
}%
}%
}
\expandafter\def\expandafter\MakePrivateLetters\expandafter{%
\MakePrivateLetters \catcode`\_=11\relax
}
\providecommand*\SpecialOptIndex[1]{%
\@bsphack
\index{#1\actualchar{\protect\ttfamily #1}
(option)\encapchar usage}%
\index{options:\levelchar#1\actualchar{\protect\ttfamily #1}\encapchar
usage}\@esphack}
\providecommand*\opt[1]{\texttt{#1}}
\providecommand*\SpecialKeyIndex[1]{%
\@bsphack
\index{#1\actualchar{\protect\ttfamily #1}
(key)\encapchar usage}%
\index{keys:\levelchar#1\actualchar{\protect\ttfamily #1}\encapchar
usage}\@esphack}
\providecommand*\key[1]{\textsf{#1}}
\providecommand*\eTeX{$\m@th\varepsilon$-\TeX}
\def\MTmeta#1{%
\ensuremath\langle
\ifmmode \expandafter \nfss@text \fi
{%
\meta@font@select
\edef\meta@hyphen@restore
{\hyphenchar\the\font\the\hyphenchar\font}%
\hyphenchar\font\m@ne
\language\l@nohyphenation
#1\/%
\meta@hyphen@restore
}\ensuremath\rangle
\endgroup
}
\makeatother
\DeclareRobustCommand\meta{\begingroup\MakePrivateLetters\MTmeta}%
\def\MToarg#1{{\ttfamily[}\meta{#1}{\ttfamily]}\endgroup}
\DeclareRobustCommand\oarg{\begingroup\MakePrivateLetters\MToarg}%
\def\MHmarg#1{{\ttfamily\char`\{}\meta{#1}{\ttfamily\char`\}}\endgroup}
\DeclareRobustCommand\marg{\begingroup\MakePrivateLetters\MHmarg}%
\def\MHarg#1{{\ttfamily\char`\{#1\ttfamily\char`\}}\endgroup}
\DeclareRobustCommand\arg{\begingroup\MakePrivateLetters\MHarg}%
\def\MHcs#1{\texttt{\char`\\#1}\endgroup}
\DeclareRobustCommand\cs{\begingroup\MakePrivateLetters\MHcs}
\def\endverbatim{\if@newlist
\leavevmode\fi\endtrivlist\vspace{-\baselineskip}}
\expandafter\let\csname endverbatim*\endcsname =\endverbatim
\let\MTtheindex\theindex
\def\theindex{\MTtheindex\MakePrivateLetters}
\NewDocumentCommand\Framebox{ o O{c} m }{%
\IfNoValueTF{#1}{%
\framebox{\footnotesize\strut #3}%
}{%
\framebox[#1][#2]{\footnotesize\strut #3}%
}%
}
%\usepackage[draft]{fixme}
%\fxsetup{
% multiuser,
%layout=marginnote,
%}
%\providecommand\fxnote[2][]{}
\usepackage{xurl}
\usepackage[final,
hyperindex=false,
colorlinks,
]{hyperref}
\renewcommand*\usage[1]{\textit{\hyperpage{#1}}}
\OnlyDescription
\begin{document}
\DocInput{mathtools.dtx}
\end{document}
%</driver>
% \fi
%
% \changes{v1.19}{2017/03/31}{Updated to match some macro renaming in
% \pkg{mhsetup}}
% \changes{v1.0}{2004/07/26}{Initial release}
%
% \GetFileInfo{mathtools.drv}
%
% \CheckSum{3775}
%
% \title{The \pkg{mathtools} package\thanks{This file has version number
% \fileversion, last revised \filedate.}}
%
% \author{Morten Høgholm, Lars Madsen and the \LaTeX3 project}
% \date{\filedate}
%
% \maketitle
%
% \begin{abstract}
% \noindent The \pkg{mathtools} package is an extension package to
% \pkg{amsmath}. There are two things on \pkg{mathtools}' agenda:
% (1)~correct various bugs/deficiencies in \pkg{amsmath} until
% these are fixed by the \AmS{} and (2)~provide useful tools
% for mathematical typesetting, be it a small macro for
% typesetting a prescript or an underbracket, or entirely new
% display math constructs such as a \env{multlined} environment.
% \end{abstract}
%
% \tableofcontents
%
% \section{Introduction}
%
% Although \pkg{amsmath} provides many handy tools for mathematical
% typesetting, it is nonetheless a static package. This is not a bad
% thing, because what it does, it mostly does quite well and having
% a stable math typesetting package is ``a good thing.'' However,
% \pkg{amsmath} does not fulfill all the needs of the mathematical
% part of the \LaTeX{} community, resulting in many authors writing
% small snippets of code for tweaking the mathematical layout. Some
% of these snippets have also been posted to newsgroups and mailing
% lists over the years, although more often than not without being
% released as stand-alone packages.
%
% The \pkg{mathtools} package is exactly what its name implies: tools
% for mathematical typesetting. It is a collection of many of these
% often needed small tweaks---with some big tweaks added as well. It
% can only do so by having harvesting newsgroups for code and/or you
% writing the maintainers with wishes for code to be included, so if
% you have any good macros or just macros that help you when writing
% mathematics, then don't hesitate to report them.
%
% As of 2020, \pkg{mathtools} (and \pkg{empheq}) is now hosted at the
% \LaTeX3 team GitHub at
% \begin{center}
% \url{https://github.com/latex3/mathtools}
% \end{center}
% So if you have any issue, feel free to register an issue there.
%
% \medskip\noindent
% Update 2013: We now make \cs{(}\cs{)} and \cs[\cs]
% robust (can be disabled via \texttt{nonrobust} package option).
%
% \section{Package loading}
%
%
% The \pkg{mathtools} package requires \pkg{amsmath} but is able to
% pass options to it as well. Thus a line like
% \begin{verbatim}
% \usepackage[fleqn,tbtags]{mathtools}
% \end{verbatim}
% is equivalent to
% \begin{verbatim}
% \usepackage[fleqn,tbtags]{amsmath}
% \usepackage{mathtools}
% \end{verbatim}
%
%
% \subsection{Special \pkg{mathtools} options}
%
% \begin{codesyntax}
% \SpecialOptIndex{fixamsmath}\opt{fixamsmath}\texttt{~~~~}
% \SpecialOptIndex{donotfixamsmathbugs}\opt{donotfixamsmathbugs}
% \end{codesyntax}
% The option \opt{fixamsmath} (default) fixes two bugs in
% \pkg{amsmath}.\footnote{See the online \LaTeX{} bugs database
% \url{http://www.latex-project.org/cgi-bin/ltxbugs2html} under
% \AmS-\LaTeX{} problem reports 3591 and 3614.} Should you for some
% reason not want to fix these bugs then just add the option
% \opt{donotfixamsmathbugs} (if you can do it without typos). The
% reason for this extremely long name is that I really don't see why
% you wouldn't want these bugs to be fixed, so I've made it slightly
% difficult not to fix them.
%
% \begin{codesyntax}
% \SpecialOptIndex{allowspaces}\opt{allowspaces}\texttt{~~~~}
% \SpecialOptIndex{disallowspaces}\opt{disallowspaces}
% \end{codesyntax}
% Sometimes \pkg{amsmath} gives you nasty surprises, as here where
% things look seemingly innocent:
% \begin{verbatim}
% \[
% \begin{gathered}
% [t] = 100 \\
% [v] = 200
% \end{gathered}
% \]
% \end{verbatim}
% Without \pkg{mathtools} this will result in this output:
% \[
% \begin{gathered}[c]
% = 100 \\
% [v] = 200
% \end{gathered}
% \]
% Yes, the \texttt{[t]} has been gobbled without warning! Note, with
% modern \pkg{amsmath} \verb|\begin{gathered}[x]| will eat \verb|[x]|
% and \emph{issue a warning unless} \texttt{x} is \texttt{t},
% \texttt{b} or \texttt{c}.\footnote{Older \pkg{amsmath} will
% silently gobble the argument.} This is hardly what you'd expect
% as an end user, as the desired output was probably something like
% this instead:
% \[
% \begin{gathered}[c]
% [t] = 100 \\
% [v] = 200
% \end{gathered}
% \]
% With the option \opt{disallowspaces} (default) \pkg{mathtools}
% disallows spaces in front of optional arguments where it could
% possibly cause problems just as \pkg{amsmath} does with |\\|
% inside the display environments. This includes the environments
% \env{gathered} (and also those shown in \S
% \vref{subsec:gathered}), \env{aligned}, \env{multlined}, and the
% extended \env{matrix}-environments (\S \vref{subsubsec:matrices}).
% If you however want to preserve the more dangerous standard
% optional spaces, simply choose the option \opt{allowspaces}.
%
% \begin{codesyntax}
% \SpecialOptIndex{legacycolonsymbols}\opt{legacycolonsymbols}
% \end{codesyntax}
% As of Summer 2022, we've had to rename several \cs{...colon...}
% symbol macros in order to have a consistent naming scheme across
% different packages.\footnote{For example with \pkg{unicode-math}.}
% If needed, this package option brings back the original
% \cs{...colon...} definitions. See page~\pageref{colonsymbols} for
% more information.
%
% \section{Tools for mathematical typesetting}
%
% \begin{codesyntax}
% \SpecialUsageIndex{\mathtoolsset}\cs{mathtoolsset}\marg{key val list}
% \end{codesyntax}
% Many of the tools shown in this manual can be turned on and off by
% setting a switch to either true or false. In all cases it is done
% with the command \cs{mathtoolsset}. A typical use could be something like
% \begin{verbatim}
% \mathtoolsset{
% showonlyrefs,
% mathic % or mathic = true
% }
% \end{verbatim}
% More information on the keys later on.
%
%
% \subsection{Fine-tuning mathematical layout}
%
% Sometimes you need to tweak the layout of formulas a little to get
% the best result and this part of the manual describes the various
% macros \pkg{mathtools} provides for this.
%
% \subsubsection{A complement to \texttt{\textbackslash smash},
% \texttt{\textbackslash llap}, and \texttt{\textbackslash rlap}}
%
% \begin{codesyntax}
% \SpecialUsageIndex{\mathllap}
% \cs{mathllap}\oarg{mathstyle}\marg{math}\texttt{~~}
% \SpecialUsageIndex{\mathclap}
% \cs{mathclap}\oarg{mathstyle}\marg{math}\\
% \SpecialUsageIndex{\mathrlap}
% \cs{mathrlap}\oarg{mathstyle}\marg{math}\texttt{~~}
% \SpecialUsageIndex{\clap}
% \cs{clap}\marg{text}\\
% \SpecialUsageIndex{\mathmbox}
% \cs{mathmbox}\marg{math}\phantom{\meta{mathstyle}}\texttt{~~~~}
% \SpecialUsageIndex{\mathmakebox}
% \cs{mathmakebox}\oarg{width}\oarg{pos}\marg{math}
% \end{codesyntax}
% In \cite{Perlis01}, Alexander R.~Perlis describes some simple yet
% useful macros for use in math displays. For example the display
% \begin{verbatim}
% \[
% X = \sum_{1\le i\le j\le n} X_{ij}
% \]
% \end{verbatim}
% \[
% X = \sum_{1\le i\le j\le n} X_{ij}
% \]
% contains a lot of excessive white space. The idea that comes to
% mind is to fake the width of the subscript. The command
% \cs{mathclap} puts its argument in a zero width box and centers
% it, so it could possibly be of use here.
% \begin{verbatim}
% \[
% X = \sum_{\mathclap{1\le i\le j\le n}} X_{ij}
% \]
% \end{verbatim}
% \[
% X = \sum_{\mathclap{1\le i\le j\le n}} X_{ij}
% \]
% For an in-depth discussion of
% these macros I find it better to read the article; an online
% version can be found at
% \begin{quote}
% \url{http://www.tug.org/TUGboat/Articles/tb22-4/tb72perlS.pdf}
% \end{quote}
% Note that the definitions shown in the article do not exactly
% match the definitions in \pkg{mathtools}. Besides providing an
% optional argument for specifying the desired math style, these
% versions also work around a most unfortunate \TeX{}
% ``feature.''\footnote{The faulty reboxing procedure.} The
% \cs{smash} macro is fixed too.
%
%
% \subsubsection{Forcing a cramped style}
%
% \begin{codesyntax}
% \SpecialUsageIndex{\cramped}
% \cs{cramped}\oarg{mathstyle}\marg{math}
% \end{codesyntax}
% \cttPosting{Michael Herschorn}{1992/07/21}
% Let's look at another example where we have used \cs{mathclap}:
% \begin{verbatim}
% \begin{equation}\label{eq:mathclap}
% \sum_{\mathclap{a^2<b^2<c}}\qquad
% \sum_{a^2<b^2<c}
% \end{equation}
% \end{verbatim}
% \begin{equation}\label{eq:mathclap}
% \sum_{\mathclap{a^2<b^2<c}}\qquad
% \sum_{a^2<b^2<c}
% \end{equation}
% Do you see the difference? Maybe if I zoomed in a bit:
% \begingroup \fontsize{24}{\baselineskip}\selectfont
% \[
% \sum_{\mathclap{a^2<b^2<c}}\qquad
% \sum_{a^2<b^2<c}
% \]
% \endgroup
% Notice how the limit of the right summation sign is typeset in a
% more compact style than the left. It is because \TeX{} sets the
% limits of operators in a \emph{cramped} style. For each of \TeX's
% four math styles (\cs{displaystyle}, \cs{textstyle},
% \cs{scriptstyle}, and \cs{scriptscriptstyle}), there also exists a
% cramped style that doesn't raise exponents as much. Besides in the
% limits of operators, \TeX{} also automatically uses these cramped
% styles in radicals such as \cs{sqrt} and in the denominators of
% fractions, but unfortunately there are no primitive commands that
% allow you to detect crampedness or switch to it.
%
% \pkg{mathtools} offers the command \cs{cramped} which forces a
% cramped style in normal un-cramped math. Additionally you can
% choose which of the four styles you want it in as well by
% specifying it as the optional argument:
% \begin{verbatim}
% \[
% \cramped{x^2} \leftrightarrow x^2 \quad
% \cramped[\scriptstyle]{x^2} \leftrightarrow {\scriptstyle x^2}
% \]
% \end{verbatim}
% \[
% \cramped{x^2} \leftrightarrow x^2 \quad
% \cramped[\scriptstyle]{x^2} \leftrightarrow {\scriptstyle x^2}
% \]
% You may be surprised how often the cramped style can be
% beneficial to your output. Take a look at this example:
% \begin{verbatim}
% \begin{quote}
% The 2005 Euro\TeX{} conference is held in Abbaye des
% Pr\'emontr\'es, France, marking the 16th ($2^{2^2}$) anniversary
% of both Dante and GUTenberg (the German and French \TeX{} users
% group resp.).
% \end{quote}
% \end{verbatim}
% \begin{quote}
% The 2005 Euro\TeX{} conference is held in Abbaye des
% Pr\'emontr\'es, France, marking the 16th ($2^{2^2}$) anniversary
% of both Dante and GUTenberg (the German and French \TeX{} users
% group resp.).
% \end{quote}
% Typesetting on a grid is generally considered quite desirable, but
% as the second line of the example shows, the exponents of $2$
% cause the line to be too tall for the normal value of
% \cs{baselineskip}, so \TeX{} inserts a \cs{lineskip} (normal value
% is \the\lineskip). In order to circumvent the problem, we can
% force a cramped style so that the exponents aren't raised as much:
% \begin{verbatim}
% \begin{quote}
% The 2005 Euro\TeX{} ... 16th ($\cramped{2^{2^2}}$) ...
% \end{quote}
% \end{verbatim}
% \begin{quote}
% The 2005 Euro\TeX{} conference is held in Abbaye des
% Pr\'emontr\'es, France, marking the 16th ($\cramped{2^{2^2}}$)
% anniversary of both Dante and GUTenberg (the German and French
% \TeX{} users group resp.).
% \end{quote}
%
% \begin{codesyntax}
% \SpecialUsageIndex{\crampedllap}
% \cs{crampedllap}\oarg{mathstyle}\marg{math}\texttt{~~}
% \SpecialUsageIndex{\crampedclap}
% \cs{crampedclap}\oarg{mathstyle}\marg{math}\\
% \SpecialUsageIndex{\crampedrlap}
% \cs{crampedrlap}\oarg{mathstyle}\marg{math}
% \end{codesyntax}
% The commands \cs{crampedllap}, \cs{crampedclap}, and
% \cs{crampedrlap} are identical to the three \cs{mathXlap} commands
% described earlier except the argument is typeset in cramped style.
% You need this in order to typeset \eqref{eq:mathclap} correctly
% while still faking the width of the limit.
% \begin{verbatim}
% \begin{equation*}\label{eq:mathclap-b}
% \sum_{\crampedclap{a^2<b^2<c}}
% \tag{\ref{eq:mathclap}*}
% \end{equation*}
% \end{verbatim}
% \begin{equation*}\label{eq:mathclap-b}
% \sum_{\crampedclap{a^2<b^2<c}}
% \tag{\ref{eq:mathclap}*}
% \end{equation*}
% Of course you could just type
% \begin{verbatim}
% \sum_{\mathclap{\cramped{a^2<b^2<c}}}
% \end{verbatim}
% but it has one major disadvantage: In order for \cs{mathXlap} and
% \cs{cramped} to get the right size, \TeX{} has to process them
% four times, meaning that nesting them as shown above will cause
% \TeX{} to typeset $4^2$ instances before choosing the right one.
% In this situation however, we will of course need the same style
% for both commands so it makes sense to combine the commands in
% one, thus letting \TeX{} make the choice only once rather than
% twice.
%
% \begin{codesyntax}
% \SpecialEnvIndex{crampedsubarray}\cs{begin}\arg{crampedsubarray}\marg{col}
% \meta{contents} \cs{end}\arg{crampedsubarray}\\
% \SpecialUsageIndex{\crampedsubstack}
% \cs{crampedsubstack}\marg{lines separated by \cs{}\cs{}}
% \end{codesyntax}
% \SuggestedBy{Henri Menke}{2019/07/08} If we go back to
% \eqref{eq:mathclap} and apply \cs{substack}, you'll notice that the
% cramped style, the sum would normally apply, is now gone:
% \begin{verbatim}
% \[
% \sum_{\substack{a^2<b^2<c}}\qquad
% \sum_{a^2<b^2<c}
% \]
% \end{verbatim}
% \begingroup \fontsize{24}{\baselineskip}\selectfont
% \[
% \sum_{\substack{a^2<b^2<c}}\qquad
% \sum_{a^2<b^2<c}
% \]
% \endgroup
% We therefore provide a cramped version of
% \cs{substack}.\footnote{\cs{substack} is internally implemented via
% the \env{subarray}-env, so our cramped version of \cs{substack} is implemented via a
% cramped version of this env.}
% \begin{verbatim}
% \[
% \sum_{\crampedsubstack{a^2<b^2<c}}\qquad
% \sum_{a^2<b^2<c}
% \]
% \end{verbatim}
% \begingroup \fontsize{24}{\baselineskip}\selectfont
% \[
% \sum_{\crampedsubstack{a^2<b^2<c}}\qquad
% \sum_{a^2<b^2<c}
% \]
% \endgroup
% Note: We may need to add a similar hook into multlined.
%
%
%
%
%
% \subsubsection{Smashing an operator}
%
%
%
% \begin{codesyntax}
% \SpecialUsageIndex{\smashoperator}
% \cs{smashoperator}\oarg{pos}\marg{operator with limits}
% \end{codesyntax}
% \FeatureRequest{Lars Madsen}{2004/05/04} Above we showed how to get
% \LaTeX{} to ignore the width of the subscript of an
% operator. However this approach takes a lot of extra typing,
% especially if you have a wide superscript, meaning you have to put
% in \cs{crampedclap} in both sub- and superscript. To make things
% easier, \pkg{mathtools} provides a \cs{smashoperator} command,
% which simply ignores the width of the sub- and superscript. It also
% takes an optional argument, \texttt{l}, \texttt{r}, or \texttt{lr}
% (default, \texttt{rl} is an alias for \texttt{lr}), denoting which
% side of the operator should be ignored (smashed).
% \begin{verbatim}
% \[
% V = \sum_{1\le i\le j\le n}^{\infty} V_{ij} \quad
% X = \smashoperator{\sum_{1\le i\le j\le n}^{3456}} X_{ij} \quad
% Y = \smashoperator[r]{\sum\limits_{1\le i\le j\le n}} Y_{ij} \quad
% Z = \smashoperator[l]{\mathop{T}_{1\le i\le j\le n}} Z_{ij}
% \]
% \end{verbatim}
% \[
% V = \sum_{1\le i\le j\le n}^{\infty} V_{ij} \quad
% X = \smashoperator{\sum_{1\le i\le j\le n}^{3456}} X_{ij} \quad
% Y = \smashoperator[r]{\sum\limits_{1\le i\le j\le n}} Y_{ij} \quad
% Z = \smashoperator[l]{\mathop{T}_{1\le i\le j\le n}} Z_{ij}
% \]
% Note that \cs{smashoperator} always sets its argument in display
% style and with limits even if you have used the \opt{nosumlimits}
% option of \pkg{amsmath}. If you wish, you can use shorthands for
% \texttt{\_} and \texttt{\textasciicircum} such as \cs{sb} and
% \cs{sp}.
%
%
% \subsubsection{Adjusting limits of operators}
%
% \begin{codesyntax}
% \SpecialUsageIndex{\adjustlimits}
% \cs{adjustlimits}\marg{operator$\sb1$}\texttt{\_}\marg{limit$\sb1$}
% \marg{operator$\sb2$}\texttt{\_}\marg{limit$\sb2$}
% \end{codesyntax}
% \FeatureRequest{Lars Madsen}{2004/07/09}
% When typesetting two consecutive operators with limits one often
% wishes the limits of the operators were better aligned. Look
% closely at these examples:
% \begin{verbatim}
% \[
% \text{a)} \lim_{n\to\infty} \max_{p\ge n} \quad
% \text{b)} \lim_{n\to\infty} \max_{p^2\ge n} \quad
% \text{c)} \lim_{n\to\infty} \sup_{p^2\ge nK} \quad
% \text{d)} \limsup_{n\to\infty} \max_{p\ge n}
% \]
% \end{verbatim}
% \[
% \text{a)} \lim_{n\to\infty} \max_{p\ge n} \quad
% \text{b)} \lim_{n\to\infty} \max_{p^2\ge n} \quad
% \text{c)} \lim_{n\to\infty} \sup_{p^2\ge nK} \quad
% \text{d)} \limsup_{n\to\infty} \max_{p\ge n}
% \]
% a) looks okay, but b) is not quite as good because the second
% limit ($\cramped{p^2\ge n}$) is significantly taller than the
% first ($n\to\infty$). With c)~things begin to look really bad,
% because the second operator has a descender while the first
% doesn't, and finally we have d)~which looks just as bad as~c). The
% command \cs{adjustlimits} is useful in these cases, as you can
% just put it in front of these consecutive operators and it'll make
% the limits line up.
% \medskip\par\noindent
% \begin{minipage}{\textwidth}
% \begin{verbatim}
% \[
% \text{a)} \adjustlimits\lim_{n\to\infty} \max_{p\ge n} \quad
% \text{b)} \adjustlimits\lim_{n\to\infty} \max_{p^2\ge n} \quad
% \text{c)} \adjustlimits\lim_{n\to\infty} \sup_{p^2\ge nK} \quad
% \text{d)} \adjustlimits\limsup_{n\to\infty} \max_{p\ge n}
% \]
% \end{verbatim}
% \end{minipage}
% \[
% \text{a)} \adjustlimits\lim_{n\to\infty} \max_{p\ge n} \quad
% \text{b)} \adjustlimits\lim_{n\to\infty} \max_{p^2\ge n} \quad
% \text{c)} \adjustlimits\lim_{n\to\infty} \sup_{p^2\ge nK} \quad
% \text{d)} \adjustlimits\limsup_{n\to\infty} \max_{p\ge n}
% \]
% The use of \cs{sb} instead of \texttt{\_} is allowed.
%
%
% \subsubsection{Swapping space above \texorpdfstring{\AmS}{AMS} display math environments }
% \label{sec:swapping}
%
% One feature that the plain old \env{equation} environment has that
% the \AmS\ environments do not (because of technical reasons) is
% the feature of using less space above the equation if the situation
% presents itself. The \AmS\ environments cannot do this, but one can
% manually, using
% \begin{codesyntax}
% \SpecialUsageIndex{\SwapAboveDisplaySkip}
% \cs{SwapAboveDisplaySkip}
% \end{codesyntax}
% as the very first content within an \AmS\ display math
% environment. It will then issue an \cs{abovedisplayshortskip}
% instead of the normal \cs{abovedisplayskip}.
%
% Note it will not work with the \env{equation} or \env{multline} environments.
%
% Here is an example of the effect
% \begin{verbatim}
% \noindent\rule\textwidth{1pt}
% \begin{align*} A &= B \end{align*}
% \noindent\rule\textwidth{1pt}
% \begin{align*}
% \SwapAboveDisplaySkip
% A &= B
% \end{align*}
% \end{verbatim}
% \noindent\rule\textwidth{1pt}
% \begin{align*} A &= B \end{align*}
% \noindent\rule\textwidth{1pt}
% \begin{align*}
% \SwapAboveDisplaySkip
% A &= B
% \end{align*}
%
%
% \subsection{Controlling tags}
%
% In this section various tools for altering the appearance of tags
% are shown. All of the tools here can be used at any point in the
% document but they should probably affect the whole document, so
% the preamble is the best place to issue them.
%
% \subsubsection{The appearance of tags}
% \begin{codesyntax}
% \SpecialUsageIndex{\newtagform}
% \cs{newtagform}\marg{name}\oarg{inner_format}\marg{left}\marg{right}\\
% \SpecialUsageIndex{\renewtagform}
% \cs{renewtagform}\marg{name}\oarg{inner_format}\marg{left}\marg{right}\\
% \SpecialUsageIndex{\usetagform}
% \cs{usetagform}\marg{name}
% \end{codesyntax}
% Altering the layout of equation numbers in \pkg{amsmath} is not
% very user friendly (it involves a macro with three \texttt{@}'s in
% its name), so \pkg{mathtools} provides an interface somewhat
% reminiscent of the page style concept. This way you can define
% several different tag forms and then choose the one you prefer.
%
% As an example let's try to define a tag form which puts the
% equation number in square brackets. First we define a brand new tag
% form:
% \begin{verbatim}
% \newtagform{brackets}{[}{]}
% \end{verbatim}
% Then we activate it:
% \begin{verbatim}
% \usetagform{brackets}
% \end{verbatim}
% The result is then
% \newtagform{brackets}{[}{]}
% \usetagform{brackets}
% \begin{equation}
% E \neq m c^3
% \end{equation}
%
% Similarly you could define a second version of the brackets that
% prints the equation number in bold face instead
% \begin{verbatim}
% \newtagform{brackets2}[\textbf]{[}{]}
% \usetagform{brackets2}
% \begin{equation}
% E \neq m c^3
% \end{equation}
% \end{verbatim}
% \newtagform{brackets2}[\textbf]{[}{]}
% \usetagform{brackets2}
% \begin{equation}
% E \neq m c^3
% \end{equation}
% When you reference an equation with \cs{eqref}, the tag form in
% effect at the time of referencing controls the formatting, so be
% careful if you use different tag forms throughout your document.
%
% If you want to renew a tag form, then use the command
% \cs{renewtagform}. Should you want to
% return to the standard setting then choose\usetagform{default}
% \begin{verbatim}
% \usetagform{default}
% \end{verbatim}
%
% \changes{v1.12}{2012/05/09}{Added caveat}
% \noindent\textbf{Caveat regarding \pkg{ntheorem}}: If you like to
% change the appearence of the tags \emph{and} you are also using the
% \pkg{ntheorem} package, then please postpone the change of
% appearance until \emph{after} loading \pkg{ntheorem}. (In order to
% do its thing, \pkg{ntheorem} has to mess with the tags\dots)
%
% \subsubsection{Showing only referenced tags}
%
% \begin{codesyntax}
% \SpecialKeyIndex{showonlyrefs}$\key{showonlyrefs}=\texttt{true}\vert\texttt{false}$\\
% \SpecialKeyIndex{showmanualtags}$\key{showmanualtags}=\texttt{true}\vert\texttt{false}$\\
% \SpecialUsageIndex{\refeq}\cs{refeq}\marg{label}
% \end{codesyntax}
% First of, one should always use \cs{eqref} when referring to
% equation numbers. When \opt{showonlyrefs} is true, we monitor
% \cs{eqref}\marg{label}, and those used will get an equation number,
% whereas those not used will not. Note: We do \emph{not} monitor the
% normal \cs{ref} command! See the follow paragraph for situations
% for what to do when \cs{eqref} cannot be used to refer to the equation.
%
% An equation where the tag is produced with a manual \cs{tag*}
% shouldn't be referenced with the normal \cs{eqref} because that
% would format it according to the current tag format. Using just
% \cs{ref} on the other hand may not be a good solution either as
% the argument of \cs{tag*} is always set in upright shape in the
% equation and you may be referencing it in italic text. In the
% example below, the command \cs{refeq} is used to avoid what could
% possibly lead to confusion in cases where the tag font has very
% different form in upright and italic shape (here we switch to
% Palatino in the example):
% \begin{verbatim}
% \begin{quote}\renewcommand*\rmdefault{ppl}\normalfont\itshape
% \begin{equation*}
% a=b \label{eq:example}\tag*{Q\&A}
% \end{equation*}
% See \ref{eq:example} or is it better with \refeq{eq:example}?
% \end{quote}
% \end{verbatim}
% \begin{quote}\renewcommand*\rmdefault{ppl}\normalfont\itshape
% \begin{equation*}
% a=b \label{eq:example}\tag*{Q\&A}
% \end{equation*}
% See \ref{eq:example} or is it better with \refeq{eq:example}?
% \end{quote}
%
%
% Another problem sometimes faced is the need for showing the
% equation numbers for only those equations actually referenced. In
% \pkg{mathtools} this can be done by setting the key
% \key{showonlyrefs} to either true or false by using
% \cs{mathtoolsset}. You can also choose whether or not to show the
% manual tags specified with \cs{tag} or \cs{tag*} by setting the
% option \key{showmanualtags} to true or false.\footnote{I recommend
% setting \key{showmanualtags} to true, else the whole idea of using
% \cs{tag} doesn't really make sense, does it?} For both keys just
% typing the name of it chooses true as shown in the following
% example.
%
% \begin{verbatim}
% \mathtoolsset{showonlyrefs,showmanualtags}
% \usetagform{brackets}
% \begin{gather}
% a=a \label{eq:a} \\
% b=b \label{eq:b} \tag{**}
% \end{gather}
% This should refer to the equation containing $a=a$: \eqref{eq:a}.
% Then a switch of tag forms.
% \usetagform{default}
% \begin{align}
% c&=c \label{eq:c} \\
% d&=d \label{eq:d}
% \end{align}
% This should refer to the equation containing $d=d$: \eqref{eq:d}.
% \begin{equation}
% e=e
% \end{equation}
% Back to normal.\mathtoolsset{showonlyrefs=false}
% \begin{equation}
% f=f
% \end{equation}
% \end{verbatim}
% \mathtoolsset{showonlyrefs,showmanualtags}
% \usetagform{brackets}
% \begin{gather}
% a=a \label{eq:a} \\
% b=b \label{eq:b} \tag{**}
% \end{gather}
% This should refer to the equation containing $a=a$: \eqref{eq:a}.
% Then a switch of tag forms.
% \usetagform{default}
% \begin{align}
% c&=c \label{eq:c} \\
% d&=d \label{eq:d}