Debian Codegraph @

texmf-dist/doc/latex/skeyval/skeyval-pokayoke1.tex

raw
1 %++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++%
2 % This is file 'skeyval-pokayoke1.tex', version 1.3, 2013/05/15. %
3 % %
4 % This package and accompanying files may be distributed and/or %
5 % modified under the conditions of the LaTeX Project Public License, %
6 % either version 1.3 of this license or any later version. The latest %
7 % version of this license is in http://www.latex-project.org/lppl.txt %
8 % and version 1.3 or later is part of all distributions of LaTeX %
9 % version 2005/12/01 or later. %
10 % %
11 % The LPPL maintenance status of this software is 'author-maintained'. %
12 % %
13 % This software is provided 'as it is', without warranty of any kind, %
14 % either expressed or implied, including, but not limited to, the %
15 % implied warranties of merchantability and fitness for a particular %
16 % purpose. %
17 % %
18 % The following files constitute the skeyval bundle and must be %
19 % distributed as a whole: %
20 % %
21 % README, skeyval.sty, skeyval-core.tex, skeyval-for.tex, %
22 % skeyval-view.sty, skeyval-ltxpatch.sty, skeyval-ltxcmds.tex, %
23 % skeyval-pstkey.sty, skeyval-pstkey.tex, skeyval-testclass.cls, %
24 % skeyval-testpkg.sty, skeyval-pokayoke1, skeyval-pokayoke2, %
25 % skeyval-view-pokayoke1. %
26 % %
27 % Copyright (c) 2010-2013 Ahmed Musa ([email protected]). %
28 %++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++%
29
30 \makeatletter
31 \RequirePackage{skeyval-ltxpatch}
32
33 % With 'skeyval-ltxpatch' loaded, class options will not be zapped and
34 % expandable commands can be passed as options.
35
36 \documentclass[
37 text style=\ttfamily,
38 show author=true,
39 insertwatermark,
40 watermarktext={skeyval-test1\\[.25ex]Page~\thepage},
41 watermarkcolor=brown!80!yellow
42 ]{skeyval-testclass}
43
44 \skvifpackageloadedTF{xcolor}{}{\usepackage[dvipsname]{xcolor}}
45 \usepackage{lipsum}
46
47 % The command \cmdalign is just for illustrating how key values
48 % may be expanded at key setting time:
49 \def\cmdalign{justified}
50
51 \usepackage[
52 author=Albert X\"avier Einstein,
53 align=.expanded{\cmdalign},
54 show author=true,
55 unknown-option,
56 ]{skeyval-testpkg}
57
58 %+++++++++++ Keys whose names are zapped internally ++++++++++++++%
59
60 \skvzcmdkeys[KV]{fam}[mp@]{provide value,give value}[some value]{}
61 \skvzboolkeys[KV]{fam}[mp@]{provide value,give value}[true]{}
62
63 %++++++++++++++++++++++ Parenthesized keys +++++++++++++++++++++++%
64
65 % Parenthesized keys are keys with names that have parentheses
66 % The following is a key of 3 arguments. The default values are
67 % \x, \y, and \numexpr\x*2 - since there are 3 arguments.
68 %
69 \skvpntkey[KV]{fam}{evaluate (?) as (?) using (?)}[{\x}{\y}{\numexpr\x*2}]{%
70 \def\argone{#1}\def\argtwo{#2}\def\argthree{#3}%
71 % '\detokenize{\pgfmath}' won't work here!
72 \skvxifinTF{\relax\string\pgfmath}{\relax\detokenize{#3}}{%
73 #3%
74 }{%
75 \edef#2{#3}%
76 }%
77 }
78
79 % The above parenthesized key can be set as follows:
80 %
81 \def\cmda{2}
82 \skvsetkeys[KV]{fam}{%
83 evaluate (\cmda) as (\cmdb) using (\pgfmathsetmacro\cmdb{\cmda*10})
84 }
85 %\show\argthree
86
87 \newcommand*\vgap{\endgraf\medskip}
88 \def\keycval{xx}
89
90 %% +++++++++++++++ Examples of using \directkeys command ++++++++++%
91
92 % Note: When the value of a handler contains equality sign (=) or
93 % comma (,), it should be enclosed in braces.
94
95 \directkeys*{
96 .exec=\skvtestcnt\z@,
97 .prefix = KV1,
98 .family = fam1,
99 .holder prefix = mp@,
100 .add paths={KV2/fam2,KV3/fam3},
101 .ignore paths={KV2/fam2,KV3/fam3},
102 .restore paths={KV2/fam2,KV3/fam3},
103 .save initial values of keys,
104 .initialize keys after define=false,
105 .new keys = {
106 .ord/keya/{dfta,dftb}/
107 %\def\skvhp{my@}
108 \def\cmda##1{#1*##1*#2}\logsetting
109 ,
110 .arg/keya/{#1,#2},
111 % See argument of keyb below:
112 .cmd/keyb/{1cm,2cm}/
113 \edef\boxht{\the\dimexpr#1*2\relax}
114 \edef\boxwd{\the\dimexpr#2*2\relax},
115 .choice/keyc/center/{right,left,center,justified},
116 .bool/keyd/true,
117 .cmd/keye/dfte/\def\cmde##1{##1#1},
118 .cmd/keyf/dftf/\def\cmdf##1{##1#1},
119 .ord/.need value{keyg}/dftg,
120 .ord/.forbid value{keyh}/dfth,
121 },
122 .args={
123 keyb={#1,#2}
124 },
125 .set={
126 keya={val1,val2},keyb={2.5cm,5cm}
127 },
128 .get value={KV1}{fam1}{keya}\cmda,
129 .ignore keys={
130 keyd,keye
131 },
132 .set with defaults={
133 keyd,keye,keyf,keyg
134 },
135 .restore keys = keye,
136 .link={keye2/keye},
137 % Choices for keye can be declared directly:
138 .state pattern expanded={keye,keye2}/{
139 center.do=\def\curralign##1{\hfil##1\hfil},
140 right.do=\def\curralign##1{\hfill##1},
141 left.do=\def\curralign##1{##1\hfill},
142 justified.do=\let\curralign\@iden
143 },
144 .exec code={
145 \def\leftval{left}\def\rightval{right}
146 \def\rrightval{\rightval}
147 },
148 % key1 and key2 are undefined. They will be defined internally
149 % with the default values of keyc and keyd:
150 .prepend slots={
151 key1/{keyc=.expanded{\rightval}},key2/{keyd=false}
152 },
153 .append slots={
154 key1/{keye=right,keyf=valf}
155 },
156 % When key3 and key4 are set, use their expanded values to set keye:
157 .elink={
158 {key3,key4}/keye
159 },
160 .slot expand twice={
161 key5/{keyf=#1,keyg=#1}
162 },
163 .set keys={
164 key3=.expand once{\leftval},
165 key5=.expand twice{\rrightval}
166 },
167 .prepend links={
168 {key6,key7}/{keye,keyf},
169 {key8,key9}/{keye,keyg}
170 },
171 .exec code=\skvsetkeys[KV1]{fam1}{key6=center},
172 % Set keya and keyb on previously declared and the following paths.
173 % Enter known keys in \mysuccesslist. Try 14 families; stop when
174 % 12 families have been hit (ie, keys have been set in them
175 % successfully):
176 .exec code=\def\flukepaths{},
177 .search also set keys={
178 .paths={KX/famx,KV1/fam1,KV3/fam3,KV3/fam4,KV4/fam3,KV4/fam4},
179 .ignore keys={keyc},
180 .try=14,
181 .min success=10,
182 .max success=12,
183 .success list=\mysuccesslist,
184 .if any path fails={%
185 \edef\flukepaths{\skvaddlist,\flukepaths\skvcurrentpath}
186 },
187 .if hits less than goal={\skvsetkeys[KV1]{fam1}{keyc=center}},
188 .kv={keya={val1,val2},keyb={1cm,2cm},keyc}
189 },
190 % .exec code={\show\mysuccesslist},
191 \directkeys*{
192 .exec=\skvtestcnt\z@\def\mysuccesslist{},
193 .paths={KUA/fam1,KUA/fam2,KUB/fam1,KUB/fam2},
194 .define ordinary keys={
195 {keya,keyb,keyc}/.na/
196 \def\y##1{#1*##1}
197 \typeout{***}\logsetting
198 \skvsetkeys[KV1]{fam1}{keyc=center}
199 ,
200 }
201 },
202 % '.try set keys' works independent of previously declared paths:
203 .try set keys={
204 .paths={
205 KUA/fam1,KUA/fam2,KUA/fam3,KUA/fam4,
206 KUB/fam1,KUB/fam2,KUB/fam3,KUB/fam4,
207 KUC/fam1,KUC/fam2,KUC/fam3,KUC/fam4
208 },
209 .try=8,
210 .upper goal=4,
211 .lower goal=2,
212 .ignore keys={keyb,keyc},
213 .success list=\mysuccesslist,
214 .kv={keya=vala,keyb=valb,keyc=valc}
215 },
216 %.exec code={\show\mysuccesslist},
217 }
218
219 \directkeys*{
220 .exec=\skvtestcnt\z@\def\mysuccesslist{},
221 .paths={KUA/fam1,KUB/fam2},
222 .hp=mp@,
223 .ignore keys={keyd},
224 .define keys={
225 .initialize keys after define=true,
226 .save initial values of keys,
227 .exec code/\skvtestcnt\z@,
228 % keya has no default but has a complex callback:
229 .ord/keya/.na/{
230 \skvtestcnt\z@\def\mysuccesslistb{}
231 \directkeys{
232 .path={KVX/famx},
233 .search also set keys={%
234 .paths={KUA/fam1,KUA/fam2,KUB/fam1,KUB/fam2},
235 .try=8,
236 .upper goal=4,
237 .lower goal=1,
238 .success list=\mysuccesslistb,
239 .kv={keyb=valb}
240 },
241 % .exec code=\show\mysuccesslistb,
242 }
243 }
244 ,
245 % No default:
246 .ord/{keyb,keyc,keyd}/.na/\def\x##1{#1*##1}\logsetting,
247 .exec code=\def\cmda#1{\if0#1\fi},
248 % No callback:
249 .choice/keye/center/{center,left,right},
250 .choice/keye2/center/{
251 center.do=\def\giv@c{#1},
252 left.do=\def\giv@l{#1},
253 right.do=\def\giv@r{#1}
254 }/.na/\@@warning{Invalid value '\detokenize{#1}' for keye2},
255 },
256 .try set keys={%
257 .paths={
258 KUA/fam1,KUA/fam2,KUA/fam3,KUA/fam4,
259 KUB/fam1,KUB/fam2,KUB/fam3,KUB/fam4
260 },
261 .try=1,
262 .upper goal=1,
263 .lower goal=1,
264 .ignore keys={keyc,keyd},
265 .success list=\mysuccesslist,
266 .kv={keya=vala,keyc=valc,keyd=vald}
267 },
268 % .exec code={\show\mysuccesslist},
269 % Defining new handlers that can't be overloaded.
270 % '.resd handler' and '.resd handlers' are reserved handlers.
271 % They can be used to define new handlers (see below).
272 .new reserved handlers={
273 {.resd handler,.resd handlers}=\dirkeysdefhandlers{00}{#1},
274 },
275 .resd handlers={
276 .example handler1=\def\val{#1}, .example handler2=\edef\val{#1}
277 },
278 % .exec=\skvshowcs{dirkeys@[email protected] handler1},
279 }
280
281 \makeatother
282
283 \begin{document}
284
285 \title{The \texttt{\textcolor{blue}{skeyval}} Package\\[1ex]
286 Version 1.1a\\[1ex]
287 \textsf{Test document 1}}
288 \author{Ahmed Musa}
289 \maketitle
290
291 %%+++++++++++++++++++ Producing arbitrary texts +++++++++++++++++++++%%
292
293 \noindent
294 An author writing an article for publication in \textsc{TUGboat} is
295 encouraged to create it on a computer file and submit it on magnetic tape.
296 \par
297 \hfill{\small Barbara Beeton, 1981}
298 \par\bigskip
299
300 \begin{\mpfalign}
301 \skvxifstrcmpTF\mpfalign{justified}{\noindent}{}
302 \mpftextstyle
303 The printer should refuse to employ wandering men, foreigners who,
304 after having committed some grievous error, can easily disappear and
305 return to their own country.
306 \hfill{\small Hieronymus Hornschuch (1608)}\endgraf
307 \end{\mpfalign}
308
309 \begingroup
310 \par\bigskip
311 \noindent
312 If you want to find out anything from the theoretical physicists
313 about the methods they use, I advise you to stick closely to
314 one principle: don't listen to their words, fix your mind
315 on their deeds.
316 \ifmpfshowauthor
317 \nobreak
318 \quad\hskip\fill\finalhyphendemerits0\relax
319 \textcolor{red}{\mpfauthor}
320 \fi
321 \endgroup
322
323
324 %%++++++++++++++++++++++ Shadow boxes ++++++++++++++++++++++++%%
325
326 \par\bigskip
327 \begin{center}
328 \hrule
329 \par\bigskip
330
331 \newshadowbox{test 1}
332 \newshadowbox[framecolor=magenta,shadecolor=cyan,shadowsize=8pt,
333 align=left]{test 2}
334 \newshadowbox[shadow=false,boxwidth=1cm]{test 3}
335 \newshadowbox[framesize=2pt,framecolor=red,shadowcolor=green]{test 4}
336 \newshadowbox[put frame=false,shadow,shadowsize=9pt,shadecolor=yellow,
337 shadowcolor=violet!50,align=right]{test 5}
338 \par\bigskip
339 \hrule
340 \end{center}
341
342
343 %%++++++++++++++++++++++++++ Citation ++++++++++++++++++++++++%%
344
345 \par\bigskip
346 \noindent
347 \newcitation[
348 author=George Bernard Shaw (1856--1950),
349 show author,
350 leftmargin=0pt,
351 rightmargin=0pt,
352 put frame,
353 framecolor=blue,
354 shadecolor=yellow!25!green!14,
355 frame thickness=1pt,
356 ]{%
357 A man of great common sense and good taste; meaning thereby
358 a man without originality and/or moral courage.
359 }
360
361 \par\bigskip
362 \noindent
363 \newcitation[
364 author=George Bernard Shaw (1856--1950),
365 show author,
366 leftmargin=0pt,
367 rightmargin=0pt,
368 put frame=false,
369 framecolor=yellow!30!blue,
370 shadecolor=yellow!25,
371 frame thickness=5pt,
372 width=.8\textwidth,
373 ]{%
374 A man of great common sense and good taste; meaning thereby
375 a man without originality and/or moral courage.
376 }
377
378 \par\bigskip
379 \noindent
380 \newcitation[
381 author=Mohammed Ali,
382 show author,
383 leftmargin=0pt,
384 rightmargin=0pt,
385 put frame,
386 framecolor=red!70!green,
387 shadecolor=magenta!5!red!4,
388 frame thickness=10pt,
389 ]{%
390 I always say I was `the greatest'; I have never said I was the smartest.
391 \vgap
392 At home I am a nice, quiet guy, but I don't want the world to know.
393 Humble people, I have found, don't get very far.
394 \vgap
395 To win, you must have the skill and the will. But the will must be
396 stronger than the skill.
397 \vgap
398 I'm the best golfer; I just haven't played it yet.
399 }
400
401
402 %++++++++++++++++++ Collecting body of environment +++++++++++++++++++%
403
404 \bigskip
405 \begin{collectbody}[
406 title=Example of collect body,
407 title scale=.8,
408 title text style=\ttfamily\color{red}
409 ]
410 \lipsum[1]
411 \end{collectbody}
412
413 \end{document}
414
415
416 %%+++++++++++++++++++++ Assigning arguments to keys +++++++++++++++++%%
417
418 \skvsetdefaultprefix{myprefix}
419 \skvordkey{fam}{key1}[deafult1]{}
420 \skvcmdkey{fam}[mp@]{key2}[deafultx,defaulty]{%
421 \def\cmd##1{#1+#2+##1}%
422 }
423 \skvassignargs{fam}[.expanded]{key2}{#1,#2}
424 \def\valuex{valuex}
425 \def\valuey{valuey}
426 \skvsetkeys[myprefix]{fam}{key1=value1,key2={\valuex,\valuey}}
427
428 %%+++++++++++++++++++++ Examples of \skvmakekeys +++++++++++++++++++%%
429
430 \skvmakekeys[
431 .prefix=KVA,
432 .families={fam1,fam2},
433 .hp=thp@,
434 .all new,
435 .define in all families,
436 .initialize=true
437 ]{%
438 .ord/{keya,keyb}/default-a,
439 .cmd/{keyc,keyd}/.na/\def\y##1{#1**##1},
440 .choice/keyf/center/{center.do=\def\x##1{#1*##1},left,right},
441 .zbool/show center/true/\edef\cmd{\ifthp@showcenter Yes\else No\fi},
442 }
443 %\skvshowcs{KVA/fam2/keyf.@cbk}
444 %\skvshowcs{KVA/fam1/keyb.@defa}
445 \def\keybval{xx}
446 \skvsetkeys[KVA]{fam1}{keyb=.expand once{\keybval}}
447
448
449 %%+++++++++++++++++++++ Examples of \skvusekeys +++++++++++++++++++%%
450
451 \skvmakekeys[
452 .prefix=KVA,
453 .families={fam1,fam2},
454 .hp=thp@,
455 .all new
456 ]{%
457 .ord/keya/{default-a}/\def\y##1{##1*#1*##1},
458 .ord/keyb/defa-b,
459 }
460
461 \def\keybval{xx}
462
463 \skvusekeys[
464 .prefix=KVA,
465 .families={fam1,fam2},
466 .set in all families,
467 .save unknown keys
468 ]{%
469 keya,
470 keyb=.expand once{\keybval}
471 }
472
473 % Families fam3 and fam4 aren't defined. Hence, with 'save unknown keys'
474 % set to 'true' by default, keys keya and keyb are saved as rm keys with
475 % their default values.
476 \skvusekeys[
477 .prefix=KVA,
478 .families={fam3,fam4},
479 .set in all families,
480 .save unknown keys
481 ]{%
482 keya,keyb=.expand once{\keybval}
483 }
484 %\skvshowcs{KVA/fam3/.@rmkeys}
485 %\skvshowcs{KVA/fam4/.@rmkeys}
486
487
488 %%+++++++++++++++ Key values with unbalanced conditionals ++++++++++++%%
489
490 \skvcmdkey[SKVT]{fam}[mpf]{keya}[keya-defa]{\def\keyaval{#1}}
491 \skvsetkeys[SKVT]{fam}{keya=\fi}
492
493 %%+++++++++++++++++++++ Examples of \skvkeyslet +++++++++++++++++++%%
494
495 \skvsaveinitialvaluekeys[KV]{fam}{keya,keyb,keyc}
496 %\skvshowcs{KV/fam/.@needini}
497 \skvmakekeys[
498 .prefix=KV,
499 .family=fam,
500 .hp=thp@,
501 .all new,
502 .initialize,
503 .save initial values
504 ]{%
505 .ord/keya/defa-a/\def\keyay##1{##1*#1*##1},
506 .cmd/{keyb,keyc}/defa-b/\def\keyby##1{##1*#1*##1},
507 .cmd/keyd,
508 }
509 %\skvshowcs{KV/fam/.@inikv}
510 \skvignorekeys[KV]{fam}{keyb,keyc}
511 \skvkeyslet[KV]{fam}{keyA=keya,keyB=keyb,keyC=keyc}
512 \skvshowcs{KV/fam/.@needini}
513
514
515 %++++++++++++++++++ Evaluating boolean expressions +++++++++++++++++++%
516
517 \skvifexprTF{%
518 not ( expr { \skvifdefTF\xa } and expr { \skvifemptyTF\xa } )
519 or ( expr { \skvifdefTF\xb } or expr { \skvifxTF\xa\xb } )
520 }{%
521 \def\x{T}%
522 }{%
523 \def\x{F}%
524 }
525
526 %++++++++++++++++++++++++++++ \cicadaloop +++++++++++++++++++++++++++%
527
528 \makeatletter
529 \skvtestcnt\z@
530 \def\blist{{X};\fi;{Y};Z}
531 \def\stack{}
532 \let\romn\romannumeral
533 \cicadaloop{{a},\if,{b},c}\if01\fi{%
534 \advance\skvtestcnt by\@ne
535 \@tempcntb\z@\@tempswafalse
536 \cicadaloop*[;]\blist\if@tempswa\fi{%
537 \advance\@tempcntb by\@ne
538 \typeout{Doing \romn\skvtestcnt, \romn\@tempcntb:
539 \detokenize{#1, ##1}}%
540 \edef\stack{%
541 \unexpanded\expandafter{\stack}\noexpand\do
542 {\romn\skvtestcnt,\romn\@tempcntb}{\unexpanded{#1;##1}}%
543 }%
544 \ifnum\@tempcntb>\tw@\@tempswatrue\fi
545 }%
546 }
547 \makeatother
548
549 %++++++++++++++++++++++++ \ifcases ++++++++++++++++++++++++++++++%
550
551 \skvifcases b\then
552 case{a}{\def\x{do a}}
553 case{b}{\def\x{do b}}
554 case{c}{\def\x{do c}}
555 % default{\def\x{no match}}
556 \fi
557
558 \skvifcasse{x}
559 case{a}{\def\x{do a}}
560 case{b}{\def\x{do b}}
561 case{c}{\def\x{do c}}
562 \elsedo
563 \def\x{no match}
564 \endif
565
566 \skvifcasse{x}
567 case{a}{\def\x{do a}}
568 case{b}{\def\x{do b}}
569 case{c}{\def\x{do c}}
570 %\elsedo
571 % \def\x{no match}
572 \endif
573
574 %++++++++++++ Processing a key's value as a comma list +++++++++++%
575
576 \skvordkeys[KV]{fam}{key1,key2}[default]{%
577 .arg{#1/#2}%
578 \def\x##1{##1*#1*#2}%
579 }
580 \def\aval{val1a/val1b}
581 \def\bval{val2a/val2b,val2c/val2d}
582 \skvsetkeys[KV]{fam}{%
583 key1=\aval,
584 key2=.eprocess list{\bval}
585 }
586
587 \skvordkeys[KV]{fam}{key1}[default]{\def\x##1{##1*#1}}
588 \def\aval{val1a,val1b,val1c,val1d}
589 \def\bval{\aval}
590 \def\cval{\bval}
591 \skvsetkeys[KV]{fam}{%
592 key1=.expand once process list{\aval},
593 key1=.expand twice process list{\bval},
594 key1=.expand process list{\cval}
595 }
596
597 % End of file skeyval-pokayoke1.tex