Jump to navigation Jump to search
3,112 bytes removed ,  13:02, 16 May 2013
no edit summary
=== ConTeXt Features ===
* [[Modes]]: Conditional processing of text
* [[Setups]]: An alternative to macros for storing chunks of code
=== Commands and Arguments ===
To avoid problems, also pay attention to the following:
On the other hand you can only process one variable at the same time, so
<tt>\getvariable</tt> uses the '''singular''' form and works with '''braces'''.
OK, here comes a simple example. Let's say, that we want to have variable
And don't forget:
'''Just ensure, that Ensure hat all variables are set, before you use them!''' 
==== Using setups for namespaces ====
Using <tt>\setups</tt> for a variable namespace allows an easier control over the
containing variables.
All you have to do is to define the setups
<tt>namespace:set</tt> and/or <tt>namespace:reset</tt>
for a given namespace.
Now every time a variable of that namespace is assigned (written), ConTeXt
automatically calls these setups. Reading of variables is totally unaffected by these
A possible use are default values, calculations and even verification.
So once you have 'setup' your variables proper, you don't have to worry about
unset variables and alike any more. Also changes can be made easy, as there is only
one common setup.
The drawback is the slower speed in use,
as every assignment to a variable calls these setups.
To give you the idea, try this example.
The <tt>set</tt>-part is called
* '''right after''' the definition of the namespace (initialisation) and
* '''after''' a value is assigned to a variable.
The <tt>reset</tt>-part is called
* '''right after''' any assignment, but still in front of the <tt>set</tt>-part.
\startsetups namespace:set
\writestatus{VARIABLES}{namespace:set is beeing called..}%
\ {\green [namespace:set]}
% whatever must be done with your variables after you assign a value
% (initialisation with defaults,..)
\startsetups namespace:reset
\writestatus{VARIABLES}{namespace:set is beeing called..}%
\ {\green [namespace:reset]}
% whatever must be done after an assignment (verification, calculation,..)
% \setups[namespace:set] is automatically called right after 'set' is assigned
% watch for the colors
{\bf reading has no effect\par}
{\tt Calling \type{\getvariable{namespace}{key}}...\getvariable{namespace}{key}}
{\bf writing calls reset and set\par}
{\tt Calling \type{\setvariables[namespace][key=value]}...\setvariables[namespace][key=value]}
== Defining new commands ==
The newly defined command <tt>\!test</tt> can of course only be called upon when we are in the <cmd>unprotect</cmd>ed state, otherwise TeX reads the command <tt>\!</tt>, followed by the word <tt>test</tt> (and probably complains loudly about not being in math mode). These protection/unprotection commands can be nested. When the nesting becomes deeper than one level, the system reports the current protection level. It is a good habit to always start your macro files with <cmd>unprotect</cmd> and end them with <cmd>protect</cmd>.
\TextWithSpaces{A gap from here to there!}
== Setups ==
In ConTeXt it is easy to create local variables and grouping. Local variables can be simulated as in:
\startsetups whatever
% some useful definitions here
Using definitions here.
But you can place setups almost everywhere and environment will not be affected by their execution. It is useful to wrap overlay definitions and such in setups as in (copied from [[Colorful_CD_Inlay]] page):
\defineoverlay [origin] [\setups{origin}]
\startsetups origin
\vbox to \overlayheight {
\hfill Fiona Apple\enspace EM\enspace2005\quad\strut\endgraf
You can even do things like:
\startsetups settest
\def\command{do something with}
I want to \command{} command.
\command aaa % will give "undefined control sequence" error
[[Category:Inside ConTeXt]]
[[Category:ConTeXt programming]]

Navigation menu