The skeycommand Package(r)

Version 0.4

This package has been superseded by the key command and key environment commands of the 1txkeys package. It is maintained only for the sake of those already using it. Prospective users should instead employ the facilities of the ltxkeys package.

Ahmed Musa(r)

Preston, Lancashire, UK

The skeycommand package provides tools for defining LaTeX-style commands and environments using parameters and keys together. The advantages of keys over parameters include the facts that the former aren't limited to nine but can rise as desired by the user, and keys are much easier to match to their values than parameters to arguments, especially if the parameters are many. Moreover, keys can have natural functions. The design approach and user interfaces in the skeycommand package differ from those found in the keycommand package. This package also provides the Uneutwooptcmd and meuwooptcmicron macros for defining new commands and environments with two options/optional arguments. At both key command definition and invocation times there is no reference by the user to the semantics of key parsing and management. All the complex semantics and calculations involved in defining and setting keys are transparent to the user. The user of the skeycommand package has access to some of the machinery of ltxkeys package (including the pointer mechanism) at the much lesser cost of worrying only about the key names and their values. Native boolean keys are automatically recognized and handled appropriately. However, because of the need to keep the user interface simple, choice and style keys aren't available in this package.

## License

This work (i.e., all the files in the skeycommand package bundle) may be distributed and/or modified under the conditions of the LaTeX Project Public License (LPPL), either version 1.3 of this license or any later version.

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.

(c) MMX


Here,

* \(\langle\texttt{cmd}\rangle\) is the new control sequence; \(\langle\texttt{env}\rangle\) is the new environment name.
* \(\langle\texttt{mp}\rangle\) is the prefix for macros deriving from the defined keys whose values will be used in the new command or environment (this is called the _macro prefix_ in the parlance of keys). If you don't supply the optional \(\langle\texttt{mp}\rangle\), the package will use the first three letters of the key command or environment name, excluding the escape character but including an added 'at sign' (\(\mathfrak{e}\)). The aim of the default 'at sign' is to aid the visual separation of key names from macro prefixes.
* \(\langle\texttt{keyval}\rangle\) is the key-value list [e. g., (keya=valuea, keyb=valueb)].
* \(\langle\texttt{narg}\rangle\) is the number of parameters/arguments for the new command or environment (excluding the keys), as you would normally enter it in \newcommand and \newenvironment.
* \(\langle\texttt{afft1}\rangle\) is the default value for your optional argument (normally the first argument in \newcommand and \newenvironment).
* \(\langle\texttt{defn}\rangle\) is the replacement text (as in \newcommand and \newenvironment).

**Note 2.1**: The number of parameters (\(\langle\texttt{narg}\rangle\)) for the new command or environment is limited to eight (8), and not the nine (9) that TeX allows. The ninth one is taken up by the keys. Indeed, we could have designed \newkeycmd, \renewkeycmd, \newkeyevniron, \renewkeyevniron to take nine parameters (apart from the keys) but the need for parameters is greatly diminished by the theoretically limitless number of keys that each command can have.

Please note the angle brackets surrounding \(\langle\texttt{mp}\rangle\), and the parentheses surrounding \(\langle\texttt{keyval}\rangle\) in the above syntaxes. The \(\langle\texttt{mp}\rangle\) can't be empty (i. e., don't enter <>) because it will be used by the package to build unique names for the macros that will hold the key values. You can choose not to enter anything for \(\langle\texttt{mp}\rangle\), i. e., no angled brackets at all. In this case the package will happily use the default prefix <xxx@>, where 'xxx' represents the first three letters of the new command or environment name, excluding the escape character. Also, \(\langle\texttt{keyval}\rangle\) can't be empty: if it was empty, then we should wonder why you're using key commands instead of TeX's \newcommand and \newenvironment.

In \(\langle\texttt{defn}\rangle\), you refer to your arguments in the normal way. You refer to the values of the keys using macros whose first three characters (after the escape character) are the \(\langle\texttt{mp}\rangle\) or, if \(\langle\texttt{mp}\rangle\) is not supplied, the first three letters of the declared key command (excluding the escape character). The family name of the keys defined via a key command is the key command name itself (without the escape character)--but the user is not required to know anything about such jargons as 'key families.' The package uses this internally in developing the keys. The key prefix is always 'KV.' If any of your key values contains parentheses, simply enclose them in braces, to avoid confusing them with \(\langle\texttt{keyval}\rangle\) list.

The starred (\(\star\)) variants give'short' macros, while the plain (unstarred) variants yield 'long' macros, in the sense usually understood in TeX.

The optional \(\langle\texttt{mp}\rangle\) will be useful if you fear clashes with previously defined key commands. Although, to be defined, key commands must be definable, two key commands may have their first three or four characters identical, thereby leading to clashes of their key-value prefixes.

### Final tokens of every environment

The user can add some tokens to the very end of every subsequent environment by declaring those tokens in \skceveryeoe, which by default contains only TeX's \ignorespacesafterend, that is, the \skeycommand package automatically issuesIt is important to note that new tokens are prepended (not appended) to the hook that underlies \skceveryeoe, such that by default \ignorespacesafetrend always comes last in the list. You can empty the token list \skceveryeoe by issuing \skceveryeoe{} and rebuild the list afresh, still by prepending elements to it. \skceveryeoe isn't actually a token list register, but has been designed to behave like one. It is safe to issue \skceveryeoe{(token)} and/or \skceveryeoe{} in the pre-code part of the environment. The following example illustrates this point.

Example: \newkeyenviron \newkeyenviron*{testenv}<mp@>(xwidth=2cm,width=1.5cm,

bool=false,body=null,author=NULL){%

\centering\fbox{\mp@xwidth}{\mp@body}}

\ifmp@bool\color{red}\fi

\fbox{\parbox{\mp@ywidth}{\mp@body}}%

\normalcolor

\skceveryeoe{\%

\skceveryeoe{\ignorespacesafetrend}%

\skceveryeoe{\ndgraft}{\bselineskip}

\centerline{\itshape}{upp@author}}

\def\testmacro##{aaa#1bbb}% just to test parameter use

\f{%

\def\testmacro##1{xxx##1yyyy}%

\begin{document}

\begin{testenv}(xwidth=5cm,width=4cm,bool=true,

author={Corelius Tacitus \textbackslash{textup}((55--120^AD))},body={%

\ Love of fame is the last thing even learned men can bear

\%

\end{document}

Result of example code

\begin{tabular}{|l|l|} \hline Love of fame is the last thing even learned men can bear to be parted from. & Love of fame is the last thing even learned men can bear to be parted from. \\ \hline \end{tabular}

### Invoking new key commands and environments

The syntaxes for calling new key commands and environments are as follows:

Invoking commands and environments \cmd[(arg1)]{(arg2)}...{(argn)}(\keyval))

\begin{tabular}{|l|} 
\begin{tabular}{|l|} \hline Invoking commands and environments \\ \hline \textbackslash{text}((arg1)]{(arg2)}...{(argn)}(\keyval)) \\ \end{tabular}

\begin{tabular}{|l|} \hline \textbackslash{text}((arg1)]{(arg2)}...{(argn)}(\keyval)) \\ \end{tabular}

\begin{tabular}{|l|} \hline \end{tabular}

where \cmd and env have been previously defined using key command and key environment. You refer to your arguments using parameter number one #1 onwards, up to a maximum of ##8 (yes, #8,not #9). Here, \(\langle\)keyval\(\rangle\) (including the parenthesis) are optional arguments: you can omit them if you want to use the values of the keys set at key command definition time. Using keys is preferable to using parameters: you don't have to match parameters to arguments and, in principle, there is no limit to the number of keys that are permissible.

#### 2.4 Commands and environments with two optional arguments

The skeycommand package uses the following macros internally. They can be used to define new commands and environments with two optional arguments. Their philosophy, intent, and use syntaxes differ from those of the twoopt package. They may be useful to some users in a few circumstances, but I recommend the use of the above key commands in all instances.

```
Newmacros:\newtwooptcmd,\newtwooptenviron,etc
```

```
newtwooptcmd(cmd[(narg)][(dft1)]{(defn)} newtwooptcmd*(cmd)[(narg)][(dft1)]{(defn)}
```

```
newtwooptcmd*(cmd)[(narg)][(dft1)]{(defn)}
```

```
newtwooptenviron(cmd[(narg)][(dft1)]{(defn)}
```

```
newtwooptenviron*(cmd)[(narg)][(dft1)]{(defn)}
```

```
newtwooptenviron*(cmd)[(narg)][(dft1)]{(defn)}
```

```
\(\langle\)narg\(\rangle\) is the total number of arguments, including the first and second optional arguments. Where are the second optional arguments here, you might be wondering? The second optional argument is usually empty and doesn't appear at command definition time. The second optional argument isn't the second argument of your command (as in twoopt package), but the last. At command invocation, if you don't supply a value for the second optional argument, the command will assume it to be empty. But how do you supply a value for the second optional argument? The next section shows how.

#### 2.4.1 Invoking commands and environments with two optional arguments

The syntaxes for calling commands and environments with two optional arguments are as follows:
``` Macro:Commandsandenvironmentswithtwooptionalarguments ```
``` \cmd[(1stoptrg)]{(arg2)}...{\(\langle\)narg\(\rangle\)}{\(\langle\)2ndoptrg\(\rangle)} \begin{enumv}[(1stoptrg)]{(arg2)}...{\(\langle\)narg\(\rangle\)}{\(\langle\)2ndoptrg\(\rangle)} environmentbody \end{enumv}
```

If \(\langle\)2ndoptrg\(\rangle\) is empty at command or environment invocation, the command or environment will assume it to be empty. Now you can see the conceptual link between \newtwooptcmd (and friends) and \newkeycmd (and friends).

## 3 Examples

The source codes for the following examples are available in the accompanying user guide (file skeycommand-guide.tex).




Result of example code

**G. H. Hardy vs. Srinivasa Ramanujan (1920)**

Hardy: Srinivasa, can you see that number from here, the one on that taxi cab?

Ramanujan: I can see it, it is 1729.

Hardy: What a dull registration number to have on your vehicle?

Ramanujan: No, it is a very interesting number.

Hardy: What is interesting about it?

Ramanujan: It is the smallest number expressible as a sum of two cubes in two different ways.

Hardy: What are the different ways?


If I write a tune you all say it's commonplace---if I don't, you all say it's rot.% }% }% }end{Quote}
230\begin{Quote}(left=4Opt,right=4Opt,mode=false,  whoby={ALBERT EINSTEIN},source={The World As I See It})% {ifmp@mode\color{red}\else\color{blue}\}\{fi  If you want to find out anything from the theoretical physicists about the methods they use, I advise you to stick closely to one principle: don't listen to their words, fix your attention on their deeds.% }% }end{Quote} Result of example code "An author writing an article for publication in TUGboat is encouraged to create it on a computer file and submit it on magnetic tape." }B. BEETON, _How to Prepare a File For Publication in TUGboat_ (1981) Source: The TeXBook "The printer should refuse to employ wandering men, foreigners who, after having committed some grievous error, can easily disappear and return to their own country." }HIBERONYMUS HORNSCHUCH (1608) Source: The TeXBook "If I write a tune you all say it's commonplace--if I don't, you all say it's rot." }EDWARD ELGAR (1898) Source: Letter to A. J. Jaeger "If you want to find out anything from the theoretical physicists about the methods they use, I advise you to stick closely to one principle: don't listen to their words, fix your attention on their deeds." }






**Version 0.3** [2010/05/21]

Introduced \skceveryeoe

**Version 0.2** [2010/05/20]

Addressed the case of \newkeycmd without parameters

**Version 0.1** [2010/05/05]

First public release