Changes

Jump to navigation Jump to search
2,107 bytes added ,  12:56, 21 March 2006
And don't forget:
'''Just ensure, that 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
settings.
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.
 
<texcode>
\setupoutput[pdftex]
 
\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,..)
\stopsetups
 
 
\startsetups namespace:reset
%
\writestatus{VARIABLES}{namespace:set is beeing called..}%
\ {\green [namespace:reset]}
% whatever must be done after an assignment (verification, calculation,..)
\stopsetups
 
 
% \setups[namespace:set] is automatically called right after 'set' is assigned
\setvariables[namespace]
[set={\setups[namespace:set]},
reset={\setups[namespace:reset]},
]
 
% watch for the colors
\setupcolors[state=start]
 
\starttext
\hairline
{\bf reading has no effect\par}
{\tt Calling \type{\getvariable{namespace}{key}}...\getvariable{namespace}{key}}
 
\blank
{\bf writing calls reset and set\par}
{\tt Calling \type{\setvariables[namespace][key=value]}...\setvariables[namespace][key=value]}
 
\stoptext
 
</texcode>
== Defining new commands ==
37

edits

Navigation menu