summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/keycommand/keycommand.sty
blob: 23b30abba2ae725856a3cdc042955cd81a0bc8ed (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
%%
%% This is file `keycommand.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% keycommand.dtx  (with options: `package')
%% 
%% This is a generated file.
%% 
%% keycommand : an easy way to define commands with keys
%% 
%% 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 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]
\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
   #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@pref@x}
\def\kcmd@pref@x{%
   \ifx\x\@sptoken         \let\next\kcmd@pref@x@space
   \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}%
         \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.}}%
         \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\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
         \protected\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
   \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
   \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}
\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}}
\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
  \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
}
\endinput
%%
%% End of file `keycommand.sty'.