diff options
Diffstat (limited to 'macros/latex/contrib/keyval2e')
-rw-r--r-- | macros/latex/contrib/keyval2e/README | 45 | ||||
-rw-r--r-- | macros/latex/contrib/keyval2e/keyval2e-examples.pdf | bin | 0 -> 46126 bytes | |||
-rw-r--r-- | macros/latex/contrib/keyval2e/keyval2e-examples.tex | 67 | ||||
-rw-r--r-- | macros/latex/contrib/keyval2e/keyval2e-guide.pdf | bin | 0 -> 297995 bytes | |||
-rw-r--r-- | macros/latex/contrib/keyval2e/keyval2e-guide.tex | 225 | ||||
-rw-r--r-- | macros/latex/contrib/keyval2e/keyval2e.sty | 269 |
6 files changed, 606 insertions, 0 deletions
diff --git a/macros/latex/contrib/keyval2e/README b/macros/latex/contrib/keyval2e/README new file mode 100644 index 0000000000..93c794d5d1 --- /dev/null +++ b/macros/latex/contrib/keyval2e/README @@ -0,0 +1,45 @@ +This is the README file for the keyval2e package. + +VERSION + +Version 0.0.2, August 2011 + +SUMMARY + +The keyval2e package provides lightweight and robust facilities for +creating and managing keys. Its machinery isn't as extensive as +that of, eg, ltxkeys package, but it is equally robust. Ease of +use and speed of processing are the two main motives of this package. +Some, indeed many, applications of the key-value syntax (while they +call for robustness) don't require the full armor of key-value +processing as found in, eg, the ltxkeys package. + +Ordinary, boolean, and choice keys can be created using only +one command (\kve@definekeys). Keys can be initialized (with +the command \kve@setdefaults) as soon as they are created or later. And +in any run the default values of keys can be used to set keys that +have no current values. The latter task is accomplished by the +command \kve@setafterdefaults, meaning 'set keys with the current +values after those without current values have been initialized/set +with their default values'. Normally, keys are set with the +re-entrant command \kve@setkeys. + +LICENSE + +Copyright (c) 2011 Ahmed Musa. + +This software is author-maintained. Permission is granted to copy, +distribute and/or modify this software under the terms of the +LaTeX Project Public License, version 1.3 or higher. This software +is provided 'as it is', without warranty of any kind, either +expressed or implied, including, but not limited to, the implied +warranties of merchantability and fitness for any particular purpose. + +RELATED PACKAGES + +keyval.sty, xkeyval.sty, ltxkeys.sty + +AUTHOR + +Ahmed Musa (amusa22@gmail.com) + diff --git a/macros/latex/contrib/keyval2e/keyval2e-examples.pdf b/macros/latex/contrib/keyval2e/keyval2e-examples.pdf Binary files differnew file mode 100644 index 0000000000..62ecefd351 --- /dev/null +++ b/macros/latex/contrib/keyval2e/keyval2e-examples.pdf diff --git a/macros/latex/contrib/keyval2e/keyval2e-examples.tex b/macros/latex/contrib/keyval2e/keyval2e-examples.tex new file mode 100644 index 0000000000..a13274b3e2 --- /dev/null +++ b/macros/latex/contrib/keyval2e/keyval2e-examples.tex @@ -0,0 +1,67 @@ +% keyval2e.sty examples, version 0.0.2, August 2011 + +\documentclass{article} +\usepackage{keyval2e,color} +\makeatletter +\kve@definekeys[KV]{fam}[mp@]{% + keyone/+/\ifstrcmpTF{#1}{+}{\def\userinput{#1}}{\def\userinput{not `+'}}, + keytwo/+, + keythree/+, + keyfour/+, + keyfive/true/\ifmp@keyfive\def\x{keyfive is 'true'}\else + \def\x{keyfive is 'false'}\fi, + keysix/true +} + +% \show\ifmp@keyfive + +% The starred variant of \kve@definekeys gives error for the +% already defined key 'keyone': +% \kve@definekeys*[KV]{fam}[mp@]{keyone/+} + +% Changing the family and macro-prefix makes 'keyone' definable again: +\kve@definekeys*[KV]{famx}[mpx@]{keyone/+} + +\def\fourplus{+,+,+,+} +\newcommand*\putmany[2][*]{% + \begingroup + \toks@{}\@tempcnta\z@ + \loop + \advance\@tempcnta\@ne + \toks@\expandafter{\the\toks@#1}% + \ifnum\@tempcnta<#2\relax + \repeat + \expandafter\endgroup\the\toks@ +} +\newcommand{\testa}[2]{% + \kve@setafterdefaults[KV]{fam}{#2}% + \edef\tempa{\mp@keyone,\mp@keytwo,\mp@keythree,\mp@keyfour}% + \noindent + \vbox{% + \hsize\dimexpr1.1\hsize\relax\leftskip=-1.5cm + \def\redstar{\textcolor{red}{*}}\ttfamily + Test #1: \redstar\space\texttt{\tempa}\space\redstar\space + \ifxTF\tempa\fourplus + {All values are defaults\putmany[\space]{2}}% + {At least one value is set}% + \@spaces\textcolor{red}{||} keyone's value: \userinput + }% +} +\newcommand{\testb}[2][]{\testa{#2}{#1}} + +\begin{document} + +\title{The \texttt{\color{blue}keyval2e} Package \\Examples} +\maketitle + +\testa{Aa}{}\\ +\testa{Ba}{keyone=+, keythree=+}\\ +\testa{Ca}{keytwo=+, keythree=a}\\ +\testa{Da}{keyone=b, keythree=a,keyfour=+}\\ + +\testb{Ab}\\ +\testb[keyone=+, keythree=+]{Bb}\\ +\testb[keytwo=+, keythree=a]{Cb}\\ +\testb[keyone=b, keytwo=+,keythree=a]{Db}\\ + +\end{document}
\ No newline at end of file diff --git a/macros/latex/contrib/keyval2e/keyval2e-guide.pdf b/macros/latex/contrib/keyval2e/keyval2e-guide.pdf Binary files differnew file mode 100644 index 0000000000..61a4720964 --- /dev/null +++ b/macros/latex/contrib/keyval2e/keyval2e-guide.pdf diff --git a/macros/latex/contrib/keyval2e/keyval2e-guide.tex b/macros/latex/contrib/keyval2e/keyval2e-guide.tex new file mode 100644 index 0000000000..99883c7d15 --- /dev/null +++ b/macros/latex/contrib/keyval2e/keyval2e-guide.tex @@ -0,0 +1,225 @@ +\documentclass[ + use-a4-paper, + use-10pt-font, + final-version, + use-UK-English, + fancy-section-headings, + frame-section-numbers, + para-abstract-style, + input-config-file, + no-hyperref-messages +]{amltxdoc} + +\hfuzz1pt +\makeatletter +\WrapQuotes +\makeindex + +\begin{document} + +\begin{frontmatter} +\title{The \texttt{\color{blue}keyval2e} Package\titleref{t1}} +\titlenotes[t1]{% + The package is available at \url{\titleurltext}. This user manual + corresponds to version~0.0.2. +} +\subtitle{Robust and fast key parser} +\titleurl{http://www.ctan.org/tex-archive/macros/latex/contrib/keyval2e/} +\author{Ahmed Musa \Email{amusa22@gmail.com}\\Preston, Lancashire, UK} + +\end{frontmatter} + +\begin{xwmshade}[fillcolor=white,framecolor=orange,framerule=1pt,framesep=2pt, + width=1.0\hsize]\tableofcontents +\end{xwmshade} + + +\docsection(sec:introduction){Introduction} + +\lletter{T}{he \pkg'{keyval2e}} provides lightweight and robust facilities for creating and managing keys. Its machinery isn't as extensive as that of, \eg, \pkg'{ltxkeys} but it is equally robust. Ease of use and speed of processing are the two main motives of this package. Some, indeed many, applications of the key-value syntax (while they call for robustness) don't require the full armor of key-value processing as found in, \eg, the \pkg'{ltxkeys}. This package was prompted by a subscriber's post on \comptexttex in August 2011. + +In the \pkg'{keyval2e}, command, boolean, and choice keys can be created using only one command (\fx{\kve@definekeys}). Keys can be initialized with their default values (with the command \fx{\kve@setdefaults}) as soon as they are created, or at any time. And in any run the default values of keys can be used to set keys that have no current values. The latter task is accomplished by the command \fx{\kve@setafterdefaults}, meaning \quoted{set keys with their current user-supplied values after the absent keys (\ie, those without current values) have been initialized/set with their default values}. + +Keys can be set with the re-entrant command \fx{\kve@setkeys}, but this will not automatically set up the absent keys (\ie, keys not submitted to the command in its current run) with their default values. To set keys up with their default values, the user has to call \fx{\kve@setdefaults} or \fx{\kve@setafterdefaults}. + +The \pkg'{keyval2e} has no provision for processing package or class options. See the \pkg'{ltxkeys} for this service. I have seen users who require the services of keys only in documents, and not in package or class files. And some package authors still use \latex's native option processing schemes. For those authors, the \pkg'{keyval2e} may be used to process keys (but not options) in package and class files. Since the \pkg'{catoptions} is loaded by the \pkg'{keyval2e} and the former has a robust and extensive options parsing scheme, it may be used for the options processing requirements of the user. + +The \pkg'{keyval2e} provides handy tools for creating commands based on the infrastructure of keys. See the file \file{keyval2e-examples} for examples. The so-called \quoted{key commands} (see \pkg'{keycommand, skeycommand}) can be created rather easily with the facilities of this package. + +The \pkg'{keyval} provides a simple and widely used interface, but it is not robust, in the sense that it strips off outer curly braces in key values. Also, it has no means to automatically call up default key values after the keys have been defined. Moreover, it automatically redefines existing keys. + + +\docsection{Package options} + +The \pkg'{keyval2e} currently has no options. + + +\docsection{User commands} + +As previously mentioned in \amref{sec:introduction}, the \pkg'{keyval2e} can be used to directly define only command and boolean keys. Choice keys can, however, be created indirectly as command keys by using the \fx{\kve@checkchoice} command (see \amref{sec:utilities}). For the user, the only difference between command and ordinary keys is that command keys define macros to hold the user input, making command keys more attractive than ordinary keys. + +The only key-defining command in this package is \fx{\kve@definekeys}. This command distinguishes a boolean key from command keys by the default value of the boolean key. Therefore, all boolean keys must have default values in the set \fnz*{true,false}, otherwise they will be treated as command keys. Command keys may have no default values and no callbacks. + +\start+{newmacro}[\kve@definekeys, \kve@setkeys, etc] +\kve@definekeys[|A(pref)]{|A(fam)}[|A(mp)]{% + |A(key-1)/|A(dft-1)/|A(cbk-1), + ..., + |A(key-n)/|A(dft-n)/|A(cbk-n) +} + +\kve@definekeys|*[|A(pref)]{|A(fam)}[|A(mp)]{% + |A(key-1)/|A(dft-1)/|A(cbk-1), + ..., + |A(key-n)/|A(dft-n)/|A(cbk-n) +} + +\kve@setkeys[|A(pref)]{|A(fam)}[|A(na)]{|A(keyval)} + +\kve@setdefaults[|A(pref)]{|A(fam)}[|A(na)] + +\kve@setafterdefaults[|A(pref)]{|A(fam)}[|A(na)]{|A(keyval)} +\finish{newmacro} +\fxim*{\kve@definekeys,\kve@setkeys,\kve@setdefaults,\kve@setafterdefaults} + +Here, \ang{pref} is the optional key prefix (its default is \fx{KV}), \ang{fam} is the mandatory family, \ang{mp} is the key-value-holding macro prefix (its default is \fx{kvmp@}), \ang{dft-i} is the default value of key \quotedfx{i}, \ang{cbk-i} is the callback (\ie, the function that will be executed when the key is set) of key \quotedfx{i}, and \ang{keyal} is a list of \keyval pairs. + +\ang{na} is a comma-separated list of keys that should be ignored, ie, not set in the current run of setting keys\footnote{When setting keys, undefined keys are reported by the \pkg'{keyval2e} as undefined and are not saved as \quoted{remaining keys}, unlike in the \pkg'{ltxkeys}. Moreover, there are no \quoted{undefined key handlers} and no \quoted{handled keys} in this package. Please see the \pkg'{ltxkeys} for these features.}. \mpkey will hold the current value of \ang{key}. The key macro (\ie, the macro that holds the key's callback) is always \preffamkey. + +The \stform of the command \fx{\kve@definekeys} will define only definable keys, in the sense of \latex's \hx{\newcommand}. In that case the commands \mpkey must also be unique, \ie, not previously defined. The plain form \fx{\kve@definekeys} will always define the key, whether or not the key already exists; existing keys will thus be overwritten in this case. + +You can use \quotedfx{#1} in \ang{cbk} to access the user-supplied value of the current key. Also the macros \ffx'{\currpref, \currfam, \currkey, \currval, \currkeyval} are always available when setting keys and may be called in \ang{cbk} at key definition time. + +\Note The list parser for the command \fx{\kve@definekeys} is \qcomma. Hence, if you have literal comma in \ang{cbk}, the \ang{cbk} has to be enclosed in curly braces. Leading and trailing spaces in the elements are removed in the internal processing. Explicit spaces (\ie, those needed by the key user) will therefore need to be wrapped in curly braces. + +The command \fx{\kve@setdefaults} will set all the keys in the given family \ang{fam} and prefix \ang{pref} with their default values. All boolean keys (\ie, those with a default in the set \fnz*{true,false}) will be initialized with a default value of \fx{false}. This is to avoid premature toggling of the state of such keys. The command \fxis{\kve@setwithdefaults}{\kve@setdefaults} is an alias for \fx{\kve@setdefaults}. + +\Note After the keys have been defined, they are automatically set with their default values using the command \fx{\kve@setdefaults}. This provides default definitions for immediate use. + +The command \fx{\kve@setafterdefaults} will set the given \keyval pairs after initializing to default values all those keys (in the given family and prefix) that are not listed in the accompanying \keyval list. This provides a mechanism for (re)initialing to default values those keys that don't have values in \keyval. This type of (re)initialization is often required in the deployment of keys---since the immediate past user values of the keys may no longer be valid. It is useful to have a handy way of accomplishing this task semi-automatically. + + +\docsubsection(sec:utilities){Utility macros} + +The following macros are utilities. + +\start{newmacro}[\kve@checkchoice] +\kve@checkchoice{|A(teststring)}{|A(nominations)}{|A(nomatch)} +\finish{newmacro} +\fxim*{\kve@checkchoice} + +The expandable command \fx{\kve@checkchoice} can be used to create choice keys as command keys. The \ang{nominations} have the syntax + +\start'{macro}[Nominations and callbacks] +|A(nom-1)|R(:)|A(cbk-1),...,|A(nom-n)|R(:)|A(cbk-n) +\finish{macro} + +Here, please note the \qcolon, which separates \ang{nom} from \ang{cbk}. \ang{cbk-i} will be executed if \ang{nom-i} matches \ang{teststring}. The first match found takes priority over subsequent matches. The fallback \ang{nomatch} will be executed if \ang{teststring} doesn't match any of the \ang{nom}'s. + +\start{newmacro}[\kve@checkbool] +\kve@checkbool{|A(val)}{|A(true)}{|A(false)} +\finish{newmacro} +\fxim*{\kve@checkbool} + +This checks if \ang{val} is an admissible value of a boolean, namely, if it is in the set \fnz*{true,false}. If \ang{val} is valid, the text \ang{true} will be executed; otherwise \ang{false} will be executed. + +\Note The user-supplied values of all boolean keys are automatically checked by this command. Hence, the user doesn't have to call this command repeatedly to confirm the validity of values of boolean keys. + +\start{newmacro}[\kve@keyvalerr] +\kve@keyvalerr +\finish{newmacro} +\fxim*{\kve@keyvalerr} + +This is a parameterless command that uses \ffx'{\currkey,\currval} internally. It simply generates an error to indicate that the current value of a key is invalid. It will indicate the key name and the truncated version of the key value that is invalid. + + +\docsection(sec:examples){Examples} + +\start{example}[\kve@definekeys] +|R(\kve@definekeys)[KV]{fam}[mp@]{% + |com(keya and keyb are boolean keys. They will call \kve@checkbool) + |com(internally to check the user input for them. keya has no callback:) + keya/true, + keyb/false/\ifmp@keyb\def\x{found}\else\def\x{not found}\fi, + |com(keyc is a choice key:) + keyc/left/|R(\kve@checkchoice){#1}{left:\let\x\flushleft, + right:\let\x\flushright}{|R(\kve@keyvalerr)}, + |com(keyd has no default. Therefore, it can't be set without a user value.) + |com(In |fx(\kve@setdefaults) we set it with a default value of `empty', but) + |com(its user must always provide a value for it:) + keyd, + |com(keyone has an empty default value. This doesn't mean `no default':) + keyone//\ifnullTF{#1}{\def\x{empty}}{\def\x{#1}}, + |com(keytwo has no callback:) + keytwo/+, + |com(keythree has a braced default value:) + keythree/{left}/\def\y##1{`para-scientific gobbledegook' ##1}, + |com(keyfour sets keyone |(see |amref(nte:reentrance)|):) + keyfour/left/|R(\kve@setkeys)[KV]{fam}{keyone=#1}, +} +\finish{example} + +Remember that after the keys have been defined, they are automatically set with their default values using the command \fx{\kve@setdefaults}. + +\begin{note} +\label{nte:reentrance} +The type of re-entrance staged by key \fx{keyfour} above should in general be done with care, otherwise you could end up with infinite re-entrance. Therefore, the package sets a re-entrance limit of 4, to alert the user to the probability that an infinite loop has been created by him in using \fx{\kve@setkeys}. In the unlikely event that you need to exceed this limit, then please turn to the \pkg'{ltxkeys}. +\end{note} + +The following command says \quoted{set the given keys with their current values, after the absent keys of the given family and prefix have been set up with their default values}. Keys with current values will not be set with their default values: + +\start{example}[\kve@setafterdefaults] +\kve@setafterdefaults[KV]{fam}{keyone=+,keytwo=abc,keythree=+,keyfour=xax} +\finish{example} + +Please see \file{keyval2e-examples} for the fuller version of the following example: + +\start+{example}[Creating a key command] +\documentclass{minimal} +\usepackage{keyval2e} +\makeatletter +\kve@definekeys|*[KV]{fam}[mp@]{% + keyone/+, + keytwo/+, + keythree/+, + keyfour/+ +} +\def\fourplus{+,+,+,+} +\newcommand{\test}[2]{% + |R(\kve@setafterdefaults)[KV]{fam}{#2}% + \edef\tempa{\mp@keyone,\mp@keytwo,\mp@keythree,\mp@keyfour}% + Test #1: *\texttt{\tempa}*% + \ifxTF\tempa\fourplus{All values are defaults}{At least one value is set}% +} +\begin{document} +\ttfamily\noindent +\test{A}{}\\ +\test{B}{keythree=+}\\ +\test{C}{keythree=a}\\ +\end{document} +\finish{example} + + +\docsection(sec:version-hist){Version history} + +The \stsign on the right-hand side of the following lists means the subject features in the package but is not reflected anywhere in this user guide. + +\begin{versionhist} + \begin{version}{0.0.2}{2011/08/22} + \item Automatically call \fx{\kve@checkbool} when setting boolean keys \vsecref{sec:utilities} + \item Raise error for keys that have no user input and no default value \vsecref{sec:examples} + \end{version} + \begin{version}{0.0.1a}{2011/08/14} + \item Completed the user guide\vsecref* + \end{version} + \begin{version}{0.0.1}{2011/08/13} + \item First public release\vsecref* + \end{version} +\end{versionhist} + +\newpage +\indexpreamble{Index numbers refer to page numbers.} +\indexpreambleformat{\centering} +\indexcolumns\tw@ +\printindex + +\end{document}
\ No newline at end of file diff --git a/macros/latex/contrib/keyval2e/keyval2e.sty b/macros/latex/contrib/keyval2e/keyval2e.sty new file mode 100644 index 0000000000..6d4769568e --- /dev/null +++ b/macros/latex/contrib/keyval2e/keyval2e.sty @@ -0,0 +1,269 @@ +%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++% +% % +% This is file 'keyval2e.sty', version 0.0.2, August 2011 % +% % +% This package and accompanying files may be distributed and/or % +% modified under the conditions of the LaTeX Project Public License, % +% either version 1.3 of this license or any later version. The latest % +% version of this license is in http://www.latex-project.org/lppl.txt % +% and version 1.3 or later is part of all distributions of LaTeX % +% version 2005/12/01 or later. % +% % +% The LPPL maintenance status of this software is 'author-maintained'. % +% % +% This software is provided 'as it is', without warranty of any kind, % +% either expressed or implied, including, but not limited to, the % +% implied warranties of merchantability and fitness for a particular % +% purpose. % +% % +% Copyright (c) 2011 Ahmed Musa (a.musa@rocketmail.com). % +% % +%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++% + +\@ifpackageloaded{catoptions}{}{\RequirePackage{catoptions}[2011/07/20]} +\UseNormalCatcodes +\StyleFilePurpose{Lightweight and robust key-value parser (AM)} +\StyleFileRCSInfo +$Id: keyval2e.sty,v 0.0.2 2011/08/24 09:00:00 Ahmed Musa Exp $ +\ProvidesPackage{keyval2e}[\StyleFileInfo] +\NeedsTeXFormat{LaTeX2e}[1996/12/01] +\SetStyleFileMessages[kve@]{info}{warn}{err} +\newvariables{count}[kve@]{keydepth}[0] +\robust@def*\kve@parse{\cpt@teststopt\kve@parse@a,} +\robust@def*\kve@parse@a[#1]#2#3{% + \kve@ifblank#2\doblank\gobble@to@relax + \cpt@stchoose{cpt@st}{#2}\reserved@e\kve@parse + \pushfunctions\kve@parse + {\ifloopbreak,\kve@do,\kve@act}\cpt@csvdepth + \cpt@sttrue\cpt@csvnormalize[#1]\reserved@e + \def\kve@act##1{#3}% + \def\kve@do##1#1{% + \edef\reserved@a{\unexpanded\expandafter{\@gobble##1}}% + \ifxTF\reserved@a\cpt@nnil{}{% + \expandafter\kve@act\expandafter{\reserved@a}\relax + \@nameuse{@\ifloopbreak second\else first\fi oftwo}% + {\kve@do.}{\gobble@to@sentinel\cpt@nil#1}% + }% + }% + \loopbreakfalse + \expandafter\kve@do\expandafter.\reserved@e#1\cpt@nil#1% + \popfunctions\kve@parse\cpt@csvdepth\cpt@relax +} +\robust@def*\kve@ifblank#1\doblank#2{% + \ifcat$\detokenize\expandafter{\@gobble#1.}$% + \expandafter\@iden + \else + \expandafter\@gobble + \fi + {#2}% +} +% \kve@definekeys[<pref>]{<fam>}[<mp>]{keya/defa/callback,...} +\robust@def*\kve@definekeys{% + \begingroup\endlinechar\m@one + \cpt@teststopt\kve@d@finekeys{KV}% +} +\newletcs\kve@definekey\kve@definekeys +\robust@def*\kve@d@finekeys[#1]#2{% + \cpt@testopt{\kve@d@f@nekeys{#1}{#2}}{kvmp@}% +} +\robust@def*\kve@d@f@nekeys#1#2[#3]#4{% + \gletcs\ifkve@tempsw\ifcpt@st + \endgroup + \kve@ifblank#4\doblank\gobble@to@relax + \def\kve@d@f@n@keys##1{% + \ifkve@tempsw + \ifcsndefinable{#1@#2@\currkey}{% + \ifcsndefinable{#3\currkey}{}% + }% + \fi + \begingroup + \def\kve@true{true}\def\kve@false{false}% + \expandafter\endgroup\ifcase\ifx\currval\kve@true0\else + \ifx\currval\kve@false0\else1\fi\fi\relax + \expandafter\newif\csname if#3\currkey\endcsname + \@namedef{#1@#2@\currkey}####1{% + \kve@checkbool{####1}{% + \usename{#3\currkey####1}% + \@namedef{#3\currkey}{####1}##1\relax + }{% + \kve@keyvalerr + }% + }% + \else + \@namedef{#1@#2@\currkey}####1{% + \@namedef{#3\currkey}{####1}##1\relax + }% + \fi + }% + \@namedef{#1@#2@initialkeyvals}{}% + \def\kve@tempc{^?}% + \def\kve@splita##1/{% + \edef\currkey{\cpttrimspaces{##1}}% + \kve@splitb.% + }% + \def\kve@splitb##1/##2/##3\kve@nil{% + \edef\currval{\expandafter\cpttrimspaces\expandafter{\@gobble##1}}% + \ifx\currval\kve@tempc + \def\currval{}% + \else + \expandafter\edef\csname#1@#2@\currkey @default\endcsname{% + \cptmakecs{#1@#2@\currkey}{\expandcsonce\currval}% + }% + \fi + \edef\kve@tempb{\unexpanded{##2}}% + \ifx\kve@tempb\kve@tempc\def\kve@tempb{}\fi + \expandafter\kve@d@f@n@keys\expandafter{\kve@tempb}% + \letcstocsn\kve@tempa{#1@#2@initialkeyvals}% + \expandafter\edef\csname#1@#2@initialkeyvals\endcsname{% + \cptliststack,\kve@tempa\currkey=% + \oifstrcmpTF\currval{true}{false}{\expandcsonce\currval}% + }% + }% + \kve@parse{#4}{\kve@splita##1/^?/^?/\kve@nil}% + \kve@setdefaults[#1]{#2}[]\cpt@relax +} +% \kve@setkeys[pref]{<fam>}[na]{<keyval>} +\robust@def*\kve@setkeys{\cpt@testopt\kve@setkeys@a{KV}} +\robust@def*\kve@setkeys@a[#1]#2{\cpt@testopt{\kve@setkeys@b{#1}{#2}}{}} +\robust@def*\kve@setkeys@b#1#2[#3]#4{% + \kve@ifblank#4\doblank\gobble@to@relax + \ifnum\kve@keydepth>4\relax + \kve@err{Maximum re-entrance limit of 4 exceeded + \MsgBrk by \string\kve@setkeys}\@ehc + \fi + \pushfunctions\kve@setkeys{\currpref,\currfam,\currkey,% + \currval,\currkeyval}\kve@keydepth + \def\currpref{#1}\def\currfam{#2}% + \edef\kve@na{\cptcommanormalize{#3}}% + \def\kve@splita##1={% + \def\currkey{##1}% + \kve@splitb.% + }% + \def\kve@splitb##1=##2\kve@nil{% + \cpt@swafalse + \kve@ifblank##2\doblank{% + \ifcsndefTF{#1@#2@\currkey @default}{% + \cpt@swatrue + }{% + \kve@err{No user value and no default value + \MsgBrk for key '\currkey'}\@ehc + }% + }% + \edef\currval{\unexpanded\expandafter{\@gobble##1}}% + \edef\currkeyval{\expandcsonce\currkey=\expandcsonce\currval}% + \xifinsetTF{,\cptoxdetok\currkey,}{,\cptoxdetok\kve@na,} + {}{\kve@setkeys@c{#1}{#2}}% + }% + \cpt@stfalse\cpt@kvnormalize[,]{#4}% + \kve@parse*\normalized@list{\kve@splita##1==\kve@nil}% + \popfunctions\kve@setkeys\kve@keydepth + \cpt@relax +} +\robust@def*\kve@setkeys@c#1#2{% + \ifcsndefTF{#1@#2@\currkey}{% + \ifcpt@swa + \begingroup + \@namedef{#1@#2@\currkey}##1{\toks@{\def\currval{##1}}}% + \csname#1@#2@\currkey @default\endcsname + \expandafter\endgroup\the\toks@ + \fi + \csname#1@#2@\currkey\expandafter + \endcsname\expandafter{\currval}\relax + }{% + \kve@err{Key '\currkey' not defined} + {Key '\currpref,\currfam,\currkey' is undefined}% + }% +} +\robust@def*\kve@getkeynames#1{% + \def\kve@keynames{}% + \kve@ifblank#1\doblank\gobble@to@relax + \begingroup + \cpt@stfalse\cpt@kvnormalize[,]{#1}% + \def\kve@g@tkeynames##1=##2\kve@nil{% + \edef\kve@keynames{% + \cptliststack,\kve@keynames\cpttrimspaces{##1}% + }% + }% + \kve@parse*\normalized@list{\kve@g@tkeynames##1=\kve@nil}% + \postgroupdef\kve@keynames\endgroup\cpt@relax +} +% \kve@setdefaults[<pref>]{<fam>}[<na>] +\robust@def*\kve@setdefaults{\cpt@testopt\kve@s@tdefaults{KV}} +\newletcs\kve@setwithdefaults\kve@setdefaults +\robust@def*\kve@s@tdefaults[#1]#2{% + \cpt@testopt{\kve@s@td@faults{#1}{#2}}{}% +} +\robust@def*\kve@s@td@faults#1#2[#3]{% + \ifcsndefTF{#1@#2@initialkeyvals}{% + \cptexpanded{% + \kve@setkeys[#1]{#2}[#3] + {\expandcsnonce{#1@#2@initialkeyvals}}% + }% + }{% + \kve@err{No initial key values for family '#2'} + {No initial key-value pairs saved for '#1,#2'.}% + }% +} +% \kve@setafterdefaults[<pref>]{<fam>}[<na>]{<keyval>} +\robust@def*\kve@setafterdefaults{% + \cpt@testopt\kve@s@tafterdefaults{KV}% +} +\robust@def*\kve@s@tafterdefaults[#1]#2{% + \cpt@testopt{\kve@s@taft@rdefaults{#1}{#2}}{}% +} +\robust@def*\kve@s@taft@rdefaults#1#2[#3]#4{% + \kve@ifblank#4\doblank\gobble@to@relax + \kve@getkeynames{#4}% + \letcstocsn\kve@tempa{#1@#2@initialkeyvals}% + \ifdefTF\kve@tempa{% + \cptexpanded{% + \kve@setkeys[#1]{#2}[\kve@keynames,#3] + {\expandcsonce\kve@tempa}% + \kve@setkeys[#1]{#2}[#3]{\unexpanded{#4}}% + }% + }{% + \kve@err{No initial key values for family '#2'} + {No initial key-value pairs saved for '#1,#2'.}% + }% + \cpt@relax +} +\robust@def*\kve@keyvalerr{% + \kve@getinnoval*[10]\currval + \kve@err{Invalid value '\innoval' for key '\currkey'} + {Key '\currkey' has an inadmissible value '\innoval'.}% +} +\robust@def*\kve@getinnoval{\cpt@teststopt\kve@g@tinnoval{10}} +\robust@def*\kve@g@tinnoval[#1]#2{% + \begingroup + \def\innoval{}\@tempcnta\z@pt + \def\siso@do##1{% + \advance\@tempcnta by1 + \ifnum\@tempcnta<#1\relax\edef\innoval{\innoval##1}\fi + }% + \cptexpandarg\siso@@loop + {\if@boolTF{cpt@st}\cptoxdetok\detokenize{#2}}% + \edef\innoval{\innoval\ifnum\@tempcnta>#1\string\ETC\fi}% + \postgroupdef\innoval\endgroup +} +\robust@def*\kve@checkbool#1#2#3{% + \lowercase{\xifinsetTF{,\cpttrimspaces{#1},}} + {,true,false,}{#2}{#3}% +} +\robust@def*\kve@checkchoice#1#2#3{% + \expandafter\cptswapfirstbraced\expandafter + {\romannumeral-`\q\cpttrimspaces{#1}} + {\kve@ch@ckchoice#2,\cpt@mil:\cpt@mil,\cpt@nil}{#3}% +} +\robust@def*\kve@ch@ckchoice#1:#2,#3\cpt@nil#4#5{% + \kve@ifblank#3\doblank{% + \unexpanded{#5}\gobble@to@relax + }% + \xifstrcmpTF{\cpttrimspaces{#1}}{\unexpanded{#4}}{% + \unexpanded{#2}% + }{% + \kve@ch@ckchoice#3\cpt@nil{#4}{#5}% + }% + \cpt@relax +} + +\endinput
\ No newline at end of file |