summaryrefslogtreecommitdiff
path: root/macros/generic/expkv/expkv.dtx
blob: 3cd8479be5641919449b2ecdea1a4f9462868a30 (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
% \iffalse meta-comment
%
% File: expkv.dtx Copyright (C) 2020 Jonathan P. Spratte
%
% This work  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
%
% ------------------------------------------------------------------------------
%
%<*driver>^^A>>=
\def\nameofplainTeX{plain}
\ifx\fmtname\nameofplainTeX\else
  \expandafter\begingroup
\fi
\input l3docstrip.tex
\askforoverwritefalse
\preamble

--------------------------------------------------------------
expkv -- an expandable key=val implementation
E-mail: jspratte@yahoo.de
Released under the LaTeX Project Public License v1.3c or later
See http://www.latex-project.org/lppl.txt
--------------------------------------------------------------

Copyright (C) 2020 Jonathan P. Spratte

This  work 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
  Jonathan P. Spratte.

This work consists of the file  expkv.dtx
and the derived files           expkv.pdf
                                expkv.sty
                                expkv.tex

\endpreamble
% stop docstrip adding \endinput
\postamble
\endpostamble
\generate{\file{expkv.sty}{\from{expkv.dtx}{pkg}}}
\generate{\file{expkv.tex}{\from{expkv.dtx}{tex}}}
\ifx\fmtname\nameofplainTeX
  \expandafter\endbatchfile
\else
  \expandafter\endgroup
\fi
%
\IfFileExists{expkv.tex}{\input{expkv.tex}}{}
\ProvidesFile{expkv.dtx}
  [\csname ekvDate\endcsname\ an expandable key=val implementation]
\PassOptionsToPackage{full}{textcomp}
\documentclass{l3doc}
\RequirePackage[oldstylenums,nott]{kpfonts}
\input{glyphtounicode}
\pdfgentounicode=1
\RequirePackage{xfp} ^^A required for an example
\RequirePackage{listings}
\RequirePackage{booktabs}
\RequirePackage{array}
\RequirePackage{collcell}
\RequirePackage{siunitx}
\DeclareSIUnit\ops{ops}
\RequirePackage{xcolor}
\RequirePackage{caption}
\RequirePackage{microtype}
\RequirePackage{accsupp}
\RequirePackage{enumitem}
\lstset
  {
    ,flexiblecolumns=false
    ,basewidth=.53em
    ,gobble=2
    ,basicstyle=\fontfamily{jkp}\itshape
    ,morekeywords=^^A
      {^^A
        \ekvdef,\ekvdefNoVal,\ekvlet,\ekvletNoVal,\ekvletkv,\ekvletkvNoVal,^^A
        \ekvset,\ekvparse,\ekvVersion,\ekvDate,\ekvifdefined,^^A
        \ekvifdefinedNoVal,\ekvbreak,\ekvbreakPreSneak,\ekvbreakPostSneak,^^A
        \ekvsneak,\ekvsneakPre,\ekvchangeset
      }
    ,morecomment=[l]\%
    ,commentstyle=\color[gray]{0.4}
    ,literate={\{}{{\CodeSymbol\{}}{1}
              {\}}{{\CodeSymbol\}}}{1}
    ^^A,literate=*{<key>}{\key}{4}{<set>}{\set}{4}
  }
\newcommand*\CodeSymbol[1]{\textbf{#1}}
\RequirePackage{randtext}
\let\metaORIG\meta
\protected\def\meta #1{\texttt{\metaORIG{#1}}}
\renewcommand*\thefootnote{\fnsymbol{footnote}}
\definecolor{expkvred}{HTML}{9F393D}
\colorlet{expkvgrey}{black!75}
\makeatletter
\newcommand*\expFormat
  {^^A
    {^^A
      \rmfamily
      \bfseries
      {\color{expkvgrey}e\kern-.05em x\kern-.05em}^^A
      \lower.493ex\hbox{{\color{expkvgrey}P}}^^A
    }^^A
  }
\newcommand*\kvstyle
  {^^A
    \normalfont\rmfamily\bfseries\color{expkvred}^^A
  }
\newcommand*\expkv
  {^^A
    \texorpdfstring
      {^^A
        \mbox
          {^^A
            \BeginAccSupp{ActualText=expkv}^^A
            \href{https://github.com/Skillmon/tex_expkv}
              {^^A
                \rmfamily
                \bfseries
                {\color{expkvgrey}e\kern-.05em x\kern-.05em}^^A
                \lower.493ex
                  \hbox{{\color{expkvgrey}P}\kern-.1em{\color{expkvred}k}}^^A
                \kern-.18em{\color{expkvred}v}^^A
              }^^A
            \EndAccSupp{}^^A
          }^^A
      }
      {expkv}^^A
  }
\newcommand*\expkvpkg[1]
  {^^A
    \texorpdfstring
      {^^A
        \mbox
          {^^A
            \BeginAccSupp{ActualText=expkv-#1}^^A
            \href{https://github.com/Skillmon/tex_expkv-#1}
              {^^A
                \rmfamily
                \bfseries
                {\color{expkvgrey}e\kern-.05em x\kern-.05em}^^A
                \lower.493ex
                  \hbox{{\color{expkvgrey}P}\kern-.1em{\color{expkvred}k}}^^A
                \kern-.18em{\color{expkvred}v}^^A
                {\color{expkvgrey}^^A
                  \kern.05em\rule[-.1ex]{.08em}{1.2ex}\kern.05em\textsc{#1}^^A
                }^^A
              }^^A
            \EndAccSupp{}^^A
          }^^A
      }
      {expkv-#1}^^A
  }
\newcommand*\expkvd{\expkvpkg{def}}
\newcommand*\expkvc{\expkvpkg{cs}}
\newcommand*\expkvo{\expkvpkg{opt}}
\newcommand\kv{\meta{key}=\meta{value}}
\newcommand\key{\meta{key}}
\newcommand\val{\meta{value}}
\newcommand\set{\meta{set}}
\hypersetup{linkcolor=red!80!black,urlcolor=purple!80!black}
\DoNotIndex{\def,\edef,\,,\=,\begingroup,\catcode,\chardef,\csname,\endcsname}
\DoNotIndex{\endgroup,\endinput,\errmessage,\expandafter,\input,\let,\long}
\DoNotIndex{\protected,\ProvidesFile,\ProvidesPackage,\relax,\space}
\DoNotIndex{\@,\unexpanded,\string,\expanded,\detokenize,\meaning,\lastnamedcs}
\DoNotIndex{\ifcsname}
\DoNotIndex{\ifx}
\DoNotIndex{\else}
\DoNotIndex{\fi}
\@gobble\fi ^^A ignoring \ifx and \ifcsname, but only one \fi
\@ifdefinable\gobbledocstriptag{\def\gobbledocstriptag#1>{}}
\newcommand*\pmso[1] ^^A poor man's strike out
  {^^A
    \leavevmode
    \begingroup
      \sbox0{#1}^^A
      \rlap{\vrule height .6ex depth -.5ex width \wd0\relax}^^A
      \usebox0\relax
    \endgroup
  }
\makeatother
\begin{document}
  \title
    {^^A
      \texorpdfstring
        {^^A
          \huge\expkv
          \\[\medskipamount]
          \Large an {\expFormat}andable
          \meta{{\kvstyle k}\kern-.05em ey}=^^A
          \meta{{\kvstyle v}\kern-.05em alue}
          implementation^^A
        }{expkv - an expandable <key>=<value> implementation}^^A
    }
  \date{\ekvDate\space v\ekvVersion}
  \author{Jonathan P. Spratte\thanks{\protect\randomize{jspratte@yahoo.de}}}
  \DocInput{expkv.dtx}
\end{document}
%</driver>^^A=<<
% \fi
%
% \maketitle
% \renewcommand*\thefootnote{\arabic{footnote}}
%
% \begin{abstract}
% \noindent\parfillskip=0pt
% \expkv\ provides a small interface for \kv\ parsing. The parsing macro is
% \emph{fully expandable}, the \meta{code} of your keys might be not. \expkv\ is
% \emph{swift}, close to the fastest \kv\ implementation. However it is the
% fastest which copes with active commas and equal signs and doesn't strip
% braces accidentally.
% \end{abstract}
%
% \tableofcontents
%
% \begin{documentation}^^A>>=
%
% \section{Documentation}
%
% \expkv\ provides an expandable \kv\ parser. The \kv\ pairs should be given as
% a comma separated list and the separator between a \key\ and the associated
% \val\ should be an equal sign. Both, the commas and the equal signs, might be
% of category 12 (other) or 13 (active). To support this is necessary as for
% example \pkg{babel} turns characters active for some languages, for instance
% the equal sign is turned active for Turkish.
%
% \expkv\ is usable as generic code or as a \LaTeX\ package. To use it, just
% use one of:
% \begin{lstlisting}
% \usepackage{expkv} % LaTeX
% \input expkv       % plainTeX
% \end{lstlisting}
% The \LaTeX\ package doesn't do more than \file{expkv.tex}, except calling
% |\ProvidesPackage| and setting things up such that \file{expkv.tex} will use
% |\ProvidesFile|.
%
% In the \expkv\ family are other packages contained which provide additional
% functionality. Those packages currently are:
% \begin{description}[format=\expkvpkg]
%   \item[def]
%     a key-defining frontend for \expkv\ using a \kv\ syntax
%   \item[cs]
%     define expandable \kv\ macros using \expkv
%   \item[opt]
%     parse package and class options with \expkv
% \end{description}
% Note that while the package names are stylised with a vertical rule, their
% names are all lower case with a hyphen (\emph{e.g.}, \file{expkv-def}).
%
% \subsection{Setting up Keys}\label{sec:define}
% \expkv\ provides a rather simple approach to setting up keys, similar to
% \pkg{keyval}. However there is an auxiliary package named \expkvd\ which
% provides a more sophisticated interface, similar to well established packages
% like \pkg{pgfkeys} or \pkg{l3keys}.
%
% Keys in \expkv\ (as in almost all other \kv\ implementations) belong to a
% \emph{set} such that different sets can contain keys of the same name. Unlike
% many other implementations \expkv\ doesn't provide means to set a default
% value, instead we have keys that take values and keys that don't (the latter
% are called |NoVal| keys by \expkv), but both can have the same name (on the
% user level).
%
% The following macros are available to define new keys. Those macros containing
% ``|def|'' in their name can be prefixed by anything allowed to prefix |\def|
% (but \emph{don't} use |\outer|, keys defined with it won't ever be usable),
% prefixes allowed for |\let| can prefix those with ``|let|'' in their name,
% accordingly. Neither \set\ nor \key\ are allowed to be empty for new keys.
% \set\ will be used as is inside of |\csname ...\endcsname| and \key\ will get
% |\detokenize|d.
%
% \begin{function}{\ekvdef}
%   \begin{syntax}
%     \cs{ekvdef}\marg{set}\marg{key}\marg{code}
%   \end{syntax}
%   Defines a \key\ taking a value in a \set\ to expand to \meta{code}. In
%   \meta{code} you can use |#1| to refer to the given value.
% \end{function}
%
% \begin{function}{\ekvdefNoVal}
%   \begin{syntax}
%     \cs{ekvdefNoVal}\marg{set}\marg{key}\marg{code}
%   \end{syntax}
%   Defines a no value taking \key\ in a \set\ to expand to \meta{code}.
% \end{function}
%
% \begin{function}{\ekvlet}
%   \begin{syntax}
%     \cs{ekvlet}\marg{set}\marg{key}\meta{cs}
%   \end{syntax}
%   Let the value taking \key\ in \set\ to \meta{cs}, there are no checks on
%   \meta{cs} enforced.
% \end{function}
%
% \begin{function}{\ekvletNoVal}
%   \begin{syntax}
%     \cs{ekvletNoVal}\marg{set}\marg{key}\meta{cs}
%   \end{syntax}
%   Let the no value taking \key\ in \set\ to \meta{cs}, it is not checked
%   whether \meta{cs} exists or that it takes no parameter.
% \end{function}
%
% \begin{function}{\ekvletkv}
%   \begin{syntax}
%     \cs{ekvletkv}\marg{set}\marg{key}\marg{set2}\marg{key2}
%   \end{syntax}
%   Let the \key\ in \set\ to \meta{key2} in \meta{set2}, it is not checked
%   whether that second key exists (but take a look at
%   \cs[no-index]{ekvifdefined}).
% \end{function}
%
% \begin{function}{\ekvletkvNoVal}
%   \begin{syntax}
%     \cs{ekvletkvNoVal}\marg{set}\marg{key}\marg{set2}\marg{key2}
%   \end{syntax}
%   Let the \key\ in \set\ to \meta{key2} in \meta{set2}, it is not checked
%   whether that second key exists (but take a look at
%   \cs[no-index]{ekvifdefinedNoVal}).
% \end{function}
%
% \begin{function}{\ekvdefunknown}
%   \begin{syntax}
%     \cs{ekvdefunknown}\marg{set}\marg{code}
%   \end{syntax}
%   By default an error will be thrown if an unknown \key\ is encountered. With
%   this macro you can define \meta{code} that will be executed for a given
%   \set\ when an unknown \key\ with a \val\ was encountered instead of throwing
%   an error. You can refer to the given \val\ with |#1| and to the unknown
%   \key's name with |#2| in \meta{code}.\footnotemark
% \end{function}
% \footnotetext{That order is correct, this way the code is faster.}
%
% \begin{function}{\ekvdefunknownNoVal}
%   \begin{syntax}
%     \cs{ekvdefunknownNoVal}\marg{set}\marg{code}
%   \end{syntax}
%   As already explained for \cs[no-index]{ekvdefunknown}, \expkv\ would throw
%   an error when encountering an unknown \key. With this you can instead let it
%   execute \meta{code} if an unknown |NoVal| \key\ was encountered. You can
%   refer to the given \key\ with |#1| in \meta{code}.
% \end{function}
%
% \subsection{Parsing Keys}
%
% \begin{function}{\ekvset}
%   \begin{syntax}
%     \cs{ekvset}\marg{set}\{\kv,\ldots\}
%   \end{syntax}
%   Splits \kv\ pairs on commas. From both \key\ and \val\ up to one space is
%   stripped from both ends, if then only a braced group remains the braces are
%   stripped as well. So |\ekvset{foo}{bar=baz}| and
%   |\ekvset{foo}{ {bar}= {baz} }| will both do
%   \texttt{\cs[no-index]{\meta{foobarcode}}\{baz\}}, so you can hide commas,
%   equal signs and spaces at the ends of either \key\ or \val\ by putting
%   braces around them. If you omit the equal sign the code of the key created
%   with the |NoVal| variants described in \autoref{sec:define} will be
%   executed. If \kv\ contains more than a single unhidden equal sign, it will
%   be split at the first one and the others are considered part of the value.
%   |\ekvset| should be nestable.
% \end{function}
%
% \begin{function}{\ekvsetSneaked}
%   \begin{syntax}
%     \cs{ekvsetSneaked}\marg{set}\marg{sneak}\{\kv,\ldots\}
%   \end{syntax}
%   Just like \cs[no-index]{ekvset}, this macro parses the \kv\ pairs within the
%   given \set. But \cs[no-index]{ekvsetSneaked} will behave as if
%   \cs[no-index]{ekvsneak} has been called with \meta{sneak} as its argument as
%   the first action.
% \end{function}
%
% \begin{function}{\ekvsetdef}
%   \begin{syntax}
%     \cs{ekvsetdef}\meta{cs}\marg{set}
%   \end{syntax}
%   With this function you can define a shorthand macro \meta{cs} to parse keys
%   of a specified \set. It is always defined |\long|, but if you need to you
%   can also prefix it with |\global|. The resulting macro is faster than but
%   else equivalent to the idiomatic definition:\par
%   \texttt
%     {\string\long\string\def\meta{cs}\#1\{\string\ekvset\marg{set}\{\#1\}\}}
% \end{function}
%
% \begin{function}{\ekvsetSneakeddef}
%   \begin{syntax}
%     \cs{ekvsetSneakeddef}\meta{cs}\marg{set}
%   \end{syntax}
%   Just like \cs[no-index]{ekvsetdef} this defines a shorthand macro \meta{cs},
%   but this macro will make it a shorthand for \cs[no-index]{ekvsetSneaked},
%   meaning that \meta{cs} will take two arguments, the first being stuff that
%   should be given to \cs[no-index]{ekvsneak} and the second the \kv\ list. The
%   resulting macro is faster than but else equivalent to the idiomatic
%   definition:\par
%   \texttt
%     {%
%       \string\long\string\def\meta{cs}\#1\#2\{^^A
%       \string\ekvsetSneaked\marg{set}\{\#1\}\{\#2\}\}^^A
%     }
% \end{function}
%
% \begin{function}{\ekvsetdefSneaked}
%   \begin{syntax}
%     \cs{ekvsetSneakeddef}\meta{cs}\marg{set}\marg{sneaked}
%   \end{syntax}
%   And this one behaves like \cs[no-index]{ekvsetSneakeddef} but with a fixed
%   \meta{sneaked} argument. So the resulting macro is faster than but else
%   equivalent to the idiomatic definition:\par
%   \texttt
%     {%
%       \string\long\string\def\meta{cs}\#1\{^^A
%       \string\ekvsetSneaked\marg{set}\marg{sneaked}\{\#1\}\}^^A
%     }
% \end{function}
%
% \begin{function}{\ekvparse}
%   \begin{syntax}
%     \cs{ekvparse}\meta{cs1}\meta{cs2}\{\kv,\ldots\}
%   \end{syntax}
%   This macro parses the \kv\ pairs and provides those list elements which are
%   only keys as the argument to \meta{cs1}, and those which are a \kv\ pair to
%   \meta{cs2} as two arguments. It is fully expandable as well and returns the
%   parsed list in |\unexpanded|, which has no effect outside of an |\expanded|
%   or |\edef| context\footnotemark.
%   If you need control over the necessary steps of expansion you
%   can use |\expanded| around it.
%
%   |\ekvbreak|, |\ekvsneak|, and |\ekvchangeset| and their relatives don't work
%   in |\ekvparse|.  It is analogue to \pkg{expl3}'s |\keyval_parse:NNn|, but
%   not with the same parsing rules -- |\keyval_parse:NNn| throws an error on
%   multiple equal signs per \kv\ pair and on empty \key\ names in a \kv\ pair,
%   both of which |\ekvparse| doesn't deal with.
%
%   As a small example:
% \begin{lstlisting}
% \ekvparse\handlekey\handlekeyval{foo = bar, key, baz={zzz}}
% \end{lstlisting}
%   would expand to
% \begin{lstlisting}
% \handlekeyval{foo}{bar}\handlekey{key}\handlekeyval{baz}{zzz}
% \end{lstlisting}
%   and afterwards |\handlekey| and |\handlekeyval| would have to further handle
%   the \key. There are no macros like these two contained in \expkv, you have
%   to set them up yourself if you want to use |\ekvparse| (of course the names
%   might differ). If you need the results of |\ekvparse| as the argument for
%   another macro, you should use |\expanded| as only then the input stream will
%   contain the output above:
% \begin{lstlisting}
% \expandafter\handle\expanded{\ekvparse\k\kv{foo = bar, key, baz={zzz}}}
% \end{lstlisting}
%   would expand to
% \begin{lstlisting}
% \handle\kv{foo}{bar}\k{key}\kv{baz}{zzz}
% \end{lstlisting}
% \end{function}
% \footnotetext 
%   {^^A
%     This is a change in behaviour, previously (v0.3 and before) \cs{ekvparse}
%     would expand in exactly two steps. This isn't always necessary, but makes
%     the parsing considerably slower. If this is necessary for your application
%     you can put an \cs[no-index]{expanded} around it and will still be faster
%     since you need only a single \cs[no-index]{expandafter} this way.^^A
%   }.
%
% \subsection{Miscellaneous}
%
% \subsubsection{Other Macros}
%
% \expkv\ provides some other macros which might be of interest.
%
% \begin{function}{\ekvVersion,\ekvDate}
%   These two macros store the version and date of the package.
% \end{function}
% \begin{function}{\ekvifdefined,\ekvifdefinedNoVal}
%   \begin{syntax}
%     \cs{ekvifdefined}\marg{set}\marg{key}\marg{true}\marg{false}
%     \cs{ekvifdefinedNoVal}\marg{set}\marg{key}\marg{true}\marg{false}
%   \end{syntax}
%   These two macros test whether there is a \key\ in \set. It is false if
%   either a hash table entry doesn't exist for that key or its meaning is
%   |\relax|.
% \end{function}
%
% \begin{function}{\ekvifdefinedset}
%   \begin{syntax}
%     \cs{ekvifdefinedset}\marg{set}\marg{true}\marg{false}
%   \end{syntax}
%   This macro tests whether \set\ is defined (which it is if at least one key
%   was defined for it). If it is \meta{true} will be run, else \meta{false}.
% \end{function}
%
% \begin{function}{\ekvbreak,\ekvbreakPreSneak,\ekvbreakPostSneak}
%   \begin{syntax}
%     \cs{ekvbreak}\marg{after}
%   \end{syntax}
%   Gobbles the remainder of the current |\ekvset| macro and its argument list
%   and reinserts \meta{after}. So this can be used to break out of |\ekvset|.
%   The first variant will also gobble anything that has been sneaked out using
%   |\ekvsneak| or |\ekvsneakPre|, while |\ekvbreakPreSneak| will put
%   \meta{after} before anything that has been smuggled and |\ekvbreakPostSneak|
%   will put \meta{after} after the stuff that has been sneaked out.
% \end{function}
%
% \begin{function}{\ekvsneak,\ekvsneakPre}
%   \begin{syntax}
%     \cs{ekvsneak}\marg{after}
%   \end{syntax}
%   Puts \meta{after} after the effects of |\ekvset|. The first variant will put
%   \meta{after} after any other tokens which might have been sneaked before,
%   while |\ekvsneakPre| will put \meta{after} before other smuggled stuff.
%   This reads and reinserts the remainder of the current |\ekvset| macro and
%   its argument list to do its job. After |\ekvset| has parsed the entire \kv\
%   list everything that has been |\ekvsneak|ed will be left in the input
%   stream. A small usage example is shown in \autoref{sec:sneakex}.
% \end{function}
%
% \begin{function}{\ekvchangeset}
%   \begin{syntax}
%     \cs{ekvchangeset}\marg{new-set}
%   \end{syntax}
%   Replaces the current set with \meta{new-set}, so for the rest of the current
%   |\ekvset| call, that call behaves as if it was called with
%   \texttt{\cs[no-index]{ekvset}\marg{new-set}}. Just like |\ekvsneak| this
%   reads and reinserts the remainder of the current |\ekvset| macro to do its
%   job. It is comparable to using \texttt{\meta{key}/.cd} in \pkg{pgfkeys}.
% \end{function}
%
% \bigskip
%
% \begin{function}{\ekv@name,\ekv@name@set,\ekv@name@key}
%   \begin{syntax}
%     \cs{ekv@name}\marg{set}\marg{key}\\
%     \cs{ekv@name@set}\marg{set}\\
%     \cs{ekv@name@key}\marg{key}
%   \end{syntax}
%   The names of the macros that correspond to a key in a set are build with
%   these macros. The name is built from two blocks, one that is formatting the
%   \set\ name (|\ekv@name@set|) and one for formatting the \key\ name
%   (|\ekv@name@key|). To get the actual name the argument to |\ekv@name@key|
%   must be |\detokenize|d. Both blocks are put together (with the necessary
%   |\detokenize|) by |\ekv@name|.
%   For |NoVal| keys an additional |N| gets appended irrespective of these
%   macros' definition, so their name is
%   \texttt{\cs[no-index]{ekv@name}\marg{set}\marg{key}N}.\par
%   You can use these macros to implement additional functionality or access key
%   macros outside of \expkv, but \emph{don't} change them! \expkv\ relies on
%   their exact definitions internally.
% \end{function}
%
% \subsubsection{Bugs}
%
% Just like \pkg{keyval}, \expkv\ is bug free. But if you find \pmso{bugs}hidden
% features\footnote{Thanks, David!} you can tell me about them either via mail
% (see the first page) or directly on GitHub if you have an account there:
% \url{https://github.com/Skillmon/tex_expkv}
%
% \subsubsection{Comparisons}
%
% Comparisons of speed are done with a very simple test key and the help of the
% \pkg{l3benchmark} package. The key and its usage should be equivalent to
% \begin{lstlisting}
% \protected\ekvdef{test}{height}{\def\myheight{#1}}
% \ekvsetdef\expkvtest{test}
% \expkvtest{ height = 6 }
% \end{lstlisting}
% and only the usage of the key, not its definition, is benchmarked. For the
% impatient, the essence of these comparisons regarding speed and buggy
% behaviour is contained in \autoref{tab:comp}.
%
% As far as I know \expkv\ is the only fully expandable \kv\ parser. I tried to
% compare \expkv\ to every \kv\ package listed on
% \href{https://ctan.org/topic/keyval}{CTAN}, however, one might notice that
% some of those are missing from this list. That's because I didn't get the
% others to work due to bugs, or because they just provide wrappers around other
% packages in this list.
%
% In this subsubsection is no benchmark of |\ekvparse| and |\keyval_parse:NNn|
% contained, as most other packages don't provide equivalent features to my
% knowledge. |\ekvparse| is slightly faster than |\ekvset|, but keep in mind
% that it does less. The same is true for |\keyval_parse:NNn| compared to
% |\keys_set:nn| of \pkg{expl3} (where the difference is much bigger). Comparing
% just the two, |\ekvparse| is a tad faster than |\keyval_parse:NNn| because of
% the two tests (for empty key names and only a single equal sign) which are
% omitted.
%
% \paragraph{\pkg{keyval}} is about \SIrange{30}{40}{\percent} faster and has a
% comparable feature set just a slightly different way how it handles keys
% without values.  That might be considered a drawback, as it limits the
% versatility, but also as an advantage, as it might reduce doubled code. Keep
% in mind that as soon as someone loads \pkg{xkeyval} the performance of
% \pkg{keyval} gets replaced by \pkg{xkeyval}'s.
%
% Also \pkg{keyval} has a bug, which unfortunately can't really be resolved
% without breaking backwards compatibility for \emph{many} documents, namely it
% strips braces from the argument before stripping spaces if the argument isn't
% surrounded by spaces, also it might strip more than one set of braces. Hence
% all of the following are equivalent in their outcome, though the last two
% lines should result in something different than the first two:
% \begin{lstlisting}[belowskip=0pt]
% \setkeys{foo}{bar=baz}
% \setkeys{foo}{bar= {baz}}
% \setkeys{foo}{bar={ baz}}  % should be ` baz'
% \setkeys{foo}{bar={{baz}}} % should be `{baz}'
% \end{lstlisting}
%
% \paragraph{\pkg{xkeyval}} is roughly twenty times slower, but it provides more
% functionality, e.g., it has choice keys, boolean keys, and so on. It contains
% the same bug as \pkg{keyval} as it has to be compatible with it by design (it
% replaces \pkg{keyval}'s frontend), but also adds even more cases in which
% braces are stripped that shouldn't be stripped, worsening the situation.
%
% \paragraph{\pkg{ltxkeys}} is no longer compatible with the \LaTeX\ kernel
% starting with the release 2020-10-01. It is over 380 times slower -- which is
% funny, because it aims to be ``[\ldots] faster [\ldots] than these earlier
% packages [referring to \pkg{keyval} and \pkg{xkeyval}].'' It needs more time
% to parse zero~keys than five of the packages in this comparison need to parse
% 100~keys.  Since it aims to have a bigger feature set than \pkg{xkeyval}, it
% most definitely also has a bigger feature set than \expkv.  Also, it can't
% parse |\long| input, so as soon as your values contain a |\par|, it'll throw
% errors.  Furthermore, \pkg{ltxkeys} doesn't strip outer braces at all by
% design, which, imho, is a weird design choice. In addition \pkg{ltxkeys} loads
% \pkg{catoptions} which is known to introduce bugs (e.g., see
% \url{https://tex.stackexchange.com/questions/461783}). Because it is no longer
% compatible with the kernel, I stop benchmarking it (so the numbers listed here
% and in \autoref{tab:comp} regarding \pkg{ltxkeys} were last updated on
% 2020-10-05).
%
% \paragraph{\pkg{l3keys}} is around four and a half times slower, but has an,
% imho, great interface to define keys. It strips \emph{all} outer spaces, even
% if somehow multiple spaces ended up on either end. It offers more features,
% but is pretty much bound to \pkg{expl3} code. Whether that's a drawback is up
% to you.
%
% \paragraph{\pkg{pgfkeys}} is around \num{2.7} times slower for one key if one
% uses the |/|\meta{path}|/.cd| syntax and almost \SI{20}{\percent} slower if
% one uses |\pgfqkeys|, but has an \emph{enormous} feature set.
% To get the best performance |\pgfqkeys| was used in the benchmark. This
% reduces the overhead for setting the base directory of the benchmark keys by
% about \SI{43}{\ops} (so both $p_0$ and $T_0$ would be about \SI{43}{\ops}
% bigger if |\pgfkeys{|\meta{path}|/.cd,|\meta{keys}|}| was used instead).
% It has the same or a very similar bug \pkg{keyval} has. The brace bug (and
% also the category fragility) can be fixed by \pkg{pgfkeyx}, but this package
% was last updated in 2012 and it slows down |\pgfkeys| by factor~\num{8}. Also
% \pkg{pgfkeyx} is no longer compatible with versions of \pkg{pgfkeys} newer
% than 2020-05-25.
%
% \paragraph{\pkg{kvsetkeys} with \pkg{kvdefinekeys}} is about \num{4.4} times
% slower, but it works even if commas and equals have category codes different
% from 12 (just as some other packages in this list). Else the features of the
% keys are equal to those of \pkg{keyval}, the parser has more features, though.
%
% \paragraph{\pkg{options}} is \num{1.7} times slower for only a single value.
% It has a much bigger feature set. Unfortunately it also suffers from the
% premature unbracing bug \pkg{keyval} has.
%
% \paragraph{\pkg{simplekv}} is hard to compare because I don't speak French (so
% I don't understand the documentation). There was an update released on
% 2020-04-27 which greatly improved the package's performance and adds
% functionality so that it can be used more like most of the other \kv\
% packages. It has problems with stripping braces and spaces in a hard to
% predict manner just like \pkg{keyval}. Also, while it tries to be robust
% against category code changes of commas and equal signs, the used mechanism
% fails if the \kv\ list already got tokenised. Regarding unknown keys it got a
% very interesting behaviour. It doesn't throw an error, but stores the \val\ in
% a new entry accessible with \cs[no-index]{useKV}. Also if you omit \val\ it
% stores |true| for that \key. For up to three keys, \expkv\ is a bit faster,
% for more keys \pkg{simplekv} takes the lead.
%
% \paragraph{\pkg{yax}} is over twenty times slower. It has a pretty strange
% syntax, imho, and again a direct equivalent is hard to define. It has the
% premature unbracing bug, too. Also somehow loading \pkg{yax} broke
% \pkg{options} for me. The tested definition was:
% \begin{lstlisting}[belowskip=0pt]
% \usepackage{yax}
% \defactiveparameter yax {\storevalue\myheight yax:height } % key setup
% \setparameterlist{yax}{ height = 6 }                       % benchmarked
% \end{lstlisting}
%
% \begin{table}
%   \def\fnsym{\textcolor{red!80!black}{*}}%
%   \sisetup{round-precision=1, round-mode=places}%
%   \begingroup
%   \centering
%   \newcommand*\yes{\textcolor{red!80!black}  {yes}}^^A
%   \newcommand*\no {\textcolor{green!80!black}{no}}^^A
%   \caption[Comparison of \kv\ packages]
%     {^^A
%       Comparison of \kv\ packages. The packages are ordered from
%       fastest to slowest for one \kv\ pair. Benchmarking was done using
%       \pkg{l3benchmark} and the scripts in the \file{Benchmarks} folder
%       of the \href{https://github.com/Skillmon/tex_expkv}{git repository}.
%       The columns $p_i$ are the polynomial coefficients of a linear fit to the
%       run-time, $p_0$ can be interpreted as the overhead for initialisation
%       and $p_1$ the cost per key. The $T_0$ column is the actual mean ops
%       needed for an empty list argument, as the linear fit doesn't match that
%       point well in general. The column ``BB'' lists whether the
%       parsing is affected by some sort of brace bug, ``CF'' stands for
%       category code fragile and lists whether the parsing breaks with active
%       commas or equal signs.^^A
%       \label{tab:comp}^^A
%     }
%   \begin{tabular}
%       {>{\collectcell\pkg}l<{\endcollectcell}*3{S[table-format=4.1]}ccc}
%     \toprule
%     \rmfamily Package & {$p_1$} & {$p_0$} & {$T_0$}& BB & CF & Date \\
%     \midrule
%     keyval    &   13.742 &    1.486 &    7.254 & \yes & \yes & 2014-10-28 \\
%     \expkv    &   19.701 &    2.169 &    6.592 & \no  & \no  & 2020-10-10 \\
%     simplekv  &   18.334 &    6.971 &   17.710 & \yes & \yes & 2020-04-27 \\
%     pgfkeys   &   24.274 &    1.725 &   10.650 & \yes & \yes & 2020-09-05 \\
%     options   &   23.600 &   15.638 &   20.830 & \yes & \yes & 2015-03-01 \\
%     kvsetkeys & {\fnsym} & {\fnsym} &   40.290 & \no  & \no  & 2019-12-15 \\
%     l3keys    &   71.309 &   33.131 &   31.590 & \no  & \no  & 2020-09-24 \\
%     xkeyval   &  253.563 &  202.246 &  168.300 & \yes & \yes & 2014-12-03 \\
%     yax       &  421.853 &  157.003 &  114.700 & \yes & \yes & 2010-01-22 \\
%     ltxkeys   & 3400.142 & 4737.958 & 5368.000 & \no  & \no  & 2012-11-17 \\
%     \bottomrule
%   \end{tabular}
%   \par
%   \endgroup
%   \medskip
%   \fnsym For \pkg{kvsetkeys} the linear model used for the other
%   packages is a poor fit, \pkg{kvsetkeys} seems to have approximately
%   quadratic run-time, the coefficients of the second degree polynomial fit are
%   $p_2=\num{8.240}$, $p_1=\num{44.862}$, and $p_0=\num{60.793}$. Of course the
%   other packages might not really have linear run-time, but at least from 1~to
%   20~keys the fits don't seem too bad. If one extrapolates the fits for 100
%   \kv\ pairs one finds that most of them match pretty well, the exception
%   being \pkg{ltxkeys}, which behaves quadratic as well with
%   $p_2=\num{23.500}$, $p_1=\num{2906.634}$, and $p_0=\num{6547.489}$.
% \end{table}
%
% \subsection{Examples}
%
% \subsubsection{Standard Use-Case}
%
% Say we have a macro for which we want to create a \kv\ interface. The macro
% has a parameter, which is stored in the dimension |\ourdim| having a default
% value from its initialisation. Now we want to be able to change that dimension
% with the |width| key to some specified value. For that we'd do
% \begin{lstlisting}
% \newdimen\ourdim
% \ourdim=150pt
% \protected\ekvdef{our}{width}{\ourdim=#1\relax}
% \end{lstlisting}
% as you can see, we use the set |our| here. We want the key to behave different
% if no value is specified. In that case the key should not use its initial
% value, but be smart and determine the available space from
% \cs[no-index]{hsize}, so we also define
% \begin{lstlisting}
% \protected\ekvdefNoVal{our}{width}{\ourdim=.9\hsize}
% \end{lstlisting}
% Now we set up our macro to use this \kv\ interface
% \begin{lstlisting}
% \protected\def\ourmacro#1{\begingroup\ekvset{our}{#1}\the\ourdim\endgroup}
% \end{lstlisting}
% Finally we can use our macro like in the following\\
% \begin{minipage}{6cm}
% \begin{lstlisting}
% \ourmacro{}\par
% \ourmacro{width}\par
% \ourmacro{width=5pt}\par
% \end{lstlisting}
% \end{minipage}^^A
% \begin{minipage}{\dimexpr\linewidth-6cm\relax}
%   \newdimen\ourdim\ourdim=150pt
%   \protected\ekvdef{our}{width}{\ourdim=#1\relax}^^A
%   \protected\ekvdefNoVal{our}{width}{\ourdim=.9\hsize}^^A
%   \protected\def\ourmacro#1^^A
%     {\begingroup\ekvset{our}{#1}\the\ourdim\endgroup}^^A
%   \ourmacro{}\par
%   \ourmacro{width}\par
%   \ourmacro{width=5pt}\par
% \end{minipage}
%
% \paragraph{The same key using \protect\expkvd}
% Using \expkvd\ we can set up the equivalent key using a \kv\ interface, after
% the following we could use |\ourmacro| in the same way as above. \expkvd\ will
% allocate and initialise |\ourdim| and define the |width| key |\protected| for
% us, so the result will be exactly the same -- with the exception that the
% default will use |\ourdim=.9\hsize\relax| instead.
% \begin{lstlisting}
% \input expkv-def                 % or \usepackage{expkv-def}
% \ekvdefinekeys{our}
%   {
%     dimen    width = \ourdim,
%     qdefault width = .9\hsize,
%     initial  width = 150pt
%   }
% \end{lstlisting}
%
% \subsubsection{An Expandable \kv\ Macro Using \cs[no-index]{ekvsneak}}
% \label{sec:sneakex}
%
% Let's set up an expandable macro, that uses a \kv\ interface. The problems
% we'll face for this are:
% \begin{enumerate}
%   \item ignoring duplicate keys
%   \item default values for keys which weren't used
%   \item providing the values as the correct argument to a macro (ordered)
% \end{enumerate}
%
% First we need to decide which \kv\ parsing macro we want to do this with,
% |\ekvset| or |\ekvparse|. For this example we also want to show the
% usage of |\ekvsneak|, hence we'll choose |\ekvset|. And we'll have to use
% |\ekvset| such that it builds a parsable list for our macro internals. To
% gain back control after |\ekvset| is done we have to put an internal of our
% macro at the start of that list, so we use an internal key that uses
% |\ekvsneakPre| after any user input.
%
% To ignore duplicates will be easy if the value of the key used last will be
% put first in the list, so the following will use |\ekvsneakPre| for the
% user-level keys. If we wanted some key for which the first usage should be the
% binding one we would use |\ekvsneak| instead for that key.
%
% Providing default values can be done in different ways, we'll use a simple
% approach in which we'll just put the outcome of our keys if they were used
% with default values before the parsing list terminator.
%
% Ordering the keys can be done simply by searching for a specific token for
% each argument which acts like a flag, so our sneaked out values will include
% specific tokens acting as markers.
%
% Now that we have answers for our technical problems, we have to decide what
% our example macro should do. How about we define a macro that calculates the
% sine of a number and rounds that to a specified precision? As a small extra
% this macro should understand input in radian and degree and the used
% trigonometric function should be selectable as well. For the hard part of this
% task (expandably evaluating trigonometric functions) we'll use the \pkg{xfp}
% package.
%
% First we set up our keys according to our earlier considerations and set up
% the user facing macro |\sine|. The end marker of the parsing list will be a
% |\sine@stop| token, which we don't need to define and we put our defaults
% right before it.
%
% \begin{lstlisting}
% \RequirePackage{xfp}
% \makeatletter
% \ekvdef{expex}{f}{\ekvsneakPre{\f{#1}}}
% \ekvdef{expex}{round}{\ekvsneakPre{\rnd{#1}}}
% \ekvdefNoVal{expex}{degree}{\ekvsneakPre{\deg{d}}}
% \ekvdefNoVal{expex}{radian}{\ekvsneakPre{\deg{}}}
% \ekvdefNoVal{expex}{internal}{\ekvsneakPre{\sine@rnd}}
% \newcommand*\sine[2]
%   {\ekvset{expex}{#1,internal}\rnd{3}\deg{d}\f{sin}\sine@stop{#2}}
% \end{lstlisting}
% For the sake of simplicity we defined the macro |\sine| with two mandatory
% arguments, the first being the \kv\ list, the second the argument to the
% trigonometric function. We could've used \pkg{xparse}'s facilities here to
% define an expandable macro which takes an optional argument instead.
%
% Now we need to define some internal macros to extract the value of each key's
% last usage (remember that this will be the group after the first special
% flag-token). For that we use one delimited macro per key.
% \begin{lstlisting}
% \def\sine@rnd#1\rnd#2#3\sine@stop{\sine@deg#1#3\sine@stop{#2}}
% \def\sine@deg#1\deg#2#3\sine@stop{\sine@f#1#3\sine@stop{#2}}
% \def\sine@f#1\f#2#3\sine@stop{\sine@final{#2}}
% \end{lstlisting}
% After the macros |\sine@rnd|, |\sine@deg|, and |\sine@f| the macro
% |\sine@final| will see
% \texttt
%   {^^A
%     \cs[no-index]{sine@final}^^A
%     \marg{f}\marg{degree/radian}\marg{round}\marg{num}^^A
%   }.
% Now |\sine@final| has to expandably deal with those arguments such that the
% |\fpeval| macro of \pkg{xfp} gets the correct input. Luckily this is pretty
% straight forward in this example. In |\fpeval| the trigonometric functions
% have names such as |sin| or |cos| and the degree taking variants |sind| or
% |cosd|. And since the |degree| key puts a |d| in |#2| and the |radian| key
% leaves |#2| empty all we have to do to get the correct function name is stick
% the two together.
% \begin{lstlisting}
% \newcommand*\sine@final[4]{\fpeval{round(#1#2(#4),#3)}}
% \makeatother
% \end{lstlisting}
% Let's test our macro:\\
% \begin{minipage}{.7\linewidth}
%   \begin{lstlisting}[gobble=4]
%   \sine{}{60}\par
%   \sine{round=10}{60}\par
%   \sine{f=cos,radian}{pi}\par
%   \edef\myval{\sine{f=tan}{1}}\texttt{\meaning\myval}
%   \end{lstlisting}
% \end{minipage}\hfill
% \begin{minipage}{.2\linewidth}
%   \makeatletter
%   \ekvdef{expex}{f}{\ekvsneakPre{\f{#1}}}^^A
%   \ekvdef{expex}{round}{\ekvsneakPre{\rnd{#1}}}^^A
%   \ekvdefNoVal{expex}{degree}{\ekvsneakPre{\deg{d}}}^^A
%   \ekvdefNoVal{expex}{radian}{\ekvsneakPre{\deg{}}}^^A
%   \ekvdefNoVal{expex}{internal}{\ekvsneakPre{\sine@rnd}}^^A
%   \newcommand*\sine[2]
%     {\ekvset{expex}{#1,internal}\rnd{3}\deg{d}\f{sin}\sine@stop{#2}}^^A
%   \def\sine@rnd#1\rnd#2#3\sine@stop{\sine@deg#1#3\sine@stop{#2}}^^A
%   \def\sine@deg#1\deg#2#3\sine@stop{\sine@f#1#3\sine@stop{#2}}^^A
%   \def\sine@f#1\f#2#3\sine@stop{\sine@final{#2}}^^A
%   \newcommand*\sine@final[4]{\fpeval{round(#1#2(#4),#3)}}^^A
%   \makeatother
%   \sine{}{60}\par
%   \sine{round=10}{60}\par
%   \sine{f=cos,radian}{pi}\par
%   \edef\myval{\sine{f=tan}{1}}\texttt{\meaning\myval}
% \end{minipage}
%
% \paragraph{The same macro using \protect\expkvc}
% Using \expkvc\ we can set up something equivalent with a bit less code. The
% implementation chosen in \expkvc\ is more efficient than the example above and
% way easier to code for the user.
% \begin{lstlisting}
% \makeatletter
% \ekvcSplitAndForward\sine\sine@
%   {
%     f=sin,
%     unit=d,
%     round=3,
%   }
% \ekvcSecondaryKeys\sine
%   {
%     nmeta degree={unit=d},
%     nmeta radian={unit={}},
%   }
% \newcommand*\sine@[4]{\fpeval{round(#1#2(#4),#3)}}
% \makeatother
% \end{lstlisting}
% The resulting macro will behave just like the one previously defined, but will
% have an additional |unit| key, since in \expkvc\ every argument must have a
% value taking key which defines it.
%
%
% \subsection{Error Messages}
%
% \expkv\ should only send messages in case of errors, there are no warnings and
% no info messages. In this subsection those errors are listed.
%
% \subsubsection{Load Time}
%
% \file{expkv.tex} checks whether \eTeX\ is available. If it isn't, an error
% will be thrown using |\errmessage|:
% \begin{lstlisting}
% ! expkv Error: e-TeX required.
% \end{lstlisting}
%
% \subsubsection{Defining Keys}
%
% If you get any error from \expkv\ while you're trying to define a key, the
% definition will be aborted and gobbled.
%
% If you try to define a key with an empty set name you'll get:
% \begin{lstlisting}
% ! expkv Error: empty set name not allowed.
% \end{lstlisting}
%
% Similarly, if you try to define a key with an empty key name:
% \begin{lstlisting}
% ! expkv Error: empty key name not allowed.
% \end{lstlisting}
%
% Both of these messages are done in a way that doesn't throw additional errors
% due to |\global|, |\long|, etc., not being used correctly if you prefixed one
% of the defining macros.
%
% \subsubsection{Using Keys}
%
% This subsubsection contains the errors thrown during |\ekvset|. The errors are
% thrown in an expandable manner by providing an undefined macro. In the
% following messages \lstinline|<key>| gets replaced with the problematic key's
% name, and \lstinline|<set>| with the corresponding set. If any errors during
% \kv\ handling are encountered, the entry in the comma separated list will be
% omitted after the error is thrown and the next \kv\ pair will be parsed.
%
% If you're using an undefined key you'll get:
% \begin{lstlisting}
% ! Undefined control sequence.
% <argument> \! expkv Error:
%                            unknown key (`<key>', set `<set>').
% \end{lstlisting}
%
% If you're using a key for which only a normal version and no |NoVal| version
% is defined, but don't provide a value, you'll get:
% \begin{lstlisting}
% ! Undefined control sequence.
% <argument> \! expkv Error:
%                            value required (`<key>', set `<set>').
% \end{lstlisting}
%
% If you're using a key for which only a |NoVal| version and no normal version
% is defined, but provide a value, you'll get:
% \begin{lstlisting}
% ! Undefined control sequence.
% <argument> \! expkv Error:
%                            value forbidden (`<key>', set `<set>').
% \end{lstlisting}
%
% If you're using a set for which you never executed one of the defining macros
% from \autoref{sec:define} you'll get a low level \TeX\ error, as that isn't
% actively tested by the parser (and hence will lead to undefined behaviour and
% not be gracefully ignored). The error will look like
% \begin{lstlisting}
% ! Missing \endcsname inserted.
% <to be read again>
%                    \! expkv Error: Set `<set>' undefined.
% \end{lstlisting}
%
% \subsection{License}
%
% Copyright \textcopyright\ 2020\unless\ifnum\year=2020--\the\year\fi\
% Jonathan P. Spratte
%
% \medskip\noindent
% This work 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:
%
% \url{http://www.latex-project.org/lppl.txt}
%
% \noindent
% This work is ``maintained'' (as per LPPL maintenance status) by
%
% \mbox{Jonathan P. Spratte}.
%
% \end{documentation}^^A=<<
%
% \begin{implementation}^^A>>=
%
% \clearpage
%
% \section{Implementation}^^A>>=
%^^A the LaTeX package >>=
% \subsection{The \LaTeX\ Package}
% First we set up the \LaTeX\ package. That one doesn't really do much except
% |\input|ting the generic code and identifying itself as a package.
% \gobbledocstriptag
%<*pkg>
%    \begin{macrocode}
\def\ekv@tmp
  {%
    \ProvidesFile{expkv.tex}%
      [\ekvDate\space v\ekvVersion\space an expandable key=val implementation]%
  }
\input{expkv.tex}
\ProvidesPackage{expkv}%
  [\ekvDate\space v\ekvVersion\space an expandable key=val implementation]
%    \end{macrocode}
% \gobbledocstriptag
%</pkg>
%^^A=<<
%^^A main file >>=
% \subsection{The Generic Code}
% The rest of this implementation will be the generic code.
% \gobbledocstriptag
%<*tex>
%
% We make sure that it's only input once:
%    \begin{macrocode}
\expandafter\ifx\csname ekvVersion\endcsname\relax
\else
  \expandafter\endinput
\fi
%    \end{macrocode}
%
% Check whether \eTeX\ is available -- \expkv\ requires \eTeX.
%    \begin{macrocode}
\begingroup\expandafter\expandafter\expandafter\endgroup
\expandafter\ifx\csname numexpr\endcsname\relax
  \errmessage{expkv requires e-TeX}
  \expandafter\endinput
\fi
%    \end{macrocode}
%
% \begin{macro}{\ekvVersion,\ekvDate}
% We're on our first input, so lets store the version and date in a macro.
%    \begin{macrocode}
\def\ekvVersion{1.5}
\def\ekvDate{2020-10-10}
%    \end{macrocode}
% \end{macro}
%
% If the \LaTeX\ format is loaded we want to be a good file and report back who
% we are, for this the package will have defined |\ekv@tmp| to use
% |\ProvidesFile|, else this will expand to a |\relax| and do no harm.
%    \begin{macrocode}
\csname ekv@tmp\endcsname
%    \end{macrocode}
%
% Store the category code of |@| to later be able to reset it and change it to
% 11 for now.
%    \begin{macrocode}
\expandafter\chardef\csname ekv@tmp\endcsname=\catcode`\@
\catcode`\@=11
%    \end{macrocode}
% |\ekv@tmp| might later be reused to gobble any prefixes which might be
% provided to |\ekvdef| and similar in case the names are invalid, we just
% temporarily use it here as means to store the current category code of |@| to
% restore it at the end of the file, we never care for the actual definition of
% it.
%
% \begin{macro}[internal]{\ekv@if@lastnamedcs}
% If the primitive |\lastnamedcs| is available, we can be a bit faster than
% without it. So we test for this and save the test's result in this macro.
%    \begin{macrocode}
\begingroup
  \edef\ekv@tmpa{\string \lastnamedcs}
  \edef\ekv@tmpb{\meaning\lastnamedcs}
  \ifx\ekv@tmpa\ekv@tmpb
    \def\ekv@if@lastnamedcs{\long\def\ekv@if@lastnamedcs##1##2{##1}}
  \else
    \def\ekv@if@lastnamedcs{\long\def\ekv@if@lastnamedcs##1##2{##2}}
  \fi
  \expandafter
\endgroup
\ekv@if@lastnamedcs
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[internal]{\ekv@empty}
% Sometimes we have to introduce a token to prevent accidental brace stripping.
% This token would then need to be removed by |\@gobble| or similar. Instead we
% can use |\ekv@empty| which will just expand to nothing, that is faster than
% gobbling an argument.
%    \begin{macrocode}
\def\ekv@empty{}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[internal]
%   {
%     \@gobble,\@firstofone,\@firstoftwo,\@secondoftwo,
%     \ekv@gobbleto@stop,\ekv@fi@gobble,\ekv@fi@firstoftwo,\ekv@fi@secondoftwo,
%     \ekv@gobble@mark,\ekv@gobble@from@mark@to@stop
%   }
% Since branching tests are often more versatile than |\if...\else...\fi|
% constructs, we define helpers that are branching pretty fast. Also here are
% some other utility functions that just grab some tokens. The ones that are
% also contained in \LaTeX\ don't use the |ekv| prefix. Not all of the ones
% defined here are really needed by \expkv\ but are provided because packages
% like \expkvd\ or \expkvo\ need them (and I don't want to define them in each
% package which might need them).
%    \begin{macrocode}
\long\def\@gobble#1{}
\long\def\@firstofone#1{#1}
\long\def\@firstoftwo#1#2{#1}
\long\def\@secondoftwo#1#2{#2}
\long\def\ekv@fi@gobble\fi\@firstofone#1{\fi}
\long\def\ekv@fi@firstoftwo\fi\@secondoftwo#1#2{\fi#1}
\long\def\ekv@fi@secondoftwo\fi\@firstoftwo#1#2{\fi#2}
\long\def\ekv@gobbleto@stop#1\ekv@stop{}
\def\ekv@gobble@mark\ekv@mark{}
\long\def\ekv@gobble@from@mark@to@stop\ekv@mark#1\ekv@stop{}
%    \end{macrocode}
% \end{macro}
% As you can see |\ekv@gobbleto@stop| uses a special marker |\ekv@stop|. The
% package will use three such markers, the one you've seen already, |\ekv@mark|
% and |\ekv@nil|. Contrarily to how for instance \pkg{expl3} does things, we
% don't define them, as we don't need them to have an actual meaning. This has
% the advantage that if they somehow get expanded -- which should never happen
% if things work out -- they'll throw an error directly.
%
% \begin{macro}[internal]
%   {
%     \ekv@ifempty,\ekv@ifempty@,\ekv@ifempty@true,\ekv@ifempty@false,
%     \ekv@ifempty@true@F,\ekv@ifempty@true@F@gobble,
%     \ekv@ifempty@true@F@gobbletwo
%   }
% We can test for a lot of things building on an if-empty test, so lets define a
% really fast one. Since some tests might have reversed logic (true if something
% is not empty) we also set up macros for the reversed branches.
%    \begin{macrocode}
\long\def\ekv@ifempty#1%
  {%
    \ekv@ifempty@\ekv@ifempty@A#1\ekv@ifempty@B\ekv@ifempty@true
      \ekv@ifempty@A\ekv@ifempty@B\@secondoftwo
  }
\long\def\ekv@ifempty@#1\ekv@ifempty@A\ekv@ifempty@B{}
\long\def\ekv@ifempty@true\ekv@ifempty@A\ekv@ifempty@B\@secondoftwo#1#2{#1}
\long\def\ekv@ifempty@false\ekv@ifempty@A\ekv@ifempty@B\@firstoftwo#1#2{#2}
\long\def\ekv@ifempty@true@F\ekv@ifempty@A\ekv@ifempty@B\@firstofone#1{}
\long\def\ekv@ifempty@true@F@gobble\ekv@ifempty@A\ekv@ifempty@B\@firstofone#1#2%
  {}
\long\def\ekv@ifempty@true@F@gobbletwo
    \ekv@ifempty@A\ekv@ifempty@B\@firstofone#1#2#3%
  {}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[internal]{\ekv@ifblank,\ekv@ifblank@}
% The obvious test that can be based on an if-empty is if-blank, meaning a test
% checking whether the argument is empty or consists only of spaces. Our version
% here will be tweaked a bit, as we want to check this, but with one leading
% |\ekv@mark| token that is to be ignored. The wrapper |\ekv@ifblank| will not
% be used by \expkv\ for speed reasons but \expkvo\ uses it.
%    \begin{macrocode}
\long\def\ekv@ifblank#1%
  {%
    \ekv@ifblank@#1\ekv@nil\ekv@ifempty@B\ekv@ifempty@true
      \ekv@ifempty@A\ekv@ifempty@B\@secondoftwo
  }
\long\def\ekv@ifblank@\ekv@mark#1{\ekv@ifempty@\ekv@ifempty@A}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[internal]{\ekv@ifdefined}
% We'll need to check whether something is defined quite frequently, so why not
% define a macro that does this. The following test is expandable and pretty
% fast. The version with |\lastnamedcs| is the fastest version to test for an
% undefined macro I know of (that considers both undefined macros and those with
% the meaning |\relax|).
%    \begin{macrocode}
\ekv@if@lastnamedcs
  {%
    \def\ekv@ifdefined#1{\ifcsname#1\endcsname\ekv@ifdef@\fi\@secondoftwo}
    \def\ekv@ifdef@\fi\@secondoftwo
      {%
        \fi
        \expandafter\ifx\lastnamedcs\relax
          \ekv@fi@secondoftwo
        \fi
        \@firstoftwo
      }
  }
  {%
    \def\ekv@ifdefined#1%
      {%
        \ifcsname#1\endcsname\ekv@ifdef@\fi\ekv@ifdef@false#1\endcsname\relax
          \ekv@fi@secondoftwo
        \fi
        \@firstoftwo
      }
    \def\ekv@ifdef@\fi\ekv@ifdef@false{\fi\expandafter\ifx\csname}
    \long\def\ekv@ifdef@false
        #1\endcsname\relax\ekv@fi@secondoftwo\fi\@firstoftwo#2#3%
      {#3}
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[internal]{\ekv@strip,\ekv@strip@a,\ekv@strip@b,\ekv@strip@c}
% We borrow some ideas of \pkg{expl3}'s \pkg{l3tl} to strip spaces
% from keys and values. This |\ekv@strip| also strips one level of outer braces
% \emph{after} stripping spaces, so an input of | {abc} | becomes |abc| after
% stripping. It should be used with |#1| prefixed by |\ekv@mark|. Also this
% implementation at most strips \emph{one} space from both sides (which should
% be fine most of the time, since \TeX\ reads consecutive spaces as a single one
% during tokenisation).
%    \begin{macrocode}
\def\ekv@strip#1%
  {%
    \long\def\ekv@strip##1%
      {%
        \ekv@strip@a
          ##1\ekv@nil
          \ekv@mark#1%
          #1\ekv@nil
        \ekv@stop
      }%
    \long\def\ekv@strip@a##1\ekv@mark#1{\ekv@strip@b##1\ekv@mark}%
    \long\def\ekv@strip@b##1#1\ekv@nil {\ekv@strip@c##1\ekv@nil}%
  }
\ekv@strip{ }
\long\def\ekv@strip@c\ekv@mark#1\ekv@nil\ekv@mark#2\ekv@nil\ekv@stop#3{#3{#1}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[internal]{\ekv@expB@unbraceA,\ekv@expB@unbraceA@}
% To reduce some code doublets while gaining some speed, it is often useful to
% expand the first token in a definition once. Let's define a wrapper for this.
%    \begin{macrocode}
\long\def\ekv@expB@unbraceA#1#2%
  {%
    \expandafter\ekv@expB@unbraceA@\expandafter{#2}{#1}%
  }
\long\def\ekv@expB@unbraceA@#1#2{#2{#1}}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ekv@name,\ekv@name@set,\ekv@name@key}
% The keys will all follow the same naming scheme, so we define it here.
%    \begin{macrocode}
\def\ekv@name@set#1{ekv#1(}
\def\ekv@name@key#1{#1)}
\edef\ekv@name
  {%
    \unexpanded\expandafter{\ekv@name@set{#1}}%
    \unexpanded\expandafter{\ekv@name@key{\detokenize{#2}}}%
  }
\ekv@expB@unbraceA{\def\ekv@name#1#2}{\ekv@name}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[internal]{\ekv@undefined@set}
% We can misuse the macro name we use to expandably store the set-name in a
% single token -- since this increases performance drastically, especially for
% long set-names -- to throw a more meaningful error message in case a set isn't
% defined. The name of |\ekv@undefined@set| is a little bit misleading, as it is
% called in either case inside of |\csname|, but the result will be a control
% sequence with meaning |\relax| if the set is undefined, hence will break the
% |\csname| building the key-macro which will throw the error message.
%    \begin{macrocode}
\def\ekv@undefined@set#1{! expkv Error: Set `#1' undefined.}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[internal]{\ekv@checkvalid}
% We place some restrictions on the allowed names, though, namely sets and
% keys are not allowed to be empty -- blanks are fine (meaning \mbox{set-
% or} key-names consisting of spaces). The |\def\ekv@tmp| gobbles any \TeX\
% prefixes which would otherwise throw errors. This will, however, break the
% package if an |\outer| has been gobbled this way. I consider that good,
% because keys shouldn't be defined |\outer| anyways.
%    \begin{macrocode}
\edef\ekv@checkvalid
  {%
    \unexpanded\expandafter{\ekv@ifempty{#1}}%
    \unexpanded
      {{%
        \def\ekv@tmp{}%
        \errmessage{expkv Error: empty set name not allowed}%
      }}%
      {%
        \unexpanded\expandafter{\ekv@ifempty{#2}}%
        \unexpanded
          {%
            {%
              \def\ekv@tmp{}%
              \errmessage{expkv Error: empty key name not allowed}%
            }%
            \@secondoftwo
          }%
      }%
    \unexpanded{\@gobble}%
  }
\ekv@expB@unbraceA{\protected\def\ekv@checkvalid#1#2}{\ekv@checkvalid}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ekvifdefined,\ekvifdefinedNoVal}
% And provide user-level macros to test whether a key is defined.
%    \begin{macrocode}
\ekv@expB@unbraceA{\ekv@expB@unbraceA{\def\ekvifdefined#1#2}}%
  {\expandafter\ekv@ifdefined\expandafter{\ekv@name{#1}{#2}}}
\ekv@expB@unbraceA{\ekv@expB@unbraceA{\def\ekvifdefinedNoVal#1#2}}%
  {\expandafter\ekv@ifdefined\expandafter{\ekv@name{#1}{#2}N}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}
%   {
%     \ekvdef,\ekvdefNoVal,\ekvlet,\ekvletNoVal,\ekvletkv,\ekvletkvNoVal,
%     \ekvdefunknown,\ekvdefunknownNoVal
%   }
% Set up the key defining macros |\ekvdef| etc. We use temporary macros to set
% these up with a few expansions already done.
%    \begin{macrocode}
\def\ekvdef#1#2#3#4%
  {%
    \protected\long\def\ekvdef##1##2##3%
      {#1{\expandafter\def\csname#2\endcsname####1{##3}#3}}%
    \protected\long\def\ekvdefNoVal##1##2##3%
      {#1{\expandafter\def\csname#2N\endcsname{##3}#3}}%
    \protected\def\ekvlet##1##2##3%
      {#1{\expandafter\let\csname#2\endcsname##3#3}}%
    \protected\def\ekvletNoVal##1##2##3%
      {#1{\expandafter\let\csname#2N\endcsname##3#3}}%
    \ekv@expB@unbraceA{\ekv@expB@unbraceA{\ekv@expB@unbraceA{%
        \protected\long\def\ekvdefunknown##1##2}}}%
      {%
        \expandafter\ekv@expB@unbraceA@\expandafter
          {%
            \expandafter\expandafter\expandafter
            \def\expandafter\csname\ekv@name{##1}{}u\endcsname####1####2{##2}%
            #3%
          }%
          {\ekv@checkvalid{##1}.}%
      }%
    \ekv@expB@unbraceA{\ekv@expB@unbraceA{\ekv@expB@unbraceA{%
        \protected\long\def\ekvdefunknownNoVal##1##2}}}%
      {%
        \expandafter\ekv@expB@unbraceA@\expandafter
          {%
            \expandafter\expandafter\expandafter
            \def\expandafter\csname\ekv@name{##1}{}uN\endcsname####1{##2}%
            #3%
          }%
          {\ekv@checkvalid{##1}.}%
      }%
    \protected\def\ekvletkv##1##2##3##4%
      {%
        #1%
          {%
            \expandafter\let\csname#2\expandafter\endcsname
            \csname#4\endcsname
            #3%
          }%
      }%
    \protected\def\ekvletkvNoVal##1##2##3##4%
      {%
        #1%
          {%
            \expandafter\let\csname#2N\expandafter\endcsname
            \csname#4N\endcsname
            #3%
          }%
      }%
  }
\edef\ekvdefNoVal
  {%
    {\unexpanded\expandafter{\ekv@checkvalid{#1}{#2}}}%
    {\unexpanded\expandafter{\ekv@name{#1}{#2}}}%
    {%
      \unexpanded{\expandafter\ekv@defsetmacro\csname}%
      \unexpanded\expandafter{\ekv@undefined@set{#1}\endcsname{#1}}%
    }%
    {\unexpanded\expandafter{\ekv@name{#3}{#4}}}%
  }%
\expandafter\ekvdef\ekvdefNoVal
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[internal]{\ekv@defsetmacro}
%   In order to enhance the speed the set name given to |\ekvset| will be turned
%   into a control sequence pretty early, so we have to define that control
%   sequence.
%    \begin{macrocode}
\edef\ekv@defsetmacro
  {%
    \unexpanded{\ifx#1\relax\edef#1##1}%
      {%
        \unexpanded\expandafter{\ekv@name@set{#2}}%
        \unexpanded\expandafter{\ekv@name@key{##1}}%
      }%
    \unexpanded{\fi}%
  }
\ekv@expB@unbraceA{\protected\def\ekv@defsetmacro#1#2}{\ekv@defsetmacro}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ekvifdefinedset}
%    \begin{macrocode}
\ekv@expB@unbraceA{\ekv@expB@unbraceA{\def\ekvifdefinedset#1}}%
  {%
    \expandafter\ekv@ifdefined\expandafter{\ekv@undefined@set{#1}}%
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ekvset}
% Set up |\ekvset|, which should not be affected by active commas and equal
% signs. The equal signs are a bit harder to cope with and we'll do that later,
% but the active commas can be handled by just doing two comma-splitting loops
% one at actives one at others. That's why we define |\ekvset| here with a
% temporary meaning just to set up the things with two different category codes.
% |#1| will be a \texttt{,\textsubscript{13}} and |#2| will be a
% \texttt{=\textsubscript{13}}.
%    \begin{macrocode}
\begingroup
\def\ekvset#1#2{%
\endgroup
\ekv@expB@unbraceA{\long\def\ekvset##1##2}%
  {%
    \expandafter\expandafter\expandafter
    \ekv@set\expandafter\csname\ekv@undefined@set{##1}\endcsname
      \ekv@mark##2#1\ekv@stop#1{}%
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[internal]{\ekv@set}
% |\ekv@set| will split the \kv\ list at active commas. Then it has to check
% whether there were unprotected other commas and resplit there.
%    \begin{macrocode}
\long\def\ekv@set##1##2#1%
  {%
%    \end{macrocode}
% Test whether we're at the end, if so invoke |\ekv@endset|,
%    \begin{macrocode}
    \ekv@gobble@from@mark@to@stop##2\ekv@endset\ekv@stop
%    \end{macrocode}
% else go on with other commas.
%    \begin{macrocode}
    \ekv@set@other##1##2,\ekv@stop,%
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[internal]{\ekv@endset}
% |\ekv@endset| is a hungry little macro. It will eat everything that remains
% of |\ekv@set| and unbrace the sneaked stuff.
%    \begin{macrocode}
\long\def\ekv@endset
    \ekv@stop\ekv@set@other##1\ekv@mark\ekv@stop,\ekv@stop,##2%
  {##2}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[internal]{\ekv@eq@other,\ekv@eq@active}
%   Splitting at equal signs will be done in a way that checks whether there is
%   an equal sign and splits at the same time. This gets quite messy and the
%   code might look complicated, but this is pretty fast (faster than first
%   checking for an equal sign and splitting if one is found). The splitting
%   code will be adapted for |\ekvset| and |\ekvparse| to get the most speed,
%   but some of these macros don't require such adaptions. |\ekv@eq@other| and
%   |\ekv@eq@active| will split the argument at the first equal sign and insert
%   the macro which comes after the first following |\ekv@mark|. This allows for
%   fast branching based on \TeX's argument grabbing rules and we don't have to
%   split after the branching if the equal sign was there.
%    \begin{macrocode}
\long\def\ekv@eq@other##1=##2\ekv@mark##3%
  {%
    ##3##1\ekv@stop\ekv@mark##2%
  }
\long\def\ekv@eq@active##1#2##2\ekv@mark##3%
  {%
    ##3##1\ekv@stop\ekv@mark##2%
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[internal]{\ekv@set@other}
%   The macro |\ekv@set@other| is guaranteed to get only single \kv\ pairs.
%    \begin{macrocode}
\long\def\ekv@set@other##1##2,%
  {%
%    \end{macrocode}
%   First we test whether we're done.
%    \begin{macrocode}
    \ekv@gobble@from@mark@to@stop##2\ekv@endset@other\ekv@stop
%    \end{macrocode}
%   If not we split at the equal sign of category other.
%    \begin{macrocode}
    \ekv@eq@other##2\ekv@nil\ekv@mark\ekv@set@eq@other@a
      =\ekv@mark\ekv@set@eq@active
%    \end{macrocode}
%   And insert the set name for the next recursion step of |\ekv@set@other|.
%    \begin{macrocode}
    ##1%
    \ekv@mark
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[internal]{\ekv@set@eq@other@a, \ekv@set@eq@other@b}
%   The first of these two macros runs the split-test for equal signs of
%   category active. It will only be inserted if the \kv\ pair contained at
%   least one equal sign of category other and |##1| will contain everything up
%   to that equal sign.
%    \begin{macrocode}
\long\def\ekv@set@eq@other@a##1\ekv@stop
  {%
    \ekv@eq@active##1\ekv@nil\ekv@mark\ekv@set@eq@other@active
      #2\ekv@mark\ekv@set@eq@other@b
  }
%    \end{macrocode}
%   The second macro will have been called by |\ekv@eq@active| if no active
%   equal sign was found. All it does is remove the excess tokens of that
%   test and forward the \kv\ pair to |\ekv@set@pair|. Normally we would have to
%   also gobble an additional |\ekv@mark| after |\ekv@stop|, but this mark is
%   needed to delimit |\ekv@set@pair|'s argument anyway, so we just leave it
%   there.
%    \begin{macrocode}
\ekv@expB@unbraceA
  {%
    \long\def\ekv@set@eq@other@b
        ##1\ekv@nil\ekv@mark\ekv@set@eq@other@active\ekv@stop\ekv@mark
        ##2\ekv@nil=\ekv@mark\ekv@set@eq@active
  }%
  {\ekv@strip{##1}{\expandafter\ekv@set@pair\detokenize}\ekv@mark##2\ekv@nil}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[internal]{\ekv@set@eq@other@active}
%   |\ekv@set@eq@other@active| will be called if the \kv\ pair was wrongly
%   split on an equal sign of category other but has an earlier equal sign of
%   category active. |##1| will be the contents up to the active equal sign and
%   |##2| everything that remains until the first found other equal sign. It has
%   to reinsert the equal sign and forward things to |\ekv@set@pair|.
%    \begin{macrocode}
\ekv@expB@unbraceA
  {%
    \long\def\ekv@set@eq@other@active
        ##1\ekv@stop##2\ekv@nil#2\ekv@mark
        \ekv@set@eq@other@b\ekv@mark##3=\ekv@mark\ekv@set@eq@active
  }%
  {\ekv@strip{##1}{\expandafter\ekv@set@pair\detokenize}\ekv@mark##2=##3}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[internal]{\ekv@set@eq@active, \ekv@set@eq@active@}
%   |\ekv@set@eq@active| will be called when there was no equal sign of category
%   other in the \kv\ pair. It removes the excess tokens of the prior test and
%   split-checks for an active equal sign.
%    \begin{macrocode}
\long\def\ekv@set@eq@active
    ##1\ekv@nil\ekv@mark\ekv@set@eq@other@a\ekv@stop\ekv@mark
  {%
    \ekv@eq@active##1\ekv@nil\ekv@mark\ekv@set@eq@active@
      #2\ekv@mark\ekv@set@noeq
  }
%    \end{macrocode}
%   If an active equal sign was found in |\ekv@set@eq@active| we'll have to pass
%   the now split \kv\ pair on to |\ekv@set@pair|.
%    \begin{macrocode}
\ekv@expB@unbraceA
  {\long\def\ekv@set@eq@active@##1\ekv@stop##2\ekv@nil#2\ekv@mark\ekv@set@noeq}%
  {%
    \ekv@strip{##1}{\expandafter\ekv@set@pair\detokenize}\ekv@mark##2\ekv@nil
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[internal]{\ekv@set@noeq}
%   If no active equal sign was found by |\ekv@set@eq@active| there is no equal
%   sign contained in the parsed list entry. In that case we have to check
%   whether the entry is blank in order to ignore it (in which case we'll have
%   to gobble the set-name which was put after these tests by |\ekv@set@other|).
%   Else this is a |NoVal| key and the entry is passed on to |\ekv@set@key|.
%    \begin{macrocode}
\edef\ekv@set@noeq
  {%
    \unexpanded
      {%
        \ekv@ifblank@##1\ekv@nil\ekv@ifempty@B\ekv@set@was@blank
          \ekv@ifempty@A\ekv@ifempty@B
      }%
    \unexpanded\expandafter
      {\ekv@strip{##1}{\expandafter\ekv@set@key\detokenize}\ekv@mark}%
  }
\ekv@expB@unbraceA
  {%
    \long\def\ekv@set@noeq
        ##1\ekv@nil\ekv@mark\ekv@set@eq@active@\ekv@stop\ekv@mark
  }%
  {\ekv@set@noeq}
\def\ekv@set@was@blank##1%
  {%
    \def\ekv@set@was@blank
        \ekv@ifempty@A\ekv@ifempty@B
        \ekv@strip@a\ekv@mark####1\ekv@nil\ekv@mark##1##1\ekv@nil\ekv@stop
        ####2\ekv@mark
      {\ekv@set@other}%
  }
\ekv@set@was@blank{ }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[internal]{\ekv@endset@other}
%   All that's left for |\ekv@set@other| is the macro which breaks the recursion
%   loop at the end. This is done by gobbling all the remaining tokens.
%    \begin{macrocode}
\long\def\ekv@endset@other
    \ekv@stop
    \ekv@eq@other\ekv@mark\ekv@stop\ekv@nil\ekv@mark\ekv@set@eq@other@a
    =\ekv@mark\ekv@set@eq@active
  {\ekv@set}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ekvbreak,\ekvbreakPreSneak,\ekvbreakPostSneak}
% Provide macros that can completely stop the parsing of |\ekvset|, who knows
% what it'll be useful for.
%    \begin{macrocode}
\long\def\ekvbreak##1##2\ekv@stop#1##3{##1}
\long\def\ekvbreakPreSneak ##1##2\ekv@stop#1##3{##1##3}
\long\def\ekvbreakPostSneak##1##2\ekv@stop#1##3{##3##1}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ekvsneak,\ekvsneakPre}
% One last thing we want to do for |\ekvset| is to provide macros that just
% smuggle stuff after |\ekvset|'s effects.
%    \begin{macrocode}
\long\def\ekvsneak##1##2\ekv@stop#1##3%
  {%
    ##2\ekv@stop#1{##3##1}%
  }
\long\def\ekvsneakPre##1##2\ekv@stop#1##3%
  {%
    ##2\ekv@stop#1{##1##3}%
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ekvparse}
% Additionally to the |\ekvset| macro we also want to provide an |\ekvparse|
% macro, that has the same scope as |\keyval_parse:NNn| from \pkg{expl3}.
% This is pretty analogue to the |\ekvset| implementation, we just put an
% |\unexpanded| here and there instead of other macros to stop the |\expanded|
% on our output.
%    \begin{macrocode}
\long\def\ekvparse##1##2##3%
  {%
    \ekv@parse##1##2\ekv@mark##3#1\ekv@stop#1%
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[internal]{\ekv@parse}
%    \begin{macrocode}
\long\def\ekv@parse##1##2##3#1%
  {%
    \ekv@gobble@from@mark@to@stop##3\ekv@endparse\ekv@stop
    \ekv@parse@other##1##2##3,\ekv@stop,%
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[internal]{\ekv@endparse}
%    \begin{macrocode}
\long\def\ekv@endparse
    \ekv@stop\ekv@parse@other##1\ekv@mark\ekv@stop,\ekv@stop,%
  {}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[internal]{\ekv@parse@other}
%    \begin{macrocode}
\long\def\ekv@parse@other##1##2##3,%
  {%
    \ekv@gobble@from@mark@to@stop##3\ekv@endparse@other\ekv@stop
    \ekv@eq@other##3\ekv@nil\ekv@mark\ekv@parse@eq@other@a
      =\ekv@mark\ekv@parse@eq@active
    ##1##2%
    \ekv@mark
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[internal]{\ekv@parse@eq@other@a,\ekv@parse@eq@other@b}
%    \begin{macrocode}
\long\def\ekv@parse@eq@other@a##1\ekv@stop
  {%
    \ekv@eq@active##1\ekv@nil\ekv@mark\ekv@parse@eq@other@active
      #2\ekv@mark\ekv@parse@eq@other@b
  }
\ekv@expB@unbraceA
  {%
    \long\def\ekv@parse@eq@other@b
        ##1\ekv@nil\ekv@mark\ekv@parse@eq@other@active\ekv@stop\ekv@mark
        ##2\ekv@nil=\ekv@mark\ekv@parse@eq@active
  }%
  {\ekv@strip{##1}\ekv@parse@pair##2\ekv@nil}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[internal]{\ekv@parse@eq@other@active}
%    \begin{macrocode}
\ekv@expB@unbraceA
  {%
    \long\def\ekv@parse@eq@other@active
        ##1\ekv@stop##2\ekv@nil#2\ekv@mark
        \ekv@parse@eq@other@b\ekv@mark##3=\ekv@mark\ekv@parse@eq@active
  }%
  {\ekv@strip{##1}\ekv@parse@pair##2=##3}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[internal]{\ekv@parse@eq@active,\ekv@parse@eq@active@}
%    \begin{macrocode}
\long\def\ekv@parse@eq@active
    ##1\ekv@nil\ekv@mark\ekv@parse@eq@other@a\ekv@stop\ekv@mark
  {%
    \ekv@eq@active##1\ekv@nil\ekv@mark\ekv@parse@eq@active@
      #2\ekv@mark\ekv@parse@noeq
  }
\ekv@expB@unbraceA
  {\long\def\ekv@parse@eq@active@##1\ekv@stop##2#2\ekv@mark\ekv@parse@noeq}%
  {%
    \ekv@strip{##1}\ekv@parse@pair##2%
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[internal]{\ekv@parse@noeq}
%    \begin{macrocode}
\edef\ekv@parse@noeq
  {%
    \unexpanded
      {%
        \ekv@ifblank@##1\ekv@nil\ekv@ifempty@B\ekv@parse@was@blank
          \ekv@ifempty@A\ekv@ifempty@B
      }%
      \unexpanded\expandafter{\ekv@strip{##1}\ekv@parse@key}%
  }
\ekv@expB@unbraceA
  {%
    \long\def\ekv@parse@noeq
        ##1\ekv@nil\ekv@mark\ekv@parse@eq@active@\ekv@stop\ekv@mark
  }%
  {\ekv@parse@noeq}
\def\ekv@parse@was@blank##1%
  {%
    \def\ekv@parse@was@blank
        \ekv@ifempty@A\ekv@ifempty@B
        \ekv@strip@a\ekv@mark####1\ekv@nil\ekv@mark##1##1\ekv@nil\ekv@stop
        \ekv@parse@key
      {\ekv@parse@other}%
  }
\ekv@parse@was@blank{ }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[internal]{\ekv@endparse@other}
%    \begin{macrocode}
\long\def\ekv@endparse@other
    \ekv@stop
    \ekv@eq@other\ekv@mark\ekv@stop\ekv@nil\ekv@mark\ekv@parse@eq@other@a
    =\ekv@mark\ekv@parse@eq@active
  {\ekv@parse}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[internal]{\ekv@parse@pair,\ekv@parse@pair@}
%    \begin{macrocode}
\ekv@expB@unbraceA{\long\def\ekv@parse@pair##1##2\ekv@nil}%
  {%
    \ekv@strip{##2}\ekv@parse@pair@{##1}%
  }
\long\def\ekv@parse@pair@##1##2##3##4%
  {%
    \unexpanded{##4{##2}{##1}}%
    \ekv@parse@other##3##4%
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[internal]{\ekv@parse@key}
%    \begin{macrocode}
\long\def\ekv@parse@key##1##2##3%
  {%
    \unexpanded{##2{##1}}%
    \ekv@parse@other##2##3%
  }
%    \end{macrocode}
% \end{macro}
%
% Finally really setting things up with |\ekvset|'s temporary meaning:
%    \begin{macrocode}
}
\catcode`\,=13
\catcode`\==13
\ekvset,=
%    \end{macrocode}
%
% \begin{macro}{\ekvsetSneaked}
% This macro can be defined just by expanding |\ekvsneak| once after expanding
% |\ekvset|. To expand everything as much as possible early on we use a
% temporary definition.
%    \begin{macrocode}
\edef\ekvsetSneaked
  {%
    \unexpanded{\ekvsneak{#2}}%
    \unexpanded\expandafter{\ekvset{#1}{#3}}%
  }
\ekv@expB@unbraceA{\ekv@expB@unbraceA{\long\def\ekvsetSneaked#1#2#3}}%
  {\ekvsetSneaked}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ekvchangeset}
% Provide a macro that is able to switch out the current \set\ in |\ekvset|.
% This operation is slow (by comparison, it should be slightly faster than
% |\ekvsneak|), but allows for something similar to \pkg{pgfkeys}'s
% \texttt{\meta{key}/.cd} mechanism. However this operation is more expensive
% than |/.cd| as we can't just redefine some token to reflect this, but have to
% switch out the set expandably, so this works similar to the |\ekvsneak| macros
% reading and reinserting the remainder of the \kv\ list.
%    \begin{macrocode}
\ekv@expB@unbraceA{\def\ekvchangeset#1}%
  {%
    \expandafter\expandafter\expandafter
    \ekv@changeset\expandafter\csname\ekv@undefined@set{#1}\endcsname\ekv@empty
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[internal]{\ekv@changeset}
% This macro does the real change-out of |\ekvchangeset|. |#2| will have a
% leading |\ekv@empty| so that braces aren't stripped accidentally, but that
% will not hurt and just expand to nothing in one step.
%    \begin{macrocode}
\long\def\ekv@changeset#1#2\ekv@set@other#3%
  {%
    #2\ekv@set@other#1%
  }
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}[internal]
%   {
%     \ekv@set@pair,\ekv@set@pair@a,\ekv@set@pair@b,\ekv@set@pair@c,
%     \ekv@set@pair@d,\ekv@set@pair@e
%   }
%   |\ekv@set@pair| gets invoked with the space and brace stripped and
%   |\detokenize|d key-name as its first, the value as the second, and the set
%   name as the third argument. It provides tests for the key-macros and
%   everything to be able to throw meaningful error messages if it isn't
%   defined. We have two routes here, one if |\lastnamedcs| is defined and one
%   if it isn't. The big difference is that if it is we can omit a |\csname| and
%   instead just expand |\lastnamedcs| once to get the control sequence.
%   If the macro is defined the value will be space and brace stripped and the
%   key-macro called. Else branch into the error handling provided by
%   |\ekv@set@pair|.
%    \begin{macrocode}
\ekv@if@lastnamedcs
  {%
    \long\def\ekv@set@pair#1\ekv@mark#2\ekv@nil#3%
      {%
        \ifcsname #3{#1}\endcsname\ekv@set@pair@a\fi\@secondoftwo
          {#2}%
          {%
            \ifcsname #3{}u\endcsname\ekv@set@pair@a\fi\@secondoftwo
              {#2}%
              {%
                \ekv@ifdefined{#3{#1}N}%
                  \ekv@err@noarg
                  \ekv@err@unknown
                  #3%
              }%
              {#1}%
          }%
        \ekv@set@other#3%
      }
    \def\ekv@set@pair@a\fi\@secondoftwo
      {\fi\expandafter\ekv@set@pair@b\lastnamedcs}
  }
  {%
    \long\def\ekv@set@pair#1\ekv@mark#2\ekv@nil#3%
      {%
        \ifcsname #3{#1}\endcsname
            \ekv@set@pair@a\fi\ekv@set@pair@c#3{#1}\endcsname
          {#2}%
          {%
            \ifcsname #3{}u\endcsname
                \ekv@set@pair@a\fi\ekv@set@pair@c#3{}u\endcsname
              {#2}%
              {%
                \ekv@ifdefined{#3{#1}N}%
                  \ekv@err@noarg
                  \ekv@err@unknown
                  #3%
              }%
              {#1}%
          }%
        \ekv@set@other#3%
      }
    \def\ekv@set@pair@a\fi\ekv@set@pair@c{\fi\expandafter\ekv@set@pair@b\csname}
    \long\def\ekv@set@pair@c#1\endcsname#2#3{#3}
  }
\long\def\ekv@set@pair@b#1%
  {%
    \ifx#1\relax
      \ekv@set@pair@e
    \fi
    \ekv@set@pair@d#1%
  }
\ekv@expB@unbraceA{\long\def\ekv@set@pair@d#1#2#3}{\ekv@strip{#2}#1}
\long\def\ekv@set@pair@e\fi\ekv@set@pair@d#1#2#3{\fi#3}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[internal]
%   {\ekv@set@key,\ekv@set@key@a,\ekv@set@key@b,\ekv@set@key@c}
% Analogous to |\ekv@set@pair|, |\ekv@set@key| builds the |NoVal| key-macro and
% provides an error-branch. |\ekv@set@key@| will test whether the key-macro is
% defined and if so call it, else the errors are thrown.
%    \begin{macrocode}
\ekv@if@lastnamedcs
  {%
    \long\def\ekv@set@key#1\ekv@mark#2%
      {%
        \ifcsname #2{#1}N\endcsname\ekv@set@key@a\fi\@firstofone
          {%
            \ifcsname #2{}uN\endcsname\ekv@set@key@a\fi\@firstofone
              {%
                \ekv@ifdefined{#2{#1}}%
                  \ekv@err@reqval
                  \ekv@err@unknown
                  #2%
              }%
              {#1}%
          }%
        \ekv@set@other#2%
      }
    \def\ekv@set@key@a\fi\@firstofone{\fi\expandafter\ekv@set@key@b\lastnamedcs}
  }
  {%
    \long\def\ekv@set@key#1\ekv@mark#2%
      {%
        \ifcsname #2{#1}N\endcsname
            \ekv@set@key@a\fi\ekv@set@key@c#2{#1}N\endcsname
          {%
            \ifcsname #2{}uN\endcsname
                \ekv@set@key@a\fi\ekv@set@key@c#2{}uN\endcsname
              {%
                \ekv@ifdefined{#2{#1}}%
                  \ekv@err@reqval
                  \ekv@err@unknown
                  #2%
              }%
              {#1}%
          }%
        \ekv@set@other#2%
      }
    \def\ekv@set@key@a\fi\ekv@set@key@c{\fi\expandafter\ekv@set@key@b\csname}
    \long\def\ekv@set@key@c#1N\endcsname#2{#2}
  }
\long\def\ekv@set@key@b#1%
  {%
    \ifx#1\relax
      \ekv@fi@secondoftwo
    \fi
    \@firstoftwo#1%
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ekvsetdef}
%   Provide a macro to define a shorthand to use |\ekvset| on a specified \set.
%   To gain the maximum speed |\ekvset| is expanded twice by
%   |\ekv@expB@unbraceA| so that during runtime the macro storing the set name
%   is already built and one |\expandafter| doesn't have to be used.
%    \begin{macrocode}
\ekv@expB@unbraceA{\ekv@expB@unbraceA{\ekv@expB@unbraceA{\ekv@expB@unbraceA{%
\protected\def\ekvsetdef#1#2}}}}%
  {%
    \ekv@expB@unbraceA{\ekv@expB@unbraceA{\long\def#1##1}}%
      {\ekvset{#2}{##1}}%
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ekvsetSneakeddef,\ekvsetdefSneaked}
% And do the same for |\ekvsetSneaked| in the two possible ways, with a fixed
% sneaked argument and with a flexible one.
%    \begin{macrocode}
\ekv@expB@unbraceA{\ekv@expB@unbraceA{\ekv@expB@unbraceA{\ekv@expB@unbraceA{%
\protected\def\ekvsetSneakeddef#1#2}}}}%
  {%
    \ekv@expB@unbraceA{\ekv@expB@unbraceA{\long\def#1##1##2}}%
      {\ekvsetSneaked{#2}{##1}{##2}}%
  }
\ekv@expB@unbraceA{\ekv@expB@unbraceA{\ekv@expB@unbraceA{\ekv@expB@unbraceA{%
\protected\def\ekvsetdefSneaked#1#2#3}}}}%
  {%
    \ekv@expB@unbraceA{\ekv@expB@unbraceA{\long\def#1##1}}%
      {\ekvsetSneaked{#2}{#3}{##1}}%
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[internal]{\ekv@err,\ekv@err@}
% Since |\ekvset| is fully expandable as long as the code of the keys is (which
% is unlikely) we want to somehow throw expandable errors, in our case via
% undefined control sequences.
%    \begin{macrocode}
\begingroup
\edef\ekv@err
  {%
    \endgroup
    \unexpanded{\long\def\ekv@err}##1%
      {%
        \unexpanded{\expandafter\ekv@err@\@firstofone}%
        {\unexpanded\expandafter{\csname ! expkv Error:\endcsname}##1.}%
        \unexpanded{\ekv@stop}%
      }%
  }
\ekv@err
\def\ekv@err@{\expandafter\ekv@gobbleto@stop}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[internal]
%   {
%     \ekv@err@common,\ekv@err@common@,
%     \ekv@err@unknown,\ekv@err@noarg,\ekv@err@reqval
%   }
% Now we can use |\ekv@err| to set up some error messages so that we can later
% use those instead of the full strings.
%    \begin{macrocode}
\long\def\ekv@err@common #1#2{\expandafter\ekv@err@common@\string#2{#1}}
\long\def\ekv@err@common@#1`#2' #3.#4#5{\ekv@err{#4 (`#5', set `#2')}}
\ekv@expB@unbraceA{\long\def\ekv@err@unknown#1}%
  {\ekv@err@common{unknown key}{#1}}
\ekv@expB@unbraceA{\long\def\ekv@err@noarg  #1}%
  {\ekv@err@common{value forbidden}{#1}}
\ekv@expB@unbraceA{\long\def\ekv@err@reqval #1}%
  {\ekv@err@common{value required}{#1}}
%    \end{macrocode}
% \end{macro}
%
% Now everything that's left is to reset the category code of |@|.
%    \begin{macrocode}
\catcode`\@=\ekv@tmp
%    \end{macrocode}
%
% \gobbledocstriptag
%</tex>
%^^A=<<
%
%^^A=<<
%
% \end{implementation}^^A=<<
%
% \clearpage
% \PrintIndex
%
\endinput
%
^^A vim: ft=tex fdm=marker fmr=>>=,=<<