Evaluation control primitives

This section describes several primitives for controlling the way expressions in the style-sheet language are evaluated. The primitives are analoguous to the Scheme primitives eval, quote, quasiquote, etc., although the TeXmacs conventions are slightly different than those used by conventional functional languages like Scheme.

<eval|expr>
(force evaluation)

Typeset the result of the evaluation of expr. This primitive is usually combined with a tag like quote or quasiquote for delaying the evaluation.

<quote|expr>
(delayed evaluation)

Evaluation of the expression <quote|expr> yields expr itself. This kind of delayed evaluation may be useful in combination with the eval primitive which forces evaluation.

<quasiquote|expr>
(delay evaluation and substitution)

This tag is a variant of the quote tag, which returns the expression expr in which all subexpressions of the form <unquote|subexpr> have been replaced by the evaluations of subexpr. For instance,

<assign|hello|<quasiquote|<macro|name|<unquote|<localize|Hello>> name.>>>

may be used to define a macro hello whose value is localized for the current language. In a French document, the declaration would typically be equivalent to

<assign|hello|<macro|name|Bonjour name.>>

Notice however that it is usually better not to use the quasiquote primitive for such applications. When defining

<assign|hello|<macro|name|<localize|Hello> name.>>

the typesetting of <hello|Name> would naturally adapt itself to the current language, while the above version would always use the language at the moment of the definition of the macro. Nevertheless, the first form does have the advantage that the localization of the word “Hello” only has to be computed once, when the macro is defined. Therefore, the quasiquote primitive may sometimes be used in order to improve performance.

<unquote|subexpr>
(mark substitutable subexpressions)

This tag is used in combination with quasiquote and quasi in order to mark the subexpressions which need to be evaluated.

<unquote*|subexprs>
(unquote splicing)

This tag is similar to unquote, except that the argument subexprs now evaluates to a list of subexpressions, which are inserted into the arguments of the parent node. For instance, consider the macro

< assign | fun | < xmacro | x |

<\quasi|

<tree|dup|<unquote*|<quote-arg|x>>|<unquote*|<quote-arg|x>>>

>

> >

Then <fun|a|b|c> is typeset as

<quasi|expr>
(substitution)

This tag is a shortcut for <eval|<quasiquote|expr>>. This primitive is often used in the TeXmacs style files in order to write macros which define sets of other macros. For instance, the macro

<assign|new-theorem|<macro|name|text|<quasi|<assign|<unquote|name>|<macro|body|<surround|<no-indent><strong|<unquote|text>. >|<right-flush>|body>>>>>>

may be used in order to define new theorem-like environments.

<quote-value|var>
(retrieve a value but don't evaluate)

When retrieving an environment variable var, one is usually interested in its typesetted value, as given by <value|var>. In some cases, it may be useful to access the real, non-typesetted value. This can be done with <quote-value|var>.

<quote-arg|var|index-1||index-n>
(retrieve an argument but don't evaluate)

When retrieving (a subexpression of) a macro argument var, one is usually interested in its typesetted value, as given by <arg|var|index-1||index-n>. In some cases, it may be useful to access the real, non-typesetted value. This can be done with <quote-arg|var|index-1||index-n>.

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".