GNU TeXmacsUser manualReferenceAboutEnglish
Links, loci and references

1.Introduction

TeXmacs has a general linking mechanism which goes well beyond hyperlinks. Any piece of a document can be turned into a locus, that is, a fragment which carries one or more identifiers; links are typed tuples whose vertices are identifiers, URLs or scripts. Hyperlinks, labels and references, actions, the tooltips which preview a reference, the colouring of visited links, the synchronization of “mirror” copies, the notification of modifications of whole buffers to Scheme and the navigation between documents are all built on this single mechanism.

This chapter describes the mechanism as seen from the source code: the C++ registry which maps identifiers to trees and trees to links, the way the typesetter registers loci and the editor reacts to them, the Scheme code which creates links and follows them, and the separate but closely related machinery of labels and references. The primitives themselves (locus, id, link, url, script, observer, hard-id, set-binding, …) are documented for authors in linking primitives, and the security rules for scripts in links in scripts and security.

2.Overview

The main objects are:

Locus

A locus tag (locus a1 … an body) whose arguments a1, …, an are identifiers (id name), links (link type v1 …) or observers (observer name callback). The standard macros label, reference, pageref, hlink and action expand to loci.

Identifier

A string. It names one or more subtrees of open documents. Several naming schemes coexist: unique identifiers +… created by create-unique-id, “hard” identifiers %… computed by hard-id from memory addresses, identifiers &… for loci whose body is not accessible, and buffer names for the buffer notifier.

Link

A tree (link type attrs v1 … vn) (the attributes are added by the typesetter). Each vertex is (id name), (url dest) or (script fun args…). The type (for instance hyperlink, anchor, action, mouse-over, focus, mirror) decides how the link is followed.

Link repository

An object which owns a set of loci and links and registers them in the global tables while it lives. Each bridge of the typesetter has one, so loci exist exactly as long as the corresponding part of the document is typeset.

The data flow is:

document tree
  | typesetting (build_locus)
  v
link_repository of each bridge
  | registers
  v
id -> tree pointers, tree -> ids, vertex -> links
  | queried by
  v
editor: ids under the mouse and the cursor
  | link-follow-ids
  v
Scheme: go-to-id, go-to-url, scripts

Labels and references use loci for navigation, but their numbers are stored elsewhere: in the reference table ref of the buffer data, filled during typesetting by set-binding.

3.Source files

Data/Observers/link.hpp
,
link.cpp

The classes soft_link and link_repository, the global tables, the navigation queries (get_ids, get_trees, get_links), visited loci and locus rendering preferences, and the propagation of modifications through mirror links (link_announce).

Data/Observers/tree_pointer.cpp

The observer which keeps pointing to a locus while the document is edited, with an optional Scheme callback (tree_pointer, scheme_observer).

Typeset/Concat/concat_active.cpp

build_locus, which registers the identifiers and links of a locus and chooses its colour, and the inline typesetting of loci (typeset_locus, typeset_set_binding).

Typeset/Bridge/bridge.cpp
,
bridge_surround.cpp
,
bridge_locus.cpp
,
Typeset/Line/lazy_typeset.cpp

The per-bridge link repositories and the block level typesetting of loci.

Typeset/Boxes/Modifier/change_boxes.cpp
,
Typeset/Boxes/Basic/boxes.cpp

Locus boxes, and the hyperlinks and anchors emitted when printing.

Typeset/Env/env_default.cpp
,
env_exec.cpp

The default definitions of label, reference, pageref, hlink and action; exec_hard_id, exec_set_binding, exec_get_binding.

Edit/Interface/edit_mouse.cpp
,
edit_interface.cpp
,
edit_keyboard.cpp

Active loci under the mouse and the cursor, and the calls of link-follow-ids.

Edit/Editor/edit_typeset.cpp
,
Edit/Interface/edit_cursor.cpp

The reference and auxiliary tables of the editor, search_label and go_to_label.

progs/link/locus-edit.scm

Unique identifiers and loci.

progs/link/link-edit.scm

Interactive creation and removal of links.

progs/link/link-navigate.scm

Link lists, navigation lists and following links.

progs/link/link-extern.scm

Links between files: the file registry and the link locations stored in documents.

progs/link/link-extract.scm
,
link-menu.scm
,
link-kbd.scm

Pages listing loci, environments and linked files; menus and keyboard shortcuts.

progs/link/ref-edit.scm
,
ref-markup.scm
,
ref-menu.scm

Tools for labels and references: broken references, duplicate labels, inferred references, previews, smart references.

Paths of C++ files are relative to

src/src/

, paths of Scheme files to

src/TeXmacs/

.

4.Contents of this chapter

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