GNU TeXmacsUser manualReferenceAboutEnglishยทDeutsch
Linking primitives

The most common linking tags, label, reference, pageref, hlink, action and include, are actually built-in macros defined in the default environment (

Typeset/Env/env_default.cpp

) in terms of the lower level primitives locus, id, link, url, script, set-binding, get-binding and include*, which are described at the end of this section. For instance, hlink is defined as

<assign|hlink|<macro|body|destination|<locus|<id|<hard-id|body>>|<link|hyperlink|<id|<hard-id|body>>|<url|destination>>|body>>>

<label|name>
(reference target)

The operand must evaluate to a literal string, it is used as a target name which can be referred to by reference, pageref and hlink tags.

Label names should be unique in a document and in a project.

Examples in this section will make references to an example label named “there”.

<label|there>

<reference|name>
(reference to a name)

The operand must evaluate to a literal string, which is the name of a label defined in the current document or in another document of the current project.

<reference|there>

The reference is typeset as the value of the variable the-label at the point of the target label. The the-label variable is set by many numbered structures: sections, figures, numbered equations, etc.

A reference reacts to mouse clicks as an hyperlink.

<pageref|name>
(page reference to a name)

The operand must evaluate to a literal string, which is the name of a label defined in the current document or in another document of the current project.

<pageref|there>

The pageref is typeset as the number of the page containing the target label. Note that page numbers are only computed when the document is typeset with page-breaking, that is not in “automatic” or “papyrus” page type.

A pageref reacts to mouse clicks as an hyperlink.

<hlink|content|url>
(inline hyperlink)

This primitive produces an hyperlink with the visible text content pointing to url. The content is typeset as inline url. The url must evaluate to a literal string in URL syntax and can point to local or remote documents, positions inside documents can be be specified with labels.

The following examples are typeset as hyperlinks pointing to the label “there”, respectively in the same document, in a document in the same directory, and on the web.

<hlink|same document|#there>

<hlink|same directory|file.tm#there>

<hlink|on the web|http://example.org/#there>

If the document is not editable, the hyperlink is traversed by a simple click, if the document is editable, a double-click is required.

<include|url>
(include another document)

The operand is evaluated and interpreted as a file name, relative to the current document. The body of this file is typeset in place of the include tag, which must be placed in block context. The include tag is a built-in macro which expands to <include*|url>; the include* primitive loads the file (edit_env_rep::rewrite in

Typeset/Env/env_exec.cpp

) and refuses to include the current document itself.

<action|content|script>

<action|content|script|arg-1|\(\cdots\)|arg-n>
(attach an action to content)

Bind a Scheme script to a mouse click on content (as for hyperlinks, a double click is needed in editable documents). Optional arguments arg-1 until arg-n are passed to the script; they are transmitted through find-accessible, so that the script receives the accessible document subtrees which correspond to them. For instance, when clicking here, you may launch an xterm. This action is encoded by

<action|here|(lambda () (system "xterm &"))>

When clicking on actions, the user is usually prompted for confirmation, so as to avoid security problems. The user may control the desired level of security in Edit\(\rightarrow\)Preferences\(\rightarrow\)Security. Programmers may also declare certain Scheme routines to be “secure”. Scheme programs which only use secure routines are executed without confirmation from the user.

Low level linking primitives
<locus|link-1|\(\cdots\)|link-n|body>
(linkable content)

Typeset body and declare it as a locus, that is, a part of the document which participates in links. Each of the arguments link-1 until link-n is evaluated and should be an identifier <id|name>, a link <link|type|participant-1|\(\cdots\)|participant-n> or an observer <observer|id|call-back>. The identifiers and links are registered in the linking environment of the editor, and the body is rendered as an active hyperlink region (concater_rep::typeset_locus in

Typeset/Concat/concat_active.cpp

).

<id|name>
(identifier of a locus)

Represents the unique identifier name of a locus. Identifiers are usually generated by hard-id, or derived from the names of labels (the label macro uses <id|<merge|#|Id>> as an anchor).

<hard-id>

<hard-id|content>
(unique identifier)

Evaluates to a string which uniquely identifies content (or, without argument, the current typesetting environment). The identifier is computed from the memory addresses of the typesetting environment and of the source subtree obtained by expanding content (see find-accessible), so it should never be stored in documents.

<link|type|participant-1|\(\cdots\)|participant-n>
(typed link)

Declares a link of a given type (like hyperlink, action or anchor) between the participants participant-1 until participant-n. The participants are identifiers (id), urls (url) or scripts (script). A link only has an effect when it occurs as one of the first arguments of a locus.

<url|destination>

<url|destination|location>
(link destination)

Represents an external or internal destination, in URL syntax, as a participant of a link.

<script|function|arg-1|\(\cdots\)|arg-n>
(script to be executed)

Represents a Scheme function, together with its arguments, as a participant of a link. The function and the arguments are evaluated.

<observer|id|call-back>
(call-back on changes)

When used as an argument of locus, register the locus under the identifier id, together with the name of a Scheme call-back function which is invoked by the linking environment. The call-back is only registered if it is secure.

<relay|content|arg-1|\(\cdots\)|arg-n>
(relay events)

Typeset content inside a special box which transmits the (evaluated) arguments arg-1 until arg-n together with the mouse and keyboard events it receives.

<set-binding|key|value>

<set-binding|value>
(bind a label)

The first form associates the evaluated value to the label key, together with the current page number; this binding is later retrieved by get-binding. The label macro is defined as a locus containing <set-binding|Id|the-label>. The second form binds value to all the keys which have been accumulated in the the-tags environment variable (see the tag macro), and sets the-label to value. Bindings which are made in an included file or in another part of a project also remember the corresponding location. When evaluated, set-binding returns an internal hidden-binding tag.

<get-binding|key>

<get-binding|key|kind>
(retrieve a binding)

Returns the value associated to the label key. When kind is 1, the page number of the label is returned instead. The reference and pageref macros are implemented using <get-binding|Id> and <get-binding|Id|1>. Undefined labels are recorded as missing references when the warn-missing variable is set.

<has-binding|key>

<has-binding|key|kind>
(test for a binding)

Returns true if a value (or a page number, when kind is 1) is associated to the label key, and false otherwise.

<get-attachment|name>
(retrieve auxiliary data)

Returns the auxiliary data attached to the current document (or the master document of the project) under the given name.

<toc-notify|kind|title>
(table of contents entry for the viewer)

Produces an invisible box which informs the renderer about a sectional entry of a given kind with a given title. It is used by the PDF renderer for generating the outline (bookmarks) of exported documents.

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