diff options
author | Karl Berry <karl@freefriends.org> | 2010-01-28 23:01:23 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2010-01-28 23:01:23 +0000 |
commit | a30dc652eb93949bfefbdb8f7a536f185cd10377 (patch) | |
tree | 398b69a78d723497712bbda9eb5ec1a895c177db /Master/texmf-dist/tex/latex/keyreader | |
parent | ab51c86a9a56057bf65dd24070192b97472331df (diff) |
keyreader 0.3 (27jan10)
git-svn-id: svn://tug.org/texlive/trunk@16856 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/keyreader')
-rw-r--r-- | Master/texmf-dist/tex/latex/keyreader/keyreader.sty | 596 |
1 files changed, 466 insertions, 130 deletions
diff --git a/Master/texmf-dist/tex/latex/keyreader/keyreader.sty b/Master/texmf-dist/tex/latex/keyreader/keyreader.sty index 5b28021c5b2..da826d47d9b 100644 --- a/Master/texmf-dist/tex/latex/keyreader/keyreader.sty +++ b/Master/texmf-dist/tex/latex/keyreader/keyreader.sty @@ -1,6 +1,6 @@ -%+++++++++++++++++++++++++++++++++++++ LICENSE ++++++++++++++++++++++++++++++++++++++% +%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++% % % -% This is file 'keyreader.sty', version 0.2. % +% This is file 'keyreader.sty', version 0.3. % % % % This package reads multiple keys to be defined by xkeyval.sty. % % % @@ -24,8 +24,8 @@ \catcode064 11% @ \catcode123 01% { \catcode125 02% } -\def\x{\endgroup - \edef\kr@restorecodes{% +\def\KR@tempa{\endgroup + \edef\KR@restorecodes{% \catcode035 \the\catcode035% # \catcode064 \the\catcode064% @ \catcode123 \the\catcode123% { @@ -33,66 +33,156 @@ \catcode061 \the\catcode061% = }% } -\x +\KR@tempa \@makeother{\=}% \catcode035=06% # \catcode064=11% @ \catcode123=01% { \catcode125=02% } -\def\kr@ensurecode#1#2{% - \edef\kr@restorecodes{% - \kr@restorecodes +\def\KR@ensurecode#1#2{% + \edef\KR@restorecodes{% + \KR@restorecodes \catcode#1=\the\catcode#1\relax }% \catcode#1=#2\relax } -\AtEndOfPackage{\kr@restorecodes} -\kr@ensurecode{044}{12}% , -\kr@ensurecode{058}{12}% : -\kr@ensurecode{059}{12}% ; -\kr@ensurecode{038}{03}% & +\AtEndOfPackage{\KR@restorecodes} +\KR@ensurecode{044}{12}% , +\KR@ensurecode{058}{12}% : +\KR@ensurecode{059}{12}% ; \ProvidesPackage{keyreader}% - [2010/01/13 v0.2 Read multiple keys for the xkeyval parser (AM)] + [2010/01/24 v0.3 Extensions for the xkeyval parser (AM)] \NeedsTeXFormat{LaTeX2e}[1996/12/01] \@ifpackageloaded{xkeyval}{}{\RequirePackage{xkeyval}[2008/08/13]} -\protected\long\def\kr@warn#1{\PackageWarningNoLine{keyreader}{#1}} -\protected\long\def\kr@err#1{\PackageError{keyreader}{#1}{\@ehc}} -\protected\long\def\kr@afterfi#1\fi{\fi#1} -\def\kr@CommandListParser#1{% - \long\def\kr@define@keylist##1##2{% - \mathchardef\kr@tempcntb=\z@ - ##1\kr@readlist##2#1& - }% - \long\def\kr@readlist##1#1##2&{% - \kr@ifblank{##1}{}% +\def\KR@nil{\noexpand\KR@nil} +\protected\long\def\KR@info#1{\PackageInfo{keyreader}{#1\@gobble}} +\protected\long\def\KR@warn#1{\PackageWarningNoLine{keyreader}{#1}} +\protected\long\def\KR@err#1#2{\PackageError{keyreader}{#1}{#2}} +\protected\long\def\KR@afterfi#1\fi{\fi#1} +\protected\long\def\KR@afterelsefi#1\else#2\fi{\fi#1} +\def\KR@commandlistparser#1{% + \long\def\KR@define@keylist##1##2{% + \mathchardef\KR@tempcntb=\z@ + ##1\KR@readlist##2#1\KR@nil + }% + \long\def\KR@readlist##1#1##2\KR@nil{% + \KR@ifblank{##1}{}% {% - \edef\@i{\detokenize{##1}}% - \edef\@ii{\detokenize{\stopread}}% - \ifx\@i\@ii - \mathchardef\kr@tempcntb=\@ne - \stopread##2& - \else - \kr@define@key##1& - \fi + \KR@ifstrequal{##1}{\stopread}{% + \mathchardef\KR@tempcntb=\@ne + \stopread##2\KR@nil + }{% + \KR@define@multiple@keys##1\KR@nil + }% }% - \ifnum\kr@tempcntb=\z@ - \kr@ifblank{##2}{}{\kr@readlist##2&}% + \ifnum\KR@tempcntb=\z@ + \KR@ifblank{##2}{}{\KR@readlist##2\KR@nil}% \fi }% } -\define@cmdkey[KV]{keyreader}[kr@]{parser}[;]{% - \if\kr@parser,\kr@afterfi\kr@err{Parser can't be comma}\fi - \kr@CommandListParser{#1}% +\def\KR@expandargs#1#2#3#4{% + \begingroup + \protected@edef\KR@tempa{\endgroup + \ifcase#1\relax + \noexpand#2{#3}% + \or + \unexpanded{#2#3}{#4}% + \or + \noexpand#2{#3}{#4}% + \or + {#2}{#3}{#4}% + \else + \KR@err{Erroneous expansion type '#1'}{\noexpand\@ehc} + \fi + }% + \KR@tempa +} +\long\def\KR@inputerr#1#2{% + \KR@err{Erroneous value '#1' for key '#2'}{% + Please use the correct value for key '#2'.}% +} +\protected\long\def\KR@ifblank#1{% + \KR@ifbl@nk#1\KR@nil\KR@nil\@secondoftwo\@firstoftwo:} +\long\def\KR@ifbl@nk#1#2\KR@nil#3#4#5:{#4} +\protected\def\KR@xifblank#1{\KR@expandargs{0}\KR@ifblank{#1}} +\def\KR@findescape#1{% + \begingroup + \escapechar=92\relax + \edef\KR@tempa{\expandafter\@car\string#1\@nil}% + \ifx\KR@tempa\@backslashchar + \aftergroup\@secondoftwo + \else + \aftergroup\@firstoftwo + \fi + \endgroup +} +\protected\long\def\KR@ifstrequal#1#2{% + \begingroup + \KR@expandargs{1}\KV@@sp@def\KR@tempa{\detokenize{#1}}% + \KR@expandargs{1}\KV@@sp@def\KR@tempb{\detokenize{#2}}% + \ifx\KR@tempa\KR@tempb + \aftergroup\@firstoftwo + \else + \aftergroup\@secondoftwo + \fi + \endgroup +} +\protected\long\def\KR@xifstrequal#1#2{% + \KR@expandargs{2}\KR@ifstrequal{#1}{#2}% +} +\def\KR@listparser@err{% + \KR@err{List parser '\KR@parser' not allowed}% + {Use semicolon (preferable) or colon.}% +} +\define@cmdkey[KV]{keyreader}[KR@]{parser}[;]{% + \@onelevel@sanitize\KR@parser + \KR@xifblank{\KR@parser}{\KR@listparser@err}{}% + \KR@expandargs{1}\KV@@sp@def\KR@parser\KR@parser% + \def\KR@tempa{,}% + \ifx\KR@parser\KR@tempa\KR@listparser@err\fi + \KR@expandargs{0}\KR@commandlistparser\KR@parser% +} +\def\KR@keyprefix@err{% + \KR@err{Key prefix '\KR@keyprefix' is not allowed}% + {Use another prefix.}% +} +\define@cmdkey[KV]{keyreader}[KR@]{keyprefix}[KV]{% + \KR@xifblank{\KR@keyprefix}{\KR@keyprefix@err}{}% + \KR@expandargs{1}\KV@@sp@def\KR@keyprefix\KR@keyprefix% + \XKV@for@n{KR,mp,fam,XKV}\KR@tempa{% + \ifx\KR@keyprefix\KR@tempa\KR@keyprefix@err\fi + }% +} +\def\KR@keyfamily@err{% + \KR@err{Key family '\KR@keyfamily' is not allowed}% + {Use another family name.}% } -\define@cmdkey[KV]{keyreader}[kr@]{keyprefix}[KV]{} -\define@cmdkey[KV]{keyreader}[kr@]{keyfamily}[fam]{} -\define@cmdkey[KV]{keyreader}[kr@]{macroprefix}[mp@]{} -\define@boolkey[KV]{keyreader}[kr@]{xchoicelist}[true]{} -\DeclareOptionX*{\kr@warn{Unknown option '\CurrentOption' ignored}} +\define@cmdkey[KV]{keyreader}[KR@]{keyfamily}[fam]{% + \KR@xifblank{\KR@keyfamily}{\KR@keyfamily@err}{}% + \KR@expandargs{1}\KV@@sp@def\KR@keyfamily\KR@keyfamily% + \XKV@for@n{KR,mp,keyreader,KV,XKV}\KR@tempa{% + \ifx\KR@keyfamily\KR@tempa\KR@keyfamily@err\fi + }% +} +\def\KR@macroprefix@err{% + \KR@err{Macro prefix '\KR@macroprefix' is not allowed}% + {Use another prefix.}% +} +\define@cmdkey[KV]{keyreader}[KR@]{macroprefix}[mp@]{% + \KR@xifblank{\KR@macroprefix}{\KR@macroprefix@err}{}% + \KR@expandargs{1}\KV@@sp@def\KR@macroprefix\KR@macroprefix% + \XKV@for@n{KR,keyreader,fam,KV,XKV}\KR@tempa{% + \ifx\KR@macroprefix\KR@tempa\KR@macroprefix@err\fi + }% +} +\define@boolkey+[KV]{keyreader}[KR@]{xchoicelist}[true]{}{% + \KR@inputerr{#1}{xchoicelist}% +} +\DeclareOptionX*{\KR@warn{Unknown option '\CurrentOption' ignored}} \ExecuteOptionsX[KV]<keyreader>{parser,keyprefix,keyfamily,macroprefix} \ProcessOptionsX*[KV]<keyreader>\relax \newcommand\krsetup[1]{\setkeys[KV]{keyreader}{#1}} -\def\kr@defcommand#1#2{% +\def\KR@named@f#1#2{% \ifcsname#2\endcsname \expandafter\ifx\csname#2\endcsname\relax\else \def\reserved@a{#2}% @@ -102,10 +192,19 @@ \expandafter#1\csname#2\expandafter\endcsname \fi } -\def\kr@namedef#1{\kr@defcommand\def{#1}} -\def\kr@nameedef#1{\kr@defcommand\edef{#1}} -\def\kr@nameuse#1{\ifcsname#1\endcsname\csname#1\expandafter\endcsname\fi} -\def\kr@ifnameundef#1{% +\def\KR@namedef#1{\KR@named@f\def{#1}} +\def\KR@n@medef#1#2{\expandafter\def\csname#1\endcsname{#2}} +\def\KR@nameedef#1{\KR@named@f\edef{#1}} +\def\KR@n@meedef#1#2{\expandafter\edef\csname#1\endcsname{#2}} +\def\KR@nameuse#1{\ifcsname#1\endcsname\csname#1\expandafter\endcsname\fi} +\def\KR@ifnamedef#1{% + \ifcsname#1\endcsname + \expandafter\@firstoftwo + \else + \expandafter\@secondoftwo + \fi +} +\def\KR@ifnameundef#1{% \ifcsname#1\endcsname \expandafter\ifx\csname#1\endcsname\relax \expandafter\expandafter\expandafter\@firstoftwo @@ -116,116 +215,353 @@ \expandafter\@firstoftwo \fi } -\long\def\kr@ifnextchar#1#2#3{% \new@ifnextchar +\long\def\KR@ifnextchar#1#2#3{% \new@ifnextchar \let\tmp@d=#1\def\tmp@a{#2}\def\tmp@b{#3}% - \futurelet\@let@token\kr@ifnch -} -\long\def\kr@ifnch{\ifx\@let@token\tmp@d\let\tmp@b\tmp@a\fi\tmp@b} -\long\def\kr@testopt#1#2{\kr@ifnextchar[{#1}{#1[{#2}]}} -\long\def\kr@ifstar#1#2{\kr@ifnextchar*{\def\tmp@a*{#1}\tmp@a}{#2}} -\long\def\kr@ifblank#1{\kr@ifbl@nk#1&&\@secondoftwo\@firstoftwo:} -\long\def\kr@ifbl@nk#1#2#4#5:{#4} -\long\def\kr@expandonce#1{\unexpanded\expandafter{#1}} -\long\def\kr@csexpandonce#1{\expandafter\kr@expandonce\csname#1\endcsname} -\@ifdefinable\stopread{\long\def\stopread#1&{\long\def\kr@remainder{#1}}} -\long\def\kr@inputerr#1#2{\kr@err{Erroneous value '#1' for key '#2'}} -\mathchardef\kr@tempcnta=\z@\mathchardef\kr@tempcntb=\z@ -\mathchardef\kr@tempcntc=\z@ + \futurelet\@let@token\KR@ifnch +} +\long\def\KR@ifnch{\ifx\@let@token\tmp@d\let\tmp@b\tmp@a\fi\tmp@b} +\long\def\KR@testopt#1#2{\KR@ifnextchar[{#1}{#1[{#2}]}} +\long\def\KR@ifstar#1#2{\KR@ifnextchar*{\def\tmp@a*{#1}\tmp@a}{#2}} +\long\def\KR@expandonce#1{\unexpanded\expandafter{#1}} +\long\def\KR@csexpandonce#1{\expandafter\KR@expandonce\csname#1\endcsname} +\newcommand*\nameletcs[2]{\expandafter\let\csname#1\endcsname#2} +\newcommand*\csletname[2]{\expandafter\let\expandafter#1\csname#2\endcsname} +\newcommand*\nameletname[2]{% + \expandafter\let\csname#1\expandafter\endcsname\csname#2\endcsname +} +\def\define@comp@boolkeys{\KR@testopt{\KR@comp@opta}{KV}} +\def\KR@comp@opta[#1]#2{\KR@testopt{\KR@define@comp@boolkeys[#1]{#2}}{mp@}} +\def\KR@define@comp@boolkeys[#1]#2[#3]#4[#5]#6#7#8{% + \KR@namedef{comp@#2@#4}{\KR@nameuse{if#3#4}\KR@nameuse{#3#6false}\fi}% + \KR@namedef{comp@#2@#6}{\KR@nameuse{if#3#6}\KR@nameuse{#3#4false}\fi}% + \KR@namedef{func@#2@#4}{#7}% + \KR@namedef{func@#2@#6}{#8}% + \begingroup\protected@edef\KR@tempa{\endgroup + \unexpanded{\define@boolkey+[#1]{#2}[#3]{#4}[#5]{% + \KR@nameuse{comp@#2@#4}\KR@nameuse{func@#2@#4}}% + {\KR@inputerr{##1}{#4}}% + }% + \unexpanded{\define@boolkey+[#1]{#2}[#3]{#6}[#5]{% + \KR@nameuse{comp@#2@#6}\KR@nameuse{func@#2@#6}}% + {\KR@inputerr{##1}{#6}}% + }% + }% + \KR@tempa +} +\newcommand*\KR@star@or@none{} +\newcommand*\KR@star@or@long[1]{% + \KR@ifstar {% + \let\l@ngrel@x\relax + \def\KR@star@or@none{*}#1% + }{% + \let\l@ngrel@x\long + \def\KR@star@or@none{}#1% + }% +} +\protected\long\def\requirecmd{\KR@star@or@long\KR@require@cmd} +\newcommand\KR@require@cmd[1]{% + \ifdefined#1% + \KR@afterelsefi + \expandafter\CheckCommand\KR@star@or@none + \else + \KR@afterfi + \expandafter\newcommand\KR@star@or@none + \fi + {#1}% +} +\def\@check@eq#1#2{% + \unless\ifx#1#2% + \KR@warn{% + Previous definition of \string#1\MessageBreak + doesn't match your new definition.\MessageBreak + *** I haven't redefined \string#1\space *** + }% + \fi +} +\protected\def\KR@undeftoggle@err#1{% + \KR@err{Toggle '#1' undefined}% + {You need to first define '#1' before use.}% +} +\protected\def\deftog#1{% + \KR@ifnamedef{KR@toggle@#1}{% + \KR@warn{Toggle '#1' redefined\on@line}% + }{}% + \nameletcs{KR@toggle@#1}\@secondoftwo +} +\protected\def\newtog#1{% + \KR@ifnamedef{KR@toggle@#1}{% + \KR@err{Toggle '#1' already defined}% + {Please provide a new toggle or redefine '#1'.}% + }{% + \nameletcs{KR@toggle@#1}\@secondoftwo + }% +} +\protected\def\providetog#1{% + \KR@ifnamedef{KR@toggle@#1}{% + \KR@info{Toggle '#1' already defined.\MessageBreak + Not redefined\on@line}% + }{% + \nameletcs{KR@toggle@#1}\@secondoftwo + }% +} +\protected\def\requiretog#1{% + \expandafter\requirecmd\csname KR@toggle@#1\endcsname[2]{##2}% +} +\protected\def\settog#1#2{% + \KR@ifnamedef{KR@toggle@#1}{% + \KR@ifnamedef{KR@t@ggle#2}{% + \nameletname{KR@toggle@#1}{KR@t@ggle#2}% + }{% + \KR@err{% + Inadmissible value '#2' for toggle '#1' + }{% + Valid values for toggles are 'true' and 'false'. + }% + }% + }{% + \KR@undeftoggle@err{#1}% + }% +} +\protected\def\togtrue#1{% + \KR@ifnamedef{KR@toggle@#1}{% + \nameletcs{KR@toggle@#1}\KR@t@ggletrue + }{% + \KR@undeftoggle@err{#1}% + }% +} +\protected\def\togfalse#1{% + \KR@ifnamedef{KR@toggle@#1}{% + \nameletcs{KR@toggle@#1}\KR@t@gglefalse + }{% + \KR@undeftoggle@err{#1}% + }% +} +\global\let\KR@t@ggletrue\@firstoftwo +\global\let\KR@t@gglefalse\@secondoftwo +\protected\def\iftog#1{% + \KR@ifnamedef{KR@toggle@#1}{% + \csname KR@toggle@#1\endcsname + }{% + \KR@undeftoggle@err{#1}% + }% +} +\protected\def\ifnottog#1{% + \KR@ifnamedef{KR@toggle@#1}{% + \csname KR@toggle@#1\endcsname\@secondoftwo\@firstoftwo + }{% + \KR@undeftoggle@err{#1}\@gobbletwo + }% +} +\def\define@togkey{\XKV@t@stopta{\XKV@testoptd\KR@define@togkey{}}} +\def\KR@define@togkey#1#2[#3]{% + \ifXKV@pl\KR@afterelsefi + \expandafter\KR@d@f@ne@togkey + \else\KR@afterfi + \expandafter\KR@d@fine@togkey + \fi + \csname\XKV@header#2\endcsname{#2}{#1#2}{#3}% +} +\def\KR@d@fine@togkey#1#2#3#4#5{% + \KR@d@f@ne@t@gkey#1{#2}{#3}{#4}% + {{\settog{#3}{\XKV@resa}#5}}% +} +\def\KR@d@f@ne@togkey#1#2#3#4#5#6{% + \KR@d@f@ne@t@gkey#1{#2}{#3}{#4}% + {{\settog{#3}{\XKV@resa}#5}{#6}}% +} +\def\KR@d@f@ne@t@gkey#1#2#3#4#5{% + \newtog{#3}% + \ifXKV@st\XKV@define@default{#2}{#4}\fi + \ifXKV@pl + \def#1##1{\XKV@pltrue\XKV@sttrue + \XKV@checkchoice[\XKV@resa]{##1}{true,false}#5% + }% + \else + \def#1##1{\XKV@plfalse\XKV@sttrue + \XKV@checkchoice[\XKV@resa]{##1}{true,false}#5% + }% + \fi +} +\def\define@togkeys{\XKV@plfalse\XKV@testoptd\KR@define@togkeys{}} +\def\KR@define@togkeys#1#2[#3]{% + \XKV@sp@deflist\KR@tempa{#2}% + \XKV@for@o\KR@tempa\KR@tempa{% + \expandafter\KR@d@fine@togkeys\expandafter{\KR@tempa}{#1}{#3}% + }% +} +\def\KR@d@fine@togkeys#1#2#3{% + \expandafter\KR@d@f@ne@t@gkey\csname\XKV@header#1\endcsname + {#1}{#2#1}{#3}{{\settog{#2#1}{\XKV@resa}}}% +} +\@ifdefinable\stopread{% + \long\def\stopread#1\KR@nil{% + {\toks@{#1}\long\xdef\KR@remainder{\the\toks@}} + }% +} +\mathchardef\KR@tempcnta=\z@\mathchardef\KR@tempcntb=\z@ +\mathchardef\KR@tempcntc=\z@ \protected\long\def\define@keylist{% - \kr@ifstar{\kr@define@keylist\expandafter}{\kr@define@keylist\@firstofone}% + \KR@ifstar{\KR@define@keylist\expandafter}% + {\KR@define@keylist\@firstofone}% } -\def\ChoiceKeyValues#1#2{% - \ifkr@xchoicelist - \expandafter\edef\csname kr@altlist@\kr@keyfamily @#1\endcsname{#2}% +\newcommand\ChoiceKeyValues[2]{% + \ifKR@xchoicelist + \KR@n@meedef{\KR@keyfamily @#1@altlist}{#2}% \else - \kr@ifnameundef{kr@altlist@\kr@keyfamily @#1}{% - \kr@nameedef{kr@altlist@\kr@keyfamily @#1}{#2}% + \KR@ifnameundef{\KR@keyfamily @#1@altlist}{% + \KR@nameedef{\KR@keyfamily @#1@altlist}{#2}% }{% - \kr@err{You have attempted to set two \MessageBreak - \string\ChoiceKeyValues\space for the same choice key,\MessageBreak - in the same family}% + \KR@err{% + You have attempted to set two \MessageBreak + \string\ChoiceKeyValues\space for the choice\MessageBreak + key '#1' in the same family '\KR@keyfamily' + }{% + You can only do that if you set 'xchoicelist'=true. + }% }% \fi } \@ifdefinable\CKVS{\global\let\CKVS\ChoiceKeyValues} -\def\kr@define@key#1,#2,#3,#4&{% +\def\KR@define@multiple@keys#1,#2,#3,#4\KR@nil{% + \edef\KR@tempa{\string\if\KR@macroprefix#2}% + \@onelevel@sanitize\KR@tempa + \KR@expandargs{2}\in@{\KR@tempa}{\detokenize{#4}}% + \ifin@ + \KR@afterfi + \KR@err{% + You can't use \string\if\space and \string\fi\space in key macro + }{% + Use \string\fif\space and \string\ffi\space instead. + }% + \fi + \KR@expandargs{2}\in@{\detokenize{\fif}}{\detokenize{#4}}% + \ifin@ + \KR@afterelsefi + \KR@namedef{\KR@keyfamily @#2@func}{#4}% + \else + \KR@afterfi + \KR@nameedef{\KR@keyfamily @#2@func}{\KR@expandonce{#4}}% + \fi \begingroup - \protected@edef\x{\endgroup + \protected@edef\KR@tempa{\endgroup \ifcase#1\relax - \mathchardef\kr@tempcntc=\@ne + \mathchardef\KR@tempcntc=\@ne \or - \noexpand\define@key[\kr@keyprefix]{\kr@keyfamily}% - {#2}[#3]{\kr@expandonce{#4}}% + \noexpand\define@key[\KR@keyprefix]{\KR@keyfamily}% + {#2}[#3]{% + \KR@namedef{\KR@keyfamily @#2@value}{\unexpanded{##1}}% + \noexpand\KR@nameuse{\KR@keyfamily @#2@func}% + }% \or - \noexpand\define@cmdkey[\kr@keyprefix]{\kr@keyfamily}% - [\kr@macroprefix]{#2}[#3]{\kr@expandonce{#4}}% + \noexpand\define@cmdkey[\KR@keyprefix]{\KR@keyfamily}% + [\KR@macroprefix]{#2}[#3]{% + \KR@namedef{\KR@keyfamily @#2@value}{\unexpanded{##1}}% + \noexpand\KR@nameuse{\KR@keyfamily @#2@func}% + }% \or - \noexpand\define@boolkey+[\kr@keyprefix]{\kr@keyfamily}% - [\kr@macroprefix]{#2}[#3]{\kr@expandonce{#4}}% - {\unexpanded{\kr@inputerr{##1}{#2}}}% + \noexpand\define@boolkey+[\KR@keyprefix]{\KR@keyfamily}% + [\KR@macroprefix]{#2}[#3]{% + \KR@namedef{\KR@keyfamily @#2@value}{\unexpanded{##1}}% + \noexpand\KR@nameuse{\KR@keyfamily @#2@func}% + }{% + \unexpanded{\KR@inputerr{##1}{#2}}% + }% \or - \kr@ifnameundef{kr@altlist@\kr@keyfamily @#2}{\mathchardef\kr@tempcnta=\@ne}{} - \noexpand\define@choicekey*+[\kr@keyprefix]{\kr@keyfamily}{#2}% - [\unexpanded{\val\nr}]{\kr@nameuse{kr@altlist@\kr@keyfamily @#2}}[#3]% - {\kr@expandonce{#4}}{\unexpanded{\kr@inputerr{##1}{#2}}}% + \noexpand\define@togkey+[\KR@keyprefix]{\KR@keyfamily}% + [\KR@macroprefix]{#2}[#3]{% + \KR@namedef{\KR@keyfamily @#2@value}{\unexpanded{##1}}% + \noexpand\KR@nameuse{\KR@keyfamily @#2@func}% + }{% + \unexpanded{\KR@inputerr{##1}{#2}}% + }% + \or + \KR@ifnameundef{\KR@keyfamily @#2@altlist}{% + \mathchardef\KR@tempcnta=\@ne}{}% + \noexpand\define@choicekey*+[\KR@keyprefix]{\KR@keyfamily}{#2}% + [\unexpanded{\val\nr}]{% + \KR@nameuse{\KR@keyfamily @#2@altlist}% + }[#3]{% + \KR@namedef{\KR@keyfamily @#2@value}{\unexpanded{##1}}% + \noexpand\KR@nameuse{\KR@keyfamily @#2@func}% + }{% + \unexpanded{\KR@inputerr{##1}{#2}}% + }% \else - \mathchardef\kr@tempcntc=\@ne + \mathchardef\KR@tempcntc=\@ne \fi - }\x - \ifnum\kr@tempcnta=\@ne\kr@afterfi - \kr@err{% - Alternate key values list for '#2' is empty: - \MessageBreak choicekey can't be defined. - \MessageBreak You need to first define admissible - \MessageBreak key values through '\string\ChoiceKeyValues' - \MessageBreak for choice key '#2' - }% + }% + \KR@tempa + \ifnum\KR@tempcnta=\@ne + \KR@afterfi + \KR@err{% + Choice key '#2' can't be defined.\MessageBreak + Alternate key values list for '#2' is empty + }{% + You need to first define admissible\MessageBreak + key values through '\string\ChoiceKeyValues'\MessageBreak + for choice key '#2' + }% \fi - \ifnum\kr@tempcntc=\@ne\kr@afterfi - \kr@err{Unknown key type/identifier '#1'}% + \ifnum\KR@tempcntc=\@ne + \KR@afterfi + \KR@err{% + Unknown key type/identifier '#1' + }{% + You can only use key types 1 to 5. + }% \fi } -\def\define@comp@boolkeys{\kr@testopt{\kr@comp@opta}{KV}} -\def\kr@comp@opta[#1]#2{\kr@testopt{\kr@define@comp@boolkeys[#1]{#2}}{mp@}} -\def\kr@define@comp@boolkeys[#1]#2[#3]#4[#5]#6#7#8{% - \kr@namedef{comp@#2@#4}{\kr@nameuse{if#3#4}\kr@nameuse{#3#6false}\fi}% - \kr@namedef{comp@#2@#6}{\kr@nameuse{if#3#6}\kr@nameuse{#3#4false}\fi}% - \kr@namedef{func@#2@#4}{#7}% - \kr@namedef{func@#2@#6}{#8}% - \begingroup\protected@edef\x{\endgroup - \unexpanded{\define@boolkey+[#1]{#2}[#3]{#4}[#5]{% - \kr@nameuse{comp@#2@#4}\kr@nameuse{func@#2@#4}}% - {\kr@inputerr{##1}{#4}}% - }% - \unexpanded{\define@boolkey+[#1]{#2}[#3]{#6}[#5]{% - \kr@nameuse{comp@#2@#6}\kr@nameuse{func@#2@#6}}% - {\kr@inputerr{##1}{#6}}% +\def\krsetkeys{% + \def\fif##1{% + \KR@findescape{##1}{}{% + \KR@err{Bad argument '\string##1'}% + {Backslash in '\string##1' not allowed.}% }% - }\x -} -\def\disabledkeyerr{% - \kr@err{Key '\disabledkey' has been disabled.\MessageBreak - You can't set or reset it at this late stage.\MessageBreak - You should have set it earlier in the\MessageBreak - \string\documentclass\space or \string\usepackage}% -} -\def\krdisable@keys{\XKV@testoptb\kr@dis@ble@keys} -\long\def\kr@dis@ble@keys#1{% - \XKV@checksanitizeb{#1}\kr@tempa - \XKV@for@o\kr@tempa\kr@tempa{% - \XKV@ifundefined{\XKV@header\kr@tempa}{% - \kr@warn{Key '\kr@tempa' undefined: can't be disabled}% + \csname if##1\endcsname + }% + \let\ffi\fi + \XKV@testopta{\XKV@testoptc\XKV@setkeys}% +} +\protected\def\KR@disabledkey@err{% + \KR@err{% + Key '\KR@disabledkey' has been disabled + }{% + You can't set or reset '\KR@disabledkey' at this\MessageBreak + late stage. You should have set it \MessageBreak + earlier in \string\documentclass\space or \string\usepackage + }% +} +\def\krdisable@keys{\XKV@testoptb\KR@dis@ble@keys} +\long\def\KR@dis@ble@keys#1{% + \XKV@checksanitizeb{#1}\KR@tempa + \XKV@for@o\KR@tempa\KR@tempa{% + \XKV@ifundefined{\XKV@header\KR@tempa}{% + \KR@warn{Key '\KR@tempa' undefined: can't be disabled\on@line}% }{% - \global\let\disabledkey\kr@tempa + \global\let\KR@disabledkey\KR@tempa }% - \XKV@ifundefined{\XKV@header\kr@tempa @default}{% - \edef\kr@tempc{\noexpand\XKV@define@key{\kr@tempa}}% + \XKV@ifundefined{\XKV@header\KR@tempa @default}{% + \edef\KR@tempb{\noexpand\XKV@define@key{\KR@tempa}}% }{% - \edef\kr@tempc{\noexpand\XKV@define@key{\kr@tempa}[]}% + \edef\KR@tempb{\noexpand\XKV@define@key{\KR@tempa}[]}% }% - \expandafter\kr@tempc\expandafter{\disabledkeyerr}% + \expandafter\KR@tempb\expandafter{\KR@disabledkey@err}% }% } +\protected\def\KR@cs#1#2{% + \begingroup\toks@{#1}% + \edef\@i{\the\toks@}\@onelevel@sanitize\@i + \KR@expandargs{1}\KV@@sp@def\@i{\@i}% + \tt\textup{\textcolor{#2}{\KR@expandonce{\@i}}}% + \endgroup\xspace +} +\protected\def\KR@cx#1#2{% + \begingroup\toks@{#1}% + \edef\@i{\expandafter\expandafter\expandafter\zap@space% + \expandafter\detokenize\expandafter{\the\toks@} \@empty}% + \tt\textup{\textcolor{#2}{\KR@expandonce{\@i}}}% + \endgroup\xspace +} \endinput |