summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/keycommand/keycommand.dtx
blob: 5f5ac85f3a343f85f3f5cc5f5a0ed236177cf03f (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
% \iffalse meta-comment
% keycommand : key-value interface for commands and environments in LaTeX v3.1415 2010/04/27]
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either
% version 1.3 of this license or (at your option) any later
% version. The latest version of this license is in
%    http://www.latex-project.org/lppl.txt
%
% This work consists of the main source file keycommand.dtx
% and the derived files
%    keycommand.sty, keycommand.pdf, keycommand.ins,
%    keycommand-example.tex
%
% Unpacking:
%    (a) If keycommand.ins is present:
%           etex keycommand.ins
%    (b) Without keycommand.ins:
%           etex keycommand.dtx
%    (c) If you insist on using LaTeX
%           latex \let\install=y\input{keycommand.dtx}
%        (quote the arguments according to the demands of your shell)
%
% Documentation:
%           (pdf)latex keycommand.dtx
% Copyright (C) 2009-2010 by Florent Chervet <florent.chervet@free.fr>
%<*ignore>
\begingroup
  \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: keycommand 2010/04/27 v3.1415 key-value interface for commands and environments in LaTeX}
\Msg{************************************************************************}

\keepsilent
\askforoverwritefalse

\let\MetaPrefix\relax
\preamble

This is a generated file.

keycommand : key-value interface for commands and environments in LaTeX [v3.1415 2010/04/27]

This work may be distributed and/or modified under the
conditions of the LaTeX Project Public License, either
version 1.3 of this license or (at your option) any later
version. The latest version of this license is in
   http://www.latex-project.org/lppl.txt

This work consists of the main source file keycommand.dtx
and the derived files
   keycommand.sty, keycommand.pdf, keycommand.ins,
   keycommand-example.tex

keycommand : an easy way to define commands with optional keys
Copyright (C) 2009-2010 by Florent Chervet <florent.chervet@free.fr>

\endpreamble
\let\MetaPrefix\DoubleperCent

\generate{%
   \file{keycommand.ins}{\from{keycommand.dtx}{install}}%
   \file{keycommand.sty}{\from{keycommand.dtx}{package}}%
   \file{keycommand-example.tex}{\from{keycommand.dtx}{example}}%
}

\generate{%
   \file{keycommand.drv}{\from{keycommand.dtx}{driver}}%
}

\obeyspaces
\Msg{************************************************************************}
\Msg{*}
\Msg{* To finish the installation you have to move the following}
\Msg{* file into a directory searched by TeX:}
\Msg{*}
\Msg{*     keycommand.sty}
\Msg{*}
\Msg{* To produce the documentation run the file `keycommand.dtx'}
\Msg{* through LaTeX.}
\Msg{*}
\Msg{* Happy TeXing!}
\Msg{*}
\Msg{************************************************************************}

\endbatchfile
%</install>
%<*ignore>
\fi
%</ignore>
%<*driver>
\edef\thisfile{\jobname}
\def\thisinfo{key-value interface for commands and environments in \LaTeX.}
\def\thisdate{2010/04/27}
\def\thisversion{3.1415}
\let\loadclass\LoadClass
\def\LoadClass#1{\loadclass[abstracton]{scrartcl}\let\scrmaketitle\maketitle\AtEndOfClass{\let\maketitle\scrmaketitle}}
\documentclass[a4paper,oneside]{ltxdoc}
\usepackage[latin9]{inputenc}
\usepackage[american]{babel}
\usepackage[T1]{fontenc}
\usepackage{etex,etoolbox,holtxdoc,geometry,tocloft,graphicx,xspace,fancyhdr,color,bbding,embedfile,framed,multirow,txfonts,makecell,enumitem,arydshln}
\CodelineNumbered
\usepackage{keyval}\makeatletter\let\keyval@setkeys\setkeys\makeatother
\usepackage{xkeyval}\let\xsetkeys\setkeys
\usepackage{kvsetkeys}
\usepackage{fancyvrb}
\lastlinefit999
\geometry{top=2cm,headheight=1cm,headsep=.3cm,bottom=1.4cm,footskip=.5cm,left=2.5cm,right=1cm}
\hypersetup{%
  pdftitle={The keycommand package},
  pdfsubject={key-value interface for commands and environments in LaTeX.},
  pdfauthor={Florent CHERVET},
  colorlinks,linkcolor=reflink,
  pdfstartview={FitH},
  pdfkeywords={tex, e-tex, latex, package, keys, keycommand, newcommand, keyval, kvsetkeys, programming},
  bookmarksopen=true,bookmarksopenlevel=3}
\embedfile{\thisfile.dtx}
\begin{document}
   \DocInput{\thisfile.dtx}
\end{document}
%</driver>
% \fi
%
% \CheckSum{1111}
%
% \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         \~}
%
% \DoNotIndex{\begin,\CodelineIndex,\CodelineNumbered,\def,\DisableCrossrefs,\~,\@ifpackagelater}
% \DoNotIndex{\DocInput,\documentclass,\EnableCrossrefs,\end,\GetFileInfo}
% \DoNotIndex{\NeedsTeXFormat,\OnlyDescription,\RecordChanges,\usepackage}
% \DoNotIndex{\ProvidesClass,\ProvidesPackage,\ProvidesFile,\RequirePackage}
% \DoNotIndex{\filename,\fileversion,\filedate,\let}
% \DoNotIndex{\@listctr,\@nameuse,\csname,\else,\endcsname,\expandafter}
% \DoNotIndex{\gdef,\global,\if,\item,\newcommand,\nobibliography}
% \DoNotIndex{\par,\providecommand,\relax,\renewcommand,\renewenvironment}
% \DoNotIndex{\stepcounter,\usecounter,\nocite,\fi}
% \DoNotIndex{\@fileswfalse,\@gobble,\@ifstar,\@unexpandable@protect}
% \DoNotIndex{\AtBeginDocument,\AtEndDocument,\begingroup,\endgroup}
% \DoNotIndex{\frenchspacing,\MessageBreak,\newif,\PackageWarningNoLine}
% \DoNotIndex{\protect,\string,\xdef,\ifx,\texttt,\@biblabel,\bibitem}
% \DoNotIndex{\z@,\wd,\wheremsg,\vrule,\voidb@x,\verb,\bibitem}
% \DoNotIndex{\FrameCommand,\MakeFramed,\FrameRestore,\hskip,\hfil,\hfill,\hsize,\hspace,\hss,\hbox,\hb@xt@,\endMakeFramed,\escapechar}
% \DoNotIndex{\do,\date,\if@tempswa,\@tempdima,\@tempboxa,\@tempswatrue,\@tempswafalse,\ifdefined,\ifhmode,\ifmmode,\cr}
% \DoNotIndex{\box,\author,\advance,\multiply,\Command,\outer,\next,\leavevmode,\kern,\title,\toks@,\trcg@where,\tt}
% \DoNotIndex{\the,\width,\star,\space,\section,\subsection,\textasteriskcentered,\textwidth}
% \DoNotIndex{\",\:,\@empty,\@for,\@gtempa,\@latex@error,\@namedef,\@nameuse,\@tempa,\@testopt,\@width,\\,\m@ne,\makeatletter,\makeatother}
% \DoNotIndex{\maketitle,\parindent,\setbox,\x,\kernel@ifnextchar}
% \DoNotIndex{\KVS@CommaComma,\KVS@CommaSpace,\KVS@EqualsSpace,\KVS@Equals,\KVS@Global,\KVS@SpaceEquals,\KVS@SpaceComma,\KVS@Comma}
% \DoNotIndex{\DefineShortVerb,\DeleteShortVerb,\UndefineShortVerb,\MakeShortVerb,\endinput}
% \let\ClearPage\clearpage
% \makeatletter
% \MakeShortVerb{\+}\DeleteShortVerb{\|}\DefineShortVerb{\|}
% \catcode`\§ \active   \def§{\@ifnextchar §{\par\nobreak\vskip-2\parskip}{\par\nobreak\vskip-\parskip}}
% \def\thispackage{\xpackage{\thisfile}\xspace}
% \def\ThisPackage{\Xpackage{\thisfile}\xspace}
% \def\Xpackage{\@dblarg\X@package}
% \def\X@package[#1]#2{%
%     \xpackage{#2\footnote{\noindent\xpackage{#2}: \href{http://www.ctan.org/tex-archive/macros/latex/contrib/#1}{\nolinkurl{CTAN:macros/latex/contrib/#1}}}}}
% \def\Underbrace#1_#2{$\underbrace{\vtop to2ex{}\hbox{#1}}_{\footnotesize\hbox{#2}}$}
%
% \parindent\z@\parskip.4\baselineskip\topsep\parskip\partopsep\z@
% \g@addto@macro\macro@font{\macrocodecolor\let\AltMacroFont\macro@font}
% \g@addto@macro\@list@extra{\parsep\parskip\topsep\z@\itemsep\z@}
% \def\smex{\leavevmode\hb@xt@2em{\hfil$\longrightarrow$\hfil}}
% \newrobustcmd\verbfont{\usefont{T1}{\ttdefault}{\f@series}{n}}    \let\vb\verbfont
% \renewrobustcmd\#[1]{{\usefont{T1}{pcr}{bx}{n}\char`\##1}}
% \newrobustcmd\csred[1]{\textcolor{red}{\cs{#1}}}
% \renewrobustcmd\cs[2][]{\mbox{\vb#1\expandafter\@gobble\string\\#2}}
% \newrobustcmd\CSbf[1]{\textbf{\CS{#1}}}
% \newrobustcmd\csbf[2][]{\textbf{\cs[{#1}]{#2}}}
% \newrobustcmd\textttbf[1]{\textbf{\texttt{#1}}}
% \renewrobustcmd*\bf{\bfseries}\newcommand\nnn{\normalfont\mdseries\upshape}\newcommand\nbf{\normalfont\bfseries\upshape}
% \newrobustcmd*\blue{\color{blue}}\newcommand*\red{\color{dr}}\newcommand*\green{\color{green}}\newcommand\rred{\color{red}}
% \newrobustcmd\rrbf{\color{red}\bfseries}
% \definecolor{copper}{rgb}{0.67,0.33,0.00}  \newcommand\copper{\color{copper}}
% \definecolor{dg}{rgb}{0.16,0.33,0.00}      \newcommand\dg{\color{dg}}
% \definecolor{db}{rgb}{0,0,0.502}           \newcommand\db{\color{db}}
% \definecolor{dr}{rgb}{0.49,0.00,0.00}      \let\dr\red
% \newrobustcmd\bk{\color{black}}\newcommand\md{\mdseries}
%
% \fancyhf{}\fancyhead[L]{The \thispackage package -- \thisinfo}
% \fancyfoot[L]{\color[gray]{.35}\scriptsize\thispackage\quad[rev.\thisversion]\quad\copyright\oldstylenums{2009-2010}\,\lower.3ex\hbox{\NibRight}\,Florent Chervet}
% \fancyfoot[R]{\oldstylenums{\thepage} / \oldstylenums{\pageref{LastPage}}}
% \pagestyle{fancy}
% \fancypagestyle{plain}{%
%     \let\headrulewidth\z@
%     \fancyhf{}%
%     \fancyfoot[R]{\oldstylenums{\thepage} / \oldstylenums{\pageref{LastPage}}}}
%
% \newcommand\macrocodecolor{\color{macrocode}}\definecolor{macrocode}{rgb}{0.18,0.00,0.45}
% \newcommand\reflinkcolor{\color{reflink}}\definecolor{reflink}{rgb}{0.49,0.00,0.00}
% \font\umrandA=umranda at 20pt
% \def\@serp{\leavevmode\lower20pt\hbox{\umrandA\char'131}}
% \def\serp#1{\@serp\hfil #1\hfil\reflectbox{\@serp}}
% \newrobustcmd\stform{\@ifnextchar*{\@stform[]\textasteriskcentered\@gobble}\@stform}
% \newrobustcmd\@stform[2][\string]{\textttbf{\rred#1#2}\xspace}
%
% \makeatother
%
% \deffootnote{1em}{0pt}{\rlap{\textsuperscript{\thefootnotemark}}\kern1em}
%
% \title{\vskip-18pt\mdseries {\bfseries\ThisPackage}\kern.6em package}
% \author{\footnotesize\xemail{florent.chervet@free.fr}}
% \date{\thisdate~--~version \thisversion}
% \subtitle{\thisinfo}
% ^^A\subject{\vskip-2cm\serp{The completely redesigned}}
% \subject{\vskip-2cm\relax The \textit{free} and \textit{open source}}
%
% \maketitle
% 
% \makeatletter\begingroup\let\@thefnmark\@empty\let\@makefntext\@firstofone
% \footnotetext{\noindent
% This documentation is produced with the +DocStrip+ utility.
% \begin{tabbing}
% \qquad\=\smex\=To get the documentation, \= run (thrice):\quad\= \texttt{pdflatex keycommand.dtx} \\
% \qquad\>\>To get the index, \> run:\>\texttt{makeindex -s gind.ist keycommand.idx} \\
% \>\smex\>To get the package, \> run:\>        \texttt{etex keycommand.dtx}
% \end{tabbing}§
% The \xext{dtx} file is embedded into this pdf file thank to \xpackage{embedfile} by H. Oberdiek.}
% \endgroup\makeatother
% 
% \hypersetup{bookmarksopenlevel=3}
% \deffootnote{1em}{0pt}{\rlap{\thefootnotemark.}\kern1em}
% \vspace*{-18pt}
% \begin{abstract}\parindent0pt\noindent\leftskip1cm\rightskip\leftskip\lastlinefit0%
%
% \thispackage provides an easy way to define commands or environments
% with optional keys.
% \smallskip
%
% \csbf{newkeycommand} \cs{renewkeycommand} \cs{providekeycommand} and \csbf{newkeyenvironment},\linebreak 
% \cs{renewkeyenvironment} are macros to define such commands and environments with keys.
% 
% \thispackage is designed to make easier interface for user-defined commands.  In particular,
% \csbf{newkeycommand}\stform+ permits the use of key-commands in every context. 
% \medskip
%
% Keys are defined with the command itself in a very natural way.
% You can restrict the possible values for the keys by declaring them with a \textbf{type}.
% Available types for keys are : \textit{boolean}, \textit{enum} and \textit{choice} (see \ref{subsec:GeneralSyntax}).
%
% \smallskip
%
% The \thispackage package requires and is based on the package \xpackage{xkeyval} by Hendri Adriaens, and uses
% the \cs{kv@normalize} macro of \xpackage{kvsetkeys} (Heiko Oberdiek) for robustness, as shown
% in \ref{kvsetkeys-comparisons}).
%
% It works with an \eTeX{} distribution of \LaTeX.
% \end{abstract}
%
% \DeleteShortVerb{\+}\enlargethispage{2\baselineskip}
% \cftbeforesecskip=4pt plus2pt minus2pt
% \cftbeforesubsecskip=0pt plus2pt minus2pt
% \renewcommand\contentsname{Contents\quad\leaders\vrule height3.4pt depth-3pt\hfill\null\kern0pt\vskip-6pt}
% ^^A\vskip-.8\baselineskip
% \tableofcontents
%
% \clearpage\MakeShortVerb{\+}
%
% \def\B#1{\texttt{[}\meta{#1}\texttt{]}}
%
% \section{User Interface}
%
% \subsection{General syntax}\label{subsec:GeneralSyntax}
%
% \begin{declcs}{newkeycommand}%
%  \Underbrace{\textcolor{red}{\textasteriskcentered\string+[short-unexpand]}}_{\makecell[c]{modifiers \\ Optional}}\,%
%  \Underbrace{\M{command}}_{Required}\,%
%   {\color{db}\Underbrace{\B{keys=defaults}\,\B{OptKey}\,\B{<n>}}_{Optional}\,}%
%   \Underbrace{\M{definition}}_{Required}
% \end{declcs}
%
% \cs{newkeycommand} will define \cs{command} as a new key-command!\quad well...
%
% Use the \stform* form when you do not want it to be a \cs{long} macro (as for \LaTeX{}-\cs{newcommand}).
%
% The +[keys=defaults]+ argument define the keys with their default values. It is optional, but a key-command
% without keys seems to be useless (at least for me...). Keys may be defined as :
%
% \newlist{myenum}{enumerate}{1}
% \setlist[myenum]{label={},topsep=-\parskip,itemsep=-\parskip,parsep=\parskip,after=\vskip-\baselineskip}
%
% \renewcommand\theadfont{\tt\bfseries}
% \noindent\begin{tabular}{|c|>{\db}c|m{8cm}|}\hline
% \thead{Type} & \thead{exemple}                                              & \thead{value of \cs{commandkey}}                                                                                         \\ \hline
% general      & color{\dg=red}                                               & \cs{commandkey}\{{\db color}\} is `{\dg red}' and may be anything (text, number, macro...)                                           \\ \hline
% boolean      & {\rred bool} bold{\dg =true}                                 & \cs{commandkey}\{{\db bold}\} is:
%                                                                                                       \begin{myenum}
%                                                                                                       \item {\tt 0}\quad (for {\dg false})
%                                                                                                       \item {\tt 1}\quad (for {\dg true})
%                                                                                                       \end{myenum}          \\ \hline
% \multirow{2}*{enumerate} & {\rred enum} position{\dg=\{left,centered,right\}} & \cs{commandkey}\{{\db position}\} is:
%                                                                                                     \begin{myenum}
%                                                                                                     \item `{\dg left}'\quad by default and can be
%                                                                                                     \item `{\dg centered}' or
%                                                                                                     \item `{\dg right}'
%                                                                                                        \end{myenum}         \\ \cdashline{2-3}[1pt/2pt]
%                          & {\rred enum\textasteriskcentered} position{\dg=\{left,centered,right\}}  & This is the same, except match is case \textbf{in}sensitive   \bottopstrut                                   \\ \hline
% \multirow{2}*{choice}    & {\rred choice} position={\dg \{left,centered,right\}} & \cs{commandkey}\{{\db position}\} is:
%                                                                                                     \begin{myenum}
%                                                                                                     \item {\tt 0}\quad (for {\dg left} the default value),
%                                                                                                     \item {\tt 1}\quad (for {\dg centered})
%                                                                                                     \item {\tt 2}\quad (for {\dg right})
%                                                                                                     \end{myenum}                           \\ \cdashline{2-3}[1pt/2pt]
%                          & {\rred choice\textasteriskcentered} position={\dg\{left,centered,right\}} & This is the same, except match is case \textbf{in}sensitive   \bottopstrut                                   \\ \hline
% \end{tabular}
%
% The {\db+OptKey+} argument is used if you wish to capture the +key=value+ pairs that are not specifically defined (more on this in the examples section \ref{sec:examples}).
%
% The key-command may have {\tt 0} up to {\tt 9} \textbf{mandatory} arguments : specify the number by +<n>+ ({\tt 0} if omitted).
%
% The \stform+ form expands the \cs{commandkey} before executing the key-command itself, as explain in section \ref{sec:example:plus}.
%
% \subsection{First example :}
%
% \begin{tabbing}\label{textrule}
% \,\=\csbf{new}\=\textttbf{keycommand}\cs[\copper]{textrule}+[+{\color{db}+raise=.4ex,width=3em,thick=.4pt+}+][1]{%+ \\ ^^A+][1]{%+}\\
% \>\>\cs{rule}+[+\cs[\red]{commandkey}+{+{\db+raise+}+}]{+\cs[\red]{commandkey}+{+{\db+width+}+}{+\cs[\red]{commandkey}+{+{\db+thick+}+}}+\\
% \>\>\#1 \\
% \>\>\cs{rule}+[+\cs[\red]{commandkey}+{+{\db+raise+}+}]{+\cs[\red]{commandkey}+{+{\db+width+}+}}{+\cs[\red]{commandkey}+{+{\db+thick+}+}}}+
% \end{tabbing}
%
% defines the keys {\db+width+}, {\db+thick+} and {\db+raise+} with their default values (if not specified):
% {\db+3em+}, {\db+.4pt+} and {\db+.4ex+}. Now \cs[\copper]{textrule} can be used as follow:
% \begin{tabbing}
% \=1:\quad\=\cs[\copper]{textrule}+[width=2em]{hello}+\hskip2.5cm\=\smex\qquad\=        \rule[.4ex]{2em}{.4pt}hello\rule[.4ex]{2em}{.4pt} \\
% \>2:\>\cs[\copper]{textrule}+[thick=5pt,width=2em]{hello}+\>\smex\>                  \rule[.4ex]{2em}{5pt}hello\rule[.4ex]{2em}{5pt}\\
% \>3:\>\cs[\copper]{textrule}+{hello}+\quad \>\smex\>                                 \rule[.4ex]{3em}{.4pt}hello\rule[.4ex]{3em}{.4pt}\\
% \>4:\>\cs[\copper]{textrule}+[thick=2pt,raise=1ex]{hello}+\>\smex\>                  \rule[1ex]{3em}{2pt}hello\rule[1ex]{3em}{2pt} \\
% \> \textit{et c\ae tera}.
% \end{tabbing}
%
% \clearpage
%
% \subsection[Second example : the \string+ form]{Second example : the {\rred\bf\string+} form}
% \label{sec:example:plus}
%
% \DeleteShortVerb{\+}
% \begin{Verbatim}[gobble=1,commandchars=$(),frame=lines]
% ($bf\newkeycommand)($rred$bf+[\|])($copper\myfigure)[image,
%                              caption,
%                              enum placement={H,h,b,t,p},
%                              width=\textwidth,
%                              label=
%                             ][($db OtherKeys)]{%
%        ($rred|)($bf\begin){figure}($dr|)[($red\commandkey){placement}]
%           ($rred|)($bf\includegraphics)($dr|)[width=($red\commandkey){width},($red\commandkey){($db OtherKeys)}]{%
%                             ($red\commandkey){image}}%
%           ($dg\ifcommandkey){caption}{($rred|)\caption($rred|){($red\commandkey){caption}}}{}%
%           ($dg\ifcommandkey){label}{($rred|)\label($rred|){($red\commandkey){label}}}{}%
%        ($rred|)($bf\end){figure}($rred|)}
% \end{Verbatim}
% \MakeShortVerb{\+}
%
% With the \stform+ form of \cs{newkeycommand}, the definition will be expanded (at run time). The optional {\rred\bf+[\|]+} argument
% means that everything inside {\bf\rred+|+ ... +|+} is protected from expansion.
%
% {\dg\cs{ifcommandkey}}\{\meta{name}\}\{\meta{true}\}\{\meta{false}\}\quad expands \meta{true} if the commandkey \meta{name} is not blank.
%
% {\db \meta{Otherkeys}} captures the keys given by the user but not declared: they are simply given back to \cs{includegraphics} here...
%
%
% \subsection[Explanation of the \string+ form]{Explanation of the {\rred\bf\string+} form}
% \DeleteShortVerb{\+}
% The |\commankey{|\meta{name}|}| stuff is expanded at run time using the following scheme:§§
% \begin{Verbatim}[gobble=1,commandchars=!(),frame=lines]
%     (!bf\newkeycommand)(!copper\keyMacro)[A=\defA,B=\defB,C=\defC,D=\defD][1]{(!dg\begingroup)
%        (!dg\edef)\keyMacro##1{(!dg\endgroup)
%            (!dg\noexpand)\Macro{(!red\getcommandkey){A}}
%                           {(!red\getcommandkey){B}}
%                           {(!red\getcommandkey){C}}
%                           {(!red\getcommandkey){D}}
%     }\keyMacro{#1}}
% \end{Verbatim}
% Therefore, the arguments of \cs{Macro} are ready: there is no more \cs{commandkey} stuff, but instead the values of the keys
% as you gave them to the key-command. \cs{getcommandkey}\{A\} is expanded to \cs{defA}.
%
% But \cs{defA} is not expanded of course: in the \stform+ form, \cs{commandkey} has the meaning of \cs{getcommandkey}.
%
% As you can see, the mandatory arguments \#1, \#2 etc. are \textbf{never expanded}: there is no need to protect them inside the special (usually {\rred\bf\textbar}) character.
%
%
% \MakeShortVerb{\+}
% \clearpage
%
% \subsection{key-environments}
%
% \begin{declcs}{newkeyenvironment}%
%  \Underbrace{\textcolor{red}{\textasteriskcentered\string+[short-unexpand]}}_{\makecell[c]{modifiers \\ Optional}}\,%
%  \Underbrace{\M{envir name}}_{Required}\,%
%   {\db\Underbrace{\B{keys=defaults}\,\B{OptKey}\,\B{<n>}}_{Optional}\,}%
%   \Underbrace{\M{begin}}_{Required}\Underbrace{\M{end}}_{Required}
% \end{declcs}
%
% In the same way, you may define environments with optional keys as follow:§
% \begin{tabbing}
% \qquad\=+\newkeyenvironment+\=+{EnvirWithKeys}[kOne=+default value,...+][n]+\\
% \>\>+{+ commands at begin +EnvirWithKeys }+ \\
% \>\>+{+ commands at end +EnvirWithKeys }+
% \end{tabbing}
%
% Where $n$ is the number of mandatory other arguments (\emph{ie} without keys), if any.
%
% Key-environments may be defined with the \stform+ form in the same way as \cs{newkeycommand} is used.
% Be aware that each part of the environment: \meta{begin} and \meta{end} are expanded at run time then, 
% and the optional {\rred\bf+[\|]+} argument protects from expansion in each of those parts.
% 
% \subsection[Example of a \string+ key-environment]{Example of a {\rred\bf\string+} key-environment}
% 
% \DeleteShortVerb{\+}
% \begin{Verbatim}[gobble=1,commandchars=$(),frame=lines]
% ($bf\newkeyenvironment)($rred$bf+[\|])({$copper myfigure)}[
%                              caption,
%                              enum placement={H,h,b,t,p},
%                              width=.5\linewidth,
%                              label
%                             ][($db OtherKeys)][1]%
%     {% ($nbf$dg begin part)
%        ($rred|)($bf\begin){figure}($rred|)[($red\commandkey){placement}]
%           ($rred|)($bf\includegraphics)($rred|)[($red\commandkey){($db OtherKeys)},width=($red\commandkey){width}]{$#1}%
%     }
%     {% ($nbf$dg end part)
%           ($dg\ifcommandkey){caption}{($rred|)\caption($rred|){($red\commandkey){caption} image file = $#1}}{}%
%           ($dg\ifcommandkey){label}{($rred|)\label($rred|){($red\commandkey){label}}}{}%
%        ($rred|)($bf\end){figure}($rred|)%
%     }
% \end{Verbatim}
% \MakeShortVerb{\+}
%
% As you can see, \cs{commandkey} and mandatory arguments (\#1 here) are available both in the \meta{begin} 
% and in the \meta{end} parts of the key-environment.
% 
%
% \DefineShortVerb{\+}
%
% \section{Messages and more}
%
% \subsection{Invalid keys}
%
% If you use the command +\textule+ (defined in \ref{textrule}) with a key say: +height+
% that has not been declared at the definition of the key-command, you will get an
% error message like this:
% \begin{quote}\tt
% The key-value pairs ``height=...''§
% cannot be processed for key-command \string\textrule!§
% See the definition of the keycommand!
% \end{quote}
% The error is recoverable: the key is ignored.
%
% If you assign a value to an \textit{enum} or a \textit{choice} key, which is not allowed in the definition,
% you will get the following message:
% \begin{quote}\tt
% The value ``...'' is not allowed in key ...§
% for key-command \string\command§
% I'll use the default value ``...'' for this key instead§
% See the definition of the key-command!
% \end{quote}
% The error is recoverable: the key is assigned its default value.
%
% If you use a \cs{commandkey}\{\meta{name}\} in a key-command where \meta{name} is not defined as a key,
% you will get the \TeX{} generic error message :§
% \qquad undefined control sequence : \cs{keycmd->...@name}.
%
%
% \subsection{Testing keys}
%
% \begin{declcs}{ifcommandkey}\,\M{key name}\,\M{commands if key is NOT blank}\,\M{commands if key is blank}
% \end{declcs}
%
% When you define a key command you may let the default value of a key empty. Then, you may wish to
% expand some commands only if the key has been given by the user (with a non empty value). This can
% be achieved using the macro |\ifcommandkey|.
%
% \clearpage
% \subsection{xkeyval, keyval and kvsetkeys comparison}
%
% \begin{tabbing}
% \quad\=\xpackage{xkeyval}: \expandafter\meaning\csname ver@xkeyval.sty\endcsname \\
% \>\xpackage{keyval}: \expandafter\meaning\csname ver@keyval.sty\endcsname \\
% \>\xpackage{kvsetkeys}: \expandafter\meaning\csname ver@kvsetkeys.sty\endcsname
% \end{tabbing}
%
% \makeatletter\def\theadfont{\tt\bfseries}
% \define@key{fam}{key}{\def\result{#1}}
% \begin{table}[h]\label{kvsetkeys-comparisons}
% \begin{tabular}{|l|l|>{\color{db}}l|>{\color{dg}}l|}\hline
% \thead{\bf Example} & \thead{keyval} & \thead{xkeyval} & \thead{\makecell{kvsetkeys\\and\\keycommand}} \\ \hline
% +\setkeys{fam}{key={{value}}}+
%     & \keyval@setkeys{fam}{key={{value}}}\meaning\result
%     & \xsetkeys{fam}{key={{value}}}\meaning\result
%     & \kvsetkeys{fam}{key={{value}}}\meaning\result \\\hline
% +\setkeys{fam}{key={{{value}}}}+
%     & \keyval@setkeys{fam}{key={{{value}}}}\meaning\result
%     & \xsetkeys{fam}{key={{{value}}}}\meaning\result
%     & \kvsetkeys{fam}{key={{{value}}}}\meaning\result \\\hline
% +\setkeys{fam}{key=+\textvisiblespace+{{{value}}}}+
%     & \keyval@setkeys{fam}{key= {{{value}}}}\meaning\result
%     & \xsetkeys{fam}{key= {{{value}}}}\meaning\result
%     & \kvsetkeys{fam}{key= {{{value}}}}\meaning\result \\\hline
% \end{tabular}
% \caption{Then it is clear that, at this time, \xpackage{kvsetkeys} has the only correct behaviour...}
% \end{table}
%
% In \thispackage the key-value pairs are first normalized using \xpackage{kvsetkeys}-\cs{kv@normalize}. Then braces are added
% around the values in order to keep the good behaviour of \xpackage{kvsetkeys} while using \xpackage{xkeyval}.
% \makeatother
%
%
%
%
% \StopEventually{
% }
%
% \begin{center}\vskip6pt$\star$\hskip4em\lower12pt\hbox{$\star$}\hskip4em$\star$\vadjust{\vskip12pt}\end{center}
%
% \section{Implementation} \label{Implementation}
% \csdef{HDorg@PrintMacroName}#1{\hbox to4em{\strut \MacroFont \string #1\ \hss}}
%
% \subsection{Identification}
%
% This package is intended to use with \LaTeX{} so we don't check if it is loaded twice.
%
%    \begin{macrocode}
%<*package>
\NeedsTeXFormat{LaTeX2e}% LaTeX 2.09 can't be used (nor non-LaTeX)
   [2005/12/01]% LaTeX must be 2005/12/01 or younger (see kvsetkeys.dtx).
\ProvidesPackage{keycommand}
   [2010/04/27 v3.1415 - key-value interface for commands and environments in LaTeX]
%    \end{macrocode}
%
% \subsection{Requirements}
%
% The package is based on \xpackage{xkeyval}. However, \xpackage{xkeyval} is far less reliable
% than \xpackage{kvsetkeys} as far as spaces and bracket (groups) are concerned, as shown in the section
% \ref{kvsetkeys-comparisons} of this documentation.
%
% Therefore, we also use the macros of \xpackage{kvsetkeys} in order to \textit{normalize} the \texttt{key=value}
% list before setting the keys. This way, we take advantage of both \xpackage{xkeyval} and \xpackage{kvsetkeys} !
%
% As long as we use \eTeX{} primitives in \xpackage{keycommand} we also load the
% \xpackage{etex} package in order to get an error message if \eTeX{} is not running.
%
% The \xpackage{etoolbox} package gives some facility to write \xpackage{keycommand}.
% 
% From version \texttt{3.141} onwards, \thispackage does not load \xpackage{etextools} anymore.
%
%    \begin{macrocode}
\def\kcmd@pkg@name{keycommand}
\RequirePackage{etex,kvsetkeys,xkeyval,etoolbox}
%    \end{macrocode}
%
% Save the \cs{setkeys} macro of \xpackage{xkeyval} package (in case it was overwritten by a
% subsequent load of \xpackage{kvsetkeys} or \xpackage{keyval} for example :
%    \begin{macrocode}
\protected\def\kcmd@Xsetkeys{\XKV@sttrue\XKV@plfalse\XKV@testoptc\XKV@setkeys}% in case \setkeys 
%                                                                                was overwritten
%    \end{macrocode}
% Some \cs{catcode} assertions internally used by \thispackage:
%    \begin{macrocode}
\let\kcmd@AtEnd\@empty
\def\TMP@EnsureCode#1#2{%
  \edef\kcmd@AtEnd{%
    \kcmd@AtEnd
    \catcode#1 \the\catcode#1\relax
  }%
  \catcode#1 #2\relax
}
\TMP@EnsureCode{32}{10}% space
\TMP@EnsureCode{61}{12}% = sign
\TMP@EnsureCode{45}{12}% - sign
\TMP@EnsureCode{62}{12}% > sign
\TMP@EnsureCode{46}{12}% . dot
\TMP@EnsureCode{47}{8}% / slash (etextools)
\AtEndOfPackage{\kcmd@AtEnd\undef\kcmd@AtEnd}
%    \end{macrocode}
% 
% \begin{macro}{\kcmd@ifstrdigit}\qquad\qquad
% This macro is used too test the optional arguments of \cs{newkeycommand}, 
% in particular, one must know in an argument is a single digit (representing
% the number of mandatory arguments) or anything else (representing the \texttt{key=value} 
% list or the ``special'' \texttt{OptKey} key:
%    \begin{macrocode}
\iffalse%\ifdefined\pdfmatch% use \pdfmatch if present
   \long\def\kcmd@ifstrdigit#1{\csname @\ifnum\pdfmatch
      {\detokenize{^[[:space:]]*[[:digit:]][[:space:]]*$}}{\detokenize{#1}}=1 %
      first\else second\fi oftwo\endcsname}
\else% use filter, very efficient !
\def\kcmd@ifstrdigit#1{%
   \kcmd@nbk#1//%
      {\expandafter\expandafter\expandafter\kcmd@ifstrdigit@i
         \expandafter\expandafter\expandafter{\detokenize\expandafter{\number\number0#1}}}%
      {\@secondoftwo}//%
}
\def\kcmd@ifstrdigit@i#1{%
   \def\kcmd@ifstrdigit@ii##1#1##2##3\kcmd@ifstrdigit@ii{%
      \csname @\ifx##20first\else second\fi oftwo\endcsname
      }\kcmd@ifstrdigit@ii 00 01 02 03 04 05 06 07 08 09 0#1 \relax\kcmd@ifstrdigit@ii
}
\fi
%    \end{macrocode}
% \end{macro}
%
% \subsection{Defining (and undefining) command-keys}
%\begin{macro}{\kcmd@keyfam}\qquad
% The macro expands to the family-name, given the keycommand name:
%    \begin{macrocode}
\def\kcmd@keyfam#1{\detokenize{keycmd->}\expandafter\@gobble\string#1}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\kcmd@nbk}\qquad is the optimized \cs{ifnotblank} macro of \xpackage{etoolbox}
% (with \textttbf{/} having a catcode of 8):
%    \begin{macrocode}
\def\kcmd@nbk#1#2/#3#4#5//{#4}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\kcmd@normalize@setkeys}~\par
% This macro assigns the values to the keys (expansion of \xpackage{xkeyval}-\cs{setkeys}
% on the result of \xpackage{kvsetkeys}-\cs{kv@normalize}). Braces are normalized too so that
% \verb+key=+\textvisiblespace+{{{value}}}+ is the same as \verb+key={{{value}}}+ as explained in section \ref{kvsetkeys-comparisons}:
%    \begin{macrocode}
\newrobustcmd\kcmd@normalize@setkeys[4]{%
% #1 = key-command,
% #2 = family,
% #3 = other-key,
% #4 = key-values pairs
   \kv@normalize{#4}\toks@{}%
   \expandafter\kv@parse@normalized\expandafter{\kv@list}{\kcmd@normalize@braces{#2}}%
   \edef\kv@list{\kcmd@Xsetkeys{\unexpanded{#2}}{\the\toks@}}\kv@list
   \kcmd@nbk#3//% undeclared keys are assigned to "OtherKeys"
      {\cslet{#2@#3}\XKV@rm}% (if specified, ie not empty)
      {\expandafter\kcmd@nbk\XKV@rm//% (otherwise a recoverable error is thown)
         {\PackageError\kcmd@pkg@name{The key-value pairs :\MessageBreak
         \XKV@rm\MessageBreak
         cannot be processed for key-command \string#1\MessageBreak
         See the definition of the key-command!}{}}{}//}//%
}
\long\def\kcmd@normalize@braces#1#2#3{% This is kvsetkeys processor for normalizing braces
   \toks@\expandafter{\the\toks@,#2}%
   \ifx @\detokenize{#3}@\else \toks@\expandafter{\the\toks@={{{#3}}}}\fi
}
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\kcmd@definekey}~\par
% \CS{kcmd@definekey} define the keys declared for the key-command.
% It is used as the \emph{processor} for the \cs{kv@parse} macro of \xpackage{kvsetkeys}.
% The macro appends the key names to the key list: ``\textit{family}.keylist''.
%
% keys are first checked for their type (bool, enum, enum*, choice or choice*) :
%
%    \begin{macrocode}
\def\kcmd@check@typeofkey#1{% expands to
% 0 if key has no type,
% 1 if boolean,
% 2 if enum*,
% 3 if enum,
% 4 if choice*,
% 5 if choice
   \kcmd@check@typeofkey@bool#1bool //%
      {\kcmd@check@typeofkey@enumst#1enum* //%
         {\kcmd@check@typeofkey@enum#1enum //%
            {\kcmd@check@typeofkey@choicest#1choice* //%
               {\kcmd@check@typeofkey@choice#1choice //%
                  05//}4//}3//}2//}1//}
\def\kcmd@check@typeofkey@bool #1bool #2//{\kcmd@nbk#1//}
\def\kcmd@get@keyname@bool #1bool #2//{#2}
\def\kcmd@check@typeofkey@enumst #1enum* #2//{\kcmd@nbk#1//}
\def\kcmd@get@keyname@enumst #1enum* #2//{#2}
\def\kcmd@check@typeofkey@enum #1enum #2//{\kcmd@nbk#1//}
\def\kcmd@get@keyname@enum #1enum #2//{#2}
\def\kcmd@check@typeofkey@choicest #1choice* #2//{\kcmd@nbk#1//}
\def\kcmd@get@keyname@choicest #1choice* #2//{#2}
\def\kcmd@check@typeofkey@choice #1choice #2//{\kcmd@nbk#1//}
\def\kcmd@get@keyname@choice #1choice #2//{#2}
%
\protected\long\def\kcmd@definekey#1#2#3#4#5{% define the keys using xkeyval macros
% #1 = keycommand,
% #2 = \global,
% #3 = family,
% #4 = key (before = sign),
% #5 = default (after = sign)
   \ifcase\kcmd@check@typeofkey{#4}\relax% standard
      #2\csedef{#3.keylist}{\csname#3.keylist\endcsname,#4}%
      \define@cmdkey{#3}[{#3@}]{#4}[{#5}]{}%
   \or% bool
      #2\csedef{#3.keylist}{\csname#3.keylist\endcsname,\kcmd@get@keyname@bool#4//}%
      \kcmd@define@boolkey#1{#3}{\kcmd@get@keyname@bool#4//}{#5}%
   \or% enum*
      #2\csedef{#3.keylist}{\csname#3.keylist\endcsname,\kcmd@get@keyname@enumst#4//}%
      \kcmd@define@choicekey#1*{#3}{\kcmd@get@keyname@enumst#4//}{#5}{\expandonce\val}%
   \or% enum
      #2\csedef{#3.keylist}{\csname#3.keylist\endcsname,\kcmd@get@keyname@enum#4//}%
      \kcmd@define@choicekey#1{}{#3}{\kcmd@get@keyname@enum#4//}{#5}{\expandonce\val}%
   \or% choice*
      #2\csedef{#3.keylist}{\csname#3.keylist\endcsname,\kcmd@get@keyname@choicest#4//}%
      \kcmd@define@choicekey#1*{#3}{\kcmd@get@keyname@choicest#4//}{#5}{\number\nr}%
   \or% choice
      #2\csedef{#3.keylist}{\csname#3.keylist\endcsname,\kcmd@get@keyname@choice#4//}%
      \kcmd@define@choicekey#1{}{#3}{\kcmd@get@keyname@choice#4//}{#5}{\number\nr}%
   \fi
   \ifx#2\global\relax
      #2\csletcs{KV@#3@#4}{KV@#3@#4}% globalize
      #2\csletcs{KV@#3@#4@default}{KV@#3@#4@default}% globalize default value
   \fi
}
%
\long\def\kcmd@firstchoiceof#1,#2\kcmd@nil{\unexpanded{#1}}
%
\long\def\kcmd@define@choicekey#1#2#3#4#5#6{%
   \begingroup\edef\kcmd@define@choicekey{\endgroup
      \noexpand\define@choicekey#2+{#3}{#4}
            [\noexpand\val\noexpand\nr]%
            {\unexpanded{#5}}% list of allowed values
            [{\kcmd@firstchoiceof#5,\kcmd@nil}]% default value
            {\csedef{#3@#4}{\unexpanded{#6}}}% define key value if in the allowed list
            {\kcmd@error@handler\noexpand#1{#3}{#4}{\kcmd@firstchoiceof#5,\kcmd@nil}}% error handler
   }\kcmd@define@choicekey
}
\def\kcmd@define@boolkey#1#2#3#4{\begingroup
   \kcmd@nbk#4//{\def\default{#4}}{\def\default{true}}//%
   \edef\kcmd@define@boolkey{\endgroup
      \noexpand\define@choicekey*+{#2}{#3}[\noexpand\val\noexpand\nr]%
            {false,true}
            [{\unexpanded\expandafter{\default}}]%
            {\csedef{#2@#3}{\noexpand\number\noexpand\nr}}%
            {\kcmd@error@handler\noexpand#1{#2}{#3}{\unexpanded\expandafter{\default}}}%
   }\kcmd@define@boolkey
}
%
\protected\long\def\kcmd@error@handler#1#2#3#4{%
% #1 = key-command,
% #2 = family,
% #3 = key,
% #4 = default
   \PackageError\kcmd@pkg@name{%
      Value `\val\space' is not allowed in key #3\MessageBreak
      for key-command \string#1.\MessageBreak
      I'll use the default value `#4' for this key.\MessageBreak
      See the definition of the key-command!}{%
      \csdef{#2@#3}{#4}}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\kcmd@undefinekeys}~\par
% Now in case we redefine a key-command, we would like the old keys (\emph{ie} the keys
% associated to the old definition of the command) to be cleared, undefined.
% That's the job of \cs{kcmd@undefinekeys}.
%    \begin{macrocode}
\protected\def\kcmd@undefinekeys#1#2{% #1 = global, #2 = family
   \ifcsundef{#2.keylist}
      {\cslet{#2.keylist}\@gobble}
      {\expandafter\expandafter\expandafter\docsvlist
         \expandafter\expandafter\expandafter{%
                        \csname #2.keylist\endcsname}%
      \cslet{#2.keylist}\@gobble}%
}
\def\kcmd@undefinekey#1#2#3{% #1 = global, #2 = family, #3 = key
   #1\csundef{KV@#2@#3}%
   #1\csundef{KV@#2@#3@default}%
}
%    \end{macrocode}
% \end{macro}
% 
%\begin{macro}{\kcmd@setdefaults}\qquad\qquad
% sets the defaults values for the keys at the very beginning of the keycommand:
%    \begin{macrocode}
\def\kcmd@setdefaults#1{%
   \ifcsundef{#1.keylist}{}
   {\expandafter\expandafter\expandafter\docsvlist
      \expandafter\expandafter\expandafter{%
                           \csname#1.keylist\endcsname}}%
}
%    \end{macrocode}
%\end{macro}
% 
% 
%
% \begin{macro}{\kcmd@def}
% checks \cs{@ifdefinable} and cancels definition if needed:
%    \begin{macrocode}
\protected\long\def\kcmd@def#1#2[#3][#4][#5]#6#7{%
   \ifx#1\kcmd@donot@provide  \endgroup
   \else
      \@tempswafalse\@ifdefinable#1{\@tempswatrue}%
      \if@tempswa
         \edef\kcmd@fam{\kcmd@keyfam{#1}}%
         \expandafter\kcmd@defcommand\expandafter{\kcmd@fam}#1[{#3}][{#4}][{#5}]{#6}{#2}{#7}%
      \else\endgroup
      \fi
   \fi
}
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\kcmd@defcommand}\qquad\qquad prepares (expands) the arguments before closing the group opened at the very beginning.
% Then it proceeds (\cs{kcmd@yargdef} (normal interface)  or \cs{kcmd@yargedef} (when \cs{newkeycommand}\stform+ is used))
%    \begin{macrocode}
\protected\long\def\kcmd@defcommand#1#2[#3][#4][#5]#6#7#8{%
   \let\commandkey\relax  \let\getcommandkey\relax  \let#2\relax   
   \cslet{#1}\relax  \cslet{#1.commankey}\relax  \cslet{#1.getcommandkey}\relax
   \def\do{\kcmd@undefinekey{\kcmd@gbl}{#1}}%
   \edef\kcmd@defcommand{\endgroup
      \kcmd@undefinekeys{\kcmd@gbl}{#1}% undefines all keys for this keycommand family
      \ifx\kcmd@unexpandchar\@empty\else
         \kcmd@mount@unexpandchar{#1}{\unexpanded\expandafter{\kcmd@unexpandchar}}%
      \fi
      \unexpanded{\kv@parse{#3,#4}}{\kcmd@definekey\noexpand#2{\kcmd@gbl}{#1}}% defines keys
      \csdef{#1.commandkey}####1{\noexpand\csname#1@####1\endcsname}%
      \csdef{#1.getcommandkey}####1{%
         \unexpanded{\unexpanded\expandafter\expandafter\expandafter}{%
                           \noexpand\csname#1@####1\endcsname}}%
      \kcmd@ifplus% \newkeycommand+ / \newkeyenvironment+
         \protected\csdef{#1}{%
            \kcmd@yargedef{\kcmd@gbl}{\kcmd@long}\csname#1\endcsname
                          {\number#5}{\noexpand#7}{\csname#1.unexpandchar\endcsname}}%
         \ifx#7\@gobble\else 
             \protected\def#7{\kcmd@yargedef#7}%
         \fi
      \else% \newkeycommand / \newkeyenvironment
         \csdef{#1}{%
            \kcmd@yargdef{\kcmd@gbl}{\kcmd@long}\csname#1\endcsname
                          {\number#5}{\noexpand#7}}%
         \ifx#7\@gobble\else \def#7####1{% that means we have to define a key-environment
            \def#7{%
               \let\getcommandkey\csname#1.getcommandkey\endcsname
               \let\commandkey\csname#1.commandkey\endcsname
               ####1}%
            }%
         \fi
      \fi
      \def\noexpand\do####1{\unexpanded{\expandafter\noexpand\csname}KV@#1@####1@default%
                                                                                     \endcsname}% 
      \let\commandkey\relax \let\getcommandkey\relax \let#2\relax
      \kcmd@gbl\protected\edef#2{% entry point
         \let\getcommandkey\noexpand\noexpand\csname#1.getcommandkey\endcsname
         \kcmd@ifplus  \let\commandkey\getcommandkey
         \else         \let\commandkey\noexpand\noexpand\csname#1.commandkey\endcsname
         \fi
         \noexpand\kcmd@setdefaults{#1}%
         \ifx#7\@gobble \noexpand\noexpand\noexpand\@testopt
                        {\kcmd@setkeys#2{#1}{\kcmd@otherkey{#4}}}{}%
         \else          \noexpand\noexpand\noexpand\@testopt
                        {\kcmd@setkeys#2{#1}{\kcmd@otherkey{#4}}}{}%
         \fi
         }%
      \csname#1\endcsname% expand \kcmd@yargedef or \kcmd@yargdef
   }\kcmd@defcommand{#6}{#8}% #6 = definition, #8 = definition end-envir
}
\protected\long\def\kcmd@setkeys#1#2#3[#4]{% #1=key-command, #2=family, #3=otherkey, #4=key=value pairs
   \kcmd@normalize@setkeys{#1}{#2}{#3}{#4}\csname#2\endcsname
}
\long\def\kcmd@otherkey#1{\kcmd@nbk#1//{\kcmd@otherkey@name#1=\kcmd@nil}{}//}
\long\def\kcmd@otherkey@name#1=#2\kcmd@nil{#1}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\kcmd@mount@unexpandchar}~\par
% This macro defines the macro \cs{"\textit{family.unexpandchar}"}. 
% \CS{"\textit{family.unexpandchar}"} activates the shortcut character 
% for \cs{unexpanded} and defines its meaning.
%    \begin{macrocode}
\protected \def \kcmd@mount@unexpandchar#1#2{%
   \protected\csdef{#1.unexpandchar}{\begingroup
      \catcode`\~\active \lccode`\~`#2 \lccode`#2 0\relax
         \lowercase{%
            \expandafter\endgroup\expandafter\def\expandafter~{%
               \catcode`#2\active
               \long\def~########1~{\unexpanded{########1}}}%
         ~}%
   }%
}
%    \end{macrocode}
% \end{macro}
%
%----------------------------------------------------------------------------
% \begin{macro}{\kcmd@yargdef}\qquad\qquad
% This is the ``{\tt argdef}'' macro for the normal (non \string+) form:
%    \begin{macrocode}
\protected \def \kcmd@yargdef #1#2#3#4#5{\begingroup
% #1 = global or {}
% #2 = long or {}
% #3 = Command
% #4 = nr of args
% #5 = endenvir (or \@gobble if not an environment, or \relax if #3 is endenvir)
   \def \kcmd@yargd@f ##1#4##2##{\afterassignment#5\endgroup
      #1#2\expandafter\def\expandafter#3\@gobble ##1#4%
   }\kcmd@yargd@f 0##1##2##3##4##5##6##7##8##9###4%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\kcmd@yargedef}\qquad\qquad
% This is the ``{\tt argdef}'' macro for the {\rred\bf\string+} form:
%    \begin{macrocode}
\protected \def \kcmd@yargedef#1#2#3#4#5#6{\begingroup
% #1 = global or {}
% #2 = long or {}
% #3 = Command
% #4 = nr of args
% #5 = endenvir (or \@gobble if not an environment, or \relax if #3 is endenvir)
% #6 = unexpandchar mounting macro
  \kcmd@nargs{#4}% 
   \protected\long\def\kcmd@yarg@edef##1##2{\endgroup
         #1\edef#3{\begingroup #6%
            #2\edef#3\unexpanded{##2}{\endgroup\unexpanded{##1}%
         }#3}%
   }%
   \protected\def\kcmd@envir##1{%
      \edef\next{\kcmd@yarg@edef{\def\noexpand#5{\expandonce{#5##1}}\expandonce{#3##1}}}\next
   }%
   \protected\def\kcmd@command##1{%
      \edef\next{\kcmd@yarg@edef{\expandonce{#3##1}}}\next
   }%
   \protected\def\kcmd@yargedef##1{%
      \kcmd@yargedef@##1 0####1####2####3####4####5####6####7####8####9#####4%
   }%
   \ifx#5\@gobble % keycommand
      \def\next{\kcmd@command}%
   \else          % key-environmment
      \def\next{\kcmd@envir}%
   \fi
   \let\@next\relax
   \def\kcmd@yargedef@##1##2#4##3##{%
      \ifx\@next\relax 
         \edef\@next{\next{\expandonce{\kcmd@nargs}}{\expandonce{\@gobble##2#4}}}%
         \ifx#5\@gobble \edef\@next{\expandonce\@next\noexpand#5}%
         \else \edef\@next{\edef\noexpand\@next{\noexpand\unexpanded{\expandonce\@next}}#5}%
         \fi
      \fi
      \afterassignment\@next
      \expandafter\def\expandafter##1\@gobble##2#4%
   }%
   \kcmd@yargedef#3%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\kcmd@nargs}\qquad
% Filter macros used by \cs{kcmd@yargedef} to get the correct number of arguments:
%    \begin{macrocode}
\def\kcmd@nargs#1{\edef\kcmd@nargs%##1##2##3##4##5##6##7##8##9%
        {\ifnum#1>0{####1%
         \ifnum#1>1}{####2%
         \ifnum#1>2}{####3%
         \ifnum#1>3}{####4%
         \ifnum#1>4}{####5%
         \ifnum#1>5}{####6%
         \ifnum#1>6}{####7%
         \ifnum#1>7}{####8%
         \ifnum#1>8}{####9%
         \fi\fi\fi\fi\fi\fi\fi\fi}\fi}%
}%
%    \end{macrocode}
% \end{macro}
%
% \subsection{new key-commands}
%
% \begin{macro}{\newkeycommand}\qquad\qquad
% Here are the entry points:
%    \begin{macrocode}
\newrobustcmd*\newkeycommand{\begingroup
   \let\kcmd@gbl\@empty\kcmd@star@or@long\new@keycommand}
\newrobustcmd*\renewkeycommand{\begingroup
   \let\kcmd@gbl\@empty\kcmd@star@or@long\renew@keycommand}
\newrobustcmd*\providekeycommand{\begingroup
   \let\kcmd@gbl\@empty\kcmd@star@or@long\provide@keycommand}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\kcmd@star@or@long}~\par
% This is the adaptation of \LaTeX's \cs{@star@or@long} macro:
%    \begin{macrocode}
\def\kcmd@star@or@long#1{\@ifstar
      {\let\kcmd@long\@empty\kcmd@plus#1}
      {\def\kcmd@long{\long}\kcmd@plus#1}}
\def\kcmd@@ifplus#1{\@ifnextchar +{\@firstoftwo{#1}}}% same as LaTeX's \@ifstar
\def\kcmd@plus#1{\kcmd@@ifplus
      {\def\kcmd@ifplus{\iftrue}\kcmd@testopt#1}
      {\def\kcmd@ifplus{\iffalse}\kcmd@testopt#1}}
\def\kcmd@testopt#1{\@testopt{\kcmd@unexpandchar#1}{}}
%    \end{macrocode}
% \end{macro}
%
%\begin{macro}{\kcmd@unexpandchar}\qquad\qquad\quad
% Reads the possible unexpand-char shortcut:
%    \begin{macrocode}
\def\kcmd@unexpandchar#1[#2]{%
   \kcmd@ifplus
      \kcmd@nbk#2//
         {\def\kcmd@unexpandchar{#2}% only once inside group...
          \def\kcmd@unexpandchar@activate{\catcode`#2 \active}%
         }{%
          \let\kcmd@unexpandchar\@empty
          \let\kcmd@unexpandchar@activate\relax
         }//%
   \else  \let\kcmd@unexpandchar\@empty
      \kcmd@nbk#2//%
         {\PackageError\kcmd@pkg@name{shortcut option for \string\unexpanded\MessageBreak
         You can't use a shortcut option for \string\unexpanded\MessageBreak
         without the \string+ form of \string\newkeycommand!}%
         {I will ignore this option and proceed.}%
         }%
         {}//%      
   \fi#1}
%    \end{macrocode}
%\end{macro}
%
% \begin{macro}{\new@keycommand}\qquad\qquad
% Reads the key-command name (cs-token):
%    \begin{macrocode}
\def\new@keycommand#1{\@testopt{\@newkeycommand#1}0}
%    \end{macrocode}
% \end{macro}
%
%\begin{macro}{\@newkeycommand}\qquad\qquad
% Reads the first optional parameter (keys or number of mandatory args):
%    \begin{macrocode}
\long\def\@newkeycommand#1[#2]{% #2 = key=values or N=mandatory args
   \kcmd@ifplus \kcmd@unexpandchar@activate \fi% activates unexpand-char before reading definition
   \kcmd@ifstrdigit{#2}%
      {\@new@key@command#1[][][{#2}]}% no kv, no optkey, number of args
      {\@testopt{\@new@keycommand#1[{#2}]}0}}% kv, check for optkey/nr of args
%    \end{macrocode}
% \end{macro}
%
%\begin{macro}{\@new@keycommand}\qquad\qquad
% Reads the second optional parameter (opt key or number of mandatory args):
%    \begin{macrocode}
\long\def\@new@keycommand#1[#2][#3]{%
   \kcmd@ifstrdigit{#3}%
      {\@new@key@command#1[{#2}][][{#3}]}% no optkey
      {\@testopt{\@new@key@command#1[{#2}][{#3}]}0}}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\@new@key@command}\qquad\qquad
% Reads the definition of the command (\cs{kcmd@def} handles both cases of commands and environements).
% The so called "unexpand-char shortcut" has been activated before reading command definition:
%    \begin{macrocode}
\long\def\@new@key@command#1[#2][#3][#4]#5{%
      \kcmd@def#1\@gobble[{#2}][{#3}][{#4}]{#5}{}}
%    \end{macrocode}
%\end{macro}
%
% \begin{macro}{\renew@keycommand}
%    \begin{macrocode}
\def\renew@keycommand#1{\begingroup
   \escapechar\m@ne\edef\@gtempa{{\string#1}}%
   \expandafter\@ifundefined\@gtempa
      {\endgroup\@latex@error{\noexpand#1undefined}\@ehc}
      \endgroup
   \let\@ifdefinable\@rc@ifdefinable
   \new@keycommand#1%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\provide@keycommand}
%    \begin{macrocode}
\def\provide@keycommand#1{\begingroup
   \escapechar\m@ne\edef\@gtempa{{\string#1}}%
   \expandafter\@ifundefined\@gtempa
      {\endgroup\new@keycommand#1}
      {\endgroup\def\kcmd@donot@provide{\renew@keycommand\kcmd@donot@provide
         }\kcmd@donot@provide}%
}
\let\kcmd@donot@provide\@empty% it must not be undefined
%    \end{macrocode}
% \end{macro}
%
% \subsection{new key-environments}
%
% \begin{macro}{\newkeyenvironment}
%    \begin{macrocode}
\newrobustcmd*\newkeyenvironment{\begingroup
   \let\kcmd@gbl\@empty\kcmd@star@or@long\new@keyenvironment}
\newrobustcmd\renewkeyenvironment{\begingroup
   \let\kcmd@gbl\@empty\kcmd@star@or@long\renew@keyenvironment}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\new@keyenvironment}
%    \begin{macrocode}
\def\new@keyenvironment#1{\@testopt{\@newkeyenva{#1}}{}}
\long\def\@newkeyenva#1[#2]{%
   \kcmd@ifstrdigit{#2}%
      {\@newkeyenv{#1}{[][][{#2}]}}
      {\@testopt{\@newkeyenvb{#1}[{#2}]}{}}}
\long\def\@newkeyenvb#1[#2][#3]{%
   \kcmd@ifstrdigit{#3}%
      {\@newkeyenv{#1}{[{#2}][][{#3}]}}
      {\@testopt{\@newkeyenvc{#1}{[{#2}][{#3}]}}0}}
\long\def\@newkeyenvc#1#2[#3]{\@newkeyenv{#1}{#2[{#3}]}}
\long\def\@newkeyenv#1#2{%
   \kcmd@ifplus \kcmd@unexpandchar@activate \fi
   \kcmd@keyenvir@def{#1}{#2}%
}
\long\def\kcmd@keyenvir@def#1#2#3#4{%
   \expandafter\let\csname end#1\endcsname\relax
   \expandafter\kcmd@def\csname #1\expandafter\endcsname\csname end#1\endcsname#2{#3}{#4}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\renew@keyenvironment}
%    \begin{macrocode}
\def\renew@keyenvironment#1{%
  \@ifundefined{#1}%
     {\@latex@error{Environment #1 undefined}\@ehc
     }\relax
  \cslet{#1}\relax
  \new@keyenvironment{#1}}
%    \end{macrocode}
% \end{macro}
% \iffalse
%<package>
%<package>
% \fi
%
% \subsection{Tests on keys}
%
% \begin{macro}{\ifcommandkey}\qquad
% \{\meta{key-name}\}\{\meta{true}\}\{\meta{false}\}\quad expands \meta{true} only if the value of the key
% is not blank:
%    \begin{macrocode}
\newcommand*\ifcommandkey[1]{\csname @\expandafter\expandafter\expandafter
   \kcmd@nbk\commandkey{#1}//{first}{second}//%
   oftwo\endcsname}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\showcommandkeys}\qquad\qquad are helper macros essentially for debuging purpose...
%    \begin{macrocode}
\newrobustcmd*\showcommandkeys[1]{\let\do\showcommandkey\docsvlist{#1}}
\newrobustcmd*\showcommandkey[1]{key \string"#1\string" = %
   \detokenize\expandafter\expandafter\expandafter{\commandkey{#1}}\par}
%    \end{macrocode}
% \end{macro}
% 
%
%    \begin{macrocode}
%</package>
%    \end{macrocode}
%
% \section{Examples}
% \label{sec:examples}
%
%    \begin{macrocode}
%<*example>
\ProvidesFile{keycommand-example}
\documentclass[a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage[american]{babel}
\usepackage{keycommand,framed,fancyvrb}
%
\makeatletter
\parindent\z@
\newkeycommand*\Rule[raise=.4ex,width=1em,thick=.4pt][1]{%
   \rule[\commandkey{raise}]{\commandkey{width}}{\commandkey{thick}}%
   #1%
   \rule[\commandkey{raise}]{\commandkey{width}}{\commandkey{thick}}}

\newkeycommand*\charleads[sep=1][2]{%
   \ifhmode\else\leavevmode\fi\setbox\@tempboxa\hbox{#2}\@tempdima=1.584\wd\@tempboxa%
   \cleaders\hb@xt@\commandkey{sep}\@tempdima{\hss\box\@tempboxa\hss}#1%
   \setbox\@tempboxa\box\voidb@x}
\newcommand*\charfill[1][]{\charleads[{#1}]{\hfill\kern\z@}}
\newcommand*\charfil[1][]{\charleads[{#1}]{\hfil\kern\z@}}
%
\newkeyenvironment*{dblruled}[first=.4pt,second=.4pt,sep=1pt,left=\z@]{%
   \def\FrameCommand{%
      \vrule\@width\commandkey{first}%
      \hskip\commandkey{sep}
      \vrule\@width\commandkey{second}%
      \hspace{\commandkey{left}}}%
   \parindent\z@
   \MakeFramed {\advance\hsize-\width \FrameRestore}}
   {\endMakeFramed}
%
\makeatother
\begin{document}
\title{This is {\tt keycommand-example.tex}}
\author{Florent Chervet}
\date{July 22, 2009}

\maketitle

{\Large Please refer to {\tt keycommand-example.tex} for definitions.}

\section{Example of a keycommand : \texttt{\string\Rule}}

\begin{tabular*}\textwidth{rl}
\verb+\Rule[width=2em]{hello}+:&\Rule[width=2em]{hello}\cr
\verb+\Rule[thick=1pt,width=2em]{hello}+:&\Rule[thick=1pt,width=2em]{hello}\cr
\verb+\Rule{hello}+:&\Rule{hello}\cr
\verb+\Rule[thick=1pt,raise=1ex]{hello}+:&\Rule[thick=1pt,raise=1ex]{hello}
\end{tabular*}

\section{Example of a keycommand : \texttt{\string\charfill}}

\begin{tabular*}\textwidth{rp{.4\textwidth}}
\verb+\charfill{$\star$}+: & \charfill{$\star$}\cr
\verb+\charfill[sep=2]{$\star$}+: & \charfill[sep=2]{$\star$} \\
\verb+\charfill[sep=.7]{\textasteriskcentered}+: & \charfill[sep=.7]{\textasteriskcentered}
\end{tabular*}


\section{Example of a keyenvironment : \texttt{dblruled}}

Key environment \texttt{dblruled } uses \texttt{framed.sty} and therefore it can be used 
even if a pagebreak occurs inside the environment:
\medskip

\verb+\begin{dblruled}+\par
\verb+   test for dblruled key-environment\par+\par
\verb+   test for dblruled key-environment\par+\par
\verb+   test for dblruled key-environment+\par
\verb+\end{dblruled}+

\begin{dblruled}
 test for dblruled key-environment\par
 test for dblruled key-environment\par
 test for dblruled key-environment
\end{dblruled}


\verb+\begin{dblruled}[first=4pt,sep=2pt,second=.6pt,left=.2em]+\par
\verb+   test for dblruled key-environment\par+\par
\verb+   test for dblruled key-environment\par+\par
\verb+   test for dblruled key-environment+\par
\verb+\end{dblruled}+

\begin{dblruled}[first=4pt,sep=2pt,second=.6pt,left=.2em]
 test for dblruled key-environment\par
 test for dblruled key-environment\par
 test for dblruled key-environment
\end{dblruled}

\end{document}
%</example>
%    \end{macrocode}
% \DeleteShortVerb{\+}^^A\UndefineShortVerb{\+}
% \begin{History}
% 
%   \begin{Version}{2010/04/27 v3.1415}
%   \item Key-environment can now be nested ! (it's not too late... I hope so)
%   \item Keys and mandatory arguments as well can be used in both \texttt{begin} end \texttt{end} part of the environment.
%   \end{Version}
% 
%   \begin{Version}{2010/04/25 v3.141}
%   \item No new feature but a real improvement in optimization. \\
%         In particular, \thispackage does not load \xpackage{etextools} anymore. \\
%   \item Bug fix for \cs{providekeycommand}.
%         
%   \end{Version}
%
%   \begin{Version}{2010/04/18 v3.14}
%   \item Correction of bug in the normalization process. \\
%         Correction of a bug in \cs{ifcommandkey} (undesirable space...)
%   \item Modification of the pdf documentation for the \stform+ form of key-environments.
%   \end{Version}
%
%   \begin{Version}{2010/03/28 v3.0}
%   \item Complete redesign of the implementation. \\
%   \xpackage{keycommand} is now based on some macros of \xpackage{etoolbox}.
%
%   \item Adding the + prefix and the ability to capture keys that where not defined.
%
%   \end{Version}
%
%   \begin{Version}{2009/07/22 v1.0}
%   \item
%     First version.
%   \end{Version}
%
% \end{History}
%
% \begin{thebibliography}{9}
%
% \bibitem{xkeyval}
%   Hendri Adriaens:
%   \textit{The \xpackage{xkeyval} package};
%   2008/08/13 v2.6a;
%   \CTAN{macros/latex/contrib/xkeyval.dtx}
%
% \bibitem{kvsetkeys}
%   Heiko Oberdiek:
%   \textit{The \xpackage{kvsetkeys} package};
%   2007/09/29 v1.3;
%   \CTAN{macros/latex/contrib/oberdiek/kvsetkeys.dtx}.
%
% \bibitem{keyval}
%   David Carlisle:
%   \textit{The \xpackage{keyval} package};
%   1999/03/16 v1.13;
%   \CTAN{macros/latex/required/graphics/keyval.dtx}.
%
% \end{thebibliography}
%
% \PrintIndex
%
% \label{LastPage}
% \Finale