diff options
author | Karl Berry <karl@freefriends.org> | 2012-08-19 22:19:25 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2012-08-19 22:19:25 +0000 |
commit | e9d394d17c224d094859430ed2d214491caf0e45 (patch) | |
tree | bcc98b0bcd7a4a621fde96c8cc02b602141fa621 /Master/texmf-dist/doc/latex/ltxkeys/ltxkeys-guide.tex | |
parent | fc31e4178a0deb96c5f9c78ef8b269e4210473b6 (diff) |
ltxkeys (19aug12)
git-svn-id: svn://tug.org/texlive/trunk@27462 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/doc/latex/ltxkeys/ltxkeys-guide.tex')
-rw-r--r-- | Master/texmf-dist/doc/latex/ltxkeys/ltxkeys-guide.tex | 1963 |
1 files changed, 1391 insertions, 572 deletions
diff --git a/Master/texmf-dist/doc/latex/ltxkeys/ltxkeys-guide.tex b/Master/texmf-dist/doc/latex/ltxkeys/ltxkeys-guide.tex index 80ce3f8eb08..f391d691602 100644 --- a/Master/texmf-dist/doc/latex/ltxkeys/ltxkeys-guide.tex +++ b/Master/texmf-dist/doc/latex/ltxkeys/ltxkeys-guide.tex @@ -9,18 +9,48 @@ inputfile, input-config-file, no-hyperref-messages, - wrapquote + wrapquote, ]{amltxdoc} \makeatletter -\hfuzz1pt\vfuzz2pt -\makeindex -\AfterAfterStartOfDocument{% - \def\amd@sectitlefmt{\centering\Large\sffamily\color{secheadcolor}}% -} -\let\footnote\ltsfootnote -\extrarowheight=2pt -\arrayrulecolor{yellow} + +\ltscommenbegin +% Include the use of the following commands in this manual: +% \ifltxkeysnovalue +% \ltxkeysignorekeys +% \ltxkeysgignorekeys +% \ltxkeysremoveignorekeys +% \ltxkeysgremoveignorekeys +% \ltxkeysdeleteignorekeys +% \ltxkeysgdeleteignorekeys + +% \ltxkeyssaveinitialvaluekeys +% \ltxkeysgsaveinitialvaluekeys +% \ltxkeysremovesaveinitialvaluekeys +% \ltxkeysgremovesaveinitialvaluekeys +% \ltxkeysdeletesaveinitialvaluekeys +% \ltxkeysgdeletesaveinitialvaluekeys + +% \ltxkeysgetrmkeys +% \ltxkeysggetrmkeys + +% \ltxkeyspresetkeys +% \ltxkeysgpresetkeys +% \ltxkeyspostsetkeys +% \ltxkeysgpostsetkeys +% \ltxkeyspreposetkeys +% \ltxkeysgpreposetkeys + +% \ltxkeysinitializermkeys +% \ltxkeysginitializermkeys +% \ltxkeysifexpr + +% \pathkeysbreaklist, \newpath + +\ltxkeysifinlistTF, \ltxkeysnormalizeset, \ltxkeysnormalizecsset +\carmustykeys + +\ltscommentend \begin{document} @@ -30,25 +60,25 @@ The package is available at \url{\titleurltext}.\sep This user manual corresponds to version~0.0.3 of the package. } -\subtitle{A robust key parser} +\subtitle{A robust key parser for \latex} \titleurl{http://mirror.ctan.org/macros/latex/contrib/ltxkeys/} -\author{Ahmed Musa\authorref{a1,a2}} -\authornotes[a1,a2]{% - The University of Central Lancashire, Preston, UK.\sep - Email address for all \pkg'{ltxkeys} related matters: \email{amusa22@gmail.com}. +\author{Ahmed Musa\authorref{a1}} +\authornotes[a1]{% + The University of Central Lancashire, Preston, UK. \email{amusa22@gmail.com}. } \end{frontmatter} \hrule \vskip 1ex plus 1pt minus 1pt \begingroup -\def\contentsname{\centerline{\Large\sffamily\textcolor{blue}{Contents}}}% -\hypersetup{linkcolor=blue}\tableofcontents +\def\contentsname{\centerline{\Large\sffamily\textcolor{blue}{Contents}}} +\hypersetup{linkcolor=blue} +\sffamily\tableofcontents \endgroup \hrule \ltsnewfootnote{1}{% - 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'{\ltxkeys@definekeys, \ltxkeys@declarekeys}, 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. + 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. } \ltsnewfootnote{2}{% Options are also keys, but (from the user's viewpoint) there might be a need to treat options separately when dealing with unknown keys. @@ -57,44 +87,57 @@ \docsection(sec:intro){Introduction} -\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 and faster 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, catoptions}, 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}.}: +\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}.}: -\start'{example}[Braced option values] +%[Braced option values] +\start'{example} \pkgoptions{% opt1=val1,opt2=val2, layout={left=3cm,right=3cm,top=2.5cm,bottom=2.5cm,include=true} } \finish{example} -As a practical example, the \pkg'{amtools} has the command \fx{\amloadmodules} with the syntax +As a practical example, consider the command \fx{\loadModules} with the syntax \start'{example}[Braced key values] -\amloadmodules{|A(base)}{|A(modules)} +\loadModules{|A(base)}{|A(modules)} \finish{example} -where \ang{modules} is a comma-separated \keyval list. Like the above \quotedtt{layout} option, each key of \fx{\amloadmodules} may have a value (representing module options) that is itself a comma-separated \keyval list. +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. -Well, the type of robustness described here isn't actually difficult to implement within the \pkg'{xkeyval}. This is indeed what the \pkg'{combokeys} does: it patches some 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{combokeys} packages. +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. -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}). 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. +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. 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. -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 keys (including ordinary keys, command keys, style keys, choice 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. +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: -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, pathkeys, 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. +\begin{syntax} +\define@key[KV]{fam}{textsize}[5cm and 10cm]{% + \textwidth=#1 \textheight=#2 +} +\setkeys[KV]{fam}{textsize=2.5cm and 8cm} +\finish{syntax} -\ltsnote 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.}. +The \pkg'{ltxkeys} can compactly define and set all types of key with delimited and multiple parameters for key macros. See \sref{sec:weirdargs}. + +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. + +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, pathkeys, 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. The notion of pathkeys is particularly interesting and powerful. Users more interested in this concept and its applications can skip many sections of this guide on their way to \sref{sec:pathkeys}. + +\ltsnote +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.}. \docsubsection{Motivation} -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 the \pkg'{ltxkeys} can be used as a more robust replacement for the \pkg'{xkeyval}, of course with modifications of names and some syntaxes. The \pkg'{xkeyval} has been frozen since August 2008. +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. \docsection(sec:packageoptions)<package options>{Package options} -The package options are listed in \sref{tab:pkgoptions}. The package options can be passed via \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: +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: \start{example}[Package options] \documentclass[tracingkeys,keyparser={|nv},pathkeys]{article} @@ -102,7 +145,7 @@ The package options are listed in \sref{tab:pkgoptions}. The package options can \usepackage[tracingkeys,keyparser={|nv}]{ltxkeys} \finish{example} -They can also be passed via the command \fx{\ltxkeys@options}: +They can also be passed locally via the command \fx{\ltxkeys@options}: \start{newmacro}[\ltxkeys@options] \ltxkeys@options{tracingkeys=false,keyparser={;}} @@ -110,13 +153,13 @@ They can also be passed via the command \fx{\ltxkeys@options}: \fxim*{\ltxkeys@options} \newltablenote{ltxkeys-1}{% - 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'{\ltxkeys@definekeys, \ltxkeys@declarekeys} 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. + 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. } \newltablenote{ltxkeys-2}{% - 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. 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. + 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. } \newltablenote{ltxkeys-3}{% - The key-setting commands are \ffx'{\ltxkeys@setkeys,\ltxkeys@setrmkeys,\ltxkeys@setaliaskey}. 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}. + 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}. } \newltablenote{ltxkeys-4}{% 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. @@ -124,8 +167,10 @@ They can also be passed via the command \fx{\ltxkeys@options}: \begingroup \small +%\trace* \begin{tabularx}{\linewidth}{|p{3cm}|p{2cm}|X|} -\caption{Package options\xwmlabel{tab:pkgoptions}}\\\hline +\caption{Package options. All the package options can also be changed globally via \headhx{\documentclass} and locally through the control sequence \headfx{\ltxkeys@options}.} \xwmlabel{tab:pkgoptions} +\\\hline \rowcolor{pink} \bfseries Option&\bfseries Default&\bfseries Meaning\\\hline \endfirsthead @@ -138,13 +183,15 @@ They can also be passed via the command \fx{\ltxkeys@options}: \hline \endlastfoot \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 -\fx{keyparser} & \texttt{;} & The list parser used by some internal loops in defining keys.\useltablenote[tab:pkgoptions:note2]{ltxkeys-2}\\\hline +\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, \pathkeys}. \useltablenote[tab:pkgoptions:note2]{ltxkeys-2}\\\hline \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 \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, but when dealing with \quoted{pathkeys} (see \sref{sec:pathkeys}) the term excludes the 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 \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 -\fx{pathkeys} & \hx{false} & Load the \pkg'{pathkeys} (see \sref{sec:pathkeys}). +\fx{pathkeys} & \hx{false} & Load the \pkg'{pathkeys} (see \sref{sec:pathkeys}).\\\hline +\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. \end{tabularx} \endgroup +%\endtrace \docsection{Defining keys} @@ -167,14 +214,14 @@ In the following, syntactic quantities in square brackets (\eg, \fx{[yyy]}) and \finish{newmacro} \fxim*{\ltxkeys@ordkey,\ltxkeys@newordkey} -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{\ltxkeys@setkeys} 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{\ltxkeys@setkeys}. 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.}. +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.}. Run the following example and do \fx{\show\cmdb} and \fx{\show\cmdd}: \start{example}[\ltxkeys@ordkey] \ltxkeys@ordkey[KV]{fam}{keya}[\def\cmda#1{aa#1}]{\def\cmdb##1{#1bb##1}} \ltxkeys@ordkey[KV]{fam}{keyb}[\def\cmdc##1{cc##1}]{\def\cmdd##1{#1dd##1}} -\ltxkeys@setkeys[KV]{fam}{keya,keyb} +\ltxkeyssetkeys[KV]{fam}{keya,keyb} \finish{example} \docsubsubsection(sec:ordkeys-sameattributes) @@ -189,6 +236,43 @@ The commands \ffx'{\ltxkeys@ordkey,\ltxkeys@newordkey} can be used to introduce \fxim*{\ltxkeys@ordkeys,\ltxkeys@newordkeys} +\docsubsection(sec:lispkeys)<lispkeys>{List keys (lispkeys)} + +\start+{newmacro}[\ltxkeys@lispkey,\ltxkeys@newlispkey, etc.] +\ltxkeys@lispkey[|A(pref)]{|A(fam)}{|A(key)}[|A(dft)]{|A(cbk)} +\ltxkeys@newlispkey[|A(pref)]{|A(fam)}{|A(key)}[|A(dft)]{|A(cbk)} +\ltxkeys@lispkeys[|A(pref)]{|A(fam)}{|A(keys)}[|A(dft)]{|A(cbk)} +\ltxkeys@newlispkeys[|A(pref)]{|A(fam)}{|A(keys)}[|A(dft)]{|A(cbk)} +\finish{newmacro} +\fxim*{\ltxkeys@lispkey,\ltxkeys@newlispkey,\ltxkeys@lispkeys,\ltxkeys@newlispkeys} + +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). + +Each item will be processed by the key's callback. 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{\ltxkeyslispnr} 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. + +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. + +\start+{example}[\ltxkeys@lispkey] +\ltxkeys@lispkey[KV]{fam}{keya}[aaa, bbb]{% + |com(`#1' here refers to the current item of the list:) + \csndef{ww@\romannumeral\ltxkeyslispnr}{#1}% +} +|com(User inputs that are comma-separated should be wrapped in braces:) +\ltxkeyssetkeys[KV]{fam}{keya={val1, val2, val3}} + +\ltxkeys@lispkey[KV]{fam}{keyb}[aaa; bbb]{% + |R(\listsep){;}% + \ifnum\ltxkeyslispnr>2\relax + \ltxkeysbreakloop + \else + \csn@def{ww@\romannumeral\ltxkeyslispnr}{#1}% + \fi +} +\ltxkeyssetkeys[KV]{fam}{keyb=val1; val2; val3; val4} +\ltxkeyssetkeys[KV]{fam}{keyb=val5} +\finish{example} + + \docsubsection(sec:cmdkeys)<command keys (cmd)>{Command keys} \start+{newmacro}[\ltxkeys@cmdkey,\ltxkeys@newcmdkey] @@ -243,9 +327,10 @@ If \ang{mp} is given, the command \mpkey will hold the current user input for th If the \stform is used, all undefined dependants will be defined and set on the fly as the parent is being set. If the \stform isn't used and undefined dependants occur, then an error message will be flagged at the time the parent is being set. -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 dependant keys, but it may be lost in the callbacks of dependant keys, because a dependant 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 of dependant 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. +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 dependant keys, but it may be lost in the callbacks of dependant keys, because a dependant 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 dependant 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. -\ltsnote \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 dependant key refers to the current value of that dependant key. Here is an example that defines and sets all undefined dependants on the fly: +\ltsnote +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 dependant key refers to the current value of that dependant key. Here is an example that defines and sets all undefined dependants on the fly: \start+{example}[\ltxkeys@stylekey] \ltxkeys@stylekey|*[KV]{fam}[mp@]{keya}[{left}]|(% @@ -253,10 +338,10 @@ Most of the time it is possible to access the parent key's current value with \f |com(at the time it is being set. Use \parentkey and \parentval) |com(here to access the parent key name and its current value:) ord/keyb/{right}/\def\y##1{#1##1}; - |com( The default of keyc is the current value of parent |(keya|):) + |com( The default of `keyc' is the current value of parent `keya':) cmd/keyc/\parentval; |com(Because \KV@fam@keya@value appears below, it will be saved) - |com(when the parent key (keya) is being set, otherwise it would be) + |com(when the parent key `keya' is being set, otherwise it would be) |com(unavailable:) bool/keyd/true/\ifmp@keyd\edef\x##1{##1\KV@fam@keya@value}\fi |){% @@ -264,25 +349,25 @@ Most of the time it is possible to access the parent key's current value with \f |com(it is being set:) \def\x##1{##1xx#1xx}% |com(Check the value of parent key:) - \ltxkeys@checkchoice[,]|(\userinput\order|){#1}{left,right,center}{}{% - \@latex@error{Invalid input '#1'}\@ehd + \ltxkeyscheckchoice[,]|(\userinput\order|){#1}{left,right,center}{}{% + \@latex@error{Invalid input `#1'}\@ehd }% } \finish{example} -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'{\ltxkeys@checkchoice, \CheckUserInput} can be found in \sref{sec:checkchoice}. +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}. -You can try setting \fx{keya} as follows to see what happens to keys \ffx'{keyb,keyc,keyd}: +You can try setting \ttx{keya} as follows to see what happens to keys \ffx'{keyb,keyc,keyd}: -\start{example}[\ltxkeys@setkeys] -\ltxkeys@setkeys[KV]{fam}{keya=right} +\start{example}[\ltxkeyssetkeys] +\ltxkeyssetkeys[KV]{fam}{keya=right} \finish{example} The following will flag an error because \fx{{right}} isn't in the list of nominations \fnz*{left,right,center}: -\start{example}[\ltxkeys@setkeys] -\ltxkeys@setkeys[KV]{fam}{keya={right}} +\start{example}[\ltxkeyssetkeys] +\ltxkeyssetkeys[KV]{fam}{keya={right}} \finish{example} 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. @@ -312,7 +397,7 @@ The commands \ffx'{\ltxkeys@stylekey,\ltxkeys@newstylekey} can be used to introd \finish{newmacro} \fxim*{\ltxkeys@boolkey,\ltxkeys@newboolkey} -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{\ltxkeys@setkeys} according to the user input. If \ang{mp} is not specified, a boolean of the form \ipreffamkey{ifbool} will instead be created. +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. 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. @@ -356,12 +441,72 @@ Biboolean keys have equal symmetry (\ie, they can call each other with equal pro }{% \ifmp@keyb\def\y##1{##1y#1y##1}\fi }{% - \@latex@error{Invalid value `\string#1' for keya or keyb}\@ehc + \@latex@error{Invalid value `#1' for key `\ltxkeyscurrentkey'}\@ehc } \finish{example} -\docsubsection(sec:choicekeys)<choice keys (choice)>{Choice keys} +\docsubsection(sec:switchkeys)<switch keys (type: switch)>{Switch keys} + +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. + +\start+{newmacro}[\ltxkeys@switchkey,\ltxkeys@newswitchkey] +\ltxkeys@switchkey[|A(pref)]{|A(fam)}[|A(mp)]{|A(key)}[|A(dft)]{|A(cbk)} +\ltxkeys@switchkey|+[|A(pref)]{|A(fam)}[|A(mp)]{|A(key)}[|A(dft)]{|A(cbk)}{|A(fn)} +\ltxkeys@newswitchkey[|A(pref)]{|A(fam)}[|A(mp)]{|A(key)}[|A(dft)]{|A(cbk)} +\ltxkeys@newswitchkey|+[|A(pref)]{|A(fam)}[|A(mp)]{|A(key)}[|A(dft)]{|A(cbk)}{|A(fn)} +\finish{newmacro} +\fxim*{\ltxkeys@switchkey,\ltxkeys@newswitchkey} + +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. + +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}. + +The \plform of \ffx'{\ltxkeys@switchkey,\ltxkeys@newswitchkey} 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. + +\start{example} +\ltxkeys@switchkey[KV]{fam}{keya}[true]{% + \if\switchKV@fam@keya + \def\x##1{##1*#1*##1}% + \fi +} +\ltxkeys@switchkey+[KV]{fam}[mp@]{keyb}[true]{% + \if\mp@keyb + \def\y##1{##1*#1*##1}% + \fi +}{ + \@latex@error{Invalid value `#1' for key `keyb'}\@ehc +} +\ltxkeyssetkeys[KV]{fam}{keya=true,keyb=false} +\finish{example} + + +\docsubsubsection(sec:switchkeys-sameattributes) + {Switch keys that share the same attributes} + +The commands \ffx'{\ltxkeys@switchkey,\ltxkeys@newswitchkey} 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: + +\start+{newmacro}[\ltxkeys@switchkeys,\ltxkeys@newswitchkeys] +\ltxkeys@switchkeys[|A(pref)]{|A(fam)}[|A(mp)]{|A(keys)}[|A(dft)]{|A(cbk)} +\ltxkeys@switchkeys|+[|A(pref)]{|A(fam)}[|A(mp)]{|A(keys)}[|A(dft)]{|A(cbk)}{|A(fn)} +\ltxkeys@newswitchkeys[|A(pref)]{|A(fam)}[|A(mp)]{|A(keys)}[|A(dft)]{|A(cbk)} +\ltxkeys@newswitchkeys|+[|A(pref)]{|A(fam)}[|A(mp)]{|A(keys)}[|A(dft)]{|A(cbk)}{|A(fn)} +\finish{newmacro} +\fxim*{\ltxkeys@switchkeys,\ltxkeys@newswitchkeys} + +\start{example} +\ltxkeys@switchkeys+[KV]{fam}[mp@]{keya,keyb,keyc}[true]{% + \if\@nameuse{mp@\ltxkeyscurrentkey}% + \def\x##1{value of key `\ltxkeyscurrentkey' = #1 *** arg = ##1}% + \fi +}{ + \@latex@error{Invalid value `#1' for key `\ltxkeyscurrentkey'}\@ehc +} +\ltxkeyssetkeys[KV]{fam}{keya=true,keyb=false,keyc=true} +\finish{example} + + +\docsubsection(sec:choicekeys)<choice keys (type: choice)>{Choice keys} 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. @@ -382,18 +527,18 @@ The choice keys of the \pkg'{ltxkeys} differ from those of the \pkg'{xkeyval} in 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{\ltxkeys@choicekey} uses \ipreffamkey{chc} to hold the user input. -When \ang{alt} has no literal form \quotedfx{/.code} or forward slash \quotedfx{/} in it, then it is expected to be of the familiar \pkg'{xkeyval} syntax: +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: \start'{macro}[Syntax of `nominations' for choice keys] {choice1,choice2,etc.} \finish{macro} -If \ang{alt} has \quotedfx{/.code} or \quotedfx{/} in it, then it is expected to have one of the following syntaxes: +If \ang{alt} has \quotedfx{/.do} or \quotedfx{/} in it, then it is expected to have one of the following syntaxes: \start'{macro}[Syntaxes of `nominations' for choice keys] {% - choice1|R(/.code=)callback1|R(|A(keyparser)) - choice2|R(/.code=)callback2|R(|A(keyparser)) + choice1|R(/.do=)callback1|R(|A(keyparser)) + choice2|R(/.do=)callback2|R(|A(keyparser)) etc. } @@ -406,22 +551,23 @@ If \ang{alt} has \quotedfx{/.code} or \quotedfx{/} in it, then it is expected to } \finish{macro} \aiidxm*[\emph,choice keys]{nominations} -\aidxm*{/.code} -\aidxs*{.code}{/.code} +\aidxm*{/.do} +\aidxs*{.do}{/.do} If the parser is \qsemicolon, then we would have \start'{example}[Syntaxes of `nominations' for choice keys] -{choice1|R(/.code=)callback1; choice2|R(/.code=)callback2; etc.} +{choice1|R(/.do=)callback1; choice2|R(/.do=)callback2; etc.} |R(or) {choice1|R(/)callback1; choice2|R(/)callback2; etc.} \finish{example} -This means that if you have \quotedfx{/.code} 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. +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. -\ltsnote 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{.code} separates \ang{choice} from the callback \ang{cbk}. If no \quotedfx{.code} 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{.code} nor \quotedfx{/} is necessary. +\ltsnote +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. It is possible to refer to the current value of \ang{key} as \fx{#1} in \ang{alt}. @@ -447,10 +593,10 @@ The \stform of \fx{\ltxkeys@choicekey} will convert the user input to lowercase \ltxkeys@choicekey|*|+[KV]{fam}[mp@]{keyb}[\userinput\order]{% |com(There are callbacks for these nominations:) - land/.code=\def\x##1{*##1*#1*##1}; - air/.code=\edef\z{\expandcsonce\ltxkeys@tval}; - sea/.code=\edef\myinput{\cpttrimspaces{#1}}; - space/.code=\letcsntocs{#1@earth}\relax + land/.do=\def\x##1{*##1*#1*##1}; + air/.do=\edef\z{\expandcsonce\ltxkeyscurrentvalue}; + sea/.do=\edef\myinput{\ltstrimspaces{#1}}; + space/.do=\letcsntocs{#1@earth}\relax }[center]{% \def\z##1##2{==##1++#1++##2==}% }{% @@ -461,7 +607,7 @@ The \stform of \fx{\ltxkeys@choicekey} will convert the user input to lowercase |com(The callbacks can also take the following form:) center/\ltxkeys@cmdkey[KV]{fam}[mp@]{keyd}{\def\x####1{####1*##1*####1}}, right/\let\align\flushright, - left/\let\align\flushleft\edef\userinput{\cpttrimspaces{#1}}, + left/\let\align\flushleft\edef\userinput{\ltstrimspaces{#1}}, justified/\let\align\relax }[center]{% \def\z##1##2{==##1++#1++##2==}% @@ -472,12 +618,12 @@ The \stform of \fx{\ltxkeys@choicekey} will convert the user input to lowercase center/\ltxkeys@cmdkey[KV]{fam}[mp@]{keyd}[|R(\usevalue){keyb}] {\def\x####1{####1*##1*####1}}, right/\def\y##1{##1++#1++##1}, - left/\edef\userinput{\cpttrimspaces{#1}}, + left/\edef\userinput{\ltstrimspaces{#1}}, justified/\letcsntocs{#1@align}\relax }[center]{% \def\z##1##2{==##1++#1++##2==}% } -\ltxkeys@setkeys[KV]{fam}{keyb=center,keyd} +\ltxkeyssetkeys[KV]{fam}{keyb=center,keyd} \finish{example} The representations \ffx'{\savevalue,\usevalue,\needvalue} are pointers (see \sref{sec:keypointers}). @@ -505,50 +651,105 @@ The commands \ffx'{\ltxkeys@choicekey,\ltxkeys@newchoicekey} can be used to intr \fxim*{\ltxkeys@choicekeys,\ltxkeys@newchoicekeys} +\docsection{Default values of keys} +The code after \fx{.do=} will be executed whenever the default value of the key is used. + +% \ltxkeys@ordkey[KV]{fam}{keya}[\def\y#1{#1}.do=\def\x#1{#1}]{% +% \def\cmda##1{##1*#1*##1} +% } + +\docsection(sec:everykeydefault){Every default value of a key} + +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: + +\start+{newmacro}[\ltxkeyseverykeydefault] +\ltxkeyseverykeydefault[|A(prefs)]{|A(fams)}{#1#2#3#4} +\finish{newmacro} +\fxim*{\ltxkeyseverykeydefault} + +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. + +The following example defines key-default handler for two key prefixes and two families. + +\start{example}[\ltxkeyseverykeydefault] +\ltxkeyseverykeydefault[KV1,KV2]{fam1,fam2}{% + \wlog{Prefix: #1/ Family: #2/ Key name: #3/ Default value: \unexpanded{#4}}% +} +\finish{example} + + \docsubsection(sec:definekeys){Defining boolean and command keys with one command} \aidx*{defining multiple keys} 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: -\start{newmacro}[\ltxkeys@definekeys] -\ltxkeys@definekeys[|A(pref)]{|A(fam)}[|A(mp)]{% +\start{newmacro}[\ltxkeysdefinekeys] +\ltxkeysdefinekeys[|A(pref)]{|A(fam)}[|A(mp)]{% |A(key)|R(=)|A(dft)/|A(cbk); another set of key attributes; etc. } -\ltxkeys@definekeys|*[|A(pref)]{|A(fam)}[|A(mp)]{% +\ltxkeysdefinekeys|*[|A(pref)]{|A(fam)}[|A(mp)]{% |A(key)|R(=)|A(dft)/|A(cbk); another set of key attributes; etc. } \finish{newmacro} -\fxim*{\ltxkeys@definekeys} +\fxim*{\ltxkeysdefinekeys} 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: -\start{newmacro}[\ltxkeys@definekeys] -\ltxkeys@definekeys[|A(pref)]{|A(fam)}[|A(mp)]{% +\start{newmacro}[\ltxkeysdefinekeys] +\ltxkeysdefinekeys[|A(pref)]{|A(fam)}[|A(mp)]{% |A(key)|R(/)|A(dft)/|A(cbk); another set of key attributes; etc. } -\ltxkeys@definekeys|*[|A(pref)]{|A(fam)}[|A(mp)]{% +\ltxkeysdefinekeys|*[|A(pref)]{|A(fam)}[|A(mp)]{% |A(key)|R(/)|A(dft)/|A(cbk); another set of key attributes; etc. } \finish{newmacro} -\fxim*{\ltxkeys@definekeys} +\fxim*{\ltxkeysdefinekeys} + +You can use the command \fx{\ltxkeyscheckuserinput} in \ang{cbk} to indirectly introduce choice keys as command keys (see example below). + +Ordinary keys and conventional choice keys can't be introduced directly by this command (use the command \fx{\ltxkeysdeclarekeys} instead). -You can use the command \fx{\CheckUserInput} in \ang{cbk} to indirectly introduce choice keys as command keys (see example below). +The \stform of \fx{\ltxkeysdefinekeys} can be used to define non-existing boolean and command keys in the sense of \hx{\newcommand}. -Ordinary keys and conventional choice keys can't be introduced directly by this command (use the command \fx{\ltxkeys@declarekeys} instead). +\begin{noteenv}* +\label{nte:definekeys-1} +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: -The \stform of \fx{\ltxkeys@definekeys} can be used to define non-existing boolean and command keys in the sense of \hx{\newcommand}. +\start{example}[\ltxkeysdefinekeys] +\def\alist{} +\ltxkeysdefinekeys[pref]{fam}[mp]{% + keya/defaulta/\edef\alist{\ifx\alist\@empty\else\alist,\fi#1}; + keyb/defaultb/\def\callback##1{##1*#1}% +} +\finish{example} -\ltsnote Keys defined by \fx{\ltxkeys@definekeys} 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. +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{\ifltxkeys@dec} 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: + +\start{example}[\ltxkeysdefinekeys] +\def\alist{} +\ltxkeysdefinekeys[pref]{fam}[mp]{% + keya/defaulta/ + \ifltxkeys@dec\else + |com(Don't execute this when defining the key:) + \edef\alist{\ifx\alist\@empty\else\alist,\fi#1}% + \fi; + keyb/defaultb/\def\callback##1{##1*#1}% +} +\finish{example} + +So here the building of the list by \ttx{keya} wouldn't start until the key has been defined (\ie, outside \fx{\ltxkeysdefinekeys}). +\end{noteenv} -\ltsnote In \ffx'{\ltxkeys@definekeys, \ltxkeys@declarekeys} 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}. +\ltsnote +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}. -\start+{example}[\ltxkeys@definekeys] +\start+{example}[\ltxkeysdefinekeys] |com(The |stform defines new keys:) -\ltxkeys@definekeys|*[KV]{fam}[mp@]{% +\ltxkeysdefinekeys|*[KV]{fam}[mp@]{% |com(Command key with callback:) keya={keepbraced}/\def\x##1{##1*#1*##1}; |com(Boolean key:) @@ -556,8 +757,8 @@ The \stform of \fx{\ltxkeys@definekeys} can be used to define non-existing boole |com(Command key with no callback:) keyc=xxx; |com(Choice-like command key:) - keyd=center/\CheckUserInput{#1}{left,right,center} - \ifinputvalid |label(mac:ifinputvalid) + keyd=center/\ltxkeyscheckuserinput{#1}{left,right,center} + \ifltxkeysinputvalid |label(mac:ifltxkeysinputvalid) \edef\myval{\expandcsonce\userinput} \edef\numberinlist{\number\order} \edef\mychoices{\expandcsonce\nominations} @@ -568,50 +769,51 @@ The \stform of \fx{\ltxkeys@definekeys} can be used to define non-existing boole keye=false; } \finish{example} -\fxim*{\ifinputvalid,\CheckUserInput,\nominations,\userinput} -\aiidxm*[\bs,choice keys]{nominations,ifinputvalid} +\fxim*{\ifltxkeysinputvalid,\ltxkeyscheckuserinput,\nominations,\userinput} +\aiidxm*[\bs,choice keys]{nominations,ifltxkeysinputvalid} -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{inputvalid} is associated with the command \fx{\CheckUserInput} and is available to the user. It is set \hx{true} when the user input is valid, and \hx{false} otherwise. The command \fx{\CheckUserInput} expects two arguments: the user input and the list of nominations. It doesn't expect two branches (see \sref{sec:checkchoice}). +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}). \docsubsection(sec:declarekeys){Defining all types of key with one command} \aidx*{defining multiple keys} -\start{newmacro}[\ltxkeys@declarekeys] -\ltxkeys@declarekeys[|A(pref)]{|A(fam)}[|A(mp)]{%|label(mac:declarekeys) +\start{newmacro}[\ltxkeysdeclarekeys] +\ltxkeysdeclarekeys[|A(pref)]{|A(fam)}[|A(mp)]{%|label(mac:declarekeys) |A(keytype)/|A(keyname)/|A(dft)/|A(cbk); another set of key attributes; etc. } -\ltxkeys@declarekeys|*[|A(pref)]{|A(fam)}[|A(mp)]{% +\ltxkeysdeclarekeys|*[|A(pref)]{|A(fam)}[|A(mp)]{% |A(keytype)/|A(keyname)/|A(dft)/|A(cbk); another set of key attributes; etc. } \finish{newmacro} -\fxim*{\ltxkeys@declarekeys} +\fxim*{\ltxkeysdeclarekeys} \aidx*{style keys (sty*)} -Here, the default value \ang{dft} and the 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{\ltxkeys@stylekey} above, namely, undefined dependants 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}. +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{\ltxkeys@stylekey} above, namely, undefined dependants 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}. Choice keys must have their names associated with their admissible \ang{alt} values in the format \keydotchoice{keyname}{alt} (see example below). -The \stform of \fx{\ltxkeys@declarekeys} can be used to define new keys (in the sense of \hx{\newcommand}). +The \stform of \fx{\ltxkeysdeclarekeys} can be used to define new keys (in the sense of \hx{\newcommand}). -\ltsnote Keys defined by \fx{\ltxkeys@declarekeys} 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. +\ltsnote +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}. -\start+{example}[\ltxkeys@declarekeys] -\ltxkeys@declarekeys|*[KV]{fam}[mp@]{% +\start+{example}[\ltxkeysdeclarekeys] +\ltxkeysdeclarekeys|*[KV]{fam}[mp@]{% |com(Ordinary key with callback:) ord/keya/.1\paperwidth/\leftmargin=#1\relax; - |com(Command key with callback. `.code=' is allowed before callback:) - cmd/keyb/10mm/.code=\rightmargin=#1\def\x##1{##1*#1*##1}; + |com(Command key with callback. `.do=' is allowed before callback:) + cmd/keyb/10mm/.do=\rightmargin=#1\def\x##1{##1*#1*##1}; |com(Boolean key without callback:) bool/keyc/true; |com(Boolean key with callback:) bool/keyd/true/\ifmp@keyd\@tempswatrue\else\@tempswafalse\fi; |com(Style key with callback but no dependants:) - sty/keye/aaa/.code=\def\y##1{##1yyy#1}; + sty/keye/aaa/.do=\def\y##1{##1yyy#1}; |com(Style key with callback and dependants `keyg' and `keyh':) sty|*/keyf/blue/\def\y##1{##1#1}/ cmd|R(>)keyg|R(>)\parentval|R(>)\def\z####1{####1+##1+####1}|R(,) @@ -622,46 +824,47 @@ The \stform of \fx{\ltxkeys@declarekeys} can be used to define new keys (in the \edef\shoot{\ifcase\order 0\or 1\or 2\fi}; |com(Choice key with complex nominations:) choice/keyj|R(.){ - center/.code=\def\mp@textalign{center}, - left/.code=\def\mp@textalign{flushleft}, - |com(`.code=' can be omitted:) + center/.do=\def\mp@textalign{center}, + left/.do=\def\mp@textalign{flushleft}, + |com(`.do=' can be omitted:) right/\def\mp@textalign{flushright}, justified/\let\mp@textalign\relax } /center/\def\yy##1{##1yy#1}; - ord/keyk/\letcstocsn\func{as-defined-by-user} + ord/keyk/\letcstocsn\func{as-defined-by-user}; + switch/keyl/true/\if\mp@keyl\def\y##1{##1+#1+##1}\fi; } \finish{example} \aidx*{style keys (sty*)} -\aidx*{/.code} +\aidx*{/.do} -Notice the \fx{>...>} used for the attributes of the dependant keys \quotedlist'{keyg,keyh} of style key \quoted{keyf}. Dependent keys come as the last attributes of a style key, and they (dependant keys) are separated by \qcomma. The default value of the dependant key \quoted{keyg} will in this example be whatever is submitted for \quoted{keyf}. As indicated in \sref{sec:stylekeys}, the function \fx{\KV@fam@keyf@value} has a longer shelf life than \fx{\parentval}. Notice also the syntax \keydotchoice{keyi}{left,right,center} for the choice keys \quotedlist'{keyi,keyj}. It says that the alternate admissible values for \quoted{keyi} are \quotedlist'{left,right,center,justified}; similarly for key \quoted{keyj}. +Notice the notation \fx{>...>} used for the attributes of the dependant keys \ttx{keyg,keyh} of style key \quoted{keyf}. Dependent keys are the last attributes of a style key, and they (dependant keys) are separated by \qcomma. The default value of the dependant key \quoted{keyg} will in this example be whatever is submitted for \quoted{keyf}. As indicated in \sref{sec:stylekeys}, the function \fx{\KV@fam@keyf@value} has a longer lifespan than \fx{\parentval}. Notice also 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}. -\docsubsubsection(sec:sametypekeys){Defining keys of common type with - \headfx{\ltxkeys@declarekeys}} +\docsubsubsection(sec:sametypekeys)[Defining keys of common type] + {Defining keys of common type with \headfx{\ltxkeysdeclarekeys}} -If you have to define keys of the same type with the command \fx{\ltxkeys@declarekeys}, then the following syntax allows you to avoid entering the key types repeatedly: +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: -\start{macro}[\ltxkeys@declarekeys] -\ltxkeys@declarekeys|(|A(keytype)|)[|A(pref)]{|A(fam)}[|A(mp)]{% +\start{macro}[\ltxkeysdeclarekeys] +\ltxkeysdeclarekeys|(|A(keytype)|)[|A(pref)]{|A(fam)}[|A(mp)]{% |A(keyname)/|A(dft)/|A(cbk); another set of key; etc. } -\ltxkeys@declarekeys|*|(|A(keytype)|)[|A(pref)]{|A(fam)}[|A(mp)]{% +\ltxkeysdeclarekeys|*|(|A(keytype)|)[|A(pref)]{|A(fam)}[|A(mp)]{% |A(keyname)/|A(dft)/|A(cbk); another set of key; etc. } \finish{macro} -\fxi*{\ltxkeys@declarekeys} +\fxi*{\ltxkeysdeclarekeys} -\start+{example}[\ltxkeys@declarekeys] -\ltxkeys@declarekeys|(bool|)[KV]{fam}[mp@]{% +\start+{example}[\ltxkeysdeclarekeys] +\ltxkeysdeclarekeys|(bool|)[KV]{fam}[mp@]{% keya/true/\def\x##1{##1*#1*##1}; keyb/true; keyc/true/\def\y##1{##1yyy#1} } -\ltxkeys@declarekeys|*|(sty|*|)[KV]{fam}[mp@]{% +\ltxkeysdeclarekeys|*|(sty|*|)[KV]{fam}[mp@]{% keyd/xxx/\def\y##1{##1yyy#1}; |com(keyf is a dependant of keye:) keye/blue/\def\y##1{##1#1}/cmd>keyf>\parentval>\def\z####1{####1+##1+####1} @@ -679,7 +882,7 @@ To make a key a need-value key, simply attach the pointer \fx{\needvalue} to the \ltxkeys@cmdkey[KV]{fam}[mp@]{\needvalue{keya}}[blue]{% \def\x##1{##1x#1x##1}% } -\ltxkeys@setkeys[KV]{fam}{keya} +\ltxkeyssetkeys[KV]{fam}{keya} |com( -> Error: the author of `keya' designed it to require a user value.) \finish{example} @@ -691,23 +894,23 @@ See more about key pointers in \sref{sec:keypointers}. 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. -Cross-family keys are automatically initialized after being defined---as we saw in the case of the commands \ffx'{\ltxkeys@definekeys,\ltxkeys@declarekeys}. +Cross-family keys are automatically initialized after being defined---as we saw in the case of the commands \ffx'{\ltxkeysdefinekeys,\ltxkeysdeclarekeys}. -\start+{newmacro}[\ltxkeys@savexfamilykeys,\ltxkeys@definexfamilykeys] -\ltxkeys@savexfamilykeys<|A(id)>{|A(keylist)} -\ltxkeys@savexfamilykeys|*<|A(id)>|A(keylistcmd) +\start+{newmacro}[\ltxkeyssavexfamilykeys,\ltxkeysdefinexfamilykeys] +\ltxkeyssavexfamilykeys<|A(id)>{|A(keylist)} +\ltxkeyssavexfamilykeys|*<|A(id)>|A(keylistcmd) -\ltxkeys@savexfamilykeys<|A(id)>|(|A(keytype)|){|A(keylist)} -\ltxkeys@savexfamilykeys|*<|A(id)>|(|A(keytype)|)|A(keylistcmd) +\ltxkeyssavexfamilykeys<|A(id)>|(|A(keytype)|){|A(keylist)} +\ltxkeyssavexfamilykeys|*<|A(id)>|(|A(keytype)|)|A(keylistcmd) -\ltxkeys@definexfamilykeys<|A(id)>[|A(pref)]{|A(fam)}[|A(mp)]{|A(na)} -\ltxkeys@definexfamilykeys|*<|A(id)>[|A(pref)]{|A(fam)}[|A(mp)]{|A(na)} +\ltxkeysdefinexfamilykeys<|A(id)>[|A(pref)]{|A(fam)}[|A(mp)]{|A(na)} +\ltxkeysdefinexfamilykeys|*<|A(id)>[|A(pref)]{|A(fam)}[|A(mp)]{|A(na)} \finish{newmacro} -\fxim*{\ltxkeys@savexfamilykeys,\ltxkeys@definexfamilykeys} +\fxim*{\ltxkeyssavexfamilykeys,\ltxkeysdefinexfamilykeys} -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{\ltxkeys@definekeys} and \emfx{\ltxkeys@declarekeys} is where you now have to locate \ang{na}}. For any use of the command \fx{\ltxkeys@definexfamilykeys} we expect the \ang{na} to be far less than the remaining keys. The \stform of \fx{\ltxkeys@savexfamilykeys} will expand \ang{keylistcmd} once before saving the xfamily keys. The \stform of \fx{\ltxkeys@definexfamilykeys} will define only definable keys, in the sense of \hx{\newcommand}. +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}. -\ang{keylist} and \ang{keylistcmd} have the same syntax as the last arguments of \ffx'{\ltxkeys@definekeys,\ltxkeys@declarekeys}: +\ang{keylist} and \ang{keylistcmd} have the same syntax as the last arguments of \ffx'{\ltxkeysdefinekeys,\ltxkeysdeclarekeys}: \start'{newmacro}[Syntax of keylist] |A(keytype)/|A(keyname)/|A(dft)/|A(cbk); @@ -715,14 +918,14 @@ another set of key attributes; etc. \finish{newmacro} -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 dependants after \ang{cbk} (see the syntaxes of the commands \ffx'{\ltxkeys@definekeys, \ltxkeys@declarekeys}). +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 dependants after \ang{cbk} (see the syntaxes of the commands \ffx'{\ltxkeysdefinekeys, \ltxkeysdeclarekeys}). The mandatory identifier \ang{id} for each list must be unique, not withstanding the fact that the identifiers have their separate namespace. -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{\ltxkeys@savexfamilykeys}. The parenthesis can't appear with an empty content. +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. \start+{example}[xfamily keys] -\ltxkeys@savexfamilykeys<x1>{% +\ltxkeyssavexfamilykeys<x1>{% ord/keya/\paperwidth/\mylength=#1; cmd/keyb/black/\def\y##1{##1}; choice/keyc.{left,right,center}/center/\def\z##1{##1}; @@ -731,75 +934,75 @@ If the xfamily keys are all of the same type (\ie, only one of the types \fnz{or |com(Now define the keys previously stored with the id no. x1.) |com(For now don't define keys keyb and keyc:) -\ltxkeys@definexfamilykeys<x1>[KV]{fam}[mp@]{keyb,keyc} +\ltxkeysdefinexfamilykeys<x1>[KV]{fam}[mp@]{keyb,keyc} |com(Once defined the keys can be executed separately:) -\ltxkeys@setkeys[KV]{fam}{keya=.5\hsize,keyd=false} +\ltxkeyssetkeys[KV]{fam}{keya=.5\hsize,keyd=false} \show\ifmp@keyd |com(Now define the keys previously stored with the id no. x1 for) |com(another family. This time we don't want to define key keyb:) -\ltxkeys@definexfamilykeys<x1>[KVA]{|R(fama)}[mpa@]{keyb} +\ltxkeysdefinexfamilykeys<x1>[KVA]{|R(fama)}[mpa@]{keyb} |com(You can save and define xfamily keys of only one key type,) |com(command keys in the following example:) -\ltxkeys@savexfamilykeys<x1>|R(|(cmd|)){% +\ltxkeyssavexfamilykeys<x1>|R(|(cmd|)){% keya/\paperwidth; keyb/blue/\def\x##1{#1x##1}; } |com(Define the saved keys and ignore none of them:) -\ltxkeys@definexfamilykeys|*<x1>[KV]{fam}[mp@]{} -\ltxkeys@setkeys[KV]{fam}{keya=.5\hsize,keyb=red} +\ltxkeysdefinexfamilykeys|*<x1>[KV]{fam}[mp@]{} +\ltxkeyssetkeys[KV]{fam}{keya=.5\hsize,keyb=red} \finish{example} -\fxi*{\ltxkeys@savexfamilykeys,\ltxkeys@definexfamilykeys} +\fxi*{\ltxkeyssavexfamilykeys,\ltxkeysdefinexfamilykeys} \start+{example}[xfamily keys] |com(`keya' and `keyd' are starred style keys but `keyd' has no dependants:) -\ltxkeys@savexfamilykeys<a1>|(sty|*|){% - keya/center/.code=\def\xx##1{##1xx#1}/ +\ltxkeyssavexfamilykeys<a1>|(sty|*|){% + keya/center/.do=\def\xx##1{##1xx#1}/ ord>\needvalue{keyb}>\parentval>\edef\yy##1{##1yy\unexpanded{#1}}, |com(The braces around `center' |(the default value of `keyc'|)) |com(will be preserved in parsing:) cmd>keyc>{center}; |com(The braces around the callback of `keyd' will be preserved:) - keyd/red/.code={\def\x{\color{#1}print aaa}}; + keyd/red/.do={\def\x{\color{#1}print aaa}}; } |com(Ignore `keyd' in defining keys saved in `a1':) -\ltxkeys@definexfamilykeys*<a1>[KV]{fam}[mp@]{keyd} +\ltxkeysdefinexfamilykeys*<a1>[KV]{fam}[mp@]{keyd} |com(On setting `keya', `keyb' and `keyc' will be defined and initialized:) -\ltxkeys@setkeys[KV]{fam}{keya=left} +\ltxkeyssetkeys[KV]{fam}{keya=left} \finish{example} -\aidx*{/.code} +\aidx*{/.do} Here is a real-life example that mimics some of the macros of the \pkg'{xwatermark}: \start+{example}[xfamily keys] -\ltxkeys@savexfamilykeys<a1>{% +\ltxkeyssavexfamilykeys<a1>{% cmd/width/\textwidth; cmd/textcolor/black; cmd/framecolor/black; cmd/framesep/3\p@; cmd/framerule/0.4\p@; choice/textalign|R(.){% - center/.code=\def\mp@textalign{center}, - left/.code=\def\mp@textalign{flushleft}, - right/.code=\def\mp@textalign{flushright} + center/.do=\def\mp@textalign{center}, + left/.do=\def\mp@textalign{flushleft}, + right/.do=\def\mp@textalign{flushright} }/center; bool/framebox/true; ord/junkkey/throwaway; } |com(Ignore keys `framebox' and `junkkey' when defining family `ltxframebox':) -\ltxkeys@definexfamilykeys*<a1>[KV]{ltxframebox}[mp@]{framebox,junkkey} +\ltxkeysdefinexfamilykeys*<a1>[KV]{ltxframebox}[mp@]{framebox,junkkey} |com(Ignore key `junkkey' when defining family `ltxminipage':) -\ltxkeys@definexfamilykeys<a1>[KV]{ltxminipage}[mp@]{junkkey} +\ltxkeysdefinexfamilykeys<a1>[KV]{ltxminipage}[mp@]{junkkey} |com(No key is ignored when defining `junkfamily':) -\ltxkeys@definexfamilykeys<a1>[KVX]{junkfamily}[mp@]{} +\ltxkeysdefinexfamilykeys<a1>[KVX]{junkfamily}[mp@]{} \newcommand*\ltxframebox[2][]{% - \ltxkeys@setkeys[KV]{ltxframebox}{#1}% + \ltxkeyssetkeys[KV]{ltxframebox}{#1}% \begingroup \fboxsep\mp@framesep\fboxrule\mp@framerule - \cptdimdef\mp@boxwidth{\mp@width-2\fboxsep-2\fboxrule}% + \ltsdimdef\mp@boxwidth{\mp@width-2\fboxsep-2\fboxrule}% \color{\mp@framecolor}% \noindent \fbox{% @@ -813,11 +1016,11 @@ Here is a real-life example that mimics some of the macros of the \pkg'{xwaterma \endgroup } \newcommand*\ltxminipage[2][]{% - \ltxkeys@setkeys[KV]{ltxminipage}{#1}% + \ltxkeyssetkeys[KV]{ltxminipage}{#1}% \begingroup \fboxsep\mp@framesep \fboxrule\ifmp@framebox\mp@framerule\else\z@\fi - \cptdimdef\mp@boxwidth{\mp@width-2\fboxsep-2\fboxrule}% + \ltsdimdef\mp@boxwidth{\mp@width-2\fboxsep-2\fboxrule}% \noindent\begin{lrbox}\@tempboxa \begin{minipage}[c][\height][s]\mp@boxwidth \@killglue @@ -846,7 +1049,7 @@ Here is a real-life example that mimics some of the macros of the \pkg'{xwaterma } \end{document} \finish{example} -\fxi*{\ltxkeys@savexfamilykeys,\ltxkeys@definexfamilykeys} +\fxi*{\ltxkeyssavexfamilykeys,\ltxkeysdefinexfamilykeys} \docsection(sec:settingkeys)<setting keys>{Setting keys} @@ -856,17 +1059,17 @@ In the \pkg'{ltxkeys} there are many functions for setting keys. Keys can be set \docsubsection{Setting defined keys} -\start+{newmacro}[\ltxkeys@setkeys] -\ltxkeys@setkeys[|A(pref)]{|A(fam)}[|A(na)]{|A(keyval)} -\ltxkeys@setkeys|*[|A(pref)]{|A(fam)}[|A(na)]{|A(keyval)} -\ltxkeys@setkeys|+[|A(prefs)]{|A(fams)}[|A(na)]{|A(keyval)} -\ltxkeys@setkeys|*|+[|A(prefs)]{|A(fams)}[|A(na)]{|A(keyval)} +\start+{newmacro}[\ltxkeyssetkeys] +\ltxkeyssetkeys[|A(pref)]{|A(fam)}[|A(na)]{|A(keyval)} +\ltxkeyssetkeys|*[|A(pref)]{|A(fam)}[|A(na)]{|A(keyval)} +\ltxkeyssetkeys|+[|A(prefs)]{|A(fams)}[|A(na)]{|A(keyval)} +\ltxkeyssetkeys|*|+[|A(prefs)]{|A(fams)}[|A(na)]{|A(keyval)} \finish{newmacro} -\fxim*{\ltxkeys@setkeys} +\fxim*{\ltxkeyssetkeys} -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 \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{\ltxkeys@setrmkeys}. 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. +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. -To avoid infinite re-entrance of \fx{\ltxkeys@setkeys} and the consequent bombing out of the command, the package option \fxim{keydepthlimit} is introduced. Its default value is~4, meaning that \fx{\ltxkeys@setkeys} can't ordinarily be nested beyond level~4. If you must nest \fx{\ltxkeys@setkeys} beyond this level, an unlikely need, you can raise the \fx{keydepthlimit} as a package option via \hx{\usepackage} or, if \pkg'{catoptions} is loaded before \hx{\documentclass}, via \hx{\documentclass}. For example, +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, \start'{example}[Setting keydepthlimit] \usepackage[keydepthlimit=6]{ltxkeys} @@ -878,76 +1081,78 @@ The more appropriate name \fxi{keystacklimit} is an alias for \fx{keydepthlimit} \docsubsection(sec:rmkeys)<rmkeys,remaining keys>{Setting \headquoted{remaining} keys} -The command \fx{\ltxkeys@setrmkeys}, which has both star (\redstar) and plus (\redplus) variants, is the counterpart of \fx{\setrmkeys} of the \pkg'{xkeyval}: +The command \fx{\ltxkeyssetrmkeys}, which has both star (\redstar) and plus (\redplus) variants, is the counterpart of \fx{\setrmkeys} of the \pkg'{xkeyval}: -\start{newmacro}[\ltxkeys@setrmkeys] -\ltxkeys@setrmkeys[|A(pref)]{|A(fam)}[|A(na)] -\ltxkeys@setrmkeys|*[|A(pref)]{|A(fam)}[|A(na)] -\ltxkeys@setrmkeys|+[|A(prefs)]{|A(fams)}[|A(na)] -\ltxkeys@setrmkeys|*|+[|A(prefs)]{|A(fams)}[|A(na)] +\start{newmacro}[\ltxkeyssetrmkeys] +\ltxkeyssetrmkeys[|A(pref)]{|A(fam)}[|A(na)] +\ltxkeyssetrmkeys|*[|A(pref)]{|A(fam)}[|A(na)] +\ltxkeyssetrmkeys|+[|A(prefs)]{|A(fams)}[|A(na)] +\ltxkeyssetrmkeys|*|+[|A(prefs)]{|A(fams)}[|A(na)] \finish{newmacro} -\fxim*{\ltxkeys@setrmkeys} +\fxim*{\ltxkeyssetrmkeys} -The command \fx{\ltxkeys@setrmkeys} sets in the given prefixes and families the \quoted{remaining keys} saved when calling the \stform of \fx{\ltxkeys@setkeys} or \fx{\ltxkeys@setrmkeys}. \ang{na} is again the list of keys that should be ignored, \ie, not executed and not saved. The \unstform of \fx{\ltxkeys@setrmkeys} will report an error if a key is undefined. The \stform of the macro \fx{\ltxkeys@setrmkeys}, like the \stform of \fx{\ltxkeys@setkeys}, ignores keys that it cannot find and saves them on the list saved for a future call to \fx{\ltxkeys@setrmkeys}. Keys listed in \ang{na} will be ignored fully and will not be appended to the saved list of remaining keys. +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. \docsubsection(sec:aliasedkeys)<aliased keys>{Setting aliased keys} -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. +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.}. -\start{newmacro}[\ltxkeys@setaliaskey] -\ltxkeys@setaliaskey{|A(key)}[|A(value)] +\start{newmacro}[\ltxkeyssetaliaskey] +\ltxkeyssetaliaskey{|A(key)}[|A(value)] \finish{newmacro} -\fxim*{\ltxkeys@setaliaskey} +\fxim*{\ltxkeyssetaliaskey} -Here, \ang{value} is optional; if it is not given, \ang{key} will be set with the current value of its alias. The command \fxis'{\setaliaskey}{\ltxkeys@setaliaskey} is a shortened variant of \fx{\ltxkeys@setaliaskey}. +Here, \ang{value} is optional; if it is not given, \ang{key} will be set with the current value of its alias. -\start+{example}[\ltxkeys@setaliaskey] -\ltxkeys@definekeys|*[KV]{fam}[mp@]{% +\start+{example}[\ltxkeyssetaliaskey] +\ltxkeysdefinekeys|*[KV]{fam}[mp@]{% printsign=true; - printmark=true/\ltxkeys@setaliaskey{printsign}[false]; + printmark=true/\ltxkeyssetaliaskey{printsign}[false]; keya=$+++$; - keyb=star/\ltxkeys@setaliaskey{keya}[$***$] + keyb=star/\ltxkeyssetaliaskey{keya}[$***$] } -\ltxkeys@definekeys|*[KV]{fam}[mp@]{% - keya=sun/\CheckUserInput{#1}{star,sun,moon} - \ifinputvalid +\ltxkeysdefinekeys|*[KV]{fam}[mp@]{% + keya=sun/\ltxkeyscheckuserinput{#1}{star,sun,moon} + \ifltxkeysinputvalid \edef\givenval{\userinput} \edef\found{\ifcase\order star@\or sun@\or moon@\fi} \else \@latex@error{Input `#1' not valid}\@ehd \fi; - keyb=star/\ltxkeys@setaliaskey{keya}; + keyb=star/\ltxkeyssetaliaskey{keya}; } \finish{example} -The boolean \fx{\ifinputvalid} associated with the command \fx{\CheckUserInput} is described in \sref{mac:ifinputvalid} (see also \sref{sec:checkchoice}). +The boolean \fx{\ifltxkeysinputvalid} associated with the command \fx{\ltxkeyscheckuserinput} is described in \sref{mac:ifltxkeysinputvalid} (see also \sref{sec:checkchoice}). -The example involving \quotedlist'{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. +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. -Schemes like the following are disallowed, to avoid back-linking of \fx{\ltxkeys@setaliaskey}. The package will flag an error if something like the following occurs: +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: -\start+{example}[Illegal nested \ltxkeys@setaliaskey] -\ltxkeys@ordkey[KV]{fam}{keya}[true]{\setaliaskey{keyb}} -\ltxkeys@ordkey[KV]{fam}{keyb}[true]{\setaliaskey{keya}} -\ltxkeys@setkeys[KV]{fam}{keya} +\start+{example}[Illegal nested \ltxkeyssetaliaskey] +\ltxkeys@ordkey[KV]{fam}{keya}[true]{\ltxkeyssetaliaskey{keyb}} +\ltxkeys@ordkey[KV]{fam}{keyb}[true]{\ltxkeyssetaliaskey{keya}} +\ltxkeyssetkeys[KV]{fam}{keya} \finish{example} -\aidx*{no nested \headfx{\setaliaskey}} +\aidx*{no nested \headfx{\ltxkeyssetaliaskey}} \docsubsection(sec:keypointers){Using key pointers} \aidx*{key pointers} \aidxs*{pointers}{key pointers} -The \ffx'{\savevalue,\usevalue} pointers of the \pkg'{xkeyval} are still available at key setting time, but with increased robustness and optimization. Curly braces in values are preserved throughout, and instead of saving the value of each key tagged with \fx{\savevalue} 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}). +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. -The pointer \fx{\needvalue} is a new type. It 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'{\savevalue,\usevalue,\needvalue} can all be called when defining keys. The pointer \fx{\usevalue} will, however, be ignored when defining keys, \ie, if present, it's simply dropped. If required at setting keys, it has to be explicitly indicated there. The pointers \ffx'{\savevalue,\usevalue} can both be used when setting keys, but not the pointer \fx{\needvalue}. The presence of the pointer \fx{\needvalue} when setting keys prompts an error. +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. + +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}). Here is an interesting example and proof of concept of pointers: \start'{example}[Key pointers] \ltxkeys@stylekeys|*[KV]{fam}{% - \needvalue{keya},\savevalue\needvalue{keyb},\needvalue\savevalue{keyc} + \needvalue{keya},\savevalue\needvalue{keyb},\gneedvalue\gsavevalue{keyc} }[{left}]|(% |com(`#1' here refers to the value of the dependant key at the) |com(time it is being set.) @@ -959,17 +1164,17 @@ Here is an interesting example and proof of concept of pointers: \def\x##1{##1xx#1} } -\ltxkeys@setkeys[KV]{fam}{% - \savevalue{keya}={\def\y##1{##1}}, +\ltxkeyssetkeys[KV]{fam}{% + \gsavevalue{keya}={\def\y##1{##1}}, \savevalue{keyb}=\usevalue{keya}, keyc=\usevalue{keyb} } \finish{example} -\fxi*{\savevalue,\usevalue,\needvalue} +\fxi*{\savevalue,\gsavevalue,\usevalue,\needvalue, \gneedvalue, \forbidvalue, \gforbidvalue} -If you have to save the values of many keys, then the above scheme of placing \fx{\savevalue} on keys at key setting time can be avoided by using the following commands: +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: -\start+{newmacro}[\ltxkeys@savevaluekeys,\ltxkeys@addsavevaluekeys, etc] +\start+{newmacro}[\ltxkeys@savevaluekeys,\ltxkeys@addsavevaluekeys, etc.] \ltxkeys@savevaluekeys[|A(pref)]{|A(fam)}{|A(list)} \ltxkeys@addsavevaluekeys[|A(pref)]{|A(fam)}{|A(list)} \ltxkeys@removesavevaluekeys[|A(pref)]{|A(fam)}{|A(list)} @@ -979,9 +1184,11 @@ If you have to save the values of many keys, then the above scheme of placing \f \ltxkeys@emptifysavevaluekeys|![|A(pref)]{|A(fam)} \finish{newmacro} \fxim*{\ltxkeys@savevaluekeys,\ltxkeys@addsavevaluekeys, - \ltxkeys@removesavevaluekeys,\ltxkeys@undefsavevaluekeys} + \ltxkeys@removesavevaluekeys,\ltxkeys@undefsavevaluekeys, + \ltxkeys@emptifysavevaluekeys} 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. The command \fx{\ltxkeys@emptifysavevaluekeys} will simplify emptify the content of the save-key list. The \clform of the commands + \start+{macro} \ltxkeys@undefsavevaluekeys \ltxkeys@emptifysavevaluekeys @@ -990,7 +1197,7 @@ The command \fx{\ltxkeys@savevaluekeys} will create, for the given key family an will undefine or emptify the existing save-key list globally. \start+{example}[\ltxkeys@savevaluekeys] -\ltxkeys@definekeys[KV]{fam}[mp@]{% +\ltxkeysdefinekeys[KV]{fam}[mp@]{% ord/keya/2cm/\def\x##1{#1xx##1}; cmd/keyb/John; bool/keyc/true/\ifmp@keyc\def\y##1{##1yy#1}\fi; @@ -1003,30 +1210,58 @@ will undefine or emptify the existing save-key list globally. \ltxkeys@removesavevaluekeys[KV]{fam}{keya,keyb} \ltxkeys@undefsavevaluekeys[KV]{fam} -\ltxkeys@setkeys[KV]{fam}{keya=\usevalue{keyc},keyb=\usevalue{keya}} +\ltxkeyssetkeys[KV]{fam}{keya=\usevalue{keyc},keyb=\usevalue{keya}} \finish{example} +The following commands are also available: + +\start+{newmacro}[\ltxkeys@needvaluekeys,\ltxkeys@addneedvaluekeys, etc.] +\ltxkeys@needvaluekeys[|A(pref)]{|A(fam)}{|A(list)} +\ltxkeys@addneedvaluekeys[|A(pref)]{|A(fam)}{|A(list)} +\ltxkeys@removeneedvaluekeys[|A(pref)]{|A(fam)}{|A(list)} +\ltxkeys@undefneedvaluekeys[|A(pref)]{|A(fam)} +\ltxkeys@undefneedvaluekeys|![|A(pref)]{|A(fam)} +\ltxkeys@emptifyneedvaluekeys[|A(pref)]{|A(fam)} +\ltxkeys@emptifyneedvaluekeys|![|A(pref)]{|A(fam)} + +\ltxkeys@forbidvaluekeys[|A(pref)]{|A(fam)}{|A(list)} +\ltxkeys@addforbidvaluekeys[|A(pref)]{|A(fam)}{|A(list)} +\ltxkeys@removeforbidvaluekeys[|A(pref)]{|A(fam)}{|A(list)} +\ltxkeys@undefforbidvaluekeys[|A(pref)]{|A(fam)} +\ltxkeys@undefforbidvaluekeys|![|A(pref)]{|A(fam)} +\ltxkeys@emptifyforbidvaluekeys[|A(pref)]{|A(fam)} +\ltxkeys@emptifyforbidvaluekeys|![|A(pref)]{|A(fam)} +\finish{newmacro} +\fxim*{\ltxkeys@needvaluekeys,\ltxkeys@addneedvaluekeys, + \ltxkeys@removeneedvaluekeys,\ltxkeys@undefneedvaluekeys, + \ltxkeys@emptifyneedvaluekeys, + \ltxkeys@forbidvaluekeys,\ltxkeys@addforbidvaluekeys, + \ltxkeys@removeforbidvaluekeys,\ltxkeys@undefforbidvaluekeys, + \ltxkeys@emptifyforbidvaluekeys +} + + \docsubsection(sec:savedvalueofkey) <saved value of key>{Accessing the saved value of a key} -As mentioned earlier, the pointers \ffx'{\savevalue, \usevalue} are available for saving and using the values of keys within the command \fx{\ltxkeys@setkeys}. But suppose you have used \fx{\savevalue} within \fx{\ltxkeys@setkeys} to set the value of a key, how do you access that value outside of \fx{\ltxkeys@setkeys}? You can do this by using the following \fx{\ltxkeys@storevalue} command: +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: -\start{newmacro}[\ltxkeys@storevalue] -\ltxkeys@storevalue[|A(pref)]{|A(fam)}{|A(key)}|A(cs) -\ltxkeys@storevalue|+[|A(pref)]{|A(fam)}{|A(key)}|A(cs)|A(fallback) +\start{newmacro}[\ltxkeysstorevalue] +\ltxkeysstorevalue[|A(pref)]{|A(fam)}{|A(key)}|A(cs) +\ltxkeysstorevalue|+[|A(pref)]{|A(fam)}{|A(key)}|A(cs)|A(fallback) \finish{newmacro} -\fxim*{\ltxkeys@storevalue} +\fxim*{\ltxkeysstorevalue} 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. -\start+{example}[\ltxkeys@storevalue] +\start+{example}[\ltxkeysstorevalue] \ltxkeys@cmdkey[KV]{fam}{\needvalue{keya}}[{left}]{% \def\x##1{##1xx#1} } -\ltxkeys@setkeys[KV]{fam}{\savevalue{keya}={\def\y##1{##1}}} -\ltxkeys@storevalue[KV]{fam}{keya}\tempa -\ltxkeys@storevalue|+[KV]{fam}{keya}\tempb{% - \@latex@error{No value saved for key 'keya'}\@ehc +\ltxkeyssetkeys[KV]{fam}{\savevalue{keya}={\def\y##1{##1}}} +\ltxkeysstorevalue[KV]{fam}{keya}\tempa +\ltxkeysstorevalue|+[KV]{fam}{keya}\tempb{% + \@latex@error{No value saved for key `keya'}\@ehc } \finish{example} @@ -1035,21 +1270,21 @@ Here, \ang{cs} is the macro (defined or undefined) that will receive the saved v \aidxm*{presetting keys, post-setting keys} \start+{newmacro}[\ltxkeys@presetkeys,\ltxkeys@postsetkeys,etc.] -\ltxkeys@presetkeys[|A(pref)]{|A(fam)}{|A(keys)} -\ltxkeys@presetkeys|![|A(pref)]{|A(fam)}{|A(keys)} -\ltxkeys@addpresetkeys[|A(pref)]{|A(fam)}{|A(keys)} -\ltxkeys@addpresetkeys|![|A(pref)]{|A(fam)}{|A(keys)} -\ltxkeys@removepresetkeys[|A(pref)]{|A(fam)}{|A(keys)} -\ltxkeys@removepresetkeys|![|A(pref)]{|A(fam)}{|A(keys)} +\ltxkeys@presetkeys[|A(pref)]{|A(fam)}{|A(keyvals)} +\ltxkeys@presetkeys|![|A(pref)]{|A(fam)}{|A(keyvals)} +\ltxkeys@addpresetkeys[|A(pref)]{|A(fam)}{|A(keyvals)} +\ltxkeys@addpresetkeys|![|A(pref)]{|A(fam)}{|A(keyvals)} +\ltxkeys@removepresetkeys[|A(pref)]{|A(fam)}{|A(keyvals)} +\ltxkeys@removepresetkeys|![|A(pref)]{|A(fam)}{|A(keyvals)} \ltxkeys@undefpresetkeys[|A(pref)]{|A(fam)} \ltxkeys@undefpresetkeys|![|A(pref)]{|A(fam)} -\ltxkeys@postsetkeys[|A(pref)]{|A(fam)}{|A(keys)} -\ltxkeys@postsetkeys|![|A(pref)]{|A(fam)}{|A(keys)} -\ltxkeys@addpostsetkeys[|A(pref)]{|A(fam)}{|A(keys)} -\ltxkeys@addpostsetkeys|![|A(pref)]{|A(fam)}{|A(keys)} -\ltxkeys@removepostsetkeys[|A(pref)]{|A(fam)}{|A(keys)} -\ltxkeys@removepostsetkeys|![|A(pref)]{|A(fam)}{|A(keys)} +\ltxkeys@postsetkeys[|A(pref)]{|A(fam)}{|A(keyvals)} +\ltxkeys@postsetkeys|![|A(pref)]{|A(fam)}{|A(keyvals)} +\ltxkeys@addpostsetkeys[|A(pref)]{|A(fam)}{|A(keyvals)} +\ltxkeys@addpostsetkeys|![|A(pref)]{|A(fam)}{|A(keyvals)} +\ltxkeys@removepostsetkeys[|A(pref)]{|A(fam)}{|A(keyvals)} +\ltxkeys@removepostsetkeys|![|A(pref)]{|A(fam)}{|A(keyvals)} \ltxkeys@undefpostsetkeys[|A(pref)]{|A(fam)} \ltxkeys@undefpostsetkeys|![|A(pref)]{|A(fam)} \finish{newmacro} @@ -1057,7 +1292,9 @@ Here, \ang{cs} is the macro (defined or undefined) that will receive the saved v \ltxkeys@undefpresetkeys,\ltxkeys@postsetkeys,\ltxkeys@addpostsetkeys, \ltxkeys@removepostsetkeys,\ltxkeys@undefpostsetkeys} -The optional \redclam here, as in many 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{\ltxkeys@setkeys} for the given key prefix and family}. \fx{\ltxkeys@addpresetkeys} is an alias for \fx{\ltxkeys@presetkeys}, and this helps explain that \fx{\ltxkeys@presetkeys} is indeed a list merger. Neither the command \fx{\ltxkeys@presetkeys} nor \fx{\ltxkeys@postsetkeys} set keys itself, contrary to what the names might suggest. \quoted{Post-setting keys} means \quoted{these keys are to be set after setting other keys in every run of \fx{\ltxkeys@setkeys} for the given key prefix and family}. \fx{\ltxkeys@addpostsetkeys} is an alias for \fx{\ltxkeys@postsetkeys}. The commands +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{\ltxkeys@addpresetkeys} is an alias for \fx{\ltxkeys@presetkeys}, and this helps explain that \fx{\ltxkeys@presetkeys} is indeed a list merger. Neither the command \fx{\ltxkeys@presetkeys} nor \fx{\ltxkeys@postsetkeys} set keys itself, contrary to what the names might suggest. + +\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{\ltxkeys@addpostsetkeys} is an alias for \fx{\ltxkeys@postsetkeys}. The commands \start+{macro} \ltxkeys@removepresetkeys|![|A(pref)]{|A(fam)}{|A(keys)} @@ -1076,7 +1313,7 @@ respectively, undefine all preset and post-set keys in the given family. Logically, you can't enter the same key twice in either preset or post-set list in the same family and prefix. \start+{example}[\ltxkeys@presetkeys, \ltxkeys@postsetkeys, etc.] -\ltxkeys@definekeys|*[KV1]{fam1}[mp@]{% +\ltxkeysdefinekeys|*[KV1]{fam1}[mp@]{% keya/left/\def\x##1{#1x##1}; \needvalue{keyb}/right; keyc/center; @@ -1088,24 +1325,24 @@ Logically, you can't enter the same key twice in either preset or post-set list |com(Eventually, only `keya' will be preset:) \ltxkeys@removepresetkeys|![KV1]{fam1}{keyb=\flushright} ... -|com(Because of the |redstar and |redplus signs on \ltxkeys@setkeys, all unknown) +|com(Because of the |redstar and |redplus signs on \ltxkeyssetkeys, all unknown) |com(keys |(those with prefix `KV2' and in family `fam2'|) will be saved in) -|com(the list of remaining keys, and can be set later with \ltxkeys@setrmkeys:) -\ltxkeys@setkeys|*|+[KV1,KV2]{fam1,fam2}[keyd]{keya=xxx,keyb=yyy,keyc} +|com(the list of remaining keys, and can be set later with \ltxkeyssetrmkeys:) +\ltxkeyssetkeys|*|+[KV1,KV2]{fam1,fam2}[keyd]{keya=xxx,keyb=yyy,keyc} \finish{example} \docsubsection(sec:initializekeys) <initializing keys>{Initializing keys} -\start{newmacro}[\ltxkeys@initializekeys] -\ltxkeys@initializekeys[|A(prefs)]{|A(fams)}[|A(na)] +\start{newmacro}[\ltxkeysinitializekeys] +\ltxkeysinitializekeys[|A(prefs)]{|A(fams)}[|A(na)] \finish{newmacro} -\fxim*{\ltxkeys@initializekeys} +\fxim*{\ltxkeysinitializekeys} -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'{\ltxkeys@definekeys, \ltxkeys@declarekeys} are automatically instantly initialized, except slave/alias and dependant keys. Alias and dependant keys aren't initialized in this case in order to avoid cyclic re-entrance of \fx{\ltxkeys@setkeys}. +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 dependant keys. Alias and dependant keys aren't initialized in this case in order to avoid cyclic re-entrance of \fx{\ltxkeyssetkeys}. -The command \fx{\ltxkeys@initializekeys} can be used in place of \fx{\ltxkeys@executeoptions}, since \fx{\ltxkeys@executeoptions} (similar to \latex kernel's \hx{\ExecuteOptions}) fulfils the sole purpose of setting up default values of options. Keys defined via \ffx'{\ltxkeys@definekeys, \ltxkeys@declarekeys} don't have to be initialized, since they're automatically initialized at definition time. +The command \fx{\ltxkeysinitializekeys} can be used in place of \fx{\ltxkeys@executeoptions}, since \fx{\ltxkeys@executeoptions} (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}. \begin{noteenv} \label{nte:initializekeys} @@ -1115,23 +1352,23 @@ Keys that have been processed by \fx{\ltxkeys@processoptions} (\ie, keys submitt \docsubsection(sec:launchingkeys)<launching keys>{Launching keys} -\start{newmacro}[\ltxkeys@launchkeys] -\ltxkeys@launchkeys[|A(prefs)]{|A(fams)}{|A(curr)} -\ltxkeys@launchkeys|*[|A(prefs)]{|A(fams)}{|A(curr)} -\ltxkeys@launchkeys|+[|A(prefs)]{|A(fams)}{|A(curr)} -\ltxkeys@launchkeys|*|+[|A(prefs)]{|A(fams)}{|A(curr)} +\start{newmacro}[\ltxkeyslaunchkeys] +\ltxkeyslaunchkeys[|A(prefs)]{|A(fams)}{|A(curr)} +\ltxkeyslaunchkeys|*[|A(prefs)]{|A(fams)}{|A(curr)} +\ltxkeyslaunchkeys|+[|A(prefs)]{|A(fams)}{|A(curr)} +\ltxkeyslaunchkeys|*|+[|A(prefs)]{|A(fams)}{|A(curr)} \finish{newmacro} -\fxim*{\ltxkeys@launchkeys} +\fxim*{\ltxkeyslaunchkeys} -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'{\ltxkeys@launchkeys, \ltxkeys@initializekeys} is that in \fx{\ltxkeys@launchkeys} 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{\ltxkeys@launchkeys} will be the \ang{na} (ignored) keys for the command \fx{\ltxkeys@initializekeys}. +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}. -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{\ltxkeys@launchkeys} have the same meaning as in \fx{\ltxkeys@setkeys} (\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{\ltxkeys@setrmkeys}. 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. +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. \docsubsubsection(sec:nonlaunchkeys) - <non-launch keys>{Non-initialize and non-launch keys} + <non-launch keys>{Noninitialize and non\-la\-unch keys} -Listing all the keys that shouldn't be reinitialized by \fx{\ltxkeys@initializekeys} in the \ang{na} list every time \fx{\ltxkeys@initializekeys} 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{\ltxkeys@launchkeys}). This might be the case with package and class options. The command \fx{\ltxkeys@nonlaunchkeys} 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{\ltxkeys@launchkeys} or \fx{\ltxkeys@initializekeys}, they can be listed in the \fx{\ltxkeys@nonlaunchkeys} command: +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{\ltxkeys@nonlaunchkeys} 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{\ltxkeys@nonlaunchkeys} command: \start{newmacro}[\ltxkeys@nonlaunchkeys] \ltxkeys@nonlaunchkeys[|A(prefs)]{|A(fams)}{|A(keys)} @@ -1140,36 +1377,43 @@ Listing all the keys that shouldn't be reinitialized by \fx{\ltxkeys@initializek Keys across multiple prefixes and families can be submitted to the \fx{\ltxkeys@nonlaunchkeys} command: undefined keys are simply ignored by \fx{\ltxkeys@nonlaunchkeys}. -\ltsnote The command \fx{\ltxkeys@nonlaunchkeys} doesn't mean that the keys in \ang{keys} can no longer be set via the command \fx{\ltxkeys@setkeys}; it simply implies that keys appearing in \fx{\ltxkeys@nonlaunchkeys} will not be reinitialized to their default values when members of their class are being launched or reinitialized. The command \fx{\ltxkeys@noninitializekeys} is an alias for \fx{\ltxkeys@nonlaunchkeys}. +\ltsnote +The command \fx{\ltxkeys@nonlaunchkeys} 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{\ltxkeys@nonlaunchkeys} will not be reinitialized to their default values when members of their class are being launched or reinitialized. The command \fx{\ltxkeys@noninitializekeys} is an alias for \fx{\ltxkeys@nonlaunchkeys}. \docsubsection(sec:unknownkeyhandler) <unknown key and option handlers>{Handling unknown keys and options} -You can use the macro \fx{\ltxkeys@unknownkeyhandler} to declare to the \pkg'{ltxkeys} the course of action to take if, while setting keys, it discovers that a key is undefined or unknown. The command \fx{\ltxkeys@unknownoptionhandler} applies to unknown options (see \sref{sec:declareoption})\usefootnote{2}. The syntax of these commands is +You can use the macro \fx{\ltxkeys@unknownkeyhandler} 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{\ltxkeys@unknownoptionhandler} applies to unknown options (see \sref{sec:declareoption})\usefootnote{2}. The syntax of these commands is \start+{newmacro}[\ltxkeys@unknownkeyhandler,\ltxkeys@unknownoptionhandler] \ltxkeys@unknownkeyhandler[|A(prefs)]{|A(fams)}{|A(cbk)} -\ltxkeys@unknownoptionhandler[|A(pref)]<|A(fam)>{|A(cbk)} +\ltxkeys@unknownoptionhandler[|A(prefs)]<|A(fams)>{|A(cbk)} \finish{newmacro} \fxim*{\ltxkeys@unknownkeyhandler,\ltxkeys@unknownoptionhandler} -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{\CurrentPref}) in this macro to represent the current key prefix, \fx{#2} (or \fx{\CurrentFam}) for the current family, \fx{#3} (or \fx{\CurrentKey}) for the current key name, and \fx{#4} (or \fx{\CurrentVal}) for the value of the current key. If \fx{\CurrentVal} 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{\InnocentVal} instead of \fx{\CurrentVal}. However, \fx{\InnocentVal} detokenizes the current key value and, if the value is more than 20 characters, gives only the first 20 characters of a key's value. +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. -The following example provides an unknown key handler for two key prefixes (\ffx'{KVA, KVB}) and two key families (\ffx'{fam1,fam2}): +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. + +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}). + +\start+{example}[\ltxkeys@unknownkeyhandler,\ltxkeys@unknownoptionhandler] +\ltxkeys@unknownoptionhandler[KV]<fam1,fam2>{% + \wlog{Prefix: #1/ Family: #2/ Option name: #3/ Value: \unexpanded{#4}}% +} -\start+{example}[\ltxkeys@unknownkeyhandler] \ltxkeys@unknownkeyhandler[KVA,KVB]{fam1,fam2}{% \@expandtwoargs\in@{,#3,}{,\myspecialkeys,}% - \ifin@ + \ifdefboolTF{in@}{% |com(The reader may want to investigate what the parameter texts) |com(##1 and ####1 below stand for |(see |sref(nte:unknownkey) below|):) \ltxkeys@ordkey[#1]{#2}{#3}[#4]{\def\x####1{####1xx##1}}% - \else + }{% \ltxmsg@warn{Unknown key `#3' with value `#4' in family `#2' ignored}\@ehd - |com(\ltxmsg@warn{Unknown key `\CurrentKey' with value) - |com( `\InnocentVal' in family `\CurrentFam' ignored}\@ehd) - \fi + |com(\ltxmsg@warn{Unknown key `\ltxkeyscurrentkey' with value) + |com( `\ltxkeysinnocentvalue' in family `\ltxkeyscurrentfamily' ignored}\@ehd) + }% } \finish{example} @@ -1186,11 +1430,11 @@ To see what the parameter texts \fx{##1} and \fx{####1} above stand for, run the \ifin@ \ltxkeys@ordkey[#1]{#2}{#3}[#4]{\def\x####1{####1xx##1}}% \else - \ltxmsg@warn{Unknown key `#3' with value `\InnocentVal' + \ltxmsg@warn{Unknown key `#3' with value `\ltxkeysinnocentvalue' in family `#2' ignored}\@ehd \fi } -\ltxkeys@setkeys[KV]{fam}{keyd=aaa,keye=bbb} +\ltxkeyssetkeys[KV]{fam}{keyd=aaa,keye=bbb} \show\KV@fam@keyd \finish{example} @@ -1208,17 +1452,66 @@ To see what the parameter texts \fx{##1} and \fx{####1} above stand for, run the 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. -\docsection(sec:disablingkeys)<disabling keys>{Disabling keys} +\docsection(sec:disablingkeys)<disabling keys>{Disabling families and keys} + +\docsubsection{Disabling families} + +\start{newmacro}[\ltxkeys@disablefamilies,\ltxkeys@gdisablefamilies] +\ltxkeys@disablefamilies[|A(prefs)]{|A(fams)}[|A(nakeys)] +\ltxkeys@disablefamilies|*[|A(prefs)]{|A(fams)}[|A(nakeys)] +\ltxkeys@gdisablefamilies[|A(prefs)]{|A(fams)}[|A(nakeys)] +\ltxkeys@gdisablefamilies|*[|A(prefs)]{|A(fams)}[|A(nakeys)] +\finish{newmacro} +\fxim*{\ltxkeys@disablefamilies,\ltxkeys@gdisablefamilies} + +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'{\ltxkeys@disablefamilies,\ltxkeys@gdisablefamilies} 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{\ltxkeys@disablefamilies} acts locally, while \fx{\ltxkeys@gdisablefamilies} has a global effect. + +The plain forms of \ffx'{\ltxkeys@disablefamilies,\ltxkeys@gdisablefamilies} 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'{\ltxkeys@disablekeys, \ltxkeys@gdisablekeys}. + +\start{example}[\ltxkeys@disablefamilies] +\ltxkeys{% + |com(The commands \declare@keys, \set@keys and \set@rmkeys are available) + |com(only within \ltxkeys.) + \declare@keys*[KV1]{fam1}[mp@]{% + bool/key1/true/\def\xx##1{##1\\#1\\##1}; + bool/key2/true/\def\yy##1{##1*#1*##1}; + cmd/key3/aaa/; + cmd/key4/bbb/ + }% + \\ + \declare@keys*[KV2]{fam2}[mp@]{% + bool/key1/true; + bool/key2/true; + cmd/key3/yyy/; + cmd/key4/zzz/ + }% + \\ + \ltxkeys@disablefamilies[KV1,KV2]{fam1,fam2}[key3,key4] +} +\showcsn{KV1@fam2@disabledkeys} +\finish{example} + + +\docsubsection{Disabling keys} -\start{newmacro}[\ltxkeys@disablekeys] +\start{newmacro}[\ltxkeys@disablekeys,\ltxkeys@gdisablekeys] \ltxkeys@disablekeys[|A(prefs)]{|A(fams)}{|A(keys)} +\ltxkeys@gdisablekeys[|A(prefs)]{|A(fams)}{|A(keys)} \ltxkeys@disablekeys|*[|A(prefs)]{|A(fams)}{|A(keys)} +\ltxkeys@gdisablekeys|*[|A(prefs)]{|A(fams)}{|A(keys)} \finish{newmacro} -\fxim*{\ltxkeys@disablekeys} +\fxim*{\ltxkeys@disablekeys,\ltxkeys@gdisablekeys} -Here, \ang{keys} is a comma-separated list of keys to be disabled. The macro \fx{\ltxkeys@disablekeys} 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{\ltxkeys@disablekeys} with a warning message. Because it is possible to mix prefixes and families in \fx{\ltxkeys@disablekeys}, undefined keys may readily be encountered when disabling keys. To see those undefined keys in the transcript file, enable the package option \fx{tracingkeys}. +Here, \ang{prefs}, \ang{fams} and \ang{keys} are comma-separated lists of prefixes, families and associated keys to be disabled. The macro \fx{\ltxkeys@disablekeys} 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{\ltxkeys@disablekeys} with a warning message. Because it is possible to mix prefixes and families in \fx{\ltxkeys@disablekeys}, 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{\ltxkeys@gdisablekeys} will disable the given keys globally. -The plain form of \fx{\ltxkeys@disablekeys} disables the given keys instantly, while the \stform disables the keys at \hx{\AtBeginDocument}. Authors can use this command to bar users of their keys from calling those keys after a certain point. +The \unstform+ of \fx{\ltxkeys@disablekeys} and \fx{\ltxkeys@gdisablekeys} 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. + +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{\ltxkeys@disablekeys} and/or \fx{\ltxkeys@gdisablekeys}) by the command + +\start'{macro}[Recalling list of disabled keys] +\|A(pref)@|A(fam)@disabledkeys +\finish{macro} +\aidx*{recalling the list of disabled keys} \docsection(sec:optionskeys){Option and non-option keys} @@ -1270,7 +1563,7 @@ which is just an alias for \fx{\ltxkeys@handledkeys}. 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{\ltxkeys@handledkeys}) by the command -\start'{macro}[List of handled keys] +\start'{macro}[Recalling list of handled keys] \|A(pref)@|A(fam)@handledkeys \finish{macro} \aidx*{recalling the list of handled keys} @@ -1327,16 +1620,33 @@ The \stform+ of these commands will defer action to the end of the current packa \docsection(sec:badkeynames)<illegal key name>{Bad key names} -Some key names are indeed inadmissible. The \pkg{ltxkeys} considers the following literals, among others, as inadmissible for key names: +Some key names are indeed inadmissible. The \pkg{ltxkeys} considers the literals in \sref{tab:badkeynames}, among others, as inadmissible for key names: -\start'{macro}[Default bad key names] -.code ordkey cmdkey choicekey boolkey -handledkeys presetkeys postsetkeys executedkeys rmkeys -needvalue savevalue usevalue savevaluekeys needvaluekeys -xkeys bool boolean tog togg -toggle switch true false on -off count skip -\finish{macro} +\begingroup +\settowidth\@tempdima{needvaluekeys} +\edef\colwidth{\the\dimexpr\@tempdima+0mm} +\small +\begin{longtable}[c]{|*{5}{p{\colwidth}|}} +\caption{Default bad key names\xwmlabel{tab:badkeynames}} +\\\hline +\endfirsthead +\multicolumn{4}{|l|}{\emph{Continued from last page}}\\\hline +\endhead +\multicolumn{4}{|r|}{\emph{Continued on next page}}\\\hline +\endfoot +\hline +\endlastfoot +ord & cmd & sty & style & bool \\\hline +choice & ordkey & cmdkey & stylekey & choicekey \\\hline +boolkey & .do & .code & set & setkeys \\\hline +execute & executekeys & executedkeys & handled & handledkeys \\\hline +presetkeys & preset & postsetkeys & postset & rmkeys \\\hline +ifdef & boolean & tog & toggle & switch \\\hline +true & false & on & off & count \\\hline +dimen & skip & toks & savevalue & savevaluekeys \\\hline +xfamilykeys & needvalue & needvaluekeys & usevalue & \\ +\end{longtable} +\endgroup For reasons of efficiency, the \pkg'{ltxkeys} will attempt to catch bad key names only if the package option \fx{tracingkeys} is enabled. @@ -1372,14 +1682,15 @@ where, again, \ang{list} is comma-separated. It is not advisable to remove any m The \unstform of \fx{\ltxkeys@declareoption} is simply a form of \fx{\ltxkeys@ordkey}, 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. -The \stform of \fx{\ltxkeys@declareoption} 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{\CurrentKey} and \fx{\CurrentVal} 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{\ltxkeys@unknownoptionhandler} is equivalent to the \stform of \fx{\ltxkeys@declareoption}. +The \stform of \fx{\ltxkeys@declareoption} 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{\ltxkeys@unknownoptionhandler} is equivalent to the \stform of \fx{\ltxkeys@declareoption}. -\ltsnote The \stform of \fx{\ltxkeys@declareoption} differs from the starred form of \LaTeX's \hx{\DeclareOption} and the starred form of \pkg'{xkeyval}'s \hx{\DeclareOptionX}. +\ltsnote +The \stform of \fx{\ltxkeys@declareoption} differs from the starred form of \LaTeX's \hx{\DeclareOption} and the starred form of \pkg'{xkeyval}'s \hx{\DeclareOptionX}. \start+{example}[\ltxkeys@declareoption] \ltxkeys@declareoption|*[KV]<mypackage>{% \PackageWarning{mypackage}{% - Unknown option `\CurrentKey' with value `\InnocentVal' ignored}% + Unknown option `\ltxkeyscurrentkey' with value `\ltxkeysinnocentvalue' ignored}% } \ltxkeys@declareoption|*{\PassOptionsToClass{#3}{article}} @@ -1453,17 +1764,18 @@ can each be used to introduce several options that share the same path or bases \finish{newmacro} \fxim*{\ltxkeys@declaremultitypeoptions} -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{\ltxkeys@stylekey} above, namely, undefined dependants 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{\ltxkeys@declaremultitypeoptions} is identical to that of \fx{\ltxkeys@declarekeys} except for the following differences: For \fx{\ltxkeys@declarekeys} the family is mandatory and must be given in curly braces, while for \fx{\ltxkeys@declaremultitypeoptions} 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{\ltxkeys@declaremultitypeoptions}, the optional family is expected to be given in angled brackets. The \stform of the command \fx{\ltxkeys@declaremultitypeoptions} defines only undefined options. An alias for the long command \fx{\ltxkeys@declaremultitypeoptions} is \fx{\declaremultitypeoptions}. - +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{\ltxkeys@stylekey} above, namely, undefined dependants 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{\ltxkeys@declaremultitypeoptions} 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{\ltxkeys@declaremultitypeoptions} 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{\ltxkeys@declaremultitypeoptions}, the optional family is expected to be given in angled brackets. The \stform of the command \fx{\ltxkeys@declaremultitypeoptions} defines only undefined options. An alias for the long command \fx{\ltxkeys@declaremultitypeoptions} is \fx{\declaremultitypeoptions}. \start{example}[\ltxkeys@declaremultitypeoptions] \declaremultitypeoptions*[KV]<fam>[mp@]{% cmd/option1/xx/\def\x##1{##1xx#1}; bool/option2/true; + sty* } \finish{example} + \docsection(sec:executeoption){Executing options} \start{newmacro}[\ltxkeys@executeoptions] @@ -1482,7 +1794,7 @@ This executes/sets the \keyval pairs given in \ang{keyval}. The optional \ang{na \finish{newmacro} \fxim*{\ltxkeys@processoptions} -The command \fx{\ltxkeys@processoptions} 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{\ltxkeys@processoptions} 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'{catoptions}. When used in a class file, the macro \fx{\ltxkeys@processoptions} 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. +The command \fx{\ltxkeys@processoptions} 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{\ltxkeys@processoptions} 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{\ltxkeys@processoptions} 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. The \stform of \fx{\ltxkeys@processoptions} 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{\ltxkeys@processoptions}\Redstar, the local key too will be set. In this case, \fx{#1} in the command \fx{\ltxkeys@declareoption} (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. @@ -1500,13 +1812,13 @@ The macros \ffx'{\ltxkeys@beforeprocessoptions,\ltxkeys@afterprocessoptions} can \start{example}[\ltxkeys@afterprocessoptions] \ltxkeys@cmdkey[KV]{fam}[mp@]{keya}[]{% - \iflacus#1\dolacus\else + \iflacus#1\then\else \ltxkeys@afterprocessoptions{\RequirePackage[#1]{mypackage}}% \fi } \finish{example} -In this example, \fx{#1} refers (as usual) to the user input for key \fx{keya}. Here, we assume that the values of \fx{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 \fx{keya} is empty or not. That is why \fx{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{\dolacus}, tests for emptiness of its argument.}. +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.}. \docsection(sec:keycommands)<command keys, environment keys> @@ -1518,24 +1830,25 @@ Key commands and environments are commands and environments that expect \keyval \item The defined commands and environments can have up to nine conventional parameters, in addition to the \keyval pairs. \item Anyone or all of the nine command or environment parameters can be delimited. \item All the various types of key (command keys, boolean keys, \eetc) can be used as the keys for the new command or environment. -\item With the prefixes \ffx'{\ltxkeysglobal,\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}. +\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}. \item The exit code for the key environment can have access to the arguments of the environment, unlike in \latex's environment. \item Simple commands are provided for accessing the current values (and, in the case of boolean keys, the current states) of keys. \end{enum} 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: -\start+{newmacro}[\ltxkeyscmd,\ltxkeysenv, etc] -|A(pref)\ltxkeyscmd|A(cs)[|A(narg)][|A(dft)]<|A(delim)>|(|A(keys)|){|A(defn)} -|A(pref)\reltxkeyscmd|A(cs)[|A(narg)][|A(dft)]<|A(delim)>|(|A(keys)|){|A(defn)} -|A(pref)\ltxkeysenv{|A(name)}[|A(narg)][|A(dft)]<|A(delim)>|(|A(keys)|){|A(begdefn)}{|A(enddefn)} -|A(pref)\reltxkeysenv{|A(name)}[|A(narg)][|A(dft)]<|A(delim)>|(|A(keys)|){|A(begdefn)}{|A(enddefn)} +\start+{newmacro}[\ltxkeyscommand,\ltxkeysenvironment, etc] +|A(pref)\ltxkeyscommand|A(cs)[|A(narg)][|A(dft)]<|A(delim)>|(|A(keys)|){|A(defn)} +|A(pref)\reltxkeyscommand|A(cs)[|A(narg)][|A(dft)]<|A(delim)>|(|A(keys)|){|A(defn)} +|A(pref)\ltxkeysenvironment{|A(name)}[|A(narg)][|A(dft)]<|A(delim)>|(|A(keys)|){|A(begdefn)}{|A(enddefn)} +|A(pref)\reltxkeysenvironment{|A(name)}[|A(narg)][|A(dft)]<|A(delim)>|(|A(keys)|){|A(begdefn)}{|A(enddefn)} \finish{newmacro} -\fxim*{\ltxkeyscmd,\reltxkeyscmd,\ltxkeysenv,\reltxkeysenv} +\fxim*{\ltxkeyscommand,\reltxkeyscommand,\ltxkeysenvironment,\reltxkeysenvironment,\ltxkeysglobal, +\ltxkeysprotected,\ltxkeysrobust} 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. -The \ang{keys} have the same syntax as they do for the command \fx{\ltxkeys@declarekeys} (\sref{sec:declarekeys}). The parameter delimiters \ang{delim}, given above in angled brackets, have the syntax: +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: \start'{newmacro}[Parameter delimiters] 1|A(delim1) 2|A(delim2) ... 9|A(delim9) @@ -1551,7 +1864,7 @@ In the \latex \hhx'{\newenvironment,\renewenvironment} commands, with the syntax \finish{macro} \hxim*{\newenvironment,\renewenvironment} -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'{\ltxkeysenv,\reltxkeysenv}, 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}. +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}. 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: @@ -1580,15 +1893,39 @@ The commands \ffx'{\val,\ifval,\ifvalTF, \keyval,\ifkeyval,\ifkeyvalTF}, like th \docsubsection(sec:eoe){Final tokens of every environment} -The user can add some tokens to the very end of every subsequent environment by declaring those tokens in the macro \fxim{\ltxkeys@everyeoe}, which by default contains only \latex's command \fxi{\ignorespacesafterend}. That is, the \pkg'{ltxkeys} automatically issues +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 -\start{example}[\ltxkeys@everyeoe] -|makered(\ltxkeys@everyeoe){\ignorespacesafterend} +\start{example}[\ltxkeyseveryeoe] +|makered(\ltxkeyseveryeoe){\ignorespacesafterend} \finish{example} -It is important to note that new tokens are prepended (and not appended) to the internal hook that underlies \fx{\ltxkeys@everyeoe}, such that by default \fx{\ignorespacesafterend} always comes last in the list. You can empty the list \fx{\ltxkeys@everyeoe} by issuing \fx*{\ltxkeys@everyeoe{}} and rebuild it anew, still by prepending elements to it. \fx{\ltxkeys@everyeoe} isn't actually a token list register but it behaves like one\ltsfootnote{However, you can't do \ftfx{\ltxkeys@everyeoe\expandafter{\cmd}} because \ftfx{\ltxkeys@everyeoe} isn't a token list register.}. It is safe to issue \fx{\ltxkeys@everyeoe}\fnu{token} and/or \fx*{\ltxkeys@everyeoe{}} in the \ang{begdefn} part of the key environment. One of the examples in \sref{sec:keycommand-examples} illustrates this point. +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. -\ltsnote 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}. +\ltsnote +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}. + + +\docsubsection(sec:keycommand-hooks){Key command and environment hooks} + +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. + + +\start+{newmacro}[\ltxkeysbeforekeycmdsetkeys, etc.] +\ltxkeysbeforekeycmdsetkeys|A(keycmd){|A(code)} +\ltxkeysafterkeycmdsetkeys|A(keycmd){|A(code)} +\ltxkeysafterkeycmdsetkeys|A(keycmd){|A(code)} +\ltxkeysafterkeycmdbody|A(keycmd){|A(code)} +\ltxkeyssavecmdkeyvalues|A(keycmd){|A(keys)} +\ltxkeysrestorecmdkeyvalues|A(keycmd) +\ltxkeyssavelengths{|A(lengths)} +\ltxkeysrestorelengths{|A(lengths)} +\finish{newmacro} +\fxim*{\ltxkeysbeforekeycmdsetkeys,\ltxkeysafterkeycmdsetkeys, + \ltxkeysafterkeycmdsetkeys,\ltxkeysafterkeycmdbody,\ltxkeyssavelengths, + \ltxkeysrestorelengths,\ltxkeyssavecmdkeyvalues,\ltxkeysrestorecmdkeyvalues +} + +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). \docsubsection(sec:keycommand-examples){Examples of key command and environment} @@ -1596,11 +1933,11 @@ It is important to note that new tokens are prepended (and not appended) to the \start+{example}[Key command] |com(It is possible to use parameter delimiters, as the following) |com(\@nil and \@mil show:) -|com(\ltxkeysglobal\ltxkeysrobust\ltxkeyscmd*\cmdframebox) +|com(\ltxkeysglobal\ltxkeysrobust\ltxkeyscommand*\cmdframebox) |com( [3][default]<2\@nil 3\@mil>|(|A(keys)|){|A(defn)}) |com(No parameter delimiters for the following:) -\ltxkeysglobal\ltxkeysrobust\ltxkeyscmd*\cmdframebox[3][default]|(% +\ltxkeysglobal\ltxkeysrobust\ltxkeyscommand*\cmdframebox[3][default]|(% cmd/width/\textwidth; cmd/textcolor/black; cmd/framecolor/red; @@ -1609,7 +1946,7 @@ It is important to note that new tokens are prepended (and not appended) to the bool/putframe/true; bool/testbool/true; |){% - \begingroup + \ltxkeyssavelengths{\fboxrule,\fboxsep}% \fboxrule\keyval{framerule}\relax \fboxsep\keyval{framesep}\relax \ifkeyval putframe\then @@ -1623,7 +1960,7 @@ It is important to note that new tokens are prepended (and not appended) to the }% \ifkeyval putframe\then}\fi \ifkeyvalTF{testbool}{\def\x{T}}{\def\y{F}}% - \endgroup + \ltxkeysrestorelengths{\fboxrule,\fboxsep}% } \begin{document} @@ -1639,14 +1976,14 @@ It is important to note that new tokens are prepended (and not appended) to the \finish{example} \start{example}[Key environment] -\ltxkeysenv*{testenv}[1][right]|(% +\ltxkeysenvironment*{testenv}[1][right]|(% cmd/xwidth/2cm; cmd/ywidth/1.5cm; cmd/body; cmd/|R(\needvalue){author}/\null; bool/boola/false; |){% - \ltxkeys@iffound{,#1,}\in{,right,left,}\then\else + \ltxkeysiffound{,#1,}\in{,right,left,}\then\else \@latex@error{Unknown text alignment type `#1'}\@ehd \fi \centering @@ -1654,15 +1991,15 @@ It is important to note that new tokens are prepended (and not appended) to the \ifkeyval boola\then\color{red}\fi \fbox{\parbox{\keyval{ywidth}}{\usename{ragged#1}\keyval{body}}}% \normalcolor - |com(\val, \ifval, etc, are unavailable in \ltxkeys@everyeoe. Hence) + |com(\val, \ifval, etc, are unavailable in \ltxkeyseveryeoe. Hence) |com(we save the value of `author' here:) \protected@edef\quoteauthor{\val{author}}% - |com(Re-initialize \ltxkeys@everyeoe:) - |R(\ltxkeys@everyeoe){}% - |R(\ltxkeys@everyeoe){\ignorespacesafterend}% - |R(\ltxkeys@everyeoe){\endgraf\vskip\baselineskip + |com(Re-initialize \ltxkeyseveryeoe:) + |R(\ltxkeyseveryeoe){}% + |R(\ltxkeyseveryeoe){\ignorespacesafterend}% + |R(\ltxkeyseveryeoe){\endgraf\vskip\baselineskip \centerline{\itshape\quoteauthor}} - |com(Just to test parameter use inside \ltxkeysenv:) + |com(Just to test parameter use inside \ltxkeysenvironment:) \def\testmacroa##1{aaa##1}% }{% \def\testmacrob##1{##1bbb}% @@ -1683,11 +2020,11 @@ It is important to note that new tokens are prepended (and not appended) to the \start+{example}[Key environment] |com(The following line has parameter delimiters \@nil and \@mil:) -|com(\ltxkeysglobal\ltxkeysrobust\ltxkeysenv*{envframebox}) +|com(\ltxkeysglobal\ltxkeysrobust\ltxkeysenvironment*{envframebox}) |com( [3][default]<2\@nil 3\@mil>|(|A(defn)|){}) |com(No parameter delimiters for the following:) -|R(\ltxkeysglobal\ltxkeysrobust)\ltxkeysenv*{envframebox}[3][default]|(% +|R(\ltxkeysglobal\ltxkeysrobust)\ltxkeysenvironment*{envframebox}[3][default]|(% cmd/width/\textwidth/\def\xx##1{##1}; cmd/textcolor/black; cmd/framerule/.4pt; @@ -1723,7 +2060,7 @@ It is important to note that new tokens are prepended (and not appended) to the \start+{example}[Nested key environments] \def\testenv{} -\reltxkeysenv{testenv}|(% +\reltxkeysenvironment{testenv}|(% |com(The \y below is just a test:) cmd/fraclen/0.1cm/\def\y##1{#1yyy##1}; cmd/framerule/.4pt; @@ -1731,7 +2068,7 @@ It is important to note that new tokens are prepended (and not appended) to the cmd/textcolor/black; bool/putframe/true; |){% - \cptdimdef\tempb{.5\textwidth-\val{fraclen}*\currentgrouplevel}% + \ltsdimdef\tempb{.5\textwidth-\val{fraclen}*\currentgrouplevel}% \noindent \endgraf\fboxrule=\val{framerule}\relax \color{\val{framecolor}}% @@ -1772,29 +2109,29 @@ It is important to note that new tokens are prepended (and not appended) to the \end{document} \finish{example} -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. +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. \start+{example}[Key command] -\ltxkeyscmd\myframebox[2][default text]|(% +\ltxkeyscommand\myframebox[2][default text]|(% cmd/width/\textwidth; cmd/textcolor/black; cmd/framecolor/black; cmd/framesep/3\p@; cmd/framerule/0.4\p@; |com(The following is choice key `textalign' with default value `center'.) - |com(The `.code=' in the admissible values is optional, but not the forward) - |com(slash `/'.) + |com(The `.do=' in the admissible values is optional, but not the forward) + |com(slash `/':) |R(choice/textalign.{%) - |R(center/.code=\def\ttextalign{center},) - |R(left/.code=\def\ttextalign{flushleft},) - |R(right/.code=\def\ttextalign{flushright}) + |R(center/.do=\def\ttextalign{center},) + |R(left/.do=\def\ttextalign{flushleft},) + |R(right/.do=\def\ttextalign{flushright}) |R(}/center); bool/putframe/true |){% \begingroup \fboxsep\myframebox@framesep \fboxrule\myframebox@framerule\relax - \cptdimdef\myframebox@boxwidth + \ltsdimdef\myframebox@boxwidth {\myframebox@width-2\fboxsep-2\fboxrule}% \noindent\begin{lrbox}\@tempboxa \begin{minipage}[c][\height][s]\myframebox@boxwidth @@ -1822,89 +2159,169 @@ The following example shows that in place of the functions \ffx'{\val,\ifval,\if \docsection(sec:declarevariables)<declarevariables>{Declaring variables} -Sometimes keys are used simply to save values for later use. This can be achieved easily by using the command \fx{\ltxkeys@declarevariables}. +Sometimes keys are used simply to save values for later use. This can be achieved easily by using the command \fx{\ltxkeysdeclarevariables}. -\start{newmacro}[\ltxkeys@declarevariables,\setvarvalues,\getvarvalue] -\ltxkeys@declarevariables[|A(namespace)]{% +\start{newmacro}[\ltxkeysdeclarevariables,\ltxkeyssetvarvalues,\ltxkeysgetvarvalue] +\ltxkeysdeclarevariables[|A(namespace)]{% |A(key-1) = |A(dft-1) = |A(cbk-1), ..., |A(key-n) = |A(dft-n) = |A(cbk-n) } -\setvarvalues[|A(namespace)]{|keyval pairs} -\getvarvalue[|A(namespace)]{|A(key)} +\ltxkeyssetvarvalues[|A(namespace)]{|keyval pairs} +\ltxkeysgetvarvalue[|A(namespace)]{|A(key)} \finish{newmacro} -\fxim*{\ltxkeys@declarevariables,\setvarvalues,\getvarvalue} +\fxim*{\ltxkeysdeclarevariables,\ltxkeyssetvarvalues,\ltxkeysgetvarvalue} 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. -The key default value \ang{dft} and callback \ang{cbk} are optional and may be missing in the mandatory argument of \fx{\ltxkeys@declarevariables}. +The key default value \ang{dft} and callback \ang{cbk} are optional and may be missing in the mandatory argument of \fx{\ltxkeysdeclarevariables}. -\start{example}[\ltxkeys@declarevariables] -\ltxkeys@declarevariables[mynamespace]{% +\start{example}[\ltxkeysdeclarevariables] +\ltxkeysdeclarevariables[mynamespace]{% var1 = {default value1} = \def\userinput{#1}\def\cmd##1{##1}, |com(No callback:) var2 = default value2, |com(No default value and no callback:) var3 } -\setvarvalues[mynamespace]{var1=new value1, var2=new value2} -\edef\x{\getvarvalue[mynamespace]{var1}} +\ltxkeyssetvarvalues[mynamespace]{var1=new value1, var2=new value2} +\edef\x{\ltxkeysgetvarvalue[mynamespace]{var1}} \begin{document} -\getvarvalue[mynamespace]{var1} +\ltxkeysgetvarvalue[mynamespace]{var1} \end{document} \finish{example} The private namespace is optional but clashes of control sequences might occur: -\start{example}[\ltxkeys@declarevariables] -\ltxkeys@declarevariables{% +\start{example}[\ltxkeysdeclarevariables] +\ltxkeysdeclarevariables{% var1 = {default value1} = \def\userinput{#1}\def\cmd##1{##1}, |com(No callback:) var2 = default value2, |com(No default value and no callback:) var3 } -\setvarvalues{var1=new value1, var2=new value2} -\edef\x{\getvarvalue{var1}} +\ltxkeyssetvarvalues{var1=new value1, var2=new value2} +\edef\x{\ltxkeysgetvarvalue{var1}} \begin{document} -\getvarvalue{var1} +\ltxkeysgetvarvalue{var1} \end{document} \finish{example} +\docsection(sec:ltxkeys-command){The \headfx{\ltxkeys} command} + +\start{newmacro}[\ltxkeys] +\ltxkeys|*|'{|A(code-1) \\ |A(code-2) ... \\ ... |A(code-n)} +\finish{newmacro} +\fxim*{\ltxkeys} + +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}. + +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. + +\begingroup +\small +\begin{tabularx}{\linewidth}{|p{4.5cm}|p{5.5cm}|} +\caption{Command abbreviations available within \headfx{\ltxkeys} + \xwmlabel{tab:ltxkeys-cmdabbrv}}\\\hline +\rowcolor{pink} +\bf Command & \bf Abbreviation \\\hline +\endfirsthead +\hline +\multicolumn{2}{|l|}{\emph{Continued from last page}}\\\hline +\bf Command & \bf Abbreviation \\\hline +\endhead +\multicolumn{2}{|r|}{\emph{Continued on next page}}\\\hline +\endfoot +\hline +\endlastfoot +\fx{\ordkey} & \fx{\ltxkeys@ordkey} \\\hline +\fx{\ordkeys} & \fx{\ltxkeys@ordkeys} \\\hline +\fx{\listkey} & \fx{\ltxkeys@listkey} \\\hline +\fx{\listkeys} & \fx{\ltxkeys@listkeys} \\\hline +\fx{\cmdkey} & \fx{\ltxkeys@cmdkey} \\\hline +\fx{\cmdkeys} & \fx{\ltxkeys@cmdkeys} \\\hline +\fx{\boolkey} & \fx{\ltxkeys@boolkey} \\\hline +\fx{\boolkeys} & \fx{\ltxkeys@boolkeys} \\\hline +\fx{\switchkey} & \fx{\ltxkeys@switchkey} \\\hline +\fx{\switchkeys} & \fx{\ltxkeys@switchkeys} \\\hline +\fx{\choicekey} & \fx{\ltxkeys@choicekey} \\\hline +\fx{\choicekeys} & \fx{\ltxkeys@choicekeys} \\\hline +\fx{\stylekey} & \fx{\ltxkeys@stylekey} \\\hline +\fx{\stylekeys} & \fx{\ltxkeys@stylekeys} \\\hline +\fx{\definekeys} & \fx{\ltxkeysdefinekeys} \\\hline +\fx{\declarekeys} & \fx{\ltxkeysdeclarekeys} \\\hline +\fx{\declareoptions} & \fx{\ltxkeys@declaremultitypeoptions} \\\hline +\fx{\ifdeclaringkeys}\fx{\then} & \fx{\ifltxkeys@dec} \\\hline +\fx{\setkeys} & \fx{\ltxkeyssetkeys}\\\hline +\fx{\setrmkeys} & \fx{\ltxkeyssetrmkeys}\\\hline +\end{tabularx} +\endgroup + +\start{example}[\ltxkeys] +\ltxkeys|'{ + \switchkeys|+[KV]{fam}[mp@]{keya,keyb}[true]{ + \if\@nameuse{mp@\ltxkeyscurrentkey} + \def\xx##1{##1*#1*##1} + \fi + }{% + \keyvalueerror + } + \declarekeys*[KV]{fam}[mp@]{ + bool/keyc/true/\def\x##1{##1\\#1\\##1}; + cmd/keyd/keyd-default/\def\currval{#1}; + }% + \\ + |com(Arbitrary code to be executed on its own:) + \def\x##1{x ##1 x} + \\ + \setkeys*[KV]{fam}[keyb,keyc]{keya=false,keyb,keyc=false,keyd=yy} + \setrmkeys|*[KV]{fam}[keyc] +} +\finish{example} + + \docsection(sec:pathkeys)<pathkeys>{Pathkeys} Let us start this section with a welcome message: you don't have to repeatedly type in long key paths and commands when using pathkeys. There is plenty of help ahead on how to reduce estate when using pathkeys. -The \pkg'{pathkeys} can be loaded on its own (via \hx{\RequirePackage} or \hx{\usepackage}) or as an option to the \pkg'{ltxkeys} (see \sref{tab:pkgoptions}). All the options listed in \sref{tab:pkgoptions} are accepted by the \pkg'{pathkeys}. They are all passed on to \pkg'{ltxkeys}, except \fx{pathkeys} that is simply ignored by \pkg'{pathkeys}. +The \pkg'{pathkeys} can be loaded on its own (via \hx{\RequirePackage} or \hx{\usepackage}) or as an option to the \pkg'{ltxkeys} (see \sref{tab:pkgoptions})\footnote{The user has no access to the command \fx{\pathkeys} unless he/she first loads \pkg'{pathkeys}.}. All the options listed in \sref{tab:pkgoptions} are accepted by the \pkg'{pathkeys}. They are all passed on to \pkg'{ltxkeys}, except \fx{pathkeys} that is simply ignored by \pkg'{pathkeys}. -Pathkeys are keys with a tree or directory structure\footnote{This might sound like \textpgfkeys, but the semantics, syntaxes, and the implementation here are all different from those of \textpgfkeys.}. When defining and setting pathkeys, the full key path is usually required. This is also the case when seeking the current value or state of a key. When using pathkeys the user is relieved of the need to known and remember where the optional arguments have to be placed in calls to macros. And like the commands \ffx'{\ltxkeys@definekeys, \ltxkeys@declarekeys}, pathkeys are automatically initialized after definition, \ie, they are automatically set with their default values. +Pathkeys are keys with a tree or directory structure\footnote{This might sound like \textpgfkeys, but the semantics, syntaxes, and the implementation here are all different from those of \textpgfkeys.}. When defining and setting pathkeys, the full key path is usually required. This is also the case when seeking the current value or state of a key. When using pathkeys the user is relieved of the need to known and remember where the optional arguments have to be placed in calls to macros. And like the commands \ffx'{\ltxkeysdefinekeys, \ltxkeysdeclarekeys}, pathkeys are automatically initialized after definition, \ie, they are automatically set with their default values. Boolean keys are set with a default value of \quoted{false} irrespective of the user-specified default value. See \sref{sec:definekeys,sec:declarekeys} for an explanation of this philosophy. The command for defining and setting pathkeys is \fx{\pathkeys}, which has the following syntax. The same command is used for several other tasks related to pathkeys. The \quoted{flag} entry in the argument of \fx{\pathkeys} determines the action that the command is expected to take. \start+{newmacro}[\pathkeys] -\pathkeys{|A(paths)/|A(flag)|R(:) |A(attrib)} +\pathkeys|*|'{|A(paths)/|A(flag)|R(:) |A(attrib)} \finish{newmacro} \fxim*{\pathkeys} +The \stform of \fx{\pathkeys} will expand its argument once before commencing the loop and executing the codes on the specified paths. The \pmform is equivalent to invoking the package option \fx{endcallbackline} before calling \fx{\pathkeys}. Using both \redstar and \redprime makes \hx{\endlinechar} $-1$ but the effect is not enforced, since in the \stform of \fx{\pathkeys} the argument has already been read. + In the argument of command \fx{\pathkeys}, \ang{paths} has the syntax -\start+{newmacro}[\pathkeys] -|A(main1)/|A(sub1)/|A(subsub1)/...|R(,)|A(main2)/|A(sub2)/|A(subsub2)/...|R(,)etc. +\start+{newmacro}[Paths in \pathkeys] +|A(main-1)/|A(sub-1)/|A(subsub-1)|R(,)|A(main-2)/|A(sub-2)/|A(subsub-2),...|R(,)etc. \finish{newmacro} \fxim*{\pathkeys} -in which individual paths are separated by \qcomma. The quantity \ang{main} is the main path and \ang{sub} is the sub path, \eetc. Note that there is no forward slash ~(\fx{/}) before \ang{paths} or \ang{main}. If the path is empty, the default path \quotedfx{dft@main/dft@sub/}, or the user-supplied current path (see later), is used. There is more about the default and current paths later in this guide. +in which individual paths are separated by \qcomma. The quantity \ang{main} is the main path and \ang{sub} is the sub path, \eetc. It should be noted that there is no forward slash ~(\fx{/}) before \ang{paths} or \ang{main}. If the path is empty, the default path \quotedfx{pathkeys@default@main/pathkeys@default@sub}, or the user-supplied current path (see later), is used. \emph{Note, however, that when the current path is empty, the default path is not resorted to automatically; you have to indicate that this is your choice.} You can call \fx{\pathkeysusedefaultpath} to indicate that you really want the default path to be the current path. The aim is that users don't leave out the path when they don't actually intend it to be empty. There is more about the default and current paths later in this guide. -The \ang{attrib} is determined by the key called \ang{flag}. The \ang{flag} determines the action the command \fx{\pathkeys} takes, and must be a member of the set described in \sref{tab:flags}. The action specified by \ang{flag} is, if applicable on all the given paths, taken on all the given paths\footnote{However, in most of this manual only one path is used in the sample syntaxes and in the examples.}. See the table notes for the \ang{attrib}'s of the flags. The attributes describe the arguments associated with the flags, \ie, the quantities expected after the \qcolon in the argument of \fx{\pathkeys}. The \ang{na} is the list of keys that are ignored by the \ang{flag}'s action. If it is present in the attribute \ang{attrib} part of \fx{\pathkeys}, it must always be given in square brackets \quotedfx{[]} (see \sref{nte:pathkeys-flags}). +The \ang{attrib}, the property of a pathkey, is determined by the quantity called \ang{flag}. The \ang{flag} determines the action the command \fx{\pathkeys} takes, and must be a member of the set described in \sref{tab:flags}. The action specified by \ang{flag} is, if applicable on all the given paths, taken on all the given paths. Multiple paths should invariably be comma-separated. See the notes of \sref{tab:flags} for the \ang{attrib}'s of the flags. The attributes describe the arguments associated with the flags, \ie, the quantities expected after the \qcolon in the argument of \fx{\pathkeys}. The \ang{na} is the list of keys that are ignored by the \ang{flag}'s action. If it is present in the attribute \ang{attrib} part of \fx{\pathkeys}, it must always be given in square brackets \quotedfx{[]} (see \sref{nte:pathkeys-flags}). Not all the flags expect, or can process, the \ang{na} list. -For flags with \redstar and \redplus signs the user should make sure there is no space between the flag and its star or plus sign: such a space will not be zapped internally, since syntactic matching is required. +Some important points about the command \fx{\pathkeys}: +\begin{enum} +\item A key message of the above syntax of \ang{paths} is that several paths can be submitted to \fx{\pathkeys} in one go. The attribute \ang{attrib} will then apply to all the given paths, according to the given \ang{flag}. If \ang{flag} involves defining keys, the keys will be defined on all the listed paths. If \ang{flag} involves determining if a key is defined on any of the given paths, all the listed paths are searched to find the key. +\item Within the command \fx{\pathkeys}, if the package option \fx{endcallbackline} is enabled, every line implicitly ends with a comment sign. Invariably, within \fx{\pathkeys} the \quoted{at sign} (\fx{@}) has category code~11 (letter). So no need to reassign this category code to~11 within \fx{\pathkeys}. +\item For flags with \redstar, \redplus and \redclam signs, the user should make sure there is no space between the flag and its star, plus or exclamation sign: such a space will not be zapped internally, since syntactic matching is used. The sign is part of the flag's name. +\end{enum} \newltablenote{pathkeys-flags-1}{% The flag \fx{declareoptions}\Redstar simply signifies the user's aim to define definable options; it has nothing to do with the \stform of the command \fx{\ltxkeys@declareoption} of \sref{sec:declareoption}. The attribute is the same as for \fx{define} flag. } \newltablenote{pathkeys-flags-2}{% - The arguments of the unknown key or option handler are the main path, subpaths (separated by forward slash), key name, and the current key value (see \sref{sec:unknownkeyhandler}). The key or option handler can have up to a maximum of~4 arguments. + The key or option handler can have up to a maximum of~4 arguments. The arguments of the unknown key or option handler are the main path (argument 1); subpaths, separated by forward slash (argument 2); key name (argument 3), and the current key value (argument 4). The handler can/should be defined by the user (see \sref{sec:unknownkeyhandler}). } \newcolumntype{C}{>{\hfill}p{.7cm}} @@ -1913,7 +2330,7 @@ For flags with \redstar and \redplus signs the user should make sure there is no \small \begin{tabularx}{\linewidth}{|C|>{\raggedright}p{2.5cm}|X|} \caption{Flags and attributes for pathkeys\label{tab:flags}}\\\hline -\ltablenotehead{These notes describe the attributes of handlers, \ie, what are required to be specified in the command \fx{\pathkeys} after the \qcolon sign. \ang{na} keys are the keys to be ignored; they must appear in square brackets, \eg, \fx{[keya]}.} +\ltablenotehead{These notes describe the attributes of key flags, \ie, what are required to be specified in the command \fx{\pathkeys} after the \qcolon sign. \ang{na} keys are the keys to be ignored; they must appear in square brackets, \eg, \ttx{[keya, keyb]}.} \rowcolor{pink} \bfseries No. &\bfseries Flag & \bfseries Meaning\\\hline \endfirsthead @@ -1929,9 +2346,9 @@ For flags with \redstar and \redplus signs the user should make sure there is no \rownr & \fx{define}\Redstar & Define the keys only if they don't already exist.\ltablenote{Same as for \fx{define} flag.} \\\hline \rownr & \fx{declareoptions} & Declare the given options whether or not they already exist.\ltablenote{Same as for \fx{define} flag.} \\\hline \rownr & \fx{declareoptions}\Redstar & Declare the options if they don't already exist. \useltablenote{pathkeys-flags-1} \\\hline -\rownr & \fx{preset} & Preset the listed keys on the given path. This actually means preparing the list of preset keys. \ltablenote{\keyval pairs (see \sref{sec:presettingkeys}).} \\\hline +\rownr & \fx{preset} & Preset the listed keys on the given path. This actually means preparing the list of preset keys, for later use when setting keys with the flag \fx{set} or any key-setting flag. \ltablenote{\keyval pairs (see \sref{sec:presettingkeys}).} \\\hline \rownr & \fx{preset}\Redclam & Preset the listed keys, saving the list globally. \ltablenote{\keyval pairs (see \sref{sec:presettingkeys}).} \\\hline -\rownr & \fx{postset} & Post-set the listed keys. \ltablenote{\keyval pairs (see \sref{sec:presettingkeys}).} \\\hline +\rownr & \fx{postset} & Post-set the listed keys. This actually means preparing the list of postset keys. \ltablenote{\keyval pairs (see \sref{sec:presettingkeys}).} \\\hline \rownr & \fx{postset}\Redclam & Post-set the listed keys, saving the list globally. \ltablenote{\keyval pairs (see \sref{sec:presettingkeys}).} \\\hline \rownr & \fx{set} & Set the listed keys. \ltablenote{\ang{na} keys and \keyval pairs (see \sref{sec:settingkeys}).} \\\hline \rownr & \fx{set}\Redstar & Set the listed keys and save undefined keys in the list of \quoted{remaining keys} without raising errors. \ltablenote{\ang{na} keys and \keyval pairs (see \sref{sec:settingkeys}).} \\\hline @@ -1939,21 +2356,21 @@ For flags with \redstar and \redplus signs the user should make sure there is no \rownr & \fx{setrm} & Set the \quoted{remaining keys}. \ltablenote{\ang{na} keys (see \sref{sec:rmkeys}).} \\\hline \rownr & \fx{setrm}\Redstar & Set the \quoted{remaining keys} and again save undefined keys in the revised list of \quoted{remaining keys} without raising errors. \ltablenote{\ang{na} keys (see \sref{sec:rmkeys}).} \\\hline \rownr & \fx{setrm}\Redstar\Redplus & Set the \quoted{remaining keys} in all the given key prefixes and families; save undefined keys in the revised list of \quoted{remaining keys} without raising errors. \ltablenote{\ang{na} keys (see \sref{sec:rmkeys}).} \\\hline - \rownr & \fx{executeoptions} & Execute the listed options. \ltablenote{\ang{na} keys and \keyval pairs (see \sref{sec:executeoption}).} \\\hline \rownr & \fx{processoptions} & Process the listed options in the order in which they were declared, and don't copy \hx{\documentclass} options. \ltablenote{\ang{na} keys (see \sref{sec:processoption}).} \\\hline \rownr & \fx{processoptions}\Redstar & Process the listed options in the order in which they appear in the command \hx{\usepackage}, and copy \hx{\documentclass} options. \ltablenote{\ang{na} keys (see \sref{sec:processoption}).} \\\hline \rownr & \fx{launch} & Launch the listed keys (see \sref{sec:launchingkeys}). \ltablenote{\keyval pairs.} \\\hline -\rownr & \fx{store value} & Store the value of \ang{key} in the given \ang{macro}. \ltablenote{\ang{key} and \ang{macro}, \eg, \fx{keya \cmda}.} \\\hline -\rownr & \fx{print value} & Print the current value of \ang{key}. \ltablenote{\ang{key}, \eg, \fx{keya}.}\\\hline -\rownr & \fx{add value} & Add the specified value to the current value of key. \ltablenote{\ang{key} and \ang{value}.} \\\hline -\rownr & \fx{ifbool} & Test the state of a boolean key. This returns \ang{true} or \ang{false}. \ltablenote{\ang{key}.}\\\hline -\rownr & \fx{ifdef} & Test if key is currently defined on any of the given comma-separated multiple paths. This returns \ang{true} or \ang{false}. \ltablenote{\ang{key}.}\\\hline -\rownr & \fx{ifkeyonpath} & Test if key is currently defined on any of the given comma-separated multiple paths. This returns \ang{true} or \ang{false}. \ltablenote{\ang{key}.}\\\hline +\rownr & \fx{storevalue} & Store the value of \ang{key} in the given \ang{macro}. \ltablenote{\ang{key} and \ang{macro}, \eg, \ttx{keya}~\fx{\cmda}.} \\\hline +\rownr & \fx{printvalue} & Print the current value of \ang{key}. \ltablenote{\ang{key}, \eg, \ttx{keya}.}\\\hline +\rownr & \fx{addvalue} & Add the specified value to the current value of key. \ltablenote{\ang{key} and \ang{value} to assign.} \\\hline +\rownr & \fx{ifbool} & Test the state of a boolean key. This returns \ang{true} or \ang{false}. \ltablenote{\ang{key}, \eg, \ttx{keya}.}\\\hline +\rownr & \fx{ifdef} & Test if \ang{key} is currently defined on any of the given comma-separated multiple paths. This returns \ang{true} or \ang{false}. This is equivalent to \fx{ifkeyonpath}. \ltablenote{\ang{key}, \eg, \ttx{keya}.}\\\hline +\rownr & \fx{ifkeyonpath} & Test if \ang{key} is currently defined on any of the given comma-separated multiple paths. This returns \ang{true} or \ang{false}. This is synonymous with \fx{ifdef}. \ltablenote{\ang{key}, \eg, \ttx{keya}.}\\\hline \rownr & \fx{disable} & Immediately disable the given keys. \ltablenote{The attribute is a comma-separated key list.} \\\hline \rownr & \fx{disable}\Redstar & Disable the given keys at the hook \hx{\AtBeginDocument} and not immediately. \ltablenote{Comma-separated key list.}\\\hline -\rownr & \fx{key handler} or \fx{handler} & Unknown key handler.\useltablenote{pathkeys-flags-2}\\\hline -\rownr & \fx{option handler} & Unknown option handler (see \sref{sec:unknownkeyhandler}). Options are keys with a special default family. There might be a reason to handle unknown options separately from unknown keys. +\rownr & \fx{keyhandler} or \fx{handler} & Unknown key handler.\useltablenote{pathkeys-flags-2}\\\hline +\rownr & \fx{optionhandler} & Unknown option handler (see \sref{sec:unknownkeyhandler}). Options are keys with a special default family. There might be a reason to handle unknown options separately from unknown keys.\\\hline +\rownr & \fx{normalcode} & The given code will simply be executed. Virtually any code can be the \ang{attrib} of this flag. This is the flag to use to, for example, change path within \fx{\pathkeys} command. It should be recalled that path changes within \fx{\pathkeys} command are limited in scope, since the current path is pushed upon entry into this command and popped on exit. \end{tabularx} \endgroup @@ -1969,7 +2386,7 @@ The syntax for specifying keys to be defined by \fx{\pathkeys} is (see \sref{sec } \finish{newmacro} -The default value \ang{dft} and the callback \ang{cbk} can be absent in all cases. \ang{keytype} may be any member of the set \fnz{ord,cmd,sty,sty*,bool,choice}. The star (\redstar) in \quoted{sty\Redstar} has the same meaning as in \fx{\ltxkeys@stylekey} (\sref{sec:stylekeys}), namely, undefined dependants will be defined on the fly when the parent is set/executed. \aidx*{style keys (sty*)} +Here, the default list parser (\qsemicolon) is shown. This can be changed by using the package option \fx{keyparser}---see \sref{sec:packageoptions}. The default key value \ang{dft} and the callback \ang{cbk} can be absent in all cases. \ang{keytype} may be any member of the set \fnz{ord,cmd,sty,sty*,bool,choice}. The star (\redstar) in \quoted{sty\Redstar} has the same meaning as in \fx{\ltxkeys@stylekey} (\sref{sec:stylekeys}), namely, undefined dependants will be defined on the fly when the parent is set/executed. \aidx*{style keys (sty*)} \start{example}[Syntax for defining pathkeys] |com(Define keys on only one path:) @@ -1980,7 +2397,7 @@ The default value \ang{dft} and the callback \ang{cbk} can be absent in all case |com(Define keys on multiple paths:) \pathkeys{fam1/subfam1/subsubfam1,fam2/subfam2/subsubfam2,.../|R(define): cmd/keya/defaultval/\def\cmda#1{#1}; - bool/keyb/true; + bool/keyb/true } \finish{example} @@ -1989,17 +2406,18 @@ Choice keys must have their names associated with their nominations (\ie, admiss \start'{newmacro}[Syntax for defining choice keys in \pathkeys] |com(`keya' is a choice key with simple nominations and callback, while `keyb') |com(is a choice key with complex nominations. The function \order is generated) -|com(internally by the package for choice keys.) +|com(internally by the package for choice keys. It means the numerical order of) +|com(of the nomination, starting from zero.) \pathkeys{fam/subfam/subsubfam/|R(define): choice/keya|boldreddot{left,right,center}/center/ \edef\x{\ifcase\order 0\or 1\or 2\fi}; choice/keyb|boldreddot{% - center/.code=\def\textalign{center}, - left/.code=\def\textalign{flushleft}, - |com(`.code=' can be omitted, as in:) + center/.do=\def\textalign{center}, + left/.do=\def\textalign{flushleft}, + |com(`.do=' can be omitted, as in:) right/\def\textalign{flushright}, justified/\let\textalign\relax - }/center/\def\x##1{##1xx#1}; + }/center/\def\x##1{##1xx#1} } \finish{newmacro} @@ -2008,7 +2426,7 @@ The \ang{na} keys, if they are present in the attribute of \fx{\pathkeys}, must \start{example}[`na' keys] \pathkeys{fam/subfam/subsubfam/|R(define): cmd/keya/xx/\def\cmda#1{#1}; - bool/keyb/true; + bool/keyb/true } |com(Set `keya' and ignore `keyb':) \pathkeys{fam/subfam/subsubfam/|R(set): keya=zz,keyb=true [keyb]} @@ -2016,7 +2434,7 @@ The \ang{na} keys, if they are present in the attribute of \fx{\pathkeys}, must \pathkeys{fam/subfam/subsubfam/|R(set): [keyb] keya=zz,keyb=true} \finish{example} -See \sref{sec:options-pathkeys} for further examples of the use of ignored keys. Here we can see that a value is provided for \quoted{keyb} and yet we're ignoring the key. However, in practical applications it is often impossible to predict the set of keys (among a set of them) that may be executed at any time by the user of the keys. Therefore, \ang{na} keys are much more useful than the above example demonstrates\@gobble{.} +See \sref{sec:options-pathkeys} for further examples of the use of ignored keys. Here we can see that a value is provided for \quoted{keyb} and yet we're ignoring the key. However, in practical applications it is often impossible to predict the subset of keys (among a set of them) that may be executed at any time by the user of the keys. Therefore, \ang{na} keys are much more useful than the above example demonstrates\@gobble{.} \end{noteenv} Some of the commands associated with pathkeys are listed below. The abbreviation \ang{pk} means the full key path and key name, all separated by forward slash. @@ -2030,14 +2448,15 @@ Some of the commands associated with pathkeys are listed below. The abbreviation \pathkeyskeyval{|A(pk)} \ifpathkeyskeyval{|A(pk)} \then ... \else ... \fi \ifpathkeyskeyvalTF{|A(pk)}{|A(true)}{|A(false)} -\pathkeys@storevalue{|A(pk)}|A(cmd) +\pathkeysstorevalue{|A(pk)}|A(cmd) \finish{newmacro} \fxim*{\pathkeysval,\ifpathkeysval,\ifpathkeysvalTF,\pathkeyskeyval, - \ifpathkeyskeyval,\ifpathkeyskeyvalTF,\pathkeys@storevalue} + \ifpathkeyskeyval,\ifpathkeyskeyvalTF,\pathkeysstorevalue} -The commands \ffx'{\pathkeysval, \pathkeyskeyval} simply yield the current value of the key. The commands \ffx'{\ifpathkeysval, \ifpathkeyskeyval}, which require \fx{\then} to form balanced conditionals, test the current state of the boolean key \ang{pk} in a \tex-like syntax. The commands \ffx'{\ifpathkeysvalTF, \ifpathkeyskeyvalTF} also test the current state of the boolean key \ang{pk} but return \ang{true} or \ang{false} in a \latex syntax. The command \fx{\pathkeys@storevalue} stores the current value of key \ang{pk} in the given command \ang{cmd}. +The commands \ffx'{\pathkeysval, \pathkeyskeyval} simply yield the current value of the key. The commands \ffx'{\ifpathkeysval, \ifpathkeyskeyval}, which require \fx{\then} to form balanced conditionals, test the current state of the boolean key \ang{pk} in a \tex-like syntax. The commands \ffx'{\ifpathkeysvalTF, \ifpathkeyskeyvalTF} also test the current state of the boolean key \ang{pk} but return \ang{true} or \ang{false} in a \latex syntax. The command \fx{\pathkeysstorevalue} stores the current value of key \ang{pk} in the given command \ang{cmd}. -\ltsnote If called outside an assignment or document environment, the macros \ffx'{\pathkeysval, \pathkeyskeyval} can give \quoted{no document error}, to signify that a token has been output outside these situations. And one source of problem with \ffx'{\ifpathkeysval, \ifpathkeyskeyval} is to omit \fx{\then} after their argument. If you find yourself typing long key paths and the commands \ffx'{\pathkeysval, \pathkeyskeyval}, \eetc, repeatedly, there is help ahead on how to reduce estate when using pathkeys. +\ltsnote +If called outside an assignment or document environment, the macros \ffx'{\pathkeysval, \pathkeyskeyval} can give \quoted{no document error}, to signify that a token has been output outside these situations. And one source of problem with \ffx'{\ifpathkeysval, \ifpathkeyskeyval} is to omit \fx{\then} after their argument. If you find yourself typing long key paths and the commands \ffx'{\pathkeysval, \pathkeyskeyval}, \eetc, repeatedly, there is help ahead on how to reduce the amount of typing required in using pathkeys. The following provide our first examples of pathkeys and a demonstration of some of the commands associated with pathkeys. @@ -2045,7 +2464,7 @@ The following provide our first examples of pathkeys and a demonstration of some \pathkeys{fam/subfam/subsubfam/|R(define): cmd/xwidth/\@tempdima/\def\y##1{#1yy##1}; cmd/keya/\def\cmda#1{#1}; - bool/putframe/true; + bool/putframe/true } \pathkeys{fam/subfam/subsubfam/|R(set): putframe=true [keya]} \pathkeys{fam/subfam/subsubfam/|R(ifdef): xwidth}{\def\x{T}}{\def\x{F}} @@ -2054,14 +2473,14 @@ The following provide our first examples of pathkeys and a demonstration of some \pathkeys{fam/subfam/subsubfam/|R(print value): xwidth}=\z@pt \pathkeys{fam/subfam/subsubfam/|R(store value): keya \cmd} \pathkeys{fam/subfam/subsubfam/|R(add value): keya=\def\cmdb#1{#1}} -\pathkeys@storevalue{fam/subfam/subsubfam/putframe}\cmd +\pathkeysstorevalue{fam/subfam/subsubfam/putframe}\cmd \edef\x{|R(\ifpathkeysvalTF){fam/subfam/subsubfam/putframe}{T}{F}} \edef\x{|R(\ifpathkeysval) fam/subfam/subsubfam/putframe|R(\then) T\else F\fi} \edef\x{|R(\ifpathkeysval) fam/subfam/subsubfam/putframe|R(\then) T\else F\fi} |com(`xputframe' is undefined. What does the following return?) \edef\x{|R(\pathkeysval){fam/subfam/subsubfam/xputframe}} |com(Unknown key handler:) -\pathkeys{fam/subfam/subsubfam/|R(key handler): +\pathkeys{fam/subfam/subsubfam/|R(keyhandler): |com(`#1' is the key's main path, `#2' is the subpaths combined,) |com(`#3' is the key name, and `#4' is the current value of the key:) \ltxkeys@warn{Unknown key `#3' with value `#4' ignored.}% @@ -2070,6 +2489,7 @@ The following provide our first examples of pathkeys and a demonstration of some \finish{example} \fxim*{unknown key handler in pathkeys} + \start+{example}[Pathkeys] \pathkeys{KV/frame/framebox/|R(define*): cmd/width/\textwidth/\def\x##1{#1xx##1}; @@ -2079,13 +2499,13 @@ The following provide our first examples of pathkeys and a demonstration of some cmd/framerule/0.4\p@; cmd/cornersize/20\p@; choice/textalign.{% - center/.code=\def\ttextalign{center}, - left/.code=\def\ttextalign{flushleft}, - right/.code=\def\ttextalign{flushright} + center/.do=\def\ttextalign{center}, + left/.do=\def\ttextalign{flushleft}, + right/.do=\def\ttextalign{flushright} }/center; bool/putframe/true; cmd/arga; - cmd/argb; + cmd/argb } \newcommand*\myframebox[1][]{% @@ -2094,7 +2514,7 @@ The following provide our first examples of pathkeys and a demonstration of some \begingroup \fboxsep\pathkeysval{KV/frame/framebox/framesep}% \fboxrule\pathkeysval{KV/frame/framebox/framerule}\relax - \cptdimdef\boxwidtha{% + \ltsdimdef\boxwidtha{% \pathkeysval{KV/frame/framebox/width}-2\fboxsep-2\fboxrule }% \noindent\begin{lrbox}\@tempboxa @@ -2124,8 +2544,9 @@ The following provide our first examples of pathkeys and a demonstration of some \end{document} \finish{example} + \begin{noteenv} -When using pathkeys (and in general the commands \ffx'{\ltxkeys@definekeys,\ltxkeys@declarekeys}), there is a potential problem in deploying forward slashes in key defaults and macros without enclosing those slashes in curly braces. They will confuse the parser. Several solutions exist, including tweaking the relevant internal parser, but I haven't decided on the optimal solution to this possibility. For example, the following will fail: +When using pathkeys (and in general the commands \ffx'{\ltxkeysdefinekeys,\ltxkeysdeclarekeys}), there is a potential problem in deploying forward slashes in key defaults and macros without enclosing those slashes in curly braces. They will confuse the parser. Several solutions exist, including tweaking the relevant internal parser, but I haven't decided on the optimal solution to this possibility. For example, the following will fail: \start{example}[Forward slashes in key defaults and macros] \pathkeys{fam/subfam/subsubfam/define*: @@ -2145,6 +2566,31 @@ Its correct form is \end{noteenv} +\docsubsection(sec:pathkeys-sametype)<pathkeys of common type> + {Defining pathkeys of common type} + +To define pathkeys of the same/one type (in the set \fnz{ord,cmd,sty,sty*,bool,choice}), simply put \quoted{(\ang{type})}, within the parenthesis, after \ang{flag} and omit \ang{keytype} in \ang{attrib}. For example, the following defines only boolean pathkeys: + +\start{example}[Pathkeys of the same type] +\pathkeys{fam/subfam/subsubfam/|R(define|*|(bool|)): + |com(No |ang(keytype) in the following specifications:) + keya/true/\ifpathkeysval|R({)fam/subfam/subsubfam/keya|R(})\then + \def\x{T}\else\def\x{F}\fi; + keyb/true/\ifpathkeysvalTF{fam/subfam/subsubfam/keyb} + {\def\x##1{##1}}{\def\x{F}} +} +\finish{example} + +And the following defines only command keys: + +\start{example}[Pathkeys of the same type] +\pathkeys{fam/subfam/|R(define|*|(cmd|)): + keya/keya-default/\def\cmda##1{##1}; + keyb/keyb-default +} +\finish{example} + + \docsubsection(sec:pathkeys-shortcmds){Shortened pathkeys commands} As seen above, the estate for deploying pathkeys can be large when compared with the amount of typing required for conventional keys presented in the previous chapters. To reduce the estate, the first line of thought is to store any long path in a macro and call the macro instead of the path. The path is always fully expanded under safe actives. The following example demonstrates this approach. @@ -2161,7 +2607,8 @@ As seen above, the estate for deploying pathkeys can be large when compared with \pathkeys{\mypath/set: putframe=true} \pathkeys{\mypath/ifdef: xwidth}{\def\x{T}}{\def\x{F}} \pathkeys{\mypath/print value: xwidth}=\z@pt -\pathkeys@storevalue{\mypath/putframe}\cmd +\pathkeysstorevalue{\mypath/putframe}\cmd +\pathkeysstorevalueof{\mypath/putframe}\cmda \edef\x{\ifpathkeysvalTF{\mypath/putframe}{T}{F}} \edef\x{\ifpathkeysval \mypath/putframe\then T\else F\fi} \edef\x{\ifpathkeysval \mypath/putframe\then T\else F\fi} @@ -2170,110 +2617,161 @@ As seen above, the estate for deploying pathkeys can be large when compared with Instead of defining your own commands like the above \fx{\mypath}, you can use the following name-spaced commands: -\start+{newmacro}[\newpath,\defpath,\changepath,\undefpath,\usepath] -\newpath{|A(pathname)}{|A(path)} -\defpath{|A(pathname)}{|A(path)} -\changepath{|A(pathname)}{|A(path)} -\undefpath{|A(pathname)} -\usepath{|A(pathname)} -\finish{newmacro} -\fxim*{\newpath,\defpath,\changepath,\undefpath,\usepath} +\start+{newmacro}[\pathkeysnewpath,\pathkeysusepaths, etc.] +\pathkeysnewpath{|A(pathname)}{|A(path)} +\pathkeysdefpath{|A(pathname)}{|A(path)} +\pathkeysassignpaths{|A(pathname-1)=|A(path-1),...,|A(pathname-n)=|A(path-n)} +\pathkeyschangepath{|A(pathname)}{|A(path)} +\pathkeysundefpaths{|A(pathname-1),|A(pathname-2),...,|A(pathname-n)} +\pathkeysundefpath{|A(pathname)} +\pathkeysgundefpaths{|A(pathname-1),|A(pathname-2),...,|A(pathname-n)} +\pathkeysgundefpath{|A(pathname)} +\pathkeysusepaths{|A(pathname-1),|A(pathname-2),...,|A(pathname-n)} +\pathkeysusepath{|A(pathname)} +\finish{newmacro} +\fxim*{\pathkeysnewpath,\pathkeysdefpath,\pathkeysassignpaths, \pathkeyschangepath,\pathkeysundefpaths, \pathkeysgundefpaths,\pathkeysusepaths} + +These commands have their own separate namespace. Internally, the plural forms of these commands are the same as their singular variants. Here, +\begin{enum} +\item After the definition of \ang{pathname}, it is used as an abbreviation for the full path \ang{path}. +\item The command \fx{\pathkeysnewpath} creates \ang{pathname} if it didn't already exist. +\item The command \fx{\pathkeysdefpath} creates \ang{pathname} whether or not it exists. +\item The command \fx{\pathkeyschangepath} is equivalent to \fx{\pathkeysdefpath}. +\item The commands \ffx'{\pathkeysundefpaths, \pathkeysgundefpaths} undefine the comma-separated list of \ang{pathnames} locally and globally, respectively. +\item The command \fx{\pathkeysassignpaths} defines a series of unique pathnames as shown by its use syntax above. The equality sign in that syntax is mandatory. Existing paths are not overwritten. +\item The commands \ffx'{\pathkeysusepaths,\pathkeysusepath} are synonymous and expand the comma-separated entries in \ang{pathnames} or \ang{pathname} to their full meaning. The action specified by \ang{flag} is then executed on all the listed paths. +\item The macros + \start{syntax} + \pathkeysnewpath \pathkeysdefpath \pathkeysassignpaths + \pathkeyschangepath \pathkeysundefpaths \pathkeysundefpath + \pathkeysgundefpaths \pathkeysgundefpath \pathkeysusepaths + \pathkeysusepath + \finish{syntax} + have shorter counterparts via the command \fx{\pathkeysuseshortcmds} (see \sref{tab:pathkeys-cmdabbrv}). +\end{enum} -These commands have their own separate namespace. Here, \ang{pathname} is used, after definition, as an abbreviation for the full path \ang{path}. The command \fx{\newpath} creates \ang{pathname} if it didn't already exist; \fx{\defpath} creates \ang{pathname} whether or not it exists; \fx{\changepath} is equivalent to \fx{\defpath}; \fx{\undefpath} undefines \ang{pathname}; and \fx{\usepath} expands \ang{pathname} to its full meaning. The macro \fx{\usepath} does accept, as argument, a comma-separated list of pathnames. When using the flag \fx{ifdef} or \fx{ifkeyonpath}, if \ang{path} or \ang{pathname} is a comma-separated list, all the given paths are searched in determining if the key is defined (see the following example). +The macros \ffx'{\usepaths, \usepath}, which are available only within the \fx{\pathkeys} command, are synonymous with their longer variants. +%\endtrace -\start+{example}[\newpath, \usepath] -\newpath{path1}{fam/subfam/subsubfam1} -\newpath{path2}{fam/subfam/subsubfam2} -\pathkeys{\usepath{path1}/define: +\start+{example}[\pathkeysassignpaths, \pathkeysusepaths] +\pathkeysassignpaths{path1=fam/subfam/subsubfam1,path2=fam/subfam/subsubfam2} +|com(Define `keya' and `keyb' on paths 1 and 2:) +\pathkeys{|R(\usepaths){path1,path2}/define|R(*): cmd/keya/xx/\def\cmda#1{#1}; bool/keyb/true } -\pathkeys{|R(\usepath{path1,path2})/ifkeyonpath: keya}{\def\x{T}}{\def\x{F}} -\pathkeys@storevalue{\usepath{path1}/keyb}\cmd -\edef\x{\ifpathkeysvalTF{\usepath{path1}/keya}{T}{F}} -\finish{example} - -\start+{example}[\defpath, \usepath, set, setrm] -\defpath{path1}{fam/subfam/subsubfam1} -\defpath{path2}{fam/subfam/subsubfam2} -|com(Define `key1' on two paths:) -\pathkeys{\usepath{path1,path2}/define*: +|com(Check if `keya' is defined on either path 1 or 2:) +\pathkeys{|R(\usepaths){path1,path2}/ifkeyonpath: keya}{\def\x{T}}{\def\x{F}} +|com(\usepaths and \usepath aren't available outside \pathkeys:) +\pathkeysstorevalue{|R(\pathkeysusepath){path1}/keyb}\cmd +\edef\x{\ifpathkeysvalTF{|R(\pathkeysusepaths){path1}/keya}{T}{F}} + +|com(Force redefine `path1' and `path2':) +\pathkeysdefpath{path1}{fam/subfam/subsubfam1} +\pathkeysdefpath{path2}{fam/subfam/subsubfam2} +|com(Define `key1' on `path1' and `path2':) +\pathkeys{|R(\usepaths){path1,path2}/define: cmd/key1/12cm/\def\y##1{#1yy##1} } -|com(Set keys on paths 1 and 2 and put undefined keys in the `rm list') +|com(Set keys on `path1' and `path2' and put undefined keys in the `rm list') |com(instead of raising errors:) -\pathkeys{\usepath{path1,path2}/|R(set*+): +\pathkeys{|R(\usepaths){path1,path2}/|R(set*+): key1=10cm,key2=true,key3=xx } -|com(Set `rm keys` and again put undefined keys in the `rm list') +|com(Set `rm keys' and again put undefined keys in the `rm list') |com(instead of raising errors:) -\pathkeys{\usepath{path1,path2}/|R(setrm*+):} +\pathkeys{|R(\usepaths){path1,path2}/|R(setrm*+):} \finish{example} -The following shortened counterparts of the pathkeys commands are provided (see \sref{tab:pathkeys-cmdabbrv}). The abbreviated commands are available only after the user has invoked \fx{\pathkeys@useshortcmds}, which expects no argument. The command \fx{\pathkeys@useshortcmds} has only local effect, \ie, the abbreviations may be localized to a group. The abbreviations are defined only if they're definable (\ie, didn't exist before calling the command \fx{\pathkeys@useshortcmds}). +The shortened counterparts of the pathkeys commands are provided in \sref{tab:pathkeys-cmdabbrv}. The abbreviated commands become available only after the user has invoked the macro \fx{\pathkeysuseshortcmds} (or \fx{\pathkeysuseshortnames}), which expects no argument. The abbreviations-building macro \fx{\pathkeysuseshortcmds} has only local effect, \ie, the abbreviations may be localized to a group. The abbreviations are defined only if they're definable (\ie, didn't exist before calling the command \fx{\pathkeysuseshortcmds})\footnote{The user can introduce his own abbreviations using the command \ftfx{\pathkeysmakeshortcmds}.}. \begingroup\small -\begin{tabularx}{\linewidth}{|p{3.5cm}|p{2.5cm}|p{3.5cm}|X|} +\begin{tabularx}{\linewidth}{|p{4cm}|p{2.25cm}|p{4cm}|p{2.25cm}|} \caption{Pathkeys command abbreviations\xwmlabel{tab:pathkeys-cmdabbrv}}\\\hline \rowcolor{pink} \bf Command & \bf Abbreviation & \bf Command & \bf Abbreviation\\\hline \endfirsthead \hline -\multicolumn{3}{|l|}{\emph{Continued from last page}}\\\hline +\multicolumn{4}{|l|}{\emph{Continued from last page}}\\\hline \bf Command & \bf Abbreviation & \bf Command & \bf Abbreviation\\\hline \endhead -\multicolumn{3}{|r|}{\emph{Continued on next page}}\\\hline +\multicolumn{4}{|r|}{\emph{Continued on next page}}\\\hline \endfoot \hline \endlastfoot \fx{\pathkeysval} & \fx{\pkv} & \fx{\pathkeyskeyval} & \fx{\pkkv} \\\hline \fx{\ifpathkeysval} & \fx{\ifpkv} & \fx{\ifpathkeyskeyval} & \fx{\ifpkkv} \\\hline \fx{\ifpathkeysvalTF} & \fx{\ifpkvTF} & \fx{\ifpathkeyskeyvalTF} & \fx{\ifpkkvTF} \\\hline +\fx{\pathkeysnewpath} & \fx{\newpath} & \fx{\pathkeysdefpath} & \fx{\defpath} \\\hline +\fx{\pathkeyschangepath} & \fx{\changepath} & \fx{\pathkeysassignpaths} & \fx{\assignpaths} \\\hline +\fx{\pathkeysundefpaths} & \fx{\undefpaths} & \fx{\pathkeysundefpath} & \fx{\undefpath} \\\hline +\fx{\pathkeysgundefpaths} & \fx{\gundefpaths} & \fx{\pathkeysgundefpath} & \fx{\gundefpath} \\\hline +\fx{\pathkeysusepath} & \fx{\usepath} & \fx{\pathkeysusepaths} & \fx{\usepaths} \\\hline \end{tabularx} \endgroup -The user isn't constrained to use the short form commands of \sref{tab:pathkeys-cmdabbrv}. He/she can define his/her own short forms by using the command \fx{\pathkeys@makeshortcmds}, which has the syntax: +The user isn't constrained to use the short form commands of \sref{tab:pathkeys-cmdabbrv}. He can define his own short forms by using the command \fx{\pathkeysmakeshortcmds}, which has the syntax: -\start{newmacro}[\pathkeys@makeshortcmds] -\pathkeys@makeshortcmds{|A(short-1)=|A(long-1), ..., |A(short-n)=|A(long-n)} +\start{newmacro}[\pathkeysmakeshortcmds] +\pathkeysmakeshortcmds{|A(short-1)=|A(long-1), ..., |A(short-n)=|A(long-n)} \finish{newmacro} -where \ang{short-i} and \ang{long-i} are the short (new) and long (existing) aliases of the command \ang{i}. The \eqsign is mandatory here. You don't have to (in fact, you shouldn't) call \fx{\pathkeys@useshortcmds} after calling \fx{\pathkeys@makeshortcmds}. +where \ang{short-i} and \ang{long-i} are the short (new) and long (existing) aliases of the command \ang{i}. The \eqsign is mandatory here. You don't have to (in fact, you shouldn't) call \fx{\pathkeysuseshortcmds} after calling \fx{\pathkeysmakeshortcmds}. -\start{example}[\pathkeys@makeshortcmds] -\pathkeys@makeshortcmds{\kval=\pathkeyskeyval,\ifkvalTF=\ifpathkeyskeyvalTF} +\start{example}[\pathkeysmakeshortcmds] +\pathkeysmakeshortcmds{\kval=\pathkeyskeyval,\ifkvalTF=\ifpathkeyskeyvalTF} \finish{example} \docsubsection(sec:pathkeys-dftpath){Default and current paths} -\start+{newmacro}[\pathkeys@currentpath, etc.] -\pathkeys@addtodefaultpath{|A(path)} -\pathkeys@changedefaultpath{|A(path)} -\pathkeys@currentpath{|A(path)} -\pathkeys@usedefaultpath -\pathkeys@pushcurrentpath -\pathkeys@popcurrentpath -\pathkeys@pathhistory +We begin the section with a note of caution: path changes within the \fx{\pathkeys} command are limited in scope, since the current path is pushed upon entry into this command and popped on exit. To change the current path while in \fx{\pathkeys} command, use the \fx{normalcode} flag of \sref{tab:flags}. + +\start+{newmacro}[\pathkeyscurrentpath, etc.] +\pathkeysaddtodefaultpath{|A(path)} +\pathkeyschangedefaultpath{|A(path)} +\pathkeyscurrentpath{|A(path)} +\pathkeysusedefaultpath +\pathkeyspushcurrentpath +\pathkeyspopcurrentpath +\pathkeyspathhistory \finish{newmacro} -\fxim*{\pathkeys@addtodefaultpath,\pathkeys@changedefaultpath, - \pathkeys@currentpath,\pathkeys@usedefaultpath,\pathkeys@pushcurrentpath, - \pathkeys@popcurrentpath,\pathkeys@pathhistory} +\fxim*{\pathkeysaddtodefaultpath,\pathkeyschangedefaultpath, + \pathkeyscurrentpath,\pathkeysusedefaultpath,\pathkeyspushcurrentpath, + \pathkeyspopcurrentpath,\pathkeyspathhistory} + +If the key path is empty, then the current path will be used. If there is no current path, the default path will be used, \emph{but only after the user has issued \fx{\pathkeysusedefaultpath}}. The default path is \quotedfx{pathkeys@default@main/pathkeys@default@sub}. The default path can be made the current path by invoking the command \fx{\pathkeysusedefaultpath}, which is parameterless. The default path can be changed by the one-parameter commands \ffx'{\pathkeysaddtodefaultpath, \pathkeyschangedefaultpath}. + +The current path can be declared by providing an argument to the non-expandable one-parameter command \fx{\pathkeyscurrentpath}. The declared current path will be available in the macro \fx{\pathkeyscurrentpathtext}, which is expandable. \emph{A call to \fx{\pathkeyscurrentpath} immediately changes the current path}. The internal macro \fx{\pathkeyscurrentpathtext} always holds the current path. It is possible for the user to change \fx{\pathkeyscurrentpathtext} directly, but this is not recommended, since it will not allow the path history to be revised. That is why \fx{\pathkeyscurrentpathtext} doesn't look like a user command. For example, the following assignment is possible but not advisable: + +\start{syntax}[\pathkeyscurrentpathtext] +\let\pathkeyscurrentpathtext=\pathkeysdefaultpath +\finish{syntax} +\fxi*{\pathkeyscurrentpathtext} -If the key path is empty, then the current path will be used; and if there is no current path, the default path will be used. The default path is \fx{dft@main/dft@sub}. This can be changed by the commands \ffx'{\pathkeys@addtodefaultpath, \pathkeys@changedefaultpath}. The current path can be declared by providing an argument to the command \fx{\pathkeys@currentpath}. The default path can be made the current path by invoking the command \fx{\pathkeys@usedefaultpath}, which is parameterless. +This should only be done via \fx{\pathkeysusedefaultpath}. -It isn't mandatory, but it is useful, to first push the prevailing path before changing it. This can be done by calling the parameterless command \fx{\pathkeys@pushcurrentpath}. When you're done with the current path, you can revert to the path before the current path by calling the command \fx{\pathkeys@popcurrentpath}. You can get the entire history of path changes from the container \fx{\pathkeys@pathhistory}, which is useful in complex situations. However, it should be noted that \fx{\pathkeys@pathhistory} doesn't contain a chronological order of path changes: if a path is already contained in it, it wouldn't be added again. +If you change the default path by calling any of the commands \ffx'{\pathkeysaddtodefaultpath, \pathkeyschangedefaultpath}, you will have to call \fx{\pathkeysusedefaultpath} to update \fx{\pathkeyscurrentpathtext}. For some reason, this is not done automatically. + +It isn't mandatory, but it is useful, to first push the prevailing path before changing it. This can be done by calling the parameterless command \fx{\pathkeyspushcurrentpath}. When you're done with the current path, you can revert to the path before the current path by calling the command \fx{\pathkeyspopcurrentpath}. You can get the entire history of path changes from the container \fx{\pathkeyspathhistory}, which is useful in complex situations. However, it should be noted that \fx{\pathkeyspathhistory} doesn't contain a chronological order of path changes: if a path is already contained in it, it wouldn't be added again. Also, \fx{\pathkeyspathhistory} is built and revised globally: path changes in local groups will appear in \fx{\pathkeyspathhistory} outside the groups. The commands \ffx'{\pathkeysundefpaths, \pathkeysgundefpaths} don't affect this behavior. + +I can't see a user need for it, but you can use the command \fx{\pathkeysifnopath} to ascertain if a given \ang{path} actually contains a valid path. This is used internally. + +\start{newmacro}[\pathkeysifnopath] +\pathkeysifnopath{|A(path)}{|A(true)}{|A(false)} +\finish{newmacro} +\fxim*{\pathkeysifnopath} -Before the current path is resorted to, the path for the commands \ffx{\pathkeys, \pathkeysval, \ifpathkeysval}, \eetc must be empty (\ie, no main and no subs). Therefore, in any given setting, the path that is dominant can be made current so that it isn't given in \ffx{\pathkeys, \pathkeysval, \ifpathkeysval}, \eetc. The non-dominant paths could then be listed in full. Of course, there can't be more than one current path. +Before the current path is resorted to (\ie, used), the path specified in the the commands \ffx{\pathkeys, \pathkeysval, \ifpathkeysval}, \eetc must be empty (\ie, no main and no subs). Therefore, in any given setting, the path that is dominant can be made current so that it isn't given in \ffx{\pathkeys, \pathkeysval, \ifpathkeysval}, \eetc. The non-dominant paths could then be listed in full. Of course, there can't be more than one current path. Perhaps a better approach is to use \ffx{\pathkeysnewpath, \pathkeysusepaths}, etc. -\start+{example}[\pathkeys@currentpath, etc.] +\start+{example}[\pathkeyscurrentpath, etc.] \newcommand*\myframebox[1][]{% - |R(\pathkeys@currentpath){KV/frame/framebox}% + |R(\pathkeyscurrentpath){KV/frame/framebox}% \pathkeys{launch:#1}% \begingroup - |R(\pathkeys@useshortcmds) + |R(\pathkeysuseshortcmds) \fboxsep\pkv{framesep}\fboxrule\pkv{framerule}\relax - \cptdimdef\boxwidtha{\pkv{width}-2\fboxsep-2\fboxrule}% + \ltsdimdef\boxwidtha{\pkv{width}-2\fboxsep-2\fboxrule}% \noindent\begin{lrbox}\@tempboxa \begin{minipage}[c][\height][s]\boxwidtha \@killglue @@ -2297,6 +2795,62 @@ Before the current path is resorted to, the path for the commands \ffx{\pathkeys \end{document} \finish{example} +\start+{example}[Tiling with pathkeys] +\documentclass{article} +\usepackage{atbegshi,picture,graphicx,ifpdf} +\usepackage{pathkeys} +\makeatletter +\pathkeys{wallpaper/fam/|R(define*|(cmd|)): + viewport/00 00 100 100; + xtilenr/2; + ytilenr/2; + wpxoffset/0pt; + wpyoffset/0pt; + inputpath// +} +\newcommand*\mytilewallpaper[2][]{% + \begingroup + \pathkeyscurrentpath{wallpaper/fam}% + \pathkeys{set:#1}% + \pathkeysuseshortcmds + \edef\ffileext{\ifpdf pdf\else eps\fi}% + \edef\reserved@a{\pkv{inputpath}}% + \edef\reserved@a{\expandafter\ltxkeysstripallouterbraces + \expandafter{\reserved@a}}% + \edef\Ginput@path{\ifcsemptyTF\reserved@a{}{{\reserved@a/}}}% + \ltsdimdef\tilewidth{|(\paperwidth-\pkv{wpxoffset}*2|)/\pkv{xtilenr}}% + \ltsdimdef\tileheight{|(\paperheight-\pkv{wpyoffset}*2|)/\pkv{ytilenr}}% + \ltsdimdef\tileY{-\paperheight+\pkv{wpyoffset}}% + \@tempcntb\z@ + \ltswhilenum\@tempcntb<\pkv{ytilenr}\do{% + \edef\tileX{\pkv{wpxoffset}}% + \@tempcnta\z@ + \ltswhilenum\@tempcnta<\pkv{xtilenr}\do{% + \leavevmode\@killglue + \ltsexpanded{\noexpand\put|(\tileX,\tileY|){\noexpand\includegraphics + [viewport=\pkv{viewport},height=\tileheight,width=\tilewidth,clip]% + {#2.\ffileext}}}% + \advance\@tempcnta\@ne + \ltsdimadd\tileX{\tilewidth}% + }% + \advance\@tempcntb\@ne + \ltsdimadd\tileY{\tileheight}% + }% + \endgroup +} +\makeatother + +\begin{document} +\def\wpspec{[viewport=20 21 590 400,xtilenr=4,ytilenr=4, + wpxoffset=2cm,wpyoffset=2cm,inputpath={./graphics}]{comet1}} +\AtBeginShipout{% + \AtBeginShipoutUpperLeft{% + \ifnumoddTF\thepage{}{\expandafter\mytilewallpaper\wpspec}% +}} +x +\end{document} +\finish{example} + \docsubsection(sec:nestedpathkeys){Nested pathkeys} @@ -2312,10 +2866,10 @@ The command \fx{\pathkeys} can be nested, as the following example shows: |com(The callback of `keyb' says ``if `keyb' is `true', define `keyc''':) bool/keyb/true/ |R(\pathkeys){\mypath/ifbool: keyb}{% - |R(\pathkeys){\mypath/define: cmd/keyc/xx/\def\cmdc####1{####1#1}}% - }{% + |R(\pathkeys){\mypath/define: cmd/keyc/xx/\def\cmdc####1{####1#1}} + }{ |com(`keyd' has no callback:) - |R(\pathkeys){\mypath/define: choice/keyd.{yes,no}/yes}% + |R(\pathkeys){\mypath/define: choice/keyd.{yes,no}/yes} } } \pathkeys{\mypath/set: keyb=true} @@ -2332,7 +2886,7 @@ Try to find out why the following produces an error: \pathkeys{\mypath/set: keya=bbb} \finish{example} -The reason is that \fx{keyb} was defined when the default was being set up for \fx{keya} after the definition of \fx{keya}. The second setting of \fx{keya} prompts an error that \fx{keyb} is being redefined. Notice that \fx{keyb} is to be defined uniquely by the flag \fx{define}\Redstar. To avoid this type of error, you may consider removing \redstar from \fx{define}\Redstar. +The reason is that \ttx{keyb} was defined when the default was being set up for \ttx{keya} after the definition of \ttx{keya}. The second setting of \ttx{keya} prompts an error that \ttx{keyb} is being redefined. Notice that \ttx{keyb} is to be defined uniquely by the flag \fx{define}\Redstar. To avoid this type of error, you may consider removing \redstar from \fx{define}\Redstar. \docsubsection(sec:options-pathkeys){Pathkeys as class or package options} @@ -2341,26 +2895,211 @@ To use the command \fx{\pathkeys} for declaring class or package options, the us \start{example}[Declaring and processing options] \ProvidesPackage{mypackage}[2011/11/11 v0.1 My test package] -\newpath{mypath}{mypackage/myfunc/myfunckeys} +\pathkeysnewpath{mypath}{mypackage/myfunc/myfunckeys} |com(Declare three unique options:) -\pathkeys{\usepath{mypath}/|R(declareoptions)|*: +\pathkeys{\pathkeysusepath{mypath}/|R(declareoptions)|*: cmd/opt1/12cm/\def\y##1{#1yy##1}; - bool/opt2/true/\ifpathkeysval{\usepath{mypath}/opt2}\then + bool/opt2/true/\ifpathkeysval{\pathkeysusepaths{mypath}/opt2}\then \def\x{T}\else\def\x{F}\fi; - ord/opt3/zz/\def\z##1{#1zz##1}; + ord/opt3/zz/\def\z##1{#1zz##1} } |com(Set up defaults for options `opt1' and `opt2', ignoring option `opt3':) -\pathkeys{\usepath{mypath}/|R(executeoptions): +\pathkeys{\pathkeysusepaths{mypath}/|R(executeoptions): opt1=10cm,opt2=true,opt3=yy [opt3] } |com(Ignore `opt1' when processing options:) -\pathkeys{\usepath{mypath}/|R(processoptions)|*: [opt1]} +\pathkeys{\pathkeysusepath{mypath}/|R(processoptions)|*: [opt1]} \documentclass[opt1=2cm,opt2=false]{article} \usepackage[opt3=somevalue]{mypackage} \finish{example} +\docsubsection(sec:classes-pathkeys)<classes in pathkeys> + {\headquoted{Classes} in \headfx{pathkeys} command} + +The \fx{\pathkeys} command indeed can accommodate \quoted{classes}. This is one of its advantages. Each class is made up of one unit of \ang{paths}, \ang{flag} and \ang{attrib}, as in + +\start+{newmacro}[A single classes in \pathkeys] +\pathkeys|*[|A(classparser)]{|A(paths)/|A(flag)|R(:) |A(attrib)} +\finish{newmacro} +\fxi*{\pathkeys} + +The \stform of \fx{\pathkeys} expects a macro that contains the given classes. It will expand the given macro once before processing its contents further. The optional argument \ang{classparser} is the class list parser/separator (see below)\footnote{The default list parser for \ang{attrib} remains \qsemicolon. This too can be changed via the package option \ftfx{keyparser} (see \sref{tab:pkgoptions}).}. The default list parser for classes is double bar \quotedfx{||}, but this can be changed, within limits, by the user. It can be changed to one or a combination of characters that aren't in the set \fx{{,;:@|/}}. Active bars that are list parsers will be normalized internally. Those bars that aren't list parsers will be left intact. + +The following is the syntax for multiple classes in \fx{\pathkeys}: + +\start+{newmacro}[Classes in \pathkeys] +\pathkeys|*[|A(classparser)]{ + |A(paths-1)/|A(flag-1)|R(:) |A(attrib-1) |dbar + |A(paths-2)/|A(flag-2)|R(:) |A(attrib-2) |dbar + ... |dbar + |A(paths-n)/|A(flag-n)|R(:) |A(attrib-n) +} +\finish{newmacro} + +Here, \ang{attrib-1} will be executed on all the paths listed in \ang{paths-1}, \ang{attrib-2} on all of \ang{paths-2}, \eetc. + +\start+{example}[Classes in \pathkeys] +\ltxkeys@options{endcallbackline=true} +\pathkeys{ + |com(Define command keys `keya' and `keyb' on path `fam1/subfam1':) + |R(fam1/subfam1/define*|(cmd|)): + keya/keya-default/\def\cmda##1{##1}; + keyb/keyb-default + |dbar + |com(Define boolean keys `keyc' and `keyd' on path `fam1/subfam1':) + |R(fam1/subfam1/define*|(bool|)): + keyc/true/\ifpathkeysval{fam1/subfam1/keyc}\then\def\cmdb##1{##1}\fi; + keyd/true + |dbar + |com(Define command option `opt1' on path `options1/suboptions1':) + |R(options1/suboptions1/declareoptions|(cmd|)): + opt1/{default-arg1,default-arg2}/ + |com(The boolean `\ifpathkeys@dec' is true when keys are being defined,) + |com(and false otherwise. It requires \then to follow it. In its place,) + |com(you can use `\ifltxkeys@dec', which requires no \then.) + |com(`\argpattern' is introduced in |sref(sec:weirdargs).) + |R(\argpattern){#1,#2} + \ifpathkeys@dec\then\else + \def\cmda##1{#1***##1} + \def\cmdb##1{#2+++##1} + \fi; + |dbar + |com(Set `keya' and `keyc' on path `fam1/subfam1'; ignore `keyb':) + |R(fam1/subfam1/set): keya=xx, keyb=yy, keyc=false [keyb] + |dbar + |com(Set 2-argument `opt1' on path `options1/suboptions1':) + |R(options1/suboptions1/set): opt1={x,y} + |dbar + |com(Change current path to `fam2/subfam2' and define command \cmde:) + |R(normalcode): + \pathkeyscurrentpath{fam2/subfam2} + \def\cmde##1{x##1x} + |dbar + |com(Define command keys `keya' and `keyb' on current path `fam2/subfam2':) + |R(define|(cmd|)): + keya/keya-default/\def\cmda##1{##1}; + keyb/keyb-default + |dbar + |com(Set `keya' and `keyb' on current path `fam2/subfam2':) + |R(set): keya=ww, keyb=zz + |dbar + |com(Define `keya' and `keyb' on paths `fam3/subfam3' and `fam4/subfam4':) + |R(fam3/subfam3,fam4/subfam4/define): + cmd/keya/keya-default/\def\cmda##1{##1}; + |com(What is the problem with the next definition? This illustrates) + |com(a point of caution about defining keys on multiple paths. When) + |com(setting `keyb' on path `fam4/subfam4', we will be executing its) + |com(callback on path `fam3/subfam3':) + bool/keyb/true/\ifpathkeysvalTF{fam3/subfam3/keyb}{\def\x{T}}{\def\x{F}} + |dbar + |com(Define the following keys on paths `fam1/subfam1' and `fam2/subfam2':) + fam1/subfam1,fam2/subfam2/define*: + choice/boxalign.{% + center/.do=\def\ttextalign{center}\def\cmd##1{#1xx##1}, + left/.do=\def\ttextalign{flushleft}, + right/.do=\def\ttextalign{flushright} + }/center; + bool/putframe/true; + cmd/boxlength/2cm; + ord/boxheight/1.5cm +} +\finish{example} + +It should be recalled that path changes within \fx{\pathkeys} command are limited in scope, since the current path is pushed upon entry into this command and popped on exit. + + +\docsection(sec:weirdargs){Keys with argument patterns} + +\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: + +\start+{macro}[Key-definition commands that can have argument pattern] +\ltxkeys@ordkey \ltxkeys@newordkey +\ltxkeys@ordkeys \ltxkeys@newordkeys +\ltxkeys@cmdkey \ltxkeys@newcmdkey +\ltxkeys@cmdkeys \ltxkeys@newcmdkeys +\ltxkeys@stylekey \ltxkeys@newstylekey +\ltxkeys@stylekeys \ltxkeys@newstylekeys +\ltxkeysdefinekeys (only when defining cmd keys) +\ltxkeysdeclarekeys (only when defining ord, cmd, sty keys) +\pathkeys (only when defining ord, cmd, sty keys) +\finish{macro} +\fxi*{\ltxkeys@ordkey,\ltxkeys@newordkey,\ltxkeys@ordkeys,\ltxkeys@newordkeys, +\ltxkeys@cmdkey,\ltxkeys@newcmdkey,\ltxkeys@cmdkeys,\ltxkeys@newcmdkeys, +\ltxkeys@stylekey,\ltxkeys@newstylekey,\ltxkeys@stylekeys,\ltxkeys@newstylekeys, +\ltxkeysdefinekeys,\ltxkeysdeclarekeys} + +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: + +\start{example}[Key callback with multiple arguments] +\ltxkeys@ordkey[KV]{fam}{textsize}[{2cm,8cm}]{% + |com(Since `ltxkeys' package preserves outer braces in values of keys,) + |com(first strip any possible outer braces from the key's value:) + \ltsstripallouterbraces{#1}\reserved@a + |com(Test if the key's value contains comma:) + \oifinsetTF{,}{\reserved@a}{% + \def\do##1,##2\@nil{% + \textwidth=##1 + \textheight=##2 + }% + \expandafter\do\reserved@a\@nil + }{% + \@latex@error{Bad argument for key `textsize'} + {No comma in value of key `textsize'}% + }% +} +\ltxkeyssetkeys[KV]{fam}{textsize={4cm,10cm}} +\finish{example} + +With the \pkg'{ltxkeys} this can be achieved directly as follows: + +\start{example}[Key callback with multiple arguments] +\ltxkeys@ordkey[KV]{fam}{textsize}[{2cm,8cm}]{% + |R(\argpattern){#1,#2} \textwidth=#1 \textheight=#2\relax +} +\ltxkeyssetkeys[KV]{fam}{textsize={4cm,10cm}} +\finish{example} + +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. + +The same principles apply when using the macros \ffx'{\ltxkeysdefinekeys, \ltxkeysdeclarekeys, \pathkeys}: simply put \argpat anywhere within the key's callback, but note that it doesn't apply in the case of boolean and choice keys. + +\start+{example}[Key callback with multiple arguments] +\ltxkeys@cmdkey[KV]{fam}[mp@]{keya}[{default1 and default2}]{% + |R(\argpattern){#1 and #2}\def\z##1{#1xx##1xx#2} +} +\ltxkeyssetkeys[KV]{fam}{keya={arg1 and arg2}} + +\ltxkeysdeclarekeys[KV]{fam}[mp@]{% + cmd/keya/{left/right}/|R(\argpattern){#1/#2}\def\xa##1{#1/##1/#2}; + bool/keyb/true/\ifmp@keyb\def\xb##1{#1xx##1}\fi; + sty*/keyc/blue+green+black/|R(\argpattern){#1+#2+#3}\def\xc##1{#1==#2==#3}/ + |com(Dependant `keyd'. Choice key can't have weird arguments:) + choice>keyd.{% + left/.do=\def\y##1{#1 xx ##1}, + right/.do=\def\y##1{##1 yy #1}, + center/.do=\def\y##1{##1 zz #1} + }>left>\def\xd##1{##1xx#1}; + ord/keye/{x y z w}/|R(\argpattern){#1 #2 #3 #4}\def\xe{#1 #2 #3 #4}; +} +\ltxkeyssetkeys[KV]{fam}{keya={value1/value2}, keyc={value1+value2+value3}} +\finish{example} + +Caution should be exercised when using \argpat for the dependant key of a style key in the case in which the value of the parent key is used as the default for the dependant 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{\ltxkeys@stylekeys} will define and initialize dependant keys on the fly. + +\start+{example}[Style key callback with multiple arguments] +\ltxkeys@stylekeys|*[KV]{fam}[mp@]{keya}[{left right center}]|(% + ord/keyb/\parentval/|R(\argpattern){#1,#2}\edef\y{\expandcsonce{#1}#2}; + ord/keyc/\KV@fam@keya@value/|R(\argpattern){#1,#2}\def\y##1{#1xx##1xx#2}; + cmd/keyd/{center} +|){% + |R(\argpattern){#1 #2 #3 #4 #5}\def\x##1{#1xx##1xx#2#3#4#5} +} +\ltxkeyssetkeys[KV]{fam}{keya={arg1 arg2 arg3}} +\finish{example} + + \docsection(sec:misc-commands){Some miscellaneous commands} Some of the macros used internally by the \pkg'{ltxkeys} are available to the user. A few of them are described below. @@ -2368,51 +3107,60 @@ Some of the macros used internally by the \pkg'{ltxkeys} are available to the us \docsubsection(sec:trimspaces){Trimming leading and trailing spaces} -\start+{newmacro}[\ltxkeys@trimspaces,\ltxkeys@trimspacesincs] -\ltxkeys@trimspaces{|A(token)}|A(cs) -\ltxkeys@trimspacesincs|A(cs) +\start+{newmacro}[\ltxkeyshardtrimspaces,\ltxkeyssimpletrimspaces, etc.] +\ltxkeyssimpletrimspaces{|A(token)}|A(cs) +\ltxkeyshardtrimspaces{|A(token)}|A(cs) +\ltxkeyscurrtrimspaces{|A(token)}|A(cs) +\ltxkeysusesimpletrimspaces +\ltxkeysusehardtrimspaces +\ltxkeystrimspacesincs|A(cs) +\ltxkeystrimspacesset +\ltxkeystrimspacesincsset \finish{newmacro} -\fxim*{\ltxkeys@trimspaces,\ltxkeys@trimspacesincs} +\fxim*{\ltxkeyshardtrimspaces,\ltxkeyssimpletrimspaces, + \ltxkeyscurrtrimspaces,\ltxkeystrimspacesincs,\ltxkeysusesimpletrimspaces, + \ltxkeysusehardtrimspaces,\ltxkeystrimspacesset,\ltxkeystrimspacesincsset} -The command \fx{\ltxkeys@trimspaces} trims (\ie, removes) 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. +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}. -The command \fx{\ltxkeys@trimspacesincs} trims the leading and trailing spaces around the token in the macro \ang{cs} and returns the result in \ang{cs}. +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}. \docsubsection(sec:checkchoice){Checking user inputs} -\start+{newmacro}[\ltxkeys@checkchoice,\ltxkeys@checkinput,\CheckUserInput] -\ltxkeys@checkchoice[|A(parser)]|(|A(val)|A(order)|){|A(input)}{|A(nomin)}{|A(true)} -\ltxkeys@checkchoice|*[|A(parser)]|(|A(val)|A(order)|){|A(input)}{|A(nomin)}{|A(true)} -\ltxkeys@checkchoice|+[|A(parser)]|(|A(val)|A(order)|){|A(input)}{|A(nomin)}{|A(true)}{|A(false)} -\ltxkeys@checkchoice|*|+[|A(parser)]|(|A(val)|A(order)|){|A(input)}{|A(nomin)}{|A(true)}{|A(false)} -\ltxkeys@checkinput{|A(input)}{|A(nomin)}{|A(true)}{|A(false)} -\CheckUserInput{|A(input)}{|A(nomin)} +\start+{newmacro}[\ltxkeyscheckchoice,\ltxkeyscheckinput,\ltxkeyscheckuserinput] +\ltxkeyscheckchoice[|A(parser)]|(|A(val)|A(order)|){|A(input)}{|A(nomin)}{|A(true)} +\ltxkeyscheckchoice|*[|A(parser)]|(|A(val)|A(order)|){|A(input)}{|A(nomin)}{|A(true)} +\ltxkeyscheckchoice|+[|A(parser)]|(|A(val)|A(order)|){|A(input)}{|A(nomin)}{|A(true)}{|A(false)} +\ltxkeyscheckchoice|*|+[|A(parser)]|(|A(val)|A(order)|){|A(input)}{|A(nomin)}{|A(true)}{|A(false)} +\ltxkeyscheckinput{|A(input)}{|A(nomin)}{|A(true)}{|A(false)} +\ltxkeyscheckuserinput{|A(input)}{|A(nomin)} \finish{newmacro} -\fxim*{\ltxkeys@checkchoice,\ltxkeys@checkinput,\CheckUserInput, - \ltxkeys@commacheckchoice} +\fxim*{\ltxkeyscheckchoice,\ltxkeyscheckinput,\ltxkeyscheckuserinput, + \ltxkeyscommacheckchoice} -The command \fx{\ltxkeys@checkchoice} 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{\ltxkeys@checkchoice} will convert \ang{input} into lowercase before checking it against the nominations. The \plform of \fx{\ltxkeys@checkchoice} 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{\ltxkeys@commacheckchoice}, whose parser is implicitly \qcomma and does not need to be given by the user.}. +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.}. -The commands \ffx'{\ltxkeys@checkinput,\CheckUserInput} 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{\ltxkeys@checkinput} expects two branches of callback, while \fx{\CheckUserInput} expects no callback. Instead, \fx{\CheckUserInput} will toggle the internal boolean \fx{\ifinputvalid} to \hx{true} if the input is valid, and to \hx{false} otherwise. The internal boolean \fx{\ifinputvalid} could then be called by the user after the test. +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. \docsubsection(sec:ifinset){Does a test string exist in a string?} -\start+{newmacro}[\ltxkeys@in,\ltxkeys@iffound] +\start+{newmacro}[\ltxkeys@in,\ltxkeysiffound] \ltxkeys@in{|A(teststr)}{|A(str)} \ltxkeys@in|*{|A(teststr)}{|A(str)}{|A(true)}{|A(false)} -\ltxkeys@iffound|A(teststr)|R(\in)|A(str)|R(\then) |A(true) \else |A(false) \fi +\ltxkeysiffound|A(teststr)|R(\in)|A(str)|R(\then) |A(true) \else |A(false) \fi \finish{newmacro} -\fxim*{\ltxkeys@in,\ltxkeys@iffound} +\fxim*{\ltxkeys@in,\ltxkeysiffound} -The \unstform of the command \fx{\ltxkeys@in} 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{\ltxkeys@in} returns two \latex branches \ang{true} and \ang{false}. On the other hand, the command \fx{\ltxkeys@iffound} requires the first argument to be delimited by \fx{\in} and the second argument by \fx{\then}. +The \unstform of the command \fx{\ltxkeys@in} 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{\ltxkeys@in} 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}. -\start{example}[\ltxkeys@iffound] -\ltxkeys@iffound xx\in aax\then \def\x{T}\else \def\x{F}\fi +\start{example}[\ltxkeysiffound] +\ltxkeysiffound xx\in aax\then \def\x{T}\else \def\x{F}\fi \finish{example} -\ltsnote The command \fx{\ltxkeys@iffound} trims leading and trailing spaces around the tokens \ang{teststr} and \ang{str} before the test! The commands \ffx'{\ltxkeys@in,\ltxkeys@iffound} aren't expandable. +\ltsnote +The command \fx{\ltxkeysiffound} trims leading and trailing spaces around the tokens \ang{teststr} and \ang{str} before the test! The commands \ffx'{\ltxkeys@in,\ltxkeysiffound} aren't expandable. \docsubsection(sec:ifpattern){Does a given pattern exist in the meaning of a macro?} @@ -2428,16 +3176,72 @@ The command \fx{\ltxkeys@ifpattern} simply determines if the meaning of \ang{cmd \docsubsection(sec:ltxkeysifcase) {\ltsneverexpand{\ttcl{texcolor}{\bs ifcase}} for arbitrary strings} -\start+{newmacro}[\ltxkeys@ifcase,\ltxkeys@findmatch] -\ltxkeys@ifcase{|A(teststr)}{|A(case-1):|A(cbk-1),...,|A(case-n):|A(cbk-n)} - {|A(true)}{|A(false)} -\ltxkeys@findmatch{|A(teststr)}{|A(case-1):|A(cbk-1),...,|A(case-n):|A(cbk-n)}{|A(fn)} +\start+{newmacro}[\ltxkeysifcase,\ltxkeysfindmatch] +\ltxkeysifcase{|A(teststr)}{% + |A(case-1):|A(cbk-1),...,|A(case-n):|A(cbk-n)}{|A(true)}{|A(false)} + +\ltxkeysfindmatch{|A(teststr)}{|A(case-1):|A(cbk-1),...,|A(case-n):|A(cbk-n)}{|A(fn)} \finish{newmacro} -\fxim*{\ltxkeys@ifcase,\ltxkeys@findmatch} +\fxim*{\ltxkeysifcase,\ltxkeysfindmatch} + +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}. + +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. -The command \fx{\ltxkeys@ifcase} 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{\ltxkeys@ifcase} returns empty \fx{\currmatch} and executes \ang{false}. +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}. + +\start{newmacro}[\ltxkeysifcasse] +\ltxkeysifcasse|A(testoper){|A(teststr)} + {|A(case-1)}\do{|A(cbk-1)} + ... + |A(case-n)\do{|A(cbk-n)} +\ifnone + \do{|A(nomatch)} +\endif +\finish{newmacro} +\fxim*{\ltxkeysifcasse} + +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. + +\start{example}[\ltxkeysifcasse] +\edef\x{% + \ltxkeysifcasse\ifcassedimcmpTF{1pt+2pt+3pt} + {=2pt}\do{equal to 2pt} + {<3pt}\do{less than 3pt} + {>4pt}\do{greater than 4pt} + \ifnone + \do{no match} + \endif +} +\edef\x{% + \ltxkeysifcasse\ifcassenumcmpTF{1+2+3} + {=2}\do{equal to 2} + {<3}\do{less than 3} + \ifnone + \do{no match} + \endif +} +\edef\x{% + \ltxkeysifcasse\ifstrcmpTF{x} + {a}\do{\def\y{a}} + {b}\do{\def\y{b}} + {c}\do{\def\y{c}} + \ifnone + |com(The \do must always be there, even when the |A(nomatch) is empty:) + \do{} + \endif +} -The command \fx{\ltxkeys@findmatch} works like \fx{\ltxkeys@ifcase} but executes the fallback \ang{fn} (instead of \ang{true} or \ang{false}) when no match is found. +\begin{document} +\ltxkeysifcasse\ifstrcmpTF{x} + {a}\do{\def\y{a}} + {b}\do{\def\y{b}} + {c}\do{\def\y{c}} +\ifnone + \do{\def\y{no match}} +\endif +\end{document} +\finish{example} \docsubsection(sec:ifincsvlist){Is the number of elements from a sublist found in a csv list $\ge n$?} @@ -2495,31 +3299,33 @@ The command \fx{\ltxkeys@getorder} returns in \fx{\ltxkeys@order} the numerical \docsubsection(sec:list-normalization){List normalization} -\start+{newmacro}[\ltxkeys@commanormalize,\ltxkeys@kvnormalize] -\ltxkeys@commanormalize{|A(list)}|A(cmd) -\ltxkeys@commanormalizeset{{|A(list-1)}|A(cmd-1),...,{|A(list-n)}|A(cmd-n)} -\ltxkeys@kvnormalize{|A(list)}|A(cmd) -\ltxkeys@kvnormalizeset{{|A(list-1)}|A(cmd-1),...,{|A(list-n)}|A(cmd-n)} +\start+{newmacro}[\ltxkeyscommanormalize,\ltxkeyskvnormalize] +\ltxkeyscommanormalize{|A(list)}|A(cmd) +\ltxkeyscommanormalizeset{{|A(list-1)}|A(cmd-1),...,{|A(list-n)}|A(cmd-n)} +\ltxkeyskvnormalize{|A(list)}|A(cmd) +\ltxkeyskvnormalizeset{{|A(list-1)}|A(cmd-1),...,{|A(list-n)}|A(cmd-n)} \finish{newmacro} -\fxim*{\ltxkeys@commanormalize,\ltxkeys@commanormalizeset, - \ltxkeys@kvnormalize,\ltxkeys@kvnormalizeset} +\fxim*{\ltxkeyscommanormalize,\ltxkeyscommanormalizeset, + \ltxkeyskvnormalize,\ltxkeyskvnormalizeset} + +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. -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{\ltxkeys@kvnormalize}, \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{\ltxkeys@kvnormalize} 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. \docsubsection(sec:listparse){Parsing arbitrary csv or kv list} -\start{newmacro}[\ltxkeys@parse] -\ltxkeys@parse|A(flag)[|A(parser)]{|A(list)} -\ltxkeys@parse|*|A(flag)[|A(parser)]{|A(listcmd)} +\start{newmacro}[\ltxkeyslistparse] +\ltxkeyslistparse|A(flag)[|A(parser)]{|A(list)} +\ltxkeyslistparse|*|A(flag)[|A(parser)]{|A(listcmd)} \finish{newmacro} -\fxim*{\ltxkeys@parse} +\fxim*{\ltxkeyslistparse} -The unexpandable command \fx{\ltxkeys@parse} is the list processor for the \pkg'{ltxkeys}. It can process both arbitrary \ang{parser}-separated lists and \keyval pairs. 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{\ltxkeys@parse} loops over the given \ang{parser}-separated \ang{list} and execute the user-defined, one-parameter command \fx{\ltxkeys@do} 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{\ltxkeys@parse} will expand \ang{listcmd} once before commencing the loop. +The unexpandable command \fx{\ltxkeyslistparse} 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{\ltxkeyslistparse} 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{\ltxkeyslistparse} 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{\ltxkeyslistparse} will expand \ang{listcmd} once before commencing the loop. \begingroup \small \begin{tabularx}{\linewidth}{|p{1cm}|X|} -\caption{Flags for command \fx{\ltxkeys@parse}\label{tab:parser-flags}}\\\hline +\caption{Flags for command \ltsprotectedtokens{\fx{\ltxkeyslistparse}} + \label{tab:parser-flags}}\\\hline \rowcolor{pink} \bfseries Flag &\bfseries Meaning\\\hline \endfirsthead @@ -2531,102 +3337,66 @@ The unexpandable command \fx{\ltxkeys@parse} is the list processor for the \pkg' \endfoot \hline \endlastfoot -$0$ & \ang{list} is assumed to be an ordinary list (\ie, not a list of \keyval pairs); it isn't normalized by \fx{\ltxkeys@parse} prior to parsing. \\\hline -$1$ & \ang{list} is assumed to be an ordinary list (\ie, not a list of \keyval pairs); it is normalized by \fx{\ltxkeys@parse} prior to parsing. \\\hline -$2$ & \ang{list} is assumed to be a list of \keyval pairs; it isn't normalized by \fx{\ltxkeys@parse} prior to parsing. \\\hline -$3$ & \ang{list} is assumed to be a list of \keyval pairs; it is normalized by \fx{\ltxkeys@parse} prior to parsing. +$0$ & \ang{list} is assumed to be an ordinary list (\ie, not a list of \keyval pairs); it isn't normalized by \fx{\ltxkeyslistparse} prior to parsing. \\\hline +$1$ & \ang{list} is assumed to be an ordinary list (\ie, not a list of \keyval pairs); it is normalized by \fx{\ltxkeyslistparse} prior to parsing. \\\hline +$2$ & \ang{list} is assumed to be a list of \keyval pairs; it isn't normalized by the command \fx{\ltxkeyslistparse} prior to parsing. \\\hline +$3$ & \ang{list} is assumed to be a list of \keyval pairs; it is normalized by \fx{\ltxkeyslistparse} prior to parsing. \end{tabularx} \endgroup -Here are some points to note about the list processor \fx{\ltxkeys@parse}: +Here are some points to note about the list processor \fx{\ltxkeyslistparse}: \begin{enum} -\item If an item contains \ang{parser}, it must be wrapped in curly braces when using \fx{\ltxkeys@parse}, 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). -\item White spaces before and after the list separator are always ignored by the normalizer called by \fx{\ltxkeys@parse}. If an item contains \ang{parser} or starts with a space, it must, therefore, be wrapped in curly braces before calling \fx{\ltxkeys@parse}. -\item Since when \ang{flag} is $0$ or $2$ the command \fx{\ltxkeys@parse} 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{\ltxkeys@parse} if the boolean \fx{\ifltxkeys@useempty} is true. You may thus issue the command \fx{\ltxkeys@useemptytrue} before calling \fx{\ltxkeys@parse}. 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{\ifltxkeys@useempty} is false by default. -\item The command \fx{\ltxkeys@parse} can be nested to any level and can be mixed with other looping macros. -\item In the command \fx{\ltxkeys@parse}, it is always possible to break out of the loop prematurely at any level of nesting, simply by issuing the command \fx{\loopbreak}. Breaking an inner loop doesn't affect the continuation of the outer loop, and vice versa. -\item The argument of the one-parameter command \fx{\ltxkeys@do} can be passed to a multi-parameter command, or to a command that expects delimited arguments. +\item If an item contains \ang{parser}, it must be wrapped in curly braces when calling the command \fx{\ltxkeyslistparse}, 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). +\item White spaces before and after the list separator are always ignored by the normalizer called by \fx{\ltxkeyslistparse}. If an item contains \ang{parser} or starts with a space, it must, therefore, be wrapped in curly braces before calling \fx{\ltxkeyslistparse}. +\item Since when \ang{flag} is $0$ or $2$ the command \fx{\ltxkeyslistparse} 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{\ltxkeyslistparse} if the boolean \fx{\ifltxkeys@useempty} is true. You may thus issue \fx{\ltxkeys@useemptytrue} before calling \fx{\ltxkeyslistparse}. 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{\ifltxkeys@useempty} is false by default, and its state is nesting-level dependant. +\item The command \fx{\ltxkeyslistparse} can be nested to any level and can be mixed with other looping macros. +\item In the command \fx{\ltxkeyslistparse}, it is always possible to break out of the loop prematurely at any level of nesting, simply by issuing the command \fx{\ltxkeysbreakloop}, which toggles the boolean \fx{\ifltxkeysbreakloop}\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 dependant. +\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. \end{enum} -\docsubsection(sec:declarelistparser){Expandable list parser} - -\start{newmacro}[\ltxkeys@declarelistparser] -\ltxkeys@declarelistparser|A(iterator){|A(parser)} -\def|A(processor)#1{...#1...} -|A(iterator){|A(list)}|A(processor) -|A(iterator)|!{|A(list)}|A(processor) -\finish{newmacro} -\fxim*{\ltxkeys@declarelistparser} - -Given a parser (or list separator) \ang{parser}, the command \fx{\ltxkeys@declarelistparser} can be used to define an expandable list iterator \ang{iterator}. The item processor \ang{processor} should be a one-parameter macro, which will receive and process each element of \ang{list}. The optional \clsign determines whether or not the processor is actually expanded and executed in the current expansion context. If \redclam is given, the processor is expanded and executed, otherwise it is merely given the elements as argument without expansion. In general, \ang{list} isn't normalized, but is expanded once, before commencing the loop. The list can be normalized by the command \fx{\csv@@normalize} of the \pkg'{catoptions} before looping\footnote{The \pkg'{ltxtools-base} provides the command \ftfx{\ltsdeclarelistparser}, which works similar to the macro \ftfx{\ltxkeys@declarelistparser} but has a dynamic, expandable list normalizer for arbitrary list parsers/separators.}. The following example demonstrates the concept. The user can insert \fx{\listbreak} as an item in the list to break out of the iteration prematurely. - -\start+{example}[\ltxkeys@declarelistparser] -\ltxkeys@declarelistparser\iterator{;} -\def\do#1{#1} -|com(The following example will yield `\x=macro:->\do{a}\do{b}\do{c}':) -\edef\x{\iterator{a;b;c}\do} -|com(The following example will yield `\x=macro:->abc':) -\edef\x{\iterator|!{a;b;c}\do} - -|com(The following example will add `a,b,c' to macro \y:) -\ltxkeys@declarelistparser\doloop{,} -\doloop{a,b,c}{\cptaddtolist\y} -|com(The following example will add `d,e' to macro \y and ignore `f':) -\doloop|!{d,e,\listbreak,f}{\cptaddtolist\y} - -|com(Nesting of the |A(iterator) is possible:) -\ltxkeys@declarelistparser\alistparser{,} -\ltxkeys@declarelistparser\blistparser{;} -\def\@do#1{#1} -\def\do#1{=#1=\blistparser!{x;y;z}\@do} -\edef\x{\alistparser!{a,b,c}\do} -|com(This gives: \x=macro:->=a=xyz=b=xyz=c=xyz) -\finish{example} - - \docsubsection(sec:removeelements){Remove one or all occurrences of elements from a csv list} -\start{newmacro}[\ltxkeys@removeelements] -\ltxkeys@removeelements[|A(parser)]|(|A(nr)|)|A(listcmd){|A(sublist)}{|A(fd)}{|A(nf)} -\ltxkeys@removeelements|*[|A(parser)]|(|A(nr)|)|A(listcmd){|A(sublist)}{|A(fd)}{|A(nf)} +\start{newmacro}[\ltxkeysremoveelements] +\ltxkeysremoveelements[|A(parser)]|(|A(nr)|)|A(listcmd){|A(sublist)}{|A(fd)}{|A(nf)} +\ltxkeysremoveelements|*[|A(parser)]|(|A(nr)|)|A(listcmd){|A(sublist)}{|A(fd)}{|A(nf)} \finish{newmacro} -\fxim*{\ltxkeys@removeelements} +\fxim*{\ltxkeysremoveelements} -The command \fx{\ltxkeys@removeelements} 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{\ltxkeys@removeelements}. The challenge to the user is to remember that the command \fx{\ltxkeys@removeelements} requires these callbacks, which may both be empty. The \stform of \fx{\ltxkeys@removeelements} 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{\ltxkeys@removeelements} is called. Here, \ang{sublist} is simply \ang{parser}-separated. +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. -\start{example}[\ltxkeys@removeelements] +\start{example}[\ltxkeysremoveelements] \def\xx{a;b;c;d;d;e;f;c;d} |com(Remove at most 2 occurrences of `c' and `d' from \xx:) -\ltxkeys@removeelements[;]|(2|)\xx{c;d}{\def\x{done}}{\def\x{nil found}} +\ltxkeysremoveelements[;]|(2|)\xx{c;d}{\def\x{done}}{\def\x{nil found}} |com(Remove all occurrences of `c' and `d' from \xx:) -\ltxkeys@removeelements|*[;]\xx{c;d}{\def\x{done}}{\def\x{nil found}} +\ltxkeysremoveelements|*[;]\xx{c;d}{\def\x{done}}{\def\x{nil found}} \finish{example} \docsubsection(sec:replaceelements){Replace one or all occurrences of elements in a csv list} -\start{newmacro}[\ltxkeys@replaceelements] -\ltxkeys@replaceelements[|A(parser)]|(|A(nr)|)|A(listcmd){|A(sublist)}{|A(fd)}{|A(nf)} -\ltxkeys@replaceelements|*[|A(parser)]|(|A(nr)|)|A(listcmd){|A(sublist)}{|A(fd)}{|A(nf)} +\start{newmacro}[\ltxkeysreplaceelements] +\ltxkeysreplaceelements[|A(parser)]|(|A(nr)|)|A(listcmd){|A(sublist)}{|A(fd)}{|A(nf)} +\ltxkeysreplaceelements|*[|A(parser)]|(|A(nr)|)|A(listcmd){|A(sublist)}{|A(fd)}{|A(nf)} \finish{newmacro} -\fxim*{\ltxkeys@replaceelements} +\fxim*{\ltxkeysreplaceelements} -The command \fx{\ltxkeys@replaceelements} 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{\ltxkeys@replaceelements}. The challenge to the user is to remember that the command \fx{\ltxkeys@replaceelements} requires these callbacks, which may both be empty. The \stform of \fx{\ltxkeys@replaceelements} 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{\ltxkeys@replaceelements} is used. Here, the syntax of \ang{sublist} is as follows: +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: -\start'{macro}[Sublist for \ltxkeys@replaceelements] +\start'{macro}[Sublist for \ltxkeysreplaceelements] {{|A(old-1)}{|A(new-1)}|A(parser)...|A(parser){|A(old-n)}{|A(new-n)}} \finish{macro} where \ang{old-i} is the element to be replaced and \ang{new-i} is its replacement. -\start{example}[\ltxkeys@replaceelements] +\start{example}[\ltxkeysreplaceelements] \def\xx{a;b;c;d;d;e;f;c;d} |com(Replace at most 2 occurrences of `c' and `d' in \xx with `s' and `t',) |com(respectively:) -\ltxkeys@replaceelements[;]|(2|)\xx{c{s};d{t}}{\def\x{done}}{\def\x{nil found}} +\ltxkeysreplaceelements[;]|(2|)\xx{c{s};d{t}}{\def\x{done}}{\def\x{nil found}} |com(Replace all occurrences of `c' and `d' in \xx with `s' and `t':) -\ltxkeys@replaceelements|*[;]\xx{c{s};d{t}}{\def\x{done}}{\def\x{nil found}} +\ltxkeysreplaceelements|*[;]\xx{c{s};d{t}}{\def\x{done}}{\def\x{nil found}} \finish{example} @@ -2634,22 +3404,22 @@ where \ang{old-i} is the element to be replaced and \ang{new-i} is its replaceme 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: -\start+{newmacro}[\ltxkeys@stripNouterbraces, \ltxkeys@stripallouterbraces, etc.] -\ltxkeys@stripNouterbraces|A(nr){|A(token)} -\ltxkeys@stripallouterbraces{|A(token)} -\ltxkeys@stripallouterbracesincs{|A(cmd)} +\start+{newmacro}[\ltxkeysstripNouterbraces, \ltxkeysstripallouterbraces, etc.] +\ltxkeysstripNouterbraces|A(nr){|A(token)} +\ltxkeysstripallouterbraces{|A(token)} +\ltxkeysstripallouterbracesincs{|A(cmd)} \finish{newmacro} -\fxim*{\ltxkeys@stripNouterbraces, - \ltxkeys@stripallouterbraces,\ltxkeys@stripallouterbracesincs} +\fxim*{\ltxkeysstripNouterbraces, + \ltxkeysstripallouterbraces,\ltxkeysstripallouterbracesincs} -The command \fx{\ltxkeys@stripNouterbraces} strips \ang{nr} number of outer braces from \ang{token}. The command \fx{\ltxkeys@stripallouterbraces} strips all outer braces from \ang{token}. The command \fx{\ltxkeys@stripallouterbracesincs} 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. +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. -\start+{example}[\ltxkeys@stripNouterbraces,\ltxkeys@stripallouterbraces, etc.] +\start+{example}[\ltxkeysstripNouterbraces,\ltxkeysstripallouterbraces, etc.] \toks@\expandafter\expandafter\expandafter - {\ltxkeys@stripNouterbraces{2}{{{\y}}}} + {\ltxkeysstripNouterbraces{2}{{{\y}}}} \edef\x{\unexpanded\expandafter\expandafter\expandafter - {\ltxkeys@stripNouterbraces\@m{{{\y}}}}} -\edef\x{\ltxkeys@stripallouterbraces{{{{\y}}}}} + {\ltxkeysstripNouterbraces\@m{{{\y}}}}} +\edef\x{\ltxkeysstripallouterbraces{{{{\y}}}}} \finish{example} @@ -2658,9 +3428,57 @@ The command \fx{\ltxkeys@stripNouterbraces} strips \ang{nr} number of outer brac 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. -\docsubsection(sec:patchingkeymacros){Patching key macros} -Patching the macro of an existing key, instead of redefining the key. \pkg'{etoolbox}'s \hx{\patchcmd} doesn't permit the patching of commands with nested parameters. But since key macros may have nested parameters, a new patching scheme is to be first explored. +\docsection(sec:add-patch-keycode){Adding to and patching key macros} + +\subdocsection(sec:addkeycode){Adding to key macros} +% \krdaddkeycode, \krdappendkeycode, \krdprependkeycode + + +\subdocsection(sec:patchkeycode){Patching key macros} +% \krdpatchkeycode, \krdgpatchkeycode + +Sometimes you may want to modify the macro of an existing key. For some reasons, redefining the key may not be the best option, besides being uneconomical. + +The following \fx{\krdpatchkeycode} command and use syntax can be utilized to patch/modify existing key macros. In rare circumstances one may wish to modify an subsisting key macro, especially one defined in an existing package, without redefining the key afresh. Key macros are intrinsically parameterized functions and \latex kernel's \fx{\g@addto@macro} can't be used to patch parameterized functions. + +\start{newmacro}[\krdpatchkeycode] +\krdpatchkeycode|*|![|nang(keyprefixes)]{|nang(families)}{ + |nang(key-1) {|nang(search-1)} {|nang(replace-1)} ; + |nang(key-2) {|nang(search-2)} {|nang(replace-2)} ; + ... + |nang(key-n) {|nang(search-n)} {|nang(replace-n)} +}{% + |nang(fallback-s) +}{% + |nang(fallback-f) +} +\finish{newmacro} +\fxim*{\krdpatchkeycode} + +Here, \ang{keyprefixes} and \ang{families} are comma-separated lists of key prefixes and families; \ang{key-1} to \ang{key-n} are key names; \ang{search-1} to \ang{search-n} are the search patterns, and the quantities \ang{replace-1} to \ang{replace-n} the corresponding replacement texts. \ang{fallback-s} and \ang{fallback-f} are the actions that should be taken if the patching succeeds or fails for any of the existing keys. \fx{\krdpatchkeycode} loops over the given key prefixes and families to find the listed keys. If a key can't be located (in terms of being previously defined), it is ignored and a warning message is logged (if the package option \fx{verbose} is enabled). Within the \ang{fallback-s} and \ang{fallback-f} blocks, you can use \fx{\krd@currkey}, \fx{\curr@fam}, and \fx{\krd@pref} to refer to the current key name, family and prefix (see example below). The \clsign instructs \fx{\krdpatchkeycode} to globalize the outcome; the \stsign is explained below. + +Also, within the search-and-replace block you can use \fx{#1} to refer to the parameter of the key macro, which ordinarily corresponds to the value of the current key. There is no need to double the parameter character. But if you're introducing a new parameterized command within this block, you would need to double the parameter character. Normally, the command \fx{\patchcmd} of \cref{sec:cmd-patch} (and hence \fx{\krdpatchkeycode}) doesn't allow nested commands, and hence no doubling of the parameter character in the replacement text. If you want to nest commands or double the parameter character in the replacement text, you need to use the \stform of \fx{\patchcmd} or \fx{\krdpatchkeycode} (see example below). + +White spaces between the key name and the search pattern are ignored within the block of key names and search and replacement patterns. You can insert \fx{\ltxkeyslistbreak} within this block to prematurely break out of the loop. The remaining elements of the list will be saved in \fx{\ListRemainder} (see \cref{sec:list-process}). + +The default list parser in \fx{\krdpatchkeycode} is the semicolon (\fx{;}). This can be changed by using \fx{\krdDeclareKeyPatchParser}, which takes only one argument (the list parser). + +\start{example}[\krdpatchkeycode] +\declare@ordkey[KV]{fam}{keya}[value]{\def\x##1{x##1x}} +\declare@boolkey[KX]{fax}[mp@]{keyb}[true]{\def\y{#1}} + +\krdpatchkeycode|*|![KV,KX]{fam,fax}{% + keya {\def\x##1{x##1x}} {\def\X##1{XX##1XX}}, + keyb {\def\y{y#1y}} {\def\Y{YY#1YY}} +}{% + \wlog{Patching of `\krdcurrentkeymacro' succeeded}% +}{% + \wlog{Patching of `\krdcurrentkeymacro' failed}% +} +\show\KV@fam@keya +\finish{example} + \docsubsection(sec:changedependantkeys) @@ -2676,9 +3494,10 @@ Patching the macro of an existing key, instead of redefining the key. \pkg'{etoo Here, \ang{paren} is the parent key of dependants keys; \ang{deps} is the full specification of new or existing dependant keys (as in \sref{sec:stylekeys}), with their default values and callbacks; \ang{olddeps} are the old dependants to replace with \ang{newdeps}. This would require patching macros of the form \jpreffamkey{dependants}, which might have nested parametered-commands. -\docsubsection(sec:toggle+switchkeys){Toggle and switch keys} -Introduce toggle keys and switch keys, but in practice who needs them? I would really need user views before implementing this feature. Toggles and switches, found in, \eg, the \pkg'{catoptions}, 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. However, toggles and switches haven't yet made it into the popular imagination of \tex users. +\docsubsection(sec:togglekeys){Toggle keys} + +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. \docsection(sec:version-hist){Version history} @@ -2701,7 +3520,7 @@ The following change history highlights significant changes that affect user uti \newpage \ltsindexpreamble{Index numbers refer to page numbers.} \ltsindexpreambleformat{\centering} -\ltsindexcolumns\tw@ +\ltsindexcolumns=2 \printindex \end{document} |