Debian Codegraph @

texmf-dist/doc/luametatex/base/luametatex-nodes.tex

raw
1 % language=us runpath=texruns:manuals/luametatex
2
3 % \showenginevalues{alignmentcontextvalues}
4 % \showenginevalues{appendlinecontextvalues}
5 % \showenginevalues{automigrationvalues}
6 % \showenginevalues{autoparagraphvalues}
7 % \showenginevalues{getbalancestepoptionvalues}
8 % \showenginevalues{getbalancecallbackvalues}
9 % \showenginevalues{breakcontextvalues}
10 % \showenginevalues{buildcontextvalues}
11 % \showenginevalues{charactercontrolvalues}
12 % \showenginevalues{charactertagvalues}
13 % \showenginevalues{doublescriptoptionvalues}
14 % \showenginevalues{discpartvalues}
15 % \showenginevalues{glyphdiscvalues}
16 % \showenginevalues{fillvalues}
17 % \showenginevalues{flagvalues}
18 % \showenginevalues{groupvalues}
19 % \showenginevalues{hyphenationvalues}
20 % \showenginevalues{iovalues}
21 % \showenginevalues{kerneloptionvalues}
22 % \showenginevalues{linebreakstatevalues}
23 % \showenginevalues{mathclassoptionvalues}
24 % \showenginevalues{mathcontrolvalues}
25 % \showenginevalues{mathgluevalues}
26 % \showenginevalues{mathoptionvalues}
27 % \showenginevalues{mathparametervalues}
28 % \showenginevalues{mathscriptordervalues}
29 % \showenginevalues{mathscriptsmodevalues}
30 % \showenginevalues{mathsurroundvalues}
31 % \showenginevalues{mathvariantpresets}
32 % \showenginevalues{mathvariantvalues}
33 % \showenginevalues{modevalues}
34 % \showenginevalues{mvloptionvalues}
35 % \showenginevalues{normalizelinevalues}
36 % \showenginevalues{normalizeparvalues}
37 % \showenginevalues{packtypevalues}
38 % \showenginevalues{pagecontextvalues}
39 % \showenginevalues{parametermodevalues}
40 % \showenginevalues{parcontextvalues}
41 % \showenginevalues{parmodevalues}
42 % \showenginevalues{partriggervalues}
43 % \showenginevalues{prepoststatevalues}
44 % \showenginevalues{protrusionboundaryvalues}
45 % \showenginevalues{runstatevalues}
46 % \showenginevalues{shapingpenaltiesvalues}
47 % \showenginevalues{specialmathclassvalues}
48 % \showenginevalues{specificationoptionvalues}
49 % \showenginevalues{textcontrolvalues}
50 % \showenginevalues{uleaderlocationvalues}
51 % \showenginevalues{unitclassvalues}
52
53 % function node.direct.addmargins
54 % function node.direct.addxoffset
55 % function node.direct.addxymargins
56 % function node.direct.addyoffset
57
58 % function node.direct.appendaftertail
59 % function node.direct.appendtocurrentlist
60 % function node.direct.prependbeforehead
61
62 % function node.direct.collapsing
63
64 % function node.direct.copyonly
65
66 % function node.direct.effectiveglue
67
68 % function node.direct.exchange
69
70 % function node.direct.findattributerange
71 % function node.direct.firstchar
72 % function node.direct.firstglyph
73 % function node.direct.firstitalicglyph
74
75 % function node.direct.flushnode
76
77 % function node.direct.getanchors
78
79 % function node.direct.getattribute
80 % function node.direct.getattributelist
81 % function node.direct.getattributes
82 %
83 % function node.direct.setattributelist
84 % function node.direct.setattributes
85 %
86 % function node.direct.unsetattributes
87 % function node.direct.patchattributes
88 % function node.direct.getusedattributes
89 % function node.direct.currentattributes
90
91 % function node.direct.getbox
92 %
93 % function node.direct.setbox
94
95 % function node.direct.getchar
96 % function node.direct.getchardict
97 % function node.direct.getcharspec
98 %
99 % function node.direct.setchar
100 % function node.direct.setchardict
101
102 % function node.direct.getchoice
103 %
104 % function node.direct.setchoice
105
106 % function node.direct.getclass
107 % function node.direct.setclass
108
109 % function node.direct.getcontrol
110 % function node.direct.setcontrol
111
112 % function node.direct.getcornerkerns
113
114 % function node.direct.getdata
115 % function node.direct.setdata
116
117 % function node.direct.getdegree
118 % function node.direct.setdegree
119
120 % function node.direct.getdelimiter
121 % function node.direct.setdelimiter
122
123 % function node.direct.setdirection
124 % function node.direct.getdirection
125
126 % function node.direct.getexcept
127 % function node.direct.setexcept
128
129 % ....
130 %
131 % function node.direct.setfam
132
133 % function node.direct.getfield
134 % function node.direct.setfield
135
136 % function node.direct.getfont
137 % function node.direct.setfont
138
139 % function node.direct.getgeometry
140 % function node.direct.setgeometry
141
142 % function node.direct.getglue
143 % function node.direct.setglue
144
145 % function node.direct.getglyphdata
146 % function node.direct.setglyphdata
147
148 % function node.direct.getid
149 % function node.direct.getidsubtype
150
151 % function node.direct.getindex
152 % function node.direct.setindex
153
154 % function node.direct.getinputfields
155 % function node.direct.setinputfields
156
157 % function node.direct.getkern
158 % function node.direct.setkern
159
160 % function node.direct.getglyphdimensions
161 % function node.direct.getruledimensions
162 % function node.direct.getlistdimensions
163 % function node.direct.getkerndimension
164 %
165 % function node.direct.setruledimensions
166
167 % function node.direct.getlanguage
168 % function node.direct.setlanguage
169
170 % function node.direct.getnodes
171
172 % function node.direct.getnormalizedline
173
174 % function node.direct.getnumerator
175 % function node.direct.setnumerator
176
177 % function node.direct.getdenominator
178 % function node.direct.setdenominator
179
180 % function node.direct.getoffsets
181 % function node.direct.setoffsets
182
183 % function node.direct.getoptions
184 % function node.direct.setoptions
185
186 % function node.direct.getorientation
187 % function node.direct.setorientation
188
189 % function node.direct.getparstate
190
191 % function node.direct.getpenalty
192 % function node.direct.setpenalty
193
194 % function node.direct.getpropertiestable
195
196 % function node.direct.getfam
197
198 % function node.direct.getrightdelimiter
199 % function node.direct.getleftdelimiter
200 % function node.direct.gettopdelimiter
201 % function node.direct.getbottomdelimiter
202 %
203 % function node.direct.setbottomdelimiter
204 % function node.direct.setrightdelimiter
205 % function node.direct.setleftdelimiter
206 % function node.direct.settopdelimiter
207
208 % function node.direct.getscript
209 % function node.direct.setscript
210
211 % function node.direct.getspeciallist
212 % function node.direct.setspeciallist
213
214 % function node.direct.getstate (n,[state])
215 %
216 % function node.direct.setstate
217
218 % function node.direct.getscale
219 % function node.direct.getscales
220 %
221 % function node.direct.setscales
222
223 % function node.direct.getsubtype
224 %
225 % function node.direct.setsubtype
226
227 % function node.direct.getbottom
228 % function node.direct.gettop
229 %
230 % function node.direct.setbottom
231 % function node.direct.settop
232
233 % function node.direct.getwordrange
234
235 % function node.direct.getxscale
236 % function node.direct.getxyscales
237 % function node.direct.getyscale
238
239 % function node.direct.hasattribute
240 % function node.direct.hasdimensions
241 % function node.direct.hasdiscoption
242 % function node.direct.hasgeometry
243 % function node.direct.hasglyphoption
244
245 % function node.direct.hyphenating
246
247 % function node.direct.ignoremathskip
248
249 % function node.direct.isboth
250 % function node.direct.ischar
251 % function node.direct.isdirect
252 % function node.direct.isglyph
253 % function node.direct.isitalicglyph
254 % function node.direct.isnext
255 % function node.direct.isnextchar
256 % function node.direct.isnextglyph
257 % function node.direct.isnode
258 % function node.direct.isprev
259 % function node.direct.isprevchar
260 % function node.direct.isprevglyph
261 % function node.direct.issimilarglyph
262 % function node.direct.isspeciallist
263 % function node.direct.isvalid
264
265 % function node.direct.lastnode
266
267 % function node.direct.makeextensible
268
269 % function node.direct.migrate
270
271 % function node.direct.naturalhsize
272
273 % function node.direct.newcontinuationatom
274
275 % function node.direct.newmathglyph
276 % function node.direct.newtextglyph
277
278 % function node.direct.patchparshape
279
280 % function node.direct.protectglyphsnone
281
282 % function node.direct.removefromlist
283
284 % function node.direct.repack
285 % function node.direct.reverse
286
287 % function node.direct.serialized
288 % function node.direct.setanchors
289
290 % function node.direct.setlink
291
292 % function node.direct.setsplit
293
294 % function node.direct.settotal
295
296 % function node.direct.show
297
298 % function node.direct.softenhyphens
299
300 % function node.direct.startofpar
301
302 % function node.direct.tostring
303 % function node.direct.tovaliddirect
304
305 % function node.direct.traverseitalic
306 % function node.direct.traverseleader
307
308 % function node.direct.usedlist
309 % function node.direct.usesfont
310
311 % function node.direct.verticalbreak
312
313 % function node.direct.xscaled
314 % function node.direct.yscaled
315
316 % function node.direct.isloop -- undocumented
317
318 % node.shared.size
319 % node.shared.id
320 % node.shared.getcachestate
321
322 % node.hybrid.gluetostring
323
324 \environment luametatex-style
325
326 \startdocument[title=Nodes]
327
328 \startsection[title={Introduction}]
329
330 The (to be) typeset content is collected in a double linked list of so called
331 nodes. A node is an array of values. When looked at from the \LUA\ end you can
332 either seen them as \type [option=LUA] {<t:userdata>} or as \type [option=LUA]
333 {<t:integer>}. In the case of userdata you access fields like this:
334
335 \starttyping [option=LUA]
336 local width = foo.width -- foo is userdata
337 \stoptyping
338
339 while the indexed variant uses:
340
341 \starttyping [option=LUA]
342 local width = nodes.direct.getwidth(foo) -- foo is an integer
343 \stoptyping
344
345 In \CONTEXT\ we mostly use the second variant but it's a matter of taste so users
346 can you whatever they like most. When you print a userdata node you see something
347 like this:
348
349 \startlines
350 \startluacode
351 context.type(tostring(node.new("glyph"))) context.par()
352 context.type(tostring(node.new("hlist"))) context.par()
353 context.type(tostring(node.new("glue" ))) context.par()
354 \stopluacode
355 \stoplines
356
357 The number in the middle is the one you would also see if you use the indexed
358 approach and often these numbers are kind of large. A number \type {13295}
359 doesn't mean that we have that many nodes. The engine has a large array of memory
360 words (pairs of 32 bit integers) and a node is a slice of then with the index
361 pointing to where we start. So, if we have a node that has 5 value pairs, the
362 slice runs from \type {13295} upto \type {13299} that consume 40 bytes.
363
364 In this chapter we introduce the nodes that are exposed to the user. We will
365 discuss the relevant fields as well as ways to access them. Because there are
366 similar fields in different nodes, we can share accessors.
367
368 It is important to notice that not all fields that can be accessed (set and get)
369 are under full user control. For instance, in math we have a \type {noad} type
370 that is actually shared between several construct (like atoms, accents and
371 fences) and not all parameters make sense for each of them. Some properties are
372 set while the formula is assembled. It fits in the \LUAMETATEX\ concept to open
373 up everything but abusing this can lead to side effects. It makes no sense to add
374 all kind of safeguards against wrong or unintended usage because in the end only
375 a few users will go that low level anyway.
376
377 Not all fields mentioned are accessible in the userdata variant. It is also good
378 to notice that some fields are fabricated, for instance \type {total} is the sum
379 of \type {height} and \type {depth}.
380
381 \stopsection
382
383 \startsection[title={\LUA\ node representation}]
384
385 As mentioned, nodes are represented in \LUA\ as user data objects with a variable
386 set of fields or by a numeric identifier when requested and we showed that when
387 you print a node user data object you will see these numbers.
388
389 \startfourrows
390 \ctxlua{moduledata.node.codes("types")}
391 \stopfourrows
392
393 You can ask for a list of fields with \type {node.fields} and for valid subtypes
394 with \type {node.subtypes}. There are plenty specific field values and you can
395 some idea about them by calling \type {tex.get*values()} which returns a table if
396 numbers (exclusive numbers or bits). We use these to get the tables that are
397 shown with each node type.
398
399 There are a lot of helpers and below we show them per node type. In later
400 sections some will come back organized by type of usage. Trivial getters and
401 setters will not be discussed. It's good to know that some getters take more
402 arguments where the second one can for instance trigger more return values. The
403 number of arguments to a setter can also be more than a few. As with everything
404 \LUAMETATEX\ the \CONTEXT\ sources can also be seen as a reference.
405
406 \stopsection
407
408 \startsection[title={Main text nodes}]
409
410 These are the nodes that comprise actual typesetting commands. A few fields are
411 present in all nodes regardless of their type, these are: \type {next}, \type
412 {id} and \type {subtype}. The \type {subtype} is sometimes just a dummy entry
413 because not all nodes actually use the \type {subtype}, but this way you can be
414 sure that all nodes accept it as a valid field name, and that is often handy in
415 node list traversal. In the following tables \type {next} and \type {id} are not
416 explicitly mentioned. Besides these three fields, almost all nodes also have an
417 \type {attr} field, and there is a also a field called \type {prev}.
418
419 \startsubsection[title={hlist and vlist, aka boxes}]
420
421 These lists share fields and subtypes although some subtypes can only occur in
422 horizontal lists while others are unique for vertical lists.
423
424 \showenginefields {hlist}
425 \showenginesubtypes {hlist}
426 \showenginevalues {directionvalues}
427 \showenginevalues {listgeometryvalues}
428 \showenginevalues {listanchorvalues}
429 \showenginevalues {listsignvalues}
430
431 The \type {shift} is a displacement perpendicular to the character (horizontal) or
432 line (vertical) progression direction.
433
434 The \type {orientation}, \type {woffset}, \type {hoffset}, \type {doffset}, \type
435 {xoffset} and \type {yoffset} fields are special. They can be used to make the
436 backend rotate and shift boxes which can be handy in for instance vertical
437 typesetting. Because they relate to (and depend on the) the backend they are not
438 discussed here (yet). The \type {pre} and \type {post} fields refer to migrated
439 material in both list types, while the adjusted variants only make sense in
440 horizontal lists.
441
442 \showengineusagepernode{hlist}
443
444 \stopsubsection
445
446 \startsubsection[title={rule}]
447
448 Contrary to traditional \TEX, \LUATEX\ has more subtypes subtypes because we also
449 use rules to store reuseable objects and images. However, in \LUAMETATEX\ these
450 are gone but we reserve these subtypes. Apart form the basic rules a lot is up to
451 the backend.
452
453 \showenginefields {rule}
454 \showenginesubtypes {rule}
455 \showenginevalues {ruleoptionvalues}
456
457 The width, height and depth of regular rules defaults to the special value of
458 $\cldcontext {tex . magicconstants . runningrule}$ which indicates a running rule
459 that adapts its dimensions to the box that it sits in.
460
461 The \type {left} and type {right} keys are somewhat special (and experimental).
462 When rules are auto adapting to the surrounding box width you can enforce a shift
463 to the right by setting \type {left}. The value is also subtracted from the width
464 which can be a value set by the engine itself and is not entirely under user
465 control. The \type {right} is also subtracted from the width. It all happens in
466 the backend so these are not affecting the calculations in the frontend (actually
467 the auto settings also happen in the backend). For a vertical rule \type {left}
468 affects the height and \type {right} affects the depth. There is no matching
469 interface at the \TEX\ end (although we can have more keywords for rules it would
470 complicate matters and introduce a speed penalty.) However, you can just
471 construct a rule node with \LUA\ and write it to the \TEX\ input. The \type
472 {outline} subtype is just a convenient variant and the \type {transform} field
473 specifies the width of the outline. The \type {xoffset} and \type {yoffset}
474 fields can be used to shift rules. Because they relate to (and depend on the) the
475 backend they are not discussed here (yet). Of course all this assumes that the
476 backend deals with it. Internally fields with different names can use the same
477 variable, depending on the subtype; dedicated names just make more sense.
478
479 \showengineusagepernode{rule}
480
481 \stopsubsection
482
483 \startsubsection[title={insert}]
484
485 This node relates to the \type {\insert} primitive and support the fields:
486
487 \showenginefields {insert}
488
489 Here the subtype indicates the class of the insert and that number is also used
490 to access the box, dimen and skip registers that relate to the insert, if we
491 use inserts in the traditional way.
492
493 \showengineusagepernode{insert}
494
495 \stopsubsection
496
497 \startsubsection[title={mark}]
498
499 This one relates to the \type {\marks} primitive and only has a few fields, one
500 being a token list as field which is kind of rare.
501
502 \showenginefields {mark}
503 \showenginesubtypes {mark}
504
505 \showengineusagepernode{mark}
506
507 \stopsubsection
508
509 \startsubsection[title={adjust}]
510
511 This node results from \type {\vadjust} usage:
512
513 \showenginefields {adjust}
514 \showenginesubtypes {adjust}
515 \showenginevalues {adjustoptionvalues}
516
517 \showengineusagepernode{vadjust}
518
519 \stopsubsection
520
521 \startsubsection[title={disc (discretionary)}]
522
523 The \typ {\discretionary}, \typ {\explicitdiscretionary} and \typ
524 {\automaticdiscretionary} primitives as well as the discretionary that comes from
525 hyphenation all have the pre, post and replace lists. Because these lists have
526 head and tail pointers the getters and setters handle this for you.
527
528 \showenginefields {disc}
529 \showenginesubtypes {disc}
530 \showenginevalues {discoptionvalues}
531
532 \showengineusagepernode{disc}
533
534 \stopsubsection
535
536 \startsubsection[title={math}]
537
538 Math nodes represent the boundaries of a math formula, normally wrapped between
539 \type {$} and \type {$}. The glue fields are only used when the \type {surround}
540 field is zero.
541
542 \showenginefields {math}
543 \showenginesubtypes {math}
544
545 \showengineusagepernode{math}
546
547 \stopsubsection
548
549 \startsubsection[title={glue}]
550
551 Skips are about the only type of data objects in traditional \TEX\ that are not a
552 simple value. They are inserted when \TEX\ sees a space in the text flow but also
553 by \type {\hskip} and \type {skip}. The structure that represents the glue
554 components of a skip internally is called a \type {gluespec}. In \LUAMETATEX\ we
555 don't use the spec itself but just its values.
556
557 \showenginefields {glue}
558 \showenginesubtypes {glue}
559 \showenginevalues {glueoptionvalues}
560
561 Note that we use the key \type {width} in both horizontal and vertical glue. This
562 suited the \TEX\ internals well so we decided to stick to that naming.
563
564 The effective width of some glue subtypes depends on the stretch or shrink needed
565 to make the encapsulating box fit its dimensions. For instance, in a paragraph
566 lines normally have glue representing spaces and these stretch or shrink to make
567 the content fit in the available space. The \type {effectiveglue} function that
568 takes a glue node and a parent (hlist or vlist) returns the effective width of
569 that glue item. When you pass \type {true} as third argument the value will be
570 rounded.
571
572 \showengineusagepernode{glue}
573
574 \stopsubsection
575
576 \startsubsection[title={gluespec}]
577
578 Internally \LUAMETATEX\ (like its ancestors) also uses nodes to store data that
579 is not seen in node lists. For instance the state of expression scanning (\type
580 {\dimexpr} etc.) and conditionals (\type {\ifcase} etc.) is also kept in lists of
581 nodes. A glue, which has five components, is stored in a node as well, so, where
582 most registers store just a number, a skip register (of internal quantity) uses a
583 pointer to a glue spec node. It has similar fields as glue nodes, which is not
584 surprising because in the past (and other engines than \LUATEX) a glue node also
585 has its values stored in a glue spec. This has some advantages because often the
586 values are the same, so for instance spacing related skips were not resolved
587 immediately but pointed to the current value of a space related internal register
588 (like \type {\spaceskip}). But, in \LUATEX\ and therefore \LUAMETATEX\ we do
589 resolve these quantities immediately and we put the current values in the glue
590 nodes.
591
592 \showenginefields {gluespec}
593
594 You will only find these nodes in a few places, for instance when you query an
595 internal quantity. In principle we could do without them as we have interfaces
596 that use the five numbers instead. For compatibility reasons we keep glue spec
597 nodes exposed but this might change in the future. Of course there are no
598 subtypes here because it's just a data store.
599
600 \showengineusagepernode{gluespec}
601
602 \stopsubsection
603
604 \startsubsection[title={kern}]
605
606 The \type {\kern} command creates such nodes but for instance the font and math
607 machinery can also add them.
608
609 \showenginefields {kern}
610 \showenginesubtypes {kern}
611
612 \showengineusagepernode{kern}
613
614 \stopsubsection
615
616 \startsubsection[title={penalty}]
617
618 The \type {\penalty} command is one that generates these nodes. There is not much
619 to tell about them, apart from that in \LUAMETATEX\ they have options and a
620 possible spread related \type {nepalty} field that is used internally.
621
622 \showenginefields {penalty}
623 \showenginesubtypes {penalty}
624 \showenginevalues {penaltyoptionvalues}
625
626 \showengineusagepernode{penalty}
627
628 \stopsubsection
629
630 \startsubsection[title={glyph}]
631
632 These are probably the mostly used nodes and although you can push them in the
633 current list with for instance \prm {char} \TEX\ will normally do it for you when
634 it considers some input to be text. Glyph nodes are relatively large and have many
635 fields.
636
637 \showenginefields {glyph}
638 \showenginesubtypes {glyph}
639 \showenginevalues {glyphoptionvalues}
640 \showenginevalues {glyphdiscvalues}
641 \showenginevalues {discpartvalues}
642 \showenginevalues {glyphprotectionvalues}
643
644 The \type {width}, \type {height} and \type {depth} values are read|-|only.
645 In \LUATEX\ \type {expansion} has been introduced as part of the separation between
646 front- and backend. It is the result of extensive experiments with a more
647 efficient implementation of expansion. Early versions of \LUATEX\ already
648 replaced multiple instances of fonts in the backend by scaling but contrary to
649 \PDFTEX\ in \LUATEX\ we now also got rid of font copies in the frontend and
650 replaced them by expansion factors that travel with glyph nodes. Apart from a
651 cleaner approach this is also a step towards a better separation between front-
652 and backend.
653
654 % The \type {ischar} function checks if a node is a glyph node with a subtype still
655 % less than 256. This function can be used to determine if applying font logic to a
656 % glyph node makes sense. The value \type {nil} gets returned when the node is not
657 % a glyph, a character number is returned if the node is still tagged as character
658 % and \type {false} gets returned otherwise. When nil is returned, the id is also
659 % returned. The \type {isglyph} variant doesn't check for a subtype being less
660 % than 256, so it returns either the character value or nil plus the id. These
661 % helpers are not always faster than separate calls but they sometimes permit
662 % making more readable tests. The \type {usesfont} helpers takes a node
663 % and font id and returns true when a glyph or disc node references that font.
664
665 % The \type {isnextchar} and \type {isprevchar} return a next node, a character
666 % code (or false) and an node id or next character code. The four \type {is}
667 % checkers take a node and optionally a font, data, state, scale, xscale and yscale
668 % value that are then checked.
669
670 \showengineusagepernode{glyph}
671
672 \stopsubsection
673
674 \startsubsection[title={boundary}]
675
676 This node relates to the \type {\noboundary}, \type {\boundary}, \type
677 {\protrusionboundary}, \type {\wordboundary} etc. These are relative small nodes
678 that determine what happens before and after them.
679
680 \showenginefields {boundary}
681 \showenginesubtypes {boundary}
682 \showenginevalues {protrusionboundaryvalues}
683
684 \showengineusagepernode{boundary}
685
686 \stopsubsection
687
688 \startsubsection[title={par}]
689
690 This node is inserted at the start of a paragraph. You should not mess too much
691 with this one. They are also inserted when \type {\local...} primitives are used
692 that relate boxes to positions in the line and overload certain parameters that
693 play a role in the line break routine. There are many fields!
694
695 \showenginefields[2]{par}
696 \showenginesubtypes {par}
697
698 \showengineusagepernode{par}
699
700 \stopsubsection
701
702 \startsubsection[title={dir}]
703
704 Direction nodes mark parts of the running text that need a change of direction
705 and the \type {\textdirection} command generates them. Contrary to \LUATEX\
706 we only have two directions.
707
708 \showenginefields {dir}
709 \showenginesubtypes {dir}
710
711 \showengineusagepernode{dir}
712
713 \stopsubsection
714
715 \startsubsection[title={whatsit}]
716
717 A whatsit node is a real simple one and it only has a subtype. It is even less
718 than a user node (which it actually could be) and uses hardly any memory. What
719 you do with it it entirely up to you: it's is real minimalistic. You can assign a
720 subtype and it has attributes. It is all up to the user (and the backend) how
721 they are handled.
722
723 \showenginefields {whatsit}
724
725 \showengineusagepernode{whatsit}
726
727 \stopsubsection
728
729 \startsubsection[title={attribute}]
730
731 This is a small node but used a lot. When an attribute is set and travels with a
732 node, we actually have a forward (only) linked list with a head node that keeps a
733 reference count. These lists are (to be) sorted by attribute index. Normally you
734 will {\em not} mess directly with these list because you can get unwanted side
735 effects.
736
737 \showenginefields {attribute}
738 \showenginesubtypes {attribute}
739
740 \showengineusagepernode{attribute}
741
742 \stopsubsection
743
744 \startsubsection[title={alignrecord}]
745
746 This node can be encountered in alignments and will eventually become a \type
747 {hlist} or \type {vlist} node. It therefore has the same size and fields as those
748 nodes. However, the following fields are overloaded by other parameters: \type
749 {woffset}, \type {hoffset}, \type {doffset}, \type {xoffset}, \type {yoffset},
750 \type {orientation}, \type {pre} and \type {post}. Be careful!
751
752 \showenginefields {alignrecord}
753
754 \showengineusagepernode{alignrecord}
755
756 \stopsubsection
757
758 \startsubsection[title={unset}]
759
760 This node can be encountered in alignments and will eventually become a \type
761 {hlist} or \type {vlist} node. It therefore has the same size and fields as those
762 nodes. However, the following fields are (at least temporarily) there and they
763 use the slots of \type {woffset}, \type {hoffset}, \type {doffset} and \type
764 {orientation}. Be careful!
765
766 \showenginefields {unset}
767
768 \showengineusagepernode{unset}
769
770 \stopsubsection
771
772 \stopsection
773
774 \startsection[title={Math nodes}]
775
776 \startsubsection[title=The concept]
777
778 Many object fields in math mode are either simple characters in a specific family
779 or math lists or node lists: \type {mathchar}, \type {mathtextchar}, {subbox}
780 and \type {submlist} and \type {delimiter}. These are endpoints and therefore the
781 \type {next} and \type {prev} fields of these these subnodes are unused.
782
783 There is a subset of nodes dedicated to math called noads. These are used for
784 simple atoms, fractions, fences, accents and radicals. When you enter a formula,
785 \TEX\ creates a node list with regular (math) nodes and noads. Then it hands over
786 the list the math processing engine. The result of that is a nodelist without
787 noads. Most of the noads contain subnodes so that the list of possible fields is
788 actually quite small. Math formulas are both a linked list and a tree. For
789 instance in $e = mc^2$ there is a linked list \type {e = m c} but the \type {c}
790 has a superscript branch that itself can be a list with branches.
791
792 Eventually I might give a more detailed description of the differences between
793 the five noad variants but for now the following has to do. One will quite likely
794 not set that many fields at the \LUA\ end but running over the many sub lists can
795 make sense. One has to know what the engine is doing anyway.
796
797 \stopsubsection
798
799 \startsubsection[title=noad]
800
801 First, there are the objects (the \TEX book calls them \quote {atoms}) that are
802 associated with the simple math objects: ord, op, bin, rel, open, close, punct,
803 inner, over, under, vcenter. These all have the same fields, and they are
804 combined into a single node type with separate subtypes for differentiation.
805 However, before reading on you should realize that \LUAMETATEX\ has an extended
806 math engine. We hale not only more classes, we also have many more keys in the
807 nodes. We won't cover these details here.
808
809 \showenginefields {noad}
810 \showenginesubtypes {noad}
811 \showenginevalues {noadoptionvalues}
812
813 In addition to the subtypes (related to classes) that the engines knows of, there
814 can be user defined subtypes. Not all fields make sense for every derives noad:
815 \type {accent}, \type {fence}, \type {fraction} or \type {radical} but there we
816 (currently) only mention the additional ones. These additional fields are taken
817 from a pool of extra fields. Not all fields are always accessible for these nodes.
818
819 \showengineusagepernode{noad}
820
821 \stopsubsection
822
823 \startsubsection[title=mathchar]
824
825 The \type {mathchar} is the simplest subnode field, it contains the character and
826 family for a single glyph object. The family eventually resolves on a reference
827 to a font. Internally this nodes is one of the math kernel nodes.
828
829 \showenginefields {mathchar}
830 %showenginesubtypes {mathchar}
831 \showenginevalues {kerneloptionvalues}
832
833 \showengineusagepernode{mathchar}
834
835 \stopsubsection
836
837 \startsubsection[title=mathtextchar]
838
839 The \type {mathtextchar} is a special case that you will not normally encounter,
840 it arises temporarily during math list conversion (its sole function is to
841 suppress a following italic correction). Internally this nodes is one of the math
842 kernel nodes.
843
844 \showenginefields {mathtextchar}
845 %showenginesubtypes {mathtextchar}
846 \showenginevalues {kerneloptionvalues}
847
848 \showengineusagepernode{mathtextchar}
849
850 \stopsubsection
851
852 \startsubsection[title=subbox]
853
854 These \type {subbox} subnode is used for subsidiary list items where
855 the \type {list} points to a \quote {normal} vbox or hbox.
856
857 \showenginefields {subbox}
858 %showenginesubtypes {subbox}
859
860 \showengineusagepernode{subbox}
861
862 \stopsubsection
863
864 \startsubsection[title=submlist]
865
866 In \type {submlist} subnode the \type {list} points to a math list that is yet to
867 be converted. Their fields
868
869 \showenginefields {submlist}
870 %showenginesubtypes {submlist}
871
872 \showengineusagepernode{submlist}
873
874 \stopsubsection
875
876 \startsubsection[title={delimiter}]
877
878 There is a fifth subnode type that is used exclusively for delimiter fields. As
879 before, the \type {next} and \type {prev} fields are unused, but we do have:
880
881 \showenginefields {delimiter}
882 %showenginesubtypes {delimiter}
883
884 The fields \type {largechar} and \type {largefamily} can be zero, in that case
885 the font that is set for the \type {smallfamily} is expected to provide the large
886 version as an extension to the \type {smallchar}.
887
888 \showengineusagepernode{delimiter}
889
890 \stopsubsection
891
892 \startsubsection[title={accent}]
893
894 Accent nodes deal with stuff on top or below a math constructs.
895
896 \showenginefields {accent}
897 \showenginesubtypes {accent}
898
899 {\em For more fields see \type {noad}. At some point we might move fields from
900 that list to here but only when the engine also gets that split.}
901
902 \showengineusagepernode{accent}
903
904 \stopsubsection
905
906 \startsubsection[title={style}]
907
908 These nodes are signals to switch to another math style. Currently the subtype is
909 actually used to store the style but don't rely on that for the future.
910
911 \showenginefields {style}
912 %showenginesubtypes {style}
913 \showenginevalues {mathstylenamevalues}
914 \showenginevalues {mathstylevalues}
915
916 \showengineusagepernode{style}
917
918 \stopsubsection
919
920 \startsubsection[title={parameter}]
921
922 These nodes are used to (locally) set math parameters. The subtype reflects a math style.
923
924 \showenginefields {parameter}
925
926 \showengineusagepernode{parameter}
927
928 \stopsubsection
929
930 \startsubsection[title={choice}]
931
932 Most of the fields of this node are lists. Depending on the subtype different
933 field names are used.
934
935 \showenginefields {choice}
936 \showenginesubtypes {choice}
937
938 \showengineusagepernode{choice}
939
940 \stopsubsection
941
942 \startsubsection[title={radical}]
943
944 Radical nodes are the most complex as they deal with scripts as well as
945 constructed large symbols. Warning: never assign a node list to the \type
946 {nucleus}, \type {sub}, \type {sup}, \type {left}, or \type {degree} field unless
947 you are sure its internal link structure is correct, otherwise an error can be
948 triggered.
949
950 \showenginefields {radical}
951 \showenginesubtypes {radical}
952
953 {\em For more fields see \type {noad}. At some point we might move fields from
954 that list to here but only when the engine also gets that split.}
955
956 \showengineusagepernode{radical}
957
958 \stopsubsection
959
960 \startsubsection[title={fraction}]
961
962 Fraction nodes are also used for delimited cases, hence the \type {left} and
963 \type {right} fields among.
964
965 \showenginefields {fraction}
966 \showenginesubtypes {fraction}
967
968 {\em For more fields see \type {noad}. At some point we might move fields from
969 that list to here but only when the engine also gets that split.}
970
971 \showengineusagepernode{fraction}
972
973 \stopsubsection
974
975 \startsubsection[title={fence}]
976
977 Fence nodes come in pairs but either one can be a dummy (this period driven empty
978 fence). Some of these fields are used by the renderer and might get adapted in
979 the process.
980
981 \showenginefields {fence}
982 \showenginesubtypes {fence}
983
984 {\em For more fields see \type {noad}. At some point we might move fields from
985 that list to here but only when the engine also gets that split.}
986
987 \showengineusagepernode{fence}
988
989 \stopsubsection
990
991 \stopsection
992
993 \startsection[title=Helpers]
994
995 \startsubsection[title={Introduction}]
996
997 The userdata node variant has accessors on that object but when we use the
998 indexed variant we use functions. As a consequence there are more helpers for
999 direct nodes that for userdata nodes and many of them accept more arguments or
1000 have multiple return values. When you use \CONTEXT\ you will notice that instead
1001 of the \typ {node.direct} namespace we use \type {nuts}. Among the reasons is
1002 that we had an intermediate variant in \CONTEXT\ \MKIV\ before we had these
1003 direct nodes. That variant was more efficient than the userdata accessors and
1004 triggered the introduction of direct nodes after which we dropped the
1005 intermediate variant. So, for \CONTEXT\ users direct nodes are nuts.
1006
1007 \stopsubsection
1008
1009 \startsubsection[title={Housekeeping}]
1010
1011 This function returns an array that maps node id numbers to node type strings,
1012 providing an overview of the possible top|-|level \type {id} types.
1013
1014 \starttyping[option=LUA]
1015 function node.types ( )
1016 return <t:table> -- identifiers
1017 end
1018 \stoptyping
1019
1020 This shows the names of the nodes and their internal numbers. Not all nodes are
1021 visible unless one goes really deep down into lists. The next two convert a name
1022 to its internal numeric representation and vise versa. The numbers don't relate
1023 to importance or some ordering; they just appear in the order that is handy for
1024 the engine. Commands like this are rather optimized so performance should be ok
1025 but you can of course always store the id in a \LUA\ number.
1026
1027 \starttyping[option=LUA]
1028 function node.id ( <t:string> name )
1029 return <t:integer> -- identifier
1030 end
1031
1032 function node.type ( <t:integer> identifier )
1033 return <t:string> -- name
1034 end
1035 \stoptyping
1036
1037 This function returns an indexed table with valid field names for a particular
1038 type of node. Some fields (like \type {total}) can be constructed from other
1039 fields.
1040
1041 \starttyping[option=LUA]
1042 function node.fields ( <t:integer> identifier | <t:string> name )
1043 return <t:table> -- fields
1044 end
1045 \stoptyping
1046
1047 The \type {hasfield} function returns a boolean that is only true if \type {n} is
1048 actually a node, and it has the field.This function probably is not that useful
1049 but some nodes don't have a \type {subtype}, \type {attr} or \type {prev} field
1050 and this is a way to test for that.
1051
1052 \starttyping[option=LUA]
1053 function node.direct.hasfield ( <t:direct> n | <t:string> name )
1054 return <t:boolean> -- okay
1055 end
1056 \stoptyping
1057
1058 The \type {new} function creates a new node. All its fields are initialized to
1059 either zero or \type {nil} except for \type {id} and \type {subtype}. Instead of
1060 numbers you can also use strings (names). If you pass a second argument the
1061 subtype will be set too.
1062
1063 \starttyping[option=LUA]
1064 function node.direct.new (
1065 <t:number> id | <t:string> name
1066 )
1067 return <t:direct.> -- node
1068 end
1069
1070 function node.direct.new (
1071 <t:number> id | <t:string> name,
1072 <t:number> | <t:string> subtype
1073 )
1074 return <t:direct.> -- node
1075 end
1076 \stoptyping
1077
1078 As already has been mentioned, you are responsible for making sure that nodes
1079 created this way are used only once, and are freed when you don't pass them
1080 back somehow.
1081
1082 The next one frees node \type {n} from \TEX's memory. Be careful: no checks are
1083 done on whether this node is still pointed to from a register or some \type
1084 {next} field: it is up to you to make sure that the internal data structures
1085 remain correct. Fields that point to nodes or lists are flushed too. So, when
1086 you used their content for something else you need to set them to nil first.
1087
1088 \starttyping[option=LUA]
1089 function node.direct.free ( <t:direct> n )
1090 return <t:direct> -- next
1091 end
1092 \stoptyping
1093
1094 The \type {free} function returns the next field of the freed node, while the
1095 \type {flushnode} alternative returns nothing.
1096
1097 \starttyping[option=LUA]
1098 function node.direct.flush ( <t:direct> n )
1099 -- no return values
1100 end
1101 \stoptyping
1102
1103 A list starting with node \type {n} can be flushed from \TEX's memory too. Be
1104 careful: no checks are done on whether any of these nodes is still pointed to
1105 from a register or some \type {next} field: it is up to you to make sure that the
1106 internal data structures remain correct.
1107
1108 \starttyping[option=LUA]
1109 function node.direct.flushlist ( <t:direct> n )
1110 -- no return values
1111 end
1112 \stoptyping
1113
1114 When you free for instance a discretionary node, \type {flushlist} is applied to
1115 the \type {pre}, \type {post}, \type {replace} so you don't need to do that
1116 yourself. Assigning them \type {nil} won't free those lists!
1117
1118 This creates a deep copy of node \type {n}, including all nested lists as in the case
1119 of a hlist or vlist node. Only the \type {next} field is not copied.
1120
1121 \starttyping[option=LUA]
1122 function node.direct.copy ( <t:direct> n )
1123 return <t:direct> -- copy
1124 end
1125 \stoptyping
1126
1127 A deep copy of the node list that starts at \type {n} can be created too. If
1128 \type {m} is also given, the copy stops just before node \type {m}.
1129
1130 \starttyping[option=LUA]
1131 function node.direct.copylist ( <t:direct> n )
1132 return <t:direct> -- copy
1133 end
1134
1135 function node.direct.copylist ( <t:direct> n, <t:direct> m )
1136 return <t:direct> -- copy
1137 end
1138 \stoptyping
1139
1140 Note that you cannot copy attribute lists this way. However, there is normally no
1141 need to copy attribute lists because when you do assignments to the \type {attr}
1142 field or make changes to specific attributes, the needed copying and freeing
1143 takes place automatically. When you change a value of an attribute {\em in} a
1144 list, it will affect all the nodes that share that list.
1145
1146 \starttyping[option=LUA]
1147 function node.direct.write ( <t:direct> n )
1148 -- no return values
1149 end
1150 \stoptyping
1151
1152 This function will append a node list to \TEX's \quote {current list}. The node
1153 list is not deep|-|copied! There is no error checking either! You might need to
1154 enforce horizontal mode in order for this to work as expected.
1155
1156 \stopsubsection
1157
1158 \startsubsection[title={Manipulating lists}]
1159
1160 Unless there is a bug or a callback messes up a node list is dual linked. In original
1161 \TEX\ nodes had to be small so nodes only had a next pointer. If you run into an issue
1162 you can use the next helper to sure that the node list is double linked.
1163
1164 \starttyping[option=LUA]
1165 function node.direct.slide ( <t:direct> n)
1166 return <t:direct> -- tail
1167 end
1168 \stoptyping
1169
1170 In most cases \TEX\ itself only uses \type {next} pointers but your other
1171 callbacks might expect proper \type {prev} pointers too. So, when you run into
1172 issues or are in doubt, apply the slide function before you return the list. You
1173 can also get the tail without sliding:
1174
1175 \starttyping[option=LUA]
1176 function node.direct.tail ( <t:direct> n )
1177 return <t:direct> -- tail
1178 end
1179 \stoptyping
1180
1181 For tracing purposes we have a few counters. The first one returns the number of
1182 nodes contained in the node list that starts at \type {n}. If \type {m} is also
1183 supplied it stops at \type {m} instead of at the end of the list. The node \type
1184 {m} is not counted.
1185
1186 \starttyping[option=LUA]
1187 function node.direct.length (
1188 <t:direct> n
1189 )
1190 return <t:integer>
1191 end
1192
1193 function node.direct.length (
1194 <t:direct> n,
1195 <t:direct> m
1196 )
1197 return <t:integer>
1198 end
1199 \stoptyping
1200
1201 The second one the number of nodes contained in the node list that starts at
1202 \type {n} that have a matching \type {id} field. If \type {m} is also supplied,
1203 counting stops at \type {m} instead of at the end of the list. The node \type {m}
1204 is not counted. This function also accept string \type {id}'s.
1205
1206 \starttyping[option=LUA]
1207 function node.direct.count (
1208 <t:integer> id,
1209 <t:direct> n
1210 )
1211 return <t:integer>
1212 end
1213
1214 function node.direct.count (
1215 <t:integer> id,
1216 <t:direct> n,
1217 <t:direct> m
1218 )
1219 return <t:integer>
1220 end
1221 \stoptyping
1222
1223 This function removes the node \type {current} from the list following \type
1224 {head}. It is your responsibility to make sure it is really part of that list.
1225 The return values are the new \type {head} and \type {current} nodes. The
1226 returned \type {current} is the node following the \type {current} in the calling
1227 argument, and is only passed back as a convenience (or \type {nil}, if there is
1228 no such node). The returned \type {head} is more important, because if the
1229 function is called with \type {current} equal to \type {head}, it will be
1230 changed. When the third argument is passed, the node is freed.
1231
1232 \starttyping[option=LUA]
1233 function node.direct.remove ( <t:direct> head, <t:direct> current )
1234 return
1235 <t:direct> head,
1236 <t:direct> current,
1237 <t:direct> removed
1238 end
1239
1240 function node.direct.remove ( <t:direct> head, <t:direct> current, <t:boolean> free)
1241 return
1242 <t:direct> -- head,
1243 <t:direct> -- current
1244 end
1245 \stoptyping
1246
1247 This function inserts the node \type {new} before \type {current} into the list
1248 following \type {head}. It is your responsibility to make sure that \type
1249 {current} is really part of that list. The return values are the (potentially
1250 mutated) \type {head} and the node \type {new}, set up to be part of the list
1251 (with correct \type {next} field). If \type {head} is initially \type {nil}, it
1252 will become \type {new}.
1253
1254 \starttyping[option=LUA]
1255 function node.direct.insertbefore (
1256 <t:direct> head,
1257 <t:direct> current,
1258 <t:direct> new
1259 )
1260 return
1261 <t:direct>, -- head
1262 <t:direct> -- new
1263 end
1264 \stoptyping
1265
1266 This function inserts the node \type {new} after \type {current} into the list
1267 following \type {head}. It is your responsibility to make sure that \type
1268 {current} is really part of that list. The return values are the \type {head} and
1269 the node \type {new}, set up to be part of the list (with correct \type {next}
1270 field). If \type {head} is initially \type {nil}, it will become \type {new}.
1271
1272 \starttyping[option=LUA]
1273 function node.direct.insertafter (
1274 <t:direct> head,
1275 <t:direct> current,
1276 <t:direct> new
1277 )
1278 return
1279 <t:direct>, -- head
1280 <t:direct> -- new
1281 end
1282 \stoptyping
1283
1284 You can also mess with the list by changing the \type {next} or \type {prev} fields, using:
1285
1286 \starttyping[option=LUA]
1287 function node.direct.setprev ( <t:direct> n, <t:direct> prv ) end
1288 function node.direct.setnext ( <t:direct> n, <t:direct> nxt ) end
1289 function node.direct.setboth ( <t:direct> n, <t:direct> prv, <t:direct> nxt ) end
1290 \stoptyping
1291
1292 The next function pops the last node from \TEX's \quote{current list}. It returns
1293 that node, or \type {nil} if the current list is empty.
1294
1295 \starttyping[option=LUA]
1296 function node.direct.lastnode ( )
1297 return <t:direct> n
1298 end
1299 \stoptyping
1300
1301 This helper returns the location of the first match at or after node \type {n}:
1302
1303 \starttyping[option=LUA]
1304 function node.direct.findnode ( <t:direct> n, <t:integer> subtype )
1305 return <t:direct> -- n
1306 end
1307
1308 function node.direct.findnode ( <t:direct> n )
1309 return
1310 <t:direct>, -- n
1311 <t:integer> -- subtype
1312 end
1313 \stoptyping
1314
1315 \stopsubsection
1316
1317 \startsubsection[title={Traversing}]
1318
1319 The easiest do-it-yourself approach to run over a list of nodes is to use one of
1320 the following functions:
1321
1322 \starttyping[option=LUA]
1323 function node.direct.getnext ( <t:direct> n )
1324 return <t:direct> | <t:nil>
1325 end
1326
1327 function node.direct.getprev ( <t:direct> n )
1328 return <t:direct> | <t:nil>
1329 end
1330
1331 function node.direct.getboth ( <t:direct> n )
1332 return
1333 <t:direct> | <t:nil>, -- prev
1334 <t:direct> | <t:nil> -- next
1335 end
1336 \stoptyping
1337
1338 Instead of using these you can use one of the iterators that loops over the node
1339 list that starts at \type {n}.
1340
1341 \starttyping[option=LUA]
1342 function node.direct.traverse ( <t:direct> n )
1343 return
1344 <t:direct> t,
1345 <t:integer> id,
1346 <t:integer> subtype
1347 end
1348 \stoptyping
1349
1350 Typically code looks like this:
1351
1352 \starttyping[option=LUA]
1353 for n in node.traverse(head) do
1354 -- whatever
1355 end
1356 \stoptyping
1357
1358 which is functionally equivalent to:
1359
1360 \starttyping[option=LUA]
1361 do
1362 local n
1363 local function f (head,var)
1364 local t
1365 if var == nil then
1366 t = head
1367 else
1368 t = var.next
1369 end
1370 return t
1371 end
1372 while true do
1373 n = f (head, n)
1374 if n == nil then
1375 break
1376 end
1377 -- whatever
1378 end
1379 end
1380 \stoptyping
1381
1382 It should be clear from the definition of the function \type {f} that even though
1383 it is possible to add or remove nodes from the node list while traversing, you
1384 have to take great care to make sure all the \type {next} (and \type {prev})
1385 pointers remain valid.
1386
1387 If the above is unclear to you, see the section \quote {For Statement} in the
1388 \LUA\ Reference Manual.
1389
1390 This is an iterator that loops over all the nodes in the list that starts at
1391 \type {n} that have a matching \type {id} field. See the previous section for
1392 details. The change is in the local function \type {f}, which now does an extra
1393 while loop checking against the upvalue \type {id}, kind of like:
1394
1395 \starttyping
1396 local function f(head,var)
1397 local t
1398 if var == nil then
1399 t = head
1400 else
1401 t = var.next
1402 end
1403 while not t.id == id do
1404 t = t.next
1405 end
1406 return t
1407 end
1408 \stoptyping
1409
1410 This and the previously discussed \type {traverse} are the only traverses
1411 provided for userdata nodes.
1412
1413 \starttyping[option=LUA]
1414 function node.direct.traverseid ( <t:integer> id, <t:direct> n )
1415 return
1416 <t:direct> t,
1417 <t:integer> subtype
1418 end
1419 \stoptyping
1420
1421 The \type {traversechar} iterator loops over the \type {glyph} nodes in a list.
1422 Only nodes with a subtype less than 256 are seen.
1423
1424 {\em NEEDS CHECKING: protected check}
1425
1426 \starttyping[option=LUA]
1427 function node.direct.traversechar ( <t:direct> n )
1428 return
1429 <t:direct>, -- n
1430 <t:integer>, -- char
1431 <t:integer> -- font
1432 end
1433 \stoptyping
1434
1435 The \type {traverseglyph} iterator loops over a list and returns the list and
1436 filters all glyphs:
1437
1438 \starttyping[option=LUA]
1439 function node.direct.traverseglyph ( <t:direct> n )
1440 return
1441 <t:direct>, -- n
1442 <t:integer>, -- char
1443 <t:integer> -- font
1444 end
1445 \stoptyping
1446
1447 This iterator loops over the \type {hlist} and \type {vlist} nodes in a list. The
1448 four return values can save some time compared to fetching these fields but in
1449 practice you seldom need them all.
1450
1451 \starttyping[option=LUA]
1452 function node.direct.traverselist ( <t:direct> n )
1453 return
1454 <t:direct>, -- n
1455 <t:integer>, -- identifier
1456 <t:integer>, -- subtype
1457 <t:direct> -- list
1458 end
1459 \stoptyping
1460
1461 This iterator loops over nodes that have content: \type {hlist}, \type {vlist},
1462 \type {glue} with leaders, \type {glyph}, \type {disc} and \type {rule} nodes.
1463
1464 \starttyping[option=LUA]
1465 function node.direct.traversecontent ( <t:direct> n )
1466 return
1467 <t:direct>, -- n
1468 <t:integer>, -- identifier
1469 <t:integer>, -- subtype
1470 <t:direct> -- listorleader
1471 end
1472 \stoptyping
1473
1474 The traversers also support backward traversal. An optional extra boolean triggers
1475 this. Yet another optional boolean will automatically start at the end of the
1476 given list. So, if we want both we use:
1477
1478 \starttyping[option=LUA]
1479 function node.direct.traverse (
1480 <t:direct> n,
1481 <t:boolean> reverse,
1482 <t:boolean> startatend
1483 )
1484 return
1485 <t:direct> t,
1486 <t:integer> id,
1487 <t:integer> subtype
1488 end
1489 \stoptyping
1490
1491 \stopsubsection
1492
1493 \startsubsection[title={Glyphs}]
1494
1495 Glyphs have a lot of parameters and there are many setters and getters that
1496 can access them. Some generic ones, like \type {getwidth} are discussed
1497 in other subsections, some are more specific to glyphs:
1498
1499 \starttyping[option=LUA]
1500 function node.direct.getslant ( <t:direct> g ) return <t:integer> end
1501 function node.direct.getweight ( <t:direct> g ) return <t:integer> end
1502 \stoptyping
1503
1504 and
1505
1506 \starttyping[option=LUA]
1507 function node.direct.setslant ( <t:direct> g, <t:integer> slant ) end
1508 function node.direct.setweight ( <t:direct> g, <t:integer> weight ) end
1509 \stoptyping
1510
1511 \stopsubsection
1512
1513 \startsubsection[title={Glue}]
1514
1515 You can set the five properties of a glue in one go. If a non|-|numeric value is
1516 passed the property becomes zero.
1517
1518 \starttyping[option=LUA]
1519 function node.direct.setglue ( <t:direct> n )
1520 -- no return values
1521 end
1522
1523 function node.direct.setglue (
1524 <t:direct> n,
1525 <t:integer> width,
1526 <t:integer> stretch,
1527 <t:integer> shrink,
1528 <t:integer> stretchorder,
1529 <t:integer> shrinkorder
1530 )
1531 -- no return values
1532 end
1533 \stoptyping
1534
1535 When you pass values, only arguments that are numbers are assigned so the next
1536 call will only adapt the width and shrink.
1537
1538 \starttyping[option=LUA]
1539 node.direct.setglue(n,655360,false,65536)
1540 \stoptyping
1541
1542
1543 When a list node is passed, you set the glue, order and sign instead. The next
1544 call will return five values or nothing when no glue is passed.
1545
1546 \starttyping[option=LUA]
1547 function node.direct.getglue ( <t:direct> n )
1548 return
1549 <t:integer>, -- width
1550 <t:integer>, -- stretch
1551 <t:integer>, -- shrink
1552 <t:integer>, -- stretchorder
1553 <t:integer> -- shrinkorder
1554 \stoptyping
1555
1556 When the second argument is false, only the width is returned (this is consistent
1557 with \type {tex.get}). When a list node is passed, you get back the glue that is
1558 set, the order of that glue and the sign.
1559
1560 This function returns \type {true} when the width, stretch and shrink properties
1561 are all zero.
1562
1563 \starttyping[option=LUA]
1564 function node.direct.iszeroglue ( <t:direct> n )
1565 return <t:boolean> -- allzero
1566 end
1567 \stoptyping
1568
1569 Glue is not only, well, glue. The to be filled space can also be occupied by a rule,
1570 boxes, glyphs and what more. You can get the list that makes this with:
1571
1572 \starttyping[option=LUA]
1573 function node.direct.getleader ( <t:direct> n )
1574 return <t:direct> -- list
1575 end
1576 \stoptyping
1577
1578 and set the list with
1579
1580 \starttyping[option=LUA]
1581 function node.direct.setleader ( <t:direct> n, <t:direct> l | <t:nil> )
1582 -- no return values
1583 end
1584 \stoptyping
1585
1586 \stopsubsection
1587
1588 \startsubsection[title={Attributes}]
1589
1590 Assignments to attributes registers result in assigning lists with set attributes
1591 to nodes and the implementation is non|-|trivial because the value that is
1592 attached to a node is essentially a (sorted) sparse array of key|-|value pairs.
1593 It is generally easiest to deal with attribute lists and attributes by using the
1594 dedicated functions in the \type {node} library.
1595
1596 An \type {attribute} comes in two variants, indicated by subtype. Because
1597 attributes are stored in a sorted linked list, and because they are shared, the
1598 first node is a list reference node and the following ones are value nodes. So,
1599 most attribute nodes are value nodes. These are forward linked lists. Because
1600 there are assumptions to how these list are build you should rely on the helpers,
1601 also because details might change.
1602
1603 This returns the currently active list of attributes, if there is one.
1604
1605 \starttyping[option=LUA]
1606 function node.direct.currentattr()
1607 return <t:direct> -- list
1608 end
1609 \stoptyping
1610
1611 The intended usage of \type {currentattr} is as follows (we use the userdata
1612 interface here):
1613
1614 \starttyping[option=LUA]
1615 local x1 = node.new("glyph")
1616 x1.attr = node.currentattr()
1617 local x2 = node.new("glyph")
1618 x2.attr = node.currentattr()
1619 \stoptyping
1620
1621 or:
1622
1623 \starttyping[option=LUA]
1624 local x1 = node.new("glyph")
1625 local x2 = node.new("glyph")
1626 local ca = node.currentattr()
1627 x1.attr = ca
1628 x2.attr = ca
1629 \stoptyping
1630
1631 The attribute lists are reference counted and the assignment takes care of
1632 incrementing the count. You cannot expect the value \type {ca} to be valid any
1633 more when you assign attributes (using \type {tex.setattribute}) or when control
1634 has been passed back to \TEX.
1635
1636 \starttyping[option=LUA]
1637 <number> v = node.hasattribute ( <node> n, <number> id )
1638 <number> v = node.hasattribute ( <node> n, <number> id, <number> val )
1639 \stoptyping
1640
1641 Tests if a node has the attribute with number \type {id} set. If \type {val} is
1642 also supplied, also tests if the value matches \type {val}. It returns the value,
1643 or, if no match is found, \type {nil}.
1644
1645 \starttyping[option=LUA]
1646 function node.direct.getattribute ( <t:direct> n, <t:integer> id )
1647 return <t:integer> -- value
1648 end
1649 \stoptyping
1650
1651 The previous function tests if a node has an attribute with number \type {id}
1652 set. It returns the value, or, if no match is found, \type {nil}. If no \type
1653 {id} is given then the zero attributes is assumed.
1654
1655 %
1656 \starttyping[option=LUA]
1657 function node.direct.findattribute ( <t:direct> n, <t:integer> id )
1658 return
1659 <t:integer>, -- value
1660 <t:direct> -- node
1661 end
1662 \stoptyping
1663
1664 Finds the first node that has attribute with number \type {id} set. It returns
1665 the value and the node if there is a match and otherwise nothing.
1666
1667 \starttyping[option=LUA]
1668 function node.direct.setattribute ( <t:direct> n, <t:integer> id, <t:integer> value )
1669 -- no return values
1670 end
1671 \stoptyping
1672
1673 Sets the attribute with number \type {id} to the value \type {value}. Duplicate
1674 assignments are ignored.
1675
1676 \starttyping[option=LUA]
1677 function node.direct.unsetattribute ( <t:direct> n, <t:integer> id )
1678 return <t:integer> -- value
1679 end
1680
1681 function node.direct.unsetattribute ( <t:direct> n, <t:integer> id, <t:integer> value )
1682 return <t:integer> -- value
1683 end
1684 \stoptyping
1685
1686 Unsets the attribute with number \type {id}. If \type {value} is also supplied,
1687 it will only perform this operation if the value matches \type {value}. Missing
1688 attributes or attribute|-|value pairs are ignored. If the attribute was actually
1689 deleted, the function returns its old value, otherwise it returns \type {nil}.
1690
1691 \stopsubsection
1692
1693 \startsubsection[title={Glyph handling}]
1694
1695 Processing a character stream into a visual representation using glyphs is one of
1696 the important processes in the engine. In \TEX82 this happens in two places. When
1697 the text is read ligaturing and kerning takes place and the list can, if needed,
1698 be packed into a box because the dimensions are now known. When that list is to
1699 become a paragraph it might be that lines get split and when a word can be
1700 hyphenated the ligaturing and kerning is reverted, the word gets hyphenated,
1701 ligatures and kerns get reapplied and the process goes on.
1702
1703 In \OPENTYPE\ processing characters is way more complex. Even if we delegate this
1704 to a library, the fact that we have a mix of text and whatever, potential
1705 hyphenation as well as spaces turned glue, means that we need to do some juggling
1706 with nodes. For that reason hyphenation (of the whole list), ligaturing and
1707 kerning has been split into clearly separates stages. One can still apply the
1708 original \TEX\ variants but in practice it is \LUA\ that does the juggling of
1709 nodes in more complex situations. And we're not only talking of font processing.
1710 For instance, additional inter-character kerning can be done in \LUA\ too.
1711
1712 This all means that we have quite a repertoire of helpers that deal with glyph
1713 processing efficiently.
1714
1715 We can locate the first node in the list starting at \type {n} that is a glyph node
1716 with a subtype indicating it is a glyph, or \type {nil}. If \type {m} is given,
1717 processing stops at (but including) that node, otherwise processing stops at the
1718 end of the list. The \type {char} and \type {glyph} variants check for the
1719 protected field being (yet) unset or (already) set.
1720
1721 \starttyping[option=LUA]
1722 function node.direct.firstglyphnode ( <t:direct> n )
1723 return <t:direct> -- n
1724 end
1725
1726 function node.direct.firstglyphnode ( <t:direct> n, <t:direct> m )
1727 return <t:direct> -- n
1728 end
1729 \stoptyping
1730
1731 The next functions can be used to determine if processing is needed. We distinguish between
1732 a character (unprocessed) and a glyph (processed or unprocessed). When we check for a glyph
1733 there are three possible outcomes:
1734
1735 \starttyping[option=LUA]
1736 function node.direct.isglyph ( <t:direct> n )
1737 return
1738 <t:nil>,
1739 <t:nil>
1740 end
1741
1742 function node.direct.isglyph ( <t:direct> n )
1743 return
1744 <t:false>,
1745 <t:integer> -- identifier
1746 end
1747
1748 function node.direct.isglyph ( <t:direct> n )
1749 return
1750 <t:integer>, -- character
1751 <t:integer> -- font
1752 end
1753 \stoptyping
1754
1755 Checking for a processed character is more complicated. If the glyph has been processed and
1756 the protected property has been set, we get this:
1757
1758 \starttyping[option=LUA]
1759 function node.direct.ischar ( <t:direct> n )
1760 return <t:false>
1761 end
1762 \stoptyping
1763
1764 If that's not the case additional arguments are checked. If we don't pass a valid
1765 integer, the character value is returned:
1766
1767 \starttyping[option=LUA]
1768 function node.direct.ischar ( <t:direct> n, <t:integer> font )
1769 return <t:integer> -- character
1770 end
1771 \stoptyping
1772
1773 btu when we passed a font identifier indeed we check if that one matches the one in the
1774 glyph and if not again we get:
1775
1776 \starttyping[option=LUA]
1777 function node.direct.ischar ( <t:direct> n, <t:integer> font )
1778 return <t:false> --
1779 end
1780 \stoptyping
1781
1782 From there on we check for more arguments to match the glyph fields:
1783
1784 \starttyping[option=LUA]
1785 function node.direct.ischar (
1786 <t:direct> n,
1787 <t:integer> font,
1788 <t:integer> data
1789 )
1790 return <t:false> | <t:integer> -- character
1791
1792 end
1793
1794 function node.direct.ischar (
1795 <t:direct> n,
1796 <t:integer> font,
1797 <t:integer> data,
1798 <t:integer> state
1799 )
1800 return <t:false> | <t:integer> -- character
1801
1802 end
1803
1804 function node.direct.ischar (
1805 <t:direct> n,
1806 <t:integer> font,
1807 <t:integer> scale,
1808 <t:integer> xscale,
1809 <t:integer> yscale,
1810 )
1811 return <t:false> | <t:integer> -- character
1812
1813 end
1814
1815 function node.direct.ischar (
1816 <t:direct> n,
1817 <t:integer> font,
1818 <t:integer> data,
1819 <t:integer> scale,
1820 <t:integer> xscale,
1821 <t:integer> yscale,
1822 )
1823 return <t:false> | <t:integer> -- character
1824
1825 end
1826 \stoptyping
1827
1828 There are reasons for these combined tests and they can be found in the \CONTEXT\
1829 font handler. A related helper is one that compares the \type {font}, \type
1830 {data}, \type {scale}, \type {xscale}, \type {yscale}, \type {slant} and \type
1831 {weight}.
1832
1833 \starttyping[option=LUA]
1834 function node.direct.issimilarglyph ( <t:direct> one, <t:direct> two )
1835 return <t:boolean> -- similar
1836 end
1837 \stoptyping
1838
1839 This function returns the first glyph or disc node in the given list:
1840
1841 \starttyping[option=LUA]
1842 function node.direct.hasglyph ( <t:direct> n )
1843 return <t:direct> -- n
1844 end
1845 \stoptyping
1846
1847 Traditional \TEX\ ligature processing can be achieved with the next helper. This
1848 assumes that the ligature information is present in the font. In \CONTEXT\ we
1849 call this base mode processing.
1850
1851 \starttyping[option=LUA]
1852 function node.direct.ligaturing ( <t:direct> first )
1853 return
1854 <t:direct>, -- head
1855 <t:direct>, -- tail
1856 <t:boolean> -- success
1857 end
1858
1859 function node.direct.ligaturing ( <t:direct> first, <t:direct> last )
1860 return
1861 <t:direct>, -- head
1862 <t:direct>, -- tail
1863 <t:boolean> -- success
1864 end
1865 \stoptyping
1866
1867 Traditional \TEX\ font kern processing can be achieved with the next helper. This
1868 assumes that the kern information is present in the font. In \CONTEXT\ we
1869 call this base mode processing.
1870
1871 \starttyping[option=LUA]
1872 function node.direct.kerning ( <t:direct> first )
1873 return
1874 <t:direct>, -- head
1875 <t:direct>, -- tail
1876 <t:boolean> -- success
1877 end
1878
1879 function node.direct.kerning ( <t:direct> first, <t:direct> last )
1880 return
1881 <t:direct>, -- head
1882 <t:direct>, -- tail
1883 <t:boolean> -- success
1884 end
1885 \stoptyping
1886
1887 When processing is done, you can mark the glyph nodes as protected in order to
1888 prevent redundant processing, for instance because boxed material gets unboxed.
1889 Where in \LUATEX\ the subtype gets changed by adding or subtracting 256, in
1890 \LUAMETATEX\ we have a dedicated (small) protection field.
1891
1892 \starttyping[option=LUA]
1893 function node.direct.protectglyph ( <t:direct> n )
1894 -- no return values
1895 end
1896
1897 function node.direct.protectglyphs ( <t:direct> first, <t:direct> last )
1898 -- no return values
1899 end
1900 \stoptyping
1901
1902 The opposite action can also be done.
1903
1904 \starttyping[option=LUA]
1905 function node.direct.unprotectglyph ( <t:direct> n )
1906 -- no return values
1907 end
1908
1909 function node.direct.unprotectglyphs ( <t:direct> first, <t:direct> last )
1910 -- no return values
1911 end
1912 \stoptyping
1913
1914 The next function checks if protrusion is active at a line boundary, in which case the glyph
1915 node can be skipped. It's not that useful in the end.
1916
1917 \starttyping[option=LUA]
1918 function node.direct.protrusionskipable ( <t:direct> n )
1919 return <t:boolean> -- skippable
1920 end
1921 \stoptyping
1922
1923 Once we're done we can freeze leaders: apply the glue to the leader and freeze
1924 the boxes or whatever is at hand.
1925
1926 \starttyping[option=LUA]
1927 function node.direct.flattenleaders ( <t:direct> n )
1928 return
1929 <t:direct>, -- head
1930 <t:integer> -- count
1931 end
1932 \stoptyping
1933
1934 \stopsubsection
1935
1936 \startsubsection[title=Discretionaries]
1937
1938 Discretionaries and glyphs are the carriers of text. Where the core of \type
1939 {glyph} nodes are the \type {font} and \type {char} fields, in \type {disc} nodes
1940 we have to focus on the \type {pre}, \type {post} and \type{replace} fields.
1941 These point to linked lists that are a mix of glyph, kerns and (in \LUAMETATEX\
1942 fixed width) glue. here are the accessors: \footnote {These are a bit more
1943 generic because they also return fields from \type {choice} nodes and possibly
1944 \type {hlist} and \type {vlist} nodes.}
1945
1946 \starttyping[option=LUA]
1947 function node.direct.getpost ( <t:direct> d, <t:boolean> tailtoo )
1948 return
1949 <t:direct>, -- head
1950 <t:direct> -- tail
1951 end
1952
1953 function node.direct.getpre ( <t:direct> d, <t:boolean> tailtoo )
1954 return
1955 <t:direct>, -- head
1956 <t:direct> -- tail
1957 end
1958
1959 function node.direct.getreplace ( <t:direct> d, <t:boolean> tailtoo )
1960 return
1961 <t:direct>, -- head
1962 <t:direct> -- tail
1963 end
1964 \stoptyping
1965
1966 \starttyping[option=LUA]
1967 function node.direct.getdisc ( <t:direct> d, <t:boolean> tailtoo )
1968 return
1969 <t:direct>, -- prehead
1970 <t:direct>, -- posthead
1971 <t:direct>, -- replacehead
1972 <t:direct>, -- pretail
1973 <t:direct>, -- posttail
1974 <t:direct> -- replacetail
1975 end
1976 \stoptyping
1977
1978 We also have setters:
1979
1980 \starttyping[option=LUA]
1981 function node.direct.setpost ( <t:direct> d, <t:direct> | <t:nil> ) end
1982 function node.direct.setpre ( <t:direct> d, <t:direct> | <t:nil> ) end
1983 function node.direct.setreplace ( <t:direct> d, <t:direct> | <t:nil> ) end
1984 \stoptyping
1985
1986 A major update can be done with this one:
1987
1988 \starttyping[option=LUA]
1989 function node.direct.setdisc (
1990 <t:direct>, -- discretionary
1991 <t:direct> | <t:nil>, -- pre
1992 <t:direct> | <t:nil>, -- post
1993 <t:direct> | <t:nil>, -- replace
1994 <t:subtype> | <t:nil>, -- subtype
1995 <t:subtype> | <t:nil> -- penalty
1996 )
1997 -- no return values
1998 end
1999 \stoptyping
2000
2001 From this you can deduce that we can also say:
2002
2003 \starttyping[option=LUA]
2004 function node.direct.getpenalty ( <t:direct> d )
2005 return <t:integer> -- penalty
2006 end
2007
2008 function node.direct.setpenalty ( <t:direct> d, <t:integer> penalty )
2009 -- no return value
2010 end
2011 \stoptyping
2012
2013 The next pair targets glyphs and normally you will not use the setter, because
2014 the engine takes care of setting that state.
2015
2016 \starttyping[option=LUA]
2017 function node.direct.getdiscpart ( <t:direct> g )
2018 return
2019 <t:integer>, -- part
2020 <t:integer>, -- after
2021 <t:integer> -- code
2022
2023 end
2024
2025 function node.direct.setdiscpart (
2026 <t:direct> g,
2027 <t:integer> part
2028 <t:integer> after
2029 <t:integer> code
2030 )
2031 -- no return value
2032 end
2033 \stoptyping
2034
2035 The part and after properties relate to discretionary nodes that might have been
2036 flattened. The complication in (tracing) here is that information is lost so we
2037 store the states in the glyph node.
2038
2039 \showenginevalues{discpartvalues}
2040
2041 The code properties relate to where the (usually hyphen) character comes from:
2042
2043 \showenginevalues{glyphdiscvalues}
2044
2045 When you fool around with disc nodes you need to be aware of the fact that they
2046 have a special internal data structure. As long as you reassign the fields when
2047 you have extended the lists it's ok because then the tail pointers get updated,
2048 but when you add to list without reassigning you might end up in trouble when
2049 the linebreak routine kicks in. You can call this function to check the list for
2050 issues with disc nodes.
2051
2052 \starttyping[option=LUA]
2053 function node.direct.checkdiscretionary ( <t:direct> n )
2054 -- no return values
2055 end
2056 \stoptyping
2057
2058 The plural variant runs over all disc nodes in a list, the singular variant
2059 checks one node only (it also checks if the node is a disc node).
2060
2061 \starttyping[option=LUA]
2062 function node.direct.checkdiscretionaries ( <t:direct> head )
2063 -- no return values
2064 end
2065 \stoptyping
2066
2067 This function will remove the discretionaries in the list and inject the replace
2068 field when set.
2069
2070 \starttyping[option=LUA]
2071 function node.direct.flattendiscretionaries ( <t:direct> n )
2072 return
2073 <t:direct>, -- head
2074 <t:integer> -- count
2075 end
2076 \stoptyping
2077
2078 \stopsubsection
2079
2080 \startsubsection[title=Packaging and dimensions]
2081
2082 At some point a node list has to be packed in either a horizontal or vertical
2083 box. There are restrictions to what can get packed, for instance you cannot have
2084 glyphs in a vertical list.
2085
2086
2087 The \type {hpack} function creates a new hlist by packaging the list that begins
2088 at node \type {n} into a horizontal box. With only a single argument, this box is
2089 created using the natural width of its components. In the three argument form,
2090 \type {info} must be either \type {additional} or \type {exactly}, and \type {w}
2091 is the additional (\type {\hbox spread}) or exact (\type {\hbox to}) width to be
2092 used. The second return value is the badness of the generated box.
2093
2094 \starttyping[option=LUA]
2095 function node.direct.hpack (
2096 <t:direct> list
2097 )
2098 return
2099 <t:direct>, -- box
2100 <t:integer> -- badness
2101 end
2102
2103 function node.direct.hpack (
2104 <t:direct> list,
2105 <t:integer> width,
2106 <t:string> info -- "additional" | "exactly"
2107 )
2108 return
2109 <t:direct>, -- box
2110 <t:integer> -- badness
2111 end
2112
2113 function node.direct.hpack (
2114 <t:direct> list,
2115 <t:integer> width,
2116 <t:string> info, -- "additional" | "exactly"
2117 <t:integer> direction
2118 )
2119 return
2120 <t:direct>, -- box
2121 <t:integer> -- badness
2122 end
2123 \stoptyping
2124
2125 % Caveat: there can be unexpected side|-|effects to this function, like migration
2126 % of \type {mark} and \type {insert} nodes. Also note that the content of \type {h}
2127 % is the original node list \type {n}: if you free \type {h} you will also free the
2128 % node list itself, unless you explicitly set the \type {list} field to \type {nil}
2129 % beforehand. And in a similar way, calling free on \type {n} will invalidate \type
2130 % {h} as well!
2131
2132 The \type {vpack} function creates a new vlist by packaging the list that begins
2133 at node \type {n} into a vertical box. With only a single argument, this box is
2134 created using the natural height of its components. In the three argument form,
2135 \type {info} must be either \type {additional} or \type {exactly}, and \type {w}
2136 is the additional (\type {\vbox spread}) or exact (\type {\vbox to}) height to be
2137 used.
2138
2139 \starttyping[option=LUA]
2140 function node.direct.vpack (
2141 <t:direct> list
2142 )
2143 return
2144 <t:direct>, -- box
2145 <t:integer> -- badness
2146 end
2147
2148 function node.direct.vpack (
2149 <t:direct> list,
2150 <t:integer> height,
2151 <t:string> info -- "additional" | "exactly"
2152 )
2153 return
2154 <t:direct>, -- box
2155 <t:integer> -- badness
2156 end
2157
2158 function node.direct.vpack (
2159 <t:direct> list,
2160 <t:integer> height,
2161 <t:string> info, -- "additional" | "exactly"
2162 <t:integer> direction
2163 )
2164 return
2165 <t:direct>, -- box
2166 <t:integer> -- badness
2167 end
2168 \stoptyping
2169
2170 This function calculates the natural in|-|line dimensions of the node list starting
2171 at node \type {first} and terminating just before node \type {last} (or the end of the
2172 list, if there is no second argument). The return values are scaled points.
2173
2174 \starttyping[option=LUA]
2175 function node.direct.dimensions (
2176 <t:direct> first,
2177 <t:direct> last
2178 )
2179 return
2180 <t:integer>, -- width
2181 <t:integer>, -- height
2182 <t:integer> -- depth
2183 end
2184 \stoptyping
2185
2186 This alternative calling method takes glue settings into account and is especially useful for
2187 finding the actual width of a sublist of nodes that are already boxed, for
2188 example in code like this, which prints the width of the space in between the
2189 \type {a} and \type {b} as it would be if \type {\box0} was used as-is:
2190
2191 \starttyping
2192 \setbox0 = \hbox to 20pt {a b}
2193
2194 \directlua{print (node.dimensions(
2195 tex.box[0].glueset,
2196 tex.box[0].gluesign,
2197 tex.box[0].glueorder,
2198 tex.box[0].head.next,
2199 node.tail(tex.box[0].head)
2200 )) }
2201 \stoptyping
2202
2203 You need to keep in mind that this is one of the few places in \TEX\ where floats
2204 are used, which means that you can get small differences in rounding when you
2205 compare the width reported by \type {hpack} with \type {dimensions}.
2206
2207 \starttyping[option=LUA]
2208 function node.direct.dimensions (
2209 <t:number> glueset,
2210 <t:integer> gluesign
2211 <t:integer> glueorder,
2212 <t:direct> first,
2213 <t:direct> last
2214 )
2215 return
2216 <t:integer>, -- width
2217 <t:integer>, -- height
2218 <t:integer> -- depth
2219 end
2220 \stoptyping
2221
2222 This alternative saves a few lookups and can be more convenient in some
2223 cases:
2224
2225 \starttyping[option=LUA]
2226 function node.direct.rangedimensions (
2227 <t:direct> parent,
2228 <t:direct> first,
2229 <t:direct> last
2230 )
2231 return
2232 <t:integer>, -- width
2233 <t:integer>, -- height
2234 <t:integer> -- depth
2235 end
2236 \stoptyping
2237
2238 If you only need the width, a simple and somewhat more efficient variant is this,
2239 where again \type {last} is optional:
2240
2241 \starttyping[option=LUA]
2242 function node.direct.naturalwidth (
2243 <t:direct> first,
2244 <t:direct> last
2245 )
2246 return <t:integer> -- width
2247 end
2248 \stoptyping
2249
2250 More low level are the following helpers. They accept various kind of nodes
2251 \type {hlist}, \type {vlist}, \type {unset}, \type {rule}, \type {glyph} or \type {glue}
2252 (because these can have a leader).
2253
2254 \starttyping[option=LUA]
2255 function node.direct.getwhd ( <t:direct> n )
2256 return
2257 <t:dimension>, -- width
2258 <t:dimension>, -- height
2259 <t:dimension> -- depth
2260 end
2261 \stoptyping
2262
2263 In case of as glyph you can also get the expansion:
2264
2265 \starttyping[option=LUA]
2266 function node.direct.getwhd ( <t:direct> n, <t:true> expansion )
2267 return
2268 <t:dimension>, -- width
2269 <t:dimension>, -- height
2270 <t:dimension>, -- depth
2271 <t:integer> -- expansion
2272 end
2273 \stoptyping
2274
2275 The \type {getwidth} accepts even more node types: \type {hlist}, \type {vlist},
2276 \type {unset}, \type {align}, \type {rule}, \type {glue}, \type {gluespec}, \type
2277 {glyph}, \type {kern} and \type {math} (surround).
2278
2279 \starttyping[option=LUA]
2280 function node.direct.getwidth ( <t:direct> n )
2281 return <t:dimension> -- width
2282 end
2283 \stoptyping
2284
2285 And for glyphs:
2286
2287 \starttyping[option=LUA]
2288 function node.direct.getwidth ( <t:direct> n, <t:true> expansion )
2289 return
2290 <t:dimension>,-- width
2291 <t:dimension> -- expansion
2292 end
2293 \stoptyping
2294
2295 The getter for height operates on \type {hlist}, \type {vlist}, \type {unset},
2296 \type {rule}, \type {insert} and \type {fence}.
2297
2298 \starttyping[option=LUA]
2299 function node.direct.getheight ( <t:direct> n )
2300 return <t:dimension> -- height
2301 end
2302 \stoptyping
2303
2304 For the depth we have a different repertoire: \type {hlist}, \type {vlist}, \type
2305 {unset}, \type {rule}, \type {insert}, \type {glyph} and \type {fence}.
2306
2307 \starttyping[option=LUA]
2308 function node.direct.getdepth ( <t:direct> n )
2309 return <t:dimension> -- depth
2310 end
2311 \stoptyping
2312
2313 For \type {hlist}, \type {vlist}, \type {unset}, \type {rule}, \type
2314 {insert_node:}, \type {glyph} and \type {fence} we can get the total of height
2315 and depth:
2316
2317 \starttyping[option=LUA]
2318 function node.direct.gettotal ( <t:direct> n )
2319 return <t:dimension> -- height + depth
2320 end
2321 \stoptyping
2322
2323 Only \type {hlist} and \type {vlist} have a (vertical or horizontal) shift:
2324
2325 \starttyping[option=LUA]
2326 function node.direct.getshift ( <t:direct> n )
2327 return <t:dimension> -- shift
2328 end
2329 \stoptyping
2330
2331 This one is only valid for \type {glyph} and \type {kern} nodes:
2332
2333 \starttyping[option=LUA]
2334 function node.direct.getexpansion ( <t:direct> n )
2335 return <t:dimension> -- expansion
2336 end
2337 \stoptyping
2338
2339 Before we move on we mention the setters:
2340
2341 \starttyping[option=LUA]
2342 function node.direct.setwidth ( <t:direct> n, <t:dimension> width ) end
2343 function node.direct.setheight ( <t:direct> n, <t:dimension> height ) end
2344 function node.direct.setdepth ( <t:direct> n, <t:dimension> depth ) end
2345 function node.direct.setshift ( <t:direct> n, <t:dimension> shift ) end
2346 function node.direct.setexpansion ( <t:direct> n, <t:integer> expansion ) end
2347 \stoptyping
2348
2349 The combined one ignores values that are no number, so passing (e.g.) \type {nil}
2350 or (nicer) \type {false} will retain the value.
2351
2352 \starttyping[option=LUA]
2353 function nodedirect.setwhd (
2354 <t:direct> node,
2355 <t:dimension> width,
2356 <t:dimension> height,
2357 <t:dimension> depth,
2358 -- no return values
2359 end
2360 \stoptyping
2361
2362 These \type {hlist} and \type {vlist} nodes (but others as well have) a field
2363 called \type {list}:
2364
2365 \starttyping[option=LUA]
2366 function node.direct.getlist ( <t:direct> b )
2367 return <t:direct> -- list
2368 end
2369
2370 function node.direct.setlist ( <t:direct> b, <t:direct> list )
2371 -- nothing to return
2372 end
2373 \stoptyping
2374
2375 When a list is packages, glue is resolved and the list node gets its glue properties
2376 set so that the backend can apply the stretch and shrink to the glue amount. There might
2377 be situations where you want to do this explicitly, which is why we provide:
2378
2379 \starttyping[option=LUA]
2380 function node.direct.freeze ( <t:direct> b )
2381 -- nothing to return
2382 end
2383 \stoptyping
2384
2385 In \LUAMETATEX\ we can handle nested marks, inserts and adjusts, and
2386 pre and post material can get bound to a box. We can use these to access them:
2387
2388 \starttyping[option=LUA]
2389 function node.direct.getpost ( <t:direct> b, <t:boolean> tailtoo )
2390 return
2391 <t:direct>, -- head
2392 <t:direct> -- tail
2393 end
2394
2395 function node.direct.getpre ( <t:direct> b, <t:boolean> tailtoo )
2396 return
2397 <t:direct>, -- head
2398 <t:direct> -- tail
2399 end
2400 \stoptyping
2401
2402 and these to set them, although they are unlikely candidates for that.
2403
2404 \starttyping[option=LUA]
2405 function node.direct.setpost ( <t:direct> b, <t:direct> | <t:nil> ) end
2406 function node.direct.setpre ( <t:direct> b, <t:direct> | <t:nil> ) end
2407 \stoptyping
2408
2409 \stopsubsection
2410
2411 \startsubsection[title={Math}]
2412
2413 We start with the function that runs the internal \quote {mlist to hlist}
2414 conversion that turns a the yet unprocessed math list into a horizontal list. The
2415 interface is the same as for the callback callback {mlisttohlist}.
2416
2417 \starttyping[option=LUA]
2418 function node.direct.mlisttohlist (
2419 <t:direct> list,
2420 <t:string> displaytype,
2421 <t:boolean> penalties
2422 )
2423 <t:direct> -- result
2424 end
2425 \stoptyping
2426
2427 When you have a horizontal list with math you can locate the relevant portion
2428 with:
2429
2430 \starttyping[option=LUA]
2431 function node.direct.beginofmath ( <t:direct> n ) return <t:direct> end
2432 function node.direct.endofmath ( <t:direct> n ) return <t:direct> end
2433 \stoptyping
2434
2435 You can for instance use these helpers to skip over math in case you're
2436 processing text.
2437
2438 The math noads have a nucleus and scripts. In \LUAMETATEX\ we have the usual
2439 super- and subscript but also prescripts and a primescript, so five scripts in
2440 total so naturally we have getters for these:
2441
2442 \starttyping[option=LUA]
2443 function node.direct.getnucleus ( <t:direct> n ) return <t:direct> | <t:nil> end
2444 function node.direct.getprime ( <t:direct> n ) return <t:direct> | <t:nil> end
2445 function node.direct.getsup ( <t:direct> n ) return <t:direct> | <t:nil> end
2446 function node.direct.getsub ( <t:direct> n ) return <t:direct> | <t:nil> end
2447 function node.direct.getsuppre ( <t:direct> n ) return <t:direct> | <t:nil> end
2448 function node.direct.getsubpre ( <t:direct> n ) return <t:direct> | <t:nil> end
2449 \stoptyping
2450
2451 plus:
2452
2453 \starttyping[option=LUA]
2454 function node.direct.getscripts ( <t:direct> n )
2455 return
2456 <t:direct>, -- primescript
2457 <t:direct>, -- superscript
2458 <t:direct>, -- subscript
2459 <t:direct>, -- superprescript
2460 <t:direct> -- subprescript
2461 end
2462 \stoptyping
2463
2464 These are complemented by setters. When the second argument is not passes (or nil)
2465 the field is reset.
2466
2467 \starttyping[option=LUA]
2468 function node.direct.setnucleus ( <t:direct> n, <t:direct> nucleus ) end
2469 function node.direct.setprime ( <t:direct> n, <t:direct> primescript ) end
2470 function node.direct.setsup ( <t:direct> n, <t:direct> superscript ) end
2471 function node.direct.setsub ( <t:direct> n, <t:direct> subscript ) end
2472 function node.direct.setsuppre ( <t:direct> n, <t:direct> superprescript ) end
2473 function node.direct.setsubpre ( <t:direct> n, <t:direct> subprescript ) end
2474 \stoptyping
2475
2476 And of course:
2477
2478 \starttyping[option=LUA]
2479 function node.direct.getscripts (
2480 <t:direct> primescript,
2481 <t:direct> superscript,
2482 <t:direct> subscript,
2483 <t:direct> superprescript,
2484 <t:direct> subprescript
2485 )
2486 -- no return values
2487 end
2488 \stoptyping
2489
2490 In the discretionaries subsection we mention accessing pre, post and replace
2491 fields. These functions can also be used for \type {choice} nodes. Discussing
2492 this is currently beyond this manual.
2493
2494 \stopsubsection
2495
2496 \startsubsection[title={MVL}]
2497
2498 Some properties of the currently used main vertical list can be fetched with:
2499
2500 \starttyping[option=LUA]
2501 function node.direct.getmvllist (
2502 -- currently no parameters
2503 )
2504 return
2505 <t:direct>, -- head
2506 <t:direct>, -- tail
2507 <t:integer> -- mvl
2508 end
2509 \stoptyping
2510
2511 \stopsubsection
2512
2513 \startsubsection[title={Balancing}]
2514
2515 The \type {node.direct.vbalance} function will either disappear or get accompanied
2516 by related helpers (mirroring primitives); it depends on what \CONTEXT\ needs.
2517
2518 Updating marks is done with the following set of helpers, that just call the code
2519 that does the same before handing over content to the output routine:
2520
2521 \starttyping[option=LUA]
2522 function nodes.direct.updatetopmarks ( )
2523 return <t:boolean> -- done
2524 end
2525
2526 function nodes.direct.updatefirstmarks ( )
2527 return <t:boolean> -- done
2528 end
2529
2530 function nodes.direct.updatefirstandbotmark ( <t:direct> box )
2531 -- no return value
2532 end
2533
2534 function nodes.direct.updatemarks ( <t:direct> box )
2535 return <t:boolean> -- done
2536 end
2537 \stoptyping
2538
2539 \stopsubsection
2540
2541 \startsubsection[title={\SYNCTEX}]
2542
2543 You can set and query the \SYNCTEX\ fields, a file number aka tag and a line
2544 number, for a \type {glue}, \type {kern}, \type {hlist}, \type {vlist}, \type
2545 {rule} and \type {math} nodes as well as \type {glyph} nodes (although this last
2546 one is not used in native \SYNCTEX).
2547
2548 \starttyping[option=LUA]
2549 function node.direct.setsynctexfields ( <t:integer> fileid, <t:integer> line )
2550 -- no return values
2551 end
2552
2553 function node.direct.getsynctexfields ( <t:direct> n )
2554 return
2555 <t:integer>, -- fileid
2556 <t:integer> -- line
2557 end
2558 \stoptyping
2559
2560 Of course you need to know what you're doing as no checking on sane values takes
2561 place. Also, the \SYNCTEX\ interpreter used in editors is rather peculiar and has
2562 some assumptions (heuristics) and there are different incompatible versions
2563 floating around. Even more important to notice is that the engine doesn't do
2564 anything with this so support is upto \LUA.
2565
2566 \stopsubsection
2567
2568 \startsubsection[title={Two access models}]
2569
2570 Deep down in \TEX\ a node has a number which is a numeric entry in a memory
2571 table. In fact, this model, where \TEX\ manages memory is real fast and one of
2572 the reasons why plugging in callbacks that operate on nodes is quite fast too.
2573 Each node gets a number that is in fact an index in the memory table and that
2574 number often is reported when you print node related information. You go from
2575 user data nodes and there numeric references and back with:
2576
2577 \starttyping[option=LUA]
2578 function node.todirect ( <t:node> n) return <t:direct> end
2579 function node.tonode ( <t:direct> d) return <t:node> end
2580 \stoptyping
2581
2582 The user data model is rather robust as it is a virtual interface with some
2583 additional checking while the more direct access which uses the node numbers
2584 directly. However, even with user data you can get into troubles when you free
2585 nodes that are no longer allocated or mess up lists. If you apply \type
2586 {tostring} to a node you see its internal (direct) number and id.
2587
2588 The userdata model provides key based access while the direct model always
2589 accesses fields via functions:
2590
2591 \starttyping[option=LUA]
2592 local c = nodeobject.char
2593 local c = getfield(nodenumber,"char")
2594 \stoptyping
2595
2596 If you use the direct model, even if you know that you deal with numbers, you
2597 should not depend on that property but treat it as an abstraction just like
2598 traditional nodes. In fact, the fact that we use a simple basic datatype has the
2599 penalty that less checking can be done, but less checking is also the reason why
2600 it's somewhat faster. An important aspect is that one cannot mix both methods,
2601 but you can cast both models. So, multiplying a node number makes no sense.
2602
2603 So our advice is: use the indexed (table) approach when possible and investigate
2604 the direct one when speed might be a real issue. For that reason \LUATEX\ also
2605 provide the \type {get*} and \type {set*} functions in the top level node
2606 namespace. There is a limited set of getters. When implementing this direct
2607 approach the regular index by key variant was also optimized, so direct access
2608 only makes sense when nodes are accessed millions of times (which happens in some
2609 font processing for instance).
2610
2611 We're talking mostly of getters because setters are less important. Documents
2612 have not that many content related nodes and setting many thousands of properties
2613 is hardly a burden contrary to millions of consultations.
2614
2615 Normally you will access nodes like this:
2616
2617 \starttyping
2618 local next = current.next
2619 if next then
2620 -- do something
2621 end
2622 \stoptyping
2623
2624 Here \type {next} is not a real field, but a virtual one. Accessing it results in
2625 a metatable method being called. In practice it boils down to looking up the node
2626 type and based on the node type checking for the field name. In a worst case you
2627 have a node type that sits at the end of the lookup list and a field that is last
2628 in the lookup chain. However, in successive versions of \LUATEX\ these lookups
2629 have been optimized and the most frequently accessed nodes and fields have a
2630 higher priority.
2631
2632 In the direct namespace there are more helpers and most of them are accompanied
2633 by setters. The getters and setters are clever enough to see what node is meant.
2634 We don't deal with whatsit nodes: their fields are always accessed by name. It
2635 doesn't make sense to add getters for all fields, we just identifier the most
2636 likely candidates. In complex documents, many node and fields types never get
2637 seen, or seen only a few times, but for instance glyphs are candidates for such
2638 optimization.
2639
2640 In previous sections we only show the functions in the \type {node.direct}
2641 namespace. The following functions are available in both \type {node} and \type
2642 {node.direct}:
2643
2644 \startthreerows
2645 \startluacode
2646 context.starttabulate { "|T|" }
2647 for k, v in table.sortedhash(node.direct) do
2648 if type(v) == "function" and node[k] then
2649 context.NC() context(k)
2650 context.NC() context.NR()
2651 end
2652 end
2653 context.stoptabulate()
2654 \stopluacode
2655 \stopthreerows
2656
2657 In \CONTEXT\ these are duplicated in \type {nodes.nuts} so that is the reference.
2658 Quite some functions gets mapped onto the \type {nodes} namespace. In addition we
2659 emulate some userdata functions and add some of our own. We show them here because
2660 this manual takes \CONTEXT\ as reference.
2661
2662 \starttworows
2663 \startluacode
2664 context.starttabulate { "|T|c|c|" }
2665 context.BC() context("node.direct")
2666 context.BC() context("node")
2667 context.BC() context("nodes")
2668 context.NC() context.NR()
2669 context.NC()
2670 context.NC()
2671 context.NC()
2672 context.NC() context.NR()
2673 -- todo: add a little space here
2674 for k, v in table.sortedhash(node.direct) do
2675 if type(v) == "function" then
2676 context.NC() context(k)
2677 context.NC() if node [k] then context("$⋆$") end
2678 context.NC() if nodes[k] then context("$⋆$") end
2679 context.NC() context.NR()
2680 end
2681 end
2682 context.stoptabulate()
2683 \stopluacode
2684 \stoptworows
2685
2686 The following functions are in the \CONTEXT\ \type {nodes} namespace but don't
2687 come from the library. Again, we show them here because \CONTEXT\ is the
2688 reference.
2689
2690 \starttworows
2691 \startluacode
2692 context.starttabulate { "|T|c|c|" }
2693 context.BC() context("nodes")
2694 context.BC() context("nodes.nuts")
2695 context.BC() context("node")
2696 context.NC() context.NR()
2697 context.NC()
2698 context.NC()
2699 context.NC()
2700 context.NC() context.NR()
2701 for k, v in table.sortedhash(nodes) do
2702 if type(v) == "function" and not node.direct[k] then
2703 context.NC() context(k)
2704 context.NC() if nodes.nuts[k] then context("$⋆$") end
2705 context.NC() if node [k] then context("$⋆$") end
2706 context.NC() context.NR()
2707 end
2708 end
2709 context.stoptabulate()
2710 \stopluacode
2711 \stoptworows
2712
2713 We have quite some helpers and some accept different node types. Here is the
2714 repertoire:
2715
2716 \startluacode
2717 context.starttabulate { "|lT|plT|" }
2718 for name, usage in table.sortedhash(moduledata.repertoire) do
2719 context.NC() context(name)
2720 context.NC() context("% t",table.sortedkeys(usage))
2721 context.NC() context.NR()
2722 end
2723 context.stoptabulate()
2724 \stopluacode
2725
2726 \stopsubsection
2727
2728 \startsubsection[title={Properties}]
2729
2730 Attributes are a convenient way to relate extra information to a node. You can
2731 assign them at the \TEX\ end as well as at the \LUA\ end and consult them at the
2732 \LUA\ end. One big advantage is that they obey grouping. They are linked lists
2733 and normally checking for them is pretty efficient, even if you use a lot of
2734 them. A macro package has to provide some way to manage these attributes at the
2735 \TEX\ end because otherwise clashes in their usage can occur.
2736
2737 Each node also can have a properties table and you can assign values to this
2738 table using the \type {setproperty} function and get properties using the \type
2739 {getproperty} function. Managing properties is way more demanding than managing
2740 attributes.
2741
2742 Take the following example:
2743
2744 \starttyping
2745 \directlua {
2746 local n = node.new("glyph")
2747
2748 node.setproperty(n,"foo")
2749 print(node.getproperty(n))
2750
2751 node.setproperty(n,"bar")
2752 print(node.getproperty(n))
2753
2754 node.free(n)
2755 }
2756 \stoptyping
2757
2758 This will print \type {foo} and \type {bar} which in itself is not that useful
2759 when multiple mechanisms want to use this feature. A variant is:
2760
2761 \starttyping
2762 \directlua {
2763 local n = node.new("glyph")
2764
2765 node.setproperty(n,{ one = "foo", two = "bar" })
2766 print(node.getproperty(n).one)
2767 print(node.getproperty(n).two)
2768
2769 node.free(n)
2770 }
2771 \stoptyping
2772
2773 This time we store two properties with the node. It really makes sense to have a
2774 table as property because that way we can store more. But in order for that to
2775 work well you need to do it this way:
2776
2777 \starttyping
2778 \directlua {
2779 local n = node.new("glyph")
2780
2781 local t = node.getproperty(n)
2782
2783 if not t then
2784 t = { }
2785 node.setproperty(n,t)
2786 end
2787 t.one = "foo"
2788 t.two = "bar"
2789
2790 print(node.getproperty(n).one)
2791 print(node.getproperty(n).two)
2792
2793 node.free(n)
2794 }
2795 \stoptyping
2796
2797 Here our own properties will not overwrite other users properties unless of
2798 course they use the same keys. So, eventually you will end up with something:
2799
2800 \starttyping
2801 \directlua {
2802 local n = node.new("glyph")
2803
2804 local t = node.getproperty(n)
2805
2806 if not t then
2807 t = { }
2808 node.setproperty(n,t)
2809 end
2810 t.myself = { one = "foo", two = "bar" }
2811
2812 print(node.getproperty(n).myself.one)
2813 print(node.getproperty(n).myself.two)
2814
2815 node.free(n)
2816 }
2817 \stoptyping
2818
2819 This assumes that only you use \type {myself} as subtable. The possibilities are
2820 endless but care is needed. For instance, the generic font handler that ships
2821 with \CONTEXT\ uses the \type {injections} subtable and you should not mess with
2822 that one!
2823
2824 There are a few helper functions that you normally should not touch as user: \typ
2825 {getpropertiestable} and will give the table that stores properties (using
2826 direct entries) and you can best not mess too much with that one either because
2827 \LUAMETATEX\ itself will make sure that entries related to nodes will get wiped when
2828 nodes get freed, so that the \LUA\ garbage collector can do its job. In fact, the
2829 main reason why we have this mechanism is that it saves the user (or macro
2830 package) some work. One can easily write a property mechanism in \LUA\ where
2831 after a shipout properties gets cleaned up but it's not entirely trivial to make
2832 sure that with each freed node also its properties get freed, due to the fact
2833 that there can be nodes left over for a next page. And having a callback bound to
2834 the node deallocator would add way to much overhead.
2835
2836 When we copy a node list that has a table as property, there are several
2837 possibilities: we do the same as a new node, we copy the entry to the table in
2838 properties (a reference), we do a deep copy of a table in the properties, we
2839 create a new table and give it the original one as a metatable. After some
2840 experiments (that also included timing) with these scenarios we decided that a
2841 deep copy made no sense, nor did nilling. In the end both the shallow copy and
2842 the metatable variant were both ok, although the second one is slower. The most
2843 important aspect to keep in mind is that references to other nodes in properties
2844 no longer can be valid for that copy. We could use two tables (one unique and one
2845 shared) or metatables but that only complicates matters.
2846
2847 When defining a new node, we could already allocate a table but it is rather easy
2848 to do that at the lua end e.g.\ using a metatable \type {__index} method. That
2849 way it is under macro package control. When deleting a node, we could keep the
2850 slot (e.g. setting it to false) but it could make memory consumption raise
2851 unneeded when we have temporary large node lists and after that only small lists.
2852 Both are not done because in the end this is what happens now: when a node is
2853 copied, and it has a table as property, the new node will share that table. The
2854 copy gets its own table with the original table as metatable.
2855
2856 A few more experiments were done. For instance: copy attributes to the properties
2857 so that we have fast access at the \LUA\ end. In the end the overhead is not
2858 compensated by speed and convenience, in fact, attributes are not that slow when
2859 it comes to accessing them. So this was rejected.
2860
2861 Another experiment concerned a bitset in the node but again the gain compared to
2862 attributes could be neglected and given the small amount of available bits it also
2863 demands a pretty strong agreement over what bit represents what, and this is
2864 unlikely to succeed in the \TEX\ community. It doesn't pay off.
2865
2866 Just in case one wonders why properties make sense: it is not so much speed that
2867 we gain, but more convenience: storing all kinds of (temporary) data in attributes
2868 is no fun and this mechanism makes sure that properties are cleaned up when a
2869 node is freed. Also, the advantage of a more or less global properties table is
2870 that we stay at the \LUA\ end. An alternative is to store a reference in the node
2871 itself but that is complicated by the fact that the register has some limitations
2872 (no numeric keys) and we also don't want to mess with it too much.
2873
2874 \stopsubsection
2875
2876 \stopsection
2877
2878 \stopdocument