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
|
% \iffalse meta-comment
%
% Copyright (C) 2006, 2007, 2009, 2010 by
% Heiko Oberdiek <heiko.oberdiek at googlemail.com>
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either
% version 1.3c of this license or (at your option) any later
% version. This version of this license is in
% http://www.latex-project.org/lppl/lppl-1-3c.txt
% and the latest version of this license is in
% http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of
% LaTeX version 2005/12/01 or later.
%
% This work has the LPPL maintenance status "maintained".
%
% This Current Maintainer of this work is Heiko Oberdiek.
%
% The Base Interpreter refers to any `TeX-Format',
% because some files are installed in TDS:tex/generic//.
%
% This work consists of the main source file kvsetkeys.dtx
% and the derived files
% kvsetkeys.sty, kvsetkeys.pdf, kvsetkeys.ins, kvsetkeys.drv,
% kvsetkeys-example.tex, kvsetkeys-test1.tex,
% kvsetkeys-test2.tex, kvsetkeys-test3.tex.
%
% Distribution:
% CTAN:macros/latex/contrib/oberdiek/kvsetkeys.dtx
% CTAN:macros/latex/contrib/oberdiek/kvsetkeys.pdf
%
% Unpacking:
% (a) If kvsetkeys.ins is present:
% tex kvsetkeys.ins
% (b) Without kvsetkeys.ins:
% tex kvsetkeys.dtx
% (c) If you insist on using LaTeX
% latex \let\install=y\input{kvsetkeys.dtx}
% (quote the arguments according to the demands of your shell)
%
% Documentation:
% (a) If kvsetkeys.drv is present:
% latex kvsetkeys.drv
% (b) Without kvsetkeys.drv:
% latex kvsetkeys.dtx; ...
% The class ltxdoc loads the configuration file ltxdoc.cfg
% if available. Here you can specify further options, e.g.
% use A4 as paper format:
% \PassOptionsToClass{a4paper}{article}
%
% Programm calls to get the documentation (example):
% pdflatex kvsetkeys.dtx
% makeindex -s gind.ist kvsetkeys.idx
% pdflatex kvsetkeys.dtx
% makeindex -s gind.ist kvsetkeys.idx
% pdflatex kvsetkeys.dtx
%
% Installation:
% TDS:tex/generic/oberdiek/kvsetkeys.sty
% TDS:doc/latex/oberdiek/kvsetkeys.pdf
% TDS:doc/latex/oberdiek/kvsetkeys-example.tex
% TDS:doc/latex/oberdiek/test/kvsetkeys-test1.tex
% TDS:doc/latex/oberdiek/test/kvsetkeys-test2.tex
% TDS:doc/latex/oberdiek/test/kvsetkeys-test3.tex
% TDS:source/latex/oberdiek/kvsetkeys.dtx
%
%<*ignore>
\begingroup
\catcode123=1 %
\catcode125=2 %
\def\x{LaTeX2e}%
\expandafter\endgroup
\ifcase 0\ifx\install y1\fi\expandafter
\ifx\csname processbatchFile\endcsname\relax\else1\fi
\ifx\fmtname\x\else 1\fi\relax
\else\csname fi\endcsname
%</ignore>
%<*install>
\input docstrip.tex
\Msg{************************************************************************}
\Msg{* Installation}
\Msg{* Package: kvsetkeys 2010/03/01 v1.9 Key value parser (HO)}
\Msg{************************************************************************}
\keepsilent
\askforoverwritefalse
\let\MetaPrefix\relax
\preamble
This is a generated file.
Copyright (C) 2006, 2007, 2009, 2010 by
Heiko Oberdiek <heiko.oberdiek at googlemail.com>
This work may be distributed and/or modified under the
conditions of the LaTeX Project Public License, either
version 1.3c of this license or (at your option) any later
version. This version of this license is in
http://www.latex-project.org/lppl/lppl-1-3c.txt
and the latest version of this license is in
http://www.latex-project.org/lppl.txt
and version 1.3 or later is part of all distributions of
LaTeX version 2005/12/01 or later.
This work has the LPPL maintenance status "maintained".
This Current Maintainer of this work is Heiko Oberdiek.
The Base Interpreter refers to any `TeX-Format',
because some files are installed in TDS:tex/generic//.
This work consists of the main source file kvsetkeys.dtx
and the derived files
kvsetkeys.sty, kvsetkeys.pdf, kvsetkeys.ins, kvsetkeys.drv,
kvsetkeys-example.tex, kvsetkeys-test1.tex,
kvsetkeys-test2.tex, kvsetkeys-test3.tex.
\endpreamble
\let\MetaPrefix\DoubleperCent
\generate{%
\file{kvsetkeys.ins}{\from{kvsetkeys.dtx}{install}}%
\file{kvsetkeys.drv}{\from{kvsetkeys.dtx}{driver}}%
\usedir{tex/generic/oberdiek}%
\file{kvsetkeys.sty}{\from{kvsetkeys.dtx}{package}}%
\usedir{doc/latex/oberdiek}%
\file{kvsetkeys-example.tex}{\from{kvsetkeys.dtx}{example}}%
\usedir{doc/latex/oberdiek/test}%
\file{kvsetkeys-test1.tex}{\from{kvsetkeys.dtx}{test1}}%
\file{kvsetkeys-test2.tex}{\from{kvsetkeys.dtx}{test2}}%
\file{kvsetkeys-test3.tex}{\from{kvsetkeys.dtx}{test2,noetex}}%
}
\catcode32=13\relax% active space
\let =\space%
\Msg{************************************************************************}
\Msg{*}
\Msg{* To finish the installation you have to move the following}
\Msg{* file into a directory searched by TeX:}
\Msg{*}
\Msg{* kvsetkeys.sty}
\Msg{*}
\Msg{* And install the following script file:}
\Msg{*}
\Msg{* }
\Msg{*}
\Msg{* To produce the documentation run the file `kvsetkeys.drv'}
\Msg{* through LaTeX.}
\Msg{*}
\Msg{* Happy TeXing!}
\Msg{*}
\Msg{************************************************************************}
\endbatchfile
%</install>
%<*ignore>
\fi
%</ignore>
%<*driver>
\NeedsTeXFormat{LaTeX2e}
\ProvidesFile{kvsetkeys.drv}%
[2010/03/01 v1.9 Key value parser (HO)]%
\documentclass{ltxdoc}
\usepackage{holtxdoc}[2008/08/11]
\begin{document}
\DocInput{kvsetkeys.dtx}%
\end{document}
%</driver>
% \fi
%
% \CheckSum{1135}
%
% \CharacterTable
% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
% Digits \0\1\2\3\4\5\6\7\8\9
% Exclamation \! Double quote \" Hash (number) \#
% Dollar \$ Percent \% Ampersand \&
% Acute accent \' Left paren \( Right paren \)
% Asterisk \* Plus \+ Comma \,
% Minus \- Point \. Solidus \/
% Colon \: Semicolon \; Less than \<
% Equals \= Greater than \> Question mark \?
% Commercial at \@ Left bracket \[ Backslash \\
% Right bracket \] Circumflex \^ Underscore \_
% Grave accent \` Left brace \{ Vertical bar \|
% Right brace \} Tilde \~}
%
% \GetFileInfo{kvsetkeys.drv}
%
% \title{The \xpackage{kvsetkeys} package}
% \date{2010/03/01 v1.9}
% \author{Heiko Oberdiek\\\xemail{heiko.oberdiek at googlemail.com}}
%
% \maketitle
%
% \begin{abstract}
% Package \xpackage{kvsetkeys} provides \cs{kvsetkeys}, a variant
% of package \xpackage{keyval}'s \cs{setkeys}. It allows to specify
% a handler that deals with unknown options. Active commas and equal
% signs may be used (e.g. see \xpackage{babel}'s shorthands) and
% only one level of curly braces is removed from the values.
% \end{abstract}
%
% \tableofcontents
%
% \def\M#1{\texttt{\{}\meta{#1}\texttt{\}}}
%
% \section{Documentation}
%
% First I want to recommend the very good review article
% ``A guide to key-value methods'' by Joseph Wright \cite{tb94wright}.
% It introduces the different key-value packages and compares them.
%
% \subsection{Motivation}
%
% \cs{kvsetkeys} serves as replacement for \xpackage{keyval}'s
% \cs{setkeys}. It basically uses the same syntax. But the
% implementation is more robust and predictable:
% \begin{description}
% \item[Active syntax characters:]
% Comma `|,|' and the equals sign `|=|' are used inside
% key value lists as syntax characters. Package \xpackage{keyval}
% uses the catcode of the characters that is active during
% package loading, usually this is catcode 12 (other).
% But it can happen that the catcode setting of the syntax characters
% changes. Especially active characters are of interest, because
% some language adaptations uses them. For example, option \xoption{turkish}
% of package \xpackage{babel} uses the equals sign as active shorthand
% character. Therefore package \xpackage{kvsetkeys} deals with
% both catcode settings 12 (other) and 13 (active).
% \item[Brace removal:]
% Package \xpackage{keyval}'s \cs{setkeys} removes up to two
% levels of curly braces around the value in some unpredictable way:
%\begin{quote}
%|\setkeys{fam}{key={{value}}} || || | $\rightarrow$ |value|\\
%|\setkeys{fam}{key={{{value}}}} | $\rightarrow$ |{value}|\\
%|\setkeys{fam}{key= {{{value}}}}| $\rightarrow$ |{{value}}|
%\end{quote}
% This package \xpackage{kvsetkeys} follows a much stronger rule:
% Exactly one level of braces are removed from an item, if the
% item is surrounded by curly braces. An item can be a
% the key value pair, the key or the value.
%\begin{quote}
%|\kvsetkeys{fam}{key={value}} || | $\rightarrow$ |value|\\
%|\kvsetkeys{fam}{key={{value}} | $\rightarrow$ |{value}|\\
%|\kvsetkeys{fam}{key= {{value}}| $\rightarrow$ |{value}|
%\end{quote}
% \item[Arbitrary values:] Unmatched conditionals are supported.
% \end{description}
%
% Before I describe
% \cs{kvsetkeys} in more detail, first I want to explain, how
% this package deals with key value lists. For the package also
% provides low level interfaces that can be used by package authors.
%
% \subsection{Normalizing key value lists}
%
% \begin{declcs}{kv@normalize}\,\M{key value list}
% \end{declcs}
% If the user specifies key value lists, he usually prefers
% nice formatted source code, e.g.:
% \begin{quote}
%\begin{verbatim}
%\hypersetup{
% pdftitle = {...},
% pdfsubject = {...},
% pdfauthor = {...},
% pdfkeywords = {...},
% ...
%}
%\end{verbatim}
% \end{quote}
% Thus there can be spaces around keys, around |=| or around the value.
% Also empty entries are possible by too many commas. Therefore these
% spaces and empty entries are silently removed by package \xpackage{keyval}
% and this package. Whereas the contents of the value can be protected
% by curly braces, especially if spaces or commas are used inside,
% a key name must not use spaces or other syntax characters.
%
% \cs{kv@normalize} takes a key value list and performs the cleanup:
% \begin{itemize}
% \item Spaces are removed.
% \item Syntax characters (comma and equal sign) that are active
% are replaced by the same characters with standard catcode.
% (Example: \xpackage{babel}'s language option \xoption{turkish}
% uses the equal sign as active shorthand character.)
% \end{itemize}
% The result is stored in \cs{kv@list}, e.g.:
% \begin{quote}
% |\kv@list| $\rightarrow$ |,pdftitle={...},pdfsubject={...},...,|
% \end{quote}
% Curly braces around values (or keys) remain untouched.
% \begin{description}
% \item[v1.3+:]
% One comma is added in front of the list and each pair ends with
% a comma. Thus an empty list consists of one comma, otherwise
% two commas encloses the list. Empty entries other than the first
% are removed.
% \item[v1.0 -- v1.2:]
% Empty entries are removed later. In fact it adds a comma at the begin
% and end to protect the last value and an easier implementation.
% \end{description}
%
% \subsection{Parsing key value lists}
%
% \begin{declcs}{kv@parse}\,\M{key value list}\,\M{processor}
% \end{declcs}
% It is easier to parse a normalized list, thus \cs{kv@parse}
% normalizes the list and calls \cs{kv@parse@normalized}.
%
% \begin{declcs}{kv@parse@normalized}\,\M{key value list}%
% \,\M{processor}
% \end{declcs}
% Now the key value list is split into single key value pairs.
% For further processing the key and value are given as arguments
% for the \meta{processor}:
% \begin{quote}
% \meta{processor}\,\M{key}\,\M{value}
% \end{quote}
% Also key and value are stored in macro names:
% \begin{itemize}
% \item \cs{kv@key} stores the key.
% \item \cs{kv@value} stores the value or if the value was not
% specified it has the meaning \cs{relax}.
% \end{itemize}
% The behaviour in pseudo code:
% \begin{quote}
% foreach (\meta{key}, \meta{value}) in (\meta{key value list})\\
% \hspace*{1.5em}\cs{kv@key} := \meta{key}\\
% \hspace*{1.5em}\cs{kv@value} := \meta{value}\\
% \hspace*{1.5em}\meta{processor}\,\M{key}\,\M{value}
% \end{quote}
%
% \subsection{Processing key value pairs}
%
% \begin{declcs}{kv@processor@default}\,\M{family}\,\M{key}\,\M{value}
% \end{declcs}
% There are many possiblities to process key value pairs.
% \cs{kv@processor@default} is the processor used in \cs{kvsetkeys}.
% It reimplements and extends the behaviour of
% \xpackage{keyval}'s \cs{setkeys}.
% In case of unknown keys \cs{setkeys} raise an error.
% This processer, however, calls a handler instead, if it
% is provided by the family.
%
% The behaviour in pseudo code:
% \begin{quote}
% if \meta{key} exists\\
% \hspace*{1.5em}call the keyval code of \meta{key}\\
% else\\
% \hspace*{1.5em}if \meta{handler} for \meta{family} exists\\
% \hspace*{3em}\meta{handler}\,\M{key}\,\M{value}\\
% \hspace*{1.5em}else\\
% \hspace*{3em}raise unknown key error\\
% \hspace*{1.5em}fi\\
% fi
% \end{quote}
%
% \subsection{Default family handler}
%
% \cs{kv@processor@default} calls \meta{handler}, the default
% handler for the family, if the key does not exist in the family.
% The handler is called with two arguments, the key and the value.
% It can be defined with \cs{kv@set@family@hander}:
%
% \begin{declcs}{kv@set@family@handler}\,\M{family}\,\M{handler definition}
% \end{declcs}
% This sets the default family handler for the keyval family
% \meta{family}. Inside \meta{handler definition} |#1| stands for
% the key and |#2| is the value. Also \cs{kv@key} and \cs{kv@value}
% can be used for the key and the value. If the value is not given,
% \cs{kv@value} has the meaning \cs{relax}.
%
% \subsection{Put it all together}
%
% \begin{declcs}{kvsetkeys}\,\M{family}\,\M{key value list}
% \end{declcs}
% The work is done by the previous commands. \cs{kvsetkeys}
% just calls them:
% \begin{quote}
% \cs{kv@parse}\,\M{key value list}^^A
% \texttt{\{}\cs{kv@processor@default}\,\M{family}\texttt{\}}
% \end{quote}
%
% Thus you can replace \cs{setkeys} of package \xpackage{keyval}
% by the key value parser of this package:
% \begin{quote}
% |\renewcommand*{\setkeys}{\kvsetkeys}|\\
% or\\
% |\let\setkeys\kvsetkeys|
% \end{quote}
%
% \subsection{Comma separated lists}
%
% Since version 2007/09/29 v1.3 this package also supports the normalizing
% and parsing of general comma separated lists.
%
% \begin{declcs}{comma@normalize}\,\M{comma list}
% \end{declcs}
% Macro \cs{comma@normalize} normalizes the comma separated list,
% removes spaces around commas. The result is put in macro \cs{comma@list}.
%
% \begin{declcs}{comma@parse}\,\M{comma list}\,\M{processor}
% \end{declcs}
% Macro \cs{comma@parse} first normalizes the comma separated list
% and then parses the list by calling \cs{comma@parse@normalized}.
%
% \begin{declcs}{comma@parse@normalized}\,\M{normalized comma list}^^A
% \,\M{processor}
% \end{declcs}
% The list is parsed. Empty entries are ignored. \meta{processor}
% is called for each non-empty entry with the entry as argument:
% \begin{quote}
% \meta{processor}|{|\meta{entry}|}|
% \end{quote}
% Also the entry is stored in the macro \cs{comma@entry}.
%
% \section{Example}
%
% The following example prints a short piece of HTML code using
% the tabbing environment for indenting purpose and a key value
% syntax for specifying the attributes of an HTML tag.
% The example illustrates the use of a default family handler.
% \begin{macrocode}
%<*example>
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{kvsetkeys}
\usepackage{keyval}
\makeatletter
\newcommand*{\tag}[2][]{%
% #1: attributes
% #2: tag name
\begingroup
\toks@={}%
\let\@endslash\@empty
\kvsetkeys{tag}{#1}%
\texttt{%
\textless #2\the\toks@\@endslash\textgreater
}%
\endgroup
}
\kv@set@family@handler{tag}{%
% #1: key
% #2: value
\toks@\expandafter{%
\the\toks@
\space
#1=\string"#2\string"%
}%
}
\define@key{tag}{/}[]{%
\def\@endslash{/}%
}
\makeatother
\begin{document}
\begin{tabbing}
\mbox{}\qquad\=\qquad\=\kill
\tag{html}\\
\>\dots\\
\>\tag[border=1]{table}\\
\>\>\tag[width=200, span=3, /]{colgroup}\\
\>\>\dots\\
\>\tag{/table}\\
\>\dots\\
\tag{/html}\\
\end{tabbing}
\end{document}
%</example>
% \end{macrocode}
%
% \StopEventually{
% }
%
% \section{Implementation}
%
% \subsection{Identification}
%
% \begin{macrocode}
%<*package>
% \end{macrocode}
% Reload check, especially if the package is not used with \LaTeX.
% \begin{macrocode}
\begingroup
\catcode44 12 % ,
\catcode45 12 % -
\catcode46 12 % .
\catcode58 12 % :
\catcode64 11 % @
\catcode123 1 % {
\catcode125 2 % }
\expandafter\let\expandafter\x\csname ver@kvsetkeys.sty\endcsname
\ifx\x\relax % plain-TeX, first loading
\else
\def\empty{}%
\ifx\x\empty % LaTeX, first loading,
% variable is initialized, but \ProvidesPackage not yet seen
\else
\catcode35 6 % #
\expandafter\ifx\csname PackageInfo\endcsname\relax
\def\x#1#2{%
\immediate\write-1{Package #1 Info: #2.}%
}%
\else
\def\x#1#2{\PackageInfo{#1}{#2, stopped}}%
\fi
\x{kvsetkeys}{The package is already loaded}%
\aftergroup\endinput
\fi
\fi
\endgroup
% \end{macrocode}
% Package identification:
% \begin{macrocode}
\begingroup
\catcode35 6 % #
\catcode40 12 % (
\catcode41 12 % )
\catcode44 12 % ,
\catcode45 12 % -
\catcode46 12 % .
\catcode47 12 % /
\catcode58 12 % :
\catcode64 11 % @
\catcode91 12 % [
\catcode93 12 % ]
\catcode123 1 % {
\catcode125 2 % }
\expandafter\ifx\csname ProvidesPackage\endcsname\relax
\def\x#1#2#3[#4]{\endgroup
\immediate\write-1{Package: #3 #4}%
\xdef#1{#4}%
}%
\else
\def\x#1#2[#3]{\endgroup
#2[{#3}]%
\ifx#1\@undefined
\xdef#1{#3}%
\fi
\ifx#1\relax
\xdef#1{#3}%
\fi
}%
\fi
\expandafter\x\csname ver@kvsetkeys.sty\endcsname
\ProvidesPackage{kvsetkeys}%
[2010/03/01 v1.9 Key value parser (HO)]
% \end{macrocode}
%
% \begin{macrocode}
\begingroup
\catcode123 1 % {
\catcode125 2 % }
\def\x{\endgroup
\expandafter\edef\csname KVS@AtEnd\endcsname{%
\catcode35 \the\catcode35\relax
\catcode64 \the\catcode64\relax
\catcode123 \the\catcode123\relax
\catcode125 \the\catcode125\relax
}%
}%
\x
\catcode35 6 % #
\catcode64 11 % @
\catcode123 1 % {
\catcode125 2 % }
\def\TMP@EnsureCode#1#2{%
\edef\KVS@AtEnd{%
\KVS@AtEnd
\catcode#1 \the\catcode#1\relax
}%
\catcode#1 #2\relax
}
\TMP@EnsureCode{36}{3}% $
\TMP@EnsureCode{38}{4}% &
\TMP@EnsureCode{39}{12}% '
\TMP@EnsureCode{44}{12}% ,
\TMP@EnsureCode{46}{12}% .
\TMP@EnsureCode{47}{12}% /
\TMP@EnsureCode{61}{12}% =
\TMP@EnsureCode{94}{7}% ^ (superscript)
\TMP@EnsureCode{96}{12}% `
\TMP@EnsureCode{126}{13}% ~ (active)
% \end{macrocode}
%
% \subsection{Package loading}
%
% \begin{macrocode}
\begingroup\expandafter\expandafter\expandafter\endgroup
\expandafter\ifx\csname RequirePackage\endcsname\relax
\input infwarerr.sty\relax
\input etexcmds.sty\relax
\else
\RequirePackage{infwarerr}[2007/09/09]%
\RequirePackage{etexcmds}[2010/01/28]%
\fi
% \end{macrocode}
%
% \begin{macrocode}
\expandafter\ifx\csname toks@\endcsname\relax
\toksdef\toks@=0 %
\fi
% \end{macrocode}
%
% \subsection{Check for \eTeX}
%
% \cs{unexpanded}, \cs{ifcsname}, and \cs{unless} are used if found.
% \begin{macrocode}
\begingroup\expandafter\endgroup
\ifcase0\ifetex@unexpanded
\expandafter\ifx\csname ifcsname\endcsname\relax
\else
\expandafter\ifx\csname unless\endcsname\relax
\else
1%
\fi
\fi
\fi
\catcode`\$=9 % ignore
\catcode`\&=14 % comment
\else % e-TeX
\catcode`\$=14 % comment
\catcode`\&=9 % ignore
\fi
% \end{macrocode}
%
% \subsection{Generic help macros}
%
% \begin{macro}{\KVS@Empty}
% \begin{macrocode}
\def\KVS@Empty{}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\KVS@FirstOfTwo}
% \begin{macrocode}
\long\def\KVS@FirstOfTwo#1#2{#1}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\KVS@SecondOfTwo}
% \begin{macrocode}
\long\def\KVS@SecondOfTwo#1#2{#2}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\KVS@IfEmpty}
% \begin{macrocode}
\long\def\KVS@IfEmpty#1{%
& \edef\KVS@Temp{\etex@unexpanded{#1}}%
$ \begingroup
$ \toks@{#1}%
$ \edef\KVS@Temp{\the\toks@}%
$ \expandafter\endgroup
\ifx\KVS@Temp\KVS@Empty
\expandafter\KVS@FirstOfTwo
\else
\expandafter\KVS@SecondOfTwo
\fi
}
% \end{macrocode}
% \end{macro}
%
% \subsection{Normalizing}
%
% \begin{macro}{\kv@normalize}
% \begin{macrocode}
\long\def\kv@normalize#1{%
\begingroup
\toks@{,#1,}%
\KVS@Comma
\KVS@SpaceComma{ }%
\KVS@CommaSpace
\KVS@CommaComma
\KVS@Equals
\KVS@SpaceEquals{ }%
\KVS@EqualsSpace
\xdef\KVS@Global{\the\toks@}%
\endgroup
\let\kv@list\KVS@Global
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\comma@normalize}
% \begin{macrocode}
\def\comma@normalize#1{%
\begingroup
\toks@{,#1,}%
\KVS@Comma
\KVS@SpaceComma{ }%
\KVS@CommaSpace
\KVS@CommaComma
\xdef\KVS@Global{\the\toks@}%
\endgroup
\let\comma@list\KVS@Global
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\KVS@Comma}
% Converts active commas into comma with catcode other.
% Also adds a comma at the end to protect the last value
% for next cleanup steps.
% \begin{macrocode}
\begingroup
\lccode`\,=`\,%
\lccode`\~=`\,%
\lowercase{\endgroup
\def\KVS@Comma{%
\toks@\expandafter{\expandafter}\expandafter
\KVS@@Comma\the\toks@~\KVS@Nil
}%
\long\def\KVS@@Comma#1~#2\KVS@Nil{%
\toks@\expandafter{\the\toks@#1}%
\KVS@IfEmpty{#2}{%
}{%
\KVS@@Comma,#2\KVS@Nil
}%
}%
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\KVS@SpaceComma}
% Removes spaces before the comma, may add commas at the end.
% \begin{macrocode}
\long\def\KVS@SpaceComma#1{%
\expandafter\KVS@@SpaceComma\the\toks@#1,\KVS@Nil
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\KVS@@SpaceComma}
% \begin{macrocode}
\long\def\KVS@@SpaceComma#1 ,#2\KVS@Nil{%
\KVS@IfEmpty{#2}{%
\toks@{#1}%
}{%
\toks@{#1,#2}%
\expandafter\KVS@@SpaceComma\the\toks@\KVS@Nil
}%
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\KVS@CommaSpace}
% Removes spaces after the comma, may add commas at the end.
% \begin{macrocode}
\def\KVS@CommaSpace{%
\expandafter\KVS@@CommaSpace\the\toks@, \KVS@Nil
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\KVS@@CommaSpace}
% \begin{macrocode}
\long\def\KVS@@CommaSpace#1, #2\KVS@Nil{%
\KVS@IfEmpty{#2}{%
\toks@{#1}%
}{%
\toks@{#1,#2}%
\expandafter\KVS@@CommaSpace\the\toks@\KVS@Nil
}%
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\KVS@CommaComma}
% Replaces multiple commas by one comma.
% \begin{macrocode}
\def\KVS@CommaComma{%
\expandafter\KVS@@CommaComma\the\toks@,\KVS@Nil
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\KVS@@CommaComma}
% \begin{macrocode}
\long\def\KVS@@CommaComma#1,,#2\KVS@Nil{%
\toks@{#1,#2}%
\KVS@IfEmpty{#2}{%
}{%
\expandafter\KVS@@CommaComma\the\toks@\KVS@Nil
}%
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\KVS@Equals}
% Converts active equals signs into catcode other characters.
% \begin{macrocode}
\begingroup
\lccode`\==`\=%
\lccode`\~=`\=%
\lowercase{\endgroup
\def\KVS@Equals{%
\toks@\expandafter{\expandafter}\expandafter
\KVS@@Equals\the\toks@~\KVS@Nil
}%
\long\def\KVS@@Equals#1~#2\KVS@Nil{%
\edef\KVS@Temp{\the\toks@}%
\ifx\KVS@Temp\KVS@Empty
\expandafter\KVS@FirstOfTwo
\else
\expandafter\KVS@SecondOfTwo
\fi
{%
\toks@{#1}%
}{%
\toks@\expandafter{\the\toks@=#1}%
}%
\KVS@IfEmpty{#2}{%
}{%
\KVS@@Equals#2\KVS@Nil
}%
}%
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\KVS@SpaceEquals}
% Removes spaces before the equals sign.
% \begin{macrocode}
\long\def\KVS@SpaceEquals#1{%
\expandafter\KVS@@SpaceEquals\the\toks@#1=\KVS@Nil
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\KVS@@SpaceEquals}
% \begin{macrocode}
\long\def\KVS@@SpaceEquals#1 =#2\KVS@Nil{%
\KVS@IfEmpty{#2}{%
\toks@{#1}%
}{%
\toks@{#1=#2}%
\expandafter\KVS@@SpaceEquals\the\toks@\KVS@Nil
}%
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\KVS@EqualsSpace}
% Removes spaces after the equals sign.
% \begin{macrocode}
\def\KVS@EqualsSpace{%
\expandafter\KVS@@EqualsSpace\the\toks@= \KVS@Nil
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\KVS@@EqualsSpace}
% \begin{macrocode}
\long\def\KVS@@EqualsSpace#1= #2\KVS@Nil{%
\KVS@IfEmpty{#2}{%
\toks@{#1}%
}{%
\toks@{#1=#2}%
\expandafter\KVS@@EqualsSpace\the\toks@\KVS@Nil
}%
}
% \end{macrocode}
% \end{macro}
%
% \subsection{Parsing key value lists}
%
% \begin{macro}{\kv@parse}
% Normalizes and parses the key value list. Also sets \cs{kv@list}.
% \begin{macrocode}
\long\def\kv@parse#1{%
\kv@normalize{#1}%
\expandafter\kv@parse@normalized\expandafter{\kv@list}%
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\kv@parse@normalized}
% |#1|: key value list\\
% |#2|: processor
% \begin{macrocode}
\long\def\kv@parse@normalized#1#2{%
\KVS@Parse#1,\KVS@Nil{#2}%
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\KVS@Parse}
% |#1,#2|: key value list\\
% |#3|: processor
% \begin{macrocode}
\long\def\KVS@Parse#1,#2\KVS@Nil#3{%
\KVS@IfEmpty{#1}{%
}{%
\KVS@Process#1=\KVS@Nil{#3}%
}%
\KVS@IfEmpty{#2}{%
}{%
\KVS@Parse#2\KVS@Nil{#3}%
}%
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\KVS@Process}
% |#1|: key\\
% |#2|: value, |=|\\
% |#3|: processor
% \begin{macrocode}
\long\def\KVS@Process#1=#2\KVS@Nil#3{%
\def\kv@key{#1}%
\KVS@IfEmpty{#2}{%
\let\kv@value\relax
#3{#1}{}%
}{%
\KVS@@Process{#1}#2\KVS@Nil{#3}%
}%
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\KVS@@Process}
% |#1|: key\\
% |#2|: value\\
% |#3|: processor
% \begin{macrocode}
\long\def\KVS@@Process#1#2=\KVS@Nil#3{%
& \edef\kv@value{\etex@unexpanded{#2}}%
$ \begingroup
$ \toks@{#2}%
$ \xdef\KVS@Global{\the\toks@}%
$ \endgroup
$ \let\kv@value\KVS@Global
#3{#1}{#2}%
}
% \end{macrocode}
% \end{macro}
%
% \subsection{Parsing comma lists}
%
% \begin{macro}{\comma@parse}
% Normalizes and parses the key value list. Also sets \cs{comma@list}.
% \begin{macrocode}
\def\comma@parse#1{%
\comma@normalize{#1}%
\expandafter\comma@parse@normalized\expandafter{\comma@list}%
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\comma@parse@normalized}
% |#1|: comma list\\
% |#2|: processor
% \begin{macrocode}
\def\comma@parse@normalized#1#2{%
\KVS@CommaParse#1,\KVS@Nil{#2}%
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\KVS@CommaParse}
% |#1,#2|: comma list\\
% |#3|: processor
% \begin{macrocode}
\def\KVS@CommaParse#1,#2\KVS@Nil#3{%
\KVS@IfEmpty{#1}{%
}{%
\def\comma@entry{#1}%
#3{#1}%
}%
\KVS@IfEmpty{#2}{%
}{%
\KVS@CommaParse#2\KVS@Nil{#3}%
}%
}
% \end{macrocode}
% \end{macro}
%
% \subsection{Processing key value pairs}
%
% \begin{macro}{\kv@processor@default}
% \begin{macrocode}
\long\def\kv@processor@default#1#2#3{%
& \unless\ifcsname KV@#1@#2\endcsname
$ \begingroup\expandafter\expandafter\expandafter\endgroup
$ \expandafter\ifx\csname KV@#1@#2\endcsname\relax
& \unless\ifcsname KVS@#1@handler\endcsname
$ \begingroup\expandafter\expandafter\expandafter\endgroup
$ \expandafter\ifx\csname KVS@#1@handler\endcsname\relax
\kv@error@unknownkey{#1}{#2}%
\else
\csname KVS@#1@handler\endcsname{#2}{#3}%
\relax
\fi
\else
\ifx\kv@value\relax
& \unless\ifcsname KV@#1@#2@default\endcsname
$ \begingroup\expandafter\expandafter\expandafter\endgroup
$ \expandafter\ifx\csname KV@#1@#2@default\endcsname\relax
\kv@error@novalue{#1}{#2}%
\else
\csname KV@#1@#2@default\endcsname
\relax
\fi
\else
\csname KV@#1@#2\endcsname{#3}%
\fi
\fi
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\kv@set@family@handler}
% \begin{macrocode}
\def\kv@set@family@handler#1{%
\KVS@SetFamilyHandler{#1}\@nil
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\KVS@SetFamilyHandler}
% \begin{macrocode}
\def\KVS@SetFamilyHandler#1\@nil#{%
\expandafter\def\csname KVS@#1@handler\endcsname##1##2%
}
% \end{macrocode}
% \end{macro}
%
% \subsection{Error handling}
%
% \begin{macro}{\kv@error@novalue}
% \begin{macrocode}
\def\kv@error@novalue{%
\kv@error@generic{No value specified for}%
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\kv@error@unknownkey}
% \begin{macrocode}
\def\kv@error@unknownkey{%
\kv@error@generic{Undefined}%
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\kv@error@generic}
% \begin{macrocode}
\def\kv@error@generic#1#2#3{%
\@PackageError{kvsetkeys}{%
#1 key `#3'%
}{%
The keyval family of the key `#3' is `#2'.\MessageBreak
\MessageBreak
\@ehc
}%
}
% \end{macrocode}
% \end{macro}
%
% \subsection{Do it all}
%
% \begin{macro}{\kvsetkeys}
% \begin{macrocode}
\long\def\kvsetkeys#1#2{%
\kv@parse{#2}{\kv@processor@default{#1}}%
}
% \end{macrocode}
% \end{macro}
%
% \begin{macrocode}
\KVS@AtEnd
%</package>
% \end{macrocode}
%
% \section{Test}
%
% \subsection{Catcode checks for loading}
%
% \begin{macrocode}
%<*test1>
% \end{macrocode}
% \begin{macrocode}
\catcode`\{=1 %
\catcode`\}=2 %
\catcode`\#=6 %
\catcode`\@=11 %
\expandafter\ifx\csname count@\endcsname\relax
\countdef\count@=255 %
\fi
\expandafter\ifx\csname @gobble\endcsname\relax
\long\def\@gobble#1{}%
\fi
\expandafter\ifx\csname @firstofone\endcsname\relax
\long\def\@firstofone#1{#1}%
\fi
\expandafter\ifx\csname loop\endcsname\relax
\expandafter\@firstofone
\else
\expandafter\@gobble
\fi
{%
\def\loop#1\repeat{%
\def\body{#1}%
\iterate
}%
\def\iterate{%
\body
\let\next\iterate
\else
\let\next\relax
\fi
\next
}%
\let\repeat=\fi
}%
\def\RestoreCatcodes{}
\count@=0 %
\loop
\edef\RestoreCatcodes{%
\RestoreCatcodes
\catcode\the\count@=\the\catcode\count@\relax
}%
\ifnum\count@<255 %
\advance\count@ 1 %
\repeat
\def\RangeCatcodeInvalid#1#2{%
\count@=#1\relax
\loop
\catcode\count@=15 %
\ifnum\count@<#2\relax
\advance\count@ 1 %
\repeat
}
\expandafter\ifx\csname LoadCommand\endcsname\relax
\def\LoadCommand{\input kvsetkeys.sty\relax}%
\fi
\def\Test{%
\RangeCatcodeInvalid{0}{47}%
\RangeCatcodeInvalid{58}{64}%
\RangeCatcodeInvalid{91}{96}%
\RangeCatcodeInvalid{123}{255}%
\catcode`\@=12 %
\catcode`\\=0 %
\catcode`\{=1 %
\catcode`\}=2 %
\catcode`\#=6 %
\catcode`\[=12 %
\catcode`\]=12 %
\catcode`\%=14 %
\catcode`\ =10 %
\catcode13=5 %
\LoadCommand
\RestoreCatcodes
}
\Test
\csname @@end\endcsname
\end
% \end{macrocode}
% \begin{macrocode}
%</test1>
% \end{macrocode}
%
% \subsection{Macro tests}
%
% \subsubsection{Preamble}
%
% \begin{macrocode}
%<*test2>
\NeedsTeXFormat{LaTeX2e}
\nofiles
\documentclass{article}
%<noetex>\let\SavedUnexpanded\unexpanded
%<noetex>\let\unexpanded\UNDEFINED
\makeatletter
\chardef\KVS@TestMode=1 %
\makeatother
\usepackage{kvsetkeys}[2010/03/01]
%<noetex>\let\unexpanded\SavedUnexpanded
\usepackage{qstest}
\IncludeTests{*}
\LogTests{log}{*}{*}
% \end{macrocode}
%
% \subsubsection{Time}
%
% \begin{macrocode}
\begingroup\expandafter\expandafter\expandafter\endgroup
\expandafter\ifx\csname pdfresettimer\endcsname\relax
\else
\makeatletter
\newcount\SummaryTime
\newcount\TestTime
\SummaryTime=\z@
\newcommand*{\PrintTime}[2]{%
\typeout{%
[Time #1: \strip@pt\dimexpr\number#2sp\relax\space s]%
}%
}%
\newcommand*{\StartTime}[1]{%
\renewcommand*{\TimeDescription}{#1}%
\pdfresettimer
}%
\newcommand*{\TimeDescription}{}%
\newcommand*{\StopTime}{%
\TestTime=\pdfelapsedtime
\global\advance\SummaryTime\TestTime
\PrintTime\TimeDescription\TestTime
}%
\let\saved@qstest\qstest
\let\saved@endqstest\endqstest
\def\qstest#1#2{%
\saved@qstest{#1}{#2}%
\StartTime{#1}%
}%
\def\endqstest{%
\StopTime
\saved@endqstest
}%
\AtEndDocument{%
\PrintTime{summary}\SummaryTime
}%
\makeatother
\fi
% \end{macrocode}
%
% \subsubsection{Test sets}
%
% \begin{macrocode}
\makeatletter
\def\@makeactive#1{%
\catcode`#1=13\relax
}
\@makeactive\,
\def,{\errmessage{COMMA}}
\@makeother\,
\@makeactive\=
\def={\errmessage{EQUALS}}
\@makeother\=
\begin{qstest}{normalize}{normalize,active-chars,space-removal}%
\long\def\Test#1#2{%
\@makeother\,%
\@makeother\=%
\scantokens{\toks@={#2}}%
\edef\Result{\the\toks@}%
\@makeother\,%
\@makeother\=%
\@Test{#1}%
\@makeactive\,%
\@Test{#1}%
\@makeactive\=%
\@Test{#1}%
\@makeother\,%
\@Test{#1}%
\@makeother\=%
}%
\long\def\@Test#1{%
\scantokens{\kv@normalize{#1}}%
\expandafter\expandafter\expandafter\Expect
\expandafter\expandafter\expandafter
{\expandafter\kv@list\expandafter}\expandafter{\Result}%
\Expect*{\ifx\kv@list\Result true\else false\fi}{true}%
}%
\Test{}{,}%
\Test{,}{,}%
\Test{,,}{,}%
\Test{,,,}{,}%
\Test{ , }{,}%
\Test{{a}}{,{a},}%
\Test{,{a}}{,{a},}%
\Test{{a},}{,{a},}%
\Test{{a},{b}}{,{a},{b},}%
\Test{{b}={c},{}=,{}={},{d}=}{,{b}={c},{}=,{}={},{d}=,}%
\Test{{}}{,{},}%
\Test{{},{},{}}{,{},{},{},}%
\Test{=}{,=,}%
\Test{=,=,=}{,=,=,=,}%
\Test{a=\par}{,a=\par,}%
\Test{\par}{,\par,}%
\def\TestSet#1{%
\Test{#1#1}{,}%
\Test{#1#1,#1#1}{,}%
\Test{#1#1,#1#1,#1#1}{,}%
\Test{#1#1#1#1#1}{,}%
\Test{{a}#1#1=#1#1{b}}{,{a}={b},}%
}%
\TestSet{ }%
\begingroup
\let\saved@normalize\kv@normalize
\def\kv@normalize#1{%
\saved@normalize{#1}%
\@onelevel@sanitize\kv@list
\@onelevel@sanitize\Result
}%
\Test{#,#=#,{#}={#},{#}=,{#}}{,#,#=#,{#}={#},{#}=,{#},}%
\endgroup
\begingroup
\def\Test#1#2{%
\edef\Result{#2}%
\@Test{#1}%
}%
\Test{{ a = b }}{,{ a = b },}%
\@makeactive\,%
\Test{{,}}{\string,{\noexpand,}\string,}%
\@makeother\,%
\@makeactive\=%
\Test{a={=}}{,a\string={\noexpand=},}%
\endgroup
\Test{a=b}{,a=b,}%
\Test{a={b}}{,a={b},}%
\Test{a ={b}}{,a={b},}%
\Test{a= {b}}{,a={b},}%
\Test{a = {b}}{,a={b},}%
\Test{a = {b} ,}{,a={b},}%
\Test{a}{,a,}%
\Test{ a}{,a,}%
\Test{a }{,a,}%
\Test{ a }{,a,}%
\Test{, a ,}{,a,}%
\Test{, a b ,}{,a b,}%
\Test{,a ,}{,a,}%
\Test{ a =}{,a=,}%
\Test{ a = }{,a=,}%
\Test{a =}{,a=,}%
\Test{{a} =}{,{a}=,}%
\Test{{a}= {}}{,{a}={},}%
\Test{, a = {}}{,a={},}%
\Test{a,,b}{,a,b,}%
\Test{a=\fi}{,a=\fi,}%
\Test{a=\iffalse}{,a=\iffalse,}%
\Test{a=\iffalse,b=\fi}{,a=\iffalse,b=\fi,}%
\end{qstest}
\begin{qstest}{parse}{parse,brace-removal}
\def\Processor#1#2{%
\expandafter\Expect\expandafter{\kv@key}{#1}%
\toks@{#2}%
\edef\x{\the\toks@}%
\ifx\kv@value\relax
\Expect*{\the\toks@}{}%
\def\Value{<>}%
\else
\edef\Value{[\the\toks@]}%
\@onelevel@sanitize\Value
\fi
\toks@{#1}%
\ifx\Result\@empty
\edef\Result{[\the\toks@]=\Value}%
\else
\edef\Result{\Result,[\the\toks@]=\Value}%
\fi
\@onelevel@sanitize\Result
}%
\def\Test#1#2{%
\sbox0{%
\let\Result\@empty
\kv@parse{#1}\Processor
\Expect*{\Result}{#2}%
}%
\Expect*{\the\wd0}{0.0pt}%
}%
\Test{}{}%
\Test{{}}{}%
\Test{{{}}}{[]=<>}%
\Test{{{{}}}}{[{}]=<>}%
\Test{a}{[a]=<>}%
\Test{{a}}{[a]=<>}%
\Test{{a}}{[a]=<>}%
\Test{{{a}}}{[a]=<>}%
\Test{{{{a}}}}{[{a}]=<>}%
\Test{a=}{[a]=[]}%
\Test{{a}=}{[a]=[]}%
\Test{{{a}}=}{[{a}]=[]}%
\Test{a={}}{[a]=[]}%
\Test{{a}={{}}}{[a]=[{}]}%
\Test{a=b}{[a]=[b]}%
\Test{a=\fi}{[a]=[\fi]}%
\Test{a=\iffalse}{[a]=[\iffalse]}%
\Test{a=\iffalse,b=\fi}{[a]=[\iffalse],[b]=[\fi]}%
\Test{{ a = b }}{[ a ]=[ b ]}%
\Test{{{ a = b }}}{[ a = b ]=<>}%
\end{qstest}
\begin{qstest}{comma}{comma,parse}
\def\Processor#1{%
\expandafter\Expect\expandafter{\comma@entry}{#1}%
\toks@{#1}%
\ifx\Result\@empty
\edef\Result{[\the\toks@]}%
\else
\edef\Result{\Result,[\the\toks@]}%
\fi
\@onelevel@sanitize\Result
}%
\def\Test#1#2{%
\sbox0{%
\let\Result\@empty
\comma@parse{#1}\Processor
\Expect*{\Result}{#2}%
}%
\Expect*{\the\wd0}{0.0pt}%
}%
\Test{}{}%
\Test{{}}{}%
\Test{{{}}}{[{}]}%
\Test{a}{[a]}%
\Test{{a}}{[a]}%
\Test{{{a}}}{[{a}]}%
\Test{a=}{[a=]}%
\Test{a\fi}{[a\fi]}%
\Test{a\iffalse}{[a\iffalse]}%
\Test{\iffalse,\fi}{[\iffalse],[\fi]}%
\Test{ a , b , c }{[a],[b],[c]}%
\Test{ { } ,{ }, { }, { } , { } }{[ ],[ ],[ ],[ ],[ ]}%
\Test{ {{}} ,{{}}, {{}}, {{}} , {{}} }{[{}],[{}],[{}],[{}],[{}]}%
\end{qstest}
\begin{document}
\end{document}
%</test2>
% \end{macrocode}
%
% \section{Installation}
%
% \subsection{Download}
%
% \paragraph{Package.} This package is available on
% CTAN\footnote{\url{ftp://ftp.ctan.org/tex-archive/}}:
% \begin{description}
% \item[\CTAN{macros/latex/contrib/oberdiek/kvsetkeys.dtx}] The source file.
% \item[\CTAN{macros/latex/contrib/oberdiek/kvsetkeys.pdf}] Documentation.
% \end{description}
%
%
% \paragraph{Bundle.} All the packages of the bundle `oberdiek'
% are also available in a TDS compliant ZIP archive. There
% the packages are already unpacked and the documentation files
% are generated. The files and directories obey the TDS standard.
% \begin{description}
% \item[\CTAN{install/macros/latex/contrib/oberdiek.tds.zip}]
% \end{description}
% \emph{TDS} refers to the standard ``A Directory Structure
% for \TeX\ Files'' (\CTAN{tds/tds.pdf}). Directories
% with \xfile{texmf} in their name are usually organized this way.
%
% \subsection{Bundle installation}
%
% \paragraph{Unpacking.} Unpack the \xfile{oberdiek.tds.zip} in the
% TDS tree (also known as \xfile{texmf} tree) of your choice.
% Example (linux):
% \begin{quote}
% |unzip oberdiek.tds.zip -d ~/texmf|
% \end{quote}
%
% \paragraph{Script installation.}
% Check the directory \xfile{TDS:scripts/oberdiek/} for
% scripts that need further installation steps.
% Package \xpackage{attachfile2} comes with the Perl script
% \xfile{pdfatfi.pl} that should be installed in such a way
% that it can be called as \texttt{pdfatfi}.
% Example (linux):
% \begin{quote}
% |chmod +x scripts/oberdiek/pdfatfi.pl|\\
% |cp scripts/oberdiek/pdfatfi.pl /usr/local/bin/|
% \end{quote}
%
% \subsection{Package installation}
%
% \paragraph{Unpacking.} The \xfile{.dtx} file is a self-extracting
% \docstrip\ archive. The files are extracted by running the
% \xfile{.dtx} through \plainTeX:
% \begin{quote}
% \verb|tex kvsetkeys.dtx|
% \end{quote}
%
% \paragraph{TDS.} Now the different files must be moved into
% the different directories in your installation TDS tree
% (also known as \xfile{texmf} tree):
% \begin{quote}
% \def\t{^^A
% \begin{tabular}{@{}>{\ttfamily}l@{ $\rightarrow$ }>{\ttfamily}l@{}}
% kvsetkeys.sty & tex/generic/oberdiek/kvsetkeys.sty\\
% kvsetkeys.pdf & doc/latex/oberdiek/kvsetkeys.pdf\\
% kvsetkeys-example.tex & doc/latex/oberdiek/kvsetkeys-example.tex\\
% test/kvsetkeys-test1.tex & doc/latex/oberdiek/test/kvsetkeys-test1.tex\\
% test/kvsetkeys-test2.tex & doc/latex/oberdiek/test/kvsetkeys-test2.tex\\
% test/kvsetkeys-test3.tex & doc/latex/oberdiek/test/kvsetkeys-test3.tex\\
% kvsetkeys.dtx & source/latex/oberdiek/kvsetkeys.dtx\\
% \end{tabular}^^A
% }^^A
% \sbox0{\t}^^A
% \ifdim\wd0>\linewidth
% \begingroup
% \advance\linewidth by\leftmargin
% \advance\linewidth by\rightmargin
% \edef\x{\endgroup
% \def\noexpand\lw{\the\linewidth}^^A
% }\x
% \def\lwbox{^^A
% \leavevmode
% \hbox to \linewidth{^^A
% \kern-\leftmargin\relax
% \hss
% \usebox0
% \hss
% \kern-\rightmargin\relax
% }^^A
% }^^A
% \ifdim\wd0>\lw
% \sbox0{\small\t}^^A
% \ifdim\wd0>\linewidth
% \ifdim\wd0>\lw
% \sbox0{\footnotesize\t}^^A
% \ifdim\wd0>\linewidth
% \ifdim\wd0>\lw
% \sbox0{\scriptsize\t}^^A
% \ifdim\wd0>\linewidth
% \ifdim\wd0>\lw
% \sbox0{\tiny\t}^^A
% \ifdim\wd0>\linewidth
% \lwbox
% \else
% \usebox0
% \fi
% \else
% \lwbox
% \fi
% \else
% \usebox0
% \fi
% \else
% \lwbox
% \fi
% \else
% \usebox0
% \fi
% \else
% \lwbox
% \fi
% \else
% \usebox0
% \fi
% \else
% \lwbox
% \fi
% \else
% \usebox0
% \fi
% \end{quote}
% If you have a \xfile{docstrip.cfg} that configures and enables \docstrip's
% TDS installing feature, then some files can already be in the right
% place, see the documentation of \docstrip.
%
% \subsection{Refresh file name databases}
%
% If your \TeX~distribution
% (\teTeX, \mikTeX, \dots) relies on file name databases, you must refresh
% these. For example, \teTeX\ users run \verb|texhash| or
% \verb|mktexlsr|.
%
% \subsection{Some details for the interested}
%
% \paragraph{Attached source.}
%
% The PDF documentation on CTAN also includes the
% \xfile{.dtx} source file. It can be extracted by
% AcrobatReader 6 or higher. Another option is \textsf{pdftk},
% e.g. unpack the file into the current directory:
% \begin{quote}
% \verb|pdftk kvsetkeys.pdf unpack_files output .|
% \end{quote}
%
% \paragraph{Unpacking with \LaTeX.}
% The \xfile{.dtx} chooses its action depending on the format:
% \begin{description}
% \item[\plainTeX:] Run \docstrip\ and extract the files.
% \item[\LaTeX:] Generate the documentation.
% \end{description}
% If you insist on using \LaTeX\ for \docstrip\ (really,
% \docstrip\ does not need \LaTeX), then inform the autodetect routine
% about your intention:
% \begin{quote}
% \verb|latex \let\install=y\input{kvsetkeys.dtx}|
% \end{quote}
% Do not forget to quote the argument according to the demands
% of your shell.
%
% \paragraph{Generating the documentation.}
% You can use both the \xfile{.dtx} or the \xfile{.drv} to generate
% the documentation. The process can be configured by the
% configuration file \xfile{ltxdoc.cfg}. For instance, put this
% line into this file, if you want to have A4 as paper format:
% \begin{quote}
% \verb|\PassOptionsToClass{a4paper}{article}|
% \end{quote}
% An example follows how to generate the
% documentation with pdf\LaTeX:
% \begin{quote}
%\begin{verbatim}
%pdflatex kvsetkeys.dtx
%makeindex -s gind.ist kvsetkeys.idx
%pdflatex kvsetkeys.dtx
%makeindex -s gind.ist kvsetkeys.idx
%pdflatex kvsetkeys.dtx
%\end{verbatim}
% \end{quote}
%
% \begin{thebibliography}{9}
% \bibitem{tb94wright}
% A guide to key-value methods, Joseph Wright, second draft for
% \href{http://www.tug.org/tugboat}{TUGBoat}, 2009-03-17.
% \url{http://www.texdev.net/wp-content/uploads/2009/03/keyval.pdf}
%
% \bibitem{keyval}
% David Carlisle:
% \textit{The \xpackage{keyval} package};
% 1999/03/16 v1.13;
% \CTAN{macros/latex/required/graphics/keyval.dtx}.
%
% \end{thebibliography}
%
% \begin{History}
% \begin{Version}{2006/03/06 v1.0}
% \item
% First version.
% \end{Version}
% \begin{Version}{2006/10/19 v1.1}
% \item
% Fix of \cs{kv@set@family@handler}.
% \item
% Example added.
% \end{Version}
% \begin{Version}{2007/09/09 v1.2}
% \item
% Using package \xpackage{infwarerr} for error messages.
% \item
% Catcode section rewritten.
% \end{Version}
% \begin{Version}{2007/09/29 v1.3}
% \item
% Normalizing and parsing of comma separated lists added.
% \item
% \cs{kv@normalize} rewritten.
% \item
% Robustness increased for normalizing and parsing,
% e.g. for values with unmatched conditionals.
% \item
% \eTeX\ is used if available.
% \item
% Tests added for normalizing and parsing.
% \end{Version}
% \begin{Version}{2009/07/19 v1.4}
% \item
% Bug fix for \cs{kv@normalize}: unwanted space removed (Florent Chervet).
% \end{Version}
% \begin{Version}{2009/07/30 v1.5}
% \item
% Documentation addition: recommendation for Joseph Wright's
% review article.
% \end{Version}
% \begin{Version}{2009/12/12 v1.6}
% \item
% Short info shortened.
% \end{Version}
% \begin{Version}{2009/12/22 v1.7}
% \item
% Internal optimization (\cs{KVS@CommaSpace}, \dots, \cs{KVS@EqualsSpace}).
% \end{Version}
% \begin{Version}{2010/01/28 v1.8}
% \item
% Compatibility to ini\TeX\ added.
% \end{Version}
% \begin{Version}{2010/03/01 v1.9}
% \item
% Support of \cs{par} inside values.
% \end{Version}
% \end{History}
%
% \PrintIndex
%
% \Finale
\endinput
|