ltboxes.dtx

David Carlisle  Leslie Lamport  Frank Mittelbach

Chris Rowley

1995/10/31

1 L^{A}TEX Box commands

\makebox  \makebox[⟨wid⟩][⟨pos⟩]{⟨obj ⟩}

Puts ⟨obj ⟩ in an \hbox of width ⟨wid⟩, positioned by ⟨pos⟩.

The possible ⟨pos⟩ are: s stretched, l flushleft, r flushright, c (default) centred.

If ⟨wid⟩ is missing, then ⟨pos⟩ is also missing and ⟨obj ⟩ is put in an \hbox of its natural width.

\makebox(⟨x⟩,⟨y⟩)[⟨pos⟩]{⟨obj ⟩} Puts ⟨obj ⟩ in an \hbox of width x∗\unitlength and height y∗\unitlength. ⟨pos⟩ arguments are s, l, r or c (default) for stretched, flushleft, flushright or centred, and t or b for top, bottom – or combinations like tr or rb. Default for horizontal and vertical are centered. Note that in this picture mode version of \makebox a [b] aligns on the bottom of the text as documented. If you want to align on

the baseline use \makebox( , )[b]{\raisebox{0pt}[\height][0pt]{xyz}}} or
\makebox( , )[b]{\smash{xyz}}

\mbox \mbox{⟨obj ⟩} The same as \makebox{⟨obj ⟩}, but is more efficient as no check-

ing for optional arguments is done.

\newsavebox \newsavebox{\cmd} : If \cmd is undefined, then defines it to be a TEX box

register.

\savebox \savebox{\cmd} ... : \cmd is defined to be a TEX box register, and the ’...’ are any \makebox arguments. It is like \makebox, except it doesn’t produce text but saves the value in \box \cmd.

\sbox \sbox{⟨cmd⟩}{⟨obj ⟩} is an efficient abbreviation for

\savebox{⟨cmd⟩}{⟨obj ⟩}.
lrbox      \begin{lrbox}{⟨cmd⟩}⟨text⟩\end{lrbox} is equivalent to

\sbox{⟨cmd⟩}{⟨text⟩} except that any white space at the beginning and end of ⟨text⟩ is ignored.

\framebox \framebox ... : like \makebox, except it puts a ‘frame’ around the box. The frame is made of lines of thickness \fboxrule, separated by space \fboxsep from the text – except for \framebox(X,Y) ... , where the thickness of the lines is as for the picture environment, and there is no separation added.

\fbox \fbox{⟨obj ⟩} is an abbreviation for \framebox{⟨obj ⟩}. \parbox \parbox[⟨pos⟩][⟨height⟩][⟨inner-pos⟩]{⟨width⟩}{⟨text⟩} : Makes a box with

\hsize ⟨width⟩, positioned by ⟨pos⟩ as follows: c : \vcenter (placed in $...$ if not in math mode) b : \vbox t : \vtop default value is c. Sets \hsize := ⟨width⟩ and calls \@parboxrestore, which does the following: Restores the original definitions of:

    \par \\ \- \' \` \=

Resets the following parameters:

    \parindent  = 0pt

\parskip  = 0pt  added 20 Jan 87

    \linewidth  = \hsize
    \@totalleftmargin = 0pt
    \leftskip  = 0pt
    \rightskip  = 0pt
    \@rightskip  = 0pt
    \parfillskip  = 0pt plus 1fil
    \lineskip  = \normallineskip
    \baselineskip  = \normalbaselineskip

   Calls \sloppy
   Note: \@arrayparboxrestore same as \@parboxrestore but it doesn’t re-

store \\.

minipage minipage : Similar to \parbox, except it also makes this look like a page by

setting

   \textwidth == \columnwidth == box width

changes footnotes by redefining: \@mpfn == mpfootnote

\thempfn == \thempfootnote
\@footnotetext == \@mpfootnotetext

resets the following list environment parameters:

\@listdepth == \@mplistdepth

where \@mplistdepth is initialized to zero,

and executes \@minipagerestore to allow the document style to reset any other parameters it desires. It sets @minipage true, and resets \everypar to set it false. This switch keeps \addvspace from putting space at the top of a minipage.

Change added 24 May 89: \minipage sets @minipage globally; \endminipage resets it false.

\rule \rule[⟨raised⟩]{⟨width⟩}{⟨height⟩} : Makes a ⟨width⟩ ∗ ⟨height⟩ rule, raised

⟨raised⟩.

\underline \underline{⟨text⟩} : Makes an underlined hbox with ⟨text⟩ in it.

\raisebox \raisebox{⟨distance⟩}[⟨height⟩][⟨depth⟩]{⟨box⟩} : Raises ⟨box⟩ up by ⟨distance⟩ length (down if ⟨distance⟩ negative). Makes TEX think that the new box extends ⟨height⟩ above the line and ⟨depth⟩ below, for a total vertical length of ⟨height⟩+⟨depth⟩. Default values of ⟨height⟩ & ⟨depth⟩ = actual height and depth of box in new position.

1 ⟨∗2ekernel⟩

 2 \message{boxes,}

\makebox \makebox User level command just looks for optional [ or (.

 3 \def\makebox{%
 4 \leavevmode
 5 \@ifnextchar(%)
 6  \@makepicbox
 7  {\@ifnextchar[\@makebox\mbox}}

\mbox The basic horizontal box command for L^{A}TEX.

 8 \long\def\mbox#1{\leavevmode\hbox{#1}}

\@makebox Look for a possible second optional argument (defaults to c).

 9 \def\@makebox[#1]{%
10 \@ifnextchar [{\@imakebox[#1]}{\@imakebox[#1][c]}}
\@begin@tempboxa Helper macro for supporting \height, \width etc. Grab #1 into \@tempboxa and

measure it.

11 \long\def\@begin@tempboxa#1#2{%
12 \begingroup
13  \setbox\@tempboxa#1{\color@begingroup#2\color@endgroup}%
14  \def\width{\wd\@tempboxa}%
15  \def\height{\ht\@tempboxa}%
16  \def\depth{\dp\@tempboxa}%
17  \let\totalheight\@ovri
18  \totalheight\height
19  \advance\totalheight\depth}

\@end@tempboxa End the group started by \@begin@tempboxa, so that the scope of \height only includes the ‘length’ argument to the user-command.

20 \let\@end@tempboxa\endgroup
\bm@c \bm@l \bm@r \bm@s \bm@t \bm@b Set up spacing.
21 \def\bm@c{\hss\unhbox\@tempboxa\hss}
22 \def\bm@l{\unhbox\@tempboxa\hss}\let\bm@t\bm@l
23 \def\bm@r{\hss\unhbox\@tempboxa}\let\bm@b\bm@r
24 \def\bm@s{\unhbox\@tempboxa}
\@imakebox Internal form of \makebox.
25 \long\def\@imakebox[#1][#2]#3{%
26 \@begin@tempboxa\hbox{#3}%
27  \setlength\@tempdima{#1}%       support calc
28  \hb@xt@\@tempdima{\csname bm@#2\endcsname}%
29 \@end@tempboxa}

\@makepicbox Picture mode form of \makebox.
30 \def\@makepicbox(#1,#2){%
31 \@ifnextchar[{\@imakepicbox(#1,#2)}{\@imakepicbox(#1,#2)[]}}

\@imakepicbox picture mode version

32 \long\def\@imakepicbox(#1,#2)[#3]#4{%
33 \vbox to#2\unitlength
34 {\let\mb@b\vss \let\mb@l\hss\let\mb@r\hss
35  \let\mb@t\vss
36  \@tfor\reserved@a :=#3\do{%
37  \if s\reserved@a
38  \let\mb@l\relax\let\mb@r\relax
39  \else
40  \expandafter\let\csname mb@\reserved@a\endcsname\relax
41  \fi}%
42  \mb@t
43  \hb@xt@ #1\unitlength{\mb@l #4\mb@r}%
44  \mb@b

This kern ensures that a b option aligns on the bottom of the text rather than the baseline. this is the documented behaviour in the L^{A}TEXBook. The kern is removed in compatibility mode.

45  \kern\z@}}

\set@color This macro is initialy a no-op, but the colour package will redefine it to insert a

\special.
46 \let\set@color\relax
\color@begingroup \color@endgroup \color@setgroup \normalcolor \color@hbox \color@vbox \color@endbox These macros are initialy a no-op, but the colour package will redefine them to be
\begingroup, \endgroup, \begingroup\set@color,
\hbox\bgroup\color@begingroup, \color@endgroup\egroup. and ⟨set to main

document colour⟩ respectively.

47 \let\color@begingroup\relax
48 \let\color@endgroup\relax
49 \let\color@setgroup\relax
50 \let\normalcolor\relax
51 \let\color@hbox\relax
52 \let\color@vbox\relax
53 \let\color@endbox\relax

\newsavebox Allocate a new ‘savebox’.

54 \def\newsavebox#1{\@ifdefinable{#1}{\newbox#1}}

\savebox Save #1 in a box register.

55 \def\savebox#1{%
56 \@ifnextchar(%)
57  {\@savepicbox#1}{\@ifnextchar[{\@savebox#1}{\sbox#1}}}

\sbox Save #1 in a box register.

58 \long\def\sbox#1#2{\setbox#1\hbox{%
59 \color@setgroup#2\color@endgroup}}

\@savebox Look for second optional argument.

60 \def\@savebox#1[#2]{%
61 \@ifnextchar [{\@isavebox#1[#2]}{\@isavebox#1[#2][c]}}
\@isavebox
62 \long\def\@isavebox#1[#2][#3]#4{%
63 \sbox#1{\@imakebox[#2][#3]{#4}}}

\@savepicbox Picture mode version of \savebox.

64 \def\@savepicbox#1(#2,#3){%
65 \@ifnextchar[%]
66  {\@isavepicbox#1(#2,#3)}{\@isavepicbox#1(#2,#3)[]}}
\@isavepicbox Picture mode version of \savebox.
67 \long\def\@isavepicbox#1(#2,#3)[#4]#5{%
68 \sbox#1{\@imakepicbox(#2,#3)[#4]{#5}}}

\lrbox lrbox: the new environment form of \sbox. Use \aftergroup tricks to enable a local assignment to be made to the box, in a way that it still has an effect outside the lrbox environment.

69 \def\lrbox#1{%
70 \edef\reserved@a{%
71  \endgroup
72  \setbox#1\hbox{%
73  \begingroup\aftergroup}%
74  \def\noexpand\@currenvir{\@currenvir}%
75  \def\noexpand\@currenvline{\on@line}}%
76 \reserved@a
77  \@endpefalse
78  \color@setgroup
79  \ignorespaces}

\endlrbox End the lrbox environment.

80 \def\endlrbox{\unskip\color@endgroup}

\usebox unchanged

81 \def\usebox#1{\leavevmode\copy #1\relax}

\frame The following definition of \frame was written by Pavel Curtis (Extra space removed 14 Jan 88) RmS 92/08/24: Replaced occurence of \@halfwidth by

\@wholewidth
82 \long\def\frame#1{%
83 \leavevmode
84 \hbox{%

 85  \hskip-\@wholewidth
 86  \vbox{%
 87  \vskip-\@wholewidth
 88  \hrule \@height\@wholewidth
 89  \hbox{%
 90  \vrule\@width\@wholewidth
 91  #1%
 92  \vrule\@width\@wholewidth}%
 93  \hrule\@height\@wholewidth
 94  \vskip-\@wholewidth}%
 95  \hskip-\@wholewidth}}

\fboxrule \fboxsep user level parameters,

 96 \newdimen\fboxrule
 97 \newdimen\fboxsep

\fbox Abbreviated framed box command.

 98 \long\def\fbox#1{%
 99 \leavevmode
100 \setbox\@tempboxa\hbox{%
101  \color@begingroup
102  \kern\fboxsep{#1}\kern\fboxsep
103  \color@endgroup}%
104 \@frameb@x\relax}
\framebox Framed version of \makebox.
105 \def\framebox{%
106 \@ifnextchar(%)
107  \@framepicbox{\@ifnextchar[\@framebox\fbox}}

\@framebox Deal with optional arguments.

108 \def\@framebox[#1]{%
109 \@ifnextchar[%]
110  {\@iframebox[#1]}%
111  {\@iframebox[#1][c]}}

\@iframebox The handling the optional arguments. In order to set the whole box, including the frame to the specified dimension, we first determine that dimension from the natural size of the text, #3. calculated width.

112 \long\def\@iframebox[#1][#2]#3{%
113 \leavevmode
114 \@begin@tempboxa\hbox{#3}%
115  \setlength\@tempdima{#1}%
116  \setbox\@tempboxa\hb@xt@\@tempdima
117  {\kern\fboxsep\csname bm@#2\endcsname\kern\fboxsep}%
118  \@frameb@x{\kern-\fboxrule}%
119 \@end@tempboxa}

\@frameb@x Common part of \framebox and \fbox. #1 is a negative kern in the \framebox case so that the vertical rules do not add to the width of the box.

120 \def\@frameb@x#1{%
121 \@tempdima\fboxrule
122 \advance\@tempdima\fboxsep
123 \advance\@tempdima\dp\@tempboxa
124 \hbox{%
125  \lower\@tempdima\hbox{%
126  \vbox{%
127  \hrule\@height\fboxrule
128  \hbox{%
129  \vrule\@width\fboxrule
130  #1%
131  \vbox{%
132  \vskip\fboxsep
133  \box\@tempboxa
134  \vskip\fboxsep}%
135  #1%
136  \vrule\@width\fboxrule}%
137  \hrule\@height\fboxrule}%

138 }% 139 }% 140 }

\@framepicbox Picture mode version.

141 \def\@framepicbox(#1,#2){%
142 \@ifnextchar[{\@iframepicbox(#1,#2)}{\@iframepicbox(#1,#2)[]}}

\@iframepicbox Picture mode version.

143 \long\def\@iframepicbox(#1,#2)[#3]#4{%
144 \frame{\@imakepicbox(#1,#2)[#3]{#4}}}

\parbox The main vertical-box command for L^{A}TEX.

145 \def\parbox{%
146 \@ifnextchar[%]
147  \@iparbox
148  {\@iiiparbox c\@empty[s]}}

\@iparbox Optional argument handling.

149 \def\@iparbox[#1]{%
150 \@ifnextchar[%]
151  {\@iiparbox{#1}}%
152  {\@iiiparbox{#1}\@empty[s]}}

\@iiparbox Optional argument handling.

153 \def\@iiparbox#1[#2]{%
154 \@ifnextchar[%]
155  {\@iiiparbox{#1}{#2}}%
156  {\@iiiparbox{#1}{#2}[#1]}}

\@iiiparbox \@parboxto The internal version of \parbox.
157 \let\@parboxto\@empty
158 \long\def\@iiiparbox#1#2[#3]#4#5{%
159 \leavevmode
160 \@pboxswfalse
161 \setlength\@tempdima{#4}%
162 \@begin@tempboxa\vbox{\hsize\@tempdima\@parboxrestore#5\endgraf}%
163  \ifx\@empty#2\else
164  \setlength\@tempdimb{#2}%
165  \def\@parboxto{to\@tempdimb}%
166  \fi
167  \if#1b\vbox
168  \else\if #1t\vtop
169  \else\ifmmode\vcenter
170  \else\@pboxswtrue $\vcenter
171  \fi\fi\fi
172  \@parboxto{\let\hss\vss\let\unhbox\unvbox
173  \csname bm@#3\endcsname}%
174  \if@pboxsw \m@th$\fi
175 \@end@tempboxa}

\@arrayparboxrestore Restore various paragraph parameters.

176 \def\@arrayparboxrestore{%
177 \let\par\@@par
178 \let\-\@dischyph

Redefined accents to allow changes in font encoding

179 \let\'\@acci\let\`\@accii\let\=\@acciii
180 \parindent\z@ \parskip\z@skip
181 \everypar{}%
182 \linewidth\hsize
183 \@totalleftmargin\z@
184 \leftskip\z@skip \rightskip\z@skip \@rightskip\z@skip
185 \parfillskip\@flushglue \lineskip\normallineskip
186 \baselineskip\normalbaselineskip
187 \sloppy}

\parboxrestore Restore various paragraph parameters, and also \\.

188 \def\@parboxrestore{\@arrayparboxrestore\let\\\@normalcr}

\if@minipage Switch that is true at the start of a minipage.

189 \newif\if@minipage \@minipagefalse

\minipage Essentially an environment form of \parbox.

190 \def\minipage{%
191 \@ifnextchar[%]
192  \@iminipage
193  {\@iiiminipage c\@empty[s]}}

\@iminipage Optional argument handling.

194 \def\@iminipage[#1]{%
195 \@ifnextchar[%]
196  {\@iiminipage{#1}}%
197  {\@iiiminipage{#1}\@empty[s]}}

\@iiminipage Optional argument handling.

198 \def\@iiminipage#1[#2]{%
199 \@ifnextchar[%]
200  {\@iiiminipage{#1}{#2}}%
201  {\@iiiminipage{#1}{#2}[#1]}}
\@iiiminipage Internal form of minipage.
202 \def\@iiiminipage#1#2[#3]#4{%
203 \leavevmode
204 \@pboxswfalse
205 \setlength\@tempdima{#4}%
206 \def\@mpargs{{#1}{#2}[#3]{#4}}%
207 \setbox\@tempboxa\vbox\bgroup
208  \color@begingroup
209  \hsize\@tempdima
210  \textwidth\hsize \columnwidth\hsize
211  \@parboxrestore
212  \def\@mpfn{mpfootnote}\def\thempfn{\thempfootnote}\c@mpfootnote\z@
213  \let\@footnotetext\@mpfootnotetext
214  \let\@listdepth\@mplistdepth \@mplistdepth\z@
215  \@minipagerestore\global\@minipagetrue %% \global added 24 May 89
216  \everypar{\global\@minipagefalse\everypar{}}}

\@minipagerestore Hook so that other styles can reset other commands in a minipage.

217 \let\@minipagerestore=\relax
\endminipage
218 \def\endminipage{%
219  \par
220  \unskip
221  \ifvoid\@mpfootins\else
222  \vskip\skip\@mpfootins
223  \normalcolor
224  \footnoterule
225  \unvbox\@mpfootins
226  \fi
227  \global\@minipagefalse   %% added 24 May 89
228 \color@endgroup
229 \egroup
230 \expandafter\@iiiparbox\@mpargs{\unvbox\@tempboxa}}
\@mplistdepth \@mpfootins Versions of \@listdepth and \footins local to minipage.
231 \newcount\@mplistdepth
232 \newinsert\@mpfootins

\@mpfootnotetext Minipage version of \@footnotetext.

Final \strut added 27 Mar 89, on suggestion by Don Hosek

233 \long\def\@mpfootnotetext#1{%
234 \global\setbox\@mpfootins\vbox{%
235  \unvbox\@mpfootins
236  \reset@font\footnotesize
237  \hsize\columnwidth
238  \@parboxrestore
239  \protected@edef\@currentlabel
240  {\csname p@mpfootnote\endcsname\@thefnmark}%
241  \color@begingroup
242  \@makefntext{%
243  \rule\z@\footnotesep\ignorespaces#1\@finalstrut\strutbox}%
244  \color@endgroup}}
245 \newif\if@pboxsw

\rule Draw a rule of the specified size.

246 \def\rule{\@ifnextchar[\@rule{\@rule[\z@]}}

\@rule internal form of \rule.

247 \def\@rule[#1]#2#3{%
248 \@tempdima#3\advance\@tempdima #1%
249 \leavevmode
250 \hbox{\vrule\@width#2\@height\@tempdima\@depth-#1}}
\@@underline Saved primitive \underline.
251 \let\@@underline\underline

\underline L^{A}TEX version works outside math.

252 \def\underline#1{%
253 \relax
254 \ifmmode\@@underline{#1}%
255 \else $\@@underline{\hbox{#1}}\m@th$\relax\fi}

\raisebox Raise a box, and change its vertical dimensions.

256 \def\raisebox#1{%
257 \leavevmode
258 \@ifnextchar[{\@rsbox{#1}}{\@irsbox{#1}[]}}

\@rsbox Optional argument handling.

259 \def\@rsbox#1[#2]{%
260 \@ifnextchar[{\@iirsbox{#1}[#2]}{\@irsbox{#1}[#2]}}
\@argrsbox ...

\@irsbox Internal version of \raisebox (less than two optional args).

261 \long\def\@irsbox#1[#2]#3{%
262 \@begin@tempboxa\hbox{#3}%

263  \setlength\@tempdima{#1}%
264  \ifx\\#2\\\else\setlength\@tempdimb{#2}\fi
265  \setbox\@tempboxa\hbox{\raise\@tempdima\box\@tempboxa}%
266  \ifx\\#2\\\else\ht\@tempboxa\@tempdimb\fi
267  \box\@tempboxa
268 \@end@tempboxa}

\@iirsbox Internal version of \raisebox (two optional args).

269 \long\def\@iirsbox#1[#2][#3]#4{%
270 \@begin@tempboxa\hbox{#4}%
271  \setlength\@tempdima{#1}%
272  \setlength\@tempdimb{#2}%
273  \setlength\dimen@{#3}%
274  \setbox\@tempboxa\hbox{\raise\@tempdima\box\@tempboxa}%
275  \ht\@tempboxa\@tempdimb
276  \dp\@tempboxa\dimen@
277  \box\@tempboxa
278 \@end@tempboxa}

\@finalstrut This macro adds a special strut the depth of the box given as #1, and height and width 0pt. It is used for ensuring that the last line of a paragraph has the correct depth in ‘p’ columns of tables and in footnotes. In vertical mode nothing is done, as adding the strut (as done in 2.09) would start a new paragraph. It would be possible to inspect \prevdepth to check the depth of the just-completed paragraph, but we do not do that here. Actually we do even less now, skip the vmode test as it broke tabular ‘p’ columns. .

The \nobreak was added (1995/10/31) to allow hyphenation of the final word of the paragraph.

279 \def\@finalstrut#1{%
280 \unskip\ifhmode\nobreak\fi\vrule\@width\z@\@height\z@\@depth\dp#1}

1.1 Some low-level constructs

The following commands are basically inherited from plain TEX.

\leftline \rightline \centerline \@@line These macros place text on a full line either centred or left or right adjusted.

281 \def\@@line{\hb@xt@\hsize}
282 \def\leftline#1{\@@line{#1\hss}}
283 \def\rightline#1{\@@line{\hss#1}}
284 \def\centerline#1{\@@line{\hss#1\hss}}

\rlap \llap These macros place text to the left or right of the current reference point without taking up space.

285 \def\rlap#1{\hb@xt@\z@{#1\hss}}
286 \def\llap#1{\hb@xt@\z@{\hss#1}}

287 ⟨/2ekernel⟩