This repository has been archived by the owner on Sep 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
faq-how-do-i.tex
4141 lines (3750 loc) · 160 KB
/
faq-how-do-i.tex
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
\section{How do I do\dots{}?}
\subsection{Mathematics}
\Question[Q-proof]{Proof environment}
It was long thought impossible to make a \environment{proof}
environment which automatically includes an `end-of-proof' symbol.
Some proofs end in displayed maths; others do not. If the input file
contains % ! line break
\texttt{...\csx{]} }\cmdinvoke{end}{proof} then \LaTeX{} finishes off
the displayed maths and gets ready for a new line before it reads any
instructions connected with ending the proof, so the code is very
tricky. You \emph{can} insert the symbol by hand, but the
(apparently) original `automatic' solution came with Paul Taylor's
\Package{QED}.
Nowadays, the \Package{ntheorem} package now solves the problem for
\LaTeX{} users: it provides an automatic way of signalling
the end of a proof.
The \AMSLaTeX{} package \Package{amsthm} also provides a
\environment{proof} environment that does the job; though you need to
insert a \csx{qedhere} command if the proof ends with a displayed
equation:
\begin{quote}
\begin{verbatim}
\begin{proof}
text...
\begin{equation*}
maths... \tag*{\qedhere}
\end{equation*}
\end{proof}
\end{verbatim}
\end{quote}
The \cmdinvoke{tag*}{\csx{qedhere}} construction may be used in any of
\AMSLaTeX{}'s numbering environments.
\begin{ctanrefs}
\item[amsthm.sty]Distributed as part of the \AMSLaTeX{} bundle
\CTANref{amslatex}[amsthm]
\item[ntheorem.sty]\CTANref{ntheorem}
\end{ctanrefs}
\LastEdit{2011-03-09}
\Question[Q-theoremfmt]{Theorem bodies printed in a roman font}
If you want to take advantage of the powerful \csx{newtheorem} command
without the constraint that the contents of the theorem is in a sloped
font (for example, you may want to use it to create remarks, examples, proofs,
\dots{}) then you can use the \AMSLaTeX{} \Package{amsthm} package
(which now supersedes the \Package{theorem} package previously
recommended in these answers).
Alternatively, the following sets up an environment
\environment{remark} whose content is in the default roman font.
\begin{quote}
\begin{narrowversion}
\begin{verbatim}
\newtheorem{preremark}{Remark}
\newenvironment{remark}%
{\begin{preremark}\upshape}%
{\end{preremark}}
\end{verbatim}
\end{narrowversion}
\begin{wideversion}
\begin{verbatim}
\newtheorem{preremark}{Remark}
\newenvironment{remark}%
{\begin{preremark}\upshape}{\end{preremark}}
\end{verbatim}
\end{wideversion}
\end{quote}
The \Package{ntheorem} package provides control of the fonts used by
theorems, directly.
\begin{ctanrefs}
\item[amsthm.sty]Distributed as part of \CTANref{amslatex}[amsthm]
\item[ntheorem.sty]\CTANref{ntheorem}
\item[theorem.sty]Distributed as part of \CTANref{2etools}[theorem]
\end{ctanrefs}
\Question[Q-newfunction]{Defining a new log-like function in \LaTeX{}}
Use the \csx{mathop} command, as in:
\begin{quote}
\begin{verbatim}
\newcommand{\diag}{\mathop{\mathrm{diag}}}
\end{verbatim}
\end{quote}
Subscripts and superscripts on \csx{diag} will be placed below and
above the function name, as they are on
\csx{lim}. If you want your subscripts and superscripts always placed
to the right, do:
\begin{quote}
\begin{narrowversion}
\begin{verbatim}
\newcommand{\diag}%
{\mathop{\mathrm{diag}}\nolimits}
\end{verbatim}
\end{narrowversion}
\begin{wideversion}
\begin{verbatim}
\newcommand{\diag}{\mathop{\mathrm{diag}}\nolimits}
\end{verbatim}
\end{wideversion}
\end{quote}
\AMSLaTeX{} (in its \Package{amsopn} package, which is automatically
loaded by \Package{amsmath}) provides a command
\csx{DeclareMathOperator} that takes does the same job as the first
definition above. To create our original \csx{diag} command, one would
say:
\begin{quote}
\begin{verbatim}
\DeclareMathOperator{\diag}{diag}
\end{verbatim}
\end{quote}
\csx{DeclareMathOperator*} declares the operator always to have its
sub- and superscripts in the % ! line break
``\Qref*{\csx{limits} position}{Q-limits}''.
The \Package{amsopn} command \csx{operatorname} allows you to
introduce \emph{ad hoc} operators into your mathematics, so
\begin{quote}
\csx{[} \cmdinvoke{operatorname}{foo}\texttt{(bar)} \csx{]}
\end{quote}
typesets the same as
\begin{quote}
\begin{verbatim}
\DeclareMathOperator{\foo}{foo}
...
\[ \foo(bar) \]
\end{verbatim}
\end{quote}
As with \csx{DeclareMathOperator} there's a starred version
\csx{operatorname*} for sub- and superscripts in the limits position.
(It should be noted that ``log-like'' was reportedly a \emph{joke} on
Lamport's part; it is of course clear what was meant.)
\begin{ctanrefs}
\item[amsopn.sty]Distributed as part of the \AMSLaTeX{} distribution
\CTANref{amslatex}[amsopn]
\end{ctanrefs}
\Question[Q-braket]{Set specifications and Dirac brackets}
One of the few glaring omissions from \TeX{}'s mathematical
typesetting capabilities is a means of setting separators in the
middle of mathematical expressions. \TeX{} provides primitives called
\csx{left} and \csx{right}, which can be used to modify brackets (of
whatever sort) around a mathematical expression, as in:
% beware line wrap
\csx{left(}\texttt{ <expression> }\csx{right)}~--- the size of the
parentheses is matched to the vertical extent of the expression.
However, in all sorts of mathematical enterprises one may find oneself
needing a \csx{middle} command, to be used in expressions like
\begin{quote}
\begin{wideversion}
\begin{verbatim}
\left\{ x \in \mathbb{N} \middle| x \mbox{ even} \right\}
\end{verbatim}
\end{wideversion}
\begin{narrowversion}
\begin{verbatim}
\left\{ x\in \mathbb{N} \middle|
x \mbox{ even} \right\}
\end{verbatim}
\end{narrowversion}
\end{quote}
to specify the set of even natural numbers. The % ! line break
\Qref*{\eTeX{} system}{Q-etex}
defines just such a command, but users of Knuth's original need some
support. Donald Arseneau's \Package{braket} package provides commands
for set specifications (as above) and for Dirac brackets (and bras and
kets). The package uses the \eTeX{} built-in command if it finds
itself running under \eTeX{}.
\begin{ctanrefs}
\item[braket.sty]\CTANref{braket}
\end{ctanrefs}
\Question[Q-cancellation]{Cancelling terms in maths expressions}
A technique used when explaining the behaviour of expressions or
equations (often for pedagogical purposes). The \Package{cancel}
package provides several variants of cancellation marks
(``\texttt{\textbackslash }'', ``\texttt{/}'' and ``\texttt{X}''), and
a means of cancelling `to' a particular value.
Documentation of \Package{cancel} is in the package file.
\begin{ctanrefs}
\item[cancel.sty]\CTANref{cancel}
\end{ctanrefs}
\Question[Q-mathsize]{Adjusting maths font sizes}
In \plaintex{}, when you introduce a new font size you must also
declare what size fonts are to be used in mathematics with it. This
is done by declaring \csx{textfont}, \csx{scriptfont} and
\csx{scriptscriptfont} for the maths families you're using; all such
things are described in chapter~17 of the % line wrap!
\Qref*{\TeX{}book}{Q-tex-books} and in other books and
\Qref*{tutorials}{Q-man-tex} that discuss \plaintex{} in sufficient
detail.
In \LaTeX{}, of course, all this stuff is automated: there is a scheme
that, for each (text) font size, determines what maths font sizes are
to be used. The scheme first checks a set of ``known'' text sizes,
for each of which maths sizes are declared in advance. If the text
size isn't ``known'', the script- and scriptscriptfont sizes are
calculated as fixed ratios of the tex font size. (The values used are
\csx{defaultscriptratio}\ensuremath{=}0.7, and
\csx{defaultscriptscriptratio}\ensuremath{=}0.5.)
The fixed-ratio formula is capable of producing inconvenient results
(particularly if you are using fonts which \LaTeX{} believes are only
available in a fixed set of sizes). You may also want to replace
\LaTeX{}'s ideas altogether, for example by setting maths noticeably
larger or smaller than its surrounding text. For this purpose, the
\LaTeX{} command
\cmdinvoke{DeclareMathSizes}{\meta{tfs}}{\meta{ts}}{\meta{ss}}{\meta{sss}}
may be used (this is the same command that \LaTeX{} itself uses to
define its own set of sizes). This establishes (or re-establishes)
the maths font sizes to be used when the surrounding text font size is
\texttt{\meta{tfs}}; (\texttt{\meta{ts}} being the size used for
\csx{textfont}, \texttt{\meta{ss}} for \csx{scriptfont} and
\texttt{\meta{sss}} for \csx{scriptscriptfont}).
For example, you might want to use a font with a smaller body height
than Computer Modern, but still prefer \acro{CM} math to any of the
alternatives. In this case, you might use:
\begin{quote}
\begin{verbatim}
\DeclareMathSizes{10}{9}{7}{5}
\end{verbatim}
\end{quote}
to get 9pt maths when the surrounding body text is (nominal) 10pt.
\csx{DeclareMathSizes} may only be used in the preamble of the
document: only one association is available for each text font size
for the whole document. The default settings are specified in
\File{fontdef.dtx} in the latex distribution, and are compiled into
\File{fontmath.ltx}; the arguments to the command are just numbers
(`\texttt{pt}' is assumed), but some of them are written using
\Qref*{\LaTeX{} abbreviations}{Q-ltxabbrv} for standard font sizes.
Beware simply copying (parts of) the \LaTeX{} definitions~--- since
they contain those internal abbreviations, they need to be treated as
\Qref{internal commands}{Q-atsigns}.
\begin{ctanrefs}
\item[fontdef.dtx]\CTANref{fontdef}
\item[fontmath.ltx]\CTANref{fontmath}
\end{ctanrefs}
\LastEdit{2011-06-01}
\Question[Q-mathlips]{Ellipses}
\keywords{\csx{dots} \csx{cdots} \csx{vdots} \csx{ddots}}
Ellipses are commonly required, and \LaTeX{} natively supplies a fair
range (\csx{dots}, \csx{cdots}, \csx{vdots} and \csx{ddots}). By using
the \Package{graphics} package, one can change the slope of the
\csx{ddots} command, as in
\begin{quote}
\begin{verbatim}
$ ... \reflectbox{$\ddots$} ... $
\end{verbatim}
\end{quote}
While this works, it is not a recommended way of achieving the desired
result (see below). Moreover, \LaTeX{}'s range is not adequate to
everyone's requirements, and at least three packages provide
extensions to the set.
The \AMSLaTeX{} bundle provides a range of ``semantically-named''
ellipses, for use in different situations: \csx{dotsb} for use between
pairs of binary operators, \csx{dotsc} for use between pairs of commas,
and so on.
The \Package{yhmath} package defines an \csx{adots} command, which is
the analogue of \csx{ddots}, sloping forwards rather than backwards.
The \Package{yhmath} package comes with a rather interesting font that
extends the standard \Package{cmex}; details are in the documentation.
The \Package{mathdots} package (besides fixing up the behaviour of
\AllTeX{} \csx{ddots} and \csx{vdots} when the font size changes)
provides an ``inverse diagonal'' ellipsis \csx{iddots} (doing the same
job as \Package{yhmath}'s \csx{adots}, but better).
Documentation of \Package{yhmath} appears, processed, in the
distribution (thus saving you the bother of installing the package
before being able to read the documentation). Documentation of
\Package{mathdots} appears at the end the package file itself.
\begin{ctanrefs}
\item[amslatex]\CTANref{amslatex}
\item[graphics.sty]Part of the \CTANref{graphics} bundle
\item[mathdots.sty]\CTANref{mathdots}
\item[yhmath]\CTANref{yhmath}
\end{ctanrefs}
\LastEdit{2013-08-21}
\Question[Q-limits]{Sub- and superscript positioning for operators}
The commonest hand-written style for expressions is to place the limit
expressions on operators such as \csx{sum} and \csx{int} physically
above and below the operator. In \AllTeX{}, we write these limit
expressions using sub- and superscripts applied to the operator, but
they don't always appear in the ``handwritten'' way in \TeX{}'s
output.
The reason is, that when an expression appears in non-display maths,
in running text (and is therefore in \TeX{} \csx{textstyle}), placing
the limits thus could lead to ragged line spacing (and hence
difficult-to-read text). It is therefore common (in \csx{textstyle})
to place the limits as one would sub- and superscripts of variables.
This is not universally satisfactory, so the primitive \csx{limits} is
provided:
\begin{quote}
\begin{verbatim}
$\sum\limits_{n=1}^{m} ...$
\end{verbatim}
\end{quote}
which will place the limits right above and below the symbol (and be
blowed to the typography\dots{}).
Contrariwise, you may wish to change the arrangement of the limits
when in \csx{displaystyle}. For this purpose, there's a corresponding
\csx{nolimits}:
\begin{quote}
\begin{verbatim}
\[\sum\nolimits_{n=1}^{m} ...\]
\end{verbatim}
\end{quote}
which will place the limits as they would be in \csx{textstyle}.
Alternatively, one can manipulate the
\csx{textstyle}/\csx{displaystyle} state of the mathematics. To get
``\csx{limits} placement'' in inline maths,
\begin{quote}
\begin{verbatim}
$\displaystyle\sum_{n=1}^{m} ...$
\end{verbatim}
\end{quote}
and for ``\csx{nolimits} placement'' in display maths,
\csx{nolimits}:
\begin{quote}
\begin{verbatim}
\[\textstyle\sum_{n=1}^{m} ...\]
\end{verbatim}
\end{quote}
will serve. Either of these forms may have effects other than on the
operator you're considering, but there are still those who prefer this
formulation.
Remember, if you're % ! line break
\Qref*{declaring a special operator of your own}{Q-newfunction}, the
\AMSLaTeX{} functions (that you ought to be using) allow you to choose
how limits are displayed, at definition time.
(Note that the macro \csx{int} normally has \csx{nolimits} built in to
its definition. There is an example in the \TeX{}book to show how odd
\csx{int}\csx{limits} looks when typeset.)
\Question[Q-mathstext]{Text inside maths}
When we type maths in \AllTeX{}, the letters from which we make up
ordinary text assume a special significance: they all become
single-letter variable names. The letters appear in italics, but it's
not the same sort of italics that you see when you're typing ordinary
text: a run of maths letters (for example ``here'') looks oddly
``lumpy'' when compared with the word written in italic text. The
difference is that the italic text is kerned to make the letters fit
well together, whereas the maths is set to look as if you're
multiplying \emph{h} by \emph{e} by \emph{r} by \emph{e}. The other
way things are odd in \TeX{} maths typing is that spaces are ignored:
at best we can write single words in this oddly lumpy font.
So, if we're going to have good-looking text in amongst maths we're
writing, we have to take special precautions. If you're using
\LaTeX{}, the following should help.
The simplest is to use \csx{mbox} or \csx{textrm}:
\begin{quote}
\begin{verbatim}
$e = mc^2 \mbox{here we go again}$
\end{verbatim}
\end{quote}
The problem is that, with either, the size of the text remains firmly
at the surrounding text size, so that
\begin{quote}
\begin{verbatim}
$z = a_{\mbox{other end}}$
\end{verbatim}
\end{quote}
can look quite painfully wrong.
The other simple technique, \csx{textrm}, is no more promising:
\begin{quote}
\begin{verbatim}
$z = a_{\textrm{other end}}$
\end{verbatim}
\end{quote}
does the same as \csx{mbox}, by default.
(The maths-mode instance of your roman font (\csx{mathrm}) gets the
size right, but since it's intended for use in maths, its spaces get
ignored~--- use \csx{mathrm} for upright roman alphabetic variable
names, but not otherwise.)
You can correct these problems with size selectors in the text, as:
\begin{quote}
\begin{verbatim}
$z = a_{\mbox{\scriptsize other end}}$
\end{verbatim}
\end{quote}
which works if your surrounding text is at default document size, but
gives you the wrong size otherwise.
The \csx{mbox} short cut is (just about) \acro{OK} for ``occasional''
use, but serious mathematics calls for a technique that
relieves the typist of the sort of thought required. As usual, the
\AMSLaTeX{} system provides what's necessary~--- the \csx{text}
command. (The command is actually provided by the \Package{amstext}
package, but the ``global'' \Package{amsmath} package loads it.) Thus
anyone using \AMSLaTeX{} proper has the command available, so even
this author can write:
\begin{quote}
\begin{verbatim}
\usepackage{amsmath}
...
$z = a_{\text{other end}}$
\end{verbatim}
\end{quote}
and the text will be at the right size, and in the same font as
surrounding text. (The \Package{amstext} package also puts
\csx{textrm} to rights~--- but \csx{text} is easier to type than
\csx{textrm}!)
\AMSLaTeX{} also makes provision for interpolated comments in the
middle of one of its multi-line display structures, through the
\csx{intertext} command. For example:
\begin{quote}
\begin{narrowversion}
\begin{verbatim}
\begin{align}
A_1&=N_0(\lambda;\Omega')-
\phi(\lambda;\Omega'),\\
A_2&=\phi(\lambda;\Omega')-
\phi(\lambda;\Omega),\\
\intertext{and}
A_3&=\mathcal{N}(\lambda;\omega).
\end{align}
\end{verbatim}
\end{narrowversion}
\begin{wideversion}
\begin{verbatim}
\begin{align}
A_1&=N_0(\lambda;\Omega')-\phi(\lambda;\Omega'),\\
A_2&=\phi(\lambda;\Omega')-\phi(\lambda;\Omega),\\
\intertext{and} A_3&=\mathcal{N}(\lambda;\omega).
\end{align}
\end{verbatim}
\end{wideversion}
\end{quote}
places the text ``and'' on a separate line before the last line of the
display. If the interjected text is short, or the equations
themselves are light-weight, you may find that \csx{intertext} leaves
too much space. Slightly more modest is the \csx{shortintertext}
command from the \Package{mathtools} package:
\begin{quote}
\begin{verbatim}
\begin{align}
a =& b
\shortintertext{or}
c =& b
\end{align}
\end{verbatim}
\end{quote}
To have the text on the same line as the second equation, one can use
the \environment{flalign} environment (from \Package{amsmath})
with lots of dummy equations (represented by the double \texttt{\&}
signs):
\begin{quote}
\begin{verbatim}
\begin{flalign}
&& a =& b && \\
\text{or} && c =& b &&
\end{flalign}
\end{verbatim}
\end{quote}
\begin{ctanrefs}
\item[amsmath.sty]Distributed as part of \AMSLaTeX{}
\CTANref{amslatex}[amsmath]
\item[amstext.sty]Distributed as part of \AMSLaTeX{}
\CTANref{amslatex}[amstext]
\item[mathtools.sty]Distributed as part of the \Package{mh} bundle
\CTANref{mh}[mathtools]
\end{ctanrefs}
\Question[Q-reuseq]{Re-using an equation}
To repeat an existing equation, one wants not only to have the same
mathematics in it, one also wants to re-use the original label it had.
The \Package{amsmath} package comes to our help, here:
\begin{quote}
\begin{verbatim}
\usepackage{amsmath}
...
\begin{equation}
a=b
\label{eq1}
\end{equation}
...
Remember that
\begin{equation}
a=b
\tag{\ref{eq1}}
\end{equation}
\end{verbatim}
\end{quote}
Here, the second instance of \ensuremath{a=b} will be
typeset with a copy, made by the \csx{tag} command, of the label of the
first instance.
\begin{ctanrefs}
\item[amsmath.sty]Distributed as part of \AMSLaTeX{}
\CTANref{amslatex}[amsmath]
\end{ctanrefs}
\Question[Q-brkinline]{Line-breaking in in-line maths}
\TeX{}, by default, allows you to split a mathematical expression at
the end of the line; it allows breaks at relational operators (like
``='', ``\textless'', etc.) and at binary operators (like ``+'',
``-'', etc.). In the case of large expressions, this can sometimes be
a life-saver.
However, in the case of simple expressions like \ensuremath{a=b+c}, a
break can be really disturbing to the reader, and one would like to
avoid it.
Fortunately, these breaks are controllable: there are ``penalties''
associated with each type of operator: the penalty
says how
undesirable a break at each point is. Default values are:
\begin{quote}
\begin{verbatim}
\relpenalty = 500
\binoppenalty = 700
\end{verbatim}
\end{quote}
You make the break progressively less attractive by increasing these
values. You can actually forbid all breaks, everywhere, by:
\begin{quote}
\begin{verbatim}
\relpenalty = 10000
\binoppenalty = 10000
\end{verbatim}
\end{quote}
If you want just to prevent breaks in a single expression, write:
\begin{quote}
\begin{verbatim}
{%
\relpenalty = 10000
\binoppenalty = 10000
$a=b+c$
}
\end{verbatim}
\end{quote}
and the original values will remain undisturbed outside the braces.
This is tedious: there is often value in an alternative approach,
in which you say which parts of the expression may not break whatever
happens, and fortunately this is surprisingly easy. Suppose we want
to defer a break until after the equality, we could write:
\begin{quote}
\begin{verbatim}
${a+b+c+d} = z+y+x+w$
\end{verbatim}
\end{quote}
The braces say ``treat this subformula as one atom'' and (in \TeX{} at
least) atoms don't get split: not a \csx{binoppenalty} change in sight.
\Question[Q-mathonlyref]{Numbers for referenced equations only}
There are those who consider that papers look untidy with numbers on
every equation; there is also a school of thought that claims that
there should be numbers everywhere, in case some reader wants to make
reference an equation to which the author made no cross-reference.
If you hold to the ``only cross-referenced'' school of thought, you
can (using the \csx{nonumber} command on the relevant equations, or by
using the \AMSLaTeX{} unnumbered environments such as
\environment{equation*}) mark those of your equations to which you
make no reference. In a long or complex paper, this procedure could
well become deeply tedious.
Fortunately, help is at hand: the \Package{mh} bundle's
\Package{mathtools} package offers a `\pkgoption{showonlyrefs}'
switch through its \csx{mathtoolsset} command; when that's in
operation, only those equations to which you make reference will be
numbered in the final output. See the package's documentation for
details of how to make references when the switch is in effect.
\begin{ctanrefs}
\item[mathtools.sty]Distributed as part of \CTANref{mh}[mathtools]
\end{ctanrefs}
\Question[Q-subheight]{Even subscript height}
Other things being equal, \TeX{} will aim to position subscripts and
superscripts in places that ``look good''. Unfortunately, it only
does this for the sub- and superscripts of each atom at a time, so if
you have
\begin{quote}
\begin{verbatim}
$ X^{1}_{2} X_{2} $
\end{verbatim}
\end{quote}
the second subscript will appear higher, since the first has moved
down to avoid the superscript;
the effect can be noticeably distracting:
\begin{quote}
\begin{typesetversion}
$ X^{1}_{2} X_{2} $
\end{typesetversion}
\begin{htmlversion}
\includegraphics{faq-images1.png}
\end{htmlversion}
\end{quote}
You can avoid the problem, for a single instance, by
\begin{quote}
\begin{verbatim}
$ X^{1}_{2} X^{}_{2} $
\end{verbatim}
\end{quote}
here, the dummy superscript has the requisite ``pushing down'' effect:
\begin{quote}
\begin{typesetversion}
$ X^{1}_{2} X^{}_{2} $
\end{typesetversion}
\begin{htmlversion}
\includegraphics{faq-images2.png}
\end{htmlversion}
\end{quote}
While this technique does what is necessary, it is tedious and
potentially error-prone. So, for more than one or two equations
in a document, the \LaTeX{} user is advised to use the
\Package{subdepth} package, which forces the lower position for all
subscripts.
\begin{ctanrefs}
\item[subdepth.sty]\CTANref{subdepth}
\end{ctanrefs}
\subsection{Lists}
\Question[Q-enumerate]{Fancy enumeration lists}
The \Package{enumerate} package allows you to control the display of
the enumeration counter. The package adds an optional parameter to
the \environment{enumerate} environment, which is used to specify the
layout of the labels. The layout parameter contains an enumeration
type (`\texttt{1}' for arabic numerals, `\texttt{a}' or `\texttt{A}'
for alphabetic enumeration, and `\texttt{i}' or `\texttt{I}' for Roman
numerals), and things to act as decoration of the enumeration. So,
for example
\begin{quote}
\begin{verbatim}
\usepackage{enumerate}
...
\begin{enumerate}[(a)]
\item ... ...
\end{enumerate}
\end{verbatim}
\end{quote}
starts a list whose labels run (a), (b), (c), \dots{}; while
\begin{quote}
\begin{verbatim}
\usepackage{enumerate}
...
\begin{enumerate}[I/]
\item ... ...
\end{enumerate}
\end{verbatim}
\end{quote}
starts a list whose labels run I/, II/, III/, \dots{}
The \Package{paralist} package, whose primary purpose is % beware line break
\Qref*{compaction of lists}{Q-complist}, provides the same facilities
for its \environment{enumerate}-like environments.
If you need non-stereotyped designs, the \Package{enumitem} package
gives you most of the flexibility you might want to design your own.
The silly roman example above could be achieved by:
\begin{quote}
\begin{verbatim}
\usepackage{enumitem}
...
\begin{enumerate}[label=\Roman{*}/]
\item ... ...
\end{enumerate}
\end{verbatim}
\end{quote}
Note that the `\texttt{*}' in the key value stands for the list
counter at this level. You can also manipulate the format of
references to list item labels:
\begin{quote}
\begin{narrowversion}
\begin{verbatim}
\usepackage{enumitem}
...
\begin{enumerate}[label=\Roman{*}/,
ref=(\roman{*})]
\item ... ...
\end{enumerate}
\end{verbatim}
\end{narrowversion}
\begin{wideversion}
\begin{verbatim}
\usepackage{enumitem}
...
\begin{enumerate}[label=\Roman{*}/, ref=(\roman{*})]
\item ... ...
\end{enumerate}
\end{verbatim}
\end{wideversion}
\end{quote}
to make references to the list items format appear as (i), (ii),
(iii), etc.
The \Class{memoir} class includes functions that match those in the
\Package{enumerate} package, and has similar functionality for
\environment{itemize} lists.
%% It is possible (if not particularly convenient) to do the same thing
%% yourself. Suppose you want your top-level \environment{enumerate}s to
%% be labelled I/, II/, III/, \dots{}, then give these commands:
%% \begin{verbatim}
%% \renewcommand{\theenumi}{\Roman{enumi}}
%% \renewcommand{\labelenumi}{\theenumi/}
%% \end{verbatim}
%% The possible styles of numbering are given in Section~6.3 of Lamport's
%% book (see \Qref[question]{\TeX{}-related books}{Q-book-lists}). Both
%% \csx{theenumi} and \csx{labelenumi} must be changed, since
%% \csx{theenumi} is used in cross-references to the list.
%%
%% For lower level \environment{enumerate}s, replace |enumi| by |enumii|,
%% |enumiii| or |enumiv|, according to the level. If your label is much
%% larger than the default, you should also change \csx{leftmargini},
%% \csx{leftmarginii}, \emph{etc}.
\begin{ctanrefs}
\item[enumerate.sty]Distributed as part of \CTANref{2etools}[enumerate]
\item[enumitem.sty]\CTANref{enumitem}
\item[memoir.cls]\CTANref{memoir}
\item[paralist.sty]\CTANref{paralist}
\end{ctanrefs}
\Question[Q-complist]{How to adjust list spacing}
\Qref*{Lamport's book}{Q-latex-books} lists various
parameters for the layout of list (things like \csx{topsep},
\csx{itemsep} and \csx{parsep}), but fails to mention that they're set
automatically within the standard (\LaTeX{}-defined) lists. This
happens because each list
executes a command \csx{@list}\texttt{\meta{depth}} (the depth
appearing as a lower-case roman numeral); what's more, the top-level
\csx{@listi} is usually reset when the font size is changed. As a
result, it's rather tricky for
the user to control list spacing. Of course, the real answer is to use
a document class designed with more modest list spacing, but we all
know such things are hard to come by. The \Class{memoir} class doesn't
provide more compact lists, but offers the user control over the list
spacing using \csx{firmlist} and \csx{tightlist} (and \texttt{*}-ed
versions of them); see section~8.6 of the memoir manual.
There are packages that provide some control of list spacing, but they
seldom address the separation from surrounding text (defined by
\csx{topsep}). The \Package{expdlist} package, among its many controls
of the appearance of \environment{description} lists, offers a
compaction parameter (see the documentation); the \Package{mdwlist}
package offers a \csx{makecompactlist} command for users' own list
definitions, and uses it to define compact lists
\environment{itemize*}, \environment{enumerate*} and
\environment{description*}. In fact, you can write lists such as
these commands define pretty straightforwardly~--- for example:
\begin{quote}
\begin{verbatim}
\newenvironment{itemize*}%
{\begin{itemize}%
\setlength{\itemsep}{0pt}%
\setlength{\parskip}{0pt}}%
{\end{itemize}}
\end{verbatim}
\end{quote}
The \Package{paralist} package provides several approaches to list
compaction:
\begin{itemize}
\item its \environment{asparaenum} environment formats each item as if
it were a paragraph introduced by the enumeration label (which saves
space if the item texts are long);
\item its \environment{compactenum} environment is the same sort of
compact list as is provided in \Package{expdlist} and
\Package{mdwlist}; and
\item its \environment{inparaenum} environment produces a list ``in
the paragraph'', i.e., with no line break between items, which is a
great space-saver if the list item texts are short.
\end{itemize}
The package will manipulate its \environment{enumerate} environment
labels just like the \Qref*{\Package{enumerate} package}{Q-enumerate}
does.
\Package{Paralist} also provides \environment{itemize} equivalents
(\environment{asparaitem}, etc.), and \environment{description}
equivalents (\environment{asparadesc}, etc.).
The \Package{multenum} package offers a more regular form of
\Package{paralist}'s \environment{inparaenum}; you define a notional
grid on which list entries are to appear, and list items will always
appear at positions on that grid. The effect is somewhat like that of
the `tab' keys on traditional typewriters; the package was designed
for example sheets, or lists of answers in the appendices of a book.
The \Package{expdlist}, \Package{mdwlist} and \Package{paralist}
packages all offer other facilities for list configuration: you should
probably not try the ``do-it-yourself'' approaches outlined below if
you need one of the packages for some other list configuration
purpose.
For ultimate flexibility (including manipulation of \csx{topsep}), the
\Package{enumitem} package permits adjustment of list parameters using
a ``\emph{key}\latexhtml{\ensuremath{=}}{=}\meta{value}'' format.
For example, one might write
\begin{quote}
\begin{verbatim}
\usepackage{enumitem}
...
\begin{enumerate}[topsep=0pt, partopsep=0pt]
\item ...
\item ...
\end{enumerate}
\end{verbatim}
\end{quote}
to suppress all spacing above and below your list, or
\begin{quote}
\begin{verbatim}
\usepackage{enumitem}
...
\begin{enumerate}[itemsep=2pt,parsep=2pt]
\item ...
\item ...
\end{enumerate}
\end{verbatim}
\end{quote}
to set spacing between items and between paragraphs within items.
\Package{Enumitem} also permits manipulation of the label format in a
more ``basic'' (and therefore more flexible) manner than the % ! line break
\Qref*{\Package{enumerate} package}{Q-enumerate} does.
The ultimate in compaction (of every sort) is offered by the
\Package{savetrees} package; compaction of lists is included. The
package's prime purpose is to save space at every touch and turn:
don't use it if you're under any design constraint whatever!
\begin{ctanrefs}
\item[enumerate.sty]Distributed as part of \CTANref{2etools}[enumitem]
\item[enumitem.sty]\CTANref{enumitem}
\item[expdlist.sty]\CTANref{expdlist}
\item[memoir.cls]\CTANref{memoir}
\item[memoir \nothtml{\rmfamily}manual]\CTANref{memoir-man}
\item[mdwlist.sty]Distributed as part of \CTANref{mdwtools}[mdwlist]
\item[multenum.sty]\CTANref{multenum}
\item[paralist.sty]\CTANref{paralist}
\item[savetrees.sty]\CTANref{savetrees}
\end{ctanrefs}
\LastEdit{2012-10-30}
\Question[Q-interruptlist]{Interrupting enumerated lists}
It's often convenient to have commentary text, `outside' the list,
between successive entries of a list. In the case of
\environment{itemize} lists this is no problem, since there's never
anything to distinguish successive items, while in the case of
\environment{description} lists, the item labels are under the user's
control so there's no automatic issue of continuity.
For \environment{enumerate} lists, the labels are generated
automatically, and are context-sensitive, so the context (in this
case, the state of the enumeration counter) needs to be preserved.
The belt-and-braces approach is to remember the state of the
enumeration in your own counter variable, and then restore it when
restarting enumerate:
\begin{quote}
\begin{verbatim}
\newcounter{saveenum}
...
\begin{enumerate}
...
\setcounter{saveenum}{\value{enumi}}
\end{enumerate}
<Commentary text>
\begin{enumerate}
\setcounter{enumi}{\value{saveenum}}
...
\end{enumerate}
\end{verbatim}
\end{quote}
This is reasonable, in small doses\dots{} Problems (apart from sheer
verbosity) are getting the level right (``should I use counter
\texttt{enumi}, \texttt{enumii}, \dots{}'') and remembering not to
nest the interruptions (i.e., not to have a separate list, that is
itself interrupted) in the ``commentary text'').
The \Package{mdwlist} package defines commands \csx{suspend} and
\csx{resume} that simplify the process:
\begin{quote}
\begin{verbatim}
\begin{enumerate}
...
\suspend{enumerate}
<Commentary text>
\resume{enumerate}
...
\end{enumerate}
\end{verbatim}
\end{quote}
The package allows an optional name (as in
\cmdinvoke{suspend}[id]{enumerate}) to allow you to identify a
particular suspension, and hence provide a handle for manipulating
nested suspensions.
If you're suspending a \Qref*{fancy-enumeration list}{Q-enumerate},
you need to
re-supply the optional ``item label layout'' parameters required by
the \Package{enumerate} package when resuming the list, whether by the
belt-and-braces approach, or by the \Package{mdwlist}
\cmdinvoke{resume}{enumerate} technique. The task is a little tedious
in the \Package{mdwlist} case, since the optional argument has to be
encapsulated, whole, inside an optional argument to \csx{resume},
which requires use of extra braces:
\begin{quote}
\begin{verbatim}
\begin{enumerate}[\textbf{Item} i]
...
\suspend{enumerate}
<comment>
\resume{enumerate}[{[\textbf{Item} i]}]
...
\end{enumerate}
\end{verbatim}
\end{quote}
\nothtml{\noindent}The \Package{enumitem} package, in its most recent
release, will also allow you to resume lists:
\begin{quote}
\begin{verbatim}
\begin{enumerate}
...
\end{enumerate}
<comment>
\begin{enumerate}[resume]
...
\end{enumerate}
\end{verbatim}
\end{quote}
which feels just as ``natural'' as the \Package{mdwtools} facility,
and has the advantage of playing well with the other excellent
facilities of \Package{enumitem}.
\Package{Expdlist} has a neat way of providing for comments, with its
\csx{listpart} command. The command's argument becomes a comment
between items of the list:
\begin{quote}
\begin{verbatim}
\begin{enumerate}
\item item 1
\item item 2
\listpart{interpolated comment}
\item item 3
\end{enumerate}
\end{verbatim}
\end{quote}
This, you will realise, means it doesn't even have to think about
suspending or resuming the list, and of course it works equally well
in any of the list environments (thought it's not actually
\emph{necessary} for any but \environment{enumerate}).
\Package{Enumitem} also allows multi-level suspension and resumption
of lists:
\begin{quote}
\begin{verbatim}
\begin{enumerate}
\item outer item 1
\end{enumerate}
<comment>
\begin{enumerate}[resume]
\item outer item 2
% nested enumerate
\begin{enumerate}
\item inner item 1
\end{enumerate}
<nested comment>
% resume nested enumerate
\begin{enumerate}[resume]
\item inner item 2
\end{enumerate}