sync with experimental
[luatex.git] / manual / luatex-nodes.tex
blob21f1789e5a99b08462d7b78c7b516a2876fec246
1 % language=uk
3 \environment luatex-style
4 \environment luatex-logos
6 \startcomponent luatex-nodes
8 \startchapter[reference=nodes,title={Nodes}]
10 \section{\LUA\ node representation}
12 \TEX's nodes are represented in \LUA\ as userdata object with a variable set of
13 fields. In the following syntax tables, such the type of such a userdata object
14 is represented as \syntax {<node>}.
16 The current return value of \type {node.types()} is:
17 \startluacode
18 for id, name in table.sortedhash(node.types()) do
19 context.type(name)
20 context(" (%s), ",id)
21 end
22 context.removeunwantedspaces()
23 context.removepunctuation()
24 \stopluacode
25 . % period
27 The \type {\lastnodetype} primitive is \ETEX\ compliant. The valid range is still
28 $[-1,15]$ and glyph nodes (formerly known as char nodes) have number~0 while
29 ligature nodes are mapped to~7. That way macro packages can use the same symbolic
30 names as in traditional \ETEX. Keep in mind that these \ETEX\ node numbers are
31 different from the real internal ones and that there are more \ETEX\ node types
32 than~15.
34 You can ask for a list of fields with the \type {node.fields} (which takes an id)
35 and for valid subtypes with \type {node.subtypes} (which takes a string because
36 eventually we might support more used enumerations).
38 \subsection{Attributes}
40 The newly introduced attribute registers are non|-|trivial, because the value
41 that is attached to a node is essentially a sparse array of key|-|value pairs. It
42 is generally easiest to deal with attribute lists and attributes by using the
43 dedicated functions in the \type {node} library, but for completeness, here is
44 the low|-|level interface.
46 \subsubsection{attribute_list nodes}
48 An \type {attribute_list} item is used as a head pointer for a list of attribute
49 items. It has only one user-visible field:
51 \starttabulate[|lT|l|p|]
52 \NC \rmbf field \NC \bf type \NC \bf explanation \NC \NR
53 \NC next \NC node \NC pointer to the first attribute \NC \NR
54 \stoptabulate
56 \subsubsection{attribute nodes}
58 A normal node's attribute field will point to an item of type \type
59 {attribute_list}, and the \type {next} field in that item will point to the first
60 defined \quote {attribute} item, whose \type {next} will point to the second
61 \quote {attribute} item, etc.
63 \starttabulate[|lT|l|p|]
64 \NC \rmbf field \NC \bf type \NC \bf explanation \NC \NR
65 \NC next \NC node \NC pointer to the next attribute \NC \NR
66 \NC number \NC number \NC the attribute type id \NC \NR
67 \NC value \NC number \NC the attribute value \NC \NR
68 \stoptabulate
70 As mentioned it's better to use the official helpers rather than edit these
71 fields directly. For instance the \type {prev} field is used for other purposes
72 and there is no double linked list.
74 \subsection{Main text nodes}
76 These are the nodes that comprise actual typesetting commands. A few fields are
77 present in all nodes regardless of their type, these are:
79 \starttabulate[|lT|l|p|]
80 \NC \rmbf field \NC \bf type \NC \bf explanation \NC \NR
81 \NC next \NC node \NC the next node in a list, or nil \NC \NR
82 \NC id \NC number \NC the node's type (\type {id}) number \NC \NR
83 \NC subtype \NC number \NC the node \type {subtype} identifier \NC \NR
84 \stoptabulate
86 The \type {subtype} is sometimes just a stub entry. Not all nodes actually use
87 the \type {subtype}, but this way you can be sure that all nodes accept it as a
88 valid field name, and that is often handy in node list traversal. In the
89 following tables \type {next} and \type {id} are not explicitly mentioned.
91 Besides these three fields, almost all nodes also have an \type {attr} field, and
92 there is a also a field called \type {prev}. That last field is always present,
93 but only initialized on explicit request: when the function \type {node.slide()}
94 is called, it will set up the \type {prev} fields to be a backwards pointer in
95 the argument node list. By now most of \TEX's node processing makes sure that the
96 \type {prev} nodes are valid but there can be exceptions, especially when the
97 internal magic uses a leading \type {temp} nodes to temporarily store a state.
99 \subsubsection{hlist nodes}
101 \starttabulate[|lT|l|p|]
102 \NC \rmbf field \NC \bf type \NC \bf explanation \NC \NR
103 \NC subtype \NC number \NC \showsubtypes{list} \NC \NR
104 \NC attr \NC node \NC list of attributes \NC \NR
105 \NC width \NC number \NC the width of the box \NC \NR
106 \NC height \NC number \NC the height of the box \NC \NR
107 \NC depth \NC number \NC the depth of the box \NC \NR
108 \NC shift \NC number \NC a displacement perpendicular to the character progression direction \NC \NR
109 \NC glue_order \NC number \NC a number in the range $[0,4]$, indicating the glue order \NC \NR
110 \NC glue_set \NC number \NC the calculated glue ratio \NC \NR
111 \NC glue_sign \NC number \NC 0 = \type {normal}, 1 = \type {stretching}, 2 = \type {shrinking} \NC \NR
112 \NC head/list \NC node \NC the first node of the body of this list \NC \NR
113 \NC dir \NC string \NC the direction of this box, see~\in[dirnodes] \NC \NR
114 \stoptabulate
116 A warning: never assign a node list to the \type {head} field unless you are sure
117 its internal link structure is correct, otherwise an error may result.
119 Note: the field name \type {head} and \type {list} are both valid. Sometimes it
120 makes more sense to refer to a list by \type {head}, sometimes \type {list} makes
121 more sense.
123 \subsubsection{vlist nodes}
125 This node is similar to \type {hlist}, except that \quote {shift} is a displacement
126 perpendicular to the line progression direction, and \quote {subtype} only has
127 the values 0, 4, and~5.
129 \subsubsection{rule nodes}
131 Contrary to traditional \TEX, \LUATEX\ has more subtypes because we also use
132 rules to store reuseable objects and images. User nodes are invisible and can be
133 intercepted by a callback.
135 \starttabulate[|lT|l|p|]
136 \NC \rmbf field \NC \bf type \NC \bf explanation \NC \NR
137 \NC subtype \NC number \NC \showsubtypes{rule} \NC \NR
138 \NC attr \NC node \NC list of attributes \NC \NR
139 \NC width \NC number \NC the width of the rule where the special value $-1073741824$ is used for \quote {running} glue dimensions \NC \NR
140 \NC height \NC number \NC the height of the rule (can be negative) \NC \NR
141 \NC depth \NC number \NC the depth of the rule (can be negative) \NC \NR
142 \NC dir \NC string \NC the direction of this rule, see~\in[dirnodes] \NC \NR
143 \NC index \NC number \NC an optional index that can be referred to \NC \NR
144 \stoptabulate
146 \subsubsection{ins nodes}
148 \starttabulate[|lT|l|p|]
149 \NC \rmbf field \NC \bf type \NC \bf explanation \NC \NR
150 \NC subtype \NC number \NC the insertion class \NC \NR
151 \NC attr \NC node \NC list of attributes \NC \NR
152 \NC cost \NC number \NC the penalty associated with this insert \NC \NR
153 \NC height \NC number \NC height of the insert \NC \NR
154 \NC depth \NC number \NC depth of the insert \NC \NR
155 \NC head/list \NC node \NC the first node of the body of this insert \NC \NR
156 \stoptabulate
158 There is a set of extra fields that concern the associated glue: \type {width},
159 \type {stretch}, \type {stretch_order}, \type {shrink} and \type {shrink_order}.
160 These are all numbers.
162 A warning: never assign a node list to the \type {head} field unless you are sure
163 its internal link structure is correct, otherwise an error may be result. You can use
164 \type {list} instead (often in functions you want to use local variable swith similar
165 names and both names are equally sensible).
167 \subsubsection{mark nodes}
169 \starttabulate[|lT|l|p|]
170 \NC \rmbf field \NC \bf type \NC \bf explanation \NC \NR
171 \NC subtype \NC number \NC unused \NC \NR
172 \NC attr \NC node \NC list of attributes \NC \NR
173 \NC class \NC number \NC the mark class \NC \NR
174 \NC mark \NC table \NC a table representing a token list \NC \NR
175 \stoptabulate
177 \subsubsection{adjust nodes}
179 \starttabulate[|lT|l|p|]
180 \NC \rmbf field \NC \bf type \NC \bf explanation \NC \NR
181 \NC subtype \NC number \NC \showsubtypes{adjust} \NC \NR
182 \NC attr \NC node \NC list of attributes \NC \NR
183 \NC head/list \NC node \NC adjusted material \NC \NR
184 \stoptabulate
186 A warning: never assign a node list to the \type {head} field unless you are sure
187 its internal link structure is correct, otherwise an error may be result.
189 \subsubsection{disc nodes}
191 \starttabulate[|lT|l|p|]
192 \NC \rmbf field \NC \bf type \NC \bf explanation \NC \NR
193 \NC subtype \NC number \NC \showsubtypes{disc} \NC \NR
194 \NC attr \NC node \NC list of attributes \NC \NR
195 \NC pre \NC node \NC pointer to the pre|-|break text \NC \NR
196 \NC post \NC node \NC pointer to the post|-|break text \NC \NR
197 \NC replace \NC node \NC pointer to the no|-|break text \NC \NR
198 \NC penalty \NC number \NC the penalty associated with the break, normally \type {\hyphenpenalty} or \type {\exhyphenpenalty} \NC \NR
199 \stoptabulate
201 The subtype numbers~4 and~5 belong to the \quote {of-f-ice} explanation given
202 elsewhere.
204 These disc nodes are kind of special as at some point they also keep information
205 about breakpoints and nested ligatures. The \type {pre}, \type {post} and \type
206 {replace} fields at the \LUA\ end are in fact indirectly accessed and have a
207 \type {prev} pointer that is not \type {nil}. This means that when you mess
208 around with the head of these (three) lists, you also need to reassign them
209 because that will restore the proper \type {prev} pointer, so:
211 \starttyping
212 pre = d.pre
213 -- change the list starting with pre
214 d.pre = pre
215 \stoptyping
217 Otherwise you can end up with an invalid internal perception of reality and
218 \LUATEX\ might even decide to crash on you. It also means that running forward
219 over for instance \type {pre} is ok but backward you need to stop at \type {pre}.
220 And you definitely must not mess with the node that \type {prev} points to, if
221 only because it is not really an node but part of the disc data structure (so
222 freeing it again might crash \LUATEX).
224 \subsubsection{math nodes}
226 \starttabulate[|lT|l|p|]
227 \NC \rmbf field \NC \bf type \NC \bf explanation \NC \NR
228 \NC subtype \NC number \NC \showsubtypes{math} \NC \NR
229 \NC attr \NC node \NC list of attributes \NC \NR
230 \NC surround \NC number \NC width of the \type {\mathsurround} kern \NC \NR
231 \stoptabulate
233 There is a set of extra fields that concern the associated glue: \type {width},
234 \type {stretch}, \type {stretch_order}, \type {shrink} and \type {shrink_order}.
235 These are all numbers.
237 \subsubsection{glue nodes}
239 Skips are about the only type of data objects in traditional \TEX\ that are not a
240 simple value. The structure that represents the glue components of a skip is
241 called a \type {glue_spec}, and it has the following accessible fields:
243 \starttabulate[|lT|l|p|]
244 \NC \rmbf key \NC \bf type \NC \bf explanation \NC \NR
245 \NC width \NC number \NC the horizontal or vertical displacement \NC \NR
246 \NC stretch \NC number \NC extra (positive) displacement or stretch amount \NC \NR
247 \NC stretch_order \NC number \NC factor applied to stretch amount \NC \NR
248 \NC shrink \NC number \NC extra (negative) displacement or shrink amount\NC \NR
249 \NC shrink_order \NC number \NC factor applied to shrink amount \NC \NR
250 \stoptabulate
252 The effective width of some glue subtypes depends on the stretch or shrink needed
253 to make the encapsulating box fit its dimensions. For instance, in a paragraph
254 lines normally have glue representing spaces and these stretch of shrink to make
255 the content fit in the available space. The \type {effective_glue} function that
256 takes a glue node and a parent (hlist or vlist) returns the effective width of
257 that glue item.
259 A gluespec node is a special kind of node that is used for storing a set of glue
260 values in registers. Originally they were also used to store properties of glue
261 nodes (using a system of reference counts) but we now keep these properties in
262 the glue nodes themselves, which gives a cleaner interface to \LUA.
264 The indirect spec approach was in fact an optimization in the original \TEX\
265 code. First of all it can save quite some memory because all these spaces that
266 become glue now share the same specification (only the reference count is
267 incremented), and zero testing is also a bit faster because only the pointer has
268 to be checked (this is no longer true for engines that implement for instance
269 protrusion where we really need to ensure that zero is zero when we test for
270 bounds). Another side effect is that glue specifications are read|-|only, so in
271 the end copies need to be made when they are used from \LUA\ (each assignment to
272 a field can result in a new copy). So in the end the advantages of sharing are
273 not that high (and nowadays memory is less an issue, also given that a glue node
274 is only a few memory words larger than a spec).
276 \starttabulate[|lT|l|p|]
277 \NC \rmbf field \NC \bf type \NC \bf explanation \NC \NR
278 \NC subtype \NC number \NC \showsubtypes{glue} \NC \NR
279 \NC attr \NC node \NC list of attributes \NC \NR
280 \NC leader \NC node \NC pointer to a box or rule for leaders \NC \NR
281 \stoptabulate
283 In addition there are the \type {width}, \type {stretch} \type {stretch_order},
284 \type {shrink}, and \type {shrink_order} fields. Note that we use the key \type
285 {width} in both horizontal and vertical glue. This suits the \TEX\ internals well
286 so we decided to stick to that naming.
288 A regular word space also results in a \type {spaceskip} subtype (this used to be
289 a \type {userskip} with subtype zero).
291 \subsubsection{kern nodes}
293 \starttabulate[|lT|l|p|]
294 \NC \rmbf field \NC \bf type \NC \bf explanation \NC \NR
295 \NC subtype \NC number \NC \showsubtypes{kern} \NC \NR
296 \NC attr \NC node \NC list of attributes \NC \NR
297 \NC kern \NC number \NC fixed horizontal or vertical advance \NC \NR
298 \stoptabulate
300 \subsubsection{penalty nodes}
302 \starttabulate[|lT|l|p|]
303 \NC \rmbf field \NC \bf type \NC \bf explanation \NC \NR
304 \NC subtype \NC number \NC not used \NC \NR
305 \NC attr \NC node \NC list of attributes \NC \NR
306 \NC penalty \NC number \NC the penalty value \NC \NR
307 \stoptabulate
309 \subsubsection[glyphnodes]{glyph nodes}
311 \starttabulate[|lT|l|p|]
312 \NC \rmbf field \NC \rmbf type \NC \rmbf explanation \NC \NR
313 \NC subtype \NC number \NC bitfield \NC \NR
314 \NC attr \NC node \NC list of attributes \NC \NR
315 \NC char \NC number \NC the chatacter index in the font \NC \NR
316 \NC font \NC number \NC the font identifier \NC \NR
317 \NC lang \NC number \NC the language identifier \NC \NR
318 \NC left \NC number \NC the frozen \type {\lefthyphenmnin} value \NC \NR
319 \NC right \NC number \NC the frozen \type {\righthyphenmnin} value \NC \NR
320 \NC uchyph \NC boolean \NC the frozen \type {\uchyph} value \NC \NR
321 \NC components \NC node \NC pointer to ligature components \NC \NR
322 \NC xoffset \NC number \NC a virtual displacement in horizontal direction \NC \NR
323 \NC yoffset \NC number \NC a virtual displacement in vertical direction \NC \NR
324 \NC xadvance \NC number \NC an additional advance after the glyph (experimental) \NC \NR
325 \NC width \NC number \NC the (original) width of the character \NC \NR
326 \NC height \NC number \NC the (original) height of the character\NC \NR
327 \NC depth \NC number \NC the (original) depth of the character\NC \NR
328 \NC expansion_factor \NC number \NC the to be applied expansion_factor \NC \NR
329 \stoptabulate
331 The \type {width}, \type {height} and \type {depth} values are read|-|only. The
332 \type {expansion_factor} is assigned in the parbuilder and used in the backend.
334 A warning: never assign a node list to the components field unless you are sure
335 its internal link structure is correct, otherwise an error may be result. Valid
336 bits for the \type {subtype} field are:
338 \starttabulate[|c|l|]
339 \NC \rmbf bit \NC \bf meaning \NC \NR
340 \NC 0 \NC character \NC \NR
341 \NC 1 \NC ligature \NC \NR
342 \NC 2 \NC ghost \NC \NR
343 \NC 3 \NC left \NC \NR
344 \NC 4 \NC right \NC \NR
345 \stoptabulate
347 See \in {section} [charsandglyphs] for a detailed description of the \type
348 {subtype} field.
350 The \type {expansion_factor} has been introduced as part of the separation
351 between font- and backend. It is the result of extensive experiments with a more
352 efficient implementation of expansion. Early versions of \LUATEX\ already
353 replaced multiple instances of fonts in the backend by scaling but contrary to
354 \PDFTEX\ in \LUATEX\ we now also got rid of font copies in the frontend and
355 replaced them by expansion factors that travel with glyph nodes. Apart from a
356 cleaner approach this is also a step towards a better separation between front-
357 and backend.
359 The \type {is_char} function checks if a node is a glyph node with a subtype still
360 less than 256. This function can be used to determine if applying font logic to a
361 glyph node makes sense. The value \type {nil} gets returned when the node is not
362 a glyph, a character number is returned if the node is still tagged as character
363 and \type {false} gets returned otherwise. When nil is returned, the id is also
364 returned. The \type {is_glyph} variant doesn't check for a subtype being less
365 than 256, so it returns either the character value or nil plus the id. These
366 helpers are not always faster than separate calls but they sometimes permit
367 making more readable tests.
369 \subsubsection{boundary nodes}
371 \starttabulate[|lT|l|p|]
372 \NC \rmbf field \NC \bf type \NC \bf explanation \NC \NR
373 \NC subtype \NC number \NC \showsubtypes{boundary} \NC \NR
374 \NC attr \NC node \NC list of attributes \NC \NR
375 \NC value \NC number \NC values 0--255 are reserved \NC \NR
376 \stoptabulate
378 This node relates to the \type {\noboundary}, \type {\boundary}, \type
379 {\protrusionboundary} and \type {\wordboundary} primitives.
381 \subsubsection{local_par nodes}
383 \starttabulate[|lT|l|p|]
384 \NC \rmbf field \NC \bf type \NC \bf explanation \NC \NR
385 \NC attr \NC node \NC list of attributes \NC \NR
386 \NC pen_inter \NC number \NC local interline penalty (from \type {\localinterlinepenalty}) \NC \NR
387 \NC pen_broken \NC number \NC local broken penalty (from \type {\localbrokenpenalty}) \NC \NR
388 \NC dir \NC string \NC the direction of this par. see~\in [dirnodes] \NC \NR
389 \NC box_left \NC node \NC the \type {\localleftbox} \NC \NR
390 \NC box_left_width \NC number \NC width of the \type {\localleftbox} \NC \NR
391 \NC box_right \NC node \NC the \type {\localrightbox} \NC \NR
392 \NC box_right_width \NC number \NC width of the \type {\localrightbox} \NC \NR
393 \stoptabulate
395 A warning: never assign a node list to the \type {box_left} or \type {box_right}
396 field unless you are sure its internal link structure is correct, otherwise an
397 error may be result.
399 \subsubsection[dirnodes]{dir nodes}
401 \starttabulate[|lT|l|p|]
402 \NC \rmbf field \NC \bf type \NC \bf explanation \NC \NR
403 \NC attr \NC node \NC list of attributes \NC \NR
404 \NC dir \NC string \NC the direction (but see below) \NC \NR
405 \NC level \NC number \NC nesting level of this direction whatsit \NC \NR
406 \stoptabulate
408 A note on \type {dir} strings. Direction specifiers are three|-|letter
409 combinations of \type {T}, \type {B}, \type {R}, and \type {L}.
411 These are built up out of three separate items:
413 \startitemize[packed]
414 \startitem
415 the first is the direction of the \quote{top} of paragraphs.
416 \stopitem
417 \startitem
418 the second is the direction of the \quote{start} of lines.
419 \stopitem
420 \startitem
421 the third is the direction of the \quote{top} of glyphs.
422 \stopitem
423 \stopitemize
425 However, only four combinations are accepted: \type {TLT}, \type {TRT}, \type
426 {RTT}, and \type {LTL}.
428 Inside actual \type {dir} whatsit nodes, the representation of \type {dir} is not
429 a three-letter but a four|-|letter combination. The first character in this case
430 is always either \type {+} or \type {-}, indicating whether the value is pushed
431 or popped from the direction stack.
433 \subsubsection{margin_kern nodes}
435 \starttabulate[|lT|l|p|]
436 \NC \rmbf field \NC \bf type \NC \bf explanation \NC \NR
437 \NC subtype \NC number \NC \showsubtypes{margin_kern} \NC \NR
438 \NC attr \NC node \NC list of attributes \NC \NR
439 \NC width \NC number \NC the advance of the kern \NC \NR
440 \NC glyph \NC node \NC the glyph to be used \NC \NR
441 \stoptabulate
443 \subsection{Math nodes}
445 These are the so||called \quote {noad}s and the nodes that are specifically
446 associated with math processing. Most of these nodes contain subnodes so that the
447 list of possible fields is actually quite small. First, the subnodes:
449 \subsubsection{Math kernel subnodes}
451 Many object fields in math mode are either simple characters in a specific family
452 or math lists or node lists. There are four associated subnodes that represent
453 these cases (in the following node descriptions these are indicated by the word
454 \type {<kernel>}).
456 The \type {next} and \type {prev} fields for these subnodes are unused.
458 \subsubsubsection{math_char and math_text_char subnodes}
460 \starttabulate[|lT|l|p|]
461 \NC \rmbf field \NC \bf type \NC \bf explanation \NC \NR
462 \NC attr \NC node \NC list of attributes \NC \NR
463 \NC char \NC number \NC the character index \NC \NR
464 \NC fam \NC number \NC the family number \NC \NR
465 \stoptabulate
467 The \type {math_char} is the simplest subnode field, it contains the character
468 and family for a single glyph object. The \type {math_text_char} is a special
469 case that you will not normally encounter, it arises temporarily during math list
470 conversion (its sole function is to suppress a following italic correction).
472 \subsubsubsection{sub_box and sub_mlist subnodes}
474 \starttabulate[|lT|l|p|]
475 \NC \rmbf field \NC \bf type \NC \bf explanation \NC \NR
476 \NC attr \NC node \NC list of attributes \NC \NR
477 \NC head/list \NC node \NC list of nodes \NC \NR
478 \stoptabulate
480 These two subnode types are used for subsidiary list items. For \type {sub_box},
481 the \type {head} points to a \quote {normal} vbox or hbox. For \type {sub_mlist},
482 the \type {head} points to a math list that is yet to be converted.
484 A warning: never assign a node list to the \type {head} field unless you are sure
485 its internal link structure is correct, otherwise an error may be result.
487 \subsubsection{Math delimiter subnode}
489 There is a fifth subnode type that is used exclusively for delimiter fields. As
490 before, the \type {next} and \type {prev} fields are unused.
492 \subsubsubsection{delim subnodes}
494 \starttabulate[|lT|l|p|]
495 \NC \rmbf field \NC \bf type \NC \bf explanation \NC \NR
496 \NC attr \NC node \NC list of attributes \NC \NR
497 \NC small_char \NC number \NC character index of base character \NC \NR
498 \NC small_fam \NC number \NC family number of base character \NC \NR
499 \NC large_char \NC number \NC character index of next larger character \NC \NR
500 \NC large_fam \NC number \NC family number of next larger character \NC \NR
501 \stoptabulate
503 The fields \type {large_char} and \type {large_fam} can be zero, in that case the
504 font that is sed for the \type {small_fam} is expected to provide the large
505 version as an extension to the \type {small_char}.
507 \subsubsection{Math core nodes}
509 First, there are the objects (the \TEX book calls then \quote {atoms}) that are
510 associated with the simple math objects: ord, op, bin, rel, open, close, punct,
511 inner, over, under, vcent. These all have the same fields, and they are combined
512 into a single node type with separate subtypes for differentiation.
514 \subsubsubsection{simple nodes}
516 \starttabulate[|lT|l|p|]
517 \NC \rmbf field \NC \bf type \NC \bf explanation \NC \NR
518 \NC subtype \NC number \NC \showsubtypes{noad} \NC \NR
519 \NC attr \NC node \NC list of attributes \NC \NR
520 \NC nucleus \NC kernel node \NC base \NC \NR
521 \NC sub \NC kernel node \NC subscript \NC \NR
522 \NC sup \NC kernel node \NC superscript \NC \NR
523 \stoptabulate
525 \subsubsubsection{accent nodes}
527 \starttabulate[|lT|l|p|]
528 \NC \rmbf field \NC \bf type \NC \bf explanation \NC \NR
529 \NC subtype \NC number \NC \showsubtypes{accent} \NC \NR
530 \NC nucleus \NC kernel node \NC base \NC \NR
531 \NC sub \NC kernel node \NC subscript \NC \NR
532 \NC sup \NC kernel node \NC superscript \NC \NR
533 \NC accent \NC kernel node \NC top accent \NC \NR
534 \NC bot_accent \NC kernel node \NC bottom accent \NC \NR
535 \NC fraction \NC number \NC larger step criterium (divided by 1000) \NC \NR
536 \stoptabulate
538 \subsubsubsection{style nodes}
540 \starttabulate[|lT|l|p|]
541 \NC \rmbf field \NC \bf type \NC \bf explanation \NC \NR
542 \NC style \NC string \NC contains the style \NC \NR
543 \stoptabulate
545 There are eight possibilities for the string value: one of \quote {display},
546 \quote {text}, \quote {script}, or \quote {scriptscript}. Each of these can have
547 a trailing \type {'} to signify \quote {cramped} styles.
549 \subsubsubsection{choice nodes}
551 \starttabulate[|lT|l|p|]
552 \NC \rmbf field \NC \bf type \NC \bf explanation \NC \NR
553 \NC attr \NC node \NC list of attributes \NC \NR
554 \NC display \NC node \NC list of display size alternatives \NC \NR
555 \NC text \NC node \NC list of text size alternatives \NC \NR
556 \NC script \NC node \NC list of scriptsize alternatives \NC \NR
557 \NC scriptscript \NC node \NC list of scriptscriptsize alternatives \NC \NR
558 \stoptabulate
560 Warning: never assign a node list to the \type {display}, \type {text}, \type
561 {script}, or \type {scriptscript} field unless you are sure its internal link
562 structure is correct, otherwise an error may be result.
564 \subsubsubsection{radical nodes}
566 \starttabulate[|lT|l|p|]
567 \NC \rmbf field \NC \bf type \NC \bf explanation \NC \NR
568 \NC subtype \NC number \NC \showsubtypes{radical} \NC \NR
569 \NC attr \NC node \NC list of attributes \NC \NR
570 \NC nucleus \NC kernel node \NC base \NC \NR
571 \NC sub \NC kernel node \NC subscript \NC \NR
572 \NC sup \NC kernel node \NC superscript \NC \NR
573 \NC left \NC delimiter node \NC \NC \NR
574 \NC degree \NC kernel node \NC only set by \type {\Uroot} \NC \NR
575 \NC width \NC number \NC required width \NC \NR
576 \NC options \NC number \NC bitset of rendering options \NC \NR
577 \stoptabulate
579 Warning: never assign a node list to the \type {nucleus}, \type {sub}, \type
580 {sup}, \type {left}, or \type {degree} field unless you are sure its internal
581 link structure is correct, otherwise an error may be result.
583 \subsubsubsection{fraction nodes}
585 \starttabulate[|lT|l|p|]
586 \NC \rmbf field \NC \bf type \NC \bf explanation \NC \NR
587 \NC attr \NC node \NC list of attributes \NC \NR
588 \NC width \NC number \NC (optional) width of the fraction \NC \NR
589 \NC num \NC kernel node \NC numerator \NC \NR
590 \NC denom \NC kernel node \NC denominator \NC \NR
591 \NC left \NC delimiter node \NC left side symbol \NC \NR
592 \NC right \NC delimiter node \NC right side symbol \NC \NR
593 \NC middle \NC delimiter node \NC middle symbol \NC \NR
594 \NC options \NC number \NC bitset of rendering options \NC \NR
595 \stoptabulate
597 Warning: never assign a node list to the \type {num}, or \type {denom} field
598 unless you are sure its internal link structure is correct, otherwise an error
599 may be result.
601 \subsubsubsection{fence nodes}
603 \starttabulate[|lT|l|p|]
604 \NC \rmbf field \NC \bf type \NC \bf explanation \NC \NR
605 \NC subtype \NC number \NC \showsubtypes{fence} \NC \NR
606 \NC attr \NC node \NC list of attributes \NC \NR
607 \NC delim \NC delimiter node \NC delimiter specification \NC \NR
608 \NC italic \NC number \NC italic correction \NC \NR
609 \NC height \NC number \NC required height \NC \NR
610 \NC depth \NC number \NC required depth \NC \NR
611 \NC options \NC number \NC bitset of rendering options \NC \NR
612 \NC class \NC number \NC spacing related class \NC \NR
613 \stoptabulate
615 Warning: some of these fields are used by the renderer and might get adapted in
616 the process.
618 \subsection{whatsit nodes}
620 Whatsit nodes come in many subtypes that you can ask for by running
621 \type {node.whatsits()}:
622 \startluacode
623 for id, name in table.sortedpairs(node.whatsits()) do
624 context.type(name)
625 context(" (%s), ",id)
627 context.removeunwantedspaces()
628 context.removepunctuation()
629 \stopluacode
630 . % period
632 \subsubsection{front|-|end whatsits}
634 \subsubsubsection{open whatsits}
636 \starttabulate[|lT|l|p|]
637 \NC \rmbf field \NC \bf type \NC \bf explanation \NC \NR
638 \NC attr \NC node \NC list of attributes \NC \NR
639 \NC stream \NC number \NC \TEX's stream id number \NC \NR
640 \NC name \NC string \NC file name \NC \NR
641 \NC ext \NC string \NC file extension \NC \NR
642 \NC area \NC string \NC file area (this may become obsolete) \NC \NR
643 \stoptabulate
645 \subsubsubsection{write whatsits}
647 \starttabulate[|lT|l|p|]
648 \NC \rmbf field \NC \bf type \NC \bf explanation \NC \NR
649 \NC attr \NC node \NC list of attributes \NC \NR
650 \NC stream \NC number \NC \TEX's stream id number \NC \NR
651 \NC data \NC table \NC a table representing the token list to be written \NC \NR
652 \stoptabulate
654 \subsubsubsection{close whatsits}
656 \starttabulate[|lT|l|p|]
657 \NC \rmbf field \NC \bf type \NC \bf explanation \NC \NR
658 \NC attr \NC node \NC list of attributes \NC \NR
659 \NC stream \NC number \NC \TEX's stream id number \NC \NR
660 \stoptabulate
662 \subsubsubsection{user_defined whatsits}
664 User|-|defined whatsit nodes can only be created and handled from \LUA\ code. In
665 effect, they are an extension to the extension mechanism. The \LUATEX\ engine
666 will simply step over such whatsits without ever looking at the contents.
668 \starttabulate[|lT|l|p|]
669 \NC \rmbf field \NC \bf type \NC \bf explanation \NC \NR
670 \NC attr \NC node \NC list of attributes \NC \NR
671 \NC user_id \NC number \NC id number \NC \NR
672 \NC type \NC number \NC type of the value \NC \NR
673 \NC value \NC number \NC a \LUA\ number \NC \NR
674 \NC \NC node \NC a node list \NC \NR
675 \NC \NC string \NC a \LUA\ string \NC \NR
676 \NC \NC table \NC a \LUA\ table \NC \NR
677 \stoptabulate
679 The \type {type} can have one of six distinct values. The number is the \ASCII\
680 value if the first character if the type name (so you can use string.byte("l")
681 instead of \type {108}).
683 \starttabulate[|lT|lT|p|]
684 \NC \rmbf value \NC \bf meaning \NC \bf explanation \NC \NR
685 \NC 97 \NC a \NC list of attributes (a node list) \NC \NR
686 \NC 100 \NC d \NC a \LUA\ number \NC \NR
687 \NC 108 \NC l \NC a \LUA\ value (table, number, boolean, etc) \NC \NR
688 \NC 110 \NC n \NC a node list \NC \NR
689 \NC 115 \NC s \NC a \LUA\ string \NC \NR
690 \NC 116 \NC t \NC a \LUA\ token list in \LUA\ table form (a list of triplets) \NC \NR
691 \stoptabulate
693 \subsubsubsection{save_pos whatsits}
695 \starttabulate[|lT|l|p|]
696 \NC \rmbf field \NC \bf type \NC \bf explanation \NC \NR
697 \NC attr \NC node \NC list of attributes \NC \NR
698 \stoptabulate
700 \subsubsubsection{late_lua whatsits}
702 \starttabulate[|lT|l|p|]
703 \NC \rmbf field \NC \bf type \NC \bf explanation \NC \NR
704 \NC attr \NC node \NC list of attributes \NC \NR
705 \NC data \NC string \NC data to execute \NC \NR
706 \NC string \NC string \NC data to execute \NC \NR
707 \NC name \NC string \NC the name to use for \LUA\ error reporting \NC \NR
708 \stoptabulate
710 The difference between \type {data} and \type {string} is that on assignment, the
711 \type {data} field is converted to a token list, cf. use as \type {\latelua}. The
712 \type {string} version is treated as a literal string.
714 \subsubsection{\DVI\ backend whatsits}
716 \subsubsection{special whatsits}
718 \starttabulate[|lT|l|p|]
719 \NC \rmbf field \NC \bf type \NC \bf explanation \NC \NR
720 \NC attr \NC node \NC list of attributes \NC \NR
721 \NC data \NC string \NC the \type {\special} information \NC \NR
722 \stoptabulate
724 \subsubsection{\PDF\ backend whatsits}
726 \subsubsubsection{pdf_literal whatsits}
728 \starttabulate[|lT|l|p|]
729 \NC \rmbf field \NC \bf type \NC \bf explanation \NC \NR
730 \NC attr \NC node \NC list of attributes \NC \NR
731 \NC mode \NC number \NC the \quote {mode} setting of this literal \NC \NR
732 \NC data \NC string \NC the \type {\pdfliteral} information \NC \NR
733 \stoptabulate
735 Possible mode values are:
737 \starttabulate[|lT|p|]
738 \NC \rmbf value \NC \rmbf \PDFTEX\ keyword \NC \NR
739 \NC 0 \NC setorigin \NC \NR
740 \NC 1 \NC page \NC \NR
741 \NC 2 \NC direct \NC \NR
742 \NC 3 \NC raw \NC \NR
743 \stoptabulate
745 The higher the number, the less checking and the more you can run into troubles.
746 Especially the \type {raw} variant can produce bad \PDF\ so you can best check
747 what you generate.
749 \subsubsubsection{pdf_refobj whatsits}
751 \starttabulate[|lT|l|p|]
752 \NC \rmbf field \NC \bf type \NC \bf explanation \NC \NR
753 \NC attr \NC node \NC list of attributes \NC \NR
754 \NC objnum \NC number \NC the referenced \PDF\ object number \NC \NR
755 \stoptabulate
757 \subsubsubsection{pdf_annot whatsits}
759 \starttabulate[|lT|l|p|]
760 \NC \rmbf field \NC \bf type \NC \bf explanation \NC \NR
761 \NC attr \NC node \NC list of attributes \NC \NR
762 \NC width \NC number \NC the width (not used in calculations) \NC \NR
763 \NC height \NC number \NC the height (not used in calculations) \NC \NR
764 \NC depth \NC number \NC the depth (not used in calculations) \NC \NR
765 \NC objnum \NC number \NC the referenced \PDF\ object number \NC \NR
766 \NC data \NC string \NC the annotation data \NC \NR
767 \stoptabulate
769 \subsubsubsection{pdf_start_link whatsits}
771 \starttabulate[|lT|l|p|]
772 \NC \rmbf field \NC \bf type \NC \bf explanation \NC \NR
773 \NC attr \NC node \NC list of attributes \NC \NR
774 \NC width \NC number \NC the width (not used in calculations) \NC \NR
775 \NC height \NC number \NC the height (not used in calculations) \NC \NR
776 \NC depth \NC number \NC the depth (not used in calculations) \NC \NR
777 \NC objnum \NC number \NC the referenced \PDF\ object number \NC \NR
778 \NC link_attr \NC table \NC the link attribute token list \NC \NR
779 \NC action \NC node \NC the action to perform \NC \NR
780 \stoptabulate
782 \subsubsubsection{pdf_end_link whatsits}
784 \starttabulate[|lT|l|p|]
785 \NC \rmbf field \NC \bf type \NC \bf explanation \NC \NR
786 \NC attr \NC node \NC \NC \NR
787 \stoptabulate
789 \subsubsubsection{pdf_dest whatsits}
791 \starttabulate[|lT|l|p|]
792 \NC \rmbf field \NC \bf type \NC \bf explanation \NC \NR
793 \NC attr \NC node \NC list of attributes \NC \NR
794 \NC width \NC number \NC the width (not used in calculations) \NC \NR
795 \NC height \NC number \NC the height (not used in calculations) \NC \NR
796 \NC depth \NC number \NC the depth (not used in calculations) \NC \NR
797 \NC named_id \NC number \NC is the \type {dest_id} a string value? \NC \NR
798 \NC dest_id \NC number \NC the destination id \NC \NR
799 \NC \NC string \NC the destination name \NC \NR
800 \NC dest_type \NC number \NC type of destination \NC \NR
801 \NC xyz_zoom \NC number \NC the zoom factor (times 1000) \NC \NR
802 \NC objnum \NC number \NC the \PDF\ object number \NC \NR
803 \stoptabulate
805 \subsubsubsection{pdf_action whatsits}
807 These are a special kind of item that only appears inside \PDF\ start link
808 objects.
810 \starttabulate[|lT|l|p|]
811 \NC \rmbf field \NC \bf type \NC \bf explanation \NC \NR
812 \NC action_type \NC number \NC the kind of action involved \NC \NR
813 \NC action_id \NC number or string \NC token list reference or string \NC \NR
814 \NC named_id \NC number \NC the index of the destination \NC \NR
815 \NC file \NC string \NC the target filename \NC \NR
816 \NC new_window \NC number \NC the window state of the target \NC \NR
817 \NC data \NC string \NC the name of the destination \NC \NR
818 \stoptabulate
820 Valid action types are:
822 \starttabulate[|lT|lT|]
823 \NC 0 \NC page \NC \NR
824 \NC 1 \NC goto \NC \NR
825 \NC 2 \NC thread \NC \NR
826 \NC 3 \NC user \NC \NR
827 \stoptabulate
829 Valid window types are:
831 \starttabulate[|lT|lT|]
832 \NC 0 \NC notset \NC \NR
833 \NC 1 \NC new \NC \NR
834 \NC 2 \NC nonew \NC \NR
835 \stoptabulate
837 \subsubsubsection{pdf_thread whatsits}
839 \starttabulate[|lT|l|p|]
840 \NC \rmbf field \NC \bf type \NC \bf explanation \NC \NR
841 \NC attr \NC node \NC list of attributes \NC \NR
842 \NC width \NC number \NC the width (not used in calculations) \NC \NR
843 \NC height \NC number \NC the height (not used in calculations) \NC \NR
844 \NC depth \NC number \NC the depth (not used in calculations) \NC \NR
845 \NC named_id \NC number \NC is \type {tread_id} a string value? \NC \NR
846 \NC tread_id \NC number \NC the thread id \NC \NR
847 \NC \NC string \NC the thread name \NC \NR
848 \NC thread_attr \NC number \NC extra thread information \NC \NR
849 \stoptabulate
851 \subsubsubsection{pdf_start_thread whatsits}
853 \starttabulate[|lT|l|p|]
854 \NC \rmbf field \NC \bf type \NC \bf explanation \NC \NR
855 \NC attr \NC node \NC list of attributes \NC \NR
856 \NC width \NC number \NC the width (not used in calculations) \NC \NR
857 \NC height \NC number \NC the height (not used in calculations) \NC \NR
858 \NC depth \NC number \NC the depth (not used in calculations) \NC \NR
859 \NC named_id \NC number \NC is \type {tread_id} a string value? \NC \NR
860 \NC tread_id \NC number \NC the thread id \NC \NR
861 \NC \NC string \NC the thread name \NC \NR
862 \NC thread_attr \NC number \NC extra thread information \NC \NR
863 \stoptabulate
865 \subsubsubsection{pdf_end_thread whatsits}
867 \starttabulate[|lT|l|p|]
868 \NC \rmbf field \NC \bf type \NC \bf explanation \NC \NR
869 \NC attr \NC node \NC \NC \NR
870 \stoptabulate
872 \subsubsubsection{pdf_colorstack whatsits}
874 \starttabulate[|lT|l|p|]
875 \NC \rmbf field \NC \bf type \NC \bf explanation \NC \NR
876 \NC attr \NC node \NC list of attributes \NC \NR
877 \NC stack \NC number \NC colorstack id number \NC \NR
878 \NC command \NC number \NC command to execute \NC \NR
879 \NC data \NC string \NC data \NC \NR
880 \stoptabulate
882 \subsubsubsection{pdf_setmatrix whatsits}
884 \starttabulate[|lT|l|p|]
885 \NC \rmbf field \NC \bf type \NC \bf explanation \NC \NR
886 \NC attr \NC node \NC list of attributes \NC \NR
887 \NC data \NC string \NC data \NC \NR
888 \stoptabulate
890 \subsubsubsection{pdf_save whatsits}
892 \starttabulate[|lT|l|p|]
893 \NC \rmbf field \NC \bf type \NC \bf explanation \NC \NR
894 \NC attr \NC node \NC list of attributes \NC \NR
895 \stoptabulate
897 \subsubsubsection{pdf_restore whatsits}
899 \starttabulate[|lT|l|p|]
900 \NC \rmbf field \NC \bf type \NC \bf explanation \NC \NR
901 \NC attr \NC node \NC list of attributes \NC \NR
902 \stoptabulate
904 \section{The \type {node} library}
906 The \type {node} library contains functions that facilitate dealing with (lists
907 of) nodes and their values. They allow you to create, alter, copy, delete, and
908 insert \LUATEX\ node objects, the core objects within the typesetter.
910 \LUATEX\ nodes are represented in \LUA\ as userdata with the metadata type
911 \type {luatex.node}. The various parts within a node can be accessed using
912 named fields.
914 Each node has at least the three fields \type {next}, \type {id}, and \type
915 {subtype}:
917 \startitemize[intro]
919 \startitem
920 The \type {next} field returns the userdata object for the next node in a
921 linked list of nodes, or \type {nil}, if there is no next node.
922 \stopitem
924 \startitem
925 The \type {id} indicates \TEX's \quote{node type}. The field \type {id} has a
926 numeric value for efficiency reasons, but some of the library functions also
927 accept a string value instead of \type {id}.
928 \stopitem
930 \startitem
931 The \type {subtype} is another number. It often gives further information
932 about a node of a particular \type {id}, but it is most important when
933 dealing with \quote {whatsits}, because they are differentiated solely based
934 on their \type {subtype}.
935 \stopitem
937 \stopitemize
939 The other available fields depend on the \type {id} (and for \quote {whatsits},
940 the \type {subtype}) of the node. Further details on the various fields and their
941 meanings are given in~\in{chapter}[nodes].
943 Support for \type {unset} (alignment) nodes is partial: they can be queried and
944 modified from \LUA\ code, but not created.
946 Nodes can be compared to each other, but: you are actually comparing indices into
947 the node memory. This means that equality tests can only be trusted under very
948 limited conditions. It will not work correctly in any situation where one of the
949 two nodes has been freed and|/|or reallocated: in that case, there will be false
950 positives.
952 At the moment, memory management of nodes should still be done explicitly by the
953 user. Nodes are not \quote {seen} by the \LUA\ garbage collector, so you have to
954 call the node freeing functions yourself when you are no longer in need of a node
955 (list). Nodes form linked lists without reference counting, so you have to be
956 careful that when control returns back to \LUATEX\ itself, you have not deleted
957 nodes that are still referenced from a \type {next} pointer elsewhere, and that
958 you did not create nodes that are referenced more than once.
960 There are statistics available with regards to the allocated node memory, which
961 can be handy for tracing.
963 \subsection{Node handling functions}
965 \subsubsection{\type {node.is_node}}
967 \startfunctioncall
968 <boolean> t =
969 node.is_node(<any> item)
970 \stopfunctioncall
972 This function returns true if the argument is a userdata object of
973 type \type {<node>}.
975 \subsubsection{\type {node.types}}
977 \startfunctioncall
978 <table> t =
979 node.types()
980 \stopfunctioncall
982 This function returns an array that maps node id numbers to node type strings,
983 providing an overview of the possible top|-|level \type {id} types.
985 \subsubsection{\type {node.whatsits}}
987 \startfunctioncall
988 <table> t =
989 node.whatsits()
990 \stopfunctioncall
992 \TEX's \quote{whatsits} all have the same \type {id}. The various subtypes are
993 defined by their \type {subtype} fields. The function is much like \type
994 {node.types}, except that it provides an array of \type {subtype} mappings.
996 \subsubsection{\type {node.id}}
998 \startfunctioncall
999 <number> id =
1000 node.id(<string> type)
1001 \stopfunctioncall
1003 This converts a single type name to its internal numeric representation.
1005 \subsubsection{\type {node.subtype}}
1007 \startfunctioncall
1008 <number> subtype =
1009 node.subtype(<string> type)
1010 \stopfunctioncall
1012 This converts a single whatsit name to its internal numeric representation (\type
1013 {subtype}).
1015 \subsubsection{\type {node.type}}
1017 \startfunctioncall
1018 <string> type =
1019 node.type(<any> n)
1020 \stopfunctioncall
1022 In the argument is a number, then this function converts an internal numeric
1023 representation to an external string representation. Otherwise, it will return
1024 the string \type {node} if the object represents a node, and \type {nil}
1025 otherwise.
1027 \subsubsection{\type {node.fields}}
1029 \startfunctioncall
1030 <table> t =
1031 node.fields(<number> id)
1032 <table> t =
1033 node.fields(<number> id, <number> subtype)
1034 \stopfunctioncall
1036 This function returns an array of valid field names for a particular type of
1037 node. If you want to get the valid fields for a \quote {whatsit}, you have to
1038 supply the second argument also. In other cases, any given second argument will
1039 be silently ignored.
1041 This function accepts string \type {id} and \type {subtype} values as well.
1043 \subsubsection{\type {node.has_field}}
1045 \startfunctioncall
1046 <boolean> t =
1047 node.has_field(<node> n, <string> field)
1048 \stopfunctioncall
1050 This function returns a boolean that is only true if \type {n} is
1051 actually a node, and it has the field.
1053 \subsubsection{\type {node.new}}
1055 \startfunctioncall
1056 <node> n =
1057 node.new(<number> id)
1058 <node> n =
1059 node.new(<number> id, <number> subtype)
1060 \stopfunctioncall
1062 Creates a new node. All of the new node's fields are initialized to either zero
1063 or \type {nil} except for \type {id} and \type {subtype} (if supplied). If you
1064 want to create a new whatsit, then the second argument is required, otherwise it
1065 need not be present. As with all node functions, this function creates a node on
1066 the \TEX\ level.
1068 This function accepts string \type {id} and \type {subtype} values as well.
1070 \subsubsection{\type {node.free} and \type {node.flush_node}}
1072 \startfunctioncall
1073 <node> next =
1074 node.free(<node> n)
1075 flush_node(<node> n)
1076 \stopfunctioncall
1078 Removes the node \type {n} from \TEX's memory. Be careful: no checks are done on
1079 whether this node is still pointed to from a register or some \type {next} field:
1080 it is up to you to make sure that the internal data structures remain correct.
1082 The \type {free} function returns the next field of the freed node, while the
1083 \type {flush_node} alternative returns nothing.
1085 \subsubsection{\type {node.flush_list}}
1087 \startfunctioncall
1088 node.flush_list(<node> n)
1089 \stopfunctioncall
1091 Removes the node list \type {n} and the complete node list following \type {n}
1092 from \TEX's memory. Be careful: no checks are done on whether any of these nodes
1093 is still pointed to from a register or some \type {next} field: it is up to you
1094 to make sure that the internal data structures remain correct.
1096 \subsubsection{\type {node.copy}}
1098 \startfunctioncall
1099 <node> m =
1100 node.copy(<node> n)
1101 \stopfunctioncall
1103 Creates a deep copy of node \type {n}, including all nested lists as in the case
1104 of a hlist or vlist node. Only the \type {next} field is not copied.
1106 \subsubsection{\type {node.copy_list}}
1108 \startfunctioncall
1109 <node> m =
1110 node.copy_list(<node> n)
1111 <node> m =
1112 node.copy_list(<node> n, <node> m)
1113 \stopfunctioncall
1115 Creates a deep copy of the node list that starts at \type {n}. If \type {m} is
1116 also given, the copy stops just before node \type {m}.
1118 Note that you cannot copy attribute lists this way, specialized functions for
1119 dealing with attribute lists will be provided later but are not there yet.
1120 However, there is normally no need to copy attribute lists as when you do
1121 assignments to the \type {attr} field or make changes to specific attributes, the
1122 needed copying and freeing takes place automatically.
1124 \subsubsection{\type {node.next}}
1126 \startfunctioncall
1127 <node> m =
1128 node.next(<node> n)
1129 \stopfunctioncall
1131 Returns the node following this node, or \type {nil} if there is no such node.
1133 \subsubsection{\type {node.prev}}
1135 \startfunctioncall
1136 <node> m =
1137 node.prev(<node> n)
1138 \stopfunctioncall
1140 Returns the node preceding this node, or \type {nil} if there is no such node.
1142 \subsubsection{\type {node.current_attr}}
1144 \startfunctioncall
1145 <node> m =
1146 node.current_attr()
1147 \stopfunctioncall
1149 Returns the currently active list of attributes, if there is one.
1151 The intended usage of \type {current_attr} is as follows:
1153 \starttyping
1154 local x1 = node.new("glyph")
1155 x1.attr = node.current_attr()
1156 local x2 = node.new("glyph")
1157 x2.attr = node.current_attr()
1158 \stoptyping
1162 \starttyping
1163 local x1 = node.new("glyph")
1164 local x2 = node.new("glyph")
1165 local ca = node.current_attr()
1166 x1.attr = ca
1167 x2.attr = ca
1168 \stoptyping
1170 The attribute lists are ref counted and the assignment takes care of incrementing
1171 the refcount. You cannot expect the value \type {ca} to be valid any more when
1172 you assign attributes (using \type {tex.setattribute}) or when control has been
1173 passed back to \TEX.
1175 Note: this function is somewhat experimental, and it returns the {\it actual}
1176 attribute list, not a copy thereof. Therefore, changing any of the attributes in
1177 the list will change these values for all nodes that have the current attribute
1178 list assigned to them.
1180 \subsubsection{\type {node.hpack}}
1182 \startfunctioncall
1183 <node> h, <number> b =
1184 node.hpack(<node> n)
1185 <node> h, <number> b =
1186 node.hpack(<node> n, <number> w, <string> info)
1187 <node> h, <number> b =
1188 node.hpack(<node> n, <number> w, <string> info, <string> dir)
1189 \stopfunctioncall
1191 This function creates a new hlist by packaging the list that begins at node \type
1192 {n} into a horizontal box. With only a single argument, this box is created using
1193 the natural width of its components. In the three argument form, \type {info}
1194 must be either \type {additional} or \type {exactly}, and \type {w} is the
1195 additional (\type {\hbox spread}) or exact (\type {\hbox to}) width to be used. The
1196 second return value is the badness of the generated box.
1198 Caveat: at this moment, there can be unexpected side|-|effects to this function,
1199 like updating some of the \type {\marks} and \type {\inserts}. Also note that the
1200 content of \type {h} is the original node list \type {n}: if you call \type
1201 {node.free(h)} you will also free the node list itself, unless you explicitly set
1202 the \type {list} field to \type {nil} beforehand. And in a similar way, calling
1203 \type {node.free(n)} will invalidate \type {h} as well!
1205 \subsubsection{\type {node.vpack}}
1207 \startfunctioncall
1208 <node> h, <number> b =
1209 node.vpack(<node> n)
1210 <node> h, <number> b =
1211 node.vpack(<node> n, <number> w, <string> info)
1212 <node> h, <number> b =
1213 node.vpack(<node> n, <number> w, <string> info, <string> dir)
1214 \stopfunctioncall
1216 This function creates a new vlist by packaging the list that begins at node \type
1217 {n} into a vertical box. With only a single argument, this box is created using
1218 the natural height of its components. In the three argument form, \type {info}
1219 must be either \type {additional} or \type {exactly}, and \type {w} is the
1220 additional (\type {\vbox spread}) or exact (\type {\vbox to}) height to be used.
1222 The second return value is the badness of the generated box.
1224 See the description of \type {node.hpack()} for a few memory allocation caveats.
1226 \subsubsection{\type {node.dimensions}, \type {node.rangedimensions}}
1228 \startfunctioncall
1229 <number> w, <number> h, <number> d =
1230 node.dimensions(<node> n)
1231 <number> w, <number> h, <number> d =
1232 node.dimensions(<node> n, <string> dir)
1233 <number> w, <number> h, <number> d =
1234 node.dimensions(<node> n, <node> t)
1235 <number> w, <number> h, <number> d =
1236 node.dimensions(<node> n, <node> t, <string> dir)
1237 \stopfunctioncall
1239 This function calculates the natural in|-|line dimensions of the node list starting
1240 at node \type {n} and terminating just before node \type {t} (or the end of the
1241 list, if there is no second argument). The return values are scaled points. An
1242 alternative format that starts with glue parameters as the first three arguments
1243 is also possible:
1245 \startfunctioncall
1246 <number> w, <number> h, <number> d =
1247 node.dimensions(<number> glue_set, <number> glue_sign, <number> glue_order,
1248 <node> n)
1249 <number> w, <number> h, <number> d =
1250 node.dimensions(<number> glue_set, <number> glue_sign, <number> glue_order,
1251 <node> n, <string> dir)
1252 <number> w, <number> h, <number> d =
1253 node.dimensions(<number> glue_set, <number> glue_sign, <number> glue_order,
1254 <node> n, <node> t)
1255 <number> w, <number> h, <number> d =
1256 node.dimensions(<number> glue_set, <number> glue_sign, <number> glue_order,
1257 <node> n, <node> t, <string> dir)
1258 \stopfunctioncall
1260 This calling method takes glue settings into account and is especially useful for
1261 finding the actual width of a sublist of nodes that are already boxed, for
1262 example in code like this, which prints the width of the space in between the
1263 \type {a} and \type {b} as it would be if \type {\box0} was used as-is:
1265 \starttyping
1266 \setbox0 = \hbox to 20pt {a b}
1268 \directlua{print (node.dimensions(
1269 tex.box[0].glue_set,
1270 tex.box[0].glue_sign,
1271 tex.box[0].glue_order,
1272 tex.box[0].head.next,
1273 node.tail(tex.box[0].head)
1274 )) }
1275 \stoptyping
1277 You need to keep in mind that this is one of the few places in \TEX\ where floats
1278 are used, which means that you can get small differences in rounding when you
1279 compare the width reported by \type {hpack} with \type {dimensions}.
1281 The second alternative saves a few lookups and can be more convenient in some
1282 cases:
1284 \startfunctioncall
1285 <number> w, <number> h, <number> d =
1286 node.rangedimensions(<node> parent, <node> first)
1287 <number> w, <number> h, <number> d =
1288 node.rangedimensions(<node> parent, <node> first, <node> last)
1289 \stopfunctioncall
1291 \subsubsection{\type {node.mlist_to_hlist}}
1293 \startfunctioncall
1294 <node> h =
1295 node.mlist_to_hlist(<node> n, <string> display_type, <boolean> penalties)
1296 \stopfunctioncall
1298 This runs the internal mlist to hlist conversion, converting the math list in
1299 \type {n} into the horizontal list \type {h}. The interface is exactly the same
1300 as for the callback \type {mlist_to_hlist}.
1302 \subsubsection{\type {node.slide}}
1304 \startfunctioncall
1305 <node> m =
1306 node.slide(<node> n)
1307 \stopfunctioncall
1309 Returns the last node of the node list that starts at \type {n}. As a
1310 side|-|effect, it also creates a reverse chain of \type {prev} pointers between
1311 nodes.
1313 \subsubsection{\type {node.tail}}
1315 \startfunctioncall
1316 <node> m =
1317 node.tail(<node> n)
1318 \stopfunctioncall
1320 Returns the last node of the node list that starts at \type {n}.
1322 \subsubsection{\type {node.length}}
1324 \startfunctioncall
1325 <number> i =
1326 node.length(<node> n)
1327 <number> i =
1328 node.length(<node> n, <node> m)
1329 \stopfunctioncall
1331 Returns the number of nodes contained in the node list that starts at \type {n}.
1332 If \type {m} is also supplied it stops at \type {m} instead of at the end of the
1333 list. The node \type {m} is not counted.
1335 \subsubsection{\type {node.count}}
1337 \startfunctioncall
1338 <number> i =
1339 node.count(<number> id, <node> n)
1340 <number> i =
1341 node.count(<number> id, <node> n, <node> m)
1342 \stopfunctioncall
1344 Returns the number of nodes contained in the node list that starts at \type {n}
1345 that have a matching \type {id} field. If \type {m} is also supplied, counting
1346 stops at \type {m} instead of at the end of the list. The node \type {m} is not
1347 counted.
1349 This function also accept string \type {id}'s.
1351 \subsubsection{\type {node.traverse}}
1353 \startfunctioncall
1354 <node> t =
1355 node.traverse(<node> n)
1356 \stopfunctioncall
1358 This is a \LUA\ iterator that loops over the node list that starts at \type {n}.
1359 Typically code looks like this:
1361 \starttyping
1362 for n in node.traverse(head) do
1365 \stoptyping
1367 is functionally equivalent to:
1369 \starttyping
1371 local n
1372 local function f (head,var)
1373 local t
1374 if var == nil then
1375 t = head
1376 else
1377 t = var.next
1379 return t
1381 while true do
1382 n = f (head, n)
1383 if n == nil then break end
1387 \stoptyping
1389 It should be clear from the definition of the function \type {f} that even though
1390 it is possible to add or remove nodes from the node list while traversing, you
1391 have to take great care to make sure all the \type {next} (and \type {prev})
1392 pointers remain valid.
1394 If the above is unclear to you, see the section \quote {For Statement} in the
1395 \LUA\ Reference Manual.
1397 \subsubsection{\type {node.traverse_id}}
1399 \startfunctioncall
1400 <node> t =
1401 node.traverse_id(<number> id, <node> n)
1402 \stopfunctioncall
1404 This is an iterator that loops over all the nodes in the list that starts at
1405 \type {n} that have a matching \type {id} field.
1407 See the previous section for details. The change is in the local function \type
1408 {f}, which now does an extra while loop checking against the upvalue \type {id}:
1410 \starttyping
1411 local function f(head,var)
1412 local t
1413 if var == nil then
1414 t = head
1415 else
1416 t = var.next
1418 while not t.id == id do
1419 t = t.next
1421 return t
1423 \stoptyping
1425 \subsubsection{\type {node.traverse_char}}
1427 This iterators loops over the glyph nodes in a list. Only nodes with a subtype
1428 less than 256 are seen.
1430 \startfunctioncall
1431 <node> n =
1432 node.traverse_char(<node> n)
1433 \stopfunctioncall
1435 \subsubsection{\type {node.has_glyph}}
1437 This function returns the first glyph or disc node in the given list:
1439 \startfunctioncall
1440 <node> n =
1441 node.has_glyph(<node> n)
1442 \stopfunctioncall
1444 \subsubsection{\type {node.end_of_math}}
1446 \startfunctioncall
1447 <node> t =
1448 node.end_of_math(<node> start)
1449 \stopfunctioncall
1451 Looks for and returns the next \type {math_node} following the \type {start}. If
1452 the given node is a math endnode this helper return that node, else it follows
1453 the list and return the next math endnote. If no such node is found nil is
1454 returned.
1456 \subsubsection{\type {node.remove}}
1458 \startfunctioncall
1459 <node> head, current =
1460 node.remove(<node> head, <node> current)
1461 \stopfunctioncall
1463 This function removes the node \type {current} from the list following \type
1464 {head}. It is your responsibility to make sure it is really part of that list.
1465 The return values are the new \type {head} and \type {current} nodes. The
1466 returned \type {current} is the node following the \type {current} in the calling
1467 argument, and is only passed back as a convenience (or \type {nil}, if there is
1468 no such node). The returned \type {head} is more important, because if the
1469 function is called with \type {current} equal to \type {head}, it will be
1470 changed.
1472 \subsubsection{\type {node.insert_before}}
1474 \startfunctioncall
1475 <node> head, new =
1476 node.insert_before(<node> head, <node> current, <node> new)
1477 \stopfunctioncall
1479 This function inserts the node \type {new} before \type {current} into the list
1480 following \type {head}. It is your responsibility to make sure that \type
1481 {current} is really part of that list. The return values are the (potentially
1482 mutated) \type {head} and the node \type {new}, set up to be part of the list
1483 (with correct \type {next} field). If \type {head} is initially \type {nil}, it
1484 will become \type {new}.
1486 \subsubsection{\type {node.insert_after}}
1488 \startfunctioncall
1489 <node> head, new =
1490 node.insert_after(<node> head, <node> current, <node> new)
1491 \stopfunctioncall
1493 This function inserts the node \type {new} after \type {current} into the list
1494 following \type {head}. It is your responsibility to make sure that \type
1495 {current} is really part of that list. The return values are the \type {head} and
1496 the node \type {new}, set up to be part of the list (with correct \type {next}
1497 field). If \type {head} is initially \type {nil}, it will become \type {new}.
1499 \subsubsection{\type {node.first_glyph}}
1501 \startfunctioncall
1502 <node> n =
1503 node.first_glyph(<node> n)
1504 <node> n =
1505 node.first_glyph(<node> n, <node> m)
1506 \stopfunctioncall
1508 Returns the first node in the list starting at \type {n} that is a glyph node
1509 with a subtype indicating it is a glyph, or \type {nil}. If \type {m} is given,
1510 processing stops at (but including) that node, otherwise processing stops at the
1511 end of the list.
1513 \subsubsection{\type {node.ligaturing}}
1515 \startfunctioncall
1516 <node> h, <node> t, <boolean> success =
1517 node.ligaturing(<node> n)
1518 <node> h, <node> t, <boolean> success =
1519 node.ligaturing(<node> n, <node> m)
1520 \stopfunctioncall
1522 Apply \TEX-style ligaturing to the specified nodelist. The tail node \type {m} is
1523 optional. The two returned nodes \type {h} and \type {t} are the new head and
1524 tail (both \type {n} and \type {m} can change into a new ligature).
1526 \subsubsection{\type {node.kerning}}
1528 \startfunctioncall
1529 <node> h, <node> t, <boolean> success =
1530 node.kerning(<node> n)
1531 <node> h, <node> t, <boolean> success =
1532 node.kerning(<node> n, <node> m)
1533 \stopfunctioncall
1535 Apply \TEX|-|style kerning to the specified node list. The tail node \type {m} is
1536 optional. The two returned nodes \type {h} and \type {t} are the head and tail
1537 (either one of these can be an inserted kern node, because special kernings with
1538 word boundaries are possible).
1540 \subsubsection{\type {node.unprotect_glyphs}}
1542 \startfunctioncall
1543 node.unprotect_glyphs(<node> n)
1544 \stopfunctioncall
1546 Subtracts 256 from all glyph node subtypes. This and the next function are
1547 helpers to convert from \type {characters} to \type {glyphs} during node
1548 processing.
1550 \subsubsection{\type {node.protect_glyphs} and \type {node.protect_glyph}}
1552 \startfunctioncall
1553 node.protect_glyphs(<node> n)
1554 \stopfunctioncall
1556 Adds 256 to all glyph node subtypes in the node list starting at \type {n},
1557 except that if the value is 1, it adds only 255. The special handling of 1 means
1558 that \type {characters} will become \type {glyphs} after subtraction of 256. A
1559 single character can be marked by the singular call.
1561 \subsubsection{\type {node.last_node}}
1563 \startfunctioncall
1564 <node> n =
1565 node.last_node()
1566 \stopfunctioncall
1568 This function pops the last node from \TEX's \quote{current list}. It returns
1569 that node, or \type {nil} if the current list is empty.
1571 \subsubsection{\type {node.write}}
1573 \startfunctioncall
1574 node.write(<node> n)
1575 \stopfunctioncall
1577 This is an experimental function that will append a node list to \TEX's \quote
1578 {current list} The node list is not deep|-|copied! There is no error checking
1579 either!
1581 \subsubsection{\type {node.protrusion_skippable}}
1583 \startfunctioncall
1584 <boolean> skippable =
1585 node.protrusion_skippable(<node> n)
1586 \stopfunctioncall
1588 Returns \type {true} if, for the purpose of line boundary discovery when
1589 character protrusion is active, this node can be skipped.
1591 \subsection{Glue handling}
1593 \subsubsection{\type {node.setglue}}
1595 You can set the properties of a glue in one go. If you pass no values, the glue
1596 will become a zero glue.
1598 \startfunctioncall
1599 node.setglue(<node> n)
1600 node.setglue(<node> n,width,stretch,shrink,stretch_order,shrink_order)
1601 \stopfunctioncall
1603 When you pass values, only arguments that are numbers
1604 are assigned so
1606 \starttyping
1607 node.setglue(n,655360,false,65536)
1608 \stoptyping
1610 will only adapt the width and shrink.
1612 \subsubsection{\type {node.getglue}}
1614 The next call will return 5 values (or northing when no glue is passed).
1616 \startfunctioncall
1617 <integer> width, <integer> stretch, <integer> shrink, <integer> stretch_order,
1618 <integer> shrink_order = node.getglue(<node> n)
1619 \stopfunctioncall
1621 When the second argument is false, only the width is returned (this is consistent
1622 with \type {tex.get}).
1624 \subsubsection{\type {node.is_zero_glue}}
1626 This function returns \type {true} when the width, stretch and shrink properties
1627 are zero.
1629 \startfunctioncall
1630 <boolean> isglue =
1631 node.is_zero_glue(<node> n)
1632 \stopfunctioncall
1634 \subsection{Attribute handling}
1636 Attributes appear as linked list of userdata objects in the \type {attr} field of
1637 individual nodes. They can be handled individually, but it is much safer and more
1638 efficient to use the dedicated functions associated with them.
1640 \subsubsection{\type {node.has_attribute}}
1642 \startfunctioncall
1643 <number> v =
1644 node.has_attribute(<node> n, <number> id)
1645 <number> v =
1646 node.has_attribute(<node> n, <number> id, <number> val)
1647 \stopfunctioncall
1649 Tests if a node has the attribute with number \type {id} set. If \type {val} is
1650 also supplied, also tests if the value matches \type {val}. It returns the value,
1651 or, if no match is found, \type {nil}.
1653 \subsubsection{\type {node.get_attribute}}
1655 \startfunctioncall
1656 <number> v =
1657 node.get_attribute(<node> n, <number> id)
1658 \stopfunctioncall
1660 Tests if a node has an attribute with number \type {id} set. It returns the
1661 value, or, if no match is found, \type {nil}.
1663 \subsubsection{\type {node.find_attribute}}
1665 \startfunctioncall
1666 <number> v, <node> n =
1667 node.find_attribute(<node> n, <number> id)
1668 \stopfunctioncall
1670 Finds the first node that has attribute with number \type {id} set. It returns
1671 the value and the node if there is a match and otherwise nothing.
1673 \subsubsection{\type {node.set_attribute}}
1675 \startfunctioncall
1676 node.set_attribute(<node> n, <number> id, <number> val)
1677 \stopfunctioncall
1679 Sets the attribute with number \type {id} to the value \type {val}. Duplicate
1680 assignments are ignored. {\em [needs explanation]}
1682 \subsubsection{\type {node.unset_attribute}}
1684 \startfunctioncall
1685 <number> v =
1686 node.unset_attribute(<node> n, <number> id)
1687 <number> v =
1688 node.unset_attribute(<node> n, <number> id, <number> val)
1689 \stopfunctioncall
1691 Unsets the attribute with number \type {id}. If \type {val} is also supplied, it
1692 will only perform this operation if the value matches \type {val}. Missing
1693 attributes or attribute|-|value pairs are ignored.
1695 If the attribute was actually deleted, returns its old value. Otherwise, returns
1696 \type {nil}.
1698 \subsubsection{\type {node.slide}}
1700 This helper makes sure that the node lists is double linked and returns the found
1701 tail node.
1703 \startfunctioncall
1704 <node> tail =
1705 node.slide(<node> n)
1706 \stopfunctioncall
1708 \subsubsection{\type {node.check_discretionary} and \type {node.check_discretionaries}}
1710 When you fool around with disc nodes you need to be aware of the fact that they
1711 have a special internal data structure. As long as you reassign the fields when
1712 you have extended the lists it's ok because then the tail pointers get updated,
1713 but when you add to list without reassigning you might end up in troubles when
1714 the linebreak routien kicks in. You can call this function to check the list for
1715 issues with disc nodes.
1717 \startfunctioncall
1718 node.check_discretionary(<node> n)
1719 node.check_discretionaries(<node> head)
1720 \stopfunctioncall
1722 The plural variant runs over all disc nodes in a list, the singular variant
1723 checks one node only (it also checks if the node is a disc node).
1725 \subsubsection{\type {node.family_font}}
1727 When you pass it a proper family identifier the next helper will return the font
1728 currently associated with it. You can normally also access the font with the normal
1729 font field or getter because it will resolve the family automatically for noads.
1731 \startfunctioncall
1732 <integer> id =
1733 node.family_font(<integer> fam)
1734 \stopfunctioncall
1736 \section{Two access models}
1738 Deep down in \TEX\ a node has a number which is an numeric entry in a memory
1739 table. In fact, this model, where \TEX\ manages memory is real fast and one of
1740 the reasons why plugging in callbacks that operate on nodes is quite fast too.
1741 Each node gets a number that is in fact an index in the memory table and that
1742 number often gets reported when you print node related information.
1744 There are two access models, a robust one using a so called user data object that
1745 provides a virtual interface to the internal nodes, and a more direct access which
1746 uses the node numbers directly. The first model provide key based access while
1747 the second always accesses fields via functions:
1749 \starttyping
1750 nodeobject.char
1751 getfield(nodenumber,"char")
1752 \stoptyping
1754 If you use the direct model, even if you know that you deal with numbers, you
1755 should not depend on that property but treat it an abstraction just like
1756 traditional nodes. In fact, the fact that we use a simple basic datatype has the
1757 penalty that less checking can be done, but less checking is also the reason why
1758 it's somewhat faster. An important aspect is that one cannot mix both methods,
1759 but you can cast both models. So, multiplying a node number makes no sense.
1761 So our advice is: use the indexed (table) approach when possible and investigate
1762 the direct one when speed might be an real issue. For that reason we also provide
1763 the \type {get*} and \type {set*} functions in the top level node namespace.
1764 There is a limited set of getters. When implementing this direct approach the
1765 regular index by key variant was also optimized, so direct access only makes
1766 sense when we're accessing nodes millions of times (which happens in some font
1767 processing for instance).
1769 We're talking mostly of getters because setters are less important. Documents
1770 have not that many content related nodes and setting many thousands of properties
1771 is hardly a burden contrary to millions of consultations.
1773 Normally you will access nodes like this:
1775 \starttyping
1776 local next = current.next
1777 if next then
1778 -- do something
1780 \stoptyping
1782 Here \type {next} is not a real field, but a virtual one. Accessing it results in
1783 a metatable method being called. In practice it boils down to looking up the node
1784 type and based on the node type checking for the field name. In a worst case you
1785 have a node type that sits at the end of the lookup list and a field that is last
1786 in the lookup chain. However, in successive versions of \LUATEX\ these lookups
1787 have been optimized and the most frequently accessed nodes and fields have a
1788 higher priority.
1790 Because in practice the \type {next} accessor results in a function call, there
1791 is some overhead involved. The next code does the same and performs a tiny bit
1792 faster (but not that much because it is still a function call but one that knows
1793 what to look up).
1795 \starttyping
1796 local next = node.next(current)
1797 if next then
1798 -- do something
1800 \stoptyping
1802 Some accessors are used frequently and for these we provide more efficient helpers:
1804 \starttabulate[|T|p|]
1805 \NC getnext \NC parsing nodelist always involves this one \NC \NR
1806 \NC getprev \NC used less but is logical companion to \type {getnext} \NC \NR
1807 \NC getboth \NC returns the next and prev pointer of a node \NC \NR
1808 \NC getid \NC consulted a lot \NC \NR
1809 \NC getsubtype \NC consulted less but also a topper \NC \NR
1810 \NC getfont \NC used a lot in \OPENTYPE\ handling (glyph nodes are consulted a lot) \NC \NR
1811 \NC getchar \NC idem and also in other places \NC \NR
1812 \NC getwhd \NC returns the \type {width}, \type {height} and \type {depth} of a list, rule or
1813 (unexpanded) glyph as well as glue (its spec is looked at) and unset nodes\NC \NR
1814 \NC getdisc \NC returns the \type {pre}, \type {post} and \type {replace} fields and
1815 optionally when true is passed also the tail fields. \NC \NR
1816 \NC getlist \NC we often parse nested lists so this is a convenient one too \NC \NR
1817 \NC getleader \NC comparable to list, seldom used in \TEX\ (but needs frequent consulting
1818 like lists; leaders could have been made a dedicated node type) \NC \NR
1819 \NC getfield \NC generic getter, sufficient for the rest (other field names are
1820 often shared so a specific getter makes no sense then) \NC \NR
1821 \NC getbox \NC gets the given box (a list node) \NC \NR
1822 \stoptabulate
1824 In the direct namespace there are more such helpers and most of them are
1825 accompanied by setters. The getters and setters are clever enough to see what
1826 node is meant. We don't deal with whatsit nodes: their fields are always accessed
1827 by name. It doesn't make sense to add getters for all fields, we just identifier
1828 the most likely candidates. In complex documents, many node and fields types
1829 never get seen, or seen only a few times, but for instance glyphs are candidates
1830 for such optimization. The \type {node.direct} interface has some more helpers.
1831 \footnote {We can define the helpers in the node namespace with \type {getfield}
1832 which is about as efficient, so at some point we might provide that as module.}
1834 The \type {setdisc} helper takes three (optional) arguments plus an optional
1835 fourth indicating the subtype. Its \type {getdisc} takes an optional boolean;
1836 when its value is \type {true} the tail nodes will also be returned. The \type
1837 {setfont} helper takes an optional second argument, it being the character. The
1838 directmode setter \type {setlink} takes a list of nodes and will link them,
1839 thereby ignoring \type {nil} entries. The first valid node is returned (beware:
1840 for good reason it assumes single nodes). For rarely used fields no helpers are
1841 provided and there are a few that probably are used seldom too but were added for
1842 consistency. You can of course always define additional accessor using \type
1843 {getfield} and \type {setfield} with little overhead.
1845 % \startcolumns[balance=yes]
1847 \def\yes{$+$} \def\nop{$-$}
1849 \starttabulate[|T|c|c|]
1851 \NC \bf function \NC \bf node \NC \bf direct \NC \NR
1853 %NC \type {do_ligature_n} \NC \yes \NC \yes \NC \NR % was never documented and experimental
1854 \NC \type {check_discretionaries}\NC \yes \NC \yes \NC \NR
1855 \NC \type {copy_list} \NC \yes \NC \yes \NC \NR
1856 \NC \type {copy} \NC \yes \NC \yes \NC \NR
1857 \NC \type {count} \NC \yes \NC \yes \NC \NR
1858 \NC \type {current_attr} \NC \yes \NC \yes \NC \NR
1859 \NC \type {dimensions} \NC \yes \NC \yes \NC \NR
1860 \NC \type {effective_glue} \NC \yes \NC \yes \NC \NR
1861 \NC \type {end_of_math} \NC \yes \NC \yes \NC \NR
1862 \NC \type {family_font} \NC \yes \NC \nop \NC \NR
1863 \NC \type {fields} \NC \yes \NC \nop \NC \NR
1864 \NC \type {find_attribute} \NC \yes \NC \yes \NC \NR
1865 \NC \type {first_glyph} \NC \yes \NC \yes \NC \NR
1866 \NC \type {flush_list} \NC \yes \NC \yes \NC \NR
1867 \NC \type {flush_node} \NC \yes \NC \yes \NC \NR
1868 \NC \type {free} \NC \yes \NC \yes \NC \NR
1869 \NC \type {get_attribute} \NC \yes \NC \yes \NC \NR
1870 \NC \type {getattributelist} \NC \nop \NC \yes \NC \NR
1871 \NC \type {getboth} \NC \yes \NC \yes \NC \NR
1872 \NC \type {getbox} \NC \nop \NC \yes \NC \NR
1873 \NC \type {getchar} \NC \yes \NC \yes \NC \NR
1874 \NC \type {getcomponents} \NC \nop \NC \yes \NC \NR
1875 \NC \type {getdepth} \NC \nop \NC \yes \NC \NR
1876 \NC \type {getdir} \NC \nop \NC \yes \NC \NR
1877 \NC \type {getdisc} \NC \yes \NC \yes \NC \NR
1878 \NC \type {getfield} \NC \yes \NC \yes \NC \NR
1879 \NC \type {getfont} \NC \yes \NC \yes \NC \NR
1880 \NC \type {getglue} \NC \yes \NC \yes \NC \NR
1881 \NC \type {getheight} \NC \nop \NC \yes \NC \NR
1882 \NC \type {getid} \NC \yes \NC \yes \NC \NR
1883 \NC \type {getkern} \NC \nop \NC \yes \NC \NR
1884 \NC \type {getlang} \NC \nop \NC \yes \NC \NR
1885 \NC \type {getleader} \NC \yes \NC \yes \NC \NR
1886 \NC \type {getlist} \NC \yes \NC \yes \NC \NR
1887 \NC \type {getnext} \NC \yes \NC \yes \NC \NR
1888 \NC \type {getnucleus} \NC \nop \NC \yes \NC \NR
1889 \NC \type {getoffsets} \NC \nop \NC \yes \NC \NR
1890 \NC \type {getpenalty} \NC \nop \NC \yes \NC \NR
1891 \NC \type {getprev} \NC \yes \NC \yes \NC \NR
1892 \NC \type {getproperty} \NC \yes \NC \yes \NC \NR
1893 \NC \type {getshift} \NC \nop \NC \yes \NC \NR
1894 \NC \type {getwidth} \NC \nop \NC \yes \NC \NR
1895 \NC \type {getwhd} \NC \nop \NC \yes \NC \NR
1896 \NC \type {getsub} \NC \nop \NC \yes \NC \NR
1897 \NC \type {getsubtype} \NC \yes \NC \yes \NC \NR
1898 \NC \type {getsup} \NC \nop \NC \yes \NC \NR
1899 \NC \type {has_attribute} \NC \yes \NC \yes \NC \NR
1900 \NC \type {has_field} \NC \yes \NC \yes \NC \NR
1901 \NC \type {has_glyph} \NC \yes \NC \yes \NC \NR
1902 \NC \type {hpack} \NC \yes \NC \yes \NC \NR
1903 \NC \type {id} \NC \yes \NC \nop \NC \NR
1904 \NC \type {insert_after} \NC \yes \NC \yes \NC \NR
1905 \NC \type {insert_before} \NC \yes \NC \yes \NC \NR
1906 \NC \type {is_char} \NC \yes \NC \yes \NC \NR
1907 \NC \type {is_direct} \NC \nop \NC \yes \NC \NR
1908 \NC \type {is_glue_zero} \NC \yes \NC \yes \NC \NR
1909 \NC \type {is_glyph} \NC \yes \NC \yes \NC \NR
1910 \NC \type {is_node} \NC \yes \NC \yes \NC \NR
1911 \NC \type {kerning} \NC \yes \NC \yes \NC \NR
1912 \NC \type {last_node} \NC \yes \NC \yes \NC \NR
1913 \NC \type {length} \NC \yes \NC \yes \NC \NR
1914 \NC \type {ligaturing} \NC \yes \NC \yes \NC \NR
1915 \NC \type {mlist_to_hlist} \NC \yes \NC \nop \NC \NR
1916 \NC \type {new} \NC \yes \NC \yes \NC \NR
1917 \NC \type {next} \NC \yes \NC \nop \NC \NR
1918 \NC \type {prev} \NC \yes \NC \nop \NC \NR
1919 \NC \type {protect_glyphs} \NC \yes \NC \yes \NC \NR
1920 \NC \type {protect_glyph} \NC \yes \NC \yes \NC \NR
1921 \NC \type {protrusion_skippable} \NC \yes \NC \yes \NC \NR
1922 \NC \type {rangedimensions} \NC \yes \NC \yes \NC \NR
1923 \NC \type {remove} \NC \yes \NC \yes \NC \NR
1924 \NC \type {set_attribute} \NC \nop \NC \yes \NC \NR
1925 \NC \type {setattributelist} \NC \nop \NC \yes \NC \NR
1926 \NC \type {setboth} \NC \nop \NC \yes \NC \NR
1927 \NC \type {setbox} \NC \nop \NC \yes \NC \NR
1928 \NC \type {setchar} \NC \nop \NC \yes \NC \NR
1929 \NC \type {setcomponents} \NC \nop \NC \yes \NC \NR
1930 \NC \type {setdepth} \NC \nop \NC \yes \NC \NR
1931 \NC \type {setdir} \NC \nop \NC \yes \NC \NR
1932 \NC \type {setdisc} \NC \nop \NC \yes \NC \NR
1933 \NC \type {setfield} \NC \yes \NC \yes \NC \NR
1934 \NC \type {setfont} \NC \nop \NC \yes \NC \NR
1935 \NC \type {setglue} \NC \yes \NC \yes \NC \NR
1936 \NC \type {setheight} \NC \nop \NC \yes \NC \NR
1937 \NC \type {setid} \NC \nop \NC \yes \NC \NR
1938 \NC \type {setkern} \NC \nop \NC \yes \NC \NR
1939 \NC \type {setlang} \NC \nop \NC \yes \NC \NR
1940 \NC \type {setleader} \NC \nop \NC \yes \NC \NR
1941 \NC \type {setlist} \NC \nop \NC \yes \NC \NR
1942 \NC \type {setnext} \NC \nop \NC \yes \NC \NR
1943 \NC \type {setnucleus} \NC \nop \NC \yes \NC \NR
1944 \NC \type {setoffsets} \NC \nop \NC \yes \NC \NR
1945 \NC \type {setpenalty} \NC \nop \NC \yes \NC \NR
1946 \NC \type {setprev} \NC \nop \NC \yes \NC \NR
1947 \NC \type {setproperty} \NC \nop \NC \yes \NC \NR
1948 \NC \type {setshift} \NC \nop \NC \yes \NC \NR
1949 \NC \type {setwidth} \NC \nop \NC \yes \NC \NR
1950 \NC \type {setwhd} \NC \nop \NC \yes \NC \NR
1951 \NC \type {setsub} \NC \nop \NC \yes \NC \NR
1952 \NC \type {setsubtype} \NC \nop \NC \yes \NC \NR
1953 \NC \type {setsup} \NC \nop \NC \yes \NC \NR
1954 \NC \type {slide} \NC \yes \NC \yes \NC \NR
1955 \NC \type {subtypes} \NC \yes \NC \nop \NC \NR
1956 \NC \type {subtype} \NC \yes \NC \nop \NC \NR
1957 \NC \type {tail} \NC \yes \NC \yes \NC \NR
1958 \NC \type {todirect} \NC \yes \NC \yes \NC \NR
1959 \NC \type {tonode} \NC \yes \NC \yes \NC \NR
1960 \NC \type {tostring} \NC \yes \NC \yes \NC \NR
1961 \NC \type {traverse_char} \NC \yes \NC \yes \NC \NR
1962 \NC \type {traverse_id} \NC \yes \NC \yes \NC \NR
1963 \NC \type {traverse} \NC \yes \NC \yes \NC \NR
1964 \NC \type {types} \NC \yes \NC \nop \NC \NR
1965 \NC \type {type} \NC \yes \NC \nop \NC \NR
1966 \NC \type {unprotect_glyphs} \NC \yes \NC \yes \NC \NR
1967 \NC \type {unset_attribute} \NC \yes \NC \yes \NC \NR
1968 \NC \type {usedlist} \NC \yes \NC \yes \NC \NR
1969 \NC \type {vpack} \NC \yes \NC \yes \NC \NR
1970 \NC \type {whatsitsubtypes} \NC \yes \NC \nop \NC \NR
1971 \NC \type {whatsits} \NC \yes \NC \nop \NC \NR
1972 \NC \type {write} \NC \yes \NC \yes \NC \NR
1973 \stoptabulate
1975 % \stopcolumns
1977 The \type {node.next} and \type {node.prev} functions will stay but for
1978 consistency there are variants called \type {getnext} and \type {getprev}. We had
1979 to use \type {get} because \type {node.id} and \type {node.subtype} are already
1980 taken for providing meta information about nodes. Note: The getters do only basic
1981 checking for valid keys. You should just stick to the keys mentioned in the
1982 sections that describe node properties.
1984 Some nodes have indirect references. For instance a math character refers to a
1985 family instead of a font. In that case we provide a virtual font field as
1986 accessor. So, \type {getfont} and \type {.font} can be used on them. The same is
1987 true for the \type {width}, \type {height} and \type {depth} of glue nodes. These
1988 actually access the spec node properties, and here we can set as well as get the
1989 values.
1991 \stopchapter
1993 \stopcomponent