System Macros/Definitions and Assignments

From Wiki
< System Macros
Revision as of 12:02, 25 December 2006 by Taco (talk | contribs) (move the argument stuff to the right page)
Jump to navigation Jump to search

< Prev: Handling Arguments | Top: System Macros | Next: Branches & Decisions >

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

\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{}

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

The macro \strippedcsname can be very useful when using \csname like in:

\csname if\strippedcsname\something\endcsname

This expands to \ifsomething.

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


When \command is followed by a [setup], then

\complexcommand [setup]

executes, else we get


An alternative for \complexorsimple is:

\complexorsimpleempty {command}

Depending on the presence of [setup], this one leads to one of:

\complexcommando [setup]
\complexcommando []

Many ConTeXt commands started as complex or simple ones, but changed into more versatile (more object oriented) ones using the \get...argument 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:


Of course, we must have available

\def\simplecommand {...}

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:

  {do something with arg}

This expands to something like:

\def\somecommand arg \startspecifier arg \stopspecifier%
  {do something with arg}

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

  {do #1 something #2 with #3 arg}

which becomes:

  {do #1 something #2 with #3 arg}

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

< Prev: Handling Arguments | Top: System Macros | Next: Branches & Decisions >