summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/skeyval/skeyval-pokayoke1.tex
blob: 2617d62184065fc842498fc81b6e88c0f0da1d99 (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

\RequirePackage{skeyval-ltxpatch}

% With 'skeyval-ltxpatch' loaded, class options will not be zapped and
% expandable commands can be passed as options.

\documentclass[
  text style=\ttfamily,
  show author=true,
  insertwatermark,
  watermarktext={skeyval-test1\\[.25ex]Page~\thepage},
  watermarkcolor=brown!80!yellow
]{skeyval-testclass}

\skvifpackageloaded{xcolor}{}{\usepackage[dvipsname]{xcolor}}
\usepackage{lipsum}


% The command \cmdalign is just for illustrating how key values
% may be expanded at key setting time:
\def\cmdalign{justified}

\usepackage[
  author=Albert X\"avier Einstein,
  align=.expanded{\cmdalign},
  show author=true,
  unknown-option,
]{skeyval-testpkg}

\makeatletter

% Keys whose names are zapped internally:
\skvzcmdkeys[KV]{fam}[mp@]{provide value,give value}[true]{}
\skvzboolkeys[KV]{fam}[mp@]{provide value,give value}[true]{}

% Parenthesized keys are keys with names that have parentheses.
% The following is a key of 3 arguments. The default values are
% \x, \y, and \numexpr\x*2.
\skvpntkey[KV]{fam}{evaluate (?) as (?) using (?)}[\x\y{\numexpr\x*2}]{%
  \def\argone{#1}\def\argtwo{#2}\def\argthree{#3}%
  % '\detokenize{\pgfmath}' won't work here!
  \skvxifin{\relax\string\pgfmath}{\relax\detokenize{#3}}{%
    #3%
  }{%
    \edef#2{#3}%
  }%
}

% The above parenthesized key can be set as follows:
\def\cmda{2}
\skvsetkeys[KV]{fam}{%
  evaluate (\cmda) as (\cmdb) using (\pgfmathsetmacro\cmdb{\cmda*10})
}
%\show\argthree

\newcommand*\vgap{\endgraf\medskip}
\def\keycval{xx}

%% +++++++++++++++ Examples of using \directkeys command +++++++++ %%

% Note: When the value of a handler contains equality sign (=) or
% comma (,), it should be enclosed in braces.

\directkeys*{
  .exec=\skvsratchcnt\z@,
  .prefix = KV1,
  .family = fam1,
  .holder prefix = mp@,
  .add paths={KV2/fam2,KV3/fam3},
  .ignore roots={KV2/fam2,KV3/fam3},
  .restore roots={KV2/fam2,KV3/fam3},
  .save initial values of keys,
  .initialize keys after define=false,
  .new keys = {
    .ord/keya/{dfta,dftb}/
      \def\cmda##1{#1*##1*#2}
      \logsetting
      ,
    .arg/keya/{#1,#2},
    .cmd/keyb/{1cm,2cm}/
      \edef\boxht{\the\dimexpr#1*2\relax}
      \edef\boxwd{\the\dimexpr#1*10\relax},
    .choice/keyc/center/{right,left,center,justified},
    .bool/keyd/true,
    .cmd/keye/dfte/\def\cmde##1{##1#1},
    .cmd/keyf/dftf/\def\cmdf##1{##1#1},
    .ord/.value required{keyg}/dftg,
    .ord/.forbid value{keyh}/dfth,
  },
  .args={
    keyb={#1,#2}
  },
  .set={
    keya={val1,val2},keyb={2.5cm,5cm}
  },
  .get value={KV1}{fam1}{keya}\cmda,
  .ignore keys={
    keyd,keye
  },
  .set with defaults={
    keyd,keye,keyf,keyg
  },
  .restore keys = keye,
  .choice=keye/{
    center.do=\def\curralign##1{\hfil##1\hfil},
    right.do=\def\curralign##1{\hfill##1},
    left.do=\def\curralign##1{##1\hfill},
    justified.do=\let\curralign\@iden
  },
  .exec code ={
    \def\leftval{left}\def\rightval{right}
    \def\rrightval{\rightval}
  },
  % key1 and key2 are undefined. They will be defined internally
  % with the default values of keyc and keyd:
  .prepend style={
    key1/{keyc=.expanded{\rightval}},key2/{keyd=false}
  },
  .append style={
    key1/{keye=right,keyf=valf}
  },
  % When key3 and key4 are set, use their expanded values to set keye:
  .elink={
    {key3,key4}/keye
  },
  .style expand twice={
    key5/{keyf=#1,keyg=#1}
  },
  .set keys={
    key3=.expand once{\leftval},
    key5=.expand twice{\rrightval}
  },
  .prepend link={
    {key6,key7}/{keye,keyf},{key8,key9}/{keye,keyg}
  },
  .exec code=\skvsetkeys[KV1]{fam1}{key6=center},
  % Set keya and keyb on previously declared and the following paths.
  % Enter known keys in \mysuccesslist. Try 14 families; stop when
  % 12 families have been hit (ie, keys have been set in them
  % successfully):
  .search also set keys={
    .add prefixes={KV3,KV4},
    .add families={fam3,fam4},
    .try=14,
    .upper goal=12,
    .success list=\mysuccesslist
  }{
    keya={val1,val2},keyb={1cm,2cm}
  },
%  .exec code={\show\mysuccesslist},
  \directkeys*{
    .exec=\skvsratchcnt\z@\def\mysuccesslist{},
    .paths={KUA/fam1,KUB/fam2},
    .define keys={
      .ords/{keya,keyb,keyc}/.na/
        \def\y##1{#1*##1}
        \typeout{***}
        \logsetting
      ,
    }
  },
  % '.try set keys' works independent of previously declared paths:
  .try set keys={
    .prefixes={KUA,KUB,KUC},
    .families={fam1,fam2,fam3,fam4},
    .try=8,
    .upper goal=4,
    .lower goal=2,
    .ignore keys={keyb,keyc},
    .success list=\mysuccesslist
  }{
    keya=vala,keyb=valb,keyc=valc
  },
%  .exec code={\show\mysuccesslist},
}

\makeatother

\begin{document}

\title{The \texttt{\textcolor{blue}{skeyval}} Package\\[1ex]
  Version 1.1\\[1ex]
  \textsf{Test document 1}}
\author{Ahmed Musa}
\maketitle

%%+++++++++++++++++++ Producing arbitrary texts +++++++++++++++++++++%%

\noindent
An author writing an article for publication in \textsc{TUGboat} is
encouraged to create it on a computer file and submit it on magnetic tape.
\par
\hfill{\small Barbara Beeton, 1981}
\par\bigskip

\begin{\mpfalign}
\skvxifstrcmp\mpfalign{justified}{\noindent}{}
\mpftextstyle
The printer should refuse to employ wandering men, foreigners who,
after having committed some grievous error, can easily disappear and
return to their own country.
\hfill{\small Hieronymus Hornschuch (1608)}\endgraf
\end{\mpfalign}


\begingroup
\par\bigskip
\noindent
If you want to find out anything from the theoretical physicists
about the methods they use, I advise you to stick closely to
one principle: don't listen to their words, fix your mind
on their deeds.
\ifmpfshowauthor
  \nobreak
  \quad\hskip\fill\finalhyphendemerits0\relax
  \textcolor{red}{\mpfauthor}
\fi
\endgroup


%%++++++++++++++++++++++ Shadow boxes ++++++++++++++++++++++++%%

\par\bigskip
\begin{center}
\hrule
\par\bigskip
\newshadowbox{test 1}
\newshadowbox[framecolor=magenta,shadecolor=cyan,shadowsize=8pt,
  align=left]{test 2}
\newshadowbox[shadow=false,boxwidth=1cm]{test 3}
\newshadowbox[framesize=2pt,framecolor=red,shadowcolor=green]{test 4}
\newshadowbox[put frame=false,shadow,shadowsize=9pt,shadecolor=yellow,
  shadowcolor=violet!50,align=right]{test 5}
\par\bigskip
\hrule
\end{center}


%%++++++++++++++++++++++++++ Citation ++++++++++++++++++++++++%%

\par\bigskip
\noindent
\newcitation[
    author=George Bernard Shaw (1856--1950),
    show author,
    leftmargin=0pt,
    rightmargin=0pt,
    put frame,
    framecolor=blue,
    shadecolor=yellow!25!green!14,
    frame thickness=1pt,
]{%
    A man of great common sense and good taste; meaning thereby
    a man without originality and/or moral courage.
}

\par\bigskip
\noindent
\newcitation[
    author=George Bernard Shaw (1856--1950),
    show author,
    leftmargin=0pt,
    rightmargin=0pt,
    put frame=false,
    framecolor=yellow!30!blue,
    shadecolor=yellow!25,
    frame thickness=5pt,
    width=.8\textwidth,
]{%
    A man of great common sense and good taste; meaning thereby
    a man without originality and/or moral courage.
}

\par\bigskip
\noindent
\newcitation[
    author=Mohammed Ali,
    show author,
    leftmargin=0pt,
    rightmargin=0pt,
    put frame,
    framecolor=red!70!green,
    shadecolor=magenta!5!red!4,
    frame thickness=10pt,
]{%
    I always say I was `the greatest'; I have never said I was the smartest.
    \vgap
    At home I am a nice, quiet guy, but I don't want the world to know.
    Humble people, I have found, don't get very far.
    \vgap
    To win, you must have the skill and the will. But the will must be
    stronger than the skill.
    \vgap
    I'm the best golfer; I just haven't played it yet.
}


%++++++++++++++++++ Collecting body of environment +++++++++++++++++++%

\bigskip
\begin{collectbody}[
  title=Example of collect body,
  title scale=.8,
  title text style=\ttfamily\color{red}
]
\lipsum[1]
\end{collectbody}


\end{document}


%%+++++++++++++++++++++ Examples of \skvmakekeys +++++++++++++++++++%%

\skvmakekeys[
  prefix=KVA,
  families={fam1,fam2},
  hp=thp@,
  all new,
  define in all families,
  initialize=true
]{%
  .ords/{keya,keyb}/{default-a},
  .cmds/{keyc,keyd}/,
  .choice/keyf/center/{center.do=\def\x##1{#1*##1},left,right},
  .zbool/show center/true/\edef\cmd{\ifthp@showcenter Yes\else No\fi},
}
%\skvshowcs{KVA/fam2/keyf.@cbk}
%\skvshowcs{KVA/fam1/keyb.@defa}
\def\keybval{xx}
\skvsetkeys[KVA]{fam1}{keyb=.expand once{\keybval}}


%%+++++++++++++++++++++ Examples of \skvusekeys +++++++++++++++++++%%

\skvmakekeys[
  .prefix=KVA,
  .families={fam1,fam2},
  .hp=thp@,
  .all new
]{%
  .ord/keya/{default-a}/\def\y##1{##1*#1*##1},
  .ord/keyb/defa-b,
}

\def\keybval{xx}

\skvusekeys[
  .prefix=KVA,
  .families={fam1,fam2},
  .set in all families,
  .save unknown keys
]{%
  keya,
  keyb=.expand once{\keybval}
}

% Families fam3 and fam4 aren't defined. Hence, with 'save unknown keys'
% set to 'true' by default, keys keya and keyb are saved as rm keys with
% their default values.
\skvusekeys[
  .prefix=KVA,
  .families={fam3,fam4},
  .set in all families,
  .save unknown keys
]{%
  keya,keyb=.expand once{\keybval}
}
%\skvshowcs{KVA/fam3/.@rmkeys}
%\skvshowcs{KVA/fam4/.@rmkeys}


%%+++++++++++++++ Key values with unbalanced conditionals ++++++++++++%%

\skvcmdkey[SKVT]{fam}[mpf]{keya}[keya-defa]{\def\keyaval{#1}}
\skvsetkeys[SKVT]{fam}{keya=\fi}

%%+++++++++++++++++++++ Examples of \skvkeyslet +++++++++++++++++++%%

\skvsaveinitialvaluekeys[KV]{fam}{keya,keyb,keyc}
%\skvshowcs{KV/fam/.@needini}
\skvmakekeys[
  prefix=KV, family=fam, hp=thp@, all new,initialize,save initial values
]{%
  .ord/keya/defa-a/\def\keyay##1{##1*#1*##1},
  .cmds/{keyb,keyc}/defa-b/\def\keyby##1{##1*#1*##1},
  .cmd/keyd,
}
%\skvshowcs{KV/fam/.@inikv}
\skvignorekeys[KV]{fam}{keyb,keyc}
\skvkeyslet[KV]{fam}{keyA=keya,keyB=keyb,keyC=keyc}
\skvshowcs{KV/fam/.@needini}


%++++++++++++++++++ Evaluating boolean expressions +++++++++++++++++++%

\skvifexpr{%
  not ( expr { \skvifdef\xa } and expr { \skvifempty\xa } )
  or ( expr { \skvifdef\xb } or expr { \skvifx\xa\xb } )
}{%
  \def\x{T}%
}{%
  \def\x{F}%
}

%++++++++++++++++++++++++++++ \cicadaloop +++++++++++++++++++++++++++%

\makeatletter
\@tempcnta\z@
\def\blist{{X};\fi;{Y};Z}
\def\stack{}
\let\romn\romannumeral
\cicadaloop{{a},\if,{b},c}\if01\fi{%
  \advance\@tempcnta by\@ne
  \@tempcntb\z@\@tempswafalse
  \cicadaloop*[;]\blist\if@tempswa\fi{%
    \advance\@tempcntb by\@ne
    \typeout{Doing \romn\@tempcnta, \romn\@tempcntb:
      \detokenize{#1, ##1}}%
    \edef\stack{%
      \unexpanded\expandafter{\stack}\noexpand\do
      {\romn\@tempcnta,\romn\@tempcntb}{\unexpanded{#1;##1}}%
    }%
    \ifnum\@tempcntb>\tw@\@tempswatrue\fi
  }%
}
\makeatother

% End of file skeyval-pokayoke1.tex