summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/expl3/l3box.dtx
blob: fbf531008d2046de398624ce6ae12dd9657103d4 (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
% \iffalse
%% File: l3box.dtx Copyright (C) 2005-2011 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
%%
%%    http://www.latex-project.org/lppl.txt
%%
%% This file is part of the ``expl3 bundle'' (The Work in LPPL)
%% and all files in that bundle must be distributed together.
%%
%% The released version of this bundle is available from CTAN.
%%
%% -----------------------------------------------------------------------
%%
%% The development version of the bundle can be found at
%%
%%    http://www.latex-project.org/svnroot/experimental/trunk/
%%
%% for those people who are interested.
%%
%%%%%%%%%%%
%% NOTE: %%
%%%%%%%%%%%
%%
%%   Snapshots taken from the repository represent work in progress and may
%%   not work or may contain conflicting material!  We therefore ask
%%   people _not_ to put them into distributions, archives, etc. without
%%   prior consultation with the LaTeX Project Team.
%%
%% -----------------------------------------------------------------------
%
%<*driver|package>
\RequirePackage{l3names}
%</driver|package>
%\fi
\GetIdInfo$Id: l3box.dtx 2178 2011-03-06 09:03:44Z mittelba $
          {L3 Experimental Box module}
%\iffalse
%<*driver>
%\fi
\ProvidesFile{\filename.\filenameext}
  [\filedate\space v\fileversion\space\filedescription]
%\iffalse
\documentclass[full]{l3doc}
\begin{document}
\DocInput{l3box.dtx}
\end{document}
%</driver>
% \fi
%
%
% \title{The \textsf{l3box} package\thanks{This file
%         has version number \fileversion, last
%         revised \filedate.}\\
% Boxes}
% \author{\Team}
% \date{\filedate}
% \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{Generic functions}
%
%  \begin{function}{ \box_new:N   |
%                    \box_new:c   }
%  \begin{syntax}
%     "\box_new:N"   <box>
%  \end{syntax}
%  Defines <box> to be a new variable of type "box".
%  \begin{texnote}
%  "\box_new:N" is the equivalent of plain \TeX{}'s \tn{newbox}.
%  \end{texnote}
%  \end{function}
%
%  \begin{function}{%
%                   \if_hbox:N |
%                   \if_vbox:N |
%                   \if_box_empty:N |
%  }
%  \begin{syntax}
%     "\if_hbox:N" <box> <true code>"\else:" <false code>"\fi:"
%     "\if_box_empty:N" <box> <true code>"\else:" <false code>"\fi:"
%  \end{syntax}
%  "\if_hbox:N" and "\if_vbox:N" check if <box> is an horizontal or
%  vertical box resp. "\if_box_empty:N" tests if <box> is empty (void)
%  and executes "code" according to the test outcome.
%  \begin{texnote}
%    These are the \TeX{} primitives \tn{ifhbox}, \tn{ifvbox} and
%    \tn{ifvoid}.
%  \end{texnote}
%  \end{function}
%
%  \begin{function}{\box_if_horizontal_p:N |
%                   \box_if_horizontal_p:c |
%                   \box_if_horizontal:N / (TF) |
%                   \box_if_horizontal:c / (TF) }
%  \begin{syntax}
%     "\box_if_horizontal:NTF"   <box> \Arg{true code} \Arg{false code}
%  \end{syntax}
%  Tests if <box> is an horizontal box and executes <code> accordingly.
%  \end{function}
%
%  \begin{function}{\box_if_vertical_p:N |
%                   \box_if_vertical_p:c |
%                   \box_if_vertical:N / (TF) |
%                   \box_if_vertical:c / (TF) }
%  \begin{syntax}
%     "\box_if_vertical:NTF"   <box> \Arg{true code} \Arg{false code}
%  \end{syntax}
%  Tests if <box> is a vertical box and executes <code> accordingly.
%  \end{function}
%
%  \begin{function}{%
%                   \box_if_empty_p:N |
%                   \box_if_empty_p:c |
%                   \box_if_empty:N / (TF) |
%                   \box_if_empty:c / (TF) |
%  }
%  \begin{syntax}
%     "\box_if_empty:NTF"   <box> \Arg{true code} \Arg{false code}
%  \end{syntax}
%  Tests if <box> is empty (void) and executes "code" according to the
%  test outcome.
%  \begin{texnote}
%  "\box_if_empty:NTF" is the \LaTeX3 function name for \tn{ifvoid}.
%  \end{texnote}
%  \end{function}
%
%
%  \begin{function}{%
%                   \box_set_eq:NN |
%                   \box_set_eq:cN |
%                   \box_set_eq:Nc |
%                   \box_set_eq:cc |
%                   \box_set_eq_clear:NN |
%                   \box_set_eq_clear:cN |
%                   \box_set_eq_clear:Nc |
%                   \box_set_eq_clear:cc |
%  }
%  \begin{syntax}
%     "\box_set_eq:NN"   <box1> <box2>
%  \end{syntax}
%  Sets <box1> equal to <box2>. The "_clear" versions eradicate the contents
%  of <box2> afterwards.
%  \end{function}
%
%
%  \begin{function}{%
%                   \box_gset_eq:NN |
%                   \box_gset_eq:cN |
%                   \box_gset_eq:Nc |
%                   \box_gset_eq:cc |
%                   \box_gset_eq_clear:NN |
%                   \box_gset_eq_clear:cN |
%                   \box_gset_eq_clear:Nc |
%                   \box_gset_eq_clear:cc |
%  }
%  \begin{syntax}
%     "\box_gset_eq:NN"   <box1> <box2>
%  \end{syntax}
%  Globally sets <box1> equal to <box2>. The "_clear" versions eradicate the contents
%  of <box2> afterwards.
%  \end{function}
%
%
%  \begin{function}{%
%                   \box_set_to_last:N |
%                   \box_set_to_last:c |
%                   \box_gset_to_last:N |
%                   \box_gset_to_last:c |
%  }
%  \begin{syntax}
%     "\box_set_to_last:N"   <box> 
%  \end{syntax}
%  Sets <box> equal to the previous box |\l_last_box| and removes
%  |\l_last_box| from the current list (unless in outer vertical
%  or math mode).
%  \end{function}
%
%  \begin{function}{%
%                   \box_move_right:nn |
%                   \box_move_left:nn |
%                   \box_move_up:nn |
%                   \box_move_down:nn |
%  }
%  \begin{syntax}
%     "\box_move_left:nn"   \Arg{dimen} \Arg{box function}
%  \end{syntax}
%  Moves <box function> <dimen> in the direction specified. <box
%  function> is either an operation on a box such as "\box_use:N" or a
%  ``raw'' box specification like "\vbox:n{xyz}".
%  \end{function}
%
%  \begin{function}{%
%                   \box_clear:N |
%                   \box_clear:c |
%                   \box_gclear:N |
%                   \box_gclear:c |
%  }
%  \begin{syntax}
%     "\box_clear:N"   <box>
%  \end{syntax}
%  Clears <box> by setting it to the constant "\c_void_box".
%  "\box_gclear:N" does it globally.
%  \end{function}
%
%
%  \begin{function}{%
%                   \box_use:N |
%                   \box_use:c |
%                   \box_use_clear:N |
%                   \box_use_clear:c |
%  }
%  \begin{syntax}
%     "\box_use:N"   <box> \\
%     "\box_use_clear:N" <box>
%  \end{syntax}
%  "\box_use:N" puts a copy of <box> on the current list while
%  "\box_use_clear:N" puts the box on the current list and then
%  eradicates the contents of it.
%  \begin{texnote}
%  "\box_use:N" and "\box_use_clear:N" are the \TeX{} primitives
%  \tn{copy} and \tn{box} with new (descriptive) names.
%  \end{texnote}
%  \end{function}
%
%
%  \begin{function}{%
%                   \box_ht:N |
%                   \box_ht:c |
%                   \box_dp:N |
%                   \box_dp:c |
%                   \box_wd:N |
%                   \box_wd:c |
%  }
%  \begin{syntax}
%     "\box_ht:N"   <box>
%  \end{syntax}
%  Returns the height, depth, and width of <box> for use in dimension
%  settings.
%  \begin{texnote}
%  These are the \TeX{} primitives \tn{ht}, \tn{dp} and \tn{wd}.
%  \end{texnote}
%  \end{function}
%  
%\begin{function}{ 
%  \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 local assignment.
%\end{function}
%
%\begin{function}{ 
%  \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 local assignment.
%\end{function}
%
%\begin{function}{ 
%  \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 local assignment.
%\end{function}
%
%  \begin{function}{%
%                   \box_show:N |
%                   \box_show:c |
%  }
%  \begin{syntax}
%     "\box_show:N"   <box>
%  \end{syntax}
%  Writes the contents of <box> to the log file.
%  \begin{texnote}
%  This is the \TeX{} primitive \tn{showbox}.
%  \end{texnote}
%  \end{function}
%
%
%  \begin{variable}{%
%                   \c_empty_box |
%                   \l_tmpa_box |
%                   \l_tmpb_box |
%  }
%  \begin{syntax}
%  \end{syntax}
%  "\c_empty_box" is the constantly empty box. The others are scratch
%  boxes.
%  \end{variable}
%
%
%  \begin{variable}{%
%                   \l_last_box |
%  }
%  \begin{syntax}
%  \end{syntax}
%  "\l_last_box" is more or less a read-only box register managed by the
%  engine. It denotes the last box on the current list if there is one,
%  otherwise it is void. You can set other
%  boxes to this box, with the result that the last box on the current list is
%  removed at the same time (so it is with variable with side-effects).
%  \end{variable}
%
%
%  \section{Horizontal mode}
%
%  \begin{function}{%
%                   \hbox:n |
%  }
%  \begin{syntax}
%     "\hbox:n" \Arg{contents}
%  \end{syntax}
%  Places a "hbox" of natural size.
%  \end{function}
%
%  \begin{function}{%
%                   \hbox_set:Nn |
%                   \hbox_set:cn |
%                   \hbox_gset:Nn |
%                   \hbox_gset:cn |
%  }
%  \begin{syntax}
%     "\hbox_set:Nn"   <box> \Arg{contents}
%  \end{syntax}
%  Sets <box> to be a horizontal mode box containing \m{contents}. It has
%  it's natural size. "\hbox_gset:Nn" does it globally.
%  \end{function}
%
%
%  \begin{function}{%
%                   \hbox_set_to_wd:Nnn |
%                   \hbox_set_to_wd:cnn |
%                   \hbox_gset_to_wd:Nnn |
%                   \hbox_gset_to_wd:cnn |
%  }
%  \begin{syntax}
%     "\hbox_set_to_wd:Nnn"   <box> \Arg{dimen} \Arg{contents}
%  \end{syntax}
%  Sets <box> to contain \m{contents} and have width <dimen>.
%  "\hbox_gset_to_wd:Nn" does it globally.
%  \end{function}
%
%
%  \begin{function}{%
%                   \hbox_to_wd:nn |
%                   \hbox_to_zero:n |
%  }
%  \begin{syntax}
%     "\hbox_to_wd:nn" \Arg{dimen} <contents>
%     "\hbox_to_zero:n" <contents>
%  \end{syntax}
%  Places a <box> of width <dimen> containing <contents>. "\hbox_to_zero:n"
%  is a shorthand for a width of zero.
%  \end{function}
%
%
%  \begin{function}{%
%                   \hbox_overlap_left:n |
%                   \hbox_overlap_right:n |
%  }
%  \begin{syntax}
%     "\hbox_overlap_left:n"  <contents>
%  \end{syntax}
%  Places a <box> of width zero containing <contents> in a way the it overlaps
%  with surrounding material (sticking out to the left or right).
%  \end{function}
%
%
%  \begin{function}{%
%                   \hbox_set_inline_begin:N |
%                   \hbox_set_inline_begin:c |
%                   \hbox_set_inline_end:    |
%                   \hbox_gset_inline_begin:N |
%                   \hbox_gset_inline_begin:c |
%                   \hbox_gset_inline_end:   |
%  }
%  \begin{syntax}
%     "\hbox_set_inline_begin:N" <box> <contents>
%     "\hbox_set_inline_end:"
%  \end{syntax}
%  Sets <box> to contain <contents>. This type is useful for use in
%  environment definitions.
%  \end{function}
%
%
%  \begin{function}{%
%                   \hbox_unpack:N |
%                   \hbox_unpack:c |
%                   \hbox_unpack_clear:N    |
%                   \hbox_unpack_clear:c    |
%  }
%  \begin{syntax}
%     "\hbox_unpack:N" <box>
%  \end{syntax}
%  "\hbox_unpack:N" unpacks the contents of the <box> register and
%  "\hbox_unpack_clear:N" also clears the <box> after unpacking it.
%  \begin{texnote}
%    These are the \TeX{} primitives \tn{unhcopy} and \tn{unhbox}.
%  \end{texnote}
%  \end{function}
%
%
%
%
%
%  \section{Vertical mode}
%
%  \begin{function}{%
%                   \vbox:n |
%  }
%  \begin{syntax}
%     "\vbox:n" \Arg{contents}
%  \end{syntax}
%  Places a "vbox" of natural size with baseline equal to the baseline
%  of the last object in the box, i.e., if the last object is a line of text
%  the box has the same depth as that line; otherwise the depth will be zero.
%  \end{function}
%
%  \begin{function}{%
%                   \vbox_top:n |
%  }
%  \begin{syntax}
%     "\vbox_top:n" \Arg{contents}
%  \end{syntax}
%  Same as "\vbox:n" except that the reference point will be at the baseline
%  of the first object in the box not the last.
%  \end{function}
%
%  \begin{function}{%
%                   \vbox_set:Nn |
%                   \vbox_set:cn |
%                   \vbox_gset:Nn |
%                   \vbox_gset:cn |
%  }
%  \begin{syntax}
%     "\vbox_set:Nn"   <box> \Arg{contents}
%  \end{syntax}
%  Sets <box> to be a vertical mode box containing \m{contents}. It has
%  its natural size and the reference point will be at the baseline of the
%  last object in the box. "\vbox_gset:Nn" does it globally.
%  \end{function}
%
%
%  \begin{function}{%
%                   \vbox_set_top:Nn |
%                   \vbox_set_top:cn |
%                   \vbox_gset_top:Nn |
%                   \vbox_gset_top:cn |
%  }
%  \begin{syntax}
%     "\vbox_set_top:Nn"   <box> \Arg{contents}
%  \end{syntax}
%  Sets <box> to be a vertical mode box containing \m{contents}. It has
%  its natural size  (usually a small height and a larger depth) 
%  and the reference point will be at the baseline of the
%  first object in the box. "\vbox_gset_top:Nn" does it globally.
%  \end{function}
%
%
%  \begin{function}{%
%                   \vbox_set_to_ht:Nnn |
%                   \vbox_set_to_ht:cnn |
%                   \vbox_gset_to_ht:Nnn |
%                   \vbox_gset_to_ht:cnn |
%                   \vbox_gset_to_ht:ccn |
%  }
%  \begin{syntax}
%     "\vbox_set_to_ht:Nnn"   <box> \Arg{dimen} \Arg{contents}
%  \end{syntax}
%  Sets <box> to contain \m{contents} and have total height <dimen>.
%  "\vbox_gset_to_ht:Nn" does it globally.
%  \end{function}
%
%
%  \begin{function}{%
%                   \vbox_set_inline_begin:N |
%                   \vbox_set_inline_end:    |
%                   \vbox_gset_inline_begin:N |
%                   \vbox_gset_inline_end:   |
%  }
%  \begin{syntax}
%     "\vbox_set_inline_begin:N" <box> <contents>
%     "\vbox_set_inline_end:"
%  \end{syntax}
%  Sets <box> to contain \m{contents}. This type is useful for use in
%  environment definitions.
%  \end{function}
%
%  \begin{function}{%
%                   \vbox_set_split_to_ht:NNn |
%  }
%  \begin{syntax}
%     "\vbox_set_split_to_ht:NNn" <box1> <box2> \Arg{dimen}
%  \end{syntax}
%  Sets <box1> to contain the top <dimen> part of <box2>.
%  \begin{texnote}
%    This is the \TeX{} primitive \tn{vsplit}.
%  \end{texnote}
%  \end{function}
%
%  \begin{function}{%
%                   \vbox_to_ht:nn |
%                   \vbox_to_zero:n    |
%  }
%  \begin{syntax}
%     "\vbox_to_ht:nn" \Arg{dimen} <contents> \\
%     "\vbox_to_zero:n" <contents>
%  \end{syntax}
%  Places a <box> of size <dimen> containing <contents>.
%  \end{function}
%
%
%  \begin{function}{%
%                   \vbox_unpack:N |
%                   \vbox_unpack:c |
%                   \vbox_unpack_clear:N    |
%                   \vbox_unpack_clear:c    |
%  }
%  \begin{syntax}
%     "\vbox_unpack:N" <box>
%  \end{syntax}
%  "\vbox_unpack:N" unpacks the contents of the <box> register and
%  "\vbox_unpack_clear:N" also clears the <box> after unpacking it.
%  \begin{texnote}
%    These are the \TeX{} primitives \tn{unvcopy} and \tn{unvbox}.
%  \end{texnote}
%  \end{function}
%
%
% \end{documentation}
%
% \begin{implementation}
%
%
%
% \section{\pkg{l3box} implementation}
%
%
%    Announce and ensure that the required packages are loaded.
%    \begin{macrocode}
%<*package>
\ProvidesExplPackage
  {\filename}{\filedate}{\fileversion}{\filedescription}
\package_check_loaded_expl:
%</package>
%<*initex|package>
%    \end{macrocode}
%
%  The code in this module is very straight forward so I'm not going to
%  comment it very extensively.
%
%
%  \subsection{Generic boxes}
%
%  \begin{macro}{\box_new:N,\box_new:c}
%  Defining a new \m{box} register.
% \testfile{m3box001.lvt}
%    \begin{macrocode}
%<*initex>
\alloc_new:nnnN {box} \c_zero \c_max_register_int \tex_mathchardef:D
%    \end{macrocode}
%    Now, remember that |\box255| has a special role in \TeX, it
%    shouldn't be allocated\dots
%    \begin{macrocode}
\seq_put_right:Nn \g_box_allocation_seq {255}
%</initex>
%    \end{macrocode}
%    When we run on top of \LaTeX, we just use its allocation
%    mechanism.
%    \begin{macrocode}
%<*package>
\cs_new_protected:Npn \box_new:N #1 {
  \chk_if_free_cs:N #1
  \newbox #1
}
%</package>
%    \end{macrocode}
%
%    \begin{macrocode}
\cs_generate_variant:Nn \box_new:N {c}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\if_hbox:N,\if_vbox:N,\if_box_empty:N}
%  \testfile*
%    The primitives for testing if a \m{box} is empty/void or which
%    type of box it is.
%    \begin{macrocode}
\cs_new_eq:NN \if_hbox:N        \tex_ifhbox:D
\cs_new_eq:NN \if_vbox:N        \tex_ifvbox:D
\cs_new_eq:NN \if_box_empty:N   \tex_ifvoid:D
%    \end{macrocode}
%  \end{macro}
%
%
% \begin{macro}{\box_if_horizontal_p:N,\box_if_horizontal_p:c}
% \testfile*
% \begin{macro}{\box_if_vertical_p:N,\box_if_vertical_p:c}
% \testfile*
% \begin{macro}[TF]{\box_if_horizontal:N,\box_if_horizontal:c}
% \testfile*
% \begin{macro}[TF]{\box_if_vertical:N,\box_if_vertical:c}
% \testfile*
%    \begin{macrocode}
\prg_new_conditional:Nnn \box_if_horizontal:N {p,TF,T,F} {
  \tex_ifhbox:D #1 \prg_return_true: \else: \prg_return_false: \fi:
}
\prg_new_conditional:Nnn \box_if_vertical:N {p,TF,T,F} {
  \tex_ifvbox:D #1 \prg_return_true: \else: \prg_return_false: \fi:
}
\cs_generate_variant:Nn \box_if_horizontal_p:N {c}
\cs_generate_variant:Nn \box_if_horizontal:NTF {c}
\cs_generate_variant:Nn \box_if_horizontal:NT  {c}
\cs_generate_variant:Nn \box_if_horizontal:NF  {c}
\cs_generate_variant:Nn \box_if_vertical_p:N {c}
\cs_generate_variant:Nn \box_if_vertical:NTF {c}
\cs_generate_variant:Nn \box_if_vertical:NT  {c}
\cs_generate_variant:Nn \box_if_vertical:NF  {c}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\box_if_empty_p:N,\box_if_empty_p:c}
% \testfile*
% \begin{macro}[TF]{\box_if_empty:N,\box_if_empty:c}
% \testfile*
% Testing if a \m{box} is empty/void.
%    \begin{macrocode}
\prg_new_conditional:Nnn \box_if_empty:N {p,TF,T,F} {
  \tex_ifvoid:D #1 \prg_return_true: \else: \prg_return_false: \fi:
}
\cs_generate_variant:Nn \box_if_empty_p:N {c}
\cs_generate_variant:Nn \box_if_empty:NTF {c}
\cs_generate_variant:Nn \box_if_empty:NT  {c}
\cs_generate_variant:Nn \box_if_empty:NF  {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*
%  Assigning the contents of a box to be another box.
%    \begin{macrocode}
\cs_new_protected_nopar:Npn \box_set_eq:NN #1#2 {\tex_setbox:D #1 \tex_copy:D #2}
\cs_generate_variant:Nn \box_set_eq:NN {cN,Nc,cc}
%    \end{macrocode}
%  \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*
%  Assigning the contents of a box to be another box.
%  This clears the second box globally (that's how \TeX{} does it).
%    \begin{macrocode}
\cs_new_protected_nopar:Npn \box_set_eq_clear:NN #1#2 {\tex_setbox:D #1 \tex_box:D #2}
\cs_generate_variant:Nn \box_set_eq_clear:NN {cN,Nc,cc}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\box_gset_eq:NN,\box_gset_eq:cN,
%                \box_gset_eq:Nc,\box_gset_eq:cc,
%                \box_gset_eq_clear:NN,\box_gset_eq_clear:cN,
%                \box_gset_eq_clear:Nc,\box_gset_eq_clear:cc}
% \testfile*
%  Global version of the above.
%    \begin{macrocode}
\cs_new_protected_nopar:Npn \box_gset_eq:NN {\pref_global:D\box_set_eq:NN}
\cs_generate_variant:Nn \box_gset_eq:NN {cN,Nc,cc}
\cs_new_protected_nopar:Npn \box_gset_eq_clear:NN {\pref_global:D\box_set_eq_clear:NN}
\cs_generate_variant:Nn \box_gset_eq_clear:NN {cN,Nc,cc}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{variable}{\l_last_box}
%  A different name for this read-only primitive.
%    \begin{macrocode}
\cs_new_eq:NN \l_last_box \tex_lastbox:D
%    \end{macrocode}
%  \end{variable}
%
% \begin{macro}{\box_set_to_last:N, \box_gset_to_last:N,
%               \box_set_to_last:c, \box_gset_to_last:c}
% \testfile*
%  Set a box to the previous box.
%    \begin{macrocode}
\cs_new_protected_nopar:Npn \box_set_to_last:N #1{\tex_setbox:D#1\l_last_box}
\cs_generate_variant:Nn \box_set_to_last:N {c}
\cs_new_protected_nopar:Npn \box_gset_to_last:N {\pref_global:D \box_set_to_last:N}
\cs_generate_variant:Nn \box_gset_to_last:N {c}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\box_move_left:nn,\box_move_right:nn,
%                \box_move_up:nn,\box_move_down:nn}
% \testfile*
%  Move box material in different directions.
%    \begin{macrocode}
\cs_new:Npn \box_move_left:nn #1#2{\tex_moveleft:D\dim_eval:n{#1} #2}
\cs_new:Npn \box_move_right:nn #1#2{\tex_moveright:D\dim_eval:n{#1} #2}
\cs_new:Npn \box_move_up:nn #1#2{\tex_raise:D\dim_eval:n{#1} #2}
\cs_new:Npn \box_move_down:nn #1#2{\tex_lower:D\dim_eval:n{#1} #2}
%    \end{macrocode}
%  \end{macro}
%
% \begin{macro}{\box_clear:N,\box_clear:c,
%               \box_gclear:N,\box_gclear:c}
% \testfile*
%  Clear a \m{box} register.
%    \begin{macrocode}
\cs_new_protected_nopar:Npn \box_clear:N #1{\box_set_eq_clear:NN #1 \c_empty_box }
\cs_generate_variant:Nn \box_clear:N {c}
\cs_new_protected_nopar:Npn \box_gclear:N {\pref_global:D\box_clear:N}
\cs_generate_variant:Nn \box_gclear:N {c}
%    \end{macrocode}
%  \end{macro}
%
%
% \begin{macro}{\box_ht:N,\box_ht:c,
%               \box_dp:N,\box_dp:c,
%               \box_wd:N,\box_wd:c}
% \testfile*
%  Accessing the height, depth, and width of a \m{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}
%
% \begin{macro}{\box_set_ht:Nn,
%               \box_set_ht:cn,
%               \box_set_dp:Nn,
%               \box_set_dp:cn,
%               \box_set_wd:Nn,
%               \box_set_wd:cn}
% Measuring is easy: all primitive work. These primitives are not 
% expandable, so the derived functions are not either.
%    \begin{macrocode}
\cs_new_protected_nopar:Npn \box_set_dp:Nn #1#2 {
  \box_dp:N #1 \etex_dimexpr:D #2 \scan_stop:
}
\cs_new_protected_nopar:Npn \box_set_ht:Nn #1#2 {
  \box_ht:N #1 \etex_dimexpr:D #2 \scan_stop:
}
\cs_new_protected_nopar:Npn \box_set_wd:Nn #1#2 {
  \box_wd:N #1 \etex_dimexpr:D #2 \scan_stop:
}
\cs_generate_variant:Nn \box_set_ht:Nn { c }
\cs_generate_variant:Nn \box_set_dp:Nn { c }
\cs_generate_variant:Nn \box_set_wd:Nn { c }
%    \end{macrocode}
%\end{macro}
%
%  \begin{macro}{\box_use_clear:N,\box_use_clear:c,
%                \box_use:N,\box_use:c}
%  \testfile{m3box001.lvt}
%  Using a \m{box}. These are just \TeX{} primitives with meaningful
%  names.
%    \begin{macrocode}
\cs_new_eq:NN \box_use_clear:N \tex_box:D
\cs_generate_variant:Nn \box_use_clear:N {c}
\cs_new_eq:NN \box_use:N \tex_copy:D
\cs_generate_variant:Nn \box_use:N {c}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\box_show:N,\box_show:c}
%  \testfile*
%  Show the contents of a box and write it into the log file.
%    \begin{macrocode}
\cs_set_eq:NN \box_show:N \tex_showbox:D
\cs_generate_variant:Nn \box_show:N {c}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{variable}{\c_empty_box,\l_tmpa_box,\l_tmpb_box}
%  We allocate some \m{box} registers here (and borrow a few from \LaTeX).
%    \begin{macrocode}
%<package>\cs_set_eq:NN \c_empty_box \voidb@x
%<package>\cs_new_eq:NN \l_tmpa_box \@tempboxa
%<initex>\box_new:N \c_empty_box
%<initex>\box_new:N \l_tmpa_box
\box_new:N \l_tmpb_box
%    \end{macrocode}
%  \end{variable}
%
%
%  \subsection{Vertical boxes}
%
%
%  \begin{macro}{\vbox:n,
%                \vbox_top:n}
%  \testfile{m3box003.lvt}
%  Put a vertical box directly into the input stream.
%    \begin{macrocode}
\cs_new_protected_nopar:Npn \vbox:n {\tex_vbox:D \scan_stop:}
\cs_new_protected_nopar:Npn \vbox_top:n {\tex_vtop:D \scan_stop:}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\vbox_set:Nn,\vbox_set:cn,
%                \vbox_gset:Nn,\vbox_gset:cn}
%  \testfile*
%  Storing material in a vertical box with a natural height.
%    \begin{macrocode}
\cs_new_protected:Npn \vbox_set:Nn #1#2 {\tex_setbox:D #1 \tex_vbox:D {#2}}
\cs_generate_variant:Nn \vbox_set:Nn {cn}
\cs_new_protected_nopar:Npn \vbox_gset:Nn  {\pref_global:D \vbox_set:Nn}
\cs_generate_variant:Nn \vbox_gset:Nn {cn}
%    \end{macrocode}
%  \end{macro}
%
%
%  \begin{macro}{\vbox_set_top:Nn,\vbox_set_top:cn,
%                \vbox_gset_top:Nn,\vbox_gset_top:cn}
%  \testfile*
%    Storing material in a vertical box with a natural height and reference
%    point at the baseline of the first object in the box.
%    \begin{macrocode}
\cs_new_protected:Npn \vbox_set_top:Nn #1#2 {\tex_setbox:D #1 \tex_vtop:D {#2}}
\cs_generate_variant:Nn \vbox_set_top:Nn {cn}
\cs_new_protected_nopar:Npn \vbox_gset_top:Nn  {\pref_global:D \vbox_set_top:Nn}
\cs_generate_variant:Nn \vbox_gset_top:Nn {cn}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\vbox_set_to_ht:Nnn,\vbox_set_to_ht:cnn,
%                \vbox_gset_to_ht:Nnn,\vbox_gset_to_ht:cnn,\vbox_gset_to_ht:ccn}
%  \testfile*
%  Storing material in a vertical box with a specified height.
%    \begin{macrocode}
\cs_new_protected:Npn \vbox_set_to_ht:Nnn #1#2#3 {
  \tex_setbox:D #1 \tex_vbox:D to #2 {#3}
}
\cs_generate_variant:Nn \vbox_set_to_ht:Nnn {cnn}
\cs_new_protected_nopar:Npn \vbox_gset_to_ht:Nnn { \pref_global:D \vbox_set_to_ht:Nnn }
\cs_generate_variant:Nn \vbox_gset_to_ht:Nnn {cnn,ccn}
%    \end{macrocode}
%  \end{macro}
%
%
%  \begin{macro}{\vbox_set_inline_begin:N,
%                \vbox_set_inline_end:,
%                \vbox_gset_inline_begin:N,
%                \vbox_gset_inline_end:}
%  \testfile*
%  Storing material in a vertical box. This type is useful in
%  environment definitions.
%    \begin{macrocode}
\cs_new_protected_nopar:Npn \vbox_set_inline_begin:N  #1 {
  \tex_setbox:D #1 \tex_vbox:D \c_group_begin_token }
\cs_new_eq:NN \vbox_set_inline_end: \c_group_end_token
\cs_new_protected_nopar:Npn \vbox_gset_inline_begin:N {
  \pref_global:D \vbox_set_inline_begin:N }
\cs_new_eq:NN \vbox_gset_inline_end: \c_group_end_token
%    \end{macrocode}
%  \end{macro}
%
%
%  \begin{macro}{\vbox_to_ht:nn,\vbox_to_zero:n}
%  \testfile*
%  Put a vertical box directly into the input stream.
%    \begin{macrocode}
\cs_new_protected:Npn \vbox_to_ht:nn #1#2{\tex_vbox:D to \dim_eval:n{#1}{#2}}
\cs_new_protected:Npn \vbox_to_zero:n #1 {\tex_vbox:D to \c_zero_dim {#1}}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\vbox_set_split_to_ht:NNn}
%  \testfile*
%  Splitting a vertical box in two.
%    \begin{macrocode}
\cs_new_protected_nopar:Npn \vbox_set_split_to_ht:NNn #1#2#3{
  \tex_setbox:D #1 \tex_vsplit:D #2 to #3
}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\vbox_unpack:N,\vbox_unpack:c,
%                \vbox_unpack_clear:N,\vbox_unpack_clear:c}
%  \testfile*
%  Unpacking a box and if requested also clear it.
%    \begin{macrocode}
\cs_new_eq:NN \vbox_unpack:N \tex_unvcopy:D
\cs_generate_variant:Nn \vbox_unpack:N {c}
\cs_new_eq:NN \vbox_unpack_clear:N \tex_unvbox:D
\cs_generate_variant:Nn \vbox_unpack_clear:N {c}
%    \end{macrocode}
%  \end{macro}
%
%
%
%
%
%
%  \subsection{Horizontal boxes}
%
%
%  \begin{macro}{\hbox:n}
%  Put a horizontal box directly into the input stream.
%  \testfile{m3box002.lvt}
%    \begin{macrocode}
\cs_new_protected_nopar:Npn \hbox:n {\tex_hbox:D \scan_stop:}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\hbox_set:Nn,\hbox_set:cn,
%                \hbox_gset:Nn,\hbox_gset:cn}
%  \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}
\cs_new_protected:Npn \hbox_set:Nn #1#2 {\tex_setbox:D #1 \tex_hbox:D {#2}}
\cs_generate_variant:Nn \hbox_set:Nn {cn}
\cs_new_protected_nopar:Npn \hbox_gset:Nn  {\pref_global:D \hbox_set:Nn}
\cs_generate_variant:Nn \hbox_gset:Nn {cn}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\hbox_set_to_wd:Nnn,\hbox_set_to_wd:cnn,
%                \hbox_gset_to_wd:Nnn,\hbox_gset_to_wd:cnn}
%  \testfile*
%  Storing material in a horizontal box with a specified width.
%    \begin{macrocode}
\cs_new_protected:Npn \hbox_set_to_wd:Nnn #1#2#3 {
  \tex_setbox:D #1 \tex_hbox:D to \dim_eval:n{#2} {#3}
}
\cs_generate_variant:Nn \hbox_set_to_wd:Nnn {cnn}
\cs_new_protected_nopar:Npn \hbox_gset_to_wd:Nnn {\pref_global:D \hbox_set_to_wd:Nnn }
\cs_generate_variant:Nn \hbox_gset_to_wd:Nnn {cnn}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\hbox_set_inline_begin:N,\hbox_set_inline_begin:c,
%                \hbox_gset_inline_begin:N,\hbox_gset_inline_begin:c,
%                \hbox_set_inline_end:,
%                \hbox_gset_inline_end:}
%  \testfile*
%  Storing material in a horizontal box. This type is useful in
%  environment definitions.
%    \begin{macrocode}
\cs_new_protected_nopar:Npn \hbox_set_inline_begin:N  #1 {
  \tex_setbox:D #1 \tex_hbox:D \c_group_begin_token 
}
\cs_generate_variant:Nn \hbox_set_inline_begin:N {c}
\cs_new_eq:NN \hbox_set_inline_end: \c_group_end_token
\cs_new_protected_nopar:Npn \hbox_gset_inline_begin:N {
  \pref_global:D \hbox_set_inline_begin:N 
}
\cs_generate_variant:Nn \hbox_gset_inline_begin:N {c}
\cs_new_eq:NN \hbox_gset_inline_end: \c_group_end_token
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\hbox_to_wd:nn,\hbox_to_zero:n}
%  \testfile*
%  Put a horizontal box directly into the input stream.
%    \begin{macrocode}
\cs_new_protected:Npn \hbox_to_wd:nn #1#2 {\tex_hbox:D to #1 {#2}}
\cs_new_protected:Npn \hbox_to_zero:n #1 {\tex_hbox:D to \c_zero_skip {#1}}
%    \end{macrocode}
%  \end{macro}
%
%
%  \begin{macro}{\hbox_overlap_left:n,\hbox_overlap_right:n}
%    Put a zero-sized box with the contents pushed against one side (which
%    makes it stick out on the other) directly into the input stream.
%    \begin{macrocode}
\cs_new_protected:Npn \hbox_overlap_left:n  #1 {\hbox_to_zero:n {\tex_hss:D #1}}
\cs_new_protected:Npn \hbox_overlap_right:n #1 {\hbox_to_zero:n {#1 \tex_hss:D}}
%    \end{macrocode}
%  \end{macro}
%
%
%  \begin{macro}{\hbox_unpack:N,\hbox_unpack:c,
%                \hbox_unpack_clear:N,\hbox_unpack_clear:c}
%  \testfile*
%  Unpacking a box and if requested also clear it.
%    \begin{macrocode}
\cs_new_eq:NN \hbox_unpack:N \tex_unhcopy:D
\cs_generate_variant:Nn \hbox_unpack:N {c}
\cs_new_eq:NN \hbox_unpack_clear:N \tex_unhbox:D
\cs_generate_variant:Nn \hbox_unpack_clear:N {c}
%    \end{macrocode}
%  \end{macro}
%
%
%
%^^A xo-or.sty:1528: \setbox\z@\vsplit\c_twohundred_fifty_five to\l_tmpa_dim
%^^A xo-or.dtx:222:  \global\setbox\removed@guard@box\lastbox}
%
%^^A it probably should be  \vbox_set:nn not  \vbox_set:Nn  as we can
%^^A have a number as the first arg ... do do we argue that this is not
%^^A supported on this level?
%^^A MH comment:
%^^A I don't think we should ever see people using numbers directly.
%^^A If they do it's \vbox_set:Nn \c_zero {...} anyway, not two-digit
%^^A numbers.
%
%    \begin{macrocode}
%</initex|package>
%    \end{macrocode}
% 
%    \begin{macrocode}
%<*showmemory>
\showMemUsage
%</showmemory>
%    \end{macrocode}
%
% \end{implementation}
% \PrintIndex
%
% \endinput