Changes

Jump to navigation Jump to search
split off section
[[System_Macros]]

TeX's primitive <code>\csname</code> can be used to construct all kind of commands that cannot be defined with <code>\def</code> and <code>\let</code>. Every macro programmer sooner or later wants macros like these.

<texcode>
\setvalue {name}{...} = \def\name{...}
\setgvalue {name}{...} = \gdef\name{...}
\setevalue {name}{...} = \edef\name{...}
\setxvalue {name}{...} = \xdef\name{...}
\letvalue {name}=\... = \let\name=\...
\getvalue {name} = \name
\resetvalue {name} = \def\name{}
</texcode>

As we will see, ConTeXt uses these commands many times, which is mainly due to its object oriented and parameter driven character.

The next macro can be very useful when using <code>\csname</code> like in:

<texcode>
\csname if\strippedcsname\something\endcsname
</texcode>

This expands to <code>\ifsomething</code>.

Setups can be optional. A command expecting a setup is prefixed by <code>\complex</code>, a command without one gets the prefix <code>\simple</code>. Commands like this can be defined by:

<texcode>
\complexorsimple\command
</texcode>

When <code>\command</code> is followed by a <code>[setup]</code>, then

<texcode>
\complexcommand [setup]
</texcode>

executes, else we get

<texcode>
\simplecommand
</texcode>

An alternative for <code>\complexorsimple</code> is:

<texcode>
\complexorsimpleempty {command}
</texcode>

Depending on the presence of <code>[setup]</code>, this one leads to one of:

<texcode>
\complexcommando [setup]
\complexcommando []
</texcode>

Many ConTeXt commands started as complex or simple ones, but changed into more versatile (more object oriented) ones using the <code>\get...argument</code> commands later in their existence.

The previous commands are used that often that we found it worthwile to offer two more alternatives.

These commands are called as:

<texcode>
\definecomplexorsimple\command
</texcode>

Of course, we must have available

<texcode>
\def\complexcommand[#1]{...}
\def\simplecommand {...}
</texcode>

Using this construction saves a few strings now and then.

We won't go into details here, but the general form of this using this command is:

<texcode>
\definestartstopcommand\somecommand\e!specifier{arg}{arg}%
{do something with arg}
</texcode>

This expands to something like:

<texcode>
\def\somecommand arg \startspecifier arg \stopspecifier%
{do something with arg}
</texcode>

The arguments can be anything reasonable, but double <code>#</code>'s are needed in the specification part, like:

<texcode>
\definestartstopcommand\somecommand\e!specifier{[##1][##2]}{##3}%
{do #1 something #2 with #3 arg}
</texcode>

which becomes:

<texcode>
\def\somecommand[#1][#2]\startspecifier#3\stopspecifier%
{do #1 something #2 with #3 arg}
</texcode>

Actually, this macro is never used in ConTeXt, but it used to be part of constructions like <code>\placeformula</code>.

Navigation menu