summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/keyreader/keyreader-guide.tex
blob: 41c1ca88398eabae88f9356c2e517616e6d1cf1b (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
\documentclass[
  use-a4-paper,
  use-10pt-font,
  final-version,
  use-UK-English,
  fancy-section-headings,
  frame-section-numbers,
  para-abstract-style,
  inputfile,
  input-config-file,
  no-hyperref-messages,
  wrapquote
]{amltxdoc}

\makeatletter
\hfuzz1pt\vfuzz2pt
\makeindex
\WrapQuotes
\AfterAfterStartOfDocument{%
  \def\amd@sectitlefmt{\centering\Large\sffamily\color{secheadcolor}}%
}
\let\footnote\ltsfootnote
\extrarowheight=2pt
\arrayrulecolor{yellow}

\begin{document}

\begin{frontmatter}
\title{The \texttt{\color{blue}keyreader} Package\titleref{t1,t2}}
\titlenotes[t1,t2]{%
  The package is available at \url{\titleurltext}.\sep
  This user manual corresponds to version~0.4a of the package.
}
\subtitle{A robust interface to \pkg'{xkeyval}}
\titleurl{http://mirror.ctan.org/macros/latex/contrib/keyreader/}
\author{Ahmed Musa\authorref{a1}}
\authornotes[a1]{%
  The University of Central Lancashire, Preston, UK. \email{amusa22@gmail.com}.
}
\def\abstractname{\textsf{Summary}}
\begin{abstract}
  \small
  The \pkg'{keyreader} provides robustness and some extensions to the \pkg'{xkeyval}. It preserves braces in key values and saves estate when defining keys. Also, 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. This user manual assumes that the reader is familiar with some of the functions and user interfaces of the \pkg'{xkeyval}.
\end{abstract}

\let\licensename\relax
\begin{license}
\xwmcolorbox[textalign=justified,outerframecolor=blue,innerframecolor=orange,width=.985\hsize]{%
  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.
  \endgraff
  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.
  \endgraf
  \centerline{\makered{\CopyrightYear}}\vspace{-.8\baselineskip}\relax
}
\end{license}
\end{frontmatter}

\begingroup
\normalcolor\normalfont
\hrule
\vskip 1ex plus 1pt minus 1pt
\def\contentsname{\centerline{\Large\sffamily\textcolor{blue}{Contents}}}%
\hypersetup{linkcolor=blue}\tableofcontents
\hrule
\endgroup

\vspace{3\baselineskip}
\newpage
\docsection(sec:motivation){Motivation}

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), 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'{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.

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. Because the \pkg'{keyreader} is based on the \pkg'{xkeyval}, it inherits some of the limitations of the \pkg'{xkeyval}. Has the user ever tried to pass to \pkg'{xkeyval}'s \fx{\setkeys} an unbalanced conditional (invloving \hhx{\iftrue,\iffalse,\ifx}, or \hx{\fi}) 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. The same limitation applies to the \pkg'{keyreader}. In this respect, the \pkg'{ltxkeys} is more robust.


\docsection(sec:user-commands)<user commands>{User commands}

The syntax for defining new keys is:

\start{newmacro}[\krddefinekeys]
\krddefinekeys|*[|A(kprefix)]{|A(kfamily)}[|A(mprefix)]{|A(keylist)}
\finish{newmacro}
\fxim*{\krddefinekeys}

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'{KRD,krdmp@}, respectively.

In the case of ordinary, command and boolean keys, \ang{keylist} has the syntax

\start'{newmacro}[Syntax of key keylist]
{
  |A(keytype1)/|A(keyname1)/|A(default1)/|A(callback1);
  |A(keytype2)/|A(keyname2)/|A(default2)/|A(callback2);
  etc.
}
\finish{newmacro}

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.

For choice keys, \ang{keylist} has the syntax

\start'{newmacro}[Syntax of key keylist]
{
  |A(keytype1)/|A(keyname1)/|A(default1)/|A(alt)/|A(callback1);
  |A(keytype2)/|A(keyname2)/|A(default2)/|A(alt)/|A(callback2);
  etc.
}
\finish{newmacro}

The alternate (admissible list of) values \ang{alt} has the syntax

\start'{newmacro}[Syntax of alternate list for choice keys]
|A(value1).code=|A(callback1),
|A(value1).code=|A(callback1),
etc.
\finish{newmacro}

The list parser in this case is invariably \qcomma.

The star (\redstar*) is an optional prefix. 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.

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. The new command \fx{\krdsetkeys} has the same syntax as the original \fx{\setkeys} of the \pkg'{xkeyval}, namely

\start{macro}[\setkeys]
\krdsetkeys|*|+[|A(kprefix)]{|A(families)}[|A(na)]{|A(|verbkeyval pairs)}
\finish{macro}

As usual, the star (\redstar) and plus sign (\redplus) are optional prefixes. 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.

Since a package might redefine \fx{\setkeys}, we also saved the patched \fx{\setkeys} in \fx{\krdsetkeys}. Indeed, \fx{\krdsetkeys} isn't exactly \fx{\setkeys}, since the former avoids the selective sanitization of \keyval list that is done by \fx{\setkeys}. Instead \fx{\krdsetkeys} \quoted{normalizes} the \keyval or comma-separated 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 \pkg'{xkeyval}'s command \fxi{\setrmkeys}, which sets \quoted{remaining keys}, has been modified to \fxi{\krdsetrmkeys}, while keeping \fx{\setrmkeys} unchanged. Users of the \pkg'{keyreader} should use \fx{\krdsetrmkeys} in place of \fx{\setrmkeys}.


\docsection(sec:examples)<examples>{Examples}

\start+{example}[\krddefinekeys, \krdsetkeys]
\krddefinekeys*[KV]{fam}[pnt@]{%
  |com(`#1' here refers to the user input for the key.)
  ord/keya/{black}/\def\xx##1{#1##1};
  cmd/keyb/\@fisrtofone/\def\y##1{#1##1};
  bool/keyc/true/\def\z##1{#1##1};
  choice/keyd/center/
    center.code=\def\my@align{center}\def\w##1{#1##1},
    left.code=\def\my@align{flushleft},
    right.code=\def\my@align{flushright},
    justified.code=\def\my@align{relax}%
    /\def\xa##1{#1##1};
}
\krdsetkeys[KV]{fam}[keyb]{keya={green},keyb=\@iden,keyc=false,keyd=left}
\finish{example}
\fxi*{\krddefinekeys,\setkeys,\krdsetkeys}

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}.

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.

\start{example}[Active comma and equal sign]
|com(Make comma (`,') and equal `=' active to test the list normalization)
|com(scheme of `keyreader' pacakge:)
\begingroup
\catcode`\,=13
\catcode`\==13
\gdef\keylista{{fam,famb}[keyb , keyc]{keya = {green} , keyb = \@iden ,
  keyc = false , keyd = left, keye = somevalue}}
\gdef\keylistb{\krdsetrmkeys|*|+[KV]{fam,famb}}
\endgroup
\def\reserved@a{\krdsetkeys|*|+[KV]}
\expandafter\reserved@a\keylista
\keylistb
\finish{example}
\aidx*{active comma and equal sign}


\docsection(sec:disable-keys)<disabling keys>{Disabling keys}

The command \fxim{\krddisablekeys} has the same use syntax as \pkg'{xkeyval}'s command \fxi{\disable@keys} but will issue an error (instead of a warning) when an attempt is made to set a disabled key.


\docsection(sec:options-processing)<options processing>{Options processing}

The commands \ffxi'{\krdDeclareOption, \krdExecuteOptions, \krdProcessOptions} are aliases for
\ffxi'{\DeclareOptionX, \ExecuteOptionsX, \ProcessOptionsX} of the \pkg'{xkeyval}.


\docsection(sec:version-hist){Version history}

The following change history highlights significant changes that affect user utilities and interfaces; changes of technical nature are not documented in this section.

\begin{versionhist}
  \begin{version}{0.4a}{2011/12/23}
  \item Bug fix: the key list in \fx{\krddefinekeys} shouldn't have been normalized with respect to forward slash (/).
  \end{version}
  \begin{version}{0.4}{2011/12/20}
  \item Several of the former functions of the package have been transferred to the \pkg'{ltxkeys} with even more robustness. The package now provides mainly a compact and robust interface to the features of the \pkg'{xkeyval}.
  \end{version}
  \begin{version}{0.3}{2011/03/26}
  \item Bug fix.
  \end{version}
  \begin{version}{0.2}{2011/02/25}
  \item The interface for defining new keys now accepts conditionals in key macros/functions.
  \item A mechanism is provided for automatic setting up and execution of key functions with default key values.
  \end{version}
  \begin{version}{0.1}{2010/01/10}
  \item First public release.
  \end{version}

\end{versionhist}

\newpage
\ltsindexpreamble{Index numbers refer to page numbers.}
\ltsindexpreambleformat{\centering}
\ltsindexcolumns\tw@
\printindex

\end{document}