Fix
[texmacs.git] / internal / reports / xlink.tm
blobecd60ce15eca08f81f6652240e2dcc57d9d632ab
1 <TeXmacs|1.0.3.7>
3 <style|tmdoc>
5 <\body>
6   <\make-title>
7     <title|Extended linking in <TeXmacs>>
9     <author|Joris van der Hoeven>
10   </make-title>
12   <section|Introduction>
14   The development of a robust linking system for <TeXmacs> is important for
15   many aspects of the program:
17   <\itemize>
18     <item>Usual labels, references, hyperlinks, actions.
20     <item>Links to automatically generated content (citations, tables of
21     contents, indexes, <abbr|etc.>).
23     <item>Multi-document editing.
25     <item>Observers (used to observe a resource which is subject to change);
26     may be used for automatically generated output from computer algebra or
27     proof systems.
29     <item>Spreadsheeds.
31     <item>Document enrichment with automatically generated links (Wiki) or
32     third party links.
34     <item>Document extraction based on typing information and litterate
35     programming.
37     <item>Typed links for annotation, documentation traversal information,
38     contextual browsing, <abbr|etc.>
40     <item>Collaborative editing.
41   </itemize>
43   Our approach is similar to <name|Xlink> in several respects, but it differs
44   at certain points:
46   <\itemize>
47     <item>Since <TeXmacs> is not attribute-based, <name|Xlink> attributes
48     correspond to tags, which can either be used in an attribute-like fashion
49     or in the content itself (using the concept of the current englobing
50     locus).
52     <item>Local and distant resources (<verbatim|xlink:resource> and
53     <verbatim|xlink:locator>) correspond to different types of ``loci''. In
54     contrast to <name|Xlink>, a locus identifies both a place and the
55     corresponding (linking) environment. In particular, linkbases can be
56     considered as special cases of loci.
58     An alternative implementation would be to consider linkbases as different
59     objects and to provide markup for associating a linkbase to a locus, or
60     to link a locus to its corresponding linkspace using a link with a
61     special role.
63     <item><TeXmacs> does not distinguish between extended links, simple links
64     and arcs. Links are merely relations between a finite named set of loci,
65     according to a given set of roles. In particular, the special arc
66     properties like <verbatim|xlink:show> and <verbatim|xlink:actuate> are
67     part of the role.
69     <item>Roles are not merely containers with a mere pointer to an informal
70     description. Instead, a tentative is made to invent markup which
71     describes the behaviour of a role. Additional behaviour may be defined in
72     plug-ins.
73   </itemize>
75   <section|Loci>
77   A locus is a well-identified portion of content which can participate in a
78   link. A locus can either be
80   <\enumerate>
81     <item>Part of a local document.
83     <item>Part of a distant document.
85     <item>Part of some automatically generated data.
87     <item>A container for linking data.
88   </enumerate>
90   Several properties are attached to the locus: a unique identifier and one
91   or several names, one or several roles and the linking context for the
92   locus.
94   <\explain>
95     <explain-macro|locus|attr_1|<with|mode|math|\<cdots\>>|attr_n|content>
97     <explain-macro|resource|attr_1|<with|mode|math|\<cdots\>>|attr_n>
99     <explain-macro|data|attr_1|<with|mode|math|\<cdots\>>|attr_n|content>
101     <explain-macro|linkspace|attr_1|<with|mode|math|\<cdots\>>|attr_n>
102   <|explain>
103     Declare a locus of one of the four above types and encapsulate the
104     <src-arg|content> (when specified) in the locus. The attributes are
105     instructions for attaching properties to the locus.
107     These instructions may also be specified <em|inside> the content (for
108     instance, a theorem inside a locus may add a role <verbatim|theorem> to
109     the locus, as well as data with the theorem number and the page number).
111     Notice that loci may be nested. In that case, the inner locus inherits
112     the linking properties from the outer locus (unless otherwise specified
113     using the <verbatim|autonomous> role (opposite of <verbatim|inherit>))
114     and vice versa (unless otherwise specified using the <verbatim|private>
115     role (opposite of <verbatim|public>); in the case of data loci,
116     <verbatim|private> is default).
117   </explain>
119   The following instructions specify properties for the locus. In addition,
120   one may use the <markup|data> and <markup|linkspace> instructions as well
121   as the <markup|link> and <markup|role> instructions from the next sections.
123   <\explain>
124     <explain-macro|locus-id|id>
126     <explain-macro|locus-label|id>
127   <|explain>
128     Specify a name for the locus. In the case of <markup|locus-id>, the
129     identifier <src-arg|id> must be unique in the englobing locus (which
130     defaults to the entire document when there is no englobing locus).
132     For the moment, we require the specification of unique identifiers for
133     efficiency purposes. In the future, unique identifiers should be
134     automatically generated, and the <markup|locus-id> primitive will become
135     obsolete.
137     When used as an attribute, one may use <src-arg|id> instead of
138     <explain-macro|locus-id|id>.
139   </explain>
141   <\explain>
142     <explain-macro|locus-role|id>
143   <|explain>
144     Specify a role for the locus. Roles are used to associate properties to
145     loci which may be exploited when browsing or for other purposes. Built-in
146     roles are <verbatim|autonomous>, <verbatim|inherit>, <verbatim|public>
147     and <verbatim|private>.
148   </explain>
150   <\explain>
151     <explain-macro|locus-href|href>
152   <|explain>
153     For use in <markup|resource> loci only. The <src-arg|href> specifies a
154     way to retrieve the resource. Hyperlinks may either be
156     <\itemize>
157       <item>Identifiers for other loci.
159       <item>Standard hyperlinks of the form <explain-macro|url|url>.
161       <item>An expression <explain-macro|follow|href_1|id|role_1|<with|mode|math|\<cdots\>>|role_n>
162       intended to follow any link which matches all roles to a locus with
163       identifier <src-arg|id>.
165       <item>An expression <explain-macro|union|href_1|<with|mode|math|\<cdots\>>|href_n>
166       for specifying a union of resources.
168       <item>An expression <explain-macro|execute|href|data> for resources
169       which are the result of the evaluation of a program, a form or a query
170       on <src-arg|data>.
171     </itemize>
172   </explain>
174   <\section>
175     Links
176   </section>
178   A link associates an arbitrary number of loci. It may specify one or
179   several roles which specify the behaviour of the link (browsing behaviour,
180   editing behaviour, typesetting behaviour, <abbr|etc.>).
182   <\explain>
183     <explain-macro|link|attr_1|<with|mode|math|\<cdots\>>|attr_n>
184   <|explain>
185     Declare a link between several loci. The attributes are instructions for
186     attaching properties to the link.
187   </explain>
189   The following instructions may be used to specify properties of the links:
191   <\explain>
192     <explain-macro|link-label|id>
193   <|explain>
194     Specify an identifier for the link which may be used to refer to links.
195   </explain>
197   <\explain>
198     <explain-macro|link-part|id|href>
199   <|explain>
200     Specify a part of the link with symbolic name <src-arg|id> and which
201     points to <src-arg|href> (recall that <src-arg|href> may be the
202     identifier of an other locus). The parts which are required for a given
203     link depend on the roles of the link. Standard links with role
204     <verbatim|standard> require <verbatim|src> and <verbatim|dest> parts
205     (which correspond to the values of <src-arg|id>). When a part of a link
206     which is required for a given role is not present, then its destination
207     defaults to the current locus.
208   </explain>
210   <\explain>
211     <explain-macro|link-role|id>
212   <|explain>
213     Specify a role for the link. Roles are used to associate properties to
214     links which may be exploited when browsing or for other purposes.
215     Built-in roles are
217     <\description>
218       <item*|<verbatim|standard>>Standard hyperlinks.
220       <item*|<verbatim|arc>>Standard links, but without any indication on how
221       to display or traverse the link.
223       <item*|<verbatim|full>>Link all parts in the link.
225       <item*|<verbatim|import>>Make all valid links for a source locus valid
226       in a destination locus.
228       <item*|<verbatim|access>>Automatic links from parent loci to child
229       loci.
230     </description>
232     Users may provide roles like <verbatim|><verbatim|bidirectional> for
233     bidirectional links or <verbatim|apply>, for applications of a theorem,
234     <verbatim|replace> for replacing the source of a link by the contents of
235     its destination, <abbr|etc.>
236   </explain>
238   <section|Roles>
240   Users may define new roles for loci and links. These roles may be abstract
241   containers with a behaviour which is defined in a plug-in. They may also
242   specify special properties for the role or additional constraints on the
243   role. Locus roles and link roles which are not speci
245   <\explain>
246     <explain-macro|role|attr_1|<with|mode|math|\<cdots\>>|attr_n>
247   <|explain>
248     Declare a role. The attributes are instructions for attaching properties
249     to the role.
250   </explain>
252   The following instructions may be used to specify properties of roles:
254   <\explain>
255     <explain-macro|role-label|id>
256   <|explain>
257     Associate one or several names to the role.
258   </explain>
260   <\explain>
261     <explain-macro|role-url|href>
262   <|explain>
263     Link to a page with an informal description of this role.
264   </explain>
266   <\explain>
267     <explain-macro|role-model|id>
268   <|explain>
269     [For link roles] The linking structure of the locus with name
270     <src-arg|id> is taken as model for the linking structure of this role.
271     For simple link structures, the locus would typically be a small
272     autonomous locus. For instance, if the locus <verbatim|bidi> defines
273     subloci <verbatim|src> and <verbatim|dest> with standard hyperlinks from
274     <verbatim|src> to <verbatim|dest> and vice versa, then
275     <inactive*|<role|<role-label|bidirectional>|<role-model|bidi>>> would
276     define a role for bidirectional links. The subloci <verbatim|src> and
277     <verbatim|dest> of <verbatim|bidi> become required parts of bidirectional
278     links.
279   </explain>
281   <\explain>
282     <explain-macro|role-require|cond_1|<with|mode|math|\<cdots\>>|cond_n>
283   <|explain>
284     [For link roles] Specify (disjunctive) conditions for this link to be
285     valid. The conditions are checked one by one for the set of candidate
286     links. As soon as one condition is met by a non-empty subset of the set
287     of candidate links, this non-empty subset is returned.
289     For example, assume that we have two documents which are available in
290     several languages: <verbatim|welcome.en.tm>, <verbatim|welcome.fr.tm>,
291     <verbatim|welcome.es.tm>, <verbatim|details.en.tm> and
292     <verbatim|details.fr.tm>. Given a link <verbatim|welcome>
293     <with|mode|math|\<rightarrow\>> <verbatim|details>, we have 6 matching
294     links. The first condition may check whether the languages of the source
295     and destination languages coincide (the languages may either be roles or
296     data associated to loci). A second condition may check whether the
297     destination language is English. A third condition might always evaluate
298     to <verbatim|true>.
300     In a similar way, one may define conditions which privilege ``close
301     links'' to ``distant links''.
303     The markup for specifying conditions still has to be designed. We should
304     probably rely on plug-ins. We may also provide markup for simple tests on
305     matching roles or loci.
306   </explain>
308   <\explain>
309     <explain-macro|role-show|when>
311     <explain-macro|role-actuate|when>
312   <|explain>
313     Hints for how to render the link and when the link should be traversed
314     (see <verbatim|xlink>).
315   </explain>
317   <section|Implementation>
319   All loci currently known to the editor (with the associated links) are
320   stored in a (probably hierarchically ordered) ``loci space'', which should
321   be considered as a database. Each locus has a unique identifier in this
322   database. The database is constructed during the typesetting phase.
324   <paragraph|Unique identifiers>Each document (or view) has a unique
325   identifier. Two ways are provided for associating unique identifiers to
326   loci:
328   <\itemize>
329     <item>The user specifies a unique id in the englobing locus (which will
330     be prefixed by the unique id of the englobing locus so as to yield a
331     global unique id).
333     <item>The id is automatically determined using a counter relative to the
334     englobing locus.
335   </itemize>
337   The second method may be expensive when the englobing locus is large, since
338   it may modify the environment. In the far future, we should associate
339   unique ids to nodes of lazy rewriters.
341   <paragraph|Updating>Loci which are no longer present may still remain in
342   the database and references to newly modified loci may be incorrect. When
343   an entire document is being typeset, we have to do several things:
345   <\itemize>
346     <item>Move all loci for the current document to a shadow space (where
347     they are kept during the typesetting) and remove them when typesetting is
348     done.
350     <item>Collect all couples (reference, value) which are encountered during
351     the typesetting in an auxiliary document. At the end, test whether the
352     values are still correct. If not, then it may be necessary to retypeset
353     the document.
354   </itemize>
356   <paragraph|The environment>
358   <\description>
359     <item*|<src-var|locus-current>>The unique identifier of the current locus
360     in the database.
362     <item*|<src-var|locus-nr>>For the automatic generation of a identifiers
363     for subloci.
365     <item*|<src-var|locus-contents>>The contents of the locus, except for
366     subloci, which are entered directly into the database.
367   </description>
369   Each of the environment variables is locally redefined for each
370   locus/sublocus. Notice that <markup|locus>, <markup|resource>,
371   <markup|data> and <markup|linkspace> directly affect the linkspace (and not
372   much the environment unless an identifier is automatically generated). All
373   other linking primitives are directly entered into
374   <src-var|locus-contents>. They are entered into the linkspace together with
375   the englobing locus.
377   <paragraph|Saving>When saving, all loci relative to the current document
378   are collected and saved (without uodating). When loading, they are
379   immediately entered in the database. Notice that the global variable
380   <src-var|locus-contents> should also be saved.
382   <paragraph|Automatic loci>Besides loci which are specified by the user,
383   <TeXmacs> may also automatically generate new loci (with or without data).
384   For instance, output from computer algebra systems might be stored in
385   auxiliary loci before inclusion (via copying or linking) into documents.
386   Similarly, a shared context with a proof system might be stored at an
387   auxiliary locus. For these purposes, it may be useful to associate
388   persistent unique identifiers to processes. This makes it possible to
389   recognize the execution of the same program at a different time or
390   computer.
392   <paragraph|The linkspace and link resolution>In its brute form, the link
393   space is a collection of loci with unique identifiers and such that each
394   locus defines a set of locus properties including the links.
396   In order to quickly resolve links, it is necessary to (incrementally)
397   compute a contracted version of the linkspace from which it is clear which
398   loci and links are valid at a certain locus. For this, we will use the
399   postulate that environment importation is always transitive. More
400   precisely, we need to maintain a table which associates to each locus
401   <with|mode|math|L> its ``cyclic closure'', <abbr|i.e.> the set of all loci
402   <with|mode|math|L<rprime|'>> such that <with|mode|math|L> depends on
403   <with|mode|math|L<rprime|'>> and vice versa, and the induced uncyclic graph
404   structure on this table, which we expect (hope) to be simple in practice.
405   As a consequence, we have a fast decision procedure for knowing whether a
406   given locus or link is visible inside a given other locus.
408   Next, for each name, we maintain the list of loci/links/roles in which it
409   participates and vice versa. Assume that we need the list of links for a
410   given locus. Then we first lookup the list of names for the locus and next
411   the list of links participating in one of the names. Next, we filter out
412   the links so as the keep only those which are visible in the locus. Next,
413   we lookup the roles of each remaining link, which amounts to further
414   filtering (<abbr|cf.> <markup|role-require>). The remaining links are ready
415   to be used for rendering or navigation.
417   <\remark>
418     Notice that importation of linking context may be subject to additional
419     restrictions: it is reasonable to require links with the
420     <verbatim|import> role to be outbound and defined in the locus (except
421     for publicly exported context to parent loci). This restriction may make
422     it easier to maintain the ``cyclic reduction graph'' in an incremental
423     way.
425     In practice, explicit context importation should only be used at a few
426     places (<abbr|i.e.> at the document level or in a few dedicated special
427     tags). During the incremental cyclic closure computations it is then
428     mainly necessary to keep track of the <verbatim|public>,
429     <verbatim|private>, <verbatim|autonomous> and <verbatim|inherit> roles of
430     loci.
431   </remark>
432 </body>
434 <\initial>
435   <\collection>
436     <associate|language|english>
437     <associate|page-bot|30mm>
438     <associate|page-even|30mm>
439     <associate|page-odd|30mm>
440     <associate|page-reduce-bot|15mm>
441     <associate|page-reduce-left|25mm>
442     <associate|page-reduce-right|25mm>
443     <associate|page-reduce-top|15mm>
444     <associate|page-right|30mm>
445     <associate|page-top|30mm>
446     <associate|page-type|a4>
447     <associate|par-width|150mm>
448   </collection>
449 </initial>