summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/keys3/keys3.dtx
blob: 6932050bb8c47589d6237e6480368bdad054c5b7 (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
% \iffalse meta-comment
% !TEX program  = pdflatex
% !TEX encoding = ISO-8859-1
%<*internal>
\iffalse
%</internal>
%<*readme>
---------------------------------------------------------------
The keys3 package --- Key management for LaTeX3
Maintained by Joseph Wright 
E-mail: joseph.wright@morningstar2.co.uk
Released under the LaTeX Project Public License v1.3c or later
See http://www.latex-project.org/lppl.txt
---------------------------------------------------------------

The keys3 package is an experimental implementation of key
management for LaTeX3.  The entire package is written in
expl3 code rather than in traditional TeX/LaTeX.  The key
module used by keys3 is based on that introduced by the
pgfkeys package from the pgf/TiKZ bundle. Keys are thus
addressed in a path-like manner, and are controlled by key
properties:

/module/key/.code:n = <code>,
/module/key/.value_required:,
/module/key = <value>

The keys3 package is intended as a method for testing how key
management might be implemented in LaTeX3.  Both the methods
used inside the package and the interface provided are intended
to be discussed.  Feedback is welcomed either by e-mail
(joseph.wright@morningstar2.co.uk) or at the package website
(http://keys3.berlios.de).

The experimental nature of keys3 and the underlying expl3
system means that it should not be used in production
documents.  However, programmers testing expl3, or keen to work
on improved key management systems, are encouraged to try the
package and provide feedback.

keys3 is *not* an official LaTeX3 team package.  Whether any of
the ideas explored here will be taken up by the team is
therefore unknown.  However, the keys3 package should provide
ideas on what needs to be available for key management and how
it can be implemented.
%</readme>
%<*internal>
\fi
\def\nameofplainTeX{plain}
\ifx\fmtname\nameofplainTeX\else
  \expandafter\begingroup
\fi
%</internal>
%<*install>
\input docstrip.tex
\keepsilent
\askforoverwritefalse
\preamble
---------------------------------------------------------------
The keys3 package --- Key management for LaTeX3
Maintained by Joseph Wright 
E-mail: joseph.wright@morningstar2.co.uk
Released under the LaTeX Project Public License v1.3c or later
See http://www.latex-project.org/lppl.txt
---------------------------------------------------------------

EXPERIMENTAL CODE

Do not distribute this file without also distributing the
source files specified above.

Do not distribute a modified version of this file.

\endpreamble
\postamble

Copyright (C) 2008-2009 by
  Joseph Wright <joseph.wright@morningstar2.co.uk>

It may be distributed and/or modified under the conditions of
the LaTeX Project Public License (LPPL), either version 1.3c of
this license or (at your option) any later version.  The latest
version of this license is in the file:

   http://www.latex-project.org/lppl.txt

This work is "maintained" (as per LPPL maintenance status) by
  Joseph Wright.

This work consists of the file  keys3.dtx
          and the derived files keys3.pdf,
                                keys3.sty and
                                keys3.ins.

\endpostamble
\usedir{tex/latex/keys3}
\generate{
  \file{\jobname.sty}{\from{\jobname.dtx}{package}}
}
%</install>
%<install>\endbatchfile
%<*internal>
\usedir{source/latex/keys3}
\generate{
  \file{\jobname.ins}{\from{\jobname.dtx}{install}}
}
\nopreamble\nopostamble
\usedir{doc/latex/keys3}
\generate{
  \file{README.txt}{\from{\jobname.dtx}{readme}}
}
\ifx\fmtname\nameofplainTeX
  \expandafter\endbatchfile
\else
  \expandafter\endgroup
\fi
%</internal>
%<*driver|package>
\RequirePackage{expl3}
\GetIdInfo$Id: keys3.dtx 101 2009-06-10 12:16:20Z josephwright $
  {Key management for LaTeX3}
%</driver|package>
%\fi
%\iffalse
%<*driver>
%\fi
\ProvidesFile{\filename.\filenameext}
  [\filedate\space v\fileversion\space\filedescription]
%\iffalse
\documentclass[full]{l3doc}
\begin{document}
  \DocInput{\filename.\filenameext}
\end{document}
%</driver>
% \fi
%
% \title{The \pkg{keys3} package^^A
%   \thanks{This file has version number \fileversion, last
%     revised \filedate.}\\
% Key management for \LaTeX3}
% \author{Joseph Wright^^A
%   \thanks{E-mail: joseph.wright@morningstar2.co.uk}}
% \date{\filedate}
% 
% \maketitle
% 
% \begin{documentation}
%
%\section{Key management}
%
% The key--value method is a popular system for creating large numbers
% of settings for controlling macro or package behaviour.  For the
% user, the system normally results in input of the form
%\begin{verbatim}
%  \PackageControlMacro{
%    key     = value,
%    key two = value two
%  }
%\end{verbatim}
% or
%\begin{verbatim}
%  \PackageMacro[
%    key     = value,
%    key two = value two
%  ]{argument}.
%\end{verbatim}
% For the programmer, the original \pkg{keyval} package gives only
% the most basic interface for this work.  All key macros have to be
% created one at a time, and as a result the \pkg{kvoptions} and
% \pkg{xkeyval} packages have been written to extend the ease of
% creating keys.  However, the underlying model is rather inflexible.
%
% As an alternative, \pkg{pgfkeys} from the \pkg{pgf}/Ti\emph{k}z
% bundle uses a ``file-like'' model for keys. In this model, each key
% has one or more functions attached to define its action.  In
% \pkg{pgfkeys} terminology, these are key \emph{handlers}. Keys can
% be created and used using a unified interface:
%\begin{verbatim}
%  \pgfkeys{
%    /path/key/.handler = code,
%    /path/key          = value
%  }
%\end{verbatim}
%
% The \pkg{keys3} package is aimed at creating a high-level
% programmers interface for key--value controls in \LaTeX3. Key
% creation and control follows the \pkg{pgfkeys} closely, although
% changes have been made to adhere to the new coding ideas of \LaTeX3,
% and new functions have been added.  The \pkg{keys3} package is
% \emph{not} a simple translation of \pkg{pgfkeys} to the new syntax.
% In package internals have been written from the ground up, to better
% enforce variable typing and to act in a know manner under failing
% circumstances.
% 
% In the \pkg{keys3} model, each key belongs to a module,
% which may have one or more subdivisions. Each key then has
% one or more properties which define how the key acts. The idea
% of a single function for all key control is retained:
%\begin{verbatim}
%  \keys_manage:n{
%    /module/key/.property     = code,
%    /module/sub/key/.property = more code,
%    /module/key               = value
%  }
%\end{verbatim}
% The combination of all \m{module} parts up to the \m{key} is referred
% to as the \emph{path} of the key. 
% 
% Keys are created by assigning one or more properties to the key, 
% most commonly a piece of code to execute when the key is used (this 
% is the \texttt{.code:n} property).
%\begin{verbatim}
%  \keys_manage:n{
%    /module/key/.code:n = <code>
%  }
%\end{verbatim}
% Keys are then used in the normal way, by assigning a value to the 
% key.
%\begin{verbatim}
%  \keys_manage:n{
%    /module/key = <value>
%  }
%\end{verbatim}
% Here, \meta{value} is passed to the \meta{code} defined |#1|. The
% \meta{code} can then process it in whatever way is appropriate. 
% 
% At a document level, it is likely that \cs{keys_manage:n} would be
% wrapped up into a user macro or optional argument. For \LaTeXe, a 
% generic set up macro might be created with:
%\begin{verbatim}
%  \newcommand*\SomePackageSetup[1]{%
%    \@nameuse{keys_manage:n}{%
%      /package name/.cd:,
%      #1
%    }%
%  }
%\end{verbatim}
% or to use key--value input as the optional argument for a macro:
%\begin{verbatim}
%  \newcommand*\SomePackageMacro[2][]{%
%    \begingroup
%      \@nameuse{keys_manage:n}{
%        /package name/.cd:,
%        #1
%      }%
%      % Main code for \SomePackageMacro
%    \endgroup
%  }
%\end{verbatim} 
% The same concepts using \pkg{xparse} for \LaTeX3 use:
%\begin{verbatim}
%  \DeclareDocumentCommand \SomePackageSetup { m } {
%    \keys_manage:n {
%      /package name/.cd:,
%      #1
%    }
%  }
%  \DeclareDocumentCommand \SomePackageMacro { o m } {
%    \group_begin:
%      \keys_manage:n {
%        /package name/.cd:,
%        #1
%      }
%      % Main code for \SomePackageMacro
%    \group_end:
%  }
%\end{verbatim} 
%
%\subsection{Creating, retrieving and setting keys}
%
% The main interface for key management is the the \cs{keys_manage:n}
% macro.  This can be used to create, retrieve and set keys, and is
% therefore the preferred interface for the package.
%
% \begin{function}{
%   \keys_manage:n|
%   \keys_manage_quick:n
% }
%   \begin{syntax}
%     "\keys_manage:n" <keyval list>
%   \end{syntax}
%   The main key management function, which parses over the <keyval
%   list> and processes each key. The standard version removes leading
%   and trailing spaces and checks catcodes for ungrouped ``|,|'' and
%   ``|=|'' tokens. The |_quick| version omits these tests for speed, 
%   and is therefore more suited to creating keys inside code blocks. 
% \end{function}
%
% \begin{function}{
%   \keys_manage:nn|
%   \keys_manage_quick:nn|
% }
%   \begin{syntax}
%     "\keys_manage:nn" <path> <keyval list>
%   \end{syntax}
%   Versions of the above which include a <path> as an argument. These
%   are faster versions of the |:n| macros when setting lots of keys
%   separately and with known paths.
% \end{function}
%
% Setting up and altering keys is carried out using one or more
% properties (in \pkg{pgfkeys}, these are called handlers). In all
% cases, \m{key} may be a full-qualified key with a path, or a partial
% key to which the default path will be added. Notice that when a
% single argument is required, the braces around the argument may be
% omitted without any error arising.
% 
%\subsubsection{Storing values}
%
% A common use of key--value input is to store the values given in a 
% variable for later use.  \pkg{keys3} provides pre-defined 
% properties for storing in integer, skip, token list variables and
% token registers. The method is similar in all cases:
%\begin{verbatim}
%  \keys_manage:n{
%    /module/key~one/.int_set:N   = \l_mod_data_int,
%    /module/key~two/.skip_set:N  = \l_mod_data_skip,
%    /module/key~three/.tl_set:N  = \l_mod_data_tl,
%    /module/key~four/.toks_set:N = \l_mod_data_toks
%  }
%\end{verbatim}
% These assignments are local: in each case, a global variant is
% available, with \texttt{set} replaced by \texttt{gset}. For example,
% \texttt{.tl_get:N} globally stores values in a token list variable.
%   
% When using keys to store a value, it is often convenient to give only
% the unique part of the variable name. This is particularly true when
% creating a large number of related storage areas. To achieve this,
% \pkg{keys3} requires that the module prefix to be used is defined 
% first. The special key \texttt{/keys/current_module:n} can be set with 
% the name of the current module.
%\begin{verbatim}
%  \keys_manage:n{
%    /keys/current_module:n = module,
%    /module/key/.tl_set:n = my_data,
%  }
%\end{verbatim}
% This will use a variable called \cs{l_module_my_data_tl} to store the
% input. Thus the preceding code achieves the same effect as
%\begin{verbatim}
%  \keys_manage:n{
%    /module/key/.tl_set:N = \l_module_my_data_tl
%  }
%\end{verbatim}
% The same method applies to int, skip and toks variables. The 
% appropriate prefix (\cs{l_} or \cs{g_}) and suffix (|_int|, |_skip|, 
% |_tl| or |_toks|) is always added.
% 
%\subsubsection{Multiple choice keys}
%
% Multiple choice keys are created in \pkg{keys3} using the 
% \texttt{.expects_choice:} property. Each choice is then a sub-key of 
% the choice key.
%\begin{verbatim}
%  \keys_manage:n{
%    /module/key/.expects_choice:,
%    /module/key/choice~a/.code:n = Some code,
%    /module/key/choice~b/.code:n = Some other code,
%  }
%\end{verbatim}
% In this way, choices which execute arbitrary code can be created. 
% Notice that the \m{code} should \emph{not} include a parameter (|#1|).
% 
% Often it is desirable to create a family of similar choices, which 
% only require either the text of the choice, or the position of the 
% choice in a list, to be used.  To create this type of simple choice,
% \pkg{keys3} provides the \texttt{.create_choices:nn} property. This
% applies the same code to a list of choice text. Inside the code,
% the name of the choice given is available as 
% \cs{l_keys_current_choice_tl}. The position of the choice in the 
% lists is also available, as \cs{l_keys_current_choice_int}. 
%\begin{verbatim}
%  \keys_manage:n {
%    /module/key/.create_choices:nn = {choice~a, choice~b, choice~c} {
%      You~gave~choice~``\l_keys_current_choice_tl'',~which~is~in~
%      position~\l_keys_current_choice_int\~in~the~list.
%    }
%  }
%\end{verbatim}
% 
%\subsection{Properties}
%
% \begin{function}{
%   .bool_set:N|
%   .bool_gset:N|
% }
%  \begin{syntax}
%    <key>/.bool_set:N = <bool>
%  \end{syntax}
%  Defines <key> to set <bool> to <value> (which must be either 
%  \texttt{true} or \texttt{false}).
% \end{function}
% 
% \begin{function}{
%   .bool_set:n|
%   .bool_gset:n|
% }
%  \begin{syntax}
%    <key>/.bool_set:n = <name>
%  \end{syntax}
%  Defines <key> to set switch with unique <name> to <value> (which 
%  must be either \texttt{true} or \texttt{false}). The switch
%  name will be constructed using the current <module> (if any), 
%  prefixed by |\l_| and ending with |_int|.
% \end{function}
% 
% \begin{function}{
%   .bool_set_inverse:N|
%   .bool_gset_inverse:N|
% }
%  \begin{syntax}
%    <key>/.bool_set_inverse:N = <bool>
%  \end{syntax}
%  Defines <key> to set <bool> to <value> (which must be either 
%  \texttt{true} or \texttt{false}), with reversed logic.
% \end{function}
% 
% \begin{function}{
%   .bool_set_inverse:n|
%   .bool_gset_inverse:n|
% }
%  \begin{syntax}
%    <key>/.bool_set_inverse:n = <name>
%  \end{syntax}
%  Defines <key> to set switch with unique <name> to <value> (which 
%  must be either \texttt{true} or \texttt{false}), with reversed logic. 
%  The switch name will be constructed using the current <module> (if 
%  any), prefixed by |\l_| and ending with |_int|.
% \end{function}
%
% \begin{function}{.cd:}
%  \begin{syntax}
%    <key>/.cd:
%  \end{syntax}
%  Changes path to <key>.
% \end{function}
%
% \begin{function}{
%   .code:n|
%   .code:x
%  }
%  \begin{syntax}
%    <key>/.code:n = <code>
%  \end{syntax}
%  Stores the <code> for execution when <key> is called. The <code> can
%  include one parameter (|#1|).
% \end{function}
% 
% \begin{function}{
%   .code:Nn|
%   .code:Nx
% }
%  \begin{syntax}
%    <key>/.code:Nn = <number> <code>
%  \end{syntax}
%  Stores the <code> for execution when <key> is called. The <code> can
%  include <number> parameters, which can be in the range 0--9.
% \end{function}
% 
% \begin{function}{
%   .create_choices:nn|
%   .create_choices:nx|
% }
%  \begin{syntax}
%    <key>/.create_choices:nn = <list> <code>
%  \end{syntax}
%  Creates a sub-key of <key> for each <choice> in the comma-separated
%  <list>. Each <choice> will have <code> associated with it. The 
%  current choice text is available as \cs{l_keys_current_choice_tl},
%  and its position in the <list> as \cs{l_keys_current_choice_int}.
% \end{function}
% 
% \begin{function}{.default:n}
%  \begin{syntax}
%    <key>/.default:n = <content>
%  \end{syntax}
%  Creates a default value for <key>, which is used if no value is 
%  given. The <content> is stored as a token list variable, and so 
%  must be compatible with this variable type.
% \end{function}
% 
% \begin{function}{.expects_choice:}
%  \begin{syntax}
%    <key>/.expects_choice:
%  \end{syntax}
%  Indicates that the <value> given for <key> should be a sub-key of
%  <key>. In this way, <key> accepts one of a limited range of choices.
% \end{function}
% 
% \begin{function}{
%   .int_set:N|
%   .int_gset:N|
% }
%  \begin{syntax}
%    <key>/.int_set:N = <int>
%  \end{syntax}
%  Defines <key> to store <value> in the <int> named.
% \end{function}
% 
% \begin{function}{
%   .int_set:n|
%   .int_gset:n|
% }
%  \begin{syntax}
%    <key>/.int_set:n = <name>
%  \end{syntax}
%  Defines <key> to store <value> in a int with unique name <name>. The
%  int name will be constructed using the current <module> (if any), 
%  prefixed by |\l_| and ending with |_int|.
% \end{function}
% 
% \begin{function}{.retry:n}
%  \begin{syntax}
%    <key>/.retry:n = <data>
%  \end{syntax}
%  Executes <key> if it exists and if the previous \texttt{.try:n} 
%  failed. The <data> is passed to <key>, if successful.
% \end{function}
% 
% \begin{function}{
%   .show_code:|
%   .show_key:|
% }
%  \begin{syntax}
%    <key>/.show_code:
%    <key>/.show_key:
%  \end{syntax}
%  Shows the function for the current key or the code associated with
%  the current key.
% \end{function}
% 
% \begin{function}{
%   .skip_set:N|
%   .skip_gset:N|
% }
%  \begin{syntax}
%    <key>/.skip_set:N = <skip>
%  \end{syntax}
%  Defines <key> to store <value> in the <skip> named.
% \end{function}
% 
% \begin{function}{
%   .skip_set:n|
%   .skip_gset:n|
% }
%  \begin{syntax}
%    <key>/.skip_set:n = <name>
%  \end{syntax}
%  Defines <key> to store <value> in a skip with unique name <name>. The
%  skip name will be constructed using the current <module> (if any), 
%  prefixed by |\l_| and ending with |_skip|.
% \end{function}
% 
% \begin{function}{
%   .tl_set:N|
%   .tl_set_x:N|
%   .tl_gset:N|
%   .tl_gset_x:N|
% }
%  \begin{syntax}
%    <key>/.tl_set:N = <tl>
%  \end{syntax}
%  Defines <key> to store <value> in the <tl> named. The \texttt{x}
%  versions use \cs{tl_(g)set:Nx} for this process, the standard 
%  version \cs{tl_(g)set:Nn}.
% \end{function}
% 
% \begin{function}{
%   .tl_set:n|
%   .tl_set_x:n|
%   .tl_gset:n|
%   .tl_gset_x:n|
% }
%  \begin{syntax}
%    <key>/.tl_set:n = <name>
%  \end{syntax}
%  Defines <key> to store <value> in a tl with unique name <name>. The
%  tl name will be constructed using the current <module> (if any), 
%  prefixed by |\l_| and ending with |_tl|.
% \end{function}
% 
% \begin{function}{
%   .toks_set:N|
%   .toks_gset:N|
% }
%  \begin{syntax}
%    <key>/.toks_set:N = <toks>
%  \end{syntax}
%  Defines <key> to store <value> in the <toks> named.
% \end{function}
% 
% \begin{function}{
%   .toks_set:n|
%   .toks_gset:n|
% }
%  \begin{syntax}
%    <key>/.toks_set:n = <name>
%  \end{syntax}
%  Defines <key> to store <value> in a toks with unique name <name>. The
%  rest of the toks name will be constructed using the current <module>
%  (if any), prefixes by |\l_| and ending with |_toks|.
% \end{function}
% 
% \begin{function}{.try:n}
%  \begin{syntax}
%    <key>/.try:n = <data>
%  \end{syntax}
%  Executes <key> if defined, and does nothing otherwise.  The <data> is
%  passed to <key>, if successful.
% \end{function}
% 
% \begin{function}{
%   .use_keys:n|
%   .use_keys:x|
% }
%  \begin{syntax}
%    <key>/.use_keys:n = <keyval list>
%  \end{syntax}
%  Calling <key> applies the <keyval list> as a block. Thus one <key> 
%  can make many related settings. As usual, |#1| is available in the
%  <keyval list> as <key> will take one argument.
% \end{function}
% 
% \begin{function}{
%   .use_keys:Nn|
%   .use_keys:Nx|
% }
%  \begin{syntax}
%    <key>/.use_keys:Nn = <number> <keyval list>
%  \end{syntax}
%  Calling <key> applies the <keyval list> as a block. Thus one <key> 
%  can make many related settings. The <key> will take <number> of 
%  arguments, which can be used inside the <keyval list>.
% \end{function}
% 
% \begin{function}{
%   .value_forbidden:|
%   .value_required:|
% }
%  \begin{syntax}
%    <key>/.value_forbidden:
%  \end{syntax}
%  Flags for forbidding and requiring a <value> for <key>.
% \end{function}
% 
%\subsection{Variables and constants}
%
% \begin{variable}{
%   \c_keys_0_empty_tl|
%   \c_keys_1_empty_tl|
%   \c_keys_2_empty_tl|
%   \c_keys_3_empty_tl|
%   \c_keys_4_empty_tl|
%   \c_keys_5_empty_tl|
%   \c_keys_6_empty_tl|
%   \c_keys_7_empty_tl|
%   \c_keys_8_empty_tl|
%   \c_keys_9_empty_tl|
% }
%   A set of token list variables containing empty groups.
% \end{variable}
% 
% \begin{variable}{\c_keys_cs_prefix_tl}
%   The prefix added to the fully-qualified key when saving them.
% \end{variable}
% 
% \begin{variable}{
%   \c_keys_errors_path_tl|
%   \c_keys_properties_path_tl|
%   \c_keys_utilities_path_tl|
% }
%   Paths for properties used by \pkg{l3keys} itself.
% \end{variable}
% 
% \begin{variable}{\c_keys_root_tl}
%   The root path for keys.
% \end{variable}
% 
% \begin{variable}{\l_keys_choice_code_tl}
%   The code to execute for each multiple choice when created \emph{en 
%   masse}.
% \end{variable}
% 
% \begin{variable}{
%   \l_keys_current_choice_tl|
%   \l_keys_current_choice_int|
% }
%   Information on multiple choices.
% \end{variable}
% 
% \begin{variable}{
%   \l_keys_current_key_full_tl|
%   \l_keys_current_key_name_tl|
% }
%   The current key name is stored both with and without a path.
% \end{variable}
% 
% \begin{variable}{\l_keys_current_module_tl}
%   Current module name used when creating csnames.
% \end{variable}
% 
% \begin{variable}{
%   \l_keys_current_path_tl|
%   \l_keys_default_path_tl|
%   \l_keys_choice_path_tl|
% }
%   Various key paths need to be stored.
% \end{variable}
% 
% \begin{variable}{\l_keys_current_value_toks}
%   The value given for the current key, stored as a token register.
% \end{variable}
% 
% \begin{variable}{\l_keys_no_value_bool}
%   A marker for ``no value'' as key input.
% \end{variable}
% 
% \begin{variable}{\l_keys_success_bool}
%   A marker used when trying keys without raising errors.
% \end{variable}
% 
% \begin{variable}{\l_keys_tmpa_tl}
%   A scratch variable.
% \end{variable}
% 
%\subsection{Internal functions}
%
% Notice that everything should be done using the keys system. Only
% \cs{keys_manage:n} and so on are intended for external use. In all
% cases, \m{key} is a fully-qualified key name. Functions created will
% be prefixed with \cs{c_keys_cs_prefix_tl}.
% 
% \begin{function}{\keys_bool_new:n}
%   \begin{syntax}
%     "\keys_bool_new:n" <key>
%   \end{syntax}
%   Creates a switch <key>, which will be set to \texttt{true}.
% \end{function}
% 
% \begin{function}{
%   \keys_bool_set:nN|
%   \keys_bool_set:nnn|
%  }
%   \begin{syntax}
%     "\keys_bool_set:nN" <function> <boolean>
%     "\keys_bool_set:nnn" <function> <prefix> <name>
%   \end{syntax}
%   Uses <function> (either \texttt{set} or \texttt{gset}) to use 
%   <value> in setting <boolean>. If a <name> is given, it is used to 
%   construct a csname for the switch including the current <module>. 
%   The <prefix> should be |l_| or |g_|.
% \end{function}
% 
% \begin{function}{
%   \keys_bool_set_inverse:n|
%   \keys_bool_set_inverse:nN|
%   \keys_bool_set_inverse:nnn|
%  }
%   \begin{syntax}
%     "\keys_bool_set:n" <switch>
%     "\keys_bool_set:nN" <function> <boolean>
%     "\keys_bool_set:nnn" <function> <prefix> <name>
%   \end{syntax}
%   Uses <function> (either \texttt{set} or \texttt{gset}) to use 
%   <value> in setting <boolean>. If a <name> is given, it is used to 
%   construct a csname for the switch including the current <module>. 
%   The <prefix> should be |l_| or |g_|. The logic of the setting is
%   reversed compared to the \cs{keys_bool_set:} functions.
% \end{function}
% 
% \begin{function}{
%   \keys_check_exists:NN|
%   \keys_check_exists:cN
%}
%   \begin{syntax}
%     "\keys_check_exists:NN" <var> <new cmd>
%   \end{syntax}
%   Checks that <var> exists and if not used <new cmd> to create it.
% \end{function}
% 
% \begin{function}{\keys_choice_create:n}
%   \begin{syntax}
%     "\keys_choice_create:n" <choice>
%   \end{syntax}
%   Creates <choice> as a sub-key of <key>.
% \end{function}
% 
% \begin{function}{\keys_choices_create:Nnn}
%   \begin{syntax}
%     "\keys_choices_create:Nnn" <expansion> <list> <code>
%   \end{syntax}
%   Takes a comma separated <list> and makes a <choice> as a sub-key of
%   the current <key> for each. The <choice> will execute <code>, which
%   is processed according to <expansion> (either \texttt{n} or 
%   \texttt{x}). The <code> has access to \cs{l_keys_current_choice_tl}
%   and \cs{l_keys_current_choice_int}, which indicate the choice given.
% \end{function}
% 
% 
% \begin{function}{\keys_clear_properties:n}
%   \begin{syntax}
%     "\keys_clear_properties:n" <key>
%   \end{syntax}
%   Clears the internal properties of <key>.
% \end{function}
% 
% \begin{function}{\keys_default_add:}
%   \begin{syntax}
%     "\keys_default_add:"
%   \end{syntax}
%   If no value was given for the current key, and a default value is
%   available, copies the default into \cs{l_keys_current_value_toks}.
% \end{function}
% 
% \begin{function}{\keys_msg_new:nn}
%   \begin{syntax}
%     "\keys_msg_new:nn" <name> <text>
%   \end{syntax}
%   Creates a new message with <name> which produces <text>.
% \end{function}
% 
% \begin{function}{
%   \keys_error:nn|
%   \keys_error:n|
% }
%   \begin{syntax}
%     "\keys_error:nn" <name> <arg>
%     "\keys_error:n" <name> 
%   \end{syntax}
%   Issues error <name>, with or without <argument>.
% \end{function}
% 
% \begin{function}{
%   \keys_find_code_full:|
%   \keys_find_code_name:
% }
%   \begin{syntax}
%     "\keys_find_code_full:"
%     "\keys_find_code_name:"
%   \end{syntax}
%   Find code to execute for the current fully qualified key 
%   (\texttt{full}) or key name only (\texttt{name}).
% \end{function}
% 
% \begin{function}{\keys_if_cmd_exist:n / (TF)}
%   \begin{syntax}
%     "\keys_if_cmd_exist:nTF" <key> <true code> 
%     ~~~~<false code>
%   \end{syntax}
%   Checks for the existence of a |._cmd:w| function for <key>.
% \end{function}
% 
% \begin{function}{\keys_if_exist:n / (TF)}
%   \begin{syntax}
%     "\keys_if_exist:nTF" <key> <true code> 
%     ~~~~<false code>
%   \end{syntax}
%   Checks for the existence of a <key>.
% \end{function}
% 
% \begin{function}{\keys_if_value:n / (TF)}
%   \begin{syntax}
%     "\keys_if_value:nTF" <property> <true code> <false code>
%   \end{syntax}
%   Checks for the <property> switch of a <key> (typically 
%   \texttt{required} or \texttt{forbidden}).
% \end{function}
% 
% \begin{function}{\keys_manage_internal:n}
%   \begin{syntax}
%     "\keys_manage_internal:n" <keyval list>
%   \end{syntax}
%   An internal ``recycling'' version of \cs{keys_manage_quick:n}, which
%   should not be called from outside.
% \end{function}
% 
% \begin{function}{
%   \keys_no_value_elt:n|
%   \keys_value_elt:nn
% }
%   \begin{syntax}
%     "\keys_no_value_elt:n" <elt>
%     "\keys_value_elt:nn" <elt> <value>
%   \end{syntax}
%   Functions used by \pkg{l3keyval} for each <elt> of the <keyval 
%   list> being processed.
% \end{function}
% 
% \begin{function}{\keys_parse:n}
%   \begin{syntax}
%     "\keys_parse:n" <keyval list>
%   \end{syntax}
%   Functions which actually parses <keyval list>.
% \end{function}
% 
% \begin{function}{\keys_parse_list:n}
%   \begin{syntax}
%     "\keys_parse_list:n" <keyval list>
%   \end{syntax}
%   Set up macro for \cs{keys_parse:n}.
% \end{function}
% 
% \begin{function}{
%   \keys_path_add:N|
%   \keys_path_add:w
%  }
%   \begin{syntax}
%     "\keys_path_add:N" <tl>
%     "\keys_path_add:w" <tlist> "\q_stop"
%   \end{syntax}
%   Adds a full path to key name stored in <tl> or given as <tlist>.
% \end{function}
% 
% \begin{function}{\keys_process_elt:nn}
%   \begin{syntax}
%     "\keys_process_elt:nn" <elt> <value>
%   \end{syntax}
%   Lead-off processor for converting <elt> into a fully-qualified 
%   <key> and checking validity of <value>.
% \end{function}
% 
% \begin{function}{
%   \keys_separate_path:|
%   \keys_separate_path:w
%  }
%   \begin{syntax}
%     "\keys_separate_path:" 
%     "\keys_separate_path:w" / <path 1> / <path 2> "\q_stop"
%   \end{syntax}
%   Separates key into <path> and <key name>.
% \end{function}
% 
% \begin{function}{
%   \keys_set:NN|
%   \keys_set:Nnn|
%  }
%   \begin{syntax}
%     "\keys_set:NN" <function> <variable>
%     "\keys_set:Nnn" <function> <prefix> <name>
%   \end{syntax}
%   Uses <function> to store <value> in <variable>. If a <name> is
%   given, it is used to construct a csname for the variable including
%   the current <module>. The <prefix> should be |l_| or |g_|.
% \end{function}
% 
% \begin{function}{
%   \keys_set_cmd:nn|
%   \keys_set_cmd:nx|
%   \keys_set_cmd:nNn|
%   \keys_set_cmd:nNx|
%  }
%   \begin{syntax}
%     "\keys_set_cmd:nn" <key> <code>
%     "\keys_set_cmd:nNn" <key> <number> <code>
%   \end{syntax}
%   Creates a |._cmd:w| function for <key>, with definition <code>. The
%   \texttt{N} variant can include <number> parameters.
% \end{function}
% 
% \begin{function}{
%   \keys_store:nn|
%   \keys_store:nx
%  }
%   \begin{syntax}
%     "\keys_store:nn" <key> <data>
%   \end{syntax}
%   Stores <data> in <key> function.
% \end{function}
% 
% \begin{function}{\keys_toks_set:Nn}
%   \begin{syntax}
%     "\keys_toks_set:Nn" <toks> <key>
%   \end{syntax}
%   Sets <toks> equal to the content of <key>
% \end{function}
% 
% \begin{function}{\keys_try:}
%   \begin{syntax}
%     "\keys_try:"
%   \end{syntax}
%   Attempt to execute a key, with no error if the key is unknown.
% \end{function}
% 
% \begin{function}{\keys_undefine:n}
%   \begin{syntax}
%     "\keys_undefine:n" <key>
%   \end{syntax}
%   Delete definition of <key>.
% \end{function}
% 
% \begin{function}{\keys_use:n}
%   \begin{syntax}
%     "\keys_use:n" <key>
%   \end{syntax}
%   Use definition of <key>.
% \end{function}
% 
% \begin{function}{
%   \keys_use_cmd:n|
%   \keys_use_cmd:nn
% }
%   \begin{syntax}
%     "\keys_use_cmd:n" <key>
%     "\keys_use_cmd:nn" <key> <arg>
%   \end{syntax}
%   Uses the |._cmd:w| function for <key>, passing <arg> if needed.
% \end{function}
% 
%\subsubsection{Internal properties}
%
% The internal key properties should not be accessed directly.
%
% \begin{function}{._cmd:w}
%  \begin{syntax}
%  \end{syntax}
%  The function which is executed for a key with \texttt{.code}.
% \end{function}
%
% \begin{function}{._default_tl}
%  \begin{syntax}
%  \end{syntax}
%  Holds the default value for a key.
% \end{function}
% 
% \begin{function}{._forbidden_bool}
%  \begin{syntax}
%  \end{syntax}
%  Indicates that a value cannot be given for <key>.
% \end{function}
% 
% \begin{function}{._num_args_tl}
%  \begin{syntax}
%  \end{syntax}
%  For functions defined with \texttt{.code:Nn} and \texttt{.code:Nx},
%  contains the number of arguments the associated |._cmd:w| function
%  takes.
% \end{function}
% 
% \begin{function}{._required_bool}
%  \begin{syntax}
%  \end{syntax}
%  Indicates that <key> must have a value provided.
% \end{function}
% 
% \end{documentation}
% 
% \begin{implementation}
% 
%\subsection{Implementation}
%
% The usual preliminaries.  
%    \begin{macrocode}
%<*package>
\ProvidesExplPackage
  {\filename}{\filedate}{\fileversion}{\filedescription}
%    \end{macrocode}
%
%\subsubsection{Variables and contrasts}
%
%\begin{macro}{\c_keys_0_empty_tl}
%\begin{macro}{\c_keys_1_empty_tl}
%\begin{macro}{\c_keys_2_empty_tl}
%\begin{macro}{\c_keys_3_empty_tl}
%\begin{macro}{\c_keys_4_empty_tl}
%\begin{macro}{\c_keys_5_empty_tl}
%\begin{macro}{\c_keys_6_empty_tl}
%\begin{macro}{\c_keys_7_empty_tl}
%\begin{macro}{\c_keys_8_empty_tl}
%\begin{macro}{\c_keys_9_empty_tl}
% A set of empty arguments.
%    \begin{macrocode}
\tl_new:cn { c_keys_0_empty_tl } {}
\tl_new:cn { c_keys_1_empty_tl } { {} }
\tl_new:cn { c_keys_2_empty_tl } { {} {} }
\tl_new:cn { c_keys_3_empty_tl } { {} {} {} }
\tl_new:cn { c_keys_4_empty_tl } { {} {} {} {} }
\tl_new:cn { c_keys_5_empty_tl } { {} {} {} {} {} }
\tl_new:cn { c_keys_6_empty_tl } { {} {} {} {} {} {} }
\tl_new:cn { c_keys_7_empty_tl } { {} {} {} {} {} {} {} }
\tl_new:cn { c_keys_8_empty_tl } { {} {} {} {} {} {} {} {} }
\tl_new:cn { c_keys_9_empty_tl } { {} {} {} {} {} {} {} {} {} }
%    \end{macrocode}
%\end{macro}
%\end{macro}
%\end{macro}
%\end{macro}
%\end{macro}
%\end{macro}
%\end{macro}
%\end{macro}
%\end{macro}
%\end{macro}
%
%\begin{macro}{\c_keys_cs_prefix_tl}
% First, the small number of constants needed are created. A prefix is
% used to keep all of the actual key macros in one place.
%    \begin{macrocode}
\tl_new:Nn \c_keys_cs_prefix_tl { keys-root }
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\c_keys_errors_path_tl}
%\begin{macro}{\c_keys_properties_path_tl}
%\begin{macro}{\c_keys_utilities_path_tl}
% The locations of all of the keys used by \pkg{keys3} itself.
%    \begin{macrocode}
\tl_new:Nn \c_keys_errors_path_tl     { /keys/errors }
\tl_new:Nn \c_keys_properties_path_tl { /keys/properties }
\tl_new:Nn \c_keys_utilities_path_tl  { /keys }
%    \end{macrocode}
%\end{macro}
%\end{macro}
%\end{macro}
%
%\begin{macro}{\c_keys_root_tl}
% The key root should have a clear name; like all of the key macros,
% this does not include the prefix.
%    \begin{macrocode}
\tl_new:Nn \c_keys_root_tl { / }
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\l_keys_choice_code_tl}
% When making choices, the code for each key has to be stored.
%    \begin{macrocode}
\tl_new:N \l_keys_choice_code_tl
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\l_keys_current_choice_tl}
%\begin{macro}{\l_keys_current_choice_int}
% Multiple choices need some storage.
%    \begin{macrocode}
\tl_new:N \l_keys_current_choice_tl
\int_new:N \l_keys_current_choice_int
%    \end{macrocode}
%\end{macro}
%\end{macro}
%
%\begin{macro}{\l_keys_current_key_full_tl}
%\begin{macro}{\l_keys_current_key_name_tl}
% The current key name and the fully-qualified key are stored.
%    \begin{macrocode}
\tl_new:N \l_keys_current_key_full_tl
\tl_new:N \l_keys_current_default_tl
%    \end{macrocode}
%\end{macro}
%\end{macro}
%
%\begin{macro}{\l_keys_current_module_tl}
% The module name of the current module is stored here.
%    \begin{macrocode}
\tl_new:N \l_keys_current_module_tl
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\l_keys_current_path_tl}
%\begin{macro}{\l_keys_default_path_tl}
%\begin{macro}{\l_keys_choice_path_tl}
% The current and default paths can be stored as tls. The default path
% is then initialised as the key root.
%    \begin{macrocode}
\tl_new:N \l_keys_current_path_tl
\tl_new:N \l_keys_default_path_tl
\tl_set_eq:NN \l_keys_default_path_tl \c_keys_root_tl
\tl_new:N \l_keys_choice_path_tl
%    \end{macrocode}
%\end{macro}
%\end{macro}
%\end{macro}
%
%\begin{macro}{\l_keys_current_value_toks}
% The current value is stored in a token register.
%    \begin{macrocode}
\toks_new:N \l_keys_current_value_toks
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\l_keys_no_value_bool}
% To indicate that no value has been given.
%    \begin{macrocode}
\bool_new:N \l_keys_no_value_bool
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\l_keys_success_bool}
% A switch for trying keys.
%    \begin{macrocode}
\bool_new:N \l_keys_success_bool
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\l_keys_tmpa_tl}
% A scratch area.
%    \begin{macrocode}
\tl_new:N \l_keys_tmpa_tl
%    \end{macrocode}
%\end{macro}
%
%\subsubsection{Functions}
%
%\begin{macro}{\keys_manage:n}
%\begin{macro}{\keys_manage_quick:n}
%\begin{macro}{\keys_manage_internal:n}
%\begin{macro}[aux]{\keys_manage_aux:nn}
%\begin{macro}[aux]{\keys_manage_aux:Vn}
% The main key management macros both call the auxiliary function after
% setting up the parser.  The expansion trick means a literal path is
% sent to the later function, and so the default path can be redefined.
%    \begin{macrocode}
\cs_new:Nn \keys_manage:n {
  \cs_set_eq:NN \keys_parse:n \KV_parse_space_removal_sanitize:n
  \tl_clear:N \l_keys_current_module_tl
  \keys_manage_internal:n {#1}
}
\cs_new:Nn \keys_manage_quick:n {
  \cs_set_eq:NN \keys_parse:n \KV_parse_no_space_removal_no_sanitize:n
  \tl_clear:N \l_keys_current_module_tl
  \keys_manage_internal:n {#1}
}
\cs_new:Nn \keys_manage_internal:n {
  \keys_manage_aux:Vn \l_keys_default_path_tl {#1}
}
\cs_new:Nn \keys_manage_aux:nn {
  \tl_set_eq:NN \l_keys_default_path_tl \c_keys_root_tl
  \keys_parse_list:n {#2}
  \tl_set:Nn \l_keys_default_path_tl {#1}
}
\cs_generate_variant:Nn \keys_manage_aux:nn { Vn }
%    \end{macrocode}
%\end{macro}
%\end{macro}
%\end{macro}
%\end{macro}
%\end{macro}
%\begin{macro}{\keys_manage:nn}
%\begin{macro}{\keys_manage_quick:nn}
%\begin{macro}[aux]{\keys_manage_aux:nnn}
%\begin{macro}[aux]{\keys_manage_aux:Vnn}
% This version uses the same tricks but includes the path as a second
% argument.  When setting lots of keys separately, this is a little
% faster than the key-based method.
%    \begin{macrocode}
\cs_new:Nn \keys_manage:nn {
  \cs_set_eq:NN \keys_parse:n \KV_parse_space_removal_sanitize:n
  \keys_manage_aux:Vnn \l_keys_default_path_tl {#1} {#2}
}
\cs_new:Nn \keys_manage_quick:nn {
  \cs_set_eq:NN \keys_parse:n \KV_parse_space_no_removal_no_sanitize:n
  \keys_manage_aux:Vnn \l_keys_default_path_tl {#1} {#2}
}
\cs_new:Nn \keys_manage_aux:nnn {
  \tl_set:Nn \l_keys_default_path_tl {#2}
  \tl_clear:N \l_keys_current_module_tl
  \keys_parse_list:n {#3}
  \tl_set:Nn \l_keys_default_path_tl {#1}
}
\cs_generate_variant:Nn \keys_manage_aux:nnn { Vnn }
%    \end{macrocode}
%\end{macro}
%\end{macro}
%\end{macro}
%\end{macro}
%
%\subsubsection{Internal functions}
%
%\begin{macro}{\keys_bool_new:n}
% To create a new switch, which will be true (as the existence of the 
% switch is the flag here).
%    \begin{macrocode}
\cs_new_nopar:Nn \keys_bool_new:n {
  \bool_new:c { \c_keys_cs_prefix_tl #1 }
  \bool_set_true:c { \c_keys_cs_prefix_tl #1 }
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\keys_bool_set:nN}
%\begin{macro}{\keys_bool_set:nnn}
% Boolean keys are created by using the fact that only \texttt{true} and
% \texttt{false} give the right result when looking for a setting 
% function. A default is also set, so that the key name alone can be 
% given.
%    \begin{macrocode}
\cs_new_nopar:Nn \keys_bool_set:nN {
  \keys_parse_list:n {
    \c_keys_properties_path_tl /.code:n = {
      \cs_if_exist:cTF { bool_ #1 _ ##1 :N } {
        \use:c { bool_ #1 _ ##1 :N } #2
      }{
        \keys_error:nn { Boolean~expected } {##1}
      }
    },
    \l_keys_current_path_tl /.default:n = true
  }
}
\cs_new_nopar:Nn \keys_bool_set:nnn {
  \keys_parse_list:n {
    \c_keys_properties_path_tl /.code:x = {
      \exp_not:N \cs_if_exist:cTF { bool_ #1 _ ##1 :c } {
        \exp_not:N \use:c { bool_ #1 _ ##1 :c } 
          { #2 \l_keys_current_module_tl #3 _bool }
      }{
        \keys_error:nn { Boolean~expected } {##1}
      }
    },
    \l_keys_current_path_tl /.default:n = true
  }
}
%    \end{macrocode}
%\end{macro}
%\end{macro}
%
%\begin{macro}{\keys_bool_set_inverse:n}
%\begin{macro}{\keys_bool_set_inverse:nN}
%\begin{macro}{\keys_bool_set_inverse:nnn}
% To set keys with reversed logic, the basics can be done in the same 
% way as for the standard switches.  The only thing needed is a 
% reversal of \texttt{true}/\texttt{false}.
%    \begin{macrocode}
\cs_new_nopar:Nn \keys_bool_set_inverse:n {
  \tl_if_eq:nnTF {#1} { true } { false } { true }
}
\cs_new_nopar:Nn \keys_bool_set_inverse:nN {
  \keys_parse_list:n {
    \c_keys_properties_path_tl /.code:n = {
      \cs_if_exist:cTF { bool_ #1 _ ##1 :N } {
        \use:c { bool_ #1 _ \keys_bool_set_inverse:n {##1} :N } #2
      }{
        \keys_error:nn { Boolean~expected } {##1}
      }
    },
    \l_keys_current_path_tl /.default:n = true
  }
}
\cs_new_nopar:Nn \keys_bool_set_inverse:nnn {
  \keys_parse_list:n {
    \c_keys_properties_path_tl /.code:x = {
      \exp_not:N \cs_if_exist:cTF { bool_ #1 _ ##1 :c } {
         \exp_not:N \use:c { 
           bool_ #1 _ \exp_not:N \keys_bool_set_inverse:n {##1} :c 
         } { #2 \l_keys_current_module_tl #3 _bool }
      }{
        \keys_error:nn { Boolean~expected } {##1}
      }
    },
    \l_keys_current_path_tl /.default:n = true
  }
}
%    \end{macrocode}
%\end{macro}
%\end{macro}
%\end{macro}
%
%\begin{macro}{\keys_check_exists:NN}
%\begin{macro}{\keys_check_exists:cN}
% A check function to avoid problems later.
%    \begin{macrocode}
\cs_new_nopar:Nn \keys_check_exists:NN {
  \cs_if_exist:NF #1 {
    #2 #1
  }
}
\cs_generate_variant:Nn \keys_check_exists:NN { cN }
%    \end{macrocode}
%\end{macro}
%\end{macro}
%
%\begin{macro}{\keys_choices_create:Nnn}
%\begin{macro}[aux]{\keys_choices_create_aux:n}
%\begin{macro}[aux]{\keys_choices_create_aux:x}
%\begin{macro}{\keys_choice_create:n}
% When making multiple choices, the code for each choice is the same.
% Only the path and counter need to be altered. 
%    \begin{macrocode}
\cs_new:Nn \keys_choices_create:Nnn {
  \tl_set_eq:NN \l_keys_choice_path_tl \l_keys_current_path_tl
  \int_zero:N \l_keys_current_choice_int
  \use:c { keys_choices_create_aux: #1 } {#3}
  \clist_map_function:nN {#2} \keys_choice_create:n
  \keys_manage_internal:n { \l_keys_choice_path_tl  /.expects_choice: }
}
\cs_new:Nn \keys_choices_create_aux:n {
  \tl_set:Nn \l_keys_choice_code_tl { \exp_not:n {#1} }
}
\cs_new:Nn \keys_choices_create_aux:x {
  \tl_set:Nn \l_keys_choice_code_tl {#1}
}
\cs_new_nopar:Nn \keys_choice_create:n {
  \int_incr:N \l_keys_current_choice_int
  \keys_parse_list:n {
    \l_keys_choice_path_tl / #1 /.code:x = {
      \exp_not:n { \int_set:Nn \l_keys_current_choice_int }
        { \int_use:N \l_keys_current_choice_int }
      \exp_not:n { \tl_set:Nn \l_keys_current_choice_tl } {#1}
      \l_keys_choice_code_tl
    }
  }
}
%    \end{macrocode}
%\end{macro}
%\end{macro}
%\end{macro}
%\end{macro}
%
%\begin{macro}{\keys_clear_properties:n}
% To avoid problem on redefinition, all properties are removed.
%    \begin{macrocode}
\cs_new_nopar:Nn \keys_clear_properties:n {
  \keys_undefine:n { #1 /._cmd:w }      
  \keys_undefine:n { #1 /._default_tl }  
  \keys_undefine:n { #1 /._forbidden_bool } 
  \keys_undefine:n { #1 /._num_args_tl }
  \keys_undefine:n { #1 /._required_bool }
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\keys_default_add:}
% Copies the default value to the current one if needed.
%    \begin{macrocode}
\cs_new_nopar:Nn \keys_default_add: {
  \bool_if:NT \l_keys_no_value_bool {
    \keys_if_exist:nT 
      { \l_keys_current_key_full_tl /._default_tl } {
      \keys_toks_set:Nn \l_keys_current_value_toks
        { \l_keys_current_key_full_tl /._default_tl }
      \bool_set_false:N \l_keys_no_value_bool
    }
  }
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\keys_find_code_full:}
%\begin{macro}{\keys_find_code_name:}
% Two functions to find something to process the key value given. First,
% a search is made for either a command property for the key, or a 
% function for the key itself. If that fails, the generic handlers are 
% used after separating out the key name and key path.
%    \begin{macrocode}
\cs_new_nopar:Nn \keys_find_code_full: {
  \keys_if_cmd_exist:nTF { \l_keys_current_key_full_tl } {
    \keys_use_cmd:n { \l_keys_current_key_full_tl }
  }{
    \keys_if_exist:nTF { \l_keys_current_key_full_tl } {
      \bool_if:NTF \l_keys_no_value_bool {
        \keys_use:n { \l_keys_current_key_full_tl }
      }{
        \keys_store:nx { \l_keys_current_key_full_tl }
          { \toks_use:N \l_keys_current_value_toks }
      }
    }{
      \keys_find_code_name:
    }
  }
}
\cs_new_nopar:Nn \keys_find_code_name: {
  \keys_separate_path:
  \keys_if_cmd_exist:nTF
    { \c_keys_properties_path_tl / \l_keys_current_key_name_tl } {
    \keys_use_cmd:n  
      {\c_keys_properties_path_tl / \l_keys_current_key_name_tl}
  }{
    \keys_if_cmd_exist:nTF 
      { \l_keys_current_path_tl / unknown } {
      \keys_use_cmd:n { \l_keys_current_path_tl / unknown }
    }{
      \keys_error:n { unknown~key }
    }
  }
}
%    \end{macrocode}
%\end{macro}
%\end{macro}
%
%\begin{macro}[TF]{\keys_if_cmd_exist:n}
% A dedicated check for the |._cmd:w| property key.
%    \begin{macrocode}
\prg_new_conditional:Nnn \keys_if_cmd_exist:n {TF,T,F} {
 \if_cs_exist:w \c_keys_cs_prefix_tl #1 /._cmd:w \cs_end:
   \prg_return_true: 
  \else: 
    \prg_return_false: 
  \fi:
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}[TF]{\keys_if_exist:n}
% Check if a key exists without adding to the hash table.
%    \begin{macrocode}
\prg_new_conditional:Nnn \keys_if_exist:n {TF,T,F} {
 \if_cs_exist:w \c_keys_cs_prefix_tl #1 \cs_end:
   \prg_return_true: 
  \else: 
    \prg_return_false: 
  \fi:
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}[TF]{\keys_if_value:n}
% Used for required and forbidden values.
%    \begin{macrocode}
\prg_new_conditional:Nnn \keys_if_value:n {TF,T,F} {
 \if_cs_exist:w 
   \c_keys_cs_prefix_tl \l_keys_current_key_full_tl /._ #1 _bool 
 \cs_end:
   \prg_return_true: 
  \else: 
    \prg_return_false: 
  \fi:
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\keys_no_value_elt:n}
%\begin{macro}{\keys_value_elt:nn}
% The two functions passed to \pkg{l3keyval} to actually act on each
% key found.
%    \begin{macrocode}
\cs_new:Nn \keys_no_value_elt:n {
  \bool_set_true:N \l_keys_no_value_bool
  \keys_process_elt:nn {#1} { }
}
\cs_new:Nn \keys_value_elt:nn {
  \bool_set_false:N \l_keys_no_value_bool
  \keys_process_elt:nn {#1} {#2}
}
%    \end{macrocode}
%\end{macro}
%\end{macro}
%
%\begin{macro}{\keys_parse:n}
% The macro used to actually process the key--value input is taken from
% \pkg{l3keyval}.  There are two possible options, and so at this
% stage the macro is simply reserved.
%    \begin{macrocode}
\cs_new:Nn \keys_parse:n { \ERROR }
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\keys_parse_list:n}
% All of the management macros call this common parser. First, the key
% processing macros are defined, then the appropriate parser is called.
%    \begin{macrocode}
\cs_new:Nn \keys_parse_list:n {
  \cs_set_eq:NN \KV_key_value_elt:nn \keys_value_elt:nn
  \cs_set_eq:NN \KV_key_no_value_elt:n \keys_no_value_elt:n
  \keys_parse:n {#1}
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\keys_path_add:N}
%\begin{macro}{\keys_path_add:w}
%\begin{macro}[aux]{\keys_path_add_aux:w}
% The code to check for a path looks for a |/| at the start of the key.
%    \begin{macrocode}
\cs_new_nopar:Nn \keys_path_add:N {
  \exp_after:wN \keys_path_add:w #1 \q_stop
}
\cs_new_nopar:Npn \keys_path_add:w {
  \exp_after:wN \peek_meaning:NTF \c_keys_root_tl {
    \use_none_delimit_by_q_stop:w
  }{
    \keys_path_add_aux:w
  }
}
\cs_new_nopar:Npn \keys_path_add_aux:w #1 \q_stop {
  \tl_set:Nx \l_keys_current_key_full_tl {\l_keys_default_path_tl #1}
}
%    \end{macrocode}
%\end{macro}
%\end{macro}
%\end{macro}
%
%\begin{macro}{\keys_process_elt:nn}
%\begin{macro}[aux]{\keys_process_elt_aux:}
% The key processor starts by storing the given key name and value, and
% adding a path to the former if necessary. There is then potentially a
% need to fill in a default value before checking for required or 
% forbidden values.
%    \begin{macrocode}
\cs_new:Nn \keys_process_elt:nn {
  \tl_set:Nx \l_keys_current_key_full_tl {#1}
  \toks_set:Nn \l_keys_current_value_toks {#2}
  \keys_path_add:N \l_keys_current_key_full_tl
  \keys_default_add:
  \keys_if_value:nTF { required } {
    \bool_if:NTF \l_keys_no_value_bool {
      \keys_error:n { value~required }
    }{
      \keys_process_elt_aux:
    }
  }{
    \keys_process_elt_aux:
  }
}
\cs_new:Nn \keys_process_elt_aux: {
  \keys_if_value:nTF { forbidden } {
    \bool_if:NTF \l_keys_no_value_bool {
      \keys_find_code_full:
    }{
      \keys_error:nn { value~forbidden } 
        { \toks_use:N \l_keys_current_value_toks }
    }
  }{
    \keys_find_code_full:
  }
}
%    \end{macrocode}
%\end{macro}
%\end{macro}
%
%\begin{macro}{\keys_separate_path:}
%\begin{macro}{\keys_separate_path:w}
% A simple piece of recursion to find the key name and path.
%    \begin{macrocode}
\cs_new_nopar:Nn \keys_separate_path: {
  \tl_clear:N \l_keys_current_path_tl
  \exp_after:wN \keys_separate_path:w \l_keys_current_key_full_tl 
    / \q_stop
}
\cs_new_nopar:Npn \keys_separate_path:w / #1 / #2 \q_stop {
  \tl_if_empty:nTF {#2} {
    \tl_set:Nn \l_keys_current_key_name_tl {#1}
  }{
     \tl_put_right:Nn \l_keys_current_path_tl { / #1 }
     \keys_separate_path:w /#2 \q_stop
  }
}
%    \end{macrocode}
%\end{macro}
%\end{macro}
%
%\begin{macro}{\keys_set:NN}
%\begin{macro}{\keys_set:Nnn}
% Storage of data in outside of keys.
%    \begin{macrocode}
\cs_new_nopar:Nn \keys_set:NN {
  \keys_parse_list:n {
    \c_keys_properties_path_tl /.code:n = {
      #1 #2 {##1}
    }
  }
}
\cs_new_nopar:Nn \keys_set:Nnn {
  \keys_parse_list:n {
    \c_keys_properties_path_tl /.code:x = {
      \exp_not:N #1 { #2 \l_keys_current_module_tl #3 } {##1}
    }
  }
}
%    \end{macrocode}
%\end{macro}
%\end{macro}
%
%\begin{macro}{\keys_set_cmd:nn}
%\begin{macro}{\keys_set_cmd:nx}
%\begin{macro}{\keys_set_cmd:nNn}
%\begin{macro}{\keys_set_cmd:nNx}
%\begin{macro}{._cmd:w}
%\begin{macro}{._num_args_tl}
% Creation of the key |._cmd:w| macros happens here. For the 
% multiple-argument versions, the number of arguments is stored for
% use later on.
%    \begin{macrocode}
\cs_new:Nn \keys_set_cmd:nn {
  \keys_clear_properties:n {#1}
  \cs_set:cpn { \c_keys_cs_prefix_tl #1 /._cmd:w } ##1 {#2}
}
\cs_new:Nn \keys_set_cmd:nx {
  \keys_clear_properties:n {#1}
  \cs_set:cpx { \c_keys_cs_prefix_tl #1 /._cmd:w } ##1 {#2}
}
\cs_new:Nn \keys_set_cmd:nNn {
  \keys_clear_properties:n {#1}
  \cs_generate_from_arg_count:cNnn { \c_keys_cs_prefix_tl #1 /._cmd:w } 
      \cs_set:Npn #2 {#3}
  \keys_store:nn { #1 /._num_args_tl} {#2}
}
\cs_new:Nn \keys_set_cmd:nNx {
  \keys_clear_properties:n {#1}
  \cs_generate_from_arg_count:cNnn { \c_keys_cs_prefix_tl #1 /._cmd:w } 
      \cs_set:Npx #2 {#3}
  \keys_store:nn { #1 /._num_args_tl} {#2}
}
%    \end{macrocode}
%\end{macro}
%\end{macro}
%\end{macro}
%\end{macro}
%\end{macro}
%\end{macro}
%
%\begin{macro}{\keys_store:nn}
%\begin{macro}{\keys_store:nx}
% Direct storage of data in keys.
%    \begin{macrocode}
\cs_new:Nn \keys_store:nn {
  \tl_set:cn { \c_keys_cs_prefix_tl #1 } {#2}
}
\cs_new:Nn \keys_store:nx {
  \tl_set:cx { \c_keys_cs_prefix_tl #1 } {#2}
}
%    \end{macrocode}
%\end{macro}
%\end{macro}
%
%\begin{macro}{\keys_toks_set:Nn}
% Sets a toks to the content of a key.
%    \begin{macrocode}
\cs_new_nopar:Nn \keys_toks_set:Nn {
  \exp_args:NNv \toks_set:Nn #1 { \c_keys_cs_prefix_tl #2 }
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\keys_try:}
% A function to look for the |._cmd:w| property of a key, and executes
% it if found.
%    \begin{macrocode}
\cs_new_nopar:Nn \keys_try: {
  \bool_set_false:N \l_keys_success_bool
  \keys_if_cmd_exist:nT { \l_keys_current_path_tl } {
    \bool_set_true:N \l_keys_success_bool
    \bool_if:NT \l_keys_no_value_bool {
      \keys_if_exist:nT
        { \l_keys_current_path_tl /._default_tl } {
        \keys_toks_set:Nn \l_keys_current_value_toks
          { \l_keys_current_path_tl /._default_tl }
      }
    }
    \cs_set_eq:NN \l_keys_current_key_full_tl \l_keys_current_path_tl 
    \keys_use_cmd:n { \l_keys_current_path_tl }
  }
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\keys_undefine:n}
% To remove a key.
%    \begin{macrocode}
\cs_new_nopar:Nn \keys_undefine:n {
  \cs_set_eq:cN { \c_keys_cs_prefix_tl #1 } \c_undefined
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\keys_use:n}
% Use whatever is stored in a key.
%    \begin{macrocode}
\cs_new_nopar:Nn \keys_use:n {
  \use:c { \c_keys_cs_prefix_tl #1 }
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\keys_use_cmd:n}
%\begin{macro}{\keys_use_cmd:nn}
%\begin{macro}[aux]{\keys_use_cmd_aux:nn}
%\begin{macro}[aux]{\keys_use_cmd_aux:w}
% Some care is needed when using command keys. For commands with 
% multiple arguments a check is made in case none were given, and if
% so a series of empty values is given instead.
%    \begin{macrocode}
\cs_new_nopar:Nn \keys_use_cmd:n {
  \exp_args:Nno \keys_use_cmd:nn {#1} 
    { \toks_use:N \l_keys_current_value_toks }
}
\cs_new_nopar:Nn \keys_use_cmd:nn {
  \keys_if_exist:nTF { #1 /._num_args_tl } {
     \keys_use_cmd_aux:nn {#1} {#2}
  }{
    \keys_use:n {#1/._cmd:w} {#2}
  }
}
\cs_new_nopar:Nn \keys_use_cmd_aux:nn {
  \tl_if_empty:nTF {#2} {
    \cs_set:Npn \keys_use_cmd_aux:w {
      \keys_use:n { #1 /._cmd:w }
    }
    \exp_after:wN \exp_after:wN \exp_after:wN \keys_use_cmd_aux:w 
      \cs:w
        c_keys_ \keys_use:n { #1 /._num_args_tl } _empty_tl
      \cs_end:
  }{
    \keys_use:n { #1 /._cmd:w } #2
  }
}
%    \end{macrocode}
%\end{macro}
%\end{macro}
%\end{macro}
%\end{macro}
%
%\subsubsection{Error handling code}
%
% The \LaTeX3 approach is to have named errors called separately and 
% defined separately. To make life a little easier here, some custom
% functions are used to keep repetition down.
% 
%\begin{macro}{\keys_msg_new:nn}
% To create new error messages, a utility function is created.
%    \begin{macrocode}
\cs_new_nopar:Npn \keys_msg_new:nn #1 {
  \msg_new:nnn { keys } {#1}
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\keys_error:n}
%\begin{macro}{\keys_error:nn}
% Utilities for using errors, which always have 
% \cs{l_keys_current_key_full_tl} as the first argument.
%    \begin{macrocode}
\cs_new_protected_nopar:Nn \keys_error:nn {
  \msg_error:nnxx { keys } {#1} { \l_keys_current_key_full_tl } {#2}
}
\cs_new_protected_nopar:Nn \keys_error:n {
  \msg_error:nnx { keys } {#1} { \l_keys_current_key_full_tl }
}
%    \end{macrocode}
%\end{macro}
%\end{macro}
%
%    \begin{macrocode}
\keys_msg_new:nn 
  { unknown~key } 
  {The key `#1' is unknown and is being ignored.}
\keys_msg_new:nn 
  { value~required }
  {The key `#1' requires a value\\%
  and is being ignored.}
\keys_msg_new:nn 
  { value~forbidden }
  {The key `#1' cannot taken a value:\\%
   the given input `#2' is being ignored.}
\keys_msg_new:nn 
  { Boolean~expected } 
  {Key `#1' takes the Boolean values\\%
  `true' and `false'~only.\\%
   The given value `#2' is being ignored.}
\keys_msg_new:nn 
  { not_boolean }
  {Key `#1' is not a Boolean key: you cannot create a complement.}
\keys_msg_new:nn 
  { unknown~choice }
  {Choice `#2' unknown for key `#1':\\%
   the key is being ignored.}
%    \end{macrocode}
%
%\subsubsection{Property definitions}
%
%\begin{macro}{.code:n}
%\begin{macro}{.code:Nn}
% The \texttt{.code:n} and \texttt{.code:Nn} properties have to be 
% defined directly.
%    \begin{macrocode}
\keys_set_cmd:nn { \c_keys_properties_path_tl /.code:n } {
  \keys_set_cmd:nn { \l_keys_current_path_tl } {#1}
}
\keys_set_cmd:nNn { \c_keys_properties_path_tl /.code:Nn } 2 {
  \keys_set_cmd:nNn { \l_keys_current_path_tl } #1 {#2}
}
%    \end{macrocode}
%\end{macro}
%\end{macro}
%
% The remaining definitions can all be carried out using the package
% itself. As category codes and spaces are not an issue here, the
% |_quick| version of \cs{keys_manage} is used.
% 
% First, an error is created for unknown keys: this is done early to
% catch any internal errors.
%    \begin{macrocode}
\keys_manage_quick:n {
  \c_keys_errors_path_tl /unknown/.code:n = {
    \keys_error:n { unknown~key }
  }
}
%    \end{macrocode}
%    
%\begin{macro}{.code:x}
%\begin{macro}{.code:Nx}
% Fully-expanded versions of the basic \texttt{.code} properties.
%    \begin{macrocode}
\keys_manage_quick:n {
  \c_keys_properties_path_tl /.code:x/.code:n = {
    \keys_set_cmd:nx { \l_keys_current_path_tl } {#1}
  },
  \c_keys_properties_path_tl /.code:Nx/.code:Nn = 2 {
    \keys_set_cmd:nNx { \l_keys_current_path_tl } {#1} {#2}
  }
}
%    \end{macrocode}
%\end{macro}
%\end{macro}
%    
%\begin{macro}{.cd:}
% The change-directory property simply alters the value of the default
% path. 
%    \begin{macrocode}
\keys_manage_quick:n {
    \c_keys_properties_path_tl /.cd:/.code:n = {
    \tl_set:Nx \l_keys_default_path_tl { \l_keys_current_path_tl / }
  }
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{.value_forbidden:}
%\begin{macro}{._required_bool}
%\begin{macro}{.value_required:}
%\begin{macro}{._forbidden_bool}
% Values are required or forbidden by creating the appropriate flags.
%    \begin{macrocode}
\keys_manage_quick:n {
  \c_keys_properties_path_tl /.value_required:/.code:n = {
    \keys_bool_new:n { \l_keys_current_path_tl /._required_bool }
    \keys_undefine:n { \l_keys_current_path_tl /._forbidden_bool }
  },
  \c_keys_properties_path_tl /.value_forbidden:/.code:n = {
    \keys_bool_new:n { \l_keys_current_path_tl /._forbidden_bool }
    \keys_undefine:n { \l_keys_current_path_tl /._required_bool }
  }
}
%    \end{macrocode}
%\end{macro}
%\end{macro}
%\end{macro}
%\end{macro}
%
%\begin{macro}{.default:n}
%\begin{macro}{._default_tl}
% The default value for a key is stored in the |._default_tl|
% private property.
%    \begin{macrocode}
\keys_manage_quick:n {
  \c_keys_properties_path_tl /.default:n/.code:n = {
    \keys_store:nn { \l_keys_current_path_tl /._default_tl } {#1}
    \keys_undefine:n { \l_keys_current_path_tl /._required_bool }
  }
}
%    \end{macrocode}
%\end{macro}
%\end{macro}
%
%\begin{macro}{.tl_set:N}
%\begin{macro}{.tl_set_x:N}
%\begin{macro}{.tl_gset:N}
%\begin{macro}{.tl_gset_x:N}
% Storage of the value in a tl, as given or expanded, local or global.
%    \begin{macrocode}
\keys_manage_quick:n {
  \c_keys_properties_path_tl /.tl_set:N/.code:n = {
    \keys_check_exists:NN #1 \tl_new:N
    \keys_set:NN \tl_set:Nn #1
  },
  \c_keys_properties_path_tl /.tl_set_x:N/.code:n = {
    \keys_check_exists:NN #1 \tl_new:N
    \keys_set:NN \tl_set:Nx #1
  },
  \c_keys_properties_path_tl /.tl_gset:N/.code:n = {
    \keys_check_exists:NN #1 \tl_new:N
    \keys_set:NN \tl_gset:Nn #1
  },
  \c_keys_properties_path_tl /.tl_gset_x:N/.code:n = {
    \keys_check_exists:NN #1 \tl_new:N
    \keys_set:NN \tl_gset:Nx #1
  }
}
%    \end{macrocode}
%\end{macro}
%\end{macro}
%\end{macro}
%\end{macro}
%
%\begin{macro}{.int_set:N}
%\begin{macro}{.int_gset:N}
%\begin{macro}{.skip_set:N}
%\begin{macro}{.skip_gset:N}
%\begin{macro}{.toks_set:N}
%\begin{macro}{.toks_gset:N}
% For int, skip and toks storage, no expansion to worry about.
%    \begin{macrocode}
\keys_manage_quick:n {
  \c_keys_properties_path_tl /.int_set:N/.code:n = {
    \keys_check_exists:NN #1 \int_new:N
    \keys_set:NN \int_set:Nn #1
  },
  \c_keys_properties_path_tl /.int_gset:N/.code:n = {
    \keys_check_exists:NN #1 \int_new:N
    \keys_set:NN \int_gset:Nn #1
  },
  \c_keys_properties_path_tl /.skip_set:N/.code:n = {
    \keys_check_exists:NN #1 \skip_new:N
    \keys_set:NN \skip_set:Nn #1
  },
  \c_keys_properties_path_tl /.skip_gset:N/.code:n = {
    \keys_check_exists:NN #1 \skip_new:N
    \keys_set:NN \skip_gset:Nn #1
  },
  \c_keys_properties_path_tl /.toks_set:N/.code:n = {
    \keys_check_exists:NN #1 \toks_new:N
    \keys_set:NN \toks_set:Nn #1
  },
  \c_keys_properties_path_tl /.toks_gset:N/.code:n = {
    \keys_check_exists:NN #1 \toks_new:N
    \keys_set:NN \toks_gset:Nn #1
  }
}
%    \end{macrocode}
%\end{macro}
%\end{macro}
%\end{macro}
%\end{macro}
%\end{macro}
%\end{macro}
%
% The prefix for the current module is needed when storing material
% by csname. 
%    \begin{macrocode}
\keys_manage_quick:n {
  \c_keys_utilities_path_tl /current_module:n/.code:n = {
    \tl_if_empty:nTF {#1} {
      \tl_clear:N \l_keys_current_module_tl
    }{
      \tl_set:Nn \l_keys_current_module_tl { #1 _ }
    }
  }
}
%    \end{macrocode}
%    
%\begin{macro}{.tl_set:n}
%\begin{macro}{.tl_set_x:n}
%\begin{macro}{.tl_gset:n}
%\begin{macro}{.tl_gset_x:n}
%\begin{macro}{.int_set:n}
%\begin{macro}{.int_gset:n}
%\begin{macro}{.skip_set:n}
%\begin{macro}{.skip_gset:n}
%\begin{macro}{.toks_set:n}
%\begin{macro}{.toks_gset:n}
% With the module available, storage properties that only need the 
% unique part of the variable name are created.
%    \begin{macrocode}
\keys_manage_quick:n {
  \c_keys_properties_path_tl /.tl_set:n/.code:n = {
    \keys_check_exists:cN { l_ #1 _tl } \tl_new:N
    \keys_set:Nnn \tl_set:cn { l_ } { #1 _tl }
  },
  \c_keys_properties_path_tl /.tl_set_x:n/.code:n = {
    \keys_check_exists:cN { l_ #1 _tl } \tl_new:N
    \keys_set:Nnn \tl_set:cx { l_ } { #1 _tl }
  },
  \c_keys_properties_path_tl /.tl_gset:n/.code:n = {
    \keys_check_exists:cN { g_ #1 _tl } \tl_new:N
    \keys_set:Nnn \tl_gset:cn { g_ } { #1 _tl }
  },
  \c_keys_properties_path_tl /.tl_gset_x:n/.code:n = {
    \keys_check_exists:cN { g_ #1 _tl } \tl_new:N
    \keys_set:Nnn \tl_gset:cx { g_ } { #1 _tl }
  },
  \c_keys_properties_path_tl /.int_set:n/.code:n = {
    \keys_check_exists:cN { l_ #1 _int } \int_new:N
    \keys_set:Nnn \int_set:cn { l_ } { #1 _int }
  },
  \c_keys_properties_path_tl /.int_gset:n/.code:n = {
    \keys_check_exists:cN { g_ #1 _int } \int_new:N
    \keys_set:Nnn \int_gset:cn { g_ } { #1 _int }
  },
  \c_keys_properties_path_tl /.skip_set:n/.code:n = {
    \keys_check_exists:cN { l_ #1 _skip } \skip_new:N
    \keys_set:Nnn \skip_set:cn { l_ } { #1 _skip }
  },
  \c_keys_properties_path_tl /.skip_gset:n/.code:n = {
    \keys_check_exists:cN { g_ #1 _skip } \skip_new:N
    \keys_set:Nnn \skip_gset:cn { g_ } { #1 _skip }
  },
  \c_keys_properties_path_tl /.toks_set:n/.code:n = {
   \keys_check_exists:cN { g_ #1 _toks } \toks_new:N
    \keys_set:Nnn \toks_set:cn { l_ } { #1 _toks }
  },
  \c_keys_properties_path_tl /.toks_gset:n/.code:n = {
    \keys_check_exists:cN { g_ #1 _toks } \toks_new:N
    \keys_set:Nnn \toks_gset:cn { g_ } { #1 _toks }
  },
}
%    \end{macrocode}
%\end{macro}
%\end{macro}
%\end{macro}
%\end{macro}
%\end{macro}
%\end{macro}
%\end{macro}
%\end{macro}
%\end{macro}
%\end{macro}
%
%\begin{macro}{.bool_set:N}
%\begin{macro}{.bool_gset:N}
%\begin{macro}{.bool_set:n}
%\begin{macro}{.bool_gset:n}
% The properties for switches look similar, although internally things
% are rather different.
%    \begin{macrocode}
\keys_manage_quick:n {
  \c_keys_properties_path_tl /.bool_set:N/.code:n = {
    \keys_bool_set:nN { set } #1
  },
  \c_keys_properties_path_tl /.bool_gset:N/.code:n = {
    \keys_bool_set:nN { gset } #1
  },
  \c_keys_properties_path_tl /.bool_set:n/.code:n = {
    \keys_bool_set:nnn { set } { l_ } { #1 }
  },
  \c_keys_properties_path_tl /.bool_gset:n/.code:n = {
    \keys_bool_set:nnn { gset } { g_ } { #1 }
  },
}
%    \end{macrocode}
%\end{macro}
%\end{macro}
%\end{macro}
%\end{macro}
%
%\begin{macro}{.bool_set_inverse:N}
%\begin{macro}{.bool_gset_inverse:N}
%\begin{macro}{.bool_set_inverse:n}
%\begin{macro}{.bool_gset_inverse:n}
% The inverse versions of the switches are handled in the same way
% here.
%    \begin{macrocode}
\keys_manage_quick:n {
  \c_keys_properties_path_tl /.bool_set_inverse:N/.code:n = {
    \keys_bool_set_inverse:nN { set } #1
  },
  \c_keys_properties_path_tl /.bool_gset_inverse:N/.code:n = {
    \keys_bool_set_inverse:nN { gset } #1
  },
  \c_keys_properties_path_tl /.bool_set_inverse:n/.code:n = {
    \keys_bool_set_inverse:nnn { set } { l_ } { #1 }
  },
  \c_keys_properties_path_tl /.bool_gset_inverse:n/.code:n = {
    \keys_bool_set_inverse:nnn { gset } { g_ } { #1 }
  },
}
%    \end{macrocode}
%\end{macro}
%\end{macro}
%\end{macro}
%\end{macro}
%
%\begin{macro}{.expects_choice:}
% Multiple choice keys are created by searching sub-keys. So the
% code to make a key into a multiple choice is quite simple.
%    \begin{macrocode}
\keys_manage_quick:n {
  \c_keys_properties_path_tl /.expects_choice:/.code:n = {
    \keys_manage_internal:n {
      \l_keys_current_path_tl /.cd:,
      .code:n = {
        \tl_set:Nn \l_keys_current_choice_tl {##1}
        \int_zero:N \l_keys_current_choice_int
        \exp_args:No \keys_parse_list:n 
          { \l_keys_current_key_full_tl / ##1 }
      },
      unknown/.code:n = {
        \keys_error:nn { unknown~choice } 
          { \l_keys_current_key_name_tl }
      }
    }
  },
}
%    \end{macrocode}
%\end{macro}
%\begin{macro}{.create_choices:nn}
%\begin{macro}{.create_choices:nx}
% Creating choices as a block.
%    \begin{macrocode}
\keys_manage_quick:n {
  \c_keys_properties_path_tl /.create_choices:nn/.code:Nn = 2 {
    \keys_choices_create:Nnn n {#1} {#2}
  },
  \c_keys_properties_path_tl /.create_choices:nx/.code:Nn = 2 {
    \keys_choices_create:Nnn x {#1} {#2}
  },
}
%    \end{macrocode}
%\end{macro}
%\end{macro}
%
%\begin{macro}{.use_keys:n}
%\begin{macro}{.use_keys:x}
%\begin{macro}{.use_keys:Nn}
%\begin{macro}{.use_keys:Nx}
% Keys calling other keys is actually quite easy.
%    \begin{macrocode}
\keys_manage_quick:n {
  \c_keys_properties_path_tl /.use_keys:n/.code:n = {
    \keys_manage_internal:n {
      \l_keys_current_path_tl /.code:n = { \keys_parse_list:n {#1} }
    }
  },
  \c_keys_properties_path_tl /.use_keys:x/.code:n = {
    \keys_manage_internal:n {
      \l_keys_current_path_tl /.code:x = {
        \exp_not:N \keys_parse_list:n {#1}
      }
    }
  },
  \c_keys_properties_path_tl /.use_keys:Nn/.code:Nn = 2 {
    \keys_manage_internal:n {
      \l_keys_current_path_tl /.code:Nn = #1 { \keys_parse_list:n {#2} }
    }
  },
  \c_keys_properties_path_tl /.use_keys:Nx/.code:Nn = 2 {
    \keys_manage_internal:n {
      \l_keys_current_path_tl /.code:Nx =
        #1 { \exp_not:N \keys_parse_list:n {#2} }
    }
  }
}
%    \end{macrocode}
%\end{macro}
%\end{macro}
%\end{macro}
%\end{macro}
%
%\begin{macro}{.try:n}
%\begin{macro}{.retry:n}
% For attempting to set keys without assuming they exist.
%    \begin{macrocode}
\keys_manage_quick:n {
  \c_keys_properties_path_tl /.try:n/.code:n = { \keys_try: },
  \c_keys_properties_path_tl /.retry:n/.code:n = {
    \bool_if:NF \l_keys_success_bool { \keys_try: }
  }
}
%    \end{macrocode}
%\end{macro}
%\end{macro}
%
%\begin{macro}{.show_code:}
%\begin{macro}{.show_key:}
% Finally, two keys for debugging problems.
%    \begin{macrocode}
\keys_manage_quick:n {
  \c_keys_properties_path_tl /.show_code:/.code:n = {
    \cs_show:c { 
      \c_keys_cs_prefix_tl \l_keys_current_path_tl /._cmd:w 
    }
  },
  \c_keys_properties_path_tl /.show_key:/.code:n = {
    \cs_show:c { \c_keys_cs_prefix_tl \l_keys_current_path_tl }
  }
}
%</package>
%    \end{macrocode}
%\end{macro}
%\end{macro}
%
% \end{implementation}