/
l3box.dtx
2113 lines (2113 loc) · 72.4 KB
/
l3box.dtx
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
% \iffalse meta-comment
%
%% File: l3box.dtx Copyright (C) 2005-2019 The LaTeX3 Project
%
% It may be distributed and/or modified under the conditions of the
% LaTeX Project Public License (LPPL), either version 1.3c of this
% license or (at your option) any later version. The latest version
% of this license is in the file
%
% https://www.latex-project.org/lppl.txt
%
% This file is part of the "l3kernel bundle" (The Work in LPPL)
% and all files in that bundle must be distributed together.
%
% -----------------------------------------------------------------------
%
% The development version of the bundle can be found at
%
% https://github.com/latex3/latex3
%
% for those people who are interested.
%
%<*driver>
\documentclass[full,kernel]{l3doc}
\begin{document}
\DocInput{\jobname.dtx}
\end{document}
%</driver>
% \fi
%
% \title{^^A
% The \pkg{l3box} package\\ Boxes^^A
% }
%
% \author{^^A
% The \LaTeX3 Project\thanks
% {^^A
% E-mail:
% \href{mailto:latex-team@latex-project.org}
% {latex-team@latex-project.org}^^A
% }^^A
% }
%
% \date{Released 2019-01-01}
%
% \maketitle
%
% \begin{documentation}
%
% There are three kinds of box operations: horizontal mode denoted
% with prefix |\hbox_|, vertical mode with prefix |\vbox_|, and the
% generic operations working in both modes with prefix |\box_|.
%
% \section{Creating and initialising boxes}
%
% \begin{function}{\box_new:N, \box_new:c}
% \begin{syntax}
% \cs{box_new:N} \meta{box}
% \end{syntax}
% Creates a new \meta{box} or raises an error if the name is
% already taken. The declaration is global. The \meta{box} is
% initially void.
% \end{function}
%
% \begin{function}{\box_clear:N, \box_clear:c, \box_gclear:N, \box_gclear:c}
% \begin{syntax}
% \cs{box_clear:N} \meta{box}
% \end{syntax}
% Clears the content of the \meta{box} by setting the box equal to
% \cs{c_empty_box}.
% \end{function}
%
% \begin{function}
% {\box_clear_new:N, \box_clear_new:c, \box_gclear_new:N, \box_gclear_new:c}
% \begin{syntax}
% \cs{box_clear_new:N} \meta{box}
% \end{syntax}
% Ensures that the \meta{box} exists globally by applying
% \cs{box_new:N} if necessary, then applies
% \cs[index=box_clear:N]{box_(g)clear:N} to leave
% the \meta{box} empty.
% \end{function}
%
% \begin{function}
% {
% \box_set_eq:NN, \box_set_eq:cN, \box_set_eq:Nc, \box_set_eq:cc,
% \box_gset_eq:NN, \box_gset_eq:cN, \box_gset_eq:Nc, \box_gset_eq:cc
% }
% \begin{syntax}
% \cs{box_set_eq:NN} \meta{box_1} \meta{box_2}
% \end{syntax}
% Sets the content of \meta{box_1} equal to that of \meta{box_2}.
% \end{function}
%
% \begin{function}
% {
% \box_set_eq_clear:NN, \box_set_eq_clear:cN,
% \box_set_eq_clear:Nc, \box_set_eq_clear:cc
% }
% \begin{syntax}
% \cs{box_set_eq_clear:NN} \meta{box_1} \meta{box_2}
% \end{syntax}
% Sets the content of \meta{box_1} within the current \TeX{} group
% equal to that of \meta{box_2}, then clears \meta{box_2} globally.
% \end{function}
%
% \begin{function}
% {
% \box_gset_eq_clear:NN, \box_gset_eq_clear:cN,
% \box_gset_eq_clear:Nc, \box_gset_eq_clear:cc
% }
% \begin{syntax}
% \cs{box_gset_eq_clear:NN} \meta{box_1} \meta{box_2}
% \end{syntax}
% Sets the content of \meta{box_1} equal to that of \meta{box_2}, then
% clears \meta{box_2}. These assignments are global.
% \end{function}
%
% \begin{function}[EXP, pTF, added=2012-03-03]
% {\box_if_exist:N, \box_if_exist:c}
% \begin{syntax}
% \cs{box_if_exist_p:N} \meta{box}
% \cs{box_if_exist:NTF} \meta{box} \Arg{true code} \Arg{false code}
% \end{syntax}
% Tests whether the \meta{box} is currently defined. This does not
% check that the \meta{box} really is a box.
% \end{function}
%
% \section{Using boxes}
%
% \begin{function}{\box_use:N, \box_use:c}
% \begin{syntax}
% \cs{box_use:N} \meta{box}
% \end{syntax}
% Inserts the current content of the \meta{box} onto the current
% list for typesetting.
% \begin{texnote}
% This is the \TeX{} primitive \tn{copy}.
% \end{texnote}
% \end{function}
%
% \begin{function}{\box_use_drop:N, \box_use_drop:c}
% \begin{syntax}
% \cs{box_use_drop:N} \meta{box}
% \end{syntax}
% Inserts the current content of the \meta{box} onto the current
% list for typesetting. The \meta{box} is then cleared at the group level the
% box was set at, \emph{i.e.}~the current content is \enquote{dropped} entirely.
% For example, with
% \begin{verbatim}
% \hbox_set:Nn \l_tmpa_box { A }
% \group_begin:
% \hbox_set:Nn \l_tmpa_box { B }
% \group_begin:
% \box_use_drop:N \l_tmpa_box
% \group_end:
% \box_show:N \l_tmpa_box
% \group_end:
% \box_show:N \l_tmpa_box
% \end{verbatim}
% the first use of |\box_show:N| will show an entirely cleared (void) box, and the
% second will show the letter |A| in the box.
%
% This function is useful as boxes can contain an open-ended amount of material. As
% such, they can have a significant memory impact on \TeX{}. At the same time, it is
% often the case that once a box has been inserted, it is no longer needed at all.
% Using |\box_use_drop:N| in these circumstances therefore offers improved memory
% use and performance. It should therefore be preferred over \cs{box_use:N} where
% it is clear that the content is no longer needed in the variable.
% \begin{texnote}
% This is the \TeX{} primitive \tn{box}.
% \end{texnote}
% \end{function}
%
% \begin{function}{\box_move_right:nn, \box_move_left:nn}
% \begin{syntax}
% \cs{box_move_right:nn} \Arg{dimexpr} \Arg{box function}
% \end{syntax}
% This function operates in vertical mode, and inserts the
% material specified by the \meta{box function}
% such that its reference point is displaced horizontally by the given
% \meta{dimexpr} from the reference point for typesetting, to the right
% or left as appropriate. The \meta{box function} should be
% a box operation such as |\box_use:N \<box>| or a \enquote{raw}
% box specification such as |\vbox:n { xyz }|.
% \end{function}
%
% \begin{function}{\box_move_up:nn, \box_move_down:nn}
% \begin{syntax}
% \cs{box_move_up:nn} \Arg{dimexpr} \Arg{box function}
% \end{syntax}
% This function operates in horizontal mode, and inserts the
% material specified by the \meta{box function}
% such that its reference point is displaced vertically by the given
% \meta{dimexpr} from the reference point for typesetting, up
% or down as appropriate. The \meta{box function} should be
% a box operation such as |\box_use:N \<box>| or a \enquote{raw}
% box specification such as |\vbox:n { xyz }|.
% \end{function}
%
% \section{Measuring and setting box dimensions}
%
% \begin{function}{\box_dp:N, \box_dp:c}
% \begin{syntax}
% \cs{box_dp:N} \meta{box}
% \end{syntax}
% Calculates the depth (below the baseline) of the \meta{box}
% in a form suitable for use in a \meta{dimension expression}.
% \begin{texnote}
% This is the \TeX{} primitive \tn{dp}.
% \end{texnote}
% \end{function}
%
% \begin{function}{\box_ht:N, \box_ht:c}
% \begin{syntax}
% \cs{box_ht:N} \meta{box}
% \end{syntax}
% Calculates the height (above the baseline) of the \meta{box}
% in a form suitable for use in a \meta{dimension expression}.
% \begin{texnote}
% This is the \TeX{} primitive \tn{ht}.
% \end{texnote}
% \end{function}
%
% \begin{function}{\box_wd:N, \box_wd:c}
% \begin{syntax}
% \cs{box_wd:N} \meta{box}
% \end{syntax}
% Calculates the width of the \meta{box} in a form
% suitable for use in a \meta{dimension expression}.
% \begin{texnote}
% This is the \TeX{} primitive \tn{wd}.
% \end{texnote}
% \end{function}
%
% \begin{function}[updated = 2011-10-22]{\box_set_dp:Nn, \box_set_dp:cn}
% \begin{syntax}
% \cs{box_set_dp:Nn} \meta{box} \Arg{dimension expression}
% \end{syntax}
% Set the depth (below the baseline) of the \meta{box} to the value of
% the \Arg{dimension expression}. This is a global assignment.
% \end{function}
%
% \begin{function}[updated = 2011-10-22]{\box_set_ht:Nn, \box_set_ht:cn}
% \begin{syntax}
% \cs{box_set_ht:Nn} \meta{box} \Arg{dimension expression}
% \end{syntax}
% Set the height (above the baseline) of the \meta{box} to the value of
% the \Arg{dimension expression}. This is a global assignment.
% \end{function}
%
% \begin{function}[updated = 2011-10-22]{\box_set_wd:Nn, \box_set_wd:cn}
% \begin{syntax}
% \cs{box_set_wd:Nn} \meta{box} \Arg{dimension expression}
% \end{syntax}
% Set the width of the \meta{box} to the value of the
% \Arg{dimension expression}. This is a global assignment.
% \end{function}
%
% \section{Box conditionals}
%
% \begin{function}[EXP,pTF]{\box_if_empty:N, \box_if_empty:c}
% \begin{syntax}
% \cs{box_if_empty_p:N} \meta{box}
% \cs{box_if_empty:NTF} \meta{box} \Arg{true code} \Arg{false code}
% \end{syntax}
% Tests if \meta{box} is a empty (equal to \cs{c_empty_box}).
% \end{function}
%
% \begin{function}[EXP,pTF]{\box_if_horizontal:N, \box_if_horizontal:c}
% \begin{syntax}
% \cs{box_if_horizontal_p:N} \meta{box}
% \cs{box_if_horizontal:NTF} \meta{box} \Arg{true code} \Arg{false code}
% \end{syntax}
% Tests if \meta{box} is a horizontal box.
% \end{function}
%
% \begin{function}[EXP,pTF]{\box_if_vertical:N, \box_if_vertical:c}
% \begin{syntax}
% \cs{box_if_vertical_p:N} \meta{box}
% \cs{box_if_vertical:NTF} \meta{box} \Arg{true code} \Arg{false code}
% \end{syntax}
% Tests if \meta{box} is a vertical box.
% \end{function}
%
% \section{The last box inserted}
%
% \begin{function}
% {
% \box_set_to_last:N, \box_set_to_last:c,
% \box_gset_to_last:N, \box_gset_to_last:c
% }
% \begin{syntax}
% \cs{box_set_to_last:N} \meta{box}
% \end{syntax}
% Sets the \meta{box} equal to the last item (box) added to the current
% partial list, removing the item from the list at the same time. When
% applied to the main vertical list, the \meta{box} is always void as
% it is not possible to recover the last added item.
% \end{function}
%
% \section{Constant boxes}
%
% \begin{variable}[updated = 2012-11-04]{\c_empty_box}
% This is a permanently empty box, which is neither set as horizontal
% nor vertical.
% \begin{texnote}
% At the \TeX{} level this is a void box.
% \end{texnote}
% \end{variable}
%
% \section{Scratch boxes}
%
% \begin{variable}[updated = 2012-11-04]{\l_tmpa_box, \l_tmpb_box}
% Scratch boxes for local assignment. These are never used by
% the kernel code, and so are safe for use with any \LaTeX3-defined
% function. However, they may be overwritten by other non-kernel
% code and so should only be used for short-term storage.
% \end{variable}
%
% \begin{variable}{\g_tmpa_box, \g_tmpb_box}
% Scratch boxes for global assignment. These are never used by
% the kernel code, and so are safe for use with any \LaTeX3-defined
% function. However, they may be overwritten by other non-kernel
% code and so should only be used for short-term storage.
% \end{variable}
%
% \section{Viewing box contents}
%
% \begin{function}[updated = 2012-05-11]{\box_show:N, \box_show:c}
% \begin{syntax}
% \cs{box_show:N} \meta{box}
% \end{syntax}
% Shows full details of the content of the \meta{box} in the terminal.
% \end{function}
%
% \begin{function}[added = 2012-05-11]{\box_show:Nnn, \box_show:cnn}
% \begin{syntax}
% \cs{box_show:Nnn} \meta{box} \Arg{intexpr_1} \Arg{intexpr_2}
% \end{syntax}
% Display the contents of \meta{box} in the terminal, showing the first
% \meta{intexpr_1} items of the box, and descending into \meta{intexpr_2}
% group levels.
% \end{function}
%
% \begin{function}[added = 2012-05-11]{\box_log:N, \box_log:c}
% \begin{syntax}
% \cs{box_log:N} \meta{box}
% \end{syntax}
% Writes full details of the content of the \meta{box} to the log.
% \end{function}
%
% \begin{function}[added = 2012-05-11]{\box_log:Nnn, \box_log:cnn}
% \begin{syntax}
% \cs{box_log:Nnn} \meta{box} \Arg{intexpr_1} \Arg{intexpr_2}
% \end{syntax}
% Writes the contents of \meta{box} to the log, showing the first
% \meta{intexpr_1} items of the box, and descending into \meta{intexpr_2}
% group levels.
% \end{function}
%
% \section{Boxes and color}
%
% All \LaTeX{}3 boxes are \enquote{color safe}: a color set inside the box
% stops applying after the end of the box has occurred.
%
% \section{Horizontal mode boxes}
%
% \begin{function}[updated = 2017-04-05]{\hbox:n}
% \begin{syntax}
% \cs{hbox:n} \Arg{contents}
% \end{syntax}
% Typesets the \meta{contents} into a horizontal box of natural
% width and then includes this box in the current list for typesetting.
% \end{function}
%
% \begin{function}[updated = 2017-04-05]{\hbox_to_wd:nn}
% \begin{syntax}
% \cs{hbox_to_wd:nn} \Arg{dimexpr} \Arg{contents}
% \end{syntax}
% Typesets the \meta{contents} into a horizontal box of width
% \meta{dimexpr} and then includes this box in the current list for
% typesetting.
% \end{function}
%
% \begin{function}[updated = 2017-04-05]{\hbox_to_zero:n}
% \begin{syntax}
% \cs{hbox_to_zero:n} \Arg{contents}
% \end{syntax}
% Typesets the \meta{contents} into a horizontal box of zero width
% and then includes this box in the current list for typesetting.
% \end{function}
%
% \begin{function}[updated = 2017-04-05]
% {\hbox_set:Nn, \hbox_set:cn, \hbox_gset:Nn, \hbox_gset:cn}
% \begin{syntax}
% \cs{hbox_set:Nn} \meta{box} \Arg{contents}
% \end{syntax}
% Typesets the \meta{contents} at natural width and then stores the
% result inside the \meta{box}.
% \end{function}
%
% \begin{function}[updated = 2017-04-05]
% {
% \hbox_set_to_wd:Nnn, \hbox_set_to_wd:cnn,
% \hbox_gset_to_wd:Nnn, \hbox_gset_to_wd:cnn
% }
% \begin{syntax}
% \cs{hbox_set_to_wd:Nnn} \meta{box} \Arg{dimexpr} \Arg{contents}
% \end{syntax}
% Typesets the \meta{contents} to the width given by the \meta{dimexpr}
% and then stores the result inside the \meta{box}.
% \end{function}
%
% \begin{function}[updated = 2017-04-05]{\hbox_overlap_right:n}
% \begin{syntax}
% \cs{hbox_overlap_right:n} \Arg{contents}
% \end{syntax}
% Typesets the \meta{contents} into a horizontal box of zero width
% such that material protrudes to the right of the insertion point.
% \end{function}
%
% \begin{function}[updated = 2017-04-05]{\hbox_overlap_left:n}
% \begin{syntax}
% \cs{hbox_overlap_left:n} \Arg{contents}
% \end{syntax}
% Typesets the \meta{contents} into a horizontal box of zero width
% such that material protrudes to the left of the insertion point.
% \end{function}
%
% \begin{function}[updated = 2017-04-05]
% {
% \hbox_set:Nw, \hbox_set:cw,
% \hbox_set_end:,
% \hbox_gset:Nw, \hbox_gset:cw,
% \hbox_gset_end:
% }
% \begin{syntax}
% \cs{hbox_set:Nw} \meta{box} \meta{contents} \cs{hbox_set_end:}
% \end{syntax}
% Typesets the \meta{contents} at natural width and then stores the
% result inside the \meta{box}. In contrast
% to \cs{hbox_set:Nn} this function does not absorb the argument
% when finding the \meta{content}, and so can be used in circumstances
% where the \meta{content} may not be a simple argument.
% \end{function}
%
% \begin{function}[added = 2017-06-08]
% {
% \hbox_set_to_wd:Nnw, \hbox_set_to_wd:cnw,
% \hbox_gset_to_wd:Nnw, \hbox_gset_to_wd:cnw
% }
% \begin{syntax}
% \cs{hbox_set_to_wd:Nnw} \meta{box} \Arg{dimexpr} \meta{contents} \cs{hbox_set_end:}
% \end{syntax}
% Typesets the \meta{contents} to the width given by the \meta{dimexpr}
% and then stores the result inside the \meta{box}. In contrast
% to \cs{hbox_set_to_wd:Nnn} this function does not absorb the argument
% when finding the \meta{content}, and so can be used in circumstances
% where the \meta{content} may not be a simple argument
% \end{function}
%
% \begin{function}{\hbox_unpack:N, \hbox_unpack:c}
% \begin{syntax}
% \cs{hbox_unpack:N} \meta{box}
% \end{syntax}
% Unpacks the content of the horizontal \meta{box}, retaining any stretching
% or shrinking applied when the \meta{box} was set.
% \begin{texnote}
% This is the \TeX{} primitive \tn{unhcopy}.
% \end{texnote}
% \end{function}
%
% \begin{function}{\hbox_unpack_clear:N, \hbox_unpack_clear:c}
% \begin{syntax}
% \cs{hbox_unpack_clear:N} \meta{box}
% \end{syntax}
% Unpacks the content of the horizontal \meta{box}, retaining any stretching
% or shrinking applied when the \meta{box} was set. The \meta{box} is
% then cleared globally.
% \begin{texnote}
% This is the \TeX{} primitive \tn{unhbox}.
% \end{texnote}
% \end{function}
%
% \section{Vertical mode boxes}
%
% Vertical boxes inherit their baseline from their contents. The
% standard case is that the baseline of the box is at the same position
% as that of the last item added to the box. This means that the box
% has no depth unless the last item added to it had depth. As a
% result most vertical boxes have a large height value and small or
% zero depth. The exception are |_top| boxes, where the reference point
% is that of the first item added. These tend to have a large depth and
% small height, although the latter is typically non-zero.
%
% \begin{function}[updated = 2017-04-05]{\vbox:n}
% \begin{syntax}
% \cs{vbox:n} \Arg{contents}
% \end{syntax}
% Typesets the \meta{contents} into a vertical box of natural height
% and includes this box in the current list for typesetting.
% \end{function}
%
% \begin{function}[updated = 2017-04-05]{\vbox_top:n}
% \begin{syntax}
% \cs{vbox_top:n} \Arg{contents}
% \end{syntax}
% Typesets the \meta{contents} into a vertical box of natural height
% and includes this box in the current list for typesetting. The
% baseline of the box is equal to that of the \emph{first}
% item added to the box.
% \end{function}
%
% \begin{function}[updated = 2017-04-05]{\vbox_to_ht:nn}
% \begin{syntax}
% \cs{vbox_to_ht:nn} \Arg{dimexpr} \Arg{contents}
% \end{syntax}
% Typesets the \meta{contents} into a vertical box of height
% \meta{dimexpr} and then includes this box in the current list for
% typesetting.
% \end{function}
%
% \begin{function}[updated = 2017-04-05]{\vbox_to_zero:n}
% \begin{syntax}
% \cs{vbox_to_zero:n} \Arg{contents}
% \end{syntax}
% Typesets the \meta{contents} into a vertical box of zero height
% and then includes this box in the current list for typesetting.
% \end{function}
%
% \begin{function}[updated = 2017-04-05]
% {\vbox_set:Nn, \vbox_set:cn, \vbox_gset:Nn, \vbox_gset:cn}
% \begin{syntax}
% \cs{vbox_set:Nn} \meta{box} \Arg{contents}
% \end{syntax}
% Typesets the \meta{contents} at natural height and then stores the
% result inside the \meta{box}.
% \end{function}
%
% \begin{function}[updated = 2017-04-05]
% {\vbox_set_top:Nn, \vbox_set_top:cn, \vbox_gset_top:Nn, \vbox_gset_top:cn}
% \begin{syntax}
% \cs{vbox_set_top:Nn} \meta{box} \Arg{contents}
% \end{syntax}
% Typesets the \meta{contents} at natural height and then stores the
% result inside the \meta{box}. The baseline of the box is equal
% to that of the \emph{first} item added to the box.
% \end{function}
%
% \begin{function}[updated = 2017-04-05]
% {
% \vbox_set_to_ht:Nnn, \vbox_set_to_ht:cnn,
% \vbox_gset_to_ht:Nnn, \vbox_gset_to_ht:cnn
% }
% \begin{syntax}
% \cs{vbox_set_to_ht:Nnn} \meta{box} \Arg{dimexpr} \Arg{contents}
% \end{syntax}
% Typesets the \meta{contents} to the height given by the
% \meta{dimexpr} and then stores the result inside the \meta{box}.
% \end{function}
%
% \begin{function}[updated = 2017-04-05]
% {
% \vbox_set:Nw, \vbox_set:cw,
% \vbox_set_end:,
% \vbox_gset:Nw, \vbox_gset:cw,
% \vbox_gset_end:
% }
% \begin{syntax}
% \cs{vbox_set:Nw} \meta{box} \meta{contents} \cs{vbox_set_end:}
% \end{syntax}
% Typesets the \meta{contents} at natural height and then stores the
% result inside the \meta{box}. In contrast
% to \cs{vbox_set:Nn} this function does not absorb the argument
% when finding the \meta{content}, and so can be used in circumstances
% where the \meta{content} may not be a simple argument.
% \end{function}
%
% \begin{function}[added = 2017-06-08]
% {
% \vbox_set_to_ht:Nnw, \vbox_set_to_ht:cnw,
% \vbox_gset_to_ht:Nnw, \vbox_gset_to_ht:cnw
% }
% \begin{syntax}
% \cs{vbox_set_to_ht:Nnw} \meta{box} \Arg{dimexpr} \meta{contents} \cs{vbox_set_end:}
% \end{syntax}
% Typesets the \meta{contents} to the height given by the \meta{dimexpr}
% and then stores the result inside the \meta{box}. In contrast
% to \cs{vbox_set_to_ht:Nnn} this function does not absorb the argument
% when finding the \meta{content}, and so can be used in circumstances
% where the \meta{content} may not be a simple argument
% \end{function}
%
%
% \begin{function}[updated = 2018-12-29]
% {
% \vbox_set_split_to_ht:NNn, \vbox_set_split_to_ht:cNn,
% \vbox_set_split_to_ht:Ncn, \vbox_set_split_to_ht:ccn,
% \vbox_gset_split_to_ht:NNn, \vbox_gset_split_to_ht:cNn,
% \vbox_gset_split_to_ht:Ncn, \vbox_gset_split_to_ht:ccn
% }
% \begin{syntax}
% \cs{vbox_set_split_to_ht:NNn} \meta{box_1} \meta{box_2} \Arg{dimexpr}
% \end{syntax}
% Sets \meta{box_1} to contain material to the height given by the
% \meta{dimexpr} by removing content from the top of \meta{box_2}
% (which must be a vertical box).
% \end{function}
%
% \begin{function}{\vbox_unpack:N, \vbox_unpack:c}
% \begin{syntax}
% \cs{vbox_unpack:N} \meta{box}
% \end{syntax}
% Unpacks the content of the vertical \meta{box}, retaining any stretching
% or shrinking applied when the \meta{box} was set.
% \begin{texnote}
% This is the \TeX{} primitive \tn{unvcopy}.
% \end{texnote}
% \end{function}
%
% \begin{function}{\vbox_unpack_clear:N, \vbox_unpack_clear:c}
% \begin{syntax}
% \cs{vbox_unpack:N} \meta{box}
% \end{syntax}
% Unpacks the content of the vertical \meta{box}, retaining any stretching
% or shrinking applied when the \meta{box} was set. The \meta{box}
% is then cleared globally.
% \begin{texnote}
% This is the \TeX{} primitive \tn{unvbox}.
% \end{texnote}
% \end{function}
%
% \section{Affine transformations}
%
% Affine transformations are changes which (informally) preserve straight
% lines. Simple translations are affine transformations, but are better handled
% in \TeX{} by doing the translation first, then inserting an unmodified box.
% On the other hand, rotation and resizing of boxed material can best be
% handled by modifying boxes. These transformations are described here.
%
% \begin{function}[added = 2017-04-04]
% {\box_autosize_to_wd_and_ht:Nnn, \box_autosize_to_wd_and_ht:cnn}
% \begin{syntax}
% \cs{box_autosize_to_wd_and_ht:Nnn} \meta{box} \Arg{x-size} \Arg{y-size}
% \end{syntax}
% Resizes the \meta{box} to fit within the given \meta{x-size} (horizontally)
% and \meta{y-size} (vertically); both of the sizes are dimension
% expressions. The \meta{y-size} is the height only: it does not include any
% depth. The updated \meta{box} is an |hbox|, irrespective of the nature
% of the \meta{box} before the resizing is applied. The final size of the
% \meta{box} is the smaller of \Arg{x-size} and \Arg{y-size},
% \emph{i.e.}~the result fits within the dimensions specified. Negative
% sizes cause the material in the \meta{box} to be reversed in direction,
% but the reference point of the \meta{box} is unchanged. Thus a negative
% \meta{y-size} results in the \meta{box} having a depth dependent on the
% height of the original and \emph{vice versa}. The resizing applies within
% the current \TeX{} group level.
% \end{function}
%
% \begin{function}[added = 2017-04-04]
% {\box_autosize_to_wd_and_ht_plus_dp:Nnn, \box_autosize_to_wd_and_ht_plus_dp:cnn}
% \begin{syntax}
% \cs{box_autosize_to_wd_and_ht_plus_dp:Nnn} \meta{box} \Arg{x-size} \Arg{y-size}
% \end{syntax}
% Resizes the \meta{box} to fit within the given \meta{x-size} (horizontally)
% and \meta{y-size} (vertically); both of the sizes are dimension
% expressions. The \meta{y-size} is the total vertical size (height plus
% depth). The updated \meta{box} is an |hbox|, irrespective of the nature
% of the \meta{box} before the resizing is applied. The final size of the
% \meta{box} is the smaller of \Arg{x-size} and \Arg{y-size},
% \emph{i.e.}~the result fits within the dimensions specified. Negative
% sizes cause the material in the \meta{box} to be reversed in direction,
% but the reference point of the \meta{box} is unchanged. Thus a negative
% \meta{y-size} results in the \meta{box} having a depth dependent on the
% height of the original and \emph{vice versa}. The resizing applies within
% the current \TeX{} group level.
% \end{function}
%
% \begin{function}
% {\box_resize_to_ht:Nn, \box_resize_to_ht:cn}
% \begin{syntax}
% \cs{box_resize_to_ht:Nn} \meta{box} \Arg{y-size}
% \end{syntax}
% Resizes the \meta{box} to \meta{y-size} (vertically), scaling the horizontal
% size by the same amount; \meta{y-size} is a dimension expression. The
% \meta{y-size} is the height only: it does not include any depth. The updated
% \meta{box} is an |hbox|, irrespective of the nature of the \meta{box}
% before the resizing is applied. A negative \meta{y-size} causes the
% material in the \meta{box} to be reversed in direction, but the reference
% point of the \meta{box} is unchanged. Thus a negative \meta{y-size}
% results in the \meta{box} having a depth dependent on the height of the
% original and \emph{vice versa}. The resizing applies within the current
% \TeX{} group level.
% \end{function}
%
% \begin{function}
% {\box_resize_to_ht_plus_dp:Nn, \box_resize_to_ht_plus_dp:cn}
% \begin{syntax}
% \cs{box_resize_to_ht_plus_dp:Nn} \meta{box} \Arg{y-size}
% \end{syntax}
% Resizes the \meta{box} to \meta{y-size} (vertically), scaling the horizontal
% size by the same amount; \meta{y-size} is a dimension expression. The
% \meta{y-size} is the total vertical size (height plus depth). The updated
% \meta{box} is an |hbox|, irrespective of the nature of the \meta{box}
% before the resizing is applied. A negative \meta{y-size} causes
% the material in the \meta{box} to be reversed in direction, but the
% reference point of the \meta{box} is unchanged. Thus a negative
% \meta{y-size} results in the \meta{box} having a depth dependent on the
% height of the original and \emph{vice versa}. The resizing applies within
% the current \TeX{} group level.
% \end{function}
%
% \begin{function}{\box_resize_to_wd:Nn, \box_resize_to_wd:cn}
% \begin{syntax}
% \cs{box_resize_to_wd:Nn} \meta{box} \Arg{x-size}
% \end{syntax}
% Resizes the \meta{box} to \meta{x-size} (horizontally), scaling the vertical
% size by the same amount; \meta{x-size} is a dimension expression. The updated
% \meta{box} is an |hbox|, irrespective of the nature of the \meta{box}
% before the resizing is applied. A negative \meta{x-size} causes the
% material in the \meta{box} to be reversed in direction, but the reference
% point of the \meta{box} is unchanged. Thus a negative \meta{x-size}
% results in the \meta{box} having a depth dependent on the height of the
% original and \emph{vice versa}. The resizing applies within the current
% \TeX{} group level.
% \end{function}
%
% \begin{function}[added = 2014-07-03]
% {\box_resize_to_wd_and_ht:Nnn, \box_resize_to_wd_and_ht:cnn}
% \begin{syntax}
% \cs{box_resize_to_wd_and_ht:Nnn} \meta{box} \Arg{x-size} \Arg{y-size}
% \end{syntax}
% Resizes the \meta{box} to \meta{x-size} (horizontally) and \meta{y-size}
% (vertically): both of the sizes are dimension expressions. The
% \meta{y-size} is the height only and does not include any depth. The updated
% \meta{box} is an |hbox|, irrespective of the nature of the \meta{box}
% before the resizing is applied. Negative sizes cause the material in
% the \meta{box} to be reversed in direction, but the reference point of the
% \meta{box} is unchanged. Thus a negative \meta{y-size} results in
% the \meta{box} having a depth dependent on the height of the original and
% \emph{vice versa}. The resizing applies within the current \TeX{} group
% level.
% \end{function}
%
% \begin{function}[added = 2017-04-06]
% {\box_resize_to_wd_and_ht_plus_dp:Nnn, \box_resize_to_wd_and_ht_plus_dp:cnn}
% \begin{syntax}
% \cs{box_resize_to_wd_and_ht_plus_dp:Nnn} \meta{box} \Arg{x-size} \Arg{y-size}
% \end{syntax}
% Resizes the \meta{box} to \meta{x-size} (horizontally) and \meta{y-size}
% (vertically): both of the sizes are dimension expressions. The
% \meta{y-size} is the total vertical size (height plus depth). The updated
% \meta{box} is an |hbox|, irrespective of the nature of the \meta{box}
% before the resizing is applied. Negative sizes cause the material in
% the \meta{box} to be reversed in direction, but the reference point of the
% \meta{box} is unchanged. Thus a negative \meta{y-size} results in
% the \meta{box} having a depth dependent on the height of the original and
% \emph{vice versa}. The resizing applies within the current \TeX{} group
% level.
% \end{function}
%
% \begin{function}{\box_rotate:Nn, \box_rotate:cn}
% \begin{syntax}
% \cs{box_rotate:Nn} \meta{box} \Arg{angle}
% \end{syntax}
% Rotates the \meta{box} by \meta{angle} (in degrees) anti-clockwise about
% its reference point. The reference point of the updated box is moved
% horizontally such that it is at the left side of the smallest rectangle
% enclosing the rotated material. The updated \meta{box} is an |hbox|,
% irrespective of the nature of the \meta{box} before the rotation is applied.
% The rotation applies within the current \TeX{} group level.
% \end{function}
%
% \begin{function}{\box_scale:Nnn, \box_scale:cnn}
% \begin{syntax}
% \cs{box_scale:Nnn} \meta{box} \Arg{x-scale} \Arg{y-scale}
% \end{syntax}
% Scales the \meta{box} by factors \meta{x-scale} and \meta{y-scale} in
% the horizontal and vertical directions, respectively (both scales are
% integer expressions). The updated \meta{box} is an |hbox|, irrespective
% of the nature of the \meta{box} before the scaling is applied. Negative
% scalings cause the material in the \meta{box} to be reversed in
% direction, but the reference point of the \meta{box} is unchanged.
% Thus a negative \meta{y-scale} results in the \meta{box} having a depth
% dependent on the height of the original and \emph{vice versa}. The resizing
% applies within the current \TeX{} group level.
% \end{function}
%
% \section{Primitive box conditionals}
%
% \begin{function}[EXP]{\if_hbox:N}
% \begin{syntax}
% \cs{if_hbox:N} \meta{box}
% ~~\meta{true code}
% \cs{else:}
% ~~\meta{false code}
% \cs{fi:}
% \end{syntax}
% Tests is \meta{box} is a horizontal box.
% \begin{texnote}
% This is the \TeX{} primitive \tn{ifhbox}.
% \end{texnote}
% \end{function}
%
% \begin{function}[EXP]{\if_vbox:N}
% \begin{syntax}
% \cs{if_vbox:N} \meta{box}
% ~~\meta{true code}
% \cs{else:}
% ~~\meta{false code}
% \cs{fi:}
% \end{syntax}
% Tests is \meta{box} is a vertical box.
% \begin{texnote}
% This is the \TeX{} primitive \tn{ifvbox}.
% \end{texnote}
% \end{function}
%
% \begin{function}[EXP]{\if_box_empty:N}
% \begin{syntax}
% \cs{if_box_empty:N} \meta{box}
% ~~\meta{true code}
% \cs{else:}
% ~~\meta{false code}
% \cs{fi:}
% \end{syntax}
% Tests is \meta{box} is an empty (void) box.
% \begin{texnote}
% This is the \TeX{} primitive \tn{ifvoid}.
% \end{texnote}
% \end{function}
%
% \end{documentation}
%
% \begin{implementation}
%
% \section{\pkg{l3box} implementation}
%
% \begin{macrocode}
%<*initex|package>
% \end{macrocode}
%
% \begin{macrocode}
%<@@=box>
% \end{macrocode}
%
% \subsection{Support code}
%
% \begin{macro}{\@@_dim_eval:w}
% \begin{macro}{\@@_dim_eval:n}
% Evaluating a dimension expression expandably. The only
% difference with \cs{dim_eval:n} is the lack of \cs{dim_use:N}, to
% produce an internal dimension rather than expand it into characters.
% \begin{macrocode}
\cs_new_eq:NN \@@_dim_eval:w \tex_dimexpr:D
\__kernel_patch_args:nNNpn
{
{
\__kernel_chk_expr:nNnN {#1}
\@@_dim_eval:w { } \@@_dim_eval:n
}
}
\cs_new:Npn \@@_dim_eval:n #1
{ \@@_dim_eval:w #1 \scan_stop: }
% \end{macrocode}
% \end{macro}
% \end{macro}
%
% \subsection{Creating and initialising boxes}
%
% \TestFiles{m3box001.lvt}
%
% \begin{macro}{\box_new:N, \box_new:c}
% Defining a new \meta{box} register: remember that box $255$ is not
% generally available.
% \begin{macrocode}
%<*package>
\cs_new_protected:Npn \box_new:N #1
{
\__kernel_chk_if_free_cs:N #1
\cs:w newbox \cs_end: #1
}
%</package>
\cs_generate_variant:Nn \box_new:N { c }
% \end{macrocode}
%
% \begin{macro}{\box_clear:N, \box_clear:c}
% \begin{macro}{\box_gclear:N, \box_gclear:c}
% \testfile*
% Clear a \meta{box} register.
% \begin{macrocode}
\cs_new_protected:Npn \box_clear:N #1
{ \box_set_eq:NN #1 \c_empty_box }
\cs_new_protected:Npn \box_gclear:N #1
{ \box_gset_eq:NN #1 \c_empty_box }
\cs_generate_variant:Nn \box_clear:N { c }
\cs_generate_variant:Nn \box_gclear:N { c }
% \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\box_clear_new:N, \box_clear_new:c}
% \begin{macro}{\box_gclear_new:N, \box_gclear_new:c}
% \testfile*
% Clear or new.
% \begin{macrocode}
\cs_new_protected:Npn \box_clear_new:N #1
{ \box_if_exist:NTF #1 { \box_clear:N #1 } { \box_new:N #1 } }
\cs_new_protected:Npn \box_gclear_new:N #1
{ \box_if_exist:NTF #1 { \box_gclear:N #1 } { \box_new:N #1 } }
\cs_generate_variant:Nn \box_clear_new:N { c }
\cs_generate_variant:Nn \box_gclear_new:N { c }
% \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}
% {\box_set_eq:NN, \box_set_eq:cN, \box_set_eq:Nc, \box_set_eq:cc}
% \testfile*
% \begin{macro}
% {\box_gset_eq:NN, \box_gset_eq:cN, \box_gset_eq:Nc, \box_gset_eq:cc}
% \testfile*
% Assigning the contents of a box to be another box.
% \begin{macrocode}
\__kernel_patch:nnNNpn { \__kernel_chk_var_local:N #1 } { }
\cs_new_protected:Npn \box_set_eq:NN #1#2
{ \tex_setbox:D #1 \tex_copy:D #2 }
\__kernel_patch:nnNNpn { \__kernel_chk_var_global:N #1 } { }
\cs_new_protected:Npn \box_gset_eq:NN #1#2
{ \tex_global:D \tex_setbox:D #1 \tex_copy:D #2 }
\cs_generate_variant:Nn \box_set_eq:NN { c , Nc , cc }
\cs_generate_variant:Nn \box_gset_eq:NN { c , Nc , cc }
% \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}
% {
% \box_set_eq_clear:NN, \box_set_eq_clear:cN,
% \box_set_eq_clear:Nc, \box_set_eq_clear:cc
% }
% \testfile*
% \begin{macro}
% {
% \box_gset_eq_clear:NN, \box_gset_eq_clear:cN,
% \box_gset_eq_clear:Nc, \box_gset_eq_clear:cc
% }
% \testfile*
% Assigning the contents of a box to be another box.
% This clears the second box globally (that's how \TeX{} does it).
% \begin{macrocode}
\__kernel_patch:nnNNpn { \__kernel_chk_var_local:N #1 } { }
\cs_new_protected:Npn \box_set_eq_clear:NN #1#2
{ \tex_setbox:D #1 \tex_box:D #2 }
\__kernel_patch:nnNNpn { \__kernel_chk_var_global:N #1 } { }
\cs_new_protected:Npn \box_gset_eq_clear:NN #1#2
{ \tex_global:D \tex_setbox:D #1 \tex_box:D #2 }
\cs_generate_variant:Nn \box_set_eq_clear:NN { c , Nc , cc }
\cs_generate_variant:Nn \box_gset_eq_clear:NN { c , Nc , cc }
% \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}[pTF]{\box_if_exist:N, \box_if_exist:c}
% Copies of the \texttt{cs} functions defined in \pkg{l3basics}.
% \begin{macrocode}
\prg_new_eq_conditional:NNn \box_if_exist:N \cs_if_exist:N
{ TF , T , F , p }
\prg_new_eq_conditional:NNn \box_if_exist:c \cs_if_exist:c
{ TF , T , F , p }
% \end{macrocode}
% \end{macro}
%
% \subsection{Measuring and setting box dimensions}
%
% \begin{macro}{\box_ht:N, \box_ht:c}
% \begin{macro}{\box_dp:N, \box_dp:c}
% \begin{macro}{\box_wd:N, \box_wd:c}
% \testfile*
% Accessing the height, depth, and width of a \meta{box} register.
% \begin{macrocode}
\cs_new_eq:NN \box_ht:N \tex_ht:D
\cs_new_eq:NN \box_dp:N \tex_dp:D
\cs_new_eq:NN \box_wd:N \tex_wd:D
\cs_generate_variant:Nn \box_ht:N { c }
\cs_generate_variant:Nn \box_dp:N { c }
\cs_generate_variant:Nn \box_wd:N { c }
% \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\box_set_ht:Nn, \box_set_ht:cn}
% \begin{macro}{\box_set_dp:Nn, \box_set_dp:cn}
% \begin{macro}{\box_set_wd:Nn, \box_set_wd:cn}
% Setting the size is easy: all primitive work. These primitives are not
% expandable, so the derived functions are not either.
% When debugging, the dimension expression |#2| is surrounded by
% parentheses to catch early termination.