6 <expand|tmdoc-title|The boxes produced by the typesetter>
10 The <apply|TeXmacs> typesetter essentially translates a document
11 represented by a tree into a graphical box, which can either be displayed
12 on the screen or on a printer. Contrary to a system like <apply|LaTeX>, the
13 graphical box actually contains much more information than is necessary for
14 a graphical rendering. Roughly speaking, this information can be subdivided
15 into the following categories:
18 <item>Logical and physical bounding boxes.
20 <item>A method for graphical rendering.
22 <item>Miscellaneous typesetting information.
24 <item>Keeping track of the source subtree which led to box.
26 <item>Computing the positions of cursors and selections.
28 <item>Event handlers for dynamic content.
31 The logical bounding box is used by the typesetter to position the box with
32 respect to other boxes. A certain amount of other information, such as the
33 slant of the box, is also stored for the typesetter. The physical bounding
34 box encloses the graphical representation of the box. This knowledge is
35 needed when partially redrawing a box in an efficient way.
37 In order to position the cursor or when making a selection, it is necessary
38 to have a correspondence between logical positions in the source tree and
39 physical positions in the typesetted boxes. More precisely, boxes and their
40 subboxes are logically organized as a tree. Boxes provide routines to
41 translate between paths in the box tree and the source tree and to find the
42 path which is associated to a graphical point.
44 <section|The correspondence between a box and its source>
46 <subsection|Discussion of the problems being encountered>
48 In order to implement the correspondence between paths in the source tree
49 and the box tree, one has to face several simultaneous difficulties:
52 <item>Due to line breaking, footnotes and macro expansions, the
53 correspondence may be non straightforward.
55 <item>The correspondence has to be reasonably time and space efficient.
57 <item>Some boxes, such header and footers, or certain results of macro
58 expansions, may not be ``accessible''. Although one should be able to
59 find a reasonable cursor position when clicking on them, the contents of
60 this box can not be edited directly.
62 <item>The correspondence has to be reasonably complete (see the next
66 The first difficulty forces us to store a path in the source tree along
67 with any box. In order to save storage, this path is stored in a reversed
68 manner, so that common heads can be shared. This common head sharing is
69 also necessary to quickly change the source locations when modifying the
70 source tree, for instance by inserting a new paragraph.
72 In order to cope with the third difficulty, the inverse path may start with
73 a negative number, which indicates that the box can not directly be edited
74 (we also say that the box is a decoration). In this case, the tail of the
75 inverse path corresponds to a location in the source tree, where the cursor
76 should be positioned when clicking on the box. The negative number
77 influences the way in which this is done.
79 <subsection|The three kinds of paths>
81 More precisely, we have to deal with three kinds of paths:
84 <expand|item*|Tree paths.>These paths correspond to paths in the source
85 tree. Actually, the path minus its last item points to a subtree of the
86 source tree. The last item gives a position in this subtree: if the
87 subtree is a leaf, i.e. a string, it is a position in this string.
88 Otherwise a zero indicates a position before the subtree and a one a
89 position after the subtree.
91 <expand|item*|Inverse paths.>These are just reverted tree paths (with
92 shared tails), with an optional negative head. A negative head indicates
93 that the tree path is not accessible, i.e. the corresponding subtree does
94 not correspond to editable content. If the negative value is
95 <with|mode|math|-2>, <with|mode|math|-3> or <with|mode|math|-4>, then a
96 zero or one has to be put behind the tree path, depending on the value
97 and the cursor position.
99 <expand|item*|Box paths.>These paths correspond to logical paths in the
100 box tree. Again, the path minus its last item points to a subbox of the
101 main box, and the last item gives a position in this subtree: if the
102 subbox corresponds to a text box it is a position in this text. Otherwise
103 a zero indicates a position before the subbox and a one a position after
104 it. In the case of side boxes, a two and a three may also indicate the
105 position after the left script resp. before the right script.
108 <subsection|The conversion routines>
110 In order to implement the conversion between the three kinds of paths,
111 every box comes with a reference inverse path <verbatim|ip> in the source
112 tree. Composite boxes also come with a left and a right inverse path
113 <verbatim|lip> resp. <verbatim|rip>, which correspond to the left-most and
114 right-most accessible paths in its subboxes (if there are such subboxes).
119 \ \ \ \ virtual path box_rep::find_tree_path (path bp)
122 transforms a box path into a tree path. This routine (which only uses
123 <verbatim|ip>) is fast and has a linear time complexity as a function of
124 the lengths of the paths. The routine:\
127 \ \ \ \ virtual path box_rep::find_box_path (path p)
130 does the inverse conversion. Unfortunately, in the worst case, it may be
131 necessary to search for the matching tree path in all subboxes.
132 Nevertheless, in the best case, a dichotomic algorithm (which uses
133 <verbatim|lip> and <verbatim|rip>), finds the right branch how to descend
134 in a logarithmic time. This algorithm also has a quadratic time complexity
135 as a function of the lengths of the paths, because we frequently need to
138 <section|The cursor and selections>
140 In order to fulfill the requirement of being a ``structured editor'',
141 <apply|TeXmacs> needs to provide a (reasonably) complete correspondence
142 between logical tree paths and physical cursor positions. This yields an
143 additional difficulty in the case of ``environment changes'', such as a
144 change in font or color. Indeed, when you are on the border of such a
145 change, it is not clear <with|font shape|italic|a priori> which environment
148 In <apply|TeXmacs>, the cursor position therefore contains an
149 <with|mode|math|x> and a <with|mode|math|y> coordinate, as well as an
150 additional infinitesimal <with|mode|math|x>-coordinate, called
151 <with|mode|math|\<delta\>>. A change in environment is then represented by
152 a box with an infinitesimal width. Although the
153 <with|mode|math|\<delta\>>-position of the cursor is always zero when you
154 select using the mouse, it may be non zero when moving around using the
155 cursor keys. The linear time routine:\
158 \ \ \ \ virtual path box_rep::find_box_path (SI x, SI y, SI delta)
161 as a function of the length of the path searches the box path which
162 corresponds to a cursor position. Inversely, the routine:\
165 \ \ \ \ virtual cursor box_rep::find_cursor (box bp)
168 yields a graphical representation for the cursor at a certain box path. The
169 cursor is given by its <with|mode|math|x>, <with|mode|math|y> and
170 <with|mode|math|\<delta\>> coordinates and a line segment relative to this
171 origin, given by its extremities <with|mode|math|(x<rsub|1>,y<rsub|1>)> and
172 <with|mode|math|(x<rsub|2>,y<rsub|2>)>.
174 In a similar way, the routine:\
177 \ \ \ \ virtual selection box_rep::find_selection (box lbp, box rbp)
180 computes the selection between two given box paths. This selection
181 comprises two delimiting tree paths and a graphical representation in the
182 form of a list of rectangles.
184 <apply|tmdoc-copyright|1998--2002|Joris van der Hoeven>
186 <expand|tmdoc-license|Permission is granted to copy, distribute and/or
187 modify this document under the terms of the GNU Free Documentation License,
188 Version 1.1 or any later version published by the Free Software Foundation;
189 with no Invariant Sections, with no Front-Cover Texts, and with no
190 Back-Cover Texts. A copy of the license is included in the section entitled
191 "GNU Free Documentation License".>
196 <associate|paragraph width|150mm>
197 <associate|odd page margin|30mm>
198 <associate|shrinking factor|4>
199 <associate|page right margin|30mm>
200 <associate|page top margin|30mm>
201 <associate|reduction page right margin|25mm>
202 <associate|page type|a4>
203 <associate|reduction page bottom margin|15mm>
204 <associate|even page margin|30mm>
205 <associate|reduction page left margin|25mm>
206 <associate|page bottom margin|30mm>
207 <associate|reduction page top margin|15mm>
208 <associate|language|english>
214 <associate|idx-1|<tuple|<uninit>|?>>
215 <associate|toc-1|<tuple|1|?>>
216 <associate|toc-2|<tuple|2|?>>
217 <associate|idx-2|<tuple|<uninit>|?>>
218 <associate|toc-3|<tuple|2.1|?>>
219 <associate|toc-4|<tuple|2.2|?>>
220 <associate|toc-5|<tuple|2.3|?>>
221 <associate|toc-6|<tuple|3|?>>
222 <associate|toc-7|<tuple|4.|?>>
229 <vspace*|1fn><with|font series|<quote|bold>|math font
230 series|<quote|bold>|1<space|2spc>Introduction><value|toc-dots><pageref|toc-1><vspace|0.5fn>
232 <vspace*|1fn><with|font series|<quote|bold>|math font
233 series|<quote|bold>|2<space|2spc>The correspondence between a box and
234 its source><value|toc-dots><pageref|toc-2><vspace|0.5fn>
236 2.1<space|2spc>Discussion of the problems being
237 encountered<value|toc-dots><pageref|toc-3>
239 2.2<space|2spc>The three kinds of paths<value|toc-dots><pageref|toc-4>
241 2.3<space|2spc>The conversion routines<value|toc-dots><pageref|toc-5>
243 <vspace*|1fn><with|font series|<quote|bold>|math font
244 series|<quote|bold>|3<space|2spc>The cursor and
245 selections><value|toc-dots><pageref|toc-6><vspace|0.5fn>