\ansno1.1: A \TeX nician (underpaid); sometimes also called a \TeX acker. \ansno2.1: |Alice said, ``I always use an en-dash instead of a hyphen when|\break |specifying page numbers like `480--491' in a bibliography.''| \ (The wrong answer to this question ends with |'480-49l' in a bibliography."|) \ansno2.2: You get em-dash and hyphen (----), which looks awful. \ansno2.3: fluffier firefly fisticuffs, flagstaff fireproofing, chiffchaff and riffraff. \ansno2.4: |``\thinspace`|; and either |`{}``| or |{`}``| or something similar. Reason: There's usually less space {\sl preceding\/} a single left quote than there is preceding a double left quote. \ (Left and right are opposites.) \ansno2.5: Eliminating ^|\thinspace| would mean that a user need not learn the term; but it is not advisable to minimize terminology by ``overloading'' math mode with tricky constructions. For example, a user who wishes to take advantage of \TeX's ^|\mathsurround| feature would be thwarted by non-mathematical uses of dollar signs. \ (Incidentally, neither |\thinspace| nor ^|\,| are built into \TeX; both are defined in terms of more primitive features, in Appendix~B.) \ansno3.1: |\I|, |\exercise|, and |\\|. (The last of these is of type~2, i.e., a control symbol, since the second backslash is not a letter; the first backslash keeps the second one from starting its own control sequence.) \ansno3.2: |math\'ematique| and |centim\`etre|.^^|\'|^^|\`| \ansno3.3: According to the index, |\|\] is primitive but |\|\ isn't. The command `|\def\^^M{\ }|' in Appendix~B is what actually defines |\|\, since a return is representable as |^^M|. Asking \TeX\ to |\show\^^M| \looseness-1 produces the response `|>| |\^^M=macro:->\|\]|.|'. \ansno3.4: There are 256 of length~2; most of these are undefined when \TeX\ begins. \ (\TeX\ allows any character to be an escape, but it does not distinguish between control sequences that start with different escape characters.) \ If we assume that there are 52 letters, there are exactly $52^2$ possible control sequences of length~3 (one for each pair of letters, from |AA| to |zz|). But Chapter~7 explains how to use ^|\catcode| to change any character into a ``^{letter}''; therefore it's possible to use any of $256^2$ potential control sequences of length~3. \ansno4.1: |Ulrich Dieter, {\sl Journal f\"ur die reine und angewandte|\parbreak |Mathematik\/ \bf201} (1959), 37--70.|\par\nobreak\smallskip\noindent It's convenient to use a single group for both |\sl| and |\bf| here. The `|\/|' is a refinement that you might not understand until you read the rest of Chapter~4. \ansno4.2: |{\it Explain ... typeset a\/ {\rm roman} word ... sentence.}| Note the position of the italic correction in this case. \ansno4.3: |\def\ic#1{\setbox0=\hbox{#1\/}\dimen0=\wd0|\parbreak |\setbox0=\hbox{#1}\advance\dimen0 by -\wd0}|. \ansno4.4: Control word names are made of letters, not digits. \ansno4.5: Say |\def\sl{\it}| at the beginning, and delete other definitions of\/ |\sl| that might be present in your format file (e.g., there might be one inside a |\tenpoint| macro). \ansno4.6: |\font\squinttenrm=cmr10 at 5pt|\parbreak |\font\squinttenrm=cmr10 scaled 500| \ansno5.1: |{shelf}ful| or |shelf{}ful|, etc.; or even |shelf\/ful|, which yields a shelf\/ful instead of a shelf{}ful. In fact, the latter idea---to insert an ^{italic correction}---is preferable because \TeX\ will ^^|\/| reinsert the ff ligature by itself after ^{hyphenating} |shelf{}ful|. \ (Appendix~H points out that ligatures are put into a hyphenated word that contains no ``^{explicit kerns},'' and an italic correction is an explicit kern.) \ But the italic correction may be too much (especially in an italic font); |shelf{|^|\kern||0pt}ful| is often best. \ansno5.2: `\]|{|\]|}|\]' or `\]|{}|\]|{}|\]', etc. Plain \TeX\ also has a ^|\space| macro, so you can type |\space\space\space|. \ (These aren't strictly equivalent to `|\|\]|\|\]|\|\]', since they adjust the spaces by the current ``^{space factor},'' as explained later.) \ansno5.3: In the first case, you get the same result as if the innermost braces had not appeared at all, because you haven't used the grouping to change fonts or to control spacing or anything. \TeX\ doesn't mind if you want to waste your time making groups for no particular reason. But in the second case, the necessary braces were forgotten. You get the letter `S' centered on a line by itself, followed by a paragraph that begins with `o should this.' on the next line. \ansno5.4: You get the same result as if another pair of braces were present around `|\it centered|', except that the period is typeset from the italic font. \ (Both periods look about the same.) \ The |\it| font will not remain in force after the |\centerline|, but this is something of a coincidence: \TeX\ uses the braces to determine what text is to be centered, but then it removes the braces. The |\centerline| operation, as defined in Appendix~B\null, puts the resulting braceless text inside {\sl another\/} group; and that's why |\it| disappears after |\centerline|. \ (If you don't understand this, just don't risk leaving out braces in tricky situations, and you'll be OK.) \ansno5.5: |\def\ital#1{{\it#1\/}}|. \ Pro:~Users might find this easier to learn, because it works more like |\centerline| and they don't have to remember to make the italic correction. \ Con:~To avoid the italic correction just before a {\it comma} or {\it period}, users should probably be taught another control sequence; for example, with \begintt \def\nocorr{\kern0pt } \endtt a user could type `|\ital{comma} or \ital{period\nocorr},|'. The alternative of putting a period or comma in italics, to avoid the italic correction, doesn't look as good. A long sequence of italics would be inefficient for \TeX, since the entire text for the argument to |\ital| must be read into memory only to be scanned again. \ansno5.6: |{1 {2 3 4 5} 4 6} 4|. \ansno5.7: |\def\beginthe#1{\begingroup\def\blockname{#1}}|\parbreak |\def\endthe#1{\def\test{#1}%|\parbreak | \ifx\test\blockname\endgroup|\parbreak | \else\errmessage{You should have said|\parbreak | \string\endthe{\blockname}}\fi}| \ansno6.1: Laziness and/or obstinacy. \ansno6.2: There's an unwanted space after `called---', because (as the book says) \TeX\ treats the end of a line as if it were a blank space. That blank space is usually what you want, except when a line ends with a hyphen or a dash; so you should {\sc WATCH OUT} for lines that end with hyphens or dashes. \ansno6.3: It represents the heavy bar that shows up in your output. \ (This bar wouldn't be present if\/ ^|\overfullrule| had been set to |0pt|, nor is it present in an underfull box.) \ansno6.4: This is the ^|\parfillskip| space that ends the paragraph. In plain \TeX\ the parfillskip is zero when the last line of the paragraph is full; hence no space actually appears before the rule in the output of Experiment~3. But all hskips show up as spaces in an overfull box message, even if they're zero. \ansno6.5: Run \TeX\ with \hbox{|\hsize=1.5in|} \hbox{|\tolerance=10000|} \hbox{|\raggedright|} \hbox{|\hbadness=-1|} and then |\input story|. \TeX\ will report the badness of all lines (except the final lines of paragraphs, where fill glue makes the badness zero). \ansno6.6: |\def\extraspace{\nobreak \hskip 0pt plus .15em\relax}|\parbreak |\def\dash{\unskip\extraspace---\extraspace}|\par\nobreak\smallskip\noindent (If you try this with the story at 2-inch and 1.5-inch sizes, you will notice a substantial improvement. The |\unskip| allows people to leave a space before typing |\dash|. \TeX\ will try to hyphenate before |\dash|, but not before `|---|'; cf.\ Appendix~H\null. The ^|\relax| at the end of |\extraspace| is a precaution in case the next word is `|minus|'.) \ansno6.7: \TeX\ would have deleted five tokens: |1|, |i|, |n|, \], |\centerline|. (The space was at the end of line~2, the |\centerline| at the beginning of line~3.) \ansno6.8: A control sequence like |\centerline| might well define a control sequence like |\ERROR| before telling \TeX\ to look at |#1|. Therefore \TeX\ doesn't interpret control sequences when it scans an argument. \ansno7.1: Three forbidden characters were used. One should type \begintt Procter \& Gamble's ... \$2, a 10\% gain. \endtt (Also the facts are wrong.) \ansno7.2: Reverse slashes (backslashes) are fairly uncommon in formulas or text, and |\\| is very easy to type; it was therefore felt best not to reserve |\\| for such limited use. Typists can define |\\| to be whatever they want (including |\backslash|). \ansno7.3: 1, 2, 3, 4, 6, 7, 8, 10, 11, 12, 13. ^{Active characters} (type 13) are somewhat special; they behave like control sequences in most cases (e.g., when you say `^|\let||\x=~|' or `^|\ifx||\x~|'), but they behave like character tokens when they appear in the token list of\/ ^|\uppercase| or ^|\lowercase|, and when unexpanded after ^|\if| or ^|\ifcat|. \ansno7.4: It ends with either |>| or |}| or any character of category 2; then the effects of all |\catcode| definitions within the group are wiped out, except those that were ^|\global|. \TeX\ doesn't have any built-in knowledge about how to pair up particular kinds of grouping characters. New category codes take effect as soon as a |\catcode| assignment has been digested. For example, \begintt {\catcode`\>=2 > \endtt is a complete group. But without the space after `|2|' it would not be complete, since \TeX\ would have read the~`|>|' and converted it to a token before knowing what category code was being specified; \TeX\ always reads the token following a constant before evaluating that ^{constant}. \ansno7.5: If you type `|\message{\string~}|' and `|\message{\string\~}|', \TeX\ responds with `|~|' and `|\~|', respectively. ^^|\message| To get |\|$_{12}$ from |\string| you therefore need to make backslash an active character. One way to do this is \begintt {\catcode`/=0 \catcode`\\=13 /message{/string\}} \endtt (The ``^{null control sequence}'' that you get when there are no tokens between |\csname| and |\endcsname| is not a solution to this exercise, because |\string| converts it to `|\csname\endcsname|'. There is, however, another solution: If \TeX's ^|\escapechar| parameter---which will be explained in one of the next dangerous bends---is negative or greater than~255, then `|\string\\|' works.) \ansno7.6: |\|$_{12}$ |a|$_{12}$ |\|$_{12}$ \]$_{10}$ |b|$_{12}$. \ansno7.7: |\def\ifundefined#1{\expandafter\ifx\csname#1\endcsname\relax}|% \hfil\break Note that a control sequence like this must be used with care; it cannot be included in ^{conditional} text, because the |\ifx| will not be seen when |\ifundefined| isn't expanded. \ansno7.8: First |\uppercase| produces `|A\lowercase{BC}|'; then you get `|Abc|'. \ansno7.9: `\thinspace|\copyright\ \uppercase\expandafter{\romannumeral\year}|% \thinspace'. \ (This is admittedly tricky; the `^|\expandafter|' expands the token after the `|{|', not the token after the group.) \ansno7.10: (We assume that parameter |#2| is not simply an active character, and that ^|\escapechar| is between 0 and~255.) \begintt \def\gobble#1{} % remove one token \def\appendroman#1#2#3{\edef#1{\csname \expandafter\gobble\string#2\romannumeral#3\endcsname}} \endtt \ansno8.1: The |%| would be treated as a comment character, because its category code is~14; thus, no |%| token or |}| token would get through to the gullet of \TeX\ where numbers are treated. When a character is of category 0, 5, 9, 14, or~15, the extra |\| must be used; and the |\| doesn't hurt, so you can always use it to be safe. \ansno8.2: (a)~Both characters terminate the current line; but a character of category~5 might be converted into \]$_{10}$ or a \cstok{par} token, while a character of category~14 never produces a token. (b)~They produce character tokens stamped with different category numbers. For example, |$|$_3$ is not the same token as |$|$_4$, so \TeX's digestive processes will treat them differently. (c)~Same as~(b), plus the fact that control sequence names treat letters differently. (d)~No. (e)~Yes; characters of category~10 are ignored at the beginning of every line, since every line starts in state~$N$. (f)~No. \ansno8.3: \TeX\ had just read the control sequence |\vship|, so it was in state~$S$, and it was just ready to read the space before `|1in|'. Afterwards it ignored that space, since it was in state~$S$; but if you had typed |I\obeyspaces| in response to that error message, you would have seen the space. Incidentally, when \TeX\ prints the ^{context of an error message}, the bottom pair of lines comes from a text file, but the other pairs of lines are portions of token lists that \TeX\ is reading (unless they begin with `|<*>|', when they represent text inserted during ^{error recovery}). \ansno8.4: |$|$_{3}$ |x|$_{11}$ |^|$_7$ |2|$_{12}$ |$|$_{3}$ |~|$_{13}$ \]$_{10}$ \cstok{TeX} |b|$_{12}$ |v|$_{12}$ \]$_{10}$. The final space comes from the \ placed at the end of the line. Code |^^6| yields |v| only when not followed by |0|--|9| or |a|--|f|. The initial space is ignored, because state~$N$ governs the beginning of the line. \ansno8.5: |H|$_{11}$ |i|$_{11}$ |!|$_{12}$ \]$_{10}$ \cstok{par} \cstok{par}. The `\]' comes from the \ at the end of the first line; the second and third lines each contribute a \cstok{par}. \ansno8.6: The two |^^B|'s are not recognized as consecutive superscript characters, since the first |^^B| is converted to code~2 which doesn't equal the following character |^|. Hence the result is seven tokens: |^^B|$_7$ |^^B|$_7$ |M|$_{11}$ \cstok{\^{}\^{}B} \]$_{10}$ |^^M|$_{11}$ \cstok{M\^{}\^{}M}. The last of these is a control word whose name has two letters. The \ after |\M| is deleted before \TeX\ inserts the \ token. \ansno8.7: Both alternatives work fine in text; in particular, they combine as in |\lq\lq| to form ligatures. But the definition in Appendix~B works also in connection with constants; e.g., |\char\lq\%| and |\char\rq140| are valid. \ (Incidentally, the construction |\let\lq=`| would not work with constants, since the quotes in a ^\ must come from character tokens of category~12; after |\let\lq=`| the control sequence token |\lq| will not expand into a character token, nor {\sl is\/} it a character token!) ^^|\let| ^^{implicit character} \ansno9.1: |na\"\i ve| or |na{\"\i}ve| or |na\"{\i}ve|. \ansno9.2: Belov\`ed prot\'eg\'e; r\^ole co\"ordinator; souffl\'es, cr\^epes, p\^at\'es, etc. \ansno9.3: |\AE sop's \OE uvres en fran\c cais|. \ansno9.4: |{\sl Commentarii Academi\ae\ scientiarum imperialis|\hfil\break |petropolitan\ae\/} became {\sl Akademi\t\i a Nauk SSSR, Doklady}.| \ansno9.5: |Ernesto Ces\`aro, P\'al Erd\H os, \O ystein Ore, Stanis\l aw \'Swier%|\break|czkowski, Serge\u\i\ \t Iur'ev, Mu\d hammad ibn M\^us\^a al-Khw\^arizm\^\i.| \ansno9.6: The proper umlaut is |\H|, which isn't available in |\tt|, so it's necessary to borrow the accent from another font. For example, \hbox{|{\tt P\'al Erd{\bf\H{\tt o}}s}|} uses a bold accent, which is suitably dark. \ansno9.7: |{\it Europe on {\sl\$}15.00 a day\/}| \ansno9.8: The extra braces keep font changes local. An argument makes the use of\/ |\'| more consistent with the use of other accents like |\d|, which are manufactured from other characters without using the |\accent| primitive. \ansno10.1: Exactly $7227\pt$. \ansno10.2: $\rm-.013837\,in$, $\rm0.\,mm$, $\rm+42.1\,dd$, $\rm3\,in$, $\rm29\,pc$, $\rm123456789\,sp$. \ (The lines of text in this manual are 29~picas wide.) \ansno10.3: The first is not allowed, since octal notation cannot be used with a decimal point. The second is, however, legal, since a \ can be hexadecimal according to the rule mentioned in Chapter~8; it means $\rm12\,cc$, which is $\rm144\,dd\approx154.08124\,pt$. The third is also accepted, since a \ can be empty; it is a complicated way to say $\rm0\,sp$. \ansno10.4: {\obeylines|\def\tick#1{\vrule height 0pt depth #1pt}| |\def\\{\hbox to 1cm{\hfil\tick4\hfil\tick8}}| |\vbox{\hrule\hbox{\tick8\\\\\\\\\\\\\\\\\\\\}}| \noindent(You might also try putting ticks at every millimeter, in order % to see how good your system is; % some output devices can't handle 101~rules all at once.)} \ansno10.5: For example, say `|\magnification=\magstep1 \input story \end|' to get magnification 1200; |\magstep2| and |\magstep3| are 1440 and 1728. Three separate runs are needed, since there can be at most one magnification per job. The output may look funny if the fonts don't exist at the stated magnifications. \ansno10.6: Magnification is by a factor of 1.2. Since font |\first| is |cmr10| at $12\pt$, it will be |cmr10| at $14.4\pt$ after magnification; font |\second| will be |cmr10| at $12\pt$. \ (\TeX\ changes `|12truept|' into `|10pt|', and the final output magnifies it back to $12\pt$.) \ansno11.1: This |E| is inside a box that's inside a box. \ansno11.2: The idea is to construct a box and to look inside. For example, \begintt \setbox0=\hbox{\sl g\/} \showbox0 \endtt reveals that |\/| is implemented by placing a kern after the character. Further experiment shows that this kern is inserted even when the italic correction is zero. \ansno11.3: The height, depth, and width of the enclosing box should be just large enough to enclose all of the contents, so the result is: \begintt \hbox(8.98608+0.0)x24.44484 .\tenrm T .\kern 1.66702 .\hbox(6.83331+0.0)x6.80557, shifted -2.15277 ..\tenrm E .\kern 1.25 .\tenrm X \endtt (You probably predicted a height of |8.9861|; \TeX's internal calculations are in |sp|, not |pt|/100000, so the rounding in the fifth decimal place is not readily predictable.) \ansno11.4: No applications of such symmetrical boxes to English-language printing were apparent; it seemed pointless to carry extra generality as useless baggage that would rarely if ever be used, merely for the sake of symmetry. In other words, the author wore a computer science cap instead of a mathematician's mantle on the day that \TeX's boxes were born. Time will tell whether or not this was a fundamental error! \ansno11.5: The following solution is based on a general |\makeblankbox| macro that prints the edges of a box using rules of given thickness outside and inside that box; the box dimensions are those of\/ |\box0|.\par |\def\dolist{\afterassignment\dodolist\let\next= }|\parbreak |\def\dodolist{\ifx\next\endlist \let\next\relax|\parbreak | \else \\\let\next\dolist \fi|\parbreak | \next}|\par |\def\endlist{\endlist}|\par |\def\hidehrule#1#2{\kern-#1%|\parbreak | \hrule height#1 depth#2 \kern-#2 }|\par |\def\hidevrule#1#2{\kern-#1{\dimen0=#1|\parbreak | \advance\dimen0 by#2\vrule width\dimen0}\kern-#2 }|\par |\def\makeblankbox#1#2{\hbox{\lower\dp0\vbox{\hidehrule{#1}{#2}%|\parbreak | \kern-#1 % overlap the rules at the corners|\parbreak | \hbox to \wd0{\hidevrule{#1}{#2}%|\parbreak | \raise\ht0\vbox to #1{}% set the vrule height|\parbreak | \lower\dp0\vtop to #1{}% set the vrule depth|\parbreak | \hfil\hidevrule{#2}{#1}}%|\parbreak | \kern-#1\hidehrule{#2}{#1}}}}|\par |\def\maketypebox{\makeblankbox{0pt}{1pt}}|\par |\def\makelightbox{\makeblankbox{.2pt}{.2pt}}|\par |\def\\{\expandafter\if\space\next\|\parbreak | \else \setbox0=\hbox{\next}\maketypebox\fi}|\par |\def\demobox#1{\setbox0=\hbox{\dolist#1\endlist}%|\parbreak | \copy0\kern-\wd0\makelightbox}|\par \ansno11.6: |\def\frac#1/#2{\leavevmode\kern.1em|\parbreak |\raise.5ex\hbox{\the\scriptfont0 #1}\kern-.1em|\parbreak |/\kern-.15em\lower.25ex\hbox{\the\scriptfont0 #2}}| \ansno12.1: $9+16$ units, $9+32$ units, $12+0$ units. \ (But \TeX\ would consider so much stretching to be ``infinitely bad.'') \ansno12.2: `What happens now?' is placed in a line of width |\hsize|, with twice as much space at the left as at the right; `and now?' is put flush right on the following line. \ansno12.3: The first two give an ``overfull box'' if the argument doesn't fit on a line; the third allows the argument to stick out into the margins instead. \ (Plain \TeX's ^|\centerline| is |\centerlinec|; the stickout effect shows up in the narrow-column experiment of Chapter~6.) \ If the argument contains no infinite glue, |\centerlinea| and |\centerlineb| produce the same effect; but |\centerlineb| will center an argument that contains `fil' glue. \ansno12.4: |Mr.~\& Mrs.~User were married by Rev.~Drofnats, who preached on Matt.~19\thinspace:\thinspace3--9.| \ (Such thin spaces are traditional for ^{Biblical references} to chapter and verse, but you weren't really expected to know that. Plain \TeX\ defines ^|\thinspace| to be a kern, not glue; hence no break between lines will occur at a thinspace.) \ansno12.5: |Donald~E.\ Knuth, ``Mathematical typography,'' {\sl Bull.\ Amer.\ Math.\ Soc.\ \bf1} (1979), 337--372.| \ (But the `|\|' after `|E.|' isn't necessary, because of a rule you will learn if you venture around the next dangerous bend.) \ansno12.6: There are several ways; perhaps the easiest are to type `|\hbox{NASA}.|'\ or `|NASA\null.|' \ (The ^|\null| macro is an abbreviation for `|\hbox{}|'.) \ansno12.7: 1000, except: 999 after |O|, |B|, |S|, |D|, and |J|; 1250 after the comma; 3000 after the exclamation point, the right-quote marks, and the periods. If a period had come just after the |B| (i.e., if the text had said `|B. Sally|'), the space factor after that period would have been~1000, not~3000. \ansno12.8: |\box3| is $2\pt$ high, $4\pt$ deep, $3\pt$ wide. Starting at the reference point of\/ |\box3|, go right $.75\pt$ and down $3\pt$ to reach the reference point of\/ |\box1|; or go right $1\pt$ to reach the reference point of\/ |\box2|. \ansno12.9: The stretch and shrink components of\/ |\baselineskip| and |\lineskip| should be equal, and the |\lineskiplimit| should equal the normal |\lineskip| spacing, to guarantee continuity. \ansno12.10: Yes it did, but only because none of his boxes had a negative height or depth. He would have been safer if he had set |\baselineskip=-1000pt|, |\lineskip=0pt|, and |\lineskiplimit=16383pt|. \ (Plain \TeX's ^|\offinterlineskip| macro does this.) \ansno12.11: The interline glue will be zero, and the natural height is $1+1-3+2=1\pt$ (because the depth of\/ |\box2| isn't included in the natural height); so the glue will ultimately become |\vskip-1pt| when it's set. Thus, |\box3| is $3\pt$ high, $2\pt$ deep, $4\pt$ wide. Its reference point coincides with that of\/ |\box2|; to get to the reference point of\/ |\box1| you go up $2\pt$ and right $3\pt$. \ansno12.12: The interline glue will be $6\pt$ minus $3\,{\rm fil}$; the final depth will be zero, since |\box2| is followed by glue; the natural height is $12\pt$; and the shrinkability is $5\,{\rm fil}$. So |\box4| will be $4\pt$ high, $0\pt$ deep, $1\pt$ wide, and it will contain five items: |\vskip|\penalty0\hbox{|-1.6pt|}, |\box1|, |\vskip1.2pt|, |\moveleft4pt\box2|, |\vskip-1.6pt|. Starting at the reference point of |\box4|, you get to the reference point of\/ |\box1| by going up $4.6\pt$, or to the reference point of\/ |\box2| by going up $.4\pt$ and left $4\pt$. \ (For example, you go up $4\pt$ to get to the upper left corner of |\box4|; then down $-1.6\pt$, i.e., up $1.6\pt$, to get to the upper left corner of\/ |\box1|; then down $1\pt$ to reach its reference point. This problem is clearly academic, since it's rather ridiculous to include infinite shrinkability in the baselineskip.) \ansno12.13: Now |\box4| will be $4\pt$ high, $-4\pt$ deep, $1\pt$ wide, and it will contain |\vskip|\penalty0\hbox{|-2.4pt|}, |\box1|, |\vskip-1.2pt|, |\moveleft4pt\box2|, |\vskip-2.4pt|. From the baseline of\/ |\box4|, go up exactly $5.4\pt$ to reach the baseline of\/ |\box1|, or exactly $3.6\pt$ to reach the baseline of\/ |\box2|. \ansno12.14: |\vbox to| $x$|{}| produces height $x$; |\vtop to| $x$|{}| produces depth $x$; the other dimensions are zero. \ (This holds even when $x$ is negative.) \ansno12.15: There are several possibilities: \begintt \def\nullbox#1#2#3{\vbox to#1{\vss\hrule height-#2depth#2width#3}} \endtt works because the rule will be of zero thickness. Less tricky is \begintt \def\nullbox#1#2#3{\vbox to#1{\vss\vtop to#2{\vss\hbox to#3{}}}} \endtt Both of these are valid with negative height and/or depth, but they do not produce negative width. If the width might be negative, but not the height or depth, you can use, e.g., |\def\nullbox#1#2#3{\hbox to#3{\hss\raise#1\null\lower#2\null}}|. It's impossible for |\hbox| to construct a box whose height or depth is negative; it's impossible for |\vbox| or |\vtop| to construct a box whose width is negative.\par However, there's actually a trivial solution to the general problem, based on features that will be discussed later: \begintt \def\nullbox#1#2#3{\setbox0=\null \ht0=#1 \dp0=#2 \wd0=#3 \box0 } \endtt \ansno12.16: |\def\llap#1{\hbox to 0pt{\hss#1}}| \ansno12.17: You get `A' at the extreme left and `puzzle.\null' at the extreme right, because the space between words has the only stretchability that is finite; the infinite stretchability cancels out. \ (In this case, \TeX's rule about ^{infinite glue} differs from what you would get in the limit if the value of $1\,{\rm fil}$ were finite but getting larger and larger. The true limiting behavior would stretch the text `A~puzzle.\null' in the same way, but it would also move that text infinitely far away beyond the right edge of the page.) \ansno13.1: Simply saying |\hbox{...}| won't work, since that box will just continue the previous vertical list without switching modes. You need to start the paragraph explicitly, and the straightforward way to do that is to say |\indent\hbox{...}|. But suppose you want to define a macro that expands to an hbox, where this macro is to be used in the midst of a paragraph as well as at the beginning; then you don't want to force users to type |\indent| before calling your macro at the beginning of a paragraph, nor do you want to say |\indent| in the macro itself (since that might insert unwanted indentations). One solution to this more general problem is to say `|\|\]^|\unskip||\hbox{...}|', since |\|\] makes the mode horizontal while |\unskip| removes the unwanted space. Plain \TeX\ provides a ^|\leavevmode| macro, which solves this problem in what is probably the most efficient way: |\leavevmode| is an abbreviation for `|\unhbox\voidbox|', where |\voidbox| is a permanently empty box register. \ansno13.2: The output of\/ |\tracingcommands| shows that four blank space tokens were digested; these originated at the ends of lines 2,~3, 4, and~5. Only the first had any effect, since blank spaces are ignored in math formulas and in vertical modes. \ansno13.3: The |end-group character| finishes the paragraph and the |\vbox|, and |\bye| stands for `|\vfill...|', so the next three commands are \begintt {math mode: math shift character $} {restricted horizontal mode: end-group character }} {vertical mode: \vfill} \endtt \ansno13.4: It contains only mixtures of vertical glue and horizontal rules whose reference points appear at the left of the page; there's no text. \ansno13.5: Vertical mode can occur only as the outermost mode; horizontal mode and display math mode can occur only when immediately enclosed by vertical or internal vertical mode; ordinary math mode cannot be immediately enclosed by vertical or internal vertical mode; all other cases are possible. \ansno14.1: |(cf.~Chapter~12).|\parbreak |Chapters 12 and~21.|\parbreak |line~16 of Chapter~6's {\tt story}|\parbreak |lines 7 to~11|\parbreak |lines 2,~3, 4, and~5.|\parbreak |(2)~a big black bar|\parbreak |All 256~characters are initially of category~12,|\parbreak |letter~{\tt x} in family~1.|\parbreak |the factor~$f$, where $n$~is 1000~times~$f$.| \ansno14.2: `|for all $n$~greater than~$n_0$|' avoids distracting breaks. \ansno14.3: `|exercise \hbox{4.3.2--15}|' guarantees that there is no break after the ^{en-dash}. But this precaution is rarely necessary, so `|exercise 4.3.2--15|' is an acceptable answer. No |~| is needed; `\hbox{4.3.2--15}' is so long that it causes no offense at the beginning of a line. \ansno14.4: The space you get from |~| will stretch or shrink with the other spaces in the same line, but the space inside an hbox has a fixed width since that glue has already been set once and for all. Furthermore the first alternative permits the word Chap-\break ter to be ^{hyphenate}d. \ansno14.5: `|\hbox{$x=0$}|' is unbreakable, and we will see later that `|${x=0}$|' cannot be broken. Both of these solutions set the glue surrounding the equals sign to some fixed value, but such glue normally wants to stretch; furthermore, the |\hbox| solution might include undesirable blank space at the beginning or end of a line, if\/ ^|\mathsurround| is nonzero. A third solution `|$x=\nobreak0$|' avoids both defects. \ansno14.6: |\exhyphenpenalty=10000| prohibits all such breaks, according to the rules found later in this chapter. Similarly, |\hyphenpenalty=10000| prevents breaks after implicit (discretionary) hyphens. \ansno14.7: The second and fourth lines are indented by an additional ``quad'' of space, i.e., by one extra em in the current type style. \ (The control sequence |\quad| does an ^|\hskip|; when \TeX\ is in vertical mode, |\hskip| begins a new paragraph and puts glue after the indentation.) \ If\/ |\indent| had been used instead, those lines wouldn't have been indented any more than the first and third, because |\indent| is implicit at the beginning of every paragraph. Double indentation on the second and fourth lines could have been achieved by `|\indent\indent|'. \ansno14.8: |ba\ck/en| and |Be\ttt/uch|, where the macros |\ck/| and |\ttt/| are defined by \begintt \def\ck/{\discretionary{k-}{k}{ck}} \def\ttt/{tt\discretionary{-}{t}{}} \endtt The English word `eighteen' might deserve similar treatment. \TeX's hyphenation algorithm will not make such spelling changes automatically. \ansno14.9: |\def\break{\penalty-10000 }| \ansno14.10: You get a forced break as if\/ |\nobreak| were not present, because |\break| cannot be cancelled by another penalty. In general if you have two penalties in a row, their combined effect is the same as a single penalty whose value is the minimum of the two original values, unless both of those values force breaks. \ (You get two breaks from |\break\break|; the second one creates an empty line.) \ansno14.11: Breaks are forced when $p\le-10000$, so there's no point in subtracting a large constant whose effect on the total demerits is known {\sl a priori}, especially when that might cause arithmetic overflow. \ansno14.12: $(10+131)^2+0^2+10000=29881$ and $(10+1)^2+50^2+10000=12621$. In both cases the ^|\adjdemerits| were added because the lines were visually incompatible (decent, then very loose, then decent); plain \TeX's values for ^|\linepenalty| and |\adjdemerits| were used. \ansno14.13: Because \TeX\ discards a glue item that occurs just before |\par|. Ben should have said, e.g., `|\hfilneg\ \par|'. \ansno14.14: Just say |\parfillskip|\stretch|=|\stretch|\parindent|. Of course, \TeX\ will not be able to find appropriate line breaks unless each paragraph is sufficiently long or sufficiently lucky; but with an appropriate text, your output will be immaculately symmetrical.{\parfillskip=\parindent\par} \ansno14.15: Assuming that the author is deceased and/or set in his or her ways, the remedy is to insert `|{\parfillskip=0pt\par\parskip=0pt\noindent}|' in random places, after each 50 lines or so of text. \ (Every space between words is usually a feasible breakpoint, when you get sufficiently far from the beginning of a paragraph.) \ansno14.16: |{\leftskip=-1pt \rightskip=1pt| \ |\par}|\par \nobreak\medskip\noindent (This applies to a full paragraph; if you want to correct only isolated lines, you have to do it by hand.) \ansno14.17: `|\def\line#1{\hbox to\hsize{\hskip\leftskip#1\hskip\rightskip}}|' is the only change needed. \ (Incidentally, ^{displayed equations} don't take account of\/ |\leftskip| and |\rightskip| either; it's more difficult to change that, because so many variations are possible.) \ansno14.18: The author's best solution is based on a variable |\dimen| register |\x|: \begintt \setbox1=\hbox{I} \setbox0=\vbox{\parshape=11 -0\x0\x -1\x2\x -2\x4\x -3\x6\x -4\x8\x -5\x10\x -6\x12\x -7\x14\x -8\x16\x -9\x18\x -10\x20\x \ifdim \x>2em \rightskip=-\wd1 \else \frenchspacing \rightskip=-\wd1 plus1pt minus1pt \leftskip=0pt plus 1pt minus1pt \fi \parfillskip=0pt \tolerance=1000 \noindent I turn, ... hand.} \centerline{\hbox to \wd1{\box0\hss}} \endtt Satisfactory results are obtained with font |cmr10| when |\x| is set to $8.9\pt$, $13.4\pt$, $18.1\pt$, $22.6\pt$, $32.6\pt$, and $47.2\pt$, yielding triangles that are respectively 11,~9, 8, 7, 6, and~5 lines tall. \ansno14.19: |\item{}| at the beginning of each paragraph that wants hanging indentation. \ansno14.20: |\item{$\bullet$}| \ansno14.21: Either change |\hsize| or |\rightskip|. The trick is to change it back again at the end of a paragraph. Here's one way, without grouping: \begintt \let\endgraf=\par \edef\restorehsize{\hsize=\the\hsize} \def\par{\endgraf \restorehsize \let\par=\endgraf} \advance\hsize by-\parindent \endtt \ansno14.22: |\dimen0=\hsize \advance\dimen0 by 2em|\parbreak |\parshape=3 0pt\hsize 0pt\hsize -2em\dimen0| \ansno14.23: The three paragraphs can be combined into a single paragraph, if you use `|\hfil\vadjust{\vskip\parskip}\break\indent|' instead of `|\par|' after the first two. Then of course you say, e.g., |\hangindent=-50pt \hangafter=-15|. \ (The same idea can be applied in connection with |\looseness|, if you want \TeX\ to make one of three paragraphs looser but if you don't want to choose which one it will be. However, long paragraphs fill \TeX's memory; please use restraint.) \ See also the next exercise. \ansno14.24: Use |\hangcarryover| between paragraphs, defined as follows: \begintt \def\hangcarryover{\edef\next{\hangafter=\the\hangafter \hangindent=\the\hangindent} \par\next \edef\next{\prevgraf=\the\prevgraf} \indent\next} \endtt \ansno14.25: It will set the current paragraph in the minimum number of lines that can be achieved without violating the tolerance; and, given that number of lines, it will break them optimally. \ (However, nonzero looseness makes \TeX\ work harder, so this is not recommended if you don't want to pay for the extra computation. You can achieve almost the same result much more efficiently by setting ^|\linepenalty||=100|, say.) \ansno14.26: 150, 100, 0, 250. \ (When the total penalty is zero, as between lines 3 and~4 in this case, no penalty is actually inserted.) \ansno14.27: |\interlinepenalty| plus |\clubpenalty| plus |\widowpenalty| (and also plus |\brokenpenalty|, if the first line ends with a discretionary break). \ansno14.28: The tricky part is to avoid ``opening up'' the paragraph by adding anything to its height; yet this star is to be contributed after a line having an unknown depth, because the depth of the line depends on details of line breaking that aren't known until afterwards. The following solution uses ^|\strut|, and assumes that the line containing the marginal star does not have depth exceeding ^|\dp||\strutbox|, the depth of a ^|\strut|. \begintt \def\strutdepth{\dp\strutbox} \def\marginalstar{\strut\vadjust{\kern-\strutdepth\specialstar}} \endtt Here |\specialstar| is a box of height zero and depth |\strutdepth|, and it puts an asterisk in the left margin: \begintt \def\specialstar{\vtop to \strutdepth{ \baselineskip\strutdepth \vss\llap{* }\null}} \endtt \ansno14.29: |\def\insertbullets{\everypar={\llap{$\bullet$\enspace}}}|\par \nobreak\smallskip\noindent (A similar device can be used to insert hanging indentation, and/or to number the paragraphs automatically.) \ansno14.30: First comes |\parskip| glue (but you might not see it on the current page if you say |\showlists|, since glue disappears at the top of each page). Then comes the result of\/ |\everypar|, but let's assume that |\everypar| doesn't add anything to the horizontal list, so that you get an empty horizontal list; then there's no partial paragraph before the display. The displayed equation follows the normal rules (it occupies lines 1--3 of the paragraph, and uses the indentation and length of line~2, if there's a nonstandard shape). Nothing follows the display, since a blank space is ignored after a closing `|$$|'.\par Incidentally, the behavior is different if you start a paragraph with `|$$|' instead of with |\noindent$$|, ^^{display at beginning of paragraph} since \TeX\ inserts a paragraph indentation that will appear on a line by itself (with |\leftskip| and |\parfillskip| and |\rightskip| glue). \ansno14.31: A break at |\penalty50| would cancel |\hskip2em\nobreak\hfil|, so the next line would be forced to start with the reviewer's name flush left. \ (But ^|\vadjust||{}| would actually be better than |\hbox{}|; it uses \TeX\ more efficiently.) \ansno14.32: Otherwise the line-breaking algorithm might prefer two final lines to one final line, simply in order to move a hyphen from the second-last line up to the third-last line where it doesn't cause demerits. This in fact caused some surprises when the |\signed| macro was being tested; |\tracingparagraphs=1| was used to diagnose the problem. \ansno14.33: Distributing the extra space evenly would lead to three lines of the maximum badness (10000). It's better to have just one bad line instead of three, since \TeX\ doesn't distinguish degrees of badness when lines are really awful. In this particular case the ^|\tolerance| was 200, so \TeX\ didn't try any line breaks that would stretch the first two lines; but even if the tolerance had been raised to 10000, the optimum setting would have had only one underfull line. If you really want to spread the space evenly you can do so by using ^|\spaceskip| to increase the amount of stretchability between words. \ansno14.34: |\def\raggedcenter{\leftskip=0pt plus4em \rightskip=\leftskip|% \parbreak|\parfillskip=0pt \spaceskip=.3333em \xspaceskip=.5em|\parbreak |\pretolerance=9999 \tolerance=9999 \parindent=0pt|\parbreak |\hyphenpenalty=9999 \exhyphenpenalty=9999 }| \ansno15.1: The last three page-break calculations would have been \begintt % t=503.0 plus 8.0 minus 4.0 g=528.0 b=3049 p=150 c=3199# % t=514.0 plus 8.0 minus 4.0 g=528.0 b=533 p=-100 c=433# % t=542.0 plus 11.0 minus 6.0 g=528.0 b=* p=0 c=* \endtt so the break would have occurred at the same place. The badness would have been~533, but the page would still have looked tolerable. \ (On the other hand if that paragraph had been two lines shorter instead of one, the first two lines of the next ``dangerous bend'' paragraph would have appeared on that page; the natural height $t=531\pt$ would have been able to shrink to $g=528\pt$ because the three ``medskips'' on the page would have had a total shrinkability of $6\pt$. This would certainly have been preferable to a stretched-out page whose badness was~3049; but the author might have seen it and written another sentence or two, so that the paragraph would not have been broken up. After all, this manual is supposed to be an example of good practice.) \ansno15.2: The next legal break after the beginning of a dangerous bend paragraph occurs $28\pt$ later, because there is $6\pt$ additional space for a |\medskip|, followed by two lines of $11\pt$ each. \TeX\ does not allow breaking between those two lines; the ^|\clubpenalty| is set briefly to 10000 in Appendix~E\null, since the dangerous bend symbol is two lines tall. \ansno15.3: A page always contains at least one box, if there are no insertions, since the legal breakpoints are discarded otherwise. Statement~(a) fails if the height of the topmost box exceeds $10\pt$. Statement~(b) fails if the depth of the bottommost box exceeds $2.2\pt$, or if some glue or kern comes between the bottommost box and the page break (unless that glue or kern exactly cancels the depth of the box). \ansno15.4: |\topinsert\vskip2in\rightline{\vbox{\hsize|\stretch|...|\stretch |artwork.}}\endinsert| does the job. But it's slightly more efficient to avoid ^|\rightline| by changing ^|\leftskip| as follows: `|\leftskip=\hsize \advance\leftskip by-3in|'. Then \TeX\ doesn't have to read the text of the caption twice. \ansno15.5: It would appear on page~25, since it does fit there. A |\midinsert| will jump ahead of other insertions only if it is not carried over to another page; for example, if the second 3-inch insertion were a |\midinsert|, it would not appear on page~26, because it is converted to a |\topinsert| as soon as the |\midinsert| macro notices that the insertion is too big for page~25. \ansno15.6: Set |\count1| to 50, then |\dimen2| to~$50\pt$, then |\count1| to~6, then |\skip2| to~$-10\pt$ plus~$6\,{\rm fil}$ minus~$50\pt$, then |\skip2| to~$60\pt$ plus~$-36\,{\rm fil}$ minus~$-300\pt$, then |\skip2| to~$1\,{\rm sp}$ minus~$-6\,{\rm sp}$, then |\count6| to~1, then |\skip1| to~$25\pt$ plus~$1\,{\rm sp}$ minus~$1\,{\rm fill}$, then |\skip2| to~$25\pt$ minus~$-150\pt$, then |\skip1| to~$0\pt$ plus~$1\,{\rm sp}$ minus~$1\,{\rm fill}$. \ansno15.7: If\/ |\skip4| has infinite stretchability, |\skip5| will be zero; otherwise it will be $0\pt$ plus~$1\pt$. \ansno15.8: |\advance\dimen2 by0.5\dimen3 \divide\dimen2 by\dimen3|\parbreak |\multiply\dimen2 by\dimen3| \ansno15.9: |\count1| takes the values 5, then~2 (the old 5 is saved), then~4 (which is made global), then~8 (and 4~is saved); finally the value~4 is restored, and that is the answer. \ (For further remarks, see the discussion of\/ |\tracingrestores| in Chapter~27.) \ansno15.10: |\hbox{\hbox{A}A}|. After `|\unhbox5|', |\box5| is void; |\unhcopy5| yields nothing. \ansno15.11: |\hbox{A}|. But after `|{\global\setbox3=\hbox{A}\setbox3=\box3}|', |\box3| will be void. \ansno15.12: |\newcount\notenumber|\parbreak |\def\clearnotenumber{\notenumber=0\relax}|\parbreak |\def\note{\advance\notenumber by 1|\parbreak | \footnote{$^{\the\notenumber}$}}| \ansno15.13: Yes, in severe circumstances. (1)~If there is no other legal breakpoint, \TeX\ will take a break whose cost is~$\infty$. (2)~If |\vadjust{\eject}| occurs on the same line as a footnote, before that footnote, the reference will be forcibly detached. (3)~Other |\vadjust| commands on that line could also interpose breakpoints before the insertion. \ansno16.1: |$\gamma+\nu\in\Gamma$|. \ansno16.2: ^|\le|, ^|\ge|, and ^|\ne|. \ (These are short for ``less-or-equal,'' ``greater-or-equal,'' and ``not-equal.'') \ You can also use the names ^|\leq|, ^|\geq|, and ^|\neq|. \ (The fourth most common symbol is, perhaps, `$\infty$', which stands for ``^{infinity}'' and is called `^|\infty|'.) \ansno16.3: In the former, the `|_2|' applies to the plus sign ($x + _2F_3$); but in the latter, it applies to an empty subformula ($x + {}_2F_3$). \ansno16.4: The results are `${x^y}^z$' and `$x^{y^z}$'; the $z$ in the first alternative is the same size as the $y$, but in the second it is smaller. Furthermore, the $y$ and $z$ in the first case aren't quite at the same height. \ (Good typists never even think of the first construction, because mathematicians never want it.) \ansno16.5: The second alternative doesn't work properly when there's a subscript at the same time as a prime. Furthermore, some mathematicians use |\prime| also in the subscript position; they write, for example, $F'(w,z)=\partial F(w,z)/\partial z$ and $F_\prime(w,z)=\partial F(w,z)/ \partial w$. \ansno16.6: |$R_i{}^{jk}{}_l$|. \ansno16.7: |10^{10}|; \stretch|2^{n+1}|; \stretch|(n+1)^2|; \stretch|\sqrt{1-x^2}|; \stretch|\overline{w+\overline z}|; \stretch|p_1^{e_1}|; \stretch |a_{b_{c_{d_e}}}|; \stretch|\root3\of{h''_n(\alpha x)}|. \ (Of course, you should enclose these formulas in dollar signs so that \TeX\ will process them in math mode. Superscripts and subscripts can be given in either order; for example, |h''_n| and |h_n''| both work the same. You should not leave out any of the braces shown here; for example, `|$10^10$|' would yield `$10^10$'. But it doesn't hurt to insert additional braces around letters or numbers, as in `|({n}+{1})^{2}|'. The indicated blank spaces are necessary unless you use extra braces; otherwise \TeX\ will complain about undefined control sequences |\overlinez| and |\alphax|.) \ansno16.8: He got `If$ x = y\ldots$' because he forgot to leave a space after `|If|'; ^{spaces} disappear between dollar signs. He should also have ended the sentence with `|$y$.|'; punctuation that belongs to a sentence should not be included in a formula, as we will see in Chapter~18. \ (But you aren't expected to know that yet.) \ansno16.9: |Deleting an element from an $n$-tuple leaves an $(n-1)$-tuple.| \ansno16.10: $Q,f,g,j,p,q,y$. \ (The analogous ^{Greek} letters are ^^{italic letters with descenders} ^^{descenders} $\beta,\gamma,\zeta,\eta,\mu,\xi,\rho,\phi,\varphi,\chi,\psi$.) \ansno16.11: |$z^{*2}$| and |$h_*'(z)$|. \ansno16.12: |$3{\cdot}1416$|. \ (One of the earlier examples in this chapter showed that ^|\cdot| is a binary operation; putting it in braces makes it act like an ordinary symbol.)\par If you have lots of constants like this, for example in a table, there's a way to make ordinary periods act like |\cdot| symbols: Just define ^|\mathcode||`.| to be |"0201|, assuming that the fonts of plain \TeX\ are being used. However, this could be dangerous, since ordinary periods are used frequently in displayed equations; the |\mathcode| change should be confined to places where every period is to be a |\cdot|. \ansno16.13: |$e^{-x^2}$|, |$D\sim p^\alpha M+l$|, and |$\ghat\in(H^{\pi_1^{-1}})'$|. \ (If you are reading the dangerous bend sections, you know that the recommended way to define |\ghat| is `|\def\ghat{{\hat g}}|'.) \ansno17.1: $x+y^{2/(k+1)}$\quad(|$x+y^{2/(k+1)}$|). \ansno17.2: $((a+1)/(b+1))x$\quad(|$((a+1)/(b+1))x$|). \ansno17.3: He got the displayed formula$$x=(y^2\over k+1)$$ because he forgot that an unconfined |\over| applies to everything. \ (He should probably have typed `|$$x=\left(y^2\over k+1\right)$$|', using ideas that will be presented later in this chapter; this not only makes the parentheses larger, it keeps the `$x=$' out of the fraction, because |\left| and |\right| introduce subformulas.) \ansno17.4: `|$7{1\over2}\cents$|' or `|7$1\over2$\cents|'. \ (Incidentally, the definition used here was |\def\cents{\hbox{\rm\rlap/c}}|.) ^^|\rlap|^^|\cents| \ansno17.5: Style $D'$ is used for the subformula $p_2^{e'}$, hence style~$S'$ is used for the superscript~$e'$ and the subscript~2, and style~$\SS'$ is used for the supersuperscript prime. The square root sign and the $p$ appear in text size; the 2 and the~$e$ appear in script size; and the $\prime$ is in scriptscript size. \ansno17.6: |$${1\over2}{n\choose k}$$|; |$$\displaystyle{n\choose k}\over2$$|. All of these braces are necessary. \ansno17.7: |$${p \choose 2} x^2 y^{p-2} - {1 \over 1-x}{1 \over 1-x^2}.$$| \ansno17.8: |$$\sum_{i=1}^p\sum_{j=1}^q\sum_{k=1}^ra_{ij}b_{jk}c_{ki}$$|. \ansno17.9: |$$\sum_{{\scriptstyle 1\le i\le p \atop \scriptstyle 1\le j\le q} \atop \scriptstyle 1\le k\le r} a_{ij} b_{jk} c_{ki}$$|. \ansno17.10: |$\displaystyle\biggl({\partial^2\over\partial x^2}+|\hfil\break |{\partial^2\over\partial y^2}\biggr)\bigl|\||\varphi(x+iy)\bigr|\||^2=0$|. \ansno17.11: Formulas that are more than one line tall are usually two lines tall, not 1$1\over2$ or 2$1\over2$ lines tall. \ansno17.12: |$\bigl(x+f(x)\bigr) \big/ \bigl(x-f(x)\bigr)$|. \ Notice especially the `|\big/|'; an ordinary ^{slash} would look too small between the |\big| parentheses. \ansno17.13: |$$\pi(n)=\sum_{k=2}^n\left\lfloor\phi(k)\over k-1\right\rfloor.$$| \ansno17.14: |$$\pi(n)=\sum_{m=2}^n\left\lfloor\biggl(\sum_{k=1}^{m-1}\bigl| \hfil\break |\lfloor(m/k)\big/\lceil m/k\rceil\bigr\rfloor\biggr)^{-1}\right\rfloor.$$| \ansno17.15: A displayed formula equivalent to |$${D}{{T}\over{T}^{{S}^{SS}}}$$|. \ansno17.16: |\def\sqr#1#2{{\vcenter{\vbox{\hrule height.#2pt|\parbreak | \hbox{\vrule width.#2pt height#1pt \kern#1pt|\parbreak | \vrule width.#2pt}|\parbreak | \hrule height.#2pt}}}}|\parbreak |\def\square{\mathchoice\sqr34\sqr34\sqr{2.1}3\sqr{1.5}3}| \ansno17.17: |\def\euler{\atopwithdelims<>}|. \ansno17.18: The |\textfont0| that was current at the beginning of the formula will be used, because this redefinition is local to the braces. \ (It would be a different story if `^|\global||\textfont|' had appeared instead; that would have changed the meaning of\/ |\textfont0| at all levels.) \ansno17.19: |"2208| and |"220F|. \ansno17.20: |\mathchardef\alpha="710B|. Incidentally, |{\rm\alpha}| will then give a spurious result, because character position \hex{0B} of roman fonts does not contain an alpha; you should warn your users about what characters they are allowed to type under the influence of special conventions like ^|\rm|. \ansno17.21: If\/ |\delcode`{| were set to some nonnegative delimiter code, you would get no error message when you wrote something like `|\left{|'. This would be bad because strange effects would happen when certain subformulas were given as arguments to macros, or when they appeared in alignments. But it has an even worse defect, because a user who gets away with `|\left{|' is likely to try also `|\bigl{|', which fails miserably. \ansno17.22: Since |\bigl| is defined as a macro with one parameter, it gets just `|\delimiter|' as the argument. You have to write `|\bigl{\delimiter"426830A}|' to make this work. On the other hand, |\left| will balk if the following character is a left brace. Therefore it's best to have control sequence names for all delimiters. \ansno18.1: |$R(n,t)=O(t^{n/2})$, as $t\to0^+$.| \ (N.B.: `|O(|', not `|0('|.) \ansno18.2: |$$p_1(n)=\lim_{m\to\infty}\sum_{\nu=0}^\infty|\parbreak | \bigl(1-\cos^{2m}(\nu!^n\pi/n)\bigr).$$|\par \smallskip\noindent $\bigl[$Mathematicians may enjoy interpreting this formula; cf.~G.~H. ^{Hardy}, {\sl Messenger of Mathematics\/ \bf35} (1906), 145--146.$\bigr]$ \ansno18.3: |\def\limsup{\mathop{\overline{\rm lim}}}|\parbreak |\def\liminf{\mathop{\underline{\rm lim}}}|\par \smallskip\noindent [Notice that the limits `$n\to\infty$' appear at different levels, in both of the displays, because `sup' and the underbar descend below the baseline. It is possible to unify the limit positions by using ^{phantoms}, as explained later in this chapter. For example, \begintt \def\limsup{\mathop{\vphantom{\underline{}}\overline{\rm lim}}} \endtt would give lower limits in the same position as |\liminf|.] \ansno18.4: $x\equiv0(\pmod y^n)$. He should have typed `|$x\equiv0\pmod{y^n}$|'. \ansno18.5: |$${n\choose k}\equiv{\lfloor n/p\rfloor\choose|\parbreak | \lfloor k/p\rfloor}{n\bmod p\choose k\bmod p}\pmod p.$$| \ansno18.6: |$\bf\bar x^{\rm T}Mx={\rm0}\iff x=0$|. \ (If you typed a space between |\rm| and~|0|, you wasted a keystroke; but don't feel guilty about it.) \ansno18.7: |$S\subseteq{\mit\Sigma}\iff S\in{\cal S}$|. In this case the braces are redundant and could be eliminated; but you shouldn't try to do {\sl everything\/} with fewest keystrokes, or you'll outsmart yourself some day. \ansno18.8: |$${\it available}+\sum_{i=1}^n\max\bigl({\it full}(i),|\parbreak |{\it reserved}(i)\bigr)={\it capacity}.$$| \smallskip\noindent [If\/ |\it| had been used throughout the formula, the subscript~$i$ and superscript~$n$ would have caused error messages saying `^|\scriptfont| |4| |is| |undefined|', since plain \TeX\ makes |\it| available only in text size.] \ansno18.9: |{\obeylines \sfcode`;=3000|^^|\sfcode|\parbreak |{\bf for $j:=2$ step $1$ until $n$ do}|\parbreak |\quad {\bf begin} ${\it accum}:=A[j]$; $k:=j-1$; $A[0]:=\it accum$;|\parbreak |\quad {\bf while $A[k]>\it accum$ do}|\parbreak |\qquad {\bf begin} $A[k+1]:=A[k]$; $k:=k-1$;|\parbreak |\qquad {\bf end};|\parbreak |\quad $A[k+1]:=\it accum$;|\parbreak |\quad {\bf end}.\par}|\par \smallskip\noindent [This is something like the ``poetry'' example in Chapter~14, but much more difficult. Some manuals of style say that ^{punctuation} should inherit the font of the preceding character, so that three kinds of semicolons should be typeset; e.g., these experts recommend `$k:=j-1$; \ $A[0]:={}${\it accum;} \ {\bf end;}'. The author heartily disagrees.] \ansno18.10: |Let $H$~be a Hilbert space, \ $C$~a closed bounded convex subset of~$H$, \ $T$~a nonexpansive self map of~$C$. Suppose that as $n\to\infty$, \ $a_{n,k}\to0$ for each~$k$, and $\gamma_n=\sum_{k=0}^\infty(a_{n,k+1}-|\allowbreak|a_{n,k})^+\to0$. Then for each $x$~in~$C$, \ $A_nx=\sum_{k=0}^\infty a_{n,k}T^kx$ converges weakly to a fixed point of~$T$.|\par [If any mathematicians are reading this, they might either appreciate or resent the following attempt to edit the given paragraph into a more acceptable style: ``% Let $C$~be a closed, bounded, convex subset of a Hilbert space~$H$, and let $T$~be a nonexpansive self map of~$C$. Suppose that as $n\to\infty$, we have $a_{n,k}\to0$ for each~$k$, and $\gamma_n=\sum_{k=0}^\infty(a_{n,k+1}-a_{n,k})^+\to0$. Then for each $x$~in~$C$, the infinite sum $A_nx=\sum_{k=0}^\infty a_{n,k}T^kx$ converges weakly to a fixed point of~$T$.''] \ansno18.11: |$$\int_0^\infty{t-ib\over t^2+b^2}e^{iat}\,dt=|\parbreak | e^{ab}E_1(ab),\qquad a,b>0.$$| \ansno18.12: |$$\hbar=1.0545\times10^{-27}\rm\,erg\,sec.$$| \ansno18.13: There are ten atoms (the first is $f$ and last is $y^2$); their types, and the interatomic spacing, are respectively \begindisplay \def\0{\thinspace}% \def\1{\thinspace{\tt\bslash,}\thinspace}% \def\2{\thinspace{\tt\bslash>}\thinspace}% \def\3{\thinspace{\tt\bslash;}\thinspace} Ord\0Open\0Ord\0Punct\1Ord\0Close\3Rel\3Ord\2Bin\2Ord. \enddisplay \ansno18.14: |$\left]-\infty,T\right[\times\left]-\infty,T\right[$|. \ (Or one could say ^|\mathopen| and ^|\mathclose| instead of\/ |\left| and |\right|; then \TeX\ would not choose the size of the delimiters, nor would it consider the subformulas to be of type Inner.) \ % that formula was quoted from MR review of paper by Mario Marino % in Ricerche Mat. 24 (1975), no.~1, 152--171 Open intervals are more clearly expressed in print by using parentheses instead of reversed brackets; for example, compare `$(-\infty,T)\times(-\infty,T)$' to the given formula. \ansno18.15: The first |+| will become a Bin atom, the second an Ord; hence the result is $x$, medium space, $+$, medium space, $+$, no space, 1. \ansno18.16: |$x_1+x_1x_2+\cdots+x_1x_2\ldots x_n$| \ and\hfil\break |$(x_1,\ldots,x_n)\cdot(y_1,\ldots,y_n)=x_1y_1+\cdots+x_ny_n$|. \ansno18.17: The commas belong to the sentence, not to the formula; his decision to put them into math mode meant that \TeX\ didn't put large enough spaces after them. Also, his formula `$i=1, 2, \ldots, n$' allows no breaks between lines, except after the $=$, so he's risking overfull box problems. But suppose the sentence had been more terse: \begindisplay Clearly $a_i1}f(t)\,d\pi(t).$$| \ansno18.41: |$$\{\underbrace{\overbrace{\mathstrut a,\ldots,a}|\parbreak | ^{k\;a\mathchar`'\rm s},|\parbreak | \overbrace{\mathstrut b,\ldots,b}|\parbreak | ^{l\;b\mathchar`'\rm s}}_{k+l\rm\;elements}\}.$$|\par \smallskip\noindent Notice how ^{apostrophes} (instead of primes) were obtained. \ansno18.42: |$$\pmatrix{\pmatrix{a&b\cr c&d\cr}&|\parbreak | \pmatrix{e&f\cr g&h\cr}\cr|\parbreak | \noalign{\smallskip}|\parbreak | 0&\pmatrix{i&j\cr k&l\cr}\cr}.$$| \ansno18.43: |$$\det\left|\||\,\matrix{|\parbreak | c_0&c_1\hfill&c_2\hfill&\ldots&c_n\hfill\cr|\parbreak | c_1&c_2\hfill&c_3\hfill&\ldots&c_{n+1}\hfill\cr|\parbreak | c_2&c_3\hfill&c_4\hfill&\ldots&c_{n+2}\hfill\cr|\parbreak | \,\vdots\hfill&\,\vdots\hfill&|\parbreak | \,\vdots\hfill&&\,\vdots\hfill\cr|\parbreak | c_n&c_{n+1}\hfill&c_{n+2}\hfill&\ldots&c_{2n}\hfill\cr|\parbreak | }\right|\||>0.$$| \ansno18.44: |$$\mathop{{\sum}'}_{x\in A}f(x)\mathrel{\mathop=^{\rm def}}|\parbreak | \sum_{\scriptstyle x\in A\atop\scriptstyle x\ne0}f(x).$$|\par \smallskip\noindent This works because |{\sum}| is type Ord (so its superscript is not set above), but ^|\mathop||{{\sum}'}| is type Op (so its subscript is set below). The limits are centered on $\sum'$, however, not on $\sum$. If you don't like that, the remedy is more difficult; one solution is to use |\sumprime_{x\in A}| where ^|\sumprime| is defined as follows: \par\nobreak\medskip |\def\sumprime_#1{\setbox0=\hbox{$\scriptstyle{#1}$}|\parbreak | \setbox2=\hbox{$\displaystyle{\sum}$}|\parbreak | \setbox4=\hbox{${}'\mathsurround=0pt$}|\parbreak | \dimen0=.5\wd0 \advance\dimen0 by-.5\wd2|\parbreak | \ifdim\dimen0>0pt|\parbreak | \ifdim\dimen0>\wd4 \kern\wd4 \else\kern\dimen0\fi\fi|\parbreak | \mathop{{\sum}'}_{\kern-\wd4 #1}}| \ansno18.45: |$$2\uparrow\uparrow k\mathrel{\mathop=^{\rm def}}|\parbreak | 2^{2^{2^{\cdot^{\cdot^{\cdot^2}}}}}|\parbreak | \vbox{\hbox{$\Big\}\scriptstyle k$}\kern0pt}.$$|\par \ansno18.46: If you have to do a lot of commutative diagrams, you will want to define some macros like those in the first few lines of this solution. The ^|\matrix| macro resets the baselines to ^|\normalbaselines|, because other commands like |\openup| might have changed them, so we redefine |\normalbaselines| in this solution. Some of the things shown here haven't been explained yet, but Chapter~22 will reveal all. \smallskip |$$\def\normalbaselines{\baselineskip20pt|\parbreak | \lineskip3pt \lineskiplimit3pt }|\parbreak |\def\mapright#1{\smash{|\parbreak | \mathop{\longrightarrow}\limits^{#1}}}|\parbreak |\def\mapdown#1{\Big\downarrow|\parbreak | \rlap{$\vcenter{\hbox{$\scriptstyle#1$}}$}}|\parbreak |\matrix{&&&&&&0\cr|\parbreak | &&&&&&\mapdown{}\cr|\parbreak | 0&\mapright{}&{\cal O}_C&\mapright\iota&|\parbreak | \cal E&\mapright\rho&\cal L&\mapright{}&0\cr|\parbreak | &&\Big\Vert&&\mapdown\phi&&\mapdown\psi\cr|\parbreak | 0&\mapright{}&{\cal O}_C&\mapright{}&|\parbreak | \pi_*{\cal O}_D&\mapright\delta&|\parbreak | R^1f_*{\cal O}_V(-D)&\mapright{}&0\cr|\parbreak | &&&&&&\mapdown{\theta_i\otimes\gamma^{-1}}\cr|\parbreak | &&&&&&\hidewidth R^1f_*\bigl({\cal O}|\parbreak | _V(-iM)\bigr)\otimes\gamma^{-1}|^|\hidewidth||\cr|\parbreak | &&&&&&\mapdown{}\cr|\parbreak | &&&&&&0\cr}$$| \ansno19.1: |$$\sum_{n=0}^\infty a_nz^n\qquad\hbox{converges if}\qquad|\parbreak | |\||z|\||<\Bigl(\limsup_{n\to\infty}\root n\!\of{|\||a_n|\|^^|\root| |}\,\Bigr)^{-1}.$$|\kern-.33pt\par \smallskip |$${f(x+\Delta x)-f(x)\over\Delta x}\to f'(x)|\parbreak | \qquad\hbox{as $\Delta x\to0$.}$$|\par \smallskip |$$\|\||u_i\|\||=1,\qquad u_i\cdot u_j=0\quad\hbox{if $i\ne j$.}$$|\par \smallskip |$$\it\hbox{The confluent image of}\quad\left\{|\parbreak | \matrix{\hbox{an arc}\hfill\cr\hbox{a circle}\hfill\cr|\parbreak | \hbox{a fan}\hfill\cr}|\parbreak | \right\}\quad\hbox{is}\quad\left\{|\parbreak | \matrix{\hbox{an arc}\hfill\cr|\parbreak | \hbox{an arc or a circle}\hfill\cr|\parbreak | \hbox{a fan or an arc}\hfill\cr}\right\}.$$|\par \smallskip\noindent The first example includes |\!| and |\,| to give slightly refined spacing; but the point of the problem was to illustrate the hbox, not to fuss over such extra details. The last example can be done much more simply using the ideas of Chapter~22, if you don't mind descending to the level of \TeX\ primitives; for example, the first matrix could be replaced by ^^|\halign| \begintt \,\vcenter{\halign{#\hfil\cr an arc\cr a circle\cr a fan\cr}}\, \endtt and the second is similar. \ansno19.2: |$$\textstyle y={1\over2}x$$|. \ (Switching to text style is especially common in multiline formulas. For example, you will probably find occasions to use ^|\textstyle| on both sides of the |&|'s within an ^|\eqalign|.) \ansno19.3: The latter formula will be in text style, not display style. And even if you do type `|$$\hbox{$\displaystyle{|\|}$}$$|', the results are not quite the same, as we will see later: \TeX\ will compress the glue in `|$$|\|$$|' if the formula is too wide to fit on a line at its natural width, but the glue inside |\hbox{...}| is frozen at its natural width. The |\hbox| version also invokes |\everymath|. \ansno19.4: One solution is to put the formula in an hbox that occupies a full line: \begintt $$\leftline{\indent$\displaystyle 1-{1\over2}+{1\over3}-{1\over4}+\cdots=\ln2$}$$ \endtt But this takes a bit of typing. If you make the definitions \begintt \def\leftdisplay#1$${\leftline{\indent$\displaystyle{#1}$}$$} \everydisplay{\leftdisplay} \endtt you can type `|$$|\|$$|' as usual, and the formatting will be inserted automatically. \ (This doesn't work with equation numbers; Appendix~D illustrates how to handle them as well.) \ansno19.5: |$$\prod_{k\ge0}{1\over(1-q^kz)}=|\parbreak | \sum_{n\ge0}z^n\bigg/\!\!\prod_{1\le k\le n}(1-q^k).\eqno(16')$$| \ansno19.6: |\eqno\hbox{(3--1)}|. \ansno19.7: When you type an ^{asterisk} in math mode, plain \TeX\ considers |*| to be a binary operation. In the cases `|(*)|' and `|(**)|', the binary operations are converted to type~Ord, because they don't appear in a binary context; but the middle asterisk in `|(***)|' remains of type~Bin. So the result was `$(***)$'. To avoid the extra medium spaces, you can type `|\eqno(*{*}*)|'; or you can change ^|\mathcode||`*|, if you never use |*| as a binary operation. \ansno19.8: Assuming that |\hsize| is less than $10000\pt$, the natural width of this equation will be too large to fit on a line; also, |\quad| specifies glue at the left. Therefore `$x=y$' will appear exactly $1\em$ from the left, and `(5)' will appear flush right. \ (The widths will satisfy ^^{displays, non-centered} $w=z-q$, $d=0$, $k=q-e=18\rm\,mu$.) \ In the case of\/ |\leqno|, `(5)' will appear flush left, followed by one quad of space in |\textfont2|, followed by one quad of space in the current text font, followed by `$x=y$'. \ansno19.9: (Note in particular that the final `|.|'\ comes {\sl before\/} the final `|\cr|'.) \begintt $$\eqalign{T(n)\le T(2^{\lceil\lg n\rceil}) &\le c(3^{\lceil\lg n\rceil}-2^{\lceil\lg n\rceil})\cr &<3c\cdot3^{\lg n}\cr &=3c\,n^{\lg3}.\cr}$$ \endtt \ansno19.10: |$$\eqalign{P(x)&=a_0+a_1x+a_2x^2+\cdots+a_nx^n,\cr|\parbreak | P(-x)&=a_0-a_1x+a_2x^2-\cdots+(-1)^na_nx^n.\cr}\eqno(30)$$|\par \ansno19.11: Both sides of that equation are considered to be on the left, so you get results that look like this: $$\openup-\jot \left\{\eqalign{\alpha&=f(z)\cr \beta&=f(z^2)\cr \gamma=f(z^3)\cr} \right\}.$$ \ansno19.12: |$$\leqalignno{\gcd(u,v)&=\gcd(v,u);&(9)\cr|\parbreak | \gcd(u,v)&=\gcd(-u,v).&(10)\cr}$$| \ansno19.13: % |$$\eqalignno{\biggl(\int_{-\infty}^\infty e^{-x^2}\,dx\biggr)^2|\parbreak | &=\int_{-\infty}^\infty\int_{-\infty}^\infty|\parbreak | e^{-(x^2+y^2)}\,dx\,dy\cr|\parbreak | &=\int_0^{2\pi}\int_0^\infty e^{-r^2}r\,dr\,d\theta\cr|\parbreak | &=\int_0^{2\pi}\biggl(-{e^{-r^2}\over2}|\parbreak | \bigg|\||_{r=0}^{r=\infty}\,\biggr)\,d\theta\cr|\parbreak | &=\pi.&(11)\cr}$$| ^^|\bigg| \ansno19.14: You get the displayed box $$\eqalign{x&=y+z\cr \noalign{\hbox{and}} x^2&=y^2+z^2.\cr}$$ Reason: The `and' occurs at the left of the |\eqalign| box, not at the left of the whole display, and the |\eqalign| box is centered as usual. \ansno19.15: By raising the equation number, he increased the line height, so \TeX\ put extra space between that line and the previous line when it calculated the inter-line glue. If he had said `^|\smash||{\raise...}|', he wouldn't have had that problem. \ansno19.16: |$$\displaylines{\hfill x\equiv x;\hfill\llap{(1)}\cr|\parbreak | \hfill\hbox{if}\quad x\equiv y\quad\hbox{then}\quad|\parbreak | y\equiv x;\hfill\llap{(2)}\cr|\parbreak | \hfill\hbox{if}\quad x\equiv y\quad\hbox{and}\quad|\parbreak | y\equiv z\quad\hbox{then}\quad|\parbreak | x\equiv z.\hfill\llap{(3)}\cr}$$|\par\medskip\noindent There's also a trickier solution, which begins with \begintt $$\displaylines{x\equiv x;\hfil\llap{(1)}\hfilneg\cr \endtt \ansno19.17: |$$\eqalignno{x_nu_1+\cdots+x_{n+t-1}u_t|\parbreak | &=x_nu_1+(ax_n+c)u_2+\cdots\cr|\parbreak | &\qquad+\bigl(a^{t-1}x_n+c(a^{t-2}+\cdots+1)\bigr)u_t\cr|\parbreak | &=(u_1+au_2+\cdots+a^{t-1}u_t)x_n+h(u_1,\ldots,u_t).|\parbreak | \quad&(47)\cr}$$|\par\noindent You weren't expected to insert the `|\quad|' on the last line; such refinements usually can't be anticipated until you see the first proofs. But without that |\quad| the `(47)' would occur half a quad closer to the formula. \ansno19.18: |$$\displaylines{\quad\sum_{1\le j\le n}{1\over|\parbreak | (x_j-x_1)\ldots(x_j-x_{j-1})(x-x_j)(x_j-x_{j+1})|\parbreak | \ldots(x_j-x_n)}\hfill\cr|\parbreak | \hfill={1\over(x-x_1)\ldots(x-x_n)}.\quad(27)\cr}$$| \ansno19.19: |$$\def\\#1;{(#1;q^2)_\infty} % to save typing|\parbreak |\displaystyle{q^{{1\over2}n(n+1)}\\ea;\\eq/a;\qquad\atop|\parbreak | \hfill\\caq/e;\\cq^2\!/ae;}|\parbreak |\over(e;q)_\infty(cq/e;q)_\infty$$| \ansno20.1: |\def\mustnt{I must not talk in class.\par}|\parbreak |\def\five{\mustnt\mustnt\mustnt\mustnt\mustnt}|\parbreak |\def\twenty{\five\five\five\five}|\parbreak |\def\punishment{\twenty\twenty\twenty\twenty\twenty}|\par \smallskip\noindent Solutions to more complicated problems of this type are discussed later. \ansno20.2: |ABCAB|. \ (The first |\a| expands into |A\def\a{B...}|; this redefines |\a|, so the second |\a| expands into |B...|, etc.) \ At least, that's what happens if\/ |\puzzle| is encountered when \TeX\ is building a list. But if |\puzzle| is expanded in an ^|\edef| or ^|\message| or something like that, we will see later that the interior |\def| commands are not performed while the expansion is taking place, and the control sequences following |\def| are expanded; so the result is an infinite string \begintt A\def A\def A\def A\def A\def A\def A\def A\def A... \endtt which causes \TeX\ to abort because the program's input stack is finite. This example points out that a control sequence (e.g., |\b|) need not be defined when it appears in the replacement text of a definition. The example also shows that \TeX\ doesn't expand a macro until it needs to. \ansno20.3: \def\row#1{(#1_1,\ldots,#1_n)}$\row{\bf x}$. Note that the subscripts are bold here, because the expansion |(\bf x_1,\ldots,\bf x_n)| doesn't ``turn off'' ^|\bf|. To prevent this, one should write |\row{{\bf x}}|; or (better), |\row\xbold|, in conjunction with |\def\xbold{{\bf x}}|. \ansno20.4: The catch is that the parameters have to percolate down to the |\mustnt| macro, if you extend the previous answer: \begintt \def\mustnt#1#2{I must not #1 in #2.\par} \def\five#1#2{\mustnt{#1}{#2}...\mustnt{#1}{#2}} \def\twenty#1#2{\five{#1}{#2}...\five{#1}{#2}} \def\punishment#1#2{\twenty{#1}{#2}...\twenty{#1}{#2}} \endtt When you pass parameters from one macro to another in this way, you need to enclose them in braces as shown. But actually this particular solution punishes \TeX\ much more than it needs to, because it takes a lot of time to copy the parameters and read them again and again. There's a much more efficient way to do the job, by defining control sequences: \begintt \def\mustnt{I must not \doit\ in \thatplace.\par} \def\punishment#1#2{\def\doit{#1}\def\thatplace{#2}% \twenty\twenty\twenty\twenty\twenty} \endtt and by defining |\five| and |\twenty| without parameters as before. You can also delve more deeply into \TeX nicalities, constructing solutions that are more efficient yet; \TeX\ works even faster when macros communicate with each other via ^{boxes}. ^^{efficient macros} ^^{communication between macros} For example, \begintt \def\mustnt{\copy0 } \def\punishment#1#2{\setbox0= \vbox{\strut I must not #1 in #2.\strut}% \twenty\twenty\twenty\twenty\twenty} \endtt sets 100 identical paragraphs at high speed, because \TeX\ has to process the paragraph and break it into lines only once. It's much faster to ^{copy a box} than to build it up from scratch. \ (The ^{struts} in this example keep the interbaseline distances correct between boxed paragraphs, as explained in Chapter~12. Two struts are used, for if the message takes more than one line there will be a strut at both top and bottom. If it were known that each sentence will occupy only a single line, no struts would be needed, because interline glue is added as usual when a box created by |\copy| is appended to the current vertical list.) \ansno20.5: The |##| feature is indispensable when the replacement text of a definition contains other definitions. For example, consider \begintt \def\a#1{\def\b##1{##1#1}} \endtt after which `|\a!|'\ will expand to `|\def\b#1{#1!}|'. We will see later that |##| is also important for alignments; see, for example, the definition of\/ |\matrix| in Appendix~B. \ansno20.6: |\def\a#{\b}|. \ansno20.7: Let's go slowly on this one, so that the answer will give enough background to answer all similar questions. The \ of the definition consists of the three tokens |#1|, |#2|, |[|$_1$; the \ consists of the six tokens |{|$_1$, |#|$_6$, |]|$_2$, |!|$_6$, |#2|, |[|$_1$. \ (When two tokens of category~6 occur in the replacement text, the character code of the second one survives; the character code of a category-6 character is otherwise irrelevant. Thus, `|\def\!#1!2#[{##]!!#2]|' would produce an essentially identical definition.) \ When expanding the given token list, argument~|#1| is |x|$_{11}$, since it is undelimited. Argument~|#2| is delimited by~|[|$_1$, which is different from~|{|$_1$, so it is set provisionally to |{[y]]|; but the outer ``braces'' are stripped off, so |#2|~reduces to the three tokens |[|$_1$, |y|$_{11}$,~|]|$_2$. The result of the expansion is therefore \begindisplay |{|$_1$ |#|$_6$ |]|$_2$ |!|$_6$ |[|$_1$ |y|$_{11}$ |]|$_2$ |[|$_1$ |z|$_{11}$ |}|$_2$. \enddisplay Incidentally, if you display this with ^|\tracingmacros||=1|, \TeX\ says \begintt \!!1#2[->{##]!!#2[ #1<-x #2<-[y] \endtt Category codes are not shown, but a character of category~6 always appears twice in succession. A parameter token in the replacement text uses the character code of the final parameter in the parameter text. ^^{token lists, as displayed by TeX} \ansno20.8: Yes indeed. In the first case, |\a| receives the meaning of\/~|\b| that is current at the time of the |\let|. In the second case, |\a|~becomes a~macro that will expand into the token~|\b| whenever |\a|~is used, so it has the meaning of\/~|\b| that is current at the time of use. You need |\let|, if you want to interchange the meanings of\/ |\a| and~|\b|. \ansno20.9: (a) Yes. \ (b) No; any other control sequence can appear (except those declared as |\outer| macros). \ansno20.10: |\def\overpaid{{\count0=\balance|\parbreak | You have overpaid your tax by \dollaramount.|\parbreak | \ifnum\count0<100 It is our policy to refund|\parbreak | such a small amount only if you ask for it.|\parbreak | \else A check for this amount is being mailed|\parbreak | under separate cover.\fi}}| \ansno20.11: The tricky part is to get the zero in an amount like `|$2.01|'. \begintt \def\dollaramount{\count2=\count0 \divide\count2 by100 \$\number\count2.% \multiply\count2 by-100 \advance\count2 by\count0 \ifnum \count2<10 0\fi \number\count2 } \endtt \ansno20.12: |\def\category#1{\ifcase\catcode`#1|\parbreak | escape\or begingroup\or endgroup\or math\or|\parbreak | align\or endline\or parameter\or superscript\or|\parbreak | subscript\or ignored\or space\or letter\or|\parbreak | otherchar\or active\or comment\or invalid\fi}|\par \ansno20.13: (a,b)~True. (c,d)~False. (e,f)~True. In case~(e), the \ starts with `|ue|'. (g)~The |\ifx| is false and the inner |\if| is true; so the outer |\if| becomes `|\if True...|', which is false. \ (Interestingly, \TeX\ knows that the outer |\if| is false even before it has looked at the |\fi|'s that close the |\ifx| and the inner |\if|.) \ansno20.14: One idea is to say \begintt \let\save=\c \let\c=0 \edef\a{\b\c\d} \let\c=\save \endtt because control sequences equivalent to characters are not expandable. However, this doesn't expand occurrences of~|\c| that might be present in the expansions of\/ |\b| and~|\d|. Another way, which is free of this defect, is \begintt \edef\next#1#2{\def#1{\b#2\d}} \next\a\c \endtt (and it's worth a close look!). \ansno20.15: |\toks0={\c} \toks2=\expandafter{\d}|\parbreak |\edef\a{\b\the\toks0 \the\toks2 }| \smallskip\noindent (Notice that ^|\expandafter| expands the token after the left brace here.) \ansno20.16: The following shouldn't be taken too seriously, but it does work: ^^|\span| \begintt {\setbox0=\vbox{\halign{#{\c\span\d}\cr \let\next=0\edef\next#1{\gdef\next{\b#1}}\next\cr}}} \let\a=\next \endtt \ansno20.17: Neither one, although |\a| will behave like an unmatched left brace when it is expanded. The definition of\/ |\b| is {\sl not complete}, because it expands to `|\def\b{{}|'; \TeX\ will continue to read ahead, looking for another right brace, possibly discovering a runaway definition! It's impossible to define a macro that has unmatched braces. But you {\sl can\/} say |\let\a={|; Appendix~D discusses several other ^{brace tricks}. \ansno20.18: One way is to redefine |\catcode`\^^M=9| (ignored) just before the |\read|, so that the \ will be ignored. Another solution is to redefine ^|\endlinechar||=-1|, so that no character is put at the end of the line. Or you could try to be tricky by stripping off the space with macro expansion as follows: \begintt \def\stripspace#1 \next{#1} \edef\myname{\expandafter\stripspace\myname\next} \endtt The latter solution doesn't work if the user types `|%|' at the end of his~or her name, or if the name contains control sequences. \ansno20.19: Here are two solutions: \begintt \def\next#1\endname{\uppercase{\def\MYNAME{#1}}} \expandafter\next\myname\endname |smallskip\edef\next{\def\noexpand\MYNAME{\myname}} \uppercase\expandafter{\next} \endtt \ansno20.20: (Here's a solution that also numbers the lines, so that the number of repetitions is easily verifiable. The only tricky part about this answer is the use of\/ ^|\endgraf|, which is a substitute for |\par| because |\loop| is not a ^|\long| macro.) \begintt \newcount\n \def\punishment#1#2{\n=0 \loop\ifnum\n<#2 \advance\n by1 \item{\number\n.}#1\endgraf\repeat} \endtt