summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/keycommand
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2009-08-26 23:58:20 +0000
committerKarl Berry <karl@freefriends.org>2009-08-26 23:58:20 +0000
commitccb587e18c23dd8a68d9deaab22ec4e090142e23 (patch)
tree8a219b6d853fcb87a9d26c4ff5f4d49a081d6068 /Master/texmf-dist/tex/latex/keycommand
parent7f22b556e93ffe99258d3be57223233879bd5e7b (diff)
keycommand 2.z (26aug09)
git-svn-id: svn://tug.org/texlive/trunk@14875 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/keycommand')
-rw-r--r--Master/texmf-dist/tex/latex/keycommand/keycommand.sty99
1 files changed, 62 insertions, 37 deletions
diff --git a/Master/texmf-dist/tex/latex/keycommand/keycommand.sty b/Master/texmf-dist/tex/latex/keycommand/keycommand.sty
index 23b30abba2a..e6043d051ed 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 keys
+%% keycommand : an easy way to define commands with optional keys
%%
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either
@@ -21,18 +21,18 @@
%% keycommand.sty, keycommand.pdf, keycommand.ins,
%% keycommand-example.tex
%%
-%% keycommand : an easy way to define commands with keys
+%% keycommand : an easy way to define commands with optional keys
%% Copyright (C) 2009 by Florent Chervet <florent.chervet@free.fr>
%%
\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 an easy way to define commands with keys]
+ [2009/07/22 v2.e- an easy way to define commands with optional keys]
\RequirePackage{etex,kvsetkeys}
-\let\kcmd@AtEnd=\`
-\def\`#1`{\csname #1\endcsname}
-\def\kcmd@keydef#1#2#3#4#5{% #1=\global(eventually), #2=command, #3=family, #4=key, #5=def
+\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{%
@@ -55,36 +55,45 @@
\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@pref@x}
-\def\kcmd@pref@x{%
- \ifx\x\@sptoken \let\next\kcmd@pref@x@space
+ \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}%
\else
- \def\kcmd@pref@x@next{\expandafter\key@cmd\noexpand}%
+ \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 \def\next{\kcmd@error{a \string\def\space
- was expected after \string\keycmd.}}%
+ \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}
-\begingroup\def\:{\kcmd@pref@x@space}
-\expandafter\gdef\: {\futurelet\x\kcmd@pref@x}
-\endgroup
-\def\kcmd@addto@prfx#1{\expandafter\def\expandafter
- \kcmd@prfx\expandafter{\kcmd@prfx#1}\kcmd@pref@x@next}
-\def\kcmd@pref@x@next{\futurelet\x\kcmd@pref@x}
-\def\kcmd@error#1{\@latex@error{#1}\@ehd}
+\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}%
@@ -112,7 +121,7 @@
\kcmd@undefinekeys{\kcmd@gbl}{#1}%
\kv@parse{##1}{\kcmd@definekey{\kcmd@gbl}{#1}{\kcmd@fam}}%
\kcmd@gbl\protected\def#1{% entry point
- \protected\def\commandkey########1{\noexpand\csname\kcmd@fam @########1\endcsname}%
+ \def\commandkey########1{\noexpand\csname\kcmd@fam @########1\endcsname}%
\def\"kcmd\string#1"########1[########2]{%
\kvsetkeys{\kcmd@fam}{########1,########2}%
\"\string #1"}%
@@ -129,11 +138,11 @@
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}
+ {\expandafter\new@keycommand\noexpand}}
\DeclareRobustCommand\renewkeycommand{\@star@or@long
- \expandafter\renew@keycommand\noexpand}
+ {\expandafter\renew@keycommand\noexpand}}
\DeclareRobustCommand\providekeycommand{\@star@or@long
- \expandafter\provide@keycommand\noexpand}
+ {\expandafter\provide@keycommand\noexpand}}
\def\new@keycommand#1{\@testopt{\expandafter\@newkeycommand\noexpand#1}{}}
\def\@newkeycommand#1[#2]{\begingroup
\@tempswafalse\expandafter
@@ -181,20 +190,36 @@
\expandafter\let\csname\expandafter\string\csname #1\endcsname\endcsname\relax
\expandafter\let\csname end#1\endcsname\relax
\new@keyenvironment{#1}}
-\def\kv@normalize#1{%
- \begingroup
- \toks@{,#1,}%
- \KVS@Comma
- \KVS@SpaceComma{ }%
- \KVS@CommaSpace
- \KVS@CommaComma
- \KVS@Equals
- \KVS@SpaceEquals{ }%
- \KVS@EqualsSpace% <original code>\KVS@EqualsSpace{ }</original code>
- \xdef\KVS@Global{\the\toks@}%
- \endgroup
- \let\kv@list\KVS@Global
-}
+
+
+\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&#3#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
\endinput
%%
%% End of file `keycommand.sty'.