GNU TeXmacsUser manualReferenceAboutEnglish
The data relation descriptor

1.Purpose

A macro definition says how a tag is rendered, but the editor needs other information about tags: how many arguments they take, which arguments may contain the cursor, what kind of content (text, length, color, …) each argument holds, which environment variables are changed inside an argument (so that, for instance, the editor knows that the body of equation is in math mode), whether a tag is only an environment modifier, and so on. This information is stored in the data relation descriptor or DRD; see also the user-level description in data relation descriptions and the primitive drd-props in macro primitives.

The code lives in

Data/Drd/

. The DRD of built-in tags is hard-coded in

drd_std.cpp

; the DRD of user tags is mostly inferred from their macro definitions, and can be refined or frozen by drd-props declarations in style files.

This page concentrates on the interplay between macros and the DRD; the complete reference for the DRD subsystem, on the C++ and on the Scheme side, is the chapter the data relation descriptor (DRD).

2.Data structures

class drd_info_rep
(a DRD)

Its main member is rel_hashmap<tree_label,tag_info> info, a relative hash map: a DRD created with the constructor drd_info (string name, drd_info base) only stores the entries which differ from those of base, and looks up the others in base. All DRDs of documents and styles are built on top of the standard DRD std_drd. The member env holds the environment (as set by set_environment) from which the heuristics were computed. get_locals and set_locals convert the local entries to and from a tree, which is how DRDs are stored in the style cache.

class tag_info_rep
(properties of one tag)

Consists of a parent_info pi with properties of the tag itself, an array array<child_info> ci with properties of its children, and a tree extra for miscellaneous attributes (names, syntax). Both structures are bit fields (

Data/Drd/tag_info.hpp

):

parent_info

type (the type of the value of the tag, one of the TYPE_* constants), arity_mode (ARITY_NORMAL, ARITY_OPTIONS, ARITY_REPEAT, ARITY_VAR_REPEAT), arity_base, arity_extra, child_mode (CHILD_UNIFORM, CHILD_BIFORM, CHILD_DETAILED: whether one child_info is shared by all children, two are used, or one per child), border_mode, block, with_like, var_type (VAR_MACRO, VAR_PARAMETER, VAR_MACRO_PARAMETER), and one freeze_* bit per property.

child_info

type, accessible (ACCESSIBLE_NEVER, ACCESSIBLE_HIDDEN, ACCESSIBLE_ALWAYS), writability, block, env (an index into a global table of environment trees, see drd_encode and drd_decode in

tag_info.cpp

) and the corresponding freeze_* bits.

The freeze_* bits are the key to the interplay between heuristics and explicit declarations: every set_* method returns immediately if the property is frozen, and drd-props freezes each property it sets. Hence explicit declarations always win over the heuristics, whatever the order in which they are executed.

The global variable the_drd (

drd_std.hpp

) points to the DRD of the current buffer; it is set by the editor and window code, and can be changed temporarily with the helper struct with_drd. The environment instead uses the DRD of its own buffer, through the reference edit_env_rep::drd.

3.Accessibility

drd_info_rep::is_accessible_child (tree t, int i) decides whether the cursor may enter the i-th child of t. The answer depends on the global access mode (

drd_mode.hpp

): DRD_ACCESS_NORMAL only accepts ACCESSIBLE_ALWAYS, DRD_ACCESS_HIDDEN also accepts ACCESSIBLE_HIDDEN, and DRD_ACCESS_SOURCE (used in source mode) makes every child accessible. For extern trees, the properties are looked up under the pseudo label extern:f, where f is the name of the Scheme function, so that drd-props can declare the accessibility of the arguments of individual Scheme macros.

Accessibility in the DRD and accessibility of boxes (inverse paths without negative entries) are two different things which should agree: the routines which move the cursor through the tree consult the DRD, whereas the boxes determine where the cursor can actually be displayed. A child which the DRD declares accessible but which the macro typesets as a decoration (because it computes with it), or conversely, leads to inconsistent cursor behaviour.

4.Heuristic initialization from macros

void heuristic_init (hashmap<string,tree> env)
(infer DRD properties from an environment)

Iterates over all variables of env, calling heuristic_init_macro for macro values, heuristic_init_xmacro for xmacro values and heuristic_init_parameter otherwise. Each of these returns whether it changed the tag_info. Since the properties of a macro depend on those of the macros it uses, the whole loop is repeated until nothing changes; after ten rounds it gives up with the warning bad heuristic drd convergence.

heuristic_init_macro (string var, tree macro) does the following for a macro with n parameters:

For instance, for a definition (assign "my-math" (macro "body" (with "mode" "math" (arg "body")))) the heuristics find that the argument is accessible, that it is in math mode, and that my-math is with-like. Arguments which only occur inside computations (such as merge, or extern with default DRD) are not accessible, which matches the fact that they are typeset as decorations.

heuristic_init_xmacro computes a minimal arity from the largest index i used in (arg x i) or map-args and declares a repeated arity (ARITY_REPEAT). heuristic_init_parameter declares a variable of arity zero and guesses its type from its name (color, *-color, *-length, *-width) or from its value (booleans, integers, numbers, lengths).

The heuristics are run at two moments: on the environment produced by the style (in compute_env_and_drd, see the typesetting environment), and on the initial environment of the document (typeset_preamble). edit_typeset_rep::drd_update runs them once more on the environment at the cursor, which takes into account macros defined in the body of the document.

5.Explicit declarations: drd-props

edit_env_rep::exec_drd_props interprets (drd-props tag prop1 val1 …). Each recognized property is set and frozen in drd:

arity

A number, or a tuple repeat, repeat* or options with two numbers.

name, syntax

Attributes used by the user interface.

border

yes, inner, outer or no.

with-like

yes or no.

locals

An environment for all children.

accessible, hidden, unaccessible

With a child number, all or none.

normal-writability, disable-writability, enable-writability

With a child number or all.

returns, parameter, macro-parameter

A type name, for the tag itself.

a type name

(as accepted by drd_encode_type, such as regular, length, boolean) with a child number or all: the type of children.

Note that drd-props acts on the DRD passed to the environment at the moment it is executed: in a style file, this is the DRD being built by compute_env_and_drd, which is then cached along with the environment.

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