Jump to navigation Jump to search
2,335 bytes added ,  10:44, 7 September 2005
== Using variables ==
There are several ways to handle variables in ConTeXt.
The recommended and easiest method is to use the
<tt>\setvariables</tt> and <tt>\getvariable</tt> macros.
Doing it this way you also avoid to get in conflict with
allready defined stuff (as variables use their own namespace).
To store variables, you can use the <tt>\setvariables</tt>
% stores value in variable namespace:key
% stores the expanded value
% global
% global and expanded value
Use <tt>\getvariable</tt> to process a variable. Reading an undefined
variable results in the <tt>\empty</tt> token. This is not a serious problem,
as long as you expect text only.
But be warned: the compilation process breaks, if you expect a dimension
or number. So better take care, that you define your variables, before you use them.
% gets value of the variable namespace:key
 To avoid problems, also pay attention to the following: You can set several variables (same namespace) at the same time.So the command <tt>\setvariables</tt> logically uses the '''plural''' formand works with '''square brackets'''.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 variablespace before and after a letter macro called <tt>\Opening</tt>. <texcode>\long\def\Opening#1{% \getvariable{todo|This could really Letter:opening}{before} \noindent{\begstrut#1\endstrut} \getvariable{Letter:opening}{after}}</texcode> By using variables in your macros, you can separate the layout definition,so that your macros get much more flexible.Just ensure, that all variables are set, before you use them! In this example we want to have a specific example or blank line in front of the opening, andtwoblank lines right after it. The value for the second key containssquare brackets, so it must be enclosed in braces<texcode>\setvariables[Letter:opening] [before=\blank, after={\blank[2*big]}}, ]</texcode> You can now save this style setup (among others) in a separate file andinclude it at the start of your document (before <tt>\Opening</tt> isdefined or at least used). And don't forget:'''Just ensure, that all variables are set, before you use them!'''
== Defining new commands ==


Navigation menu