Debian Codegraph @

texmf-dist/doc/latex/keyreader/keyreader-guide.tex

raw
1 \documentclass[
2 use-a4-paper,
3 use-10pt-font,
4 final-version,
5 use-UK-English,
6 fancy-section-headings,
7 frame-section-numbers,
8 para-abstract-style,
9 inputfile,
10 input-config-file,
11 no-hyperref-messages,
12 wrapquote
13 ]{amltxdoc}
14
15 \makeatletter
16 \hfuzz1pt\vfuzz2pt
17 \makeindex
18 \WrapQuotes
19 \AfterAfterStartOfDocument{%
20 \def\amd@sectitlefmt{\centering\Large\sffamily\color{secheadcolor}}%
21 }
22 \let\footnote\ltsfootnote
23 \extrarowheight=2pt
24 \arrayrulecolor{yellow}
25
26 \begin{document}
27
28 \begin{frontmatter}
29 \title{}
30 \titlenotes[t1,t2]{%
31 The package is available at \url{\titleurltext}.\sep
32 This user manual corresponds to version~0.5 of the package.
33 }
34 \subtitle{}
35 \titleurl{http://mirror.ctan.org/macros/latex/contrib/keyreader/}
36 \author{Ahmed Musa\authorref{a1}}
37 \authornotes[a1]{%
38 The University of Central Lancashire, Preston, UK. \email{[email protected]}.
39 }
40 \def\abstractname{\textsf{Summary}}
41 \begin{abstract}
42 \small
43 The \pkg{keyreader} bundle is platform independent \latex package that provides robustness and some extensions to the \pkg'{xkeyval}. However, it isn't completely independent of the \pkg'{xkeyval}. It preserves braces in key values throughout parsing and saves estate when defining keys. Also, the command \fx{\krdsetkeys} allows unbalanced conditionals to be parsed as values of keys. Furthermore, when the command \fx{\krddefinekeys} is used, keys are initialized as soon as they are defined, and, unlike in the \pkg'{xkeyval}, admissible alternate values of choice keys can have individual callbacks. The looping macros of the \pkg'{xkeyval} are redefined, to increase robustness. The command \fx{\define@key} of the \pkg'{xkeyval} has had two of its subordinate commands redefined, to offset a complaint about the grabbing of the key's callback when defining keys with \fx{\define@key}. This user manual assumes that the reader is familiar with some of the functions and user interfaces of the \pkg'{xkeyval}. The \fx{\krdkeys} command ... Unlike the \pkg'{xkeyval}, the \pkg'{keyreader} can be loaded before \hx{\documentclass} and this feature doesn't affect its ability to later filter class options-list for options that have values.
44 \end{abstract}
45
46 \let\licensename\relax
47 \begin{license}
48 \xwmcolorbox[textalign=justified,outerframecolor=blue,innerframecolor=orange,width=.985\hsize]{%
49 This work (\ie, all the files in the \pkg'{keyreader} bundle) may be distributed and/or modified under the conditions of the \lppl, either version~1.3 of this license or any later version.
50 \endgraff
51 The \lppl maintenance status of this software is \quoted{author-maintained}. This software is provided \quoted{as it is}, without warranty of any kind, either expressed or implied, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose.
52 \endgraf
53 \centerline{\makered{\CopyrightYear}}\vspace{-.8\baselineskip}\relax
54 }
55 \end{license}
56 \end{frontmatter}
57
58 \begingroup
59 \normalcolor\normalfont
60 \hrule
61 \vskip 1ex plus 1pt minus 1pt
62 \def\contentsname{\centerline{\Large\textcolor{blue}{Contents}}}
63 \hypersetup{linkcolor=blue}
64 \textsf{\tableofcontents}
65 \hrule
66 \endgroup
67
68 \docsection(sec:motivation){Motivation}
69
70 The \pkg'{keyreader} predated the \pkg'{ltxkeys} and was developed to make key parsing by the \pkg'{xkeyval} robust (in the sense of preserving outer braces in key values throughout parsing and enabling the parsing of key values with unbalanced conditionals), as well as reduce the amount of typing that is required for defining several keys. To achieve robustness in key parsing, the \fx{\setkeys} command of the \pkg'{xkeyval} has been patched and renamed \fx{\krdsetkeys}. The \pkg'{xkeyval}'s \fx{\setkeys} remains unchanged, to avoid breaking existing codes that rely on it's current form. Some other low-level commands of \pkg'{xkeyval} have been patched and renamed. The \pkg'{keyreader} provides commands for compactly defining and setting all types of key (ordinary, command, boolean, and choice). Also, the \pkg'{keyreader} introduces the concept of callbacks for the alternate/admissible values of choice keys defined via the command \fx{\krddefinekeys}. Moreover, when \fx{\krddefinekeys} is used, keys are automatically set/initialized as soon as they are defined. This provides default definitions for the key macros and functions. Boolean keys are initialized with a value of \hx{false} irrespective of their default values.
71
72 The \pkg'{keyreader} has been used as a development platform for the \pkg'{ltxkeys} because the \pkg'{xkeyval}, on which the \pkg'{keyreader} is based, has been quite stable for some years, its inherent shortcomings not withstanding. Has the user ever tried to pass to \pkg'{xkeyval}'s \fx{\setkeys} an unbalanced conditional as the value of a key? He/she will quickly be hit by the error message \quoted{! Incomplete \hx{\ifx}; all text was ignored after line \ldots}, or something similar. This limitation has been removed by the \pkg'{keyreader}\footnote{But, in general, parsing unbalanced conditionals isn't advisable in \tex.}.
73
74
75 The packages in the \pkg{keyreader} bundle are ...
76
77
78 \docsection(sec:definingkeys){Defining keys}
79
80 The syntax for defining keys is:
81
82 \start{newmacro}[\krddefinekeys]
83 \krddefinekeys|*[|A(kprefix)]{|A(kfamily)}[|A(mprefix)]{|A(keylist)}
84 \finish{newmacro}
85 \fxim*{\krddefinekeys}
86
87 The optional \ang{kprefix} and mandatory \ang{kfamily} have unambiguous connotations. The optional \ang{mprefix} is the macro prefix, in the parlance of the \pkg'{xkeyval}. The default values of \ang{kprefix} and \ang{mprefix} are \ffx'{KV,krdmp}, respectively.
88
89 \start'{macro}[Syntax of key keylist]
90 \krddefinekeys[<pref>]{<fam>}[<mp>]{
91 ord/<key>/<dft>/<f1>;
92 cmd/<key>/<dft>/<f1>;
93 bool/<key>/<dft>/<f1>;
94 bool+/<key>/<dft>/<f1>/<f2>;
95 choice/<key>/<dft>/<nominations>/<f1>;
96 choice+/<key>/<dft>/<nominations>/<f1>/<f2>;
97 }
98 \finish{macro}
99
100 In the case of ordinary, command and boolean keys, \ang{keylist} has the syntax
101
102 \start'{macro}[Syntax of key keylist]
103 {
104 |A(keytype-1)/|A(keyname-1)/|A(default-1)/|A(callback-1);
105 |A(keytype-2)/|A(keyname-2)/|A(default-2)/|A(callback-2);
106 ...
107 |A(keytype-n)/|A(keyname-n)/|A(default-n)/|A(callback-n);
108 }
109 \finish{macro}
110
111 The list parser for \ang{keylist} is invariably \qsemicolon. Hence, if the user has \qsemicolon in \ang{callback}, it has to be wrapped in curly braces, to hide it from \tex's scanner. \ang{keytype} can be any member of the list \leftbrace\fx{ord} (ordinary key), \fx{cmd} (command key), \fx{bool} (boolean key), \fx{choice} (choice key)\rightbrace.
112
113 For choice keys, \ang{keylist} has the syntax
114
115 \start'{macro}[Syntax of key keylist]
116 {
117 |A(keytype-1)/|A(keyname-1)/|A(default-1)/|A(alt)/|A(callback-1);
118 |A(keytype-2)/|A(keyname-2)/|A(default-2)/|A(alt)/|A(callback-2);
119 ...
120 |A(keytype-n)/|A(keyname-n)/|A(default-n)/|A(alt)/|A(callback-n);
121 }
122 \finish{macro}
123
124 The \emph{alternate values} (also called \emph{nominations} or \emph{admissible list of user input}) \ang{alt} has the syntax
125
126 \start'{macro}[Syntax of alternate list for choice keys]
127 |A(value-1).do=|A(callback-1),
128 |A(value-2).do=|A(callback-2),
129 ...
130 |A(value-n).do=|A(callback-n),
131 \finish{macro}
132
133 The list parser in this case is invariably \qcomma.
134
135 The star (\redstar*) sign on \fx{\krddefinekeys} is an optional suffix. If it is present, then only definable (\ie, non-existent) keys will be defined. The existence of a key depends on \ang{kprefix} and \ang{kfamily}, since keys are name-spaced.
136
137 \ltsnote
138 Choice keys defined by \fx{\krddefinekeys} are of the \stform of choice keys (see the \pkg'{xkeyval} guide). Hence they will always convert the user input into lowercase before matching it against the alternate/admissible list of values specified at key definition time. The matching, as done by \fx{\krdsetkeys}, is catcode-agnostic.
139
140
141 \docsection(sec:settingkeys){Setting keys}
142
143 The command \fx{\krdsetkeys} is a more robust counterpart of the \pkg'{xkeyval}'s \fx{\setkeys}, in the sense that it preserves all outer braces in the values of keys and allows the parsing of key values with unbalanced conditionals. The new command \fx{\krdsetkeys} has the same syntax as the original \fx{\setkeys} of the \pkg'{xkeyval}, namely
144
145 \start{newmacro}[\krdsetkeys]
146 \krdsetkeys|*|+[|A(kprefix)]{|A(families)}[|A(na)]{|A(|verbkeyval)}
147 \finish{newmacro}
148 \fxim*{\krdsetkeys,\setkeys}
149
150 As usual, the star (\redstar) and plus sign (\redplus) are optional suffixes. The \stform will save all undeclared keys in the list \fx{\XKV@rm}, possibly for setting later with the command \fx{\setrmkeys}, and will not report any unknown key as undeclared. The \plform will set the given keys in all the given families, instead of in just one family. The combination \redstar\redplus* will set the listed keys in all the given families and append unknown keys to the container \fx{\XKV@rm}. \ang{na} is the list of keys that shouldn't be set in the current run.
151
152 The command \fx{\krdsetkeys} isn't exactly \pkg'{xkeyval}'s \fx{\setkeys}, since the former is more robust and avoids the selective sanitization of \keyval list that is done by \fx{\setkeys}. The macro \fx{\krdsetkeys} \quoted{normalizes} the \keyval or comma-separated key list. Therefore, users of the \pkg'{keyreader} should always call the command \fx{\krdsetkeys} instead of \fx{\setkeys}. Both have the same user interface. The \fx{\setkeys} command of the \pkg'{xkeyval}'s remains unchanged.
153
154 The \pkg'{xkeyval}'s command \fxi{\setrmkeys}, which sets \quoted{remaining keys}, has been replaced by \fxi{\krdsetrmkeys}, while keeping \fx{\setrmkeys} unchanged. Users of the \pkg'{keyreader} should use \fx{\krdsetrmkeys} in place of \fx{\setrmkeys}.
155
156 \start*+{example}[\ifkrdnovalue]
157 \krdordkey[KV]{fam}{keya}[default]{%
158 \ifkrdnovalue
159 \krd@err{No user value supplied for key `keya'}
160 {Key `KV/fam/keya' requires a user value.}%
161 \else
162 \edef\userinput{\unexpanded{#1}}%
163 \fi
164 }
165 \krdsetkeys[KV]{fam}{keya}
166 \krdsetkeys[KV]{fam}{keya=value}
167 \finish{example}
168
169
170 \docsection(sec:disable-keys)<disabling keys>{Disabling keys}
171
172 The command \fxim{\krddisablekeys} has the same use syntax as the \fxi{\disable@keys} command of the \pkg'{xkeyval}, but will issue an error (instead of a warning) when an attempt is made to set a disabled key.
173
174
175 \docsection(sec:options-processing)<options processing>{Options processing}
176
177 The commands \ffxi'{\krdDeclareOption, \krdExecuteOptions, \krdProcessOptions} are replacements for \ffxi'{\DeclareOptionX, \ExecuteOptionsX, \ProcessOptionsX} of the \pkg'{xkeyval}.
178
179
180 \docsection(sec:examples)<examples>{Some examples}
181
182 \start*+{example}[\krddefinekeys, \krdsetkeys]
183 \krddefinekeys*[KV]{fam}[pnt@]{%
184 |com(`#1' throughout here refers to the user input for the key.)
185 ord/keya/{black}/\def\xx##1{#1##1};
186 cmd/keyb/\@fisrtofone/\def\y##1{#1##1};
187 bool/keyc/true/\def\z##1{#1##1};
188 choice/keyd/center/
189 center.do=\def\vcp@align{center}\def\w##1{#1##1},
190 left.do=\def\vcp@align{flushleft},
191 right.do=\def\vcp@align{flushright},
192 justified.do=\def\vcp@align{relax}
193 /
194 \ifkrdindef\else
195 \def\xa##1{#1##1}
196 \fi;
197 ord/keye/{keye-default}/\def\y##1{#1##1}
198 }
199 \krdsetkeys[KV]{fam}[keyb]{keya={green},keyb=\@iden,keyc=false,keyd=left}
200 |com(Setting keys with values having unbalanced conditionals:)
201 \krdsetkeys[KV]{fam}{keye={\iffalse keye-value}}
202
203 \krddefinekeys*[KV]{fam}[mp@]{%
204 ord/keya/default-a/\def\x##1{#1*##1};
205 bool/keyb/true/;
206 bool+/keyc/true//\@latexerr{Invalid value for keyc}\@ehd;
207 cmd/keyd/black;
208 choice+/keye/center/
209 center.do=\let\mp@alignright\hfil\let\mp@alignleft\hfil,
210 right.do=\let\mp@alignright\hfill\let\mp@alignleft\relax,
211 left.do=\let\mp@alignright\relax\let\mp@alignleft\hfill,
212 //
213 \let\mp@alignright\hfil\let\mp@alignleft\hfil
214 \@@warning{Invalid value for 'align'; 'center' assumed}
215 ;
216 ord/keyf/.na/\def\y##1{#1*##1}; |com(No default.)
217 bool+/keyg/true; |com(Will raise error when user input is invalid.)
218 }
219 \finish{example}
220
221 The braces around \quoted{green}, the value of \fx{keya}, will be preserved throughout parsing. It should be remembered that keys are automatically set as soon as they are defined by \fx{\krddefinekeys}. The boolean \fx{\ifkrdindef} is true when \fx{\krddefinekeys} is defining keys, and false otherwise. The essence of it is that since keys are set as soon as they are defined by \fx{\krddefinekeys}, some actions should not be executed at this time, until the keys are being set by the user.
222
223 Using the keys defined in the above example, let us make \qcomma and \qequal active and see how the \pkg'{keyreader} will deal with them.
224
225 \start*{example}[Active comma and equals sign]
226 |com(Make comma (`,') and equal `=' active to test the list normalization)
227 |com(scheme of `keyreader' pacakge:)
228 \begingroup
229 \catcode`\,=13
230 \catcode`\==13
231 \gdef\keylista{{fam,famb}[keyb , keyc]{keya = {green} , keyb = \@iden ,
232 keyc = false , keyd = left, keye = somevalue}}
233 \gdef\keylistb{\krdsetrmkeys|*|+[KV]{fam,famb}}
234 \endgroup
235 \def\reserved@a{\krdsetkeys|*|+[KV]}
236 \expandafter\reserved@a\keylista
237 \keylistb
238 \finish{example}
239 \aidx*{active comma and equals sign}
240
241 The output of the following example is shown in \sref{fig:1}:
242
243 \start*{example}[\label{example:1}]
244 \documentclass{article}
245 \usepackage{keyreader}
246 \usepackage{xcolor}
247 \makeatletter
248 \newdimen\shadowsize
249 \krddefinekeys*[KV]{ebox}[mp@]{%
250 bool/frame/true;
251 bool/shadow/true;
252 cmd/framecolor/black;
253 cmd/shadecolor/white;
254 cmd/shadowcolor/gray;
255 cmd/framesize/.4pt;
256 cmd/boxsize/.1\columnwidth;
257 cmd/shadowsize/1pt;
258 choice/align/center/
259 center.do=\let\mp@alignright\hfil\let\mp@alignleft\hfil,
260 right.do=\let\mp@alignright\hfill\let\mp@alignleft\relax,
261 left.do=\let\mp@alignright\relax\let\mp@alignleft\hfill,
262 justified.do=\let\mp@alignright\relax\let\mp@alignleft\relax
263 /
264 \def\userinput{#1};
265 }
266 \savevaluekeys[KV]{ebox}{frame,framecolor,framesize}
267 |com(`Preset keys' have no `tail keys':)
268 \krdpresetkeys[KV]{ebox}{%
269 frame,framecolor=black,framesize=0.5pt,boxsize,align
270 }
271 |com(`Postset keys' have no `head keys':)
272 \krdpostsetkeys[KV]{ebox}{%
273 shadow=\usevalue{frame},shadowcolor=\usevalue{framecolor}!40,
274 shadowsize=\usevalue{framesize}*4
275 }
276 \newcommand*\ebox[2][]{%
277 \krdsetkeys[KV]{ebox}{#1}%
278 |com(What happens if we use the following, instead of the above \krdsetkeys?)
279 |com(Preset and postset keys wouldn't be set when `#1' is empty:)
280 |com(\krdifblank{#1}{}{\krdsetkeys[KV]{ebox}{#1}})
281 \begingroup
282 \ifmp@frame
283 \fboxrule=\dimexpr\mp@framesize\relax
284 \else
285 \fboxrule=0pt
286 \fi
287 \ifmp@shadow
288 \shadowsize=\dimexpr\mp@shadowsize\relax
289 \else
290 \shadowsize=0pt
291 \fi
292 \setbox0=\hbox{%
293 \fcolorbox{\mp@framecolor}{\mp@shadecolor}{%
294 \hbox to\mp@boxsize{%
295 \mp@alignright #2\mp@alignleft
296 }%
297 }%
298 }%
299 \hskip\shadowsize
300 \color{\mp@shadowcolor}%
301 \rule[-\dp0]{\wd0}{\the\dimexpr\ht0+\dp0\relax}%
302 \llap{\raisebox{\shadowsize}{\box0\hskip\shadowsize}}%
303 \endgroup
304 }
305 \makeatother
306
307 \begin{document}
308 \ebox{ebox1}
309 \ebox[framecolor=gray,boxsize=2cm,align=right]{ebox2}
310 \ebox[shadow=false,boxsize=1.5cm,align=left]{ebox3}
311 \ebox[framesize=1pt,framecolor=green,shadowcolor=blue]{ebox4}
312 \ebox[frame=false,shadow,shadowcolor=yellow,framesize=.5pt]{ebox5}
313 \end{document}
314 \finish{example}
315 \fxim*{\krdpresetkeys,\krdpostsetkeys}
316
317 \begin{figure}[h!]
318 \caption{Output of \sref{example:1}\label{fig:1}}
319 \centerline{%
320 \includegraphics[viewport=141 642 416 674,clip,scale=1]{keyreader-example1}%
321 }
322 \end{figure}
323
324
325 \docsection(sec:version-hist){Version history}
326
327 The following change history highlights significant changes that affect user utilities and interfaces; changes of technical nature are not documented in this section.
328
329 \begin{versionhist}
330 \begin{version}{0.5b}{2012/11/06}
331 \item Choice keys can't have outer-braced default or user-supplied values. Outer-braced values may not have been given in the state pattern. Hence the outer braces are removed automatically internally before matching the value against the singleton. Also, key values are no longer converted into lowercase before matching against the state pattern.
332 \end{version}
333 \begin{version}{0.5}{2012/10/10}
334 \item The \pkg'{keyreader} can now be loaded before \fx{\documentclass}.
335 \end{version}
336 \begin{version}{0.4b}{2012/01/14}
337 \item The command \fx{\krdsetkeys} can now parse key values with unbalanced conditionals.
338 \end{version}
339 \begin{version}{0.4a}{2011/12/23}
340 \item The key list in \fx{\krddefinekeys} shouldn't have been normalized with respect to forward slash (/).
341 \end{version}
342 \begin{version}{0.4}{2011/12/20}
343 \item Several of the former functions of the package have been transferred to the independent \pkg'{ltxkeys} with even more robustness. The package now provides mainly a compact and robust interface to the features of the \pkg'{xkeyval} for users of \pkg'{xkeyval}.
344 \end{version}
345 \begin{version}{0.3}{2011/03/26}
346 \item Bug fix.
347 \end{version}
348 \begin{version}{0.2}{2011/02/25}
349 \item The interface for defining new keys now accepts conditionals in key macros/functions.
350 \item A mechanism is provided for automatic setting up and execution of key functions with default key values.
351 \end{version}
352 \begin{version}{0.1}{2010/01/10}
353 \item First public release.
354 \end{version}
355
356 \end{versionhist}
357
358 \newpage
359 \ltsindexpreamble{Index numbers refer to page numbers.}
360 \ltsindexpreambleformat{\centering}
361 \ltsindexcolumns\tw@
362 \printindex
363
364 \end{document}