![]() |
How the rest of TeXmacs uses the DRD | ![]() |
The DRD is consulted in three ways: through the member drd of the editor (code in
Edit/
), through env->drd (the typesetter and the evaluator), and through the global the_drd (generic tree code, languages and converters, and all Scheme glue). This page lists the main call sites by subsystem, as a map for developers who change a property and want to know what will be affected. Paths are relative to
src/src/
.
The notion of a valid cursor position is entirely DRD-driven.
Data/Tree/tree_cursor.cpp
is_accessible_cursor (t, p) decides whether the path p is a valid cursor position in t. It refuses positions on child-enforcing tags (is_child_enforcing) and at the inner borders of parent-enforcing tags (is_parent_enforcing, with lowest_accessible_child and highest_accessible_child), descends only into accessible children, switches to source access mode inside children whose environment has mode=src (the arguments of value, arg, symbol, …), and maintains the writable mode according to get_writability_child. active, inactive and their starred versions switch the access mode for their body (is_modified_accessible). closest_accessible and friends use the same predicates.
Data/Tree/tree_traverse.cpp
The abstract cursor movements (next_valid, previous_valid, word and argument movement such as move_argument, next_tag, previous_tag, next_argument, …) skip inaccessible children; move_valid_bis temporarily switches to source mode when the starting path is itself inaccessible.
Edit/Interface/edit_cursor.cpp
make_cursor_accessible moves an inaccessible cursor to the closest valid position, in source access mode if the document is in source mode. edit_interface_rep::resume calls it with the_drd set to the editor DRD.
Edit/Modify/edit_dynamic.cpp
make_compound (l, n) chooses the smallest admissible arity when none is given (correct_arity, get_arity_mode), puts the cursor in the first accessible child, lets Scheme handle with-like tags (is_with_like), inserts the tag in inactive form if not all its children are accessible (all_accessible), and shows a message with get_name which mentions A-right for variable arities.
find_dynamic looks for the innermost ancestor with a variable arity (is_dynamic); insert_argument and remove_empty_argument use insert_point and correct_arity to insert or delete whole groups of children (for instance a row of a tree or a variable/value pair of a with). In source mode, these checks are skipped for tags which the DRD does not know (contains).
go_to_argument deactivates a tag before moving into an inaccessible argument, and activate decides where to put the cursor after activation.
make_hybrid and the activation of hybrid trees use contains (name) to recognize names of primitives.
Edit/Modify/edit_delete.cpp
remove_structure_upwards treats macros without border (var_without_border) like concat.
Edit/Replace/edit_select.cpp
select_enlarge and selection_adjust_border (
Data/Tree/tree_select.cpp
) enlarge selections which would end at an invisible border; semantic_root uses the environment of the first child (get_env) to find the enclosing mathematical or program fragment for semantic selections.
Edit/Replace/edit_search.cpp
Searching for tags (search_previous_compound, search_next_compound) only returns positions with is_accessible_path; the incremental search of next_match runs in DRD_ACCESS_HIDDEN mode, or source mode in source documents.
Data/Tree/tree_search.cpp
is_accessible_for_search accepts accessible children, the body of hidden, and in source mode all children except raw-data.
Data/Tree/tree_spell.cpp
Spell checking descends into accessible children and follows the mode and language of each child (get_env_child (t, i, MODE, mode), get_env_child (t, i, LANGUAGE, lan)), so that formulas and program code are skipped and foreign-language fragments are checked with the right dictionary.
Edit/Interface/edit_complete.cpp
Word completion collects words in accessible children only.
Edit/Interface/edit_footer.cpp
The footer names the tags around the cursor with get_name, and recognizes primitives with contains when completing hybrid commands.
Edit/Interface/edit_interface.cpp
compute_env_rects does not draw context rectangles around child-enforcing tags.
On the Scheme side (
generic/generic-menu.scm
), the variant menus use the tag names (tree-name), and the input fields for the “hidden”, i.e. inaccessible, children of the focus tag are built from tree-accessible-child?, tree-child-type, tree-child-name and tree-child-long-name; see the DRD from Scheme.
edit_typeset_rep::typeset_exec_until computes the environment at an arbitrary path by executing the document up to that path. When it descends from a tree into a child, it applies the child environment from the DRD (get_env_child (t, i, tree (ATTR))) and evaluates its values with env->exec; this is what makes (get-env "mode") return math inside the body of a user macro which wraps its argument in math mode. If the child environment is empty (child outside the layout), the descent stops. The same environment is used by drd_update.
Typeset/Bridge/bridge_compound.cpp
When a macro is typeset, a marker box for cursor positioning around it is inserted unless the macro is child-enforcing (is_child_enforcing on the_drd).
Typeset/Env/env_inactive.cpp
In source mode and for inactive markup, every argument is wrapped in src-regular, src-var, src-length, … according to get_type_child (function highlight).
Typeset/Concat/concater.cpp
The flags shown for vertical spaces and similar invisible primitives use get_name.
Typeset/Concat/concat_graphics.cpp
Graphical constraints are recognized by the type of the tag (TYPE_CONSTRAINT).
Typeset/Env/env_exec.cpp
When the evaluator expands a macro application to find an accessible subtree (edit_env_rep::expand with search_accessible), it returns the first child which is both accessible according to the DRD and attached to the source. The experimental evaluator has the same logic in
Style/Evaluate/evaluate_macro.cpp
.
Data/Tree/tree_cache.cpp
Only images with regular type are cached for client/server communication.
Data/Tree/tree_modify.cpp
correct_node replaces trees with a wrong arity by the empty string (for tags which the DRD describes).
Data/Tree/tree_correct.cpp
drd_correct (drd, t) does the same recursively for an explicit DRD. The correctors for superfluous with, invisible operators, homoglyphs and missing document tags track the mode of each child through get_env_child and decide which children may be rewritten by their type (is_correctable_child in
tree_analyze.cpp
). They run under with_drd drd (get_document_drd (t)).
Data/Tree/tree_brackets.cpp
,
tree_math_stats.cpp
Bracket upgrading and math statistics follow the mode of children.
Data/Tree/tree_analyze.cpp
is_with_like; symbol_type classifies symbols of mathematical formulas using get_syntax.
System/Language/packrat_serializer.cpp
The packrat parser serializes formulas for parsing; a tag with a syntax attribute, or a macro, is serialized as its syntax (get_syntax (t, p)), which is how user macros take part in mathematical grammar checking.
System/Language/dictionary.cpp
The translation of menu and dialog texts (tree_translate) only translates accessible children.
Data/Convert/Verbatim/verbatim.cpp
Conversion to plain text outputs accessible children only (the_drd), and uses std_drd->get_env_child for the mode.
Data/Convert/Tex/fromtex_post.cpp
The result of LaTeX import is cleaned with drd_correct (std_drd, t).
Data/Convert/AI/compress.cpp
compress_tree only rewrites accessible children in text mode and the current language.
The LaTeX exporter computes the mode of every subtree with tree-child-env (compute-mode-stats in
convert/latex/tmtex.scm
); most converters otherwise rely on Scheme tables declared with the logic engine rather than on the C++ DRD.