From 899f74725ef26bec837b6c3564ffd0108c6db6ec Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Mon, 29 Mar 2010 23:36:00 +0000 Subject: keycommand update (29mar10) git-svn-id: svn://tug.org/texlive/trunk@17616 c570f23f-e606-0410-a88d-b1316a301751 --- .../texmf-dist/tex/latex/keycommand/keycommand.sty | 429 ++++++++++++--------- 1 file changed, 253 insertions(+), 176 deletions(-) (limited to 'Master/texmf-dist/tex/latex') diff --git a/Master/texmf-dist/tex/latex/keycommand/keycommand.sty b/Master/texmf-dist/tex/latex/keycommand/keycommand.sty index 738ed1f69a5..fbb8b0f007d 100644 --- a/Master/texmf-dist/tex/latex/keycommand/keycommand.sty +++ b/Master/texmf-dist/tex/latex/keycommand/keycommand.sty @@ -8,7 +8,7 @@ %% %% This is a generated file. %% -%% keycommand : an easy way to define commands with optional keys [v2.z 2009/08/26] +%% keycommand : key-value interface for commands and environments in LaTeX [v3.0 2010/03/28] %% %% This work may be distributed and/or modified under the %% conditions of the LaTeX Project Public License, either @@ -22,204 +22,281 @@ %% keycommand-example.tex %% %% keycommand : an easy way to define commands with optional keys -%% Copyright (C) 2009 by Florent Chervet +%% Copyright (C) 2009-2010 by Florent Chervet %% - \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} - [2009/07/22 v2.e- an easy way to define commands with optional keys] -\RequirePackage{etex,kvsetkeys} -\edef\kcmd@AtEnd{\catcode34 \the\catcode34}% " -\catcode34 4 -\def\kcmd@keydef#1#2#3#4#5{% #1=\global, #2=command, #3=family, #4=key, #5=def - #1\expandafter\edef\csname kcmd@keys\string#2\endcsname{% - \csname kcmd@keys\string#2\endcsname,#4}% - #1\@namedef{KV@#3@#4@default\expandafter}\expandafter{% - \csname KV@#3@#4\endcsname{#5}}% - #1\@namedef{KV@#3@#4}##1} -\def\kcmd@definekey#1#2#3#4#5{% - \begingroup\edef\@tempa{\endgroup - \unexpanded{\kcmd@keydef{#1}{#2}{#3}{#4}{#5}}{\def - \expandafter\noexpand\csname #3@#4\endcsname{####1}}% - }\@tempa} -\def\kcmd@undefinekeys#1#2{% - \@ifundefined{kcmd@keys\string#2} - \relax - {\expandafter\@for\expandafter\kcmp@temp - \expandafter:\expandafter=\csname kcmd@keys\string#2\endcsname - \do{#1\expandafter\let - \csname KV@kcmd@\expandafter\@gobble\string #2@\kcmp@temp @default\endcsname - \@undefined - #1\expandafter\let - \csname KV@kcmd@\expandafter\@gobble\string #2@\kcmp@temp\endcsname - \@undefined}}% - #1\@namedef{kcmd@keys\string#2}{\@gobble}} - -\DeclareRobustCommand\keycmd{\@star@or@long\kcmd@prefix} -\def\kcmd@prefix{\begingroup - \let\kcmd@gbl\@empty - \def\kcmd@prfx{\l@ngrel@x}% - \futurelet\x\kcmd@@prefix} -\def\kcmd@@prefix{% - \let\kcmd@next@addto\kcmd@next@prefix - \ifx\x\@sptoken \let\next\kcmd@space@prefix - \else \let\next\kcmd@addto@prfx - \ifx\x\long - \else\ifx\x\outer - \else\ifx\x\protected - \else\ifx\x\global \def\kcmd@gbl{\global}% + [2010/03/29 v3.0 - key-value interface for commands and environments in LaTeX] +\def\kcmd@pkg@name{keycommand} +\RequirePackage{etex,kvsetkeys,xkeyval,etoolbox,etextools} +\def\kcmd@Xsetkeys{\XKV@testopta{\XKV@testoptc\XKV@setkeys}}% in case \setkeys was overwritten +\@ifpackagelater{etextools}{2009/08/27}\relax + {\PackageError\kcmd@pkg@name{keycommand requires an implementation of\MessageBreak + package etextools later than 2009/08/27.\MessageBreak + Please update your distribution with a recent version of etextools}% + {The keycommand package will not be loaded.}% + \expandafter\endinput} +\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} +\newrobustcmd\kcmd@normalize@setkeys[4]{% + \kv@normalize{#4}\edef\kv@list{\csvloop[\kcmd@normalize@braces]\kv@list}% + \expandafter\@swaparg\expandafter{\kv@list}{\kcmd@Xsetkeys*{#2}}% + \ettl@nbk#3//{\csedef{#2@#3}{\expandonce{\XKV@rm}}}% + {\expandafter\ettl@nbk\XKV@rm//% + {\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{\kcmd@normalize@br@ces#1==\@nil} +\long\def\kcmd@normalize@br@ces#1=#2=#3\@nil{\unexpanded{#1={{{#2}}},}} +\def\kcmd@check@typeofkey#1{% expands to + \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//{\ettl@nbk#1//} +\def\kcmd@get@keyname@bool #1bool #2//{#2} +\def\kcmd@check@typeofkey@enumst #1enum* #2//{\ettl@nbk#1//} +\def\kcmd@get@keyname@enumst #1enum* #2//{#2} +\def\kcmd@check@typeofkey@enum #1enum #2//{\ettl@nbk#1//} +\def\kcmd@get@keyname@enum #1enum #2//{#2} +\def\kcmd@check@typeofkey@choicest #1choice* #2//{\ettl@nbk#1//} +\def\kcmd@get@keyname@choicest #1choice* #2//{#2} +\def\kcmd@check@typeofkey@choice #1choice #2//{\ettl@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 + \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\@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,\@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,\@nil}}% error handler + }\kcmd@define@choicekey} +\def\kcmd@define@boolkey#1#2#3#4{\begingroup + \ettl@nbk#4//{\def\default{#4}}{\def\default{true}}//% + \edef\kcmd@define@boolkey{\endgroup + \noexpand\define@choicekey*+{#2}{#3}[\noexpand\val\noexpand\nr]% + {false,true} + [{\expandonce\default}]% + {\csedef{#2@#3}{\noexpand\number\noexpand\nr}}% + {\kcmd@error@handler\noexpand#1{#2}{#3}{\expandonce\default}}% + }\kcmd@define@boolkey} +\protected\long\def\kcmd@error@handler#1#2#3#4{% + \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}}} +\def\kcmd@undefinekeys#1#2{% #1 = global, #2 = family + \ifcsundef{#2.keylist} + {} + {\expandnext{\csvloop[\kcmd@undefinekey{#1}{#2}]}{\csname #2.keylist\endcsname}}% + \cslet{#2.keylist}\noexpand\@gobble} +\def\kcmd@undefinekey#1#2#3{% #1 = global, #2 = family, #3 = key + #1\csundef{KV@#2@#3}% + #1\csundef{KV@#2@#3@default}% +} +\protected\long\def\kcmd@def#1#2[#3][#4][#5]#6#7{% + \@ifdefinable#1{\kcmd@defcommand#1[{#3}][{#4}][{#5}]{#6}{#2}{#7}}} +\protected\long\def\kcmd@defcommand#1[#2][#3][#4]#5#6#7{% + \edef\kcmd@fam{\kcmd@keyfam{#1}}\let\commandkey\relax + \edef\kcmd@defcommand{\endgroup + \kcmd@undefinekeys{\kcmd@gbl}{\kcmd@fam}% undefines all keys for this keycommand family + \kcmd@mount@unexpandchar{\kcmd@fam}{\expandonce\kcmd@unexpandchar}% + \unexpanded{\kv@parse{#2,#3}}{\kcmd@definekey\noexpand#1{\kcmd@gbl}{\kcmd@fam}}% defines the keys for this keycommand + \csdef{\kcmd@fam.commandkey}####1{\noexpand\csname\kcmd@fam @####1\endcsname}% + \csdef{\kcmd@fam.getcommandkey}####1{\unexpanded{\unexpanded\expandafter\expandafter\expandafter}{% + \noexpand\csname\kcmd@fam @####1\endcsname}}% + \let\commandkey\expandafter\noexpand\csname\kcmd@fam.\kcmd@plus get\fi commandkey\endcsname + \kcmd@plus % %% ENDENVIR ?? + \csdef{\kcmd@fam}{\kcmd@yargedef{\kcmd@gbl}{\kcmd@long}{\noexpandcs\kcmd@fam}{\number#4}{#6}{\csname\kcmd@fam.unexpandchar\endcsname}}% + \unless\ifx#6\relax\def#6{\kcmd@yargedef{\kcmd@gbl}{\kcmd@long}{#6}0{\relax}{\csname\kcmd@fam.unexpandchar\endcsname}}\fi \else - \def\kcmd@next@addto{\expandafter\key@cmd\noexpand}% - \ifx\x\def - \else\ifx\x\edef - \else\ifx\x\gdef \def\kcmd@gbl{\global}% - \else\ifx\x\xdef \def\kcmd@gbl{\global}% - \else \let\kcmd@next@addto\kcmd@next@prefix - \ifx\y\x\kcmd@error@prefix - \else\let\y\x - \fi - \let\next\kcmd@expand@prefix - \fi\fi\fi\fi - \fi\fi\fi\fi - \fi\next} -\def\kcmd@next@prefix{\futurelet\x\kcmd@@prefix} -\def\kcmd@expand@prefix{\expandafter\kcmd@next@prefix} -\def\kcmd@addto@prfx#1{\let\y\@undefined - \expandafter\def\expandafter\kcmd@prfx - \expandafter{\kcmd@prfx#1}\kcmd@next@addto} -\expandafter\def\expandafter\kcmd@space@prefix\space{\kcmd@next@prefix} -\def\kcmd@error@prefix{\@latex@error{A \string\def\space - (or \string\gdef\space or \string\edef\space or \string\xdef)\MessageBreak - was expected after \string\keycmd\MessageBreak - I found a \meaning\x!\MessageBreak - see keycommand documentation for more information}\@ehd} -\def\key@cmd#1{\@testopt{\expandafter\@keycmd\noexpand#1}{}} -\def\@keycmd#1[#2]{\@tempswafalse\expandafter - \@rc@ifdefinable\noexpand#1{\@tempswatrue}% - \if@tempswa - \let#1=\relax - \def\next{\kcmd@def#1{#2}}% - \else \def\next{\afterassignment\endgroup - \def\kcmd@notdefinable}% - \fi\next} -\def\kcmd@relaxify{% - \let\commandkey\relax - \let\kvsetkeys\relax - \let\kv@parse\relax - \let\@testopt\relax - \let\kv@set@family@handler\relax - \let\kcmd@undefinekeys\relax - \let\kcmd@keyerr\relax - \let\kcmd@definekey\relax - \def\"##1"{\expandafter\noexpand\csname ##1\endcsname}} -\def\kcmd@def#1#2{% #1=\Command, #2=key-values - \edef\kcmd@fam{kcmd@\expandafter\@gobble\string#1}% - \kcmd@relaxify - \edef\kcmd@def@##1{\endgroup - \kv@set@family@handler{\kcmd@fam}{\kcmd@keyerr{#1}{####1}{####2}}% - \kcmd@undefinekeys{\kcmd@gbl}{#1}% - \kv@parse{##1}{\kcmd@definekey{\kcmd@gbl}{#1}{\kcmd@fam}}% - \kcmd@gbl\protected\def#1{% entry point - \def\commandkey########1{\noexpand\csname\kcmd@fam @########1\endcsname}% - \def\"kcmd\string#1"########1[########2]{% - \kvsetkeys{\kcmd@fam}{########1,########2}% - \"\string #1"}% - \@testopt{\"kcmd\string#1"{##1}}{}}% - \let\commandkey\relax - \expandafter\expandafter\expandafter - \expandafter\expandafter\expandafter - \expandafter\kcmd@prfx\"\string#1"% - }\kcmd@def@{#2}} -\def\kcmd@keyerr#1#2#3{% - \let\wheremsg\@empty - \ifdefined\trcg@where\trcg@where{#1}\fi - \@latex@error{There was no key "#2" \MessageBreak - in the keycommand \string#1!\MessageBreak - see the definition of the keycommand (or environment)\wheremsg}\@ehd} -\DeclareRobustCommand\newkeycommand{\@star@or@long - {\expandafter\new@keycommand\noexpand}} -\DeclareRobustCommand\renewkeycommand{\@star@or@long - {\expandafter\renew@keycommand\noexpand}} -\DeclareRobustCommand\providekeycommand{\@star@or@long - {\expandafter\provide@keycommand\noexpand}} -\def\new@keycommand#1{\@testopt{\expandafter\@newkeycommand\noexpand#1}{}} -\def\@newkeycommand#1[#2]{\begingroup - \@tempswafalse\expandafter - \@ifdefinable\noexpand#1{\@tempswatrue}% - \if@tempswa - \let#1=\relax - \let\kcmd@gbl\@empty - \def\kcmd@prfx##1{\unexpanded{\@testopt{\@argdef{##1}}0}}% - \def\next{\kcmd@def#1{#2}}% - \else \def\next{\afterassignment\endgroup - \def\kcmd@notdefinable}% - \fi\next} -\def\renew@keycommand#1{\begingroup + \csdef{\kcmd@fam}{\kcmd@yargdef{\kcmd@gbl}{\kcmd@long}{\noexpandcs\kcmd@fam}{\number#4}{#6}}% + \unless\ifx#6\relax\def#6{\kcmd@yargdef{\kcmd@gbl}{\kcmd@long}{#6}0{\relax}}\fi + \fi + \kcmd@gbl\protected\edef#1{% entry point %%(?? cas où il n'y a pas de clé => pas besoin de \@testopt\kcmd@init etc ... at run time) + \let\noexpand\noexpand\commandkey\noexpand\noexpand\noexpandcs{\kcmd@fam.\kcmd@plus get\fi commandkey}% + \noexpand\csvloop[\noexpand\kcmd@resetdefault{\kcmd@fam}]{\noexpandcs{\kcmd@fam.keylist}}% + \noexpand\noexpand\noexpand\@testopt{% + \kcmd@setkeys\noexpand\noexpand#1{\kcmd@fam}{\kcmd@otherkeys{#3}}}{}}% + \noexpandcs\kcmd@fam% + }\kcmd@defcommand{#5}{#7}% +} +\protected\long\def\kcmd@setkeys#1#2#3[#4]{% + \kcmd@normalize@setkeys{#1}{#2}{#3}{#4}\csname#2\endcsname} +\def\kcmd@resetdefault#1#2{\noexpandcs{KV@#1@#2@default}} +\long\def\kcmd@otherkeys#1{\ettl@nbk#1//{\kcmd@@therkeys#1=\@nil}{}//} +\long\def\kcmd@@therkeys#1=#2\@nil{#1} +\protected\def\kcmd@mount@unexpandchar#1#2{% + \ettl@nbk#2//{% + \protected\csdef{#1.unexpandchar}{\begingroup + \catcode`\~\active \lccode`\~`#2 \lccode`#2 0\relax + \lowercase{\def~{\catcode`#2\active + \long\def~########1~{\unexpanded{########1}}}% + \ettl@aftergroup@def~\endgroup~}}}% + {\cslet{#1.unexpandchar}\@empty}//% +} +\protected \def \kcmd@yargdef #1#2#3#4#5{\begingroup + \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% +} +\protected\def\kcmd@yargedef#1#2#3#4#5#6{\begingroup + \letcs\kcmd@nargs{kcmd@#4of9}% + \long\def\kcmd@yarg@edef##1##2{\afterassignment#5\endgroup + #1\edef#3{\begingroup #6% + #2\edef\unexpanded{#3##2}{\endgroup\unexpanded{##1}% + }\noexpand#3}% + }% + \protected\def\kcmd@yarg@body{\edef\body{\unexpanded\expandafter\expandafter\expandafter{% + \expandafter#3\kcmd@nargs{{####1}}{{####2}}{{####3}}{{####4}}{{####5}}{{####6}}{{####7}}{{####8}}{{####9}}}% + }\expandafter\kcmd@yarg@edef\expandafter{\body}}% + \def\kcmd@yarged@f##1#4##2##{% + \edef\kcmd@yargedef@next{\kcmd@yarg@body{\expandonce{\@gobble ##1#4}}}% + \afterassignment\kcmd@yargedef@next + \expandafter\def\expandafter#3\@gobble ##1#4% + }\kcmd@yarged@f 0##1##2##3##4##5##6##7##8##9###4% +} +\def\kcmd@XofNINE#1{% + \def\kcmd@XofNine##1#1##2##{% + \expandafter\csedef{kcmd@#1of9}####1####2####3####4####5####6####7####8####9{% + \@gobble ##1#1}% + }\kcmd@XofNine 0##1##2##3##4##5##6##7##8##9###1{}% +} +\csvloop*[\kcmd@XofNINE]{1,2,3,4,5,6,7,8,9,0} +\undef\kcmd@XofNine\undef\kcmd@XofNINE +\protected\def\newkeycommand{\begingroup + \let\kcmd@gbl\@empty\kcmd@modifiers\new@keycommand} +\protected\def\renewkeycommand{\begingroup + \let\kcmd@gbl\@empty\kcmd@modifiers\renew@keycommand} +\protected\def\providekeycommand{\begingroup + \let\kcmd@gbl\@empty\kcmd@modifiers\provide@keycommand} +\protected\def\kcmd@modifiers#1{% + \futuredef[*+]\kcmd@modifiers{% only once inside group + \edef\kcmd@long{\expandafter\kcmd@ifstar\kcmd@modifiers*\relax}% + \edef\kcmd@plus{\expandafter\kcmd@ifplus\kcmd@modifiers+\relax}% + \@testopt{\kcmd@unexpandchar#1}{}}} +\def\kcmd@ifstar#1*#2\relax{\ettl@nbk#2//{}\long//} +\def\kcmd@ifplus#1+#2\relax{\ettl@nbk#2//{\noexpand\iftrue}{\noexpand\iffalse}//} +\def\kcmd@unexpandchar#1[#2]{\def\kcmd@unexpandchar{#2}% only once inside group... + \kcmd@plus \ettl@nbk#2// + {\def\kcmd@unexpandchar@activate{\catcode`#2 \active}}% + {\let\kcmd@unexpandchar@activate\relax}//% + \else\ettl@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.}% + \let\kcmd@unexpandchar\@empty}% + {}//% + \fi#1} +\protected\def\new@keycommand#1{\@testopt{\@newkeycommand#1}{}} +\protected\def\@newkeycommand#1[#2]{% #2 = key=values or N=mandatory args (also expanded by @newkeyenv) + \ifstrnum{#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 +\protected\def\@new@keycommand#1[#2][#3]{% + \kcmd@plus \kcmd@unexpandchar@activate \fi% activate unexpand-char before reading definition + \ifstrnum{#3}% + {\@new@key@command#1[{#2}][][{#3}]}% no optkey + {\@testopt{\@new@key@command#1[{#2}][{#3}]}0}} +\protected\long\def\@new@key@command#1[#2][#3][#4]#5{% + \kcmd@def#1\relax[{#2}][{#3}][{#4}]{#5}{}} +\protected\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 - \expandafter\new@keycommand\noexpand#1} -\def\provide@keycommand#1{\begingroup + \new@keycommand#1} +\protected\def\provide@keycommand#1{% \escapechar\m@ne\edef\@gtempa{{\string#1}}% \expandafter\@ifundefined\@gtempa - {\endgroup\new@keycommand#1} - {\endgroup\let\kcmd@notdefinable\noexpand - \renew@keycommand\kcmd@notdefinable}} -\DeclareRobustCommand\newkeyenvironment{\@star@or@long\new@keyenvironment} -\DeclareRobustCommand\renewkeyenvironment{\@star@or@long\renew@keyenvironment} + {\new@keycommand#1} + {\@testopt{\provide@key@command\kcmd@notdefinable}{}}} +\protected\def\provide@key@command#1[#2]{\@tempswafalse\kcmd@def#1{#2}} +\protected\def\newkeyenvironment{\begingroup + \let\kcmd@gbl\@empty\kcmd@modifiers\new@keyenvironment} +\protected\def\renewkeyenvironment{\begingroup + \let\kcmd@gbl\@empty\kcmd@modifiers\renew@keyenvironment} \def\new@keyenvironment#1{\@testopt{\@newkeyenva{#1}}{}} \def\@newkeyenva#1[#2]{% - \kernel@ifnextchar [{\@newkeyenvb{#1}[{#2}]}{\@newkeyenv{#1}{[{#2}][0]}}} -\def\@newkeyenvb#1[#2][#3]{\@newkeyenv{#1}{[{#2}][#3]}} -\def\@newkeyenv#1#2#3#4{% - \@ifundefined{#1}% - {\expandafter\let\csname #1\expandafter\endcsname - \csname end#1\endcsname}% - \relax - \expandafter\@newkeycommand - \csname #1\endcsname#2{#3}% - \l@ngrel@x\expandafter\def\csname end#1\endcsname{#4}} + \ifstrnum{#2}% + {\@newkeyenv{#1}{[][][{#2}]}} + {\@testopt{\@newkeyenvb{#1}[{#2}]}{}}} +\def\@newkeyenvb#1[#2][#3]{% + \ifstrnum{#3}% + {\@newkeyenv{#1}{[{#2}][][{#3}]}} + {\@testopt{\@newkeyenvc{#1}{[{#2}][{#3}]}}0}} +\def\@newkeyenvc#1#2[#3]{\@newkeyenv{#1}{#2[{#3}]}} +\long\def\@newkeyenv#1#2{% + \kcmd@plus \kcmd@unexpandchar@activate \fi + \kcmd@keyenvir@def{#1}{#2}% +} +\long\def\kcmd@keyenvir@def#1#2#3#4{% + \cslet{end#1}\protected% %%?? et si end#1 est déjà défini et pas #1 (\@ifdefinable ne teste que #1) ?? + \expandafter\kcmd@def\csname #1\expandafter\endcsname\csname end#1\endcsname#2{#3}{#4}% +} \def\renew@keyenvironment#1{% \@ifundefined{#1}% {\@latex@error{Environment #1 undefined}\@ehc }\relax - \expandafter\let\csname#1\endcsname\relax - \expandafter\let\csname\expandafter\string\csname #1\endcsname\endcsname\relax - \expandafter\let\csname end#1\endcsname\relax + \cslet{#1}\relax \new@keyenvironment{#1}} \def\kcmd@afterelse#1\else#2\fi{\fi#1} \def\kcmd@afterfi#1\fi{\fi#1} -\newcommand\kcmd@expandnext[2]{% - \ifx#1\kcmd@expandnext - \kcmd@afterelse\expandafter\expandafter\expandafter - \expandafter\@kcmd@expandnext{#2}{\expandafter\expandafter\expandafter}% - \else\kcmd@afterfi\expandafter#1\expandafter{#2}% - \fi} -\long\def\@kcmd@expandnext#1#2#3{% - \ifx#1\kcmd@expandnext - \expandafter\kcmd@afterelse\expandafter\expandafter\expandafter - \expandafter\@kcmd@expandnext{#3}{\expandafter#2#2}% - \else - \expandafter\kcmd@afterfi#2#1#2{#3}% - \fi} -\def\kcmd@expandonce#1{\unexpanded\expandafter{#1}} -\begingroup\catcode`\:=4\catcode`\&=4 -\gdef\kcmd@ifblank#1{\kcmd@ifblank@#1&&\@secondoftwo\@firstoftwo:} -\gdef\kcmd@ifblank@#1#2#4#5:{#4} -\endgroup -\newcommand\ifcommandkey[3]{% - \kcmd@expandnext\kcmd@expandnext\kcmd@expandnext\kcmd@expandnext\kcmd@expandnext - \kcmd@expandnext\kcmd@expandnext\kcmd@expandnext\kcmd@expandnext\kcmd@expandnext - \kcmd@expandnext\kcmd@expandnext\kcmd@expandnext\kcmd@ifblank{% - \kcmd@expandnext\kcmd@expandnext\kcmd@expandonce{\commandkey{#1}}} - {#3} - {#2}} -\kcmd@AtEnd +\def\kcmd@keyfam#1{\detokenize{keycmd->}\expandafter\@gobble\string#1} +\newcommand*\ifcommandkey[1]{\csname @\expandafter\expandafter\expandafter + \ettl@nbk\commandkey{#1}//{first}{second}//% + oftwo\endcsname} +\newcommand\showcommandkeys[1]{\let\do\showcommandkey\docsvlist{#1}} +\newcommand\showcommandkey[1]{key \string"#1\string" = % + \expandnext\expandnext\expandnext\detokenize{\commandkey{#1}}\par} \endinput %% %% End of file `keycommand.sty'. -- cgit v1.2.3