![]() |
Evaluation control primitives | ![]() |
This section describes several primitives for controlling the way expressions in the style-sheet language are evaluated. The primitives are analogous to the Scheme primitives eval, quote, quasiquote, etc., although the TeXmacs conventions are slightly different than those used by conventional functional languages like Scheme.
Typeset the result of the evaluation of expr. This primitive is usually combined with a tag like quote or quasiquote for delaying the 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.
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.
This tag is used in combination with quasiquote and quasi in order to mark the subexpressions which need to be evaluated.
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
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.
When retrieving an environment variable var, one is usually interested in its typeset value, as given by <value|var>. In some cases, it may be useful to access the real, non-typeset value. This can be done with <quote-value|var>.
When retrieving (a subexpression of) a macro argument var, one is usually interested in its typeset value, as given by <arg|var|index-1|\(\cdots\)|index-n>. In some cases, it may be useful to access the real, non-typeset value. This can be done with <quote-arg|var|index-1|\(\cdots\)|index-n>.
Evaluates expr and returns a copy of the result, which is disconnected from the source document.
Evaluates and typesets body, but tells the editor that the result corresponds to the macro argument arg (which is typically of the form <arg|name>): cursor positions at the borders of the rendering are identified with the borders of the argument. This primitive is used when a macro displays a transformed version of one of its arguments, and in particular for the rendering of inactive markup. The arg is not evaluated.
Evaluates and typesets body, but, for the routines which look for the accessible source of a rendering (such as loci, hard-id and find-accessible), the result stands for expr.
Expands expr (typically a macro argument) until a subtree of the source document is found, and returns this subtree, without evaluating it. It is used by the action macro in order to pass document fragments to Scheme scripts.
The implementation of these primitives is described in more detail in the chapter on macro expansion, and in particular in the sections on the evaluator and on macro expansion during typesetting.