Changes

Jump to navigation Jump to search
2,817 bytes removed ,  07:39, 25 January 2017
m
typo correction
=== ConTeXt Features ===
* [[Modes]]: Document options that can be selected when the document is processed.Conditional processing of text* [[Setups]]: An alternative to macros for storing chunks of code
=== Commands and Arguments ===
* [[System Macros]] (''Recommended reading''. Topics: temporary variables, expansion control, argument grabbing and handling, definitions and assignments, branches and decisions, cases, comma separated lists, assignments and paramtersparameters, user intractioninteraction.)* [[Programming in LuaTeX]] (Topic: alleviating the more cumbersome sides of TeX programming.)* [[Commands with KeyVal arguments|Commands with Key=Value arguments]]: For (Topic: things like <code>\command[thiskey=thatvalue]</code>. ) * [[Commands with optional arguments]]: One (Topic: one or more optional arguments within brackets.)
=== Module Parameters ===
\getvariable{namespace}{key}
</texcode>
 
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, 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 thecontaining 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), ConTeXtautomatically calls these setups. Reading of variables is totally unaffected by thesesettings.A possible use are default values, calculations and even verification. So once you have 'setup' your variables proper, you don't have to worry aboutunset variables and alike any more. Also changes can be made easy, as there is onlyone 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 ==
== Passing verbatim text as macro parameter ==
== Passing (For passing text to LuaTex verbatim text as macro parameter ==, see the [[Programming_in_LuaTeX#Manipulating_verbatim_text_for_dummies|Programming in LuaTeX]] article on this wiki.)
In case you want to write macros that should handle verbatim text,
\TextWithSpaces{A gap from here to there!}
</context>
 
 
 
== Setups ==
In ConTeXt it is easy to create local variables and grouping. Local variables can be simulated as in:
 
<texcode>
\startsetups whatever
% some useful definitions here
\stopsetups
 
\definestartstop[whatever][commands=\setups{whatever}]
 
\startwhatever
Using definitions here.
\stopwhatever
</texcode>
 
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):
 
<texcode>
\defineoverlay [origin] [\setups{origin}]
 
\startsetups origin
\vbox to \overlayheight {
\vfill\tfxx\setstrut
\hsize\overlaywidth
\hfill Fiona Apple\enspace EM\enspace2005\quad\strut\endgraf
\kern1ex
}
\stopsetups
</texcode>
 
You can even do things like:
 
<texcode>
\starttext
\startsetups settest
\def\command{do something with}
I want to \command{} command.
\stopsetups
 
\start
\setups{settest}
\stop
 
\command aaa % will give "undefined control sequence" error
 
\stoptext
</texcode>
[[Category:Inside ConTeXt]]
[[Category:ConTeXt programming]]
19

edits

Navigation menu