/
l3coffins.dtx
1973 lines (1973 loc) · 65.8 KB
/
l3coffins.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: l3coffins.dtx
%
% Copyright (C) 2010-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 \textsf{l3coffins} package\\ Coffin code layer^^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-13}
%
% \maketitle
%
% \begin{documentation}
%
% The material in this module provides the low-level support system
% for coffins. For details about the design concept of a coffin, see
% the \pkg{xcoffins} module (in the \pkg{l3experimental} bundle).
%
% \section{Creating and initialising coffins}
%
% \begin{function}[added = 2011-08-17]{\coffin_new:N, \coffin_new:c}
% \begin{syntax}
% \cs{coffin_new:N} \meta{coffin}
% \end{syntax}
% Creates a new \meta{coffin} or raises an error if the name is
% already taken. The declaration is global. The \meta{coffin} is
% initially empty.
% \end{function}
%
% \begin{function}[added = 2011-08-17, updated = 2019-01-18]
% {
% \coffin_clear:N, \coffin_clear:c,
% \coffin_gclear:N, \coffin_gclear:c
% }
% \begin{syntax}
% \cs{coffin_clear:N} \meta{coffin}
% \end{syntax}
% Clears the content of the \meta{coffin} by setting it equal to an empty
% coffin.
% \end{function}
%
% \begin{function}[added = 2011-08-17, updated = 2019-01-18]
% {
% \coffin_set_eq:NN, \coffin_set_eq:Nc,
% \coffin_set_eq:cN, \coffin_set_eq:cc,
% \coffin_gset_eq:NN, \coffin_gset_eq:Nc,
% \coffin_gset_eq:cN, \coffin_gset_eq:cc,
% }
% \begin{syntax}
% \cs{coffin_set_eq:NN} \meta{coffin_1} \meta{coffin_2}
% \end{syntax}
% Sets both the content and poles of \meta{coffin_1} equal to those
% of \meta{coffin_2}.
% \end{function}
%
% \begin{function}[EXP, pTF, added = 2012-06-20]
% {\coffin_if_exist:N, \coffin_if_exist:c}
% \begin{syntax}
% \cs{coffin_if_exist_p:N} \meta{box}
% \cs{coffin_if_exist:NTF} \meta{box} \Arg{true code} \Arg{false code}
% \end{syntax}
% Tests whether the \meta{coffin} is currently defined.
% \end{function}
%
% \section{Setting coffin content and poles}
%
% All coffin functions create and manipulate coffins locally within the
% current \TeX\ group level.
%
% \begin{function}[added = 2011-08-17, updated = 2019-01-18]
% {
% \hcoffin_set:Nn, \hcoffin_set:cn,
% \hcoffin_gset:Nn, \hcoffin_gset:cn
% }
% \begin{syntax}
% \cs{hcoffin_set:Nn} \meta{coffin} \Arg{material}
% \end{syntax}
% Typesets the \meta{material} in horizontal mode, storing the result
% in the \meta{coffin}. The standard poles for the \meta{coffin} are
% then set up based on the size of the typeset material.
% \end{function}
%
% \begin{function}[added = 2011-09-10]
% {\hcoffin_set:Nw, \hcoffin_set:cw, \hcoffin_set_end:}
% \begin{syntax}
% \cs{hcoffin_set:Nw} \meta{coffin} \meta{material} \cs{hcoffin_set_end:}
% \end{syntax}
% Typesets the \meta{material} in horizontal mode, storing the result
% in the \meta{coffin}. The standard poles for the \meta{coffin} are
% then set up based on the size of the typeset material.
% These functions are useful for setting the entire contents of an
% environment in a coffin.
% \end{function}
%
% \begin{function}[added = 2011-08-17, updated = 2019-01-18]
% {
% \vcoffin_set:Nnn, \vcoffin_set:cnn,
% \vcoffin_gset:Nnn, \vcoffin_gset:cnn
% }
% \begin{syntax}
% \cs{vcoffin_set:Nnn} \meta{coffin} \Arg{width} \Arg{material}
% \end{syntax}
% Typesets the \meta{material} in vertical mode constrained to the
% given \meta{width} and stores the result in the \meta{coffin}. The
% standard poles for the \meta{coffin} are then set up based on the
% size of the typeset material.
% \end{function}
%
% \begin{function}[added = 2011-09-10, updated = 2012-05-22]
% {\vcoffin_set:Nnw, \vcoffin_set:cnw, \vcoffin_set_end:}
% \begin{syntax}
% \cs{vcoffin_set:Nnw} \meta{coffin} \Arg{width} \meta{material} \cs{vcoffin_set_end:}
% \end{syntax}
% Typesets the \meta{material} in vertical mode constrained to the
% given \meta{width} and stores the result in the \meta{coffin}. The
% standard poles for the \meta{coffin} are then set up based on the
% size of the typeset material.
% These functions are useful for setting the entire contents of an
% environment in a coffin.
% \end{function}
%
% \begin{function}[added = 2012-07-20]
% {\coffin_set_horizontal_pole:Nnn, \coffin_set_horizontal_pole:cnn}
% \begin{syntax}
% \cs{coffin_set_horizontal_pole:Nnn} \meta{coffin}
% ~~\Arg{pole} \Arg{offset}
% \end{syntax}
% Sets the \meta{pole} to run horizontally through the \meta{coffin}.
% The \meta{pole} is placed at the \meta{offset} from the
% bottom edge of the bounding box of the \meta{coffin}. The
% \meta{offset} should be given as a dimension expression.
% \end{function}
%
% \begin{function}[added = 2012-07-20]
% {\coffin_set_vertical_pole:Nnn, \coffin_set_vertical_pole:cnn}
% \begin{syntax}
% \cs{coffin_set_vertical_pole:Nnn} \meta{coffin} \Arg{pole} \Arg{offset}
% \end{syntax}
% Sets the \meta{pole} to run vertically through the \meta{coffin}.
% The \meta{pole} is placed at the \meta{offset} from the
% left-hand edge of the bounding box of the \meta{coffin}. The
% \meta{offset} should be given as a dimension expression.
% \end{function}
%
% \section{Joining and using coffins}
%
% \begin{function}
% {
% \coffin_attach:NnnNnnnn, \coffin_attach:cnnNnnnn,
% \coffin_attach:Nnncnnnn, \coffin_attach:cnncnnnn
% }
% \begin{syntax}
% \cs{coffin_attach:NnnNnnnn}
% ~~\meta{coffin_1} \Arg{coffin_1-pole_1} \Arg{coffin_1-pole_2}
% ~~\meta{coffin_2} \Arg{coffin_2-pole_1} \Arg{coffin_2-pole_2}
% ~~\Arg{x-offset} \Arg{y-offset}
% \end{syntax}
% This function attaches \meta{coffin_2} to \meta{coffin_1} such that the bounding box
% of \meta{coffin_1} is not altered, \emph{i.e.}~\meta{coffin_2} can
% protrude outside of the bounding box of the coffin. The alignment
% is carried out by first calculating \meta{handle_1}, the
% point of intersection of \meta{coffin_1-pole_1} and
% \meta{coffin_1-pole_2}, and \meta{handle_2}, the point of intersection
% of \meta{coffin_2-pole_1} and \meta{coffin_2-pole_2}. \meta{coffin_2} is
% then attached to \meta{coffin_1} such that the relationship between
% \meta{handle_1} and \meta{handle_2} is described by the \meta{x-offset}
% and \meta{y-offset}. The two offsets should be given as dimension
% expressions.
% \end{function}
%
% \begin{function}
% {
% \coffin_join:NnnNnnnn, \coffin_join:cnnNnnnn,
% \coffin_join:Nnncnnnn, \coffin_join:cnncnnnn
% }
% \begin{syntax}
% \cs{coffin_join:NnnNnnnn}
% ~~\meta{coffin_1} \Arg{coffin_1-pole_1} \Arg{coffin_1-pole_2}
% ~~\meta{coffin_2} \Arg{coffin_2-pole_1} \Arg{coffin_2-pole_2}
% ~~\Arg{x-offset} \Arg{y-offset}
% \end{syntax}
% This function joins \meta{coffin_2} to \meta{coffin_1} such that the bounding box
% of \meta{coffin_1} may expand. The new bounding
% box covers the area containing the bounding boxes of the two
% original coffins. The alignment is carried out by first calculating
% \meta{handle_1}, the point of intersection of \meta{coffin_1-pole_1} and
% \meta{coffin_1-pole_2}, and \meta{handle_2}, the point of intersection
% of \meta{coffin_2-pole_1} and \meta{coffin_2-pole_2}. \meta{coffin_2} is
% then attached to \meta{coffin_1} such that the relationship between
% \meta{handle_1} and \meta{handle_2} is described by the \meta{x-offset}
% and \meta{y-offset}. The two offsets should be given as dimension
% expressions.
% \end{function}
%
% \begin{function}[updated = 2012-07-20]
% {\coffin_typeset:Nnnnn, \coffin_typeset:cnnnn}
% \begin{syntax}
% \cs{coffin_typeset:Nnnnn} \meta{coffin} \Arg{pole_1} \Arg{pole_2}
% ~~\Arg{x-offset} \Arg{y-offset}
% \end{syntax}
% Typesetting is carried out by first calculating \meta{handle}, the
% point of intersection of \meta{pole_1} and \meta{pole_2}. The coffin
% is then typeset in horizontal mode such that the relationship between the
% current reference point in the document and the \meta{handle} is described
% by the \meta{x-offset} and \meta{y-offset}. The two offsets should
% be given as dimension expressions. Typesetting a coffin is
% therefore analogous to carrying out an alignment where the
% \enquote{parent} coffin is the current insertion point.
% \end{function}
%
% \section{Measuring coffins}
%
% \begin{function}{\coffin_dp:N, \coffin_dp:c}
% \begin{syntax}
% \cs{coffin_dp:N} \meta{coffin}
% \end{syntax}
% Calculates the depth (below the baseline) of the \meta{coffin}
% in a form suitable for use in a \meta{dimension expression}.
% \end{function}
%
% \begin{function}{\coffin_ht:N, \coffin_ht:c}
% \begin{syntax}
% \cs{coffin_ht:N} \meta{coffin}
% \end{syntax}
% Calculates the height (above the baseline) of the \meta{coffin}
% in a form suitable for use in a \meta{dimension expression}.
% \end{function}
%
% \begin{function}{\coffin_wd:N, \coffin_wd:c}
% \begin{syntax}
% \cs{coffin_wd:N} \meta{coffin}
% \end{syntax}
% Calculates the width of the \meta{coffin} in a form
% suitable for use in a \meta{dimension expression}.
% \end{function}
%
% \section{Coffin diagnostics}
%
% \begin{function}[updated = 2011-09-02]
% {\coffin_display_handles:Nn, \coffin_display_handles:cn}
% \begin{syntax}
% \cs{coffin_display_handles:Nn} \meta{coffin} \Arg{color}
% \end{syntax}
% This function first calculates the intersections between all of
% the \meta{poles} of the \meta{coffin} to give a set of
% \meta{handles}. It then prints the \meta{coffin} at the current
% location in the source, with the position of the \meta{handles}
% marked on the coffin. The \meta{handles} are labelled as part
% of this process: the locations of the \meta{handles} and the labels
% are both printed in the \meta{color} specified.
% \end{function}
%
% \begin{function}[updated = 2011-09-02]
% {\coffin_mark_handle:Nnnn, \coffin_mark_handle:cnnn}
% \begin{syntax}
% \cs{coffin_mark_handle:Nnnn} \meta{coffin} \Arg{pole_1} \Arg{pole_2} \Arg{color}
% \end{syntax}
% This function first calculates the \meta{handle} for the
% \meta{coffin} as defined by the intersection of \meta{pole_1} and
% \meta{pole_2}. It then marks the position of the \meta{handle}
% on the \meta{coffin}. The \meta{handle} are labelled as part of
% this process: the location of the \meta{handle} and the label are
% both printed in the \meta{color} specified.
% \end{function}
%
% \begin{function}[updated = 2015-08-01]
% {\coffin_show_structure:N, \coffin_show_structure:c}
% \begin{syntax}
% \cs{coffin_show_structure:N} \meta{coffin}
% \end{syntax}
% This function shows the structural information about the
% \meta{coffin} in the terminal. The width, height and depth of the
% typeset material are given, along with the location of all of the
% poles of the coffin.
%
% Notice that the poles of a coffin are defined by four values:
% the $x$ and $y$ co-ordinates of a point that the pole
% passes through and the $x$- and $y$-components of a
% vector denoting the direction of the pole. It is the ratio between
% the later, rather than the absolute values, which determines the
% direction of the pole.
% \end{function}
%
% \begin{function}[added = 2014-08-22, updated = 2015-08-01]
% {\coffin_log_structure:N, \coffin_log_structure:c}
% \begin{syntax}
% \cs{coffin_log_structure:N} \meta{coffin}
% \end{syntax}
% This function writes the structural information about the
% \meta{coffin} in the log file. See also \cs{coffin_show_structure:N}
% which displays the result in the terminal.
% \end{function}
%
% \section{Constants and variables}
%
% \begin{variable}{\c_empty_coffin}
% A permanently empty coffin.
% \end{variable}
%
% \begin{variable}[added = 2012-06-19]{\l_tmpa_coffin, \l_tmpb_coffin}
% Scratch coffins 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}
%
% \end{documentation}
%
% \begin{implementation}
%
% \section{\pkg{l3coffins} Implementation}
%
% \begin{macrocode}
%<*initex|package>
% \end{macrocode}
%
% \begin{macrocode}
%<@@=coffin>
% \end{macrocode}
%
% \subsection{Coffins: data structures and general variables}
%
% \begin{variable}{\l_@@_internal_box}
% \begin{variable}{\l_@@_internal_dim}
% \begin{variable}{\l_@@_internal_tl}
% Scratch variables.
% \begin{macrocode}
\box_new:N \l_@@_internal_box
\dim_new:N \l_@@_internal_dim
\tl_new:N \l_@@_internal_tl
% \end{macrocode}
% \end{variable}
% \end{variable}
% \end{variable}
%
% \begin{variable}{\c_@@_corners_prop}
% The \enquote{corners}; of a coffin define the real content, as
% opposed to the \TeX{} bounding box. They all start off in the same
% place, of course.
% \begin{macrocode}
\prop_const_from_keyval:Nn \c_@@_corners_prop
{
tl = { 0pt } { 0pt } ,
tr = { 0pt } { 0pt } ,
bl = { 0pt } { 0pt } ,
br = { 0pt } { 0pt } ,
}
% \end{macrocode}
% \end{variable}
%
% \begin{variable}{\c_@@_poles_prop}
% Pole positions are given for horizontal, vertical and reference-point
% based values.
% \begin{macrocode}
\prop_const_from_keyval:Nn \c_@@_poles_prop
{
l = { 0pt } { 0pt } { 0pt } { 1000pt } ,
hc = { 0pt } { 0pt } { 0pt } { 1000pt } ,
r = { 0pt } { 0pt } { 0pt } { 1000pt } ,
b = { 0pt } { 0pt } { 1000pt } { 0pt } ,
vc = { 0pt } { 0pt } { 1000pt } { 0pt } ,
t = { 0pt } { 0pt } { 1000pt } { 0pt } ,
B = { 0pt } { 0pt } { 1000pt } { 0pt } ,
H = { 0pt } { 0pt } { 1000pt } { 0pt } ,
T = { 0pt } { 0pt } { 1000pt } { 0pt } ,
}
% \end{macrocode}
% \end{variable}
%
% \begin{variable}{\l_@@_slope_x_fp}
% \begin{variable}{\l_@@_slope_y_fp}
% Used for calculations of intersections.
% \begin{macrocode}
\fp_new:N \l_@@_slope_x_fp
\fp_new:N \l_@@_slope_y_fp
% \end{macrocode}
% \end{variable}
% \end{variable}
%
% \begin{variable}{\l_@@_error_bool}
% For propagating errors so that parts of the code can work around them.
% \begin{macrocode}
\bool_new:N \l_@@_error_bool
% \end{macrocode}
% \end{variable}
%
% \begin{variable}{\l_@@_offset_x_dim}
% \begin{variable}{\l_@@_offset_y_dim}
% The offset between two sets of coffin handles when typesetting. These
% values are corrected from those requested in an alignment for the
% positions of the handles.
% \begin{macrocode}
\dim_new:N \l_@@_offset_x_dim
\dim_new:N \l_@@_offset_y_dim
% \end{macrocode}
% \end{variable}
% \end{variable}
%
% \begin{variable}{\l_@@_pole_a_tl}
% \begin{variable}{\l_@@_pole_b_tl}
% Needed for finding the intersection of two poles.
% \begin{macrocode}
\tl_new:N \l_@@_pole_a_tl
\tl_new:N \l_@@_pole_b_tl
% \end{macrocode}
% \end{variable}
% \end{variable}
%
% \begin{variable}{\l_@@_x_dim}
% \begin{variable}{\l_@@_y_dim}
% \begin{variable}{\l_@@_x_prime_dim}
% \begin{variable}{\l_@@_y_prime_dim}
% For calculating intersections and so forth.
% \begin{macrocode}
\dim_new:N \l_@@_x_dim
\dim_new:N \l_@@_y_dim
\dim_new:N \l_@@_x_prime_dim
\dim_new:N \l_@@_y_prime_dim
% \end{macrocode}
% \end{variable}
% \end{variable}
% \end{variable}
% \end{variable}
%
% \subsection{Basic coffin functions}
%
% There are a number of basic functions needed for creating coffins and
% placing material in them. This all relies on the following data
% structures.
%
% \begin{macro}[EXP]{\@@_to_value:N}
% Coffins are a two-part structure and we rely on the internal nature of
% box allocation to make everything work. As such, we need an interface
% to turn coffin identifiers into numbers. For the purposes here, the
% signature allowed is |N| despite the nature of the underlying primitive.
% \begin{macrocode}
\cs_new_eq:NN \@@_to_value:N \tex_number:D
% \end{macrocode}
% \end{macro}
%
% \begin{macro}[EXP, pTF]{\coffin_if_exist:N, \coffin_if_exist:c}
% Several of the higher-level coffin functions would give multiple
% errors if the coffin does not exist. A cleaner way to handle this
% is provided here: the box and scope must exist. (The handle property
% list may not be present for a new coffin.)
% \begin{macrocode}
\prg_new_conditional:Npnn \coffin_if_exist:N #1 { p , T , F , TF }
{
\cs_if_exist:NTF #1
{
\cs_if_exist:cTF { g_@@_scope_ \@@_to_value:N #1 _tl }
{ \prg_return_true: }
{ \prg_return_false: }
}
{ \prg_return_false: }
}
\prg_generate_conditional_variant:Nnn \coffin_if_exist:N
{ c } { p , T , F , TF }
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_if_exist:NT}
% Several of the higher-level coffin functions would give multiple
% errors if the coffin does not exist. So a wrapper is provided to deal
% with this correctly, issuing an error on erroneous use.
% \begin{macrocode}
\cs_new_protected:Npn \@@_if_exist:NT #1#2
{
\coffin_if_exist:NTF #1
{ #2 }
{
\__kernel_msg_error:nnx { kernel } { unknown-coffin }
{ \token_to_str:N #1 }
}
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_check_scope:NN}
% A simple check to ensure that coffins are used correctly. If the scope
% is not yet set, it is determined at this stage.
% \begin{macrocode}
\cs_new_protected:Npn \@@_check_scope:NN #1#2
{
\@@_if_exist:NT #1
{
\tl_if_empty:cTF { g_@@_scope_ \@@_to_value:N #1 _tl }
{ \tl_gset:cn { g_@@_scope_ \@@_to_value:N #1 _tl } {#2} }
{
\str_if_eq:eeF
{ \tl_use:c { g_@@_scope_ \@@_to_value:N #1 _tl } } {#2}
{
\__kernel_msg_error:nnx { kernel } { wrong-coffin-scope }
{ \token_to_str:N #1 }
\tl_gset:cn { g_@@_scope_ \@@_to_value:N #1 _tl } {#2}
}
}
}
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}
% {
% \coffin_clear:N, \coffin_clear:c,
% \coffin_gclear:N, \coffin_gclear:c
% }
% Clearing coffins means emptying the box and resetting all of the
% structures.
% \begin{macrocode}
\cs_new_protected:Npn \coffin_clear:N #1
{
\@@_if_exist:NT #1
{
\@@_check_scope:NN #1 l
\box_clear:N #1
\@@_reset_structure:N #1
}
}
\cs_generate_variant:Nn \coffin_clear:N { c }
\cs_new_protected:Npn \coffin_gclear:N #1
{
\@@_if_exist:NT #1
{
\@@_check_scope:NN #1 g
\box_gclear:N #1
\@@_greset_structure:N #1
}
}
\cs_generate_variant:Nn \coffin_gclear:N { c }
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\coffin_new:N, \coffin_new:c}
% Creating a new coffin means making the underlying box and adding the
% data structures. These are created globally, as there is a need to
% avoid any strange effects if the coffin is created inside a group.
% This means that the usual rule about \cs[no-index]{l_\ldots}
% variables has to be broken. The \cs{debug_suspend:} and
% \cs{debug_resume:} functions prevent these checks. They also
% prevent \cs{prop_clear_new:c} from writing useless information to
% the log file.
% \begin{macrocode}
\cs_new_protected:Npn \coffin_new:N #1
{
\box_new:N #1
\debug_suspend:
\tl_new:c { g_@@_scope_ \@@_to_value:N #1 _tl }
\prop_clear_new:c { l_@@_corners_ \@@_to_value:N #1 _prop }
\prop_clear_new:c { l_@@_poles_ \@@_to_value:N #1 _prop }
\prop_gset_eq:cN { l_@@_corners_ \@@_to_value:N #1 _prop }
\c_@@_corners_prop
\prop_gset_eq:cN { l_@@_poles_ \@@_to_value:N #1 _prop }
\c_@@_poles_prop
\debug_resume:
}
\cs_generate_variant:Nn \coffin_new:N { c }
% \end{macrocode}
% \end{macro}
%
% \begin{macro}
% {
% \hcoffin_set:Nn, \hcoffin_set:cn,
% \hcoffin_gset:Nn, \hcoffin_gset:cn
% }
% \begin{macro}{\@@_set_horizontal:NnNNN}
% Horizontal coffins are relatively easy: set the appropriate box,
% reset the structures then update the handle positions.
% \begin{macrocode}
\cs_new_protected:Npn \hcoffin_set:Nn #1#2
{
\@@_set_horizontal:NnNNN
#1 {#2} \hbox_set:Nn \@@_update:N l
}
\cs_generate_variant:Nn \hcoffin_set:Nn { c }
\cs_new_protected:Npn \hcoffin_gset:Nn #1#2
{
\@@_set_horizontal:NnNNN
#1 {#2} \hbox_gset:Nn \@@_gupdate:N g
}
\cs_generate_variant:Nn \hcoffin_gset:Nn { c }
\cs_new_protected:Npn \@@_set_horizontal:NnNNN #1#2#3#4#5
{
\@@_if_exist:NT #1
{
\@@_check_scope:NN #1 #5
#3 #1
{
\color_ensure_current:
#2
}
#4 #1
}
}
% \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}
% {
% \vcoffin_set:Nnn, \vcoffin_set:cnn,
% \vcoffin_gset:Nnn, \vcoffin_gset:cnn
% }
% \begin{macro}{\@@_set_vertical:NnnNNN}
% Setting vertical coffins is more complex. First, the material is
% typeset with a given width. The default handles and poles are set as
% for a horizontal coffin, before finding the top baseline using a
% temporary box. No \cs{color_ensure_current:} here as that would add a
% whatsit to the start of the vertical box and mess up the location of the
% \texttt{T}~pole (see \emph{\TeX{} by Topic} for discussion of the
% \tn{vtop} primitive, used to do the measuring).
% \begin{macrocode}
\cs_new_protected:Npn \vcoffin_set:Nnn #1#2#3
{
\@@_set_vertical:NnnNNN
#1 {#2} {#3} \vbox_set:Nn \@@_update:N l
}
\cs_generate_variant:Nn \vcoffin_set:Nnn { c }
\cs_new_protected:Npn \vcoffin_gset:Nnn #1#2#3
{
\@@_set_vertical:NnnNNN
#1 {#2} {#3} \vbox_gset:Nn \@@_gupdate:N g
}
\cs_generate_variant:Nn \vcoffin_set:Nnn { c }
\cs_new_protected:Npn \@@_set_vertical:NnnNNN #1#2#3#4#5#6
{
\@@_if_exist:NT #1
{
\@@_check_scope:NN #1 #6
#4 #1
{
\dim_set:Nn \tex_hsize:D {#2}
%<*package>
\dim_set_eq:NN \linewidth \tex_hsize:D
\dim_set_eq:NN \columnwidth \tex_hsize:D
%</package>
#3
}
#5 #1
\vbox_set_top:Nn \l_@@_internal_box { \vbox_unpack:N #1 }
\@@_set_pole:Nnx #1 { T }
{
{ 0pt }
{
\dim_eval:n
{ \box_ht:N #1 - \box_ht:N \l_@@_internal_box }
}
{ 1000pt }
{ 0pt }
}
\box_clear:N \l_@@_internal_box
}
}
% \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}
% {
% \hcoffin_set:Nw, \hcoffin_set:cw,
% \hcoffin_gset:Nw, \hcoffin_gset:cw
% }
% \begin{macro}{\hcoffin_set_end:, \hcoffin_gset_end:}
% \begin{macro}{\@@_set_horizontal:NNNNw}
% These are the \enquote{begin}/\enquote{end} versions of the above:
% watch the grouping!
% \begin{macrocode}
\cs_new_protected:Npn \hcoffin_set:Nw #1
{
\@@_set_horizontal:NNNNw
#1 \hbox_set:Nw \@@_update:N l
}
\cs_generate_variant:Nn \hcoffin_set:Nw { c }
\cs_new_protected:Npn \hcoffin_gset:Nw #1
{
\@@_set_horizontal:NNNNw
#1 \hbox_gset:Nw \@@_gupdate:NN g
}
\cs_generate_variant:Nn \hcoffin_gset:Nw { c }
\cs_new_protected:Npn \@@_set_horizontal:NNNNw #1#2#3#4
{
\@@_if_exist:NT #1
{
\@@_check_scope:NN #1 #4
#2 #1 \color_ensure_current:
\cs_set_protected:Npn \hcoffin_set_end:
{
\hbox_set_end:
#3 #1
}
}
}
\cs_new_protected:Npn \hcoffin_set_end: { }
\cs_new_protected:Npn \hcoffin_gset_end: { }
% \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}
% {
% \vcoffin_set:Nnw, \vcoffin_set:cnw,
% \vcoffin_gset:Nnw, \vcoffin_gset:cnw
% }
% \begin{macro}{\vcoffin_set_end:, \vcoffin_gset_end:}
% \begin{macro}{\@@_set_vertical:NnNNNNNw}
% The same for vertical coffins.
% \begin{macrocode}
\cs_new_protected:Npn \vcoffin_set:Nnw #1#2
{
\@@_set_vertical:NnNNNNNw #1 {#2} \vbox_set:Nw
\vcoffin_set_end: \vbox_gset_end: \@@_update:N l
}
\cs_new_protected:Npn \vcoffin_gset:Nnw #1#2
{
\@@_set_vertical:NnNNNNNw #1 {#2} \vbox_gset:Nw
\vcoffin_gset_end: \vbox_gset_end: \@@_gupdate:N g
}
\cs_generate_variant:Nn \vcoffin_set:Nnw { c }
\cs_new_protected:Npn \@@_set_vertical:NnNNNNNw #1#2#3#4#5#6#7
{
\@@_if_exist:NT #1
{
\@@_check_scope:Nn #1 #7
#3 #1
\dim_set:Nn \tex_hsize:D {#2}
%<*package>
\dim_set_eq:NN \linewidth \tex_hsize:D
\dim_set_eq:NN \columnwidth \tex_hsize:D
%</package>
\cs_set_protected:Npn #4
{
#5
#6 #1
\vbox_set_top:Nn \l_@@_internal_box { \vbox_unpack:N #1 }
\@@_set_pole:Nnx #1 { T }
{
{ 0pt }
{
\dim_eval:n
{ \box_ht:N #1 - \box_ht:N \l_@@_internal_box }
}
{ 1000pt }
{ 0pt }
}
\box_clear:N \l_@@_internal_box
}
}
}
\cs_new_protected:Npn \vcoffin_set_end: { }
\cs_new_protected:Npn \vcoffin_gset_end: { }
% \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}
% {
% \coffin_set_eq:NN, \coffin_set_eq:Nc,
% \coffin_set_eq:cN, \coffin_set_eq:cc,
% \coffin_gset_eq:NN, \coffin_gset_eq:Nc,
% \coffin_gset_eq:cN, \coffin_gset_eq:cc
% }
% \begin{macro}{\@@_set_eq:NNNNNNN}
% \begin{macro}{\@@_set_eq:NNNNNN}
% Setting two coffins equal means checking the scope of the source
% coffin plus defining the scope of the target coffin. If the source
% coffin was never set up, we just clear the target.
% \begin{macrocode}
\cs_new_protected:Npn \coffin_set_eq:NN #1#2
{
\@@_set_eq:NNNNNNN #1 #2
\@@_reset_structure:N \box_set_eq:NN \prop_set_eq:cc l
\coffin_clear:N
}
\cs_generate_variant:Nn \coffin_set_eq:NN { c , Nc , cc }
\cs_new_protected:Npn \coffin_gset_eq:NN #1#2
{
\@@_set_eq:NNNNNNN #1 #2
\@@_greset_structure:N \box_gset_eq:NN \prop_gset_eq:cc g
\coffin_gclear:N
}
\cs_generate_variant:Nn \coffin_gset_eq:NN { c , Nc , cc }
\cs_new_protected:Npn \@@_set_eq:NNNNNNN #1#2#3#4#5#6#7
{
\@@_if_exist:NT #1
{
\@@_if_exist:NT #2
{
\tl_if_empty:cTF { g_@@_scope_ \@@_to_value:N #2 _tl }
{ #7 #2 }
{
#3 #1
#4 #1 #2
\exp_args:Nv \@@_set_eq:NNNNN
{ g_@@_scope_ \@@_to_value:N #2 _tl }
#1 #2 #5 #6
}
}
}
}
\cs_new_protected:Npn \@@_set_eq:NNNNN #1#2#3#4#5
{
#4
{ #5 _@@_corners_ \@@_to_value:N #2 _prop }
{ #1 _@@_corners_ \@@_to_value:N #3 _prop }
#4 { #5 _@@_poles_ \@@_to_value:N #2 _prop }
{ #1 _@@_poles_ \@@_to_value:N #3 _prop }
}
% \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{variable}{\c_empty_coffin}
% \begin{variable}{\l_@@_aligned_coffin}
% \begin{variable}{\l_@@_aligned_internal_coffin}
% Special coffins: these cannot be set up earlier as they need
% \cs{coffin_new:N}. The empty coffin is set as a box as the full
% coffin-setting system needs some material which is not yet available.
% The empty coffin is created entirely by hand: not everything is in place
% yet. The same is true for internal coffins, which need scope data.
% \begin{macrocode}
\coffin_new:N \c_empty_coffin
\coffin_new:N \l_@@_aligned_coffin
\coffin_new:N \l_@@_aligned_internal_coffin
\tl_gset:cn
{ g_@@_scope_ \@@_to_value:N \l_@@_aligned_coffin _tl } { l }
\tl_gset:cn
{ g_@@_scope_ \@@_to_value:N \l_@@_aligned_internal_coffin _tl }
{ l }
% \end{macrocode}
% \end{variable}
% \end{variable}
% \end{variable}
%
% \begin{variable}{\l_tmpa_coffin, \l_tmpb_coffin}
% The usual scratch space.
% \begin{macrocode}
\coffin_new:N \l_tmpa_coffin
\coffin_new:N \l_tmpb_coffin
% \end{macrocode}
% \end{variable}
%
% \subsection{Measuring coffins}
%
% \begin{macro}
% {
% \coffin_dp:N, \coffin_dp:c, \coffin_ht:N, \coffin_ht:c,
% \coffin_wd:N, \coffin_wd:c
% }
% Coffins are just boxes when it comes to measurement. However, semantically
% a separate set of functions are required.
% \begin{macrocode}
\cs_new_eq:NN \coffin_dp:N \box_dp:N
\cs_new_eq:NN \coffin_dp:c \box_dp:c
\cs_new_eq:NN \coffin_ht:N \box_ht:N
\cs_new_eq:NN \coffin_ht:c \box_ht:c
\cs_new_eq:NN \coffin_wd:N \box_wd:N
\cs_new_eq:NN \coffin_wd:c \box_wd:c
% \end{macrocode}
% \end{macro}
%
% \subsection{Coffins: handle and pole management}
%
% \begin{macro}{\@@_get_pole:NnN}
% A simple wrapper around the recovery of a coffin pole, with some
% error checking and recovery built-in.
% \begin{macrocode}
\cs_new_protected:Npn \@@_get_pole:NnN #1#2#3
{
\prop_get:cnNF
{ l_@@_poles_ \@@_to_value:N #1 _prop } {#2} #3
{
\__kernel_msg_error:nnxx { kernel } { unknown-coffin-pole }
{ \exp_not:n {#2} } { \token_to_str:N #1 }
\tl_set:Nn #3 { { 0pt } { 0pt } { 0pt } { 0pt } }
}
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_reset_structure:N, \@@_greset_structure:N}
% \begin{macro}{\@@_reset_structure:NNN}
% Resetting structure needs to cover the case where the structures have not
% been created. These are created globally, as there is a need to
% avoid any strange effects if the coffin is created inside a group.
% This means that the usual rule about \cs[no-index]{l_\ldots}
% variables has to be broken. The \cs{debug_suspend:} and
% \cs{debug_resume:} functions prevent these checks. They also
% prevent \cs{prop_clear_new:c} from writing useless information to
% the log file.
% \begin{macrocode}
\cs_new_protected:Npn \@@_reset_structure:N #1
{ \@@_reset_structure:NNN #1 l \prop_set_eq:cN }
\cs_new_protected:Npn \@@_greset_structure:N #1
{ \@@_reset_structure:NNN #1 g \prop_gset_eq:cN }
\cs_new_protected:Npn \@@_reset_structure:NNN #1#2#3
{
\debug_suspend:
\prop_if_exist:cF { #2 _@@_corners_ \@@_to_value:N #1 _prop }
{
\prop_new:c { #2 _@@_corners_ \@@_to_value:N #1 _prop }
\prop_new:c { #2 _@@_poles_ \@@_to_value:N #1 _prop }
\prop_gset_eq:cN { #2 _@@_corners_ \@@_to_value:N #1 _prop }
\c_@@_corners_prop
\prop_gset_eq:cN { #2 _@@_poles_ \@@_to_value:N #1 _prop }
\c_@@_poles_prop
}
\debug_resume:
#3 { #2 _@@_corners_ \@@_to_value:N #1 _prop }
\c_@@_corners_prop
#3 { #2 _@@_poles_ \@@_to_value:N #1 _prop }
\c_@@_poles_prop
}
% \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}
% {\coffin_set_horizontal_pole:Nnn, \coffin_set_horizontal_pole:cnn}
% \begin{macro}{\coffin_set_vertical_pole:Nnn, \coffin_set_vertical_pole:cnn}
% \begin{macro}{\@@_set_pole:Nnn, \@@_set_pole:Nnx}
% Setting the pole of a coffin at the user/designer level requires a
% bit more care. The idea here is to provide a reasonable interface to
% the system, then to do the setting with full expansion. The
% three-argument version is used internally to do a direct setting.
% \begin{macrocode}
\cs_new_protected:Npn \coffin_set_horizontal_pole:Nnn #1#2#3
{
\@@_if_exist:NT #1
{
\@@_set_pole:Nnx #1 {#2}
{
{ 0pt } { \dim_eval:n {#3} }
{ 1000pt } { 0pt }
}
}
}
\cs_new_protected:Npn \coffin_set_vertical_pole:Nnn #1#2#3
{
\@@_if_exist:NT #1
{
\@@_set_pole:Nnx #1 {#2}
{
{ \dim_eval:n {#3} } { 0pt }
{ 0pt } { 1000pt }
}
}
}
\cs_new_protected:Npn \@@_set_pole:Nnn #1#2#3
{
\prop_put:cnn { l_@@_poles_ \@@_to_value:N #1 _prop }
{#2} {#3}
}
\cs_generate_variant:Nn \coffin_set_horizontal_pole:Nnn { c }
\cs_generate_variant:Nn \coffin_set_vertical_pole:Nnn { c }
\cs_generate_variant:Nn \@@_set_pole:Nnn { Nnx }
% \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%