Difference between revisions of "System Macros/Definitions and Assignments"
m (Basic navigation) |
m |
||
(4 intermediate revisions by 3 users not shown) | |||
Line 15: | Line 15: | ||
As we will see, ConTeXt uses these commands many times, which is mainly due to its object oriented and parameter driven character. | As we will see, ConTeXt uses these commands many times, which is mainly due to its object oriented and parameter driven character. | ||
− | The | + | The macro <code>\strippedcsname</code> can be very useful when using <code>\csname</code> like in: |
<texcode> | <texcode> | ||
Line 56: | Line 56: | ||
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. | 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 | + | The previous commands are used so often that we found it worthwhile to offer two more alternatives. |
These commands are called as: | These commands are called as: | ||
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 | + | We won't go into details here, but the general form for using this command is: |
<texcode> | <texcode> | ||
Line 102: | Line 102: | ||
Actually, this macro is never used in ConTeXt, but it used to be part of constructions like <code>\placeformula</code>. | Actually, this macro is never used in ConTeXt, but it used to be part of constructions like <code>\placeformula</code>. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
< '''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: | + | [[Category:Programming and Databases]] |
− | [[Category: | + | [[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 >