Flow control

Besides sequences of instructions, which can be achieved using the concat primitive, and the mechanism of macro expansion, the TeXmacs style-sheet language provides a few other primitive for affecting the control flow: if, case, while and for-each. These primitives are available from the SourceFlow control menu. However, we have to warn the user that the conditional constructs are quite fragile: they only apply to inline content and the accessibility of macro arguments should not to much depend on the conditions.

The most important primitive if, which can be entered using A-?, allows for basic conditional typesetting:

< assign | appendix | < macro | title | body | < document |

<\compound|

<if|<long-document>|chapter-appendix|section-appendix>

|

title

|

body

>

> > >

In this example, appendix is a block environment consisting of a title and a body, and which is rendered as a chapter for long documents and as a section for short ones. Notice that the following implementation would have been incorrect, since the if primitive currently only works for inline content:

< assign | appendix | < macro | title | body | < document |

<\if|

<long-document>

|

<chapter-appendix|title|body>

|

<section-appendix|title|body>

>

> > >

The if primitive may also be used in order to implement optional arguments:

< assign | hey | < macro | first | second |

<\if|

<equal|second|?>

|

Hey first, you look lonely today...

|

Hey first and second, you form a nice couple!

>

> >

However, TeXmacs is not clever enough to detect which arguments are optional and which arguments are accessible (i.e. which arguments can be edited by the user). Therefore, you will have to manually give this information using the drd-props primitive. The case, while and for-each primitives are explained in more detail in the corresponding section on the TeXmacs primitives.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".