Changes

Jump to navigation Jump to search
1,236 bytes added ,  11:39, 11 March 2019
m
closing tag much needed
context --mode=screen,solution ...
== Pre-defining modes ==
Normally, the overhead for testing modes is negligible, but it can add up if modes are tested multiple times in a document (for example, as part of a macro). In such cases, you can ''define'' a mode before using them, to speed up the processing. Modes are defined using:
 
<texcode>
\definemode[...][...]
</texcode>
 
The first argument is a list of modes; the second argument may be `yes`, `no`, or `keep`. For example,
 
* <code>\definemode[screen][yes]</code> defines a mode and enables it;
* <code>\definemode[screen][no]</code> defines a mode and disables it;
* <code>\definemode[screen][keep]</code> defines a mode and keeps its previous status.
 
Typically, it is better to use <code>\definemode[...][keep]</code> so that the modes may be enabled or disabled from command line as well.
= Conditional processing based on modes =
<texcode>
\doifmodeelse {mode1, mode2, ...} {Processed if any mode is enabled} {else this is processed}
\doifnotmodeelse {mode1, mode2, ...} {Processed if any mode is disabled} {else this is processed}
\doifallmodeselse {mode1, mode2, ...} {Processed if all modes are enabled} {else this is processed}
\doifnotallmodeselse {mode1, mode2, ...} {Processed if all modes are disabled} {else this is processed}
</texcode>
 
Note that there is no command <code>\doifnotmodeelse</code> because there is no need for it; <code>\doifmodeelse</code> may be used for the same effect (with the <code>if</code> and <code>else</code> branches switched).
== Checking multiple modes in parallel (<code>case</code> statement for modes) ==
</texcode>
The same mode can be referenced multiple times, and '''all''' matching brances branches are executed.
The {{cmd|startmodeset}} ... {{cmd|stopmodeset}} environments can be nested. So, you can use
Other modes are useful for very specific situations. Some of these are described
below.
 
 
{|cellpadding="5" style="border-collapse: collapse;border-width: 1px; border-style: solid;"
<code>*first</code> mode is handy&mdash;it is active only on the first run of the
document.
 
 
 
 
{|cellpadding="5" style="border-collapse: collapse;border-width: 1px; border-style: solid;"
| '''*export'''
| Enabled when <code>\setupbackend[export=yes]</code> is set
|}
 
You may want to use different images for XML [Export]. The <code>*export</code> mode is useful in such cases.
 
 
 
{|cellpadding="5" style="border-collapse: collapse;border-width: 1px; border-style: solid;"
encountered. Similarly, a mode <code>*text</code> is enabled when
<code>\starttext</code> is encountered, and likewise for the others.
 
 
{|cellpadding="5" style="border-collapse: collapse;border-width: 1px; border-style: solid;"
if you want macros that work differently in different section blocks, you can
check for modes <code>*frontpart</code>, <code>*bodypart</code>, and so on.
 
 
{|cellpadding="5" style="border-collapse: collapse;border-width: 1px; border-style: solid;"
Sometimes you want a macro to behave differently if it is part of a section head, a section number, a list, a marking, or a register. For section heads, you can check for modes <code>*chapter</code>, <code>*section</code>, <code>*subsection</code>, etc. Similarly, <code>*list</code> is enabled inside a list, <code>*marking</code> is enabled inside a marking, and <code>*register</code> is enabled inside a register.  
{|cellpadding="5" style="border-collapse: collapse;border-width: 1px; border-style: solid;"
English and the current language is Dutch, the modes <code>**en-us</code> and
<code>*nl</code> are set (notice the extra <code>*</code> in <code>**en-us</code>).
 
 
{|cellpadding="5" style="border-collapse: collapse;border-width: 1px; border-style: solid;"
139

edits

Navigation menu