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 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675
|
% \iffalse meta-comment
%
% File: postnotes.dtx
%
% This file is part of the LaTeX package "postnotes".
%
% Copyright (C) 2022 Gustavo Barros
%
% 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
%
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
%
% This work is "maintained" (as per LPPL maintenance status) by
% Gustavo Barros.
%
% This work consists of the files postnotes.dtx,
% postnotes.ins,
% postnotes.tex,
% postnotes-code.tex,
% and the files generated from them.
%
% The released version of this package is available from CTAN.
%
% -----------------------------------------------------------------------
%
% The development version of the package can be found at
%
% https://github.com/gusbrs/postnotes
%
% for those people who are interested.
%
% -----------------------------------------------------------------------
%
% \fi
%
% \iffalse
%<*driver>
\documentclass{l3doc}
% Have \GetFileInfo pick up date and version data and used in the
% documentation.
\usepackage{postnotes}
\begin{document}
\DocInput{postnotes.dtx}
\end{document}
%</driver>
%
% \fi
%
% \DoNotIndex{\\}
%
% \NewDocumentCommand\githubissue{m}{^^A
% issue~\href{https://github.com/gusbrs/postnotes/issues/#1}{\##1}}
%
% \NewDocumentCommand\githubPR{m}{^^A
% PR~\href{https://github.com/gusbrs/postnotes/pull/#1}{\##1}}
%
% \NewDocumentCommand\contributor{m}{#1}
% \NewDocumentCommand\username{m}{`\texttt{#1}'}
%
% \NewDocumentCommand\opt{m}{\texttt{#1}}
%
% \pdfstringdefDisableCommands{^^A
% \def\opt#1{#1}
% }
%
% \AddToHook{env/macro/after}{\medskip{}}
% \AddToHook{env/variable/after}{\medskip{}}
% \AddToHook{env/function/after}{\medskip{}}
%
%
% ^^A Have the Index at 'section' level rather than 'part'. Otherwise it is
% ^^A just the same definition from 'l3doc.cls'.
% \IndexPrologue{^^A
% \section*{Index}
% \markboth{Index}{Index}
% \addcontentsline{toc}{section}{Index}
% The italic numbers denote the pages where the corresponding entry is
% described, numbers underlined point to the definition, all others indicate
% the places where it is used.^^A
% }
%
%
% \GetFileInfo{postnotes.sty}
%
% \title{^^A
% The \pkg{postnotes} package^^A
% \thanks{This file describes \fileversion, released \filedate.}^^A
% \texorpdfstring{\\{}\medskip{}}{ - }^^A
% Code documentation^^A
% \texorpdfstring{\medskip{}}{}^^A
% }
%
% \author{^^A
% Gustavo Barros^^A
% \thanks{\url{https://github.com/gusbrs/postnotes}}^^A
% }
%
% \date{\filedate}
%
% \maketitle
%
%
% \tableofcontents
%
%
% \clearpage{}
%
% \section{Initial setup}
% Start the \pkg{DocStrip} guards.
% \begin{macrocode}
%<*package>
% \end{macrocode}
%
% Identify the internal prefix (\LaTeX3 \pkg{DocStrip} convention).
% \begin{macrocode}
%<@@=postnotes>
% \end{macrocode}
%
%
% The new syntax for file/package hooks, which the package assumes, requires
% kernel 2021-11-15 (\texttt{ltnews34}, \texttt{ltfilehook}). Furthermore,
% the kernel of 2022-06-01 introduced a couple of very nice features which
% simplifies the relation with \pkg{hyperref} (\texttt{ltnews35},
% \texttt{hyperref-linktarget}): the provision of \cs{MakeLinkTarget} and the
% definition by the kernel of the starred version of \cs{ref}, which we can
% use regardless of \pkg{hyperref} being loaded. So we require the 2022-06-01
% kernel or newer.
%
% \begin{macrocode}
\providecommand\IfFormatAtLeastTF{\@ifl@t@r\fmtversion}
\IfFormatAtLeastTF{2022-06-01}
{}
{%
\PackageError{postnotes}{LaTeX kernel too old}
{%
'postnotes' requires a LaTeX kernel 2022-06-01 or newer.%
\MessageBreak Loading will abort!%
}%
\endinput
}%
% \end{macrocode}
%
%
% \begin{macrocode}
\ProvidesExplPackage {postnotes} {2022-12-28} {0.2.0}
{Endnotes for LaTeX}
% \end{macrocode}
%
%
% \section{Data}
%
%
% \begin{macro}[EXP]{\@@_data_name:n}
% Returns the name of the property list variable which stores the data of
% the \cs{postnote} with \meta{note id} number.
% \begin{syntax}
% \cs{@@_data_name:n} \Arg{note id}
% \end{syntax}
% \begin{macrocode}
\cs_new:Npn \@@_data_name:n #1
{ g_@@_ #1 _data_prop }
\cs_generate_variant:Nn \@@_data_name:n { e }
% \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@@_store:nn}
% Stores the metadata and \meta{note content} of \cs{postnote} with ID
% \meta{note id}, from where it is called. The
% \texttt{postnotes/store/note} hook is intended to add further data to the
% note, when required to support packages with specific needs.
% \begin{syntax}
% \cs{@@_store:nn} \Arg{note id} \Arg{note content}
% \end{syntax}
% \begin{macrocode}
\NewHook { postnotes/store/note }
\cs_new_protected:Npn \@@_store:nn #1#2
{
\prop_new:c { \@@_data_name:e {#1} }
\prop_gput:cnn { \@@_data_name:e {#1} } { type } { note }
\prop_gput:cnx { \@@_data_name:e {#1} } { mark }
{ \l_@@_mark_tl }
\prop_gput:cnx { \@@_data_name:e {#1} } { counter }
{ \int_use:N \c@postnote }
\prop_gput:cnx { \@@_data_name:e {#1} } { sortnum }
{
\bool_if:NTF \l_@@_manual_sortnum_bool
{ \fp_use:N \l_@@_sort_num_fp }
{ \int_use:N \c@postnote }
}
\cs_if_exist:cT { chapter }
{
\prop_gput:cnx { \@@_data_name:e {#1} }
{ thechapter } { \thechapter }
}
\prop_gput:cnx { \@@_data_name:e {#1} } { thesection }
{ \thesection }
\prop_gput:cnx { \@@_data_name:e {#1} } { pnsectname }
{ \g_@@_section_name_tl }
\prop_gput:cnx { \@@_data_name:e {#1} } { pnsectid }
{ \int_use:N \g_@@_sectid_int }
\prop_gput:cnx { \@@_data_name:e {#1} } { multibool }
{ \bool_to_str:N \l_@@_maybe_multi_bool }
\prop_gput:cnn { \@@_data_name:e {#1} } { content } {#2}
\UseHook { postnotes/store/note }
}
% \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@@_store_section:nn}
% Stores the metadata and \meta{note content} of \cs{postnotesection} with
% ID \meta{note id}, from where it is called.
% \begin{syntax}
% \cs{@@_store_section:nn} \Arg{note id} \Arg{note content}
% \end{syntax}
% \begin{macrocode}
\cs_new_protected:Npn \@@_store_section:nn #1#2
{
\prop_new:c { \@@_data_name:e {#1} }
\prop_gput:cnn { \@@_data_name:e {#1} } { type } { section }
\cs_if_exist:cT { chapter }
{
\prop_gput:cnx { \@@_data_name:e {#1} }
{ thechapter } { \thechapter }
}
\prop_gput:cnx { \@@_data_name:e {#1} } { thesection }
{ \thesection }
\prop_gput:cnn { \@@_data_name:e {#1} } { content } {#2}
}
\cs_generate_variant:Nn \@@_store_section:nn { nx }
% \end{macrocode}
% \end{macro}
%
%
% \begin{macro}
% {
% \@@_prop_get:nnN ,
% \@@_prop_item:nn ,
% \@@_prop_gclear:n ,
% }
% Convenience functions to retrieve and clear data from a note based on the
% ID number.
% \begin{syntax}
% \cs{@@_prop_get:nnN} \Arg{note id} \Arg{property} \Arg{tl var to set}
% \cs{@@_prop_item:nn} \Arg{note id} \Arg{property}
% \cs{@@_prop_gclear:n} \Arg{note id}
% \end{syntax}
% \begin{macrocode}
\cs_new_protected:Npn \@@_prop_get:nnN #1#2#3
{
\prop_get:cnNF { \@@_data_name:e {#1} } {#2} #3
{ \tl_clear:N #3 }
}
\cs_new:Npn \@@_prop_item:nn #1#2
{ \prop_item:cn { \@@_data_name:e {#1} } {#2} }
\cs_new_protected:Npn \@@_prop_gclear:n #1
{ \prop_gclear:c { \@@_data_name:e {#1} } }
% \end{macrocode}
% \end{macro}
%
%
% \begin{macro}[int]{\post@note}
% The \cs{newlabel} equivalent for \pkg{postnotes}. Based on the kernel's
% \cs{@newl@bel} so that we get \LaTeX{} checks for multiple and changed
% references for free (procedure learnt from \pkg{zref}). \cs{post@note},
% when the \file{.aux} file is read, defines macros named
% \texttt{\textbackslash{}postnote@r@\meta{label name}}, according to the
% prefix set by \cs{c_@@_ref_prefix_tl}.
% \begin{syntax}
% \cs{post@note} \Arg{label name} \Arg{label content}
% \end{syntax}
% \begin{macrocode}
\tl_const:Nn \c_@@_ref_prefix_tl { postnote@r }
\cs_new_protected:Npx \post@note #1#2
{ \exp_not:N \@newl@bel { \c_@@_ref_prefix_tl } {#1} {#2} }
% \end{macrocode}
% \end{macro}
%
%
% \begin{macro}
% {
% \@@_set_mark_page_label:n ,
% \@@_set_text_page_label:n ,
% \@@_set_print_page_label:n ,
% }
% Label setting functions for each pertinent context. They must use
% \cs{iow_shipout_x:Nn}, since the main information we are interested in is
% the \texttt{page}.
% \begin{syntax}
% \cs{@@_set_mark_page_label:n} \Arg{label name}
% \cs{@@_set_text_page_label:n} \Arg{label name}
% \cs{@@_set_print_page_label:n} \Arg{label name}
% \end{syntax}
% \begin{macrocode}
\cs_new_protected:Npn \@@_set_mark_page_label:n #1
{
\iow_shipout_x:Nn \@auxout
{ \token_to_str:N \post@note { mark@ #1 } { \thepage } }
}
\cs_generate_variant:Nn \@@_set_mark_page_label:n { x }
\cs_new_protected:Npn \@@_set_text_page_label:n #1
{
\iow_shipout_x:Nn \@auxout
{ \token_to_str:N \post@note { text@ #1 } { \int_use:N \c@page } }
}
\cs_generate_variant:Nn \@@_set_text_page_label:n { x }
\cs_new_protected:Npn \@@_set_print_page_label:n #1
{
\iow_shipout_x:Nn \@auxout
{ \token_to_str:N \post@note { print@ #1 } { \int_use:N \c@page } }
}
\cs_generate_variant:Nn \@@_set_print_page_label:n { x }
% \end{macrocode}
% \end{macro}
%
%
% \begin{macro}
% {
% \@@_get_pageref:Nn ,
% \@@_extract_pageref:n ,
% }
% Reference data extraction functions.
% \begin{syntax}
% \cs{@@_get_pageref:Nn} \Arg{tl var to set} \Arg{label name}
% \cs{@@_extract_pageref:n} \Arg{label name}
% \end{syntax}
% \begin{macrocode}
\cs_new_protected:Npn \@@_get_pageref:Nn #1#2
{
\cs_if_exist:cTF { \c_@@_ref_prefix_tl @ #2 }
{ \tl_set:Nv #1 { \c_@@_ref_prefix_tl @ #2 } }
{ \tl_clear:N #1 }
}
\cs_generate_variant:Nn \@@_get_pageref:Nn { Nx }
\cs_new:Npn \@@_extract_pageref:n #1
{
\cs_if_exist:cTF { \c_@@_ref_prefix_tl @ #1 }
{ \exp_not:v { \c_@@_ref_prefix_tl @ #1 } }
{ \c_empty_tl }
}
\cs_generate_variant:Nn \@@_extract_pageref:n { e }
% \end{macrocode}
% \end{macro}
%
%
% \section{Options}
%
% \subsection*{\opt{heading} option}
%
% \begin{macrocode}
\keys_define:nn { postnotes/setup }
{
heading .cs_set_protected:Np = \pnheading ,
heading .value_required:n = true ,
}
% \end{macrocode}
%
% \begin{macro}[int]{\pnheading}
% Provide default value for \cs{pnheading}.
% \begin{macrocode}
\cs_if_exist:cTF { chapter }
{
\cs_new_protected:Npn \pnheading
{
\chapter*{\pntitle}
\@mkboth{\pnheaderdefault}{\pnheaderdefault}
}
}
{
\cs_new_protected:Npn \pnheading
{
\section*{\pntitle}
\@mkboth{\pnheaderdefault}{\pnheaderdefault}
}
}
% \end{macrocode}
% \end{macro}
%
%
% \subsection*{\opt{format} option}
%
% \begin{macrocode}
\tl_new:N \l_@@_print_format_tl
\keys_define:nn { postnotes/setup }
{
format .tl_set:N = \l_@@_print_format_tl ,
format .initial:n = { \small } ,
format .value_required:n = true ,
}
% \end{macrocode}
%
%
% \subsection*{\opt{listenv} option}
%
% \begin{macrocode}
\tl_new:N \l_@@_print_env_tl
\bool_new:N \l_@@_print_as_list_bool
\keys_define:nn { postnotes/setup }
{
listenv .code:n =
{
\tl_if_eq:nnTF {#1} { none }
{
\bool_set_false:N \l_@@_print_as_list_bool
\tl_set:Nn \l_@@_post_printnote_tl { \par }
% \end{macrocode}
% A sensible default just in case. It should not get to be used though.
% \begin{macrocode}
\tl_set:Nn \l_@@_print_env_tl { itemize }
}
{
\bool_set_true:N \l_@@_print_as_list_bool
\tl_set:Nn \l_@@_print_env_tl {#1}
}
} ,
listenv .initial:n = { postnoteslist } ,
listenv .value_required:n = true ,
}
% \end{macrocode}
%
%
% A couple of built-in list environments provided for convenience, and
% \texttt{postnoteslist} as default. The horizontal setup of the label in
% these lists is based on the \texttt{description} environment of the standard
% classes (see the \emph{The \LaTeX{} Companion}).
%
% \begin{macrocode}
\NewDocumentEnvironment { postnoteslist } { }
{
\list { }
{
\setlength { \leftmargin } { 0pt }
\setlength { \labelwidth } { 0pt }
\setlength { \itemindent } { .5\parindent }
\cs_set_eq:NN \makelabel \@@_list_makelabel:n
\setlength { \rightmargin } { 0pt }
\setlength { \listparindent } { \parindent }
\setlength { \parsep } { \parskip }
\setlength { \itemsep } { 0pt }
\setlength { \topsep } { .5\topsep }
\setlength { \partopsep } { .5\partopsep }
}
}
{ \endlist }
\NewDocumentEnvironment { postnoteslisthang } { }
{
\list { }
{
\setlength { \leftmargin } { 1em }
\setlength { \labelwidth } { -\leftmargin }
\setlength { \itemindent } { -2\leftmargin }
\cs_set_eq:NN \makelabel \@@_list_makelabel:n
\setlength { \rightmargin } { 0pt }
\setlength { \listparindent } { \parindent }
\setlength { \parsep } { \parskip }
\setlength { \itemsep } { 0pt }
\setlength { \topsep } { .5\topsep }
\setlength { \partopsep } { .5\partopsep }
}
}
{ \endlist }
\cs_new:Npn \@@_list_makelabel:n #1
{ \hspace { \labelsep } \normalfont ~ #1 }
% \end{macrocode}
%
%
% \subsection*{\opt{makemark} and \opt{maketextmark} options}
%
% The arguments are: \texttt{\#1} is the mark, \texttt{\#2} and \texttt{\#3}
% are, respectively, the start and the end of the backlink.
%
% \begin{macrocode}
\keys_define:nn { postnotes/setup }
{
makemark .cs_set:Np = \@@_make_mark:nnn #1#2#3 ,
makemark .value_required:n = true ,
% \end{macrocode}
% From the default kernel definition of \cs{@makefnmark}.
% \begin{macrocode}
makemark .initial:n =
{ #2 \hbox { \@textsuperscript { \normalfont #1 } } #3 } ,
maketextmark .cs_set:Np = \@@_make_text_mark:nnn #1#2#3 ,
maketextmark .value_required:n = true ,
maketextmark .initial:n = { #2 #1 . #3 } ,
}
% \end{macrocode}
%
%
% \subsection*{\opt{pretextmark}, \opt{posttextmark}, \opt{postprintnote} options}
%
% \begin{macrocode}
\tl_new:N \l_@@_pre_textmark_tl
\tl_new:N \l_@@_post_textmark_tl
\tl_new:N \l_@@_post_printnote_tl
\keys_define:nn { postnotes/setup }
{
pretextmark .tl_set:N = \l_@@_pre_textmark_tl ,
pretextmark .value_required:n = true ,
posttextmark .tl_set:N = \l_@@_post_textmark_tl ,
posttextmark .value_required:n = true ,
postprintnote .tl_set:N = \l_@@_post_printnote_tl ,
postprintnote .value_required:n = true ,
}
% \end{macrocode}
%
%
% \subsection*{\opt{hyperref} and \opt{backlink} options}
%
% \begin{macrocode}
\bool_new:N \l_@@_hyperlink_bool
\bool_new:N \l_@@_hyperref_warn_bool
\bool_new:N \l_@@_backlink_bool
\keys_define:nn { postnotes/setup }
{
hyperref .choice: ,
hyperref / auto .code:n =
{
\bool_set_true:N \l_@@_hyperlink_bool
\bool_set_false:N \l_@@_hyperref_warn_bool
} ,
hyperref / true .code:n =
{
\bool_set_true:N \l_@@_hyperlink_bool
\bool_set_true:N \l_@@_hyperref_warn_bool
} ,
hyperref / false .code:n =
{
\bool_set_false:N \l_@@_hyperlink_bool
\bool_set_false:N \l_@@_hyperref_warn_bool
} ,
hyperref .initial:n = auto ,
hyperref .default:n = true ,
backlink .bool_set:N = \l_@@_backlink_bool ,
backlink .initial:n = true ,
backlink .default:n = true ,
}
% \end{macrocode}
%
% \begin{macrocode}
\AddToHook { begindocument }
{
\IfPackageLoadedTF { hyperref }
{ }
{
\bool_if:NT \l_@@_hyperref_warn_bool
{ \msg_warning:nn { postnotes } { missing-hyperref } }
\bool_set_false:N \l_@@_hyperlink_bool
}
\keys_define:nn { postnotes/setup }
{
hyperref .code:n =
{
\msg_warning:nnn { postnotes }
{ option-preamble-only } { hyperref }
} ,
backlink .code:n =
{
\msg_warning:nnn { postnotes }
{ option-preamble-only } { backlink }
} ,
}
}
\msg_new:nnn { postnotes } { option-preamble-only }
{ Option~'#1'~only~available~in~the~preamble~\msg_line_context:. }
\msg_new:nnn { postnotes } { missing-hyperref }
{ Missing~'hyperref'~package.~Setting~'hyperref=false'. }
% \end{macrocode}
%
%
% \subsection*{\opt{sort} option}
%
% \begin{macrocode}
\bool_new:N \l_@@_sort_bool
\keys_define:nn { postnotes/setup }
{
sort .bool_set:N = \l_@@_sort_bool ,
sort .initial:n = true ,
sort .default:n = true ,
}
% \end{macrocode}
%
%
% \subsection*{\opt{style} option}
%
% \begin{macrocode}
\keys_define:nn { postnotes/setup }
{
style .choice: ,
style / endnotes .meta:n =
{
listenv = none ,
format =
{
\footnotesize
\setlength { \rightskip } { 0pt }
\setlength { \leftskip } { 0pt }
\setlength { \parindent } { 1.8em }
} ,
pretextmark = { \par } ,
% \end{macrocode}
% \pkg{endnotes} uses a zero width box to get the desired alignment to the
% right, but that does not play well with the backlinks, so we have a little
% more work to do to get this right.
% \begin{macrocode}
maketextmark =
{
\hbox_set:Nn \l_tmpa_box { \@textsuperscript { \normalfont ##1 } }
\skip_horizontal:n { - \box_wd:N \l_tmpa_box }
##2 \box_use:N \l_tmpa_box ##3
} ,
} ,
style / pagenote .meta:n =
{
listenv = none ,
format = { } ,
pretextmark = { \par\noindent } ,
maketextmark = { { \normalfont ##2 ##1 . ##3 } } ,
posttextmark = { ~ } ,
} ,
}
% \end{macrocode}
%
%
% \subsection*{\cs{postnotesetup}}
%
%
% \begin{macro}[int]{\postnotesetup}
% Provide \cs{postnotesetup}.
% \begin{syntax}
% \cs{postnotesetup}\marg{options}
% \end{syntax}
% \begin{macrocode}
\NewDocumentCommand \postnotesetup { m }
{ \keys_set:nn { postnotes/setup } {#1} }
% \end{macrocode}
% \end{macro}
%
%
% \section{\cs{postnote}}
%
% Different from the traditional \cs{footnotemark} / \cs{footnotetext} system,
% in the context of end notes, the functionality which corresponds to
% \cs{footnotetext} is simply to store the data to be typeset later. Hence,
% some of the problems that afflict footnotes do not apply to end notes.
% Namely, and as far as I can tell, they can be used in ``inner horizontal
% mode'' (\cs{mbox} etc.), and in math mode, and if the ``text'' will be
% typeset in the same page as the ``mark'' is of little concern.
%
% However, the separation between ``mark'' and ``text'' is still useful in
% other contexts: floats and contexts where multiple typesetting passes are
% performed. \contributor{David Carlisle} and \contributor{Ulrike Fischer}
% shared some thoughts on the matter at the TeX.SX chat:
% \url{https://chat.stackexchange.com/transcript/message/60754383#60754383}.
%
% The interesting questions here are: if they are replaceable in their roles
% in these contexts and how much would we lose by providing them. In
% analyzing this, we have to distinguish two situations: when
% \cs{footnotemark} is called with no argument (and thus steps the counter),
% and when it is called with the optional argument (and thus refrains from
% stepping the counter).
%
% For floats, the problem they pose is that they may disturb the
% \emph{ordering} of the notes. This particular issue can be solved by using
% \cs{footnotemark} without argument, and manually adjusting the counter on
% subsequent calls to \cs{footnotetext}. A good example of the technique is
% \url{https://tex.stackexchange.com/a/43694}. True, a user may wish to
% specify the mark explicitly, but doesn't necessarily need to do it to solve
% the ordering issue.
%
% Multiple typesetting passes of content are much harder. And they abound:
% the standard classes' \cs{caption} typesets the caption once, if it is
% short, but twice if it is longer than a line; \pkg{amsmath}'s math
% environments perform a measuring pass before actually typesetting the
% equations; \pkg{amsmath}'s \cs{text} macro runs the contents through
% \cs{mathchoice} (which typesets the contents four times) when in math mode;
% \pkg{tabularx} and \pkg{tabularray} also perform measuring passes of their
% tables; so does \pkg{csquotes}' blockquotes; and certainly more that I'm
% unaware. A number of these places offer some one or another way to mitigate
% the issue: \pkg{amsmath}, \pkg{tabularx}, \pkg{csquotes} and (optionally)
% \pkg{tabularray} restore counter values after measuring steps; \pkg{amsmath}
% offers a boolean to indicate when it is a measuring pass; \pkg{csquotes}
% offers further handles. But the standard \cs{caption} offers none, and
% neither does \pkg{amsmath}'s \cs{text} macro. Well, the pkg{caption}
% package has can disable the multiple passes for \cs{caption} with the option
% \opt{singlelinecheck}, but it is not reasonable to require it for our
% purposes, so we must assume the worst case.
%
% Enrico Gregorio is categorical in stating that \cs{endnotemark} and
% \cs{endnotetext} are required for \pkg{enotez} to handle \cs{caption}, which
% apparently it didn't offer originally: ``The package should implement
% \cs{endnotemark} and \cs{endnotetext} for this case. According to the
% documentation, the author deems them to not be needed: he's wrong.''
% (\url{https://tex.stackexchange.com/a/314937}). See also
% \url{https://tex.stackexchange.com/a/43794} and
% \url{https://tex.stackexchange.com/a/358207}.
%
% In this scenario, when there's no way around the multiple passes,
% \cs{footnotemark} can only handle the general case if used with an argument,
% precisely because it inhibits the stepping of the counter. Otherwise the
% counter is stepped multiple times, and we'd get the wrong number (and mark).
% In some circumstances, if we know the number of passes is deterministic, we
% might get away by adjusting the counter manually (\cs{caption} may be dealt
% with this way: if we know it to be two lines, we can decrement the counter
% before it and get correct results, even hyperlinked). But in cases which
% adjusting the counter is sufficient, end notes can be dealt with in the same
% way, and doesn't need the separation between ``mark'' and ``text''. So,
% what is distinctive of the kernel's footnote apparatus, which allows it as
% much flexibility as one would like, is receiving an arbitrary number as
% argument and not stepping the counter. And as far as \cs{footnotemark} and
% \cs{footnotetext}) are concerned, the main point of the optional argument is
% really to ``manually establish the relation'' between the two of them. So,
% if \emph{not stepping the counter} is what is needed to handle the general
% case, is it viable to do so? What would we loose in so doing?
%
% When receiving an arbitrary number as argument, as the kernel functionality
% for footnotes and other endnotes packages do, this value is expected to the
% printed as such, hence it must correspond to the \texttt{postnote} counter
% (in our case). But this counter is in the hands of the user, and can be
% reset along the document, thus its uniqueness cannot be ensured. But not
% stepping \texttt{postnote} is perfectly viable, as it just aims at storing
% how the mark is to be typeset. However, not stepping the ID counter would
% complicate things considerably. Not doing so implies we'd lose the
% connection we have between the ``mark'' and the corresponding ``text''. We
% might add the ``text'' to the queue, but all the metadata would be lost,
% including the \pkg{hyperref} anchor, but really the set of data without
% which the kind of functionality offered would be nonviable, or severely
% hampered. Not stepping \texttt{postnote} but stepping the ID counter also
% is not sufficient, because we'd get a note in duplicity. We could naively
% think that a gap in the ID is not a problem, and just not add the duplicate
% to the queue. But how could we tell the difference between a legitimate and
% an illegitimate step of the ID counter?
%
% I have not been able to devise a way to ``reconnect'' ``text'' and ``mark''
% in the absence of the unique ID counter. The most promising idea was to
% have mandatory arguments to \cs{postnotemark} and \cs{postnotetext}
% receiving a \meta{label} which we could use to identify their counterparts,
% but I was not able to go through with this, and the attempts all increased
% complexity considerably. It is not just a label/ref system, there's got to
% be a one-to-one correspondence between the sets, uniqueness has to be
% ensured on both sides, and there cannot be ``lone'' marks or texts (a
% bijection). Besides, this label based system of identification would have
% to live side-by-side with the one based on the counter. So, even if we'd
% have unique IDs, we wouldn't know beforehand in what form it comes.
% Considering the ID is used to build the variable name in which we store the
% note's information, this would also complicate things.
%
% Besides, there are ways to get things working with multiple passes without
% the ``mark''/``text'' partition. As mentioned, there are a number of cases
% which offer some kind of ``handle'' or way to identify the multiple passes.
% \pkg{csquotes} has a dedicated hook that can be used. \pkg{amsmath} sets
% the \texttt{measuring@} boolean (which \pkg{hyperref} also defines). So,
% not all cases are as tricky as \cs{caption} or \cs{text}, and even that can
% be decently dealt with without a separation between ``mark'' and ``text''.
% Besides, in difficult cases, the package offers a \opt{nomark} option to
% \cs{postnote} to place a note, but typeset no mark. Than we can typeset a
% mark with \cs{postnoteref} referring to a \cs{label} in the note of
% interest. This would result in a correct mark without duplicity, and in a
% correct link from there to the note's text at \cs{printpostnotes}. The
% drawback is that the placement of \cs{postnote} would be important, and
% results sensitive to it. All the metadata is collected at the point of
% \cs{postnote}, anchor included, not at the point of \cs{postnoteref}. So
% the consequences are a slightly off backlink, possibly imprecise metadata,
% etc. Considering \pkg{hyperref} itself shies away completely from linking
% \cs{footnotemark} with an argument, I'd say there's some gain.
%
% The truth is there are some trade-offs, there's no ``ideal'' solution.
% Still, all in all, my judgment is that the unique ID counter is worth more
% than the inconveniences of an ocasional \texttt{\cs{postnote}[nomark]}
% referenced with \cs{postnoteref}, and even that should not be needed much.
% So, for the time being, until something else shakes this balance, I won't be
% offering \cs{postnotemark} and \cs{postnotetext}.
%
% \bigskip{}
%
% For the \pkg{hyperref} support for cross-references in \cs{postnote}, I've
% moved back and forth quite a lot. One of the ideas I fancied was using
% \cs{refstepcounter} and let \pkg{hyperref} do its job. But, since I want to
% have control of the anchor/destination name on both ``sides'', I'd have to
% set \cs{theHpostnote} locally before calling \cs{refstepcounter}, otherwise
% results might sensitive to user calls to \cs{counterwithin} (see
% \url{https://github.com/latex3/hyperref/issues/230}, thanks
% \contributor{Ulrike Fischer}). However, even if that worked well for the
% default case, we still had to setup things manually, in case of a manually
% supplied mark. All in all, I'm just calling \cs{stepcounter}, setting the
% relevant cross-reference variables once and setting the anchor manually.
%
%
% \bigskip{}
%
% \texttt{postnote} is the public, user facing, counter for \cs{postnote}. It
% determines how the note's mark gets to be typeset. It can be reset, set,
% and have its printed representation changed. Of course, whether those are
% meaningful is up to the user.
%
% \begin{macrocode}
\newcounter { postnote }
% \end{macrocode}
%
% \begin{macro}
% {
% \g_@@_note_id_int ,
% \l_@@_note_id_tl ,
% \g_@@_queue_seq ,
% }
% \cs{g_@@_note_id_int} is the internal, unique counter which provides the
% ID number of each note. It ties ``mark'' and ``text'' together, is also
% the connection between each note and its data, including the content,
% which is stored in a property list named according to \cs{@@_data_name:n}
% and the ID number. \cs{l_@@_note_id_tl} is a convenience variable storing
% the counter's value. \cs{g_@@_queue_seq} stores the sequence of notes'
% IDs that to be processed by the next call of \cs{printpostnotes}.
% \begin{macrocode}
\int_new:N \g_@@_note_id_int
\tl_new:N \l_@@_note_id_tl
\tl_set:Nn \l_@@_note_id_tl { \int_use:N \g_@@_note_id_int }
\seq_new:N \g_@@_queue_seq
% \end{macrocode}
% \end{macro}
%
%
% \begin{macro}[int]{\postnote}
% Provide \cs{postnote}.
% \begin{syntax}
% \cs{postnote} \oarg{options} \marg{note text}
% \end{syntax}
% \begin{macrocode}
\NewDocumentCommand \postnote { O { } +m }
{ \@@_note:nn {#1} {#2} }
% \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@@_note:nn}
% The internal version of \cs{postnote}. The \texttt{postnotes/note/begin}
% hook is meant to provide a place from where some additional setup for the
% note can be performed. This is being used for adding support for some
% features/packages, but can also be used, for example, to add an extra
% local property for \pkg{zref}.
% \begin{syntax}
% \cs{@@_note:nn}\oarg{options}\marg{note content}
% \end{syntax}
% \begin{macrocode}
\NewHook { postnotes/note/begin }
\cs_new_protected:Npn \@@_note:nn #1#2
{
\group_begin:
\keys_set:nn { postnotes/note } {#1}
\@@_inhibit_note:F
{
\int_gincr:N \g_@@_note_id_int
\tl_if_empty:NT \l_@@_mark_tl
{
\stepcounter { postnote }
\tl_set:Nx \l_@@_mark_tl { \thepostnote }
}
\seq_gput_right:Nx \g_@@_queue_seq
{ \l_@@_note_id_tl }
\UseHook { postnotes/note/begin }
\cs_set:Npn \@currentcounter { postnote }
\cs_set:Npx \@currentlabel { \p@postnote \l_@@_mark_tl }
\MakeLinkTarget* { postnote. \l_@@_note_id_tl .mark }
\@@_set_mark_page_label:x { \l_@@_note_id_tl }
\@@_set_user_labels:
\bool_if:NF \l_@@_nomark_bool
{
\@@_typeset_mark:xV
{ \l_@@_note_id_tl } \l_@@_mark_tl
}
\@@_store:nn { \l_@@_note_id_tl } {#2}
}
\group_end:
}
% \end{macrocode}
% \end{macro}
%
%
% Options for \cs{postnote}.
%
% \begin{macrocode}
\tl_new:N \l_@@_mark_tl
\bool_new:N \l_@@_nomark_bool
\fp_new:N \l_@@_sort_num_fp
\tl_new:N \l_@@_note_label_tl
\bool_new:N \l_@@_manual_sortnum_bool
\bool_new:N \l_@@_maybe_multi_bool
\keys_define:nn { postnotes/note }
{
markstr .tl_set:N = \l_@@_mark_tl ,
markstr .value_required:n = true ,
sortnum .code:n =
{
\fp_set:Nn \l_@@_sort_num_fp {#1}
\bool_set_true:N \l_@@_manual_sortnum_bool
} ,
sortnum .value_required:n = true ,
mark .meta:n =
{
markstr = {#1} ,
sortnum = {#1} ,
} ,
mark .value_required:n = true ,
nomark .bool_set:N = \l_@@_nomark_bool ,
nomark .default:n = true ,
label .tl_set:N = \l_@@_note_label_tl ,
label .value_required:n = true ,
}
% \end{macrocode}
%
%
% \begin{macro}{\@@_inhibit_note:TF}
% In contexts of multiple passes of content, it may be needed, or preferred,
% to inhibit the note altogether to avoid side effects and duplicity. This
% conditional, obviously, will always return the true branch unless
% something is done in the \texttt{postnotes/note/inhibit} hook. This hook
% is meant to handle support for packages or features which may justify note
% inhibition, and the code there should set \cs{l_@@_inhibit_note_bool} and
% \cs{l_@@_print_plain_mark_bool} as appropriate to the case.
% \begin{macrocode}
\bool_new:N \l_@@_inhibit_note_bool
\bool_new:N \l_@@_print_plain_mark_bool
\NewHook { postnotes/note/inhibit }
\prg_new_protected_conditional:Npnn \@@_inhibit_note: { F }
{
\bool_set_false:N \l_@@_inhibit_note_bool
\bool_set_false:N \l_@@_print_plain_mark_bool
\UseHook { postnotes/note/inhibit }
% \end{macrocode}
% Printing a plain mark here may be needed because, if we are inhibiting the
% note in a ``measuring context'' and omit it completely, the measuring being
% performed will be off by the size of the mark. So, to ensure the measuring
% can be done correctly, we place the mark. Since we'd only print this mark
% in case of inhibition, when we don't actually step the counter, to typeset
% correctly the mark that would be printed if the counter had been stepped, we
% increment \cs{c@postnote} locally and grouped, and smuggle \cs{thepostnote}
% out of the group.
% \begin{macrocode}
\bool_if:NT \l_@@_print_plain_mark_bool
{
\tl_if_empty:NT \l_@@_mark_tl
{
\group_begin:
\int_incr:N \c@postnote
\exp_args:NNNx
\group_end:
\tl_set:Nn \l_@@_mark_tl { \thepostnote }
}
\@@_typeset_mark_wrapper:n
{ \@@_make_mark:nnn { \l_@@_mark_tl } { } { } }
}
\bool_if:NTF \l_@@_inhibit_note_bool
{ \prg_return_true: }
{ \prg_return_false: }
}
% \end{macrocode}
% \end{macro}
%
%
% \begin{macro}
% {
% \@@_typeset_mark:nn ,
% \@@_typeset_mark_wrapper:n ,
% }
% Auxiliary functions for mark typesetting in \cs{@@_note:nn}.
% \cs{@@_typeset_mark_wrapper:n} is based on the definition of
% \cs{@footnotemark} in the kernel.
% \begin{syntax}
% \cs{@@_typeset_mark:nn} \Arg{note id} \Arg{mark}
% \cs{@@_typeset_mark_wrapper:n} \Arg{mark}
% \end{syntax}
% \begin{macrocode}
\cs_new_protected:Npn \@@_typeset_mark:nn #1#2
{
\@@_typeset_mark_wrapper:n
{
\bool_if:NTF \l_@@_hyperlink_bool
{
\@@_make_mark:nnn {#2}
{ \hyper@linkstart { link } { postnote. #1 .text } }
{ \hyper@linkend }
}
{ \@@_make_mark:nnn {#2} { } { } }
}
}
\cs_generate_variant:Nn \@@_typeset_mark:nn { xV }
\tl_new:N \l_@@_saved_spacefactor_tl
\cs_new_protected:Npn \@@_typeset_mark_wrapper:n #1
{
\mode_leave_vertical:
\mode_if_horizontal:T
{
\tl_set:Nx \l_@@_saved_spacefactor_tl { \the\spacefactor }
\nobreak
}
#1
\mode_if_horizontal:T
{ \spacefactor \l_@@_saved_spacefactor_tl }
\scan_stop:
}
% \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@@_set_user_labels:}
% Auxiliary function for user label setting in \cs{@@_note:nn}. Supports
% the \opt{label} and \opt{zlabel} options of \cs{postnote}.
% \begin{macrocode}
\cs_new_protected:Npn \@@_set_user_labels:
{
\tl_if_empty:NF \l_@@_note_label_tl
{ \exp_args:NV \label \l_@@_note_label_tl }
\tl_if_empty:NF \l_@@_note_zlabel_tl
{ \exp_args:NV \zlabel \l_@@_note_zlabel_tl }
}
% \end{macrocode}
% \end{macro}
%
%
% \section{\cs{postnoteref}}
%
% \begin{macro}[int]{\postnoteref}
% Provide \cs{postnoteref}.
% \begin{syntax}
% \cs{postnoteref}\meta{*}\marg{label}
% \end{syntax}
% \begin{macrocode}
\NewDocumentCommand \postnoteref { s m }
{ \@@_note_ref:nn {#1} {#2} }
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_note_ref:nn}
% The internal version of \cs{postnoteref}.
% \begin{syntax}
% \cs{@@_note_ref:nn} \Arg{star bool} \Arg{label}
% \end{syntax}
% \begin{macrocode}
\cs_new_protected:Npn \@@_note_ref:nn #1#2
{
\group_begin:
\@@_typeset_mark_wrapper:n
{
\bool_lazy_and:nnTF
{ ! #1 }
{ \l_@@_hyperlink_bool }
{
\hyperref [#2]
{ \@@_make_mark:nnn { \ref*{#2} } { } { } }
}
{ \@@_make_mark:nnn { \ref*{#2} } { } { } }
}
\group_end:
}
% \end{macrocode}
% \end{macro}
%
%
% \section{\cs{postnotesection}}
%
% \begin{macro}[int]
% {
% \postnotesection ,
% \postnotesectionx ,
% }
% Provide \cs{postnotesection} and \cs{postnotesectionx}.
% \begin{syntax}
% \cs{postnotesection}\oarg{options}\marg{section content}
% \cs{postnotesectionx}\oarg{options}\marg{section content}
% \end{syntax}
% \begin{macrocode}
\NewDocumentCommand \postnotesection { O { } +m }
{ \@@_section:nn {#1} {#2} }
\NewDocumentCommand \postnotesectionx { O { } +m }
{
% NOTE Command deprecated in 2022-12-27 for v0.2.0.
\msg_warning:nn { postnotes } { postnotesectionx-deprecated }
\postnotesection [ #1 , exp ] {#2}
}
\msg_new:nnn { postnotes } { postnotesectionx-deprecated }
{
'\iow_char:N\\postnotesectionx'~is~deprecated~\msg_line_context:.~
Use~the~'exp'~option~of~'\iow_char:N\\postnotesection'~instead.
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_section:nn}
% The internal version of \cs{postnotesection}.
% \begin{syntax}
% \cs{@@_section:nn} \Arg{options} \Arg{content}
% \end{syntax}
% \begin{macrocode}
\int_new:N \g_@@_sectid_int
\cs_new_protected:Npn \@@_section:nn #1#2
{
\group_begin:
\int_gincr:N \g_@@_sectid_int
\int_gincr:N \g_@@_note_id_int
\seq_gput_right:Nx \g_@@_queue_seq { \l_@@_note_id_tl }
\tl_gclear:N \g_@@_section_name_tl
\keys_set:nn { postnotes/section } {#1}
\bool_if:NTF \l_@@_section_exp_bool
{ \@@_store_section:nx { \l_@@_note_id_tl } {#2} }
{ \@@_store_section:nn { \l_@@_note_id_tl } {#2} }
\group_end:
}
% \end{macrocode}
% \end{macro}
%
%
% Options for \cs{postnotesection}. Actually, I would have preferred to use
% ``label'' for the \opt{name} option, but I feared I might need it further
% down the road for the traditional meaning.
%
% \begin{macrocode}
\tl_new:N \g_@@_section_name_tl
\bool_new:N \l_@@_section_exp_bool
\keys_define:nn { postnotes/section }
{
name .tl_gset:N = \g_@@_section_name_tl ,
name .value_required:n = true ,
exp .bool_set:N = \l_@@_section_exp_bool ,
exp .initial:n = false ,
exp .default:n = true ,
}
% \end{macrocode}
%
%
% \section{\cs{printpostnotes}}
%
% \begin{macro}[int]{\printpostnotes}
% Provide \cs{printpostnotes}.
% \begin{syntax}
% \cs{printpostnotes}
% \end{syntax}
% \begin{macrocode}
\NewDocumentCommand \printpostnotes { }
{ \@@_print_notes: }
% \end{macrocode}
% \end{macro}
%
%
% \begin{macro}[int]
% {
% \pnthechapter ,
% \pnthesection ,
% \pnthechapternextnote ,
% \pnthesectionnextnote ,
% \pnthepage ,
% }
% User facing variables, aimed at making available some of the notes' and
% sections' metadata for the user at specific contexts.
% \begin{macrocode}
\tl_new:N \pnthechapter
\tl_new:N \pnthesection
\tl_new:N \pnthechapternextnote
\tl_new:N \pnthesectionnextnote
\tl_new:N \pnthepage
% \end{macrocode}
% \end{macro}
%
% \begin{macro}
% {
% \g_@@_print_postnotes_int ,
% \l_@@_print_note_id_tl ,
% \l_@@_print_note_id_next_tl ,
% \l_@@_print_counter_tl ,
% \l_@@_print_mark_tl ,
% \l_@@_print_type_curr_tl ,
% \l_@@_print_type_next_tl ,
% \l_@@_print_type_prev_tl ,
% \l_@@_print_content_tl ,
% \l_@@_clear_queue_seq ,
% }
% Auxiliary variables for \cs{@@_print_notes:}.
% \begin{macrocode}
\int_new:N \g_@@_print_postnotes_int
\tl_new:N \l_@@_print_note_id_tl
\tl_new:N \l_@@_print_note_id_next_tl
\tl_new:N \l_@@_print_counter_tl
\tl_new:N \l_@@_print_mark_tl
\tl_new:N \l_@@_print_type_curr_tl
\tl_new:N \l_@@_print_type_next_tl
\tl_new:N \l_@@_print_type_prev_tl
\tl_new:N \l_@@_print_content_tl
\seq_new:N \l_@@_clear_queue_seq
% \end{macrocode}
% \end{macro}
%
%
% \cs{@@_print_notes:} hooks. Both meant at providing points of entry for
% additional setup, specially to add support to packages and features which
% require it. The \texttt{postnotes/print/begin} hook is run early in
% \cs{@@_print_notes:} and only once per call, after the user options have
% been processed. The \texttt{postnotes/print/eachnote} hook is run once for
% each note, at the point where environment variables are being set or
% restored, before the typesetting of either the mark or the text, but within
% a group of its own of each note.
%
% \begin{macrocode}
\NewHook { postnotes/print/begin }
\NewHook { postnotes/print/eachnote }
% \end{macrocode}
%
%
% The \texttt{postnotetext} is a counter used to restore the original value of
% \texttt{postnote} at the time of printing, for the purposes of
% cross-referencing, it should be different from \texttt{postnote} if a note
% may occur inside \cs{printpostnotes}. The \texttt{postnotesection} is a
% counter which is stepped for every postnote section which gets to be
% actually typeset. It's aim is to provide a valid ``enclosing counter'' to
% \texttt{postnote} in the context of \cs{printpostnotes}. Since we don't
% know where \texttt{postnote} may have been reset along the document, in the
% general case, we can't rely on any other preexisting counter. This means
% that the particular value of \texttt{postnotesection} is of little practical
% meaning, it really is just meant to provide recognizable ``bounds'' for
% \texttt{postnote} along the printing of the notes. Indeed, it is
% initialized to a very high value (larger than the conceivable number of
% postnote sections in a document), so that ``marks'' and ``texts'' don't mix
% in the same reference list, which would occur if the enclosing counters of
% both belonged to the same range, and with somewhat arbitrary results, since
% we cannot ensure the step of the enclosing counter along the document
% matches \texttt{postnotesection}. This is actually a tricky problem from
% the cross-referencing standpoint: two different things, which should be of
% the same type, are reset along the document, but shouldn't really be mixed
% together. They are both \LaTeXe{} counters, since they may be required
% externally. Their main intended use case is to support \pkg{zref-clever},
% but in principle they can be of general use.
%
% \begin{macrocode}
\newcounter { postnotetext }
\newcounter { postnotesection }
\setcounter { postnotesection } { 10000 }
% \end{macrocode}
%
%
% \begin{macro}{\@@_print_notes:}
% The internal version of \cs{printpostnotes}.
% \begin{syntax}
% \cs{@@_print_notes:}
% \end{syntax}
% \begin{macrocode}
\cs_new_protected:Npn \@@_print_notes:
{
\group_begin:
\int_gincr:N \g_@@_print_postnotes_int
\seq_if_empty:NTF \g_@@_queue_seq
{ \msg_warning:nn { postnotes } { empty-printpostnotes } }
{
\pnheading
\UseHook { postnotes/print/begin }
\tl_set:Nn \l_@@_print_type_prev_tl { open }
\seq_set_eq:NN \l_@@_clear_queue_seq \g_@@_queue_seq
\@@_verify_multipass:N \g_@@_queue_seq
\bool_if:NT \l_@@_sort_bool
{ \@@_sort_queue:N \g_@@_queue_seq }
\bool_gset_true:N \g_@@_header_vars_next_bool
\@@_get_headers_data:N \g_@@_queue_seq
\@@_set_headers_vars_first:
% \end{macrocode}
% Ensure the first note after a heading has paragraph indentation when
% \opt{listenv} is \texttt{none}. \pkg{endnotes} uses a workaroundish
% solution in \cs{enoteheading}, setting a box and then skipping back a line.
% Enrico Gregorio is correct, though, in criticizing it at
% \url{https://tex.stackexchange.com/q/575905#comment1450213_575915}, and
% suggests the use of \cs{@afterindenttrue}, which is what \pkg{indentfirst}
% does (we do the same, just locally).
% \begin{macrocode}
\bool_if:NF \l_@@_print_as_list_bool
{
\cs_set_eq:NN \@afterindentfalse \@afterindenttrue
\@afterindenttrue
}
\bool_until_do:nn { \seq_if_empty_p:N \g_@@_queue_seq }
{
\seq_gpop_left:NN \g_@@_queue_seq
\l_@@_print_note_id_tl
\@@_prop_get:nnN { \l_@@_print_note_id_tl }
{ type } \l_@@_print_type_curr_tl
\tl_if_eq:NnTF \l_@@_print_type_curr_tl { section }
{ % type_curr = `section'
\seq_if_empty:NTF \g_@@_queue_seq
{
\tl_set:Nn \l_@@_print_note_id_next_tl { noid }
\tl_set:Nn \l_@@_print_type_next_tl { close }
}
{
\seq_get_left:NN \g_@@_queue_seq
\l_@@_print_note_id_next_tl
\@@_prop_get:nnN
{ \l_@@_print_note_id_next_tl }
{ type } \l_@@_print_type_next_tl
}
% \end{macrocode}
% We only process the entry if \texttt{type_next} is \texttt{note}: here are
% skipped empty sections.
% \begin{macrocode}
\tl_if_eq:NnT \l_@@_print_type_next_tl { note }
{
\stepcounter { postnotesection }
\group_begin:
\@@_prop_get:nnN
{ \l_@@_print_note_id_tl }
{ thechapter } \pnthechapter
\@@_prop_get:nnN
{ \l_@@_print_note_id_tl }
{ thesection } \pnthesection
\@@_prop_get:nnN
{ \l_@@_print_note_id_next_tl }
{ thechapter } \pnthechapternextnote
\@@_prop_get:nnN
{ \l_@@_print_note_id_next_tl }
{ thesection } \pnthesectionnextnote
\@@_prop_get:nnN
{ \l_@@_print_note_id_tl }
{ content } \l_@@_print_content_tl
\l_@@_print_content_tl
\group_end:
% \end{macrocode}
% Set \texttt{type_prev} for the next iteration.
% \begin{macrocode}
\tl_set:NV \l_@@_print_type_prev_tl
\l_@@_print_type_curr_tl
}
}
{ % type_curr = `note'
\tl_if_eq:NnF \l_@@_print_type_prev_tl { note }
{
\bool_if:NTF \l_@@_print_as_list_bool
{ \exp_args:Nx \begin { \l_@@_print_env_tl } }
{ \group_begin: }
\l_@@_print_format_tl
}
\group_begin:
\UseHook { postnotes/print/eachnote }
\@@_get_pageref:Nx \pnthepage
{ mark@ \l_@@_print_note_id_tl }
\@@_prop_get:nnN
{ \l_@@_print_note_id_tl }
{ mark } \l_@@_print_mark_tl
\@@_prop_get:nnN
{ \l_@@_print_note_id_tl }
{ counter } \l_@@_print_counter_tl
\@@_prop_get:nnN
{ \l_@@_print_note_id_tl }
{ content } \l_@@_print_content_tl
\cs_set:Npn \@currentcounter { postnotetext }
\int_set:Nn \c@postnotetext
{ \l_@@_print_counter_tl }
\cs_set:Npx \@currentlabel
{ \p@postnote \l_@@_print_mark_tl }
\@@_text_mark_wrapper:n
{
\MakeLinkTarget*
{ postnote. \l_@@_print_note_id_tl .text }
\@@_set_text_page_label:x
{ \l_@@_print_note_id_tl }
\@@_typeset_text_mark:eV
{ \l_@@_print_note_id_tl }
\l_@@_print_mark_tl
}
\l_@@_print_content_tl
\l_@@_post_printnote_tl
\group_end:
% \end{macrocode}
% For notes, query for next note's type \texttt{after} the current note was
% typeset, to handle possible nesting. Even if nesting is not a feature, this
% should avoid hard crashes related to ``lonely \cs{item}'' or ``extra
% \cs{endgroup}'' errors, in case it occurs.
% \begin{macrocode}
\seq_if_empty:NTF \g_@@_queue_seq
{
\tl_set:Nn \l_@@_print_note_id_next_tl { noid }
\tl_set:Nn \l_@@_print_type_next_tl { close }
}
{
\seq_get_left:NN \g_@@_queue_seq
\l_@@_print_note_id_next_tl
\@@_prop_get:nnN
{ \l_@@_print_note_id_next_tl }
{ type } \l_@@_print_type_next_tl
}
\tl_if_eq:NnF \l_@@_print_type_next_tl { note }
{
\bool_if:NTF \l_@@_print_as_list_bool
{ \exp_args:Nx \end { \l_@@_print_env_tl } }
{ \group_end: }
}
% \end{macrocode}
% Set \texttt{type_prev} for the next iteration.
% \begin{macrocode}
\tl_set:NV \l_@@_print_type_prev_tl
\l_@@_print_type_curr_tl
}
}
\AddToHookNext { shipout/after }
{ \bool_gset_false:N \g_@@_header_vars_next_bool }
% \end{macrocode}
% We won't use the variables anymore, clear them to reduce memory usage.
% Given how we populated \cs{l_@@_clear_queue_seq}, this won't catch nested
% notes. But it's not worth to conditionally add new items along the way
% (testing it every iteration) for this. Again, not a feature.
% \begin{macrocode}
\seq_map_inline:Nn \l_@@_clear_queue_seq
{ \@@_prop_gclear:n { ##1 } }
}
\group_end:
}
% \end{macrocode}
% \end{macro}
%
% \begin{macrocode}
\msg_new:nnn { postnotes } { empty-printpostnotes }
{ Empty~'\iow_char:N\\printpostnotes'~\msg_line_context:. }
% \end{macrocode}
%
%
% \begin{macro}
% {
% \@@_typeset_text_mark:nn ,
% \@@_text_mark_wrapper:n ,
% }
% Auxiliary functions for mark typesetting in \cs{@@_print_notes:}.
% \begin{syntax}
% \cs{@@_typeset_text_mark:nn} \Arg{note id} \Arg{mark}
% \cs{@@_text_mark_wrapper:n} \Arg{mark}
% \end{syntax}
% \begin{macrocode}
\cs_new_protected:Npn \@@_typeset_text_mark:nn #1#2
{
\bool_lazy_and:nnTF
{ \l_@@_hyperlink_bool }
{ \l_@@_backlink_bool }
{
\@@_make_text_mark:nnn {#2}
{ \hyper@linkstart { link } { postnote. #1 .mark } }
{ \hyper@linkend }
}
{ \@@_make_text_mark:nnn {#2} { } { } }
}
\cs_generate_variant:Nn \@@_typeset_text_mark:nn { eV }
\cs_new_protected:Npn \@@_text_mark_wrapper:n #1
{
\bool_if:NTF \l_@@_print_as_list_bool
{ \item [ \l_@@_pre_textmark_tl #1 \l_@@_post_textmark_tl ] }
{ \l_@@_pre_textmark_tl #1 \l_@@_post_textmark_tl }
}
% \end{macrocode}
% \end{macro}
%
%
% \subsection*{Print auxiliary}
%
% \cs{@@_verify_multipass:N} provides a general procedure for handling cases
% of multiple passes of content. Ideally, the job should be done at
% \cs{@@_inhibit_note:F}, if at all possible. But, failing that, we can rely
% on the fact that \cs{postnote}s of measuring/trial passes don't end up being
% output and hence don't generate labels in the \file{.aux} file. This is the
% equivalent for \pkg{postnotes} to the effect of write restrictions for the
% packages based on external files, which is how they actually handle these
% cases. However, despite this being a general test, and a reasonable one,
% I'd like to restrain it's use to the minimum possible. First, using this
% criterion across the board would result in large swings on the content of
% \cs{printpostnotes} and spurious warnings in an initial compilation since
% the labels are not available on the first run. Second, I'd prefer not to
% interfere with the queue, unless we really need to. Hence, we only apply
% this check for ``eligible'' items. For signaling this eligibility, the note
% must have been stored with the \cs{l_@@_maybe_multi_bool} set to
% \texttt{true}, which is then saved in the \texttt{multibool} property. One
% implication of this procedure is that, if there are any new notes marked as
% \texttt{multibool}, three rounds of compilation will be needed, since the
% labels of the printed notes will be written only on the second run and the
% document will thus require a third one to stabilize.
%
% \begin{macro}{\@@_verify_multipass:N}
% \begin{syntax}
% \cs{@@_verify_multipass:N} \meta{\cs{g_@@_queue_seq}}
% \end{syntax}
% \begin{macrocode}
\cs_new_protected:Npn \@@_verify_multipass:N #1
{
\group_begin:
\seq_clear:N \l_tmpa_seq
\seq_map_inline:Nn #1
{
\@@_prop_get:nnN {##1} { multibool } \l_tmpa_tl
\tl_if_eq:NnTF \l_tmpa_tl { true }
{
\cs_if_exist:cT
{ \c_@@_ref_prefix_tl @ mark@ ##1 }
{ \seq_put_right:Nn \l_tmpa_seq {##1} }
}
{ \seq_put_right:Nn \l_tmpa_seq {##1} }
}
\seq_gset_eq:NN #1 \l_tmpa_seq
\group_end:
}
% \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@@_sort_queue:N}
% Sorting function for \cs{@@_print_notes:}.
% \begin{syntax}
% \cs{@@_sort_queue:N} \meta{\cs{g_@@_queue_seq}}
% \end{syntax}
% \begin{macrocode}
\cs_new_protected:Npn \@@_sort_queue:N #1
{
\group_begin:
\seq_gsort:Nn #1
{
\@@_prop_get:nnN {##1} { pnsectid } \l_tmpa_tl
\@@_prop_get:nnN {##2} { pnsectid } \l_tmpb_tl
\tl_if_eq:NNTF \l_tmpa_tl \l_tmpb_tl
{
\@@_prop_get:nnN {##1} { type } \l_tmpa_tl
\@@_prop_get:nnN {##2} { type } \l_tmpb_tl
\bool_lazy_and:nnTF
{ \str_if_eq_p:Vn \l_tmpa_tl { note } }
{ \str_if_eq_p:Vn \l_tmpb_tl { note } }
{
\@@_prop_get:nnN {##1} { sortnum } \l_tmpa_tl
\@@_prop_get:nnN {##2} { sortnum } \l_tmpb_tl
\fp_compare:nNnTF { \l_tmpa_tl } > { \l_tmpb_tl }
{ \sort_return_swapped: }
{ \sort_return_same: }
}
{ \sort_return_same: }
}
{ \sort_return_same: }
}
\group_end:
}
% \end{macrocode}
% \end{macro}
%
%
% \section{Headers}
%
% The headers infrastructure of \pkg{postnotes} is comprised of three basic
% parts:
%
% \begin{enumerate}
% \item For each \cs{postnote}, labels are set storing the \texttt{page} where
% the note occurs. Each note actually generates a pair of such labels, once
% when \cs{postnote} is called (with the mark), and another where the note
% is printed (in \cs{printpostnotes}). The former ones store \cs{thepage},
% since we want the printed representation of it for typesetting purposes,
% the latter ones store the value of the \texttt{page} counter, since we
% don't need to typeset it, but do need to perform algebraic operations with
% it. These labels are set by \cs{@@_set_mark_page_label:n},
% \cs{@@_set_text_page_label:n}, and \cs{@@_set_print_page_label:n} at the
% appropriate places. The set of these labels provides a mapping from each
% note's ``mark'' and ``text'' to the page where it occurs.
% \item This information set is processed by \cs{@@_get_headers_data:N} at the
% beginning of \cs{@@_print_notes:} to identify the first and last note of
% each page in \cs{printpostnotes}, and to generate a mapping from these
% first and last notes on each page to the pages where their corresponding
% marks occur. We also take the opportunity to enrich this mapping with
% other metadata of each note. So we get also mappings from the first and
% last note on each page to \cs{thechapter}, \cs{thesection}, and the
% \opt{name} of the section in which they occur. These mappings are stored
% in property lists \cs[no-index]{g_@@_header_\meta{info}_first_prop} and
% \cs[no-index]{g_@@_header_\meta{info}_last_prop} where the \texttt{key} is
% the page in \cs{printpostnotes} where their note's content is typeset (or
% rather where it starts to be typeset, it is the page where the text's mark
% is printed).
% \item Based on these mappings, along the span of notes section we run
% \cs{@@_set_headers_vars_next:} at each \texttt{shipout/before} hook to set
% user facing variables for the \emph{next} page, which will be available
% when their heading gets typeset. Given that at \texttt{shipout} we can
% rely on a correct value of the \texttt{page} counter, we use it as
% \texttt{key} to query the property lists generated in the previous step.
% These user facing variables are called \cs[no-index]{pnhd\meta{info}first}
% and \cs[no-index]{pnhd\meta{info}last}. Since we cannot rely on the
% shipout hook for the first page of \cs{printpostnotes},
% \cs{@@_set_headers_vars_first:} is run at its beginning to ensure correct
% values are in place on the first page of the notes section.
% \end{enumerate}
%
% These \cs[no-index]{pnhd\meta{info}first} and
% \cs[no-index]{pnhd\meta{info}last} variables can then be used to build
% simple functions which can be passed to mark commands to achieve rich
% contextual running headers.
%
%
% \begin{macro}[int]
% {
% \pnhdpagefirst ,
% \pnhdpagelast ,
% \pnhdchapfirst ,
% \pnhdchaplast ,
% \pnhdsectfirst ,
% \pnhdsectlast ,
% \pnhdnamefirst ,
% \pnhdnamelast ,
% }
% User facing variables, aimed at making available header data for the user.
% Setting these variables with correct values at the moment the header gets
% typeset is \emph{the} objective of the whole headers infrastructure of the
% package.
% \begin{macrocode}
\tl_new:N \pnhdpagefirst
\tl_new:N \pnhdpagelast
\tl_new:N \pnhdchapfirst
\tl_new:N \pnhdchaplast
\tl_new:N \pnhdsectfirst
\tl_new:N \pnhdsectlast
\tl_new:N \pnhdnamefirst
\tl_new:N \pnhdnamelast
% \end{macrocode}
% \end{macro}
%
%
% \begin{macro}
% {
% \g_@@_header_page_first_prop ,
% \g_@@_header_page_last_prop ,
% \g_@@_header_chap_first_prop ,
% \g_@@_header_chap_last_prop ,
% \g_@@_header_sect_first_prop ,
% \g_@@_header_sect_last_prop ,
% \g_@@_header_name_first_prop ,
% \g_@@_header_name_last_prop ,
% \g_@@_header_prev_last_page_tl ,
% \g_@@_header_prev_last_chap_tl ,
% \g_@@_header_prev_last_sect_tl ,
% \g_@@_header_prev_last_name_tl ,
% \l_@@_prev_text_page_tl ,
% \l_@@_curr_text_page_tl ,
% \l_@@_prev_mark_page_tl ,
% \l_@@_prev_mark_chap_tl ,
% \l_@@_prev_mark_sect_tl ,
% \l_@@_prev_mark_name_tl ,
% }
% Auxiliary variables for the headers infrastructure.
% \begin{macrocode}
\prop_new:N \g_@@_header_page_first_prop
\prop_new:N \g_@@_header_page_last_prop
\prop_new:N \g_@@_header_chap_first_prop
\prop_new:N \g_@@_header_chap_last_prop
\prop_new:N \g_@@_header_sect_first_prop
\prop_new:N \g_@@_header_sect_last_prop
\prop_new:N \g_@@_header_name_first_prop
\prop_new:N \g_@@_header_name_last_prop
\tl_new:N \g_@@_header_prev_last_page_tl
\tl_new:N \g_@@_header_prev_last_chap_tl
\tl_new:N \g_@@_header_prev_last_sect_tl
\tl_new:N \g_@@_header_prev_last_name_tl
\tl_new:N \l_@@_prev_text_page_tl
\tl_new:N \l_@@_curr_text_page_tl
\tl_new:N \l_@@_prev_mark_page_tl
\tl_new:N \l_@@_prev_mark_chap_tl
\tl_new:N \l_@@_prev_mark_sect_tl
\tl_new:N \l_@@_prev_mark_name_tl
% \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@@_get_headers_data:N}
% Process header data for \cs{@@_set_headers_vars:n}.
% \begin{syntax}
% \cs{@@_get_headers_data:N} \meta{\cs{g_@@_queue_seq}}
% \end{syntax}
% \begin{macrocode}
\cs_new_protected:Npn \@@_get_headers_data:N #1
{
\group_begin:
\tl_gclear:N \pnhdpagefirst
\tl_gclear:N \pnhdpagelast
\tl_gclear:N \pnhdchapfirst
\tl_gclear:N \pnhdchaplast
\tl_gclear:N \pnhdsectfirst
\tl_gclear:N \pnhdsectlast
\tl_gclear:N \pnhdnamefirst
\tl_gclear:N \pnhdnamelast
\prop_gclear:N \g_@@_header_page_first_prop
\prop_gclear:N \g_@@_header_page_last_prop
\prop_gclear:N \g_@@_header_chap_first_prop
\prop_gclear:N \g_@@_header_chap_last_prop
\prop_gclear:N \g_@@_header_sect_first_prop
\prop_gclear:N \g_@@_header_sect_last_prop
\prop_gclear:N \g_@@_header_name_first_prop
\prop_gclear:N \g_@@_header_name_last_prop
\tl_gclear:N \g_@@_header_prev_last_page_tl
\tl_gclear:N \g_@@_header_prev_last_chap_tl
\tl_gclear:N \g_@@_header_prev_last_sect_tl
\tl_gclear:N \g_@@_header_prev_last_name_tl
\tl_clear:N \l_@@_prev_text_page_tl
\tl_clear:N \l_@@_curr_text_page_tl
\tl_clear:N \l_@@_prev_mark_page_tl
\tl_clear:N \l_@@_prev_mark_chap_tl
\tl_clear:N \l_@@_prev_mark_sect_tl
\tl_clear:N \l_@@_prev_mark_name_tl
\seq_map_inline:Nn #1
{
\exp_args:Nx \tl_if_eq:nnT
{ \@@_prop_item:nn {##1} { type } }
{ note }
{
\@@_get_pageref:Nn
\l_@@_curr_text_page_tl { text@ ##1 }
\tl_if_empty:NF \l_@@_curr_text_page_tl
{
\tl_if_eq:NNTF
\l_@@_prev_text_page_tl
\l_@@_curr_text_page_tl
{
% \end{macrocode}
% We are on the same page as the previous note, just update the
% \texttt{prev_mark} data.
% \begin{macrocode}
\@@_get_pageref:Nn
\l_@@_prev_mark_page_tl { mark@ ##1 }
\@@_prop_get:nnN {##1} { thechapter }
\l_@@_prev_mark_chap_tl
\@@_prop_get:nnN {##1} { thesection }
\l_@@_prev_mark_sect_tl
\@@_prop_get:nnN {##1} { pnsectname }
\l_@@_prev_mark_name_tl
}
{
% \end{macrocode}
% We are on the transition between two pages, current ID is the first note of
% the new page (or on the very first note of \cs{printpostnotes}, given
% \cs{l_@@_prev_text_page_tl} is initialized to empty).
%
% Set `last' values for previous page, based on the last valid
% \texttt{prev_mark} stored ones. There is no previous page to the first one
% of \cs{printpostnotes}, so we don't set `last' values for it (conditioning
% on \cs{l_@@_prev_text_page_tl} being empty, which only occurs on the first
% note).
% \begin{macrocode}
\tl_if_empty:NF \l_@@_prev_text_page_tl
{
\prop_gput:Nxx \g_@@_header_page_last_prop
{ \l_@@_prev_text_page_tl }
{ \l_@@_prev_mark_page_tl }
\prop_gput:Nxx \g_@@_header_chap_last_prop
{ \l_@@_prev_text_page_tl }
{ \l_@@_prev_mark_chap_tl }
\prop_gput:Nxx \g_@@_header_sect_last_prop
{ \l_@@_prev_text_page_tl }
{ \l_@@_prev_mark_sect_tl }
\prop_gput:Nxx \g_@@_header_name_last_prop
{ \l_@@_prev_text_page_tl }
{ \l_@@_prev_mark_name_tl }
}
% \end{macrocode}
%
% Set `first' values for current page, based on the current note ID.
% \begin{macrocode}
\prop_gput:Nxx \g_@@_header_page_first_prop
{ \l_@@_curr_text_page_tl }
{ \@@_extract_pageref:n { mark@ ##1 } }
\prop_gput:Nxx \g_@@_header_chap_first_prop
{ \l_@@_curr_text_page_tl }
{ \@@_prop_item:nn {##1} { thechapter } }
\prop_gput:Nxx \g_@@_header_sect_first_prop
{ \l_@@_curr_text_page_tl }
{ \@@_prop_item:nn {##1} { thesection } }
\prop_gput:Nxx \g_@@_header_name_first_prop
{ \l_@@_curr_text_page_tl }
{ \@@_prop_item:nn {##1} { pnsectname } }
% \end{macrocode}
%
% Store \texttt{prev_mark} data for the first note on the page.
% \begin{macrocode}
\@@_get_pageref:Nn
\l_@@_prev_mark_page_tl { mark@ ##1 }
\@@_prop_get:nnN {##1} { thechapter }
\l_@@_prev_mark_chap_tl
\@@_prop_get:nnN {##1} { thesection }
\l_@@_prev_mark_sect_tl
\@@_prop_get:nnN {##1} { pnsectname }
\l_@@_prev_mark_name_tl
% \end{macrocode}
%
% Set \cs{l_@@_prev_text_page_tl} for the next page
% (\cs{l_@@_curr_text_page_tl} is never empty at this point, since we
% conditioned to it).
% \begin{macrocode}
\tl_set:NV \l_@@_prev_text_page_tl
\l_@@_curr_text_page_tl
}
}
}
}
% \end{macrocode}
% We can't catch the transition from the last page of \cs{printpostnotes} to
% the following one through the mapping above, but the \texttt{prev_mark}
% values of the last note in the loop are the ones we want, so we set `last'
% values for the last page based on them.
% \begin{macrocode}
\tl_if_empty:NF \l_@@_prev_text_page_tl
{
\prop_gput:Nxx \g_@@_header_page_last_prop
{ \l_@@_prev_text_page_tl }
{ \l_@@_prev_mark_page_tl }
\prop_gput:Nxx \g_@@_header_chap_last_prop
{ \l_@@_prev_text_page_tl }
{ \l_@@_prev_mark_chap_tl }
\prop_gput:Nxx \g_@@_header_sect_last_prop
{ \l_@@_prev_text_page_tl }
{ \l_@@_prev_mark_sect_tl }
\prop_gput:Nxx \g_@@_header_name_last_prop
{ \l_@@_prev_text_page_tl }
{ \l_@@_prev_mark_name_tl }
}
\group_end:
}
% \end{macrocode}
% \end{macro}
%
%
% The sequence of pages processed in \cs{@@_get_headers_data:N} is not ensured
% to be continuous, since not every page of \cs{printpostnotes} starts a note.
% There may be notes that fill whole pages, or the last page of the notes may
% end with a note that started on the penultimate page. We must handle this
% case at \cs{@@_set_headers_vars:n}. For every page for which there is
% information provided by \cs{@@_get_headers_data:N} we store a
% \texttt{header_prev_last} (the last value of the previous header) for each
% of the variables of interest. If the next page is skipped in the sequence
% (no notes starting on it), we can use these stored values to set both
% `first' and `last' variables based on them for that page.
%
%
% \begin{macro}{\@@_set_headers_vars:n}
% Set user facing variables based on data generated by
% \cs{@@_get_headers_data:N}.
% \begin{syntax}
% \cs{@@_set_headers_vars:n} \Arg{page number}
% \end{syntax}
% \begin{macrocode}
\cs_new_protected:Npn \@@_set_headers_vars:n #1
{
\group_begin:
\prop_get:NnNTF \g_@@_header_page_first_prop
{#1} \l_tmpa_tl
{ \tl_gset:NV \pnhdpagefirst \l_tmpa_tl }
{ \tl_gset:NV \pnhdpagefirst \g_@@_header_prev_last_page_tl }
\prop_get:NnNTF \g_@@_header_page_last_prop
{#1} \l_tmpa_tl
{
\tl_gset:NV \pnhdpagelast \l_tmpa_tl
\tl_gset:NV \g_@@_header_prev_last_page_tl \l_tmpa_tl
}
{ \tl_gset:NV \pnhdpagelast \g_@@_header_prev_last_page_tl }
\prop_get:NnNTF \g_@@_header_chap_first_prop
{#1} \l_tmpa_tl
{ \tl_gset:NV \pnhdchapfirst \l_tmpa_tl }
{ \tl_gset:NV \pnhdchapfirst \g_@@_header_prev_last_chap_tl }
\prop_get:NnNTF \g_@@_header_chap_last_prop
{#1} \l_tmpa_tl
{
\tl_gset:NV \pnhdchaplast \l_tmpa_tl
\tl_gset:NV \g_@@_header_prev_last_chap_tl \l_tmpa_tl
}
{ \tl_gset:NV \pnhdchaplast \g_@@_header_prev_last_chap_tl }
\prop_get:NnNTF \g_@@_header_sect_first_prop
{#1} \l_tmpa_tl
{ \tl_gset:NV \pnhdsectfirst \l_tmpa_tl }
{ \tl_gset:NV \pnhdsectfirst \g_@@_header_prev_last_sect_tl }
\prop_get:NnNTF \g_@@_header_sect_last_prop
{#1} \l_tmpa_tl
{
\tl_gset:NV \pnhdsectlast \l_tmpa_tl
\tl_gset:NV \g_@@_header_prev_last_sect_tl \l_tmpa_tl
}
{ \tl_gset:NV \pnhdsectlast \g_@@_header_prev_last_sect_tl }
\prop_get:NnNTF \g_@@_header_name_first_prop
{#1} \l_tmpa_tl
{ \tl_gset:NV \pnhdnamefirst \l_tmpa_tl }
{ \tl_gset:NV \pnhdnamefirst \g_@@_header_prev_last_name_tl }
\prop_get:NnNTF \g_@@_header_name_last_prop
{#1} \l_tmpa_tl
{
\tl_gset:NV \pnhdnamelast \l_tmpa_tl
\tl_gset:NV \g_@@_header_prev_last_name_tl \l_tmpa_tl
}
{ \tl_gset:NV \pnhdnamelast \g_@@_header_prev_last_name_tl }
\group_end:
}
\cs_generate_variant:Nn \@@_set_headers_vars:n { x }
% \end{macrocode}
% \end{macro}
%
%
% \begin{macro}
% {
% \@@_set_headers_vars_next: ,
% \@@_set_headers_vars_first: ,
% }
% The functions that actually call \cs{@@_set_headers_vars:n} at the
% appropriate contexts with appropriate page values. Though we set
% \cs{@@_set_headers_vars_next:} to run at every \texttt{shipout/before}
% hook of the document, it is made no-op by \cs{g_@@_header_vars_next_bool}
% which only has a \texttt{true} value inside \cs{printpostnotes}.
% \cs{@@_set_headers_vars_first:} must set a label and retrieve its value to
% be able to have a reliable value of its own page.
% \begin{macrocode}
\AddToHook { shipout/before } [ postnotes/header ]
{ \@@_set_headers_vars_next: }
\bool_new:N \g_@@_header_vars_next_bool
\cs_new_protected:Npn \@@_set_headers_vars_next:
{
\bool_if:NT \g_@@_header_vars_next_bool
{ \@@_set_headers_vars:x { \int_eval:n { \c@page + 1 } } }
}
\cs_new_protected:Npn \@@_set_headers_vars_first:
{
\@@_set_print_page_label:x
{ \int_use:N \g_@@_print_postnotes_int }
\@@_set_headers_vars:x
{
\@@_extract_pageref:e
{ print@ \int_use:N \g_@@_print_postnotes_int }
}
}
% \end{macrocode}
% \end{macro}
%
%
% \begin{macro}[int]{\pnheaderdefault}
% A basic header function to be used as default in the \opt{heading} option.
% It produces a header in the form ``Notes to pages N--M'', with a text
% which can be localized (see Section~\ref{sec:languages}).
% \begin{syntax}
% \cs{pnheaderdefault}
% \end{syntax}
% \begin{macrocode}
\NewDocumentCommand \pnheaderdefault {}
{
\tl_if_eq:NNTF \pnhdpagefirst \pnhdpagelast
{ \pnhdnotes{} ~ \pnhdtopage{} ~ \pnhdpagefirst }
{ \pnhdnotes{} ~ \pnhdtopages{} ~ \pnhdpagefirst -- \pnhdpagelast }
}
% \end{macrocode}
% \end{macro}
%
%
% \section{Compatibility}
%
% A dedicated temp variable for restoring data.
%
% \begin{macrocode}
\tl_new:N \l_@@_restore_tmp_tl
% \end{macrocode}
%
% \subsection*{\cs{caption}}
%
% For \cs{caption}'s possible two passes. This catches more than just
% captions, of course, but is not overkill.
%
% From the user's perspective, one-line captions will just work. For two-line
% captions, there are two alternatives: i) decrement the counter by 1
% \texttt{\textbackslash{}addtocounter\{postnote\}\{-1\}} before the caption,
% then call \cs{postnote} inside the caption; or ii) right before the caption,
% call
% \texttt{\textbackslash{}postnote[nomark]\{\textbackslash{}label\{mynote\}...\}},
% then use \texttt{\textbackslash{}postnoteref\{mynote\}} inside the caption.
%
% \begin{macrocode}
\AddToHook { postnotes/note/begin } [ postnotes ]
{
\cs_if_exist:NT \@captype
{ \bool_set_true:N \l_@@_maybe_multi_bool }
}
% \end{macrocode}
%
%
% \subsection*{\pkg{biblatex}}
%
% Thanks \contributor{Moritz Wemheuer}:
% \url{https://tex.stackexchange.com/q/597359#comment1594585_597389}.
%
%
% \begin{macrocode}
\AddToHook { package/biblatex/after }
{
% \end{macrocode}
% Let \pkg{biblatex} know we are in a ``notes'' context. See
% \url{https://tex.stackexchange.com/a/304464}, including comments.
% \begin{macrocode}
\AddToHook { postnotes/print/begin } [ postnotes ]
{ \toggletrue { blx@footnote } }
% \end{macrocode}
% Make \pkg{biblatex}'s \cs{mkbibendnote} use \cs{postnote}. This is very
% likely desired in most cases, but may occasionally not be, so we add it to
% an individually labeled hook, which can be disabled with
% \texttt{\textbackslash{}RemoveFromHook\{begindocument/before\}[postnotes/mkbibendnote]}
% in the preamble.
% \begin{macrocode}
\AddToHook { begindocument/before } [ postnotes/mkbibendnote ]
{
\cs_set:Npn \blx@theendnote { \postnote }
\cs_set:Npn \blx@theendnotetext
{ \blx@err@endnote \footnotetext }
}
}
% \end{macrocode}
%
%
% \begin{macrocode}
%<*gobble>
% \end{macrocode}
%
% I had made an initial experimental attempt to support \pkg{biblatex}'s
% \texttt{refsegment}s, \texttt{refcontext}s and \texttt{refsection}s.
% However, this attempt was rash. Even if I could get many example files to
% work for \texttt{refsegment}s and \texttt{refcontext}s, I could not do so
% for \texttt{refsection}s. More importantly, with this partial
% implementation, I could also generate documents which confused
% \pkg{biblatex} more than it helped. Things I couldn't understand well, or
% fix. All in all, I don't think this partial implementation is tenable, and
% I could not take it further. Hence, \pkg{postnotes} support for this
% feature set of \pkg{biblatex} will depend, as it should, on proper upstream
% support for ``saving'' and ``restoring'' citation ``context'' information.
%
% I have made a feature request at \pkg{biblatex} for this
% (\url{https://github.com/plk/biblatex/issues/1226}), which was
% (understandably) classified as ``long term, no promises''.
%
%
% The attempt was the following (currently ``gobbled'' from the package):
%
% \begin{macrocode}
\AddToHook { package/biblatex/after }
{
% \end{macrocode}
% Store \pkg{biblatex} variables for each note.
% \begin{macrocode}
\AddToHook { postnotes/store/note } [ postnotes ]
{
\prop_gput:cnx { \@@_data_name:e { \l_@@_note_id_tl } }
{ biblatex@refsection } { \int_use:N \c@refsection }
\prop_gput:cnx { \@@_data_name:e { \l_@@_note_id_tl } }
{ biblatex@refsegment } { \int_use:N \c@refsegment }
\prop_gput:cnx { \@@_data_name:e { \l_@@_note_id_tl } }
{ biblatex@refcontextbool }
{ \iftoggle { blx@refcontext } { true } { false } }
\prop_gput:cnV { \@@_data_name:e { \l_@@_note_id_tl } }
{ biblatex@refcontext } \blx@refcontext@context
}
% \end{macrocode}
% \pkg{biblatex} setup, once for \cs{printpostnotes} call.
% \begin{macrocode}
\AddToHook { postnotes/print/begin } [ postnotes ]
{
\@@_biblatex_endrefcontext_local:
\@@_biblatex_citereset_local:
}
% \end{macrocode}
% Restore \pkg{biblatex} variables for each note.
% \begin{macrocode}
\AddToHook { postnotes/print/eachnote } [ postnotes ]
{
\@@_prop_get:nnN { \l_@@_print_note_id_tl }
{ biblatex@refsection } \l_@@_restore_tmp_tl
\int_set:Nn \c@refsection { \l_@@_restore_tmp_tl }
\@@_prop_get:nnN { \l_@@_print_note_id_tl }
{ biblatex@refsegment } \l_@@_restore_tmp_tl
\int_set:Nn \c@refsegment { \l_@@_restore_tmp_tl }
\@@_prop_get:nnN { \l_@@_print_note_id_tl }
{ biblatex@refcontextbool } \l_@@_restore_tmp_tl
\use:c { toggle \l_@@_restore_tmp_tl } { blx@refcontext }
\@@_prop_get:nnN { \l_@@_print_note_id_tl }
{ biblatex@refcontext } \l_@@_restore_tmp_tl
\blx@edef@refcontext { \l_@@_restore_tmp_tl }
}
% \end{macrocode}
% Auxiliary functions.
%
% \begin{macro}{\@@_biblatex_endrefcontext_local:}
% Replicate the job of \cs{endrefcontext}, but with local effects,
% restrained to the group of \cs{printpostnotes}.
% \begin{macrocode}
\cs_new_protected:Npn \@@_biblatex_endrefcontext_local:
{
\togglefalse { blx@refcontext }
\tl_clear:N \blx@refcontext@labelprefix
\tl_clear:N \blx@refcontext@labelprefix@real
\tl_set:Nx \blx@refcontext@sortingtemplatename { \blx@sorting }
\tl_set:Nn \blx@refcontext@sortingnamekeytemplatename { global }
\tl_set:Nn \blx@refcontext@uniquenametemplatename { global }
\tl_set:Nn \blx@refcontext@labelalphanametemplatename { global }
\blx@edef@refcontext
{
\blx@refcontext@sortingtemplatename /
\blx@refcontext@sortingnamekeytemplatename /
/
\blx@refcontext@uniquenametemplatename /
\blx@refcontext@labelalphanametemplatename
}
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_biblatex_citereset_local:}
% Replicate the job of \cs{citereset}, but with local effects, restrained to
% the group of \cs{printpostnotes}.
% \begin{macrocode}
\cs_new_protected:Npn \@@_biblatex_citereset_local:
{
% \end{macrocode}
% \noindent
% {\em\scriptsize\verb|\global\cslet{blx@bsee@\the\c@refsection}\@empty|} \\
% {\em\scriptsize\verb|\global\cslet{blx@fsee@\the\c@refsection}\@empty|}
% \begin{macrocode}
\tl_clear:c { blx@bsee@ \int_use:N \c@refsection }
\tl_clear:c { blx@fsee@ \int_use:N \c@refsection }
% \end{macrocode}
% {\em\scriptsize\verb|\blx@ibidreset@force|}
% \begin{macrocode}
\undef \blx@lastkey@text
\undef \blx@lastkey@foot
% \end{macrocode}
% {\em\scriptsize\verb|\blx@idemreset@force|}
% \begin{macrocode}
\undef \blx@lasthash@text
\undef \blx@lasthash@foot
% \end{macrocode}
% {\em\scriptsize\verb|\blx@opcitreset@force|}
% \begin{macrocode}
\clist_map_inline:Nn \blx@trackhash@text
{ \csundef { blx@lastkey@text@ ##1 } }
\tl_clear:N \blx@trackhash@text
\clist_map_inline:Nn \blx@trackhash@foot
{ \csundef { blx@lastkey@foot@ ##1 } }
\tl_clear:N \blx@trackhash@foot
% \end{macrocode}
% {\em\scriptsize\verb|\blx@loccitreset@force|}
% \begin{macrocode}
\clist_map_inline:Nn \blx@trackkeys@text
{ \csundef { blx@lastnote@text@ ##1 } }
\tl_clear:N \blx@trackkeys@text
\clist_map_inline:Nn \blx@trackkeys@foot
{ \csundef { blx@lastnote@foot@ ##1 } }
\tl_clear:N \blx@trackkeys@foot
% \end{macrocode}
% {\em\scriptsize{}and all of them do:}
% \begin{macrocode}
\cs_set_eq:NN \blx@lastmpfn \z@
}
% \end{macrocode}
% \end{macro}
%
% \begin{macrocode}
}
% \end{macrocode}
%
% \pkg{biblatex}'s \texttt{refsections}, contrary to \texttt{refsegment}s and
% \texttt{refcontext}s which are handled in the \LaTeX{} side of things (as
% far as I can tell), need to go through \texttt{biber}, and must have correct
% corresponding citation data written to the \file{.bcf} file. And the way
% \cs{refsection} is implemented presumes each section is only ever begun once
% (fair\dots{}), thus making it difficult to ``reopen'' it, or append new
% citations to it later on, when the notes are printed. The start of a
% \texttt{refsection} must be registered on the \file{.bcf} file, and this is
% done by \cs{refsection} (and its auxiliary functions). However, a number of
% its characteristics make things particularly difficult for the purpose at
% hand: i) it unconditionally sets a label for the section which, of course,
% cannot be done twice; and, critically, ii) the optional argument of the
% environment (which receives the \meta{resources}) is used to set a local
% assignment to \cs{blx@bibfiles}, based on which the relevant information is
% written to the \file{.bcf} file, and when the group closes the information
% is gone. My best attempt is below but it is not good. It feels a wrong
% approach to ``go around'' the intended use of \cs{refsection} so much, and
% it can't handle at all its optional argument, for the reasons above. It's
% also incomplete, since it does not handle restoring
% \cs{l_@@_biblatex_orig_refsection_tl}.
%
% \begin{macrocode}
\AddToHook { package/biblatex/after }
{
\tl_new:N \l_@@_biblatex_orig_refsection_tl
\tl_new:N \g_@@_biblatex_prev_refsection_tl
\AddToHook { postnotes/print/begin } [ postnotes ]
{
\tl_set:Nx \l_@@_biblatex_orig_refsection_tl
{ \int_use:N \c@refsection }
\tl_gset:Nx \g_@@_biblatex_prev_refsection_tl
\l_@@_biblatex_orig_refsection_tl
}
\AddToHook { postnotes/print/eachnote } [ postnotes ]
{
\@@_prop_get:nnN { \l_@@_print_note_id_tl }
{ biblatex@refsection } \l_@@_restore_tmp_tl
\tl_if_eq:NNF
\l_@@_restore_tmp_tl
\g_@@_biblatex_prev_refsection_tl
{
\int_set:Nn \c@blx@maxsection
{ \l_@@_restore_tmp_tl - 1 }
\tl_gset_eq:NN \g_@@_biblatex_prev_refsection_tl
\l_@@_restore_tmp_tl
\group_begin:
\cs_set_eq:NN \label \use_none:n
\cs_set_eq:NN \blx@info \use_none:n
\blx@endrefsection
\refsection
\group_end:
}
}
}
% \end{macrocode}
%
% \begin{macrocode}
%</gobble>
% \end{macrocode}
%
%
% \subsection*{\pkg{zref-user}}
%
% \begin{macro}{\l_@@_note_zlabel_tl}
% Even though the \opt{zlabel} option is provided only when \pkg{zref-user}
% is loaded, \cs{l_@@_note_zlabel_tl} must be unconditionally defined, since
% it is presumed to exist by \cs{@@_set_user_labels:}.
% \begin{macrocode}
\tl_new:N \l_@@_note_zlabel_tl
% \end{macrocode}
% \end{macro}
%
% \begin{macrocode}
\AddToHook { package/zref-user/after }
{
% \end{macrocode}
% Provide \opt{zlabel} option.
% \begin{macrocode}
\keys_define:nn { postnotes/note }
{
zlabel .tl_set:N = \l_@@_note_zlabel_tl ,
zlabel .value_required:n = true ,
}
% \end{macrocode}
%
% \begin{macro}[int]{\postnotezref}
% Provide \cs{postnotezref}.
% \begin{syntax}
% \cs{postnotezref}\meta{*}\marg{label}
% \end{syntax}
% \begin{macrocode}
\NewDocumentCommand \postnotezref { s m }
{ \@@_note_zref:nn {#1} {#2} }
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_note_zref:nn}
% The internal version of \cs{postnotezref}.
% \begin{syntax}
% \cs{@@_note_zref:nn} \Arg{star bool} \Arg{label}
% \end{syntax}
% \begin{macrocode}
\cs_new_protected:Npn \@@_note_zref:nn #1#2
{
\group_begin:
\@@_typeset_mark_wrapper:n
{
\bool_lazy_and:nnTF
{ ! #1 }
{ \l_@@_hyperlink_bool }
{
\hyperlink
{ \zref@extractdefault {#2} { anchor } { } }
{ \@@_make_mark:nnn { \zref{#2} } { } { } }
}
{ \@@_make_mark:nnn { \zref{#2} } { } { } }
}
\group_end:
}
% \end{macrocode}
% \end{macro}
%
% \begin{macrocode}
}
% \end{macrocode}
%
%
% \subsection*{\pkg{zref-clever}}
%
% \begin{macrocode}
\AddToHook { package/zref-clever/after }
{
\zcsetup
{
countertype = { postnote = endnote } ,
countertype = { postnotetext = endnote } ,
}
\AddToHook { postnotes/print/begin } [ postnotes ]
{ \zcsetup { counterresetby = { postnotetext = postnotesection } } }
}
% \end{macrocode}
%
%
% \subsection*{\pkg{zref-check}}
%
% \begin{macrocode}
\AddToHook { package/zref-check/after }
{
\IfPackageAtLeastTF { zref-check } { 2022-07-05 }
{
\AddToHook { postnotes/store/note } [ postnotes ]
{
\prop_gput:cnx { \@@_data_name:e { \l_@@_note_id_tl } }
{ zref-check@abschap } { \int_use:N \c@zc@abschap }
\prop_gput:cnx { \@@_data_name:e { \l_@@_note_id_tl } }
{ zref-check@abssec } { \int_use:N \c@zc@abssec }
}
\AddToHook { postnotes/print/eachnote } [ postnotes ]
{
\@@_prop_get:nnN { \l_@@_print_note_id_tl }
{ zref-check@abschap } \l_@@_restore_tmp_tl
\int_set:Nn \c@zc@abschap { \l_@@_restore_tmp_tl }
\@@_prop_get:nnN { \l_@@_print_note_id_tl }
{ zref-check@abssec } \l_@@_restore_tmp_tl
\int_set:Nn \c@zc@abssec { \l_@@_restore_tmp_tl }
}
}
{ }
}
% \end{macrocode}
%
%
% \subsection*{\pkg{amsmath}}
%
% \begin{macrocode}
\AddToHook { package/amsmath/after }
{
% \end{macrocode}
% Testing for \cs{ifmeasuring@} is sufficient to get things right for the
% measuring passes in math environments.
% \begin{macrocode}
\AddToHook { postnotes/note/inhibit } [ postnotes ]
{
\legacy_if:nT { measuring@ }
{
\bool_set_true:N \l_@@_inhibit_note_bool
\bool_set_true:N \l_@@_print_plain_mark_bool
}
}
% \end{macrocode}
% However, the \cs{text} macro, defined by \pkg{amstext} (required by
% \pkg{amsmath}), poses problems if its own. Despite my best efforts, I could
% not salvage things from the use of \cs{mathchoice} and the redefinitions of
% \cs{setcounter} and \cs{addtocounter} performed by \pkg{amstext}. Setting
% \cs{l_@@_maybe_multi_bool} when \texttt{firstchoice@} is \texttt{false}
% grants us a working situation for display style. But the use of
% \cs{postnote} inside \cs{text} (and, if \pkg{amsmath} is loaded,
% \cs{textnormal}, \cs{textup}, etc.) in inline math environments is not
% supported. If a note really needs to be there, one can use the \opt{nomark}
% option and \cs{postnoteref}. Things should work in text mode and in display
% style. For some related discussion with regard to footnotes,
% see \url{https://tex.stackexchange.com/a/82820} and, in particular, Barbara
% Beeton's comment: ``This is certainly bravura code. I do hope it doesn't
% result in a request to add \cs{footnote} capabilities to \pkg{amsmath}'s
% multi-line display facilities. (The answer will almost certainly be "no".
% We agree with Kopka \& Daly.)''
% \begin{macrocode}
\AddToHook { postnotes/note/begin } [ postnotes ]
{
\legacy_if:nF { firstchoice@ }
{ \bool_set_true:N \l_@@_maybe_multi_bool }
}
}
% \end{macrocode}
%
%
% \subsection*{\pkg{csquotes}}
%
% \begin{macrocode}
\AddToHook { package/csquotes/after }
{
\bool_new:N \l_@@_csquotes_measuring_bool
\BlockquoteDisable
{ \bool_set_true:N \l_@@_csquotes_measuring_bool }
\AddToHook { postnotes/note/inhibit } [ postnotes ]
{
\bool_if:NT \l_@@_csquotes_measuring_bool
{
\bool_set_true:N \l_@@_inhibit_note_bool
\bool_set_true:N \l_@@_print_plain_mark_bool
}
}
}
% \end{macrocode}
%
%
% \subsection*{\pkg{tabularx}}
%
% For the identification of the trial passes in \pkg{tabularx}, see
% \url{https://tex.stackexchange.com/a/640035} (including discussion in the
% comments, thanks \contributor{David Carlisle}), and also
% \url{https://tex.stackexchange.com/a/227155} and
% \url{https://tex.stackexchange.com/a/352134}.
%
% \begin{macrocode}
\AddToHook { package/tabularx/after }
{
\bool_new:N \l_@@_tabularx_inside_env_bool
\AddToHook { env/tabularx/begin } [ postnotes ]
{
\bool_set_true:N \l_@@_tabularx_inside_env_bool
\cs_set_eq:NN \@@_tabularx_saved_write:Nn \write
}
\AddToHook { postnotes/note/inhibit } [ postnotes ]
{
\bool_lazy_and:nnT
{ \l_@@_tabularx_inside_env_bool }
{ ! \cs_if_eq_p:NN \write \@@_tabularx_saved_write:Nn }
{
\bool_set_true:N \l_@@_inhibit_note_bool
\bool_set_true:N \l_@@_print_plain_mark_bool
}
}
}
% \end{macrocode}
%
%
% \subsection*{\pkg{tabularray}}
%
% I've tried, but I could not find any ``handle'' to distinguish in
% \pkg{tabularray} a trial/measure pass from the final one. So we use
% \cs{@@_verify_multipass:N} for it.
%
% \begin{macrocode}
\AddToHook { package/tabularray/after }
{
\clist_map_inline:nn
{ tblr , longtblr , talltblr , booktabs , longtabs , talltabs , +array }
{
\AddToHook { env/#1/begin } [ postnotes ]
{ \bool_set_true:N \l_@@_maybe_multi_bool }
}
}
% \end{macrocode}
%
%
% \section{Languages}
% \label{sec:languages}
%
% \begin{macro}[int]
% {
% \pntitle ,
% \pnhdnotes ,
% \pnhdtopage ,
% \pnhdtopages ,
% }
% Set of language specific user variables. They are used in the default
% value of the \opt{heading} option and in \cs{pnheaderdefault} which,
% ultimately, is also used in the same place.
% \begin{macrocode}
\tl_new:N \pntitle
\tl_new:N \pnhdnotes
\tl_new:N \pnhdtopage
\tl_new:N \pnhdtopages
\tl_set:Nn \pntitle { Notes }
\tl_set:Nn \pnhdnotes { Notes }
\tl_set:Nn \pnhdtopage { to~page }
\tl_set:Nn \pnhdtopages { to~pages }
% \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@@_define_language:nn}
% Defines language specific values for \meta{postnote language} by storing a
% set of assignments for the language specific variables in \meta{setup}.
% \meta{postnote language} is an internal name, typically the ``main'' name
% of the language, based on which we can set specific \pkg{babel} or
% \pkg{polyglossia} languages or variants.
% \begin{syntax}
% \cs{@@_define_language:nn} \Arg{postnote language} \Arg{setup}
% \end{syntax}
% \begin{macrocode}
\cs_new_protected:Npn \@@_define_language:nn #1#2
{
\tl_new:c { g_@@_language_ #1 _tl }
\tl_gset:cn { g_@@_language_ #1 _tl } {#2}
}
% \end{macrocode}
% \end{macro}
%
%
% For \pkg{babel} we use the new hook system, it's clean, and avoids the
% \cs{addto} pitfalls. The appropriate hook to use is
% \texttt{babel/\meta{language}/beforeextras} so that users can override it
% with a traditional
% \texttt{\textbackslash{}addto\textbackslash{}extras\meta{language}}.
%
% Note that, for \pkg{babel}, the captions are currently handled in two
% different ways -- the ``old way'' and the ``new way'' -- and which of them
% is used depends on the language. Most still use the ``old way'', but the
% problem is that it is not universal. And the ``new way'' uses a different
% naming scheme -- \texttt{\textbackslash{}\meta{language}\meta{caption}},
% which is meant to be set with \cs{setlocalecaption}, and not suitable for
% our needs. The \texttt{\textbackslash{}extras\meta{language}} macros are
% meant for ``arbitrary'' code to be run when the language is selected, which
% is what we want. The captions used to work in the same way, but no longer
% for languages which use the ``new way''.
%
% Note also that there seems to exist some qualms about \pkg{babel}'s
% \cs{addto}. A number of packages define their own versions of it. Do so at
% least \pkg{varioref} (probably the original), \pkg{backref}, and
% \pkg{cleveref}. The latter comments that \cs{addto} is ``flawed''.
% \pkg{babel} itself comments the definition recognizing that there is an
% ``inconsistency'': depending on the case, the operation will be either local
% or global. This is documented in the manual, which explains this
% inconsistent behavior is preserved for backward compatibility, and
% recommends \pkg{etoolbox}'s facilities if available. \pkg{polyglossia} also
% recommends \pkg{etoolbox}'s \cs{gappto}. All in all, if there's need to use
% the traditional way instead of the new hooks, just rely on \texttt{expl3}
% and use \cs{tl_gput_right:Nn}.
%
% \begin{macro}{\@@_set_babel_language:nn}
% Sets \meta{babel language} to execute the setup defined by
% \cs{@@_define_language:nn} for \meta{postnote language} at the
% \texttt{babel/\meta{language}/beforeextras} hook.
% \begin{syntax}
% \cs{@@_set_babel_language:nn} \Arg{babel language} \Arg{postnote language}
% \end{syntax}
% \begin{macrocode}
\cs_new_protected:Npn \@@_set_babel_language:nn #1#2
{
\ActivateGenericHook { babel/#1/beforeextras }
\exp_args:Nnv \AddToHook { babel/#1/beforeextras }
{ g_@@_language_ #2 _tl }
}
% \end{macrocode}
% \end{macro}
%
%
% \pkg{polyglossia} uses a similar set of macros for setting up languages as
% \pkg{babel} does. However, the
% \texttt{\textbackslash{}blockextras@\meta{language}} macros are
% unfortunately internal (despite what the manual says, that's what the code
% does), thus requiring \cs{makeatletter}/\cs{makeatother} for user
% configuration, which would be an inconvenience. On the other hand,
% \pkg{polyglossia}'s \texttt{\textbackslash{}captions\meta{language}} works
% as in \pkg{babel}'s ``old way'', meaning it is just a ``hook'' to which we
% can append some code. So we use
% \texttt{\textbackslash{}captions\meta{language}} for \pkg{polyglossia}.
% Things may complicate here if there's need to set up different values for
% different language variants, since the hooks available are all necessarily
% internal, but I doubt we'll ever need variants for these simple strings.
%
% \begin{macro}{\@@_set_polyglossia_language:nn}
% Sets \meta{polyglossia language} to execute the setup defined by
% \cs{@@_define_language:nn} for \meta{postnote language} at the
% \pkg{polyglossia} \texttt{\textbackslash{}captions\meta{language}} hook.
% \begin{syntax}
% \cs{@@_set_polyglossia_language:nn} \Arg{polyglossia language}
% ~~\Arg{postnote language}
% \end{syntax}
% \begin{macrocode}
\cs_new_protected:Npn \@@_set_polyglossia_language:nn #1#2
{
\AddToHook { package/polyglossia/after }
{
\exp_args:Nnv \csgappto { captions #1 }
{ g_@@_language_ #2 _tl }
}
}
% \end{macrocode}
% \end{macro}
%
%
% \subsection*{English}
%
% \begin{macrocode}
\@@_define_language:nn { english }
{
\tl_set:Nn \pntitle { Notes }
\tl_set:Nn \pnhdnotes { Notes }
\tl_set:Nn \pnhdtopage { to~page }
\tl_set:Nn \pnhdtopages { to~pages }
}
\@@_set_babel_language:nn { english } { english }
\@@_set_babel_language:nn { british } { english }
\@@_set_babel_language:nn { american } { english }
\@@_set_babel_language:nn { canadian } { english }
\@@_set_babel_language:nn { australian } { english }
\@@_set_babel_language:nn { newzealand } { english }
\@@_set_babel_language:nn { UKenglish } { english }
\@@_set_babel_language:nn { USenglish } { english }
\@@_set_polyglossia_language:nn { english } { english }
% \end{macrocode}
%
%
% \subsection*{Portuguese}
%
% \begin{macrocode}
\@@_define_language:nn { portuguese }
{
\tl_set:Nn \pntitle { Notas }
\tl_set:Nn \pnhdnotes { Notas }
\tl_set:Nn \pnhdtopage { da~página }
\tl_set:Nn \pnhdtopages { das~páginas }
}
\@@_set_babel_language:nn { portuguese } { portuguese }
\@@_set_babel_language:nn { brazilian } { portuguese }
\@@_set_babel_language:nn { portuges } { portuguese }
\@@_set_babel_language:nn { brazil } { portuguese }
\@@_set_polyglossia_language:nn { portuguese } { portuguese }
% \end{macrocode}
%
%
% \subsection*{French}
%
% French localization validated by \contributor{\username{Pika78}} at
% \githubissue{1}.
%
% \pkg{babel-french} also has \file{.ldf}s for \texttt{francais},
% \texttt{frenchb}, and \texttt{canadien}, but they are deprecated as options
% and, if used, they fall back to either \texttt{french} or \texttt{acadian}.
%
% \begin{macrocode}
\@@_define_language:nn { french }
{
\tl_set:Nn \pntitle { Notes }
\tl_set:Nn \pnhdnotes { Notes }
\tl_set:Nn \pnhdtopage { de~la~page }
\tl_set:Nn \pnhdtopages { des~pages }
}
\@@_set_babel_language:nn { french } { french }
\@@_set_babel_language:nn { acadian } { french }
\@@_set_polyglossia_language:nn { french } { french }
% \end{macrocode}
%
%
% \subsection*{German}
%
% German localization provided by \contributor{Herbert Voß} at
% \githubissue{2}.
%
% \pkg{babel-german} also has \file{.ldf}s for \texttt{germanb} and
% \texttt{ngermanb}, but they are deprecated as options and, if used, they
% fall back respectively to \texttt{german} and \texttt{ngerman}.
%
% \begin{macrocode}
\@@_define_language:nn { german }
{
\tl_set:Nn \pntitle { Endnoten }
\tl_set:Nn \pnhdnotes { Endnoten }
\tl_set:Nn \pnhdtopage { zu~Seite }
\tl_set:Nn \pnhdtopages { zu~Seiten }
}
\@@_set_babel_language:nn { german } { german }
\@@_set_babel_language:nn { ngerman } { german }
\@@_set_babel_language:nn { austrian } { german }
\@@_set_babel_language:nn { naustrian } { german }
\@@_set_babel_language:nn { swissgerman } { german }
\@@_set_babel_language:nn { nswissgerman } { german }
\@@_set_polyglossia_language:nn { german } { german }
% \end{macrocode}
%
%
% \begin{macrocode}
%</package>
% \end{macrocode}
%
%
% \PrintIndex
%
%
|