summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/pseudo/doc/pseudo.tex
blob: 21e640267c73562ca854858c56494f58935b0e06 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
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
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
\documentclass[a4paper]{article}

\usepackage[inline]{enumitem}

\newlist{inl}{enumerate*}{1}
\setlist[inl]{
    label=\mbox{\rm($\roman*$)},
}

\usepackage{tabularx}

\usepackage{tabto}

\usepackage{float}
\usepackage[small]{caption}

\usepackage[citestyle=numeric-comp,
    giveninits,doi=false,url=false,
    natbib,sortcites,hyperref]{biblatex}

\renewcommand{\subtitlepunct}{\addcolon\addspace}
\renewbibmacro{in:}{}
\bibliography{pseudo}

% Avoid too much space after code:
\def\paragraph#1{\noindent\textbf{#1}\enskip}

\usepackage{lmodern}

\let\origbfseries\bfseries
\def\bfseries{\fontseries{b}\selectfont}

\let\origtt\texttt
\def\texttt#1{\textnormal{\origtt{#1}}}
% Still getting warnings about OT1/cmtt/b/n ...

\usepackage{tikz}
\usetikzlibrary{matrix,calc,decorations.pathreplacing,calligraphy}
\tikzset{
    auto/.style={fill=black!12}
}

\usepackage{old-arrows}
% Keep before hyperref
\RequirePackage[hang,perpage,symbol*,bottom,stable]{footmisc}
\renewcommand{\footnotemargin}{1em}

\usepackage[pdfusetitle, hidelinks, bookmarks=false]{hyperref}
\usepackage[xparse,
    breakable,
    hooks,
    listingsutf8, documentation]{tcolorbox}

% For box/float examples
\tcbuselibrary{theorems}

\usepackage{pseudo}

% ! Duplicate of the one inside the texexp in the HOWTO section:
\pseudodefinestyle{fullwidth}{
    begin-tabular =
    \tabularx{\linewidth}[t]{@{}
        r                                      % Labels
        >{\leavevmode\pseudosetup}             % Indent, font, ...
        X                                      % Code (flexible)
        >{\leavevmode\small\color{gray}}       % Comment styling
        p{0.5\linewidth}                       % Comments (fixed)
        @{}},
    end-tabular=\endtabularx,
}

\usepackage{url}
\usepackage{amsopn} % For \newmcodes@ example

\usepackage{mathtools} % For \coloneqq

\usepackage{amsmath}
\DeclareMathOperator{\MyFunc}{my-func}

\usepackage{varioref}
\usepackage[sort&compress,capitalize]{cleveref}

\crefname{page}{page}{pages}
\crefname{equation}{Eq.}{eqs.}
\crefname{figure}{Fig.}{figs.}
\crefname{section}{Sect.}{sects.}

\usepackage{booktabs}

% Avoid stretching formulas:
% http://tex.stackexchange.com/questions/104127/
\thinmuskip=3mu
\medmuskip=4mu
\thickmuskip=5mu

\makeatletter

% Copied from http://ctan.uib.no/macros/latex/base/doc.dtx
% Protect when used in moving arguments.
{\catcode`\|=\z@ \catcode`\\=12 |gdef|bslash{\}}

\ExplSyntaxOn

\DeclareDocumentCommand \bigpar { } {
    \bigskip
    \par
    \noindent
    \@afterindentfalse
    \@afterheading
}

\DeclareDocumentCommand \textb { m } {
    {\fontseries{b}\selectfont #1}
}

\NewDocumentCommand \pkg { o m } {

    \IfNoValueTF { #1 } {
        % The literal colon has a different meaning with expl3 syntax
        \href{ https\c_colon_str//ctan.org/pkg/#2 }{ \textsf { #2 } }
    } {
        \href{ #1 }{ \textsf { #2 } }
    }

}

\NewDocumentCommand \codefont { m } {
    \texttt{ #1 }
}

\NewDocumentCommand \code { s m } {
    \tl_set:Nn \l_tmpa_tl { #2 }
    \IfBooleanT { #1 } {
        \regex_replace_all:nnN
            { \s+ }{ \c{textnormal}\cB\{ \0 \cE\} } \l_tmpa_tl
    }
    \codefont{ \l_tmpa_tl }
}

\ExplSyntaxOff
\makeatother

\NewDocumentCommand \bootstrapped { s } {%
    This \IfBooleanT{#1}{version of the } command is only available inside the
    \refEnv*{pseudo} environment.%
}

\NewDocumentCommand \shortcutted { m m } {%
    If some package defines \cs{#1} before \pkg{pseudo} is loaded, \pkg{pseudo}
    will not overwrite it. The command will still be available, as \cs{#2}.%
}

\NewDocumentCommand \pseudoshortcutted { m } {%
    \shortcutted{#1}{pseudo#1}%

}

\NewDocumentCommand \novaluekey { } {%
    takes no value%
}

\NewDocumentCommand \initialkeyvalue { m } {%
    no default, initially #1%
}

\NewDocumentCommand \initiallyempty { } {%
    \initialkeyvalue{empty}%
}

\NewDocumentCommand \fontutil { m } {%
    This is a convenience for typesetting #1, and you may freely redefine it
    to whatever you prefer.%
}

\NewDocumentCommand \fontkey { m } {%
    Used to set \refc{#1font}, which is used as part of \refc{#1}. May be set
    to take a single argument or none. Not restricted to actual font commands;
    you may also mix in \cs{textcolor} or the like.%
}

\NewDocumentCommand \setandused{ m m }{%
    The command set by the \refk{#1} option. Used as part of \refc{#2}.%
}

\NewDocumentCommand \setandusedinit{ m m }{%
    The command set by the \refk{#1} option. Used as part of the initial value
    of \refk{#2}.%
}

\NewDocumentCommand \fontcmd { m } {%
    \setandused{#1font}{#1}%
}

\NewDocumentCommand \bracketing { m m m } {%
    Text or commands inserted at the #1 of a #2, when using
    \refc{#3}.%
}

\NewDocumentCommand \leftbracketing { m m } {%
    \bracketing{start}{#1}{#2}%
}

\NewDocumentCommand \rightbracketing { m m } {%
    \bracketing{end}{#1}{#2}%
}

\NewDocumentCommand \seealsostyle { m } {%
    See also \refc{#1}.  (Note that \cs{pseudo#1} is used internally here.)%
}

\NewExpandableDocumentCommand \tcolorboxstylepre { } {%
    \parindent1.5em
    \noindent
    A style defined for use with \pkg{tcolorbox} (i.e., not with
    \cs{pseudoset}).

    A simple, manually numbered example:
}

\NewExpandableDocumentCommand \tcolorboxstylepost { } {%
    To create a floating box, use the \pkg{tcolorbox} key \cs{float}. In
    general, it is probably better to create such boxes with \cs{newtcbtheorem}.
    For more information on using \pkg{tcolorbox} styles, see \cref{sec:floats}.

}

\NewExpandableDocumentCommand \tcolorboxstylenosource { m } {%
\begin{docKey}{pseudo/#1}{}{\pkg{tcolorbox} style}
    \parindent1.5em
    \noindent
    A style defined for use with \pkg{tcolorbox} (i.e., not with
    \cs{pseudoset}).
    A simple example:

\begin{tcolorbox}[pseudo/#1,
    title={Algorithm 1\enskip \pr{Hello}(x)}]
    \begin{pseudo}
        \kw{print} \st{Hello,} $x$
    \end{pseudo}
\end{tcolorbox}

    \noindent
    See the \refk{pseudo/boxed} reference entry and \cref{sec:floats} for more
    information.
\end{docKey}
}

\pgfqkeys {/tcb} {
    listing/.style = {
        listing only,
        before skip balanced=8pt plus 2pt minus 2pt,
        after app=\noindent
    }
}

\lstdefinestyle{tcblatex}{language={[LaTeX]TeX},
    columns=fullflexible,
    keepspaces=true,
    breaklines=true,
    breakatwhitespace=true,
    basicstyle=\ttfamily\small\color{black!80},
    extendedchars=true,
    nolol,
    inputencoding=\kvtcb@listingencoding,
    literate={\$}{\textcolor{black!65}{\$}}{1}%
    {~}{\textcolor{gray}{\raisebox{-.75ex}{\textasciitilde}}}{1},
    commentstyle=\color{gray},
}

\let\braces\brackets

\DeclareTCBListing{texexp}{ !O{} }{
    empty,
    arc=0pt,
    boxsep=0pt,
    overlay unbroken={
        \draw[black!50, xshift=0.5\pgflinewidth, semithick]
            ($(frame.north west)+(3pt,0)$) --
            +(-3pt,0) -- (frame.south west) -- +(3pt,0);
        \draw[black!50, xshift=-0.5\pgflinewidth, semithick]
            ($(frame.north east)+(-3pt,0)$) --
            +(3pt,0) -- (frame.south east) -- +(-3pt,0);
    },
    left=1.5em, % \parindent -- but that changes inside doc
    text above listing,
    before skip balanced=6pt plus 2pt minus 2pt,
    after skip balanced=8pt plus 2pt minus 2pt,
    after app=\noindent,
    % Because listings messes with the equals sign:
    before lower app={
        \RestorePseudoEq
    },
    #1
}

\def\refc{\refCom*}
\def\refe{\refEnv*}
\def\refk{\refKey*}
\hyphenation{pseudo-code}

\title{The \textsf{pseudo} Package}
\author{Magnus Lie Hetland}

\colorlet{dimmed}{black!30}

\ExplSyntaxOn

\regex_const:Nn \c_var_regex {
    % \A
    ([lg]\c{lst@um_})
    (.+)
    (\c{lst@um_}
    (cs
    |clist
    |dim
    |fp
    |int
    |muskip
    |seq
    |skip
    |str
    |tl
    |bool
    |box
    |coffin
    |flag
    |fparray
    |intarray
    |iowr
    |iow
    |prop
    |regex))
    \Z
}
\regex_const:Nn \c_cmd_regex { : [NncVvoxefTFpw]* \Z }
\regex_const:Nn \c_pre_regex { @@\c{lst@um_} }

% Cf. https://tex.stackexchange.com/questions/402135
\NewDocumentCommand \DimmedAts { } {

    \tl_set:No \l_tmpa_tl {\the\use:c{lst@token}}

    \regex_replace_all:NnN
        \c_var_regex
        { \c{textcolor}\cB{ dimmed \cE}\cB{ \1 \cE}
            \2
          \c{textcolor}\cB{ dimmed \cE}\cB{ \3 \cE}
      } \l_tmpa_tl

    \regex_replace_all:NnN
        \c_pre_regex
        { \c{textcolor}\cB{ dimmed \cE}\cB{ \0 \cE} } \l_tmpa_tl

    \regex_replace_all:NnN
        \c_cmd_regex
        { \c{textcolor}\cB{ dimmed \cE}\cB{ \0 \cE} } \l_tmpa_tl

    \tl_use:N \l_tmpa_tl
    \use_none:n

}

\NewDocumentCommand \Abstract { } {

    \begin{abstract}

    \ior_open:Nn \g_tmpa_ior {README.md}

    \tl_gclear:N \g_tmpa_tl

    \ior_map_inline:Nn \g_tmpa_ior {

        % Skip the first paragraph
        \regex_match:nnT { ##1 } { \c{par} } {
            \ior_map_break:
        }

    }

    \ior_map_inline:Nn \g_tmpa_ior {

        % Just using the next paragraph
        \regex_match:nnTF { ##1 } { \c{par} } {
            \ior_map_break:
        } {
            \tl_gput_right:Nn \g_tmpa_tl { ##1 }
        }

    }

    \regex_replace_all:nnN
        {\*\* ( \w+ ) \*\*}
        { \c{pkg} \cB{ \1 \cE} } \g_tmpa_tl

    \regex_replace_all:nnN
        {` ( \w+ ) `}
        { \c{code} \cB{ \1 \cE} } \g_tmpa_tl

    \noindent
    \tl_use:N \g_tmpa_tl

    \ior_close:N \g_tmpa_ior

    \end{abstract}

}

\ExplSyntaxOff

\makeatletter
\DeclareTCBListing{source}{ !O{} }{
    empty,
    breakable,
    listing only,
    arc=0pt,
    boxsep=0pt,
    left=\parindent,
    top=0pt,
    bottom=0pt,
    beforeafter skip balanced=\bigskipamount,
    after app=\noindent,
    #1
}
\makeatother

% Doesn't work:
% \usepackage{noindentafter}
% \NoIndentAfterEnv{source}

\newtcbtheorem[
        number within = section,
        crefname = {Algorithm}{algorithms}
    ]%
    {algorithm}{Algorithm}{pseudo/ruled}{alg}

\newtcbtheorem[
        use counter from = algorithm,
        crefname={Algorithm}{algorithms}
    ]%
    % {internalpseudobox}{Algorithm}{float}{pbx}
    {internalpseudobox}{Algorithm}{}{pbx}

\usepackage{ellipsis}

\begin{document}
\maketitle

\Abstract

\section{Introduction}

The \pkg{pseudo} package lets you typeset pseudocode in a straightforward and
not all too opinionated manner. You don't need to use separate commands for
different constructs; the indentation level is controlled in a manner similar
to in a \code{tabbing} environment:

\label{p:intro-euclid}
{
\pseudoset{kw}
\begin{texexp}
\begin{pseudo}
    while $a \neq b$                            \\+
        if $a > b$                              \\+
            $a = a - b$                         \\-
        else $b = b - a$                        \\-
    return $a$
\end{pseudo}
\end{texexp}
}%
%
If you prefer having \kw{end} at the end of blocks, or you'd rather wrap them
in C-style braces, you just put those in. Fonts, numbering, indentation
levels, etc., may be configured. You import \pkg{pseudo} with:
\begin{center}
\code{\cs{usepackage}[\meta{options}]\braces{pseudo}}
\end{center}
The only option usable here at the moment is \refk{kw} (used in the example
above), as the \cs{usepackage} command is a bit too eager in expanding its
arguments, but there are several options that may be provided to the
\refc{pseudoset} command, to configure things (see \cref{sec:cmdandkeyref}).
For a more complete example, see \cref{alg:euclid}.

{
\pseudoset{kw}
\TabPositions{1.5cm}
% Duplicated in example, below, without [float]:
\begin{algorithm}[float]{Euclid's algorithm, \pr{Euclid}(a, b)}{euclid}

\textbf{Input:}  \tab Two positive integers, $a$ and $b$.

\textbf{Output:} \tab The greatest common divisor of $a$ and $b$.

\begin{pseudo}[label=\small\arabic*, indent-mark, fullwidth]

    while $a \neq b$      &  If equal, both are gcd           \\+
        if $a > b$        &  Reduce max with multiple of min  \\+
            $a = a - b$   &  $a$ is largest                   \\-
        else $b = b - a$  &  $b$ is largest                   \\-
    return $a$            &  Both are gcd, so return one
%
\end{pseudo}

The running time is quadratic in the number of bits in the input.

\end{algorithm}
}

\subsection*{Microtutorial: How to produce \cref{alg:euclid}}

The pseudocode in \cref{alg:euclid} is typeset in the same way as on
\vpageref{p:intro-euclid}. The line numbers are styled using the \refk{label}
key, the vertical lines are produced by the \refk{indent-mark} option, and the
comments are just a separate column of a \code{tabularx}, which is used instead
of the built-in \code{tabular}, as explained in
\cref{sec:tabularx}.\footnote{That is, the \code{fullwidth} style that is
defined \vpageref{p:fullwidth} is used in this example.} To get the surrounding
ruled box, a \pkg{tcolorbox} is used, with the style \refk{pseudo/ruled}. This
has been set up with a predefined box environment, \code{algorithm}, which is
defined in \cref{sec:floats} (\vpageref{p:pseudo-ruled-def}). The \refc{pr}
command and its relatives (as well as most other functionality) are discussed in
\cref{sec:overview}, with individual definitions given in
\cref{sec:reference}.\footnote{The actual implementations, with explanations,
are found in \cref{sec:impl}.} The input and output descriptions are aligned
using \cs{tab} from the \pkg{tabto} package (cf.\@ \cref{sec:tabstops}).

\begin{texexp}[listing]
% In document preamble:
% \usepackage{tabto}
% \TabPositions{1.5cm}

\begin{algorithm}{Euclid's algorithm, \pr{Euclid}(a, b)}{euclid}

\textbf{Input:}  \tab Two positive integers, $a$ and $b$.

\textbf{Output:} \tab The greatest common divisor of $a$ and $b$.

\begin{pseudo}[label=\small\arabic*, indent-mark, fullwidth]
    while $a \neq b$      &  If equal, both are gcd           \\+
        if $a > b$        &  Reduce max with multiple of min  \\+
            $a = a - b$   &  $a$ is largest                   \\-
        else $b = b - a$  &  $b$ is largest                   \\-
    return $a$            &  Both are gcd, so return one
\end{pseudo}

The running time is quadratic in the number of bits in the input.

\end{algorithm}
\end{texexp}

\subsection*{Alternatives}

There are many ways of typesetting code and pseudocode in \LaTeX, so if you're
unhappy with \pkg{pseudo}, you have several alternatives to choose from. I
wrote \pkg{pseudo} based on my needs and preferences, but yours may differ, of
course. For example, I've built on tabular layouts to get
\begin{inl}
\item automatic width calculations;
\item line/row highlighting; and
\item easy embedding in \pkg[https://ctan.org/pkg/pgf]{tikz} nodes and the
like.
\end{inl}
I have also set things up inspired by existing mechanisms for numbering and
indenting lines, and treat the pseudocode as a form of text, rather than as a
form of markup in itself. The latter point means that I don't have separate
commands for conditionals, loops, etc.

The basic style of pseudocode is inspired by the standard reference
\emph{Introduction to Algorithms} by \citet{Cormen:2009} (i.e., similar to
that of \pkg{newalg},
\pkg[https://ctan.org/tex-archive/macros/latex/contrib/clrscode]{clrscode} and
\pkg{clrscode3e}).
%
Rather than locking down all aspects of pseudocode appearance, however, I've
tried to make \pkg{pseudo} highly configurable, but if it's not flexible
enough, or just not to your liking, you might want to have a look at the
following packages:

\begin{quote}
    \raggedright
    \pkg[https://ctan.org/tex-archive/macros/latex/contrib/alg]{alg},
    \pkg{algobox},
    \pkg{algorithm2e},
    \pkg{algorithmicx},
    \pkg{algorithms},
    \pkg{algpseudocodex},
    \pkg{algxpar},
    \pkg[https://ctan.org/tex-archive/macros/latex/contrib/clrscode]{clrscode},
    \pkg{clrscode3e},
    \pkg[https://www.cs.dartmouth.edu/~thc/]{clrscode4e},
    \pkg[https://github.com/esneider/latex-pseudocode]{latex-pseudocode},
    \pkg{newalg},
    \pkg[https://ctan.org/tex-archive/macros/latex/contrib/program]{program},
    \pkg[https://ctan.org/tex-archive/macros/latex/contrib/pseudocode]{pseudocode}
\end{quote}

\noindent
There are also code-typesetting packages like
\pkg[https://ctan.org/tex-archive/macros/latex/contrib/listings]{listings} and
\pkg{minted}, of course.

\subsection*{Using older \TeX\ distributions}

The imlementation of \pkg{pseudo} uses some functionality that isn't available
in older \TeX\ distributions, in particular, older versions of \pkg{xparse} and
\pkg{expl3}. Some care has been taken to make the code backward compatible to
the point where it works on \TeX\ Live~2020, which is what is used (at the time
of writing) on \href{https://arxiv.org}{arXiv}. If you run into issues somewhere
else (e.g., when submitting to some publisher with a custom setup), feel free to
\href{https://github.com/mlhetland/pseudo.sty/issues}{file an issue}, or even
\href{https://github.com/mlhetland/pseudo.sty/pulls}{provide a pull request}
with a fix. One thing to look out for is that older versions of \pkg{xparse}
parse arguments differently, so things like
\begin{texexp}[listing]
foo\\<1>
bar\\[hl]
\end{texexp}
would work, but separating the arguments with spaces, as in
\begin{texexp}[listing]
foo\\ <1>
bar\\ [hl]
\end{texexp}
will \emph{not} work, though this works with more recent versions (as seen
from some of my examples, later). For more advice on working around an older
distribution, see also \cref{sec:older}.

\section{Overview}
\label{sec:overview}

The main component of the \pkg{pseudo} package is the \refe{pseudo}
environment, which is, in a sense, a hybrid of \code{enumerate},
\code{tabular} and \code{tabbing}, in that it provides numbered lines, each
placed in a tabular row (for ease of highlighting and automatic column width
calculation), with functionality for increasing and decreasing indentation
similar to the \code{tabbing} commands \cs{+} and \cs{-} (in \pkg{pseudo},
combined with the row separator \refc{\bslash}). Here, once again, is
Euclid's algorithm for finding the gcd of $a$ and $b$:

\begin{texexp}
\begin{pseudo}
repeat the following while $a\neq b$            \\+
    if $a > b$, let $a = a - b$                 \\
    otherwise, let $b = b - a$
\end{pseudo}
\end{texexp}

\noindent
Spacing is handled similarly to in \LaTeX\ lists, with \cs{topsep} and
\cs{parskip} added before and after, as well as \cs{partopsep} whenever the
environment starts a new paragraph. The left margin (how much the pseudocode
is indented wrt.\ the surrounding text) is set by the \refk{left-margin} key
(initially \code{0pt}).\footnote{If \refe{pseudo} occurs in a box such as
\code{fbox}, or a \pkg[https://ctan.org/pkg/pgf]{tikz} node, this spacing is
dropped. See also the \refk{compact} key for overriding this behavior.}

\medskip\noindent
There are also some styling commands for special elements of the pseudocode:

\begin{texexp}
\kw{while},          % or \pseudokw    -- keywords
\cn{false},          % or \pseudocn    -- constants
\id{rank},           % or \pseudoid    -- identifiers
\st{Hello!},         % or \pseudost    -- strings
\pr{Euclid}(a, b),   % or \pseudopr    -- procedures
\fn{length}(A),      % or \pseudofn    -- functions
\ct{Important!}      % or \pseudoct    -- comments
\end{texexp}
%
The longer names (\cs{pseudokw}, \cs{pseudocn}, etc.)\@ are always available;
the more convenient short forms (\refc{kw}, \refc{cn}, etc.)\@ are prone to
name collisions, and are only defined if the names are not already in use when
\pkg{pseudo} is imported.

The \refk{indent-length} option, which determines the length of each
indentation step, is initially set via the secondary \refk{indent-text} key,
so that the any code after \code{\cs{kw}\braces{else}} aligns with the
indented text (a stylistic choice from \pkg{clrscode3e}):
\begin{texexp}
\begin{pseudo}
\kw{if} $x < y$                                 \\+
    $x = x + 1$                                 \\-
\kw{else} $x = x - 1$
\end{pseudo}
\end{texexp}
%
\label{p:indent-mark}%
The indentation may also be configured with \refk{indent-mark}, which inserts a
mark at every indenation step:
\begin{texexp}
\begin{pseudo}[indent-mark]
    while $x\leq n$                             \\+
        $x = x + 1$                             \\
        if $f(x) < y$                           \\+
            $x = x + 1$                         \\-
        print $x$                               \\-
    return $x$
\end{pseudo}
\end{texexp}
The default is a vertical line, but anything else may be supplied as an
argument. To avoid adding to the indentation, you can wrap this argument in
\cs{rlap}.\footnote{If your mark is very tall, and you don't wish it to increase
the line height, you could also wrap it in \cs{smash}.} The color may be
modified using \refk{indent-mark-color}:
\begin{texexp}
\begin{pseudo}[
    indent-mark=\rlap{$\triangleright$}, indent-mark-color=teal]
    while $x\leq n$                             \\+
        $x = x + 1$                             \\
        if $f(x) < y$                           \\+
            $x = x + 1$                         \\-
        print $x$                               \\-
    return $x$
\end{pseudo}
\end{texexp}
%
The default indent mark scales with the line height, which can be adjusted with
\refk{line-height} and \refk{extra-space}, to avoid gaps in the vertical lines,
and its width has no impact on the indentation. The width of the (default) mark
can be set with \refk{indent-mark-width}:\footnote{You can also shift the
default mark inward by setting \refk{indent-mark-shift}.}
\begin{texexp}
\begin{pseudo}[
    indent-mark, indent-mark-width=3pt, line-height=1.5]
    the                                         \\+
        lines                                   \\+[3ex]
            are                                 \\-
        scaled
\end{pseudo}
\end{texexp}
%
Note here how some extra space is specified using the optional argument
\code{3ex} with \refc{\bslash}. This is equivalent to explicitly setting the
key \refk{extra-space} (i.e., in this case,
\code{\cs{\bslash}+[extra-space=2ex]}).

If you want, you can certainly create shortcuts, e.g., with simple macro
definitions like \verb|\def\While{\kw{while}}|, or with declaration commands such
as \refc{DeclarePseudoKeyword} or \refc{DeclarePseudoConstant}. Procedures and
functions capture parenthesized arguments and set them in math mode; this
carries over in shortcuts, so if you define \verb|\Euclid| to mean
\verb|\pr{Euclid}|, then \code*{\cs{Euclid}(a, b)} yields
\pr{Euclid}(a,b).\footnote{Note that \code*{\cs{Euclid} (a, b)}, with a space
before the parenthetical, yields \pr{Euclid} (a, b).}

These commands are not used in the internals of the package, so they may be
freely redefined for different styling, such as \verb|\let\id\textsf|. They
generally do some extra work, though, such as wrapping the styled text in
\cs{textnormal} to avoid having the styles blend, adding quotes (\cs{st}) and
handling parenthesized arguments (\cs{pr}). To let you hook into their
appearance without messing with their definitions, each command has a
corresponding font command (\cs{kwfont}, \cs{cnfont}, \cs{idfont}, etc.),
which you may redefine. These fonts may even be set using correspondingly
named options, either with \refc{pseudoset} or via optional keyword arguments
to the \refe{pseudo} environment:\footnote{Because of \LaTeX\ expansion
behavior, they can \emph{not} be set globally when importing \pkg{pseudo}.}
\begin{texexp}
\pseudoset{prfont=\textsf}
Euclid's algorithm is initiated with the call \pr{Euclid}(a, b).
\end{texexp}
\noindent
You can also configure the quotes and comment markers:
\begin{texexp}
\pseudoset{
    st-left=`, st-right=', stfont=\textit,
    ct-left=\texttt{/\!/}\,, ct-right=, ctfont=
}
\begin{pseudo}
\kw{print} \st{Hello, world!} \quad \ct{Greeting}
\end{pseudo}
\end{texexp}
%
Note that \cs{stfont} and friends may either be font-switching commands like
\cs{itshape} or formatting commands like \cs{textit}, though the latter are
generally preferable when available. They need not be restricted to actual
fonts, but may include color commands, for example.

You can also set the font for the entire code lines, using the \refk{font}
option. The command you provide there should just switch the font (i.e., not
take an argument to typeset); initially, \cs{kwfont} is such a command:

\begin{texexp}
\begin{pseudo}[font=\kwfont]
while $a \neq b$                                \\+
    if $a > b$                                  \\+
        $a = a - b$                             \\-
    else $b = b - a$
\end{pseudo}
\end{texexp}

\noindent
Though not the default, this is in fact an intended configuration, to reduce
the markup noise for pseudocode that consists primarily of keywords and
mathematics. The setting \code*{\refk{font} = \refc{kwfont}} is also available
by using the \refk{kw} option (with no arguments), e.g., by importing the
package with \verb|\usepackage[kw]{pseudo}|. If you need to typeset normal
text in your pseudocode after using \refk{font}, you can use \cs{textnormal}
or \cs{normalfont}, for which \pkg{pseudo} defines aliases \refc{tn} and
\refc{nf}:

\begin{texexp}
\begin{pseudo}[kw]
for \tn{each node} $v\in V$                     \\+
    \tn{do something}                           \\-
for \nf each edge $e \in E$                     \\+
    \nf do something else
\end{pseudo}
\end{texexp}

\noindent
The row separator may have multiple pluses or (more commonly) multiple minuses
appended, indicating multiple increments or decrements to the indentation
level:

\begin{texexp}
\begin{pseudo}[kw]
for $k = 1$ to $n$                              \\+
for $i = 1$ to $n$                              \\+
for $j = 1$ to $n$                              \\+
$t_{ij} = t_{ij} \lor (t_{ik} \land t_{kj})$    \\---
return $t$
\end{pseudo}
\end{texexp}
%
The code is normally typeset in a two-column \code{tabular} (whose preamble,
and thus number of columns, is configurable via the option \refk{preamble}),
but the first column is handled by an automatic \refk{prefix} inserted before
each line, containing the numbering and column separator (\code{\&}). You
disable the prefix for the following line by using \code{\refc{\bslash}*}:

\begin{texexp}
\begin{pseudo}
  this line has an automatic prefix             \\+*
& this line does not                            \\+
  but this one does
\end{pseudo}
\end{texexp}

\noindent
This star also works after \code{\cs{begin}\braces{pseudo}}. Note that in
order to prevent your code from ending up in the numbering column, you must
insert a column separator manually. A version of the \refc{pr} command, called
\refc{hd} (or \cs{pseudohd}, where \refc{hd} stands for \emph{header}) instead
wraps a procedure call in a \code{multicolumn}, so it can be used, for
example, as an unnumbered header line:\footnote{See also \refk{hd-space}, if you
want some extra space after the header.}

\begin{texexp}
\begin{pseudo}[kw]*
\hd{Euclid}(a, b)                               \\
if $b \== 0$                                    \\+
    return $a$                                  \\-
    else return \pr{Euclid}(b, a \bmod b)
\end{pseudo}
\end{texexp}

\noindent
As can be seen in this example, \cs{==} (or \refc{eqs}) is a notational
convenience defined by \pkg{pseudo}, along with interval dots \cs{..}\@ (or
\refc{dts}) and the alternative range operator \refc{rng}:
\begin{texexp}
Do you prefer $A[1 \.. n]$ or $A[1 \rng n]$?
\end{texexp}

\noindent
Other special symbols may be found in other packages. For example, if you want
to use $\coloneqq$ for assignment, you can use \cs{coloneqq} from
\pkg{mathtools} (perhaps with \verb|\let\gets\coloneqq|).\footnote{Tip: If you
want to use a left-arrow for assignment, but think it's a bit large in Computer
Modern or Latin Modern, you can use the
\pkg[https://ctan.org/tex-archive/fonts/old-arrows]{old-arrows} package,
so \code*{x \cs{gets} y} yields $x\gets y$.}

As can be seen, one use of \code{\refc{\bslash}*} is to get an unnumbered
line, but you could also insert custom material in the first column.
%
The lines are numbered by the counter \code{pseudoline}, so you could, for
example, do:

\begin{texexp}
\begin{pseudo}*
\stepcounter{pseudoline}\Alph{pseudoline} & Look! \\*
\stepcounter{pseudoline}\Alph{pseudoline} & We're using letters!
\end{pseudo}
\end{texexp}

\noindent
This is a bit cumbersome, so there are some shortcuts. First of all, rather
than replacing the entire \refk{prefix}, you can replace only a \emph{part} of
it, namely the \refk{label}, retaining counter increments and column
separators. You can set this key for each line individually with an optional
argument to the row separator, i.e.,
\code*{\refc{\bslash}[\refk{label} = \meta{commands}]}, or at some higher
level. Within the \refe{pseudo} environment, there is also a counter named
\code{*} that is simply a local clone of \code{pseudoline}, letting you use
starred versions of counter commands, similarly to how label definitions work
in \pkg{enumitem}:\footnote{Also like in \pkg{enumitem}, there's a \refk{start}
key for setting the first line number.}

\begin{texexp}
\pseudoset{label=\small\arabic*:}
\begin{pseudo}
Look! \\
We're using something custom! \label{custom-line}
\end{pseudo}
\end{texexp}

\noindent
Note that if I refer to the labeled line with \cs{ref}, I'll just end up with
\ref{custom-line}, which is probably what I'd want in this case. If you want a
custom reference format as well, you can set that with the \refk{ref} key, in
the same way as with \refk{label}. If you use the key without arguments, it'll
use the same format as the one provided to \refk{label}:

\begin{texexp}
\pseudoset{label=(\textit{\roman*}), label-align=l, ref}
\begin{pseudo}
Look! \\
We're using Roman numerals! \label{roman-line} \\
And here's a reference to line \ref{roman-line}.
\end{pseudo}
\end{texexp}
%
The \refk{label-align} key sets the alignment of the label column, and can be
\code{l}, \code{r} or \code{c} (or really any other column type compatible
with the \pkg{array} package; you could use a \code{p\braces{\dots}} column to
get fixed width, for example).

Highlighting can also be done in a similar manner, by, e.g., inserting a
\cs{rowcolor} at the start of the first column. Rather than doing this
manually, you could use the \refk{bol} key, which inserts a command at the
beginning of the line---or the \refk{hl} key, which is equivalent to
\code*{\refk{bol-prepend} = \refc{pseudohl}}:

{
\pseudoset{hl-warn=false}%
\begin{texexp}
\begin{pseudo*}
I'm not highlighted \\[hl]
But I am!
\end{pseudo*}
\end{texexp}
}
%
Initially, the \refc{pseudohl} command that is inserted is simply a
\cs{rowcolor} that uses \refk{hl-color}, but you're free to redefine this
command to whatever you'd like.

In the previous example, there is no spacing to the sides of the table
contents. This is normally what you'd want, for example, to keep the
pseudocode aligned with the surrounding text. However, when using row
highlighting (e.g., because you are stepping through the code in some
presentation), that alignment may be less of an issue---and you'd rather widen
the highlight a bit. The horizontal padding on each side is controlled by the
\refk{hpad} key.\footnote{In fact, if you use \refk{hl} without \refk{hpad},
you'll get a warning. You can turn this warning off using \refk{hl-warn}, or by,
e.g., setting \refk{hpad} to \code{0pt}.} You can either specify a length, or
just turn on the default, by not supplying an argument. There's a similar
option, \refk{hsep}, which controls the separation between the two columns.

\begin{texexp}
\begin{pseudo}[hpad, hsep=1em, indent-length=1em]
    let's                                       \\+
        use                                     \\-
    some                                        \\+ [hl]
        padding!
\end{pseudo}
\end{texexp}

\noindent\label{p:overlays}%
For ease of use with \pkg{beamer}, the various \pkg{pseudo} options support
\pkg{beamer} overlay specifications. For example, using \code{\refk{hl}<1>}
means that the \refk{hl} specification would only take effect on slide~1. If you
use such an overlay specification on a key when \emph{not} using beamer, the key
is simply ignored.

What is more, the row separator \emph{itself} takes an overlay specification
as a shortcut for the one on \refk{hl}, so \code{\refc{\bslash}<1,2-4>} is
equivalent to \code{\refc{\bslash}[\refk{hl}<1,2-4>]}. Just like with the
optional arguments, space before the overlay specification is ignored, so
you're free to put the specification in front of the line in question:

\medskip

\noindent
\includegraphics[page=1]{hilitefig.pdf}\hfill
\includegraphics[page=2]{hilitefig.pdf}\hfill
\includegraphics[page=3]{hilitefig.pdf}\hfill
\includegraphics[page=4]{hilitefig.pdf}

\vspace{-4pt}

% ! Copied from Beamer file
\begin{texexp}[listing only]
% In a beamer presentation
\begin{pseudo}
    <1>  Go to line 3                           \\
    <3>  Go to line 4                           \\
    <2>  Go to line 2                           \\
    <4>  Go to line 1                           \\
\end{pseudo}
\end{texexp}
%
You might have expected these overlay specifications to indicate
\emph{visibility}, as they do for the \cs{item} command in \cs{enumerate}, for
example. However, in stepwise animations, highlighting patterns (showing which
line is currently executed, for example) tend to be more complex than, say, a
gradual uncovering---and therefore in greater need of abbreviation.

\label{p:pause}%
To control visibility, you could, for example, add \cs{pause} at the end of
each line, before the row separator. You can also do this using the \refk{eol}
key, either per line or at the top level, with \code*{\refk{eol} =
\cs{pause}}. There is even the shortcut key \refk{pause} for this specific
purpose (equivalent to \code*{\refk{eol-append} = \cs{pause}}):

\medskip

\noindent
\includegraphics[page=1]{pausefig.pdf}\hfill
\includegraphics[page=2]{pausefig.pdf}\hfill
\includegraphics[page=3]{pausefig.pdf}\hfill
\includegraphics[page=4]{pausefig.pdf}

\vspace{-4pt}

% ! Copied from Beamer file
\begin{texexp}[listing only]
% In a beamer presentation
\setbeamercovered{transparent}
\begin{pseudo}[pause]
    Eeny                                        \\
    Meeny                                       \\
    Miny                                        \\
    Moe                                         \\
\end{pseudo}
\end{texexp}
%
The \refk{eol} value is only inserted wherever \refc{\bslash} starts a new
line (i.e., not at the end of the environment), so in this case only three
\cs{pause} commands are inserted.

The previously discussed configuration keys are described in more detail in
\cref{sec:reference}. You can create your own presets or \emph{styles} using
\refc{pseudodefinestyle}. This command takes two arguments; the first is the
name of a key, and the second is a key--value list, as you would have supplied
it to \refc{pseudoset}. This is exactly how the \refk{starred} style is
defined (see~\cpageref{p:starred}), clearing the prefix and reducing the
preamble to a single column. This style is what's used in the starred,
unnumbered version of the \refe{pseudo} environment:
{
\pseudoset{kw}
\begin{texexp}
\begin{pseudo*}
    while $a \neq b$                            \\+
        if $a > b$                              \\+
            $a = a - b$                         \\-
        else $b = b - a$                        \\-
    return $a$
\end{pseudo*}
\end{texexp}
}

\section{Boxes and floats}
\label{sec:floats}

There are (at least) two different ways of viewing a block of pseudocode: as
an inline element, like equations, or as a float, like figures and tables. For
example, \citet{Cormen:2009} place their pseudocode inline, and refer to the
algorithms by name (e.g., ``\pr{Dijkstra}''), while \citet{Williamson:2011} place
them in floats, and refer to them by number (e.g., ``Algorithm~3.1'').%
\footnote{A third option that is sometimes used is to use a theorem-like
environment for your algorithms. There are many packages to help with this;
just search \href{https://ctan.org}{\textsc{ctan}} for
``\href{https://ctan.org/search/?phrase=theorem}{theorem}''.}

Just using the \refe{pseudo} environment is sufficient for typesetting
pseudocode as part of the body text. If you wish to place your pseudocode in a
float, you can easily use a package such as
\pkg[https://ctan.org/tex-archive/macros/latex/contrib/float]{float}.\footnote{Or
you could do a quick \href{https://ctan.org}{\textsc{ctan}} search for
``\href{https://ctan.org/search/?phrase=float}{float}'', or a look at the
\href{https://ctan.org/recommendations/float}{recommendations} related to
the \pkg[https://ctan.org/tex-archive/macros/latex/contrib/float]{float}
package, will give you many options, with varying functionality.} You could also
use the float environments supplied with packages such as \pkg{algorithms},
\pkg{algorithmicx} and \pkg{algorithm2e}.\footnote{The definition of \refc{==}
doesn't properly carry over into floats. It's properly redefined inside
\refe{pseudo}, so you probably won't notice, but if you wish to use the symbol
outside the \refe{pseudo} environment, but in a float (e.g., inside
\cs{caption}), you'll need to either call \refc{RestorePseudoEq} to
re-establish \pkg{pseudo}'s redefinition of \cs{=} or simply use \refc{eqs}
instead of \refc{==}.}

The \pkg{pseudo} package does provide some specialized setup,
however, using \pkg{tcolorbox}. This also lets you typeset non-float pseudocode
with a colored background, for example, like \citeauthor{Cormen:2022} do in the
most recent version of their textbook~\citep{Cormen:2022}.

\medskip\noindent
\textb{Note:} For performance reasons, \pkg{pseudo} does \emph{not}
automatically import \pkg{tcolorbox}; if you want to use the float
functionality, you will need to import \pkg{tcolorbox} yourself:
\begin{texexp}[listing]
\usepackage{pseudo}
% ...
\usepackage{tcolorbox}          % possibly with options
\tcbuselibrary{skins,theorems}  % remember these
\end{texexp}
It does not matter whether you import
\pkg{tcolorbox} before or after \pkg{pseudo}, but make sure you also import the
two libraries \code{skins} and \code{theorems}, as in the example above.

The styles defined by \pkg{pseudo} are versions of the commonly used
\emph{boxed} and \emph{ruled} styles, as found in, e.g.,
\pkg[https://ctan.org/tex-archive/macros/latex/contrib/float]{float}, as well as
the \emph{boxruled} and \emph{tworuled} styles found in \pkg{algorithm2e}. In
addition, there's a \emph{filled} style, with a colored background. If you wish
to customize and extend the box style, \refk{pseudo/boxruled} is probably the
best starting point, as the other styles disable the default frame drawing.

The ruled style is one of the more common ones in  use in publications. This is
a style originally used for (non-floating) tables in \emph{Concrete
Mathematics}~\citep{Graham:1994}. Rather than reproducing the look of those
tables directly, \pkg{pseudo} aims to match the style of \pkg{booktabs}, with
spacing and line thicknesses taken from its constants such as \cs{aboverulesep},
\cs{heavyrulewidth}, etc.\@ (with defaults provided if \pkg{booktabs} has not
been imported).\footnote{In \pkg{booktabs}, the contents between the top rules
make up the header row, whereas in the \emph{Concrete Mathematics} style, it's
the caption.} The \refk{pseudo/booktabs} style uses the same pattern of thin and
thick lines as \pkg{booktabs} tables, while \refk{pseudo/ruled} uses a thin line
at the bottom, as in the \emph{Concrete Mathematics} style.

The \pkg{pseudo} box styles can be used used directly to style \code{tcolorbox}
environments, possiby with additional \pkg{tcolorbox} options for customization:
{
% \pseudoset{kw}
\label{ex:clrscode4ish}
\begin{texexp}
% In document preamble:
% \usepackage[cmyk]{xcolor}
% Partial clrscode4e.sty emulation:
\definecolor{lighttan}{cmyk}{0,0.05,0.17,0}
\pseudoset{label=\small\arabic*, hd-space}

\begin{tcolorbox}[pseudo/filled, colback=lighttan]
    \begin{pseudo}*
        \hd{Bor\r{u}vka}(V, E, w, T)            \\
        \kw{while} $E$ is not empty             \\+
            \kw{for} each $u\in V$              \\+
                add light $uv \in E$ to $T$     \\-
            \kw{for} each $e \in T$             \\+
                contract $e$
    \end{pseudo}
\end{tcolorbox}
\end{texexp}
}%
Beyond the boxes themselves, you can customize the pseudocode inside them
(separately from pseudocode elsewhere) by defining the \refk{in-float} style
with \refc{pseudodefinestyle}.

You can also create new environments with \cs{newtcolorbox},\footnote{See the
\pkg{tcolorbox} for details and alternatives.} but the most common use-case will
probably be to define a (possibly floating) theorem-style environment, using
\cs{newtcbtheorem} (probably in the preamble):

\label{p:pseudo-ruled-def}
\begin{texexp}[listing]
\newtcbtheorem{algorithm}{Algorithm}{pseudo/ruled}{alg}
\end{texexp}

\noindent
Here \code{algorithm} is the name we've chosen for our new environment,
\code{Algorithm} is the label to be used when numbering (i.e., ``Algorithm~1,''
etc.), \refk{pseudo/ruled} is the ruled box style, and \code{alg} is is a prefix
that will be used in automatically labeling our boxes.

If you want a \emph{floating} box (like figures and tables, for example), simply
add the key \code{float} alongside the box style, such as:
\begin{texexp}[listing]
\newtcbtheorem{algorithm}{Algorithm}{pseudo/ruled, float}{alg}
\end{texexp}
%
Other \pkg{tcolorbox} styling options may be inserted in the same place. One can
also supply some \emph{init options} as a first argument, for configuring the
automatic numbering. For example, if we want our algorithms to be numbered
within sections, and we wish to provide \pkg{cleveref} with the appropriate
names, we could define the environment like this:\footnote{If you use the
\code{crefname} option, you should make sure to place your \cs{newtcbtheorem}
command in the preamble, and not in the document body, for the naming to take
effect.}
%
% Actual definition in preamble (so crefname works)
\begin{texexp}[listing]
\newtcbtheorem[
        number within = section,
        crefname = {Algorithm}{algorithms}
    ]%
    {algorithm}{Algorithm}{pseudo/ruled, float}{alg}
\end{texexp}
%
Once our environment has been defined with \cs{newtcbtheorem}, it can be used as
follows (here with floating turned off locally):

% Disappears when it's in a texexp, because the tcolorboxes check if they're
% first inside another box:
\vspace{0.5\baselineskip plus 2pt}
{
\pseudoset{kw}
\begin{texexp}
\begin{algorithm}{Sort an array $A$ of $n$ elements.}{gnome}
\begin{pseudo}
    $i = 1$                                     \\
    while $i < n$                               \\+
        if \nf $i\== 1$ or $A[i-1] \leq A[i]$   \\+
            $i = i + 1$                         \\-
        else \nf swap $A[i-1]$ and $A[i]$       \\+
            $i = i - 1$
\end{pseudo}
\end{algorithm}
\end{texexp}
}

The first argument is the title, or ``caption,'' and the second argument
(\code{gnome}) is the \emph{marker}, which is combined with the prefix (in our
case, \code{alg}) to create the label, \code{alg:gnome}, which can be used with
\cs{ref} or (using \pkg{cleveref}) \cs{cref}, etc.:\footnote{The separator
(\code{:}) can be configured; see the \pkg{tcolorbox} docs.}

\begin{texexp}
\Cref{alg:gnome} is the well-known \emph{gnome sort}, by
Sarbazi-Azad and Grune.
\end{texexp}

% The internalpseudobox environment is defined in the preamble, so crefname
% works.
\noindent
\Cref{pbx:booktabs,pbx:boxed,pbx:boxruled,pbx:tworuled,pbx:filled} are typeset
with the remaining box styles.

\NewDocumentCommand \boxstylesample { m } {
\begin{internalpseudobox}[pseudo/#1]{\refk{pseudo/#1}}{#1}
\begin{pseudo}[kw]
    $i = 1$ \\
    while $i < n$\\+
        if \nf $i\== 1$ or $A[i-1] \leq A[i]$ \\+
            $i = i + 1$ \\-
        else \nf swap $A[i-1]$ and $A[i]$ \\+
            $i = i - 1$
\end{pseudo}
\end{internalpseudobox}
}

\boxstylesample{booktabs}
\boxstylesample{boxed}
\boxstylesample{boxruled}
\boxstylesample{tworuled}
\boxstylesample{filled}

Unnumbered boxes may be constructed with \cs{newtcolorbox}, using the same
styles. These boxes, by default, have no title part---only the main
body, containing the pseudocode itself:

{
\pseudoset{kw}
\begin{texexp}
\newtcolorbox{pseudobox}{pseudo/filled}

\begin{pseudobox}
\begin{pseudo}*
    \hd{Sum}(a, b)                              \\
    if $b \== 0$                                \\+
        return $a$                              \\-
    return $\pr{Sum}(a, b - 1) + 1$
\end{pseudo}
\end{pseudobox}
\end{texexp}
}

It is possible to add titles using the \code{title} key, but then the definition
must be expanded slightly, to permit arguments, e.g.:

\begin{texexp}[listing]
\newtcolorbox{pseudobox}[1][]{pseudo/filled, #1}
\end{texexp}
\newtcolorbox{pseudobox}[1][]{pseudo/filled, #1}% For later use
%
Here we've added a single argument (\code{[1]}), with an empty default
(\code{[]}), and this is spliced into the box options at the end. Now we
may con\-figure each box individually, as we please:

{
\pseudoset{kw}
\begin{texexp}
\begin{pseudobox}[title={\pr{Sum}(a, b)}]
\begin{pseudo}
    if $b \== 0$                                \\+
        return $a$                              \\-
    return $\pr{Sum}(a, b - 1) + 1$
\end{pseudo}
\end{pseudobox}
\end{texexp}
}%
%
Colors (e.g., \code{colback}, \code{colbacktitle} or \code{colframe}), fonts
(e.g., \code{fonttitle}), line thicknesses (\code{boxrule} or \code{titlerule}),
puncutation (\code{separator sign} and \code{terminator sign}) etc., may also be
configured, either for all the boxes of this type (directly in the call to
\cs{newtcolorbox}) or for any individual box, as with the \code{title} key in
the previous example. The style that is closest to a plain, default
\code{tcolorbox} is \refk{pseudo/boxruled}, which may be a good starting-point
for this kind of configuration. However, if you just wish to add some minor
tweaks to one of the existing \code{pseudo} styles (e.g., changing the colors of
\refk{pseudo/filled}), starting with that style may be easier. (For some hints
on configuring the boxes, see \cref{sec:boxconfig}.)

The contents of one of these boxes need not be restricted to pseudocode---the
spacing is set up to handle plain text as well. For example, you may want to
specify inputs and outputs.\footnote{Common alternatives to ``Input/Output'' are
``Require/Ensure'' and ``Data/Result.''} (If you want to align such
specification, as in \cref{alg:euclid} \vpageref{alg:euclid}, you can use the
\pkg{tabto} package; see \cref{sec:tabstops}.)

\vspace{0.5\baselineskip plus 2pt}
{
\pseudoset{kw}
\begin{texexp}
\begin{algorithm}{Gnome sort}{} % environment defined earlier

\textbf{Input:} An array $A$ of length $n$.

\textbf{Output:} $A$, sorted in nondescending order.

\begin{pseudo}
    $i = 1$                                     \\
    while $i < n$                               \\+
        if \nf $i \== 1$ or $A[i-1] \leq A[i]$  \\+
            $i = i + 1$                         \\-
        else \nf swap $A[i-1]$ and $A[i]$       \\+
            $i = i - 1$
\end{pseudo}

The running time of the algorithm is quadratic.

\end{algorithm}
\end{texexp}
}


\section{Reference}
\label{sec:reference}

This section gives an overview of all the moving parts of the package. A
\emph{default} value is one used implicitly if the key is specified with no
explicit value given, while an \emph{initial} value is one provided to the key
at the point where \pkg{pseudo} is imported. Several commands (such as, e.g.,
\refc{pseudoprefix}) may be modified using corresponding keys (e.g.,
\refk{prefix}). When the behavior of such commands is described, the description
references their initial behavior.

\subsection{Line structure}
\label{sec:linestructure}

Each line of a \refe{pseudo} environment is (initially) structured as follows:

\smallskip
\begin{center}
\begin{tikzpicture}
    \matrix (line) [
        matrix of nodes,
        % Hard-coding, or it would use semithick, rather than very thin:
        inner sep=-.1pt,
        row sep=-.2pt,
        column sep=-.2pt,
        nodes={
            inner xsep=.5em,
            inner ysep=2pt,
            rectangle,
            draw,
            very thin,
            minimum width=3em,
            minimum height=24pt,
            text depth=.5ex,
            text height=2ex,
            nodes in empty cells,
        },
        ]
    {

        \refk{bol}
        & step
        & \refk{label}
        & \verb|&|
        & |[auto]| save
        & |[auto]| ind.
        & |[auto]| \refk{font}
        & body
        & \refk{eol}
        & \verb|\\|
        \\
    };

    \draw[semithick, decorate, decoration={calligraphic brace,mirror}]
        ($(line-1-1.south west)+(1pt,-4pt)$)
        --
        node[inner sep=0, midway, below=5pt] (prefix) {\refk{prefix}}
        ($(line-1-4.south east)+(-1pt,-4pt)$)
        ;

    \draw[semithick, decorate, decoration={calligraphic brace,mirror}]
        ($(line-1-5.south west)+(1pt,-4pt)$)
        --
        node[inner sep=0, midway, below=5pt] (setup) {\refk{setup}}
        ($(line-1-7.south east)+(-1pt,-4pt)$)
        ;

    \draw[overlay] (prefix.south) node[font=\footnotesize, below=2pt, inner sep=0pt]
        {\strut Inserted by \refc{\bslash} (not \code{\refc{\bslash}*})};

    \draw (setup.south) node[font=\footnotesize, below=2pt, inner sep=0pt]
        {\strut Part of preamble};

    \draw[semithick] (line-1-9.south) + (0,-4pt)
    -- (line-1-9.south |- setup.south)
        node[font=\footnotesize, below=2pt, inner sep=0pt]
        {\strut Inserted by \refc{\bslash} (not last)};

    \draw[semithick] (line.south west) rectangle (line.north east);
\end{tikzpicture}
\end{center}
\vspace{-2.5pt}

\noindent
The components in the \refk{prefix} are populated by the \refc{\bslash}
command (or the beginning of the environment), the ones in the \refk{setup} by
the \refk{preamble}, and the actual body is supplied by the user, inside the
environment, terminated by the row separator \refc{\bslash} (which then goes
on to populate the next row, and so on). The \refk{eol} part is also inserted
by \refc{\bslash}, except if it's used after the last line (where it doesn't
really do anything).\footnote{Thus, \refk{eol} acts more as a line
\emph{separator} than a line \emph{terminator}.} The following describes the
default behavior, which can be modified substantially by setting the
appropriate options (e.g., \refk{prefix} and \refk{setup}).

\begin{description}[style=sameline, font=\normalfont]
    \item[\refk{bol}] This field is inserted by \refc{\bslash} (and
        \code{\cs{begin}\braces{\refe{pseudo}}}) at the beginning of the
        following line, using the \refc{pseudobol} command. Because it's a the
        very beginning of the tabular row, it may be used for things like
        \cs{rowcolor} when highlighting lines (as with the \refk{hl} key).
    \item[step] This refers to a call to \cs{stepcounter*} (where \refk{*} is
        an alias for \refk{pseudoline}), getting the counter ready for the
        label itself. Note that this does \emph{not} use \cs{refstepcounter},
        so at this point the counter has not been saved yet (and so you should
        not use \cs{label} to refer to it at this point).
    \item[\refk{label}]
        This is where the numbering label is inserted, using
        \refc{pseudolabel}; initially, this inserts
        \code{\cs{arabic}\refk{*}}.
    \item[\code{\&}] At the end of the prefix is the column separator, closing
        the label column and beginning the code line column.
    \item[save] Now that we're in the column where the user will normally
        insert text and code, we save \refk{pseudoline} so it may be used with
        \cs{label} and \cs{ref}, etc. This is done using
        \refc{pseudosavelabel}, which first \emph{decrements} the counter (to
        undo the increment before the label) and then calls
        \cs{refstepcounter}.
    \item[ind.] Inserts the appropriate amount of indentation (with an indent
        step length set by \refk{indent-length} or \refk{indent-text} and the
        indentation level set by \code{+}/\code{-} flags or
        \refk{indent-level}), using \refc{pseudoindent}.
    \item[\refk{font}] Inserts the base font, using \refc{pseudofont}.
    \item[body] This is where the manually written body of the code line
        appears.
    \item[\refk{eol}] Inserted by the terminating \refc{\bslash} (using
        \refc{pseudoeol}), unless we're at the end of the environment. Useful,
        e.g., for taking actions such as a
        \pkg{beamer} \cs{pause} (cf., \refk{pause}) between the
        lines.\footnote{If the same action must be taken after the last line,
        you can simply insert it there manually.}
    \item[\refc{\bslash}] The row/line separator. Ends one line (inserting
        \refk{eol}) and begins another (inserting \refk{prefix}). As in
        tabulars in general, this command is also permitted after the final
        line of the environment, but there it does no real work (i.e., it does
        not insert \refk{eol} and does not start a new line).
\end{description}

\subsection{Command and key reference}
\label{sec:cmdandkeyref}

In addition to descriptions of the various commands and options/keys (in
alphabetical order), you'll find definitions of a couple of counters here
(\refk{*} and \refk{pseudoline}).

% Not really a key, of course -- a counter
\begin{docKey}{*}{}{}
    This counter is a duplicate of \refk{pseudoline}, available inside
    \refe{pseudo}. It makes it possible to simplify calls such as
    \code{\cs{arabic}\braces{\refk{pseudoline}}} to starred forms such as
    \cs{arabic*}, like in \pkg{enumitem}. These short forms are available (and
    intended) for use in \refk{label} and \refk{ref}.
\end{docKey}

\begin{docCommand}{..}{}
    This is a shortcut that hijacks the normal \cs{.}\@ accent command, so
    that if it is called with \code{.}\@ as an argument, the result is
    \refc{dts}. In other words, the command \cs{..}\@ is really the call
    \code{\cs{.}\braces{.}}. For any other arguments, the original \cs{.}\@ is
    used, so while \code{\$1\cs{..}n\$} produces $1\..n$, \code{\cs{.}o} still
    yields~\.o.
\end{docCommand}

\begin{docCommand}{==}{}
    \RestorePseudoEq % Having some trouble bc/o floats, or something?
    This is a shortcut that hijacks the normal \cs{=} accent command, so that
    if it is called with \code{=} as an argument, the result is \refc{eqs}. In
    other words, the command \cs{==} is really the call
    \code{\cs{=}\braces{=}}. For any other arguments, the original \cs{=} is
    used, so while \code{\$x\cs{==}y\$} produces $x\==y$, \code{\cs{=}o} still
    yields \=o.

    In some contexts, this may not work because \cs{=} has reverted to its
    original meaning (as is currently the case if you try to use it within a
    custom float, as in \cref{sec:floats}, or a standard one such as
    \code{figure}). In this case, you can restore the \pkg{pseudo} meaning (and
    the \refc{==} shortcut) by using \refc{RestorePseudoEq}. In some cases, you
    may want to just use \refc{eqs} instead.
\end{docCommand}

\begin{docCommand}{\protect\bslash}{\,\colOpt{+}%
    \,\colOpt{-}%
    \,\colOpt{*}\,%
    \colOpt{<\meta{overlay specification}>}\,\oarg{line options}}

    \parindent1.5em
    \noindent
    This row separator is the workhorse of the \pkg{pseudo} package. Just as in
    a \code{tabular} environment, it signals the end of a line. It is optional
    after the list line, where it doesn't do any work.
%
    The command may be followed by a series of one or more plus (\code{+})
    signs, each of which will increment the indentation level before starting
    a new line; similarly, it may be followed by one or more minus (\code{-})
    signs, each of which will decrement the indentation level.
%
    Normally, the command will insert a \refk{prefix} at the beginning of the
    new line; if the star (\code{*}) flag is used, this prefix is not
    inserted.

    The optional overlay specifications refer to the \refk{hl} key, so
    \code{\refc{\bslash}<3>} is equivalent to \code{\refc{\bslash}[hl<3>]}.
    This applies to the following line, as do other options set explicitly as
    optional arguments. Note that options are set locally, \emph{before} the
    new line (and a new scope) is started, so unless they are handled
    specifically (in order to carry over), they will have no effect. Thus,
    even though all options are available here, not all make sense. (Consult
    individual option keys for intended use.)

    The pluses and minuses are conceptually part of the command name, and
    there should be no whitespace before the
    star (\code{*}).
    %
    You are, however, free to insert whitespace before the overlay
    specification and the line options. This means that you may, for example,
    place the overlay specification at the beginning of the following line in
    the source.

    The \refc{\bslash} command is special in that it also permits a keyless
    value to be used among its option; this will then be taken to implicitly use
    the key \refk{extra-space}, which adds extra vertical space below as part of
    the line break. This means you can supply a length argument in the same way
    as with the ordinary \cs{\bslash} command:

\begin{texexp}
\begin{pseudo}
    no extra space after this line              \\
    but there's extra space after this line     \\[2ex]
    so this line is a bit lonely
\end{pseudo}
\end{texexp}
\end{docCommand}

\begin{docCommand}{arabic*}{}
    See \refk{*}.
\end{docCommand}

\begin{docKey}{begin-tabular}{\,=\,\meta{commands}}{no default}
    The actual command for beginning the \code{tabular} or \code{tabular}-like
    environment used by \refe{pseudo}. Normally not needed, as the
    \code{tabular} behavior may be modified by other keys, but could be used
    to use some other tabular environment, e.g., from packages such as
    \pkg{tabularx} or \pkg{longtable}. Rather than
    \code{\cs{begin}\braces{tabularx}} and \code{\cs{end}{\braces{tabularx}}},
    the command versions \cs{tabularx} and \cs{endtabularx} should be used.
    Commands such as \refc{pseudopos} and \refc{pseudopreamble} may be used as
    part of the setup:
\begin{texexp}[listing]
\pseudoset{
    begin-tabular =
        \tabularx{\linewidth}[\pseudopos]{\pseudopreamble},
    end-tabular = \endtabularx
}
\end{texexp}
\end{docKey}

\begin{docKey}{bol}{\,=\,\meta{commands}}{\initiallyempty}
    Used to set \refc{pseudobol}, which is inserted at the beginning of each
    line. See also \refk{bol-append} and \refk{bol-prepend}.
\end{docKey}

\begin{docKey}{bol-append}{\,=\,\meta{commands}}{no default}
    Locally appends \meta{commands} to \refk{bol}.
\end{docKey}

\begin{docKey}{bol-prepend}{\,=\,\meta{commands}}{no default}
    Similar to \refk{bol-append}, except that \meta{commands} are added to
    the \emph{beginning} of \refk{bol}.
\end{docKey}

\begin{docCommand}{cn}{\marg{name}}

    Indicates a constant (such as \cn{true} or \cn{nil}). First wraps the
    argument in \cs{textnormal} and then uses \refc{cnfont}. See also
    \refc{DeclarePseudoConstant}.
    \fontutil{constants}
    \pseudoshortcutted{cn}

\end{docCommand}

\begin{docKey}{cnfont}{\,=\,\meta{command}}{\initialkeyvalue{\cs{textsc}}}
    \fontkey{cn}
\end{docKey}
\begin{docCommand}{cnfont}{}
    \fontcmd{cn}
\end{docCommand}

\begin{docKey}{compact}{\,=\,\meta{boolean}}{default \code{true}, initially
    \code{false}}

    \parindent1.5em
    \noindent
    The \refe{pseudo} environment emulates the built-in \LaTeX\ lists when it
    comes to spacing above and below, in normal text. If the environment is
    part of an ongoing paragraph, paragraphs will be inserted above and below,
    along with whitespace specified by \refk{topsep} (and \cs{parskip}). If
    the environment begins a paragraph of its own, additional whitespace is
    added, as specified by \refk{partopsep}. It is also possible to specify
    space to insert to the left of the environment, using \refk{left-margin}.

    However, these spacing commands don't work well inside \cs{mbox},
    \cs{fbox}, etc. To avoid getting into trouble, \pkg{pseudo} determines that
    the environment should be \emph{compact}, and drop this surrounding space,
    if we're in inner horizontal mode at the beginning of the environment. This
    will also turn off setting \cs{prevdepth} (cf.\@ \refk{prevdepth}).

\begin{texexp}
% In document preamble:
% \usepackage{tikz}
\begin{tikzpicture}
    \draw (0,0) node [draw] {%
        \begin{pseudo}
            if we're in a node \\+
                there's no added space
        \end{pseudo}};
\end{tikzpicture}
\end{texexp}

    This may not be enough, however. For example, if you're using
    \pkg{standalone} to produce individual pseudocode images, this compactness
    may not be triggered automatically. In such cases, you can override the
    behavior using the \refk{compact} key, manually specifying whether you want
    the pseudocode to be compact or not.
\end{docKey}

\begin{docCommand}{ct}{\marg{text}}
    Indicates that \meta{text} is a comment, \ct{typeset like this}. You can
    customize the comment appearance using \refk{ctfont}, \refk{ct-left} and
    \refk{ct-right}:

\begin{texexp}
\pseudoset{
    ctfont=\color{black!75},
    ct-left=\unskip\qquad\texttt{/* },
    ct-right=\texttt{ */}
}
\begin{pseudo}
    $y=1$ \\
    $x=2$ \ct{this is a comment} \\
    $z=345$ \ct{this is another comment}
\end{pseudo}
\end{texexp}

    An alternative to using \refc{ct} is to simply set comments in a separate
    column, as demonstrated in \cref{sec:tabularx}. Or even without a separate
    column, if you use a \code{tabularx} as described there, and set the
    tabular width explicitly, you could insert an \cs{hfill} into
    \refk{ct-right} and get all end-markers aligned at the right-hand side:

    \medskip\noindent

    \begin{pseudo}[
        begin-tabular=\tabularx{\linewidth}[t]{@{}r>{\pseudosetup}X@{}},
        end-tabular=\endtabularx,
        ctfont=\color{black!75},
        ct-left=\unskip\qquad\texttt{/* },
        ct-right=\hfill\texttt{ */}
        ]
        $x=1$ \\
        $y=2$  \ct{this is a comment} \\
        $z=345$ \ct{this is another comment}
    \end{pseudo}

    \medskip\noindent

    Or if you'd rather have the comments right-aligned (like you can in, e.g.,
    \pkg{algorithm2e}), you could use insert the \cs{hfill} at the beginning of
    the \refk{ct-left}:

    \medskip\noindent

    \begin{pseudo}[
        begin-tabular=\tabularx{\linewidth}[t]{@{}r>{\pseudosetup}X@{}},
        end-tabular=\endtabularx,
        ctfont=\color{black!75},
        ct-left=\hfill\texttt{/* },
        ct-right=\texttt{ */}
        ]
        $x=1$ \\
        $y=2$  \ct{this is a comment} \\
        $z=345$ \ct{this is another comment}
    \end{pseudo}
\end{docCommand}

\begin{docKey}{ct-left}{\,=\,\meta{text}}{\initialkeyvalue{\code{(}}}
    \leftbracketing{comment}{ct}
\end{docKey}
\begin{docKey}{ct-right}{\,=\,\meta{text}}{\initialkeyvalue{\code{)}}}
    \rightbracketing{comment}{ct}
\end{docKey}
\begin{docKey}{ctfont}{}{\initialkeyvalue{\cs{textit}}}
    The font of the main text of a comment, when using \refc{ct}.
\end{docKey}
\begin{docCommand}{ctfont}{}
    \fontcmd{ct}
\end{docCommand}

\begin{docCommand}{DeclarePseudoComment}{\marg{shortcut}\marg{comment}}
    Used to declare a macro that expands to a comment. For example:
\begin{texexp}
\DeclarePseudoComment \Imp {Important!}
$x = y$ \qquad \Imp
\end{texexp}
    \seealsostyle{ct}
\end{docCommand}

\begin{docCommand}{DeclarePseudoConstant}{\marg{shortcut}\marg{constant}}
    Used to declare a macro that expands to a constant. For example:
\begin{texexp}
\DeclarePseudoConstant \False {false}
\False
\end{texexp}
    \seealsostyle{cn}
\end{docCommand}

\begin{docCommand}{DeclarePseudoFunction}{\marg{shortcut}\marg{function}}
    Used to declare a macro that expands to a function. For example:
\begin{texexp}
\DeclarePseudoFunction \Ln {length}
\Ln(A) or \Ln[A]
\end{texexp}
    \seealsostyle{fn}
\end{docCommand}

\begin{docCommand}{DeclarePseudoIdentifier}{\marg{shortcut}\marg{identifier}}
    Used to declare a macro that expands to a identifier. For example:
\begin{texexp}
\DeclarePseudoIdentifier \Rank {rank}
\Rank
\end{texexp}
    \seealsostyle{id}
\end{docCommand}

\begin{docCommand}{DeclarePseudoKeyword}{\marg{shortcut}\marg{keyword}}
    Used to declare a macro that expands to a keyword. For example:
\begin{texexp}
\DeclarePseudoKeyword \While {while}
\While
\end{texexp}
    \seealsostyle{kw}
\end{docCommand}

\begin{docCommand}{DeclarePseudoNormal}{\marg{shortcut}\marg{text}}
    Used to declare a macro that expands to normal text. For example:
\begin{texexp}
\DeclarePseudoNormal \Error {halt with an error message}
\begin{pseudo*}[kw]
    if $x \== \cn{nil}$ \\+
        \Error
\end{pseudo*}
\end{texexp}
    \seealsostyle{tn}
\end{docCommand}

\begin{docCommand}{DeclarePseudoProcedure}{\marg{shortcut}\marg{procedure}}
    Used to declare a macro that expands to a procedure. For example:
\begin{texexp}
\DeclarePseudoProcedure \Euclid {Euclid}
\Euclid(a, b)
\end{texexp}
    \seealsostyle{pr}
\end{docCommand}

\begin{docCommand}{DeclarePseudoString}{\marg{shortcut}\marg{string}}
    Used to declare a macro that expands to a string. For example:
\begin{texexp}
\DeclarePseudoString \Hello {Hello!}
\Hello
\end{texexp}
    \seealsostyle{st}
\end{docCommand}

\begin{docKey}{dim}{}{}
    Dims the following line. Equivalent to:
\begin{texexp}[listing]
\pseudodefinestyle{dim}{
    bol-append   = \color{\pseudodimcolor},
    setup-append = \color{\pseudodimcolor}
}
\end{texexp}
May be used to dim out inactive or currently less relevant lines (possibly
using overlays; see~\cpageref{p:overlays}).
\begin{texexp}
\begin{pseudo}[kw, dim-color=black!25]*
\hd{Gnome-Sort}(A)                              \\
[dim]  $i = 1$                                  \\
[dim]  while $i \leq \fn{length}[A]$            \\+
           if $i \== 1$ or $A[i] \geq A[i-1]$   \\+
               $i = i + 1$                      \\-
[dim]      else \nf swap $A[i]$ and $A[i-1]$    \\+
[dim]          $i = i - 1$
\end{pseudo}
\end{texexp}
See also \refk{bol-append}, \refk{setup-append} and \refk{dim-color}.
\end{docKey}

\begin{docKey}{dim-color}{\,=\,\meta{color}}{no default, initially
    \cs{pseudohlcolor}}
    Sets the color used by \refk{dim} (available as \cs{pseudodimcolor}). The
    initial value is the one set by \refk{hl-color}.
\end{docKey}

% Wirth notation, Pascal
% https://proofwiki.org/wiki/Definition:Real_Interval/Notation/Wirth
% https://en.wikipedia.org/wiki/Ellipsis_(computer_programming)
\begin{docCommand}{dts}{} % The name in Concrete Mathematics
    A two-dot ellipsis, for use in the Wirth interval notation $1\..n$,
    typeset as \citeauthor{Graham:1994} did in
    \citetitle{Graham:1994}~\citep{Graham:1994}. Its definition is the same as
    in \pkg{gkpmac}. Also accessible via the \refc{..} shortcut. See also
    \refc{rng}.
\end{docCommand}

\begin{docKey}{end-tabular}{}{\initialkeyvalue{\code{\cs{end}\braces{tabular}}}}
    The actual command for ending the \code{tabular} or \code{tabular}-like
    environment used by \refe{pseudo}. (See \refk{begin-tabular}.)
\end{docKey}

\begin{docKey}{eol}{\,=\,\meta{commands}}{\initiallyempty}
    Sets \refc{pseudoeol}, which is inserted at the end of all but the last
    line by \refc{\bslash}. See also \refk{eol-append} and \refk{eol-prepend}.
\end{docKey}

\begin{docKey}{eol-append}{\,=\,\meta{commands}}{no default}
    Locally appends \meta{commands} to \refk{eol}.
\end{docKey}

\begin{docKey}{eol-prepend}{\,=\,\meta{commands}}{no default}
    Similar to \refk{eol-append}, except that \meta{commands} are added to
    the \emph{beginning} of \refk{eol}.
\end{docKey}

\begin{docCommand}{eqs}{}
    Two equality signs typeset together as a binary relation, as in $x \eqs
    y$ (as opposed to the wider $x == y$, resulting from \code*{\$x == y\$}).
    It emulates the \pkg{stix} symbol \cs{eqeq}, but for use with Computer
    Modern (the default \LaTeX\ font) or Latin Modern (available via the
    \pkg[https://ctan.org/tex-archive/info/lmodern]{lmodern} package). It should
    work just fine with other fonts. Also accessible via the \refc{==} shortcut,
    and configurable via \refk{eqs-pad}, \refk{eqs-scale} and \refk{eqs-sep}.
\end{docCommand}
\begin{docKey}{eqs-pad}{\,=\,\meta{muskip}}{\initialkeyvalue{\code{0.28mu}}}
    The amount of space inserted on each side of \refc{eqs}.
\end{docKey}
\begin{docKey}{eqs-scale}{\,=\,\meta{number}}{\initialkeyvalue{\code{0.6785}}}
    The amount of horizontal scaling applied to the \code{=} signs in
    \refc{eqs}.
\end{docKey}
\begin{docKey}{eqs-sep}{\,=\,\meta{muskip}}{\initialkeyvalue{\code{0.63mu}}}
    The amount of space inserted between the two \code{=} signs in \cs{eqs}.
\end{docKey}

\begin{docKey}{in-float}{}{\pkg{pseudo} style}
    This is a style, defined using \refc{pseudodefinestyle}, that is applied to
    the contents of every \code{tcolorbox} styled using the \code{pseudo/}
    styles, such as \refk{pseudo/boxed}, \refk{pseudo/ruled}, etc. (Despite the
    name, it is not limited to boxes defined with the \code{float} key.) The
    style is initially empty, and acts as a hook for user customization (similar
    to \refk{pseudo/init}, but specifically for \pkg{pseudo} configuration):
    \begin{texexp}
    \pseudodefinestyle{in-float}{kwfont = \sffamily}
    \kw{not modified}
    \begin{tcolorbox}[pseudo/filled]
        \kw{modified}
    \end{tcolorbox}
    \end{texexp}
\end{docKey}

\begin{docKey}{extra-space}{\,=\,\meta{length}}{\initialkeyvalue{\code{0pt}}}
    \parindent1.5em
    \noindent
    Additional space to be added by \refc{\bslash}, below the baseline of the
    current row. For example:

\begin{texexp}
\begin{pseudo}[indent-mark, extra-space=2ex]
    a                                           \\+
        b                                       \\+
            c
\end{pseudo}
\end{texexp}
Note the difference from \refk{line-height}: Here the space is added below, just
like with the \emph{normal} \cs{\bslash} command, when its optional argument is
used, whereas with \refk{line-height} the height and depth of the line are both
scaled. Also, unlike with \refk{line-height}, with \refk{extra-space}, nothing
is added to the last line unless it actually ends with a \refc{\bslash} command.

The most likely use-case for this command is to add space after specific lines,
rather than for \emph{every} line, as in the previous example. For example:
\begin{texexp}
\begin{pseudo}
    one group that is           \\
    logically connected         \\ [extra-space=1.5ex]
    another group that is       \\
    separate from the first
\end{pseudo}
\end{texexp}
In fact, \refk{extra-space} is so closely tied to \refc{\bslash}, that you can
supply a keyless value as one of its options, and \refk{extra-space} will be
\emph{assumed}. So, for example, in the previous example, you could simply have
used \code{\cs{\bslash}[1.5ex]}.

If you want spacing only after the heading (created with \refc{hd}), you can set
that using the \refk{hd-space} key.
\end{docKey}

\begin{docCommand}{fn}{\marg{name}\colOpt{(\meta{arguments})}}

    Indicates a function name, such as \fn{length}, and is initially
    more or less an alias for \refc{id}. The optional arguments (given in
    parentheses) are typeset in math mode, so
    \code{\cs{fn}\braces{length}(A)} yields \fn{length}(A).
    %
    Sometimes square brackets are used with functions that are meant to
    indicate array lookups or some property access or the like. This works in
    the same manner, so
    \code{\cs{fn}\braces{length}[A]} yields \fn{length}[A]. This behavior of
    picking up arguments carries over if you define a shortcut, of course:
\begin{texexp}
\def\Ln{\fn{length}}
We're not in math mode, but the argument of \Ln[A] is.
\end{texexp}

    % Should typeset \fn{test}[A] followed by (B) in normalfont:
    % \fn{test}[A](B)
    % Should typeset \fn{test}(A) followed by [B] in normalfont:
    % \fn{test}(A)[B]
    See also \refc{DeclarePseudoFunction}.
    \fontutil{function names}
    \pseudoshortcutted{fn}
\end{docCommand}

\begin{docKey}{fnfont}{\,=\,\meta{font}}{\initialkeyvalue{\refc{idfont}}}
    \fontkey{fn}
\end{docKey}
\begin{docCommand}{fnfont}{}
    \fontcmd{fn}
\end{docCommand}

\begin{docKey}{font}{\,=\,\meta{command}}%
    {\initialkeyvalue{\cs{normalfont}}}
    Sets the base font used in the code lines. Initially, this is just
    \cs{normalfont}, but the \refk{kw} switch is a convenient way to set it to
    the keyword font \refc{kwfont}. This is presumed to be a common case,
    under the assumption that most of the pseudocode will consist of either
    keywords or mathematics. If you'd rather explicitly mark up your keywords,
    leaving \refk{font} as it is, you could use \refc{kw} (or
    \refc{DeclarePseudoKeyword} for common cases):
\begin{texexp}
\begin{pseudo*}
\kw{while} pigs don't fly                       \\+
    keep waiting
\end{pseudo*}
\end{texexp}
\end{docKey}

\begin{docCommand}{hd}{\marg{name}(\meta{arguments})}
    \parindent1.5em
    \noindent
    Typesets a procedure signature, like \refc{pr}, but is intended for use as
    a \emph{header} for a procedure, rather than a procedure call. The
    difference is that \cs{hd} wraps its contents in a \cs{multicolumn},
    spanning two columns (i.e., both the label column and the main code
    column, but not any additional columns added using \refk{preamble} or
    \refk{begin-tabular}), using the preamble set with \refk{hd-preamble}. For
    this to work, you need to use the star flag (\code{*}) to suppress the
    automatic insertion of the \refk{prefix}:

\begin{texexp}
\begin{pseudo}*
    \hd{Algorithm}(x, y, z)                     \\
    setup                                       \\
    \kw{while} condition                        \\+
        iterative step                          \\-
    \kw{return} result
\end{pseudo}
\end{texexp}

    \noindent
    The \refk{hd-space} key can be used to configure \refc{hd} so it sets the
    \refk{extra-space} key. Note that the signature arguments are mandatory; in
    order to function properly, \cs{hd} must be \emph{expandable}, and therefore
    cannot end with an optional argument, the way \refc{pr} does.
    \pseudoshortcutted{hd}
\end{docCommand}

\begin{docKey}{hd-preamble}{\,=\,\meta{columns}}{no default}
    Sets the preamble used by \refc{hd}. The result is available as the column
    type with name \cs{pseudohdpreamble}. (Note that this is the literal
    column name, and not a macro containing the name. See \refk{preamble} for
    more information.) Initially, a single left-aligned column with
    \refc{pseudohpad} on either side (see \cpageref{p:hdpreamble}). If you
    introduce more columns in \refk{preamble}, you might want to increase the
    number of columns in \refk{hd-preamble} as well, or at least remove the
    right-hand \refc{pseudohpad}.
\end{docKey}

\begin{docKey}{hd-space}{\,=\,\meta{length}}{default \code{0.41386ex}, initial
    value \code{0pt}}
    The value \refk{extra-space} is set to (before any value set manually as
    part of \refc{\bslash}) after the use of \refc{hd}. This is useful if one
    wants some extra space only after the header. The default is based on
    \pkg[https://www.cs.dartmouth.edu/~thc/]{clrscode4e},\footnote{And older
    versions, for that matter.} and, so getting spacing header spacing similar
    to that package requires only \code{\cs{pseudoset}\braces{hd-space}}. (See,
    e.g., the example \vpageref{ex:clrscode4ish}.)
\end{docKey}

\begin{docKey}{hl}{}{\novaluekey}
    Prepends \refc{pseudohl} to \refk{bol}. Normally used with \pkg{beamer} (see
    \cpageref{p:overlays}). Note that if if \refk{hpad} is set, a warning will
    be emitted (unless this is overridden by \refk{hl-warn}).
\end{docKey}

\begin{docKey}{hl-color}{\,=\,\meta{color}}{\initialkeyvalue{\code{black!12}}}
    Sets the color used by \refc{pseudohl} (available as \cs{pseudohlcolor}).
\end{docKey}

\begin{docKey}{hl-warn}{\,=\,\meta{warn}}{default \code{true}, initial
    value \code{true}}
    Permits turns off (by setting \refk{hl-warn} to \code{false}) the warning
    that is normally emitted if you use \refk{hl} without having used
    \refk{hpad}.
\end{docKey}

\begin{docKey}{hpad}{\,=\,\meta{length}}%
    {default \code{0.3em}, initially \code{0em}}
    Horizontal padding on either side of the pseudocode. Useful, among other
    things when highlighting lines, to have some of the highlighting (i.e.,
    row color) protrude beyond the text. This key also sets \refk{hl-warn} to
    \code{false}.
\end{docKey}

\begin{docKey}{hsep}{\,=\,\meta{length}}%
    {\initialkeyvalue{\code{0.75em}}}
    The space between the line labels and the code lines, i.e., between the
    two columns of numbered \refEnv*{pseudo} environments.
\end{docKey}

\begin{docCommand}{id}{\marg{name}}
    Indicates an identifier, and is simply an alias for \cs{textit} wrapped in
    \cs{textnormal}.
    See also \refc{DeclarePseudoIdentifier}.
    \fontutil{identifiers}
    \pseudoshortcutted{id}

    \medskip

    It might seem more natural to use \cs{mathit} (without \refCom*{tn}), but
    that may not give the desired results. First of all, special characters
    will not behave as if they're parts of a name:

\begin{texexp}
$\mathit{foo-bar:baz}$
\end{texexp}

    This may be remedied, e.g., by using the (internal) command
    \cs{newmcodes@} from \pkg{amsopn}, but the kerning, spacing and font
    application in the result still leaves something to be desired:

\makeatletter
\begin{texexp}
$\mathit{\newmcodes@ foo-bar:baz}$
\end{texexp}
\makeatother

    Compare this to a simple \cs{textit}:

\begin{texexp}
$\textit{foo-bar:baz}$
\end{texexp}

    The decision to use \cs{textit} means that you can't use, say, subscripts
    or the like as parts of an identifier, or mix in greek letters or other
    mathematical symbols. Though you can still easily typeset things like
    $\id{foo-$\alpha$}$, you'll have to mix in the math mode more
    explicitly (in this case, \verb|$\id{foo-$\alpha$}$|).
%
    \pseudoshortcutted{id}
\end{docCommand}
\begin{docKey}{idfont}{\,=\,\meta{font}}{\initialkeyvalue{\cs{textit}}}
    \fontkey{id}
\end{docKey}
\begin{docCommand}{idfont}{}{}
    \fontcmd{id}
\end{docCommand}

\begin{docKey}{indent-length}{\,=\,\meta{length}}{\initiallyempty}
    How large each indentation step is. If this key is not specified,
    \refk{indent-text} is used to calculate one the indent length instead.
\end{docKey}

\begin{docKey}{indent-level}{\,=\,\meta{length}}{no default, initially \code{0}}
    Sets the current indentation level. This is most usefully set on
    \refe{pseudo} environment, in concert with \refk{start}:\footnote{The
    \cs{strut} here is just to even out spacing above and below the text,
    which doesn't have fixed-height lines like the pseudocode.}
\begin{texexp}
\begin{pseudo}
    this is                                     \\+
    the first part
\end{pseudo}

\medskip \strut
This is some text interrupting the code.
\medskip

\begin{pseudo}[start=3, indent-level=1]
    this is the                                 \\-
    second part
\end{pseudo}
\end{texexp}
\end{docKey}

\def\algoexample#1{%
\begin{pseudo}[#1]
\kw{repeat} $n-1$ times \\+
    \kw{for} each edge $uv$ \\+
        update estimate for $v$ via $u$ \\--
\kw{for} each edge $uv$ \\+
    \kw{if} estimate for $v$ improves via $u$ \\+
        \kw{return} \cn{false} \\--
\kw{return} \cn{true}
\end{pseudo}
}
\begin{docKey}{indent-mark}{\,=\,\meta{mark}}{default vertical line, initially
    empty}
A mark used to indicate the start of each step of indentation.\footnote{Similar
to \code{c:indentLine\_char} in the vim plugin
\pkg[https://github.com/Yggdroot/indentLine]{indentLine}.}
Any horizontal space taken up by this mark is added to the indentation; to
prevent this, wrap the mark in \cs{rlap} (and, if necessary, in \cs{smash}, to
handle \emph{vertical} space). The following example uses
\verb|indent-mark=\rlap{$\cdot$}|:

\algoexample{indent-mark=\rlap{$\cdot$}}
%
By default, the indent mark is a vertical line that scales with the line height,
so each indented block is indicated by a single unbroken vertical line. It also
``undoes'' its own width, so it doesn't impact the indentation. The following
example uses the \refk{indent-mark} key with no argument:

\algoexample{indent-mark}
%
This default mark may be configured by using the keys \refk{indent-mark-color},
\refk{indent-mark-width} and \refk{indent-mark-shift}.
\end{docKey}

\begin{docKey}{indent-mark-color}{\,=\,\meta{color}}%
    {\initialkeyvalue{\codefont{lightgray}}}
    Sets the color to be used by the default \refk{indent-mark}. See
    \refk{indent-mark-shift} for an example.
\end{docKey}

\begin{docKey}{indent-mark-shift}{\,=\,\meta{length}}{default \code{.5em},
        initial value \code{0pt}}
    Sets the horizontal shift (from the actual start of an indent step) at which
    to render the default \refk{indent-mark}. The following example uses the
    default value, and sets \refk{indent-mark-width} to \code{.4pt} and
    \refk{indent-mark-color} to \code{black}, to approximate the look of the
    indent mark in \pkg{algorithm2e}.
\algoexample{indent-mark, indent-mark-shift, indent-mark-color=black,
indent-mark-width=.4pt}
\end{docKey}

\begin{docKey}{indent-mark-width}{\,=\,\meta{width}}%
    {\initialkeyvalue{\codefont{.6pt}}}
    Sets the width of the default \refk{indent-mark}. See
    \refk{indent-mark-shift} for an example.
    %
    The default value of \code{.6pt} corresponds to the
    \pkg[https://ctan.org/pkg/pgf]{tikz} line width \code{semithick}.
\end{docKey}

\begin{docKey}{indent-text}{\,=\,\meta{text}}%
    {\initialkeyvalue{%
    \code*{\cs{pseudofont}\cs{kw}\braces{else}\cs{\verbvisiblespace}}}}
    The size of each indentation step is set to the width of the \meta{text}.
    The default is set up so that code following on the same line as \kw{else}
    will be properly aligned, as in:

    \medskip

    \begin{pseudo*}[kw]
        if \tn{condition} \\+
            \tn{something} \\-
        else \tn{something else}
    \end{pseudo*}

    \medskip

    If you're not going to put code on the same line as \kw{else}, for
    example, you might want a different indentation size. To set it to some
    specific length, you could use
    the \refKey*{indent-length} key.
\end{docKey}

\begin{docKey}{kw}{}{\novaluekey}
    Sets \refk{font} to \refc{kwfont}.
\end{docKey}
\begin{docCommand}{kw}{\marg{name}}
    Indicates a keyword. First wraps the argument in \cs{textnormal} and then
    adds \cs{kwfont}.
    See also \refc{DeclarePseudoKeyword}.
    \fontutil{keywords}
    \pseudoshortcutted{kw}
\end{docCommand}

\begin{docKey}{kwfont}{\,=\,\meta{font}}{%
    \initialkeyvalue{\code{\cs{fontseries}\braces{b}\cs{selectfont}}}}
    \fontkey{kw}
    Note, however, that with the \refk{kw} switch, you set \code*{\refk{font}
    = \refc{kwfont}}, which is then applied as a font-switching command for
    each entire line, taking no argument. If you provide an command requiring
    an argument, the \refc{kw} command will still work, but the \refk{kw}
    switch won't:
\begin{texexp}
\pseudoset{kw}
\begin{pseudo*}[kwfont=\textsf]    % breaks kw option
    foo \kw{bar}
\end{pseudo*}
vs.\
\begin{pseudo*}[kwfont=\sffamily]  % works with kw option
    foo \kw{bar}
\end{pseudo*}
\end{texexp}
    The initial value isn't \emph{quite} as straightforward as indicated,
    however.
    For more info, see \refc{kwfont}.
\end{docKey}

\begin{docCommand}{kwfont}{}
    \parindent1.5em
    \noindent
    \fontcmd{kw}
    Its initial definition is \emph{essentially}
    \code{\cs{fontseries}\braces{b}\cs{selectfont}}, except the first time
    it's called (normally when evaluating the initial value of
    \refk{indent-text}), it also runs a check to see if the font selection
    \emph{worked}, as in some cases (such as in a default
    \pkg{beamer} presentation), the non-extended bold may not be available. In
    that case, it defaults to an extended bold (\cs{bfseries}) instead. At this
    point, the command is redefined to
    \code{\cs{fontseries}\braces{b}\cs{selectfont}} or \cs{bfseries}, as
    appropriate (i.e., without this check). So, while
    \code{\refc{kw}\braces{hello}} produces the non-extended \kw{hello} in a
    default \LaTeX\ document, it yields the extended {\origbfseries\sffamily
    hello} in a default \pkg{beamer} presentation. Perhaps more clearly, this is
    the result in plain \LaTeX\ (using
    \pkg[https://ctan.org/tex-archive/info/lmodern]{lmodern}):

{\let\bfseries\origbfseries
\begin{texexp}
\textbf{while}\\                  % Extended
\kw{while}\\                      % Keyword
{\fontseries{b}\selectfont while} % Non-extended
\end{texexp}
}\ignorespaces\par

    \noindent
    The same code results in the the following in \pkg{beamer}:

    \medskip\noindent
    \includegraphics{kwfig.pdf}

    \medskip\noindent
    You'll also get a font warning,\footnote{Of course, if you use a different
    font or theme, e.g., with the \pkg{beamer} command
    \code{\cs{usefonttheme}\braces{serif}}, you may not have any issues to begin
    with.} though only once, as it's suppressed after the first occurrence, so the
    fact that the font selection doesn't work on the last line isn't reported. Note,
    however, that the current implementation of \refc{kwfont} actually
    \emph{piggybacks} on this warning to determine if the non-extended bold is
    available. This means that if you've tried (and failed) to use
    \code{\cs{fontseries}\braces{b}} \emph{before} the fist use of \refc{kwfont},
    the fallback (i.e., extended bold) won't be triggered.

    Also note that \refk{indent-text} (which will tend to be the first
    occurrence use of \refc{kwfont}) won't be evaluated (to determine
    \refk{indent-length}) until you actually start a \refe{pseudo}
    environment, so if you're \emph{aware} that you don't have non-extended
    bold available, and you set \code*{\refk{kwfont} = \cs{bfseries}}, for
    example, there will be no attempt to use the non-extended version, and you
    won't get the font warning that the default implementation produces in
    that case.
\end{docCommand}

\begin{docKey}{label}{\,=\,\meta{commands}}{%
    \initialkeyvalue{\code{\refc{arabic*}}}}%
    \parindent1.5em
    \noindent
    Used to format the line label/number. For example, to emulate
    \pkg[https://www.cs.dartmouth.edu/~thc/]{clrscode4e} rather than
    \pkg{clrscode3e}, you'd use \code*{label = \cs{small}\cs{arabic}*}. You can
    also add punctuation or the like, as in \pkg{enumitem}:
\begin{texexp}
\pseudoset{kw, label=\footnotesize\arabic*:}

\begin{pseudo}
print \st{Hello, label!} \label{li:label}       \\
goto \tn{\ref{li:label}}
\end{pseudo}
\end{texexp}
    \noindent
    Note that \cs{label} should be used in the actual code line, as here, and
    not in the number cell (which is generally not explicitly written,
    anyway).

    As can be seen from the example, \cs{ref} is unaffected by
    \refKey*{label}, and in many cases that's what you want---as apposed to,
    say, ``\kw{goto} {\footnotesize 1:}''. In some cases, however (especially
    when using one of the other formatting commands, such as \cs{alph} or
    \cs{roman}), you \emph{do} want the reference format to reflect the
    original, or be similar in some way. To do that, you use the
    \refKey*{ref} key.
\end{docKey}

\begin{docKey}{label-align}{\,=\,\meta{column}}{\initialkeyvalue{\code{r}}}%
    Used to specify the alignment of the \refk{label} of each line. Whatever
    is provided is stored as a column type (named \cs{pseudolabelalign}),
    which is a part of the default \refk{preamble}. In other words, beyond the
    basic \code{l} and \code{r} (for left- and right-justified), you can
    supply anything that would be valid as part of the preamble (possibly
    using functionality from the \pkg{array} package). If you want to get
    creative here, though, it might be easier to get the results you want by
    specifying your own \refk{preamble} in full.
\end{docKey}

\begin{docKey}{left-margin}{\,=\,\meta{length}}{\initialkeyvalue{\code{0pt}}}
    Sets the left margin of the \code{pseudo} environment, i.e., how far it is
    indented wrt.\ the surrounding text:
\begin{texexp}
Lorem ipsum dolor sit amet:

\begin{pseudo}[left-margin=1.25em]
consetetur sadipscing elitr \\
sed diam nonumy eirmod tempor
\end{pseudo}

Invidunt ut labore et dolore magna.
\end{texexp}

To have the environment indented as (the beginning of) any normal paragraph,
you could use \code*{left-margin = \cs{parindent}}. Note that
\refk{left-margin}, as well as the spacing above and below the \refe{pseudo}
environment, is turned off inside \cs{mbox} and the like:
\begin{texexp}
\pseudoset{left-margin=1cm} % Won't affect box contents
\fbox{\begin{pseudo*}
I'm a livin' in a box \\
I'm a livin' in a cardboard box
\end{pseudo*}}
\end{texexp}
Note that as opposed to \refk{topsep} and \refk{partopsep}, we are \emph{not}
working with one of the built-in list spacing commands; \cs{leftmargin} has no
effect on this key (which is why the hyphenated naming style of other keys such
as \refk{label-align} or \refk{indent-text} is also adopted for
\refk{left-margin}).
%
See also \refk{compact}.
\end{docKey}

\begin{docKey}{line-height}{\,=\,\meta{factor}}{\initialkeyvalue{\code{1}}}
    The \meta{factor} with which to multiply the ordinary line height. For
    simple, sparse pseudocode, the oridnary line height works well, but if
    your code
    gets too crowded with text and notation, you may wish to increase
    \code{line-height}. To emulate, e.g., the
    \cs{jot} set by
    \pkg{amsmath} (which is \code{0.25\cs{baselineskip}}), you could use
    \code{1.25}, though even \code{1.1} should help in many cases.
\end{docKey}

\begin{docCommand}{nf}{}
    Switch to the normal font (i.e., without bold or italics, etc.).
    \shortcutted{nf}{normalfont}
    See also \refc{tn}.
\end{docCommand}

\begin{docKey}{partopsep}{\,=\,\meta{length}}{\initialkeyvalue{\cs{partopsep}}}
    Sets a \pkg{pseudo}-local copy of \cs{partopsep} for use in vertical spacing
    above and below the \refe{pseudo} environment. See also \refk{compact}.
\end{docKey}

\begin{docKey}{pause}{}{\novaluekey}
    Equivalent to \code*{\refk{eol-append} = \cs{pause}} (see \cref{p:pause}).
\end{docKey}

\begin{docKey}{pos}{\,=\,\meta{depth}}{\initialkeyvalue{\code{t}}}
    Specifies the vertical position of the \refe{pseudo} environment, i.e.,
    whether it should be vertically aligned on the top (\code{t}) or bottom
    (\code{b}) row, or be vertically centered (no value).
%
    This is equivalent to the (optional) \code{pos} argument to \code{tabular},
    and is in fact supplied to the internal \code{tabular} environment. The
    initial value is \code{t}, which makes sure the spacing above is
    consistent, regardless of the depth of the previous line. Here are two
    examples, set side by side:

    \medskip

    \begin{minipage}[t]{1.1cm}
    $x$
    \begin{pseudo}
    foo \\
    bar
    \end{pseudo}
    \end{minipage}
    \begin{minipage}[t]{1.1cm}
    $f(x)$
    \begin{pseudo}
    frozz \\
    bozz
    \end{pseudo}
    \end{minipage}

    \medskip

    The \refe{pseudo} environments are properly aligned. If, instead, we set
    \code*{pos = \braces{}}, they will not be, because $f(x)$ has more depth
    than $x$:\footnote{This was the behavior in older versions of
    \pkg{pseudo}.}

    \medskip

    \begin{minipage}[t]{1.1cm}
    $x$
    \begin{pseudo}[pos=]
    foo \\
    bar
    \end{pseudo}
    \end{minipage}
    \begin{minipage}[t]{1.1cm}
    $f(x)$
    \begin{pseudo}[pos=]
    frozz \\
    bozz
    \end{pseudo}
    \end{minipage}

    \medskip

    If \refk{compact} is set to \code{true}, \refk{pos} is automatically
    emptied like this---a behavior which can, of course, be overridden:

    \begin{texexp}
    Lorem
    \begin{pseudo*}[compact]
        foo \\ bar
    \end{pseudo*}
    ipsum
    \begin{pseudo*}[compact, pos=b]
        foo \\ bar
    \end{pseudo*}
    dolor
    \begin{pseudo*}[compact, pos=t]
        foo \\ bar
    \end{pseudo*}.
    \end{texexp}
\end{docKey}

\begin{docCommand}{pr}{\marg{name}\colOpt{(\meta{arguments})}}
    Indicates a procedure name, such as \cn{Quicksort}, and is initially
    more or less an alias for \refCom*{cn}. The optional arguments (in
    parentheses) are typeset in math mode, so
    \code{\cs{pr}\braces{Quicksort}(A,p,r)} yields \pr{Quicksort}(A,p,r).
    See also \refc{DeclarePseudoProcedure}.
    \fontutil{procedure names}
    \pseudoshortcutted{pr}
\end{docCommand}

\begin{docKey}{preamble}{\,=\,\meta{columns}}{no default}
    Sets the preamble to be used by the internal \code{tabular}. The result is
    available as the column type with name \cs{pseudopreamble}. (Note that
    this is the literal column name, and not a macro containing the name.
    Initially, \pkg{pseudo} uses a \code{tabular} as redefined by the
    \pkg{array}, which prevents the expansion of whatever is provided as its
    preamble, and so we supply the preamble in the form of a single ``column''
    instead.) For the default value, see the actual implementation on
    \cpageref{p:preamble} as well as the explanation in
    \cref{sec:linestructure}.
\end{docKey}

\begin{docKey}{prefix}{\,=\,\meta{commands}}{no default}
    This is the text inserted at the beginning of the following line by
    \refc{\bslash} (and by \code{\cs{begin}\braces{\refe{pseudo}}}), unless
    you use the star (\code{*}) flag. Unless modified, it inserts the code
    necessary to label the line and to move into the second column, where the
    actual code is inserted by the user. For the default value, see the actual
    implementation on \cpageref{p:prefix} as well as the explanation in
    \cref{sec:linestructure}.
\end{docKey}

\begin{docKey}{prevdepth}{\,=\,\meta{depth}}{\initialkeyvalue{\code{.3\cs{baselineskip}}}}
    This value is used to properly adjust the vertical distance to any
    following text, by setting \cs{prevdepth} to \meta{depth}, unless
    \refk{compact} is set to \code{true}. In general, it should not be
    necessary to change its value.\footnote{In previous versions,
    \cs{prevdepth} was not set. To get the old behavior, set \code*{prevdepth =
    0pt}.}
\end{docKey}

\begin{docKey}{prfont}{\,=\,\meta{font}}{\initialkeyvalue{\refc{cnfont}}}
    \fontkey{pr}
\end{docKey}
\begin{docCommand}{prfont}{}
    \fontcmd{pr}
\end{docCommand}

\begin{docEnvironment}[doclang/environment content=pseudocode]%
    {pseudo}{\oarg{options}\,\colOpt{*}\,\colOpt{<\meta{overlay
    specification}>}\,\oarg{line options}}
    The actual environment in which the pseudocode is typeset. The
    \meta{options} are local to the environment, while the \meta{line options}
    are local to the following line (in the same manner as those set in
    \refc{\bslash}; i.e., only some will actually have any effect). The star
    (\code{*}) and \meta{overlay specification} act just like those on
    \refc{\bslash}. Note that if you wish to specify \meta{line options}
    without the star or the \meta{overlay specification}, you need to supply
    at least an empty pair of brackets for the global options:
\begin{texexp}
\pseudoset{hpad} % because we're using hl
\begin{pseudo}[][hl]
First line \\
Second line
\end{pseudo}
vs.\
\begin{pseudo}[hl]
First line \\
Second line
\end{pseudo}
\end{texexp}
    There are no \code{+}/\code{-} flags here, unlike for \refc{\bslash};
    if needed, you can use \refk{indent-level}.
\end{docEnvironment}

\begin{docEnvironment}[doclang/environment content=pseudocode]%
    {pseudo*}{\oarg{options}\,\colOpt{*}\,\colOpt{<\meta{overlay
    specification}>}\,\oarg{line options}}
    An unnumbered version of the \refe{pseudo} environment. Equivalent to
    \refe{pseudo}, but with the \code{starred} style applied
    (see~\cpageref{p:starred}). Unless this style is altered, this means that
    the label column is removed from the preamble, and the prefix is reduced
    to only \refk{bol}.
\end{docEnvironment}

\begin{docKey}{pseudo/boxed}{}{\pkg{tcolorbox} style}
    \tcolorboxstylepre

\begin{texexp}
\begin{tcolorbox}[pseudo/boxed,
    title={Algorithm 1\enskip \pr{Hello}(x)}]
    \begin{pseudo}
        \kw{print} \st{Hello,} $x$
    \end{pseudo}
\end{tcolorbox}
\end{texexp}

    \tcolorboxstylepost
\end{docKey}
%
\tcolorboxstylenosource{booktabs}
\tcolorboxstylenosource{boxruled}
\tcolorboxstylenosource{filled}

\begin{docKey}{pseudo/init}{\,=\,\meta{commands}}{\pkg{tcolorbox} hook}
    Can be used to define the contents of a hook that is inserted before the
    contents of a \pkg{tcolorbox} box styled with one of the \code{pseudo/}
    styles, such as \refk{pseudo/boxruled}, etc. It is used as part of the
    \pkg{tcolorbox} configuration, and is \emph{not} set using \cs{pseudoset}.
    Useful, e.g., for setting \cs{parskip} or tabstops (with the \pkg{tabto}
    package).
\begin{texexp}
\begin{tcolorbox}[pseudo/boxed, pseudo/init=\parskip 2ex]
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed
diam nonumy eirmod tempor invidunt ut labore et dolore magna.

At vero eos et accusam et justo duo dolores et ea rebum. Stet
clita kasd gubergren, no sea takimata sanctus est Lorem ipsum
dolor sit amet.
\end{tcolorbox}
\end{texexp}
\end{docKey}

\tcolorboxstylenosource{ruled}
\tcolorboxstylenosource{tworuled}

\begin{docCommand}{pseudobol}{}
    \setandused{bol}{pseudoprefix}
\end{docCommand}

\begin{docCommand}{pseudodefinestyle}{\marg{name}\marg{options}}
    Used to define ``styles'' or meta-keys, i.e., shortcuts for setting
    several keys to given values (used, e.g., to define \refk{starred}). The
    \meta{name} is simply the name of the new meta-key, and the \meta{options}
    are just what you'd provide to, e.g., \refc{pseudoset}.
\end{docCommand}

\begin{docCommand}{pseudoeol}{}
    \setandused{eol}{\bslash}
    It is inserted between lines, but not after the last one.
\end{docCommand}

\begin{docCommand}{pseudofont}{}
    \setandused{font}{pseudosetup}
    It is used to set up the font for each pseudocode line. (See also
    \refk{kw}.)
\end{docCommand}

\begin{docCommand}{pseudohl}{}
    This is the command inserted as \refk{bol} by the \refk{hl} switch.
    Initially, it's just a \cs{rowcolor} using the color set by
    \refk{hl-color}, but you could redefine it to whatever you wish.
\end{docCommand}

\begin{docCommand}{pseudohpad}{}
    Used on the left- and right-hand sides of \refk{preamble}.
    Conceptually, it inserts the horizontal space specified by \refk{hpad}. To
    play nice with \cs{rowcolor}, however, it is not used in a
    \code{@\braces{\dots}} column; rather, it's placed in
    \code{>\braces{\dots}} and \code{<\braces{\dots}} modifiers, and the
    actual space inserted has \cs{tabcolsep} subtracted.
\end{docCommand}

\begin{docCommand}{pseudoindent}{}
    % Protrudes into the margin:
    % \setandused{indent-length}{pseudosetup}
    % Manual:
    The command set by the \refk{indent-length} and \refk{indent-mark} options.
    Used in \refc{pseudosetup}.
    More precisely, \refk{indent-length} is stored textually, and is converted
    to the length \cs{pseudoindentlength} when entering a \refe{pseudo}
    environment (so that units like \code{em} and \code{ex} adapt to the
    current font). If no \refk{indent-mark} is set, the \cs{pseudoindent}
    command then inserts a horizontal space of length
    $\cs{pseudoindentlength}\times\textit{current indent level}$. Otherwise,
    one \refk{indent-mark} and a horizontal space of length
    \cs{pseudoindentlength} is inserted for each level of indentation up to the
    current indentation level. (This horizontal space is measured from the left
    edge of the \refk{indent-mark}.)
\end{docCommand}

\begin{docCommand}{pseudolabel}{}
    \setandused{label}{pseudoprefix}
\end{docCommand}

% Counter, not key
\begin{docKey}{pseudoline}{}{}
    Counter for pseudocode lines. See also \refk{*}.
\end{docKey}

\begin{docCommand}{pseudopos}{}
    \setandusedinit{pos}{begin-tabular}
\end{docCommand}

\begin{docCommand}{pseudopreamble}{}
    \setandusedinit{preamble}{begin-tabular}
\end{docCommand}

\begin{docCommand}{pseudoprefix}{}
    \setandused{prefix}{\bslash}
\end{docCommand}

\begin{docCommand}{pseudosavelabel}{}
    Used as part of \refc{pseudosetup} to save the \refk{pseudoline} counter
    for use in \cs{label} and \cs{ref}. The \refk{pseudoline} counter is
    \emph{incremented} as part of the \refc{pseudolabel} command, but that's
    done using a plain \cs{stepcounter}, as any use of \cs{label} will
    presumably be placed in the pseudocode line (i.e., the next column). To
    save the value there, \cs{pseudosavelabel} first \emph{decrements} the
    counter, and then uses \cs{refstepcounter}.
\end{docCommand}

\begin{docCommand}{pseudoset}{\marg{options}}
    Used to set the configuration keys of the \pkg{pseudo} package (using
    \pkg{l3keys} with \code{pseudo} as the module). These may also be set as
    % package options (in \cs{usepackage}) and as
    optional arguments to the \refEnv*{pseudo} and \refEnv*{pseudo*}
    environments. For example, if you'd like to switch to \cs{rm} as your base
    font, you could use \code*{\cs{pseudoset}\braces{font = \cs{rm}}}.
\end{docCommand}

\begin{docCommand}{pseudosetup}{}
    The command set by the \refk{setup} option. Used as part of the
    \refk{preamble}.

    \medskip

    \emph{Not to be confused with \refc{pseudoset}.}
\end{docCommand}

\begin{docKey}{ref}{\,=\,\meta{commands}}{initially empty, default
    \refc{pseudolabel}}
    Shortcut for setting the \cs{thepseudoline} command. If used without
    arguments, it will use the value supplied to \refKey*{label}.
\begin{texexp}
\pseudoset {
    label = (\textsc{\alph*}),
    ref   = \Alph*,
    hsep  = .5em
}

\begin{pseudo}
print \st{Hello, ref!} \label{li:ref} \\
goto \tn{\ref{li:ref}}
\end{pseudo}
\end{texexp}
\end{docKey}

\begin{docCommand}{RestorePseudoBackslash}{}
    Command similar to the \cs{arraybackslash} of the \pkg{array} package.
    Switches the definition of \cs{\bslash} to the one used by \pkg{pseudo}.
    Useful if you've used some code that modifies \cs{\bslash} for its own
    purposes (such as \cs{raggedleft} or the like).
\end{docCommand}

\begin{docCommand}{RestorePseudoEq}{}
    Similar to \refc{RestorePseudoBackslash}. Switches the definition of \cs{=}
    to the one used by \pkg{pseudo}. Useful if \cs{=} reverts to its original
    definition in some context (see \refc{==}).
\end{docCommand}

\begin{docCommand}{rng}{}
    Used to typeset a range, slice or subarray, or simply to indicate the
    indices of an array, similar to \refc{dts}, but using a colon rather than
    two dots placed horizontally. Uses the same spacing as \refc{dts}, as
    opposed to a plain \code{:}, which adds more space (more suitable, for
    example, to set-builder notation).
\begin{texexp}
Compare $A[1\rng n]$ to $A[1:n]$.
\end{texexp}
\end{docCommand}

\begin{docKey}{setup}{\,=\,\meta{commands}}{no default}
    The setup part of each pseudocode line: Save the line counter
    (using the \refc{pseudosavelabel} command), insert the proper indentation
    (with \refc{pseudoindent}) and switch to the correct font
    (\refc{pseudofont}).

    \medskip

    Rather than setting \refk{setup} directly, you may wish to add commands
    using \refk{setup-append} or \refk{setup-prepend}.
\end{docKey}

\begin{docKey}{setup-append}{\,=\,\meta{commands}}{no default}
    Locally appends \meta{commands} to \refk{setup}.
\end{docKey}

\begin{docKey}{setup-prepend}{\,=\,\meta{commands}}{no default}
    Similar to \refk{setup-append}, except that \meta{commands} are added to
    the \emph{beginning} of \refk{setup}.
\end{docKey}

\begin{docCommand}{st}{\marg{string}}
    Typesets \meta{string} with added quotes using \refc{stfont}. (The entire
    thing is wrapped in \cs{textnormal}.) For example, \code*{print
    \cs{st}\braces{42}} yields:
    \begin{pseudo*}
        print \st{42}
    \end{pseudo*}
    See also \refc{DeclarePseudoString}.
    \fontutil{strings}
    \pseudoshortcutted{st}
\end{docCommand}

\begin{docKey}{st-left}{\,=\,\meta{text}}{no default, initially \code{``}}
    \leftbracketing{string}{st}
\end{docKey}

\begin{docKey}{st-right}{\,=\,\meta{text}}{no default, initially \code{''}}
    \rightbracketing{string}{st}
\end{docKey}


\begin{docKey}{starred}{}{\novaluekey}
    The style (defined by \refc{pseudodefinestyle}) used by the \refe{pseudo*}
    environment. You may modify this (again using \refc{pseudodefinestyle}) if
    you wish.
\end{docKey}

\begin{docKey}{start}{\,=\,\meta{number}}{no default, initially \code{1}}
    Sets the starting line number:
\begin{texexp}
\begin{pseudo}[start=10]
Maybe we're continuing from some earlier code?  \\
Anyway, let's keep going!
\end{pseudo}
\end{texexp}
See also \refk{indent-level}.
\end{docKey}

\begin{docKey}{stfont}{}{}
    \fontkey{st}
\end{docKey}

\begin{docCommand}{stfont}{}
    \fontcmd{st}
\end{docCommand}

\begin{docCommand}{tn}{\marg{text}}
    An alias for \cs{textnormal}, to break out of the font set using the
    \refKey*{font} key, for inserting ordinary prose between the keywords. For
    example, to get the result ``{\kwfont for \tn{every node} $v\in V$}'', one
    might write:

    \medskip

    \centerline{\code{for \cs{tn}\braces{every node} \$v\cs{in} V\$}}

    \medskip

    This is equivalent to using \code*{\cs{textnormal}\braces{every node}}.
    \shortcutted{tn}{textnormal}
\end{docCommand}

\begin{docKey}{topsep}{\,=\,\meta{length}}{\initialkeyvalue{\cs{topsep}}}
    Sets a \pkg{pseudo}-local copy of \cs{topsep} for use in vertical spacing
    above and below the \refe{pseudo} environment. See also \refk{compact}.
\end{docKey}

\begin{docKey}{unknown}{}{}
    \parindent1.5em
    \noindent
    Unknown keys are checked for \pkg{beamer} overlay specifications. That is,
    if an unknown key has the form

    \medskip

    \centerline{\code*{\meta{name}<\meta{overlay
    specification}> = \meta{value}}}

    \medskip

    \noindent
    then it does not trigger an error, but, if \pkg{beamer} is used, is
    rewritten to:

    \medskip

    \centerline{\code*{\cs{only}<\meta{overlay specification}>\braces{%
        \refc{pseudoset}\braces{\meta{name} = \meta{value}}%
    }}}

    \medskip

    \noindent
    If \pkg{beamer} is \emph{not} used, the key is simply ignored. Note that
    because of current limitations on how keys are handled,
    % Cf. https://github.com/latex3/latex3/issues/67
    unknown keys cannot have defaults, and so there is no way to insert a
    marker for when no value is provided, which could be used to determine
    whether to use
    \code*{\refc{pseudoset}\braces{\meta{name} = \meta{value}}}
    or simply
    \code*{\refc{pseudoset}\braces{\meta{name}}}. Instead, if an empty value
    is provided to the unknown key, that is treated in the same way as when
    the key is used
    without a value, resulting in
    \code*{\refc{pseudoset}\braces{\meta{name}}}
    rather than
    \code*{\refc{pseudoset}\braces{\meta{name} = }}.

    If an unknown key does \emph{not} take the form of a key with an overlay
    specification, a second special case is also handled: If we're processing
    arguments for \refc{\bslash}, and the key does not have an associated
    (non-blank) value, we treat the key instead as a \emph{value}, whose
    implicit key is \refk{extra-space}. This means that you can specify extra
    space in the ordinary way, with \code{\cs{\bslash}[1.5ex]}, etc.
\end{docKey}

\section{But how do I\,\dots}

Some functionality is not built in, but is still fairly easy to achieve. Some
streamlining may be added in future versions.

\subsection{\dots\,prevent paragraph indentation after \code{pseudo}?}

If you want to keep the pseudocode as part of a surrounding paragraph, you
could have it not start its own, i.e., not have an empty line before it. This
will reduce the amount of spacing as well; if you'd rather have that reduced,
you could simply drop the empty line \emph{after} the environment:

\begin{texexp}[listing]
Text before

\begin{pseudo}
    pseudocode
\end{pseudo}
%
Text after
\end{texexp}

\noindent
The effect would then be the following:

\begin{pseudo}
    pseudocode
\end{pseudo}
%
No indentation here, and normal spacing. If, however, you wish to suppress
indentation after \emph{all} instances of \refe{pseudo}, you could use the
\pkg{noindentafter} package, as follows:

\medskip

\begin{texexp}[listing]
\usepackage{noindentafter}
\NoIndentAfterEnv{pseudo}
\NoIndentAfterEnv{pseudo*}
\end{texexp}

\noindent
If you wish to override this, and indent a given paragraph after all, you can
simply use the \cs{indent} command.

\subsection{\dots\,get log-like functions?}

There's no built-in command for math-roman function names, as used in $\log$
and $\sin$, etc. (other than just setting \refk{fnfont}, if you want it
everywhere). If you wish to define your own, you could use \cs{operatorname}
or \cs{DeclareMathOperator}. For example:

\begin{texexp}
% In document preamble:
% \usepackage{amsmath}
% \DeclareMathOperator{\MyFunc}{my-func}
\begin{pseudo}[kw]
if $\MyFunc x \== 1$ \\+
    $y = \MyFunc(z + 1)$
\end{pseudo}
\end{texexp}

\noindent
The spacing is then correct whether you enclose the arguments in parentheses
or not.

\subsection{\dots\,unbold punctuation?}

If you use the \refk{kw} key, all pseudocode not in math mode will end up
using the keyword font (\refc{kwfont}), which initially is bold. Though some
\emph{do} typeset, e.g., grouping braces in boldface, you might not want to do
that; the same goes for, say, line-terminating semicolons. The
\code{theoremfont} option of, e.g., \pkg{newtx} does something similar (for
italics), but uses a custom font for that. Packages like \pkg{emrac} rely on
straightforward textual substitution, replacing certain characters with
marked-up ones, but the way things are set up at the moment, our font command
won't have access to the entire line when it's executed.

If you're adventurous, it's not hard (using the \pkg{xparse} argument type
\code{u}) to make a version that \emph{does} gobble up the entire line, up to
and including \verb|\\| (and you could then use the regular expression
functionality from \pkg{expl3}, presumably also reinserting \refc{\bslash}). A
simpler solution is to just use \refc{DeclarePseudoNormal}. Here's an example
based on pseudocode from \citet{Knuth:1975}:

\begin{texexp}
% In document preamble:
% \usepackage{mathtools}
\let\gets\coloneqq

\pseudoset{kw, indent-length=2em, line-height=1.1}

\DeclarePseudoNormal \; ;

\begin{pseudo*}
procedure \id{printstatistics}\;                            \\
begin integer $j$\;                                         \\+
    \fn{write}(\st{Closed sets for rank}, r, \st{:})\;      \\
    $j \gets L[h]$\;                                        \\
    while $j \neq h$ do                                     \\+
        begin \fn{writeon}(S[j])\; $j\gets L[j]$ end\;      \\--
end\;
\end{pseudo*}
\end{texexp}

\noindent
If you'd really like to avoid the extra backslashes, you could make the
relevant punctuation active (though that's probably a bit risky; make sure to
only do it locally, at the very least):

\begin{texexp}
\DeclarePseudoNormal \semi ;

\catcode`\;=\active
\let;\semi

\begin{pseudo*}[kw]
    begin integer $j$; % Look! The semicolon isn't bold!
\end{pseudo*}
\end{texexp}

\subsection{\dots\,use \codefont{tabularx}?}
\label{sec:tabularx}

You can use other tabular packages such as \pkg{tabularx} via
\refk{begin-tabular} and \refk{end-tabular}. Let's say, for example, that you
wish to extend the \refe{pseudo} environment to fill out the entire line, and
set up a new column for comments. You could achieve that as follows:

\label{p:fullwidth}
\begin{texexp}
\pseudodefinestyle{fullwidth}{
    begin-tabular =
    \tabularx{\linewidth}[t]{@{}
        r                                      % Labels
        >{\pseudosetup}                        % Indent, font, ...
        X                                      % Code (flexible)
        >{\leavevmode\small\color{gray}}       % Comment styling
        p{0.5\linewidth}                       % Comments (fixed)
        @{}},
    end-tabular = \endtabularx,
    setup-append = \RestorePseudoEq
}
\begin{pseudo}[kw, fullwidth, line-height=1.1]*
    \hd{Counting-Sort}(A, k) & Find positions by counting \\
    $C = \tn{an array of $k$ zeros}$ & Element frequencies \\
    for $i = 1$ to $A.\id{length}$ & Count all elements \\+
    $\dots$ & Etc.
\end{pseudo}
\end{texexp}
%
Note that using the \cs{color} command in a \code{>\braces{\dots}}
modifier with a \code{p} column places the text in a new paragraph, on the
next line; you'll need to insert \cs{leavevmode} or the like to prevent that.
This is true also of normal \code{tabular} environments. Also note
that \code{tabularx} environments with \code{X} columns don't interact nicely
with \cs{=}; so if you wish to use \refc{==}, you can reassert the definition
by adding \code{>\braces{\refc{RestorePseudoEq}}} before each
column.\footnote{You can also, of course, just use \refc{eqs} instead.}

See the \pkg{tabularx} documentation (page~4) for an explanation of why we can't
use \code{\cs{begin}\braces{tabularx}} and \code{\cs{end}\braces{tabularx}}.
Also note that because \pkg{tabularx} passes its contents as the argument to a
macro, the parsing \pkg{pseudo} uses to determine if \refc{\bslash} is at the
end of the last line doesn't work; if you add \refc{\bslash} at the end here,
you'll introduce an empty line.

\makeatletter
For simplicity, I've used \code{@\braces{}} to remove space on either side.
For \refk{hpad} to work, you should use \code{>\braces{\cs{pseudohpad}}} and
\code{<\braces{\cs{pseudohpad}}} instead, as in the standard \refk{preamble}
(see \cpageref{p:preamble}). To keep things configurable, you might also want
to use \cs{pseudolabelalign}, rather than \code{r}.
\makeatother


\subsection{\dots\,get tab stops?}
\label{sec:tabstops}

Some packages, such as \pkg{clrscode3e}, use an actual \code{tabbing}
environment internally. While this may be a bit brittle (e.g., creating problems
if you wish to insert your pseudocode into a
\pkg[https://ctan.org/pkg/pgf]{tikz} node---one of the goals of \pkg{pseudo}),
it does mean that you can use the tabbing command \cs{>} manually, to align
various construct.

If all your tabbing is done \emph{before} the text on a given code line, you
can achieve this in \pkg{pseudo} as well, by using the \code{+} and \code{-}
modifiers. (For example, the tab stops in \pkg{clrscode3e} are set at fixed
intervals, just like in \pkg{pseudo}.) But what if you'd like to align something
that comes later, such as comments after code lines? You can't simply use
\cs{hspace}, of course, unless the code lines themselves have exactly the same
length.

One solution is to use an additional column, as discussed in
\cref{sec:tabularx}, but you could also make creative use of the \cs{rlap}
command, which prevents its contents from taking up horizontal space:%
\footnote{Note that \cs{rlap} doesn't start a new paragraph, which is why I
use \cs{noindent}, here. You could replace
\code{\cs{noindent}\cs{rlap}\braces{\dots}} with
\code{\cs{makebox}[0pt][l]\braces{\dots}}. This isn't an issue in
\code{pseudo} code lines, however.}

\begin{texexp}
\noindent\rlap{This is some text}%
And here is some more
\end{texexp}

\noindent
By using \cs{rlap} on the code lines in question, you can insert \cs{hspace}
that begins at the beginning of the code line (here with an example
convenience command defined using \pkg{xparse}):

\begin{texexp}
\NewDocumentCommand \C { +u{/* } +u{ */} } {%
    \rlap{#1}\hspace{3cm}\ct{#2}\\%
}
\begin{pseudo}
\C $x = 42$      /* first comment */
\C $y = \sin x$  /* second comment */
\end{pseudo}
\end{texexp}

\noindent
See also the discussion of the \refc{ct} command for ideas on typesetting
comments. If you wish to align things across different indentation levels,
you'll have to add or subtract multiples of \cs{pseudoindentlength} (see
\refc{pseudoindent}).

Another option for aligning comments or the like is to use a custom \cs{tabular}
or \cs{tabular}-like environment, where the aligned material is placed in a
column of its own. This is the technique used in \cref{alg:gnome}, for example.
For more on this approach, see \cref{sec:tabularx}.

If you want alignment or tabbing \emph{outside} the \refe{pseudo} environment,
for example, to align the input and output descriptions inside a
\code{tcolorbox} (cf.\@ \cref{sec:floats}), an excellent alternative is the
\pkg{tabto} package.
%
You could also use other constructs, such as a \code{tabular}, \code{tabbing} or
\code{description}. An advantage of the \pkg{tabto} solution is that you retain
the paragraph spacing set up by the \pkg{tcolorbox} styles defined by
\pkg{pseudo}.

You can simply define the tab stops globally, using \cs{TabPositions} in your
preamble, or you can do it as part of the box setup, e.g.,. using
\refk{pseudo/init} when defining your \pkg{tcolorbox} environment with
\cs{newtcbtheorem} (or, as in the following simplified example,
just supply it directly as an option to the box environment).

\begin{texexp}
% In document preamble:
% \usepackage{tabto}
\begin{tcolorbox}[pseudo/filled,
    pseudo/init = {\TabPositions{1.5cm}}]

\textbf{Data}
    \tab A graph $G=(V,E)$ with weight function $w:E\to\mathbf{R}$

    \tab A start node $s\in V$

\textbf{Require}
    \tab No negative cycle in $G$ is reachable from $s$

\textbf{Result}
    \tab An matrix $D$ of distances between the vertices in $V$

\begin{pseudo}
\dots
\end{pseudo}
\end{tcolorbox}
\end{texexp}


\subsection{\dots\,use horizontal lines?}
\label{sec:horizontallines}

Many opt for a table-like appearance when typesetting algorithms, with
horizontal lines above and below, and generally a header row on top. While
this may be part of a surrounding floating environment (see
\cref{sec:floats}), you may also wish to include such lines in your actual
pseudocode. In this case, you can simply use existing \code{tabular}-based
tools such as \pkg{booktabs}, making sure to suppress the \pkg{pseudo}
\refk{prefix} using the star flag (\code{*}):

\begin{texexp}
% \usepackage{booktabs}
\begin{pseudo}*
\toprule

    \hd{Bor\r{u}vka}(G, w)                      \\
                                                %
[bol=\midrule]

    \kw{while} $E(G)$ is not empty              \\+
        \kw{for} each $u\in V(G)$               \\+
            add light $uv \in E(G)$ to $T$      \\-
        \kw{for} each $e \in T$                 \\+
            contract $e$                        \\*

\bottomrule
\end{pseudo}
\end{texexp}

\noindent
Rather than \code{\cs{\bslash}[bol=\cs{midrule}]}, you could also have used
\code{\cs{\bslash}*}, followed by \code{\cs{midrule}\cs{pseudoprefix}}. (Note
that the paragraph break between \refc{\bslash} and its argument has been
commented out.)

\subsection{\dots\,handle object attributes?}

In the \pkg{clrscode3e} package, you'll find an assortment of commands for
handling object attributes such as $A.\id{length}$. The manual says (here with
emulated kerning of the dot operator):

\begin{quote}
    You might think you could typeset $A\mkern1mu.\id{length}$ by
    \code{\$A.\cs{id}\braces{length}\$}, but that would produce
    $A\mkern1mu.\mkern-1.5mu\id{length}$, which has not quite enough space
    after the dot. \hfill(page~3)
\end{quote}

\noindent
However, this is a font issue, more than anything. If, for example, if you
want Times New Roman (like Cormen et al.)\@ and use \pkg{mathptm}, you at times
run into the problem described; with \pkg{newtx} it's less pronounced. With
other fonts (e.g., \pkg{fourier}, \pkg{mathpple} or \pkg{newtxmath} with
\pkg{libertine}), or even without any font packages (or possibly using
\pkg{lmodern}), the kerning works just fine.

In general, then, I suggest you try to use \code{\$A.\cs{id}\braces{length}\$}
and the like, and see if the result is satisfactory:

\begin{texexp}
$v.\id{prev}.\id{next} = v.\id{next}$
\end{texexp}

\noindent
If you \emph{do} need to adjust the kerning (with \cs{mkern} commands or
perhaps using \pkg{microtype}), you may of course do so, but \pkg{pseudo} does
not (at present) include any special attribute lookup commands that do it for
you.

\subsection{\dots\,indicate blocks with braces or the like?}

Some packages (such as \pkg{algorithm2e}) have support for using vertical lines
to indicate the block structure;
\pkg[https://ctan.org/tex-archive/macros/latex/contrib/pseudocode]{pseudocode}
uses large braces. In \pkg{pseudo}, there is support for using an
\refk{indent-mark}, for which the default is a semithick, gray vertical line
(see \cpageref{p:indent-mark}). However, by using
\pkg[https://ctan.org/pkg/pgf]{tikz}, you could draw all kinds of indentation
decorations.

You could, for example, add a \code{node} at the start of each code line,
containing an \verb|\@arstrut|, the (\pkg{array}) strut used to indicate the
extent of a tabular row:

% ! Contents duplicated
\makeatletter
\NewDocumentCommand \pseudoanchor { m } {%
    \tikz[baseline, overlay, remember picture]
        \node[anchor=base, inner sep=0] (#1) {\@arstrut};%
    \ignorespaces
}
\makeatother
\begin{texexp}[listing]
% \usepackage{xparse,tikz}
% \usetikzlibrary{decorations.pathreplacing,calligraphy}
\makeatletter
\NewDocumentCommand \pseudoanchor { m } {%
    \tikz[baseline, overlay, remember picture]
        \node[anchor=base, inner sep=0] (#1) {\@arstrut};%
    \ignorespaces
}
\makeatother
\end{texexp}

\noindent
You can then use the resulting nodes to draw braces or lines or whatever. First
some example setup:

% ! Duplicated
\begin{texexp}[listing]
\pseudoset{
    kw,
    indent-length = 3.5em,
    setup-append = {\pseudoanchor{L-\arabic*}}
}
\tikzset{
    braces/.style =
    {thick, decoration = {calligraphic brace, raise=.2em}},
    label/.style =
    {midway, left=3em, anchor=west, font=\strut\kwfont}
}
\end{texexp}
You would then get something like the following:
{
\pseudoset{
    kw,
    indent-length = 3.5em,
    setup-append = {\pseudoanchor{L-\arabic*}}
}
\tikzset{
    braces/.style =
    {thick, decoration = {calligraphic brace, raise=.2em}},
    label/.style =
    {midway, left=3em, anchor=west, font=\strut\kwfont}
}
\begin{texexp}
\begin{pseudo}
if $x < y$                                      \\+
    $x = y$                                     \\
    $y = 0$
\end{pseudo}
\tikz[overlay, remember picture, braces] {
    \draw[decorate] (L-3.south) -- (L-2.north) node[label] {then};
}
\end{texexp}
}

\noindent
If multiple blocks are closed at the same time, the bottom coordinates could be
things like \code*{(L-2.north |- L-3.south)} instead. To adjust the end
points, you could also use things like \code{(\$(L-3.south)+(0,.2em)\$)}.

The actual drawing of the brace (or line or whatever) isn't automated here, of
course. This could be done by some hook triggered by the \code{-} flags in
\refc{\bslash}. If it turns out there's a demand for something like that, I
might add it in a future version.

\subsection{\dots\,use \pkg{pseudo} with older \TeX\ distributions?}
\label{sec:older}

As mentioned in the introduction, I've tried to make \pkg{pseudo} work with at
least \emph{somewhat} outdated \TeX\ distributions. In these cases, the package
itself won't be available as part of the distribution, of course, but you can
simply download the file
\codefont{\href{http://mirrors.ctan.org/macros/latex/contrib/pseudo/pseudo.sty}%
{pseudo.sty}} and place it in the directory where you're compiling your document
(or anywhere else where your \LaTeX\ executable can find it).

However, there may be cases where this just doesn't work, such as when
submitting to a publisher with a really old setup.\footnote{If possible,
though, feel free to
\href{https://github.com/mlhetland/pseudo.sty/issues}{file an issue} or
\href{https://github.com/mlhetland/pseudo.sty/pulls}{provide a pull request}
to address the issue.}
In that case, the simplest solution is probably to use the
\pkg{standalone} package to produce individual PDFs of your algorithms, and then
to include those in your document. Then you can submit the PDFs rather than the
\LaTeX, so that the pseudocode need not be compiled on the old system. Each
algorithm could go in a file like this:

\begin{texexp}[listing]
\documentclass{standalone}
\usepackage{pseudo}
\begin{document}
\begin{pseudo}
    ...
\end{pseudo}
\end{document}
\end{texexp}

\noindent
Let's say this is compiled to \codefont{algo1.pdf}. You then include this file:

\begin{texexp}[listing]
\documentclass{article}
\usepackage{graphicx} % For \includegraphics
...
\begin{document}
... sanctus est Lorem ipsum dolor sit amet:

\medskip\noindent
\includegraphics{algo1.pdf}

\smallskip
Lorem ipsum dolor sit amet, consetetur sadipscing ...
\end{document}
\end{texexp}

\noindent
Of course, you can adjust the spacing (e.g., using \verb|\vspace| or the like)
to your liking. Using this method, you can can achieve results essentially
identical to if you compiled the pseudocode directly as part of the document.
Of course, you won't have access to other functionality (such as
\verb|\DeclarePseudoIdentifier| or the like) for use in the main tex, but most
of that should be possible to emulate by hand (possibly peeking at the
implementation in \cref{sec:impl}).

\subsection{\dots\,use a header with no arguments?}

Normally, \refc{hd} has a mandatory set of arguments; at the very least,
you'll need to supply the parentheses:

\begin{texexp}
\begin{pseudo}*
\hd{No-Arguments}() \\
\dots\ but still with parentheses
\end{pseudo}
\end{texexp}

\noindent
This is because \refc{hd} has to be fully expandable to be able to insert the
requisite \cs{multicolumn}, and then it cannot have any (final) optional
arguments. If you'd like, though, you can just use \cs{multicolumn} yourself
(see also \refk{hd-preamble}):

\begin{texexp}
\begin{pseudo}*
\multicolumn{2}{\pseudohdpreamble}
{\pr{No-Arguments}} \\
\dots\ and no parentheses!
\end{pseudo}
\end{texexp}

\subsection{\dots\,place algorithm boxes side by side?}

In the simplest case, maybe you just want to place two of them side by side in
the text (i.e., not as floats). Let's say you've defined an environment as
follows:

% Duplicated:
\newtcbtheorem{procedure}{Procedure}{pseudo/filled}{}
\begin{texexp}[listing]
\newtcbtheorem{procedure}{Procedure}{pseudo/filled}{}
\end{texexp}

Two of these cannot directly be placed side by side, because each will insert
paragraph breaks and spacing before and after itself. However, this code can be
disabled by using the \pkg{tcolorbox} keys \code{before} and \code{after} (along
with \code{width}, to make sure there's room. If we also want the boxes to have
the same height, we can use the key \code*{equal height group} (with some
arbitrary name):

\begin{texexp}
\begin{procedure}[after={}, width=.49\linewidth,
    equal height group=A]{}{}
\begin{pseudo}
Foo \\ Bar \\ Baz
\end{pseudo}
\end{procedure}
\hfill
\begin{procedure}[before={}, width=.49\linewidth,
    equal height group=A]{}{}
\begin{pseudo}
Frozz \\ Bozz
\end{pseudo}
\end{procedure}
\end{texexp}

\noindent
If the boxes are floats (i.e., either defined or used with the \pkg{tcolorbox}
key \code{float}, you can still use the \code*{equal height group} key. This is
useful, for example, in a twocolumn layout, if the boxes are at the top (or
bottom), one in each column.

Finally, if your boxes are floats in general, you're using a single-column
layout, and you want two boxes to float \emph{together}, side by side (e.g.,
because the pseudocode itself takes up little horizontal space), you can use the
first technique (setting \code{width}, \code{before} and \code{after}) along
with the \pkg{tcolorbox} key \code{nofloat}, and then place the boxes inside
some other float (such as a normal \LaTeX\@ \code{figure}, or a custom one using
the \pkg[https://ctan.org/tex-archive/macros/latex/contrib/float]{float}
package):

\begin{texexp}[listing]
\begin{figure}
\begin{procedure}[nofloat, after={}, width=.49\linewidth,
    equal height group=A]{}{}
\begin{pseudo}
    % ...
\end{pseudo}
\end{procedure}
\hfill
\begin{procedure}[nofloat, after={}, width=.49\linewidth,
    equal height group=A]{}{}
\begin{pseudo}
    % ...
\end{pseudo}
\end{procedure}
\end{figure}
\end{texexp}

\subsection{\dots\,have steps span multiple lines?}

First of all, you can do this by just breaking your lines manually, keeping any
additional lines belonging to the same step unnumbered, by using the starred
version of \refc{\bslash} (and skipping the number column with \code{\&}):
adding unnumbered lines:
\begin{texexp}
\begin{pseudo}[line-height=1.1]
  This step is broken\,\dots                    \\*
& \dots\,into multiple lines                    \\
  This one is not
\end{pseudo}
\end{texexp}
If you want the line breaking to be automated, you can use a \code{p} column,
specified in \refk{preamble} (perhaps defining a style using
\refc{pseudodefinestyle}), adapted from the default:\footnote{The default is
found on p.~\pageref{p:preamble}. However, in the source code there, whitespace
is insignificant. If writing your own preamble, you should avoid spurious
whitespace inside \code{>\braces{\dots}} and \code{<\braces{\dots}}.}
\begin{texexp}
\begin{pseudo}[preamble = {
        >{\pseudohpad} \pseudolabelalign
        >{\pseudosetup} p{11.7cm} <{\pseudohpad}
    },
    setup-append = \raggedright\RestorePseudoBackslash,
    line-height = 1.5]
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam
nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam
erat. \\
At vero eos et accusam et justo duo dolores et ea rebum. Stet
clita kasd gubergren, no sea takimata sanctus est Lorem ipsum
dolor sit amet.
\end{pseudo}
\end{texexp}

\noindent
In addition to introducing the \code{p} column, I've added \cs{raggedright} to
the setup (with \refk{setup-append}, with \cs{RestorePseudoBackslash} to restore
\refc{\bslash}, because \cs{raggedright} redefines it).

One disadvantage of the \code{p} column is that you need to know its exact
width. A better solution is probably to replace the default \code{tabular} with
a \code{tabularx}, as discussed in \cref{sec:tabularx}, and use an \code{X}
column, i.e.:
\begin{texexp}[listing]
    begin-tabular = \tabularx{\linewidth}[t]{
        >{\pseudohpad} \pseudolabelalign
        >{\pseudosetup} X <{\pseudohpad}
    },
    end-tabular = \endtabularx,
    setup-append = \RestorePseudoEq,
\end{texexp}


\subsection{\dots\,get the old spacing?}

The current version of the \refe{pseudo} environment ensures the spacing above
and below is adjusted, so the baselines of the previous and following lines are
positioned equally, regardless of their depths or heights. If you'd rather have
the old behavior (which, frankly, was really a bug), you can get that as
follows:
\begin{texexp}
\pseudoset{pos = {}, prevdepth = 0pt}
\end{texexp}


\subsection{\dots\,configure my \code{tcolorbox}es?}
\label{sec:boxconfig}

If you use the \pkg{pseudo} styles for \code{tcolorbox}es (see
\cref{sec:floats}), you might still wish to do some tweaking, or even redefine
most of the styling. This is done using the \pkg{tcolorbox} configuration
system, not that of \pkg{pseudo}, so it's worth consulting the \pkg{tcolorbox}
documentation (and, perhaps, the source of the \pkg{pseudo} box styles, in
\cref{sec:floatsrc}). In the following, I go through some examples of things you
might want to adjust. First, let's define a rather unstyled environment which we
can modify locally.\footnote{If you want the styling to apply to the environment
in general, simply insert it as the third argument. See the \pkg{tcolorbox}
documentation for more about \cs{newtcbtheorem}.}

% Duplicated:
\newtcbtheorem{example}{Example}{}{}
\begin{texexp}[listing]
\newtcbtheorem{example}{Example}{}{}
\end{texexp}

\paragraph{A different separator.} By default, the \pkg{pseudo} box styles use
an \cs{enskip} to separate the label part from the description, but you might
want to use something else, such as a colon or a period. You can get this by
using the \code*{separator sign} key:
\begin{texexp}
\begin{example}[pseudo/ruled, separator sign = :]{\dots}{}
    \dots
\end{example}
\end{texexp}

\paragraph{A different parskip.} You might want more or less spacing between the
paragraphs of any plain text outside your pseudocode. You do this by setting
\cs{parskip}, which is normally set as part of the \code*{before upper} key in
the \code{pseudo/\dots} styles (see p.~\ref{p:before-upper}). Rather than
overwrite the \code*{before upper} code, you can use the hook \refk{pseudo/init}
(set as part of the \pkg{tcolorbox} configuration, not using \cs{pseudoset}):%
\footnote{It is possible to use the \pkg{tcolorbox} key \code*{before upper app}
(together with the \pkg{tcolorbox} library \code{hooks}) instead of
\refk{pseudo/init}. However, the compatibility code (\cref{sec:compat}) appends
some spacing to this setup hook, and this may be messed up by inserting more
code after it. In this case, \refk{pseudo/init} is safer.}
\begin{texexp}
\begin{example}[pseudo/boxed,
    pseudo/init = \parskip\baselineskip]{\dots}{}
    The parskip

    is bigger!
\end{example}
\end{texexp}
You \emph{could} set \cs{topsep} and \cs{partopsep} in the same manner, but
unless you want to change the settings for lists (such as \code{itemize} and
\code{enumerate}), you could also just set those for pseudocode specifically,
using the \pkg{pseudo} keys \refk{topsep} and \refk{partopsep}, perhaps as part
of the \refk{in-float} style.

\bigskip

\paragraph{Different line widths.} If you start with \refk{pseudo/boxruled},
this is easy enough---you can just use the standard \pkg{tcolorbox} keys to
adjust the line widths.
\begin{texexp}
\begin{example}[pseudo/boxruled,
    boxrule = 4pt, titlerule = 2pt]{\dots}{}
    Now \emph{that's} a \emph{box}!
\end{example}
\end{texexp}
The problem with the other ruled or boxed styles is that they use the
\code{empty} skin, which removes the box drawing.\footnote{The reason they don't
just set the appropriate line widths to zero is that this generally still
results in visible hairlines in many PDF viewers.}
They then instead rely on various \code{borderline} commands. These are
cumulative, so if you want to replace some of them, you first need to clear the
deck with \code*{no borderline}, and then re-do them all. For example, maybe you
want a version of \refk{pseudo/tworuled} with light rules:
\begin{texexp}
\begin{example}[pseudo/tworuled,
    no borderline,
    toprule = \lightrulewidth,
    bottomrule = \lightrulewidth,
    borderline horizontal = {\lightrulewidth}{0pt}{black}]{\dots}{}
\dots
\end{example}
\end{texexp}
Note that even though the box rules aren't \emph{drawn}, they can still be used
for spacing---which the borderlines don't handle. In \code{pseudo/tworuled},
\code{toprule} and \code{bottomrule} are set to \cs{heavyrulewidth}, so since
we're replacing the horizontal borderlines with lighter ones, we need adjust
these as well. (If you do something similar with \refk{pseudo/ruled}, the width
of the title rule can still be changed by using the \code{titlerule} key, as in
the previous example.)

\bigskip

\paragraph{Different colors.} Again, customizing \code{pseudo/boxruled} is easy
enough; you can set the line colors using the \code{colframe}, and the fill
colors using \code{colback} and \code{colbacktitle}. The latter two keys also
work well with the \code{pseudo/filled} style (as shown in the example
\vpageref{ex:clrscode4ish}). To modify the line colors in the other styles,
you'll need borderline commands, again (though with separate styling for the
title rule). For example:
\begin{texexp}
\begin{example}[pseudo/booktabs,
    no borderline,
    titlerule style = lightgray,
    borderline horizontal = {\heavyrulewidth}{0pt}{gray}]{\dots}{}
\dots
\end{example}
\end{texexp}
If you want to style the top and bottom line separately, just use
\code*{borderline north} and \code*{borderline south} separately, rather than
the collective \code*{borderline horizontal}.

\section{Implementation}
\label{sec:impl}

\lstdefinestyle{tcblatex}{language={[LaTeX]TeX},
    aboveskip={0\p@ \@plus 6\p@},
    belowskip={0\p@ \@plus 6\p@},
    columns=fullflexible,
    keepspaces=true,
    breaklines=true,
    breakatwhitespace=true,
    basicstyle=\ttfamily\small\color{black!80},
    keywordstyle=,
    extendedchars=true,
    nolol,
    inputencoding=\kvtcb@listingencoding,
    literate={VERSION}{\pseudoversion}{3}{DATE}{\pseudodate}{10}%
    {~}{\textcolor{gray}{\raisebox{-.75ex}{\textasciitilde}}}{1},
    commentstyle=\color{gray},
}

\noindent
\textbf{Note:} In the following, \verb|_@@| and \verb|@@| represent
an internal prefix (\verb|__pseudo|), the same way they do with
\pkg{l3docstrip}.

\bigskip\noindent
First, we just define some metadata:
\begin{source}
\def \pseudoversion {VERSION}
\def \pseudodate    {DATE}
\end{source}
The \pkg{pseudo} package is implemented using experimental \LaTeX\,3, so we
start by importing \pkg{expl3}:
\begin{source}
\RequirePackage{expl3}
\end{source}
Then we're ready start the package:
\begin{source}
\ProvidesExplPackage
    {pseudo}
    {\pseudodate}
    {\pseudoversion}
    {Straightforward pseudocode}
\end{source}
Tools for defining user commands:
\begin{source}
\RequirePackage{xparse}
\end{source}
For defining \pkg{tcolorbox} styles, without importing \pkg{tcolorbox}:
\begin{source}
\RequirePackage{pgfkeys}
\end{source}
The \refe{pseudo} environment is built upon tabular functionality, and we're
using some extensions:
\begin{source}
\RequirePackage{array, xcolor, colortbl}
\end{source}
Though \emph{most} keys aren't available as \cs{usepackage} arguments, we
still use the mechanism:
\begin{source}
\RequirePackage{l3keys2e}
\end{source}
Inside the \refe{pseudo} environment, \refk{*} is an alias for
\refk{pseudoline}. To perform the proper aliasing, we use \pkg{aliascnt}:
\begin{source}
\RequirePackage{aliascnt}
\end{source}
As part of the initial setup, we also record whether we're part of a
\pkg{beamer} presentation; this will affect the overlay functionality:
\begin{source}
\bool_new:N \c_@@_beamer_bool
\@ifclassloaded{beamer}
    {\bool_set_true:N  \c_@@_beamer_bool}
    {\bool_set_false:N \c_@@_beamer_bool}
\end{source}
We're now ready to begin the actual implementation.

\subsection{Variable declarations}

Many variables are created as needed by various \code{set} commands, but some
are declared initially. First, we create a plain-vanilla \LaTeX\ counter for
the line number, as well as an outer one for the environment, the latter just
to avoid duplicate labels:
\begin{source}
\newcounter{pseudoenv}
\newcounter{pseudoline}[pseudoenv]
\end{source}
Eventually, we'll be saving the line counter so that \cs{label} commands will
work, but we'll only do so if the counter has \emph{changed} (again, to avoid
duplicate labels). To determine whether, in fact, it has, we keep the previous
one we saved:
\begin{source}
\int_new:N \g_@@_last_saved_line_int
\end{source}
Normally a counter is just saved when it's incremented (with
\cs{refstepcounter}), but in our case, we want to increment and typeset it
based on a (potentially) user-configured \refk{label}, and then actually save
it and make it the target of \cs{label} commands in a \emph{different scope}
(i.e., the next cell in the tabular row).

\bigpar

The indent size is set through the configuration key \refk{indent-length} (or
indirectly through \refk{indent-text}), while the current indent level is
manipulated by \refc{\bslash}; their product determines the actual length by
which the current line is indented. The initial indent level may be set using
\refk{indent-level}.
\begin{source}
\dim_new:N  \pseudoindentlength
\int_new:N  \g_@@_indent_level_int
\int_new:N  \l_@@_initial_indent_level_int
\end{source}

When handling unknown keys, we have special-casing of \refc{\bslash}, so we need
to know if that's the command we're in:
\begin{source}
\bool_new:N \l_@@_in_eol_bool
\end{source}

\subsection{Utilities}

\paragraph{Variants.} First, let's just generate a couple of expansion
variants we'll need of some standard commands. (I'm using the
\verb|\q_no_value| machinery rather than \verb|\c_novalue_tl| for
compatibility with older \TeX\ distributions.)
\begin{source}
\cs_generate_variant:Nn \quark_if_no_value:nTF    { VTF    }
\cs_generate_variant:Nn \tl_if_novalue:nTF        { VTF    }
\cs_generate_variant:Nn \tl_set:Nn                { Ne     }
\exp_args_generate:n                              { NNVNNV }
\end{source}
\paragraph{Defining columns.} The \refk{preamble} is is configurable, but the
\pkg{array} package makes sure it doesn't expand any part of its preamble. One
way of inserting a dynamically generated one is to simply define it all as a
single column type. To avoid getting an error when overwriting this definition
through the configuration, we'll also need to be able to \emph{un}-define column
types:
\begin{source}
\cs_new:Npn \@@_undef_col:n #1 {
    \tl_set_eq:cN { NC@find@ \token_to_str:N #1 } \scan_stop:
}
\end{source}
Note that the implementation specifically targets the \pkg{array} package. The
following command then will either define or \emph{re}-define a column type:
\begin{source}
\cs_new:Npn \@@_def_col:nn #1 #2 {
    \@@_undef_col:n { #1 }
    \newcolumntype  { #1 } { #2 }
}
\end{source}
%
\paragraph{Defining commands.}
This command creates a new command with a \code{pseudo} prefix, and defines
the prefixless version as well, \emph{if the name is available} (i.e.,
undefined):
\begin{source}
\cs_new:Npn \@@_meta_new_cmd:NNnn #1 #2 #3 #4 {
    \tl_set:Nn \l_tmpa_tl {pseudo \cs_to_str:N #2}
    \exp_args:Nc
        #1 \l_tmpa_tl #3 {#4}
    \cs_if_free:NT #2 {\cs_gset_eq:Nc #2 \l_tmpa_tl}
}

\cs_new:Npn \@@_new_cmd:Nnn #1 #2 #3 {
    \@@_meta_new_cmd:NNnn
    \NewDocumentCommand #1 {{#2}} {
        #3
    }
}

\cs_new:Npn \@@_new_ecmd:Nnn #1 #2 #3 {
    \@@_meta_new_cmd:NNnn
    % \NewExpandableDocumentCommand #1 {{#2}} {
    % Replaced for compatibility:
    \def #1 {#2} {
        #3
    }
}
\end{source}
This is for defining commands that declare styled shortcuts:
\begin{source}
\cs_new:Npn \@@_new_dec:nn #1 #2 {
    \tl_set:Nn \l_tmpa_tl { DeclarePseudo #1 }
    \exp_args:Nc
    \DeclareDocumentCommand \l_tmpa_tl { mm } {
        \DeclareDocumentCommand ##1 { } {
            \use:c { #2 } { ##2 }
        }
    }
}
\end{source}
You use this with a capitalized name for the kind of thing you're declaring,
and the name of the style command to use. For example,
\begin{center}
\verb|\@@_new_dec:nn{Keyword}{kw}|
\end{center}
will create the command \cs{DeclarePseudoKeyword}, which takes a csname and a
word, and binds the csname as a shortcut for the word, properly styled as a
keyword.

\bigskip

\paragraph{Argument parsing.} In processing the multiple \code{+} and \code{-}
arguments to \refc{\bslash}, we'll gobble up one character at a time, each
time performing some action. We also supply code to be performed once we're
done.
\begin{source}
\cs_new:Npn \@@_per_char:nnn #1 #2 #3 {
    \peek_charcode_remove:NTF { #1 } {
        #2 % body
        \@@_per_char:nnn{#1}{#2}{#3}
    } {
        #3 % tail
    }
}
\end{source}
%
\paragraph{Indentation.} The indent size (i.e., the length of a single
step of indentation) is either set directly through \refk{indent-length}, or
indirectly through \refk{indent-text}. The latter is there the default is
provided, but \refk{indent-text} is only used if there is no \refk{indent-length}.
\begin{source}
\cs_new:Npn \@@_set_indent_length: {

    \quark_if_no_value:VTF \l_@@_indent_length_tl {
        \hbox_set:Nn \l_tmpa_box { \l_@@_indent_text_tl }
        \dim_set:Nn \pseudoindentlength { \box_wd:N \l_tmpa_box }
    } {
        \dim_set:Nn \pseudoindentlength \l_@@_indent_length_tl
    }

}
\end{source}
Note that the configured indent length is stored in a \code{tl}, which is
expanded in the \refe{pseudo} environment.

The indent size is subsequently used by the indent command, which takes the
number of indentation steps as its only argument. If no \refk{indent-mark} is
set, it just inserts an appropriate horizontal space. Otherwise, it iterates
over the indent levels, inserting one indent marker for each level. Note that to
avoid affecting the indent, the \refk{indent-mark} should have no width (i.e.,
it should ``undo'' the width of any text it contains, using \cs{rlap}, a
negative \cs{hspace} or the like).
\begin{source}
\cs_new:Npn \@@_indent:N #1 {
    \tl_if_novalue:VTF \l_@@_indent_mark_tl {
        \skip_horizontal:n{ \pseudoindentlength * #1 }
    } {
        \group_begin:
        \color{\l_@@_indent_color_tl}
        \int_step_inline:nn { \g_@@_indent_level_int } {
            \l_@@_indent_mark_tl
            \skip_horizontal:n{ \pseudoindentlength }
        }
        \group_end:
    }
    \ignorespaces
}
\end{source}
%
\paragraph{Counter copying.} Inside the \refe{pseudo} environment, we want
\code{*} to be a duplicate of \code{pseudoline}, for convenience. This requires
a bit of work. We use the \pkg{aliascnt} package to deal with much of the
book-keeping, but in order for \cs{newaliascnt} to work whenever a counter
already exists, we need to undefine it first. (Here we're relying on the
internal \LaTeX\ convention of using \verb|c@| as a prefix to counter names.)

\begin{source}
\cs_new:Npn \@@_drop_ctr:n #1 {
    \cs_undefine:c { c@ #1 }
}

\cs_new:Npn \@@_copy_ctr:nn #1 #2 {
    \@@_drop_ctr:n { #1 }
    \newaliascnt   { #1 } { #2 }
}

\cs_new:Npn \@@_star_setup: {

    \cs_if_exist:cT { c@ * } {
        \@@_copy_ctr:nn { @@_orig_* } { * }
    }
    \@@_copy_ctr:nn { * } { pseudoline }

    \group_insert_after:N \@@_star_reset:

}

\cs_new:Npn \@@_star_reset: {
    \cs_if_exist:cT { c@ @@_orig_* } {
        \@@_copy_ctr:nn { * } { @@_orig_* }
        \cs_undefine:c { c@ @@_orig_* }
    }
}
\end{source}
%
\paragraph{Label saving.}
In the body of each line, we make sure to save the counter, so it's available
for the \cs{label} command. We've aready incremented \code{pseudoline} with
\cs{stepcounter} in the label, so we first need to decrement it before we
again increment it, this time with \cs{refstepcounter}. However, we only do so
if the counter actually \emph{was} incremented, i.e., if it's different from
the last one we saved.
\begin{source}
\cs_new:Npn \@@_save_label: {

    \int_set:Nn \l_tmpa_int {\arabic{pseudoline}}

    \int_compare:nF {\l_tmpa_int = \g_@@_last_saved_line_int} {
        \addtocounter{pseudoline}{-1}
        \refstepcounter{pseudoline}
        \int_gset_eq:NN \g_@@_last_saved_line_int \l_tmpa_int
    }

}

\DeclareDocumentCommand \pseudosavelabel { } {
    \@@_save_label:
}
\end{source}
%
\paragraph{Saving and restoring.} In general, we could just use local
variables and trust the scope mechanism, but if we use global assignments
inside the scope (e.g., because of where in a tabular we must assign things
and use them), the original meaning \emph{won't} be restored. Of course, this
should \emph{not} be used if assignments are local, as it will globally set
the original name to the meaning it had when we entered the scope.

In saving a macro, we also supply a name for the original, which may then be
used to refer to it until it's restored.
\begin{source}
\cs_new:Npn \@@_gsave_as:NN #1 #2 {
    \cs_gset_eq:NN #2 #1
    \group_insert_after:N \cs_gset_eq:NN
    \group_insert_after:N #1
    \group_insert_after:N #2
}
\end{source}
%
\subsection{Styles}

The first text styling commands are only straight-up shortcuts for normal font
commands:
\begin{source}
\@@_new_cmd:Nnn \nf {   } { \normalfont          }
\@@_new_cmd:Nnn \tn { m } { \textnormal { #1 }   }
\@@_new_cmd:Nnn \kw { m } { \textnormal {\kwfont { #1 } } }
\@@_new_cmd:Nnn \cn { m } { \textnormal {\cnfont { #1 } } }
\@@_new_cmd:Nnn \id { m } { \textnormal {\idfont { #1 } } }
\end{source}
(As a side-effect, we've now also defined \cs{pseudonf} and \cs{pseudotn},
which we don't really need.)
%
While we're at it, we'll define the initial value for \refc{kwfont}, which is
generally non-extended bold, if that's available, but extended bold otherwise:
\begin{source}
\cs_new:Npn \@@_b_or_bx: {

    % Note: We're relying on the warning text in \@defaultsubs
    % being defined by \selectfont if the desired font isn't
    % found. This won't happen, however, if the same
    % \curr@fontshape combination has been attempted before
    % (cf. source2e.pdf page 179).

    \group_begin:

    \cs_if_exist:NT \@defaultsubs {
        \@@_gsave_as:NN \@defaultsubs \@@_defaultsubs
        \cs_gset_eq:NN \@defaultsubs \relax
    }

    % This is what we'd like:
    \cs_gset:Nn \@@_b_or_bx: { \fontseries{b}\selectfont }

    % Try it:
    \@@_b_or_bx:

    % Fallback, if that failed:
    \cs_if_exist:NT \@defaultsubs {
        \cs_gset_eq:NN \@@_b_or_bx: \bfseries
    }

    \group_end:

    % Make sure the new version is used:
    \@@_b_or_bx:

}
\end{source}
Note that the command redefines itself after the first use, so as not to
execute the check every time.

The \refc{pr} command is also a font shortcut, but in addition takes optional
parenthesis-delimited arguments, which are set in math mode. To avoid
erroneousy slurping up following parentheticals, there should be no space
separating the command and its optional argument. With current versions of
\pkg{xparse}, this can be achieved with the \verb|!| argument type, but for
compatibility with older \TeX\ distributions, I'll deal with it ``manually.''
\begin{source}
\cs_new:Npn \@@_fmt_pr:n #1 {
    \textnormal{\prfont{ #1 }}
}

\NewDocumentCommand \@@_parse_paren_args { +d() } {
    \IfNoValueF { #1 } {
        \ensuremath{ ( #1 ) }
    }
}

\NewDocumentCommand \@@_parse_bracket_or_paren_args { +o } {
    \IfNoValueTF { #1 } {
        \@@_parse_paren_args
    } {
        \ensuremath{ [ #1 ] }
    }
}

\@@_new_cmd:Nnn \pr { m } {
    \@@_fmt_pr:n { #1 }
    \peek_catcode:NTF { ~ } { } {
        \@@_parse_paren_args
    }
}
\end{source}
The \refc{fn} command is similar, but alternatively permits arguments in
square brackets.
\begin{source}
\cs_new:Npn \@@_fmt_fn:n #1 {
    \textnormal{\fnfont{ #1 }}
}
\@@_new_cmd:Nnn \fn { m } {
    \@@_fmt_fn:n { #1 }
    \peek_catcode:NTF { ~ } { } {
        \@@_parse_bracket_or_paren_args
    }
}
\end{source}
The \refc{hd} command is similar to \refc{pr} command, except that it spans
two columns (effectively ignoring the labeling column). Because it needs to be
expandable in order to insert the multicolumn, the final, parenthesis-enclosed
argument can not be optional (unlike for \refc{pr}). Note also that \refc{hd}
sets \refk{extra-space} (or the underlying \code{tl}) based on \refk{hd-space}.
\begin{source}
% \@@_new_ecmd:Nnn \hd { m +r() } {
% Now uses \def syntax:
\@@_new_ecmd:Nnn \hd { #1 ( #2 ) } {
    \multicolumn{2}
        {\pseudohdpreamble}
        {\@@_fmt_pr:n{#1}\ensuremath{(#2)}}
        \tl_set_eq:NN \l_@@_extra_space_tl \l_@@_hd_space_tl
}
\end{source}
Finally, \refc{st} and \refc{ct} add quotes and comment delimiters,
respectively, to the typeset string, keeping it all in \cs{textnormal}:
\begin{source}
\@@_new_cmd:Nnn \st { +m } {
    \textnormal {
    \l_@@_st_left_tl {\stfont{#1}} \l_@@_st_right_tl }
}
\@@_new_cmd:Nnn \ct { +m } {
    \textnormal {
    \l_@@_ct_left_tl {\ctfont{#1}} \l_@@_ct_right_tl }
}
\end{source}
Beyond text styling, we also have styling for entire rows, i.e., highlighting:
\begin{source}
% \NewExpandableDocumentCommand \pseudohl { } {
% For backward compatibility:
\def \pseudohl {
    \rowcolor{\pseudohlcolor}
}
\end{source}
%
\paragraph{Declarations.} To declare shortcuts using the various styles,
commands à la \code{DeclareMathOperator} and \code{DeclareDocumentCommand} are
provided:
\begin{source}
\@@_new_dec:nn { Comment    } { ct }
\@@_new_dec:nn { Constant   } { cn }
\@@_new_dec:nn { Function   } { fn }
\@@_new_dec:nn { Identifier } { id }
\@@_new_dec:nn { Keyword    } { kw }
\@@_new_dec:nn { Normal     } { tn }
\@@_new_dec:nn { Procedure  } { pr }
\@@_new_dec:nn { String     } { st }
\end{source}
%
\subsection{Notation}

Here we'll define a couple of symbols that are useful for pseudocode but that
are not necessarily entirely standard mathematical notation. First, the double
equals sign, ubiquitous in modern programming languages, and useful if
\code{=} is used for assignment. The horizontal scaling of the equals signs,
as well as the space between them and the padding on both sides may be
adjusted by using the keys \refk{eqs-scale}, \refk{eqs-sep} and
\refk{eqs-pad}. Initially, these are set to emulate the \cs{eqeq} symbol from
\pkg{stix} when used with Computer Modern, Latin Modern or the like (though the
command works just fine with other fonts as well).
\begin{source}
\NewDocumentCommand \eqs { } {
    \group_begin:
    \muskip_set:Nn \l_tmpa_muskip \l_@@_eqs_pad_tl
    \muskip_set:Nn \l_tmpb_muskip \l_@@_eqs_sep_tl
    \hbox_set:Nn   \l_tmpa_box {\(=\)}
    \box_scale:Nnn \l_tmpa_box {\l_@@_eqs_scale_fp}{1}
    \mathrel{
        \tex_mskip:D     \l_tmpa_muskip
        \box_use:N       \l_tmpa_box
        \tex_mskip:D     \l_tmpb_muskip
        % \box_use_drop:N  \l_tmpa_box
        % Replaced for compatibility
        \box             \l_tmpa_box
        \tex_mskip:D     \l_tmpa_muskip
    }
    \group_end:
}
\end{source}
For convenience and source-code clarity, the following shortcut (i.e.,
\cs{==}) is defined (hijacking the \cs{=} accent command):
\begin{source}
\cs_gset_eq:NN \c_@@_orig_eq_cs \=

\DeclareDocumentCommand \= { m } {
    \tl_if_eq:nnTF { #1 } { = } {
        \eqs
    } {
        \c_@@_orig_eq_cs{#1}
    }
}

\cs_gset_eq:NN \@@_eq: \= % Stored for \RestorePseudoEq
\end{source}
Similarly, there's the
\href{https://proofwiki.org/wiki/Definition:Real_Interval/Notation/Wirth}{Pascal
two-dot interval notation}, whose implementation mirrors Knuth's \cs{dts}
command from Concrete Mathematics (see \pkg{gkpmac.tex}), with the addition of
\cs{nolinebreak}, taken from
\pkg[https://www.cs.dartmouth.edu/~thc/]{clrscode4e}.

\begin{source}
\NewDocumentCommand \dts { } {
    \nolinebreak
    \mathinner {
        \ldotp
        \ldotp
    }
    \nolinebreak
}
\end{source}
%
There's a shortcut (\cs{..}) defined for this as well (this time hijacking
\cs{.}):
\begin{source}
\cs_gset_eq:NN \c_@@_dot_cs \.

\DeclareDocumentCommand \. { m } {
    \tl_if_eq:nnTF { #1 } { . } {
        \dts
    } {
        \c_@@_dot_cs { #1 }
    }
}
\end{source}
%
Finally, we define a different syntax for numeric ranges like these (or
\emph{slices} or \emph{subarrays}). This command is based on the \cs{subarr}
command of \pkg[https://www.cs.dartmouth.edu/~thc/]{clrscode4e}.
\begin{source}
\NewDocumentCommand \rng { } {
    \nolinebreak
    \mathinner { : }
    \nolinebreak
}
\end{source}

\subsection{Options}
\label{sec:options}

Much of the behavior of \pkg{pseudo} may be configured through various options,
and these are defined below. You provide these either through \refc{pseudoset}
or (where applicable) as optional arguments to \refc{\bslash} or the
\refe{pseudo} environment itself.

The \cs{usepackage} options (handled by \pkg{l3keys2e}) are subject to full
expansion, an so many options simply won't work. In order to make the \refk{kw}
option as easily available as possible, however, we permit it here, by way of a
\code{bool} that triggers the \emph{actual} key later on:

\begin{source}
\keys_define:nn { pseudo/package } {
    kw              .bool_gset:N    = \g_@@_kw_bool,
    kw              .default:n      = true
}
\ProcessKeysOptions{ pseudo/package }
\end{source}
%
We now define the actual keys used by \refc{pseudoset}. Note that \refk{hpad}
and \refk{hsep} do \emph{not} use \verb|.dim_set:N|. This is because the
\code{dim} would then be interpreted at the point where it's \emph{set}, and
not where it's \emph{used}. If we use units like \code{em} and \code{ex},
which depend on the font and font size, the spacing would not be updated if we
change these things between setting \code{hpad} and \code{hsep} and actually
typesetting the pseudocode.

\begin{source}
\keys_define:nn { pseudo } {

    font            .tl_set:N       = \pseudofont,
    font            .initial:n      = \normalfont,

    hpad            .meta:n         = {
        hpad-val = { #1 },
        hl-warn = false,
    },
    hpad            .default:n      = 0.3em,

    % For internal use:
    hpad-val        .tl_set:N       = \l_@@_hpad_tl,
    hpad-val        .initial:n      = 0.0em,

    hsep            .tl_set:N       = \l_@@_hsep_tl,
    hsep            .initial:n      = .75em,

    left-margin     .tl_set:N       = \l_@@_left_margin_tl,
    left-margin     .initial:n      = 0pt,

    label           .tl_set:N       = \l_@@_label_tl,
    label           .initial:n      = \arabic*,

    label-align     .code:n         =
        \@@_def_col:nn{ \pseudolabelalign }{#1},
    label-align     .initial:n      = r,

    ref             .tl_set:N       = \thepseudoline,
    ref             .default:n      = \l_@@_label_tl,

    indent-length   .tl_set:N       = \l_@@_indent_length_tl,
    indent-length   .initial:V      = \q_no_value,

    indent-text     .tl_set:N       = \l_@@_indent_text_tl,
    indent-text     .initial:n      = { \pseudofont\kw{else}\ },

    indent-mark     .tl_set:N       = \l_@@_indent_mark_tl,
    indent-mark     .initial:x      = \c_novalue_tl,
\end{source}
The default \refk{indent-mark} is a vertical rule with width set by
\refk{indent-mark-width}, followed by a negative horizontal space of the same
magnitude.
\begin{source}
    indent-mark     .default:n      =
        \skip_horizontal:n { \l_@@_indent_mark_shift_tl }
        \tex_vrule:D width \l_@@_indent_mark_wd_tl
        \skip_horizontal:n {
            -\l_@@_indent_mark_wd_tl
            -\l_@@_indent_mark_shift_tl
        },

    indent-mark-width .tl_set:N     = \l_@@_indent_mark_wd_tl,
    indent-mark-width .initial:n    = \c_@@_semithick_dim,

    indent-mark-shift .tl_set:N     = \l_@@_indent_mark_shift_tl,
    indent-mark-shift .initial:n    = 0pt,
    indent-mark-shift .default:n    = .5em,

    indent-mark-color .tl_set:N     = \l_@@_indent_color_tl,
    indent-mark-color .initial:n    = lightgray,

    indent-level    .int_set:N      = \l_@@_initial_indent_level_int,

    kwfont          .tl_set:N       = \kwfont,
    kwfont          .initial:n      = \@@_b_or_bx:,

    kw              .meta:n         = { font = \kwfont },
    kw              .value_forbidden:n = true,

    hl-warn         .bool_set:N     = \l_@@_hl_warn_bool,
    hl-warn         .initial:n      = true,
    hl-warn         .default:n      = true,

    % For internal use:
    hl-warn-code    .code:n         = {
        \bool_if:nT \l_@@_hl_warn_bool {
            \msg_warning:nn { pseudo } { hl-without-hpad }
        }
    },

    hl              .meta:n         = {
        hl-warn-code,
        bol-prepend = \pseudohl
    },
    hl              .value_forbidden:n = true,


    bol             .tl_set:N       = \l_@@_bol_tl,
    bol-append      .code:n         = {
        \tl_put_right:Nn \l_@@_bol_tl {#1}
    },
    bol-prepend     .code:n         = {
        \tl_put_left:Nn \l_@@_bol_tl {#1}
    },

    eol             .tl_set:N       = \l_@@_eol_tl,
    eol-append      .code:n         = {
        \tl_put_right:Nn \l_@@_eol_tl {#1}
    },
    eol-prepend     .code:n         = {
        \tl_put_left:Nn \l_@@_eol_tl {#1}
    },

    % Defined differently in beamer -- see below
    pause           .meta:n         = ,
    pause           .value_forbidden:n = true,

    cnfont          .tl_set:N       = \cnfont,
    cnfont          .initial:n      = \textsc,

    idfont          .tl_set:N       = \idfont,
    idfont          .initial:n      = \textit,

    stfont          .tl_set:N       = \stfont,
    stfont          .initial:n      = \textnormal,

    st-left         .tl_set:N       = \l_@@_st_left_tl,
    st-left         .initial:n      = ``,

    st-right        .tl_set:N       = \l_@@_st_right_tl,
    st-right        .initial:n      = '',

    prfont          .tl_set:N       = \prfont,
    prfont          .initial:n      = \cnfont,

    fnfont          .tl_set:N       = \fnfont,
    fnfont          .initial:n      = \idfont,

    ctfont          .tl_set:N       = \ctfont,
    ctfont          .initial:n      = \textit,

    ct-left         .tl_set:N       = \l_@@_ct_left_tl,
    ct-left         .initial:n      = (,

    ct-right        .tl_set:N       = \l_@@_ct_right_tl,
    ct-right        .initial:n      = ),

    hl-color        .tl_set:N       = \pseudohlcolor,
    hl-color        .initial:n      = black!12,

    dim-color       .tl_set:N       = \pseudodimcolor,
    dim-color       .initial:n      = \pseudohlcolor,

    dim             .meta:n         = {
        bol-append   = \color{\pseudodimcolor},
        setup-append = \color{\pseudodimcolor}
    },

    line-height     .tl_set:N       = \l_@@_line_height_tl,
    line-height     .initial:n      = 1,

    extra-space     .tl_set:N       = \l_@@_extra_space_tl,
    extra-space     .initial:n      = 0pt,

    hd-space        .tl_set:N       = \l_@@_hd_space_tl,
    hd-space        .initial:n      = 0pt,
\end{source}
The default value here emulates the spacing used in
\pkg[https://www.cs.dartmouth.edu/~thc/]{clrscode4e}, though with a different
mechanism:\footnote{They insert
\code{\cs{rule}[-1.25ex]\braces{0pt}\braces{0pt}} as part of the header.}
\begin{source}
    hd-space        .default:n      = 0.41386ex,

    start           .tl_set:N       = \l_@@_start_tl,
    start           .initial:n      = 1,
\end{source}
%
\paragraph{Line structure.} The preamble for the internal \code{tabular} is
defined as a single column type, to make it easier to apply it despite the
\pkg{array} protections against expansion.
\begin{source}
    preamble        .code:n         =
        \@@_def_col:nn{ \pseudopreamble }{#1},
\end{source}
The preamble is laid out as described in \cref{sec:reference}:
\label{p:preamble}%
\begin{source}
    preamble        .initial:n      = {
        >{ \pseudohpad }
        \pseudolabelalign
        >{ \pseudosetup }
        l
        <{ \pseudohpad }
    },
    setup           .tl_set:N       = \l_@@_setup_tl,
    setup           .initial:n      = {
        \pseudoindent \pseudofont \pseudosavelabel
    },

    setup-append    .code:n         = {
        \tl_put_right:Nn \l_@@_setup_tl {#1}
    },
    setup-prepend   .code:n         = {
        \tl_put_left:Nn \l_@@_setup_tl {#1}
    },
\end{source}
The preamble used for multicolumns is treated similarly:
\label{p:hdpreamble}%
\begin{source}
    hd-preamble     .code:n         =
        \@@_def_col:nn{ \pseudohdpreamble }{#1},
    hd-preamble     .initial:n      = {
        >{ \pseudohpad } l <{ \pseudohpad }
    },
\end{source}
The prefix is inserted by the row separator command.
\label{p:prefix}%
\begin{source}
    prefix          .tl_set:N       = \pseudoprefix,
    prefix          .initial:n      = {
        \pseudobol \stepcounter* \pseudolabel &
    },
\end{source}
\paragraph{Tabular setup.}
The beginning and end of the tabular environment, as well as some positioning
and spacing.
\begin{source}
    pos             .tl_set:N       = \pseudopos,
    pos             .initial:n      = t,

    prevdepth       .tl_set:N       = \l_@@_prevdepth_tl,
    prevdepth       .initial:n      = .3 \baselineskip,

    begin-tabular   .tl_set:N       = \l_@@_begin_tabular_tl,
    begin-tabular   .initial:n      =
        \begin{tabular}[\pseudopos]{\pseudopreamble},

    end-tabular     .tl_set:N       = \l_@@_end_tabular_tl,
    end-tabular     .initial:n      = \end{tabular},
\end{source}
\paragraph{List-like spacing.} Space above and below is handled similarly to
in the built-in \LaTeX\ lists, with the option of locally overriding
\cs{topsep} and \cs{partopsep}, with \refk{compact} used to control the presence
of this spacing (overriding the ordinary automatic choice based on the current
mode).
\begin{source}
    topsep          .tl_set:N       = \l_@@_topsep_tl,
    topsep          .initial:n      = { \topsep },

    partopsep       .tl_set:N       = \l_@@_partopsep_tl,
    partopsep       .initial:n      = { \partopsep },

    compact         .meta:n         = {
        compact-val  = { #1 },
        compact-def  = true,
        compact-code = { #1 },
    },
    compact         .default:n      = true,

    % For internal use:
    compact-val     .bool_set:N     = \l_@@_compact_bool,
    compact-def     .bool_set:N     = \l_@@_compact_def_bool,
    compact-code    .code:n         = {
        \bool_if:nT { \l_@@_compact_bool } {
            \tl_clear:N \pseudopos
        }
    },
\end{source}

\paragraph{Details.} Finally, some tweakable parameters.
\begin{source}
    eqs-scale       .fp_set:N       = \l_@@_eqs_scale_fp,
    eqs-scale       .initial:n      = 0.6785,

    eqs-sep         .tl_set:N       = \l_@@_eqs_sep_tl,
    eqs-sep         .initial:n      = 0.63mu,

    eqs-pad         .tl_set:N       = \l_@@_eqs_pad_tl,
    eqs-pad         .initial:n      = 0.28mu,

}
\end{source}
%
Now that we've defined the real \refk{kw} key, we reexamine the placeholder
handled by \pkg{l3keys2e}:
\begin{source}
\bool_if:NT \g_@@_kw_bool {
    \keys_set:nn { pseudo } { kw }
}
\end{source}
%
\paragraph{Beamer overlays.}
We redefine the \refk{pause} key if we're using \pkg{beamer}:
\begin{source}
\bool_if:NT \c_@@_beamer_bool {
    \keys_define:nn { pseudo } {
        pause .meta:n = { eol-append = \pause }
    }
}
\end{source}
There's also the mechanism for handling overlay specifications on keys. Here we
handle unknown keys by checking if they end with an overlay specification, and
if they do, and we're in \pkg{beamer}, we extract it. Outside \pkg{beamer}, keys
with overlays are simply ignored.

Note that because unknown keys currently can't have a default (which we could,
in this case, use for some kind of marker, indicating no value was supplied),
the only solution is to treat an empty value the same way as no value, in this
case. This means that \code{foo<1>} and \code{foo<1>=\braces{}} are
equivalent, and both will trigger the default of \code{foo}, even though the
latter of the two really shouldn't.\footnote{See
\url{https://github.com/latex3/latex3/issues/67}.}
\begin{source}
\cs_new:Npn \@@_keys_set_overlay:nnn #1 #2 #3 {
    \bool_if:NT \c_@@_beamer_bool {
        \tl_if_novalue:nF { #1 } {
            \only<#1>{ \keys_set:nn { #2 } { #3 } }
        }
    }
}

\msg_new:nnn { pseudo } { unknown-key } {
    Unknown~key~'#1'~ignored.
}

\tl_new:N \l_@@_overlay_tl

\keys_define:nn { pseudo } {
    unknown .code:n = {

        \group_begin:

        \int_zero:N \l_tmpa_int
        \int_zero:N \l_tmpb_int

        \tl_clear:N \l_tmpa_tl
        \tl_clear:N \l_tmpb_tl

        \tl_map_inline:Nn \l_keys_key_tl {

            \tl_if_eq:nnTF { ##1 } { < } {

                \int_incr:N \l_tmpa_int
                \int_compare:nF { \l_tmpb_int == 0 } {
                    % We already found `>'!
                    % Increment again to prevent match:
                    \int_incr:N \l_tmpa_int
                }

                \tl_set_eq:NN \l_tmpb_tl \l_tmpa_tl
                \tl_clear:N \l_tmpa_tl

            } {

            \tl_if_eq:nnTF { ##1 } { > } {

                \int_incr:N \l_tmpb_int

                \tl_set_eq:NN \l_@@_overlay_tl \l_tmpa_tl
                \tl_clear:N \l_tmpa_tl

            } {

                \tl_put_right:Nn \l_tmpa_tl { ##1 }

            } }

        }

        % A single `<' and a final, single `>'?
        \bool_if:nTF {
            \int_compare_p:n { \l_tmpa_int == \l_tmpb_int == 1 }
            &&
            \tl_if_empty_p:N \l_tmpa_tl
        } {
\end{source}
We've matched a key with an overlay specification. If it's got a (non-blank)
value, we include that in the key-setting code we're building in
\cs{l\_tmpb\_tl}, and then we set the key, with the appropriate overlay
specification.
\begin{source}
            \tl_if_blank:nF{ #1 } {
                \tl_put_right:Nn \l_tmpb_tl {= #1}
            }
\end{source}
Rather than setting the keys here, inside a group, we put the code into a
variable that we'll expand outside the group, later:
\begin{source}
            \tl_set:Nn \l_tmpa_tl {
                \@@_keys_set_overlay:nnn
            }
            \tl_put_right:Nx \l_tmpa_tl { { \l_@@_overlay_tl } }
            \tl_put_right:Nn \l_tmpa_tl { { pseudo           } }
            \tl_put_right:Nx \l_tmpa_tl { { \l_tmpb_tl       } }
        } {
\end{source}
We have \emph{not} matched an overlay specification, so we just have an unknown
key. However, we have another special case to consider: If we're processing
arguments to \refc{\bslash}, we also permit a keyless value to be used to
specify extra space (normally done using \refk{extra-space}). If the unknown
key doesn't have an attached (non-blank) value, we treat the key itself as a
value, and use it as extra space. If this, too, fails, we emit an error message.
Note that we'll also make sure the variable with the key-setting code is
empty.
\begin{source}
            \tl_clear:N \l_tmpa_tl
            \bool_if:nTF {
                \bool_lazy_and_p:nn
                    { \l_@@_in_eol_bool       }
                    { \tl_if_blank_p:n { #1 } }
            } {
                \tl_set_rescan:Nno
                    \l_@@_extra_space_tl { }
                    { \l_keys_key_str  }
            } {
                \msg_error:nnx
                    { pseudo } { unknown-key }
                    { \l_keys_path_str }
            }
        }

        % Make sure extra space and key-setting carry over
        % outside the group:
        \exp_args:NNNVNNV
            \group_end:
            \tl_set:Nn \l_@@_extra_space_tl \l_@@_extra_space_tl
            \tl_set:Nn \l_tmpa_tl           \l_tmpa_tl

        % Run the key-setting code with overlay specification:
        \l_tmpa_tl

    }

}
\end{source}
%
\paragraph{Option processing.} To let the user work with the options (other
than when they're available as optional arguments to other commands), we
supply a command for setting them.
\begin{source}
\cs_new:Npn \@@_set:n #1 { \keys_set:nn { pseudo } { #1 } }
\end{source}
%
\subsection{The row separator}

Much of the work of the \refe{pseudo} environment is performed by the row
separator, that is, the \refc{\bslash} command; whatever part of the line
structure (see \cref{sec:reference}) that's not in the \refk{preamble} must be
handled by \refc{\bslash}. For example, this is where the \refk{prefix} gets
inserted. One reason for this is that there is no straightforward way to
insert the column separator (\code{\&}) from the \refk{preamble} itself; and
if you want to prevent the column separator insertion because you need to to
some custom work in the first column, you'll probably want to suppress other
parts of the \refk{prefix} as well, so they might as well be collected in one
place.

Beyond inserting material such as \cs{tabularnewline}s and \refk{prefix}
contents, \refc{\bslash} is also an entrypoint for local customization, i.e.,
modifying the indentation level and setting any locally meaningful keys.

\bigskip

\paragraph{Indentation utilities.} First we have some functions for modifying
the indentation level---essentially just incrementing, decrementing and
setting it to zero.
\begin{source}
\cs_new:Npn \@@_inc_indent: {
    \int_gincr:N \g_@@_indent_level_int
}

\cs_new:Npn \@@_dec_indent: {
\end{source}
If the user happens to dedent too much, we might as well be a bit forgiving,
and clamp the indent level to non-negative values:
\begin{source}
    % Not using \c_zero_int for compatibility
    \int_compare:nNnT \g_@@_indent_level_int > 0 {
        \int_gdecr:N \g_@@_indent_level_int
    }
}
\end{source}
%
\paragraph{The actual row separator.} The command consists of a few
interacting macros. The implementation of \refc{\bslash} is
\verb|@@_eol:|, but that is just a thin wrapper that counts pluses and
minuses, before handing the control over to \verb|@@_eol_tail|. This is where
the remaining argument parsing takes place, and the \cs{tabularnewline} is
inserted, after which control is passed to \verb|\@@_bol:| in order to begin a
new line---unless we're at the end of the environment.

\begin{source}
\cs_new:Npn \@@_eol_handle_args:nnn #1 #2 #3 {
    % Make extra-space default key for keyless value:
    \bool_set_true:N \l_@@_in_eol_bool
    \@@_keys_set_overlay:nnn { #2 } { pseudo } { hl }
    \keys_set:nn { pseudo } { #3 }
\end{source}
The variables underlying the keys (\verb|\l_@@_label_tl|, etc.) are kept
local, so they'll be restored after the environment, but in order to carry
over to the next line and its preamble, we need to perform some global
assignments here.
\begin{source}
    \tl_gset_eq:NN \pseudolabel   \l_@@_label_tl
    \tl_gset_eq:NN \pseudobol     \l_@@_bol_tl
    \tl_gset_eq:NN \pseudoeol     \l_@@_eol_tl
    \tl_gset_eq:NN \pseudosetup   \l_@@_setup_tl
\end{source}
If starred, clear out the prefix:
\begin{source}
    \IfBooleanTF { #1 } {
        \tl_gclear:N \g_@@_cur_prefix_tl
    } {
        \tl_gset_eq:NN \g_@@_cur_prefix_tl \pseudoprefix
    }
}
\NewDocumentCommand \@@_eol_tail { s d<> +O{ } } {
    \@@_eol_handle_args:nnn{#1}{#2}{#3}
\end{source}
A new line is begun only if we're not at the end of the (or, at least of
\emph{some}) environment. (We could have put the \cs{tabularnewline} outside,
but then we'd have a conditional at the beginning of the next line, which
would mess up \cs{bottomrule} or the like. We need to keep \verb|\@@_bol:|
alone at the start of the line.) We call \cs{tabularnewline} either way, in
particular for it to use any extra space provided to \refk{extra-space}.
\begin{source}
    \tl_set:Nx \l_tmpa_tl {
        \exp_not:N \tabularnewline [ \l_@@_extra_space_tl ]
    }
    \peek_meaning_ignore_spaces:NTF \end {
        \l_tmpa_tl
    } {
        \pseudoeol
        \l_tmpa_tl
        \@@_bol:
    }
}
\end{source}
And here is the actual \verb|\@@_eol:| command:
\begin{source}
\cs_new:Npn \@@_eol: {

    \@@_per_char:nnn { + } {
        \@@_inc_indent:
    } {
    \@@_per_char:nnn { - } {
        \@@_dec_indent:
    } {
        \@@_eol_tail
    } }

}
\end{source}
%
The \verb|\@@_bol:| command (currently) just inserts the \refk{prefix}:
\begin{source}
\cs_new:Npn \@@_bol: {
    \g_@@_cur_prefix_tl
}
\end{source}
%
\subsection{Various user commands}

A few user-level wrappers around internal commands. First, a couple primarily
for use in the \refk{preamble}, together with \refc{pseudosavelabel} and
\refc{pseudofont}:
\begin{source}
\NewDocumentCommand \pseudohpad { } {
    \skip_horizontal:n { \l_@@_hpad_tl - \tabcolsep }
}
\NewDocumentCommand \pseudoindent { } {
    \@@_indent:N { \g_@@_indent_level_int }
}
\end{source}
The \refc{RestorePseudoBackslash} command simply redefines the row separator,
and is used at the start of the \refe{pseudo} environment. It may be useful for
the user if some other construct redefines \refc{\bslash} as well. (This is
similar to the \cs{arraycr} command of the \pkg{array} package.)
\begin{source}
\NewDocumentCommand \RestorePseudoBackslash { } {
    \cs_gset_eq:NN \\ \@@_eol:
}
\end{source}
We also have a command for restoring our definition of \cs{=} if it has been
overwritten:
\begin{source}
\NewDocumentCommand \RestorePseudoEq { } {
    \cs_gset_eq:NN \= \@@_eq:
}
\end{source}
Finally, two utilities for working with options. The first (\refc{pseudoset})
directly sets a collection of keys, while the second
(\refc{pseudodefinestyle}) defines a new key which can be used as a shortcut
for setting multiple keys at some later point:
\begin{source}
\NewDocumentCommand \pseudoset { +m }
    { \@@_set:n { #1 } }

\NewDocumentCommand \pseudodefinestyle { m +m } {
    \keys_define:nn { pseudo } {
        #1 .meta:n = {
            #2
        }
    }
}
\end{source}
%
% Not allowed to use \code in header, here:
\subsection{The \codefont{pseudo} environment}

While this is the main attraction, it's essentially just an augmented
\code{tabular} environment, which does a bit of setup initially, using the
various macros already described.

\begin{source}
\NewDocumentEnvironment { pseudo } { +o s d<> +O{ } } {

    \group_begin:

    \@@_gsave_as:NN \\ \c_@@_saved_cr_cs
    \@@_gsave_as:NN \= \c_@@_saved_eq_cs

    % \RestorePseudoBackslash is inside the tabular
    \RestorePseudoEq

    \int_set:Nn \g_@@_last_saved_line_int {\arabic{pseudoline}}
    \@@_star_setup:

    \IfNoValueF { #1 } {
        \pseudoset { #1 }
    }
    \@@_set_indent_length:

    % If not manually set as compact/noncompact,
    % set automatically:
    \bool_if:NF \l_@@_compact_def_bool {
        \bool_set:Nn \l_@@_compact_bool {
            \mode_if_horizontal_p: && \mode_if_inner_p:
        }
    }

    \bool_if:nF { \l_@@_compact_bool } {

        \skip_set:Nn \l_tmpa_skip {
            \l_@@_topsep_tl
        }
        \mode_if_vertical:TF {
            \skip_add:Nn \l_tmpa_skip { \l_@@_partopsep_tl }
        } {
            \unskip \par
        }

        \addvspace { \l_tmpa_skip }

        \noindent
        \skip_horizontal:n{ \dim_eval:n { \l_@@_left_margin_tl } }

    }

    \dim_set:Nn   \tabcolsep    { \l_@@_hsep_tl / 2 }
    \tl_set_eq:NN \arraystretch \l_@@_line_height_tl

    \stepcounter{pseudoenv}
    \setcounter{pseudoline}{\l_@@_start_tl}
    \addtocounter{pseudoline}{-1}

    \tl_use:N \l_@@_begin_tabular_tl
\end{source}
We use \cs{noalign} to be able to place these definitions inside the tabular,
without messing up \cs{multicolumn} or \cs{hline} or the like. It's not really
supposed to be used in \pkg{expl3}; the alternative would be to create an extra
dummy line, like:
\begin{texexp}[listing]
\skip_vertical:n{ -\dim_eval:n{ \box_ht:N \@arstrutbox +
                                \box_dp:N \@arstrutbox } }
\tabularnewline
\end{texexp}
This would give us a fresh start, without moving vertically. It's probably
more hacky than just using \cs{noalign} here, though, so\,\dots
\begin{source}
    \tex_noalign:D {
\end{source}
We keep the \refc{\bslash}-definition inside the \code{tabular}, to override the
redefinition placed there by \pkg{array}, without patching any internals:
\begin{source}
        \RestorePseudoBackslash
\end{source}
In a \code{tabularx}, for example, the body is executed multiple times, so we
must make sure that any resets that are performed---such as setting the
initial indentation level---are performed each time:
\begin{source}
        \int_gset_eq:NN \g_@@_indent_level_int
                        \l_@@_initial_indent_level_int
\end{source}
Finally, we handle the line arguments, just like with the row separator:
\begin{source}
        \@@_eol_handle_args:nnn{#2}{#3}{#4}
    }
\end{source}
Definitions and setup are done, we've left the \cs{noalign}, and we can start
the line:
\begin{source}

    \@@_bol:

} {

    \tl_use:N \l_@@_end_tabular_tl
\end{source}
We'll only adjust spacing here if we're not \refk{compact}. Otherwise, we'll
just end the current group:
\begin{source}
    \bool_if:nTF { \l_@@_compact_bool } {

        \group_end:

    } {

        \mode_if_vertical:F {
            \unskip \par
            \group_insert_after:N \@endparenv
        }

        \addvspace{ \l_tmpa_skip }
\end{source}
To ensure any local changes to \refk{prevdepth} are used, we expand its local
value before setting cs{prevdepth} \emph{outside} the group.\footnote{See,
e.g., \url{https://tex.stackexchange.com/questions/56294}.}
\begin{source}
        \exp_args:NNNV
            \group_end:
            \dim_set:Nn \prevdepth \l_@@_prevdepth_tl

    }

}
\end{source}
The starred version of the environment is just a wrapper that uses the custom
(and overridable) \code{starred} style:
\label{p:starred}%
\begin{source}
\pseudodefinestyle{ starred }{
    preamble = {
        >{\pseudohpad\pseudoindent\pseudofont}
        l
        <{\pseudohpad}
    },
    prefix = {\pseudobol},
}

\NewDocumentEnvironment { pseudo* } { +O{} } {
    \begin{pseudo}[starred, #1]
    % \begin{pseudo} will "eat" any remaining arguments to pseudo*
} {
    \end{pseudo}
}
\end{source}

\subsection{Boxes and floats}
\label{sec:floatsrc}

Some spacing and width values are taken from \pkg{booktabs}, to partly emulate
its table appearance. If \pkg{booktabs} is not loaded, we'll just define these
constants ourselves; if \pkg{booktabs} is loaded later, it will blithely
overwrite these.
\begin{source}
\@ifpackageloaded { booktabs } { } {
    \dim_const:Nn \aboverulesep       { .40ex }
    \dim_const:Nn \belowrulesep       { .65ex }
    \dim_const:Nn \heavyrulewidth     { .08em }
    \dim_const:Nn \lightrulewidth     { .05em }
}
\end{source}
We also define some line widths based on those used by
\pkg[https://ctan.org/pkg/pgf]{tikz}.
% ultra thin   0.1pt
% very thin    0.2pt
% thin         0.4pt
% semithick    0.6pt
% thick        0.8pt
% very thick   1.2pt
% ultra thick  1.6pt
\begin{source}
\dim_const:Nn \c_@@_very_thin_dim     { 0.2pt }
\dim_const:Nn \c_@@_thin_dim          { 0.4pt }
\dim_const:Nn \c_@@_semithick_dim     { 0.6pt }
\end{source}
We'll be adjusting the spacing after the contents based on the value of
\cs{prevdepth}. If \cs{prevdepth} is negative, this is suppressed. Otherwise, we
add vertical space to the \cs{prevdepth}, to take us to (at least)
\code{.3\cs{baselineskip}}. Since the mechanism is the same for the title and
the body, we define a macro:
\begin{source}
\cs_new:Npn \@@_prevdepth_adjustment: {
    \par % Ensure vertical mode
    \dim_compare:nNnF \prevdepth < \c_zero_dim {
        \dim_compare:nNnT \prevdepth < { .3 \baselineskip } {
            \skip_vertical:n { .3 \baselineskip - \prevdepth }
            \skip_vertical:N \c_zero_dim % Hide previous skip
        }
    }
}
\end{source}
To permit the styling specifically of \refe{pseudo} environments inside our
boxes, we define and use a \pkg{pseudo} style, and a hook (token list) that may
overridden by the user:
\begin{source}
\pseudodefinestyle { in-float } {
    % Initially empty
}
\tl_new:N \l_@@_float_init_tl
\end{source}
We now define some \pkg{tcolorbox} box styles. Rather than importing
\pkg{tcolorbox}, we just use its key management mechanism, \pkg{pgfkeys}, with
the appropriate name\-space.
\begin{source}
\pgfqkeys { /tcb/pseudo } {
\end{source}
We begin by defining our hook \refk{pseudo/init}.
\begin{source}
    init/.code = {
        \tl_set:Nn \l_@@_float_init_tl { #1 }
    },
\end{source}
The first box style (\refk{pseudo/boxruled}) is the basis for the others.
\begin{source}
boxruled/.style = {
\end{source}
By default, our boxes aren't floats, but if the \code{float} style is used,
we'll want to have the placement configured. The \pkg{tcolorbox} default is
\code{htb}, but we're emulating normal floats, so we'll use the normal \LaTeX{}
default:
\begin{source}
    floatplacement = tbp,
\end{source}
Before the contents (which uses the upper part of the box), we adjust some
distances, and set \cs{prevdepth}, for consistent vertical spacing of the first
line. These settings may be overridden using \code*{before upper app}, which
appends code to \code*{before upper}. For example, one could change the
\cs{topsep} by using \code*{before upper app =
\braces{\cs{topsep}10pt}}.\footnote{While you might want to modify \cs{parskip},
\cs{topsep} or \cs{partopsep}, there's probably no need to change
\cs{prevdepth}.}%
\label{p:before-upper}
\begin{source}
    before~upper = {
        \dim_set:Nn \parskip    { .3 \baselineskip }
        \dim_set:Nn \topsep     { .2 \baselineskip }
        \dim_set:Nn \partopsep  { 0pt              }
        \dim_set:Nn \prevdepth  { .3 \baselineskip }
        \RestorePseudoEq            % Broken in floats
        \pseudoset { in-float }     % User hook (style)
        \l_@@_float_init_tl         % User hook (code)
    },
\end{source}
At the end of the contents, we add some spacing, again for consistent vertical
alignment.
\begin{source}
    after~upper = \@@_prevdepth_adjustment:,
\end{source}
Now we add spacing before and after the box, when it's not used with
the \code{float} key. We just mirror the spacing of the \refe{pseudo}
environment (except without the support for \refk{partopsep}).
\begin{source}
    beforeafter~skip~balanced = \l_@@_topsep_tl,
\end{source}
Now we set up basic spacing for the contents. The spacing above and below the
title is the same as for the top row of a \pkg{booktabs} tabular. For the
``body'' of the box (and the left/right), we add some extra space.
\begin{source}
    boxsep              = 0pt,
    toptitle            =   \belowrulesep,
    bottomtitle         =   \aboverulesep,
    top                 = 2 \belowrulesep,
    bottom              = 2 \aboverulesep,
    left                = 2 \belowrulesep,
    right               = 2 \belowrulesep,
\end{source}
The title has a separate part called the \emph{description} (in \pkg{tcolorbox}
theorem terms). We give the title one font (bold), and then reset that to
\cs{normalfont} when we get to the description.
\begin{source}
    fonttitle           = \bfseries,
    description~font    = \normalfont,
\end{source}
The spacing above and below the title is adjusted as for the body. We want to
separate the initial part of the title (e.g., ``Algorithm 3.2'') from the
description by an \cs{enskip} (\code{.5em} horizontal space). However, a single
normal space is hard-coded into \pkg{tcolorbox}, so we'll subtract the width of
that. (We make sure to do this with \cs{normalfont}, to not get the units warped
by an extended bold, for example.)
% Cf. https://tex.stackexchange.com/questions/229640/
\begin{source}
    before~title        =
        \dim_set:Nn \prevdepth  { .3 \baselineskip },
    after~title         = \@@_prevdepth_adjustment:,
    separator~sign      = {
        \normalfont
        \skip_horizontal:n { .5em - \fontdimen2\font\space }
    },
\end{source}
Finally, some basic styling.
\begin{source}
    sharp~corners,
    colback             = white,
    colbacktitle        = white,
    coltitle            = black,
    colframe            = black,
    boxrule             = \c_@@_thin_dim,
    titlerule           = \c_@@_very_thin_dim,
},
\end{source}
The remaining box styles are based on \code{boxruled}, but rely on other skins
(\code{empty} and \code{tile}), which remove the default frame drawing, as some
of the frame are removed. (It would be possible to simply set the relevant
widths to zero, but this tends to leave perceptible hairlines in most PDF
viewers---probably because the fram is drawn by \emph{filling} rather than
\emph{drawing}.)
\begin{source}
ruled/.style = {
    pseudo/boxruled,
    empty,
\end{source}
Even though we've removed the default frame, we do want some rules. First the
various rule thicknesses (and some horizontal spacing) are set. The ones
that are missing have their thicknesses set to zero, for spacing/positioning
purposes. The titlerule is drawn normally, but for the top and bottom rules, we
need to use the \code{borderline} mechanism.
\begin{source}
    boxrule             = 0pt,
    toprule             = \heavyrulewidth,
    titlerule           = \lightrulewidth,
    bottomrule          = \heavyrulewidth,
    left                = 0pt,
    right               = 0pt,
    titlerule~style     = draw,
    borderline~north    = {\heavyrulewidth}{0pt}{black},
    borderline~south    = {\lightrulewidth}{0pt}{black},
},
\end{source}
The \code{booktabs} is a variation of \code{ruled}, where the bottom rule is
also thick, to match the style of \code{booktabs} tables.
\begin{source}
booktabs/.style = {
    pseudo/ruled,
    no~borderline,
    bottomrule          = \heavyrulewidth,
    borderline~horizontal = {\heavyrulewidth}{0pt}{black}
},
\end{source}
The \code{boxed} style is similar, with the titlerule removed, and with the
borderline drawn on all sides. Finally, we want to ``simulate'' the title just
being the first paragraph of the contents, so we set the space above the title
\emph{almost} equal to the space used elsewhere above the content, zero out the
spacing after the title, and make the top spacing equal to the the normal
\cs{parskip} (which we set to \code{.3\cs{baselineskip}} in \code{before
upper}).
\begin{source}
boxed/.style = {
    pseudo/boxruled,
    empty,
    titlerule           = 0pt,
    borderline          = {\c_@@_thin_dim}{0pt}{black},
    toptitle            = 1.5 \belowrulesep,
    bottomtitle         = 0pt,
    top                 = 0.3 \baselineskip,
},
\end{source}
The \code{tworuled} style is based on \code{boxed} (including the spacing
adjustment between title and body), but removes the previously drawn
borderlines, adjusts the thicknesses, and draws new horizontal lines.
\begin{source}
tworuled/.style = {
    pseudo/boxed,
    no~borderline,
    left                = 0pt,
    right               = 0pt,
    boxrule             = 0pt,
    toprule             = \heavyrulewidth,
    bottomrule          = \heavyrulewidth,
    borderline~horizontal = {\heavyrulewidth}{0pt}{black},
},
\end{source}
Finally, the \code{filled} style uses the \code{tile} skin, which has no
frame, and is designed for filling. In addition to the colors, there's a slight
spacing adjustment.\footnote{The \code{tile} skin also sets things like
\code*{sharp corners} and \code{fonttitle}, so some of what we inherit from
\code{boxruled} is a bit redundant, here.} Since we have no border, we increase
the spacing a bit (though not at the top, to prevent a ``top-heavy'' look,
especially when dropping the title).
\begin{source}
filled/.style = {
    pseudo/boxruled,
    tile,
    colback             = \pseudohlcolor,   % black!12
    colbacktitle        = lightgray,        % black!25
    bottom              = 2 \aboverulesep + \c_@@_thin_dim,
    left                = 2 \belowrulesep + \c_@@_thin_dim,
    right               = 2 \belowrulesep + \c_@@_thin_dim,
}
\end{source}
And that ends the \pkg{tcolorbox} definitions:
\begin{source}
} % \pgfqkeys
\end{source}


\section{Deprecations and warnings}

Some commands are no longer intended for use, but are included for backward
compatibility. These will issue a deprecation warning when used.

% Not sure why there should be no `~` after the parameters?
\begin{source}
\msg_new:nnn { pseudo } { useinstead } {
    The~#1 command~(used~\msg_line_context:)~is~deprecated;~
    use~#2 instead.
}

\cs_new:Npn \@@_use_instead:nn #1 #2 {
    \msg_warning:nnnn { pseudo } { useinstead } { #1 } { #2 }
    % \tl_gset_eq:NN #1 #2
}

\NewDocumentCommand \pseudoslash { } {
    \@@_use_instead:nn \pseudoslash \RestorePseudoBackslash
    \RestorePseudoBackslash
}

\NewDocumentCommand \pseudoeq { } {
    \@@_use_instead:nn \pseudoeq \RestorePseudoEq
    \RestorePseudoEq
}
\end{source}
Finally, we define a warning to issue if \refk{hl} is used without \refk{hpad}.
\begin{source}
\msg_new:nnn { pseudo } { hl-without-hpad } {
    hl~used~without~hpad~\msg_line_context:.
}
\end{source}


\section{Compatibility}
\label{sec:compat}

If the box and float functionality is used with a version of \pkg{tcolorbox}
prior to~4.40 (e.g., on \url{https://arxiv.org}, at the time of writing), the
\code*{beforeafter skip balanced} option won't be defined
\begin{source}
\pgfkeysifdefined { /tcb/beforeafter~skip~balanced/.@cmd } { } {
\end{source}
To handle this, at least for the time being, \pkg{pseudo} implements a fallback
version of this option.
\begin{source}
\pgfqkeys { /tcb } {
    before~skip~balanced/.style = { before = {
        \int_compare:nNnF { \lastnodetype } = { -1 } {
            \par
            \mode_if_vertical:T {
                \@@_if_minipage:
                    \dim_compare:nNnTF \parskip > \c_zero_dim {
                        \addvspace{ -\parskip }
                    }
                \else:
                    \bool_lazy_or:nnTF {
                        \dim_compare_p:nNn
                            \prevdepth < \c_zero_dim
                    } {
                        \dim_compare_p:nNn
                            \prevdepth > { .3 \baselineskip }
                    } {
                        \addvspace { \skip_eval:n {
                            #1 - \parskip
                        } }
                    } {
                        \addvspace { \skip_eval:n {
                            #1 + .3 \baselineskip
                            - \prevdepth - \parskip
                        } }
                    }
                \fi:
                \nointerlineskip
            }
        }
        \dim_set_eq:NN \lineskip \c_zero_dim
        \noindent
    } },
    after~skip~balanced/.style = { after = {
        \par
        \mode_if_vertical:T {
            \dim_set:Nn \prevdepth { .3\baselineskip }
            \addvspace { \skip_eval:n { #1 - \parskip } }
        }
    } },
    beforeafter~skip~balanced/.style = {
        before~skip~balanced = { #1 },
        after~skip~balanced  = { #1 }
    }
}
\end{source}
We need to know if the box is in a \code{minipage}, and this is normally
detected as part of \cs{tcb@apply@box@options}. We override that macro (if
\pkg{tcolorbox} has been loaded by the time we reach the end of the preamble) to
insert the approproate definition.
\begin{source}
\RequirePackage{etoolbox}

\AtEndPreamble {
    \@ifpackageloaded { tcolorbox } {
        \tl_set_eq:NN \@@_orig_tcbopt \tcb@apply@box@options
        \def \tcb@apply@box@options #1 {
            \@@_orig_tcbopt { #1 }
            \tl_set_eq:NN \@@_if_minipage: \if@minipage
        }
    } { }
}
\end{source}
End of \cs{pgfkeysifdefined}:
\begin{source}
}
\end{source}
In older version of \pkg{tcolorbox}, we end up with extra space at the top of
the box contents. The simple solution here it so simply add \code{-\cs{parskip}}
of vertical space. This doesn't really do much harm, but it is redundant with
newer versions, and it does interfere with the use of \code*{before upper app},
for example. Therefore, we only add this spacing in older versions (for
simplicity, just going with 4.x and older). We do this at the end of the
preamble, and only if \pkg{tcolorbox} has actually been loaded at that point.
\begin{source}
\AtEndPreamble {
    \@ifpackageloaded { tcolorbox } {

        \cs_new:Npn \@@_vmaj:n #1 { \@@_vmaj_aux:w #1 \q_stop }
        \cs_new:Npn \@@_vmaj_aux:w #1 . #2 \q_stop { #1 }

        \tl_set:Nx \l_tmpa_tl { \exp_args:No \@@_vmaj:n \tcb@version }

        \int_compare:nNnT \l_tmpa_tl < 5 {

            \tcbuselibrary { hooks }
            \tcbset {
                pseudo/boxruled/.append~style = {
                    before~upper~app = \vspace { -\parskip }
                }
            }

        }

    }

}
\end{source}

\printbibliography

\end{document}