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
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
|
% \iffalse meta-comment
%
%% File: l3coffins.dtx
%
% Copyright (C) 2010-2020 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 2020-12-07}
%
% \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-21]
% {
% \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}.
% \end{function}
%
% \begin{function}[added = 2011-08-17, updated = 2019-01-21]
% {
% \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}
%
% \begin{function}[added = 2011-08-17, updated = 2019-01-21]
% {
% \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, updated = 2019-01-21]
% {
% \hcoffin_set:Nw, \hcoffin_set:cw, \hcoffin_set_end:,
% \hcoffin_gset:Nw, \hcoffin_gset:cw, \hcoffin_gset_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-21]
% {
% \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 = 2019-01-21]
% {
% \vcoffin_set:Nnw, \vcoffin_set:cnw, \vcoffin_set_end:,
% \vcoffin_gset:Nnw, \vcoffin_gset:cnw, \vcoffin_gset_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, updated = 2019-01-21]
% {
% \coffin_set_horizontal_pole:Nnn, \coffin_set_horizontal_pole:cnn,
% \coffin_gset_horizontal_pole:Nnn, \coffin_gset_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, updated = 2019-01-21]
% {
% \coffin_set_vertical_pole:Nnn, \coffin_set_vertical_pole:cnn,
% \coffin_gset_vertical_pole:Nnn, \coffin_gset_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{Coffin affine transformations}
%
% \begin{function}[updated = 2019-01-23]
% {
% \coffin_resize:Nnn, \coffin_resize:cnn,
% \coffin_gresize:Nnn, \coffin_gresize:cnn
% }
% \begin{syntax}
% \cs{coffin_resize:Nnn} \meta{coffin} \Arg{width} \Arg{total-height}
% \end{syntax}
% Resized the \meta{coffin} to \meta{width} and \meta{total-height},
% both of which should be given as dimension expressions.
% \end{function}
%
% \begin{function}
% {
% \coffin_rotate:Nn, \coffin_rotate:cn,
% \coffin_grotate:Nn, \coffin_grotate:cn
% }
% \begin{syntax}
% \cs{coffin_rotate:Nn} \meta{coffin} \Arg{angle}
% \end{syntax}
% Rotates the \meta{coffin} by the given \meta{angle} (given in
% degrees counter-clockwise). This process rotates both the
% coffin content and poles. Multiple rotations do not result in
% the bounding box of the coffin growing unnecessarily.
% \end{function}
%
% \begin{function}[updated = 2019-01-23]
% {
% \coffin_scale:Nnn, \coffin_scale:cnn,
% \coffin_gscale:Nnn, \coffin_gscale:cnn
% }
% \begin{syntax}
% \cs{coffin_scale:Nnn} \meta{coffin} \Arg{x-scale} \Arg{y-scale}
% \end{syntax}
% Scales the \meta{coffin} by a factors \meta{x-scale} and
% \meta{y-scale} in the horizontal and vertical directions,
% respectively. The two scale factors should be given as real numbers.
% \end{function}
%
% \section{Joining and using coffins}
%
% \begin{function}[updated = 2019-01-22]
% {
% \coffin_attach:NnnNnnnn, \coffin_attach:cnnNnnnn,
% \coffin_attach:Nnncnnnn, \coffin_attach:cnncnnnn,
% \coffin_gattach:NnnNnnnn, \coffin_gattach:cnnNnnnn,
% \coffin_gattach:Nnncnnnn, \coffin_gattach: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}[updated = 2019-01-22]
% {
% \coffin_join:NnnNnnnn, \coffin_join:cnnNnnnn,
% \coffin_join:Nnncnnnn, \coffin_join:cnncnnnn,
% \coffin_gjoin:NnnNnnnn, \coffin_gjoin:cnnNnnnn,
% \coffin_gjoin:Nnncnnnn, \coffin_gjoin: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}
%
% \begin{variable}[added = 2019-01-24]{\g_tmpa_coffin, \g_tmpb_coffin}
% Scratch coffins 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}
%
% \end{documentation}
%
% \begin{implementation}
%
% \section{\pkg{l3coffins} Implementation}
%
% \begin{macrocode}
%<*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_A_fp}
% \begin{variable}{\l_@@_slope_B_fp}
% Used for calculations of intersections.
% \begin{macrocode}
\fp_new:N \l_@@_slope_A_fp
\fp_new:N \l_@@_slope_B_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: both the box and the coffin structure are
% checked.
% \begin{macrocode}
\prg_new_conditional:Npnn \coffin_if_exist:N #1 { p , T , F , TF }
{
\cs_if_exist:NTF #1
{
\cs_if_exist:cTF { coffin ~ \@@_to_value:N #1 ~ poles }
{ \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}
% {
% \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
{
\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
{
\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. The \cs{debug_suspend:} and \cs{debug_resume:} functions
% prevent \cs{prop_gclear_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:
\prop_gclear_new:c { coffin ~ \@@_to_value:N #1 ~ corners }
\prop_gclear_new:c { coffin ~ \@@_to_value:N #1 ~ poles }
\prop_gset_eq:cN { coffin ~ \@@_to_value:N #1 ~ corners }
\c_@@_corners_prop
\prop_gset_eq:cN { coffin ~ \@@_to_value:N #1 ~ poles }
\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
% }
% 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
{
\@@_if_exist:NT #1
{
\hbox_set:Nn #1
{
\color_ensure_current:
#2
}
\@@_update:N #1
}
}
\cs_generate_variant:Nn \hcoffin_set:Nn { c }
\cs_new_protected:Npn \hcoffin_gset:Nn #1#2
{
\@@_if_exist:NT #1
{
\hbox_gset:Nn #1
{
\color_ensure_current:
#2
}
\@@_gupdate:N #1
}
}
\cs_generate_variant:Nn \hcoffin_gset:Nn { c }
% \end{macrocode}
% \end{macro}
%
% \begin{macro}
% {
% \vcoffin_set:Nnn, \vcoffin_set:cnn,
% \vcoffin_gset:Nnn, \vcoffin_gset:cnn
% }
% \begin{macro}{\@@_set_vertical:NnnNN}
% \begin{macro}{\@@_set_vertical_aux:}
% 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:NnnNN #1 {#2} {#3}
\vbox_set:Nn \@@_update:N
}
\cs_generate_variant:Nn \vcoffin_set:Nnn { c }
\cs_new_protected:Npn \vcoffin_gset:Nnn #1#2#3
{
\@@_set_vertical:NnnNN #1 {#2} {#3}
\vbox_gset:Nn \@@_gupdate:N
}
\cs_generate_variant:Nn \vcoffin_gset:Nnn { c }
\cs_new_protected:Npn \@@_set_vertical:NnnNN #1#2#3#4#5
{
\@@_if_exist:NT #1
{
#4 #1
{
\dim_set:Nn \tex_hsize:D {#2}
\@@_set_vertical_aux:
#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
}
}
\cs_new_protected:Npx \@@_set_vertical_aux:
{
\bool_lazy_and:nnT
{ \cs_if_exist_p:N \fmtname }
{ \str_if_eq_p:Vn \fmtname { LaTeX2e } }
{
\dim_set_eq:NN \exp_not:N \linewidth \tex_hsize:D
\dim_set_eq:NN \exp_not:N \columnwidth \tex_hsize:D
}
}
% \end{macrocode}
% \end{macro}
% \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:}
% These are the \enquote{begin}/\enquote{end} versions of the above:
% watch the grouping!
% \begin{macrocode}
\cs_new_protected:Npn \hcoffin_set:Nw #1
{
\@@_if_exist:NT #1
{
\hbox_set:Nw #1 \color_ensure_current:
\cs_set_protected:Npn \hcoffin_set_end:
{
\hbox_set_end:
\@@_update:N #1
}
}
}
\cs_generate_variant:Nn \hcoffin_set:Nw { c }
\cs_new_protected:Npn \hcoffin_gset:Nw #1
{
\@@_if_exist:NT #1
{
\hbox_gset:Nw #1 \color_ensure_current:
\cs_set_protected:Npn \hcoffin_gset_end:
{
\hbox_gset_end:
\@@_gupdate:N #1
}
}
}
\cs_generate_variant:Nn \hcoffin_gset:Nw { c }
\cs_new_protected:Npn \hcoffin_set_end: { }
\cs_new_protected:Npn \hcoffin_gset_end: { }
% \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}
% {\vcoffin_set:Nnw, \vcoffin_set:cnw, \vcoffin_gset:Nnw, \vcoffin_gset:cnw}
% \begin{macro}{\@@_set_vertical:NnNNNNw}
% \begin{macro}{\vcoffin_set_end:, \vcoffin_gset_end:}
% The same for vertical coffins.
% \begin{macrocode}
\cs_new_protected:Npn \vcoffin_set:Nnw #1#2
{
\@@_set_vertical:NnNNNNw #1 {#2} \vbox_set:Nw
\vcoffin_set_end:
\vbox_set_end: \@@_update:N
}
\cs_generate_variant:Nn \vcoffin_set:Nnw { c }
\cs_new_protected:Npn \vcoffin_gset:Nnw #1#2
{
\@@_set_vertical:NnNNNNw #1 {#2} \vbox_gset:Nw
\vcoffin_gset_end:
\vbox_gset_end: \@@_gupdate:N
}
\cs_generate_variant:Nn \vcoffin_gset:Nnw { c }
\cs_new_protected:Npn \@@_set_vertical:NnNNNNw #1#2#3#4#5#6
{
\@@_if_exist:NT #1
{
#3 #1
\dim_set:Nn \tex_hsize:D {#2}
\@@_set_vertical_aux:
\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
% }
% Setting two coffins equal is just a wrapper around other functions.
% \begin{macrocode}
\cs_new_protected:Npn \coffin_set_eq:NN #1#2
{
\@@_if_exist:NT #1
{
\box_set_eq:NN #1 #2
\prop_set_eq:cc { coffin ~ \@@_to_value:N #1 ~ corners }
{ coffin ~ \@@_to_value:N #2 ~ corners }
\prop_set_eq:cc { coffin ~ \@@_to_value:N #1 ~ poles }
{ coffin ~ \@@_to_value:N #2 ~ poles }
}
}
\cs_generate_variant:Nn \coffin_set_eq:NN { c , Nc , cc }
\cs_new_protected:Npn \coffin_gset_eq:NN #1#2
{
\@@_if_exist:NT #1
{
\box_gset_eq:NN #1 #2
\prop_gset_eq:cc { coffin ~ \@@_to_value:N #1 ~ corners }
{ coffin ~ \@@_to_value:N #2 ~ corners }
\prop_gset_eq:cc { coffin ~ \@@_to_value:N #1 ~ poles }
{ coffin ~ \@@_to_value:N #2 ~ poles }
}
}
\cs_generate_variant:Nn \coffin_gset_eq:NN { c , Nc , cc }
% \end{macrocode}
% \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 creted entirely by hand: not everything is in place
% yet.
% \begin{macrocode}
\coffin_new:N \c_empty_coffin
\coffin_new:N \l_@@_aligned_coffin
\coffin_new:N \l_@@_aligned_internal_coffin
% \end{macrocode}
% \end{variable}
% \end{variable}
% \end{variable}
%
% \begin{variable}
% {\l_tmpa_coffin, \l_tmpb_coffin, \g_tmpa_coffin, \g_tmpb_coffin}
% The usual scratch space.
% \begin{macrocode}
\coffin_new:N \l_tmpa_coffin
\coffin_new:N \l_tmpb_coffin
\coffin_new:N \g_tmpa_coffin
\coffin_new:N \g_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
{ coffin ~ \@@_to_value:N #1 ~ poles } {#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}
% Resetting the structure is a simple copy job.
% \begin{macrocode}
\cs_new_protected:Npn \@@_reset_structure:N #1
{
\prop_set_eq:cN { coffin ~ \@@_to_value:N #1 ~ corners }
\c_@@_corners_prop
\prop_set_eq:cN { coffin ~ \@@_to_value:N #1 ~ poles }
\c_@@_poles_prop
}
\cs_new_protected:Npn \@@_greset_structure:N #1
{
\prop_gset_eq:cN { coffin ~ \@@_to_value:N #1 ~ corners }
\c_@@_corners_prop
\prop_gset_eq:cN { coffin ~ \@@_to_value:N #1 ~ poles }
\c_@@_poles_prop
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}
% {
% \coffin_set_horizontal_pole:Nnn, \coffin_set_horizontal_pole:cnn,
% \coffin_gset_horizontal_pole:Nnn, \coffin_gset_horizontal_pole:cnn
% }
% \begin{macro}{\@@_set_horizontal_pole:NnnN}
% \begin{macro}
% {
% \coffin_set_vertical_pole:Nnn, \coffin_set_vertical_pole:cnn,
% \coffin_gset_vertical_pole:Nnn, \coffin_gset_vertical_pole:cnn
% }
% \begin{macro}{\@@_set_vertical_pole:NnnN}
% \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
{ \@@_set_horizontal_pole:NnnN #1 {#2} {#3} \prop_put:cnx }
\cs_generate_variant:Nn \coffin_set_horizontal_pole:Nnn { c }
\cs_new_protected:Npn \coffin_gset_horizontal_pole:Nnn #1#2#3
{ \@@_set_horizontal_pole:NnnN #1 {#2} {#3} \prop_gput:cnx }
\cs_generate_variant:Nn \coffin_gset_horizontal_pole:Nnn { c }
\cs_new_protected:Npn \@@_set_horizontal_pole:NnnN #1#2#3#4
{
\@@_if_exist:NT #1
{
#4 { coffin ~ \@@_to_value:N #1 ~ poles }
{#2}
{
{ 0pt } { \dim_eval:n {#3} }
{ 1000pt } { 0pt }
}
}
}
\cs_new_protected:Npn \coffin_set_vertical_pole:Nnn #1#2#3
{ \@@_set_vertical_pole:NnnN #1 {#2} {#3} \prop_put:cnx }
\cs_generate_variant:Nn \coffin_set_vertical_pole:Nnn { c }
\cs_new_protected:Npn \coffin_gset_vertical_pole:Nnn #1#2#3
{ \@@_set_vertical_pole:NnnN #1 {#2} {#3} \prop_gput:cnx }
\cs_generate_variant:Nn \coffin_gset_vertical_pole:Nnn { c }
\cs_new_protected:Npn \@@_set_vertical_pole:NnnN #1#2#3#4
{
\@@_if_exist:NT #1
{
#4 { coffin ~ \@@_to_value:N #1 ~ poles }
{#2}
{
{ \dim_eval:n {#3} } { 0pt }
{ 0pt } { 1000pt }
}
}
}
\cs_new_protected:Npn \@@_set_pole:Nnn #1#2#3
{
\prop_put:cnn { coffin ~ \@@_to_value:N #1 ~ poles }
{#2} {#3}
}
\cs_generate_variant:Nn \@@_set_pole:Nnn { Nnx }
% \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\@@_update:N, \@@_gupdate:N}
% Simple shortcuts.
% \begin{macrocode}
\cs_new_protected:Npn \@@_update:N #1
{
\@@_reset_structure:N #1
\@@_update_corners:N #1
\@@_update_poles:N #1
}
\cs_new_protected:Npn \@@_gupdate:N #1
{
\@@_greset_structure:N #1
\@@_gupdate_corners:N #1
\@@_gupdate_poles:N #1
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_update_corners:N, \@@_gupdate_corners:N}
% \begin{macro}{\@@_update_corners:NN}
% \begin{macro}{\@@_update_corners:NNN}
% Updating the corners of a coffin is straight-forward as at this stage
% there can be no rotation. So the corners of the content are just those
% of the underlying \TeX{} box.
% \begin{macrocode}
\cs_new_protected:Npn \@@_update_corners:N #1
{ \@@_update_corners:NN #1 \prop_put:Nnx }
\cs_new_protected:Npn \@@_gupdate_corners:N #1
{ \@@_update_corners:NN #1 \prop_gput:Nnx }
\cs_new_protected:Npn \@@_update_corners:NN #1#2
{
\exp_args:Nc \@@_update_corners:NNN
{ coffin ~ \@@_to_value:N #1 ~ corners }
#1 #2
}
\cs_new_protected:Npn \@@_update_corners:NNN #1#2#3
{
#3 #1
{ tl }
{ { 0pt } { \dim_eval:n { \box_ht:N #2 } } }
#3 #1
{ tr }
{
{ \dim_eval:n { \box_wd:N #2 } }
{ \dim_eval:n { \box_ht:N #2 } }
}
#3 #1
{ bl }
{ { 0pt } { \dim_eval:n { -\box_dp:N #2 } } }
#3 #1
{ br }
{
{ \dim_eval:n { \box_wd:N #2 } }
{ \dim_eval:n { -\box_dp:N #2 } }
}
}
% \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\@@_update_poles:N, \@@_gupdate_poles:N}
% \begin{macro}{\@@_update_poles:NN}
% \begin{macro}{\@@_update_poles:NNN}
% This function is called when a coffin is set, and updates the poles to
% reflect the nature of size of the box. Thus this function only alters
% poles where the default position is dependent on the size of the box.
% It also does not set poles which are relevant only to vertical
% coffins.
% \begin{macrocode}
\cs_new_protected:Npn \@@_update_poles:N #1
{ \@@_update_poles:NN #1 \prop_put:Nnx }
\cs_new_protected:Npn \@@_gupdate_poles:N #1
{ \@@_update_poles:NN #1 \prop_gput:Nnx }
\cs_new_protected:Npn \@@_update_poles:NN #1#2
{
\exp_args:Nc \@@_update_poles:NNN
{ coffin ~ \@@_to_value:N #1 ~ poles }
#1 #2
}
\cs_new_protected:Npn \@@_update_poles:NNN #1#2#3
{
#3 #1 { hc }
{
{ \dim_eval:n { 0.5 \box_wd:N #2 } }
{ 0pt } { 0pt } { 1000pt }
}
#3 #1 { r }
{
{ \dim_eval:n { \box_wd:N #2 } }
{ 0pt } { 0pt } { 1000pt }
}
#3 #1 { vc }
{
{ 0pt }
{ \dim_eval:n { ( \box_ht:N #2 - \box_dp:N #2 ) / 2 } }
{ 1000pt }
{ 0pt }
}
#3 #1 { t }
{
{ 0pt }
{ \dim_eval:n { \box_ht:N #2 } }
{ 1000pt }
{ 0pt }
}
#3 #1 { b }
{
{ 0pt }
{ \dim_eval:n { -\box_dp:N #2 } }
{ 1000pt }
{ 0pt }
}
}
% \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \subsection{Coffins: calculation of pole intersections}
%
% \begin{macro}{\@@_calculate_intersection:Nnn}
% \begin{macro}{\@@_calculate_intersection:nnnnnnnn}
% \begin{macro}{\@@_calculate_intersection:nnnnnn}
% The lead off in finding intersections is to recover the two poles
% and then hand off to the auxiliary for the actual calculation. There
% may of course not be an intersection, for which an error trap is
% needed.
% \begin{macrocode}
\cs_new_protected:Npn \@@_calculate_intersection:Nnn #1#2#3
{
\@@_get_pole:NnN #1 {#2} \l_@@_pole_a_tl
\@@_get_pole:NnN #1 {#3} \l_@@_pole_b_tl
\bool_set_false:N \l_@@_error_bool
\exp_last_two_unbraced:Noo
\@@_calculate_intersection:nnnnnnnn
\l_@@_pole_a_tl \l_@@_pole_b_tl
\bool_if:NT \l_@@_error_bool
{
\__kernel_msg_error:nn { kernel } { no-pole-intersection }
\dim_zero:N \l_@@_x_dim
\dim_zero:N \l_@@_y_dim
}
}
% \end{macrocode}
% The two poles passed here each have four values (as dimensions),
% ($a$, $b$, $c$, $d$) and
% ($a'$, $b'$, $c'$, $d'$). These are arguments
% $1$--$4$ and $5$--$8$, respectively. In both
% cases $a$ and $b$ are the co-ordinates of a point on the
% pole and $c$ and $d$ define the direction of the pole. Finding
% the intersection depends on the directions of the poles, which are
% given by $d / c$ and $d' / c'$. However, if one of the poles
% is either horizontal or vertical then one or more of $c$, $d$,
% $c'$ and $d'$ are zero and a special case is needed.
% \begin{macrocode}
\cs_new_protected:Npn \@@_calculate_intersection:nnnnnnnn
#1#2#3#4#5#6#7#8
{
\dim_compare:nNnTF {#3} = \c_zero_dim
% \end{macrocode}
% The case where the first pole is vertical. So the $x$-component
% of the interaction is at $a$. There is then a test on the
% second pole: if it is also vertical then there is an error.
% \begin{macrocode}
{
\dim_set:Nn \l_@@_x_dim {#1}
\dim_compare:nNnTF {#7} = \c_zero_dim
{ \bool_set_true:N \l_@@_error_bool }
% \end{macrocode}
% The second pole may still be horizontal, in which case the
% $y$-component of the intersection is $b'$. If not,
% \[
% y = \frac{d'}{c'} \left ( a - a' \right ) + b'
% \]
% with the $x$-component already known to be |#1|.
% \begin{macrocode}
{
\dim_set:Nn \l_@@_y_dim
{
\dim_compare:nNnTF {#8} = \c_zero_dim
{#6}
{
\fp_to_dim:n
{
( \dim_to_fp:n {#8} / \dim_to_fp:n {#7} )
* ( \dim_to_fp:n {#1} - \dim_to_fp:n {#5} )
+ \dim_to_fp:n {#6}
}
}
}
}
}
% \end{macrocode}
% If the first pole is not vertical then it may be horizontal. If so,
% then the procedure is essentially the same as that already done but
% with the $x$- and $y$-components interchanged.
% \begin{macrocode}
{
\dim_compare:nNnTF {#4} = \c_zero_dim
{
\dim_set:Nn \l_@@_y_dim {#2}
\dim_compare:nNnTF {#8} = { \c_zero_dim }
{ \bool_set_true:N \l_@@_error_bool }
{
% \end{macrocode}
% Now we deal with the case where the second pole may be vertical, or
% if not we have
% \[
% x = \frac{c'}{d'} \left ( b - b' \right ) + a'
% \]
% which is again handled by the same auxiliary.
% \begin{macrocode}
\dim_set:Nn \l_@@_x_dim
{
\dim_compare:nNnTF {#7} = \c_zero_dim
{#5}
{
\fp_to_dim:n
{
( \dim_to_fp:n {#7} / \dim_to_fp:n {#8} )
* ( \dim_to_fp:n {#4} - \dim_to_fp:n {#6} )
+ \dim_to_fp:n {#5}
}
}
}
}
}
% \end{macrocode}
% The first pole is neither horizontal nor vertical. To avoid even
% more complexity, we now work out both slopes and pass to an auxiliary.
% \begin{macrocode}
{
\use:x
{
\@@_calculate_intersection:nnnnnn
{ \dim_to_fp:n {#4} / \dim_to_fp:n {#3} }
{ \dim_to_fp:n {#8} / \dim_to_fp:n {#7} }
}
{#1} {#2} {#5} {#6}
}
}
}
% \end{macrocode}
% Assuming the two poles are not parallel, then the intersection point is
% found in two steps. First we find the $x$-value with
% \[
% x = \frac { sa - s'a' - b + b' }{ s - s' }
% \]
% and then finding the $y$-value with
% \[
% y = s ( x - a ) + b
% \]
% \begin{macrocode}
\cs_set_protected:Npn \@@_calculate_intersection:nnnnnn #1#2#3#4#5#6
{
\fp_compare:nNnTF {#1} = {#2}
{ \bool_set_true:N \l_@@_error_bool }
{
\dim_set:Nn \l_@@_x_dim
{
\fp_to_dim:n
{
(
#1 * \dim_to_fp:n {#3}
- #2 * \dim_to_fp:n {#5}
- \dim_to_fp:n {#4}
+ \dim_to_fp:n {#6}
)
/
( #1 - #2 )
}
}
\dim_set:Nn \l_@@_y_dim
{
\fp_to_dim:n
{
#1 * ( \l_@@_x_dim - \dim_to_fp:n {#3} )
+ \dim_to_fp:n {#4}
}
}
}
}
% \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \subsection{Affine transformations}
%
% \begin{variable}{\l_@@_sin_fp}
% \begin{variable}{\l_@@_cos_fp}
% Used for rotations to get the sine and cosine values.
% \begin{macrocode}
\fp_new:N \l_@@_sin_fp
\fp_new:N \l_@@_cos_fp
% \end{macrocode}
% \end{variable}
% \end{variable}
%
% \begin{variable}{\l_@@_bounding_prop}
% A property list for the bounding box of a coffin. This is only needed
% during the rotation, so there is just the one.
% \begin{macrocode}
\prop_new:N \l_@@_bounding_prop
% \end{macrocode}
% \end{variable}
%
% \begin{variable}{\l_@@_corners_prop, \l_@@_poles_prop}
% Used to avoid needing to track scope for intermediate steps.
% \begin{macrocode}
\prop_new:N \l_@@_corners_prop
\prop_new:N \l_@@_poles_prop
% \end{macrocode}
% \end{variable}
%
% \begin{variable}{\l_@@_bounding_shift_dim}
% The shift of the bounding box of a coffin from the real content.
% \begin{macrocode}
\dim_new:N \l_@@_bounding_shift_dim
% \end{macrocode}
% \end{variable}
%
% \begin{variable}{\l_@@_left_corner_dim}
% \begin{variable}{\l_@@_right_corner_dim}
% \begin{variable}{\l_@@_bottom_corner_dim}
% \begin{variable}{\l_@@_top_corner_dim}
% These are used to hold maxima for the various corner values: these
% thus define the minimum size of the bounding box after rotation.
% \begin{macrocode}
\dim_new:N \l_@@_left_corner_dim
\dim_new:N \l_@@_right_corner_dim
\dim_new:N \l_@@_bottom_corner_dim
\dim_new:N \l_@@_top_corner_dim
% \end{macrocode}
% \end{variable}
% \end{variable}
% \end{variable}
% \end{variable}
%
% \begin{macro}
% {
% \coffin_rotate:Nn, \coffin_rotate:cn,
% \coffin_grotate:Nn, \coffin_grotate:cn
% }
% \begin{macro}{\@@_rotate:NnNNN}
% Rotating a coffin requires several steps which can be conveniently
% run together. The sine and cosine of the angle in degrees are
% computed. This is then used to set \cs{l_@@_sin_fp} and
% \cs{l_@@_cos_fp}, which are carried through unchanged for the rest
% of the procedure.
% \begin{macrocode}
\cs_new_protected:Npn \coffin_rotate:Nn #1#2
{ \@@_rotate:NnNNN #1 {#2} \box_rotate:Nn \prop_set_eq:cN \hbox_set:Nn }
\cs_generate_variant:Nn \coffin_rotate:Nn { c }
\cs_new_protected:Npn \coffin_grotate:Nn #1#2
{ \@@_rotate:NnNNN #1 {#2} \box_grotate:Nn \prop_gset_eq:cN \hbox_gset:Nn }
\cs_generate_variant:Nn \coffin_grotate:Nn { c }
\cs_new_protected:Npn \@@_rotate:NnNNN #1#2#3#4#5
{
\fp_set:Nn \l_@@_sin_fp { sind ( #2 ) }
\fp_set:Nn \l_@@_cos_fp { cosd ( #2 ) }
% \end{macrocode}
% Use a local copy of the property lists to avoid needing to pass the
% name and scope around.
% \begin{macrocode}
\prop_set_eq:Nc \l_@@_corners_prop
{ coffin ~ \@@_to_value:N #1 ~ corners }
\prop_set_eq:Nc \l_@@_poles_prop
{ coffin ~ \@@_to_value:N #1 ~ poles }
% \end{macrocode}
% The corners and poles of the coffin can now be rotated around the
% origin. This is best achieved using mapping functions.
% \begin{macrocode}
\prop_map_inline:Nn \l_@@_corners_prop
{ \@@_rotate_corner:Nnnn #1 {##1} ##2 }
\prop_map_inline:Nn \l_@@_poles_prop
{ \@@_rotate_pole:Nnnnnn #1 {##1} ##2 }
% \end{macrocode}
% The bounding box of the coffin needs to be rotated, and to do this
% the corners have to be found first. They are then rotated in the same
% way as the corners of the coffin material itself.
% \begin{macrocode}
\@@_set_bounding:N #1
\prop_map_inline:Nn \l_@@_bounding_prop
{ \@@_rotate_bounding:nnn {##1} ##2 }
% \end{macrocode}
% At this stage, there needs to be a calculation to find where the
% corners of the content and the box itself will end up.
% \begin{macrocode}
\@@_find_corner_maxima:N #1
\@@_find_bounding_shift:
#3 #1 {#2}
% \end{macrocode}
% The correction of the box position itself takes place here. The idea
% is that the bounding box for a coffin is tight up to the content, and
% has the reference point at the bottom-left. The $x$-direction is
% handled by moving the content by the difference in the positions of
% the bounding box and the content left edge. The $y$-direction is
% dealt with by moving the box down by any depth it has acquired. The
% internal box is used here to allow for the next step.
% \begin{macrocode}
\hbox_set:Nn \l_@@_internal_box
{
\tex_kern:D
\dim_eval:n
{ \l_@@_bounding_shift_dim - \l_@@_left_corner_dim }
\exp_stop_f:
\box_move_down:nn { \l_@@_bottom_corner_dim }
{ \box_use:N #1 }
}
% \end{macrocode}
% If there have been any previous rotations then the size of the
% bounding box will be bigger than the contents. This can be corrected
% easily by setting the size of the box to the height and width of the
% content. As this operation requires setting box dimensions and these
% transcend grouping, the safe way to do this is to use the internal box
% and to reset the result into the target box.
% \begin{macrocode}
\box_set_ht:Nn \l_@@_internal_box
{ \l_@@_top_corner_dim - \l_@@_bottom_corner_dim }
\box_set_dp:Nn \l_@@_internal_box { 0pt }
\box_set_wd:Nn \l_@@_internal_box
{ \l_@@_right_corner_dim - \l_@@_left_corner_dim }
#5 #1 { \box_use_drop:N \l_@@_internal_box }
% \end{macrocode}
% The final task is to move the poles and corners such that they are
% back in alignment with the box reference point.
% \begin{macrocode}
\prop_map_inline:Nn \l_@@_corners_prop
{ \@@_shift_corner:Nnnn #1 {##1} ##2 }
\prop_map_inline:Nn \l_@@_poles_prop
{ \@@_shift_pole:Nnnnnn #1 {##1} ##2 }
% \end{macrocode}
% Update the coffin data.
% \begin{macrocode}
#4 { coffin ~ \@@_to_value:N #1 ~ corners }
\l_@@_corners_prop
#4 { coffin ~ \@@_to_value:N #1 ~ poles }
\l_@@_poles_prop
}
% \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\@@_set_bounding:N}
% The bounding box corners for a coffin are easy enough to find: this
% is the same code as for the corners of the material itself, but
% using a dedicated property list.
% \begin{macrocode}
\cs_new_protected:Npn \@@_set_bounding:N #1
{
\prop_put:Nnx \l_@@_bounding_prop { tl }
{ { 0pt } { \dim_eval:n { \box_ht:N #1 } } }
\prop_put:Nnx \l_@@_bounding_prop { tr }
{
{ \dim_eval:n { \box_wd:N #1 } }
{ \dim_eval:n { \box_ht:N #1 } }
}
\dim_set:Nn \l_@@_internal_dim { -\box_dp:N #1 }
\prop_put:Nnx \l_@@_bounding_prop { bl }
{ { 0pt } { \dim_use:N \l_@@_internal_dim } }
\prop_put:Nnx \l_@@_bounding_prop { br }
{
{ \dim_eval:n { \box_wd:N #1 } }
{ \dim_use:N \l_@@_internal_dim }
}
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_rotate_bounding:nnn}
% \begin{macro}{\@@_rotate_corner:Nnnn}
% Rotating the position of the corner of the coffin is just a case
% of treating this as a vector from the reference point. The same
% treatment is used for the corners of the material itself and the
% bounding box.
% \begin{macrocode}
\cs_new_protected:Npn \@@_rotate_bounding:nnn #1#2#3
{
\@@_rotate_vector:nnNN {#2} {#3} \l_@@_x_dim \l_@@_y_dim
\prop_put:Nnx \l_@@_bounding_prop {#1}
{ { \dim_use:N \l_@@_x_dim } { \dim_use:N \l_@@_y_dim } }
}
\cs_new_protected:Npn \@@_rotate_corner:Nnnn #1#2#3#4
{
\@@_rotate_vector:nnNN {#3} {#4} \l_@@_x_dim \l_@@_y_dim
\prop_put:Nnx \l_@@_corners_prop {#2}
{ { \dim_use:N \l_@@_x_dim } { \dim_use:N \l_@@_y_dim } }
}
% \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\@@_rotate_pole:Nnnnnn}
% Rotating a single pole simply means shifting the co-ordinate of
% the pole and its direction. The rotation here is about the bottom-left
% corner of the coffin.
% \begin{macrocode}
\cs_new_protected:Npn \@@_rotate_pole:Nnnnnn #1#2#3#4#5#6
{
\@@_rotate_vector:nnNN {#3} {#4} \l_@@_x_dim \l_@@_y_dim
\@@_rotate_vector:nnNN {#5} {#6}
\l_@@_x_prime_dim \l_@@_y_prime_dim
\prop_put:Nnx \l_@@_poles_prop {#2}
{
{ \dim_use:N \l_@@_x_dim } { \dim_use:N \l_@@_y_dim }
{ \dim_use:N \l_@@_x_prime_dim }
{ \dim_use:N \l_@@_y_prime_dim }
}
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_rotate_vector:nnNN}
% A rotation function, which needs only an input vector (as dimensions)
% and an output space. The values \cs{l_@@_cos_fp} and
% \cs{l_@@_sin_fp} should previously have been set up correctly.
% Working this way means that the floating point work is kept to a
% minimum: for any given rotation the sin and cosine values do no
% change, after all.
% \begin{macrocode}
\cs_new_protected:Npn \@@_rotate_vector:nnNN #1#2#3#4
{
\dim_set:Nn #3
{
\fp_to_dim:n
{
\dim_to_fp:n {#1} * \l_@@_cos_fp
- \dim_to_fp:n {#2} * \l_@@_sin_fp
}
}
\dim_set:Nn #4
{
\fp_to_dim:n
{
\dim_to_fp:n {#1} * \l_@@_sin_fp
+ \dim_to_fp:n {#2} * \l_@@_cos_fp
}
}
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_find_corner_maxima:N}
% \begin{macro}{\@@_find_corner_maxima_aux:nn}
% The idea here is to find the extremities of the content of the
% coffin. This is done by looking for the smallest values for the bottom
% and left corners, and the largest values for the top and right
% corners. The values start at the maximum dimensions so that the
% case where all are positive or all are negative works out correctly.
% \begin{macrocode}
\cs_new_protected:Npn \@@_find_corner_maxima:N #1
{
\dim_set:Nn \l_@@_top_corner_dim { -\c_max_dim }
\dim_set:Nn \l_@@_right_corner_dim { -\c_max_dim }
\dim_set:Nn \l_@@_bottom_corner_dim { \c_max_dim }
\dim_set:Nn \l_@@_left_corner_dim { \c_max_dim }
\prop_map_inline:Nn \l_@@_corners_prop
{ \@@_find_corner_maxima_aux:nn ##2 }
}
\cs_new_protected:Npn \@@_find_corner_maxima_aux:nn #1#2
{
\dim_set:Nn \l_@@_left_corner_dim
{ \dim_min:nn { \l_@@_left_corner_dim } {#1} }
\dim_set:Nn \l_@@_right_corner_dim
{ \dim_max:nn { \l_@@_right_corner_dim } {#1} }
\dim_set:Nn \l_@@_bottom_corner_dim
{ \dim_min:nn { \l_@@_bottom_corner_dim } {#2} }
\dim_set:Nn \l_@@_top_corner_dim
{ \dim_max:nn { \l_@@_top_corner_dim } {#2} }
}
% \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\@@_find_bounding_shift:}
% \begin{macro}{\@@_find_bounding_shift_aux:nn}
% The approach to finding the shift for the bounding box is similar to
% that for the corners. However, there is only one value needed here and
% a fixed input property list, so things are a bit clearer.
% \begin{macrocode}
\cs_new_protected:Npn \@@_find_bounding_shift:
{
\dim_set:Nn \l_@@_bounding_shift_dim { \c_max_dim }
\prop_map_inline:Nn \l_@@_bounding_prop
{ \@@_find_bounding_shift_aux:nn ##2 }
}
\cs_new_protected:Npn \@@_find_bounding_shift_aux:nn #1#2
{
\dim_set:Nn \l_@@_bounding_shift_dim
{ \dim_min:nn { \l_@@_bounding_shift_dim } {#1} }
}
% \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\@@_shift_corner:Nnnn}
% \begin{macro}{\@@_shift_pole:Nnnnnn}
% Shifting the corners and poles of a coffin means subtracting the
% appropriate values from the $x$- and $y$-components. For
% the poles, this means that the direction vector is unchanged.
% \begin{macrocode}
\cs_new_protected:Npn \@@_shift_corner:Nnnn #1#2#3#4
{
\prop_put:Nnx \l_@@_corners_prop {#2}
{
{ \dim_eval:n { #3 - \l_@@_left_corner_dim } }
{ \dim_eval:n { #4 - \l_@@_bottom_corner_dim } }
}
}
\cs_new_protected:Npn \@@_shift_pole:Nnnnnn #1#2#3#4#5#6
{
\prop_put:Nnx \l_@@_poles_prop {#2}
{
{ \dim_eval:n { #3 - \l_@@_left_corner_dim } }
{ \dim_eval:n { #4 - \l_@@_bottom_corner_dim } }
{#5} {#6}
}
}
% \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{variable}{\l_@@_scale_x_fp}
% \begin{variable}{\l_@@_scale_y_fp}
% Storage for the scaling factors in $x$ and $y$, respectively.
% \begin{macrocode}
\fp_new:N \l_@@_scale_x_fp
\fp_new:N \l_@@_scale_y_fp
% \end{macrocode}
% \end{variable}
% \end{variable}
%
% \begin{variable}{\l_@@_scaled_total_height_dim}
% \begin{variable}{\l_@@_scaled_width_dim}
% When scaling, the values given have to be turned into absolute values.
% \begin{macrocode}
\dim_new:N \l_@@_scaled_total_height_dim
\dim_new:N \l_@@_scaled_width_dim
% \end{macrocode}
% \end{variable}
% \end{variable}
%
% \begin{macro}
% {
% \coffin_resize:Nnn, \coffin_resize:cnn,
% \coffin_gresize:Nnn, \coffin_gresize:cnn
% }
% \begin{macro}{\@@_resize:NnnNN}
% Resizing a coffin begins by setting up the user-friendly names for
% the dimensions of the coffin box. The new sizes are then turned into
% scale factor. This is the same operation as takes place for the
% underlying box, but that operation is grouped and so the same
% calculation is done here.
% \begin{macrocode}
\cs_new_protected:Npn \coffin_resize:Nnn #1#2#3
{
\@@_resize:NnnNN #1 {#2} {#3}
\box_resize_to_wd_and_ht_plus_dp:Nnn
\prop_set_eq:cN
}
\cs_generate_variant:Nn \coffin_resize:Nnn { c }
\cs_new_protected:Npn \coffin_gresize:Nnn #1#2#3
{
\@@_resize:NnnNN #1 {#2} {#3}
\box_gresize_to_wd_and_ht_plus_dp:Nnn
\prop_gset_eq:cN
}
\cs_generate_variant:Nn \coffin_gresize:Nnn { c }
\cs_new_protected:Npn \@@_resize:NnnNN #1#2#3#4#5
{
\fp_set:Nn \l_@@_scale_x_fp
{ \dim_to_fp:n {#2} / \dim_to_fp:n { \coffin_wd:N #1 } }
\fp_set:Nn \l_@@_scale_y_fp
{
\dim_to_fp:n {#3}
/ \dim_to_fp:n { \coffin_ht:N #1 + \coffin_dp:N #1 }
}
#4 #1 {#2} {#3}
\@@_resize_common:NnnN #1 {#2} {#3} #5
}
% \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\@@_resize_common:NnnN}
% The poles and corners of the coffin are scaled to the appropriate
% places before actually resizing the underlying box.
% \begin{macrocode}
\cs_new_protected:Npn \@@_resize_common:NnnN #1#2#3#4
{
\prop_set_eq:Nc \l_@@_corners_prop
{ coffin ~ \@@_to_value:N #1 ~ corners }
\prop_set_eq:Nc \l_@@_poles_prop
{ coffin ~ \@@_to_value:N #1 ~ poles }
\prop_map_inline:Nn \l_@@_corners_prop
{ \@@_scale_corner:Nnnn #1 {##1} ##2 }
\prop_map_inline:Nn \l_@@_poles_prop
{ \@@_scale_pole:Nnnnnn #1 {##1} ##2 }
% \end{macrocode}
% Negative $x$-scaling values place the poles in the wrong
% location: this is corrected here.
% \begin{macrocode}
\fp_compare:nNnT \l_@@_scale_x_fp < \c_zero_fp
{
\prop_map_inline:Nn \l_@@_corners_prop
{ \@@_x_shift_corner:Nnnn #1 {##1} ##2 }
\prop_map_inline:Nn \l_@@_poles_prop
{ \@@_x_shift_pole:Nnnnnn #1 {##1} ##2 }
}
#4 { coffin ~ \@@_to_value:N #1 ~ corners }
\l_@@_corners_prop
#4 { coffin ~ \@@_to_value:N #1 ~ poles }
\l_@@_poles_prop
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}
% {
% \coffin_scale:Nnn, \coffin_scale:cnn,
% \coffin_gscale:Nnn, \coffin_gscale:cnn
% }
% \begin{macro}{\coffin_scale:NnnNN}
% For scaling, the opposite calculation is done to find the new
% dimensions for the coffin. Only the total height is needed, as this
% is the shift required for corners and poles. The scaling is done
% the \TeX{} way as this works properly with floating point values
% without needing to use the \texttt{fp} module.
% \begin{macrocode}
\cs_new_protected:Npn \coffin_scale:Nnn #1#2#3
{ \@@_scale:NnnNN #1 {#2} {#3} \box_scale:Nnn \prop_set_eq:cN }
\cs_generate_variant:Nn \coffin_scale:Nnn { c }
\cs_new_protected:Npn \coffin_gscale:Nnn #1#2#3
{ \@@_scale:NnnNN #1 {#2} {#3} \box_gscale:Nnn \prop_gset_eq:cN }
\cs_generate_variant:Nn \coffin_gscale:Nnn { c }
\cs_new_protected:Npn \@@_scale:NnnNN #1#2#3#4#5
{
\fp_set:Nn \l_@@_scale_x_fp {#2}
\fp_set:Nn \l_@@_scale_y_fp {#3}
#4 #1 { \l_@@_scale_x_fp } { \l_@@_scale_y_fp }
\dim_set:Nn \l_@@_internal_dim
{ \coffin_ht:N #1 + \coffin_dp:N #1 }
\dim_set:Nn \l_@@_scaled_total_height_dim
{ \fp_abs:n { \l_@@_scale_y_fp } \l_@@_internal_dim }
\dim_set:Nn \l_@@_scaled_width_dim
{ -\fp_abs:n { \l_@@_scale_x_fp } \coffin_wd:N #1 }
\@@_resize_common:NnnN #1
{ \l_@@_scaled_width_dim } { \l_@@_scaled_total_height_dim }
#5
}
% \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\@@_scale_vector:nnNN}
% This functions scales a vector from the origin using the pre-set scale
% factors in $x$ and $y$. This is a much less complex operation
% than rotation, and as a result the code is a lot clearer.
% \begin{macrocode}
\cs_new_protected:Npn \@@_scale_vector:nnNN #1#2#3#4
{
\dim_set:Nn #3
{ \fp_to_dim:n { \dim_to_fp:n {#1} * \l_@@_scale_x_fp } }
\dim_set:Nn #4
{ \fp_to_dim:n { \dim_to_fp:n {#2} * \l_@@_scale_y_fp } }
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_scale_corner:Nnnn}
% \begin{macro}{\@@_scale_pole:Nnnnnn}
% Scaling both corners and poles is a simple calculation using the
% preceding vector scaling.
% \begin{macrocode}
\cs_new_protected:Npn \@@_scale_corner:Nnnn #1#2#3#4
{
\@@_scale_vector:nnNN {#3} {#4} \l_@@_x_dim \l_@@_y_dim
\prop_put:Nnx \l_@@_corners_prop {#2}
{ { \dim_use:N \l_@@_x_dim } { \dim_use:N \l_@@_y_dim } }
}
\cs_new_protected:Npn \@@_scale_pole:Nnnnnn #1#2#3#4#5#6
{
\@@_scale_vector:nnNN {#3} {#4} \l_@@_x_dim \l_@@_y_dim
\prop_put:Nnx \l_@@_poles_prop {#2}
{
{ \dim_use:N \l_@@_x_dim } { \dim_use:N \l_@@_y_dim }
{#5} {#6}
}
}
% \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\@@_x_shift_corner:Nnnn}
% \begin{macro}{\@@_x_shift_pole:Nnnnnn}
% These functions correct for the $x$ displacement that takes
% place with a negative horizontal scaling.
% \begin{macrocode}
\cs_new_protected:Npn \@@_x_shift_corner:Nnnn #1#2#3#4
{
\prop_put:Nnx \l_@@_corners_prop {#2}
{
{ \dim_eval:n { #3 + \box_wd:N #1 } } {#4}
}
}
\cs_new_protected:Npn \@@_x_shift_pole:Nnnnnn #1#2#3#4#5#6
{
\prop_put:Nnx \l_@@_poles_prop {#2}
{
{ \dim_eval:n { #3 + \box_wd:N #1 } } {#4}
{#5} {#6}
}
}
% \end{macrocode}
% \end{macro}
% \end{macro}
%
% \subsection{Aligning and typesetting of coffins}
%
% \begin{macro}
% {
% \coffin_join:NnnNnnnn, \coffin_join:cnnNnnnn,
% \coffin_join:Nnncnnnn, \coffin_join:cnncnnnn,
% \coffin_gjoin:NnnNnnnn, \coffin_gjoin:cnnNnnnn,
% \coffin_gjoin:Nnncnnnn, \coffin_gjoin:cnncnnnn
% }
% \begin{macro}{\@@_join:NnnNnnnnN}
% This command joins two coffins, using a horizontal and vertical pole
% from each coffin and making an offset between the two. The result
% is stored as the as a third coffin, which has all of its handles
% reset to standard values. First, the more basic alignment function is
% used to get things started.
% \begin{macrocode}
\cs_new_protected:Npn \coffin_join:NnnNnnnn #1#2#3#4#5#6#7#8
{
\@@_join:NnnNnnnnN #1 {#2} {#3} #4 {#5} {#6} {#7} {#8}
\coffin_set_eq:NN
}
\cs_generate_variant:Nn \coffin_join:NnnNnnnn { c , Nnnc , cnnc }
\cs_new_protected:Npn \coffin_gjoin:NnnNnnnn #1#2#3#4#5#6#7#8
{
\@@_join:NnnNnnnnN #1 {#2} {#3} #4 {#5} {#6} {#7} {#8}
\coffin_gset_eq:NN
}
\cs_generate_variant:Nn \coffin_gjoin:NnnNnnnn { c , Nnnc , cnnc }
\cs_new_protected:Npn \@@_join:NnnNnnnnN #1#2#3#4#5#6#7#8#9
{
\@@_align:NnnNnnnnN
#1 {#2} {#3} #4 {#5} {#6} {#7} {#8} \l_@@_aligned_coffin
% \end{macrocode}
% Correct the placement of the reference point. If the $x$-offset
% is negative then the reference point of the second box is to the left
% of that of the first, which is corrected using a kern. On the right
% side the first box might stick out, which would show up if it is wider
% than the sum of the $x$-offset and the width of the second box.
% So a second kern may be needed.
% \begin{macrocode}
\hbox_set:Nn \l_@@_aligned_coffin
{
\dim_compare:nNnT { \l_@@_offset_x_dim } < \c_zero_dim
{ \tex_kern:D -\l_@@_offset_x_dim }
\hbox_unpack:N \l_@@_aligned_coffin
\dim_set:Nn \l_@@_internal_dim
{ \l_@@_offset_x_dim - \box_wd:N #1 + \box_wd:N #4 }
\dim_compare:nNnT \l_@@_internal_dim < \c_zero_dim
{ \tex_kern:D -\l_@@_internal_dim }
}
% \end{macrocode}
% The coffin structure is reset, and the corners are cleared: only
% those from the two parent coffins are needed.
% \begin{macrocode}
\@@_reset_structure:N \l_@@_aligned_coffin
\prop_clear:c
{
coffin ~ \@@_to_value:N \l_@@_aligned_coffin
\c_space_tl corners
}
\@@_update_poles:N \l_@@_aligned_coffin
% \end{macrocode}
% The structures of the parent coffins are now transferred to the new
% coffin, which requires that the appropriate offsets are applied. That
% then depends on whether any shift was needed.
% \begin{macrocode}
\dim_compare:nNnTF \l_@@_offset_x_dim < \c_zero_dim
{
\@@_offset_poles:Nnn #1 { -\l_@@_offset_x_dim } { 0pt }
\@@_offset_poles:Nnn #4 { 0pt } { \l_@@_offset_y_dim }
\@@_offset_corners:Nnn #1 { -\l_@@_offset_x_dim } { 0pt }
\@@_offset_corners:Nnn #4 { 0pt } { \l_@@_offset_y_dim }
}
{
\@@_offset_poles:Nnn #1 { 0pt } { 0pt }
\@@_offset_poles:Nnn #4
{ \l_@@_offset_x_dim } { \l_@@_offset_y_dim }
\@@_offset_corners:Nnn #1 { 0pt } { 0pt }
\@@_offset_corners:Nnn #4
{ \l_@@_offset_x_dim } { \l_@@_offset_y_dim }
}
\@@_update_vertical_poles:NNN #1 #4 \l_@@_aligned_coffin
#9 #1 \l_@@_aligned_coffin
}
% \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}
% {
% \coffin_attach:NnnNnnnn, \coffin_attach:cnnNnnnn,
% \coffin_attach:Nnncnnnn, \coffin_attach:cnncnnnn,
% \coffin_gattach:NnnNnnnn, \coffin_gattach:cnnNnnnn,
% \coffin_gattach:Nnncnnnn, \coffin_gattach:cnncnnnn
% }
% \begin{macro}{\@@_attach:NnnNnnnnN}
% \begin{macro}{\@@_attach_mark:NnnNnnnn}
% A more simple version of the above, as it simply uses the size of the
% first coffin for the new one. This means that the work here is rather
% simplified compared to the above code. The function used when marking
% a position is hear also as it is similar but without the structure
% updates.
% \begin{macrocode}
\cs_new_protected:Npn \coffin_attach:NnnNnnnn #1#2#3#4#5#6#7#8
{
\@@_attach:NnnNnnnnN #1 {#2} {#3} #4 {#5} {#6} {#7} {#8}
\coffin_set_eq:NN
}
\cs_generate_variant:Nn \coffin_attach:NnnNnnnn { c , Nnnc , cnnc }
\cs_new_protected:Npn \coffin_gattach:NnnNnnnn #1#2#3#4#5#6#7#8
{
\@@_attach:NnnNnnnnN #1 {#2} {#3} #4 {#5} {#6} {#7} {#8}
\coffin_gset_eq:NN
}
\cs_generate_variant:Nn \coffin_gattach:NnnNnnnn { c , Nnnc , cnnc }
\cs_new_protected:Npn \@@_attach:NnnNnnnnN #1#2#3#4#5#6#7#8#9
{
\@@_align:NnnNnnnnN
#1 {#2} {#3} #4 {#5} {#6} {#7} {#8} \l_@@_aligned_coffin
\box_set_ht:Nn \l_@@_aligned_coffin { \box_ht:N #1 }
\box_set_dp:Nn \l_@@_aligned_coffin { \box_dp:N #1 }
\box_set_wd:Nn \l_@@_aligned_coffin { \box_wd:N #1 }
\@@_reset_structure:N \l_@@_aligned_coffin
\prop_set_eq:cc
{
coffin ~ \@@_to_value:N \l_@@_aligned_coffin
\c_space_tl corners
}
{ coffin ~ \@@_to_value:N #1 ~ corners }
\@@_update_poles:N \l_@@_aligned_coffin
\@@_offset_poles:Nnn #1 { 0pt } { 0pt }
\@@_offset_poles:Nnn #4
{ \l_@@_offset_x_dim } { \l_@@_offset_y_dim }
\@@_update_vertical_poles:NNN #1 #4 \l_@@_aligned_coffin
\coffin_set_eq:NN #1 \l_@@_aligned_coffin
}
\cs_new_protected:Npn \@@_attach_mark:NnnNnnnn #1#2#3#4#5#6#7#8
{
\@@_align:NnnNnnnnN
#1 {#2} {#3} #4 {#5} {#6} {#7} {#8} \l_@@_aligned_coffin
\box_set_ht:Nn \l_@@_aligned_coffin { \box_ht:N #1 }
\box_set_dp:Nn \l_@@_aligned_coffin { \box_dp:N #1 }
\box_set_wd:Nn \l_@@_aligned_coffin { \box_wd:N #1 }
\box_set_eq:NN #1 \l_@@_aligned_coffin
}
% \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\@@_align:NnnNnnnnN}
% The internal function aligns the two coffins into a third one, but
% performs no corrections on the resulting coffin poles. The process
% begins by finding the points of intersection for the poles for each
% of the input coffins. Those for the first coffin are worked out after
% those for the second coffin, as this allows the `primed'
% storage area to be used for the second coffin. The `real' box
% offsets are then calculated, before using these to re-box the
% input coffins. The default poles are then set up, but the final result
% depends on how the bounding box is being handled.
% \begin{macrocode}
\cs_new_protected:Npn \@@_align:NnnNnnnnN #1#2#3#4#5#6#7#8#9
{
\@@_calculate_intersection:Nnn #4 {#5} {#6}
\dim_set:Nn \l_@@_x_prime_dim { \l_@@_x_dim }
\dim_set:Nn \l_@@_y_prime_dim { \l_@@_y_dim }
\@@_calculate_intersection:Nnn #1 {#2} {#3}
\dim_set:Nn \l_@@_offset_x_dim
{ \l_@@_x_dim - \l_@@_x_prime_dim + #7 }
\dim_set:Nn \l_@@_offset_y_dim
{ \l_@@_y_dim - \l_@@_y_prime_dim + #8 }
\hbox_set:Nn \l_@@_aligned_internal_coffin
{
\box_use:N #1
\tex_kern:D -\box_wd:N #1
\tex_kern:D \l_@@_offset_x_dim
\box_move_up:nn { \l_@@_offset_y_dim } { \box_use:N #4 }
}
\coffin_set_eq:NN #9 \l_@@_aligned_internal_coffin
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_offset_poles:Nnn}
% \begin{macro}{\@@_offset_pole:Nnnnnnn}
% Transferring structures from one coffin to another requires that the
% positions are updated by the offset between the two coffins. This is
% done by mapping to the property list of the source coffins, moving
% as appropriate and saving to the new coffin data structures. The
% test for a |-| means that the structures from the parent coffins
% are uniquely labelled and do not depend on the order of alignment.
% The pay off for this is that |-| should not be used in coffin pole
% or handle names, and that multiple alignments do not result in a
% whole set of values.
% \begin{macrocode}
\cs_new_protected:Npn \@@_offset_poles:Nnn #1#2#3
{
\prop_map_inline:cn { coffin ~ \@@_to_value:N #1 ~ poles }
{ \@@_offset_pole:Nnnnnnn #1 {##1} ##2 {#2} {#3} }
}
\cs_new_protected:Npn \@@_offset_pole:Nnnnnnn #1#2#3#4#5#6#7#8
{
\dim_set:Nn \l_@@_x_dim { #3 + #7 }
\dim_set:Nn \l_@@_y_dim { #4 + #8 }
\tl_if_in:nnTF {#2} { - }
{ \tl_set:Nn \l_@@_internal_tl { {#2} } }
{ \tl_set:Nn \l_@@_internal_tl { { #1 - #2 } } }
\exp_last_unbraced:NNo \@@_set_pole:Nnx \l_@@_aligned_coffin
{ \l_@@_internal_tl }
{
{ \dim_use:N \l_@@_x_dim } { \dim_use:N \l_@@_y_dim }
{#5} {#6}
}
}
% \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\@@_offset_corners:Nnn}
% \begin{macro}{\@@_offset_corner:Nnnnn}
% Saving the offset corners of a coffin is very similar, except that
% there is no need to worry about naming: every corner can be saved
% here as order is unimportant.
% \begin{macrocode}
\cs_new_protected:Npn \@@_offset_corners:Nnn #1#2#3
{
\prop_map_inline:cn { coffin ~ \@@_to_value:N #1 ~ corners }
{ \@@_offset_corner:Nnnnn #1 {##1} ##2 {#2} {#3} }
}
\cs_new_protected:Npn \@@_offset_corner:Nnnnn #1#2#3#4#5#6
{
\prop_put:cnx
{
coffin ~ \@@_to_value:N \l_@@_aligned_coffin
\c_space_tl corners
}
{ #1 - #2 }
{
{ \dim_eval:n { #3 + #5 } }
{ \dim_eval:n { #4 + #6 } }
}
}
% \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\@@_update_vertical_poles:NNN}
% \begin{macro}{\@@_update_T:nnnnnnnnN}
% \begin{macro}{\@@_update_B:nnnnnnnnN}
% The \texttt{T} and \texttt{B} poles need to be recalculated
% after alignment. These functions find the larger absolute value for
% the poles, but this is of course only logical when the poles are
% horizontal.
% \begin{macrocode}
\cs_new_protected:Npn \@@_update_vertical_poles:NNN #1#2#3
{
\@@_get_pole:NnN #3 { #1 -T } \l_@@_pole_a_tl
\@@_get_pole:NnN #3 { #2 -T } \l_@@_pole_b_tl
\exp_last_two_unbraced:Noo \@@_update_T:nnnnnnnnN
\l_@@_pole_a_tl \l_@@_pole_b_tl #3
\@@_get_pole:NnN #3 { #1 -B } \l_@@_pole_a_tl
\@@_get_pole:NnN #3 { #2 -B } \l_@@_pole_b_tl
\exp_last_two_unbraced:Noo \@@_update_B:nnnnnnnnN
\l_@@_pole_a_tl \l_@@_pole_b_tl #3
}
\cs_new_protected:Npn \@@_update_T:nnnnnnnnN #1#2#3#4#5#6#7#8#9
{
\dim_compare:nNnTF {#2} < {#6}
{
\@@_set_pole:Nnx #9 { T }
{ { 0pt } {#6} { 1000pt } { 0pt } }
}
{
\@@_set_pole:Nnx #9 { T }
{ { 0pt } {#2} { 1000pt } { 0pt } }
}
}
\cs_new_protected:Npn \@@_update_B:nnnnnnnnN #1#2#3#4#5#6#7#8#9
{
\dim_compare:nNnTF {#2} < {#6}
{
\@@_set_pole:Nnx #9 { B }
{ { 0pt } {#2} { 1000pt } { 0pt } }
}
{
\@@_set_pole:Nnx #9 { B }
{ { 0pt } {#6} { 1000pt } { 0pt } }
}
}
% \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{variable}{\c_@@_empty_coffin}
% An empty-but-horizontal coffin.
% \begin{macrocode}
\coffin_new:N \c_@@_empty_coffin
\tex_setbox:D \c_@@_empty_coffin = \tex_hbox:D { }
% \end{macrocode}
% \end{variable}
%
% \begin{macro}{\coffin_typeset:Nnnnn, \coffin_typeset:cnnnn}
% Typesetting a coffin means aligning it with the current position,
% which is done using a coffin with no content at all. As well as aligning to
% the empty coffin, there is also a need to leave vertical mode, if necessary.
% \begin{macrocode}
\cs_new_protected:Npn \coffin_typeset:Nnnnn #1#2#3#4#5
{
\mode_leave_vertical:
\@@_align:NnnNnnnnN \c_@@_empty_coffin { H } { l }
#1 {#2} {#3} {#4} {#5} \l_@@_aligned_coffin
\box_use_drop:N \l_@@_aligned_coffin
}
\cs_generate_variant:Nn \coffin_typeset:Nnnnn { c }
% \end{macrocode}
% \end{macro}
%
% \subsection{Coffin diagnostics}
%
% \begin{variable}{\l_@@_display_coffin}
% \begin{variable}{\l_@@_display_coord_coffin}
% \begin{variable}{\l_@@_display_pole_coffin}
% Used for printing coffins with data structures attached.
% \begin{macrocode}
\coffin_new:N \l_@@_display_coffin
\coffin_new:N \l_@@_display_coord_coffin
\coffin_new:N \l_@@_display_pole_coffin
% \end{macrocode}
% \end{variable}
% \end{variable}
% \end{variable}
%
% \begin{variable}{\l_@@_display_handles_prop}
% This property list is used to print coffin handles at suitable
% positions. The offsets are expressed as multiples of the basic offset
% value, which therefore acts as a scale-factor.
% \begin{macrocode}
\prop_new:N \l_@@_display_handles_prop
\prop_put:Nnn \l_@@_display_handles_prop { tl }
{ { b } { r } { -1 } { 1 } }
\prop_put:Nnn \l_@@_display_handles_prop { thc }
{ { b } { hc } { 0 } { 1 } }
\prop_put:Nnn \l_@@_display_handles_prop { tr }
{ { b } { l } { 1 } { 1 } }
\prop_put:Nnn \l_@@_display_handles_prop { vcl }
{ { vc } { r } { -1 } { 0 } }
\prop_put:Nnn \l_@@_display_handles_prop { vchc }
{ { vc } { hc } { 0 } { 0 } }
\prop_put:Nnn \l_@@_display_handles_prop { vcr }
{ { vc } { l } { 1 } { 0 } }
\prop_put:Nnn \l_@@_display_handles_prop { bl }
{ { t } { r } { -1 } { -1 } }
\prop_put:Nnn \l_@@_display_handles_prop { bhc }
{ { t } { hc } { 0 } { -1 } }
\prop_put:Nnn \l_@@_display_handles_prop { br }
{ { t } { l } { 1 } { -1 } }
\prop_put:Nnn \l_@@_display_handles_prop { Tl }
{ { t } { r } { -1 } { -1 } }
\prop_put:Nnn \l_@@_display_handles_prop { Thc }
{ { t } { hc } { 0 } { -1 } }
\prop_put:Nnn \l_@@_display_handles_prop { Tr }
{ { t } { l } { 1 } { -1 } }
\prop_put:Nnn \l_@@_display_handles_prop { Hl }
{ { vc } { r } { -1 } { 1 } }
\prop_put:Nnn \l_@@_display_handles_prop { Hhc }
{ { vc } { hc } { 0 } { 1 } }
\prop_put:Nnn \l_@@_display_handles_prop { Hr }
{ { vc } { l } { 1 } { 1 } }
\prop_put:Nnn \l_@@_display_handles_prop { Bl }
{ { b } { r } { -1 } { -1 } }
\prop_put:Nnn \l_@@_display_handles_prop { Bhc }
{ { b } { hc } { 0 } { -1 } }
\prop_put:Nnn \l_@@_display_handles_prop { Br }
{ { b } { l } { 1 } { -1 } }
% \end{macrocode}
% \end{variable}
%
% \begin{variable}{\l_@@_display_offset_dim}
% The standard offset for the label from the handle position when
% displaying handles.
% \begin{macrocode}
\dim_new:N \l_@@_display_offset_dim
\dim_set:Nn \l_@@_display_offset_dim { 2pt }
% \end{macrocode}
% \end{variable}
%
% \begin{variable}{\l_@@_display_x_dim}
% \begin{variable}{\l_@@_display_y_dim}
% As the intersections of poles have to be calculated to find which
% ones to print, there is a need to avoid repetition. This is done
% by saving the intersection into two dedicated values.
% \begin{macrocode}
\dim_new:N \l_@@_display_x_dim
\dim_new:N \l_@@_display_y_dim
% \end{macrocode}
% \end{variable}
% \end{variable}
%
% \begin{variable}{\l_@@_display_poles_prop}
% A property list for printing poles: various things need to be deleted
% from this to get a \enquote{nice} output.
% \begin{macrocode}
\prop_new:N \l_@@_display_poles_prop
% \end{macrocode}
% \end{variable}
%
% \begin{variable}{\l_@@_display_font_tl}
% Stores the settings used to print coffin data: this keeps things
% flexible.
% \begin{macrocode}
\tl_new:N \l_@@_display_font_tl
\bool_lazy_and:nnT
{ \cs_if_exist_p:N \fmtname }
{ \str_if_eq_p:Vn \fmtname { LaTeX2e } }
{
\tl_set:Nn \l_@@_display_font_tl
{ \sffamily \tiny }
}
% \end{macrocode}
% \end{variable}
%
% \begin{macro}{\@@_color:n}
% Calls \tn{color}, and otherwise does nothing if \tn{color} is not defined.
% As this is relatively rarely used, we have it self-define rather than delay
% using a hook.
% \begin{macrocode}
\cs_new_protected:Npn \@@_color:n #1 {#1}
\bool_lazy_and:nnT
{ \cs_if_exist_p:N \fmtname }
{ \str_if_eq_p:Vn \fmtname { LaTeX2e } }
{
\cs_gset_protected:Npn \@@_color:n
{
\cs_gset_protected:Npx \@@_color:n
{
\cs_if_exist:NTF \color_select:n
{ \color_select:n }
{
\cs_if_exist:NTF \color
{ \exp_not:N \color }
{ \exp_not:N \use_none:n }
}
}
\@@_color:n
}
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_rule:nn}
% Abstract out creation of rules here until there is a higher-level interface.
% \begin{macrocode}
\cs_new_protected:Npn \@@_rule:nn #1#2
{
\mode_leave_vertical:
\hbox:n { \tex_vrule:D width #1 height #2 \scan_stop: }
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\coffin_mark_handle:Nnnn, \coffin_mark_handle:cnnn}
% \begin{macro}{\@@_mark_handle_aux:nnnnNnn}
% Marking a single handle is relatively easy. The standard attachment
% function is used, meaning that there are two calculations for the
% location. However, this is likely to be okay given the load expected.
% Contrast with the more optimised version for showing all handles which
% comes next.
% \begin{macrocode}
\cs_new_protected:Npn \coffin_mark_handle:Nnnn #1#2#3#4
{
\hcoffin_set:Nn \l_@@_display_pole_coffin
{
\@@_color:n {#4}
\@@_rule:nn { 1pt } { 1pt }
}
\@@_attach_mark:NnnNnnnn #1 {#2} {#3}
\l_@@_display_pole_coffin { hc } { vc } { 0pt } { 0pt }
\hcoffin_set:Nn \l_@@_display_coord_coffin
{
\@@_color:n {#4}
\l_@@_display_font_tl
( \tl_to_str:n { #2 , #3 } )
}
\prop_get:NnN \l_@@_display_handles_prop
{ #2 #3 } \l_@@_internal_tl
\quark_if_no_value:NTF \l_@@_internal_tl
{
\prop_get:NnN \l_@@_display_handles_prop
{ #3 #2 } \l_@@_internal_tl
\quark_if_no_value:NTF \l_@@_internal_tl
{
\@@_attach_mark:NnnNnnnn #1 {#2} {#3}
\l_@@_display_coord_coffin { l } { vc }
{ 1pt } { 0pt }
}
{
\exp_last_unbraced:No \@@_mark_handle_aux:nnnnNnn
\l_@@_internal_tl #1 {#2} {#3}
}
}
{
\exp_last_unbraced:No \@@_mark_handle_aux:nnnnNnn
\l_@@_internal_tl #1 {#2} {#3}
}
}
\cs_new_protected:Npn \@@_mark_handle_aux:nnnnNnn #1#2#3#4#5#6#7
{
\@@_attach_mark:NnnNnnnn #5 {#6} {#7}
\l_@@_display_coord_coffin {#1} {#2}
{ #3 \l_@@_display_offset_dim }
{ #4 \l_@@_display_offset_dim }
}
\cs_generate_variant:Nn \coffin_mark_handle:Nnnn { c }
% \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\coffin_display_handles:Nn, \coffin_display_handles:cn}
% \begin{macro}{\@@_display_handles_aux:nnnnnn}
% \begin{macro}{\@@_display_handles_aux:nnnn}
% \begin{macro}{\@@_display_attach:Nnnnn}
% Printing the poles starts by removing any duplicates, for which the
% \texttt{H} poles is used as the definitive version for the baseline
% and bottom. Two loops are then used to find the combinations of
% handles for all of these poles. This is done such that poles are
% removed during the loops to avoid duplication.
% \begin{macrocode}
\cs_new_protected:Npn \coffin_display_handles:Nn #1#2
{
\hcoffin_set:Nn \l_@@_display_pole_coffin
{
\@@_color:n {#2}
\@@_rule:nn { 1pt } { 1pt }
}
\prop_set_eq:Nc \l_@@_display_poles_prop
{ coffin ~ \@@_to_value:N #1 ~ poles }
\@@_get_pole:NnN #1 { H } \l_@@_pole_a_tl
\@@_get_pole:NnN #1 { T } \l_@@_pole_b_tl
\tl_if_eq:NNT \l_@@_pole_a_tl \l_@@_pole_b_tl
{ \prop_remove:Nn \l_@@_display_poles_prop { T } }
\@@_get_pole:NnN #1 { B } \l_@@_pole_b_tl
\tl_if_eq:NNT \l_@@_pole_a_tl \l_@@_pole_b_tl
{ \prop_remove:Nn \l_@@_display_poles_prop { B } }
\coffin_set_eq:NN \l_@@_display_coffin #1
\prop_map_inline:Nn \l_@@_display_poles_prop
{
\prop_remove:Nn \l_@@_display_poles_prop {##1}
\@@_display_handles_aux:nnnnnn {##1} ##2 {#2}
}
\box_use_drop:N \l_@@_display_coffin
}
% \end{macrocode}
% For each pole there is a check for an intersection, which here does
% not give an error if none is found. The successful values are stored
% and used to align the pole coffin with the main coffin for output.
% The positions are recovered from the preset list if available.
% \begin{macrocode}
\cs_new_protected:Npn \@@_display_handles_aux:nnnnnn #1#2#3#4#5#6
{
\prop_map_inline:Nn \l_@@_display_poles_prop
{
\bool_set_false:N \l_@@_error_bool
\@@_calculate_intersection:nnnnnnnn {#2} {#3} {#4} {#5} ##2
\bool_if:NF \l_@@_error_bool
{
\dim_set:Nn \l_@@_display_x_dim { \l_@@_x_dim }
\dim_set:Nn \l_@@_display_y_dim { \l_@@_y_dim }
\@@_display_attach:Nnnnn
\l_@@_display_pole_coffin { hc } { vc }
{ 0pt } { 0pt }
\hcoffin_set:Nn \l_@@_display_coord_coffin
{
\@@_color:n {#6}
\l_@@_display_font_tl
( \tl_to_str:n { #1 , ##1 } )
}
\prop_get:NnN \l_@@_display_handles_prop
{ #1 ##1 } \l_@@_internal_tl
\quark_if_no_value:NTF \l_@@_internal_tl
{
\prop_get:NnN \l_@@_display_handles_prop
{ ##1 #1 } \l_@@_internal_tl
\quark_if_no_value:NTF \l_@@_internal_tl
{
\@@_display_attach:Nnnnn
\l_@@_display_coord_coffin { l } { vc }
{ 1pt } { 0pt }
}
{
\exp_last_unbraced:No
\@@_display_handles_aux:nnnn
\l_@@_internal_tl
}
}
{
\exp_last_unbraced:No \@@_display_handles_aux:nnnn
\l_@@_internal_tl
}
}
}
}
\cs_new_protected:Npn \@@_display_handles_aux:nnnn #1#2#3#4
{
\@@_display_attach:Nnnnn
\l_@@_display_coord_coffin {#1} {#2}
{ #3 \l_@@_display_offset_dim }
{ #4 \l_@@_display_offset_dim }
}
\cs_generate_variant:Nn \coffin_display_handles:Nn { c }
% \end{macrocode}
% This is a dedicated version of \cs{coffin_attach:NnnNnnnn} with
% a hard-wired first coffin. As the intersection is already known
% and stored for the display coffin the code simply uses it directly,
% with no calculation.
% \begin{macrocode}
\cs_new_protected:Npn \@@_display_attach:Nnnnn #1#2#3#4#5
{
\@@_calculate_intersection:Nnn #1 {#2} {#3}
\dim_set:Nn \l_@@_x_prime_dim { \l_@@_x_dim }
\dim_set:Nn \l_@@_y_prime_dim { \l_@@_y_dim }
\dim_set:Nn \l_@@_offset_x_dim
{ \l_@@_display_x_dim - \l_@@_x_prime_dim + #4 }
\dim_set:Nn \l_@@_offset_y_dim
{ \l_@@_display_y_dim - \l_@@_y_prime_dim + #5 }
\hbox_set:Nn \l_@@_aligned_coffin
{
\box_use:N \l_@@_display_coffin
\tex_kern:D -\box_wd:N \l_@@_display_coffin
\tex_kern:D \l_@@_offset_x_dim
\box_move_up:nn { \l_@@_offset_y_dim } { \box_use:N #1 }
}
\box_set_ht:Nn \l_@@_aligned_coffin
{ \box_ht:N \l_@@_display_coffin }
\box_set_dp:Nn \l_@@_aligned_coffin
{ \box_dp:N \l_@@_display_coffin }
\box_set_wd:Nn \l_@@_aligned_coffin
{ \box_wd:N \l_@@_display_coffin }
\box_set_eq:NN \l_@@_display_coffin \l_@@_aligned_coffin
}
% \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}
% {
% \coffin_show_structure:N, \coffin_show_structure:c,
% \coffin_log_structure:N, \coffin_log_structure:c,
% \@@_show_structure:NN
% }
% For showing the various internal structures attached to a coffin in
% a way that keeps things relatively readable. If there is no apparent
% structure then the code complains.
% \begin{macrocode}
\cs_new_protected:Npn \coffin_show_structure:N
{ \@@_show_structure:NN \msg_show:nnxxxx }
\cs_generate_variant:Nn \coffin_show_structure:N { c }
\cs_new_protected:Npn \coffin_log_structure:N
{ \@@_show_structure:NN \msg_log:nnxxxx }
\cs_generate_variant:Nn \coffin_log_structure:N { c }
\cs_new_protected:Npn \@@_show_structure:NN #1#2
{
\@@_if_exist:NT #2
{
#1 { LaTeX / kernel } { show-coffin }
{ \token_to_str:N #2 }
{
\iow_newline: >~ ht ~=~ \dim_eval:n { \coffin_ht:N #2 }
\iow_newline: >~ dp ~=~ \dim_eval:n { \coffin_dp:N #2 }
\iow_newline: >~ wd ~=~ \dim_eval:n { \coffin_wd:N #2 }
}
{
\prop_map_function:cN
{ coffin ~ \@@_to_value:N #2 ~ poles }
\msg_show_item_unbraced:nn
}
{ }
}
}
% \end{macrocode}
% \end{macro}
%
% \subsection{Messages}
%
% \begin{macrocode}
\__kernel_msg_new:nnnn { kernel } { no-pole-intersection }
{ No~intersection~between~coffin~poles. }
{
LaTeX~was~asked~to~find~the~intersection~between~two~poles,~
but~they~do~not~have~a~unique~meeting~point:~
the~value~(0pt,~0pt)~will~be~used.
}
\__kernel_msg_new:nnnn { kernel } { unknown-coffin }
{ Unknown~coffin~'#1'. }
{ The~coffin~'#1'~was~never~defined. }
\__kernel_msg_new:nnnn { kernel } { unknown-coffin-pole }
{ Pole~'#1'~unknown~for~coffin~'#2'. }
{
LaTeX~was~asked~to~find~a~typesetting~pole~for~a~coffin,~
but~either~the~coffin~does~not~exist~or~the~pole~name~is~wrong.
}
\__kernel_msg_new:nnn { kernel } { show-coffin }
{
Size~of~coffin~#1 : #2 \\
Poles~of~coffin~#1 : #3 .
}
% \end{macrocode}
%
% \begin{macrocode}
%</package>
% \end{macrocode}
%
% \end{implementation}
%
% \PrintIndex
|