![]() |
Control flow primitives | ![]() |
This primitive can be used to typeset if-body only if the condition is satisfied. If the optional else-body is specified, then it is typeset if and only if the condition fails.
Remark 1. It should be noticed that the use of conditional markup can be a bit tricky due to the fact that the accessibility of arguments cannot necessarily be checked beforehand. For instance, in the macro definition
<macro|x|<if|<visibility-flag>|x>> |
the macro argument x is accessible if and only if <visibility-flag> evaluates to true. This condition cannot necessarily be checked a priori. For certain editing operations, like searches or spell checking, the incorrect determination of the accessibility may lead to the positioning of the cursor at unaccessible places, or to the ignorance of certain markup. In the future, we plan to improve this aspect of the editor, but it is better to avoid conditional markup whenever another solution can be found.
Remark 2. The conditional constructs are only fully implemented for inline markup. In the case when you need conditional markup for block structures you currently have to write macros for the if-case and the else-case and use the compound tag. For instance:
<assign|cold|<macro|x|<with|color|blue|x>>> <assign|hot|<macro|x|<with|color|red|x>>> <assign|adaptive|<macro|x|<compound|<if|<summer>|hot|cold>|x>>> |
These commands are respectively equivalent to
<if|cond-1|body-1|\(\cdots\)<if|cond-n|body-n>> <if|cond-1|body-1|\(\cdots\)<if|cond-n|body-n|else-body>> |
Contrary to case, all bodies are typeset beforehand and the selection of the displayed body happens at rendering time, without retypesetting the document (case_box in
Typeset/Boxes/Composite/case_boxes.cpp
). The else-body is displayed by default. The event-i are evaluated and each of them may be the name of an event received by the box, mouse-over (when the mouse pointer is above the box), focus (when the cursor is inside the corresponding part of the document), any, or a comma separated list of such conditions. This primitive is useful for interactive effects in presentations and graphical user interfaces.
This construct maybe used in order to repeatedly execute a given body while a given condition is satisfied. For instance, when declaring
<assign|count| <macro|from|to|<with|i|from|<\concat| <while|<less|i|to>|i, <assign|i|<plus|i|1>>> | to > >>> |
the code <count|1|50> produces
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50 |
Apply the macro foo (the result of an evaluation, as in the case of compound) to each of the elements of the evaluated tuple. The results of the applications are discarded, so this primitive is only useful for its side effects, such as assignments. For instance, a style file may declare several similar environments with <for-each|new-theorem-like|<tuple|theorem|lemma>> when new-theorem-like is a macro which defines an environment whose name is given by its argument.
See also the if* primitive in the section on box operations, which reserves the space for its content even when the condition is not satisfied.