Difference between revisions of "System Macros/Definitions and Assignments"

From Wiki
Jump to navigation Jump to search
m
m
 
(One intermediate revision by one other user not shown)
Line 73: Line 73:
 
Using this construction saves a few strings now and then.
 
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:
+
We won't go into details here, but the general form for using this command is:
  
 
<texcode>
 
<texcode>
Line 105: Line 105:
 
< '''Prev:''' [[System Macros/Handling Arguments|Handling Arguments]] | '''Top:''' [[System Macros]] | '''Next:''' [[System Macros/Branches and Decisions|Branches & Decisions]] >
 
< '''Prev:''' [[System Macros/Handling Arguments|Handling Arguments]] | '''Top:''' [[System Macros]] | '''Next:''' [[System Macros/Branches and Decisions|Branches & Decisions]] >
  
[[Category:System Macros]]
+
[[Category:Programming and Databases]]
[[Category:ConTeXt programming]]
+
[[Category:Tools]]

Latest revision as of 16:50, 8 June 2020

< 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:

\complexorsimple\command

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

\complexcommand [setup]

executes, else we get

\simplecommand

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 so often that we found it worthwhile to offer two more alternatives.

These commands are called as:

\definecomplexorsimple\command

Of course, we must have available

\def\complexcommand[#1]{...}
\def\simplecommand {...}

Using this construction saves a few strings now and then.

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

\definestartstopcommand\somecommand\e!specifier{arg}{arg}%
  {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:

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

which becomes:

\def\somecommand[#1][#2]\startspecifier#3\stopspecifier%
  {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 >