forked from CTeX-org/tex-by-topic-cn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchapter05.tex
2223 lines (2071 loc) · 80.8 KB
/
chapter05.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
% -*- coding: utf-8 -*-
\documentclass{book}
\input{preamble}
\setcounter{chapter}{4}
\begin{document}
%\chapter{Boxes}\label{boxes}\index{boxes|(}
\chapter{Boxes}\label{boxes}\index{boxes|(}
%The horizontal and vertical boxes of \TeX\ are containers for
%pieces of horizontal and vertical lists.
%Boxes can be stored in box registers.
%This chapter treats box registers and such
%aspects of boxes as their dimensions, and the way their components
%are placed relative to each other.
The horizontal and vertical boxes of \TeX\ are containers for
pieces of horizontal and vertical lists.
Boxes can be stored in box registers.
This chapter treats box registers and such
aspects of boxes as their dimensions, and the way their components
are placed relative to each other.
%\label{cschap:hbox}\label{cschap:vbox}\label{cschap:vtop}\label{cschap:vsplit}\label{cschap:box}\label{cschap:setbox}\label{cschap:copy}\label{cschap:ifhbox}\label{cschap:ifvbox}\label{cschap:ifvoid2}\label{cschap:newbox}\label{cschap:unhbox}\label{cschap:unvbox}\label{cschap:unhcopy}\label{cschap:unvcopy}\label{cschap:ht}\label{cschap:dp}\label{cschap:wd}\label{cschap:boxmaxdepth}\label{cschap:splitmaxdepth}\label{cschap:badness}\label{cschap:hfuzz}\label{cschap:vfuzz}\label{cschap:hbadness}\label{cschap:vbadness}\label{cschap:overfullrule}\label{cschap:hsize}\label{cschap:vsize}\label{cschap:lastbox}\label{cschap:raise}\label{cschap:lower}\label{cschap:moveleft}\label{cschap:moveright}\label{cschap:everyhbox}\label{cschap:everyvbox}
%\begin{inventory}
%\item [\cs{hbox}]
% Construct a horizontal box.
%\item [\cs{vbox}]
% Construct a vertical box with reference point of the last item.
%\item [\cs{vtop}]
% Construct a vertical box with reference point of the first item.
%\item [\cs{vcenter}]
% Construct a vertical box vertically centred
% on the math axis; this command can only be used in math mode.
\label{cschap:hbox}\label{cschap:vbox}\label{cschap:vtop}\label{cschap:vsplit}\label{cschap:box}\label{cschap:setbox}\label{cschap:copy}\label{cschap:ifhbox}\label{cschap:ifvbox}\label{cschap:ifvoid2}\label{cschap:newbox}\label{cschap:unhbox}\label{cschap:unvbox}\label{cschap:unhcopy}\label{cschap:unvcopy}\label{cschap:ht}\label{cschap:dp}\label{cschap:wd}\label{cschap:boxmaxdepth}\label{cschap:splitmaxdepth}\label{cschap:badness}\label{cschap:hfuzz}\label{cschap:vfuzz}\label{cschap:hbadness}\label{cschap:vbadness}\label{cschap:overfullrule}\label{cschap:hsize}\label{cschap:vsize}\label{cschap:lastbox}\label{cschap:raise}\label{cschap:lower}\label{cschap:moveleft}\label{cschap:moveright}\label{cschap:everyhbox}\label{cschap:everyvbox}
\begin{inventory}
\item [\cs{hbox}]
Construct a horizontal box.
\item [\cs{vbox}]
Construct a vertical box with reference point of the last item.
\item [\cs{vtop}]
Construct a vertical box with reference point of the first item.
\item [\cs{vcenter}]
Construct a vertical box vertically centred
on the math axis; this command can only be used in math mode.
%\item [\cs{vsplit}]
% Split off the top part of a vertical box.
\item [\cs{vsplit}]
Split off the top part of a vertical box.
%\item [\cs{box}]
% Use a box register, emptying it.
\item [\cs{box}]
Use a box register, emptying it.
%\item [\cs{setbox}]
% Assign a box to a box register.
\item [\cs{setbox}]
Assign a box to a box register.
%\item [\cs{copy}]
% Use a box register, but retain the contents.
\item [\cs{copy}]
Use a box register, but retain the contents.
%\item [\cs{ifhbox \cs{ifvbox}}]
%\mdqon
% Test whether a box register contains a horizontal/""vertical box.
%\mdqoff
\item [\cs{ifhbox \cs{ifvbox}}]
\mdqon
Test whether a box register contains a horizontal/""vertical box.
\mdqoff
%\item [\cs{ifvoid}]
% Test whether a box register is empty.
\item [\cs{ifvoid}]
Test whether a box register is empty.
%\item [\cs{newbox}]
% Allocate a new box register.
\item [\cs{newbox}]
Allocate a new box register.
%\item [\cs{unhbox \cs{unvbox}}]
% Unpack a box register containing a horizontal/vertical box,
% adding the contents to the current horizontal/vertical list,
% and emptying the register.
\item [\cs{unhbox \cs{unvbox}}]
Unpack a box register containing a horizontal/vertical box,
adding the contents to the current horizontal/vertical list,
and emptying the register.
%\item [\cs{unhcopy \cs{unvcopy}}]
% The same as \cs{unhbox}$\,$/$\,$\cs{unvbox},
% but do not empty the register.
\item [\cs{unhcopy \cs{unvcopy}}]
The same as \cs{unhbox}$\,$/$\,$\cs{unvbox},
but do not empty the register.
%\item [\cs{ht \cs{dp} \cs{wd}}]
% Height/depth/width of the box in a box register.
\item [\cs{ht \cs{dp} \cs{wd}}]
Height/depth/width of the box in a box register.
%\item [\cs{boxmaxdepth}]
% Maximum allowed depth of boxes.
% Plain \TeX\ default:~\cs{maxdimen}.
\item [\cs{boxmaxdepth}]
Maximum allowed depth of boxes.
Plain \TeX\ default:~\cs{maxdimen}.
%\item [\cs{splitmaxdepth}]
% Maximum allowed depth of boxes generated by \cs{vsplit}.
\item [\cs{splitmaxdepth}]
Maximum allowed depth of boxes generated by \cs{vsplit}.
%\item [\cs{badness}]
% Badness of the most recently constructed box.
\item [\cs{badness}]
Badness of the most recently constructed box.
%\item [\cs{hfuzz \cs{vfuzz}}]
% Excess size that \TeX\ tolerates before it considers
%\mdqon
% a horizontal/""vertical box overfull.
%\mdqoff
\item [\cs{hfuzz \cs{vfuzz}}]
Excess size that \TeX\ tolerates before it considers
\mdqon
a horizontal/""vertical box overfull.
\mdqoff
%\item [\cs{hbadness \cs{vbadness}}]
% Amount of tolerance before \TeX\ reports an underfull
%\mdqon
% or overfull horizontal/""vertical box.
%\mdqoff
\item [\cs{hbadness \cs{vbadness}}]
Amount of tolerance before \TeX\ reports an underfull
\mdqon
or overfull horizontal/""vertical box.
\mdqoff
%\item [\cs{overfullrule}]
% Width of the rule that is printed to indicate
% overfull horizontal boxes.
\item [\cs{overfullrule}]
Width of the rule that is printed to indicate
overfull horizontal boxes.
%
%\item [\cs{hsize}]
% Line width used for text typesetting inside a vertical box.
\item [\cs{hsize}]
Line width used for text typesetting inside a vertical box.
%\item [\cs{vsize}]
% Height of the page box.
\item [\cs{vsize}]
Height of the page box.
%\item [\cs{lastbox}]
% Register containing the last item added to the current list,
% if this was a box.
\item [\cs{lastbox}]
Register containing the last item added to the current list,
if this was a box.
%\item [\cs{raise \cs{lower}}]
% Adjust vertical positioning of a box in horizontal mode.
\item [\cs{raise \cs{lower}}]
Adjust vertical positioning of a box in horizontal mode.
%\item [\cs{moveleft \cs{moveright}}]
% Adjust horizontal positioning of a box in vertical mode.
\item [\cs{moveleft \cs{moveright}}]
Adjust horizontal positioning of a box in vertical mode.
%\item [\cs{everyhbox \cs{everyvbox}}]
%\mdqon
% Token list inserted at the start of a horizontal/""vertical box.
%\mdqoff
\item [\cs{everyhbox \cs{everyvbox}}]
\mdqon
Token list inserted at the start of a horizontal/""vertical box.
\mdqoff
%\end{inventory}
\end{inventory}
%\section{Boxes}
\section{Boxes}
%In this chapter we shall look at boxes. Boxes are containers
%for pieces of horizontal or vertical lists.
%Boxes that are needed more than once can be stored in box registers.
In this chapter we shall look at boxes. Boxes are containers
for pieces of horizontal or vertical lists.
Boxes that are needed more than once can be stored in box registers.
%When \TeX\ expects a \gr{box}, any of the following forms
%is admissible:
%\begin{itemize}
%\item \cs{hbox}\gr{box specification}\lb\gr{horizontal material}\rb
%\item \cs{vbox}\gr{box specification}\lb\gr{vertical material}\rb
%\item \cs{vtop}\gr{box specification}\lb\gr{vertical material}\rb
%\item \cs{box}\gr{8-bit number}
%\item \cs{copy}\gr{8-bit number}
%\item \cs{vsplit}\gr{8-bit number}\n{to}\gr{dimen}
%\item \cs{lastbox}
%\end{itemize}
%A \gr{box specification} is defined as\label{box:spec}
%\begin{disp}\gr{box specification} $\longrightarrow$ \gr{filler}
%\nl\indent$|$ \n{to} \gr{dimen}\gr{filler}
% $|$ \n{spread} \gr{dimen}\gr{filler}
%\end{disp}
%An \gr{8-bit number} is a number in the range~0--255.
When \TeX\ expects a \gr{box}, any of the following forms
is admissible:
\begin{itemize}
\item \cs{hbox}\gr{box specification}\lb\gr{horizontal material}\rb
\item \cs{vbox}\gr{box specification}\lb\gr{vertical material}\rb
\item \cs{vtop}\gr{box specification}\lb\gr{vertical material}\rb
\item \cs{box}\gr{8-bit number}
\item \cs{copy}\gr{8-bit number}
\item \cs{vsplit}\gr{8-bit number}\n{to}\gr{dimen}
\item \cs{lastbox}
\end{itemize}
A \gr{box specification} is defined as\label{box:spec}
\begin{disp}\gr{box specification} $\longrightarrow$ \gr{filler}
\nl\indent$|$ \n{to} \gr{dimen}\gr{filler}
$|$ \n{spread} \gr{dimen}\gr{filler}
\end{disp}
An \gr{8-bit number} is a number in the range~0--255.
%The braces surrounding box material define a group;
%they can be explicit characters
%of categories 1 and~2 respectively,
%or control sequences \cs{let} to such characters;
%see also below.
The braces surrounding box material define a group;
they can be explicit characters
of categories 1 and~2 respectively,
or control sequences \cs{let} to such characters;
see also below.
%A \gr{box} can in general be used in horizontal, vertical,
%and math mode, but see below for the \cs{lastbox}.
%The connection between
%boxes and modes is explored further in Chapter~\ref{hvmode}.
A \gr{box} can in general be used in horizontal, vertical,
and math mode, but see below for the \cs{lastbox}.
The connection between
boxes and modes is explored further in Chapter~\ref{hvmode}.
%The box produced by \cs{vcenter} \ldash a command that is allowed only in
%math mode \rdash is not a \gr{box}. For instance,
%it can not be assigned with \verb=\setbox=; see further
%Chapter~\ref{math}.
The box produced by \cs{vcenter} \ldash a command that is allowed only in
math mode \rdash is not a \gr{box}. For instance,
it can not be assigned with \verb=\setbox=; see further
Chapter~\ref{math}.
%The \cs{vsplit} operation is treated in Chapter~\ref{page:break}.
The \cs{vsplit} operation is treated in Chapter~\ref{page:break}.
%\section{Box registers}
\section{Box registers}
%There are 256 box registers, numbered 0--255.
%Either a box register is empty (`void'), or it contains a horizontal
%or vertical box.
%This section discusses specifically box {\em registers};
%the sizes of boxes, and the way material is arranged inside them,
%is treated below.
There are 256 box registers, numbered 0--255.
Either a box register is empty (`void'), or it contains a horizontal
or vertical box.
This section discusses specifically box {\em registers};
the sizes of boxes, and the way material is arranged inside them,
is treated below.
%%\spoint Allocation: \cs{newbox}
%\subsection{Allocation: \cs{newbox}}
%\spoint Allocation: \cs{newbox}
\subsection{Allocation: \cs{newbox}}
%The plain \TeX\ \csidx{newbox} macro allocates an unused
%box register:
%\begin{verbatim}
%\newbox\MyBox
%\end{verbatim}
%after which one can say
%\begin{verbatim}
%\setbox\MyBox=...
%\end{verbatim}
%or
%\begin{verbatim}
%\box\MyBox
%\end{verbatim}
%and so on.
%Subsequent calls to this macro give subsequent box numbers;
%this way macro collections can allocate their own boxes
%without fear of collision with other macros.
The plain \TeX\ \csidx{newbox} macro allocates an unused
box register:
\begin{verbatim}
\newbox\MyBox
\end{verbatim}
after which one can say
\begin{verbatim}
\setbox\MyBox=...
\end{verbatim}
or
\begin{verbatim}
\box\MyBox
\end{verbatim}
and so on.
Subsequent calls to this macro give subsequent box numbers;
this way macro collections can allocate their own boxes
without fear of collision with other macros.
%The number of the box is assigned by \cs{chardef}
%(see Chapter~\ref{alloc}).
%This implies that \cs{MyBox} is equivalent to,
%and can be used as, a~\gr{number}.
%The control sequence
%\altt
%\cs{newbox} is an \cs{outer} macro.
%Newly allocated box registers are initially empty.
The number of the box is assigned by \cs{chardef}
(see Chapter~\ref{alloc}).
This implies that \cs{MyBox} is equivalent to,
and can be used as, a~\gr{number}.
The control sequence
\altt
\cs{newbox} is an \cs{outer} macro.
Newly allocated box registers are initially empty.
%\subsection{Usage: \cs{setbox}, \cs{box}, \cs{copy}}
\subsection{Usage: \cs{setbox}, \cs{box}, \cs{copy}}
%A~register is filled by assigning a \gr{box}
%\cstoidx setbox\par
%to it:
%\begin{Disp}\verb>\setbox>\gr{number}\gr{equals}\gr{box}\end{Disp}
%For example, the \gr{box} can be explicit
%\begin{Disp}\verb>\setbox37=\hbox{...}>\quad or\quad \verb>\setbox37=\vbox{...}>
%\end{Disp}
%or it can be a box register:
%\begin{verbatim}
%\setbox37=\box38
%\end{verbatim}
%Usually, box numbers will have been assigned by a \cs{newbox}
%command.
A~register is filled by assigning a \gr{box}
\cstoidx setbox\par
to it:
\begin{Disp}\verb>\setbox>\gr{number}\gr{equals}\gr{box}\end{Disp}
For example, the \gr{box} can be explicit
\begin{Disp}\verb>\setbox37=\hbox{...}>\quad or\quad \verb>\setbox37=\vbox{...}>
\end{Disp}
or it can be a box register:
\begin{verbatim}
\setbox37=\box38
\end{verbatim}
Usually, box numbers will have been assigned by a \cs{newbox}
command.
%The box in a box register is appended
%by the commands \cs{box} and~\cs{copy}
%to whatever list \TeX\ is building: the call
%\begin{verbatim}
%\box38
%\end{verbatim}
%appends box~38.
%To save memory space, box registers become empty by using them:
%\TeX\ assumes that after you have inserted a box by
%calling \csidx{box}$nn$ in some mode, you do not need the
%contents of that register any more and empties it.
%In case you {\em do\/} need the contents of
%a box register more than once,
%you can \csidx{copy} it. Calling \cs{copy}$nn$ is
%equivalent to \cs{box}$nn$ in all respects except that
%the register is not cleared.
The box in a box register is appended
by the commands \cs{box} and~\cs{copy}
to whatever list \TeX\ is building: the call
\begin{verbatim}
\box38
\end{verbatim}
appends box~38.
To save memory space, box registers become empty by using them:
\TeX\ assumes that after you have inserted a box by
calling \csidx{box}$nn$ in some mode, you do not need the
contents of that register any more and empties it.
In case you {\em do\/} need the contents of
a box register more than once,
you can \csidx{copy} it. Calling \cs{copy}$nn$ is
equivalent to \cs{box}$nn$ in all respects except that
the register is not cleared.
%It is possible to unwrap the contents of a box register
%by `unboxing' it using the commands \cs{unhbox} and \cs{unvbox},
%and their copying versions \cs{unhcopy} and \cs{unvcopy}.
%Whereas a box can be used in any mode, the
%unboxing operations can only be used in the appropriate mode,
%since in effect they contribute a partial
%horizontal or vertical list (see also Chapter~\ref{hvmode}).
%See below for more information on unboxing registers.
It is possible to unwrap the contents of a box register
by `unboxing' it using the commands \cs{unhbox} and \cs{unvbox},
and their copying versions \cs{unhcopy} and \cs{unvcopy}.
Whereas a box can be used in any mode, the
unboxing operations can only be used in the appropriate mode,
since in effect they contribute a partial
horizontal or vertical list (see also Chapter~\ref{hvmode}).
See below for more information on unboxing registers.
%%\spoint Testing: \cs{ifvoid}, \cs{ifhbox}, \cs{ifvbox}
%\subsection{Testing: \cs{ifvoid}, \cs{ifhbox}, \cs{ifvbox}}
%\spoint Testing: \cs{ifvoid}, \cs{ifhbox}, \cs{ifvbox}
\subsection{Testing: \cs{ifvoid}, \cs{ifhbox}, \cs{ifvbox}}
%Box
%registers can be tested for their contents:
%\begin{disp}\cs{ifvoid}\gr{number}\end{disp}
%is true if the box register is empty.
%Note that an empty, or `void',
%box register is not the same as a register containing an empty box.
%An empty box is still either a horizontal or a vertical box;
%a~void register can be used as both.
Box
registers can be tested for their contents:
\begin{disp}\cs{ifvoid}\gr{number}\end{disp}
is true if the box register is empty.
Note that an empty, or `void',
box register is not the same as a register containing an empty box.
An empty box is still either a horizontal or a vertical box;
a~void register can be used as both.
%The test
%\begin{disp}\cs{ifhbox}\gr{number}\end{disp}
%is true if the box register contains a horizontal box;
%\begin{disp}\cs{ifvbox}\gr{number}\end{disp}
%is true if the box register contains a vertical box.
%Both tests are false for void registers.
The test
\begin{disp}\cs{ifhbox}\gr{number}\end{disp}
is true if the box register contains a horizontal box;
\begin{disp}\cs{ifvbox}\gr{number}\end{disp}
is true if the box register contains a vertical box.
Both tests are false for void registers.
%%\spoint[lastbox] The \cs{lastbox}
%\subsection{The \cs{lastbox}}
%\label{lastbox}
%\spoint[lastbox] The \cs{lastbox}
\subsection{The \cs{lastbox}}
\label{lastbox}
%When \TeX\ has built a partial list, the last box in this
%list is accessible as the \csidx{lastbox}. This behaves
%like a box register, so you can remove the last box from the
%list by assigning the \cs{lastbox} to some box register.
%If the last item on the current list is not a box,
%the \cs{lastbox} acts like a void box register.
%It is not possible to get hold of the last box
%in the case of the main vertical list.
%The \cs{lastbox} is then always void.
When \TeX\ has built a partial list, the last box in this
list is accessible as the \csidx{lastbox}. This behaves
like a box register, so you can remove the last box from the
list by assigning the \cs{lastbox} to some box register.
If the last item on the current list is not a box,
the \cs{lastbox} acts like a void box register.
It is not possible to get hold of the last box
in the case of the main vertical list.
The \cs{lastbox} is then always void.
%As an example, the statement
%\begin{verbatim}
%{\setbox0=\lastbox}
%\end{verbatim}
%removes
%the last box from the current list, assigning it to box
%register~0. Since this assignment occurs inside a group,
%the register is cleared at the end of the group.
%At the start of a paragraph this can be used to remove the
%indentation box (see Chapter~\ref{par:start}).
%Another example of \cs{lastbox} can be found on page~\pageref{varioset}.
As an example, the statement
\begin{verbatim}
{\setbox0=\lastbox}
\end{verbatim}
removes
the last box from the current list, assigning it to box
register~0. Since this assignment occurs inside a group,
the register is cleared at the end of the group.
At the start of a paragraph this can be used to remove the
indentation box (see Chapter~\ref{par:start}).
Another example of \cs{lastbox} can be found on page~\pageref{varioset}.
%Because the \verb-\lastbox- is always empty in external vertical mode,
%it is not possible to get hold of boxes that have been
%added to the page. However, it is possible to dissect
%the page once it is in \cs{box255}, for instance doing
%\begin{verbatim}
%\vbox{\unvbox255{\setbox0=\lastbox}}
%\end{verbatim}
%inside the output routine.
Because the \verb-\lastbox- is always empty in external vertical mode,
it is not possible to get hold of boxes that have been
added to the page. However, it is possible to dissect
the page once it is in \cs{box255}, for instance doing
\begin{verbatim}
\vbox{\unvbox255{\setbox0=\lastbox}}
\end{verbatim}
inside the output routine.
%If boxes in vertical mode have been shifted by \cs{moveright}
%or \cs{moveleft}, or if boxes in horizontal mode have
%been raised by \cs{raise} or lowered by \cs{lower},
%any information about this
%displacement due to such a command is lost when
%the \cs{lastbox} is taken from the list.
If boxes in vertical mode have been shifted by \cs{moveright}
or \cs{moveleft}, or if boxes in horizontal mode have
been raised by \cs{raise} or lowered by \cs{lower},
any information about this
displacement due to such a command is lost when
the \cs{lastbox} is taken from the list.
%%\point Natural dimensions of boxes
%\section{Natural dimensions of boxes}
%\point Natural dimensions of boxes
\section{Natural dimensions of boxes}
%%\spoint Dimensions of created horizontal boxes
%\subsection{Dimensions of created horizontal boxes}
%\spoint Dimensions of created horizontal boxes
\subsection{Dimensions of created horizontal boxes}
%Inside an \csidx{hbox} all constituents are lined up next to each other,
%with their reference points on the baseline of the box,
%unless they are moved explicitly in the vertical direction
%by \cs{lower} or~\cs{raise}.
Inside an \csidx{hbox} all constituents are lined up next to each other,
with their reference points on the baseline of the box,
unless they are moved explicitly in the vertical direction
by \cs{lower} or~\cs{raise}.
%The resulting width of the box is the sum of the widths
%of the components. Thus the width of
%\begin{verbatim}
%\hbox{\hskip1cm}
%\end{verbatim}
%is positive, and the width of
%\begin{verbatim}
%\hbox{\hskip-1cm}
%\end{verbatim}
%is negative. By way of example,
%\begin{disp}\verb>a\hbox{\kern-1em b}-->\end{disp}
%gives as output
%\begin{disp}\leavevmode\hphantom{b}a\hbox{\kern-1em b}--\end{disp}
%\message{check align input/output}
%which shows that a horizontal box can have negative
%width.
The resulting width of the box is the sum of the widths
of the components. Thus the width of
\begin{verbatim}
\hbox{\hskip1cm}
\end{verbatim}
is positive, and the width of
\begin{verbatim}
\hbox{\hskip-1cm}
\end{verbatim}
is negative. By way of example,
\begin{disp}\verb>a\hbox{\kern-1em b}-->\end{disp}
gives as output
\begin{disp}\leavevmode\hphantom{b}a\hbox{\kern-1em b}--\end{disp}
\message{check align input/output}
which shows that a horizontal box can have negative
width.
%The height and depth of an \cs{hbox} are the
%maximum amount that constituent boxes project above and
%below the baseline of the box. They are non-negative when the
%box is created.
The height and depth of an \cs{hbox} are the
maximum amount that constituent boxes project above and
below the baseline of the box. They are non-negative when the
box is created.
%The commands \cs{lower} and \cs{raise} are the only possibilities
%for vertical movement inside an \cs{hbox} (other than
%including a \cs{vbox} inside the \cs{hbox}, of course);
%a~\gr{vertical command} \ldash such as \cs{vskip} \rdash
%is not allowed in a horizontal box, and
%\cs{par}, although allowed,
%does not do anything inside a horizontal box.
The commands \cs{lower} and \cs{raise} are the only possibilities
for vertical movement inside an \cs{hbox} (other than
including a \cs{vbox} inside the \cs{hbox}, of course);
a~\gr{vertical command} \ldash such as \cs{vskip} \rdash
is not allowed in a horizontal box, and
\cs{par}, although allowed,
does not do anything inside a horizontal box.
%%\spoint Dimensions of created vertical boxes
%\subsection{Dimensions of created vertical boxes}
%\spoint Dimensions of created vertical boxes
\subsection{Dimensions of created vertical boxes}
%Inside a \csidx{vbox} vertical material is lined up with the
%\cstoidx vtop\par
%reference points on the vertical line through the reference
%point of the box,
%unless components are moved explicitly in the horizontal direction
%by \csidx{moveleft} or~\csidx{moveright}.
Inside a \csidx{vbox} vertical material is lined up with the
\cstoidx vtop\par
reference points on the vertical line through the reference
point of the box,
unless components are moved explicitly in the horizontal direction
by \csidx{moveleft} or~\csidx{moveright}.
%The reference point of a vertical box
%is always located at the left boundary of the box.
%The width of a vertical box
%is then the maximal amount that any material in the
%box sticks to the right of the reference point.
%Material to the left of the reference point is
%not taken into account in the width.
%Thus the result of
%\begin{disp}\verb>a\vbox{\hbox{\kern-1em b}}-->\end{disp}
%is
%\begin{disp}\leavevmode\hphantom{b}a\vbox{\hbox{\kern-1em b}}--\end{disp}
%This should be contrasted with the above example.
The reference point of a vertical box
is always located at the left boundary of the box.
The width of a vertical box
is then the maximal amount that any material in the
box sticks to the right of the reference point.
Material to the left of the reference point is
not taken into account in the width.
Thus the result of
\begin{disp}\verb>a\vbox{\hbox{\kern-1em b}}-->\end{disp}
is
\begin{disp}\leavevmode\hphantom{b}a\vbox{\hbox{\kern-1em b}}--\end{disp}
This should be contrasted with the above example.
%The calculation of height and depth is different
%for vertical boxes constructed by \cs{vbox} and \cs{vtop}.
%The ground rule is that
%a \cs{vbox} has a reference point that lies on
%the baseline of its last component,
%and a \cs{vtop} has its reference point on the baseline of the
%first component.
%In general, the depth (height) of a \cs{vbox} (\cs{vtop})
%\alt
%can be non-zero if the last (first) item is a box or rule.
The calculation of height and depth is different
for vertical boxes constructed by \cs{vbox} and \cs{vtop}.
The ground rule is that
a \cs{vbox} has a reference point that lies on
the baseline of its last component,
and a \cs{vtop} has its reference point on the baseline of the
first component.
In general, the depth (height) of a \cs{vbox} (\cs{vtop})
\alt
can be non-zero if the last (first) item is a box or rule.
%The height of a \cs{vbox} is then the sum of the heights and
%depths of all components except the last, plus the height
%of that last component; the depth of the \cs{vbox} is the
%depth of its last component.
%The depth of a \cs{vtop}
%is the sum of the depth of the first component and the heights
%and depths of all subsequent material; its height is the
%height of the first component.
The height of a \cs{vbox} is then the sum of the heights and
depths of all components except the last, plus the height
of that last component; the depth of the \cs{vbox} is the
depth of its last component.
The depth of a \cs{vtop}
is the sum of the depth of the first component and the heights
and depths of all subsequent material; its height is the
height of the first component.
%However, the actual rules are a bit
%more complicated when the first component of a \cs{vtop}
%or the last component of a \cs{vbox} is not a box or rule.
%If the last component of a \cs{vbox} is a kern or a glue,
%the depth of that box is zero; a \cs{vtop}'s
%height is zero
%unless its first component is a box or rule.
%\altt
%(Note the asymmetry in these definitions; see below for
%an example illustrating this.)
%The depth of a \cs{vtop}, then, is equal to the total
%height plus depth of all enclosed material minus
%the height of the \cs{vtop}.
However, the actual rules are a bit
more complicated when the first component of a \cs{vtop}
or the last component of a \cs{vbox} is not a box or rule.
If the last component of a \cs{vbox} is a kern or a glue,
the depth of that box is zero; a \cs{vtop}'s
height is zero
unless its first component is a box or rule.
\altt
(Note the asymmetry in these definitions; see below for
an example illustrating this.)
The depth of a \cs{vtop}, then, is equal to the total
height plus depth of all enclosed material minus
the height of the \cs{vtop}.
%There is a limit on the depth of vertical boxes:
%if the depth of a \cs{vbox} or \cs{vtop}
%calculated by the above rules would exceed
%\cstoidx boxmaxdepth\par,
%the reference point of the box
%is moved down by the excess amount.
%More precisely, the excess depth is added to the
%natural height of the box. If the box had a \n{to} or
%\n{spread} specification, any glue is set anew to take
%the new height into account.
There is a limit on the depth of vertical boxes:
if the depth of a \cs{vbox} or \cs{vtop}
calculated by the above rules would exceed
\cstoidx boxmaxdepth\par,
the reference point of the box
is moved down by the excess amount.
More precisely, the excess depth is added to the
natural height of the box. If the box had a \n{to} or
\n{spread} specification, any glue is set anew to take
the new height into account.
%Ordinarily,
%\cs{boxmaxdepth} is set to the maximum dimension
%possible in \TeX. It is for instance reduced during some of
%the calculations in the plain \TeX\ output routine;
%see Chapter~\ref{output}.
Ordinarily,
\cs{boxmaxdepth} is set to the maximum dimension
possible in \TeX. It is for instance reduced during some of
the calculations in the plain \TeX\ output routine;
see Chapter~\ref{output}.
%\subsection{Examples}
\subsection{Examples}
%Horizontal boxes are relatively straightforward. Their width is the
%distance between the `beginning' and the `end' of the
%box,
%and consequently the width is not necessarily positive.
%With
%\begin{verbatim}
%\setbox0=\hbox{aa} \setbox1=\hbox{\copy0 \hskip-\wd0}
%\end{verbatim}
%the \cs{box1} has width zero;
%\begin{Disp} \verb-/\box1/-\quad gives\quad
%`{\setbox0=\hbox{aa}\setbox1=\hbox{\copy0 \hskip-\wd0}/\box1/}\kern.75em'
%\end{Disp}
%The height and depth of a horizontal box cannot be negative: in
%\begin{verbatim}
%\setbox0=\hbox{\vrule height 5pt depth 5pt}
%\setbox1=\hbox{\raise 10pt \box0}
%\end{verbatim}
%the \cs{box1} has depth \n{0pt} and height~\n{15pt}
Horizontal boxes are relatively straightforward. Their width is the
distance between the `beginning' and the `end' of the
box,
and consequently the width is not necessarily positive.
With
\begin{verbatim}
\setbox0=\hbox{aa} \setbox1=\hbox{\copy0 \hskip-\wd0}
\end{verbatim}
the \cs{box1} has width zero;
\begin{Disp} \verb-/\box1/-\quad gives\quad
`{\setbox0=\hbox{aa}\setbox1=\hbox{\copy0 \hskip-\wd0}/\box1/}\kern.75em'
\end{Disp}
The height and depth of a horizontal box cannot be negative: in
\begin{verbatim}
\setbox0=\hbox{\vrule height 5pt depth 5pt}
\setbox1=\hbox{\raise 10pt \box0}
\end{verbatim}
the \cs{box1} has depth \n{0pt} and height~\n{15pt}
%Vertical boxes are more troublesome than horizontal boxes.
%Let us first treat their width.
%After
%\begin{verbatim}
%\setbox0=\hbox{\hskip 10pt}
%\end{verbatim}
%the box in the
%\cs{box0} register has a width of \n{10pt}. Defining
%\begin{verbatim}
%\setbox1=\vbox{\moveleft 5pt \copy0}
%\end{verbatim}
%the \cs{box1} will have width \n{5pt}; material to the
%left of the reference point is not accounted for in the
%width of a vertical box. With
%\begin{verbatim}
%\setbox2=\vbox{\moveright 5pt \copy0}
%\end{verbatim}
%the \cs{box2} will have width \n{15pt}.
Vertical boxes are more troublesome than horizontal boxes.
Let us first treat their width.
After
\begin{verbatim}
\setbox0=\hbox{\hskip 10pt}
\end{verbatim}
the box in the
\cs{box0} register has a width of \n{10pt}. Defining
\begin{verbatim}
\setbox1=\vbox{\moveleft 5pt \copy0}
\end{verbatim}
the \cs{box1} will have width \n{5pt}; material to the
left of the reference point is not accounted for in the
width of a vertical box. With
\begin{verbatim}
\setbox2=\vbox{\moveright 5pt \copy0}
\end{verbatim}
the \cs{box2} will have width \n{15pt}.
%The depth of a \cs{vbox} is the depth of the last item if
%that is a box, so
%\begin{verbatim}
%\vbox{\vskip 5pt \hbox{\vrule height 5pt depth 5pt}}
%\end{verbatim}
%has height \n{10pt} and depth \n{5pt},
%and
%\begin{verbatim}
%\vbox{\vskip -5pt \hbox{\vrule height 5pt depth 5pt}}
%\end{verbatim}
%has height \n{0pt} and depth~\n{5pt}.
%With a glue or kern as the last item in the box, the resulting depth
%is zero, so
%\begin{verbatim}
%\vbox{\hbox{\vrule height 5pt depth 5pt}\vskip 5pt}
%\end{verbatim}
%has height \n{15pt} and depth~\n{0pt};
%\begin{verbatim}
%\vbox{\hbox{\vrule height 5pt depth 5pt}\vskip -5pt}
%\end{verbatim}
%has height \n{5pt} and depth~\n{0pt}.
The depth of a \cs{vbox} is the depth of the last item if
that is a box, so
\begin{verbatim}
\vbox{\vskip 5pt \hbox{\vrule height 5pt depth 5pt}}
\end{verbatim}
has height \n{10pt} and depth \n{5pt},
and
\begin{verbatim}
\vbox{\vskip -5pt \hbox{\vrule height 5pt depth 5pt}}
\end{verbatim}
has height \n{0pt} and depth~\n{5pt}.
With a glue or kern as the last item in the box, the resulting depth
is zero, so
\begin{verbatim}
\vbox{\hbox{\vrule height 5pt depth 5pt}\vskip 5pt}
\end{verbatim}
has height \n{15pt} and depth~\n{0pt};
\begin{verbatim}
\vbox{\hbox{\vrule height 5pt depth 5pt}\vskip -5pt}
\end{verbatim}
has height \n{5pt} and depth~\n{0pt}.
%The height of a \cs{vtop} behaves (almost) the same with respect to
%the first item of the box, as the depth of a \cs{vbox} does
%with respect to the last item. Repeating the above examples with
%a \cs{vtop} gives the following:
%\begin{verbatim}
%\vtop{\vskip 5pt \hbox{\vrule height 5pt depth 5pt}}
%\end{verbatim}
%has height \n{0pt} and depth \n{15pt},
%and
%\begin{verbatim}
%\vtop{\vskip -5pt \hbox{\vrule height 5pt depth 5pt}}
%\end{verbatim}
%has height \n{0pt} and depth~\n{5pt};
%\begin{verbatim}
%\vtop{\hbox{\vrule height 5pt depth 5pt} \vskip 5pt}
%\end{verbatim}
%has height \n{5pt} and depth~\n{10pt}, and
%\begin{verbatim}
%\vtop{\hbox{\vrule height 5pt depth 5pt} \vskip -5pt}
%\end{verbatim}
%has height \n{5pt} and depth~\n{0pt}.
The height of a \cs{vtop} behaves (almost) the same with respect to
the first item of the box, as the depth of a \cs{vbox} does
with respect to the last item. Repeating the above examples with
a \cs{vtop} gives the following:
\begin{verbatim}
\vtop{\vskip 5pt \hbox{\vrule height 5pt depth 5pt}}
\end{verbatim}
has height \n{0pt} and depth \n{15pt},
and
\begin{verbatim}
\vtop{\vskip -5pt \hbox{\vrule height 5pt depth 5pt}}
\end{verbatim}
has height \n{0pt} and depth~\n{5pt};
\begin{verbatim}
\vtop{\hbox{\vrule height 5pt depth 5pt} \vskip 5pt}
\end{verbatim}
has height \n{5pt} and depth~\n{10pt}, and
\begin{verbatim}
\vtop{\hbox{\vrule height 5pt depth 5pt} \vskip -5pt}
\end{verbatim}
has height \n{5pt} and depth~\n{0pt}.
%%\point More about box dimensions
%\section{More about box dimensions}
%\point More about box dimensions
\section{More about box dimensions}
%%\spoint Predetermined dimensions
%\subsection{Predetermined dimensions}
%\spoint Predetermined dimensions
\subsection{Predetermined dimensions}
%The size of a box can be specified in advance
%with a \gr{box specification}; see above for the syntax.
%Any glue
%in the box is then set in order to reach the required size.
%Prescribing the size of the box is done by
%\begin{disp}\cs{hbox} \n{to} \gr{dimen} \n{\lb...\rb},
% \cs{vbox} \n{to} \gr{dimen} \n{\lb...\rb}\end{disp}
%If stretchable or shrinkable glue is present in the box,
%it is stretched or shrunk in order to give the box the
%specified size. Associated with this glue setting is a badness value
%(see Chapter~\ref{glue}). If no stretch or shrink \ldash whichever
%is necessary \rdash is present, the resulting box will be underfull
%or overfull respectively. Error reporting for over/underfull
%boxes is treated below.
The size of a box can be specified in advance
with a \gr{box specification}; see above for the syntax.
Any glue
in the box is then set in order to reach the required size.
Prescribing the size of the box is done by
\begin{disp}\cs{hbox} \n{to} \gr{dimen} \n{\lb...\rb},
\cs{vbox} \n{to} \gr{dimen} \n{\lb...\rb}\end{disp}
If stretchable or shrinkable glue is present in the box,
it is stretched or shrunk in order to give the box the
specified size. Associated with this glue setting is a badness value
(see Chapter~\ref{glue}). If no stretch or shrink \ldash whichever
is necessary \rdash is present, the resulting box will be underfull
or overfull respectively. Error reporting for over/underfull
boxes is treated below.
%Another command to let a box have a size other than
%the natural size is
%\begin{disp}\cs{hbox} \n{spread} \gr{dimen} \n{\lb...\rb},
% \cs{vbox} \n{spread} \gr{dimen} \n{\lb...\rb}\end{disp}
%which tells \TeX\ to set the glue in such a way that
%the size of the box is a specified amount more than the
%natural size.
Another command to let a box have a size other than
the natural size is
\begin{disp}\cs{hbox} \n{spread} \gr{dimen} \n{\lb...\rb},
\cs{vbox} \n{spread} \gr{dimen} \n{\lb...\rb}\end{disp}
which tells \TeX\ to set the glue in such a way that
the size of the box is a specified amount more than the
natural size.
%Box specifications for \cs{vtop} vertical boxes are
%somewhat difficult to interpret. \TeX\ constructs a \cs{vtop}
%by first making a \cs{vbox}, including
%glue settings induced by a \gr{box specification};
%then it computes the height and depth by the above rules.
%Glue setting is described in Chapter~\ref{glue}.
Box specifications for \cs{vtop} vertical boxes are
somewhat difficult to interpret. \TeX\ constructs a \cs{vtop}
by first making a \cs{vbox}, including
glue settings induced by a \gr{box specification};
then it computes the height and depth by the above rules.
Glue setting is described in Chapter~\ref{glue}.
%%\spoint Changes to box dimensions
%\subsection{Changes to box dimensions}
%\spoint Changes to box dimensions
\subsection{Changes to box dimensions}
%The dimensions of a box register are accessible by the
%commands \csidx{ht}, \csidx{dp}, and~\csidx{wd};
%for instance \cs{dp13} gives the depth of box~13.
%However, not only can boxes be measured this way;
%by assigning values to these
%dimensions \TeX\ can even be fooled into thinking that