GNU TeXmacsUser manualReferenceAboutEnglishยทDeutsch
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.

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

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

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

<copy|expr>
(evaluate and copy)

Evaluates expr and returns a copy of the result, which is disconnected from the source document.

<mark|arg|body>

<mark*|arg|body>
(link rendering to a macro argument)

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.

<expand-as|expr|body>
(expand as another expression)

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.

<find-accessible|expr>
(find the source of an expression)

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.

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