Debian Codegraph @

texmf-dist/doc/latex/ltxkeys/ltxkeys-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
17 \ltscomment
18 % Include the use of the following commands in this manual:
19 % \ifltxkeys@novalue
20 % \ltxkeys@presetkeys
21 % \ltxkeys@gpresetkeys
22 % \ltxkeys@postsetkeys
23 % \ltxkeys@gpostsetkeys
24 % \ltxkeys@preposetkeys
25 % \ltxkeys@gpreposetkeys
26
27
28 \ltxkeysifinlistTF, \ltxkeysnormalizeset, \ltxkeysnormalizecsset
29 \carmustykeys
30
31 \ltscommentend
32
33 \begin{document}
34
35 \begin{frontmatter}
36 \title{The \texttt{\color{blue}ltxkeys} Package\titleref{t1,t2}}
37 \titlenotes[t1,t2]{%
38 The package is available at \url{\titleurltext}.\sep
39 This user manual corresponds to version~0.0.3 of the package.
40 }
41 \subtitle{A robust key parser for \latex}
42 \titleurl{http://mirror.ctan.org/macros/latex/contrib/ltxkeys/}
43 \author{Ahmed Musa\authorref{a1}}
44 \authornotes[a1]{%
45 The University of Central Lancashire, Preston, UK. \email{[email protected]}.
46 }
47 \end{frontmatter}
48
49 \hrule
50 \vskip 1ex plus 1pt minus 1pt
51 \begingroup
52 \def\contentsname{\centerline{\Large\sffamily\textcolor{blue}{Contents}}}
53 \hypersetup{linkcolor=blue}
54 \sffamily\tableofcontents
55 \endgroup
56 \hrule
57
58 \ltsnewfootnote{1}{%
59 Because of the multitude of functions provided by the \pkg'{ltxkeys}, it may actually slow down when executing some tasks, depending on the task at hand. The package option \fx{tracingkeys}, for example, does slow down processing. And automatically initiating keys after definition, as done by the commands \ffx'{\ltxkeysdefinekeys, \ltxkeysdeclarekeys}, also affects processing speed; so does \quoted{launching keys}, which first presets absent keys with their default values before setting the current keys (\ie, keys whose values are provided by the user at the moment of setting keys that belong to a family). Then, as in the \pkg'{xkeyval}, there are the commands for presetting and post-setting keys.
60 }
61 \ltsnewfootnote{2}{%
62 Options are also keys, but (from the user's viewpoint) there might be a need to treat options separately when dealing with unknown keys.
63 }
64
65
66 \docsection(sec:intro){Introduction}
67
68 \lletter{T}{he \pkg'{ltxkeys}} provides facilities for creating and managing keys in the manner of the \pkg'{keyval, xkeyval}, but it is intended to be more robust, faster, and provide more functionality than these earlier packages. Its robustness emanates from, inter alia, its ability to preserve braces in key values throughout parsing. The need to preserve braces in key values without expecting the user to double braces emerges often in parsing keys. This is the case in, \eg, the \pkg'{xwatermark}, but consider also the possibility of passing all the following options to a package at once, where \quotedtt{layout} is a package or class option or key\footnote{It should be noted that if a value of the demonstrative option \fx{layout} is expandable, then the option can't be passed by \hx{\documentclass} without preloading a robust options parser like \pkg{kvoptions-patch, xkvltxp, ltxtools}, or \pkg{ltxkeys} package. In fact, \latex's native options processor can't handle options with values. The \pkg'{ltxkeys}, unlike the \pkg'{xkeyval}, can be loaded before \hx{\documentclass}.}:
69
70 %[Braced option values]
71 \start'{example}
72 \pkgoptions{%
73 opt1=val1,opt2=val2,
74 layout={left=3cm,right=3cm,top=2.5cm,bottom=2.5cm,include=true}
75 }
76 \finish{example}
77
78 As a practical example, consider the command \fx{\loadModules} with the syntax
79
80 \start'{example}[Braced key values]
81 \loadModules{|A(base)}{|A(modules)}
82 \finish{example}
83
84 where \ang{modules} is a comma-separated \keyval list. Like the above \quotedtt{layout} option, each key of \fx{\loadModules} may have a value (representing module options) that is itself a comma-separated \keyval list.
85
86 Well, the type of robustness described here isn't actually difficult to implement within the \pkg'{xkeyval}. This is indeed what the \pkg'{keyreader} does: it re-implements some of the commands of the \pkg'{xkeyval} to achieve this robustness. That said, we have to indicate that the \pkg'{ltxkeys} implements this robustness intrinsically and it has many more features than the \pkg{xkeyval} and \pkg{keyreader} packages.
87
88 In some respects, depending on the task at hand, the \pkg'{ltxkeys} is faster\usefootnote{1} than the \pkg'{xkeyval} mainly because it avoids character-wise parsing of key values (which is called \quoted{selective sanitization} by the \pkg'{xkeyval}\footnote{See \ltshref{http://www.latex-project.org/cgi-bin/ltxbugs2html?pr=babel/3523}{here} for the problems of parsing key-value pairs within \pkg{babel}.}). Moreover, it is faster to normalize a comma-separated or \keyval list than trim leading and trailing spaces of each element of the list (as the \pkg'{xkeyval} does), since not all the elements of the list will normally have leading and trailing spaces. In fact, the chances are that only less than 50~percent of the elements of the list will have such spaces. As another example of optimization, anyone familiar with the implementation of the \pkg'{xkeyval} would have noticed that the macro \hx{\XKV@srstate}, which (in order to allow \hx{\setkeys} to be re-entrant) pushes and pops the states of some important functions in the package, loops over all the functions both when pushing and popping. In the \pkg'{ltxkeys}, pushing and popping functions together involve looping over the functions only once. And, unlike in the \pkg'{xkeyval}, higher order functions are undefined as soon as they are no longer needed, to avoid clogging up the stack. No additional looping is required for this.
89
90 In setting keys, the \pkg'{ltxkeys} loops over not only families, as in the \pkg'{xkeyval}, but also over key prefixes. The same strategy applies when the \pkg'{ltxkeys} tries to establish if a key is defined or not.
91
92 Normally, in the \pkg'{keyval, xkeyval} it isn't directly possible to have key macros with delimited and/or multiple parameters. So you couldn't submit \quotedfx{x and y} as a key value and expect any of these packages to split this value into two arguments for the key macro and execute the key's callback. This could only be done indirectly by the key's author, within the key's callback. For example, the following isn't directly possible by those packages:
93
94 \begin{syntax}
95 \define@key[KV]{fam}{textsize}[5cm and 10cm]{%
96 \textwidth=#1 \textheight=#2
97 }
98 \setkeys[KV]{fam}{textsize=2.5cm and 8cm}
99 \finish{syntax}
100
101 The \pkg'{ltxkeys} can compactly define and set all types of key with delimited and multiple parameters for key macros. See \sref{sec:weirdargs}.
102
103 While some user interfaces of the \pkg'{ltxkeys} are similar to those of the \pkg'{xkeyval}, there are important differences in several areas of syntax, semantics, and internal implementation. The \pkg'{ltxkeys} also provides additional facilities (beyond the \pkg'{xkeyval}) for defining and managing keys. Several types of key (including ordinary keys, command keys, style keys, choice keys, list keys, boolean and biboolean keys) can be efficiently created and managed. In the \pkg'{ltxkeys}, the notions of \quoted{pre-setting} and \quoted{post-setting} keys are similar to those of the \pkg'{xkeyval}. But the \pkg'{ltxkeys} introduces additional concepts in this respect: \quoted{initialized} and \quoted{launched} keys. The latter are special preset keys. The pointer system of the \pkg'{xkeyval}, which was available only at key-setting time, is now available also at key definition time. One more type of pointer (\fx{\needvalue}) has been introduced to require users of \quoted{need-value keys} to supply values for those keys.
104
105 Rather than simply issue an error for undefined keys when setting keys, the \pkg'{ltxkeys} provides the \quoted{undefined keys} and \quoted{undefined options} handlers, which are user-customizable. Other new concepts include \quotedlist{definable keys, cross-family keys, option keys, non-option keys, handled keys, key commands, key environments}, accessing the saved value of a key outside \hx{\setkeys} or similar commands, and declaring multiple keys and options (of all genre) using only one command.
106
107 \ltsnote
108 It is not advisable to alias the commands of the \pkg'{xkeyval} to the commands of the \pkg'{ltxkeys}. There are many existing packages that rely on the \pkg'{xkeyval} and aliasing commands that are used by other packages can cause confusion\footnote{A user of version~0.0.1 of the \pkg'{ltxkeys} had sought to do this.}.
109
110
111 \docsubsection{Motivation}
112
113 What are the \emph{raison d'etre} and origins of the \pkg'{ltxkeys}? Well, I decided to write this package as I grabbled with some practical problems of key parsing while developing version~1.5.0 of the \pkg'{xwatermark}. The tasks proved more challenging than I had initially thought and, despite its commendable and widely deployed features, I found the \pkg'{xkeyval} inadequate in some respects. As mentioned earlier, all the functions of the \pkg'{ltxkeys} can be employed for general key management in \latex beyond the \pkg'{xwatermark}. Indeed, in many ways, the \pkg'{ltxkeys} now goes far beyond the needs of \pkg'{xwatermark}. Many concepts and user interfaces were introduced long after the requirements of the \pkg'{xwatermark} had been met. The \pkg'{ltxkeys} can be used as a more robust and versatile replacement for the \pkg'{xkeyval}, of course with modifications of names and some syntaxes. The \pkg'{xkeyval} has been frozen since August 2008. Users familiar with \pkg'{pgfkeys} may also wish to explore what \pkg'{ltxkeys} has to offer.
114
115
116 \docsection(sec:packageoptions)<package options>{Package options}
117
118 The package options are listed in \sref{tab:pkgoptions}. The package options can be passed via the commands \hx{\documentclass}\footnote{Passing \pkg'{ltxkeys} options via \hx{\documentclass} implies that the package is loaded after \hx{\documentclass}. As mentioned elsewhere, the \pkg'{ltxkeys} can be loaded before or after \hx{\documentclass}.}, \hx{\RequirePackage} or \hx{\usepackage} as follows:
119
120 \start{example}[Package options]
121 \documentclass[tracingkeys,keyparser={|nv}]{article}
122 |orr
123 \usepackage[tracingkeys,keyparser={|nv}]{ltxkeys}
124 \finish{example}
125
126 They can also be passed locally via the command \fx{\setltxkeysoptions}:
127
128 \start{newmacro}[\setltxkeysoptions]
129 \setltxkeysoptions{tracingkeys=false,keyparser={;}}
130 \finish{newmacro}
131 \fxim*{\setltxkeysoptions}
132
133 \newltablenote{ltxkeys-1}{%
134 The speed of compilation may be affected by this option, but it is recommended at the pre-production stages of developing keys. The option provide some trace functionality and enables the user to, among other things, follow the progress of the \latex run and to see if a key has been defined and/or set/executed more than once in the current run. The \stform+ of the commands \ffx'{\ltxkeysdefinekeys, \ltxkeysdeclarekeys} will always flag an error if a key is being defined twice, irrespective of the state of the package option \fx{tracingkeys}. The \textltxkey variants (unlike the \textnewkey variants) of key-defining commands don't have this facility, and it may be desirable to know if and when an existing key is being redefined.
135 }
136 \newltablenote{ltxkeys-2}{%
137 Wherever the \qsemicolon is indicated as a list parser in this guide, it can be replaced by any user-specified one character parser via the package option \fx{keyparser}. To avoid confusing the user-supplied parser with internal parsers, it is advisable to enclose the chosen character in curly braces when submitting it as a package option. The braces will be stripped off internally. Please note that some of the characters that may be passed as a list parser may indeed be active; be careful to make them innocent before using them as a list/key parser. My advice is that the user sticks with the \qsemicolon as the key parser: the chances of it being made active by any package is minimal. If you have the chosen parser as literals in the callbacks of your keys, they have to be enclosed in curly braces.
138 }
139 \newltablenote{ltxkeys-3}{%
140 The key-setting commands are \ffx'{\ltxkeyssetkeys,\ltxkeyssetrmkeys,\ltxkeyssetaliaskey}. If you must nest these commands beyond level~4, you have to raise the \fx{keydepthlimit} as a package option. The option \fx{keystacklimit} is an alias for \fx{keydepthlimit}.
141 }
142 \newltablenote{ltxkeys-4}{%
143 The use of an empty prefix will normally result from explicitly declaring the prefix as \fx{[]}, rather than leaving it undeclared. Undeclared prefixes assume the default value of \fx{KV}. An empty family will result from submitting the family as empty balanced curly braces \fx{{}}. If keys lack prefix and/or family, there is a strong risk of confusing key macros/functions. For example, without a prefix and/or family, a key named \fx{width} will have a key macro defined as \fx{\width}, which portents sufficient danger.
144 }
145
146 \begingroup
147 \small
148 %\trace*
149 \begin{tabularx}{\linewidth}{|p{3cm}|p{2cm}|X|}
150 \caption{Package options. All the package options can also be changed globally via \headhx{\documentclass} and locally through the control sequence \headfx{\setltxkeysoptions}.} \xwmlabel{tab:pkgoptions}
151 \\\hline
152 \rowcolor{pink}
153 \bfseries Option&\bfseries Default&\bfseries Meaning\\\hline
154 \endfirsthead
155 \hline
156 \multicolumn{3}{|l|}{\emph{Continued from last page}}\\\hline
157 \bfseries Option&\bfseries Default&\bfseries Meaning\\\hline
158 \endhead
159 \multicolumn{3}{|r|}{\emph{Continued on next page}}\\\hline
160 \endfoot
161 \hline
162 \endlastfoot
163 \fx{tracingkeys} & \hx{false} & The global boolean switch that determines if information should be logged in the transcript file for some tasks in the package. \useltablenote[tab:pkgoptions:note1]{ltxkeys-1}\\\hline
164 \fx{keyparser} & \texttt{;} & The most user-relevant of the list parsers (\ie, item separators) used by internal loops in defining keys---mainly in the macros \ffx'{\ltxkeysdefinekeys, \ltxkeysdeclarekeys}. \useltablenote[tab:pkgoptions:note2]{ltxkeys-2}\\\hline
165 \fx{keydepthlimit} & \hx{4} & This is used to guard against erroneous infinite re-entrance of the package's key-setting commands. The default value of~4 means that neither of these commands can ordinarily be nested beyond level~4.\useltablenote[tab:pkgoptions:note3]{ltxkeys-3}\\\hline
166 \fx{reservenopath} & \hx{false} & The \quoted{path} (or roots or bases) of a key is the combination of key prefix, key family and macro prefix. These can be reserved and unreserved by any user by the tools of \sref{sec:reservedpath}. Subsequent users can, at their own risk, override all previously reserved paths by enabling the package's boolean option \fx{reservenopath}.\\\hline
167 \fx{allowemptypath} & \hx{false} & Allow the use of empty key prefix and family. This isn't advisable but some pre-existing packages might have used empty key prefixes and families. \useltablenote[tab:pkgoptions:note4]{ltxkeys-4}\\\hline
168 \fx{endcallbackline} & \hx{false} & At key-definition time, while in the callback of a key, implicitly make \hx{\endlinechar} equal to $-1$ (\ie, automatically insert comment sign at each end of line). If enabled, this option applies to all key-definition commands. The snag with this is that, when enabled, the user has to remember to manually provide explicit spaces that he/she might require at end of lines.
169 \end{tabularx}
170 \endgroup
171 %\endtrace
172
173
174 \docsection{Defining keys}
175
176 \docsubsection(sec:definablekeys){Defining only definable keys}
177
178 If the package option \fx{tracingkeys} is enabled (\ie, turned true), the user can see in the transcript file the existing keys that he has redefined with the \textltxkey variants of the key-defining commands, which redefine existing keys without any default warning or error. The log file messages being referred to here will be highlighted with the warning sign (\makered{!!}). This is always desirable in the preproduction stages of your project. However, instead of looking for these warning messages in the log file, the user can use the \textnewkey variants of the key-defining commands to bar himself from redefining existing keys.
179
180 Subsequently we will mention the \textnewkey variants of key-defining commands without necessarily explaining what they mean, since their meaning is henceforth clear.
181
182 In the following, syntactic quantities in square brackets (\eg, \fx{[yyy]}) and those in parenthesis (\eg, \fx{(yyy)}) are optional arguments.
183
184
185 \docsubsection(sec:ordkeys)<ordinary keys (ord)>{Ordinary keys}
186 \aidx*{key prefix,macro prefix,key macro}
187
188 \start+{newmacro}[\ltxkeysordkey,\ltxkeysnewordkey]
189 \ltxkeysordkey[|A(pref)]{|A(fam)}{|A(key)}[|A(dft)]{|A(cbk)}
190 \ltxkeysnewordkey[|A(pref)]{|A(fam)}{|A(key)}[|A(dft)]{|A(cbk)}
191 \finish{newmacro}
192 \fxim*{\ltxkeysordkey,\ltxkeysnewordkey}
193
194 These define a macro of the form \preffamkey of one parameter that holds the key function/callback \ang{cbk}. The default value for the \quoted{key prefix} \ang{pref} is always \fx{KV}, as in the \pkg'{xkeyval}. When \ang{key} is used in a \fx{\ltxkeyssetkeys} command (see \sref{sec:settingkeys}) containing \keyval, the macro \preffamkey takes the value as its argument and is then executed. The given argument or key value can be accessed in the key's callback \ang{cbk} by using \fx{#1} inside the function. The optional default value \ang{dft}, if available, will be used by \preffamkey when the user hasn't provided a value for the key at \fx{\ltxkeyssetkeys}. If \ang{dft} was absent at key definition and the key user hasn't provided a value for the key, an error message is flagged\footnote{The commands \ffx'{\ltxkeys@key, \ltxkeys@newkey} aren't user commands.}.
195
196 Run the following example and do \fx{\show\cmdb} and \fx{\show\cmdd}:
197
198 \start{example}[\ltxkeysordkey]
199 \ltxkeysordkey[KV]{fam}{keya}[\def\cmda#1{aa#1}]{\def\cmdb##1{#1bb##1}}
200 \ltxkeysordkey[KV]{fam}{keyb}[\def\cmdc##1{cc##1}]{\def\cmdd##1{#1dd##1}}
201 \ltxkeyssetkeys[KV]{fam}{keya,keyb}
202 \finish{example}
203
204 \docsubsubsection(sec:ordkeys-sameattributes)
205 {Ordinary keys that share the same attributes}
206
207 The commands \ffx'{\ltxkeysordkey,\ltxkeysnewordkey} can be used to introduce ordinary keys \ang{keys} that share the same path\footnote{The key path is also called the key bases.} (key prefix, key family, and macro prefix) and callback \ang{cbk}. All that is needed is to replace \ang{key} in these commands with the comma-separated list \ang{keys}. Because some users might prefer to see these commands in their plural forms when defining several keys with the same callback, we have provided the following aliases. The internal coding remains the same and no efficiency has been lost in generalization.
208
209 \start+{newmacro}[\ltxkeysordkeys,\ltxkeysnewordkeys]
210 \ltxkeysordkeys[|A(pref)]{|A(fam)}{|A(keys)}[|A(dft)]{|A(cbk)}
211 \ltxkeysnewordkeys[|A(pref)]{|A(fam)}{|A(keys)}[|A(dft)]{|A(cbk)}
212 \finish{newmacro}
213 \fxim*{\ltxkeysordkeys,\ltxkeysnewordkeys}
214
215
216 \docsubsection(sec:lispkeys)<lispkeys>{List processor keys (lispkeys)}
217
218 \start+{newmacro}[\ltxkeyslispkey,\ltxkeysnewlispkey, etc.]
219 \ltxkeyslispkey[|A(pref)]{|A(fam)}{|A(key)}[|A(dft)]{|A(cbk)}
220 \ltxkeysnewlispkey[|A(pref)]{|A(fam)}{|A(key)}[|A(dft)]{|A(cbk)}
221 \ltxkeyslispkeys[|A(pref)]{|A(fam)}{|A(keys)}[|A(dft)]{|A(cbk)}
222 \ltxkeysnewlispkeys[|A(pref)]{|A(fam)}{|A(keys)}[|A(dft)]{|A(cbk)}
223 \finish{newmacro}
224 \fxim*{\ltxkeyslispkey,\ltxkeysnewlispkey,\ltxkeyslispkeys,\ltxkeysnewlispkeys}
225
226 List processor keys (or lisp keys) are ordinary keys that accept a parser-separated list as a user input and process each element of the list. The key's callback \ang{cbk} is then a list processor, but the key author doesn't have to design and suggest his own looping system. All he has to do is to pass the parameter \fx{#1}, representing the individual items of the list, to the key's callback. The key will internally do the loop and process the list (\ie, the user input).
227
228 \Note In the lisp key's callback, the parameter character \fx{#1} represents not the entire user input (which is assumed to be a list) but the individual items of the list. Each item of the list will be processed by the key's callback.
229
230 A lisp key does accept any arbitrary list separator. When the list separator differs from \qcomma, it has to be provided in the key's callback as the argument of the undefined command \fx{\listsep}. And at key-setting time, user inputs that are comma-separated should be enclosed in curly braces, otherwise they won't be parsed properly and errors will arise. An example follows. When setting the key, the user must then use the same list separator. \fx{\ltxkeyslispcount} gives the numerical order of each item in the list. The default value and user input of a lisp key should take cognizance of the list separator. Both the default value and the user input of a lisp key can be just one item, rather than a list; in which case the current input is assumed to have just one item. Spurious leading and trailing spaces (\ie, unprotected spaces) in the list are trimmed before the list is parsed by the key's callback. Reminder: \fx{#1} in the key's callback refers to the individual item of the list, and not the entire list itself.
231
232 It is possible to call the command \fx{\ltxkeysbreakloop} in the key's callback \ang{cbk} to break out of the list processing prematurely. The unprocessed items will be handled by the command \fx{\ltxkeysdoremainder}, which can be redefined by the user. By default, it has the same meaning as the \latex kernel's \hx{\@gobble}, meaning that it simply throws away the list remainder.
233
234 \start+{example}[\ltxkeyslispkey]
235 \ltxkeyslispkey[KV]{fam}{keya}[aaa, bbb]{%
236 |com(`#1' here refers to the current item of the list:)
237 \ltscsdef{ww@\romannumeral\ltxkeyslispcount}{#1}%
238 }
239 |com(User inputs that are comma-separated should be wrapped in braces:)
240 \ltxkeyssetkeys[KV]{fam}{keya={val1, val2, val3}}
241
242 \ltxkeyslispkey[KV]{fam}{keyb}[aaa; bbb]{%
243 |R(\listsep){;}%
244 \ifnum\ltxkeyslispcount>2\relax
245 \ltxkeysbreakloop
246 \else
247 \ltscsdef{ww@\romannumeral\ltxkeyslispcount}{#1}%
248 \fi
249 }
250 \ltxkeyssetkeys[KV]{fam}{keyb=val1; val2; val3; val4}
251 \ltxkeyssetkeys[KV]{fam}{keyb=val5}
252 \finish{example}
253
254 \start+{example}[\ltxkeyslispkey]
255 \ltxkeyslispkey[KV]{fam}{keya,keyb}[default1,default2]{%
256 \begingroup
257 \color{blue}
258 \ifltxkeysnoval
259 \ifnum\ltxkeyslispcount=\@ne
260 \endgraf
261 Using default value of `\ltxkeystkey':
262 \fi
263 \else
264 \ifnum\ltxkeyslispcount=\@ne
265 \endgraf
266 Using user value of `\ltxkeystkey':
267 \fi
268 \fi
269 \endgroup
270 \endgraf
271 Doing item no. \ltxkeyslispcount: #1%
272 }
273 %\show\KV@fam@keya
274 %\endtrace
275 \let\ltxsetkeys\ltxkeyssetkeys
276 \makeatother
277
278 \begin{document}
279 \parindent0pt
280 %\trace*
281 \ltxsetkeys[KV]{fam}{keya,keyb}
282 %\endtrace
283
284 \par\bigskip
285 \ltxsetkeys[KV]{fam}{%
286 keya={item1A,item1B,item1C,item1D},
287 keyb={item2A,item2B,item2C,item2D}
288 }
289 %\endtrace
290 \end{document}
291 \finish{example}
292
293
294 \docsubsection(sec:cmdkeys)<command keys (cmd)>{Command keys}
295
296 \start+{newmacro}[\ltxkeyscmdkey,\ltxkeysnewcmdkey]
297 \ltxkeyscmdkey[|A(pref)]{|A(fam)}[|A(mp)]{|A(key)}[|A(dft)]{|A(cbk)}
298 \ltxkeysnewcmdkey[|A(pref)]{|A(fam)}[|A(mp)]{|A(key)}[|A(dft)]{|A(cbk)}
299 \finish{newmacro}
300 \fxim*{\ltxkeyscmdkey,\ltxkeysnewcmdkey}
301
302 Here, the optional quantity \ang{mp} is the \quoted{macro prefix}. If \ang{mp} is given, the command \mpkey will hold the current user input at key setting time; otherwise (\ie, if \ang{mp} is absent) the user input will be available in the macro \ipreffamkey{cmd}. The command \preffamkey is the \quoted{key macro} and will hold the callback \ang{cbk}. This type of key is traditionally called \quoted{command key} (a name that most likely emanated from the \pkg'{xkeyval}) because it gives rise to the macro \mpkey, but in the \pkg'{ltxkeys} even boolean, style and choice keys are associated with this type of macro.
303
304
305 \docsubsubsection(sec:cmdkeys-sameattributes)
306 {Command keys that share the same attributes}
307
308 The commands \ffx'{\ltxkeyscmdkey,\ltxkeysnewcmdkey} can be used to introduce command keys \ang{keys} that share the same path or bases (key prefix, key family, and macro prefix) and callback \ang{cbk}. Simply replace \ang{key} in these commands with the comma-separated list \ang{keys}. Some users might prefer to see these commands in their plural forms when defining several keys with the same callback. We have therefore provided the following aliases:
309
310 \start+{newmacro}[\ltxkeyscmdkeys,\ltxkeysnewcmdkeys]
311 \ltxkeyscmdkeys[|A(pref)]{|A(fam)}[|A(mp)]{|A(keys)}[|A(dft)]{|A(cbk)}
312 \ltxkeysnewcmdkeys[|A(pref)]{|A(fam)}[|A(mp)]{|A(keys)}[|A(dft)]{|A(cbk)}
313 \finish{newmacro}
314 \fxim*{\ltxkeyscmdkeys,\ltxkeysnewcmdkeys}
315
316
317 \docsubsection(sec:stylekeys){Style keys}
318 \aidx*{style keys (sty)}
319
320 Style keys are keys with observers (\ie, keys that are processed when the subject/master key is set). They have the following syntaxes:
321
322 \start+{newmacro}[\ltxkeysstylekey,\ltxkeysnewstylekey]
323 \ltxkeysstylekey[|A(pref)]{|A(fam)}[|A(mp)]{|A(key)}[|A(dft)]|(|A(deps)|){|A(cbk)}
324 \ltxkeysstylekey|*[|A(pref)]{|A(fam)}[|A(mp)]{|A(key)}[|A(dft)]|(|A(deps)|){|A(cbk)}
325 \ltxkeysnewstylekey[|A(pref)]{|A(fam)}[|A(mp)]{|A(key)}[|A(dft)]|(|A(deps)|){|A(cbk)}
326 \ltxkeysnewstylekey|*[|A(pref)]{|A(fam)}[|A(mp)]{|A(key)}[|A(dft)]|(|A(deps)|){|A(cbk)}
327 \finish{newmacro}
328 \fxim*{\ltxkeysstylekey,\ltxkeysnewstylekey}
329
330 The observers \ang{deps} have the syntax:
331
332 \start'{macro}[Observer keys syntax]
333 |(
334 |A(key1)=|A(value1),...,|A(key1)=|A(value1)
335 |)
336 \finish{macro}
337 \aidxs*{observer keys}{style keys}
338
339 The default value \ang{dft} and the callback \ang{cbk} can be absent in the syntax of style keys. \ang{keytype} can be \quoted{ord} (ordinary key), \quoted{cmd} (command key), \quoted{bool} (boolean key), or \quoted{choice} (choice key).
340
341 Observer keys always share the same key prefix \ang{pref}, family \ang{fam}, and macro prefix \ang{mp} with the parent key.
342
343 If \ang{mp} is given, the command \mpkey will hold the current user input for the parent key; otherwise the user input will be available in \ipreffamkey{style}. The macro \preffamkey will always hold the callback \ang{cbk}.
344
345 If the \stform is used, all undefined observers will be defined and set on the fly as the parent is being set. If the \stform isn't used and undefined observers occur, then an error message will be flagged at the time the parent is being set.
346
347 Most of the time it is possible to access the parent key's current value with \fx{\parentval}. Within \ang{dft} and \ang{cbk} of \ang{deps}, it is possible to refer to the parent key's callback with its full macro name (\ie, \preffamkey). \fx{\parentval} is always available for use as the default value of observer keys, but it may be lost in the callbacks of observer keys, because a observer key, once defined, may be set independent of, and long after, the parent key has been executed. It is, therefore, more reliable to refer to the macro \jpreffamkey{value}, which is recorded for only the parent key of style keys and which holds the current user input for the parent key. The macro \jpreffamkey{value} is recorded only if it appears at least once in the attributes or callbacks of observer keys. The macro \jpreffamkey{value} has a more unique name than \mpkey but they always contain the same value of a style key. As mentioned above, if \ang{mp} is not given, the user input for a style key will be available in the macro \ipreffamkey{style}, instead of \mpkey.
348
349 \ltsnote
350 The parameter \quotedfx{#1} in the callback of parent key refers to the current value of the parent key, while \quotedfx{#1} in the callback of any observer key refers to the current value of that observer key. Here is an example that defines and sets all undefined observers on the fly:
351
352 \start+{example}[\ltxkeysstylekey]
353 \ltxkeysstylekey|*[KV]{fam}[mp@]{keya}[{left}]|(%
354 |com(`#1' here refers to the value of the PARENT key at the time)
355 |com(it is being set:)
356 keyb=valueb,keyc=#1,keyd=2*#1
357 |){%
358 |com(`#1' here refers to the value of the PARENT key at the time)
359 |com(it is being set:)
360 \def\x##1{##1xx#1xx}%
361 |com(Check the value of parent key:)
362 \ltxkeyscheckchoice+[,]|(\userinput\order|){#1}{left,right,center}{}{%
363 \@latex@error{Invalid input `#1'}\@ehd
364 }%
365 }
366 \finish{example}
367
368
369 In this example, \fx{\userinput} corresponds to \fx{#1}, and \fx{\order} is the numerical order of the user input in the nominations \fnz*{left,right,center}. More about the commands \ffx'{\ltxkeyscheckchoice, \ltxkeyscheckuserinput} can be found in \sref{sec:checkchoice}.
370
371 You can try setting \ttx{keya} as follows to see what happens to keys \ffx'{keyb,keyc,keyd}:
372
373 \start{example}[\ltxkeyssetkeys]
374 \ltxkeyssetkeys[KV]{fam}{keya=right}
375 \finish{example}
376
377 The following will flag an error because \fx{{right}} isn't in the list of nominations \fnz*{left,right,center}:
378
379 \start{example}[\ltxkeyssetkeys]
380 \ltxkeyssetkeys[KV]{fam}{keya={right}}
381 \finish{example}
382
383 The braces in the key values above are just to exemplify the fact that braces in key values are preserved throughout key parsing. As mentioned earlier, this is essential for some packages and class files.
384
385
386 \docsubsubsection(sec:stylekeys-sameattributes)
387 {Style keys that share the same attributes}
388
389 The commands \ffx'{\ltxkeysstylekey,\ltxkeysnewstylekey} can be used to introduce style keys \ang{keys} that share the same path or bases (key prefix, key family, and macro prefix) and callback \ang{cbk}. Just replace \ang{key} in these commands with the comma-separated list \ang{keys}. However, some users might prefer to see these commands in their plural forms when defining several keys with the same callback. Hence, we also provide the following aliases:
390
391 \start+{newmacro}[\ltxkeysstylekeys,\ltxkeysnewstylekeys]
392 \ltxkeysstylekeys[|A(pref)]{|A(fam)}[|A(mp)]{|A(keys)}[|A(dft)]|(|A(deps)|){|A(cbk)}
393 \ltxkeysstylekeys|*[|A(pref)]{|A(fam)}[|A(mp)]{|A(keys)}[|A(dft)]|(|A(deps)|){|A(cbk)}
394 \ltxkeysnewstylekeys[|A(pref)]{|A(fam)}[|A(mp)]{|A(keys)}[|A(dft)]|(|A(deps)|){|A(cbk)}
395 \ltxkeysnewstylekeys|*[|A(pref)]{|A(fam)}[|A(mp)]{|A(keys)}[|A(dft)]|(|A(deps)|){|A(cbk)}
396 \finish{newmacro}
397 \fxim*{\ltxkeysstylekeys,\ltxkeysnewstylekeys}
398
399
400 \docsubsection(sec:boolkeys)<boolean keys (bool)>{Boolean keys}
401
402 \start+{newmacro}[\ltxkeysboolkey,\ltxkeysnewboolkey]
403 \ltxkeysboolkey[|A(pref)]{|A(fam)}[|A(mp)]{|A(key)}[|A(dft)]{|A(cbk)}
404 \ltxkeysboolkey|+[|A(pref)]{|A(fam)}[|A(mp)]{|A(key)}[|A(dft)]{|A(cbk)}{|A(fn)}
405 \ltxkeysnewboolkey[|A(pref)]{|A(fam)}[|A(mp)]{|A(key)}[|A(dft)]{|A(cbk)}
406 \ltxkeysnewboolkey|+[|A(pref)]{|A(fam)}[|A(mp)]{|A(key)}[|A(dft)]{|A(cbk)}{|A(fn)}
407 \finish{newmacro}
408 \fxim*{\ltxkeysboolkey,\ltxkeysnewboolkey}
409
410 In these commands, if \ang{mp} is given, the command \mpkey will hold the current user input for the key at key setting time; otherwise the user input will be available in \ipreffamkey{bool}\footnote{This differs from the system in the \pkg'{xkeyval}.}. If \ang{mp} is specified, a boolean of the form \ifmpkey will be created at key definition, which will be set by \fx{\ltxkeyssetkeys} according to the user input. If \ang{mp} is not specified, a boolean of the form \ipreffamkey{ifbool} will instead be created.
411
412 The user input for boolean keys must be in the set \fnz*{true,false}. The callback \ang{cbk} is held in the command \preffamkey, which is executed if the user input is valid.
413
414 The \plform of \ffx'{\ltxkeysboolkey,\ltxkeysnewboolkey} will execute \ang{fn} in place of \ang{cbk} if the user input isn't in \fnz*{true,false}; the plain form will issue an error in this case.
415
416
417 \docsubsubsection(sec:boolkeys-sameattributes)
418 {Boolean keys that share the same attributes}
419
420 The commands \ffx'{\ltxkeysboolkey,\ltxkeysnewboolkey} can be used to introduce boolean keys \ang{keys} that share the same path or bases (key prefix, key family, and macro prefix) and callback \ang{cbk}. Just replace \ang{key} in these commands with the comma-separated list \ang{keys}. Because some users might prefer to see these commands in their plural forms when defining several keys with the same callback, we have provided the following aliases:
421
422 \start+{newmacro}[\ltxkeysboolkeys,\ltxkeysnewboolkeys]
423 \ltxkeysboolkeys[|A(pref)]{|A(fam)}[|A(mp)]{|A(keys)}[|A(dft)]{|A(cbk)}
424 \ltxkeysboolkeys|+[|A(pref)]{|A(fam)}[|A(mp)]{|A(keys)}[|A(dft)]{|A(cbk)}{|A(fn)}
425 \ltxkeysnewboolkeys[|A(pref)]{|A(fam)}[|A(mp)]{|A(keys)}[|A(dft)]{|A(cbk)}
426 \ltxkeysnewboolkeys|+[|A(pref)]{|A(fam)}[|A(mp)]{|A(keys)}[|A(dft)]{|A(cbk)}{|A(fn)}
427 \finish{newmacro}
428 \fxim*{\ltxkeysboolkeys,\ltxkeysnewboolkeys}
429
430
431 \docsubsubsection(sec:biboolkeys)<biboolean keys>{Biboolean keys}
432
433 \start+{newmacro}[\ltxkeysbiboolkeys,\ltxkeysnewbiboolkeys]
434 \ltxkeysbiboolkeys[|A(pref)]{|A(fam)}[|A(mp)]{|A(bl1),|A(bl2)}[|A(dft)]{|A(cbk1)}{|A(cbk2)}
435 \ltxkeysbiboolkeys|+[|A(pref)]{|A(fam)}[|A(mp)]{|A(bl1),|A(bl2)}[|A(dft)]{|A(cbk1)}{|A(cbk2)}{|A(fn)}
436 \ltxkeysnewbiboolkeys[|A(pref)]{|A(fam)}[|A(mp)]{|A(bl1),|A(bl2)}[|A(dft)]{|A(cbk1)}{|A(cbk2)}
437 \ltxkeysnewbiboolkeys|+
438 [|A(pref)]{|A(fam)}[|A(mp)]{|A(bl1),|A(bl2)}[|A(dft)]{|A(cbk1)}{|A(cbk2)}{|A(fn)}
439 \finish{newmacro}
440 \fxim*{\ltxkeysbiboolkeys,\ltxkeysnewbiboolkeys}
441
442 Biboolean keys always assume opposite states: when one is true, the other is automatically toggled to false; and vice versa. Think of the options \hx{draft} and \hx{final} in a document class, but note that traditional document classes don't currently use biboolean keys. The callback \ang{cbk1} belongs to the boolean key \ang{bl1}, while \ang{cbk2} is of \ang{bl2}.
443
444 The \plform of \fx{\ltxkeysbiboolkeys} will execute \ang{fn} in place of \ang{cbk1} or \ang{cbk2} if the input is not in \fnz*{true,false}; the plain form will issue an error in this case.
445
446 Biboolean keys have equal symmetry (\ie, they can call each other with equal propensity) and they won't bomb out in an infinite reentrance. They normally would know if and when they call each other, or if they're being called by some other keys.
447
448 \start+{example}[\ltxkeysbiboolkeys]
449 \ltxkeysbiboolkeys|+[KV]{fam}[mp@]{keya,keyb}[true]{%
450 \ifmp@keya\def\x##1{##1x#1x##1}\fi
451 }{%
452 \ifmp@keyb\def\y##1{##1y#1y##1}\fi
453 }{%
454 \@latex@error{Invalid value `#1' for key `\ltxkeyscurrentkey'}\@ehc
455 }
456 \finish{example}
457
458
459 \docsubsection(sec:switchkeys)<switch keys (type: switch)>{Switch keys}
460
461 Switch keys look like boolean keys and they expect the same value set as boolean keys, namely, \fnz*{true, false}, but they are cheaper. Internally the value set of a switch key is \fnz*{00,01}. So, while the user input for a switch key must lie in the set \fnz*{true, false}, the input is internally converted to \fnz*{00,01}. This allows the values of switch keys to be tested with \tex's \hx{\if}. While each new boolean results in the creation of three commands, every new switch requires only one command.
462
463 \start+{newmacro}[\ltxkeysswitchkey,\ltxkeysnewswitchkey]
464 \ltxkeysswitchkey[|A(pref)]{|A(fam)}[|A(mp)]{|A(key)}[|A(dft)]{|A(cbk)}
465 \ltxkeysswitchkey|+[|A(pref)]{|A(fam)}[|A(mp)]{|A(key)}[|A(dft)]{|A(cbk)}{|A(fn)}
466 \ltxkeysnewswitchkey[|A(pref)]{|A(fam)}[|A(mp)]{|A(key)}[|A(dft)]{|A(cbk)}
467 \ltxkeysnewswitchkey|+[|A(pref)]{|A(fam)}[|A(mp)]{|A(key)}[|A(dft)]{|A(cbk)}{|A(fn)}
468 \finish{newmacro}
469 \fxim*{\ltxkeysswitchkey,\ltxkeysnewswitchkey}
470
471 In these commands, if \ang{mp} is given, the command \mpkey will hold the current user input for the key at key setting time; otherwise the user input will be available in \ipreffamkey{switch}. If \ang{mp} is specified, a switch of the form \mpkey will be created at key definition, which will be set by \fx{\ltxkeyssetkeys} according to the user input. If \ang{mp} is not specified, a switch of the form \ipreffamkey{switch} will instead be created.
472
473 The callback \ang{cbk} is held in the command \preffamkey, which is executed if the user input is valid, ie, in the set \fnz*{true,false}.
474
475 The \plform of \ffx'{\ltxkeysswitchkey,\ltxkeysnewswitchkey} will execute \ang{fn} in place of \ang{cbk} if the user input isn't in \fnz*{true,false}; the plain form will issue an error in this case.
476
477 \start{example}
478 \ltxkeysswitchkey[KV]{fam}{keya}[true]{%
479 \if\switchKV@fam@keya
480 \def\x##1{##1*#1*##1}%
481 \fi
482 }
483 \ltxkeysswitchkey+[KV]{fam}[mp@]{keyb}[true]{%
484 \if\mp@keyb
485 \def\y##1{##1*#1*##1}%
486 \fi
487 }{
488 \@latex@error{Invalid value `#1' for key `keyb'}\@ehc
489 }
490 \ltxkeyssetkeys[KV]{fam}{keya=true,keyb=false}
491 \finish{example}
492
493
494 \docsubsubsection(sec:switchkeys-sameattributes)
495 {Switch keys that share the same attributes}
496
497 The commands \ffx'{\ltxkeysswitchkey,\ltxkeysnewswitchkey} can be used to introduce switch keys \ang{keys} that share the same meta (key prefix, key family, macro prefix, and callback \ang{cbk}). Just replace \ang{key} in these commands with the comma-separated list \ang{keys}. Because some users might prefer to see these commands in their plural forms when defining several keys with the same callback, we have provided the following aliases:
498
499 \start+{newmacro}[\ltxkeysswitchkeys,\ltxkeysnewswitchkeys]
500 \ltxkeysswitchkeys[|A(pref)]{|A(fam)}[|A(mp)]{|A(keys)}[|A(dft)]{|A(cbk)}
501 \ltxkeysswitchkeys|+[|A(pref)]{|A(fam)}[|A(mp)]{|A(keys)}[|A(dft)]{|A(cbk)}{|A(fn)}
502 \ltxkeysnewswitchkeys[|A(pref)]{|A(fam)}[|A(mp)]{|A(keys)}[|A(dft)]{|A(cbk)}
503 \ltxkeysnewswitchkeys|+[|A(pref)]{|A(fam)}[|A(mp)]{|A(keys)}[|A(dft)]{|A(cbk)}{|A(fn)}
504 \finish{newmacro}
505 \fxim*{\ltxkeysswitchkeys,\ltxkeysnewswitchkeys}
506
507 \start{example}
508 \ltxkeysswitchkeys+[KV]{fam}[mp@]{keya,keyb,keyc}[true]{%
509 \if\@nameuse{mp@\ltxkeyscurrentkey}%
510 \def\x##1{value of key `\ltxkeyscurrentkey' = #1 *** arg = ##1}%
511 \fi
512 }{
513 \@latex@error{Invalid value `#1' for key `\ltxkeyscurrentkey'}\@ehc
514 }
515 \ltxkeyssetkeys[KV]{fam}{keya=true,keyb=false,keyc=true}
516 \finish{example}
517
518
519 \docsubsection(sec:choicekeys)<choice keys (type: choice)>{Choice keys}
520
521 The choice keys of the \pkg'{ltxkeys} differ from those of the \pkg'{xkeyval} in at least two respects; namely, the presence of the macro prefix for choice keys in the \pkg'{ltxkeys} and the introduction of the optional \quoted{\redclam} prefix.
522
523 \start+{newmacro}[\ltxkeyschoicekey,\ltxkeysnewchoicekey]
524 \ltxkeyschoicekey[|A(pref)]{|A(fam)}[|A(mp)]{|A(key)}[|A(bin)]{|A(alt)}[|A(dft)]{|A(cbk)}
525 \ltxkeyschoicekey|*[|A(pref)]{|A(fam)}[|A(mp)]{|A(key)}[|A(bin)]{|A(alt)}[|A(dft)]{|A(cbk)}
526 \ltxkeyschoicekey|*|+[|A(pref)]{|A(fam)}[|A(mp)]{|A(key)}[|A(bin)]{|A(alt)}[|A(dft)]{|A(cbk)}{|A(fn)}
527 \ltxkeyschoicekey|*|+|![|A(pref)]{|A(fam)}[|A(mp)]{|A(key)}[|A(bin)]{|A(alt)}[|A(dft)]{|A(cbk)}{|A(fn)}
528
529 \ltxkeysnewchoicekey[|A(pref)]{|A(fam)}[|A(mp)]{|A(key)}[|A(bin)]{|A(alt)}[|A(dft)]{|A(cbk)}
530 \ltxkeysnewchoicekey|*[|A(pref)]{|A(fam)}[|A(mp)]{|A(key)}[|A(bin)]{|A(alt)}[|A(dft)]{|A(cbk)}
531 \ltxkeysnewchoicekey|*|+
532 [|A(pref)]{|A(fam)}[|A(mp)]{|A(key)}[|A(bin)]{|A(alt)}[|A(dft)]{|A(cbk)}{|A(fn)}
533 \ltxkeysnewchoicekey|*|+|!
534 [|A(pref)]{|A(fam)}[|A(mp)]{|A(key)}[|A(bin)]{|A(alt)}[|A(dft)]{|A(cbk)}{|A(fn)}
535 \finish{newmacro}
536 \fxim*{\ltxkeyschoicekey,\ltxkeysnewchoicekey}
537
538 Choice keys check the user input against the nominations \ang{alt} suggested by the author of a key. The comma-separated list \ang{alt} is the list of admissible values of the key. The \stform will convert user input to lowercase before checking it against the list of nominations in \ang{alt}. In all the above variants, if the input is valid, then the callback \ang{cbk} will be executed. If the user input isn't valid, the \unplform+ will flag an error, while the \plform+ will execute \ang{fn}. The \clform+ will fully expand the user input before checking it against the nominations in \ang{alt}. The \clform arises from the fact that sometimes macros are passed as the values of choice keys. If \ang{mp} is absent, then \fx{\ltxkeyschoicekey} uses \ipreffamkey{chc} to hold the user input.
539
540 When \ang{alt} has no literal form \quotedfx{/.do} or forward slash \quotedfx{/} in it, then it is expected to be of the familiar \pkg'{xkeyval} syntax:
541
542 \start'{macro}[Syntax of `nominations' for choice keys]
543 {choice1,choice2,etc.}
544 \finish{macro}
545
546 If \ang{alt} has \quotedfx{/.do} or \quotedfx{/} in it, then it is expected to have one of the following syntaxes:
547
548 \start'{macro}[Syntaxes of `nominations' for choice keys]
549 {%
550 choice1|R(/.do=)callback1|R(|A(keyparser))
551 choice2|R(/.do=)callback2|R(|A(keyparser))
552 etc.
553 }
554
555 |R(or)
556
557 {%
558 choice1|R(/)callback1|R(|A(keyparser))
559 choice2|R(/)callback2|R(|A(keyparser))
560 etc.
561 }
562 \finish{macro}
563 \aiidxm*[\emph,choice keys]{nominations}
564 \aidxm*{/.do}
565 \aidxs*{.do}{/.do}
566
567 If the parser is \qsemicolon, then we would have
568
569 \start'{example}[Syntaxes of `nominations' for choice keys]
570 {choice1|R(/.do=)callback1; choice2|R(/.do=)callback2; etc.}
571
572 |R(or)
573
574 {choice1|R(/)callback1; choice2|R(/)callback2; etc.}
575 \finish{example}
576
577 This means that if you have \quotedfx{/.do} or \quotedfx{/} in any of the callbacks, it has to be enclosed in curly braces! Please recall that the default value of \ang{keyparser} is \qsemicolon. \fx{keyparser} is a package option. This syntax also implies that if you have the \ang{keyparser} in \ang{defn}, it has to be wrapped in curly braces.
578
579 \ltsnote
580 The \ang{keyparser} in these syntaxes of \quoted{nominations} for choice keys could also be \qcomma, without the need to declare the package option \fx{keyparser} as \qcomma. Here is the rule for parsing the \ang{alt} list. First the package checks if the declared key parser (\ie, \ang{keyparser}) is in the \ang{alt} list. If the parser exists in \ang{alt}, then the list is parsed using this parser. Otherwise the list is parsed using \qcomma as the parser. Moreover, the package checks if \quotedfx{.do} separates \ang{choice} from the callback \ang{cbk}. If no \quotedfx{.do} is found, then \quotedfx{/} is assumed to be the separator. But note that when there is no \ang{cbk} for a nomination, then neither \quotedfx{.do} nor \quotedfx{/} is necessary.
581
582 It is possible to refer to the current value of \ang{key} as \fx{#1} in \ang{alt}.
583
584 The \stform of \fx{\ltxkeyschoicekey} will convert the user input to lowercase before checking \ang{alt} and executing the callbacks. The \plform will execute \ang{fn} in place of \ang{cbk} if the user input isn't in \ang{alt}.
585
586 \ang{bin} has, \eg, the syntax \fx{[\userinput\order]}, where \fx{\userinput} will hold the user input (in lowercase if the \stform of \fx{\ltxkeyschoicekey} is called), and \fx{\order} will hold the serial number of the value in the list of nominations \ang{alt}, starting from 0. If the input isn't valid, \fx{\userinput} will still hold the user input, but \fx{\order} will be~$-1$.
587
588 \start+{example}[\ltxkeyschoicekey nominations]
589 \ltxkeyschoicekey[KV]{fam}{keya}{%
590 |com(There are no callbacks for these simple nominations:)
591 center,right,left,justified
592 }[center]{|com( <- default value)
593 \def\x##1##2{==##1++#1++##2==}%
594 }
595
596 \ltxkeyschoicekey|*|+[KV]{fam}[mp@]{keya}[\userinput\order]{%
597 center,right,left,justified
598 }[center]{%
599 \def\x##1##2{==##1++#1++##2==}%
600 }{%
601 \@latex@error{Inadmissible value `\detokenize{#1}' for keya}\@ehc
602 }
603
604 \ltxkeyschoicekey|*|+[KV]{fam}[mp@]{keyb}[\userinput\order]{%
605 |com(There are callbacks for these nominations:)
606 land/.do=\def\x##1{*##1*#1*##1};
607 air/.do=\edef\z{\expandcsonce\ltxkeyscurrentvalue};
608 sea/.do=\edef\myinput{\ltstrimspaces{#1}};
609 space/.do=\letcsntocs{#1@earth}\relax
610 }[center]{%
611 \def\z##1##2{==##1++#1++##2==}%
612 }{%
613 \@latex@error{Inadmissible value `\detokenize{#1}' for keya}\@ehc
614 }
615
616 \ltxkeyschoicekey[KV]{fam}[mp@]{keyb}[\userinput\order]{%
617 |com(The callbacks can also take the following form:)
618 center/\ltxkeyscmdkey[KV]{fam}[mp@]{keyd}{\def\x####1{####1*##1*####1}},
619 right/\let\align\flushright,
620 left/\let\align\flushleft\edef\userinput{\ltstrimspaces{#1}},
621 justified/\let\align\relax
622 }[center]{%
623 \def\z##1##2{==##1++#1++##2==}%
624 }
625
626 \ltxkeyschoicekeys[KV]{fam}[mp@]{keya,|R(\savevalue\needvalue){keyb}}%
627 [\val\order]{%
628 center/\ltxkeyscmdkey[KV]{fam}[mp@]{keyd}[|R(\usevalue){keyb}]
629 {\def\x####1{####1*##1*####1}},
630 right/\def\y##1{##1++#1++##1},
631 left/\edef\userinput{\ltstrimspaces{#1}},
632 justified/\letcsntocs{#1@align}\relax
633 }[center]{%
634 \def\z##1##2{==##1++#1++##2==}%
635 }
636 \ltxkeyssetkeys[KV]{fam}{keyb=center,keyd}
637 \finish{example}
638
639 The representations \ffx{\savevalue,\usevalue,\needvalue}, \etc are pointers (see \sref{sec:keypointers}).
640
641
642 \docsubsubsection(sec:choicekeys-sameattributes)
643 {Choice keys that share the same attributes}
644
645 The commands \ffx'{\ltxkeyschoicekey,\ltxkeysnewchoicekey} can be used to introduce choice keys \ang{keys} that share the same path or bases (key prefix, key family, and macro prefix) and callback \ang{cbk}. All the user has to do is to replace \ang{key} in these commands with the comma-separated list \ang{keys}. Some users might prefer to see these commands in their plural forms when defining several keys with the same attributes. We have therefore provided the following aliases without modifying the internal coding:
646
647 \start+{newmacro}[\ltxkeyschoicekeys,\ltxkeysnewchoicekeys]
648 \ltxkeyschoicekeys[|A(pref)]{|A(fam)}[|A(mp)]{|A(keys)}[|A(bin)]{|A(alt)}[|A(dft)]{|A(cbk)}
649 \ltxkeyschoicekeys|*[|A(pref)]{|A(fam)}[|A(mp)]{|A(keys)}[|A(bin)]{|A(alt)}[|A(dft)]{|A(cbk)}
650 \ltxkeyschoicekeys|*|+
651 [|A(pref)]{|A(fam)}[|A(mp)]{|A(keys)}[|A(bin)]{|A(alt)}[|A(dft)]{|A(cbk)}{|A(fn)}
652 \ltxkeyschoicekeys|*|+|!
653 [|A(pref)]{|A(fam)}[|A(mp)]{|A(keys)}[|A(bin)]{|A(alt)}[|A(dft)]{|A(cbk)}{|A(fn)}
654 \ltxkeysnewchoicekeys[|A(pref)]{|A(fam)}[|A(mp)]{|A(keys)}[|A(bin)]{|A(alt)}[|A(dft)]{|A(cbk)}
655 \ltxkeysnewchoicekeys|*[|A(pref)]{|A(fam)}[|A(mp)]{|A(keys)}[|A(bin)]{|A(alt)}[|A(dft)]{|A(cbk)}
656 \ltxkeysnewchoicekeys|*|+
657 [|A(pref)]{|A(fam)}[|A(mp)]{|A(keys)}[|A(bin)]{|A(alt)}[|A(dft)]{|A(cbk)}{|A(fn)}
658 \ltxkeysnewchoicekeys|*|+|!
659 [|A(pref)]{|A(fam)}[|A(mp)]{|A(keys)}[|A(bin)]{|A(alt)}[|A(dft)]{|A(cbk)}{|A(fn)}
660 \finish{newmacro}
661 \fxim*{\ltxkeyschoicekeys,\ltxkeysnewchoicekeys}
662
663
664 \docsection{Default values of keys}
665 The code after \fx{.do=} will be executed whenever the default value of the key is used.
666
667 % \ltxkeysordkey[KV]{fam}{keya}[\def\y#1{#1}.do=\def\x#1{#1}]{%
668 % \def\cmda##1{##1*#1*##1}
669 % }
670
671 \docsection(sec:everykeydefault){Every default value of a key}
672
673 The command \fx{\ltxkeyseverykeydefault} can be used to take some action (such as writing to the log file the default values assigned to keys without values) at key-setting time. The command will be invoked only if it has been initialized by the user and if the current key has no user value. It is initialized by the following syntax:
674
675 \start+{newmacro}[\ltxkeyseverykeydefault]
676 \ltxkeyseverykeydefault[|A(prefs)]{|A(fams)}{#1#2#3#4}
677 \finish{newmacro}
678 \fxim*{\ltxkeyseverykeydefault}
679
680 Here, \ang{prefs} and \ang{fams} are the key prefixes and families that will have the defined key-default handler. \ang{prefs} is optional; it has the default value of \fx{KV}. The parameters \fx{#1,#2,#3,#4} can be used by the caller to access the current key prefix, key family, key name, and key value, respectively.
681
682 The following example defines key-default handler for two key prefixes and two families.
683
684 \start{example}[\ltxkeyseverykeydefault]
685 \ltxkeyseverykeydefault[KV1,KV2]{fam1,fam2}{%
686 \wlog{Prefix: #1/ Family: #2/ Key name: #3/ Default value: \unexpanded{#4}}%
687 }
688 \finish{example}
689
690
691 \docsubsection(sec:declarekeys){Defining all types of key with one command}
692 \aidx*{defining multiple keys}
693
694 \start{newmacro}[\ltxkeysdeclarekeys]
695 \ltxkeysdeclarekeys[|A(pref)]{|A(fam)}[|A(mp)]{%|label(mac:declarekeys)
696 |A(keytype)/|A(keyname)/|A(dft)/|A(cbk);
697 another set of key attributes;
698 etc.
699 }
700 \ltxkeysdeclarekeys|*[|A(pref)]{|A(fam)}[|A(mp)]{%
701 |A(keytype)/|A(keyname)/|A(dft)/|A(cbk);
702 another set of key attributes;
703 etc.
704 }
705 \finish{newmacro}
706 \fxim*{\ltxkeysdeclarekeys}
707 \aidx*{style keys (sty*)}
708
709 Here, the default value \ang{dft} and the callback \ang{cbk} can be absent in all cases. \ang{keytype} must be any one of \fnz{ord,cmd,sty,sty*,bool,choice,switch}. The star (\redstar) in \quoted{sty\Redstar} has the same meaning as in \fx{\ltxkeysstylekey} above, namely, undefined observers will be defined on the fly when the parent key is set. The optional quantity \ang{mp} is the macro prefix, as in, \eg, \sref{sec:cmdkeys,sec:definekeys}.
710
711 Choice keys must have their names associated with their admissible \ang{alt} values in the format \keydotchoice{keyname}{alt} (see example below).
712
713 The \stform of \fx{\ltxkeysdeclarekeys} can be used to define new keys (in the sense of \hx{\newcommand}).
714
715 \ltsnote
716 Keys defined by \fx{\ltxkeysdeclarekeys} are automatically set instantly with their default values, to provide default functions for immediate use. Boolean keys are always initialized in this sense with \quoted{false}, so that they aren't turned \quoted{true} prematurely. See \sref{nte:definekeys-1} for a potential snag and its solution when keys are automatically preset as done by the command \fx{\ltxkeysdeclarekeys}.
717
718 \start+{example}[\ltxkeysdeclarekeys]
719 \ltxkeysdeclarekeys|*[KV]{fam}[mp@]{%
720 |com(Ordinary key with callback:)
721 ord/keya/.1\paperwidth/\leftmargin=#1\relax;
722 |com(Command key with callback. `.do=' is allowed before callback:)
723 cmd/keyb/10mm/.do=\rightmargin=#1\def\x##1{##1*#1*##1};
724 |com(Boolean key without callback:)
725 bool/keyc/true;
726 |com(Boolean key with callback:)
727 bool/keyd/true/\ifmp@keyd\@tempswatrue\else\@tempswafalse\fi;
728 |com(Style key with callback but no observers:)
729 style/keye/aaa/\def\y##1{##1yyy#1};
730 |com(Style key with callback and observers `keyg' and `keyh':)
731 style/keyf|R(.){
732 keyg=valueg,keyh=valueh
733 }
734 /blue/\def\y##1{##1#1};
735 |com(Choice key with simple nominations and callback. The function)
736 |com(\order is generated internally:)
737 choice/keyi|R(.){left,right,center}/center/
738 \edef\shoot{\ifcase\order 0\or 1\or 2\fi};
739 |com(Choice key with complex nominations:)
740 choice/keyj|R(.){
741 center/.do=\def\mp@textalign{center},
742 left/.do=\def\mp@textalign{flushleft},
743 right/.do=\def\mp@textalign{flushright},
744 justified/.do=\let\mp@textalign\relax
745 }
746 /center/\def\yy##1{##1yy#1};
747 ord/keyk/\letcstocsn\func{as-defined-by-user};
748 switch/keyl/true/\if\mp@keyl\def\y##1{##1+#1+##1}\fi;
749 |com(#1 here means the value of the subject key:)
750 style/key1|R(.){
751 key1a=value1a,key1b=#1
752 }
753 /dft1/\def\y##1{##1*#1};
754 }
755 \finish{example}
756 \aidx*{style keys}
757 \aidx*{/.do}
758
759 Notice the syntax \keydotchoice{keyi}{left,right,center} for the choice keys \ttx{keyi,keyj}. It says that the alternate admissible values for \quoted{keyi} are \quotedlist'{left,right, center, justified}; similarly for key \quoted{keyj}. For style keys, \keydotchoice{keyf}{keyg=valueg, keyh=valueh} means that \ttx{keyg,keyh} are observer keys of the subject \ttx{keyf}.
760
761
762 \docsubsubsection(sec:sametypekeys)[Defining keys of common type]
763 {Defining keys of common type with \headfx{\ltxkeysdeclarekeys}}
764
765 If you have to define keys of the same type with the command \fx{\ltxkeysdeclarekeys}, then the following syntax allows you to avoid entering the key types repeatedly:
766
767 \start{macro}[\ltxkeysdeclarekeys]
768 \ltxkeysdeclarekeys|(|A(keytype)|)[|A(pref)]{|A(fam)}[|A(mp)]{%
769 |A(keyname)/|A(dft)/|A(cbk);
770 another set of key; etc.
771 }
772 \ltxkeysdeclarekeys|*|(|A(keytype)|)[|A(pref)]{|A(fam)}[|A(mp)]{%
773 |A(keyname)/|A(dft)/|A(cbk);
774 another set of key; etc.
775 }
776 \finish{macro}
777 \fxi*{\ltxkeysdeclarekeys}
778
779 \start+{example}[\ltxkeysdeclarekeys]
780 \ltxkeysdeclarekeys|(bool|)[KV]{fam}[mp@]{%
781 keya/true/\def\x##1{##1*#1*##1};
782 keyb/true;
783 keyc/true/\def\y##1{##1yyy#1}
784 }
785 \ltxkeysdeclarekeys|*|(sty|*|)[KV]{fam}[mp@]{%
786 keyd/xxx/\def\y##1{##1yyy#1};
787 |com(keyf is a observer of keye:)
788 keye/blue/\def\y##1{##1#1}/cmd>keyf>\parentval>\def\z####1{####1+##1+####1}
789 }
790 \finish{example}
791
792
793 \docsubsection(sec:definekeys){Defining keys with one command}
794 \aidx*{defining multiple keys}
795
796 In my personal experience, boolean and command keys have been the most widely used types of key in the context of \pkg'{xkeyval}. More than one boolean and command keys can be defined simultaneously by the following command:
797
798 \start{newmacro}[\ltxkeysdefinekeys]
799 \ltxkeysdefinekeys[|A(pref)]{|A(fam)}[|A(mp)]{%
800 |A(key)|R(=)|A(dft)/|A(cbk);
801 another set of key attributes; etc.
802 }
803 \ltxkeysdefinekeys|*[|A(pref)]{|A(fam)}[|A(mp)]{%
804 |A(key)|R(=)|A(dft)/|A(cbk);
805 another set of key attributes; etc.
806 }
807 \finish{newmacro}
808 \fxim*{\ltxkeysdefinekeys}
809
810 The default value \ang{dft} can be absent in the case of command keys, and the callback \ang{cbk} can be absent for the two types of key. Boolean keys must, however, have default values \fnz*{true,false}, to be distinguishable from command keys. The \eqsign that separates the key name from the default value can be replaced with forward slash (/). That is, the following syntax is also permitted:
811
812 \start{newmacro}[\ltxkeysdefinekeys]
813 \ltxkeysdefinekeys[|A(pref)]{|A(fam)}[|A(mp)]{%
814 |A(key)|R(/)|A(dft)/|A(cbk);
815 another set of key attributes; etc.
816 }
817 \ltxkeysdefinekeys|*[|A(pref)]{|A(fam)}[|A(mp)]{%
818 |A(key)|R(/)|A(dft)/|A(cbk);
819 another set of key attributes; etc.
820 }
821 \finish{newmacro}
822 \fxim*{\ltxkeysdefinekeys}
823
824 You can use the command \fx{\ltxkeyscheckuserinput} in \ang{cbk} to indirectly introduce choice keys as command keys (see example below).
825
826 Ordinary keys and conventional choice keys can't be introduced directly by this command (use the command \fx{\ltxkeysdeclarekeys} instead).
827
828 The \stform of \fx{\ltxkeysdefinekeys} can be used to define non-existing boolean and command keys in the sense of \hx{\newcommand}.
829
830 \begin{noteenv}*
831 \label{nte:definekeys-1}
832 Keys defined by \fx{\ltxkeysdefinekeys} are automatically set/initialized instantly, to provide default values for immediate use. Boolean keys are preset with value \quoted{false}, so that they aren't turned \quoted{true} prematurely. There is a potential problem with this manner of presetting keys. Consider the following example, in which \ttx{keya} builds a list:
833
834 \start{example}[\ltxkeysdefinekeys]
835 \def\alist{}
836 \ltxkeysdefinekeys[pref]{fam}[mp]{%
837 keya/defaulta/\edef\alist{\ifx\alist\@empty\else\alist,\fi#1};
838 keyb/defaultb/\def\callback##1{##1*#1}%
839 }
840 \finish{example}
841
842 If, as is done by the command \fx{\ltxkeysdefinekeys}, \ttx{keya} is automatically preset at definition, the building of the list \fx{\alist} would then have started, which is most likely not what the user of the key requires. The \pkg'{ltxkeys} therefore provides an internal boolean \fx{\ifltxkeysdec} that is set true within the commands \ffx'{\ltxkeysdefinekeys, \ltxkeysdeclarekeys} and toggled false outside these commands. The boolean has other uses within these commands. It can be used as follows:
843
844 \start{example}[\ltxkeysdefinekeys]
845 \def\alist{}
846 \ltxkeysdefinekeys[pref]{fam}[mp]{%
847 keya/defaulta/
848 \ifltxkeysdec\else
849 |com(Don't execute this when defining the key:)
850 \edef\alist{\ifx\alist\@empty\else\alist,\fi#1}%
851 \fi;
852 keyb/defaultb/\def\callback##1{##1*#1}%
853 }
854 \finish{example}
855
856 So here the building of the list by \ttx{keya} wouldn't start until the key has been defined (\ie, outside \fx{\ltxkeysdefinekeys}).
857 \end{noteenv}
858
859 \ltsnote
860 In \ffx'{\ltxkeysdefinekeys, \ltxkeysdeclarekeys}, if \fx{endcallbackline} is true, every line is assumed to end with a comment sign. This is to be specially noted if a space is desired at the end of line. You can insert such a space with a comment sign, or, if appropriate, use \hx{\space}.
861
862 \start+{example}[\ltxkeysdefinekeys]
863 |com(The |stform defines new keys:)
864 \ltxkeysdefinekeys|*[KV]{fam}[mp@]{%
865 |com(Command key with callback:)
866 keya={keepbraced}/\def\x##1{##1*#1*##1};
867 |com(Boolean key:)
868 keyb=true/\def\y##1{##1yyy#1};
869 |com(Command key with no callback:)
870 keyc=xxx;
871 |com(Choice-like command key:)
872 keyd=center/\ltxkeyscheckuserinput{#1}{left,right,center}
873 \ifltxkeysinputvalid |label(mac:ifltxkeysinputvalid)
874 \edef\myval{\expandcsonce\userinput}
875 \edef\numberinlist{\number\order}
876 \edef\mychoices{\expandcsonce\nominations}
877 \else
878 \@latex@error{Input `#1' not valid}\@ehd
879 \fi;
880 |com(Boolean key with no callback:)
881 keye=false;
882 }
883 \finish{example}
884 \fxim*{\ifltxkeysinputvalid,\ltxkeyscheckuserinput,\nominations,\userinput}
885 \aiidxm*[\bs,choice keys]{nominations,ifltxkeysinputvalid}
886
887 In this example, \fx{\userinput} corresponds to \fx{#1}; \fx{\order} is the numerical order of the user input in \fx{\nominations}; the list of valid values suggested at key definition time (\fnz*{left,right,center} in this example). The boolean \fx{ltxkeysinputvalid} is associated with the command \fx{\ltxkeyscheckuserinput} and is available to the user. It is set \hx{true} when the user input is valid, and \hx{false} otherwise. The command \fx{\ltxkeyscheckuserinput} expects two arguments: the user input and the list of nominations. It doesn't expect two branches (see \sref{sec:checkchoice}).
888
889
890 \docsubsection(sec:needvalue)<need-value keys>{Need-value keys}
891
892 Sometimes you may want to create keys for which the user must always supply his/her own values, even if the keys originally have default values. The default values of keys may not always be suitable. Take, for example, the height and width of a graphics image. For functions that are meant to handle generic images, it would certainly be inappropriate to relieve the user of the need to call picture height and width without corresponding values.
893
894 To make a key a need-value key, simply attach the pointer \fx{\needvalue} to the key at definition time. This pointer can be used only when defining keys, and not when setting keys.
895
896 \start'{example}[Need-value keys]
897 \ltxkeyscmdkey[KV]{fam}[mp@]{\needvalue{keya}}[blue]{%
898 \def\x##1{##1x#1x##1}%
899 }
900 \ltxkeyssetkeys[KV]{fam}{keya}
901 |com( -> Error: the author of `keya' designed it to require a user value.)
902 \finish{example}
903
904 See more about key pointers in \sref{sec:keypointers}.
905
906
907 \docsubsection(sec:xfamilykeys)<xfamily keys>{Cross-family keys}
908 \aidxs*{cross-family keys}{xfamily keys}
909
910 There are times when it is required to use the same, or nearly the same, set of keys for different functions and purposes, and thus for different key families and prefixes. We call such keys \quoted{cross-family keys} or \quoted{xfamily keys}. Such keys bear the same names across key families and key prefixes. For example, the \pkg'{xwatermark} defines three functions (\ffx'{\xwmminipage,\xwmboxedminipage,\xwmcolorbox}) using nearly the same set of keys. In each of the three families, the keys bear the same or similar names and they have similar callbacks. The management of cross-family keys can be simplified by using the tools of this section. Even if not all the cross-family keys are needed in all the families to which they may belong, there are still advantages in using this type of keys when some of the keys cut across families.
911
912 Cross-family keys are automatically initialized after being defined---as we saw in the case of the commands \ffx'{\ltxkeysdefinekeys,\ltxkeysdeclarekeys}.
913
914 \start+{newmacro}[\ltxkeyssavexfamilykeys,\ltxkeysdefinexfamilykeys]
915 \ltxkeyssavexfamilykeys<|A(id)>{|A(keylist)}
916 \ltxkeyssavexfamilykeys|*<|A(id)>|A(keylistcmd)
917
918 \ltxkeyssavexfamilykeys<|A(id)>|(|A(keytype)|){|A(keylist)}
919 \ltxkeyssavexfamilykeys|*<|A(id)>|(|A(keytype)|)|A(keylistcmd)
920
921 \ltxkeysdefinexfamilykeys<|A(id)>[|A(pref)]{|A(fam)}[|A(mp)]{|A(na)}
922 \ltxkeysdefinexfamilykeys|*<|A(id)>[|A(pref)]{|A(fam)}[|A(mp)]{|A(na)}
923 \finish{newmacro}
924 \fxim*{\ltxkeyssavexfamilykeys,\ltxkeysdefinexfamilykeys}
925
926 Here, \ang{id} is the mandatory identifier of the key list \ang{keylist}, \ang{pref} is the key prefix, \ang{fam} the key family, \ang{mp} is the macro prefix, and \ang{na} is the list of keys belonging to \ang{keylist} that shouldn't be presently defined and initialized. The \ang{na} can be empty, but it must always be there as a mandatory argument. \emph{So, where you put the key list in the commands \emfx{\ltxkeysdefinekeys} and \emfx{\ltxkeysdeclarekeys} is where you now have to locate \ang{na}}. For any use of the command \fx{\ltxkeysdefinexfamilykeys} we expect the \ang{na} to be far less than the remaining keys. The \stform of \fx{\ltxkeyssavexfamilykeys} will expand \ang{keylistcmd} once before saving the xfamily keys. The \stform of \fx{\ltxkeysdefinexfamilykeys} will define only definable keys, in the sense of \hx{\newcommand}.
927
928 \ang{keylist} and \ang{keylistcmd} have the same syntax as the last arguments of \ffx'{\ltxkeysdefinekeys,\ltxkeysdeclarekeys}:
929
930 \start'{newmacro}[Syntax of keylist]
931 |A(keytype)/|A(keyname)/|A(dft)/|A(cbk);
932 another set of key attributes;
933 etc.
934 \finish{newmacro}
935
936 Here too \ang{keytype} must be a member of the set \fnz{ord,cmd,sty,sty*,bool,choice}, \ang{keyname} is obviously the name of the key, \ang{dft} is the default value of the key, and \ang{cbk} is the callback of the key. If the key is a style key, you can add the attributes of the observers after \ang{cbk} (see the syntaxes of the commands \ffx'{\ltxkeysdefinekeys, \ltxkeysdeclarekeys}).
937
938 The mandatory identifier \ang{id} for each list must be unique, not withstanding the fact that the identifiers have their separate namespace.
939
940 If the xfamily keys are all of the same type (\ie, only one of the types \fnz{ord,cmd,sty,sty*,bool,choice}), you can specify \ang{keytype} as an optional argument in parenthesis to the command \fx{\ltxkeyssavexfamilykeys}. The parenthesis can't appear with an empty content.
941
942 \start+{example}[xfamily keys]
943 \ltxkeyssavexfamilykeys<x1>{%
944 ord/keya/\paperwidth/\mylength=#1;
945 cmd/keyb/black/\def\y##1{##1};
946 choice/keyc.{left,right,center}/center/\def\z##1{##1};
947 bool/keyd/true
948 }
949
950 |com(Now define the keys previously stored with the id no. x1.)
951 |com(For now don't define keys keyb and keyc:)
952 \ltxkeysdefinexfamilykeys<x1>[KV]{fam}[mp@]{keyb,keyc}
953
954 |com(Once defined the keys can be executed separately:)
955 \ltxkeyssetkeys[KV]{fam}{keya=.5\hsize,keyd=false}
956 \show\ifmp@keyd
957
958 |com(Now define the keys previously stored with the id no. x1 for)
959 |com(another family. This time we don't want to define key keyb:)
960 \ltxkeysdefinexfamilykeys<x1>[KVA]{|R(fama)}[mpa@]{keyb}
961
962 |com(You can save and define xfamily keys of only one key type,)
963 |com(command keys in the following example:)
964 \ltxkeyssavexfamilykeys<x1>|R(|(cmd|)){%
965 keya/\paperwidth;
966 keyb/blue/\def\x##1{#1x##1};
967 }
968 |com(Define the saved keys and ignore none of them:)
969 \ltxkeysdefinexfamilykeys|*<x1>[KV]{fam}[mp@]{}
970 \ltxkeyssetkeys[KV]{fam}{keya=.5\hsize,keyb=red}
971 \finish{example}
972 \fxi*{\ltxkeyssavexfamilykeys,\ltxkeysdefinexfamilykeys}
973
974 \start+{example}[xfamily keys]
975 |com(`keya' and `keyd' are starred style keys but `keyd' has no observers:)
976 \ltxkeyssavexfamilykeys<a1>|(sty|*|){%
977 keya/center/.do=\def\xx##1{##1xx#1}/
978 ord>\needvalue{keyb}>\parentval>\edef\yy##1{##1yy\unexpanded{#1}},
979 |com(The braces around `center' |(the default value of `keyc'|))
980 |com(will be preserved in parsing:)
981 cmd>keyc>{center};
982 |com(The braces around the callback of `keyd' will be preserved:)
983 keyd/red/.do={\def\x{\color{#1}print aaa}};
984 }
985 |com(Ignore `keyd' in defining keys saved in `a1':)
986 \ltxkeysdefinexfamilykeys*<a1>[KV]{fam}[mp@]{keyd}
987 |com(On setting `keya', `keyb' and `keyc' will be defined and initialized:)
988 \ltxkeyssetkeys[KV]{fam}{keya=left}
989 \finish{example}
990 \aidx*{/.do}
991
992 Here is a real-life example that mimics some of the macros of the \pkg'{xwatermark}:
993
994 \start+{example}[xfamily keys]
995 \ltxkeyssavexfamilykeys<a1>{%
996 cmd/width/\textwidth;
997 cmd/textcolor/black;
998 cmd/framecolor/black;
999 cmd/framesep/3\p@;
1000 cmd/framerule/0.4\p@;
1001 choice/textalign|R(.){%
1002 center/.do=\def\mp@textalign{center},
1003 left/.do=\def\mp@textalign{flushleft},
1004 right/.do=\def\mp@textalign{flushright}
1005 }/center;
1006 bool/framebox/true;
1007 ord/junkkey/throwaway;
1008 }
1009 |com(Ignore keys `framebox' and `junkkey' when defining family `ltxframebox':)
1010 \ltxkeysdefinexfamilykeys*<a1>[KV]{ltxframebox}[mp@]{framebox,junkkey}
1011 |com(Ignore key `junkkey' when defining family `ltxminipage':)
1012 \ltxkeysdefinexfamilykeys<a1>[KV]{ltxminipage}[mp@]{junkkey}
1013 |com(No key is ignored when defining `junkfamily':)
1014 \ltxkeysdefinexfamilykeys<a1>[KVX]{junkfamily}[mp@]{}
1015
1016 \newcommand*\ltxframebox[2][]{%
1017 \ltxkeyssetkeys[KV]{ltxframebox}{#1}%
1018 \begingroup
1019 \fboxsep\mp@framesep\fboxrule\mp@framerule
1020 \ltsdimdef\mp@boxwidth{\mp@width-2\fboxsep-2\fboxrule}%
1021 \color{\mp@framecolor}%
1022 \noindent
1023 \fbox{%
1024 \removelastskip
1025 \parbox{\mp@boxwidth}{%
1026 \begin\mp@textalign
1027 \textcolor{\mp@textcolor}{#2}%
1028 \end\mp@textalign
1029 }%
1030 }%
1031 \endgroup
1032 }
1033 \newcommand*\ltxminipage[2][]{%
1034 \ltxkeyssetkeys[KV]{ltxminipage}{#1}%
1035 \begingroup
1036 \fboxsep\mp@framesep
1037 \fboxrule\ifmp@framebox\mp@framerule\else\z@\fi
1038 \ltsdimdef\mp@boxwidth{\mp@width-2\fboxsep-2\fboxrule}%
1039 \noindent\begin{lrbox}\@tempboxa
1040 \begin{minipage}[c][\height][s]\mp@boxwidth
1041 \@killglue
1042 \begin\mp@textalign
1043 \textcolor{\mp@textcolor}{#2}%
1044 \end\mp@textalign
1045 \end{minipage}%
1046 \end{lrbox}%
1047 \@killglue
1048 \color{\mp@framecolor}%
1049 \ifmp@framebox\fbox{\fi\usebox\@tempboxa\ifmp@framebox}\fi
1050 \endgroup
1051 }
1052
1053 \begin{document}
1054 \ltxframebox[
1055 framecolor=blue,textcolor=purple,textalign=left
1056 ]{%
1057 Test text\endgraf ...\endgraf test text
1058 }
1059 \medskip
1060 \ltxminipage[
1061 framecolor=blue,textcolor=purple,framebox=true,textalign=right
1062 ]{%
1063 Test text\endgraf ...\endgraf test text
1064 }
1065 \end{document}
1066 \finish{example}
1067 \fxi*{\ltxkeyssavexfamilykeys,\ltxkeysdefinexfamilykeys}
1068
1069
1070 \docsection(sec:settingkeys)<setting keys>{Setting keys}
1071
1072 In the \pkg'{ltxkeys} there are many functions for setting keys. Keys can be set by the following utilities.
1073
1074
1075 \docsubsection{Setting defined keys}
1076
1077 \start+{newmacro}[\ltxkeyssetkeys]
1078 \ltxkeyssetkeys[|A(pref)]{|A(fam)}[|A(na)]{|A(keyval)}
1079 \ltxkeyssetkeys|*[|A(pref)]{|A(fam)}[|A(na)]{|A(keyval)}
1080 \ltxkeyssetkeys|+[|A(prefs)]{|A(fams)}[|A(na)]{|A(keyval)}
1081 \ltxkeyssetkeys|*|+[|A(prefs)]{|A(fams)}[|A(na)]{|A(keyval)}
1082 \finish{newmacro}
1083 \fxim*{\ltxkeyssetkeys}
1084
1085 Here, \ang{prefs}, \ang{fams} and \ang{keyval} are comma-separated list of key prefixes, families and \keyval pairs, respectively. Keys listed in the comma-separated list\footnote{Key values with unbraced commas in them will need to be enclosed in curly braces when they are submitted to \ftfx{\ltxkeyssetkeys}, whether or not the argument pattern is simple (only one argument) or weird (more than one argument and with delimiters).} \ang{na} are ignored. The \stform will save all undefined keys with prefix \ang{pref} and in family \ang{fam} in the macro \fnl*'\bs{pref,fam,rmkeys}, to be set later, perhaps with \fx{\ltxkeyssetrmkeys}. The \plform will search in all the prefixes in \ang{prefs} and all families in \ang{fams} for a key before logging the key in \fnl*'\bs{pref,fam,rmkeys} (if the \redstar\redplus* variant is used) or reporting it as undefined.
1086
1087 To avoid infinite re-entrance of \fx{\ltxkeyssetkeys} and the consequent bombing out of the command, the package option \fxim{keydepthlimit} is introduced. Its default value is~4, meaning that \fx{\ltxkeyssetkeys} can't ordinarily be nested beyond level~4. If you must nest \fx{\ltxkeyssetkeys} beyond this level, an unlikely need, you can raise the \fx{keydepthlimit} as a package option via \hx{\usepackage} or, if \pkg'{ltxtools} is loaded before \hx{\documentclass}, via \hx{\documentclass}. For example,
1088
1089 \start'{example}[Setting keydepthlimit]
1090 \usepackage[keydepthlimit=6]{ltxkeys}
1091 \finish{example}
1092 \fxim*{keydepthlimit}
1093
1094 The more appropriate name \fxi{keystacklimit} is an alias for \fx{keydepthlimit}.
1095
1096
1097 \docsubsection(sec:rmkeys)<rmkeys,remaining keys>{Setting \headquoted{remaining} keys}
1098
1099 The command \fx{\ltxkeyssetrmkeys}, which has both star (\redstar) and plus (\redplus) variants, is the counterpart of \fx{\setrmkeys} of the \pkg'{xkeyval}:
1100
1101 \start{newmacro}[\ltxkeyssetrmkeys]
1102 \ltxkeyssetrmkeys[|A(pref)]{|A(fam)}[|A(na)]
1103 \ltxkeyssetrmkeys|*[|A(pref)]{|A(fam)}[|A(na)]
1104 \ltxkeyssetrmkeys|+[|A(prefs)]{|A(fams)}[|A(na)]
1105 \ltxkeyssetrmkeys|*|+[|A(prefs)]{|A(fams)}[|A(na)]
1106 \finish{newmacro}
1107 \fxim*{\ltxkeyssetrmkeys}
1108
1109 The command \fx{\ltxkeyssetrmkeys} sets in the given prefixes and families the \quoted{remaining keys} saved when calling the \stform of \fx{\ltxkeyssetkeys} or \fx{\ltxkeyssetrmkeys}. \ang{na} is again the list of keys that should be ignored, \ie, not executed and not saved. The \unstform of \fx{\ltxkeyssetrmkeys} will report an error if a key is undefined. The \stform of the macro \fx{\ltxkeyssetrmkeys}, like the \stform of \fx{\ltxkeyssetkeys}, ignores keys that it cannot find and saves them on the list saved for a future call to \fx{\ltxkeyssetrmkeys}. Keys listed in \ang{na} will be ignored fully and will not be appended to the saved list of remaining keys.
1110
1111
1112 \docsubsection(sec:aliasedkeys)<aliased keys>{Setting aliased keys}
1113
1114 Aliased keys differ from style keys of \sref{sec:stylekeys}. Two keys may be aliased to each other, such that when one is set, the alias is automatically set with the same or a different value. The concept is similar to, but not identical with, that of style keys. The two aliases must all be in the same family and have the same key and macro prefixes. Moreover, aliased keys must be called within the callbacks of each other, so that they can share metadata. Two aliased keys can't both call each other: only one can call the other; so the relationship isn't symmetrical. These restrictions not withstanding, aliased keys can be quite powerful in application\footnote{The restrictions have been deliberately imposed to shorten and simplify the use syntax of aliased keys. They could otherwise be easily lifted.}.
1115
1116 \start{newmacro}[\ltxkeyssetaliaskey]
1117 \ltxkeyssetaliaskey{|A(key)}[|A(value)]
1118 \finish{newmacro}
1119 \fxim*{\ltxkeyssetaliaskey}
1120
1121 Here, \ang{value} is optional; if it is not given, \ang{key} will be set with the current value of its alias.
1122
1123 \start+{example}[\ltxkeyssetaliaskey]
1124 \ltxkeysdefinekeys|*[KV]{fam}[mp@]{%
1125 printsign=true;
1126 printmark=true/\ltxkeyssetaliaskey{printsign}[false];
1127 keya=$+++$;
1128 keyb=star/\ltxkeyssetaliaskey{keya}[$***$]
1129 }
1130 \ltxkeysdefinekeys|*[KV]{fam}[mp@]{%
1131 keya=sun/\ltxkeyscheckuserinput{#1}{star,sun,moon}
1132 \ifltxkeysinputvalid
1133 \edef\givenval{\userinput}
1134 \edef\found{\ifcase\order star@\or sun@\or moon@\fi}
1135 \else
1136 \@latex@error{Input `#1' not valid}\@ehd
1137 \fi;
1138 keyb=star/\ltxkeyssetaliaskey{keya};
1139 }
1140 \finish{example}
1141
1142 The boolean \fx{\ifltxkeysinputvalid} associated with the command \fx{\ltxkeyscheckuserinput} is described in \sref{mac:ifltxkeysinputvalid} (see also \sref{sec:checkchoice}).
1143
1144 The example involving \ttx{printsign,printmark} is similar, but not equivalent, to the notion of biboolean keys. Biboolean keys have equal symmetry (\ie, they can call each other with equal propensity) and they won't bomb out in an infinite reentrance. This is not the case with aliased keys: only slave/alias can set or call master/main key. If they both call each other, the user will be alerted to the fact that there is an infinite reentrance of keys. The notion of 'slave' and 'master' used in the \pkg'{ltxkeys} may be counterintuitive but in reality it is quite logical.
1145
1146 Schemes like the following are disallowed, to avoid back-linking of \fx{\ltxkeyssetaliaskey}. The package will flag an error if something like the following occurs:
1147
1148 \start+{example}[Illegal nested \ltxkeyssetaliaskey]
1149 \ltxkeysordkey[KV]{fam}{keya}[true]{\ltxkeyssetaliaskey{keyb}}
1150 \ltxkeysordkey[KV]{fam}{keyb}[true]{\ltxkeyssetaliaskey{keya}}
1151 \ltxkeyssetkeys[KV]{fam}{keya}
1152 \finish{example}
1153 \aidx*{no nested \headfx{\ltxkeyssetaliaskey}}
1154
1155
1156 \docsubsection(sec:keypointers){Using key pointers}
1157 \aidx*{key pointers}
1158 \aidxs*{pointers}{key pointers}
1159
1160 The pointers \ffx'{\savevalue,\gsavevalue,\usevalue,\needvalue, \gneedvalue, \forbidvalue, \gforbidvalue} can all be used at key definition time, but only \ffx'{\savevalue,\gsavevalue,\usevalue} are available at key setting time. The pointer \fx{\usevalue} will be raise an error if used when defining keys. The presence of the pointer \fx{\needvalue} when setting keys prompts an error. Pointers beginning with the letter \quoted{g} have a global effect; those without \quoted{g} act only locally.
1161
1162 The pointers \ffx'{\savevalue, \gsavevalue} will save the user-supplied value of the key. The pointer \fx{\gsavevalue} has the same meaning at key definition and key setting times, namely, to globally save the value of a key. The pointers \ffx'{\needvalue, \gneedvalue} can be used by any key author to prompt the user of the key to always supply a value for the key. The pointers \ffx'{\forbidvalue, \gforbidvalue} can be used to bar the user of the key from supplying a value for the key. The pointer \fx{\usevalue}, if required at key setting time, has to be explicitly indicated there.
1163
1164 In key parsing, instead of saving the value of each key tagged with \fx{\savevalue} or \fx{\gsavevalue} in a separate macro, we save all such keys and their values in only one macro (for each combination of \ang{pref} and \ang{fam}) and use a fast search technique to find the values when they are later needed (by any key tagged with \fx{\usevalue}).
1165
1166 Here is an interesting example and proof of concept of pointers:
1167
1168 \start'{example}[Key pointers]
1169 \ltxkeysstylekeys|*[KV]{fam}{%
1170 \needvalue{keya},\savevalue\needvalue{keyb},\gneedvalue\gsavevalue{keyc}
1171 }[{left}]|(%
1172 |com(`#1' here refers to the value of the observer key at the)
1173 |com(time it is being set.)
1174 ord/\savevalue{keyb}/\parentval/\edef\y##1{##1xx\unexpanded{#1}};
1175 cmd/keyc/{center}
1176 |){%
1177 |com(`#1' here refers to the value of the parent key at the time)
1178 |com(it is being set.)
1179 \def\x##1{##1xx#1}
1180 }
1181
1182 \ltxkeyssetkeys[KV]{fam}{%
1183 \gsavevalue{keya}={\def\y##1{##1}},
1184 \savevalue{keyb}=\usevalue{keya},
1185 keyc=\usevalue{keyb}
1186 }
1187 \finish{example}
1188 \fxi*{\savevalue,\gsavevalue,\usevalue,\needvalue, \gneedvalue, \forbidvalue, \gforbidvalue}
1189
1190 If you have to save the values of many keys, then the above scheme of placing \fx{\savevalue} or \fx{\gsavevalue} on keys at key setting time can be avoided by using the following commands:
1191
1192 \start+{newmacro}[\ltxkeys@savevaluekeys,\ltxkeys@addsavevaluekeys, etc.]
1193 \ltxkeys@savevaluekeys[|A(pref)]{|A(fam)}{|A(list)}
1194 \ltxkeysgsavevaluekeys[|A(pref)]{|A(fam)}{|A(list)}
1195 \ltxkeys@addsavevaluekeys[|A(pref)]{|A(fam)}{|A(list)}
1196 \ltxkeysgaddsavevaluekeys[|A(pref)]{|A(fam)}{|A(list)}
1197 \ltxkeys@removesavevaluekeys[|A(pref)]{|A(fam)}{|A(list)}
1198 \ltxkeysgremovesavevaluekeys[|A(pref)]{|A(fam)}{|A(list)}
1199 \ltxkeys@undefsavevaluekeys[|A(pref)]{|A(fam)}
1200 \ltxkeysgundefsavevaluekeys|![|A(pref)]{|A(fam)}
1201 \finish{newmacro}
1202 \fxim*{\ltxkeys@savevaluekeys,\ltxkeys@addsavevaluekeys,
1203 \ltxkeys@removesavevaluekeys,\ltxkeys@undefsavevaluekeys}
1204
1205 The command \fx{\ltxkeys@savevaluekeys} will create, for the given key family and prefix, a list of keys whose values should be saved at key-setting time, if those keys don't already exist in the list. The command \fx{\ltxkeys@addsavevaluekeys} will add to the list those keys that don't already exist in the list; \fx{\ltxkeys@removesavevaluekeys} remove those save-keys that it can find in the list; while the command \fx{\ltxkeys@undefsavevaluekeys} will undefine the entire list of save-keys of the given key family and prefix.
1206
1207 \start+{example}[\ltxkeys@savevaluekeys]
1208 \ltxkeysdefinekeys[KV]{fam}[mp@]{%
1209 ord/keya/2cm/\def\x##1{#1xx##1};
1210 cmd/keyb/John;
1211 bool/keyc/true/\ifmp@keyc\def\y##1{##1yy#1}\fi;
1212 choice/keyd.{left,right,center}/
1213 \ifcase\order
1214 \def\shoot{0}%
1215 \or
1216 \def\shoot{1}%
1217 \or
1218 \def\shoot{2}%
1219 \fi
1220 }
1221
1222 \ltxkeys@savevaluekeys[KV]{fam}{keya,keyb,keyc}
1223 \ltxkeys@addsavevaluekeys[KV]{fam}{keyd}
1224 \ltxkeys@removesavevaluekeys[KV]{fam}{keya,keyb}
1225 \ltxkeys@undefsavevaluekeys[KV]{fam}
1226
1227 \ltxkeyssetkeys[KV]{fam}{keya=\usevalue{keyc},keyb=\usevalue{keya}}
1228 \finish{example}
1229
1230 The following commands are also available:
1231
1232 \start+{newmacro}[\ltxkeys@needvaluekeys,\ltxkeys@addneedvaluekeys, etc.]
1233 \ltxkeys@needvaluekeys[|A(pref)]{|A(fam)}{|A(list)}
1234 \ltxkeysgneedvaluekeys[|A(pref)]{|A(fam)}{|A(list)}
1235 \ltxkeys@addneedvaluekeys[|A(pref)]{|A(fam)}{|A(list)}
1236 \ltxkeysgaddneedvaluekeys[|A(pref)]{|A(fam)}{|A(list)}
1237 \ltxkeys@removeneedvaluekeys[|A(pref)]{|A(fam)}{|A(list)}
1238 \ltxkeysgremoveneedvaluekeys[|A(pref)]{|A(fam)}{|A(list)}
1239 \ltxkeys@undefneedvaluekeys[|A(pref)]{|A(fam)}
1240 \ltxkeysgundefneedvaluekeys|![|A(pref)]{|A(fam)}
1241
1242 \ltxkeys@forbidvaluekeys[|A(pref)]{|A(fam)}{|A(list)}
1243 \ltxkeysgforbidvaluekeys[|A(pref)]{|A(fam)}{|A(list)}
1244 \ltxkeys@addforbidvaluekeys[|A(pref)]{|A(fam)}{|A(list)}
1245 \ltxkeysgaddforbidvaluekeys[|A(pref)]{|A(fam)}{|A(list)}
1246 \ltxkeys@removeforbidvaluekeys[|A(pref)]{|A(fam)}{|A(list)}
1247 \ltxkeysgremoveforbidvaluekeys[|A(pref)]{|A(fam)}{|A(list)}
1248 \ltxkeys@undefforbidvaluekeys[|A(pref)]{|A(fam)}
1249 \ltxkeysgundefforbidvaluekeys|![|A(pref)]{|A(fam)}
1250 \finish{newmacro}
1251 \fxim*{\ltxkeys@needvaluekeys,\ltxkeys@addneedvaluekeys,
1252 \ltxkeys@removeneedvaluekeys,\ltxkeys@undefneedvaluekeys,
1253 \ltxkeys@forbidvaluekeys,\ltxkeys@addforbidvaluekeys,
1254 \ltxkeys@removeforbidvaluekeys,\ltxkeys@undefforbidvaluekeys,
1255 }
1256
1257
1258 \docsubsection(sec:savedvalueofkey)
1259 <saved value of key>{Accessing the saved value of a key}
1260
1261 As mentioned earlier, the pointers \ffx'{\savevalue, \usevalue} are available for saving and using the values of keys within the command \fx{\ltxkeyssetkeys}. But suppose you have used \fx{\savevalue} within \fx{\ltxkeyssetkeys} to set the value of a key, how do you access that value outside of \fx{\ltxkeyssetkeys}? You can do this by using the following \fx{\ltxkeysstorevalue} command:
1262
1263 \start{newmacro}[\ltxkeysstorevalue]
1264 \ltxkeysstorevalue[|A(pref)]{|A(fam)}{|A(key)}|A(cs)
1265 \ltxkeysstorevalue|+[|A(pref)]{|A(fam)}{|A(key)}|A(cs)|A(fallback)
1266 \finish{newmacro}
1267 \fxim*{\ltxkeysstorevalue}
1268
1269 Here, \ang{cs} is the macro (defined or undefined) that will receive the saved value of \ang{key}. The plain variant of this command will raise an error message if the value of the key wasn't previously saved, while the \plform will resort to the user-supplied function \ang{fallback}. Only saved key values can be recovered by this command.
1270
1271 \start+{example}[\ltxkeysstorevalue]
1272 \ltxkeyscmdkey[KV]{fam}{\needvalue{keya}}[{left}]{%
1273 \def\x##1{##1xx#1}
1274 }
1275 \ltxkeyssetkeys[KV]{fam}{\savevalue{keya}={\def\y##1{##1}}}
1276 \ltxkeysstorevalue[KV]{fam}{keya}\tempa
1277 \ltxkeysstorevalue|+[KV]{fam}{keya}\tempb{%
1278 \@latex@error{No value saved for key `keya'}\@ehc
1279 }
1280 \finish{example}
1281
1282
1283 \docsubsection(sec:presettingkeys){Pre-setting and post-setting keys}
1284 \aidxm*{presetting keys, post-setting keys}
1285
1286 \start+{newmacro}[\ltxkeyspresetkeys,\ltxkeyspostsetkeys,etc.]
1287 \ltxkeyspresetkeys[|A(pref)]{|A(fam)}{|A(keyvals)}
1288 \ltxkeyspresetkeys|![|A(pref)]{|A(fam)}{|A(keyvals)}
1289 \ltxkeysaddpresetkeys[|A(pref)]{|A(fam)}{|A(keyvals)}
1290 \ltxkeysaddpresetkeys|![|A(pref)]{|A(fam)}{|A(keyvals)}
1291 \ltxkeysremovepresetkeys[|A(pref)]{|A(fam)}{|A(keyvals)}
1292 \ltxkeysremovepresetkeys|![|A(pref)]{|A(fam)}{|A(keyvals)}
1293 \ltxkeysundefpresetkeys[|A(pref)]{|A(fam)}
1294 \ltxkeysundefpresetkeys|![|A(pref)]{|A(fam)}
1295
1296 \ltxkeyspostsetkeys[|A(pref)]{|A(fam)}{|A(keyvals)}
1297 \ltxkeyspostsetkeys|![|A(pref)]{|A(fam)}{|A(keyvals)}
1298 \ltxkeysaddpostsetkeys[|A(pref)]{|A(fam)}{|A(keyvals)}
1299 \ltxkeysaddpostsetkeys|![|A(pref)]{|A(fam)}{|A(keyvals)}
1300 \ltxkeysremovepostsetkeys[|A(pref)]{|A(fam)}{|A(keyvals)}
1301 \ltxkeysremovepostsetkeys|![|A(pref)]{|A(fam)}{|A(keyvals)}
1302 \ltxkeysundefpostsetkeys[|A(pref)]{|A(fam)}
1303 \ltxkeysundefpostsetkeys|![|A(pref)]{|A(fam)}
1304 \finish{newmacro}
1305 \fxim*{\ltxkeyspresetkeys,\ltxkeysaddpresetkeys,\ltxkeysremovepresetkeys,
1306 \ltxkeysundefpresetkeys,\ltxkeyspostsetkeys,\ltxkeysaddpostsetkeys,
1307 \ltxkeysremovepostsetkeys,\ltxkeysundefpostsetkeys}
1308
1309 Here, \ang{keyvals} is a comma-separated list of \keyval pairs to be preset or postset in the given families. The optional exclamation mark \redclam here, as in many (but not all) instances in the \pkg'{ltxkeys}, means that the assignments would be done and the lists built globally rather than locally. \quoted{Presetting keys} means \quoted{these keys should be set before setting other keys in every run of the command \fx{\ltxkeyssetkeys} for the given key prefix and family}\footnote{Keys contained in the current user input to \fx{\ltxkeyssetkeys} will not be preset or postset, \ie, the current user values of keys will always take priority over preset and postset values.}. The command \fx{\ltxkeysaddpresetkeys} is an alias for \fx{\ltxkeyspresetkeys}, and this helps explain that \fx{\ltxkeyspresetkeys} is indeed a list merger. Neither the command \fx{\ltxkeyspresetkeys} nor \fx{\ltxkeyspostsetkeys} set keys itself, contrary to what the names might suggest.
1310
1311 \quoted{Post-setting keys} means \quoted{these keys are to be set after setting other keys in every run of the command \fx{\ltxkeyssetkeys} for the given key prefix and family}. \fx{\ltxkeysaddpostsetkeys} is an alias for \fx{\ltxkeyspostsetkeys}. The commands
1312
1313 \start+{macro}
1314 \ltxkeysremovepresetkeys|![|A(pref)]{|A(fam)}{|A(keys)}
1315 \ltxkeysremovepostsetkeys|![|A(pref)]{|A(fam)}{|A(keys)}
1316 \finish{macro}
1317
1318 remove \ang{keys} from preset and post-set lists, respectively. The commands
1319
1320 \start+{macro}
1321 \ltxkeysundefpresetkeys|![|A(pref)]{|A(fam)}
1322 \ltxkeysundefpostsetkeys|![|A(pref)]{|A(fam)}
1323 \finish{macro}
1324
1325 respectively, undefine all preset and post-set keys in the given family.
1326
1327 Logically, you can't enter the same key twice in either preset or post-set list in the same family and prefix.
1328
1329 \start+{example}[\ltxkeyspresetkeys, \ltxkeyspostsetkeys, etc.]
1330 \ltxkeysdefinekeys|*[KV1]{fam1}[mp@]{%
1331 keya/left/\def\x##1{#1x##1};
1332 \needvalue{keyb}/right;
1333 keyc/center;
1334 keyd
1335 }
1336 \ltxkeyspresetkeys|![KV1]{fam1}{keya=\flushleft,keyb=\flushright}
1337 \ltxkeyspostsetkeys|![KV1]{fam1}{keyd=\flushleft}
1338 ...
1339 |com(Eventually, only `keya' will be preset:)
1340 \ltxkeysremovepresetkeys|![KV1]{fam1}{keyb=\flushright}
1341 ...
1342 |com(Because of the |redstar and |redplus signs on \ltxkeyssetkeys, all unknown)
1343 |com(keys |(those with prefix `KV2' and in family `fam2'|) will be saved in)
1344 |com(the list of remaining keys, and can be set later with \ltxkeyssetrmkeys:)
1345 \ltxkeyssetkeys|*|+[KV1,KV2]{fam1,fam2}[keyd]{keya=xxx,keyb=yyy,keyc}
1346 \finish{example}
1347
1348
1349 \docsubsection(sec:initializekeys)
1350 <initializing keys>{Initializing keys}
1351
1352 \start{newmacro}[\ltxkeysinitializekeys]
1353 \ltxkeysinitializekeys[|A(prefs)]{|A(fams)}[|A(na)]
1354 \finish{newmacro}
1355 \fxim*{\ltxkeysinitializekeys}
1356
1357 This presets all the keys previously defined in families \ang{fams} with their default values; it ignores keys listed in \ang{na}. If \ang{na} is a list of \keyval pairs, the key names are extracted from the list before the family keys are initialized. Any \keyval pairs in \ang{na} are not set at all. All keys defined by \ffx'{\ltxkeysdefinekeys, \ltxkeysdeclarekeys} are automatically instantly initialized, except slave/alias and observer keys. Alias and observer keys aren't initialized in this case in order to avoid cyclic re-entrance of \fx{\ltxkeyssetkeys}.
1358
1359 The command \fx{\ltxkeysinitializekeys} can be used in place of \fx{\ltxkeysexecuteoptions}, since \fx{\ltxkeysexecuteoptions} (similar to \latex kernel's \hx{\ExecuteOptions}) fulfils the sole purpose of setting up default values of options. Keys defined via \ffx'{\ltxkeysdefinekeys, \ltxkeysdeclarekeys} don't have to be initialized, since they're automatically initialized at definition time. But if you have used the scheme of \sref{nte:definekeys-1}, then it might still be necessary to initialize keys outside \ffx'{\ltxkeysdefinekeys, \ltxkeysdeclarekeys}.
1360
1361 \begin{noteenv}
1362 \label{nte:initializekeys}
1363 Keys that have been processed by \fx{\ltxkeysprocessoptions} (\ie, keys submitted by the user as package or class options via \hx{\documentclass} or \hx{\usepackage} can't be initialized or launched (see \sref{sec:launchingkeys} below for the meaning of \quoted{launched keys}). This is to avoid unwittingly setting keys to their default values after the user has submitted them as package or class options. This means that \quoted{option keys} (see \sref{sec:optionskeys}) can't be initialized or launched.
1364 \end{noteenv}
1365
1366
1367 \docsubsection(sec:launchingkeys)<launching keys>{Launching keys}
1368
1369 \start{newmacro}[\ltxkeyslaunchkeys]
1370 \ltxkeyslaunchkeys[|A(prefs)]{|A(fams)}{|A(curr)}
1371 \ltxkeyslaunchkeys|*[|A(prefs)]{|A(fams)}{|A(curr)}
1372 \ltxkeyslaunchkeys|+[|A(prefs)]{|A(fams)}{|A(curr)}
1373 \ltxkeyslaunchkeys|*|+[|A(prefs)]{|A(fams)}{|A(curr)}
1374 \finish{newmacro}
1375 \fxim*{\ltxkeyslaunchkeys}
1376
1377 This presets all keys defined in families \ang{fams} with their default values; it ignores keys listed in \ang{curr}. \ang{curr} may be the list of \keyval pairs that the user wants to use as current values of keys. Their keys are to be ignored when setting up defaults, \ie, when initializing the family keys. One major difference between \ffx'{\ltxkeyslaunchkeys, \ltxkeysinitializekeys} is that in \fx{\ltxkeyslaunchkeys} the \keyval pairs in \ang{curr} are immediately set after the absent family keys (\ie, those without current values) are reinitialized. Keys appearing in \ang{curr} in the command \fx{\ltxkeyslaunchkeys} will be the \ang{na} (ignored) keys for the command \fx{\ltxkeysinitializekeys}.
1378
1379 Keys across multiple prefixes \ang{prefs} and families \ang{fams} can be launched at the same time, but the user has to know what is he doing: the keys might not have been defined across the given families, or some keys might have been disabled in some, and not all, families. The \redstar and \redplus variants of \fx{\ltxkeyslaunchkeys} have the same meaning as in \fx{\ltxkeyssetkeys} (\sref{sec:settingkeys}). The \stform will save all undefined keys with prefix \ang{pref} and in family \ang{fam} in the macro \fnl*'\bs{pref,fam,rmkeys}, to be set later, perhaps with the command \fx{\ltxkeyssetrmkeys}. The \plform will search in all the prefixes in \ang{prefs} and all families in \ang{fams} for a key before logging the key in \fnl*'\bs{pref,fam,rmkeys} (if the \redstar\redplus* variant is the one used) or reporting it as undefined.
1380
1381
1382 \docsubsubsection(sec:nonlaunchkeys)
1383 <non-launch keys>{Noninitialize and non\-la\-unch keys}
1384
1385 Listing all the keys that shouldn't be reinitialized by \fx{\ltxkeysinitializekeys} in the \ang{na} list every time \fx{\ltxkeysinitializekeys} is called can sometimes be inconvenient, especially when dealing with a large number of keys. Perhaps even more important is the fact that sometimes you don't want some of the keys in a family to be reinitialized even though they are absent keys (\ie, they aren't listed as current keys, meaning that they aren't in the current \keyval list submitted to \fx{\ltxkeyslaunchkeys}). This might be the case with package and class options. The command \fx{\ltxkeysnonlaunchkeys} provides a convenient means for listing the non-reinitializing keys once and for all. If there are keys in a family that shouldn't be reinitialized/launched with other keys in the same family during any call to \fx{\ltxkeyslaunchkeys} or \fx{\ltxkeysinitializekeys}, they can be listed in the \fx{\ltxkeysnonlaunchkeys} command:
1386
1387 \start{newmacro}[\ltxkeysnonlaunchkeys]
1388 \ltxkeysnonlaunchkeys[|A(prefs)]{|A(fams)}{|A(keys)}
1389 \finish{newmacro}
1390 \fxim*{\ltxkeysnonlaunchkeys}
1391
1392 Keys across multiple prefixes and families can be submitted to the \fx{\ltxkeysnonlaunchkeys} command: undefined keys are simply ignored by \fx{\ltxkeysnonlaunchkeys}.
1393
1394 \ltsnote
1395 The command \fx{\ltxkeysnonlaunchkeys} doesn't mean that the keys in \ang{keys} can no longer be set via the command \fx{\ltxkeyssetkeys}; it simply implies that keys appearing in \fx{\ltxkeysnonlaunchkeys} will not be reinitialized to their default values when members of their class are being launched or reinitialized. The command \fx{\ltxkeysnoninitializekeys} is an alias for \fx{\ltxkeysnonlaunchkeys}.
1396
1397
1398 \docsubsection(sec:unknownkeyhandler)
1399 <unknown key and option handlers>{Handling unknown keys and options}
1400
1401 You can use the macro \fx{\ltxkeysunknownkeyhandler} to declare to \pkg'{ltxkeys} the course of action to take if, while setting keys, it discovers that a key is undefined or unknown. The command \fx{\ltxkeysunknownoptionhandler} applies to unknown options (see \sref{sec:declareoption})\usefootnote{2}. The syntax of these commands is
1402
1403 \start+{newmacro}[\ltxkeysunknownkeyhandler,\ltxkeysunknownoptionhandler]
1404 \ltxkeysunknownkeyhandler[|A(prefs)]{|A(fams)}{|A(cbk)}
1405 \ltxkeysunknownoptionhandler[|A(prefs)]<|A(fams)>{|A(cbk)}
1406 \finish{newmacro}
1407 \fxim*{\ltxkeysunknownkeyhandler,\ltxkeysunknownoptionhandler}
1408
1409 Here, \ang{prefs} are the optional prefixes and \ang{fams} is the mandatory families; both may contain one or more comma-separated elements. The default value of \ang{prefs} is \fx{KV}. The callback \ang{cbk} signifies the action to take when an unknown key or option is encountered. The default \ang{cbk} is to log the keys and, in each run, warn the user of the presence of unknown keys. The same \ang{cbk} can be used across key prefixes \ang{prefs} and families \ang{fams}. You can use \fx{#1} (or \fx{\ltxkeyscurrentprefix}) in \ang{cbk} to represent the current key prefix, \fx{#2} (or \fx{\ltxkeyscurrentfamily}) for the current family, \fx{#3} (or \fx{\ltxkeyscurrentkey}) for the current key name, and \fx{#4} (or \fx{\ltxkeyscurrentvalue}) for the value of the current key.
1410
1411 If \fx{\ltxkeyscurrentvalue} contains undefined macros or active characters, then attempting to print it may cause problems. Therefore, when making entries in the transcript file, it will sometimes be preferable to use \fx{\ltxkeysinnocentvalue} instead of \fx{\ltxkeyscurrentvalue}. However, \fx{\ltxkeysinnocentvalue} detokenizes the current key value and gives only the first 20 characters of a key's value.
1412
1413 The following example provides unknown option and key handlers. The unknown key handler is for two key prefixes (\ffx'{KVA, KVB}) and two key families (\ffx'{fam1,fam2}).
1414
1415 \start+{example}[\ltxkeysunknownkeyhandler,\ltxkeysunknownoptionhandler]
1416 \ltxkeysunknownoptionhandler[KV]<fam1,fam2>{%
1417 \wlog{Prefix: #1/ Family: #2/ Option name: #3/ Value: \unexpanded{#4}}%
1418 }
1419
1420 \ltxkeysunknownkeyhandler[KVA,KVB]{fam1,fam2}{%
1421 \@expandtwoargs\in@{,#3,}{,\myspecialkeys,}%
1422 \ltsifboolTF{in@}{%
1423 |com(The reader may want to investigate what the parameter texts)
1424 |com(##1 and ####1 below stand for |(see |sref(nte:unknownkey) below|):)
1425 \ltxkeysordkey[#1]{#2}{#3}[#4]{\def\x####1{####1xx##1}}%
1426 }{%
1427 \ltxmsg@warn{Unknown key `#3' with value `#4' in family `#2' ignored}\@ehd
1428 |com(\ltxmsg@warn{Unknown key `\ltxkeyscurrentkey' with value)
1429 |com( `\ltxkeysinnocentvalue' in family `\ltxkeyscurrentfamily' ignored}\@ehd)
1430 }%
1431 }
1432 \finish{example}
1433
1434 The macro \fx{\myspecialkeys} in the above example doesn't actually exist; it is only meant for illustration here. But \quoted{handled keys} may be introduced by the user to serve this purpose. This will be the set of keys for which special actions may apply at key setting time (see \sref{sec:handledkeys}).
1435
1436 \begin{noteenv}
1437 \label{nte:unknownkey}
1438 To see what the parameter texts \fx{##1} and \fx{####1} above stand for, run the following code on your own and note the outcome of \fx{\show\KV@fam@keyd}. The characters \fx{##1} will turn out to be the parameter text which can be used to access the current values of keys \ffx'{keyd,keye} after they have been defined on the fly. And \fx{####1} will be the parameter text of the arbitrary function \fx{\x}. If you do \fx{\show\KV@fam@keyd}, you'll notice that the parameter texts have been reduced by one level of nesting.
1439
1440 \start+{example}[\ltxkeysunknownkeyhandler]
1441 \def\myspecialkeys{keyc,keyd,keye}
1442 \ltxkeysunknownkeyhandler[KV]{fam}{%
1443 \@expandtwoargs\in@{,#3,}{,\myspecialkeys,}%
1444 \ifin@
1445 \ltxkeysordkey[#1]{#2}{#3}[#4]{\def\x####1{####1xx##1}}%
1446 \else
1447 \ltxmsg@warn{Unknown key `#3' with value `\ltxkeysinnocentvalue'
1448 in family `#2' ignored}\@ehd
1449 \fi
1450 }
1451 \ltxkeyssetkeys[KV]{fam}{keyd=aaa,keye=bbb}
1452 \show\KV@fam@keyd
1453 \finish{example}
1454
1455 \end{noteenv}
1456
1457
1458 \docsection(sec:ifkeydef)<is key defined?>{Checking if a key is defined}
1459
1460 \start+{newmacro}[\ltxkeysifkeydefTF,\ltxkeysifkeydefFT]
1461 \ltxkeysifkeydefTF[|A(prefs)]{|A(fams)}{|A(key)}{|A(true)}{|A(false)}
1462 \ltxkeysifkeydefFT[|A(prefs)]{|A(fams)}{|A(key)}{|A(false)}{|A(true)}
1463 \finish{newmacro}
1464 \fxim*{\ltxkeysifkeydefTF,\ltxkeysifkeydefFT}
1465
1466 These check if \ang{key} is defined with a prefix in \ang{prefs} and in family in \ang{fams}. If the test proves that \ang{key} is defined, \ang{true} text will be executed; otherwise \ang{false} will be executed.
1467
1468
1469 \docsection(sec:disablingkeys)<disabling keys>{Disabling families and keys}
1470
1471 \docsubsection{Disabling families}
1472
1473 \start{newmacro}[\ltxkeysdisablefamilies,\ltxkeysgdisablefamilies]
1474 \ltxkeysdisablefamilies[|A(prefs)]{|A(fams)}[|A(nakeys)]
1475 \ltxkeysdisablefamilies|*[|A(prefs)]{|A(fams)}[|A(nakeys)]
1476 \ltxkeysgdisablefamilies[|A(prefs)]{|A(fams)}[|A(nakeys)]
1477 \ltxkeysgdisablefamilies|*[|A(prefs)]{|A(fams)}[|A(nakeys)]
1478 \finish{newmacro}
1479 \fxim*{\ltxkeysdisablefamilies,\ltxkeysgdisablefamilies}
1480
1481 Here, \ang{prefs} and \ang{fams} are comma-separated lists of prefixes and families to be disabled. Keys listed in the comma-separated list \ang{nakeys} are ignored, \ie, they aren't disabled with their colleagues. The macros \ffx'{\ltxkeysdisablefamilies,\ltxkeysgdisablefamilies} disable keys and cause an error to be issued when a disabled family is submitted to \fx{\ltxkeyssetkeys} or invoked by the key caller. If the package option \fx{tracingkeys} is true, disabled families are highlighted in the transcript file. The command \fx{\ltxkeysdisablefamilies} acts locally, while \fx{\ltxkeysgdisablefamilies} has a global effect.
1482
1483 The plain forms of \ffx'{\ltxkeysdisablefamilies,\ltxkeysgdisablefamilies} disable the given families instantly, while the \stform+ disable the families at \hx{\AtBeginDocument}. Authors can use these commands to bar users of their keys from calling those families after a certain point. Individual keys in a family can be disabled using the commands \ffx'{\ltxkeysdisablekeys, \ltxkeysgdisablekeys}.
1484
1485 \start{example}[\ltxkeysdisablefamilies]
1486 \ltxkeys{%
1487 |com(The commands \declare@keys, \set@keys and \set@rmkeys are available)
1488 |com(only within \ltxkeys.)
1489 \declare@keys*[KV1]{fam1}[mp@]{%
1490 bool/key1/true/\def\xx##1{##1\\#1\\##1};
1491 bool/key2/true/\def\yy##1{##1*#1*##1};
1492 cmd/key3/aaa/;
1493 cmd/key4/bbb/
1494 }%
1495 \\
1496 \declare@keys*[KV2]{fam2}[mp@]{%
1497 bool/key1/true;
1498 bool/key2/true;
1499 cmd/key3/yyy/;
1500 cmd/key4/zzz/
1501 }%
1502 \\
1503 \ltxkeysdisablefamilies[KV1,KV2]{fam1,fam2}[key3,key4]
1504 }
1505 \showcsn{KV1@fam2@disabledkeys}
1506 \finish{example}
1507
1508
1509 \docsubsection{Disabling keys}
1510
1511 \start{newmacro}[\ltxkeysdisablekeys,\ltxkeysgdisablekeys]
1512 \ltxkeysdisablekeys[|A(prefs)]{|A(fams)}{|A(keys)}
1513 \ltxkeysgdisablekeys[|A(prefs)]{|A(fams)}{|A(keys)}
1514 \ltxkeysdisablekeys|*[|A(prefs)]{|A(fams)}{|A(keys)}
1515 \ltxkeysgdisablekeys|*[|A(prefs)]{|A(fams)}{|A(keys)}
1516 \finish{newmacro}
1517 \fxim*{\ltxkeysdisablekeys,\ltxkeysgdisablekeys}
1518
1519 Here, \ang{prefs}, \ang{fams} and \ang{keys} are comma-separated lists of prefixes, families and associated keys to be disabled. The macro \fx{\ltxkeysdisablekeys} causes an error to be issued when a disabled key is invoked. If the package option \fx{tracingkeys} is true, undefined keys are highlighted by \fx{\ltxkeysdisablekeys} with a warning message. Because it is possible to mix prefixes and families in \fx{\ltxkeysdisablekeys}, undefined keys may readily be encountered when disabling keys. To see those undefined keys in the transcript file, enable the package option \fx{tracingkeys}. The macro \fx{\ltxkeysgdisablekeys} will disable the given keys globally.
1520
1521 The \unstform+ of \fx{\ltxkeysdisablekeys} and \fx{\ltxkeysgdisablekeys} disable the given keys instantly, while the \stform disable the keys at \hx{\AtBeginDocument}. Authors can use this command to bar users of their keys from calling those keys after a certain point.
1522
1523 For a given key prefix \ang{pref} and family \ang{fam}, you can recall the full list of disabled keys (set up earlier by \fx{\ltxkeysdisablekeys} and/or \fx{\ltxkeysgdisablekeys}) by the command
1524
1525 \start'{macro}[Recalling list of disabled keys]
1526 \|A(pref)@|A(fam)@disabledkeys
1527 \finish{macro}
1528 \aidx*{recalling the list of disabled keys}
1529
1530
1531 \docsection(sec:optionskeys){Option and non-option keys}
1532 \aidxm*{option keys, non-option keys}
1533
1534 Sometimes you want to create keys that can only appear in \hhx{\documentclass,\RequirePackage} or \hx{\usepackage}, and at other times you may not want the user to submit a certain set of keys via these commands. The \pkg'{xwatermark}, for example, uses this concept.
1535
1536 \start+{newmacro}[\ltxkeysoptionkeys,\ltxkeysnonoptionkeys]
1537 \ltxkeysoptionkeys[|A(pref)]{|A(fam)}{|A(keys)}
1538 \ltxkeysoptionkeys|*[|A(pref)]{|A(fam)}{|A(keys)}
1539 \ltxkeysnonoptionkeys[|A(pref)]{|A(fam)}{|A(keys)}
1540 \finish{newmacro}
1541 \fxim*{\ltxkeysoptionkeys,\ltxkeysnonoptionkeys}
1542
1543 Here, \ang{keys} is a comma-separated list of keys to be made option or non-option keys.
1544 Keys listed in \fx{\ltxkeysoptionkeys} can appear only in arguments of \hhx{\documentclass, \RequirePackage} or \hx{\usepackage}, while keys listed in \fx{\ltxkeysnonoptionkeys} can't appear in these macros. The \stform of \fx{\ltxkeysoptionkeys} is equivalent to \fx{\ltxkeysnonoptionkeys}. Only defined keys may appear in \ffx'{\ltxkeysoptionkeys, \ltxkeysnonoptionkeys}.
1545
1546 \start{newmacro}[\ltxkeysmakeoptionkeys]
1547 \ltxkeysmakeoptionkeys[|A(pref)]{|A(fam)}
1548 \ltxkeysmakeoptionkeys|*[|A(pref)]{|A(fam)}
1549 \ltxkeysmakenonoptionkeys[|A(pref)]{|A(fam)}
1550 \finish{newmacro}
1551 \fxim*{\ltxkeysmakeoptionkeys}
1552
1553 The command \fx{\ltxkeysmakeoptionkeys} makes all the keys with prefix \ang{pref} and in family \ang{fam} options keys. The command \fx{\ltxkeysmakenonoptionkeys} does the reverse, \ie, makes the keys non-option keys. The \stform of \fx{\ltxkeysmakeoptionkeys} is equivalent to \fx{\ltxkeysmakenonoptionkeys}.
1554
1555
1556 \docsection(sec:handledkeys)<handled keys>{Handled keys}
1557
1558 As mentioned in \sref{sec:unknownkeyhandler}, handled keys are keys defined in a macro that is key-prefix and key-family dependent. They are defined as a list in a macro so that they can be used for future applications, such as deciding if a observer key of a style key should be defined or redefined on the fly. Handled keys should be defined, or added to, using key prefix, family and key names. You can define or add to handled keys by the following command:
1559
1560 \start{newmacro}[\ltxkeyshandledkeys]
1561 \ltxkeyshandledkeys[|A(pref)]{|A(fam)}{|A(list)}
1562 \finish{newmacro}
1563 \fxim*{\ltxkeyshandledkeys}
1564
1565 where \ang{list} is a comma-separated list of key names. This command can be issued more than once for the same key prefix \ang{pref} and family \ang{fam}, since the content of \ang{list} is usually merged with the existing list rather than being merely added or overwritten. There is also
1566
1567 \start{newmacro}[\ltxkeysaddhandledkeys]
1568 \ltxkeysaddhandledkeys[|A(pref)]{|A(fam)}{|A(list)}
1569 \finish{newmacro}
1570 \fxim*{\ltxkeysaddhandledkeys}
1571
1572 which is just an alias for \fx{\ltxkeyshandledkeys}.
1573
1574 \start{example}[\ltxkeyshandledkeys]
1575 \ltxkeyshandledkeys[KVA,KVB]{fam1,fam2}{keya,keyb,keyc}
1576 \finish{example}
1577
1578 For a given key prefix \ang{pref} and family \ang{fam}, you can recall the full list of handled keys (set up earlier by \fx{\ltxkeyshandledkeys}) by the command
1579
1580 \start'{macro}[Recalling list of handled keys]
1581 \|A(pref)@|A(fam)@handledkeys
1582 \finish{macro}
1583 \aidx*{recalling the list of handled keys}
1584
1585 You can remove handled keys from a given list of handled keys (in a family) by the following command:
1586
1587 \start{newmacro}[\ltxkeysremovehandledkeys]
1588 \ltxkeysremovehandledkeys[|A(pref)]{|A(fam)}{|A(list)}
1589 \finish{newmacro}
1590 \fxim*{\ltxkeysremovehandledkeys}
1591
1592 Rather than remove individual handled keys from a list, you might prefer or need to simply undefine or \quoted{emptify} the entire list of handled keys in a family. You can do these with the following commands:
1593
1594 \start+{newmacro}[\ltxkeysundefhandledkeys,\ltxkeysemptifyhandledkeys]
1595 \ltxkeysundefhandledkeys[|A(pref)]{|A(fam)}
1596 \ltxkeysemptifyhandledkeys[|A(pref)]{|A(fam)}
1597 \finish{newmacro}
1598 \fxim*{\ltxkeysundefhandledkeys,\ltxkeysemptifyhandledkeys}
1599
1600
1601 \docsection(sec:reservedpath){Reserving and unreserving key path or bases}
1602 \aidxm*{reserving key prefix, reserving key family}
1603
1604 By \quoted{key path} we mean the key prefix (default is \fx{KV}), key family (generally no default), and macro prefix (default is dependent on the type of key). You can reserve key path or bases (\ie, bar future users from using the same path or bases) by the following commands. Once a key family or prefix name has been used, it might be useful barring further use of those names. For example, the \pkg'{ltxkeys} has barred users from defining keys with key family \fx{ltxkeys} and macro prefix \fx{ltxkeys}.
1605
1606 \start+{newmacro}[\ltxkeysreservekeyprefix,\ltxkeysreservekeyfamily, etc.]
1607 \ltxkeysreservekeyprefix{|A(list)}
1608 \ltxkeysreservekeyprefix|*{|A(list)}
1609 \ltxkeysreservekeyfamily{|A(list)}
1610 \ltxkeysreservekeyfamily|*{|A(list)}
1611 \ltxkeysreservemacroprefix{|A(list)}
1612 \ltxkeysreservemacroprefix|*{|A(list)}
1613 \finish{newmacro}
1614 \fxim*{\ltxkeysreservekeyprefix,\ltxkeysreservekeyfamily,
1615 \ltxkeysreservemacroprefix}
1616
1617 Here, \ang{list} is a comma-separated list of bases. The \stform+ of these commands will defer reservation to the end of the current package or class, while the \unstform+ will effect the reservation immediately. As the package or class author you may want to defer the reservation to the end of your package or class.
1618
1619 Users can, at their own risk, override reserved key bases simply by issuing the package boolean option \fx{reservenopath}. This can be issued in \hhx{\documentclass,\usepackage} or \fx{\setltxkeysoptions}. This might be too drastic for many users and uses. Therefore, the \pkg'{ltxkeys} also provides the following commands that can be used for selectively unreserving currently reserved key bases:
1620
1621 \start+{newmacro}[\ltxkeysunreservekeyprefix,\ltxkeysunreservekeyfamily, etc.]
1622 \ltxkeysunreservekeyprefix{|A(list)}
1623 \ltxkeysunreservekeyprefix|*{|A(list)}
1624 \ltxkeysunreservekeyfamily{|A(list)}
1625 \ltxkeysunreservekeyfamily|*{|A(list)}
1626 \ltxkeysunreservemacroprefix{|A(list)}
1627 \ltxkeysunreservemacroprefix|*{|A(list)}
1628 \finish{newmacro}
1629 \fxim*{\ltxkeysunreservekeyprefix,\ltxkeysunreservekeyfamily,
1630 \ltxkeysunreservemacroprefix}
1631
1632 The \stform+ of these commands will defer action to the end of the current package or class, while the \unstform+ will undo the reservation immediately.
1633
1634
1635 \docsection(sec:badkeynames)<illegal key name>{Bad key names}
1636
1637 Some key names are indeed inadmissible. The \pkg{ltxkeys} considers the literals in \sref{tab:badkeynames}, among others, as inadmissible for key names:
1638
1639 \begingroup
1640 \settowidth\@tempdima{needvaluekeys}
1641 \edef\colwidth{\the\dimexpr\@tempdima+0mm}
1642 \small
1643 \begin{longtable}[c]{|*{5}{p{\colwidth}|}}
1644 \caption{Default bad key names\xwmlabel{tab:badkeynames}}
1645 \\\hline
1646 \endfirsthead
1647 \multicolumn{4}{|l|}{\emph{Continued from last page}}\\\hline
1648 \endhead
1649 \multicolumn{4}{|r|}{\emph{Continued on next page}}\\\hline
1650 \endfoot
1651 \hline
1652 \endlastfoot
1653 ord & cmd & sty & style & bool \\\hline
1654 choice & ordkey & cmdkey & stylekey & choicekey \\\hline
1655 boolkey & .do & .code & set & setkeys \\\hline
1656 execute & executekeys & executedkeys & handled & handledkeys \\\hline
1657 presetkeys & preset & postsetkeys & postset & rmkeys \\\hline
1658 ifdef & boolean & tog & toggle & switch \\\hline
1659 true & false & on & off & count \\\hline
1660 dimen & skip & toks & savevalue & savevaluekeys \\\hline
1661 xfamilykeys & needvalue & needvaluekeys & usevalue & \\
1662 \end{longtable}
1663 \endgroup
1664
1665 For reasons of efficiency, the \pkg'{ltxkeys} will attempt to catch bad key names only if the package option \fx{tracingkeys} is enabled.
1666
1667 You can add to the list of invalid key names by the following command:
1668
1669 \start+{newmacro}[\ltxkeysbadkeynames,\ltxkeysaddbadkeynames]
1670 \ltxkeysbadkeynames{|A(list)}
1671 \ltxkeysaddbadkeynames{|A(list)}
1672 \finish{newmacro}
1673 \fxim*{\ltxkeysbadkeynames,\ltxkeysaddbadkeynames}
1674
1675 where \ang{list} is a comma-separated list of inadmissible names. The updating is done by merging, so that entries are not repeated in the internal list of bad key names.
1676
1677 You can remove from the list of bad key names by using the following command:
1678
1679 \start{newmacro}[\ltxkeysremovebadkeynames]
1680 \ltxkeysremovebadkeynames{|A(list)}
1681 \finish{newmacro}
1682 \fxim*{\ltxkeysremovebadkeynames}
1683
1684 where, again, \ang{list} is comma-separated. It is not advisable to remove any member of the default bad key names.
1685
1686
1687 \docsection(sec:declareoption){Declaring options}
1688 \aidxm*{class options, package options}
1689
1690 \start+{newmacro}[\ltxkeysdeclareoption,\ltxkeysunknownoptionhandler]
1691 \ltxkeysdeclareoption[|A(pref)]<|A(fam)>{|A(option)}[|A(dft)]{|A(cbk)}
1692 \ltxkeysdeclareoption|*[|A(pref)]<|A(fam)>{|A(cbk)}
1693 \ltxkeysunknownoptionhandler[|A(pref)]<|A(fam)>{|A(cbk)}
1694 \finish{newmacro}
1695 \fxim*{\ltxkeysdeclareoption,\ltxkeysunknownoptionhandler}
1696
1697 The \unstform of \fx{\ltxkeysdeclareoption} is simply a form of \fx{\ltxkeysordkey}, with the difference that the key family \ang{fam} is now optional and, when specified, must be given in angled brackets. The default family name is \quotedhx{\@currname.\@currext}, \ie, the name of the class file or package and its file extension.
1698
1699 The \stform of \fx{\ltxkeysdeclareoption} prescribes the default action to be taken when undefined options with prefix \ang{pref} and in family \ang{fam} are passed to class or package. You may use \fx{\ltxkeyscurrentkey} and \fx{\ltxkeyscurrentvalue} within this macro to pass the unknown option and its value to another class or package or to specify other actions. In fact, you can use \fx{#1} in this macro to represent the current key prefix, \fx{#2} for the current family, \fx{#3} for the current key name, and \fx{#4} for the value of the current key. The command \fx{\ltxkeysunknownoptionhandler} is equivalent to the \stform of \fx{\ltxkeysdeclareoption}.
1700
1701 \ltsnote
1702 The \stform of \fx{\ltxkeysdeclareoption} differs from the starred form of \LaTeX's \hx{\DeclareOption} and the starred form of \pkg'{xkeyval}'s \hx{\DeclareOptionX}.
1703
1704 \start+{example}[\ltxkeysdeclareoption]
1705 \ltxkeysdeclareoption|*[KV]<mypackage>{%
1706 \PackageWarning{mypackage}{%
1707 Unknown option `\ltxkeyscurrentkey' with value `\ltxkeysinnocentvalue' ignored}%
1708 }
1709
1710 \ltxkeysdeclareoption|*{\PassOptionsToClass{#3}{article}}
1711
1712 \ltxkeysunknownoptionhandler[KV]<mypackage>{%
1713 \@expandtwoargs\in@{,#3,}{,\KV@mypackage@handledkeys,}%
1714 \ifin@
1715 |com(The reader may want to investigate what the parameter texts)
1716 |com(##1 and ####1 below stand for:)
1717 \ltxkeysordkey[#1]{#2}{#3}[#4]{\def\x####1{####1xx##1}}%
1718 \else
1719 \PassOptionsToClass{#3}{myclass}%
1720 \fi
1721 }
1722 \finish{example}
1723
1724 See note~\ref{nte:unknownkey} for the meaning of the parameter texts in this example. The contents of the macro \fx{\KV@mypackage@handledkeys} are handled keys for key prefix \fx{KV} and family \fx{fam}. See \sref{sec:handledkeys} for the meaning of handled keys.
1725
1726 \start+{newmacro}[\ltxkeysdeclarecmdoption, \ltxkeysdeclarebooloption, etc]
1727 \ltxkeysdeclareordoption[|A(pref)]<|A(fam)>{|A(option)}[|A(dft)]{|A(cbk)}
1728 \ltxkeysdeclarecmdoption[|A(pref)]<|A(fam)>[|A(mp)]{|A(option)}[|A(dft)]{|A(cbk)}
1729 \ltxkeysdeclarebooloption[|A(pref)]<|A(fam)>[|A(mp)]{|A(option)}[|A(dft)]{|A(cbk)}
1730 \ltxkeysdeclarechoiceoption[|A(pref)]{|A(fam)}[|A(mp)]{|A(option)}[|A(bin)]{|A(alt)}
1731 [|A(dft)]{|A(cbk)}
1732 \finish{newmacro}
1733 \fxim*{\ltxkeysdeclareordoption,\ltxkeysdeclarecmdoption,
1734 \ltxkeysdeclarebooloption,\ltxkeysdeclarechoiceoption}
1735
1736 These are the equivalents of the macros \ffx'{\ltxkeysordkey,\ltxkeyscmdkey, \ltxkeysboolkey, \ltxkeyschoicekey}, respectively, but now the family \ang{fam} is optional (as is \ang{pref}) and, when specified, must be given in angled brackets. The default family name for these new commands is \quotedhx{\@currname.\@currext}, \ie, the current style or class filename and filename extension. \fx{\ltxkeysdeclareordoption} is equivalent to the \unstform of \fx{\ltxkeysdeclareoption}. See the choice keys in \sref{sec:choicekeys} for the meaning of \ang{bin} and \ang{alt} associated with the command \fx{\ltxkeysdeclarechoiceoption}.
1737
1738
1739 \docsubsection(sec:options-sameattributes)
1740 {Options that share the same attributes}
1741
1742 The commands
1743
1744 \start+{macro}
1745 \ltxkeysdeclareordoption
1746 \ltxkeysdeclarecmdoption
1747 \ltxkeysdeclarebooloption
1748 \ltxkeysdeclarechoiceoption
1749 \finish{macro}
1750
1751 can each be used to introduce several options that share the same path or bases (option prefix, option family, and macro prefix) and callback \ang{cbk}. All that is needed is to replace \ang{option} in these commands with the comma-separated list \ang{options}. Because some users might prefer to see these commands in their plural forms when defining several options with the same callback, we have provided the following aliases.
1752
1753 \start+{newmacro}[\ltxkeysdeclarecmdoptions, \ltxkeysdeclarebooloptions, etc]
1754 \ltxkeysdeclareordoptions[|A(pref)]<|A(fam)>{|A(option)}[|A(dft)]{|A(cbk)}
1755 \ltxkeysdeclarecmdoptions[|A(pref)]<|A(fam)>[|A(mp)]{|A(option)}[|A(dft)]{|A(cbk)}
1756 \ltxkeysdeclarebooloptions[|A(pref)]<|A(fam)>[|A(mp)]{|A(option)}[|A(dft)]{|A(cbk)}
1757 \ltxkeysdeclarechoiceoptions[|A(pref)]{|A(fam)}[|A(mp)]{|A(option)}[|A(bin)]{|A(alt)}
1758 [|A(dft)]{|A(cbk)}
1759 \finish{newmacro}
1760 \fxim*{\ltxkeysdeclareordoptions,\ltxkeysdeclarecmdoptions,
1761 \ltxkeysdeclarebooloptions,\ltxkeysdeclarechoiceoptions}
1762
1763
1764 \docsubsection(sec:multitypeoptions){Declaring all types of option with one command}
1765 \aidx*{declaring multiple options}
1766
1767 \start{newmacro}[\ltxkeysdeclaremultitypeoptions]
1768 \ltxkeysdeclaremultitypeoptions[|A(pref)]<|A(fam)>[|A(mp)]{%
1769 |A(keytype)/|A(keyname)/|A(dft)/|A(cbk);
1770 another set of key attributes;
1771 etc.
1772 }
1773 \ltxkeysdeclaremultitypeoptions|*[|A(pref)]<|A(fam)>[|A(mp)]{%
1774 |A(keytype)/|A(keyname)/|A(dft)/|A(cbk);
1775 another set of key attributes;
1776 etc.
1777 }
1778 \finish{newmacro}
1779 \fxim*{\ltxkeysdeclaremultitypeoptions}
1780
1781 Here, the key default value \ang{dft} and callback \ang{cbk} can be absent in all cases. \ang{keytype} may be any one of \fnz{ord,cmd,sty,sty*,bool,choice}. The star (\redstar) in \quoted{sty\Redstar} has the same meaning as in \fx{\ltxkeysstylekey} above, namely, undefined observers will be defined on the fly when the parent key is set. The optional quantity \ang{mp} is the macro prefix, as in, for example, \sref{sec:cmdkeys}. The syntax for the command \fx{\ltxkeysdeclaremultitypeoptions} is identical to that of \fx{\ltxkeysdeclarekeys} except for the following differences: For \fx{\ltxkeysdeclarekeys} the family is mandatory and must be given in curly braces, while for \fx{\ltxkeysdeclaremultitypeoptions} the family is optional, with the default value of \quotedhx{\@currname.\@currext}, \ie, the name of the class file or package and its file extension. For \fx{\ltxkeysdeclaremultitypeoptions}, the optional family is expected to be given in angled brackets. The \stform of the command \fx{\ltxkeysdeclaremultitypeoptions} defines only undefined options. An alias for the long command \fx{\ltxkeysdeclaremultitypeoptions} is \fx{\declaremultitypeoptions}.
1782
1783 \start{example}[\ltxkeysdeclaremultitypeoptions]
1784 \declaremultitypeoptions*[KV]<fam>[mp@]{%
1785 cmd/option1/xx/\def\x##1{##1xx#1};
1786 bool/option2/true;
1787 }
1788 \finish{example}
1789
1790
1791
1792 \docsection(sec:executeoption){Executing options}
1793
1794 \start{newmacro}[\ltxkeysexecuteoptions]
1795 \ltxkeysexecuteoptions[|A(prefs)]<|A(fams)>[|A(na)]{|A(keyval)}
1796 \finish{newmacro}
1797 \fxim*{\ltxkeysexecuteoptions}
1798
1799 This executes/sets the \keyval pairs given in \ang{keyval}. The optional \ang{na} specifies the list of keys (without values) to be ignored. \ang{prefs} is the list of prefixes for the keys; and the optional \ang{fams} signifies families in which the keys suggested in \keyval have been defined. The default value of \ang{fams} is \fx{\@currname.\@currext}. The command \fx{\ltxkeysexecuteoptions} can thus be used to process keys with different prefixes and from several families.
1800
1801
1802 \docsection(sec:processoption){Processing options}
1803
1804 \start{newmacro}[\ltxkeysprocessoptions]
1805 \ltxkeysprocessoptions[|A(prefs)]<|A(fams)>[|A(na)]
1806 \ltxkeysprocessoptions|*[|A(prefs)]<|A(fams)>[|A(na)]
1807 \finish{newmacro}
1808 \fxim*{\ltxkeysprocessoptions}
1809
1810 The command \fx{\ltxkeysprocessoptions} processes the \keyval pairs passed by the user to the class or package. The optional argument \ang{na} can be used to specify keys that should be ignored. The optional argument \ang{fams} can be used to specify the families that have been used to define the keys. The default value of \ang{fams} is \fx{\@currname.\@currext}. The package command \fx{\ltxkeysprocessoptions} doesn't protect expandable macros in the user inputs unless the \pkg'{ltxkeys} is loaded before \hx{\documentclass}, in which case it is also possible to use the command \hx{\XProcessOptions} of the \pkg'{ltxtools}. When used in a class file, the macro \fx{\ltxkeysprocessoptions} will ignore unknown keys or options. This allows the user to use global options in the \hx{\documentclass} command which can be inherinted by packages loaded afterwards.
1811
1812 The \stform of \fx{\ltxkeysprocessoptions} works like the plain variant except that, if the \pkg'{ltxkeys} is loaded after \hx{\documentclass}, it also copies user input from the command \hx{\documentclass}. When the user specifies an option in the \hx{\documentclass} which also exists in the local family or families of the package issuing \fx{\ltxkeysprocessoptions}\Redstar, the local key too will be set. In this case, \fx{#1} in the command \fx{\ltxkeysdeclareoption} (or a similar command) will be the value entered in the \hx{\documentclass} command for this key. First the global options from \hx{\documentclass} will set local keys and afterwards the local options, specified via \hx{\usepackage}, \hx{\RequirePackage} or \hx{\LoadClass}, will set local keys, which could overwrite the previously set global options, depending on the way the options sections are constructed.
1813
1814
1815 \docsubsection(sec:afterprocessoptions)<before processoptions,after processoptions>
1816 {Hooks for `before' and `after' processing options}
1817
1818 \start+{newmacro}[\ltxkeysbeforeprocessoptions,\ltxkeysafterprocessoptions]
1819 \ltxkeysbeforeprocessoptions{|A(code)}
1820 \ltxkeysafterprocessoptions{|A(code)}
1821 \finish{newmacro}
1822 \fxim*{\ltxkeysbeforeprocessoptions,\ltxkeysafterprocessoptions}
1823
1824 The macros \ffx'{\ltxkeysbeforeprocessoptions,\ltxkeysafterprocessoptions} can be used to process an arbitrary code given in \ang{code} before and after \fx{\ltxkeysprocessoptions} has been executed. The command \fx{\ltxkeysafterprocessoptions} is particularly useful when it is required to optionally load a package, with the decision dependent on the state or outcome of an option in the current package. For obvious reasons, \latex's options parser doesn't permit the loading of packages in the options section. The command \fx{\ltxkeysafterprocessoptions} can be used to load packages after the current package's options have been processed. Here is an example for optionally loading some packages at the end of the options section:
1825
1826 \start{example}[\ltxkeysafterprocessoptions]
1827 \ltxkeyscmdkey[KV]{fam}[mp@]{keya}[]{%
1828 \iflacus#1\then\else
1829 \ltxkeysafterprocessoptions{\RequirePackage[#1]{mypackage}}%
1830 \fi
1831 }
1832 \finish{example}
1833
1834 In this example, \fx{#1} refers (as usual) to the user input for key \ttx{keya}. Here, we assume that the values of \ttx{keya} will be the \keyval pairs for options of \texttt{mypackage}. The loading of \texttt{mypackage} will be determined by whether the user input for \ttx{keya} is empty or not. That is why \ttx{keya} has an empty default value. More complex application scenarios can, of course, be easily created\footnote{The command \ftfx{\iflacus}, whose argument is delimited by \ftfx{\then}, tests for emptiness of its argument.}.
1835
1836
1837 \docsection(sec:keycommands)<command keys, environment keys>
1838 {Key commands and key environments}
1839
1840 Key commands and environments are commands and environments that expect \keyval pairs as input, in addition to any number of possible nine conventional arguments. Key commands and environments have already been introduced by the \pkg'{keycommand,skeycommand}, but the inherent robustness of the \pkg{ltxkeys} provides another opportunity to re-introduce these features here. The syntax here is also simpler and the new featureset has the following advantages over those in \pkg'{keycommand,skeycommand}:
1841
1842 \begin{enum}
1843 \item The defined commands and environments can have up to nine conventional parameters, in addition to the \keyval pairs.
1844 \item Anyone or all of the nine command or environment parameters can be delimited.
1845 \item All the various types of key (command keys, boolean keys, \eetc) can be used as the keys for the new command or environment.
1846 \item With the prefixes \ffx'{\ltxkeysglobal,\ltxkeysprotected}\footnote{\ftfx{\ltxkeysrobust} is an alias for \ftfx{\ltxkeysprotected}.}, global and robust key commands and environments can be defined in a manner that simulates \tex's \hx{\global} and \etex's \hx{\protected}.
1847 \item The exit code for the key environment can have access to the arguments of the environment, unlike in \latex's environment.
1848 \item Simple commands are provided for accessing the current values (and, in the case of boolean keys, the current states) of keys.
1849 \end{enum}
1850
1851 The specification of the mandatory arguments and any optional first argument for the key command and key environment has the same syntax as in \latex's \hhx'{\newcommand,\newenvironment}. The key command and key environment of the \pkg'{ltxkeys} have the syntaxes:
1852
1853 \start+{newmacro}[\ltxkeyscommand,\ltxkeysenvironment, etc]
1854 |A(pref)\ltxkeyscommand|A(cs)[|A(narg)][|A(dft)]<|A(delim)>|(|A(keys)|){|A(defn)}
1855 |A(pref)\reltxkeyscommand|A(cs)[|A(narg)][|A(dft)]<|A(delim)>|(|A(keys)|){|A(defn)}
1856 |A(pref)\ltxkeysenvironment{|A(name)}[|A(narg)][|A(dft)]<|A(delim)>|(|A(keys)|){|A(begdefn)}{|A(enddefn)}
1857 |A(pref)\reltxkeysenvironment{|A(name)}[|A(narg)][|A(dft)]<|A(delim)>|(|A(keys)|){|A(begdefn)}{|A(enddefn)}
1858 \finish{newmacro}
1859 \fxim*{\ltxkeyscommand,\reltxkeyscommand,\ltxkeysenvironment,\reltxkeysenvironment,\ltxkeysglobal,
1860 \ltxkeysprotected,\ltxkeysrobust}
1861
1862 Here, \ang{pref} is the optional command prefix, which may be either \fx{\ltxkeysglobal} (for global commands) or \fx{\ltxkeysprotected} (for \etex protected commands); \ang{cs} is the command; \ang{name} is the environment name; \ang{narg} is the number of parameters; \ang{dft} is the default value of the first argument; \ang{delim} are the parameter delimiters; \ang{keys} are the keys to be defined for the command or environment; \ang{defn} is the replacement text of the command; \ang{begdefn} is the environment entry text; and \ang{enddefn} is the code to execute while exiting the environment.
1863
1864 The \ang{keys} have the same syntax as they do for the command \fx{\ltxkeysdeclarekeys} (\sref{sec:declarekeys}). The parameter delimiters \ang{delim}, given above in angled brackets, have the syntax:
1865
1866 \start'{newmacro}[Parameter delimiters]
1867 1|A(delim1) 2|A(delim2) ... 9|A(delim9)
1868 \finish{newmacro}
1869
1870 where \ang{delim1} and \ang{delim2} are the delimiters for the first and second parameters, respectively, etc. Only the parameters with delimiters are to be specified in \ang{delim}. Examples are provided later.
1871
1872 In the \latex \hhx'{\newenvironment,\renewenvironment} commands, with the syntax
1873
1874 \start+{macro}[\newenvironment,\renewenvironment]
1875 \newenvironment{|A(name)}[|A(narg)][|A(dft)]{|A(begdefn)}{|A(enddefn)}
1876 \renewenvironment{|A(name)}[|A(narg)][|A(dft)]{|A(begdefn)}{|A(enddefn)}
1877 \finish{macro}
1878 \hxim*{\newenvironment,\renewenvironment}
1879
1880 the environment's parameters and/or arguments aren't accessible in \ang{enddefn}. If the environment user wants to access the parameters in \ang{enddefn}, he has to save them while still in \ang{begdefn}. This isn't the case with the commands \ffx'{\ltxkeysenvironment,\reltxkeysenvironment}, for which the user can access the environment parameters while in \ang{enddefn}. To do this, he should call the command \fxim{\envarg}, which expects as argument the corresponding numeral of the parameter text. For example, \ffx'{\envarg{1},\envarg{3}} refer to the first and third arguments of the environment, respectively. Examples are provided later. The current values of environment's keys can always be accessed in \ang{enddefn}.
1881
1882 But how do we access the current values or states of keys while in \ang{begdefn} and \ang{enddefn}? To this end the commands \ffx'{\val,\ifval,\ifvalTF,\keyval,\ifkeyval,\ifkeyvalTF} are provided. They have the following syntaxes:
1883
1884 \start+{newmacro}[\val,\ifval,\ifvalTF, etc]
1885 |com(The following commands don't first confirm that the key exists before)
1886 |com(attempting to obtain its current value or state. They are expandable:)
1887 \val{|A(key)}
1888 \ifval|A(boolkey)\then |A(true) \else |A(false) \fi
1889 \ifvalTF{|A(boolkey)}{|A(true)}{|A(false)}
1890
1891 |com(The following commands first confirm that the key exists before attempting)
1892 |com(to obtain its current value or state. They are expandable if the key)
1893 |com(is defined:)
1894 \keyval{|A(key)}
1895 \ifkeyval|A(boolkey)\then |A(true) \else |A(false) \fi
1896 \ifkeyvalTF{|A(boolkey)}{|A(true)}{|A(false)}
1897 \finish{newmacro}
1898 \fxim*{\val,\ifval,\ifvalTF,\keyval,\ifkeyval,\ifkeyvalTF}
1899
1900 The command \fx{\val} yields the current value of a command or environment key, irrespective of the type of key. Its argument should exclude the key-command name, key prefix, key family, and macro prefix. The command \fx{\ifval} expects as argument a boolean key name \ang{boolkey} (without the command name, key prefix, key family, and macro prefix) and yields either \hx{\iftrue} or \hx{\iffalse}. The command \fx{\ifvalTF} expects as argument a boolean key and yields one of two \latex branches, \ang{true} or \ang{false}.
1901
1902 The commands \ffx'{\val,\ifval,\ifvalTF} can be used in expansion contexts (including in \hx{\csname...\endcsname}) but if their arguments aren't defined as keys, they will return an undefined command, either immediately or later. On the hand, their counterparts (namely, the commands \ffx'{\keyval,\ifkeyval,\ifkeyvalTF}) will first check that the key has been defined before attempting to obtain its current value or state. This affects their expandability when a key is undefined. My advice is that the user should always use \ffx'{\keyval,\ifkeyval,\ifkeyvalTF} instead of \ffx'{\val,\ifval,\ifvalTF}, unless he is sure he hasn't committed any mistakes in key's name; but he might be writing a package---that contains these commands---for the use of the \tex community. Also, here there is an advantage in using \hx{\protected@edef} in place of \hx{\edef}: some \latex commands are protected with \hx{\protect}.
1903
1904 The commands \ffx'{\val,\ifval,\ifvalTF, \keyval,\ifkeyval,\ifkeyvalTF}, like the command and environment keys, are available in \ang{defn}, \ang{begdefn} and \ang{enddefn}. These commands (\ie, \ffx'{\val,\ifval,\ifvalTF, \keyval,\ifkeyval,\ifkeyvalTF}) are pushed on entry into \ang{defn} or \ang{begdefn}, and they are popped on exit of \ang{defn} or \ang{enddefn}. Unless they're defined elsewhere outside the \pkg'{ltxkeys}, they're undefined outside \ang{defn}, \ang{begdefn}, \ang{enddefn}, and the environment body.
1905
1906
1907 \docsubsection(sec:eoe){Final tokens of every environment}
1908
1909 The user can add some tokens to the very end of every subsequent environment by declaring those tokens in the macro \fxim{\ltxkeyseveryeoe}, which by default contains only \latex's command \fxi{\ignorespacesafterend}. That is, the \pkg'{ltxkeys} automatically issues
1910
1911 \start{example}[\ltxkeyseveryeoe]
1912 |makered(\ltxkeyseveryeoe){\ignorespacesafterend}
1913 \finish{example}
1914
1915 It is important to note that new tokens are prepended (and not appended) to the internal hook that underlies \fx{\ltxkeyseveryeoe}, such that by default \fx{\ignorespacesafterend} always comes last in the list. You can empty the list \fx{\ltxkeyseveryeoe} by issuing \fx*{\ltxkeyseveryeoe{}} and rebuild it anew, still by prepending elements to it. \fx{\ltxkeyseveryeoe} isn't actually a token list register but it behaves like one\ltsfootnote{However, you can't do \ftfx{\ltxkeyseveryeoe\expandafter{\cmd}} because \ftfx{\ltxkeyseveryeoe} isn't a token list register.}. It is safe to issue \fx{\ltxkeyseveryeoe}\fnu{token} and/or \fx*{\ltxkeyseveryeoe{}} in the \ang{begdefn} part of the key environment. One of the examples in \sref{sec:keycommand-examples} illustrates this point.
1916
1917 \ltsnote
1918 The pointer schemes of \sref{sec:keypointers} are applicable to key commands and key environments. The \fx{\needvalue} pointer is used in one of the examples in \sref{sec:keycommand-examples}.
1919
1920
1921 \docsubsection(sec:keycommand-hooks){Key command and environment hooks}
1922
1923 The commands \ffx'{\ltxkeysinitializekeys, \ltxkeyslaunchkeys} can be used to re-initialize keys to their default values. This avoids creating local groups when setting keys, but these commands will not re-initialize \quoted{option keys} (\ie, keys that are instantiated package or class options). The \pkg'{ltxkeys} deals with this problem via the following hooks.
1924
1925
1926 \start+{newmacro}[\ltxkeysbeforekeycmdsetkeys, etc.]
1927 \ltxkeysbeforekeycmdsetkeys|A(keycmd){|A(code)}
1928 \ltxkeysafterkeycmdsetkeys|A(keycmd){|A(code)}
1929 \ltxkeysafterkeycmdsetkeys|A(keycmd){|A(code)}
1930 \ltxkeysafterkeycmdbody|A(keycmd){|A(code)}
1931 \ltxkeyssavecmdkeyvalues|A(keycmd){|A(keys)}
1932 \ltxkeysrestorecmdkeyvalues|A(keycmd)
1933 \ltxkeyssavelengths{|A(lengths)}
1934 \ltxkeysrestorelengths{|A(lengths)}
1935 \finish{newmacro}
1936 \fxim*{\ltxkeysbeforekeycmdsetkeys,\ltxkeysafterkeycmdsetkeys,
1937 \ltxkeysafterkeycmdsetkeys,\ltxkeysafterkeycmdbody,\ltxkeyssavelengths,
1938 \ltxkeysrestorelengths,\ltxkeyssavecmdkeyvalues,\ltxkeysrestorecmdkeyvalues
1939 }
1940
1941 Here, \ang{code} will be executed at the right instance when \ang{keycmd} is being executed. The command \fx{\ltxkeyssavecmdkeyvalues} will save in a unique stack for the command \fx{keycmd} the current values of all the keys listed in the comma-separated list \ang{keys}. The saved values can be restituted via \fx{\ltxkeysrestorecmdkeyvalues}. This way, the values of the keys can be changed and reinstated without deploying local groups. The commands \ffx'{\ltxkeyssavelengths, \ltxkeysrestorelengths} will, respectively, simply save and reinstate the values of the given lengths (counters, dimensions, and skips).
1942
1943
1944 \docsubsection(sec:keycommand-examples){Examples of key command and environment}
1945
1946 \start+{example}[Key command]
1947 |com(It is possible to use parameter delimiters, as the following)
1948 |com(\@nil and \@mil show:)
1949 |com(\ltxkeysglobal\ltxkeysrobust\ltxkeyscommand*\cmdframebox)
1950 |com( [3][default]<2\@nil 3\@mil>|(|A(keys)|){|A(defn)})
1951
1952 |com(No parameter delimiters for the following:)
1953 \ltxkeysglobal\ltxkeysrobust\ltxkeyscommand*\cmdframebox[3][default]|(%
1954 cmd/width/\textwidth;
1955 cmd/textcolor/black;
1956 cmd/framecolor/red;
1957 cmd/framerule/.4pt;
1958 cmd/framesep/4pt;
1959 bool/putframe/true;
1960 bool/testbool/true;
1961 |){%
1962 \ltxkeyssavelengths{\fboxrule,\fboxsep}%
1963 \fboxrule\keyval{framerule}\relax
1964 \fboxsep\keyval{framesep}\relax
1965 \ifkeyval putframe\then
1966 \fcolorbox{\keyval{framecolor}}{gray!25}{%
1967 \fi
1968 \parbox{\keyval{width}}{%
1969 \color{\keyval{textcolor}}%
1970 Arg-1: #1\\
1971 Arg-2: #2\\
1972 Arg-3: #3%
1973 }%
1974 \ifkeyval putframe\then}\fi
1975 \ifkeyvalTF{testbool}{\def\x{T}}{\def\y{F}}%
1976 \ltxkeysrestorelengths{\fboxrule,\fboxsep}%
1977 }
1978
1979 \begin{document}
1980 \cmdframebox[Text-1]{Text-2\\ ...\\ text-3}{Text-4}|(%
1981 width=.5\textwidth,
1982 framecolor=cyan,
1983 textcolor=purple,
1984 framerule=1pt,
1985 framesep=10pt,
1986 putframe=true
1987 |)
1988 \end{document}
1989 \finish{example}
1990
1991 \start{example}[Key environment]
1992 \ltxkeysenvironment*{testenv}[1][right]|(%
1993 cmd/xwidth/2cm;
1994 cmd/ywidth/1.5cm;
1995 cmd/body;
1996 cmd/|R(\needvalue){author}/\null;
1997 bool/boola/false;
1998 |){%
1999 \ltxkeysiffound{,#1,}\in{,right,left,}\then\else
2000 \@latex@error{Unknown text alignment type `#1'}\@ehd
2001 \fi
2002 \centering
2003 \fbox{\parbox{\keyval{xwidth}}{\usename{ragged#1}\keyval{body}}}%
2004 \ifkeyval boola\then\color{red}\fi
2005 \fbox{\parbox{\keyval{ywidth}}{\usename{ragged#1}\keyval{body}}}%
2006 \normalcolor
2007 |com(\val, \ifval, etc, are unavailable in \ltxkeyseveryeoe. Hence)
2008 |com(we save the value of `author' here:)
2009 \protected@edef\quoteauthor{\val{author}}%
2010 |com(Re-initialize \ltxkeyseveryeoe:)
2011 |R(\ltxkeyseveryeoe){}%
2012 |R(\ltxkeyseveryeoe){\ignorespacesafterend}%
2013 |R(\ltxkeyseveryeoe){\endgraf\vskip\baselineskip
2014 \centerline{\itshape\quoteauthor}}
2015 |com(Just to test parameter use inside \ltxkeysenvironment:)
2016 \def\testmacroa##1{aaa##1}%
2017 }{%
2018 \def\testmacrob##1{##1bbb}%
2019 }
2020
2021 \begin{document}
2022 \begin{testenv}|(%
2023 xwidth=5cm,
2024 ywidth=4cm,
2025 boola=true,
2026 author={Cornelius Tacitus \textup{|(55--120~AD|)}},
2027 body={Love of fame is the last thing even learned men can bear
2028 to be parted from.}
2029 |)
2030 \end{testenv}
2031 \end{document}
2032 \finish{example}
2033
2034 \start+{example}[Key environment]
2035 |com(The following line has parameter delimiters \@nil and \@mil:)
2036 |com(\ltxkeysglobal\ltxkeysrobust\ltxkeysenvironment*{envframebox})
2037 |com( [3][default]<2\@nil 3\@mil>|(|A(defn)|){})
2038
2039 |com(No parameter delimiters for the following:)
2040 |R(\ltxkeysglobal\ltxkeysrobust)\ltxkeysenvironment*{envframebox}[3][default]|(%
2041 cmd/width/\textwidth/\def\xx##1{##1};
2042 cmd/textcolor/black;
2043 cmd/framerule/.4pt;
2044 ord/framecolor/brown;
2045 bool/putframe/true;
2046 |){%
2047 \begingroup
2048 \fboxrule\val{framerule}\relax
2049 \ifval putframe\then\fcolorbox{\val{framecolor}}{gray!25}{\fi
2050 \parbox{\val{width}}{%
2051 Arg-1: #1\\
2052 Arg-2: \textcolor{\val{textcolor}}{#2}\\
2053 Arg-3: #3%
2054 }%
2055 \ifval putframe\then}\fi
2056 \endgroup
2057 }{%
2058 \edef\firstarg{|R(\envarg){1}}%
2059 \def\yy##1{##1}%
2060 }
2061
2062 \begin{document}
2063 \begin{envframebox}[Text-1]{Text-2\\ ...\\ test text-2}{Text-3}|(%
2064 width=.5\textwidth,
2065 textcolor=purple,
2066 framerule=1pt,
2067 putframe=true
2068 |)
2069 \end{envframebox}
2070 \end{document}
2071 \finish{example}
2072
2073
2074 \start+{example}[Nested key environments]
2075 \def\testenv{}
2076 \reltxkeysenvironment{testenv}|(%
2077 |com(The \y below is just a test:)
2078 cmd/fraclen/0.1cm/\def\y##1{#1yyy##1};
2079 cmd/framerule/.4pt;
2080 cmd/framecolor/blue;
2081 cmd/textcolor/black;
2082 bool/putframe/true;
2083 |){%
2084 \ltsdimdef\tempb{.5\textwidth-\val{fraclen}*\currentgrouplevel}%
2085 \noindent
2086 \endgraf\fboxrule=\val{framerule}\relax
2087 \color{\val{framecolor}}%
2088 }{}
2089
2090 \begin{document}
2091 \begin{testenv}|(%
2092 fraclen=0.1cm,
2093 framerule=1.5pt,
2094 framecolor=red,
2095 textcolor=magenta,
2096 putframe=true
2097 |)%
2098 \ifval putframe\then\fbox{\fi
2099 \parbox\tempb{%
2100 \color{\val{textcolor}}%
2101 outer box\endgraf
2102 ***aaa***
2103 \vspace*{5mm}%
2104 \begin{testenv}|(%
2105 fraclen=0.1cm,
2106 framerule=3pt,
2107 framecolor=green,
2108 textcolor=cyan,
2109 putframe=true
2110 |)%
2111 \ifval putframe\then\fbox{\fi
2112 \parbox\tempb{%
2113 \color{\val{textcolor}}%
2114 inner box\endgraf\vspace*{5mm}%
2115 +++bbb+++
2116 }%
2117 \ifval putframe\then}\fi
2118 \end{testenv}%
2119 }%
2120 \ifval putframe\then}\fi
2121 \end{testenv}
2122 \end{document}
2123 \finish{example}
2124
2125 The following example shows that in place of the functions \ffx'{\val,\ifval,\ifvalTF, \keyval,\ifkeyval,\ifkeyvalTF} the user can access the values and states of keys by concatenating the command or environment name, the \quotedfx{@} sign and the name of the key. This, of course, requires that \quotedfx{@} has catcode~11.
2126
2127 \start+{example}[Key command]
2128 \ltxkeyscommand\myframebox[2][default text]|(%
2129 cmd/width/\textwidth;
2130 cmd/textcolor/black;
2131 cmd/framecolor/black;
2132 cmd/framesep/3\p@;
2133 cmd/framerule/0.4\p@;
2134 |com(The following is choice key `textalign' with default value `center'.)
2135 |com(The `.do=' in the admissible values is optional, but not the forward)
2136 |com(slash `/':)
2137 |R(choice/textalign.{%)
2138 |R(center/.do=\def\ttextalign{center},)
2139 |R(left/.do=\def\ttextalign{flushleft},)
2140 |R(right/.do=\def\ttextalign{flushright})
2141 |R(}/center);
2142 bool/putframe/true
2143 |){%
2144 \begingroup
2145 \fboxsep\myframebox@framesep
2146 \fboxrule\myframebox@framerule\relax
2147 \ltsdimdef\myframebox@boxwidth
2148 {\myframebox@width-2\fboxsep-2\fboxrule}%
2149 \noindent\begin{lrbox}\@tempboxa
2150 \begin{minipage}[c][\height][s]\myframebox@boxwidth
2151 \@killglue
2152 \begin\ttextalign
2153 \textcolor{\myframebox@textcolor}{Arg-1: #1\endgraf Arg-2: #2}%
2154 \end\ttextalign
2155 \end{minipage}%
2156 \end{lrbox}%
2157 \@killglue
2158 \color{\myframebox@framecolor}%
2159 \ifmyframebox@putframe\fbox{\fi
2160 \usebox\@tempboxa
2161 \ifmyframebox@putframe}\fi
2162 \endgroup
2163 }
2164
2165 \begin{document}
2166 \myframebox[Text-1]{Test text-2\\ ...\\test text-2}
2167 |(framerule=2pt,framecolor=blue,textcolor=purple,
2168 putframe=true,textalign=right|)
2169 \end{document}
2170 \finish{example}
2171
2172
2173 \docsection(sec:declarevariables)<declarevariables>{Declaring variables}
2174
2175 Sometimes keys are used simply to save values for later use. This can be achieved easily by using the command \fx{\ltxkeysdeclarevariables}.
2176
2177 \start{newmacro}[\ltxkeysdeclarevariables,\ltxkeyssetvarvalues,\ltxkeysgetvarvalue]
2178 \ltxkeysdeclarevariables[|A(namespace)]{%
2179 |A(key-1) = |A(dft-1) = |A(cbk-1), ..., |A(key-n) = |A(dft-n) = |A(cbk-n)
2180 }
2181 \ltxkeyssetvarvalues[|A(namespace)]{|keyval pairs}
2182 \ltxkeysgetvarvalue[|A(namespace)]{|A(key)}
2183 \finish{newmacro}
2184 \fxim*{\ltxkeysdeclarevariables,\ltxkeyssetvarvalues,\ltxkeysgetvarvalue}
2185
2186 Here, \ang{key-i}, \ang{dft-i} and \ang{cbk-i} are key name, key default value, and key callback, respectively, for key \quotedfx{i}. The optional \ang{namespace} is the private namespace for the declared variables and is used to avoid clashes of control sequences.
2187
2188 The key default value \ang{dft} and callback \ang{cbk} are optional and may be missing in the mandatory argument of \fx{\ltxkeysdeclarevariables}.
2189
2190 \start{example}[\ltxkeysdeclarevariables]
2191 \ltxkeysdeclarevariables[mynamespace]{%
2192 var1 = {default value1} = \def\userinput{#1}\def\cmd##1{##1},
2193 |com(No callback:)
2194 var2 = default value2,
2195 |com(No default value and no callback:)
2196 var3
2197 }
2198 \ltxkeyssetvarvalues[mynamespace]{var1=new value1, var2=new value2}
2199 \edef\x{\ltxkeysgetvarvalue[mynamespace]{var1}}
2200
2201 \begin{document}
2202 \ltxkeysgetvarvalue[mynamespace]{var1}
2203 \end{document}
2204 \finish{example}
2205
2206 The private namespace is optional but clashes of control sequences might occur:
2207
2208 \start{example}[\ltxkeysdeclarevariables]
2209 \ltxkeysdeclarevariables{%
2210 var1 = {default value1} = \def\userinput{#1}\def\cmd##1{##1},
2211 |com(No callback:)
2212 var2 = default value2,
2213 |com(No default value and no callback:)
2214 var3
2215 }
2216 \ltxkeyssetvarvalues{var1=new value1, var2=new value2}
2217 \edef\x{\ltxkeysgetvarvalue{var1}}
2218
2219 \begin{document}
2220 \ltxkeysgetvarvalue{var1}
2221 \end{document}
2222 \finish{example}
2223
2224
2225 \docsection(sec:ltxkeys-command){The \headfx{\ltxkeys} command}
2226
2227 \start{newmacro}[\ltxkeys]
2228 \ltxkeys|*|'{|A(code-1) \\ |A(code-2) ... \\ ... |A(code-n)}
2229 \finish{newmacro}
2230 \fxim*{\ltxkeys}
2231
2232 The command \fx{\ltxkeys} simply provides an ungrouped\footnote{Meaning no local groups are created.} environment for using the short forms of the commands shown in \sref{tab:ltxkeys-cmdabbrv}. The abbreviated commands are pushed on entry into \fx{\ltxkeys}, they are then assigned the meaning of their longer counterparts, and then popped (to whatever their original meaning was before entry into \fx{\ltxkeys}) on exist of \fx{\ltxkeys}. The list parser within \fx{\ltxkeys} is invariably \quotedfx{\\}. The list is normalized\footnote{Normalization implies replacing double \quotedfx{\\} by single \quotedfx{\\} and removing spurious spaces around each \quotedfx{\\}.} and the given codes \ang{code-i}, $i=1,...,n$, executed on the consecutive loops. The commands \ffx{\ordkeys,\cmdkeys}, \etcc, can be used to define just one key or multiple keys in the same family and of the same callback. \sref{tab:ltxkeys-cmdabbrv} lists the other abbreviations available within \fx{\ltxkeys}.
2233
2234 The \stform of \fx{\ltxkeys} will expand its argument once before commencing the loop and executing the codes \ang{code-i}, $i=1,...,n$. The \pmform is equivalent to invoking the package option \fx{endcallbackline} before calling \fx{\ltxkeys}. Using both \redstar and \redprime makes \hx{\endlinechar} $-1$ but the effect is not enforced, since in the \stform of \fx{\ltxkeys} the argument has already been read.
2235
2236 \begingroup
2237 \small
2238 \begin{tabularx}{\linewidth}{|p{4.5cm}|p{5.5cm}|}
2239 \caption{Command abbreviations available within \headfx{\ltxkeys}
2240 \xwmlabel{tab:ltxkeys-cmdabbrv}}\\\hline
2241 \rowcolor{pink}
2242 \bf Command & \bf Abbreviation \\\hline
2243 \endfirsthead
2244 \hline
2245 \multicolumn{2}{|l|}{\emph{Continued from last page}}\\\hline
2246 \bf Command & \bf Abbreviation \\\hline
2247 \endhead
2248 \multicolumn{2}{|r|}{\emph{Continued on next page}}\\\hline
2249 \endfoot
2250 \hline
2251 \endlastfoot
2252 \fx{\ordkey} & \fx{\ltxkeysordkey} \\\hline
2253 \fx{\ordkeys} & \fx{\ltxkeysordkeys} \\\hline
2254 \fx{\listkey} & \fx{\ltxkeyslistkey} \\\hline
2255 \fx{\listkeys} & \fx{\ltxkeyslistkeys} \\\hline
2256 \fx{\cmdkey} & \fx{\ltxkeyscmdkey} \\\hline
2257 \fx{\cmdkeys} & \fx{\ltxkeyscmdkeys} \\\hline
2258 \fx{\boolkey} & \fx{\ltxkeysboolkey} \\\hline
2259 \fx{\boolkeys} & \fx{\ltxkeysboolkeys} \\\hline
2260 \fx{\switchkey} & \fx{\ltxkeysswitchkey} \\\hline
2261 \fx{\switchkeys} & \fx{\ltxkeysswitchkeys} \\\hline
2262 \fx{\choicekey} & \fx{\ltxkeyschoicekey} \\\hline
2263 \fx{\choicekeys} & \fx{\ltxkeyschoicekeys} \\\hline
2264 \fx{\stylekey} & \fx{\ltxkeysstylekey} \\\hline
2265 \fx{\stylekeys} & \fx{\ltxkeysstylekeys} \\\hline
2266 \fx{\definekeys} & \fx{\ltxkeysdefinekeys} \\\hline
2267 \fx{\declarekeys} & \fx{\ltxkeysdeclarekeys} \\\hline
2268 \fx{\declareoptions} & \fx{\ltxkeysdeclaremultitypeoptions} \\\hline
2269 \fx{\ifdeclaringkeys}\fx{\then} & \fx{\ifltxkeysdec} \\\hline
2270 \fx{\setkeys} & \fx{\ltxkeyssetkeys}\\\hline
2271 \fx{\setrmkeys} & \fx{\ltxkeyssetrmkeys}\\\hline
2272 \end{tabularx}
2273 \endgroup
2274
2275 \start{example}[\ltxkeys]
2276 \ltxkeys|'{
2277 \switchkeys|+[KV]{fam}[mp@]{keya,keyb}[true]{
2278 \if\@nameuse{mp@\ltxkeyscurrentkey}
2279 \def\xx##1{##1*#1*##1}
2280 \fi
2281 }{%
2282 \keyvalueerror
2283 }
2284 \declarekeys*[KV]{fam}[mp@]{
2285 bool/keyc/true/\def\x##1{##1\\#1\\##1};
2286 cmd/keyd/keyd-default/\def\currval{#1};
2287 }%
2288 \\
2289 |com(Arbitrary code to be executed on its own:)
2290 \def\x##1{x ##1 x}
2291 \\
2292 \setkeys*[KV]{fam}[keyb,keyc]{keya=false,keyb,keyc=false,keyd=yy}
2293 \setrmkeys|*[KV]{fam}[keyc]
2294 }
2295 \finish{example}
2296
2297
2298
2299 \docsection(sec:weirdargs){Keys with argument patterns}
2300
2301 \quoted{Argument pattern} simply means the structure of the arguments that a key's macro expects in order to execute the key's callback. In \pkg'{ltxkeys} it is possible to specify the nature of the parameter pattern for the key macro, but this makes sense only in the case of ordinary (\fx{ord}), command (\fx{cmd}) and style (\fx{sty} or \fx{sty}\Redstar) keys. Boolean and choice keys can't have weird (\ie, multiple or delimited) arguments, since their expected values are restricted: boolean keys must have a value of either \hx{true} or \hx{false}, and choice keys must have \quoted{nominations}, \ie, admissible or alternate values. Therefore, the concept introduced in this section applies only to the following key-definition commands:
2302
2303 \start+{macro}[Key-definition commands that can have argument pattern]
2304 \ltxkeysordkey \ltxkeysnewordkey
2305 \ltxkeysordkeys \ltxkeysnewordkeys
2306 \ltxkeyscmdkey \ltxkeysnewcmdkey
2307 \ltxkeyscmdkeys \ltxkeysnewcmdkeys
2308 \ltxkeysstylekey \ltxkeysnewstylekey
2309 \ltxkeysstylekeys \ltxkeysnewstylekeys
2310 \ltxkeysdefinekeys (only when defining cmd keys)
2311 \ltxkeysdeclarekeys (only when defining ord, cmd, sty keys)
2312 \finish{macro}
2313 \fxi*{\ltxkeysordkey,\ltxkeysnewordkey,\ltxkeysordkeys,\ltxkeysnewordkeys,
2314 \ltxkeyscmdkey,\ltxkeysnewcmdkey,\ltxkeyscmdkeys,\ltxkeysnewcmdkeys,
2315 \ltxkeysstylekey,\ltxkeysnewstylekey,\ltxkeysstylekeys,\ltxkeysnewstylekeys,
2316 \ltxkeysdefinekeys,\ltxkeysdeclarekeys}
2317
2318 When using the \pkg'{xkeyval} it is indirectly possible to submit multiple arguments to a key's macro. Suppose we wish to set the text size, then we can define an ordinary key called \texttt{textsize} as follows:
2319
2320 \start{example}[Key callback with multiple arguments]
2321 \ltxkeysordkey[KV]{fam}{textsize}[{2cm,8cm}]{%
2322 |com(Since `ltxkeys' package preserves outer braces in values of keys,)
2323 |com(first strip any possible outer braces from the key's value:)
2324 \ltsstripallouterbraces{#1}\reserved@a
2325 |com(Test if the key's value contains comma:)
2326 \oifinsetTF{,}{\reserved@a}{%
2327 \def\do##1,##2\@nil{%
2328 \textwidth=##1
2329 \textheight=##2
2330 }%
2331 \expandafter\do\reserved@a\@nil
2332 }{%
2333 \@latex@error{Bad argument for key `textsize'}
2334 {No comma in value of key `textsize'}%
2335 }%
2336 }
2337 \ltxkeyssetkeys[KV]{fam}{textsize={4cm,10cm}}
2338 \finish{example}
2339
2340 With the \pkg'{ltxkeys} this can be achieved directly as follows:
2341
2342 \start{example}[Key callback with multiple arguments]
2343 \ltxkeysordkey[KV]{fam}{textsize}[{2cm,8cm}]{%
2344 |R(\argpattern){#1,#2} \textwidth=#1 \textheight=#2\relax
2345 }
2346 \ltxkeyssetkeys[KV]{fam}{textsize={4cm,10cm}}
2347 \finish{example}
2348
2349 The argument pattern for the key's macro should be specified within the key's callback as the argument of the undefined command \fx{\argpattern}. The token \argpat can be positioned anywhere within the key's callback, provided it isn't enclosed in curly braces. There is no need to delimit the last argument: an internal delimiter is used.
2350
2351 The same principles apply when using the macros \ffx'{\ltxkeysdefinekeys, \ltxkeysdeclarekeys}: simply put \argpat anywhere within the key's callback, but note that it doesn't apply in the case of boolean and choice keys.
2352
2353 \start+{example}[Key callback with multiple arguments]
2354 \ltxkeyscmdkey[KV]{fam}[mp@]{keya}[{default1 and default2}]{%
2355 |R(\argpattern){#1 and #2}\def\z##1{#1xx##1xx#2}
2356 }
2357 \ltxkeyssetkeys[KV]{fam}{keya={arg1 and arg2}}
2358
2359 \ltxkeysdeclarekeys[KV]{fam}[mp@]{%
2360 cmd/keya/{left/right}/|R(\argpattern){#1/#2}\def\xa##1{#1/##1/#2};
2361 bool/keyb/true/\ifmp@keyb\def\xb##1{#1xx##1}\fi;
2362 ord/keye/{x y z w}/|R(\argpattern){#1 #2 #3 #4}\def\xe{#1 #2 #3 #4};
2363 }
2364 \ltxkeyssetkeys[KV]{fam}{keya={value1/value2}, keyc={value1+value2+value3}}
2365 \finish{example}
2366
2367 Caution should be exercised when using \argpat for the observer key of a style key in the case in which the value of the parent key is used as the default for the observer key. The following gives an error because, although \ttx{keya} has two arguments, the macros \ffx'{\parentval, \KV@fam@keya@value} will not be expanded before the callbacks of \ttx{keyb,keyc} are called. Errors will be flagged when initializing (or setting without values) \ttx{keyb,keyc}. Remember that the \stform of \fx{\ltxkeysstylekeys} will define and initialize observer keys on the fly.
2368
2369 \start+{example}[Style key callback with multiple arguments]
2370 \ltxkeysstylekeys|*[KV]{fam}[mp@]{keya}[{left right center}]|(%
2371 ord/keyb/\parentval/|R(\argpattern){#1,#2}\edef\y{\expandcsonce{#1}#2};
2372 ord/keyc/\KV@fam@keya@value/|R(\argpattern){#1,#2}\def\y##1{#1xx##1xx#2};
2373 cmd/keyd/{center}
2374 |){%
2375 |R(\argpattern){#1 #2 #3 #4 #5}\def\x##1{#1xx##1xx#2#3#4#5}
2376 }
2377 \ltxkeyssetkeys[KV]{fam}{keya={arg1 arg2 arg3}}
2378 \finish{example}
2379
2380
2381 \docsection(sec:misc-commands){Some miscellaneous commands}
2382
2383 Some of the macros used internally by the \pkg'{ltxkeys} are available to the user. A few of them are described below.
2384
2385
2386 \docsubsection(sec:trimspaces){Trimming leading and trailing spaces}
2387
2388 \start+{newmacro}[\ltxkeyshardtrimspaces,\ltxkeyssimpletrimspaces, etc.]
2389 \ltxkeyssimpletrimspaces{|A(token)}|A(cs)
2390 \ltxkeyshardtrimspaces{|A(token)}|A(cs)
2391 \ltxkeyscurrtrimspaces{|A(token)}|A(cs)
2392 \ltxkeysusesimpletrimspaces
2393 \ltxkeysusehardtrimspaces
2394 \ltxkeystrimspacesincs|A(cs)
2395 \ltxkeystrimspacesset
2396 \ltxkeystrimspacesincsset
2397 \finish{newmacro}
2398 \fxim*{\ltxkeyshardtrimspaces,\ltxkeyssimpletrimspaces,
2399 \ltxkeyscurrtrimspaces,\ltxkeystrimspacesincs,\ltxkeysusesimpletrimspaces,
2400 \ltxkeysusehardtrimspaces,\ltxkeystrimspacesset,\ltxkeystrimspacesincsset}
2401
2402 The command \fx{\ltxkeyshardtrimspaces} trims (\ie, removes) all the leading and trailing spaces around \ang{token} and returns the result in the macro \ang{cs}. Forced (\ie, explicit) leading and trailing spaces around \ang{token} are removed unless they are enclosed in braces. This command comes with a small price: it mildly slows down processing, especially when tracing commands. The command \fx{\ltxkeyssimpletrimspaces} trims only one leading and one trailing space; it doesn't iterate. Forced spaces are rare, but for fear of the unknown, the default space-trimming function is \fx{\ltxkeyshardtrimspaces}. The commands \ffx'{\ltxkeysusesimpletrimspaces, \ltxkeysusehardtrimspaces} allow the user to toggle \fx{\ltxkeyscurrtrimspaces} between \quoted{hard} and \quoted{simple}.
2403
2404 The command \fx{\ltxkeystrimspacesincs} trims the leading and trailing spaces around the token in the macro \ang{cs} and returns the result in \ang{cs}. It calls \fx{\ltxkeyscurrtrimspaces}.
2405
2406
2407 \docsubsection(sec:checkchoice){Checking user inputs}
2408
2409 \start+{newmacro}[\ltxkeyscheckchoice,\ltxkeyscheckinput,\ltxkeyscheckuserinput]
2410 \ltxkeyscheckchoice[|A(parser)]|(|A(val)|A(order)|){|A(input)}{|A(nomin)}{|A(true)}
2411 \ltxkeyscheckchoice|*[|A(parser)]|(|A(val)|A(order)|){|A(input)}{|A(nomin)}{|A(true)}
2412 \ltxkeyscheckchoice|+[|A(parser)]|(|A(val)|A(order)|){|A(input)}{|A(nomin)}{|A(true)}{|A(false)}
2413 \ltxkeyscheckchoice|*|+[|A(parser)]|(|A(val)|A(order)|){|A(input)}{|A(nomin)}{|A(true)}{|A(false)}
2414 \ltxkeyscheckinput{|A(input)}{|A(nomin)}{|A(true)}{|A(false)}
2415 \ltxkeyscheckuserinput{|A(input)}{|A(nomin)}
2416 \finish{newmacro}
2417 \fxim*{\ltxkeyscheckchoice,\ltxkeyscheckinput,\ltxkeyscheckuserinput,
2418 \ltxkeyscommacheckchoice}
2419
2420 The command \fx{\ltxkeyscheckchoice} is a re-implementation of \pkg'{xkeyval}'s command \fx{\XKV@checkchoice} so as to accept arbitrary list parser \ang{parser} and for more robustness. It checks the user input \ang{input} against the list of nominations \ang{nomin}. If the input is valid, the user input is returned in \ang{val} and the numerical order (starting from zero) of the input in the nominations is returned in \ang{order}\footnote{The functions \ang{val} and \ang{order} are user-supplied macros.}. If the input isn't valid, the user input is still returned in \ang{val}, but $-1$ is returned in \ang{order}. \ang{parser} is the list parser. The \stform of \fx{\ltxkeyscheckchoice} will convert \ang{input} into lowercase before checking it against the nominations. The \plform of \fx{\ltxkeyscheckchoice} expects two branches (\ang{true} and \ang{false}) of callback at the end of the test. The \unplform expects only one branch (\ang{true}) and will return error if the input is invalid\footnote{There is also \ftfx{\ltxkeyscommacheckchoice}, whose parser is implicitly \qcomma and does not need to be given by the user.}.
2421
2422 The commands \ffx'{\ltxkeyscheckinput,\ltxkeyscheckuserinput} apply to comma-separated lists of nominations \ang{nomin} and they always convert \ang{input} to lowercase before checking it against the nominations \ang{nomin}. The macro \fx{\ltxkeyscheckinput} expects two branches of callback, while \fx{\ltxkeyscheckuserinput} expects no callback. Instead, \fx{\ltxkeyscheckuserinput} will toggle the internal boolean \fx{\ifltxkeysinputvalid} to \hx{true} if the input is valid, and to \hx{false} otherwise. The internal boolean \fx{\ifltxkeysinputvalid} could then be called by the user after the test.
2423
2424
2425 \docsubsection(sec:ifinset){Does a test string exist in a string?}
2426
2427 \start+{newmacro}[\ltxkeysin,\ltxkeysiffound]
2428 \ltxkeysin{|A(teststr)}{|A(str)}
2429 \ltxkeysin|*{|A(teststr)}{|A(str)}{|A(true)}{|A(false)}
2430 \ltxkeysiffound|A(teststr)|R(\in)|A(str)|R(\then) |A(true) \else |A(false) \fi
2431 \finish{newmacro}
2432 \fxim*{\ltxkeysin,\ltxkeysiffound}
2433
2434 The \unstform of the command \fx{\ltxkeysin} is identical with \usecsn{latex2e} kernel's (2011/06/27) \hx{\in@}. The command \hx{\in@} tests for the presence of \ang{teststr} in \ang{str} and returns the boolean \hx{\ifin@} as \hx{\iftrue} or \hx{\iffalse}. The \stform of \fx{\ltxkeysin} returns two \latex branches \ang{true} and \ang{false}. On the other hand, the command \fx{\ltxkeysiffound} requires the first argument to be delimited by \fx{\in} and the second argument by \fx{\then}.
2435
2436 \start{example}[\ltxkeysiffound]
2437 \ltxkeysiffound xx\in aax\then \def\x{T}\else \def\x{F}\fi
2438 \finish{example}
2439
2440 \ltsnote
2441 The command \fx{\ltxkeysiffound} trims leading and trailing spaces around the tokens \ang{teststr} and \ang{str} before the test! The commands \ffx'{\ltxkeysin,\ltxkeysiffound} aren't expandable.
2442
2443
2444 \docsubsection(sec:ifpattern){Does a given pattern exist in the meaning of a macro?}
2445
2446 \start{newmacro}[\ltxkeysifpattern]
2447 \ltxkeysifpattern{|A(teststr)}|A(cmd){|A(true)}{|A(false)}
2448 \finish{newmacro}
2449 \fxim*{\ltxkeysifpattern}
2450
2451 The command \fx{\ltxkeysifpattern} simply determines if the meaning of \ang{cmd} contains \ang{teststr}. It returns \ang{true} if \ang{teststr} is found in the meaning of \ang{cmd}, and \ang{false} otherwise.
2452
2453
2454 \docsubsection(sec:ltxkeysifcase)
2455 {\ltsneverexpand{\ttcl{texcolor}{\bs ifcase}} for arbitrary strings}
2456
2457 \start+{newmacro}[\ltxkeysifcase,\ltxkeysfindmatch]
2458 \ltxkeysifcase{|A(teststr)}{%
2459 |A(case-1):|A(cbk-1),...,|A(case-n):|A(cbk-n)}{|A(true)}{|A(false)}
2460
2461 \ltxkeysfindmatch{|A(teststr)}{|A(case-1):|A(cbk-1),...,|A(case-n):|A(cbk-n)}{|A(fn)}
2462 \finish{newmacro}
2463 \fxim*{\ltxkeysifcase,\ltxkeysfindmatch}
2464
2465 The command \fx{\ltxkeysifcase} tests \ang{teststr} against \ang{case-i}. If a match is found, the \ang{case-i}'s callback \ang{cbk-i} is returned in the macro \fx{\currmatch} and \ang{true} is executed. If at the end of the loop no match is found, \fx{\ltxkeysifcase} returns empty \fx{\currmatch} and executes \ang{false}.
2466
2467 The command \fx{\ltxkeysfindmatch} works like \fx{\ltxkeysifcase} but executes the fallback \ang{fn} (instead of \ang{true} or \ang{false}) when no match is found.
2468
2469 Because of the need to return \fx{\currmatch}, the macros \ffx'{\ltxkeysfindmatch,\ltxkeysifcase} are not expandable. The expandable variant of these commands is \fx{\ltxkeysifcasse}, which can be used to test with an arbitrary boolean (\quoted{true-or-false outcome}) operator \ang{testoper}.
2470
2471 \start{newmacro}[\ltxkeysifcasse]
2472 \ltxkeysifcasse|A(testoper){|A(teststr)}
2473 {|A(case-1)}\do{|A(cbk-1)}
2474 ...
2475 |A(case-n)\do{|A(cbk-n)}
2476 \ifnone
2477 \do{|A(nomatch)}
2478 \endif
2479 \finish{newmacro}
2480 \fxim*{\ltxkeysifcasse}
2481
2482 Here, \ang{nomatch} is returned when the test fails in all cases. For the sake of speed optimization, there is a restriction in the use of the command \fx{\ltxkeysifcasse}. When testing with numbers or dimensions, the braces around the test tokens are vital, and the tokens \fx{\ifnone\do{}\endif} must always be present, irrespective of the type of test. In this regard, the commands \ffx'{\ltsifcasse,\ltsdocasse} of the \pkg'{ltxtools} are more versatile, if somewhat less fast.
2483
2484 \start{example}[\ltxkeysifcasse]
2485 \edef\x{%
2486 \ltxkeysifcasse\ifcassedimcmpTF{1pt+2pt+3pt}
2487 {=2pt}\do{equal to 2pt}
2488 {<3pt}\do{less than 3pt}
2489 {>4pt}\do{greater than 4pt}
2490 \ifnone
2491 \do{no match}
2492 \endif
2493 }
2494 \edef\x{%
2495 \ltxkeysifcasse\ifcassenumcmpTF{1+2+3}
2496 {=2}\do{equal to 2}
2497 {<3}\do{less than 3}
2498 \ifnone
2499 \do{no match}
2500 \endif
2501 }
2502 \edef\x{%
2503 \ltxkeysifcasse\ifstrcmpTF{x}
2504 {a}\do{\def\y{a}}
2505 {b}\do{\def\y{b}}
2506 {c}\do{\def\y{c}}
2507 \ifnone
2508 |com(The \do must always be there, even when the |A(nomatch) is empty:)
2509 \do{}
2510 \endif
2511 }
2512
2513 \begin{document}
2514 \ltxkeysifcasse\ifstrcmpTF{x}
2515 {a}\do{\def\y{a}}
2516 {b}\do{\def\y{b}}
2517 {c}\do{\def\y{c}}
2518 \ifnone
2519 \do{\def\y{no match}}
2520 \endif
2521 \end{document}
2522 \finish{example}
2523
2524
2525 \docsubsection(sec:ifincsvlist){Is the number of elements from a sublist found in a csv list $\ge n$?}
2526
2527 \start{newmacro}[\ltxkeysifincsvlistTF]
2528 \ltxkeysifincsvlistTF[A(parser)]|(|A(nr)|){|A(sub)}{|A(main)}{|A(true)}{|A(false)}
2529 \ltxkeysifincsvlistTF|*[A(parser)]|(|A(nr)|){|A(sub)}{|A(main)}{|A(true)}{|A(false)}
2530 \finish{newmacro}
2531 \fxim*{\ltxkeysifincsvlistTF}
2532
2533 The command \fx{\ltxkeysifincsvlistTF} checks if the number of elements of \ang{parser}-separated (csv) list \ang{sub} found in \ang{main} is equal or greater than \ang{nr}. The argument \ang{main} is the main list and \ang{sub} is the sublist of test strings. Normally, \ang{sub} will be a user input and \ang{main} the list of nominations. Neither \ang{main} nor \ang{sub} is expanded in the test. If the test is true, \fx{\ltxkeysitemspresent} returns all the elements found, \fx{\ltxkeysnritems} returns the number of elements found, and \ang{true} is executed. If the test fails, \fx{\ltxkeysitemspresent} returns empty, \fx{\ltxkeysnritems} returns $-1$, and \ang{false} is executed. The \stform of \fx{\ltxkeysifincsvlistTF} will turn both input and nominations to lowercase before the test. The default values of the optional list \ang{parser} and the optional number of elements to find \ang{nr} are \qcomma and $1$, respectively.
2534
2535
2536 \docsubsection(sec:ifintsvlist){Is the number of elements from a sublist found in a tsv list $\ge n$?}
2537
2538 \start{newmacro}[\ltxkeysifintsvlistTF]
2539 \ltxkeysifintsvlistTF|(|A(nr)|){|A(sub)}{|A(main)}{|A(true)}{|A(false)}
2540 \ltxkeysifintsvlistTF|*|(|A(nr)|){|A(sub)}{|A(main)}{|A(true)}{|A(false)}
2541 \finish{newmacro}
2542 \fxim*{\ltxkeysifintsvlistTF}
2543
2544 The command \fx{\ltxkeysifintsvlistTF} checks if the number of elements of nonparser-separated (tsv) list \ang{sub} found in \ang{main} is equal or greater than \ang{nr}. The argument \ang{main} is the main list and \ang{sub} is the sublist of test strings. Normally, \ang{sub} will be a user input and \ang{main} the list of nominations. Neither \ang{main} nor \ang{sub} is expanded in the test. If the test is true, \fx{\ltxkeysitemspresent} returns all the elements found, \fx{\ltxkeysnritems} returns the number of elements found, and \ang{true} is executed. If the test fails, \fx{\ltxkeysitemspresent} returns empty, \fx{\ltxkeysnritems} returns $-1$, and \ang{false} is executed. The \stform of \fx{\ltxkeysifintsvlistTF} will turn both input and nominations to lowercase before the test.
2545
2546 Normally, tsv-matching requires that the test strings in \ang{sub} are unique in the nominations \ang{main}. Some caution is, therefore, necessary when dealing with tsv lists.
2547
2548
2549 \docsubsection(sec:ifeltcount)
2550 {Is the number of elements in a csv list $\ge n$ or $\le n$?}
2551
2552 \start{newmacro}[\ltxkeysifeltcountTF]
2553 \ltxkeysifeltcountTF[|A(parser)]|(|A(rel)|){|A(nr)}{|A(list)}{|A(true)}{|A(false)}
2554 \ltxkeysifeltcountTF|*[|A(parser)]|(|A(rel)|){|A(nr)}{|A(listcmd)}{|A(true)}{|A(false)}
2555 \finish{newmacro}
2556 \fxim*{\ltxkeysifeltcountTF}
2557
2558 The command \fx{\ltxkeysifeltcountTF} checks if the number of elements in \ang{parser}-separated list \ang{list} has relation \ang{rel} ($>=<$) with number \ang{nr}. If the test is true, \ang{true} is executed, otherwise \ang{false} is executed. The \stform of \fx{\ltxkeysifeltcountTF} will expand \ang{listcmd} once before the test. Double parsers and empty entries in \ang{list} are ignored. The default values of the optional list \ang{parser} and the optional relational type \ang{rel} are \qcomma and \quoted{$=$}, respectively. The number \ang{nr} is a mandatory argument.
2559
2560 The following example returns \ang{false} (\ie, \fx{\meaning\x -> F}).
2561
2562 \start{example}[\ltxkeysifeltcountTF]
2563 \ltxkeysifeltcountTF[;]|(<|){2}{a;b;c}{\def\x{T}}{\def\x{F}}
2564 \finish{example}
2565
2566
2567 \docsubsection(sec:getorder){What is the numerical order of an element in a csv list?}
2568
2569 \start{newmacro}[\ltxkeysgetorder]
2570 \ltxkeysgetorder[|A(parser)]{|A(elt)}{|A(list)}
2571 \ltxkeysgetorder|*[|A(parser)]{|A(elt)}{|A(listcmd)}
2572 \finish{newmacro}
2573 \fxim*{\ltxkeysgetorder,\ltxkeysorder}
2574
2575 The command \fx{\ltxkeysgetorder} returns in \fx{\ltxkeysorder} the numerical order of \ang{elt} in \ang{parser}-separated \ang{list} or \ang{listcmd}. The value of \fx{\ltxkeysorder} is the numerical order of the first match found. The count starts from zero ($0$). The \stform will expand \ang{listcmd} once before commencing the search for \ang{elt}. If no match is found, \fx{\ltxkeysorder} returns $-1$, which can be used for taking further decisions.
2576
2577
2578 \docsubsection(sec:list-normalization){List normalization}
2579
2580 \start+{newmacro}[\ltxkeyscommanormalize,\ltxkeyskvnormalize]
2581 \ltxkeyscommanormalize{|A(list)}|A(cmd)
2582 \ltxkeyscommanormalizeset{{|A(list-1)}|A(cmd-1),...,{|A(list-n)}|A(cmd-n)}
2583 \ltxkeyskvnormalize{|A(list)}|A(cmd)
2584 \ltxkeyskvnormalizeset{{|A(list-1)}|A(cmd-1),...,{|A(list-n)}|A(cmd-n)}
2585 \finish{newmacro}
2586 \fxim*{\ltxkeyscommanormalize,\ltxkeyscommanormalizeset,
2587 \ltxkeyskvnormalize,\ltxkeyskvnormalizeset}
2588
2589 These commands will normalize the comma-separated \ang{list} (or \ang{list-i}) and return the result in \ang{cmd} (or \ang{cmd-i}). For the command \fx{\ltxkeyskvnormalize}, \ang{list} is assumed to be a list of \keyval pairs. Normalization implies changing the category codes of all the active commas to their standard values, as well as trimming leading and trailing spaces around the elements of the list and removing consecutive multiple commas. Thus empty entries that are not enforced by curly braces are removed. Besides dealing with multiple commas and the spaces between entries, the command \fx{\ltxkeyskvnormalize} removes spaces between keys and the equality sign, and multiple equality signs are made only one. Further, the category codes of comma and the equality sign are made normal throughout the list.
2590
2591
2592 \docsubsection(sec:listparse){Parsing arbitrary csv or kv list}
2593
2594 \start{newmacro}[\ltxkeysdocsvlist,\ltxkeysdokvlist, etc.]
2595 \ltxkeysdocsvlist[|A(parser)]{|A(list)}
2596 \ltxkeysdocsvlist|*[|A(parser)]{|A(listcmd)}
2597 \ltxkeysparsecsvlist[|A(parser)]{|A(list)}
2598 \ltxkeysparsecsvlist|*[|A(parser)]{|A(listcmd)}
2599 \ltxkeysdokvlist[|A(parser)]{|A(list)}
2600 \ltxkeysdokvlist|*[|A(parser)]{|A(listcmd)}
2601 \ltxkeysparsekvlist[|A(parser)]{|A(list)}
2602 \ltxkeysparsekvlist|*[|A(parser)]{|A(listcmd)}
2603 \finish{newmacro}
2604 \fxim*{\ltxkeysdocsvlist,\ltxkeysparsecsvlist,\ltxkeysdokvlist,\ltxkeysparsekvlist}
2605
2606 The unexpandable command \fx{\ltxkeysdocsvlist} is the list processor for the \pkg'{ltxkeys}. It can process both arbitrary \ang{parser}-separated lists and \keyval pairs. It can also be nested to any level, and it keeps each nesting-level independent. The default value of the optional list-item separators \ang{parser} is \qcomma. The list normalizer for \fx{\ltxkeysdocsvlist} is \pkg'{ltxtools}'s \fx{\csv@@normalize}, which can deal with arbitrary list parsers/separators. The \ang{flag}, which must lie in the range $(0,3)$, determines the type of processing that is required. The admissible values of \ang{flag} and their meaning are given in \sref{tab:parser-flags}. The macro \fx{\ltxkeysdocsvlist} loops over the given \ang{parser}-separated \ang{list} and execute the user-defined, one-parameter command \fx{\ltxkeysdo} for every item in the list, passing the item as an argument and preserving outer braces. The default value of \ang{parser} is \qcomma. The \stform of \fx{\ltxkeysdocsvlist} will expand \ang{listcmd} once before commencing the loop.
2607
2608 Here are some points to note about the list processor \fx{\ltxkeysdocsvlist}:
2609 \begin{enum}
2610 \item If an item contains \ang{parser}, it must be wrapped in curly braces when calling the command \fx{\ltxkeysdocsvlist}, otherwise the elements may be mixed up during parsing. The braces will persist thereafter, but will of course be removed during printing (if the items are printed).
2611 \item White spaces before and after the list separator are always ignored by the normalizer called by \fx{\ltxkeysdocsvlist}. If an item contains \ang{parser} or starts with a space, it must, therefore, be wrapped in curly braces before calling \fx{\ltxkeysdocsvlist}.
2612 \item Since when \ang{flag} is $0$ or $2$ the command \fx{\ltxkeysdocsvlist} doesn't call the normalizer, in this case it does preserve outer/surrounding spaces in the entries. Empty entries in \ang{list} or \ang{listcmd} will be processed by \fx{\ltxkeysdocsvlist} if the boolean \fx{\ifltxkeysuseempty} is true. You may thus issue \fx{\ltxkeysuseemptytrue} before calling \fx{\ltxkeysdocsvlist}. The ability to parse empty entries is required by packages that use empty key prefixes, and/or families\footnote{The use of empty key prefixes, families and paths is, in general, not advisable.}. \fx{\ifltxkeysuseempty} is false by default, and its state is nesting-level observer.
2613 \item The command \fx{\ltxkeysdocsvlist} can be nested to any level and can be mixed with other looping macros.
2614 \item In the command \fx{\ltxkeysdocsvlist}, it is always possible to break out of the loop prematurely at any level of nesting, simply by issuing the command \fx{\ltxkeysbreakloop}\footnote{The command \fx{\ltxkeysbreakloop} may be called within the loop to terminate the loop prematurely. The unprocessed items of the list will be handled by the command \fx{\ltxkeysdoremainder}, which can be redefined by the user. By default, it is defined as the \latex kernel's \hx{\@gobble}, meaning that it simply throws away the list remainder. The command \fx{\ltxkeyslistbreak} may also be inserted as a list item to break out of the loop prematurely. The commands \ffx'{\ltxkeysbreakloop, \ltxkeyslistbreak} have different syntax and semantics.}. Breaking an inner loop doesn't affect the continuation of the outer loop, and vice versa: loop break is nesting-level observer.
2615 \item The argument of the one-parameter command \fx{\ltxkeysdo} can be passed to a multi-parameter command, or to a command that expects delimited arguments.
2616 \end{enum}
2617
2618
2619 \docsubsection(sec:sisolist){Parsing nsv/tsv list}
2620
2621 \start{newmacro}[\ltxkeysdosisolist]
2622 \ltxkeysdosisolist[|A(parser)]{|A(list)}
2623 \ltxkeysdosisolist|*[|A(parser)]{|A(listcmd)}
2624 \finish{newmacro}
2625 \fxim*{\ltxkeysdosisolist}
2626
2627
2628
2629 \docsubsection(sec:removeelements){Remove one or all occurrences of elements from a csv list}
2630
2631 \start{newmacro}[\ltxkeysremoveelements]
2632 \ltxkeysremoveelements[|A(parser)]|(|A(nr)|)|A(listcmd){|A(sublist)}{|A(fd)}{|A(nf)}
2633 \ltxkeysremoveelements|*[|A(parser)]|(|A(nr)|)|A(listcmd){|A(sublist)}{|A(fd)}{|A(nf)}
2634 \finish{newmacro}
2635 \fxim*{\ltxkeysremoveelements}
2636
2637 The command \fx{\ltxkeysremoveelements} removes \ang{nr} number of each element of \ang{sublist} from \ang{listcmd}. The default values of the optional list \ang{parser} and the optional maximum number of elements to remove \ang{nr} are \qcomma and $1$, respectively. If at least one member of \ang{sublist} is found and removed from \ang{listcmd}, then the callback \ang{fd} is returned and executed, otherwise \ang{nf} is returned. Both \ang{fd} and \ang{nf} provide some fallback following the execution of \fx{\ltxkeysremoveelements}. The challenge to the user is to remember that the command \fx{\ltxkeysremoveelements} requires these callbacks, which may both be empty. The \stform of \fx{\ltxkeysremoveelements} will remove from \ang{listcmd} all the members of \ang{sublist} found irrespective of the value of \ang{nr}. The optional \ang{nr} is therefore redundant when the \stform of \fx{\ltxkeysremoveelements} is called. Here, \ang{sublist} is simply \ang{parser}-separated.
2638
2639 \start{example}[\ltxkeysremoveelements]
2640 \def\xx{a;b;c;d;d;e;f;c;d}
2641 |com(Remove at most 2 occurrences of `c' and `d' from \xx:)
2642 \ltxkeysremoveelements[;]|(2|)\xx{c;d}{\def\x{done}}{\def\x{nil found}}
2643 |com(Remove all occurrences of `c' and `d' from \xx:)
2644 \ltxkeysremoveelements|*[;]\xx{c;d}{\def\x{done}}{\def\x{nil found}}
2645 \finish{example}
2646
2647
2648 \docsubsection(sec:replaceelements){Replace one or all occurrences of elements in a csv list}
2649
2650 \start{newmacro}[\ltxkeysreplaceelements]
2651 \ltxkeysreplaceelements[|A(parser)]|(|A(nr)|)|A(listcmd){|A(sublist)}{|A(fd)}{|A(nf)}
2652 \ltxkeysreplaceelements|*[|A(parser)]|(|A(nr)|)|A(listcmd){|A(sublist)}{|A(fd)}{|A(nf)}
2653 \finish{newmacro}
2654 \fxim*{\ltxkeysreplaceelements}
2655
2656 The command \fx{\ltxkeysreplaceelements} replaces \ang{nr} number of each element of \ang{sublist} in \ang{listcmd}. The default values of the optional list \ang{parser} and the optional maximum number of elements to replace \ang{nr} are \qcomma and $1$, respectively. If at least one member of \ang{sublist} is found and replaced in \ang{listcmd}, then the callback \ang{fd} is returned and executed, otherwise \ang{nf} is returned. Both \ang{fd} and \ang{nf} provide some fallback following the execution of \fx{\ltxkeysreplaceelements}. The challenge to the user is to remember that the command \fx{\ltxkeysreplaceelements} requires these callbacks, which may both be empty. The \stform of \fx{\ltxkeysreplaceelements} will replace in \ang{listcmd} all the members of \ang{sublist} found irrespective of the value of \ang{nr}. The optional \ang{nr} is therefore redundant when the \stform of \fx{\ltxkeysreplaceelements} is used. Here, the syntax of \ang{sublist} is as follows:
2657
2658 \start'{macro}[Sublist for \ltxkeysreplaceelements]
2659 {{|A(old-1)}{|A(new-1)}|A(parser)...|A(parser){|A(old-n)}{|A(new-n)}}
2660 \finish{macro}
2661
2662 where \ang{old-i} is the element to be replaced and \ang{new-i} is its replacement.
2663
2664 \start{example}[\ltxkeysreplaceelements]
2665 \def\xx{a;b;c;d;d;e;f;c;d}
2666 |com(Replace at most 2 occurrences of `c' and `d' in \xx with `s' and `t',)
2667 |com(respectively:)
2668 \ltxkeysreplaceelements[;]|(2|)\xx{c{s};d{t}}{\def\x{done}}{\def\x{nil found}}
2669 |com(Replace all occurrences of `c' and `d' in \xx with `s' and `t':)
2670 \ltxkeysreplaceelements|*[;]\xx{c{s};d{t}}{\def\x{done}}{\def\x{nil found}}
2671 \finish{example}
2672
2673
2674 \docsubsection(sec:stripbraces){Stripping outer braces}
2675
2676 The list and key parsers of the \pkg'{ltxkeys} preserve outer braces, but sometimes it is needed to rid a token of one or more of its outer braces. This can be achieved by the following commands:
2677
2678 \start+{newmacro}[\ltxkeysstripNouterbraces, \ltxkeysstripallouterbraces, etc.]
2679 \ltxkeysstripNouterbraces|A(nr){|A(token)}
2680 \ltxkeysstripallouterbraces{|A(token)}
2681 \ltxkeysstripallouterbracesincs{|A(cmd)}
2682 \finish{newmacro}
2683 \fxim*{\ltxkeysstripNouterbraces,
2684 \ltxkeysstripallouterbraces,\ltxkeysstripallouterbracesincs}
2685
2686 The command \fx{\ltxkeysstripNouterbraces} strips \ang{nr} number of outer braces from \ang{token}. The command \fx{\ltxkeysstripallouterbraces} strips all outer braces from \ang{token}. The command \fx{\ltxkeysstripallouterbracesincs} strips all the outer braces in the top content of the command \ang{cmd}. All these commands are expandable. Normally, \ang{token} wouldn't be expanded by these commands in the process of stripping off outer braces.
2687
2688 \start+{example}[\ltxkeysstripNouterbraces,\ltxkeysstripallouterbraces, etc.]
2689 \toks@\expandafter\expandafter\expandafter
2690 {\ltxkeysstripNouterbraces{2}{{{\y}}}}
2691 \edef\x{\unexpanded\expandafter\expandafter\expandafter
2692 {\ltxkeysstripNouterbraces\@m{{{\y}}}}}
2693 \edef\x{\ltxkeysstripallouterbraces{{{{\y}}}}}
2694 \finish{example}
2695
2696
2697 \docsection(sec:addkeycode){Adding to key macros}
2698
2699
2700
2701 \docsection(sec:todo){To-do list}
2702
2703 This section details additional package features that may become available in the foreseeable future. User views are being solicited in regard of the following proposals.
2704
2705
2706 \docsubsection(sec:changeobserverkeys){Modifying the observer keys of an existing style key}
2707
2708 \start+{newmacro}[\ltxkeysadddepkeys,etc]
2709 \ltxkeysadddepkeys[|A(pref)]{|A(fam)}{|A(paren)}{|A(deps)}
2710 \ltxkeysremovedepkeys[pref]{fam}{|A(paren)}{|A(deps)}
2711 \ltxkeysreplacedepkeys[pref]{fam}{|A(paren)}{|A(olddeps)}{|A(newdeps)}
2712 \finish{newmacro}
2713 \fxim*{\ltxkeysadddepkeys,\ltxkeysremovedepkeys,\ltxkeysreplacedepkeys}
2714
2715 Here, \ang{paren} is the parent key of observers keys; \ang{deps} is the full specification of new or existing observer keys (as in \sref{sec:stylekeys}), with their default values and callbacks; \ang{olddeps} are the old observers to replace with \ang{newdeps}. This would require patching macros of the form \jpreffamkey{observers}, which might have nested parametered-commands.
2716
2717
2718
2719 \docsubsection(sec:togglekeys){Toggle keys}
2720
2721 Introduce toggle keys. The package already contains switch keys (\sref{sec:switchkeys}). Toggles and switches, found in, \eg, the \pkg'{ltxtools}, are more efficient than conventional booleans in the sense that each of them introduces and requires only one command, while each native boolean defines and requires up to three commands.
2722
2723
2724 \docsection(sec:version-hist){Version history}
2725
2726 The following change history highlights significant changes that affect user utilities and interfaces; changes of technical nature are not documented in this section. The \stsign on the right-hand side of the following lists means the subject features in the package but is not reflected anywhere in this user guide.
2727
2728 \begin{versionhist}
2729 \begin{version}{0.0.3c}{2012/11/17}
2730 \item \fx{\ltxkeys@liskeys} changed to \fx{\ltxkeys@listkeys}\vsecref{sec:listkeys}
2731 \end{version}
2732 \begin{version}{0.0.3a-b}{2012/10/14}
2733 \item Miscellaneous bug fixes\vsecref*
2734 \end{version}
2735 \begin{version}{0.0.3}{2011/12/17}
2736 \item More flags (\ffx{preset, postset, setrm}, \eetc) have been introduced for pathkeys \vsecref{sec:pathkeys}
2737 \end{version}
2738 \begin{version}{0.0.2}{2011/09/01}
2739 \item Pathkeys introduced\vsecref{sec:pathkeys}
2740 \item User guide completed.\vsecref*
2741 \end{version}
2742 \begin{version}{0.0.1}{2011/07/30}
2743 \item First public release.\vsecref*
2744 \end{version}
2745 \end{versionhist}
2746
2747 \newpage
2748 \ltsindexpreamble{Index numbers refer to page numbers.}
2749 \ltsindexpreambleformat{\centering}
2750 \ltsindexcolumns=2
2751 \printindex
2752
2753 \end{document}