Changes

Jump to navigation Jump to search
162 bytes removed ,  11:42, 3 December 2020
m
Typo
< [[The ConTeXt Way]] | [[Inside ConTeXt]] | [[Project structure]] >
 
Very often, you want to generate multiple versions of the same document:
one version for printing and one for viewing on the screen, one version for
multiple modes can be simultaneously enabled or disabled, and the status of multiple
modes can be checked easily. Moreover, modes can be set from a command line
switch. As a result, multiple versions of a document can be generated without changingthe source file.
The name or identifier of a mode can be any combination of letters, digits, or
spaces. Names starting with <code>*</code> are reserved for system modes.
 
In this article I explain how to activate a mode and how to check if a mode is
active or not.
= Setting modes =
{{cmd|disablemode}} deactivates a mode, and {{cmd|preventmode}} permanently
deactivates a mode. All three commands take a list of modes as an argument. For
example, you can activate to active modes named <code>screen</code> and <code>solution</code> withuse:
<texcode>
\enablemode[screen,solution]
Modes can also be activated by a command line switch <code>--modes</code> to
<code>texexec</code> or <code>context</code>. For example, another way to activate the <code>screen</code> and
<code>solution</code> modes, to run ConTeXt using one of:
texexec --mode=screen,solution ...
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 casesTo speed up the processing, you a mode can be ''define'' a mode d before using them, to speed up the processing. Modes are defined usingbeingused:
<texcode>
4:3 aspect ratio and a width equal to the width of A4 paper.)
Alternatively, youcould set a default paper size for the screen and change it if screen mode isnot enabled:
<texcode>
\setuppapersize[S6][S6]
\enablemode[foo]
</texcode>
the contents of the mode environment are not execited executed because <code>foo</code> is not enabled when <code>\startmode</code> is encountered.
<texcode>
\startmodeset
% NOTE: Empty lines are not allowed here!
[mode1, mode2, ...] {Processed if either mode is enabled}
[mode3, mode4, ...] {Processed if either mode is enabled}
== Checking modes in Lua ==
In MkIV, the The state of any mode is accessible at the Lua end as <code>tex.modes</code> table. Specifically,
<texcode>
</texcode>
checks if both <code>mode1</code> and <code>mode2</code> are enabled.
 
= System modes =
| Enabled when running [[MkIV]]
|}
 
Perhaps the most useful system modes are <code>*mkii</code> and <code>*mkiv</code> which
Other modes are useful for very specific situations. Some of these are described
below.
 
<code>*first</code> mode is handy&mdash;it is active only on the first run of the
document.
 
 
You may want to use different images for XML [Export]. The <code>*export</code> mode is useful in such cases.
 
 
|}
 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.
|'''*grid'''
| Enabled when grid typesetting is enabled
|-
|'''*singlesided'''
| Enabled when singlesided layout is enabled
|-
|'''*doublesided'''
| Enabled when doublesided layout is enabled
|}
 
{|cellpadding="5" style="border-collapse: collapse;border-width: 1px; border-style: solid;"
\executesystemcommand{some_external_program ...}
% convert PS into PDF
\executesystemcommand{texmfstart pstopdf fig-1.ps}
\stopmode
</texcode>
{{Getting started navbox}} [[Category:ConTeXt programmingTools]]
93

edits

Navigation menu