summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/skdoc/skdoc.dtx
blob: e8fea60711c3721bca60f88c83e2f249ce338b5a (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
% \iffalse
%% skdoc documentation class
%%
%% Copyright (C) 2012 by Simon Sigurdhsson <sigurdhsson@gmail.com>
%% 
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%%   http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.
%% 
%% This work has the LPPL maintenance status `maintained'.
%% 
%% The Current Maintainer of this work is Simon Sigurdhsson.
%% 
%% This work consists of the files skdoc.dtx
%% and the derived filebase skdoc.cls.
%
%<*ignore>
\begingroup
  \catcode123=1 %
  \catcode125=2 %
  \def\x{LaTeX2e}%
\expandafter\endgroup
\ifcase 0\ifx\install y1\fi\expandafter
        \ifx\csname processbatchFile\endcsname\relax\else1\fi
        \ifx\fmtname\x\else 1\fi\relax
\else\csname fi\endcsname
%</ignore>
%<*install>
\input docstrip.tex

\preamble
\endpreamble

\keepsilent
\askforoverwritefalse

\generate{%
    \file{skdoc.cls}{\from{skdoc.dtx}{class}}%
}

\begingroup
\obeyspaces
\Msg{*************************************************************}%
\Msg{*                                                           *}%
\Msg{* To finish the installation you have to move the following *}%
\Msg{* file into a directory searched by TeX:                    *}%
\Msg{*                                                           *}%
\Msg{*     skdoc.cls                                             *}%
\Msg{*                                                           *}%
\Msg{* To produce the documentation run the file skdoc.dtx       *}%
\Msg{* through LaTeX.                                            *}%
\Msg{*                                                           *}%
\Msg{* Happy TeXing!                                             *}%
\Msg{*                                                           *}%
\Msg{*************************************************************}%
\endgroup%

\endbatchfile
%</install>
%<*ignore>
\fi
%</ignore>
%<*class>
\RequirePackage{expl3}
%</class>
%<*driver>
\RequirePackage{xparse}
\ProvidesExplFile{skdoc.dtx}
%</driver>
%<class>\ProvidesExplClass{skdoc}
%<*class>
    {2012/12/26}{1.0}{skdoc documentation class}
%</class>
%
%<*driver>
\msg_new:nnn{skdoc-dtx}{not-installed}
    {Run~`tex'~on~skdoc.dtx~before~generating~the~documentation!}
\IfFileExists{skdoc.cls}{}{
    \msg_fatal:nn{skdoc-dtx}{not-installed}
}
\ExplSyntaxOff
\DeclareDocumentCommand\MakePercentIgnore{}{\catcode`\%9\relax}
\DeclareDocumentCommand\MakePercentComment{}{\catcode`\%14\relax}
\DeclareDocumentCommand\DocInput{m}{
    \MakePercentIgnore\input{#1}\MakePercentComment
}
\documentclass{skdoc}
\usepackage{hologo}
\usepackage{booktabs}
\usepackage[style=authoryear,backend=biber]{biblatex}
%%\usepackage{chslacite}
\begin{filecontents}{skdoc.bib}
@online{Lazarides12,
    author = {Yannis Lazarides},
    title = {Different approach to literate programming for \LaTeX},
    year = {2012},
    url = {http://tex.stackexchange.com/q/47237/66}
}
@online{Talbot13,
    author = {Nicola Talbot},
    title = {Answer to \enquote{Distinct formatted page numbers with glossaries and Xindy}},
    year = {2013},
    url = {http://tex.stackexchange.com/a/89830/66}
}
\end{filecontents}
\addbibresource{skdoc.bib}
\OnlyDescription
\begin{document}
    \DocInput{skdoc.dtx}
\end{document}
% \fi
%
% \deftripstyle{skdoc-class}{}{}{}%
% {\small The~\textbf{\thepkg}~document~class,~\theversion}%
% {}{\small\pagemark}
% \pagestyle{skdoc-class}
%
% \version{1.0}
% \changes{1.0}{Initial version}
%
% \package[ctan=skbundle,vcs=https://github.com/urdh/skdoc]{skdoc}
% \repository{https://github.com/urdh/skdoc}
% \title{The \thepkg{} document class}
% \author{Simon Sigurdhsson}
% \email{sigurdhsson@gmail.com}
% \maketitle
%
% \begin{abstract}
% The \thepkg{} class provides macros to document the functionality
% and implementation of \LaTeX\ packages and document classes. It is
% loosely based on the \pkg{ydoc} and \pkg{ltxdoc} classes, but has
% a number of incompatible differences.
%
% The class defines a \env{MacroCode} environment which substitutes
% the usual \pkg{docstrip} method of installing packages. It has the
% ability to generate both documentation and code in a single run of
% a single file.
% \end{abstract}
%
% \tableofcontents
%
% \section{Introduction}
% This document class, inspired by a question on the \TeX\ Stack
% Exchange\footcite{Lazarides12}, aims to provide an alternative to
% the standard \pkg{docstrip} method of literate programming for
% \LaTeX\ packages. It also aims to provide a more modern, appealing
% style for \LaTeX\ package documentation.
%
% In order to achieve this, it builds upon already existing features
% of the \pkg{expl3}, \pkg{verbatim} and \pkg{ydoc} packages as well
% as the KOMA-script document classes.
%
% So far it is mainly intended to be an experiment to explore a less
% cumbersome way of writing \LaTeX\ packages, and as such I give no
% guarantee that this package will continue to exist in a working
% state (\emph{i.e.} future users may not be able to extract code from
% package documentation based on \thepkg) or that its public API
% (commands and environments described by this documentation; consider
% undocumented macros part of a private API) will be stable.
%
% The documentation of \thepkg\ is in fact typeset using the class
% itself. It does not, however, make use of the main feature of this
% class (the \env{MacroCode} environment), because bootstrapping the
% class to generate itself is more complicated than it is useful.
%
% \section{Documentation}
% Since \thepkg\ is based on \pkg{ydoc} many of the macros and
% environment present in that package are also available in \thepkg,
% in a possibly redefined incanation. However, any macros or
% environment present in \pkg{ydoc} but not described in this
% documentation should be considered part of the private API of
% \thepkg. In the future, the removal of the \pkg{ydoc} dependency
% may result in such macros being unavailable, and at present changes
% made by \thepkg\ may break such macros without notice.
%
% \subsection{Options}
% \Option{load}\WithValues{\meta{package}}\AndDefault{\cs{jobname}}
% The \thepkg\ document class has only one option. The \opt{load}
% option declares that if the package specified exists, it should
% be loaded. This is intended to load any package provided in the
% implementation, but requires that the documentation provides
% stub variants of the macros used in the documentation so that
% \LaTeX\ still completes its first run. \Warning{The \opt{load}
% option will likely disappear in a future version.}
%
% \subsection{General macros}
% The document class defines a number of general macros intended for
% use in parts of the document not strictly considered
% \enquote{documentation} or \enquote{implementation}, in addition to
% being used in those parts. These \enquote{general} macros include
% macros that define metadata, generate the title page, typeset
% notices or warnings and those that refer to macros, environments,
% packages and such.
%
% \subsubsection{Metadata}
% Several macros for defining metadata (\emph{i.e.} information about
% the package and its documentation) are made available. These mostly
% set an internal variable which is used to typeset the title page,
% and to insert PDF metadata whenever \hologo{pdfLaTeX} is used to
% generate the documentation.
%
% \DescribeMacro\package['ctan='<identifier>',vcs='<url>]{<package name>}
% The \cs{package} macro defines the package name used by \cs{thepkg},
% \cs{maketitle} and similar macros. It also calls \cs{title} to set
% a sensible default title based on the package name. The optional
% key-value argument takes two keys: \texttt{ctan} and \texttt{vcs}.
% The first one accepts an optional value \meta{identifier}, which
% should be the identifier the package has on CTAN (the default is
% \cs{jobname}), while the other takes a mandatory argument \meta{url}
% specifying the URL of a VCS repository where development versions
% of the package are available. The two optional keys imply calls to
% the \cs{ctan} and \cs{repository} macros, respectively.
%
% \DescribeMacro\version{<version>}
% Sets the version number of the package the documentation describes.
% Here, \meta{version} should not include the initial \enquote{v},
% \emph{i.e.} the argument should be the same as that given to
% \emph{e.g.} the \LaTeX3 \cs{ProvidesExplPackage} or the standard
% \pkg{ltxdoc} \cs{changes}.
%
% \DescribeMacro\ctan{<identifier>}
% As detailed above, this macro defines the CTAN identifier of the
% package, which is (optionally) used in the \cs{maketitle} macro.
%
% \DescribeMacro\repository{<url>}
% Again, as detailed above this macro defines the URL of a source code
% repository containing a development version of the package, which
% is optionally used by \cs{maketitle}.
%
% \DescribeMacro\author{<name>}
% Defines the name of the package author. This is used by
% \cs{maketitle} and is mandatory if \cs{maketitle} is used.
%
% \DescribeMacro\email{<email>}
% Defines the email of the package author. This is used by
% \cs{maketitle} and is mandatory if \cs{maketitle} is used.
%
% \DescribeMacro\title{<title>}
% Defines the package title. By default, the \cs{package} macro sets
% a sensible title that should suit most packages, but using \cs{title}
% will override this title (useful for \emph{e.g.} document classes or
% \hologo{BibTeX} styles).
%
% Three macros retrieving the set metadata are also available. They
% can be used to typeset the current version of the package, and the
% package name, respectively.
%
% \DescribeMacro\theversion
% Returns the version as defined by \cs{version}, with a leading
% \enquote{v}. That is, issuing \Macro\version{1.0} makes 
% \cs{theversion} print \enquote{v1.0}.
%
% \DescribeMacro\thepackage
% \DescribeMacro\thepkg
% The \cs{thepackage} and \cs{thepkg} macros return the package name
% as defined by the \cs{package} macro, enclosed in \cs{pkg*}. That is,
% the package name is typeset as a package but not indexed.
%
% \subsubsection{The preamble}
% The preamble of any documentation most often consists of a title page
% containing an abstract, and possibly a table of contents. The \thepkg
% \ package provides macros and environments that typeset such things,
% and these should be fully compatible with most other document classes.
%
% \DescribeMacro\maketitle
% The \cs{maketitle} macro typesets a title page. This title page uses
% the metadata defined by the macros described earlier, and typesets
% them in a manner which is illustrated by the documentation of this
% class. This style is inspired by \pkg{skrapport}, which is in turn
% inspired by the title pages of the Prac\TeX\ Journal.
%
% \DescribeEnv[<package abstract>]{abstract}
% The \env{abstract} environment typesets an abstract of the package.
% Again, its style is illustrated by this document and it is inspired
% by the \pkg{skrapport} package as well as the Prac\TeX\ Journal.
%
% \DescribeMacro\tableofcontents
% Finally, a Table of Contents may be printed. The actual table of
% contents is provided by the \pkg{scrartcl} document class, but \thepkg
% \ redefines a couple of the internal macros to style the Table of
% Contents in a manner similar to that of the \pkg{microtype} manual.
%
% \subsubsection{The LPPL license}
% \DescribeMacro\PrintLPPL
% If the LPPL license is present in a directory where \LaTeX\ can find
% it, in a file called \file{lppl.tex}, then \cs{PrintLPPL} will
% include the entire LPPL license in the document, and typeset it in
% a fairly compact manner.
%
% \subsubsection{Notices and warnings}
% The document class provides macros to indicate information that may
% be of extra importance in the documentation. Such information is
% categorized as either notices or warnings, which are treated
% differently.
% 
% \DescribeMacro\Notice{<notice>}
% A notice is a short piece of text that contains information that may
% explain some unexpected but unharmful behaviour of a macro or similar.
% It is typeset inline, emphasized and in parantheses --- as such, the
% sequence \Macro\Notice{a notice} yields \Notice{a notice}.
%
% \DescribeMacro\Warning{<warning>}
% A warning is a short comment that conveys information that the user
% must be aware of. This includes unexpected potentially harmful
% behaviour, deprecation notices and so on. It is typeset in its own
% \cs{fbox} --- the sequence \Macro\Warning{a warning} yields the
% following: \Warning{a warning}
%
% \DescribeMacro\LongWarning{<warning>}
% The \cs{LongWarning} macro is a variant of \cs{Warning} that has been
% adapted for longer texts, possibly including paragraph breaks. Like
% \cs{Warning}, it is typeset in a box: \LongWarning{a long warning}
%
% \subsubsection{Referential macros}\label{sec:ref-macros}
% The family of macros originating from \cs{cs} are used to typeset
% various concepts in running text. In addition to adhering to the
% general format of the corresponding concept, they index their
% argument. Each of these macros have a starred variant which does
% not index its argument; use these when appropriate.
%
% \DescribeMacro\cs{<command sequence>}
% Typesets a command sequence, or macro. The argument should be
% provided without the leading backslash, and the command sequence
% will be typeset in a monospaced font.
%
% \DescribeMacro\env{<environment name>}
% Typesets an environment name, which will be typeset in a monospace
% font.
%
% \DescribeMacro\pkg{<package name>}
% Typesets a package, document class or bundle name. The name will
% be typeset in a sans-serif font.
%
% \DescribeMacro\opt{<option>}
% Typesets a package or document class option. As of \theversion,
% options are typeset using a monospace font.
%
% \DescribeMacro\bib{<\hologo{BibTeX} entry type>}
% Typesets a \hologo{BibTeX} entry type. The agument should be provided
% without the leading \texttt{@} sign. The entry type will be typeset
% in a monospace font.
% 
% \DescribeMacro\thm{<theme name>}
% Typesets a theme name. As of \theversion, the theme name will be
% typeset in an upright serif font.
%
% \DescribeMacro\file{<filename>}
% Typesets a filename. As of \theversion, the filename will be typeset
% in a monospace font.
%
% \subsection{Documenting the package}\label{sec:doc-macros}
% The documentation part of any \LaTeX\ manual is arguably the most
% important one, and to facilitate proper typesetting of the
% documentation \thepkg\ povides a number of different macros, all
% inspired by or inherited from \pkg{ydoc}. The first of these
% macros that will be discussed are the macros that typeset differen
% kinds of arguments in running text.
%
% \DescribeMacro\meta{<meta text>}
% The \cs{meta} macro typesets a placeholder to be placed in an
% argument. This can be used to refer to arguments and contents of
% macros and environments described by commands discussed later in
% this documentation. It is typeset in brackets: \meta{meta text}.
%
% \DescribeMacro\marg{<mandatory argument>}
% \DescribeMacro\oarg{<optional argument>}
% \DescribeMacro\parg{<picture-style argument>}
% \DescribeMacro\aarg{<beamer-style argument>}
% \DescribeMacro\sarg
% These macros typeset different kinds of arguments (mandatory,
% optional, picture-style, beamer-style and star arguments,
% respetively). These can be used to describe arguments, but
% are mostly used internally. See table~\ref{tab:args} for
% examples of how these macros are typeset.
%
% \begin{table}[tb]
%   \centering
%   \caption{Typesetting arguments}
%   \label{tab:args}
%   \begin{tabular}{ll}
%      \toprule
%      Invokation            % Result          \\
%      \midrule
%      \Macro\marg{argument} & \marg{argument} \\
%      \Macro\oarg{argument} & \oarg{argument} \\
%      \Macro\parg{argument} & \parg{argument} \\
%      \Macro\aarg{argument} & \aarg{argument} \\
%      \Macro\sarg           & \sarg           \\
%      \bottomrule
%   \end{tabular}
% \end{table}
%
% \subsubsection{Options}
% Package options are of course important to describe, and to this
% end four macros are provided. They aid in describing options of
% both regular boolean and the more modern key-value syntax. They
% are intended to be used in a sequence: \\ 
% \mbox{\Macro\Option{...}
%       \AlsoMacro\WithValues{...}
%       \AlsoMacro\AndDefault{...}}
%
% \DescribeMacro\Option{<option>}
% \DescribeMacro\Options{<option>,...}
% These macros typeset an option, and may be followed by the
% \cs{WithValues} macro \Notice{the with \cs{Options}, only the
% first option in the list will work with \cs{WithValues}}.
%
% \DescribeMacro\WithValues{<value>,...}
% This macro typesets a comma-separated list of values a specific
% option can take. It may be followed by the \cs{AndDefault} macro.
%
% \DescribeMacro\AndDefault{<default value>}
% This macro typesets the default value of an option. It may follow
% either \cs{Options} or \cs{WithValues}.
%
% Common constructs using these macros include:
% \begin{itemize}
% \item \mbox{\small
%       \Macro\Option{<option>}
%       \AlsoMacro\WithValues{<value>,...}
%       \AlsoMacro\AndDefault{<default>}}
% \item \mbox{\small
%       \Macro\Options{<option>,no\meta{option}}
%       \AlsoMacro\AndDefault{no\meta{option}}}
% \end{itemize}
% 
% \subsubsection{Macros}
% The \thepkg\ class inherits a number of macros for describing the
% package macros from the \pkg{ydoc} package. Only four of them are
% to be considered stable.
% \LongWarning{
% The macros \cs{MakeShortMacroArgs} and \cs{DeleteShortMacroArgs}
% and the environments \env{DescribeMacros} and \env{DescribeMacrosTab}
% provided by \pkg{ydoc} are unsupported as of \thepkg\ \theversion. 
% They may work, but this is
% not a guarantee and they are most likely broken or may break other
% features of \thepkg.
% }
%
% \DescribeMacro\DescribeMacro<\textbackslash macro><macro arguments>
% The \cs{DescribeMacro} macro documents a macro along with its
% arguments. Any number of \meta{macro arguments} may follow the macro,
% and \cs{DescribeMacro} will stop reading arguments on the first
% non-argument token. The macro will be indexed.
% \LongWarning{Although \meta{\textbackslash macro} can include
% \texttt{@} signs, it is not possible to document \LaTeX3-style
% macros (with underscores and colons) without the following hack:
% \par \medskip \begingroup
% \cs*{ExplSyntaxOn} \\
% \cs*{cs\_set\_protected\_nopar:Npn}\cs*{ExplHack}\texttt{\{} \\
% \hspace*{2ex}\cs*{char\_set\_catcode\_letter:n}\texttt{\{~58~\}} \\
% \hspace*{2ex}\cs*{char\_set\_catcode\_letter:n}\texttt{\{~95~\}} \\
% \texttt{\}} \\
% \cs*{ExplSyntaxOff} \\
% \cs*{ExplHack} \\
% \endgroup }
%
% \DescribeMacro\Macro<\textbackslash macro><macro arguments>
% This is simply a variant of \cs{DescribeMacro} for use in running
% text. It is equivalent to \cs{MacroArgs}\cs{AlsoMacro}.
%
% \DescribeMacro\MacroArgs<macro aguments>
% This macro formats \meta{macro arguments} the same way
% \cs{DescribeMacro} does. As with \cs{Macro}, it is used in
% running text.
%
% \DescribeMacro\AlsoMacro<\textbackslash macro><further arguments>
% This macro should be used inside \meta{macro arguments} of the macros
% described above, and typesets an additional macro as part of the
% syntax of the described macro. For instance, the \cs{csname} macro
% could be described with the sequence
% \cs*{Macro}\cs*{csname}\texttt{<command sequence name>}
% \cs*{AlsoMacro}\cs{endcsname}, which would be rendered as
% \Macro\csname<command sequence name>\AlsoMacro\endcsname\relax.
%
% \subsubsection{Environments}
% In addition to the macros describing macros, \thepkg\ also inherits
% one environment and one macro to describe environments. These are
% similar to the macros described previously in both form and function,
% but lack equivalents for running text.
%
% \DescribeMacro\DescribeEnv[<body content>]{<name>}<arguments>
% This macro describes an environment, in the same way
% \cs{DescribeMacro} does for macros. The \meta{body content}, which
% is optional, may be used to indicate what kind of content the
% environment is designed to contain. The \cs{MacroArgs}
% macro is automatically inserted before \meta{body content}.
%
% \subsubsection{Other entities}
% The document class also provides macros to describe \hologo{BibTeX}
% entries and generic themes. The \hologo{BibTeX} entries are described
% using the \cs{BibEntry} and \cs{WithFields} macros, while themes are
% described using the \cs{Theme} macro.
%
% \DescribeMacro\BibEntry{<entry name>}
% \AlsoMacro\WithFields[<optional fields>]{<mandatory fields>}
% These two macros describe a \hologo{BibTeX} entry named
% \meta{entry name} (\emph{i.e.}, \bib*{\meta{entry name}}) along with
% its optional and mandatory fields.
%
% \DescribeMacro\Theme{<theme name>}
% This macro describes a theme named \meta{theme name}. These could be
% used to describe any kind of theme, such as color themes of a
% document class.
%
% \DescribeMacro\DescribeFile{<filename>}
% This macro describes a special file named \meta{filename}. This
% could be a configuration file or similar that is either part of
% the package or something the package reads if available.
%
% \subsection{Describing the implementation}
% In true \TeX\ (and literal programming) fashion the document class
% also provides ways to describe, in detail, parts of the
% implementation. The most essential of the implementation environments,
% without which \thepkg\ doesn't generate any files, is the
% \env{MacroCode} environment. Other than that, the implementation
% environments should be compatible with or analogous to the standard
% \pkg{ltxdoc} document class.
% 
% \subsubsection{Implementation environments}\label{sec:impl-env}
% The environments described in this section indicate the
% implementation of different concepts including macros, environments
% and options. They each have a starred variant which doesn't print
% the concept name (only indexes it), and a non-starred variant which
% does \Notice{inside these environments, \cs{changes} will refer to
% the relevant entity instead of logging \enquote{general} changes}.
%
% Some of the following environment can typeset descriptions of the 
% internal arguments (\texttt{\#1}, \texttt{\#2} \emph{etc.}) to
% improve readability of the implementation code.
%
% \DescribeEnv[<description>]{macro}{<\textbackslash macro>}
%                     <\# of args>{<arg 1 description>}'...'
%                                 {<arg n description>}
% With this environment, the implementation of a macro is described.
% Note that as with \cs{DescribeMacro}, \LaTeX3-style macros can not
% be used in \meta{\textbackslash macro} without the catcode hack
% mentioned earlier.
%
% \DescribeEnv[<description>]{environment}{<environment>}
%                     <\# of args>{<arg 1 description>}'...'
%                                 {<arg n description>}
% This environment describes the implementation of an environment.
%
% \DescribeEnv[<description>]{option}{<option>}
% This environment describes the implementation of an option.
%
% \DescribeEnv[<description>]{bibentry}{<@entry>}
% This environment describes the implementation of a \hologo{BibTeX}
% entry type.
%
% \DescribeEnv[<description>]{theme}{<theme>}
% This environment describes the implementation of a theme.
%
% \subsubsection{The \env{MacroCode} environment}
% The \enquote{main event} of the \thepkg\ document class is the
% \env{MacroCode} environment. It has roughly the same role the 
% \env{macrocode} environment has in the \pkg{docstrip} system, except
% that it in addition to typesetting the implementation also saves it
% to the target files.
%
% The workflow is simple; before using \env{MacroCode} to export code
% to a file the file must be declared using \cs{DeclareFile}, which
% also assigns a key to the file (the default is the filename). This
% key is passed to the \env{MacroCode} environment, which saves the
% code to the specified file.
%
% \DescribeMacro\DeclareFile['key='<key>',preamble='<preamble>]{<filename>}
% The \cs{DeclareFile} macro declares a file for future use with
% \env{MacroCode}. The optional argument is a comma separated list of
% key-value options, where the possible keys are \texttt{key} and
% \texttt{preamble}. Here \meta{key} is a key that is used instead
% of the filename in \env{MacroCode}, and \meta{preamble} is a
% token or command sequence expanding to a preamble which will be 
% prepended to the file on output.
%
% \DescribeMacro\PreambleTo{<\textbackslash token>}{<filename>}
% Reads the preamble from \meta{filename}. Lines from the file are
% appended to \meta{\textbackslash token} until a line which does not
% begin with \texttt{\%\%} is encountered.
%
% \DescribeMacro\SelfPreambleTo{<\textbackslash token>}
% This reads the preamble from the curent file. It is equivalent to
% the sequence
% \Macro\PreambleTo{<\textbackslash token>}{\cs*{jobname}.tex}.
%
% \DescribeEnv[<implementation>]{MacroCode}{<key>}
% The \env{MacroCode} environment typesets and exports
% \meta{implementation} verbatim to the file associated with \meta{key}.
% As such, it is the analogue of the \env{macrocode} environment from
% \pkg{ltxdoc}, but does not suffer from some of its drawbacks (the
% sensitivity to whitespace, for instance).
%
% \subsubsection{Hiding the implementation}
% For lagre packages it may be of interest to hide the implementation
% from the documentation. This is accomplished using the two marker
% macros \cs{Implementation} and \cs{Finale} (which should be present
% even if not hiding the implementation), and the switch macro
% \cs{OnlyDescription}.
%
% \DescribeMacro\Implementation
% This macro indicates the start of the implementation. Normally, this
% would directly precede the \cs{section} under which the implementation
% is organized.
%
% \DescribeMacro\Finale
% This macro indicates the end of the implementation. Usually the only
% things happening after this is the printing of indices, the change
% log, bibliographies and the end of the \env{document} environment.
%
% \DescribeMacro\OnlyDescription
% This macro, which should be issued in the preamble, indicates that the
% implementation should be hidden. \Warning{this has the side effect
% that a page break is inserted where the implementation would normally
% reside.}
%
% \subsection{Documenting changes}
% One type of useful information you should provide in your
% documentation is a list of changes. The \thepkg\ document class
% provides a change list system based on the \pkg{glossaries} package.
% As such, including a change list in your documentation requires you
% to run \texttt{makeglossaries} between the first and second \LaTeX\
% run.
%
% \DescribeMacro\changes{<version>}{<description>}
% The \cs{changes} macro provides the main interface to the change
% list system, and adds changes to the change list. Each change is
% added with a \emph{context}; if the macro is issued inside one of
% the macros described in section~\ref{sec:impl-env}, the concept
% currenly being described will be the context. Outside these
% environment, the context is \enquote{general}. For every context
% and \meta{version}, only one change may be recorded, otherwise
% \pkg{glossaries} will issue a warning.
%
% \DescribeMacro\PrintChanges
% This macro prints the list of changes. As explained earlier, this
% requires you to run \texttt{makeglossaries} between the two \LaTeX\ 
% runs.
%
% \subsection{Producing an index}
% The macros previously discussed in sections~\ref{sec:ref-macros},
% \ref{sec:doc-macros} and \ref{sec:impl-env} automatically index their
% aguments using \pkg{glossaries}. By running \texttt{makeglossaries}
% you can include an index of all macros, environments, packages and 
% such that are discussed, documented or implemented in your package.
%
% \DescribeMacro\PrintIndex
% Much like the \cs{PrintChanges} macro, this prints the index. As with
% the list of changes, this requires that you run 
% \texttt{makeglossaries} between the two \LaTeX\ runs.
%
% \iffalse
% \section{Planned improvements}
% Planned improvements of this class include
% \begin{itemize}
%     \item Do things the \LaTeX3 way, rename the variables properly
%           and generally conform to \pkg{expl3} guidelines when
%           applicable. (Way future thing.)
% \end{itemize}
% \fi
%
% \Implementation
% \section{Implementation}
% \iffalse
%</driver>
%<*class>
% \fi
% \subsection{Require packages}
% We begin with loading the \pkg{scrartcl} KOMA-script class and a
% few packages we'll be needing.
%    \begin{macrocode}
\PassOptionsToPackage{log-declarations=false}{xparse}
\LoadClass[ DIV7,
            headings=big,
            numbers=noenddot,
            abstracton,
            bibliography=totocnumbered,
            index=totoc
        ]{scrartcl}
%    \end{macrocode}
% These packages are basic low-level things that we use to declare
% commands, work with strings and so on.
%    \begin{macrocode}
\RequirePackage{etoolbox,xstring,xparse,atbegshi,kvoptions}
%    \end{macrocode}
% Now, higher-level packages we use in our definitions.
%    \begin{macrocode}
\RequirePackage{verbatim,marginnote,calc,hyperref,multicol,hologo}
\RequirePackage[nomain,xindy,numberedsection,order=letter,
                sanitize={description=false,sort=false}]{glossaries}
%    \end{macrocode}
% We also include the \pkg{ydoc} packages we'll be extending.
%    \begin{macrocode}
\RequirePackage{ydoc-code,ydoc-desc}
%    \end{macrocode}
% The rest is basically just styling.
%    \begin{macrocode}
\RequirePackage[british]{babel}
\RequirePackage[english=british]{csquotes}
\RequirePackage[font=small,labelfont=bf,textfont=it]{caption}
\RequirePackage{scrpage2,PTSerif,ascii}
\RequirePackage[defaultsans,osfigures,scale=0.95]{opensans}
\RequirePackage[babel]{microtype}
%    \end{macrocode}
% \subsection{Error messages}
% Set up some error message texts for later use.
%    \begin{macrocode}
\msg_new:nnn{skdoc}{key-exists}{File~key~"#1"~already~declared!}
\msg_new:nnn{skdoc}{key-nexists}{File~key~"#1"~hasn't~been~declared!}
\msg_new:nnn{skdoc}{wrote-file}{Writing~things~to~file~"#1".}
\msg_new:nnn{skdoc}{read-preamble}{Reading~preamble~from~file~"#1".}
\msg_new:nnn{skdoc}{no-lppl}{Could~not~include~LPPL:~lppl.tex~does~not~exist!}
%    \end{macrocode}
% \subsection{Options}
% Define the (as of version 1.0) only option, and process it.
%    \begin{macrocode}
\SetupKeyvalOptions{
    family=skdoc,
    prefix=skdoc@
}
\DeclareStringOption{load}[\jobname]
\ProcessKeyvalOptions*
%    \end{macrocode}
% If the option was used, load the given package if it exists.
%    \begin{macrocode}
\IfStrEq{\skdoc@load}{}{}{%
    \IfFileExists{\skdoc@load.sty}{%
        \RequirePackage{\skdoc@load}
    }{}
}
%    \end{macrocode}
% \subsection{The \env{MacroCode} environment}
% We need a token list and input/output.
%    \begin{macrocode}
\tl_new:N\skdoc@temptl
\ior_new:N\skdoc@input
\iow_new:N\skdoc@output
%    \end{macrocode}
% \begin{macro}{\DeclareFile}[2]
%   {A list of key-value parameters}
%   {Filename of the file being declared}
% This declares a file as part of the bundle, which means we will be
% writing things to it.
%    \begin{macrocode}
\DeclareDocumentCommand\DeclareFile{om}{
    \group_begin:
    \keys_define:nn{skdoc@declarefile}{%
        preamble .value_required:,
        preamble .code:n = \edef\skdoc@preamble{##1},
        key .value_required:,
        key .code:n = \def\skdoc@key{##1}
    }%
    \def\skdoc@preamble{}%
    \def\skdoc@key{#2}%
    \IfNoValueTF{#1}{}{\keys_set:nn{skdoc@declarefile}{#1}}
    \tl_new:c{skdoc@output@\skdoc@key}
    \int_if_exist:cTF{skdoc@output@\skdoc@key @line}{
        \msg_critical:nnx{skdoc}{key-exists}{\skdoc@key}
    }{
        \int_zero_new:c{skdoc@output@\skdoc@key @line}
    }
    \IfStrEq{\skdoc@preamble}{}{}{
        \tl_set:Nx\l_tmpa_tl{\skdoc@preamble}
        \edef\skdoc@temp{\tl_head:N\l_tmpa_tl}
        \def\skdoc@preamble@extra{
            \skdoc@temp\skdoc@temp\space~This~is~file~`#2',~generated~from~`\c_job_name_tl.tex'~(key~`\skdoc@key').
        }
    }
    \expandafter\xdef\csname skdoc@write@#2\endcsname{%
        \noexpand\msg_log:nnn{skdoc}{wrote-file}{#2}
        \noexpand\iow_open:Nn\noexpand\skdoc@output{#2}
        \noexpand\IfStrEq{\skdoc@preamble}{}{}{
            \noexpand\iow_now:Nx\noexpand\skdoc@output{\skdoc@preamble@extra}
            \noexpand\iow_now:Nx\noexpand\skdoc@output{\skdoc@preamble}
        }
        \noexpand\iow_now:Nx\noexpand\skdoc@output{\noexpand\tl_to_str:c{skdoc@output@\skdoc@key}}
        \noexpand\iow_close:N\noexpand\skdoc@output
    }
    \AfterEndDocument{\csname skdoc@write@#2\endcsname}
    \group_end:
}
%    \end{macrocode}
% \end{macro}
% \begin{environment}{skdoc@verbatim}[1]
%   {The key of the file being described}
% This environment does all the actual work for \env{MacroCode}.
%    \begin{macrocode}
\DeclareDocumentEnvironment{skdoc@verbatim}{m}{%
    \iftoggle{skdoc@impl}{\@bsphack}{}
    \def\skdoc@key{#1}
    \int_if_exist:cTF{skdoc@output@\skdoc@key @line}{}{
        \msg_critical:nnx{skdoc}{key-nexists}{\skdoc@key}
    }%
    \marginnote{
        \leavevmode
        \llap{
            \scriptsize\color{gray}
            $\langle$\skdoc@key$\rangle$
            \makebox[2ex]{\strut}
        }
    }
    \def\verbatim@processline{%
        \tl_gput_right:cx{skdoc@output@\skdoc@key}{\the\verbatim@line\iow_newline:}%
        \int_gincr:c{skdoc@output@\skdoc@key @line}%
        \iftoggle{skdoc@impl}{
            \noindent\leavevmode%
            \hspace*{-5ex}
            \begin{minipage}[c][1ex]{\textwidth}
                \makebox[4ex]{%
                    \leavevmode
                    \tiny\color{lightgray}\hfill%
                    \int_use:c{skdoc@output@\skdoc@key @line}%
                }%
                \hspace*{1ex}%
                {
                    \verbatim@font\footnotesize
                    \the\verbatim@line
                }
            \end{minipage}
            \vskip-.75ex\par
        }{}
    }%
    \let\do\@makeother\dospecials\catcode`\^^M\active%
    \iftoggle{skdoc@impl}{
        \frenchspacing\@vobeyspaces
    }{}
    \verbatim@start%
}{%
    \iftoggle{skdoc@impl}{\@esphack}{}%
}
%    \end{macrocode}
% \end{environment}
% \begin{environment}{MacroCode}[1]
%   {The key of the file being described}
%    \begin{macrocode}
\DeclareDocumentEnvironment{MacroCode}{m}{
    \iftoggle{skdoc@impl}{
        \vspace{.2\baselineskip}
        \par\noindent
    }{}
    \skdoc@verbatim{#1}
}{
    \endskdoc@verbatim
    \iftoggle{skdoc@impl}{
        \vspace{.5\baselineskip}
    }{}
}
%    \end{macrocode}
% \end{environment}
%
% \subsubsection{Reading a preamble}
% \begin{macro}{\PreambleTo}[2]
%   {A token to which we will save the preamble}
%   {File to read the preamble from}
% Read preamble from a document and store in variable.
%    \begin{macrocode}
\DeclareDocumentCommand\PreambleTo{mm}{%
    \group_begin:
    \msg_info:nnn{skdoc}{read-preamble}{#2}
    \ior_open:Nn\skdoc@input{#2}
    \bool_until_do:nn{\ior_if_eof_p:N\skdoc@input}{%
        \tl_if_empty:NTF\skdoc@temptl{}{%
            \tl_put_right:Nx\skdoc@temptl{\iow_newline:}
        }
        \tl_clear:N\l_tmpb_tl
        \ior_get_str:NN\skdoc@input\l_tmpa_tl
        \tl_put_right:Nx\l_tmpb_tl{\tl_head:N\l_tmpa_tl}
        \IfStrEq{\tl_to_str:N\l_tmpb_tl}{\@percentchar}{%
            \tl_set_eq:NN\l_tmpb_tl\skdoc@temptl
            \tl_concat:NNN\skdoc@temptl\l_tmpb_tl\l_tmpa_tl
        }{%
            \ior_close:N\skdoc@input
        }
    }
    \xdef#1{\tl_to_str:N\skdoc@temptl}
    \group_end:
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\SelfPreambleTo}[1]
%   {A token to which we will save the preamble}
% Shorthand to read preamble from current document.
%    \begin{macrocode}
\DeclareDocumentCommand\SelfPreambleTo{m}{%
    \PreambleTo{#1}{\c_job_name_tl}%
}
%    \end{macrocode}
% \end{macro}
%
% \subsection{Styling}
% \subsubsection{Colors}
% First, we redefine a couple of colors from \pkg{ydoc} as well as
% defining a couple for ourselves.
%    \begin{macrocode}
\definecolorset{RGB}{}{}{
    section,11,72,107;
    extlink,73,10,61;
    intlink,140,35,24;
    sharp,250,105,0;
    bright,198,229,217;
    macrodesc,73,10,61;
    keydesc,140,35,24;
    macroimpl,73,10,61;
    meta,11,72,107;
    scriptcolor,140,35,24;
    optioncolor,73,10,61;
    opt,73,10,61
}
%    \end{macrocode}
% \subsubsection{Fonts}
% Then we redefine a couple of the KOMA-script font commands to use
% our newly defined colors, along with other fixes.
%    \begin{macrocode}
\RenewDocumentCommand\descfont{}{\sffamily\fontseries{sb}}
\RenewDocumentCommand\sectfont{}{\sffamily\fontseries{sb}}
\addtokomafont{minisec}{\bfseries}
\addtokomafont{paragraph}{\color{section}}
\addtokomafont{section}{\color{section}}
\addtokomafont{subsection}{\color{section}}
\addtokomafont{subsubsection}{\color{section}}
\addtokomafont{descriptionlabel}{\color{section}}
\addtokomafont{sectionentry}{\rmfamily\bfseries}
\addtokomafont{sectionentrypagenumber}{\rmfamily\bfseries}
%    \end{macrocode}
% \subsubsection{Configuring \pkg{hyperref}}
% Finally, we set up \pkg{hyperref} to also use our colors.
%    \begin{macrocode}
\hypersetup{
    colorlinks=true,
    linkcolor=intlink,
    anchorcolor=intlink,
    citecolor=black,
    urlcolor=extlink
}
%    \end{macrocode}
%
% \subsection{Documentation macros}
% We can now start defining the documentation macros.
%
% \subsubsection{Inline referencing}
% We introduce a couple of macros for referencing various constructs
% in running text, \emph{i.e.} \cs{cs}-like macros. The starred
% variants will not index the use, the non-starred variants will.
%
% First, though, we introduce a toggle letting us permanently disable
% indexing inside \emph{e.g.} the table of contents and index.
%    \begin{macrocode}
\newtoggle{skdoc@noindex}
\togglefalse{skdoc@noindex}
%    \end{macrocode}
% \begin{macro}{\cs}[2]
%   {True if this is the starred variant}
%   {The macro name to be typeset}
% The \cs{cs} macro typesets a macro.
%    \begin{macrocode}
\DeclareDocumentCommand\cs{sm}{
    \texttt{\char`\\#2}
    \iftoggle{skdoc@noindex}{}{
        \IfBooleanTF{#1}{}{\index@macro{#2}}
    }
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\env}[2]
%   {True if this is the starred variant}
%   {The environment name to be typeset}
% The \cs{env} macro typesets an environment.
%    \begin{macrocode}
\DeclareDocumentCommand\env{sm}{
    \texttt{#2}
    \iftoggle{skdoc@noindex}{}{
        \IfBooleanTF{#1}{}{\index@environment{#2}}
    }
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\pkg}[2]
%   {True if this is the starred variant}
%   {The package name to be typeset}
% The \cs{pkg} macro typesets a package.
%    \begin{macrocode}
\DeclareDocumentCommand\pkg{sm}{
    \textsf{#2}
    \iftoggle{skdoc@noindex}{}{
        \IfBooleanTF{#1}{}{\index@package{#2}}
    }
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\opt}[2]
%   {True if this is the starred variant}
%   {The option name to be typeset}
% The \cs{opt} macro typesets an option
%    \begin{macrocode}
\DeclareDocumentCommand\opt{sm}{
    \texttt{#2}
    \iftoggle{skdoc@noindex}{}{
        \IfBooleanTF{#1}{}{\index@option{#2}}
    }
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\bib}[2]
%   {True if this is the starred variant}
%   {The \hologo{BibTeX} entry type name to be typeset}
% The \cs{bib} macro typesets a \hologo{BibTeX} entry type.
%    \begin{macrocode}
\DeclareDocumentCommand\bib{sm}{
    \texttt{@#2}
    \iftoggle{skdoc@noindex}{}{
        \IfBooleanTF{#1}{}{\index@bibentry{#2}}
    }
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\thm}[2]
%   {True if this is the starred variant}
%   {The theme name to be typeset}
% The \cs{thm} macro typesets a theme of some sort.
%    \begin{macrocode}
\DeclareDocumentCommand\thm{sm}{
    \textrm{#2}
    \iftoggle{skdoc@noindex}{}{
        \IfBooleanTF{#1}{}{\index@theme{#2}}
    }
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\file}[2]
%   {True if this is the starred variant}
%   {The file name to be typeset}
% The \cs{file} macro typesets a file name.
%    \begin{macrocode}
\DeclareDocumentCommand\file{sm}{
    \texttt{#2}
    \iftoggle{skdoc@noindex}{}{
        \IfBooleanTF{#1}{}{\index@file{#2}}
    }
}
%    \end{macrocode}
% \end{macro}
%
% \subsubsection{Descriptional macros}
% A range of descriptional macros are made available by the \pkg{ydoc}
% package, but we need to redefine and extend them.
%
% We begin with extending.
% \begin{macro}{\Describe@Macro}[1]
%   {The macro name, including leading backslash}
% The \cs{Describe@Macro} macro is changed to typeset its agument in
% a \cs{marginnote} instead of an \cs{fbox}.
%    \begin{macrocode}
\def\Describe@Macro#1{%
    \endgroup
    \edef\name{\expandafter\@gobble\string#1}%
    \global\@namedef{href@desc@\name}{}%
    \immediate\write\@mainaux{%
        \global\noexpand\@namedef{href@desc@\name}{}%
    }%
    \hbox\y@bgroup
    \@ifundefined{href@impl@\name}{}{\hyperlink{impl:\name}}%
    {%
        \hbox{
            \vbox to 0pt{
                \vss\hbox{
                    \raisebox{4ex}{\hypertarget{desc:\name}{}
                }
            }
        }%
        \marginnote{\llap{\PrintMacroName{#1}}}
        }%
    }%
    \ydoc@macrocatcodes
    \macroargsstyle
    \read@Macro@arg
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\descframe}[1]
%   {Contents to be framed}
% Similarly, \cs{descframe} is changed to produce an \cs{mbox}
% instead of an \cs{fbox}.
%    \begin{macrocode}
\def\descframe#1{%
    \mbox{\hspace*{1.5\descsep}#1\hspace*{2\descsep}}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\PrintMacroName}[1]
%   {Macro name to be printed}
% \cs{PrintMacroName} is hooked to also index the macro name while
% printing it.
%    \begin{macrocode}
\let\old@PrintMacroName\PrintMacroName
\DeclareDocumentCommand\PrintMacroName{m}{%
    \index@macro*{\expandafter\@gobble\string#1}
    \old@PrintMacroName{#1}
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\PrintEnvName}[2]
%   {Either \cs{end} or \cs{begin}}
%   {Name of the environment to be printed}
% Similarly to \cs{PrintMacroName}, the \cs{PrintEnvName} is hooked
% to index the environment when printing the \cs{begin} part of the
% environment.
%    \begin{macrocode}
\let\old@PrintEnvName\PrintEnvName
\def\PrintEnvName#1#2{
    \ifx#1\begin
        \edef\skdoc@temp{\noexpand\index@environment*{#2}}
        \skdoc@temp
    \fi
    \old@PrintEnvName{#1}{#2}
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\DescribeEnv}[2]
%   {Environment body or \cs{NoValue}}
%   {Environment name}
%    \begin{macrocode}
\DeclareDocumentCommand\DescribeEnv{om}{
    \medskip\par\noindent
    \marginnote{
        \envcodestyle
        \hfill\llap{\PrintEnvName{\begin}{#2}}\mbox{}\\
        \IfNoValueTF{#1}{}{\hfill\llap{\MacroArgs#1}\mbox{}\\}
        \hfill\llap{\PrintEnvName{\end}{#2}}\mbox{}\\
    }
    \begingroup
    \def\after@Macro@args{\endDescribeEnv}
    \y@bgroup
    \ydoc@macrocatcodes
    \macroargsstyle
    \read@Macro@arg
}
\DeclareDocumentCommand\endDescribeEnv{}{
    \endgroup
    \smallskip\par\noindent
}
%    \end{macrocode}
% \end{macro}
%
% Then we add a few of our own. For instance, we add macros to
% typeset descriptions of options. We also undefine the \cs{optpar}
% macro defined by \pkg{ydoc}, since we supersede it with \cs{Option}.
%    \begin{macrocode}
\let\optpar\relax
%    \end{macrocode}
% \begin{macro}{\Options}[1]
%   {A comma-separated list of options}
%    \begin{macrocode}
\DeclareDocumentCommand\Options{m}{
    \clist_set:Nn\l_tmpa_clist{#1}
    \marginnote{
        \clist_map_inline:Nn\l_tmpa_clist{
            \index@option*{####1}
            \hfill
            \llap{\textcolor{opt}{\opt{####1}}}
            \mbox{}\\
        }
    }
    \nobreak
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\Option}[1]
%   {And option}
%    \begin{macrocode}
\DeclareDocumentCommand\Option{m}{
    \Options{#1}
}
%    \end{macrocode}
% \end{macro}
% \begin{macro*}{\skdoc@WithValues@peek}
%    \begin{macrocode}
\def\skdoc@WithValues@peek{
    \ifx\@let@token\AndDefault\else\par\noindent\nobreak\fi
}
%    \end{macrocode}
% \end{macro*}
% \begin{macro}{\WithValues}[1]
%   {Values of a key-value option}
% The \cs{WithValues} macro peeks ahead to see if there's an
% \cs{AndDefault} macro further down. It typesets the values of 
% a key-vaue option
%    \begin{macrocode}
\DeclareDocumentCommand\WithValues{m}{
    \noindent\makebox[\linewidth][l]{\texttt{#1}}
    \futurelet\@let@token\skdoc@WithValues@peek
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\AndDefault}[1]
%   {The value of a key-value option}
% Typesets the default value of a key-value option. To the far
% right of the line.
%    \begin{macrocode}
\DeclareDocumentCommand\AndDefault{m}{
    \llap{\textcolor{gray}{\texttt{(#1)}}}\par\noindent\nobreak
}
%    \end{macrocode}
% \end{macro}
%
% Similar macros are provided for \hologo{BibTeX} entries.
% \begin{macro}{\BibEntry}[1]
%   {The name of the \hologo{BibTeX} entry}
%    \begin{macrocode}
\DeclareDocumentCommand\BibEntry{m}{
    \marginnote{
        \index@bibentry*{#1}
        \hfill\llap{\textcolor{macrodesc}{\bib{#1}}}
    }
    \nobreak
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\WithFields}[2]
%   {Optional fields}
%   {Mandatory fields}
%    \begin{macrocode}
\DeclareDocumentCommand\WithFields{om}{
    \noindent\makebox[\linewidth]{
        \texttt{#2}
        \IfNoValueTF{#1}{}{
            \textcolor{gray}{\texttt{,#2}}
        }
    }
    \par\noindent\nobreak
}
%    \end{macrocode}
% \end{macro}
%
% A macro for describing themes is supplied.
% \begin{macro}{\Theme}[1]
%   {The theme name}
%    \begin{macrocode}
\DeclareDocumentCommand\Theme{m}{
    \marginnote{
        \index@theme*{#1}
        \hfill\llap{\textcolor{macrodesc}{\thm{#1}}}
    }
    \nobreak\par\noindent\nobreak
}
%    \end{macrocode}
% \end{macro}
%
% And finally, a macro for describing files is provided.
% \begin{macro}{\DescribeFile}[1]
%   {The filename}
%    \begin{macrocode}
\DeclareDocumentCommand\DescribeFile{m}{
    \marginnote{
        \index@file*{#1}
        \hfill\llap{\textcolor{macrodesc}{\file{#1}}}
    }
    \nobreak\par\noindent\nobreak
}
%    \end{macrocode}
% \end{macro}
%
% \paragraph{Missing commands}
% Descriptional commands for \hologo{BibTeX} entry types and themes
% are not yet implemented.
%
% Lastly, we define an envionment for showing examples. It's
% rediculously simple, really.
% \begin{environment}{example}
%    \begin{macrocode}
\DeclareDocumentEnvironment{example}{}{
    \minisec{Example:}
}{}
%    \end{macrocode}
% \end{environment}
%
% \subsubsection{Implementation environment}
% We define environments that encase the implementation of macros,
% environments, options, \hologo{BibTeX} entry types and themes.
% Watch out---there's a lot of duplicate code here.
% \begin{environment}{macro}[3]
%   {True if this is the starred variant}
%   {Name of the macro being implemented}
%   {If given, the number of arguments that
%            \cs{macro@impl@args} will read}
%    \begin{macrocode}
\DeclareDocumentEnvironment{macro}{smo}{%
    \@bsphack
    \index@macro!{\expandafter\@gobble\string#2}
    \@macroname{#2}%
    \IfBooleanTF{#1}{
        \IfNoValueTF{#3}{}{
            \int_compare:nNnTF{#3}>{0}{
                \cs:w use_none:\prg_replicate:nn{#3}{n}\cs_end:
            }{}
        }
    }{
        \PrintMacroImpl{#2}
        \IfNoValueTF{#3}{
            \macro@impl@argline@noarg{(no~arguments)}
        }{\macro@impl@args[#3]}
    }%
}{
    \let\skdoc@macroname@key\@empty
    \IfBooleanTF{#1}{}{\@esphack}
}
%    \end{macrocode}
% \end{environment}
% \begin{environment}{environment}[3]
%   {True if this is the starred variant}
%   {Name of the environment being implemented}
%   {If given, the number of arguments that
%            \cs{macro@impl@args} will read}
%    \begin{macrocode}
\DeclareDocumentEnvironment{environment}{smo}{%
    \@bsphack
    \index@environment!{#2}
    \@environmentname{#2}%
    \IfBooleanTF{#1}{
        \IfNoValueTF{#3}{}{
            \int_compare:nNnTF{#3}>{0}{
                \cs:w use_none:\prg_replicate:nn{#3}{n}\cs_end:
            }{}
        }
    }{
        \PrintEnvImplName{#2}
        \IfNoValueTF{#3}{
            \macro@impl@argline@noarg{(no~arguments)}
        }{\macro@impl@args[#3]}
    }%
}{
    \let\skdoc@macroname@key\@empty
    \IfBooleanTF{#1}{}{\@esphack}
}
%    \end{macrocode}
% \end{environment}
% \begin{environment}{option}[3]
%   {True if this is the starred variant}
%   {Name of the option being implemented}
%   {Values this key-value option can take}
%    \begin{macrocode}
\DeclareDocumentEnvironment{option}{smg}{%
    \@bsphack
    \index@option!{#2}
    \@optionname{#2}%
    \IfBooleanTF{#1}{}{
        \PrintEnvImplName{#2}
        \IfNoValueTF{#3}{
            \macro@impl@argline@noarg{(option)}
        }{
            \macro@impl@argline@noarg{
                Option~with~values~\texttt{\textcolor{gray}{#3}}
            }
        }
    }%
}{
    \let\skdoc@macroname@key\@empty
    \IfBooleanTF{#1}{}{\@esphack}
}
%    \end{macrocode}
% \end{environment}
% \begin{environment}{bibentry}[2]
%   {True if this is the starred variant}
%   {Name of the \hologo{BibTeX} entry type being implemented}
%    \begin{macrocode}
\DeclareDocumentEnvironment{bibentry}{sm}{%
    \@bsphack
    \index@bibentry!{\expandafter\@gobble\string#2}
    \@bibentryname{#2}%
    \IfBooleanTF{#1}{}{
        \PrintEnvImplName{#2}
        \macro@impl@argline@noarg{(\hologoRobust{BibTeX}~entry~type)}
    }%
}{
    \let\skdoc@macroname@key\@empty
    \IfBooleanTF{#1}{}{\@esphack}
}
%    \end{macrocode}
% \end{environment}
% \begin{environment}{theme}[2]
%   {True if this is the starred variant}
%   {Name of the theme being implemented}
%    \begin{macrocode}
\DeclareDocumentEnvironment{theme}{sm}{%
    \@bsphack
    \index@theme!{#2}
    \@themename{#2}%
    \IfBooleanTF{#1}{}{
        \PrintEnvImplName{#2}
        \macro@impl@argline@noarg{(theme)}
    }%
}{
    \let\skdoc@macroname@key\@empty
    \IfBooleanTF{#1}{}{\@esphack}
}
%    \end{macrocode}
% \end{environment}
% We also provide starred variants of the environments, which will
% add the implementation to the index but not print anything.
% \begin{environment}{macro*}[2]
%   {Name of the macro being implemented}
%   {If given, the number of arguments that
%            \cs{macro@impl@args} will read}
%    \begin{macrocode}
\DeclareDocumentEnvironment{macro*}{mo}%
    {\begin{macro}*{#1}[#2]}{\end{macro}}
%    \end{macrocode}
% \end{environment}
% \begin{environment}{environment*}[2]
%   {Name of the environment being implemented}
%   {If given, the number of arguments that
%            \cs{macro@impl@args} will read}
%    \begin{macrocode}
\DeclareDocumentEnvironment{environment*}{mo}%
    {\begin{environment}*{#1}[#2]}{\end{environment}}
%    \end{macrocode}
% \end{environment}
% \begin{environment}{option*}[2]
%   {Name of the option being implemented}
%   {Values this key-value option can take}
%    \begin{macrocode}
\DeclareDocumentEnvironment{option*}{mg}%
    {\begin{option}*{#1}{#2}}{\end{option}}
%    \end{macrocode}
% \end{environment}
% \begin{environment}{bibentry*}[1]
%   {Name of the \hologo{BibTeX} entry type being implemented}
%    \begin{macrocode}
\DeclareDocumentEnvironment{bibentry*}{m}%
    {\begin{bibentry}*{#1}}{\end{bibentry}}
%    \end{macrocode}
% \end{environment}
% \begin{environment}{theme*}[1]
%   {Name of the theme being implemented}
%    \begin{macrocode}
\DeclareDocumentEnvironment{theme*}{m}%
    {\begin{theme}*{#1}}{\end{theme}}
%    \end{macrocode}
% \end{environment}
% And finally, we redefine some of the underlying \pkg{ydoc} macros
% to behave the way we want them to.
% For instance, we redefine the commands that print environment and
% macro implementation names so that they typeset the name i a
% \cs{marginnote} rather than in an \cs{fbox}.
% \begin{macro}{\PrintEnvImplName}[1]
%   {The environment name to be printed}
%    \begin{macrocode}
\def\PrintEnvImplName#1{%
    \par\mbox{}
    \marginnote{\llap{\implstyle{#1}}}
    \par
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\PrintMacroImpl}[1]
%   {The macro name to be printed}
%    \begin{macrocode}
\def\PrintMacroImpl#1{%
    \par
    \hbox{%
        \edef\name{\expandafter\@gobble\string#1}%
        \global\@namedef{href@impl@\name}{}%
        \immediate\write\@mainaux{%
            \global\noexpand\@namedef{href@impl@\name}{}%
        }%
        \raisebox{4ex}[4ex]{\hypertarget{impl:\name}{}}%
        \@ifundefined{href@desc@\name}{}{\hyperlink{desc:\name}}%
        \marginnote{\llap{\PrintMacroImplName{#1}}}%
    }%
    \par
}
%    \end{macrocode}
% \end{macro}
% We also redefine the utility macros belonging to \cs{macro@impl@arg}.
% \begin{macro*}{\macro@impl@argline}[2]
%   {The argument number}
%   {Description of the argument}
%    \begin{macrocode}
\def\macro@impl@argline#1#2{%
    \par\noindent{\texttt{\##1}:~#2\strut}%
}
%    \end{macrocode}
% \end{macro*}
% \begin{macro*}{\macro@impl@args}[1]
%   {The number of arguments to read}
%    \begin{macrocode}
\def\macro@impl@args[#1]{%
    \vspace*{-\baselineskip}
    \begingroup
    \let\macro@impl@argcnt\@tempcnta
    \let\macro@impl@curarg\@tempcntb
    \macro@impl@argcnt=#1\relax
    \macro@impl@curarg=0\relax
    \ifnum\macro@impl@curarg<\macro@impl@argcnt\relax
        \expandafter\macro@impl@arg
    \else
        \expandafter\macro@impl@endargs
    \fi
}
%    \end{macrocode}
% \end{macro*}
% \begin{macro*}{\macro@impl@endargs}
%    \begin{macrocode}
\def\macro@impl@endargs{
    \endgroup\par
}
%    \end{macrocode}
% \end{macro*}
% \begin{macro*}{\macro@impl@argline@noarg}[1]
%   {The line to print instead of an argument line}
% This last macro is a replacement used when there are no arguments
% or if the implementation is an option or something like that. It
% behaves pretty much like \cs{macro@impl@args}, but with only one
% argument to read.
%    \begin{macrocode}
\def\macro@impl@argline@noarg#1{%
    \vspace*{-\baselineskip}
    \par\noindent{#1\strut}\par\medskip%
}
%    \end{macrocode}
% \end{macro*}
%
% \subsection{The index}
%    \begin{macrocode}
\prg_new_conditional:Nnn\__skdoc_do_index:{p}{
    \iftoggle{skdoc@impl}{
        \prg_return_true:
    }{
        \iftoggle{skdoc@in@impl}{
            \prg_return_false:
        }{
            \prg_return_true:
        }
    }
}
%    \end{macrocode}
% The index is based on \pkg{glossaries}, and as such the whole
% process of adding entries to the index is reduced to adding
% glossary entries. This is done through two wrapper macros around
% the \cs{newglossaryentry} macro.
% \begin{macro}{\@index@}[1]
%   {The key of the index entry}
%   {The text of the index entry}
% What \cs{@index@} does is to decide wether we are hiding the
% implementation part of the documentation (discussed later), and
% wether we are in the actual implementation or not. If we are in
% the implementation and aren't printing it, we shouldn't add an
% index entry.
%    \begin{macrocode}
\DeclareDocumentCommand\@index@{mm}{
    \if_predicate:w\__skdoc_do_index_p:
        \@index@@{#1}{#2}
    \fi:
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\@index@@}[2]
%   {The key of the index entry}
%   {The text of the index entry}
% This macro does the actual adding to the glossary.
%    \begin{macrocode}
\DeclareDocumentCommand\@index@@{mm}{
    \newglossaryentry{index-#1}{
        type=index,
        name={#2},
        description={\nopostdesc},
        sort={#1}
    }
}
%    \end{macrocode}
% \end{macro}
%
% \subsubsection{Adding index entries}
% These macros add an index entry with different contents depending
% on the thing (macro, environment, etc.) that is being indexed. They
% all have non-starred variants which are used by the referring
% macros (\cs{cs} \emph{et. al}), and starred variants used by the 
% description macros (the star affects the style of the page number).
% Each environment first test wether the given entry key exists, and
% defines a new entry if it doesn't. Then, a usage of the entry is
% recorded.
% There is also a exclamation variant that is used by the implementation
% environments, that typesets a normal use of the entity.
%
% Note the duplicate use of \cs{ifglsentryexists} --- this is needed
% since \cs{@index@} doesn't always add the entity to the index
% \emph{i.e.} nothing in the implementation is added when we're hiding
% the implementation.
% \begin{macro}{\index@macro}[3]
%   {True if this is the starred variant}
%   {True if this is the exclamation variant}
%   {The name of the macro being indexed, without backslash}
%    \begin{macrocode}
\DeclareDocumentCommand\index@macro{st!m}{
    \def\skdoc@temp{#3}
    \ifglsentryexists{index-\skdoc@temp}{}{
        \@index@{#3}{\cs*{#3}}
    }
    \if_predicate:w\__skdoc_do_index_p:
        \IfBooleanTF{#2}{
            \glsadd[types=index,format=hyperul]{index-\skdoc@temp}
        }{
            \IfBooleanTF{#1}{
                \glsadd[types=index,format=hyperit]{index-\skdoc@temp}
            }{
                \glsadd[types=index]{index-\skdoc@temp}
            }
        }
    \fi:
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\index@environment}[3]
%   {True if this is the starred variant}
%   {True if this is the exclamation variant}
%   {The name of the environment being indexed}
%    \begin{macrocode}
\DeclareDocumentCommand\index@environment{st!m}{
    \def\skdoc@temp{\string#3}
    \ifglsentryexists{index-\skdoc@temp}{}{
        \@index@{\string#3}{\env*{\string#3}~(environment)}
    }
    \if_predicate:w\__skdoc_do_index_p:
        \IfBooleanTF{#2}{
            \glsadd[types=index,format=hyperul]{index-\skdoc@temp}
        }{
            \IfBooleanTF{#1}{
                \glsadd[types=index,format=hyperit]{index-\skdoc@temp}
            }{
                \glsadd[types=index]{index-\skdoc@temp}
            }
        }
    \fi:
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\index@option}[3]
%   {True if this is the starred variant}
%   {True if this is the exclamation variant}
%   {The name of the option being indexed}
%    \begin{macrocode}
\DeclareDocumentCommand\index@option{st!m}{
    \def\skdoc@temp{\string#3}
    \ifglsentryexists{index-\skdoc@temp}{}{
        \@index@{\string#3}{\opt*{\string#3}~(option)}
    }
    \if_predicate:w\__skdoc_do_index_p:
        \IfBooleanTF{#2}{
            \glsadd[types=index,format=hyperul]{index-\skdoc@temp}
        }{
            \IfBooleanTF{#1}{
                \glsadd[types=index,format=hyperit]{index-\skdoc@temp}
            }{
                \glsadd[types=index]{index-\skdoc@temp}
            }
        }
    \fi:
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\index@bibentry}[3]
%   {True if this is the starred variant}
%   {True if this is the exclamation variant}
%   {The name of the \hologo{BibTeX} entry type
%       being indexed, without initial \texttt{@} sign}
%    \begin{macrocode}
\DeclareDocumentCommand\index@bibentry{st!m}{
    \def\skdoc@temp{#3}
    \ifglsentryexists{index-\skdoc@temp}{}{
        \@index@{#3}{\bib*{#3}~(\hologoRobust{BibTeX}~entry~type)}
    }
    \if_predicate:w\__skdoc_do_index_p:
        \IfBooleanTF{#2}{
            \glsadd[types=index,format=hyperul]{index-\skdoc@temp}
        }{
            \IfBooleanTF{#1}{
                \glsadd[types=index,format=hyperit]{index-\skdoc@temp}
            }{
                \glsadd[types=index]{index-\skdoc@temp}
            }
        }
    \fi:
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\index@theme}[3]
%   {True if this is the starred variant}
%   {True if this is the exclamation variant}
%   {The name of the theme being indexed}
%    \begin{macrocode}
\DeclareDocumentCommand\index@theme{st!m}{
    \def\skdoc@temp{\string#3}
    \ifglsentryexists{index-\skdoc@temp}{}{
        \@index@{\string#3}{\thm*{\string#3}~(theme)}
    }
    \if_predicate:w\__skdoc_do_index_p:
        \IfBooleanTF{#2}{
            \glsadd[types=index,format=hyperul]{index-\skdoc@temp}
        }{
            \IfBooleanTF{#1}{
                \glsadd[types=index,format=hyperit]{index-\skdoc@temp}
            }{
                \glsadd[types=index]{index-\skdoc@temp}
            }
        }
    \fi:
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\index@package}[3]
%   {True if this is the starred variant}
%   {True if this is the exclamation variant}
%   {The name of the package being indexed}
%    \begin{macrocode}
\DeclareDocumentCommand\index@package{st!m}{
    \def\skdoc@temp{\string#3}
    \ifglsentryexists{index-\skdoc@temp}{}{
        \@index@{\string#3}{\pkg*{\string#3}~(package)}
    }
    \if_predicate:w\__skdoc_do_index_p:
        \IfBooleanTF{#2}{
            \glsadd[types=index,format=hyperul]{index-\skdoc@temp}
        }{
            \IfBooleanTF{#1}{
                \glsadd[types=index,format=hyperit]{index-\skdoc@temp}
            }{
                \glsadd[types=index]{index-\skdoc@temp}
            }
        }
    \fi:
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\index@file}[3]
%   {True if this is the starred variant}
%   {True if this is the exclamation variant}
%   {The name of the file being indexed}
%    \begin{macrocode}
\DeclareDocumentCommand\index@file{st!m}{
    \def\skdoc@temp{\string#3}
    \ifglsentryexists{index-\skdoc@temp}{}{
        \@index@{\string#3}{\file*{\string#3}~(file)}
    }
    \if_predicate:w\__skdoc_do_index_p:
        \IfBooleanTF{#2}{
            \glsadd[types=index,format=hyperul]{index-\skdoc@temp}
        }{
            \IfBooleanTF{#1}{
                \glsadd[types=index,format=hyperit]{index-\skdoc@temp}
            }{
                \glsadd[types=index]{index-\skdoc@temp}
            }
        }
    \fi:
}
%    \end{macrocode}
% \end{macro}
%
% Notice the references to \cs{hyperul}? We need to define that as
% well. It's simple enough. Note that \cs{GlsAddXdyAttribute} isn't
% called until later.
% \begin{macro}{\hyperul}[1]
%   {Word to underline and link}
%    \begin{macrocode}
\ProvideDocumentCommand\hyperul{m}{
    \underline{\hyperup{#1}}
}
%    \end{macrocode}
% \end{macro}
%
% \subsubsection{Displaying the index}
% Displaying the index is very simple. We begin by defining
% our own \pkg{glossaries} style.
%    \begin{macrocode}
\newglossarystyle{docindex}{
    \glossarystyle{indexgroup}
    \renewcommand*{\glspostdescription}{\unskip\leaders\hbox to 2.9mm{\hss.}\hfill\strut}
    \renewenvironment{theglossary}{
        \toggletrue{skdoc@noindex}
        \begin{multicols}{2}
        \setlength{\parindent}{0pt}
        \setlength{\parskip}{0pt plus 0.3pt}
        \let\item\@idxitem
    }{
        \end{multicols}
        \togglefalse{skdoc@noindex}
    }
    \renewcommand*{\glossaryentryfield}[5]{
        \item\glsentryitem{##1}\glstarget{##1}{##2}
            \ifx\relax##4\relax\else\space(##4)\fi
            ##3\glspostdescription\space ##5}
    \renewcommand*{\glsgroupheading}[1]{
        \IfStrEq{##1}{default}{
            \item{\descfont\glssymbolsgroupname}
        }{
            \item{\descfont\glsgetgrouptitle{##1}}
        }
    }
    \renewcommand*{\glsgroupskip}{
        \par\vspace{15\p@}\relax
    }
}
%    \end{macrocode}
% We follow that up by defining the actual glossay, and making sure
% to run \cs{makeglossaries} when the preamble is complete.
%    \begin{macrocode}
\newglossary{index}{ids}{ido}{Index}
\AtBeginDocument{\makeglossaries}
%    \end{macrocode}
% \begin{macro}{\PrintIndex}
% Finally, we define a command \cs{PrintIndex} that prints the index.
% Note the preamble that describes how the index page numbers work.
%    \begin{macrocode}
\providecommand*\PrintIndex{%
    \begingroup
    \renewcommand*{\glossarypreamble}{
        Numbers~written~in~boldface~refer~to~the~page~where~the~
        corresponding~entry~is~described;~numbers~underlined~refer~
        to~the~page~were~the~implementation~of~the~corresponding~
        entry~is~discussed.~Numbers~in~roman~refer~to~other~
        mentions~of~the~entry.\par
    }
    \printglossary[type=index,style=docindex]
    \endgroup
}
%    \end{macrocode}
% \end{macro}
%
% \subsubsection{Hacking \pkg{glossaries}}
% The following redefinition of an internal \pkg{glossaries} macro,
% provided by \textcite{Talbot13}, makes sure that the underlined
% and italic page numbers in the index have precedence over the plain
% nubmer format. In the event that a macro is described and implemented
% on the same page, the description format (italic) is used.
% \begin{macro}{\@gls@addpredefinedattributes}
%    \begin{macrocode}
\RenewDocumentCommand\@gls@addpredefinedattributes{}{
    \GlsAddXdyAttribute{hyperit}
    \GlsAddXdyAttribute{hyperul}
    \GlsAddXdyAttribute{glsnumberformat}
}
%    \end{macrocode}
% \end{macro}
%
% \subsection{The changelog}
% The changelog is implemented as a glossary using the
% \pkg{glossaries} package. We begin by defining a name
% for general changes, and commands that save the name of
% the current macro, environment or similar for use by the
% \cs{changes} macro.
% \begin{macro}{\generalname}
%    \begin{macrocode}
\DeclareDocumentCommand\generalname{}{General}
%    \end{macrocode}
% \end{macro}
% \begin{macro*}{\@macroname}[1]
%   {Name of the macro being described}
%    \begin{macrocode}
\DeclareDocumentCommand\@macroname{m}{
    \def\skdoc@macroname@stylized{\cs*{\expandafter\@gobble\string#1}}
    \def\skdoc@macroname@key{macro-\expandafter\@gobble\string#1}
}
%    \end{macrocode}
% \end{macro*}
% \begin{macro*}{\@environmentname}[1]
%   {Name of the environment being described}
%    \begin{macrocode}
\DeclareDocumentCommand\@environmentname{m}{
    \def\skdoc@macroname@stylized{\env*{\string#1}}
    \def\skdoc@macroname@key{env-#1}
}
%    \end{macrocode}
% \end{macro*}
% \begin{macro*}{\@optionname}[1]
%   {Name of the option being described}
%    \begin{macrocode}
\DeclareDocumentCommand\@optionname{m}{
    \def\skdoc@macroname@stylized{\opt*{\string#1}}
    \def\skdoc@macroname@key{opt-#1}
}
%    \end{macrocode}
% \end{macro*}
% \begin{macro*}{\@ebibentryname}[1]
%   {Name of the \hologo{BibTeX} entry being described}
%    \begin{macrocode}
\DeclareDocumentCommand\@bibentryname{m}{
    \def\skdoc@macroname@stylized{\bib*{\expandafter\@gobble\string#1}}
    \def\skdoc@macroname@key{bibentry-\expandafter\@gobble\string#1}
}
%    \end{macrocode}
% \end{macro*}
% \begin{macro*}{\@themename}[1]
%   {Name of the theme being described}
%    \begin{macrocode}
\DeclareDocumentCommand\@themename{m}{
    \def\skdoc@macroname@stylized{\thm*{\string#1}}
    \def\skdoc@macroname@key{thm-#1}
}
%    \end{macrocode}
% \end{macro*}
% Along with these we also define the variables they affect as empty.
%    \begin{macrocode}
\def\skdoc@macroname@stylized{}
\let\skdoc@macroname@key\@empty
%    \end{macrocode}
%
% \subsubsection{Adding changes}
% Since the changelog is based on \pkg{glossaries}, adding changes
% amounts to simply adding a glossary entry.
% \begin{macro}{\changes}[2]
%   {The version in which the changes were made}
%   {A short description of the changes}
%    \begin{macrocode}
\DeclareDocumentCommand\changes{mm}{%
    \@bsphack
    \ifglsentryexists{#1}{}{
        \newglossaryentry{#1}{
            type=changes,
            name={v#1},
            description={\nopostdesc},
            nonumberlist=true
        }
    }
    \ifx\skdoc@macroname@key\@empty
        \newglossaryentry{#1-general}{
            type=changes,
            description={\generalname{}:~#2},
            parent={#1},
            sort={0},
            nonumberlist=true
        }
        \glsadd[types=changes]{#1-general}
    \else
        \newglossaryentry{#1-\skdoc@macroname@key}{
            type=changes,
            description={\skdoc@macroname@stylized{}:~#2},
            parent={#1},
            sort={\skdoc@macroname@key},
            nonumberlist=true
        }
        \glsadd[types=changes]{#1-\skdoc@macroname@key}
    \fi
    \@esphack
}
%    \end{macrocode}
% \end{macro}
%
% \subsubsection{Displaying the changelog}
% Displaying the changelog is equally simple. We begin by defining
% our own \pkg{glossaries} style.
%    \begin{macrocode}
\newglossarystyle{changelog}{
    \glossarystyle{altlist}
    \renewenvironment{theglossary}{
        \toggletrue{skdoc@noindex}
        \begin{multicols}{2}\begin{description}
    }{
        \end{description}\end{multicols}
        \togglefalse{skdoc@noindex}
    }
    \renewcommand*{\glossaryentryfield}[5]{
        \par\vspace{5\p@}\relax
        \item[\glsentryitem{##1}\glstarget{##1}{##2}]
                    \mbox{}\par\nobreak\@afterheading
    }
    \renewcommand{\glossarysubentryfield}[6]{%
        \par\hspace*{\itemindent}
        \glssubentryitem{##2}%
        \glstarget{##2}{\strut}##4\glspostdescription\space ##6
    }
}
%    \end{macrocode}
% We follow that up by defining the actual glossay, and making sure
% to run \cs{makeglossaries} when the preamble is complete.
%    \begin{macrocode}
\newglossary{changes}{gls}{glo}{Changes}
\AtBeginDocument{\makeglossaries}
%    \end{macrocode}
% \begin{macro}{\PrintChanges}
% Finally, we define a command \cs{PrintChanges} that prints the
% list of changes.
%    \begin{macrocode}
\DeclareDocumentCommand\PrintChanges{}{%
    \begingroup
    \printglossary[type=changes,style=changelog]
    \endgroup
}
%    \end{macrocode}
% \end{macro}
%
% \subsection{Hiding the implementation}
% We define commands to hide the implementation from the documentation.
% Here, the ``implementation'' is understood to be everything between
% the \cs{Implementation} and \cs{Finale} macros. What we do is disable
% and/or reset page and section counters for the duration of the
% implementation, and set a shipout hook that simply discards the pages
% while we are in the implementation. A consquence of this is that we
% must force a page break between what's before the implementation and
% what's after, which might look horrible.
%
% Anyway, we define two toggles that keep track of things. One keeps
% track of wether to (not) hide the implementation, and one keeps track 
% of wether we are in the implementation or not. These are provided with
% sensible defaults (\emph{i.e.} true and false, respectively).
% We also define a counter in which we save the page number we had when
% the implementation started.
%    \begin{macrocode}
\newtoggle{skdoc@impl}
\newtoggle{skdoc@in@impl}
\toggletrue{skdoc@impl}
\togglefalse{skdoc@in@impl}
\newcounter{skdoc@impl@page}
%    \end{macrocode}
% Then we define the shipout hook. Fairly straight-forward.
%    \begin{macrocode}
\AtBeginShipout{
    \iftoggle{skdoc@impl}{}{
        \iftoggle{skdoc@in@impl}{\AtBeginShipoutDiscard}{}
    }
}
%    \end{macrocode}
% \begin{macro}{\OnlyDescription}
% The \cs{OnlyDescription} macro simply toggles the appropriate toggle.
%    \begin{macrocode}
\DeclareDocumentCommand\OnlyDescription{}{\togglefalse{skdoc@impl}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\Implementation}
% The \cs{Implementation} macro defines all the sectioning commands
% to be empty (saving the old ones), clears the page, saves the page
% number and toggles the appropriate toggle.
%    \begin{macrocode}
\DeclareDocumentCommand\Implementation{}{
    \iftoggle{skdoc@impl}{}{
        \clearpage
        \toggletrue{skdoc@in@impl}
        \let\skdoc@old@part\part
        \DeclareDocumentCommand\part{som}{}
        \let\skdoc@old@section\section
        \DeclareDocumentCommand\section{som}{}
        \let\skdoc@old@subsection\subsection
        \DeclareDocumentCommand\subsection{som}{}
        \let\skdoc@old@subsubsection\subsubsection
        \DeclareDocumentCommand\subsubsection{som}{}
        \let\skdoc@old@paragraph\paragraph
        \DeclareDocumentCommand\paragraph{som}{}
        \let\skdoc@old@subparagraph\subparagraph
        \DeclareDocumentCommand\subparagraph{som}{}
        \setcounter{skdoc@impl@page}{\value{page}}
    }
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\Finale}
% The \cs{Finale} macro basically just undoes what the 
% \cs{Implementation} macro did.
%    \begin{macrocode}
\DeclareDocumentCommand\Finale{}{
    \iftoggle{skdoc@impl}{}{
        \clearpage
        \togglefalse{skdoc@in@impl}
        \let\part\skdoc@old@part
        \let\section\skdoc@old@section
        \let\subsection\skdoc@old@subsection
        \let\subsubsection\skdoc@old@subsubsection
        \let\paragraph\skdoc@old@paragraph
        \let\subparagraph\skdoc@old@subparagraph
        \setcounter{page}{\value{skdoc@impl@page}}
    }
}
%    \end{macrocode}
% \end{macro}
%
% \subsection{Document metadata}
% \subsubsection{Setting metadata}
% We override a bunch of the general titlepage macros and add a few
% of our own. First, we initialize the underlying variables.
%    \begin{macrocode}
\let\@ctan\@empty%
\let\@repository\@empty%
\let\@plainemail\@empty%
\let\@email\@empty%
\let\@version\@empty%
%    \end{macrocode}
% Then, we define the actual macros.
% \begin{macro}{\package}[2]
%   {A list of key-value options}
%   {The package name}
% The \cs{package} macro sets the package name of the documentation.
% The key-value options are \opt{vcs} and \opt{ctan}.
%    \begin{macrocode}
\DeclareDocumentCommand\package{om}{%
    \keys_define:nn{skdoc@package}{%
        vcs .value_required:,%
        vcs .code:n = \repository{##1},%
        ctan .code:n = \ctan{##1},%
        ctan .default:n = #2%
    }%
    \IfNoValueTF{#1}{}{\keys_set:nn{skdoc@package}{#1}}%
    \def\@package{#2}%
    \title{The~\textbf{\pkg*{\@package}}~package}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\ctan}[1]
%   {The name of a package or bundle on CTAN}
%    \begin{macrocode}
\DeclareDocumentCommand\ctan{m}{%
    \def\@ctan{\url{http://www.ctan.org/pkg/#1}}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\repository}[1]
%   {The URI of an online repository}
%    \begin{macrocode}
\DeclareDocumentCommand\repository{m}{%
    \def\@repository{\url{#1}}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\email}[1]
%   {The email address of the author}
%    \begin{macrocode}
\DeclareDocumentCommand\email{m}{%
    \def\@plainemail{#1}%
    \def\@email{\href{mailto:\@plainemail}{\@plainemail}}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\version}[1]
%   {The version of the package, with no leading ``v''}
%    \begin{macrocode}
\DeclareDocumentCommand\version{m}{%
    \def\@version{#1}%
}
%    \end{macrocode}
% \end{macro}
% Finally, we set the default package name to \cs{jobname}.
%    \begin{macrocode}
\package{\jobname}
%    \end{macrocode}
%
% \subsubsection{Using metadata}
% We define two macros that read useful metadata; \cs{theversion}
% and \cs{thepackage}. These are used internally by \cs{maketitle}.
% \begin{macro}{\theversion}
%    \begin{macrocode}
\DeclareDocumentCommand\theversion{}{v\@version}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\thepackage}
%    \begin{macrocode}
\DeclareDocumentCommand\thepackage{}{\pkg*{\@package}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\thepkg}
%    \begin{macrocode}
\DeclareDocumentCommand\thepkg{}{\thepackage}
%    \end{macrocode}
% \end{macro}
% Additionally we define \cs{skdocpdfsettings}, which is also used
% by \cs{maketitle}, to include PDF metadata if the documentation
% is being compiled using \hologo{pdfLaTeX}.
%    \begin{macrocode}
\ifpdf
    \def\skdocpdfsettings{%
        \hypersetup{%
            pdfauthor   = {\@author\space<\@plainemail>},
            pdftitle    = {\@title},
            pdfsubject  = {Documentation~of~LaTeX~package~\@package},
            pdfkeywords = {\@package,~LaTeX,~TeX}
        }%
    }%
\else
    \let\skdocpdfsettings\empty%
\fi
%    \end{macrocode}
%
% \subsection{General document commands}
% Most of the general document commands are defined by the
% \pkg{scrartcl} document class we base ourselves on, but a few
% of them have to be redefined.
%
% \subsubsection{Notices and warnings}
% We define macros to typeset notices and warnings in the documentation
% text. Notices are typeset as \Notice{this is a notice}, and warnings
% are typeset as follows: \Warning{this is a warning}
% A macro for longer warnings is also available:
% \LongWarning{This is a longer warning.}
%
% \begin{macro}{\Notice}[1]
%   {Notice text}
%    \begin{macrocode}
\DeclareDocumentCommand\Notice{m}{
    (\emph{\textbf{Note:}~#1})
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\Warning}[1]
%   {Warning text}
%    \begin{macrocode}
\DeclareDocumentCommand\Warning{+m}{
    \vspace{\baselineskip}
    \par\noindent
    \fbox{\begin{minipage}[c]{\textwidth}
        \centering
        \textbf{Warning:}~#1
    \end{minipage}}
    \vspace{\baselineskip}
    \par
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\LongWarning}[1]
%   {Warning text}
%    \begin{macrocode}
\DeclareDocumentCommand\LongWarning{+m}{
    \Warning{
        \par\noindent
        \begin{minipage}{\textwidth}
            #1
        \end{minipage}
    }
}
%    \end{macrocode}
% \end{macro}
%
% \subsubsection{The title page}
% The title page consists of the \cs{maketitle} and the \env{abstract}.
% We redefine both, inspired slightly by the Prac\TeX\ journal and the
% \pkg{skrapport} document class.
% \begin{macro}{\@maketitle}
%    \begin{macrocode}
\def\@maketitle{%
    \newpage
    \null
    \begin{flushleft}%
    {%
        \Huge\sectfont\@title%
        \ifx\@ctan\@empty\else%
            \footnote{Available~on~\@ctan.}%
        \fi
        \ifx\@repository\@empty\else%
            \footnote{Development~version~available~on~\@repository.}%
        \fi%
        \par%
    }%
    \vskip 1em
    {%
        \Large\@author
        \ifx\@email\@empty\else%
            \space
            \newlength\skdoc@minipage@ew%
            \settowidth{\skdoc@minipage@ew}{%
                \normalsize{$\lceil${\@email}$\rfloor$}}
            \begin{minipage}[b]{\skdoc@minipage@ew}
                \normalsize{$\lceil${\@email}$\rfloor$}
            \end{minipage}\par%
        \fi%
    }%
    \ifx\@version\@empty\else
        \vskip .5em
        {%
            \large Version~\@version\par%
        }%
    \fi
    \end{flushleft}%
    \par\bigskip%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\maketitle}
%    \begin{macrocode}
\def\maketitle{%
    \begingroup
    \skdocpdfsettings
    \renewcommand\thefootnote{\@fnsymbol\c@footnote}
    \@maketitle
    \setcounter{footnote}{0}
    \skdocpdfsettings
    \endgroup
}
%    \end{macrocode}
% \end{macro}
% \begin{environment}{abstract}
%    \begin{macrocode}
\DeclareDocumentEnvironment{abstract}{}{
    \newlength\skdoc@abstract@tw%
    \newlength\skdoc@abstract@aw%
    \settowidth{\skdoc@abstract@tw}{\descfont\abstractname}%
    \setlength{\skdoc@abstract@aw}{\the\textwidth-\the\skdoc@abstract@tw-2em}%
    \begin{minipage}{\textwidth}
        \begin{minipage}[t]{\skdoc@abstract@tw}%
            \begin{flushright}%
                \leavevmode\descfont\abstractname%
            \end{flushright}%
        \end{minipage}%
        \hspace{1em}%
        \begin{minipage}[t]{\skdoc@abstract@aw}%
}{
        \end{minipage}
    \end{minipage}
}
%    \end{macrocode}
% \end{environment}
%
% \subsubsection{Table of contents}
% The table of contents are redefined to imitate the excellent table
% of contents of the \pkg{microtype} manual.
% \begin{macro*}{\l@section}
%    \begin{macrocode}
\let\l@section@\l@section
\def\l@section{\vskip -.75ex\l@section@}
%    \end{macrocode}
% \end{macro*}
% \begin{macro*}{\l@subsection}
%    \begin{macrocode}
\def\l@subsection{\vskip.35ex\penalty\@secpenalty\@dottedtocline{2}{1.5em}{2.7em}}
%    \end{macrocode}
% \end{macro*}
% \begin{macro*}{l@subsubsection}
%    \begin{macrocode}
\def\l@subsubsection#1#2{
    \leftskip 4.2em
    \parindent 0pt
    {\let\numberline\@gobble{\small #1~[#2]}}
}
%    \end{macrocode}
% \end{macro*}
% \begin{macro*}{\l@table}
%    \begin{macrocode}
\def\l@table{\@dottedtocline{1}{0pt}{1.5em}}
%    \end{macrocode}
% \end{macro*}
% \begin{macro*}{\l@figure}
%    \begin{macrocode}
\def\l@figure{\@dottedtocline{1}{0pt}{1.5em}}
%    \end{macrocode}
% \end{macro*}
%    \begin{macrocode}
\def\@pnumwidth{1.7em}
\AtEndDocument{\addtocontents{toc}{\par}}
%    \end{macrocode}
% \begin{macro}{\tableofcontents}
%    \begin{macrocode}
\let\old@tableofcontents\tableofcontents
\DeclareDocumentCommand\tableofcontents{}{
    \toggletrue{skdoc@noindex}
    \microtypesetup{protrusion=false}
    \old@tableofcontents
    \microtypesetup{protrusion=true}
    \togglefalse{skdoc@noindex}
}
%    \end{macrocode}
% \end{macro}
%
% \subsubsection{Including the LPPL license}
% A helper macro that includes the LPPL license is also provided.
% \begin{macro}{\PrintLPPL}
%    \begin{macrocode}
\DeclareDocumentCommand\PrintLPPL{}{
    \begingroup
    \IfFileExists{lppl.tex}{
        \let\old@verbatim@font\verbatim@font
        \def\verbatim@font{
            \old@verbatim@font\tiny
        }
        \def\LPPLicense{\begingroup\small}
        \def\endLPPLicense{\endmulticols\endgroup}
        \DeclareDocumentCommand\LPPLsection{m}{
            \section{####1}
        }
        \DeclareDocumentCommand\skdoc@lppl@hack{m}{
            \end{multicols}
            \begin{multicols}{2}
                [\subsection*{####1}][6\baselineskip]
        }
        \DeclareDocumentCommand\LPPLsubsection{m}{
            \subsection*{####1}
            \let\LPPLsubsection\skdoc@lppl@hack
            \begin{multicols}{2}
        }
        \DeclareDocumentCommand\LPPLsubsubsection{m}{
            \subsubsection*{####1}
        }
        \DeclareDocumentCommand\LPPLparagraph{m}{\paragraph*{####1}}
        \DeclareDocumentCommand\LPPLfile{m}{\file{####1}}
        \let\oldmakeatletter\makeatletter
        \long\def\makeatletter####1\makeatother{
            \let\makeatletter\oldmakeatletter
        }
        \setlength\leftmargini{15pt}
        \setlength\leftmarginii{12.5pt}
        \setlength\leftmarginiii{10pt}
        \newenvironment{enum}[1][0]{
            \list\labelenumi{
                \usecounter{enumi}
                \setcounter{enumi}{####1}
                \addtocounter{enumi}{-1}
                \leftmargin 30pt
                \itemindent-15pt
                \labelwidth 15pt
                \labelsep 0pt
                \def\makelabel########1{########1\hss}}
        }{\endlist}
        \input{lppl}
    }{
        \msg_warning:nn{skdoc}{no-lppl}
    }
    \endgroup
}
%    \end{macrocode}
% \end{macro}
%
% \subsection{Cosmetic changes}
% We perform a couple of cosmetic changes to existing features as
% well. First, we set a new header/footer style using the KOMA-script
% \cs{deftripstyle} macro.
%    \begin{macrocode}
\deftripstyle{skdoc}%
    {}{}{}%
    {\small The~\textbf{\pkg*{\@package}}~package,~v\@version}{}{\small\pagemark}
\AfterBeginDocument{\pagestyle{skdoc}}
%    \end{macrocode}
% We also redefine the section level format to set the section numbers
% in the margin, much like the \pkg{microtype} manual.
%    \begin{macrocode}
\RenewDocumentCommand{\othersectionlevelsformat}{m}{%
    \makebox[0pt][r]{%
    \fontfamily{fos}\mdseries\selectfont
    \csname the#1\endcsname\enskip}%
}
%    \end{macrocode}
% Finally, we actually use \pkg{microtype} in the document class, and
% make sure to disable it in the verbatim environments.
% Set up microtype properly
%    \begin{macrocode}
\g@addto@macro\@verbatim{\microtypesetup{activate=false}}
\microtypesetup{expansion,kerning,spacing,tracking}
\DisableLigatures{family = tt*}
%    \end{macrocode}
% We also want numbers on the bibliography headings, if we are loading
% \pkg{biblatex}.
%    \begin{macrocode}
\AtBeginDocument{
    \ifdefined\defbibheading
        \defbibheading{bibliography}[\bibname]{\section{#1}}
    \fi
}
%    \end{macrocode}
% Oh, and we want \cs{marginpar}s on the left, not on the right.
%    \begin{macrocode}
\AtBeginDocument{\reversemarginpar}
%    \end{macrocode}
%
% That's it, we're done!
%    \begin{macrocode}
\endinput
%    \end{macrocode}
% \iffalse
%</class>
% \fi
% \Finale
%
% \iffalse
% \section{Known issues}
% \fi
%
% \PrintChanges
% \PrintIndex
% \printbibliography
% \endinput