Changes

Jump to navigation Jump to search
1,163 bytes added ,  14:37, 16 May 2013
no edit summary
== In ConTEXt, setups are a rather common variant on macros. Setups ==have two useful properties:
In ConTeXt it is easy * Spaces inside setups are ignored. This means that you can format the setup's contents with spaces and linebreaks for maximum readability, instead of having to create local variables and groupingwrite a dense macro or, worse, a long in-place definition. Local variables You can be simulated as in:explicitly request spaces with {{cmd|space}}, {{cmd|crlf}}, {{cmd|par}}, etc.
* If you call the setup inside a {{cmd|start}} (just 'start') environment, any definitions made by that setup remain inside that group. This lets you define macros in a setup, and then call the setup inside a group to use the macros as 'local macros' of sorts.
 
== Commands ==
 
* {{cmd|startsetup| mysetup}} begins a setup definition
* {{cmd|setup|[mysetup]}} invokes a setup.
 
== Examples ==
 
 
Here are two simple examples:
{{Multicol}}
<texcode width=50%>
% Create two setups
\startsetup doc:print
\setuppapersize[A4][A4]
\stopsetup
 
\startsetup doc:screen
\setuppapersize[S6][S4]
\stopsetup
 
% Use one or another setup
\doifmodeelse {paper} {
\setup[doc:print]
} {
\setup[doc:screen]
}
</texcode>
{{Multicol-break}}
<texcode>
% Set up a headertext. Whitespace is ignored\startsetups whateverstartsetup[doc:header]% some useful definitions here \marking[chapter] \stopsetupsspace -- \definestartstop[whatever][commands=space \pagenumber\setups{whatever}]stopsetup
% Use the setup\startwhateverUsing definitions here.setupheadertexts[\stopwhateversetup{doc:header}]
</texcode>
{{Multicol-end}}
But you 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>
\starttext
\startsetups settest
\def\command{do something with} I want to \command{} my command.
\stopsetups
\start
\setups{settest}
\stop
To give you the idea, try this example.
The <tt>set</tt>-part is called* '''right after''' When you initialize the definition of namespace, the namespace (initialisation) and* '''after''' a value is setups assigned to a variable.The <tt>reset</tt>-part is {{code|set}} are called* '''right after''' any assignment, but still in front of the <tt>set</tt>-part.
<texcode>\setupoutput[pdftex]* When you assign a variable to the namespace, first the setup in {{code|reset}} is called, and then the setup in {{code|set}}.
<context source=yes>
\startsetups namespace:set
%Print message to log and to document \writestatus{VARIABLES}{namespace:set is beeing being called..}% \ space{\green [namespace:set]} \def\applecolor{red} % whatever must be done with your variables after you assign a value % % (initialisation with defaults,..)
\stopsetups
\startsetups namespace:reset
% Print message to log and document
\writestatus{VARIABLES}{namespace:set is being called..}%
\space{\red[namespace:reset]}
\startsetups namespace:reset
%
\writestatus{VARIABLES}{namespace:set is beeing called..}%
\ {\green [namespace:reset]}
% whatever must be done after an assignment (verification, calculation,..)
\stopsetups
\setvariables[namespace]
[set={\setups[namespace:set]},
key={Apples are \applecolor!},
reset={\setups[namespace:reset]},
]
\stoptext
 </texcodecontext>

Navigation menu