The Asian Journal of TEX, Volume 1, No. 1, April 2007 Article revision 2007/03/02 KTS THE KOREAN TEX SOCIETY SINCE 2007 LATEX Dissection of LATEX Macros Related to Boxes Jin-Hwan Cho chofchof@ktug.or.kr ABSTRACT Boxes and glue are the key to understand how TEX makes complicated pages from individual characters and figures. Character boxes are put together into line boxes horizontally, and the line boxes are stacked vertically into paragraph boxes which finally compose page boxes. We analyze how LATEX macro commands related to boxes are composed of TEX primitives, and how the commands function. A few examples are prepared to show characteristics of the commands, and to focus the points to which ordinary LATEX users pay attention. The paper will be useful for LATEX users not only to make better LATEX documents but also to write their own style files. 1 TEX 1. TEX. TEX.,.. TEX.,. TEX (primitive). (macro) (format). TEX Plain LATEX 2, Plain TEX LATEX. TEX, Plain TEX C, LATEX. 1. [1]. 2. LATEX 1985 Leslie Lamport LATEX Version 2.09 1994 LATEX3 LATEX2ε. Copyright 2007 by the Korean TEX Society
68 THE ASIAN JOURNAL OF TEX The Korean TEX Society 1. LATEX. LATEX,. LATEX,. 2 TEX TEX (mode). 3 (horizontal mode), (vertical mode). (math mode)... 1. TEX. TEX? (space), TEX. 4... 3. TEX.. (restricted) \hbox.. (internal). \vbox. (display). [2, Chapter 6] [3, Chapter 24, 25]. 4. 1 TEX glue dimen. dimen glue. [2, Chapter 8] [3, Chapter 12].
VOLUME 1, NO. 1, APRIL 2007 69 dimen glue. 1cm dimen, 1cm plus 0.5cm minus 0.5cm glue 1cm 0.5cm., 1.5cm 0.5cm. dimen glue. TEX glue dimen. glue TEX \hskip dimen \kern \hskip. \hskip glue dimen. dimen plus 0pt minus 0pt glue. glue \kern dimen. \vskip \hskip \kern. 3 LATEX \hbox. TEX 1 \hbox...? 5 1 The\par 2 \hbox{korean} \TeX{}\par 3 Society The Korean TEX Society 1. \hbox 1 TEX. The. \par ( ).,. \hbox Korean. \hbox. \TeX. 6 TEX \par. 5. (dangerous bend). 6. \TeX latex.ltx (1327 ) \def\tex{t\kern-.1667em\lower.5ex\hbox{e}\kern-.125em X\@}. T.
70 THE ASIAN JOURNAL OF TEX Society.. 1. 3.1 \hbox LATEX \mbox \hbox TEX \hbox.. LATEX \mbox. \mbox{ } \mbox latex.ltx. 7. 4562 \long\def\mbox#1{\leavevmode\hbox{#1}} \mbox \hbox \leavevmode. \leavevmode latex.ltx. 492 \def\leavevmode{\unhbox\voidb@x} \voidb@x, \unhbox \hbox (unload). 8 \leavevmode? \leavevmode. \hbox \unhbox [3, p. 283].,. 1 \hbox \mbox 2. 4 The\par 5 \mbox{korean} \TeX{}\par 6 Society The Korean TEX Society 2. \mbox 7. LATEX2ε (2005/12/01). latex.ltx $TEXMF/tex/latex/base/. 8. \unhbox ( \unhcopy) \box ( \copy). {\setbox0=\hbox{a b c d e f}\vbox{\hsize=1cm\copy0\unhbox0}} \copy0 \unhbox0.
VOLUME 1, NO. 1, APRIL 2007 71 return enter. \leavevmode LATEX. \leavevmode\par. TEX 9. 3.2 \hbox to \hbox spread LATEX \makebox \hbox \hbox to \hbox spread. 3. 7 \let\b\textbar 8 \B\hbox{Korean \TeX}\B\par 9 \B\hbox to 30mm{Korean \TeX}\B\par 10 \B\hbox spread 10mm{Korean \TeX}\B Korean TEX Korean Korean TEX TEX 3. \hbox to \hbox spread \mbox \hbox. LATEX \hbox \makebox. \makebox[ ][ ]{ } 4 \makebox 3. 11 \B\makebox{Korean \TeX}\B\par 12 \B\makebox[30mm][s]{Korean \TeX}\B\par 13 \B\makebox[\width+10mm][s]{Korean \TeX}\B Korean TEX Korean Korean TEX TEX 4. \makebox 10 \makebox latex.ltx. 4557 \def\makebox{% 4558 \leavevmode 4559 \@ifnextchar(%) 4560 \@makepicbox 4561 {\@ifnextchar[\@makebox\mbox}} \mbox \leavevmode. LATEX \@ifnextchar (latex.ltx 9. glue \vskip dimen \kern. LATEX \vspace \bigskip, \medskip, \smallskip. [4, p. 35] [5, p. 857]. 10. 13 calc.sty.
72 THE ASIAN JOURNAL OF TEX 796 ). \makebox ( \@makepicbox, [ \@makebox, \mbox. \makebox{#1} \mbox{#1}. \@makepicbox \vbox \@makebox. TEX. 4563 \def\@makebox[#1]{% 4564 \@ifnextchar [{\@imakebox[#1]}{\@imakebox[#1][c]}} \@makebox [c] (default) \@imakebox. 4579 \long\def\@imakebox[#1][#2]#3{% 4580 \@begin@tempboxa\hbox{#3}% 4581 \setlength\@tempdima{#1}% support calc 4582 \hb@xt@\@tempdima{\csname bm@#2\endcsname}% 4583 \@end@tempboxa} \@imakebox \@makebox. \makebox. [c l r s] [c l r],, [s]. 11 \@begin@tempboxa \hbox. \@tempboxa, (\width), (\height), (\depth), (\totalheight).. 4565 \long\def\@begin@tempboxa#1#2{% 4566 \begingroup 4567 \setbox\@tempboxa#1{\color@begingroup#2\color@endgroup}% 4568 \def\width{\wd\@tempboxa}% 4569 \def\height{\ht\@tempboxa}% 4570 \def\depth{\dp\@tempboxa}% 4571 \let\totalheight\@ovri 11. latex.ltx 4575. \@begin@tempboxa \@tempboxa. [c] \hss\unhbox\@tempboxa\hss. \hss. glue \hss [3, p. 71]. [l] \unhbox\@tempboxa\hss \hss. [r] \hss\unhbox\@tempboxa \hss. [s] \hss \@tempboxa 4582 \hb@xt@, \hbox to ( 12 ).
VOLUME 1, NO. 1, APRIL 2007 73 4572 \totalheight\height 4573 \advance\totalheight\depth} 4574 \let\@end@tempboxa\endgroup \@tempboxa \begingroup \@end@tempboxa, \endgroup \@imakebox 4581 4582. 4582 #2 [c l r s] 4581 #1. 4581 \setlength 4 13 calc.sty. 4582 \hb@xt@ \hbox to 12, \@tempboxa ( ). 3.3 \makebox. 5.. 14 \B\makebox[2\width]{Korean \TeX}\B\par 15 \B\makebox[2\width][l]{Korean \TeX}\B\par 16 \B\makebox[2\width][r]{Korean \TeX}\B\par 17 \B\makebox[2\width][s]{Korean \TeX}\B Korean TEX Korean TEX Korean TEX Korean TEX 5. \makebox 2 1 1 2 \hss [s] ( 11 ). 6. 18 \B\makebox[30mm][s]{A\hfil\hfil B\hfil C}\B\par 19 \B\makebox[30mm][s]{A\hfil B\hfil\hfil C}\B\par A B C A B C 6. \makebox 2 1 1 2 \rlap \llap 13 \makebox[0pt][l] \makebox[0pt][r]. 7 \rlap \llap 1 \makebox[0pt][l r]. \makebox[0pt][l r]. 14 \mbox \makebox \fbox \framebox.. 12. \def\hb@xt@{\hbox to} (latex.ltx 566 ) 13. \def\rlap#1{\hb@xt@\z@{#1\hss}} (latex.ltx 4847 ), \def\llap#1{\hb@xt@\z@{\hss#1}}
74 THE ASIAN JOURNAL OF TEX 20 \rlap{\b K\B}orean 21 \par 22 \llap{\b K\B}orean 23 \par 24 \makebox[0pt][l]{\b K\B}orean\par 25 \makebox[0pt][r]{\b K\B}orean\par 26 \makebox[0pt]{\b K\B}orean K orean K orean K orean K orean K orean 7. \rlap, \llap \makebox[0pt] \fbox{ } \framebox[ ][ ]{ } 8 \fboxrule (padding) \fboxsep. 15 27 \fbox{korean \TeX}\par 28 \framebox[2\width]{korean \TeX}\par 29 \setlength\fboxrule{2\fboxrule} 30 \framebox[2\width][l]{korean \TeX}\par 31 \setlength\fboxsep{2\fboxsep} 32 \framebox[2\width][r]{korean \TeX} Korean TEX Korean TEX Korean TEX Korean TEX 8. \fbox \framebox 3.4 \makebox LATEX \makebox(#1,#2)[#3]{#4} picture picture. \makebox(, )[ ]{ } (#1,#2). \width \height. 20mm 20. 20 \unitlength 16 20. [#3] [t b], [l r s].. 9 \framebox. (latex.ltx 4848 ) 14. \rlap \llap overfull.. moreverb.sty listing \llap. \rlap. \rlap{$\times$}$+$ + +. 15. 3pt 0.4pt. (latex.ltx 7757 7758 ) 16. \unitlength 1pt. (latex.ltx 5200 )
VOLUME 1, NO. 1, APRIL 2007 75 33 \setlength\unitlength{2mm} 34 \makebox(12,4.5){korean \TeX}\quad 35 \framebox(12,4.5)[s]{korean \TeX}\par 36 \makebox(12,4.5)[t]{korean \TeX}\quad 37 \framebox(12,4.5)[tl]{korean \TeX}\par 38 \makebox(12,4.5)[b]{korean \TeX}\quad 39 \framebox(12,4.5)[br]{korean \TeX} Korean TEX Korean TEX Korean TEX Korean TEX Korean TEX Korean TEX 9. picture \makebox \framebox 4 LATEX TEX \raise \lower.., \par \hbox \raise \lower. 10 \raise \lower. 40 K\raise 5pt\hbox{O}R\lower 5pt\hbox{E}A 41 \fbox{k}\fbox{\raise 5pt\hbox{O}}\fbox{R}% 42 \fbox{\lower 5pt\hbox{E}}\fbox{A} K O R E A K O R E A 10. \raise \lower LATEX \raisebox. \raisebox{ }[ ][ ]{ } \raise \hbox \raisebox \makebox \framebox... 4818 \def\raisebox#1{% 4819 \leavevmode 4820 \@ifnextchar[{\@rsbox{#1}}{\@irsbox{#1}[]}} 4821 \def\@rsbox#1[#2]{% 4822 \@ifnextchar[{\@iirsbox{#1}[#2]}{\@irsbox{#1}[#2]}} \raisebox..,... \raisebox{#1}{#2} \@irsbox{#1}[]{#2} \raisebox{#1}[#2]{#3} \@irsbox{#1}[#2]{#3} \raisebox{#1}[#2][#3]{#4} \@iirsbox{#1}[#2][#3]{#4}
76 THE ASIAN JOURNAL OF TEX \@irsbox. 4823 \long\def\@irsbox#1[#2]#3{% 4824 \@begin@tempboxa\hbox{#3}% 4825 \setlength\@tempdima{#1}% 4826 \ifx\\#2\\\else\setlength\@tempdimb{#2}\fi 4827 \setbox\@tempboxa\hbox{\raise\@tempdima\box\@tempboxa}% 4828 \ifx\\#2\\\else\ht\@tempboxa\@tempdimb\fi 4829 \box\@tempboxa 4830 \@end@tempboxa} \makebox \@begin@tempboxa #3 \@tempboxa. 4825 #1 \@tempdima, [#2] \@tempdimb. 4827 \@tempboxa \@tempdima \raise \@tempboxa. [#2] 4828 \@tempboxa \@tempboxb. 4829 \@tempboxa., #3 #1 #2. (\width, \height, \depth, \totalheight) \@begin@tempboxa \@end@tempboxa #1 #2. \@iirsbox #2 (4837 ) #3 (4838 ). 4831 \long\def\@iirsbox#1[#2][#3]#4{% 4832 \@begin@tempboxa\hbox{#4}% 4833 \setlength\@tempdima{#1}% 4834 \setlength\@tempdimb{#2}% 4835 \setlength\dimen@{#3}% 4836 \setbox\@tempboxa\hbox{\raise\@tempdima\box\@tempboxa}% 4837 \ht\@tempboxa\@tempdimb 4838 \dp\@tempboxa\dimen@ 4839 \box\@tempboxa 4840 \@end@tempboxa}? 5. 17 \raisebox 0pt. 11 \textdbend.. 0pt. 17. \textdbend 5. \textdbend manfnt.sty.
VOLUME 1, NO. 1, APRIL 2007 77 \textdbend (\totalheight). 0pt. 43 The\raisebox{.5\totalheight}[0pt]{\textdbend}Korean\par 44 The\raisebox{0pt}[0pt]{\textdbend}Korean\par 45 The\textdbend Korean\par 46 The\raisebox{-.5\totalheight}[0pt]{\textdbend}Korean\par 47 The\raisebox{-.5\totalheight}[0pt][0pt]{\textdbend}Korean The Korean The Korean The Korean The Korean The Korean 11. TEX. TEX. (absolute position) 18 ( ). TEX. 19 (relative position)? 0.5cm, 2cm \makebox \raisebox 12. 48 A% ; 49 \raisebox{5mm}[0pt][0pt]{% 50 \makebox[0pt][r]{\textdbend\hspace{2cm}}}% 51 B\par C% ; 52 \makebox[0pt][l]{\hspace{2cm}% 53 \raisebox{-1cm}[0pt][0pt]{\textdbend}}% 54 D AB CD 12. 5 LATEX \makebox \raisebox \setbox \@tempboxa 18.. (PostScript) PDF (Cartesian coordinate) TEX DVI y-.. 19. pdftex \pdflastxpos \pdflastypos.. TEX.,.
78 THE ASIAN JOURNAL OF TEX. TEX. Knuth TEX 256. 20 8 \setbox, \box, \unhbox. 0 A \setbox0=\hbox{a}, \box0, \unhbox0. 255.. plain TEX \newbox. \newbox\mybox \mybox \setbox\mybox=\hbox{a}. LATEX \newbox \newsavebox.. \hbox \mbox \makebox LATEX \setbox \sbox \savebox. \newsavebox{ } \sbox{ }{ } \savebox{ }[ ][ ]{ } 4612 \long\def\sbox#1#2{\setbox#1\hbox{% 4613 \color@setgroup#2\color@endgroup}} \sbox. \setbox \hbox \setbox. \setbox\mybox=\hbox{a} \sbox\mybox{a}. \savebox \makebox. \usebox{ } 4635 \def\usebox#1{\leavevmode\copy #1\relax} LATEX \usebox \box \copy.. 13 \usebox \copy \unhcopy. 20. TEX 1980 8 256 = 2 8., (pdf)ε-tex 32768 = 2 15. TEX 16 Omega 65536 = 2 16.
VOLUME 1, NO. 1, APRIL 2007 79 55 \newsavebox\mybox 56 \sbox\mybox{a B C } 57 \newcommand\ub{\usebox\mybox} 58 \newcommand\bc{\copy\mybox} 59 \newcommand\uc{\unhcopy\mybox} 60 \UB\UB\UB\UB\par 61 \BC\BC\BC\BC\par 62 \UC\UC\UC\UC A B C A B C A B C A B C A B C A B C A B C A B C A B C A B C A B C A B C 13. \usebox \copy \unhcopy 13 \mybox. 60 \mbox{a B C }.. 61. 1., \copy \hbox. 62 \usebox. \unhcopy A B C A B C A B C A B C. LATEX \begin{ } \end{ } (environment). LATEX lrbox. \begin{lrbox}{ } \end{lrbox} 14 myenv \mybox., \raisebox.. [5, p. 870] boxedminipage lrbox minipage. 63 \newenvironment{myenv} 64 {\begin{lrbox}{\mybox}} % 65 {\end{lrbox}% % 66 \usebox\mybox\par\usebox\mybox\par 67 \raisebox{1.5\baselineskip}[0pt]{\usebox\mybox}} 68 \begin{myenv}the Korean \TeX{} Society\end{myenv} 69 \begin{myenv}the Asian Journal of \TeX\end{myenv} The Korean TEX Society The Korean TEX Society The Korean TEX Society The Asian Journal of TEX The Asian Journal of TEX The Asian Journal of TEX 14. lrbox \wd, \ht \dp.. 15.
80 THE ASIAN JOURNAL OF TEX 70 \sbox\mybox{korean} 71 \the\wd\mybox\par 72 \usebox\mybox\usebox\mybox\par 73 \setlength{\wd\mybox}{2\wd\mybox} 74 \the\wd\mybox\par 75 \usebox\mybox\usebox\mybox 28.88972pt KoreanKorean 57.77945pt Korean Korean 15. 6 LATEX. \hbox \vbox \vtop.. \hsize.. \vbox (reference point) \vtop. 16. 76 % \hsize. 77 A\vbox{B\par C}D\vtop{E\par F}G\par 78 A\vbox{\hbox{B}\par\hbox{C}}D% 79 \vtop{\hbox{e}\par\hbox{f}}g\par 80 A\vbox{\mbox{B}\par\mbox{C}}D% 81 \vtop{\mbox{e}\par\mbox{f}}g B AC B ACDEG B AC F DE F DE F G G 16. \vbox \vtop 16 77. A., A, \vbox, D, \vtop, G. \vbox. B. B \hsize., \vbox \hsize. \vtop \vbox F E. \hsize D.? \hbox
VOLUME 1, NO. 1, APRIL 2007 81. \hsize 77. \hbox \mbox.? \mbox \hbox \mbox. 77 \hsize. \hbox \hbox to \hbox spread \vbox \vtop. \raise \lower. \moveleft \moveright. \vbox \vtop.. [3, pp. 80 81]. LATEX \parbox minipage. 6.1 LATEX \parbox \parbox. \parbox[ ][ ][ ]{ }{ }. [c b t],,.. [c t b s]. \makebox. 21 17 \parbox. [s] 82 \par \vss.. \relax. \parbox{#1}{#2} \@iiiparbox{c}{\relax}[s]{#1}{#2} \parbox[#1]{#2}{#3} \@iiiparbox{#1}{\relax}[s]{#2}{#3} \parbox[#1][#2]{#3}{#4} \@iiiparbox{#1}{#2}[#1]{#3}{#4} \parbox[#1][#2][#3]{#4}{#5} \@iiiparbox{#1}{#2}[#3]{#4}{#5} \@iiiparbox. \leavevmode. 21. 11. \hss \vss \unhbox \unvbox. \parbox [t] [l], [b] [r].
82 THE ASIAN JOURNAL OF TEX 82 \newcommand\x{par\par BOX} 83 c\fbox{\parbox[c]{7mm}{\x}}b% 84 \fbox{\parbox[b]{7mm}{\x}}t% 85 \fbox{\parbox[t]{7mm}{\x}}align\par 86 c\fbox{\parbox[c][14mm][c]{7mm}{\x}}e% 87 \fbox{\parbox[c][14mm][t]{7mm}{\x}}n% 88 \fbox{\parbox[c][14mm][b]{7mm}{\x}}t% 89 \fbox{\parbox[c][14mm][s]{7mm}{\x}}er\par 90 b\fbox{\parbox[b][14mm][c]{7mm}{\x}}o% 91 \fbox{\parbox[b][14mm][t]{7mm}{\x}}t% 92 \fbox{\parbox[b][14mm][b]{7mm}{\x}}t% 93 \fbox{\parbox[b][14mm][s]{7mm}{\x}}om\par 94 t\fbox{\parbox[t][14mm][c]{7mm}{\x}}o% 95 \fbox{\parbox[t][14mm][t]{7mm}{\x}}p% 96 \fbox{\parbox[t][14mm][b]{7mm}{\x}}t% 97 \fbox{\parbox[t][14mm][s]{7mm}{\x}}op c PAR PAR BOX b BOX tpar align BOX PAR PAR c PAR BOX e BOX npar t BOX er PAR BOX b o t PAR BOX PAR BOX opar BOX BOX PAR tbox t p PAR BOX PAR BOX tpar BOX om op 17. \parbox 4712 \long\def\@iiiparbox#1#2[#3]#4#5{% 4713 \leavevmode 4714 \@pboxswfalse 4715 \setlength\@tempdima{#4}% 4716 \@begin@tempboxa\vbox{\hsize\@tempdima\@parboxrestore#5\@@par}% 4717 \ifx\relax#2\else 4718 \setlength\@tempdimb{#2}% 4719 \edef\@parboxto{to\the\@tempdimb}% 4720 \fi 4721 \if#1b\vbox 4722 \else\if #1t\vtop 4723 \else\ifmmode\vcenter 4724 \else\@pboxswtrue $\vcenter 4725 \fi\fi\fi 4726 \@parboxto{\let\hss\vss\let\unhbox\unvbox 4727 \csname bm@#3\endcsname}% 4728 \if@pboxsw \m@th$\fi 4729 \@end@tempboxa} #4 4715 \@tempdima. 4716 \@begin@tempboxa. \vbox \hsize \@tempdima. \@parboxrestore (latex.ltx 4744 ). \@@par \par. 22 #2. 22. \let\@@par=\par (latex.ltx 558 ) \par LATEX \@@par \par \@@par.
VOLUME 1, NO. 1, APRIL 2007 83 4717. #2 \@tempdimb \@parboxto., 4726 \vbox. 4721 4725 [b t c] \vbox, \vtop, \vcenter. 23 4726 #3 \@tempboxa. 16 \parbox. LATEX. 18 \settowidth. 98 \newlength\mylen 99 \settowidth\mylen{c}% 100 A\parbox[b]{\mylen}{B\par C}D% 101 \settowidth\mylen{e}% 102 \parbox[t]{\mylen}{e\par F}G B ACDEG F 18. \settowidth \parbox. 18 98 LATEX \newlength., 99 \settowidth, \settoheight, \settodepth,, (latex.ltx 1878 1880 ). 6.2 LATEX minipage \parbox minipage. \parbox minipage ( 19 )., minipage. \begin{minipage}[ ][ ][ ]{ } \end{minipage}. \parbox \parbox. [5, pp. 863 865]. 23. \vcenter \vbox \vtop. \if@pboxsw.
84 THE ASIAN JOURNAL OF TEX 103 \begin{minipage}[b]{.5\textwidth} 104 First!\footnote{1st footnote} 105 \end{minipage}% 106 \begin{minipage}[t]{.5\textwidth} 107 \addtocounter{mpfootnote}{1} 108 Second!\footnote{2nd footnote} 109 \end{minipage} First! a a. 1st footnote Second! b b. 2nd footnote 19. minipage 7 TEX. TEX.,. TEX. TEX. LATEX. TEX LATEX TEX,. LATEX,. 1., TEX, E 19 4 (2005), 823 837. 2. Victor Eijkhout, TEX by Topic, A TEXnician s Reference, Addison-Wesley, 1992. http:// www.cs.utk.edu/~eijkhout/texbytopic-a4.pdf 3. Donald E. Knuth, The TEX book, Addison-Wesley, 1986. 4. Helmut Kopka and Patrick W. Daly, Guide to LATEX, 4th ed., Addison-Wesley, 2004. 5. Frank Mittelbach and Michel Goossens, The LATEX Companion, 2nd ed., Addison-Wesley, 2004.