new beta-0.90.0
[luatex.git] / manual / luatex-libraries.tex
blob71d14040b4e23607cb45c87e2f5a8d0c66cab913
1 % language=uk
3 \environment luatex-style
4 \environment luatex-logos
6 % HH: to be checked
8 \startcomponent luatex-libraries
10 \startchapter[reference=libraries,title={\LUATEX\ \LUA\ Libraries}]
12 The implied use of the built|-|in \LUA\ modules \type {epdf}, \type {fontloader},
13 \type {mplib}, and \type {pdfscanner} is deprecated. If you want to use these,
14 please start your source file with a proper \type {require} line. In the future,
15 \LUATEX\ will switch to loading these modules on demand.
17 The interfacing between \TEX\ and \LUA\ is facilitated by a set of library
18 modules. The \LUA\ libraries in this chapter are all defined and initialized by
19 the \LUATEX\ executable. Together, they allow \LUA\ scripts to query and change a
20 number of \TEX's internal variables, run various internal \TEX\ functions, and
21 set up \LUATEX's hooks to execute \LUA\ code.
23 The following sections are in alphabetical order. For any callback (and
24 manipulation of nodes) the following is true: you have a lot of freedom which
25 also means that you can mess up the node lists and nodes themselves. So, a bit of
26 defensive programming doesn't hurt. A crash can happen when you spoil things or
27 when \LUATEX\ can recognize the issue, a panic exit will happen. Don't bother the
28 team with such issues.
30 \section{The \type {callback} library}
32 This library has functions that register, find and list callbacks. Callbacks are
33 \LUA\ functions that are called in well defined places. There are two kind of
34 callbacks: those that mix with existing functionality, and those that (when
35 enabled) replace functionality. In mosty cases the second category is expected to
36 behave similar to the built in functionality because in a next step specific
37 data is expected. For instance, you can replace the hyphenation routine. The
38 function gets a list that can be hyphenated (or not). The final list should be
39 valid and is (normally) used for constructing a paragraph. Another function can
40 replace the ligature builder and|/|or kerner. Doing something else is possible
41 but in the end might not give the user the expected outcome.
43 The first thing you need to do is registering a callback:
45 \startfunctioncall
46 id, error = callback.register (<string> callback_name, <function> func)
47 id, error = callback.register (<string> callback_name, nil)
48 id, error = callback.register (<string> callback_name, false)
49 \stopfunctioncall
51 Here the \syntax {callback_name} is a predefined callback name, see below. The
52 function returns the internal \type {id} of the callback or \type {nil}, if the
53 callback could not be registered. In the latter case, \type {error} contains an
54 error message, otherwise it is \type {nil}.
56 \LUATEX\ internalizes the callback function in such a way that it does not matter
57 if you redefine a function accidentally.
59 Callback assignments are always global. You can use the special value \type {nil}
60 instead of a function for clearing the callback.
62 For some minor speed gain, you can assign the boolean \type {false} to the
63 non|-|file related callbacks, doing so will prevent \LUATEX\ from executing
64 whatever it would execute by default (when no callback function is registered at
65 all). Be warned: this may cause all sorts of grief unless you know {\em exactly}
66 what you are doing!
68 \startfunctioncall
69 <table> info = callback.list()
70 \stopfunctioncall
72 The keys in the table are the known callback names, the value is a boolean where
73 \type {true} means that the callback is currently set (active).
75 \startfunctioncall
76 <function> f = callback.find (callback_name)
77 \stopfunctioncall
79 If the callback is not set, \type {callback.find} returns \type {nil}.
81 \subsection{File discovery callbacks}
83 The behaviour documented in this subsection is considered stable in the sense that
84 there will not be backward|-|incompatible changes any more.
86 \subsubsection{\type {find_read_file} and \type {find_write_file}}
88 Your callback function should have the following conventions:
90 \startfunctioncall
91 <string> actual_name = function (<number> id_number, <string> asked_name)
92 \stopfunctioncall
94 Arguments:
96 \startitemize
98 \sym{id_number}
100 This number is zero for the log or \type {\input} files. For \TEX's \type {\read}
101 or \type {\write} the number is incremented by one, so \type {\read0} becomes~1.
103 \sym{asked_name}
105 This is the user|-|supplied filename, as found by \type {\input}, \type {\openin}
106 or \type {\openout}.
108 \stopitemize
110 Return value:
112 \startitemize
114 \sym{actual_name}
116 This is the filename used. For the very first file that is read in by \TEX, you
117 have to make sure you return an \type {actual_name} that has an extension and
118 that is suitable for use as \type {jobname}. If you don't, you will have to
119 manually fix the name of the log file and output file after \LUATEX\ is finished,
120 and an eventual format filename will become mangled. That is because these file
121 names depend on the jobname.
123 You have to return \type {nil} if the file cannot be found.
125 \stopitemize
127 \subsubsection{\type {find_font_file}}
129 Your callback function should have the following conventions:
131 \startfunctioncall
132 <string> actual_name = function (<string> asked_name)
133 \stopfunctioncall
135 The \type {asked_name} is an \OTF\ or \TFM\ font metrics file.
137 Return \type {nil} if the file cannot be found.
139 \subsubsection{\type {find_output_file}}
141 Your callback function should have the following conventions:
143 \startfunctioncall
144 <string> actual_name = function (<string> asked_name)
145 \stopfunctioncall
147 The \type {asked_name} is the \PDF\ or \DVI\ file for writing.
149 \subsubsection{\type {find_format_file}}
151 Your callback function should have the following conventions:
153 \startfunctioncall
154 <string> actual_name = function (<string> asked_name)
155 \stopfunctioncall
157 The \type {asked_name} is a format file for reading (the format file for writing
158 is always opened in the current directory).
160 \subsubsection{\type {find_vf_file}}
162 Like \type {find_font_file}, but for virtual fonts. This applies to both \ALEPH's
163 \OVF\ files and traditional Knuthian \VF\ files.
165 \subsubsection{\type {find_map_file}}
167 Like \type {find_font_file}, but for map files.
169 \subsubsection{\type {find_enc_file}}
171 Like \type {find_font_file}, but for enc files.
173 \subsubsection{\type {find_sfd_file}}
175 Like \type {find_font_file}, but for subfont definition files.
177 \subsubsection{\type {find_pk_file}}
179 Like \type {find_font_file}, but for pk bitmap files. This callback takes two
180 arguments: \type {name} and \type {dpi}. In your callback you can decide to
181 look for:
183 \starttyping
184 <base res>dpi/<fontname>.<actual res>pk
185 \stoptyping
187 but other strategies are possible. It is up to you to find a \quote {reasonable}
188 bitmap file to go with that specification.
190 \subsubsection{\type {find_data_file}}
192 Like \type {find_font_file}, but for embedded files (\type {\pdfobj file '...'}).
194 \subsubsection{\type {find_opentype_file}}
196 Like \type {find_font_file}, but for \OPENTYPE\ font files.
198 \subsubsection{\type {find_truetype_file} and \type {find_type1_file}}
200 Your callback function should have the following conventions:
202 \startfunctioncall
203 <string> actual_name = function (<string> asked_name)
204 \stopfunctioncall
206 The \type {asked_name} is a font file. This callback is called while \LUATEX\ is
207 building its internal list of needed font files, so the actual timing may
208 surprise you. Your return value is later fed back into the matching \type
209 {read_file} callback.
211 Strangely enough, \type {find_type1_file} is also used for \OPENTYPE\ (\OTF)
212 fonts.
214 \subsubsection{\type {find_image_file}}
216 Your callback function should have the following conventions:
218 \startfunctioncall
219 <string> actual_name = function (<string> asked_name)
220 \stopfunctioncall
222 The \type {asked_name} is an image file. Your return value is used to open a file
223 from the hard disk, so make sure you return something that is considered the name
224 of a valid file by your operating system.
226 \subsection[iocallback]{File reading callbacks}
228 The behavior documented in this subsection is considered stable in the sense that
229 there will not be backward-incompatible changes any more.
231 \subsubsection{\type {open_read_file}}
233 Your callback function should have the following conventions:
235 \startfunctioncall
236 <table> env = function (<string> file_name)
237 \stopfunctioncall
239 Argument:
241 \startitemize
243 \sym{file_name}
245 The filename returned by a previous \type {find_read_file} or the return value of
246 \type {kpse.find_file()} if there was no such callback defined.
248 \stopitemize
250 Return value:
252 \startitemize
254 \sym{env}
256 This is a table containing at least one required and one optional callback
257 function for this file. The required field is \type {reader} and the associated
258 function will be called once for each new line to be read, the optional one is
259 \type {close} that will be called once when \LUATEX\ is done with the file.
261 \LUATEX\ never looks at the rest of the table, so you can use it to store your
262 private per|-|file data. Both the callback functions will receive the table as
263 their only argument.
265 \stopitemize
267 \subsubsubsection{\type {reader}}
269 \LUATEX\ will run this function whenever it needs a new input line from the file.
271 \startfunctioncall
272 function(<table> env)
273 return <string> line
275 \stopfunctioncall
277 Your function should return either a string or \type {nil}. The value \type {nil}
278 signals that the end of file has occurred, and will make \TEX\ call the optional
279 \type {close} function next.
281 \subsubsubsection{\type {close}}
283 \LUATEX\ will run this optional function when it decides to close the file.
285 \startfunctioncall
286 function(<table> env)
288 \stopfunctioncall
290 Your function should not return any value.
292 \subsubsection{General file readers}
294 There is a set of callbacks for the loading of binary data files. These all use
295 the same interface:
297 \startfunctioncall
298 function(<string> name)
299 return <boolean> success, <string> data, <number> data_size
301 \stopfunctioncall
303 The \type {name} will normally be a full path name as it is returned by either
304 one of the file discovery callbacks or the internal version of \type
305 {kpse.find_file()}.
307 \startitemize
309 \sym{success}
311 Return \type {false} when a fatal error occurred (e.g.\ when the file cannot be
312 found, after all).
314 \sym{data}
316 The bytes comprising the file.
318 \sym{data_size}
320 The length of the \type {data}, in bytes.
322 \stopitemize
324 Return an empty string and zero if the file was found but there was a
325 reading problem.
327 The list of functions is as follows:
329 \starttabulate[|l|p|]
330 \NC \type {read_font_file} \NC ofm or tfm files \NC \NR
331 \NC \type {read_vf_file} \NC virtual fonts \NC \NR
332 \NC \type {read_map_file} \NC map files \NC \NR
333 \NC \type {read_enc_file} \NC encoding files \NC \NR
334 \NC \type {read_sfd_file} \NC subfont definition files \NC \NR
335 \NC \type {read_pk_file} \NC pk bitmap files \NC \NR
336 \NC \type {read_data_file} \NC embedded files (\type {\pdfobj file ...}) \NC \NR
337 \NC \type {read_truetype_file} \NC \TRUETYPE\ font files \NC \NR
338 \NC \type {read_type1_file} \NC \TYPEONE\ font files \NC \NR
339 \NC \type {read_opentype_file} \NC \OPENTYPE\ font files \NC \NR
340 \stoptabulate
342 \subsection{Data processing callbacks}
344 \subsubsection{\type {process_input_buffer}}
346 This callback allows you to change the contents of the line input buffer just
347 before \LUATEX\ actually starts looking at it.
349 \startfunctioncall
350 function(<string> buffer)
351 return <string> adjusted_buffer
353 \stopfunctioncall
355 If you return \type {nil}, \LUATEX\ will pretend like your callback never
356 happened. You can gain a small amount of processing time from that. This callback
357 does not replace any internal code.
359 \subsubsection{\type {process_output_buffer}}
361 This callback allows you to change the contents of the line output buffer just
362 before \LUATEX\ actually starts writing it to a file as the result of a \type
363 {\write} command. It is only called for output to an actual file (that is,
364 excluding the log, the terminal, and \type {\write18} calls).
366 \startfunctioncall
367 function(<string> buffer)
368 return <string> adjusted_buffer
370 \stopfunctioncall
372 If you return \type {nil}, \LUATEX\ will pretend like your callback never
373 happened. You can gain a small amount of processing time from that. This callback
374 does not replace any internal code.
376 \subsubsection{\type {process_jobname}}
378 This callback allows you to change the jobname given by \type {\jobname} in \TEX\
379 and \type {tex.jobname} in Lua. It does not affect the internal job name or the
380 name of the output or log files.
382 \startfunctioncall
383 function(<string> jobname)
384 return <string> adjusted_jobname
386 \stopfunctioncall
388 The only argument is the actual job name; you should not use \type {tex.jobname}
389 inside this function or infinite recursion may occur. If you return \type {nil},
390 \LUATEX\ will pretend your callback never happened. This callback does not
391 replace any internal code.
393 \subsection{Node list processing callbacks}
395 The description of nodes and node lists is in~\in{chapter}[nodes].
397 \subsubsection{\type {contribute_filter}}
399 This callback is called when \LUATEX\ adds contents to list:
401 \startfunctioncall
402 function(<string> extrainfo)
404 \stopfunctioncall
406 The string reports the group code. From this you can deduce from
407 what list you can give a treat.
409 \starttabulate
410 \NC \bf group codes \NC \bf pointer \NC \NR
412 \NC\type {pre_box} \NC \type {contrib_head} \NC \NR
413 \NC\type {pre_adjust_tail} \NC \type {pre_adjust_head} \NC \NR
414 \NC\type {just} \NC \type {just_box} \NC \NR
415 \NC\type {adjust_tail} \NC \type {adjust_head} \NC \NR
416 \stoptabulate
418 \subsubsection{\type {buildpage_filter}}
420 This callback is called whenever \LUATEX\ is ready to move stuff to the main
421 vertical list. You can use this callback to do specialized manipulation of the
422 page building stage like imposition or column balancing.
424 \startfunctioncall
425 function(<string> extrainfo)
427 \stopfunctioncall
429 The string \type {extrainfo} gives some additional information about what \TEX's
430 state is with respect to the \quote {current page}. The possible values are:
432 \starttabulate[|lT|p|]
433 \NC \ssbf value \NC \bf explanation \NC \NR
434 \NC alignment \NC a (partial) alignment is being added \NC \NR
435 \NC after_output \NC an output routine has just finished \NC \NR
436 \NC box \NC a typeset box is being added \NC \NR
437 %NC pre_box \NC interline material is being added \NC \NR
438 %NC adjust \NC \type {\vadjust} material is being added \NC \NR
439 \NC new_graf \NC the beginning of a new paragraph \NC \NR
440 \NC vmode_par \NC \type {\par} was found in vertical mode \NC \NR
441 \NC hmode_par \NC \type {\par} was found in horizontal mode \NC \NR
442 \NC insert \NC an insert is added \NC \NR
443 \NC penalty \NC a penalty (in vertical mode) \NC \NR
444 \NC before_display \NC immediately before a display starts \NC \NR
445 \NC after_display \NC a display is finished \NC \NR
446 \NC end \NC \LUATEX\ is terminating (it's all over) \NC \NR
447 \stoptabulate
449 This callback does not replace any internal code.
451 \subsubsection{\type {pre_linebreak_filter}}
453 This callback is called just before \LUATEX\ starts converting a list of nodes
454 into a stack of \type {\hbox}es, after the addition of \type {\parfillskip}.
456 \startfunctioncall
457 function(<node> head, <string> groupcode)
458 return true | false | <node> newhead
460 \stopfunctioncall
462 The string called \type {groupcode} identifies the nodelist's context within
463 \TEX's processing. The range of possibilities is given in the table below, but
464 not all of those can actually appear in \type {pre_linebreak_filter}, some are
465 for the \type {hpack_filter} and \type {vpack_filter} callbacks that will be
466 explained in the next two paragraphs.
468 \starttabulate[|lT|p|]
469 \NC \ssbf value \NC \bf explanation \NC \NR
470 \NC <empty> \NC main vertical list \NC \NR
471 \NC hbox \NC \type {\hbox} in horizontal mode \NC \NR
472 \NC adjusted_hbox \NC \type {\hbox} in vertical mode \NC \NR
473 \NC vbox \NC \type {\vbox} \NC \NR
474 \NC vtop \NC \type {\vtop} \NC \NR
475 \NC align \NC \type {\halign} or \type {\valign} \NC \NR
476 \NC disc \NC discretionaries \NC \NR
477 \NC insert \NC packaging an insert \NC \NR
478 \NC vcenter \NC \type {\vcenter} \NC \NR
479 \NC local_box \NC \type {\localleftbox} or \type {\localrightbox} \NC \NR
480 \NC split_off \NC top of a \type {\vsplit} \NC \NR
481 \NC split_keep \NC remainder of a \type {\vsplit} \NC \NR
482 \NC align_set \NC alignment cell \NC \NR
483 \NC fin_row \NC alignment row \NC \NR
484 \stoptabulate
486 As for all the callbacks that deal with nodes, the return value can be one of
487 three things:
489 \startitemize
490 \startitem
491 boolean \type {true} signals succesfull processing
492 \stopitem
493 \startitem
494 \type {<node>} signals that the \quote {head} node should be replaced by the
495 returned node
496 \stopitem
497 \startitem
498 boolean \type {false} signals that the \quote {head} node list should be
499 ignored and flushed from memory
500 \stopitem
501 \stopitemize
503 This callback does not replace any internal code.
505 \subsubsection{\type {linebreak_filter}}
507 This callback replaces \LUATEX's line breaking algorithm.
509 \startfunctioncall
510 function(<node> head, <boolean> is_display)
511 return <node> newhead
513 \stopfunctioncall
515 The returned node is the head of the list that will be added to the main vertical
516 list, the boolean argument is true if this paragraph is interrupted by a
517 following math display.
519 If you return something that is not a \type {<node>}, \LUATEX\ will apply the
520 internal linebreak algorithm on the list that starts at \type {<head>}.
521 Otherwise, the \type {<node>} you return is supposed to be the head of a list of
522 nodes that are all allowed in vertical mode, and at least one of those has to
523 represent a hbox. Failure to do so will result in a fatal error.
525 Setting this callback to \type {false} is possible, but dangerous, because it is
526 possible you will end up in an unfixable \quote {deadcycles loop}.
528 \subsubsection{\type {append_to_vlist_filter}}
530 This callback is called whenever \LUATEX\ adds a box to a vertical list:
532 \startfunctioncall
533 function(<node> box, <string> locationcode, <number prevdepth>,
534 <boolean> mirrored)
535 return list, prevdepth
537 \stopfunctioncall
539 It is ok to return nothing in which case you also need to flush the box or deal
540 with it yourself. The prevdepth is also optional. Locations are \type {box},
541 \type {alignment}, \type {equation}, \type {equation_number} and \type
542 {post_linebreak}.
544 \subsubsection{\type {post_linebreak_filter}}
546 This callback is called just after \LUATEX\ has converted a list of nodes into a
547 stack of \type {\hbox}es.
549 \startfunctioncall
550 function(<node> head, <string> groupcode)
551 return true | false | <node> newhead
553 \stopfunctioncall
555 This callback does not replace any internal code.
557 \subsubsection{\type {hpack_filter}}
559 This callback is called when \TEX\ is ready to start boxing some horizontal mode
560 material. Math items and line boxes are ignored at the moment.
562 \startfunctioncall
563 function(<node> head, <string> groupcode, <number> size,
564 <string> packtype [, <string> direction] [, <node> attributelist])
565 return true | false | <node> newhead
567 \stopfunctioncall
569 The \type {packtype} is either \type {additional} or \type {exactly}. If \type
570 {additional}, then the \type {size} is a \type {\hbox spread ...} argument. If
571 \type {exactly}, then the \type {size} is a \type {\hbox to ...}. In both cases,
572 the number is in scaled points.
574 The \type {direction} is either one of the three-letter direction specifier
575 strings, or \type {nil}.
577 This callback does not replace any internal code.
579 \subsubsection{\type {vpack_filter}}
581 This callback is called when \TEX\ is ready to start boxing some vertical mode
582 material. Math displays are ignored at the moment.
584 This function is very similar to the \type {hpack_filter}. Besides the fact
585 that it is called at different moments, there is an extra variable that matches
586 \TEX's \type {\maxdepth} setting.
588 \startfunctioncall
589 function(<node> head, <string> groupcode, <number> size, <string> packtype,
590 <number> maxdepth [, <string> direction] [, <node> attributelist]))
591 return true | false | <node> newhead
593 \stopfunctioncall
595 This callback does not replace any internal code.
597 \subsubsection{\type {hpack_quality}}
599 This callback can be used to intercept the overfull messages that can result from
600 packing a horizontal list (as happens in the par builder). The function takes a
601 few arguments:
603 \startfunctioncall
604 function(<string> incident, <number> detail, <node> head, <number> first,
605 <number> last)
606 return <node> whatever
608 \stopfunctioncall
610 The incident is one of \type {overfull}, \type {underfull}, \type {loose} or
611 \type {tight}. The detail is either the amount of overflow in case of \type
612 {overfull}, or the badness otherwise. The head is the list that is constructed
613 (when protrusion or expansion is enabled, this is an intermediate list).
614 Optionally you can return a node, for instance an overfull rule indicator. That
615 node will be appended to the list (just like \TEX's own rule would).
617 \subsubsection{\type {vpack_quality}}
619 This callback can be used to intercept the overfull messages that can result from
620 packing a vertical list (as happens in the page builder). The function takes a
621 few arguments:
623 \startfunctioncall
624 function(<string> incident, <number> detail, <node> head, <number> first,
625 <number> last)
627 \stopfunctioncall
629 The incident is one of \type {overfull}, \type {underfull}, \type {loose} or
630 \type {tight}. The detail is either the amount of overflow in case of \type
631 {overfull}, or the badness otherwise. The head is the list that is constructed.
633 \subsubsection{\type {process_rule}}
635 This is an experimental callback. It can be used with rules of subtype~4
636 (user). The callback gets three arguments: the node, the width and the
637 height. The callback can use \type {pdf.print} to write code to the \PDF\
638 file but beware of not messing up the final result. No checking is done.
640 \subsubsection{\type {pre_output_filter}}
642 This callback is called when \TEX\ is ready to start boxing the box 255 for \type
643 {\output}.
645 \startfunctioncall
646 function(<node> head, <string> groupcode, <number> size, <string> packtype,
647 <number> maxdepth [, <string> direction])
648 return true | false | <node> newhead
650 \stopfunctioncall
652 This callback does not replace any internal code.
654 \subsubsection{\type {hyphenate}}
656 \startfunctioncall
657 function(<node> head, <node> tail)
659 \stopfunctioncall
661 No return values. This callback has to insert discretionary nodes in the node
662 list it receives.
664 Setting this callback to \type {false} will prevent the internal discretionary
665 insertion pass.
667 \subsubsection{\type {ligaturing}}
669 \startfunctioncall
670 function(<node> head, <node> tail)
672 \stopfunctioncall
674 No return values. This callback has to apply ligaturing to the node list it
675 receives.
677 You don't have to worry about return values because the \type {head} node that is
678 passed on to the callback is guaranteed not to be a glyph_node (if need be, a
679 temporary node will be prepended), and therefore it cannot be affected by the
680 mutations that take place. After the callback, the internal value of the \quote
681 {tail of the list} will be recalculated.
683 The \type {next} of \type {head} is guaranteed to be non-nil.
685 The \type {next} of \type {tail} is guaranteed to be nil, and therefore the
686 second callback argument can often be ignored. It is provided for orthogonality,
687 and because it can sometimes be handy when special processing has to take place.
689 Setting this callback to \type {false} will prevent the internal ligature
690 creation pass.
692 You must not ruin the node list. For instance, the head normally is a local par node,
693 and the tail a glue. Messing too much can push \LUATEX\ into panic mode.
695 \subsubsection{\type {kerning}}
697 \startfunctioncall
698 function(<node> head, <node> tail)
700 \stopfunctioncall
702 No return values. This callback has to apply kerning between the nodes in the
703 node list it receives. See \type {ligaturing} for calling conventions.
705 Setting this callback to \type {false} will prevent the internal kern insertion
706 pass.
708 You must not ruin the node list. For instance, the head normally is a local par node,
709 and the tail a glue. Messing too much can push \LUATEX\ into panic mode.
711 \subsubsection{\type {insert_local_par}}
713 Each paragraph starts with a local par node that keeps track of for instance
714 the direction. You can hook a callback into the creator:
716 \startfunctioncall
717 function(<node> local_par, <string> location)
719 \stopfunctioncall
721 There is no return value and you should make sure that the node stays valid
722 as otherwise \TEX\ can get confused.
724 \subsubsection{\type {mlist_to_hlist}}
726 This callback replaces \LUATEX's math list to node list conversion algorithm.
728 \startfunctioncall
729 function(<node> head, <string> display_type, <boolean> need_penalties)
730 return <node> newhead
732 \stopfunctioncall
734 The returned node is the head of the list that will be added to the vertical or
735 horizontal list, the string argument is either \quote {text} or \quote {display}
736 depending on the current math mode, the boolean argument is \type {true} if
737 penalties have to be inserted in this list, \type {false} otherwise.
739 Setting this callback to \type {false} is bad, it will almost certainly result in
740 an endless loop.
742 \subsection{Information reporting callbacks}
744 \subsubsection{\type {pre_dump}}
746 \startfunctioncall
747 function()
749 \stopfunctioncall
751 This function is called just before dumping to a format file starts. It does not
752 replace any code and there are neither arguments nor return values.
754 \subsubsection{\type {start_run}}
756 \startfunctioncall
757 function()
759 \stopfunctioncall
761 This callback replaces the code that prints \LUATEX's banner. Note that for
762 successful use, this callback has to be set in the \LUA\ initialization script,
763 otherwise it will be seen only after the run has already started.
765 \subsubsection{\type {stop_run}}
767 \startfunctioncall
768 function()
770 \stopfunctioncall
772 This callback replaces the code that prints \LUATEX's statistics and \quote
773 {output written to} messages.
775 \subsubsection{\type {start_page_number}}
777 \startfunctioncall
778 function()
780 \stopfunctioncall
782 Replaces the code that prints the \type {[} and the page number at the begin of
783 \type {\shipout}. This callback will also override the printing of box information
784 that normally takes place when \type {\tracingoutput} is positive.
786 \subsubsection{\type {stop_page_number}}
788 \startfunctioncall
789 function()
791 \stopfunctioncall
793 Replaces the code that prints the \type {]} at the end of \type {\shipout}.
795 \subsubsection{\type {show_error_hook}}
797 \startfunctioncall
798 function()
800 \stopfunctioncall
802 This callback is run from inside the \TEX\ error function, and the idea is to
803 allow you to do some extra reporting on top of what \TEX\ already does (none of
804 the normal actions are removed). You may find some of the values in the \type
805 {status} table useful. This callback does not replace any internal code.
807 \subsubsection{\type {show_error_message}}
809 \startfunctioncall
810 function()
812 \stopfunctioncall
814 This callback replaces the code that prints the error message. The usual
815 interaction after the message is not affected.
817 \subsubsection{\type {show_lua_error_hook}}
819 \startfunctioncall
820 function()
822 \stopfunctioncall
824 This callback replaces the code that prints the extra \LUA\ error message.
826 \subsubsection{\type {start_file}}
828 \startfunctioncall
829 function(category,filename)
831 \stopfunctioncall
833 This callback replaces the code that prints \LUATEX's when a file is opened like
834 \type {(filename} for regular files. The category is a number:
836 \starttabulate[|||]
837 \NC 1 \NC a normal data file, like a \TEX\ source \NC \NR
838 \NC 2 \NC a font map coupling font names to resources \NC \NR
839 \NC 3 \NC an image file (\type {png}, \type {pdf}, etc) \NC \NR
840 \NC 4 \NC an embedded font subset \NC \NR
841 \NC 5 \NC a fully embedded font \NC \NR
842 \stoptabulate
844 \subsubsection{\type {stop_file}}
846 \startfunctioncall
847 function(category)
849 \stopfunctioncall
851 This callback replaces the code that prints \LUATEX's when a file is closed like
852 the \type {)} for regular files.
854 \subsection{PDF-related callbacks}
856 \subsubsection{\type {finish_pdffile}}
858 \startfunctioncall
859 function()
861 \stopfunctioncall
863 This callback is called when all document pages are already written to the \PDF\
864 file and \LUATEX\ is about to finalize the output document structure. Its
865 intended use is final update of \PDF\ dictionaries such as \type {/Catalog} or
866 \type {/Info}. The callback does not replace any code. There are neither
867 arguments nor return values.
869 \subsubsection{\type {finish_pdfpage}}
871 \startfunctioncall
872 function(shippingout)
874 \stopfunctioncall
876 This callback is called after the \PDF\ page stream has been assembled and before
877 the page object gets finalized.
879 \subsection{Font-related callbacks}
881 \subsubsection{\type {define_font}}
883 \startfunctioncall
884 function(<string> name, <number> size, <number> id)
885 return <table> font | <number> id
887 \stopfunctioncall
889 The string \type {name} is the filename part of the font specification, as given
890 by the user.
892 The number \type {size} is a bit special:
894 \startitemize[packed]
895 \startitem
896 If it is positive, it specifies an \quote{at size} in scaled points.
897 \stopitem
898 \startitem
899 If it is negative, its absolute value represents a \quote {scaled} setting
900 relative to the designsize of the font.
901 \stopitem
902 \stopitemize
904 The \type {id} is the internal number assigned to the font.
906 The internal structure of the \type {font} table that is to be returned is
907 explained in \in {chapter} [fonts]. That table is saved internally, so you can
908 put extra fields in the table for your later \LUA\ code to use. In alternative,
909 \type {retval} can be a previously defined fontid. This is useful if a previous
910 definition can be reused instead of creating a whole new font structure.
912 Setting this callback to \type {false} is pointless as it will prevent font
913 loading completely but will nevertheless generate errors.
915 \section{The \type {epdf} library}
917 The \type {epdf} library provides \LUA\ bindings to many \PDF\ access functions
918 that are defined by the poppler \PDF\ viewer library (written in C$+{}+$ by
919 Kristian H\o gsberg, based on xpdf by Derek Noonburg). Within \LUATEX\ (and
920 \PDFTEX), xpdf functionality is being used since long time to embed \PDF\ files.
921 The \type {epdf} library shall allow to scrutinize an external \PDF\ file. It
922 gives access to its document structure: catalog, cross|-|reference table,
923 individual pages, objects, annotations, info, and metadata. The \LUATEX\ team is
924 evaluating the possibility of reducing the binding to a basic low level \PDF\
925 primitives and delegate the complete set of functions to an external shared
926 object module.
928 The \type {epdf} library is still in alpha state: \PDF\ access is currently
929 read|-|only. Iit's not yet possible to alter a \PDF\ file or to assemble it from
930 scratch, and many function bindings are still missing, and it is unlikely that we
931 to support that at all. At some point we might also decide to limit the interface
932 to a reasonable subset.
934 For a start, a \PDF\ file is opened by \type {epdf.open()} with file name, e.g.:
936 \starttyping
937 doc = epdf.open("foo.pdf")
938 \stoptyping
940 This normally returns a \type {PDFDoc} userdata variable; but if the file could
941 not be opened successfully, instead of a fatal error just the value \type {nil} is
942 returned.
944 All Lua functions in the \type {epdf} library are named after the poppler
945 functions listed in the poppler header files for the various classes, e.g., files
946 \type {PDFDoc.h}, \type {Dict.h}, and \type {Array.h}. These files can be found
947 in the poppler subdirectory within the \LUATEX\ sources. Which functions are
948 already implemented in the \type {epdf} library can be found in the \LUATEX\
949 source file \type {lepdflib.cc}. For using the \type {epdf} library, knowledge of
950 the \PDF\ file architecture is indispensable.
952 There are many different userdata types defined by the \type {epdf} library,
953 currently these are \type {AnnotBorderStyle}, \type {AnnotBorder}, \type
954 {Annots}, \type {Annot}, \type {Array}, \type {Attribute}, \type {Catalog}, \type
955 {Dict}, \type {EmbFile}, \type {GString}, \type {LinkDest}, \type {Links}, \type
956 {Link}, \type {ObjectStream}, \type {Object}, \type {PDFDoc}, \type
957 {PDFRectangle}, \type {Page}, \type {Ref}, \type {Stream}, \type {StructElement},
958 \type {StructTreeRoot} \type {TextSpan}, \type {XRefEntry} and \type {XRef}.
960 All these userdata names and the Lua access functions closely resemble the
961 classes naming from the poppler header files, including the choice of mixed upper
962 and lower case letters. The Lua function calls use object|-|oriented syntax,
963 e.g., the following calls return the \type {Page} object for page~1:
965 \starttyping
966 pageref = doc:getCatalog():getPageRef(1)
967 pageobj = doc:getXRef():fetch(pageref.num, pageref.gen)
968 \stoptyping
970 But writing such chained calls is risky, as an intermediate function may return
971 \type {nil} on error; therefore between function calls there should be Lua type
972 checks (e.g., against \type {nil}) done. If a non-object item is requested (e.g.,
973 a \type {Dict} item by calling \type {page:getPieceInfo()}, cf.~\type {Page.h})
974 but not available, the Lua functions return \type {nil} (without error). If a
975 function should return an \type {Object}, but it's not existing, a \type {Null}
976 object is returned instead (also without error; this is in|-|line with poppler
977 behavior).
979 All library objects have a \type {__gc} metamethod for garbage collection. The
980 \type {__tostring} metamethod gives the type name for each object.
982 All object constructors:
984 \startfunctioncall
985 <PDFDoc> = epdf.open(<string> PDF filename)
986 <Annot> = epdf.Annot(<XRef>, <Dict>, <Catalog>, <Ref>)
987 <Annots> = epdf.Annots(<XRef>, <Catalog>, <Object>)
988 <Array> = epdf.Array(<XRef>)
989 <Attribute> = epdf.Attribute(<Type>,<Object>)| epdf.Attribute(<string>, <int>, <Object>)
990 <Dict> = epdf.Dict(<XRef>)
991 <Object> = epdf.Object()
992 <PDFRectangle> = epdf.PDFRectangle()
993 \stopfunctioncall
995 The functions \type {StructElement_Type}, \type {Attribute_Type} and \type
996 {AttributeOwner_Type} return a hash table \type {{<string>,<integer>}}.
998 \type {Annot} methods:
1000 \startfunctioncall
1001 <boolean> = <Annot>:isOK()
1002 <Object> = <Annot>:getAppearance()
1003 <AnnotBorder> = <Annot>:getBorder()
1004 <boolean> = <Annot>:match(<Ref>)
1005 \stopfunctioncall
1007 \type {AnnotBorderStyle} methods:
1009 \startfunctioncall
1010 <number> = <AnnotBorderStyle>:getWidth()
1011 \stopfunctioncall
1013 \type {Annots} methods:
1015 \startfunctioncall
1016 <integer> = <Annots>:getNumAnnots()
1017 <Annot> = <Annots>:getAnnot(<integer>)
1018 \stopfunctioncall
1020 \type {Array} methods:
1022 \startfunctioncall
1023 <Array>:incRef()
1024 <Array>:decRef()
1025 <integer> = <Array>:getLength()
1026 <Array>:add(<Object>)
1027 <Object> = <Array>:get(<integer>)
1028 <Object> = <Array>:getNF(<integer>)
1029 <string> = <Array>:getString(<integer>)
1030 \stopfunctioncall
1032 \type {Attribute} methods:
1034 \startfunctioncall
1035 <boolean> = <Attribute>:isOk()
1036 <integer> = <Attribute>:getType()
1037 <integer> = <Attribute>:getOwner()
1038 <string> = <Attribute>:getTypeName()
1039 <string> = <Attribute>:getOwnerName()
1040 <Object> = <Attribute>:getValue()
1041 <Object> = <Attribute>:getDefaultValue
1042 <string> = <Attribute>:getName()
1043 <integer> = <Attribute>:getRevision()
1044 <Attribute>:setRevision(<unsigned integer>)
1045 <boolean> = <Attribute>:istHidden()
1046 <Attribute>:setHidden(<boolean>)
1047 <string> = <Attribute>:getFormattedValue()
1048 <string> = <Attribute>:setFormattedValue(<string>)
1049 \stopfunctioncall
1051 \type {Catalog} methods:
1053 \startfunctioncall
1054 <boolean> = <Catalog>:isOK()
1055 <integer> = <Catalog>:getNumPages()
1056 <Page> = <Catalog>:getPage(<integer>)
1057 <Ref> = <Catalog>:getPageRef(<integer>)
1058 <string> = <Catalog>:getBaseURI()
1059 <string> = <Catalog>:readMetadata()
1060 <Object> = <Catalog>:getStructTreeRoot()
1061 <integer> = <Catalog>:findPage(<integer> object number, <integer> object generation)
1062 <LinkDest> = <Catalog>:findDest(<string> name)
1063 <Object> = <Catalog>:getDests()
1064 <integer> = <Catalog>:numEmbeddedFiles()
1065 <EmbFile> = <Catalog>:embeddedFile(<integer>)
1066 <integer> = <Catalog>:numJS()
1067 <string> = <Catalog>:getJS(<integer>)
1068 <Object> = <Catalog>:getOutline()
1069 <Object> = <Catalog>:getAcroForm()
1070 \stopfunctioncall
1072 \type {EmbFile} methods:
1074 \startfunctioncall
1075 <string> = <EmbFile>:name()
1076 <string> = <EmbFile>:description()
1077 <integer> = <EmbFile>:size()
1078 <string> = <EmbFile>:modDate()
1079 <string> = <EmbFile>:createDate()
1080 <string> = <EmbFile>:checksum()
1081 <string> = <EmbFile>:mimeType()
1082 <Object> = <EmbFile>:streamObject()
1083 <boolean> = <EmbFile>:isOk()
1084 \stopfunctioncall
1086 \type {Dict} methods:
1088 \startfunctioncall
1089 <Dict>:incRef()
1090 <Dict>:decRef()
1091 <integer> = <Dict>:getLength()
1092 <Dict>:add(<string>, <Object>)
1093 <Dict>:set(<string>, <Object>)
1094 <Dict>:remove(<string>)
1095 <boolean> = <Dict>:is(<string>)
1096 <Object> = <Dict>:lookup(<string>)
1097 <Object> = <Dict>:lookupNF(<string>)
1098 <integer> = <Dict>:lookupInt(<string>, <string>)
1099 <string> = <Dict>:getKey(<integer>)
1100 <Object> = <Dict>:getVal(<integer>)
1101 <Object> = <Dict>:getValNF(<integer>)
1102 <boolean> = <Dict>:hasKey(<string>)
1103 \stopfunctioncall
1105 \type {Link} methods:
1107 \startfunctioncall
1108 <boolean> = <Link>:isOK()
1109 <boolean> = <Link>:inRect(<number>, <number>)
1110 \stopfunctioncall
1112 \type {LinkDest} methods:
1114 \startfunctioncall
1115 <boolean> = <LinkDest>:isOK()
1116 <integer> = <LinkDest>:getKind()
1117 <string> = <LinkDest>:getKindName()
1118 <boolean> = <LinkDest>:isPageRef()
1119 <integer> = <LinkDest>:getPageNum()
1120 <Ref> = <LinkDest>:getPageRef()
1121 <number> = <LinkDest>:getLeft()
1122 <number> = <LinkDest>:getBottom()
1123 <number> = <LinkDest>:getRight()
1124 <number> = <LinkDest>:getTop()
1125 <number> = <LinkDest>:getZoom()
1126 <boolean> = <LinkDest>:getChangeLeft()
1127 <boolean> = <LinkDest>:getChangeTop()
1128 <boolean> = <LinkDest>:getChangeZoom()
1129 \stopfunctioncall
1131 \type {Links} methods:
1133 \startfunctioncall
1134 <integer> = <Links>:getNumLinks()
1135 <Link> = <Links>:getLink(<integer>)
1136 \stopfunctioncall
1138 \type {Object} methods:
1140 \startfunctioncall
1141 <Object>:initBool(<boolean>)
1142 <Object>:initInt(<integer>)
1143 <Object>:initReal(<number>)
1144 <Object>:initString(<string>)
1145 <Object>:initName(<string>)
1146 <Object>:initNull()
1147 <Object>:initArray(<XRef>)
1148 <Object>:initDict(<XRef>)
1149 <Object>:initStream(<Stream>)
1150 <Object>:initRef(<integer> object number, <integer> object generation)
1151 <Object>:initCmd(<string>)
1152 <Object>:initError()
1153 <Object>:initEOF()
1154 <Object> = <Object>:fetch(<XRef>)
1155 <integer> = <Object>:getType()
1156 <string> = <Object>:getTypeName()
1157 <boolean> = <Object>:isBool()
1158 <boolean> = <Object>:isInt()
1159 <boolean> = <Object>:isReal()
1160 <boolean> = <Object>:isNum()
1161 <boolean> = <Object>:isString()
1162 <boolean> = <Object>:isName()
1163 <boolean> = <Object>:isNull()
1164 <boolean> = <Object>:isArray()
1165 <boolean> = <Object>:isDict()
1166 <boolean> = <Object>:isStream()
1167 <boolean> = <Object>:isRef()
1168 <boolean> = <Object>:isCmd()
1169 <boolean> = <Object>:isError()
1170 <boolean> = <Object>:isEOF()
1171 <boolean> = <Object>:isNone()
1172 <boolean> = <Object>:getBool()
1173 <integer> = <Object>:getInt()
1174 <number> = <Object>:getReal()
1175 <number> = <Object>:getNum()
1176 <string> = <Object>:getString()
1177 <string> = <Object>:getName()
1178 <Array> = <Object>:getArray()
1179 <Dict> = <Object>:getDict()
1180 <Stream> = <Object>:getStream()
1181 <Ref> = <Object>:getRef()
1182 <integer> = <Object>:getRefNum()
1183 <integer> = <Object>:getRefGen()
1184 <string> = <Object>:getCmd()
1185 <integer> = <Object>:arrayGetLength()
1186 = <Object>:arrayAdd(<Object>)
1187 <Object> = <Object>:arrayGet(<integer>)
1188 <Object> = <Object>:arrayGetNF(<integer>)
1189 <integer> = <Object>:dictGetLength(<integer>)
1190 = <Object>:dictAdd(<string>, <Object>)
1191 = <Object>:dictSet(<string>, <Object>)
1192 <Object> = <Object>:dictLookup(<string>)
1193 <Object> = <Object>:dictLookupNF(<string>)
1194 <string> = <Object>:dictgetKey(<integer>)
1195 <Object> = <Object>:dictgetVal(<integer>)
1196 <Object> = <Object>:dictgetValNF(<integer>)
1197 <boolean> = <Object>:streamIs(<string>)
1198 = <Object>:streamReset()
1199 <integer> = <Object>:streamGetChar()
1200 <integer> = <Object>:streamLookChar()
1201 <integer> = <Object>:streamGetPos()
1202 = <Object>:streamSetPos(<integer>)
1203 <Dict> = <Object>:streamGetDict()
1204 \stopfunctioncall
1206 \type {Page} methods:
1208 \startfunctioncall
1209 <boolean> = <Page>:isOk()
1210 <integer> = <Page>:getNum()
1211 <PDFRectangle> = <Page>:getMediaBox()
1212 <PDFRectangle> = <Page>:getCropBox()
1213 <boolean> = <Page>:isCropped()
1214 <number> = <Page>:getMediaWidth()
1215 <number> = <Page>:getMediaHeight()
1216 <number> = <Page>:getCropWidth()
1217 <number> = <Page>:getCropHeight()
1218 <PDFRectangle> = <Page>:getBleedBox()
1219 <PDFRectangle> = <Page>:getTrimBox()
1220 <PDFRectangle> = <Page>:getArtBox()
1221 <integer> = <Page>:getRotate()
1222 <string> = <Page>:getLastModified()
1223 <Dict> = <Page>:getBoxColorInfo()
1224 <Dict> = <Page>:getGroup()
1225 <Stream> = <Page>:getMetadata()
1226 <Dict> = <Page>:getPieceInfo()
1227 <Dict> = <Page>:getSeparationInfo()
1228 <Dict> = <Page>:getResourceDict()
1229 <Object> = <Page>:getAnnots()
1230 <Links> = <Page>:getLinks(<Catalog>)
1231 <Object> = <Page>:getContents()
1232 \stopfunctioncall
1234 \type {PDFDoc} methods:
1236 \startfunctioncall
1237 <boolean> = <PDFDoc>:isOk()
1238 <integer> = <PDFDoc>:getErrorCode()
1239 <string> = <PDFDoc>:getErrorCodeName()
1240 <string> = <PDFDoc>:getFileName()
1241 <XRef> = <PDFDoc>:getXRef()
1242 <Catalog> = <PDFDoc>:getCatalog()
1243 <number> = <PDFDoc>:getPageMediaWidth()
1244 <number> = <PDFDoc>:getPageMediaHeight()
1245 <number> = <PDFDoc>:getPageCropWidth()
1246 <number> = <PDFDoc>:getPageCropHeight()
1247 <integer> = <PDFDoc>:getNumPages()
1248 <string> = <PDFDoc>:readMetadata()
1249 <Object> = <PDFDoc>:getStructTreeRoot()
1250 <integer> = <PDFDoc>:findPage(<integer> object number, <integer> object generation)
1251 <Links> = <PDFDoc>:getLinks(<integer>)
1252 <LinkDest> = <PDFDoc>:findDest(<string>)
1253 <boolean> = <PDFDoc>:isEncrypted()
1254 <boolean> = <PDFDoc>:okToPrint()
1255 <boolean> = <PDFDoc>:okToChange()
1256 <boolean> = <PDFDoc>:okToCopy()
1257 <boolean> = <PDFDoc>:okToAddNotes()
1258 <boolean> = <PDFDoc>:isLinearized()
1259 <Object> = <PDFDoc>:getDocInfo()
1260 <Object> = <PDFDoc>:getDocInfoNF()
1261 <integer> = <PDFDoc>:getPDFMajorVersion()
1262 <integer> = <PDFDoc>:getPDFMinorVersion()
1263 \stopfunctioncall
1265 \type {PDFRectangle} methods:
1267 \startfunctioncall
1268 <boolean> = <PDFRectangle>:isValid()
1269 \stopfunctioncall
1271 %\type {Ref} methods:
1273 %\startfunctioncall
1274 %\stopfunctioncall
1276 \type {Stream} methods:
1278 \startfunctioncall
1279 <integer> = <Stream>:getKind()
1280 <string> = <Stream>:getKindName()
1281 = <Stream>:reset()
1282 = <Stream>:close()
1283 <integer> = <Stream>:getChar()
1284 <integer> = <Stream>:lookChar()
1285 <integer> = <Stream>:getRawChar()
1286 <integer> = <Stream>:getUnfilteredChar()
1287 = <Stream>:unfilteredReset()
1288 <integer> = <Stream>:getPos()
1289 <boolean> = <Stream>:isBinary()
1290 <Stream> = <Stream>:getUndecodedStream()
1291 <Dict> = <Stream>:getDict()
1292 \stopfunctioncall
1294 \type {StructElement} methods:
1296 \startfunctioncall
1297 <string> = <StructElement>:getTypeName()
1298 <integer> = <StructElement>:getType()
1299 <boolean> = <StructElement>:isOk()
1300 <boolean> = <StructElement>:isBlock()
1301 <boolean> = <StructElement>:isInline()
1302 <boolean> = <StructElement>:isGrouping()
1303 <boolean> = <StructElement>:isContent()
1304 <boolean> = <StructElement>:isObjectRef()
1305 <integer> = <StructElement>:getMCID()
1306 <Ref> = <StructElement>:getObjectRef()
1307 <Ref> = <StructElement>:getParentRef()
1308 <boolean> = <StructElement>:hasPageRef()
1309 <Ref> = <StructElement>:getPageRef()
1310 <StructTreeRoot> = <StructElement>:getStructTreeRoot()
1311 <string> = <StructElement>:getID()
1312 <string> = <StructElement>:getLanguage()
1313 <integer> = <StructElement>:getRevision()
1314 <StructElement>:setRevision(<unsigned integer>)
1315 <string> = <StructElement>:getTitle()
1316 <string> = <StructElement>:getExpandedAbbr()
1317 <integer> = <StructElement>:getNumChildren()
1318 <StructElement> = <StructElement>:getChild()
1319 = <StructElement>:appendChild<StructElement>)
1320 <integer> = <StructElement>:getNumAttributes()
1321 <Attribute> = <StructElement>:geAttribute(<integer>)
1322 <string> = <StructElement>:appendAttribute(<Attribute>)
1323 <Attribute> = <StructElement>:findAttribute(<Attribute::Type>,boolean,Attribute::Owner)
1324 <string> = <StructElement>:getAltText()
1325 <string> = <StructElement>:getActualText()
1326 <string> = <StructElement>:getText(<boolean>)
1327 <table> = <StructElement>:getTextSpans()
1328 \stopfunctioncall
1330 \type {StructTreeRoot} methods:
1332 \startfunctioncall
1333 <StructElement> = <StructTreeRoot>:findParentElement
1334 <PDFDoc> = <StructTreeRoot>:getDoc
1335 <Dict> = <StructTreeRoot>:getRoleMap
1336 <Dict> = <StructTreeRoot>:getClassMap
1337 <integer> = <StructTreeRoot>:getNumChildren
1338 <StructElement> = <StructTreeRoot>:getChild
1339 <StructTreeRoot>:appendChild
1340 <StructElement> = <StructTreeRoot>:findParentElement
1341 \stopfunctioncall
1343 \type {TextSpan} han only one method:
1345 \startfunctioncall
1346 <string> = <TestSpan>:getText()
1347 \stopfunctioncall
1349 \type {XRef} methods:
1351 \startfunctioncall
1352 <boolean> = <XRef>:isOk()
1353 <integer> = <XRef>:getErrorCode()
1354 <boolean> = <XRef>:isEncrypted()
1355 <boolean> = <XRef>:okToPrint()
1356 <boolean> = <XRef>:okToPrintHighRes()
1357 <boolean> = <XRef>:okToChange()
1358 <boolean> = <XRef>:okToCopy()
1359 <boolean> = <XRef>:okToAddNotes()
1360 <boolean> = <XRef>:okToFillForm()
1361 <boolean> = <XRef>:okToAccessibility()
1362 <boolean> = <XRef>:okToAssemble()
1363 <Object> = <XRef>:getCatalog()
1364 <Object> = <XRef>:fetch(<integer> object number, <integer> object generation)
1365 <Object> = <XRef>:getDocInfo()
1366 <Object> = <XRef>:getDocInfoNF()
1367 <integer> = <XRef>:getNumObjects()
1368 <integer> = <XRef>:getRootNum()
1369 <integer> = <XRef>:getRootGen()
1370 <integer> = <XRef>:getSize()
1371 <Object> = <XRef>:getTrailerDict()
1372 \stopfunctioncall
1374 There is an experimental function \type {epdf.openMemStream} that takes three
1375 arguments:
1377 \starttabulate
1378 \NC \type {stream} \NC this is a (in low level \LUA\ speak) light userdata
1379 object, i.e.\ a pointer to a sequence of bytes \NC \NR
1380 \NC \type {length} \NC this is the length of the stream in bytes \NC \NR
1381 \NC \type {name} \NC this is a unique identifier that us used for hashing the
1382 stream, so that mulltiple doesn't use more memory \NC \NR
1383 \stoptabulate
1385 Instead of a light userdata stream you can also pass a \LUA\ string, in which
1386 case the given length is (at most) the string length.
1388 The returned object can be used in the \type {img} library instead of a filename.
1389 Both the memory stream and it's use in the image library is experimental and can
1390 change. In case you wonder where this can be used: when you use the swiglib
1391 library for \type {graphicmagick}, it can return such a userdata object. This
1392 permits conversion in memory and passing the result directly to the backend. This
1393 might save some runtime in one|-|pass workflows. This feature is currently not
1394 meant for production.
1396 \section{The \type {font} library}
1398 The font library provides the interface into the internals of the font system,
1399 and also it contains helper functions to load traditional \TEX\ font metrics
1400 formats. Other font loading functionality is provided by the \type {fontloader}
1401 library that will be discussed in the next section.
1403 \subsection{Loading a \TFM\ file}
1405 The behavior documented in this subsection is considered stable in the sense that
1406 there will not be backward-incompatible changes any more.
1408 \startfunctioncall
1409 <table> fnt = font.read_tfm(<string> name, <number> s)
1410 \stopfunctioncall
1412 The number is a bit special:
1414 \startitemize
1415 \startitem
1416 If it is positive, it specifies an \quote {at size} in scaled points.
1417 \stopitem
1418 \startitem
1419 If it is negative, its absolute value represents a \quote {scaled}
1420 setting relative to the designsize of the font.
1421 \stopitem
1422 \stopitemize
1424 The internal structure of the metrics font table that is returned is explained in
1425 \in {chapter} [fonts].
1427 \subsection{Loading a \VF\ file}
1429 The behavior documented in this subsection is considered stable in the sense that
1430 there will not be backward-incompatible changes any more.
1432 \startfunctioncall
1433 <table> vf_fnt = font.read_vf(<string> name, <number> s)
1434 \stopfunctioncall
1436 The meaning of the number \type {s} and the format of the returned table are
1437 similar to the ones in the \type {read_tfm()} function.
1439 \subsection{The fonts array}
1441 The whole table of \TEX\ fonts is accessible from \LUA\ using a virtual array.
1443 \starttyping
1444 font.fonts[n] = { ... }
1445 <table> f = font.fonts[n]
1446 \stoptyping
1448 See \in {chapter} [fonts] for the structure of the tables. Because this is a
1449 virtual array, you cannot call \type {pairs} on it, but see below for the \type
1450 {font.each} iterator.
1452 The two metatable functions implementing the virtual array are:
1454 \startfunctioncall
1455 <table> f = font.getfont(<number> n)
1456 font.setfont(<number> n, <table> f)
1457 \stopfunctioncall
1459 Note that at the moment, each access to the \type {font.fonts} or call to \type
1460 {font.getfont} creates a \LUA\ table for the whole font. This process can be quite
1461 slow. In a later version of \LUATEX, this interface will change (it will start
1462 using userdata objects instead of actual tables).
1464 Also note the following: assignments can only be made to fonts that have already
1465 been defined in \TEX, but have not been accessed {\it at all\/} since that
1466 definition. This limits the usability of the write access to \type {font.fonts}
1467 quite a lot, a less stringent ruleset will likely be implemented later.
1469 \subsection{Checking a font's status}
1471 You can test for the status of a font by calling this function:
1473 \startfunctioncall
1474 <boolean> f = font.frozen(<number> n)
1475 \stopfunctioncall
1477 The return value is one of \type {true} (unassignable), \type {false} (can be
1478 changed) or \type {nil} (not a valid font at all).
1480 \subsection{Defining a font directly}
1482 You can define your own font into \type {font.fonts} by calling this function:
1484 \startfunctioncall
1485 <number> i = font.define(<table> f)
1486 \stopfunctioncall
1488 The return value is the internal id number of the defined font (the index into
1489 \type {font.fonts}). If the font creation fails, an error is raised. The table
1490 is a font structure, as explained in \in {chapter} [fonts].
1492 \subsection{Projected next font id}
1494 \startfunctioncall
1495 <number> i = font.nextid()
1496 \stopfunctioncall
1498 This returns the font id number that would be returned by a \type {font.define}
1499 call if it was executed at this spot in the code flow. This is useful for virtual
1500 fonts that need to reference themselves.
1502 \subsection{Font id}
1504 \startfunctioncall
1505 <number> i = font.id(<string> csname)
1506 \stopfunctioncall
1508 This returns the font id associated with \type {csname} string, or $-1$ if \type
1509 {csname} is not defined.
1511 \subsection{Currently active font}
1513 \startfunctioncall
1514 <number> i = font.current()
1515 font.current(<number> i)
1516 \stopfunctioncall
1518 This gets or sets the currently used font number.
1520 \subsection{Maximum font id}
1522 \startfunctioncall
1523 <number> i = font.max()
1524 \stopfunctioncall
1526 This is the largest used index in \type {font.fonts}.
1528 \subsection{Iterating over all fonts}
1530 \startfunctioncall
1531 for i,v in font.each() do
1534 \stopfunctioncall
1536 This is an iterator over each of the defined \TEX\ fonts. The first returned
1537 value is the index in \type {font.fonts}, the second the font itself, as a \LUA\
1538 table. The indices are listed incrementally, but they do not always form an array
1539 of consecutive numbers: in some cases there can be holes in the sequence.
1541 \section{The \type {fontloader} library}
1543 \subsection{Getting quick information on a font}
1545 \startfunctioncall
1546 <table> info = fontloader.info(<string> filename)
1547 \stopfunctioncall
1549 This function returns either \type {nil}, or a \type {table}, or an array of
1550 small tables (in the case of a \TRUETYPE\ collection). The returned table(s) will
1551 contain some fairly interesting information items from the font(s) defined by the
1552 file:
1554 \starttabulate[|lT|l|p|]
1555 \NC \ssbf key \NC \bf type \NC \bf explanation \NC \NR
1556 \NC fontname \NC string \NC the \POSTSCRIPT\ name of the font\NC \NR
1557 \NC fullname \NC string \NC the formal name of the font\NC \NR
1558 \NC familyname \NC string \NC the family name this font belongs to\NC \NR
1559 \NC weight \NC string \NC a string indicating the color value of the font\NC \NR
1560 \NC version \NC string \NC the internal font version\NC \NR
1561 \NC italicangle \NC float \NC the slant angle\NC \NR
1562 \NC units_per_em \NC number \NC 1000 for \POSTSCRIPT-based fonts, usually 2048 for \TRUETYPE\NC \NR
1563 \NC pfminfo \NC table \NC (see \in{section}[fontloaderpfminfotable])\NC \NR
1564 \stoptabulate
1566 Getting information through this function is (sometimes much) more efficient than
1567 loading the font properly, and is therefore handy when you want to create a
1568 dictionary of available fonts based on a directory contents.
1570 \subsection{Loading an \OPENTYPE\ or \TRUETYPE\ file}
1571 If you want to use an \OPENTYPE\ font, you have to get the metric information
1572 from somewhere. Using the \type {fontloader} library, the simplest way to get
1573 that information is thus:
1575 \starttyping
1576 function load_font (filename)
1577 local metrics = nil
1578 local font = fontloader.open(filename)
1579 if font then
1580 metrics = fontloader.to_table(font)
1581 fontloader.close(font)
1583 return metrics
1586 myfont = load_font('/opt/tex/texmf/fonts/data/arial.ttf')
1587 \stoptyping
1589 The main function call is
1591 \startfunctioncall
1592 <userdata> f, <table> w = fontloader.open(<string> filename)
1593 <userdata> f, <table> w = fontloader.open(<string> filename, <string> fontname)
1594 \stopfunctioncall
1596 The first return value is a userdata representation of the font. The second
1597 return value is a table containing any warnings and errors reported by fontloader
1598 while opening the font. In normal typesetting, you would probably ignore the
1599 second argument, but it can be useful for debugging purposes.
1601 For \TRUETYPE\ collections (when filename ends in 'ttc') and \DFONT\ collections,
1602 you have to use a second string argument to specify which font you want from the
1603 collection. Use the \type {fontname} strings that are returned by \type
1604 {fontloader.info} for that.
1606 To turn the font into a table, \type {fontloader.to_table} is used on the font
1607 returned by \type {fontloader.open}.
1609 \startfunctioncall
1610 <table> f = fontloader.to_table(<userdata> font)
1611 \stopfunctioncall
1613 This table cannot be used directly by \LUATEX\ and should be turned into another
1614 one as described in~\in {chapter} [fonts]. Do not forget to store the \type
1615 {fontname} value in the \type {psname} field of the metrics table to be returned
1616 to \LUATEX, otherwise the font inclusion backend will not be able to find the
1617 correct font in the collection.
1619 See \in {section} [fontloadertables] for details on the userdata object returned
1620 by \type {fontloader.open()} and the layout of the \type {metrics} table returned
1621 by \type {fontloader.to_table()}.
1623 The font file is parsed and partially interpreted by the font loading routines
1624 from \FONTFORGE. The file format can be \OPENTYPE, \TRUETYPE, \TRUETYPE\
1625 Collection, \CFF, or \TYPEONE.
1627 There are a few advantages to this approach compared to reading the actual font
1628 file ourselves:
1630 \startitemize
1632 \startitem
1633 The font is automatically re|-|encoded, so that the \type {metrics} table for
1634 \TRUETYPE\ and \OPENTYPE\ fonts is using \UNICODE\ for the character indices.
1635 \stopitem
1637 \startitem
1638 Many features are pre|-|processed into a format that is easier to handle than
1639 just the bare tables would be.
1640 \stopitem
1642 \startitem
1643 \POSTSCRIPT|-|based \OPENTYPE\ fonts do not store the character height and
1644 depth in the font file, so the character boundingbox has to be calculated in
1645 some way.
1646 \stopitem
1648 \startitem
1649 In the future, it may be interesting to allow \LUA\ scripts access to
1650 the font program itself, perhaps even creating or changing the font.
1651 \stopitem
1653 \stopitemize
1655 A loaded font is discarded with:
1657 \startfunctioncall
1658 fontloader.close(<userdata> font)
1659 \stopfunctioncall
1661 \subsection{Applying a \quote{feature file}}
1663 You can apply a \quote{feature file} to a loaded font:
1665 \startfunctioncall
1666 <table> errors = fontloader.apply_featurefile(<userdata> font, <string> filename)
1667 \stopfunctioncall
1669 A \quote {feature file} is a textual representation of the features in an
1670 \OPENTYPE\ font. See
1672 \starttyping
1673 http://www.adobe.com/devnet/opentype/afdko/topic_feature_file_syntax.html
1674 \stoptyping
1678 \starttyping
1679 http://fontforge.sourceforge.net/featurefile.html
1680 \stoptyping
1682 for a more detailed description of feature files.
1684 If the function fails, the return value is a table containing any errors reported
1685 by fontloader while applying the feature file. On success, \type {nil} is
1686 returned.
1688 \subsection{Applying an \quote{\AFM\ file}}
1690 You can apply an \quote {\AFM\ file} to a loaded font:
1692 \startfunctioncall
1693 <table> errors = fontloader.apply_afmfile(<userdata> font, <string> filename)
1694 \stopfunctioncall
1696 An \AFM\ file is a textual representation of (some of) the meta information
1697 in a \TYPEONE\ font. See
1699 \starttyping
1700 ftp://ftp.math.utah.edu/u/ma/hohn/linux/postscript/5004.AFM_Spec.pdf
1701 \stoptyping
1703 for more information about \AFM\ files.
1705 Note: If you \type {fontloader.open()} a \TYPEONE\ file named \type {font.pfb},
1706 the library will automatically search for and apply \type {font.afm} if it exists
1707 in the same directory as the file \type {font.pfb}. In that case, there is no
1708 need for an explicit call to \type {apply_afmfile()}.
1710 If the function fails, the return value is a table containing any errors reported
1711 by fontloader while applying the AFM file. On success, \type {nil} is returned.
1713 \subsection[fontloadertables]{Fontloader font tables}
1715 As mentioned earlier, the return value of \type {fontloader.open()} is a userdata
1716 object. One way to have access to the actual metrics is to call \type
1717 {fontloader.to_table()} on this object, returning the table structure that is
1718 explained in the following subsections.
1720 However, it turns out that the result from \type {fontloader.to_table()}
1721 sometimes needs very large amounts of memory (depending on the font's complexity
1722 and size) so it is possible to access the userdata object directly.
1724 \startitemize
1725 \startitem
1726 All top|-|level keys that would be returned by \type {to_table()}
1727 can also be accessed directly.
1728 \stopitem
1729 \startitem
1730 \startitem
1731 The top|-|level key \quote {glyphs} returns a {\it virtual\/} array that
1732 allows indices from \type {f.glyphmin} to (\type {f.glyphmax}).
1733 \stopitem
1734 \startitem
1735 The items in that virtual array (the actual glyphs) are themselves also
1736 userdata objects, and each has accessors for all of the keys explained in the
1737 section \quote {Glyph items} below.
1738 \stopitem
1739 The top|-|level key \quote {subfonts} returns an {\it actual} array of userdata
1740 objects, one for each of the subfonts (or nil, if there are no subfonts).
1741 \stopitem
1742 \stopitemize
1744 A short example may be helpful. This code generates a printout of all
1745 the glyph names in the font \type {PunkNova.kern.otf}:
1747 \starttyping
1748 local f = fontloader.open('PunkNova.kern.otf')
1749 print (f.fontname)
1750 local i = 0
1751 if f.glyphcnt > 0 then
1752 for i=f.glyphmin,f.glyphmax do
1753 local g = f.glyphs[i]
1754 if g then
1755 print(g.name)
1757 i = i + 1
1760 fontloader.close(f)
1761 \stoptyping
1763 In this case, the \LUATEX\ memory requirement stays below 100MB on the test
1764 computer, while the internal structure generated by \type {to_table()} needs more
1765 than 2GB of memory (the font itself is 6.9MB in disk size).
1767 Only the top|-|level font, the subfont table entries, and the glyphs are virtual
1768 objects, everything else still produces normal \LUA\ values and tables.
1770 If you want to know the valid fields in a font or glyph structure, call the \type
1771 {fields} function on an object of a particular type (either glyph or font):
1773 \startfunctioncall
1774 <table> fields = fontloader.fields(<userdata> font)
1775 <table> fields = fontloader.fields(<userdata> font_glyph)
1776 \stopfunctioncall
1778 For instance:
1780 \startfunctioncall
1781 local fields = fontloader.fields(f)
1782 local fields = fontloader.fields(f.glyphs[0])
1783 \stopfunctioncall
1785 \subsubsection{Table types}
1787 \subsubsubsection{Top-level}
1789 The top|-|level keys in the returned table are (the explanations in this part of
1790 the documentation are not yet finished):
1792 \starttabulate[|lT|l|p|]
1793 \NC \ssbf key \NC \bf type \NC \bf explanation \NC \NR
1794 \NC table_version \NC number \NC indicates the metrics version (currently~0.3)\NC \NR
1795 \NC fontname \NC string \NC \POSTSCRIPT\ font name\NC \NR
1796 \NC fullname \NC string \NC official (human-oriented) font name\NC \NR
1797 \NC familyname \NC string \NC family name\NC \NR
1798 \NC weight \NC string \NC weight indicator\NC \NR
1799 \NC copyright \NC string \NC copyright information\NC \NR
1800 \NC filename \NC string \NC the file name\NC \NR
1801 \NC version \NC string \NC font version\NC \NR
1802 \NC italicangle \NC float \NC slant angle\NC \NR
1803 \NC units_per_em \NC number \NC 1000 for \POSTSCRIPT-based fonts, usually 2048 for \TRUETYPE\NC \NR
1804 \NC ascent \NC number \NC height of ascender in \type {units_per_em}\NC \NR
1805 \NC descent \NC number \NC depth of descender in \type {units_per_em}\NC \NR
1806 \NC upos \NC float \NC \NC \NR
1807 \NC uwidth \NC float \NC \NC \NR
1808 \NC uniqueid \NC number \NC \NC \NR
1809 \NC glyphs \NC array \NC \NC \NR
1810 \NC glyphcnt \NC number \NC number of included glyphs\NC \NR
1811 \NC glyphmax \NC number \NC maximum used index the glyphs array\NC \NR
1812 \NC glyphmin \NC number \NC minimum used index the glyphs array\NC \NR
1813 \NC notdef_loc \NC number \NC location of the \type {.notdef} glyph
1814 or \type {-1} when not present \NC \NR
1815 \NC hasvmetrics \NC number \NC \NC \NR
1816 \NC onlybitmaps \NC number \NC \NC \NR
1817 \NC serifcheck \NC number \NC \NC \NR
1818 \NC isserif \NC number \NC \NC \NR
1819 \NC issans \NC number \NC \NC \NR
1820 \NC encodingchanged \NC number \NC \NC \NR
1821 \NC strokedfont \NC number \NC \NC \NR
1822 \NC use_typo_metrics \NC number \NC \NC \NR
1823 \NC weight_width_slope_only \NC number \NC \NC \NR
1824 \NC head_optimized_for_cleartype \NC number \NC \NC \NR
1825 \NC uni_interp \NC enum \NC \type {unset}, \type {none}, \type {adobe},
1826 \type {greek}, \type {japanese}, \type {trad_chinese},
1827 \type {simp_chinese}, \type {korean}, \type {ams}\NC \NR
1828 \NC origname \NC string \NC the file name, as supplied by the user\NC \NR
1829 \NC map \NC table \NC \NC \NR
1830 \NC private \NC table \NC \NC \NR
1831 \NC xuid \NC string \NC \NC \NR
1832 \NC pfminfo \NC table \NC \NC \NR
1833 \NC names \NC table \NC \NC \NR
1834 \NC cidinfo \NC table \NC \NC \NR
1835 \NC subfonts \NC array \NC \NC \NR
1836 \NC commments \NC string \NC \NC \NR
1837 \NC fontlog \NC string \NC \NC \NR
1838 \NC cvt_names \NC string \NC \NC \NR
1839 \NC anchor_classes \NC table \NC \NC \NR
1840 \NC ttf_tables \NC table \NC \NC \NR
1841 \NC ttf_tab_saved \NC table \NC \NC \NR
1842 \NC kerns \NC table \NC \NC \NR
1843 \NC vkerns \NC table \NC \NC \NR
1844 \NC texdata \NC table \NC \NC \NR
1845 \NC lookups \NC table \NC \NC \NR
1846 \NC gpos \NC table \NC \NC \NR
1847 \NC gsub \NC table \NC \NC \NR
1848 \NC mm \NC table \NC \NC \NR
1849 \NC chosenname \NC string \NC \NC \NR
1850 \NC macstyle \NC number \NC \NC \NR
1851 \NC fondname \NC string \NC \NC \NR
1852 %NC design_size \NC number \NC \NC \NR
1853 \NC fontstyle_id \NC number \NC \NC \NR
1854 \NC fontstyle_name \NC table \NC \NC \NR
1855 %NC design_range_bottom \NC number \NC \NC \NR
1856 %NC design_range_top \NC number \NC \NC \NR
1857 \NC strokewidth \NC float \NC \NC \NR
1858 \NC mark_classes \NC table \NC \NC \NR
1859 \NC creationtime \NC number \NC \NC \NR
1860 \NC modificationtime \NC number \NC \NC \NR
1861 \NC os2_version \NC number \NC \NC \NR
1862 \NC sfd_version \NC number \NC \NC \NR
1863 \NC math \NC table \NC \NC \NR
1864 \NC validation_state \NC table \NC \NC \NR
1865 \NC horiz_base \NC table \NC \NC \NR
1866 \NC vert_base \NC table \NC \NC \NR
1867 \NC extrema_bound \NC number \NC \NC \NR
1868 \NC truetype \NC boolean \NC signals a \TRUETYPE\ font \NC \NR
1869 \stoptabulate
1871 \subsubsubsection{Glyph items}
1873 The \type {glyphs} is an array containing the per|-|character
1874 information (quite a few of these are only present if nonzero).
1876 \starttabulate[|lT|l|p|]
1877 \NC \ssbf key \NC \bf type \NC \bf explanation \NC \NR
1878 \NC name \NC string \NC the glyph name \NC \NR
1879 \NC unicode \NC number \NC unicode code point, or -1 \NC \NR
1880 \NC boundingbox \NC array \NC array of four numbers, see note below \NC \NR
1881 \NC width \NC number \NC only for horizontal fonts \NC \NR
1882 \NC vwidth \NC number \NC only for vertical fonts \NC \NR
1883 \NC tsidebearing \NC number \NC only for vertical ttf/otf fonts, and only if nonzero \NC \NR
1884 \NC lsidebearing \NC number \NC only if nonzero and not equal to boundingbox[1] \NC \NR
1885 \NC class \NC string \NC one of "none", "base", "ligature", "mark", "component"
1886 (if not present, the glyph class is \quote {automatic}) \NC \NR
1887 \NC kerns \NC array \NC only for horizontal fonts, if set \NC \NR
1888 \NC vkerns \NC array \NC only for vertical fonts, if set \NC \NR
1889 \NC dependents \NC array \NC linear array of glyph name strings, only if nonempty\NC \NR
1890 \NC lookups \NC table \NC only if nonempty \NC \NR
1891 \NC ligatures \NC table \NC only if nonempty \NC \NR
1892 \NC anchors \NC table \NC only if set \NC \NR
1893 \NC comment \NC string \NC only if set \NC \NR
1894 \NC tex_height \NC number \NC only if set \NC \NR
1895 \NC tex_depth \NC number \NC only if set \NC \NR
1896 \NC italic_correction \NC number \NC only if set \NC \NR
1897 \NC top_accent \NC number \NC only if set \NC \NR
1898 \NC is_extended_shape \NC number \NC only if this character is part of a math extension list \NC \NR
1899 \NC altuni \NC table \NC alternate \UNICODE\ items \NC \NR
1900 \NC vert_variants \NC table \NC \NC \NR
1901 \NC horiz_variants \NC table \NC \NC \NR
1902 \NC mathkern \NC table \NC \NC \NR
1903 \stoptabulate
1905 On \type {boundingbox}: The boundingbox information for \TRUETYPE\ fonts and
1906 \TRUETYPE-based \OTF\ fonts is read directly from the font file.
1907 \POSTSCRIPT-based fonts do not have this information, so the boundingbox of
1908 traditional \POSTSCRIPT\ fonts is generated by interpreting the actual bezier
1909 curves to find the exact boundingbox. This can be a slow process, so the
1910 boundingboxes of \POSTSCRIPT-based \OTF\ fonts (and raw \CFF\ fonts) are
1911 calculated using an approximation of the glyph shape based on the actual glyph
1912 points only, instead of taking the whole curve into account. This means that
1913 glyphs that have missing points at extrema will have a too|-|tight boundingbox,
1914 but the processing is so much faster that in our opinion the tradeoff is worth
1917 The \type {kerns} and \type {vkerns} are linear arrays of small hashes:
1919 \starttabulate[|lT|l|p|]
1920 \NC \ssbf key \NC \bf type \NC \bf explanation \NC \NR
1921 \NC char \NC string \NC \NC \NR
1922 \NC off \NC number \NC \NC \NR
1923 \NC lookup \NC string \NC \NC \NR
1924 \stoptabulate
1926 The \type {lookups} is a hash, based on lookup subtable names, with
1927 the value of each key inside that a linear array of small hashes:
1929 % TODO: fix this description
1930 \starttabulate[|lT|l|p|]
1931 \NC \ssbf key \NC \bf type \NC \bf explanation \NC \NR
1932 \NC type \NC enum \NC \type {position}, \type {pair}, \type
1933 {substitution}, \type {alternate}, \type
1934 {multiple}, \type {ligature}, \type {lcaret},
1935 \type {kerning}, \type {vkerning}, \type
1936 {anchors}, \type {contextpos}, \type
1937 {contextsub}, \type {chainpos}, \type
1938 {chainsub}, \type {reversesub}, \type {max},
1939 \type {kernback}, \type {vkernback} \NC \NR
1940 \NC specification \NC table \NC extra data \NC \NR
1941 \stoptabulate
1943 For the first seven values of \type {type}, there can be additional
1944 sub|-|information, stored in the sub-table \type {specification}:
1946 \starttabulate[|lT|l|p|]
1947 \NC \ssbf value \NC \bf type \NC \bf explanation \NC \NR
1948 \NC position \NC table \NC a table of the \type {offset_specs} type \NC \NR
1949 \NC pair \NC table \NC one string: \type {paired}, and an array of one
1950 or two \type {offset_specs} tables: \type
1951 {offsets} \NC \NR
1952 \NC substitution \NC table \NC one string: \type {variant} \NC \NR
1953 \NC alternate \NC table \NC one string: \type {components} \NC \NR
1954 \NC multiple \NC table \NC one string: \type {components} \NC \NR
1955 \NC ligature \NC table \NC two strings: \type {components}, \type {char} \NC \NR
1956 \NC lcaret \NC array \NC linear array of numbers \NC \NR
1957 \stoptabulate
1959 Tables for \type {offset_specs} contain up to four number|-|valued fields: \type
1960 {x} (a horizontal offset), \type {y} (a vertical offset), \type {h} (an advance
1961 width correction) and \type {v} (an advance height correction).
1963 The \type {ligatures} is a linear array of small hashes:
1965 \starttabulate[|lT|l|p|]
1966 \NC \ssbf key \NC \bf type \NC \bf explanation \NC \NR
1967 \NC lig \NC table \NC uses the same substructure as a single item in
1968 the \type {lookups} table explained above \NC \NR
1969 \NC char \NC string \NC \NC \NR
1970 \NC components \NC array \NC linear array of named components \NC \NR
1971 \NC ccnt \NC number \NC \NC \NR
1972 \stoptabulate
1974 The \type {anchor} table is indexed by a string signifying the anchor type, which
1975 is one of
1977 \starttabulate[|lT|l|p|]
1978 \NC \ssbf key \NC \bf type \NC \bf explanation \NC \NR
1979 \NC mark \NC table \NC placement mark \NC \NR
1980 \NC basechar \NC table \NC mark for attaching combining items to a base char \NC \NR
1981 \NC baselig \NC table \NC mark for attaching combining items to a ligature \NC \NR
1982 \NC basemark \NC table \NC generic mark for attaching combining items to connect to \NC \NR
1983 \NC centry \NC table \NC cursive entry point \NC \NR
1984 \NC cexit \NC table \NC cursive exit point \NC \NR
1985 \stoptabulate
1987 The content of these is a short array of defined anchors, with the
1988 entry keys being the anchor names. For all except \type {baselig}, the
1989 value is a single table with this definition:
1991 \starttabulate[|lT|l|p|]
1992 \NC \ssbf key \NC \bf type \NC \bf explanation \NC \NR
1993 \NC x \NC number \NC x location \NC \NR
1994 \NC y \NC number \NC y location \NC \NR
1995 \NC ttf_pt_index \NC number \NC truetype point index, only if given \NC \NR
1996 \stoptabulate
1998 For \type {baselig}, the value is a small array of such anchor sets sets, one for
1999 each constituent item of the ligature.
2001 For clarification, an anchor table could for example look like this :
2003 \starttyping
2004 ['anchor'] = {
2005 ['basemark'] = {
2006 ['Anchor-7'] = { ['x']=170, ['y']=1080 }
2008 ['mark'] ={
2009 ['Anchor-1'] = { ['x']=160, ['y']=810 },
2010 ['Anchor-4'] = { ['x']=160, ['y']=800 }
2012 ['baselig'] = {
2013 [1] = { ['Anchor-2'] = { ['x']=160, ['y']=650 } },
2014 [2] = { ['Anchor-2'] = { ['x']=460, ['y']=640 } }
2017 \stoptyping
2019 Note: The \type {baselig} table can be sparse!
2021 \subsubsubsection{map table}
2023 The top|-|level map is a list of encoding mappings. Each of those is a table
2024 itself.
2026 \starttabulate[|lT|l|p|]
2027 \NC \ssbf key \NC \bf type \NC \bf explanation \NC \NR
2028 \NC enccount \NC number \NC \NC \NR
2029 \NC encmax \NC number \NC \NC \NR
2030 \NC backmax \NC number \NC \NC \NR
2031 \NC remap \NC table \NC \NC \NR
2032 \NC map \NC array \NC non|-|linear array of mappings\NC \NR
2033 \NC backmap \NC array \NC non|-|linear array of backward mappings\NC \NR
2034 \NC enc \NC table \NC \NC \NR
2035 \stoptabulate
2037 The \type {remap} table is very small:
2039 \starttabulate[|lT|l|p|]
2040 \NC \ssbf key \NC \bf type \NC \bf explanation \NC \NR
2041 \NC firstenc \NC number \NC \NC \NR
2042 \NC lastenc \NC number \NC \NC \NR
2043 \NC infont \NC number \NC \NC \NR
2044 \stoptabulate
2046 The \type {enc} table is a bit more verbose:
2048 \starttabulate[|lT|l|p|]
2049 \NC \ssbf key \NC \bf type \NC \bf explanation \NC \NR
2050 \NC enc_name \NC string \NC \NC \NR
2051 \NC char_cnt \NC number \NC \NC \NR
2052 \NC char_max \NC number \NC \NC \NR
2053 \NC unicode \NC array \NC of \UNICODE\ position numbers\NC \NR
2054 \NC psnames \NC array \NC of \POSTSCRIPT\ glyph names\NC \NR
2055 \NC builtin \NC number \NC \NC \NR
2056 \NC hidden \NC number \NC \NC \NR
2057 \NC only_1byte \NC number \NC \NC \NR
2058 \NC has_1byte \NC number \NC \NC \NR
2059 \NC has_2byte \NC number \NC \NC \NR
2060 \NC is_unicodebmp \NC number \NC only if nonzero\NC \NR
2061 \NC is_unicodefull \NC number \NC only if nonzero\NC \NR
2062 \NC is_custom \NC number \NC only if nonzero\NC \NR
2063 \NC is_original \NC number \NC only if nonzero\NC \NR
2064 \NC is_compact \NC number \NC only if nonzero\NC \NR
2065 \NC is_japanese \NC number \NC only if nonzero\NC \NR
2066 \NC is_korean \NC number \NC only if nonzero\NC \NR
2067 \NC is_tradchinese \NC number \NC only if nonzero [name?]\NC \NR
2068 \NC is_simplechinese \NC number \NC only if nonzero\NC \NR
2069 \NC low_page \NC number \NC \NC \NR
2070 \NC high_page \NC number \NC \NC \NR
2071 \NC iconv_name \NC string \NC \NC \NR
2072 \NC iso_2022_escape \NC string \NC \NC \NR
2073 \stoptabulate
2075 \subsubsubsection{private table}
2077 This is the font's private \POSTSCRIPT\ dictionary, if any. Keys and values are
2078 both strings.
2080 \subsubsubsection{cidinfo table}
2082 \starttabulate[|lT|l|p|]
2083 \NC \ssbf key \NC \bf type \NC \bf explanation \NC \NR
2084 \NC registry \NC string \NC \NC \NR
2085 \NC ordering \NC string \NC \NC \NR
2086 \NC supplement \NC number \NC \NC \NR
2087 \NC version \NC number \NC \NC \NR
2088 \stoptabulate
2090 \subsubsubsection[fontloaderpfminfotable]{pfminfo table}
2092 The \type {pfminfo} table contains most of the OS/2 information:
2094 \starttabulate[|lT|l|p|]
2095 \NC \ssbf key \NC \bf type \NC \bf explanation \NC \NR
2096 \NC pfmset \NC number \NC \NC \NR
2097 \NC winascent_add \NC number \NC \NC \NR
2098 \NC windescent_add \NC number \NC \NC \NR
2099 \NC hheadascent_add \NC number \NC \NC \NR
2100 \NC hheaddescent_add \NC number \NC \NC \NR
2101 \NC typoascent_add \NC number \NC \NC \NR
2102 \NC typodescent_add \NC number \NC \NC \NR
2103 \NC subsuper_set \NC number \NC \NC \NR
2104 \NC panose_set \NC number \NC \NC \NR
2105 \NC hheadset \NC number \NC \NC \NR
2106 \NC vheadset \NC number \NC \NC \NR
2107 \NC pfmfamily \NC number \NC \NC \NR
2108 \NC weight \NC number \NC \NC \NR
2109 \NC width \NC number \NC \NC \NR
2110 \NC avgwidth \NC number \NC \NC \NR
2111 \NC firstchar \NC number \NC \NC \NR
2112 \NC lastchar \NC number \NC \NC \NR
2113 \NC fstype \NC number \NC \NC \NR
2114 \NC linegap \NC number \NC \NC \NR
2115 \NC vlinegap \NC number \NC \NC \NR
2116 \NC hhead_ascent \NC number \NC \NC \NR
2117 \NC hhead_descent \NC number \NC \NC \NR
2118 \NC os2_typoascent \NC number \NC \NC \NR
2119 \NC os2_typodescent \NC number \NC \NC \NR
2120 \NC os2_typolinegap \NC number \NC \NC \NR
2121 \NC os2_winascent \NC number \NC \NC \NR
2122 \NC os2_windescent \NC number \NC \NC \NR
2123 \NC os2_subxsize \NC number \NC \NC \NR
2124 \NC os2_subysize \NC number \NC \NC \NR
2125 \NC os2_subxoff \NC number \NC \NC \NR
2126 \NC os2_subyoff \NC number \NC \NC \NR
2127 \NC os2_supxsize \NC number \NC \NC \NR
2128 \NC os2_supysize \NC number \NC \NC \NR
2129 \NC os2_supxoff \NC number \NC \NC \NR
2130 \NC os2_supyoff \NC number \NC \NC \NR
2131 \NC os2_strikeysize \NC number \NC \NC \NR
2132 \NC os2_strikeypos \NC number \NC \NC \NR
2133 \NC os2_family_class \NC number \NC \NC \NR
2134 \NC os2_xheight \NC number \NC \NC \NR
2135 \NC os2_capheight \NC number \NC \NC \NR
2136 \NC os2_defaultchar \NC number \NC \NC \NR
2137 \NC os2_breakchar \NC number \NC \NC \NR
2138 \NC os2_vendor \NC string \NC \NC \NR
2139 \NC codepages \NC table \NC A two-number array of encoded code pages\NC \NR
2140 \NC unicoderages \NC table \NC A four-number array of encoded unicode ranges\NC \NR
2141 \NC panose \NC table \NC \NC \NR
2142 \stoptabulate
2144 The \type {panose} subtable has exactly 10 string keys:
2146 \starttabulate[|lT|l|p|]
2147 \NC \ssbf key \NC \bf type \NC \bf explanation \NC \NR
2148 \NC familytype \NC string \NC Values as in the \OPENTYPE\ font
2149 specification: \type {Any}, \type {No Fit},
2150 \type {Text and Display}, \type {Script},
2151 \type {Decorative}, \type {Pictorial} \NC
2153 \NC serifstyle \NC string \NC See the \OPENTYPE\ font specification for
2154 values \NC \NR
2155 \NC weight \NC string \NC id. \NC \NR
2156 \NC proportion \NC string \NC id. \NC \NR
2157 \NC contrast \NC string \NC id. \NC \NR
2158 \NC strokevariation \NC string \NC id. \NC \NR
2159 \NC armstyle \NC string \NC id. \NC \NR
2160 \NC letterform \NC string \NC id. \NC \NR
2161 \NC midline \NC string \NC id. \NC \NR
2162 \NC xheight \NC string \NC id. \NC \NR
2163 \stoptabulate
2165 \subsubsubsection[fontloadernamestable]{names table}
2167 Each item has two top|-|level keys:
2169 \starttabulate[|lT|l|p|]
2170 \NC \ssbf key \NC \bf type \NC \bf explanation \NC \NR
2171 \NC lang \NC string \NC language for this entry \NC \NR
2172 \NC names \NC table \NC \NC \NR
2173 \stoptabulate
2175 The \type {names} keys are the actual \TRUETYPE\ name strings. The possible keys
2176 are:
2178 \starttabulate[|lT|p|]
2179 \NC \ssbf key \NC \bf explanation \NC \NR
2180 \NC copyright \NC \NC \NR
2181 \NC family \NC \NC \NR
2182 \NC subfamily \NC \NC \NR
2183 \NC uniqueid \NC \NC \NR
2184 \NC fullname \NC \NC \NR
2185 \NC version \NC \NC \NR
2186 \NC postscriptname \NC \NC \NR
2187 \NC trademark \NC \NC \NR
2188 \NC manufacturer \NC \NC \NR
2189 \NC designer \NC \NC \NR
2190 \NC descriptor \NC \NC \NR
2191 \NC venderurl \NC \NC \NR
2192 \NC designerurl \NC \NC \NR
2193 \NC license \NC \NC \NR
2194 \NC licenseurl \NC \NC \NR
2195 \NC idontknow \NC \NC \NR
2196 \NC preffamilyname \NC \NC \NR
2197 \NC prefmodifiers \NC \NC \NR
2198 \NC compatfull \NC \NC \NR
2199 \NC sampletext \NC \NC \NR
2200 \NC cidfindfontname \NC \NC \NR
2201 \NC wwsfamily \NC \NC \NR
2202 \NC wwssubfamily \NC \NC \NR
2203 \stoptabulate
2205 \subsubsubsection{anchor_classes table}
2207 The anchor_classes classes:
2209 \starttabulate[|lT|l|p|]
2210 \NC \ssbf key \NC \bf type \NC \bf explanation \NC \NR
2211 \NC name \NC string \NC a descriptive id of this anchor class\NC \NR
2212 \NC lookup \NC string \NC \NC \NR
2213 \NC type \NC string \NC one of \type {mark}, \type {mkmk}, \type {curs}, \type {mklg} \NC \NR
2214 \stoptabulate
2216 % type is actually a lookup subtype, not a feature name. Officially, these
2217 % strings should be gpos_mark2mark etc.
2219 \subsubsubsection{gpos table}
2221 The \type {gpos} table has one array entry for each lookup. (The \type {gpos_}
2222 prefix is somewhat redundant.)
2224 \starttabulate[|lT|l|p|]
2225 \NC \ssbf key \NC \bf type \NC \bf explanation \NC \NR
2226 \NC type \NC string \NC one of \type {gpos_single}, \type {gpos_pair},
2227 \type {gpos_cursive}, \type {gpos_mark2base},\crlf
2228 \type {gpos_mark2ligature}, \type
2229 {gpos_mark2mark}, \type {gpos_context},\crlf \type
2230 {gpos_contextchain} \NC \NR
2231 \NC flags \NC table \NC \NC \NR
2232 \NC name \NC string \NC \NC \NR
2233 \NC features \NC array \NC \NC \NR
2234 \NC subtables \NC array \NC \NC \NR
2235 \stoptabulate
2237 The flags table has a true value for each of the lookup flags that is actually
2238 set:
2240 \starttabulate[|lT|l|p|]
2241 \NC \ssbf key \NC \bf type \NC \bf explanation \NC \NR
2242 \NC r2l \NC boolean \NC \NC \NR
2243 \NC ignorebaseglyphs \NC boolean \NC \NC \NR
2244 \NC ignoreligatures \NC boolean \NC \NC \NR
2245 \NC ignorecombiningmarks \NC boolean \NC \NC \NR
2246 \NC mark_class \NC string \NC \NC \NR
2247 \stoptabulate
2249 The features subtable items of gpos have:
2251 \starttabulate[|lT|l|p|]
2252 \NC \ssbf key \NC \bf type \NC \bf explanation \NC \NR
2253 \NC tag \NC string \NC \NC \NR
2254 \NC scripts \NC table \NC \NC \NR
2255 \stoptabulate
2257 The scripts table within features has:
2259 \starttabulate[|lT|l|p|]
2260 \NC \ssbf key \NC \bf type \NC \bf explanation \NC \NR
2261 \NC script \NC string \NC \NC \NR
2262 \NC langs \NC array of strings \NC \NC \NR
2263 \stoptabulate
2265 The subtables table has:
2267 \starttabulate[|lT|l|p|]
2268 \NC \ssbf key \NC \bf type \NC \bf explanation \NC \NR
2269 \NC name \NC string \NC \NC \NR
2270 \NC suffix \NC string \NC (only if used)\NC \NR % used by gpos_single to get a default
2271 \NC anchor_classes \NC number \NC (only if used)\NC \NR
2272 \NC vertical_kerning \NC number \NC (only if used)\NC \NR
2273 \NC kernclass \NC table \NC (only if used)\NC \NR
2274 \stoptabulate
2276 The kernclass with subtables table has:
2278 \starttabulate[|lT|l|p|]
2279 \NC \ssbf key \NC \bf type \NC \bf explanation \NC \NR
2280 \NC firsts \NC array of strings \NC \NC \NR
2281 \NC seconds \NC array of strings \NC \NC \NR
2282 \NC lookup \NC string or array \NC associated lookup(s) \NC \NR
2283 \NC offsets \NC array of numbers \NC \NC \NR
2284 \stoptabulate
2286 Note: the kernclass (as far as we can see) always has one entry so it could be one level
2287 deep instead. Also the seconds start at \type {[2]} which is close to the fontforge
2288 internals so we keep that too.
2290 \subsubsubsection{gsub table}
2292 This has identical layout to the \type {gpos} table, except for the
2293 type:
2295 \starttabulate[|lT|l|p|]
2296 \NC \ssbf key \NC \bf type \NC \bf explanation \NC \NR
2297 \NC type \NC string \NC one of \type {gsub_single}, \type {gsub_multiple},
2298 \type {gsub_alternate}, \type
2299 {gsub_ligature},\crlf \type {gsub_context}, \type
2300 {gsub_contextchain}, \type
2301 {gsub_reversecontextchain} \NC \NR
2302 \stoptabulate
2304 \subsubsubsection{ttf_tables and ttf_tab_saved tables}
2306 \starttabulate[|lT|l|p|]
2307 \NC \ssbf key \NC \bf type \NC \bf explanation \NC \NR
2308 \NC tag \NC string \NC \NC \NR
2309 \NC len \NC number \NC \NC \NR
2310 \NC maxlen \NC number \NC \NC \NR
2311 \NC data \NC number \NC \NC \NR
2312 \stoptabulate
2314 \subsubsubsection{mm table}
2316 \starttabulate[|lT|l|p|]
2317 \NC \ssbf key \NC \bf type \NC \bf explanation \NC \NR
2318 \NC axes \NC table \NC array of axis names \NC \NR
2319 \NC instance_count \NC number \NC \NC \NR
2320 \NC positions \NC table \NC array of instance positions
2321 (\#axes * instances )\NC \NR
2322 \NC defweights \NC table \NC array of default weights for instances \NC \NR
2323 \NC cdv \NC string \NC \NC \NR
2324 \NC ndv \NC string \NC \NC \NR
2325 \NC axismaps \NC table \NC \NC \NR
2326 \stoptabulate
2328 The \type {axismaps}:
2330 \starttabulate[|lT|l|p|]
2331 \NC \ssbf key \NC \bf type \NC \bf explanation \NC \NR
2332 \NC blends \NC table \NC an array of blend points \NC \NR
2333 \NC designs \NC table \NC an array of design values \NC \NR
2334 \NC min \NC number \NC \NC \NR
2335 \NC def \NC number \NC \NC \NR
2336 \NC max \NC number \NC \NC \NR
2337 \stoptabulate
2339 \subsubsubsection{mark_classes table}
2341 The keys in this table are mark class names, and the values are a
2342 space|-|separated string of glyph names in this class.
2344 \subsubsubsection{math table}
2346 \starttabulate[|lT|p|]
2347 \NC ScriptPercentScaleDown \NC \NC \NR
2348 \NC ScriptScriptPercentScaleDown \NC \NC \NR
2349 \NC DelimitedSubFormulaMinHeight \NC \NC \NR
2350 \NC DisplayOperatorMinHeight \NC \NC \NR
2351 \NC MathLeading \NC \NC \NR
2352 \NC AxisHeight \NC \NC \NR
2353 \NC AccentBaseHeight \NC \NC \NR
2354 \NC FlattenedAccentBaseHeight \NC \NC \NR
2355 \NC SubscriptShiftDown \NC \NC \NR
2356 \NC SubscriptTopMax \NC \NC \NR
2357 \NC SubscriptBaselineDropMin \NC \NC \NR
2358 \NC SuperscriptShiftUp \NC \NC \NR
2359 \NC SuperscriptShiftUpCramped \NC \NC \NR
2360 \NC SuperscriptBottomMin \NC \NC \NR
2361 \NC SuperscriptBaselineDropMax \NC \NC \NR
2362 \NC SubSuperscriptGapMin \NC \NC \NR
2363 \NC SuperscriptBottomMaxWithSubscript \NC \NC \NR
2364 \NC SpaceAfterScript \NC \NC \NR
2365 \NC UpperLimitGapMin \NC \NC \NR
2366 \NC UpperLimitBaselineRiseMin \NC \NC \NR
2367 \NC LowerLimitGapMin \NC \NC \NR
2368 \NC LowerLimitBaselineDropMin \NC \NC \NR
2369 \NC StackTopShiftUp \NC \NC \NR
2370 \NC StackTopDisplayStyleShiftUp \NC \NC \NR
2371 \NC StackBottomShiftDown \NC \NC \NR
2372 \NC StackBottomDisplayStyleShiftDown \NC \NC \NR
2373 \NC StackGapMin \NC \NC \NR
2374 \NC StackDisplayStyleGapMin \NC \NC \NR
2375 \NC StretchStackTopShiftUp \NC \NC \NR
2376 \NC StretchStackBottomShiftDown \NC \NC \NR
2377 \NC StretchStackGapAboveMin \NC \NC \NR
2378 \NC StretchStackGapBelowMin \NC \NC \NR
2379 \NC FractionNumeratorShiftUp \NC \NC \NR
2380 \NC FractionNumeratorDisplayStyleShiftUp \NC \NC \NR
2381 \NC FractionDenominatorShiftDown \NC \NC \NR
2382 \NC FractionDenominatorDisplayStyleShiftDown \NC \NC \NR
2383 \NC FractionNumeratorGapMin \NC \NC \NR
2384 \NC FractionNumeratorDisplayStyleGapMin \NC \NC \NR
2385 \NC FractionRuleThickness \NC \NC \NR
2386 \NC FractionDenominatorGapMin \NC \NC \NR
2387 \NC FractionDenominatorDisplayStyleGapMin \NC \NC \NR
2388 \NC SkewedFractionHorizontalGap \NC \NC \NR
2389 \NC SkewedFractionVerticalGap \NC \NC \NR
2390 \NC OverbarVerticalGap \NC \NC \NR
2391 \NC OverbarRuleThickness \NC \NC \NR
2392 \NC OverbarExtraAscender \NC \NC \NR
2393 \NC UnderbarVerticalGap \NC \NC \NR
2394 \NC UnderbarRuleThickness \NC \NC \NR
2395 \NC UnderbarExtraDescender \NC \NC \NR
2396 \NC RadicalVerticalGap \NC \NC \NR
2397 \NC RadicalDisplayStyleVerticalGap \NC \NC \NR
2398 \NC RadicalRuleThickness \NC \NC \NR
2399 \NC RadicalExtraAscender \NC \NC \NR
2400 \NC RadicalKernBeforeDegree \NC \NC \NR
2401 \NC RadicalKernAfterDegree \NC \NC \NR
2402 \NC RadicalDegreeBottomRaisePercent \NC \NC \NR
2403 \NC MinConnectorOverlap \NC \NC \NR
2404 \NC FractionDelimiterSize \NC \NC \NR
2405 \NC FractionDelimiterDisplayStyleSize \NC \NC \NR
2406 \stoptabulate
2408 \subsubsubsection{validation_state table}
2410 \starttabulate[|lT|p|]
2411 \NC \ssbf key \NC \bf explanation \NC \NR
2412 \NC bad_ps_fontname \NC \NC \NR
2413 \NC bad_glyph_table \NC \NC \NR
2414 \NC bad_cff_table \NC \NC \NR
2415 \NC bad_metrics_table \NC \NC \NR
2416 \NC bad_cmap_table \NC \NC \NR
2417 \NC bad_bitmaps_table \NC \NC \NR
2418 \NC bad_gx_table \NC \NC \NR
2419 \NC bad_ot_table \NC \NC \NR
2420 \NC bad_os2_version \NC \NC \NR
2421 \NC bad_sfnt_header \NC \NC \NR
2422 \stoptabulate
2424 \subsubsubsection{horiz_base and vert_base table}
2426 \starttabulate[|lT|l|p|]
2427 \NC \ssbf key \NC \bf type \NC \bf explanation \NC \NR
2428 \NC tags \NC table \NC an array of script list tags\NC \NR
2429 \NC scripts \NC table \NC \NC \NR
2430 \stoptabulate
2432 The \type {scripts} subtable:
2434 \starttabulate[|lT|l|p|]
2435 \NC \ssbf key \NC \bf type \NC \bf explanation \NC \NR
2436 \NC baseline \NC table \NC \NC \NR
2437 \NC default_baseline \NC number \NC \NC \NR
2438 \NC lang \NC table \NC \NC \NR
2439 \stoptabulate
2442 The \type {lang} subtable:
2444 \starttabulate[|lT|l|p|]
2445 \NC \ssbf key \NC \bf type \NC \bf explanation \NC \NR
2446 \NC tag \NC string \NC a script tag \NC \NR
2447 \NC ascent \NC number \NC \NC \NR
2448 \NC descent \NC number \NC \NC \NR
2449 \NC features \NC table \NC \NC \NR
2450 \stoptabulate
2452 The \type {features} points to an array of tables with the same layout except
2453 that in those nested tables, the tag represents a language.
2455 \subsubsubsection{altuni table}
2457 An array of alternate \UNICODE\ values. Inside that array are hashes with:
2459 \starttabulate[|lT|l|p|]
2460 \NC \ssbf key \NC \bf type \NC \bf explanation \NC \NR
2461 \NC unicode \NC number \NC this glyph is also used for this unicode \NC \NR
2462 \NC variant \NC number \NC the alternative is driven by this unicode selector \NC \NR
2463 \stoptabulate
2465 \subsubsubsection{vert_variants and horiz_variants table}
2467 \starttabulate[|lT|l|p|]
2468 \NC \ssbf key \NC \bf type \NC \bf explanation \NC \NR
2469 \NC variants \NC string \NC \NC \NR
2470 \NC italic_correction \NC number \NC \NC \NR
2471 \NC parts \NC table \NC \NC \NR
2472 \stoptabulate
2474 The \type {parts} table is an array of smaller tables:
2476 \starttabulate[|lT|l|p|]
2477 \NC \ssbf key \NC \bf type \NC \bf explanation \NC \NR
2478 \NC component \NC string \NC \NC \NR
2479 \NC extender \NC number \NC \NC \NR
2480 \NC start \NC number \NC \NC \NR
2481 \NC end \NC number \NC \NC \NR
2482 \NC advance \NC number \NC \NC \NR
2483 \stoptabulate
2486 \subsubsubsection{mathkern table}
2488 \starttabulate[|lT|l|p|]
2489 \NC \ssbf key \NC \bf type \NC \bf explanation \NC \NR
2490 \NC top_right \NC table \NC \NC \NR
2491 \NC bottom_right \NC table \NC \NC \NR
2492 \NC top_left \NC table \NC \NC \NR
2493 \NC bottom_left \NC table \NC \NC \NR
2494 \stoptabulate
2496 Each of the subtables is an array of small hashes with two keys:
2498 \starttabulate[|lT|l|p|]
2499 \NC \ssbf key \NC \bf type \NC \bf explanation \NC \NR
2500 \NC height \NC number \NC \NC \NR
2501 \NC kern \NC number \NC \NC \NR
2502 \stoptabulate
2504 \subsubsubsection{kerns table}
2506 Substructure is identical to the per|-|glyph subtable.
2508 \subsubsubsection{vkerns table}
2510 Substructure is identical to the per|-|glyph subtable.
2512 \subsubsubsection{texdata table}
2514 \starttabulate[|lT|l|p|]
2515 \NC \ssbf key \NC \bf type \NC \bf explanation \NC \NR
2516 \NC type \NC string \NC \type {unset}, \type {text}, \type {math}, \type {mathext} \NC \NR
2517 \NC params \NC array \NC 22 font numeric parameters \NC \NR
2518 \stoptabulate
2520 \subsubsubsection{lookups table}
2522 Top|-|level \type {lookups} is quite different from the ones at character level.
2523 The keys in this hash are strings, the values the actual lookups, represented as
2524 dictionary tables.
2526 \starttabulate[|lT|l|p|]
2527 \NC \ssbf key \NC \bf type \NC \bf explanation \NC \NR
2528 \NC type \NC string \NC \NC \NR
2529 \NC format \NC enum \NC one of \type {glyphs}, \type {class}, \type {coverage}, \type {reversecoverage} \NC \NR
2530 \NC tag \NC string \NC \NC \NR
2531 \NC current_class \NC array \NC \NC \NR
2532 \NC before_class \NC array \NC \NC \NR
2533 \NC after_class \NC array \NC \NC \NR
2534 \NC rules \NC array \NC an array of rule items\NC \NR
2535 \stoptabulate
2537 Rule items have one common item and one specialized item:
2539 \starttabulate[|lT|l|p|]
2540 \NC \ssbf key \NC \bf type \NC \bf explanation \NC \NR
2541 \NC lookups \NC array \NC a linear array of lookup names\NC \NR
2542 \NC glyphs \NC array \NC only if the parent's format is \type {glyphs}\NC \NR
2543 \NC class \NC array \NC only if the parent's format is \type {class}\NC \NR
2544 \NC coverage \NC array \NC only if the parent's format is \type {coverage}\NC \NR
2545 \NC reversecoverage \NC array \NC only if the parent's format is \type {reversecoverage}\NC \NR
2546 \stoptabulate
2548 A glyph table is:
2550 \starttabulate[|lT|l|p|]
2551 \NC \ssbf key \NC \bf type \NC \bf explanation \NC \NR
2552 \NC names \NC string \NC \NC \NR
2553 \NC back \NC string \NC \NC \NR
2554 \NC fore \NC string \NC \NC \NR
2555 \stoptabulate
2557 A class table is:
2559 \starttabulate[|lT|l|p|]
2560 \NC \ssbf key \NC \bf type \NC \bf explanation \NC \NR
2561 \NC current \NC array \NC of numbers \NC \NR
2562 \NC before \NC array \NC of numbers \NC \NR
2563 \NC after \NC array \NC of numbers \NC \NR
2564 \stoptabulate
2566 coverage:
2568 \starttabulate[|lT|l|p|]
2569 \NC \ssbf key \NC \bf type \NC \bf explanation \NC \NR
2570 \NC current \NC array \NC of strings \NC \NR
2571 \NC before \NC array \NC of strings\NC \NR
2572 \NC after \NC array \NC of strings \NC \NR
2573 \stoptabulate
2575 reversecoverage:
2577 \starttabulate[|lT|l|p|]
2578 \NC \ssbf key \NC \bf type \NC \bf explanation \NC \NR
2579 \NC current \NC array \NC of strings \NC \NR
2580 \NC before \NC array \NC of strings\NC \NR
2581 \NC after \NC array \NC of strings \NC \NR
2582 \NC replacements \NC string \NC \NC \NR
2583 \stoptabulate
2585 \section{The \type {img} library}
2587 The \type {img} library can be used as an alternative to \type {\pdfximage} and
2588 \type {\pdfrefximage}, and the associated \quote {satellite} commands like \type
2589 {\pdfximagebbox}. Image objects can also be used within virtual fonts via the
2590 \type {image} command listed in~\in {section} [virtualfonts].
2592 \subsection{\type {img.new}}
2594 \startfunctioncall
2595 <image> var = img.new()
2596 <image> var = img.new(<table> image_spec)
2597 \stopfunctioncall
2599 This function creates a userdata object of type \quote {image}. The \type
2600 {image_spec} argument is optional. If it is given, it must be a table, and that
2601 table must contain a \type {filename} key. A number of other keys can also be
2602 useful, these are explained below.
2604 You can either say
2606 \starttyping
2607 a = img.new()
2608 \stoptyping
2610 followed by
2612 \starttyping
2613 a.filename = "foo.png"
2614 \stoptyping
2616 or you can put the file name (and some or all of the other keys) into a table
2617 directly, like so:
2619 \starttyping
2620 a = img.new({filename='foo.pdf', page=1})
2621 \stoptyping
2623 The generated \type {<image>} userdata object allows access to a set of
2624 user|-|specified values as well as a set of values that are normally filled in
2625 and updated automatically by \LUATEX\ itself. Some of those are derived from the
2626 actual image file, others are updated to reflect the \PDF\ output status of the
2627 object.
2629 There is one required user-specified field: the file name (\type {filename}). It
2630 can optionally be augmented by the requested image dimensions (\type {width},
2631 \type {depth}, \type {height}), user|-|specified image attributes (\type {attr}),
2632 the requested \PDF\ page identifier (\type {page}), the requested boundingbox
2633 (\type {pagebox}) for \PDF\ inclusion, the requested color space object (\type
2634 {colorspace}).
2636 The function \type {img.new} does not access the actual image file, it just
2637 creates the \type {<image>} userdata object and initializes some memory
2638 structures. The \type {<image>} object and its internal structures are
2639 automatically garbage collected.
2641 Once the image is scanned, all the values in the \type {<image>} except \type
2642 {width}, \type {height} and \type {depth}, become frozen, and you cannot change
2643 them any more.
2645 You can use \type {pdf.setignoreunknownimages(1)} (or at the \TEX\ end the \type
2646 {\pdfvariable} \type {ignoreunknownimages}) to get around a quit when no known
2647 image type is found (based on name or preamble). Beware: this will not catch
2648 invalid images and we cannot guarantee side effects. A zero dimension image is
2649 still included when requested. No special flags are set. A proper workflow will
2650 not rely in such a catch but make sure that images are valid.
2652 \subsection{\type {img.keys}}
2654 \startfunctioncall
2655 <table> keys = img.keys()
2656 \stopfunctioncall
2658 This function returns a list of all the possible \type {image_spec} keys, both
2659 user-supplied and automatic ones.
2661 % hahe: i need to add r/w ro column...
2662 \starttabulate[|l|l|p|]
2663 \NC \bf field name \NC \bf type \NC description \NC \NR
2664 \NC attr \NC string \NC the image attributes for \LUATEX \NC \NR
2665 \NC bbox \NC table \NC table with 4 boundingbox dimensions
2666 \type {llx}, \type {lly}, \type {urx},
2667 and \type {ury} overruling the \type {pagebox}
2668 entry\NC \NR
2669 \NC colordepth \NC number \NC the number of bits used by the color space\NC \NR
2670 \NC colorspace \NC number \NC the color space object number \NC \NR
2671 \NC depth \NC number \NC the image depth for \LUATEX\
2672 (in scaled points)\NC \NR
2673 \NC filename \NC string \NC the image file name \NC \NR
2674 \NC filepath \NC string \NC the full (expanded) file name of the image\NC \NR
2675 \NC height \NC number \NC the image height for \LUATEX\
2676 (in scaled points)\NC \NR
2677 \NC imagetype \NC string \NC one of \type {pdf}, \type {png}, \type {jpg}, \type {jp2},
2678 \type {jbig2}, or \type {nil} \NC \NR
2679 \NC index \NC number \NC the \PDF\ image name suffix \NC \NR
2680 \NC objnum \NC number \NC the \PDF\ image object number \NC \NR
2681 \NC page \NC ?? \NC the identifier for the requested image page
2682 (type is number or string,
2683 default is the number 1)\NC \NR
2684 \NC pagebox \NC string \NC the requested bounding box, one of
2685 \type {none}, \type {media}, \type {crop},
2686 \type {bleed}, \type {trim}, \type {art} \NC \NR
2687 \NC pages \NC number \NC the total number of available pages \NC \NR
2688 \NC rotation \NC number \NC the image rotation from included \PDF\ file,
2689 in multiples of 90~deg. \NC \NR
2690 \NC stream \NC string \NC the raw stream data for an \type {/Xobject}
2691 \type {/Form} object\NC \NR
2692 \NC transform \NC number \NC the image transform, integer number 0..7\NC \NR
2693 \NC width \NC number \NC the image width for \LUATEX\
2694 (in scaled points)\NC \NR
2695 \NC xres \NC number \NC the horizontal natural image resolution
2696 (in \DPI) \NC \NR
2697 \NC xsize \NC number \NC the natural image width \NC \NR
2698 \NC yres \NC number \NC the vertical natural image resolution
2699 (in \DPI) \NC \NR
2700 \NC ysize \NC number \NC the natural image height \NC \NR
2701 \NC visiblefileame \NC string \NC when set, this name will find its way in the
2702 \PDF\ file as \type {PTEX} specification; when
2703 an empty string is assigned nothing is written
2704 to file, otherwise the natural filename is taken \NC \NR
2705 \stoptabulate
2707 A running (undefined) dimension in \type {width}, \type {height}, or \type
2708 {depth} is represented as \type {nil} in \LUA, so if you want to load an image at
2709 its \quote {natural} size, you do not have to specify any of those three fields.
2711 The \type {stream} parameter allows to fabricate an \type {/XObject} \type
2712 {/Form} object from a string giving the stream contents, e.g., for a filled
2713 rectangle:
2715 \startfunctioncall
2716 a.stream = "0 0 20 10 re f"
2717 \stopfunctioncall
2719 When writing the image, an \type {/Xobject} \type {/Form} object is created, like
2720 with embedded \PDF\ file writing. The object is written out only once. The \type
2721 {stream} key requires that also the \type {bbox} table is given. The \type
2722 {stream} key conflicts with the \type {filename} key. The \type {transform} key
2723 works as usual also with \type {stream}.
2725 The \type {bbox} key needs a table with four boundingbox values, e.g.:
2727 \startfunctioncall
2728 a.bbox = {"30bp", 0, "225bp", "200bp"}
2729 \stopfunctioncall
2731 This replaces and overrules any given \type {pagebox} value; with given \type
2732 {bbox} the box dimensions coming with an embedded \PDF\ file are ignored. The
2733 \type {xsize} and \type {ysize} dimensions are set accordingly, when the image is
2734 scaled. The \type {bbox} parameter is ignored for non-\PDF\ images.
2736 The \type {transform} allows to mirror and rotate the image in steps of 90~deg.
2737 The default value~$0$ gives an unmirrored, unrotated image. Values $1-3$ give
2738 counterclockwise rotation by $90$, $180$, or $270$~degrees, whereas with values
2739 $4-7$ the image is first mirrored and then rotated counterclockwise by $90$,
2740 $180$, or $270$~degrees. The \type {transform} operation gives the same visual
2741 result as if you would externally preprocess the image by a graphics tool and
2742 then use it by \LUATEX. If a \PDF\ file to be embedded already contains a \type
2743 {/Rotate} specification, the rotation result is the combination of the \type
2744 {/Rotate} rotation followed by the \type {transform} operation.
2746 \subsection{\type {img.scan}}
2748 \startfunctioncall
2749 <image> var = img.scan(<image> var)
2750 <image> var = img.scan(<table> image_spec)
2751 \stopfunctioncall
2753 When you say \type {img.scan(a)} for a new image, the file is scanned, and
2754 variables such as \type {xsize}, \type {ysize}, image \type {type}, number of
2755 \type {pages}, and the resolution are extracted. Each of the \type {width}, \type
2756 {height}, \type {depth} fields are set up according to the image dimensions, if
2757 they were not given an explicit value already. An image file will never be
2758 scanned more than once for a given image variable. With all subsequent \type
2759 {img.scan(a)} calls only the dimensions are again set up (if they have been
2760 changed by the user in the meantime).
2762 For ease of use, you can do right-away a
2764 \starttyping
2765 <image> a = img.scan ({ filename = "foo.png" })
2766 \stoptyping
2768 without a prior \type {img.new}.
2770 Nothing is written yet at this point, so you can do \type {a=img.scan}, retrieve
2771 the available info like image width and height, and then throw away \type {a}
2772 again by saying \type {a=nil}. In that case no image object will be reserved in
2773 the PDF, and the used memory will be cleaned up automatically.
2775 \subsection{\type {img.copy}}
2777 \startfunctioncall
2778 <image> var = img.copy(<image> var)
2779 <image> var = img.copy(<table> image_spec)
2780 \stopfunctioncall
2782 If you say \type {a = b}, then both variables point to the same \type {<image>}
2783 object. if you want to write out an image with different sizes, you can do a
2784 \type {b=img.copy(a)}.
2786 Afterwards, \type {a} and \type {b} still reference the same actual image
2787 dictionary, but the dimensions for \type {b} can now be changed from their
2788 initial values that were just copies from \type {a}.
2790 \subsection{\type {img.write}}
2792 \startfunctioncall
2793 <image> var = img.write(<image> var)
2794 <image> var = img.write(<table> image_spec)
2795 \stopfunctioncall
2797 By \type {img.write(a)} a \PDF\ object number is allocated, and a whatsit node of
2798 subtype \type {pdf_refximage} is generated and put into the output list. By this
2799 the image \type {a} is placed into the page stream, and the image file is written
2800 out into an image stream object after the shipping of the current page is
2801 finished.
2803 Again you can do a terse call like
2805 \starttyping
2806 img.write ({ filename = "foo.png" })
2807 \stoptyping
2809 The \type {<image>} variable is returned in case you want it for later
2810 processing.
2812 \subsection{\type {img.immediatewrite}}
2814 \startfunctioncall
2815 <image> var = img.immediatewrite(<image> var)
2816 <image> var = img.immediatewrite(<table> image_spec)
2817 \stopfunctioncall
2819 By \type {img.immediatewrite(a)} a \PDF\ object number is allocated, and the
2820 image file for image \type {a} is written out immediately into the \PDF\ file as
2821 an image stream object (like with \type {\immediate}\type {\pdfximage}). The object
2822 number of the image stream dictionary is then available by the \type {objnum}
2823 key. No \type {pdf_refximage} whatsit node is generated. You will need an
2824 \type {img.write(a)} or \type {img.node(a)} call to let the image appear on the
2825 page, or reference it by another trick; else you will have a dangling image
2826 object in the \PDF\ file.
2828 Also here you can do a terse call like
2830 \starttyping
2831 a = img.immediatewrite ({ filename = "foo.png" })
2832 \stoptyping
2834 The \type {<image>} variable is returned and you will most likely need it.
2836 \subsection{\type {img.node}}
2838 \startfunctioncall
2839 <node> n = img.node(<image> var)
2840 <node> n = img.node(<table> image_spec)
2841 \stopfunctioncall
2843 This function allocates a \PDF\ object number and returns a whatsit node of
2844 subtype \type {pdf_refximage}, filled with the image parameters \type {width},
2845 \type {height}, \type {depth}, and \type {objnum}. Also here you can do a terse
2846 call like:
2848 \starttyping
2849 n = img.node ({ filename = "foo.png" })
2850 \stoptyping
2852 This example outputs an image:
2854 \starttyping
2855 node.write(img.node{filename="foo.png"})
2856 \stoptyping
2858 \subsection{\type {img.types}}
2860 \startfunctioncall
2861 <table> types = img.types()
2862 \stopfunctioncall
2864 This function returns a list with the supported image file type names, currently
2865 these are \type {pdf}, \type {png}, \type {jpg}, \type {jp2} (JPEG~2000), and
2866 \type {jbig2}.
2868 \subsection{\type {img.boxes}}
2870 \startfunctioncall
2871 <table> boxes = img.boxes()
2872 \stopfunctioncall
2874 This function returns a list with the supported \PDF\ page box names, currently
2875 these are \type {media}, \type {crop}, \type {bleed}, \type {trim}, and \type
2876 {art} (all in lowercase letters).
2878 \section{The \type {kpse} library}
2880 This library provides two separate, but nearly identical interfaces to the
2881 \KPATHSEA\ file search functionality: there is a \quote {normal} procedural
2882 interface that shares its kpathsea instance with \LUATEX\ itself, and an object
2883 oriented interface that is completely on its own.
2885 \subsection{\type {kpse.set_program_name} and \type {kpse.new}}
2887 Before the search library can be used at all, its database has to be initialized.
2888 There are three possibilities, two of which belong to the procedural interface.
2890 First, when \LUATEX\ is used to typeset documents, this initialization happens
2891 automatically and the \KPATHSEA\ executable and program names are set to \type
2892 {luatex} (that is, unless explicitly prohibited by the user's startup script.
2893 See~\in {section} [init] for more details).
2895 Second, in \TEXLUA\ mode, the initialization has to be done explicitly via the
2896 \type {kpse.set_program_name} function, which sets the \KPATHSEA\ executable
2897 (and optionally program) name.
2899 \startfunctioncall
2900 kpse.set_program_name(<string> name)
2901 kpse.set_program_name(<string> name, <string> progname)
2902 \stopfunctioncall
2904 The second argument controls the use of the \quote {dotted} values in the \type
2905 {texmf.cnf} configuration file, and defaults to the first argument.
2907 Third, if you prefer the object oriented interface, you have to call a different
2908 function. It has the same arguments, but it returns a userdata variable.
2910 \startfunctioncall
2911 local kpathsea = kpse.new(<string> name)
2912 local kpathsea = kpse.new(<string> name, <string> progname)
2913 \stopfunctioncall
2915 Apart from these two functions, the calling conventions of the interfaces are
2916 identical. Depending on the chosen interface, you either call \type
2917 {kpse.find_file()} or \type {kpathsea:find_file()}, with identical arguments and
2918 return vales.
2920 \subsection{\type {find_file}}
2922 The most often used function in the library is find_file:
2924 \startfunctioncall
2925 <string> f = kpse.find_file(<string> filename)
2926 <string> f = kpse.find_file(<string> filename, <string> ftype)
2927 <string> f = kpse.find_file(<string> filename, <boolean> mustexist)
2928 <string> f = kpse.find_file(<string> filename, <string> ftype, <boolean> mustexist)
2929 <string> f = kpse.find_file(<string> filename, <string> ftype, <number> dpi)
2930 \stopfunctioncall
2932 Arguments:
2933 \startitemize[intro]
2935 \sym{filename}
2937 the name of the file you want to find, with or without extension.
2939 \sym{ftype}
2941 maps to the \type {-format} argument of \KPSEWHICH. The supported \type {ftype}
2942 values are the same as the ones supported by the standalone \type {kpsewhich}
2943 program:
2945 \startsimplecolumns
2946 \starttyping
2949 bitmap font
2952 base
2956 ls-R
2961 mfpool
2964 mppool
2965 MetaPost support
2972 graphic/figure
2974 TeX system documentation
2975 texpool
2976 TeX system sources
2977 PostScript header
2978 Troff fonts
2979 type1 fonts
2981 dvips config
2983 truetype fonts
2984 type42 fonts
2985 web2c files
2986 other text files
2987 other binary files
2988 misc fonts
2990 cweb
2991 enc files
2992 cmap files
2993 subfont definition files
2994 opentype fonts
2995 pdftex config
2996 lig files
2997 texmfscripts
2999 font feature files
3000 cid maps
3001 mlbib
3002 mlbst
3003 clua
3004 \stoptyping
3005 \stopsimplecolumns
3007 The default type is \type {tex}. Note: this is different from \KPSEWHICH, which
3008 tries to deduce the file type itself from looking at the supplied extension.
3010 \sym{mustexist}
3012 is similar to \KPSEWHICH's \type {-must-exist}, and the default is \type {false}.
3013 If you specify \type {true} (or a non|-|zero integer), then the \KPSE\ library
3014 will search the disk as well as the \type {ls-R} databases.
3016 \sym{dpi}
3018 This is used for the size argument of the formats \type {pk}, \type {gf}, and
3019 \type {bitmap font}. \stopitemize
3022 \subsection{\type {lookup}}
3024 A more powerful (but slower) generic method for finding files is also available.
3025 It returns a string for each found file.
3027 \startfunctioncall
3028 <string> f, ... = kpse.lookup(<string> filename, <table> options)
3029 \stopfunctioncall
3031 The options match commandline arguments from \type {kpsewhich}:
3033 \starttabulate[|l|l|p|]
3034 \NC \ssbf key \NC \ssbf type \NC \ssbf description \NC \NR
3035 \NC debug \NC number \NC set debugging flags for this lookup\NC \NR
3036 \NC format \NC string \NC use specific file type (see list above)\NC \NR
3037 \NC dpi \NC number \NC use this resolution for this lookup; default 600\NC \NR
3038 \NC path \NC string \NC search in the given path\NC \NR
3039 \NC all \NC boolean \NC output all matches, not just the first\NC \NR
3040 \NC mustexist \NC boolean \NC search the disk as well as ls-R if necessary\NC \NR
3041 \NC mktexpk \NC boolean \NC disable/enable mktexpk generation for this lookup\NC \NR
3042 \NC mktextex \NC boolean \NC disable/enable mktextex generation for this lookup\NC \NR
3043 \NC mktexmf \NC boolean \NC disable/enable mktexmf generation for this lookup\NC \NR
3044 \NC mktextfm \NC boolean \NC disable/enable mktextfm generation for this lookup\NC \NR
3045 \NC subdir \NC string
3046 or table \NC only output matches whose directory part
3047 ends with the given string(s) \NC \NR
3048 \stoptabulate
3050 \subsection{\type {init_prog}}
3052 Extra initialization for programs that need to generate bitmap fonts.
3054 \startfunctioncall
3055 kpse.init_prog(<string> prefix, <number> base_dpi, <string> mfmode)
3056 kpse.init_prog(<string> prefix, <number> base_dpi, <string> mfmode, <string> fallback)
3057 \stopfunctioncall
3059 \subsection{\type {readable_file}}
3061 Test if an (absolute) file name is a readable file.
3063 \startfunctioncall
3064 <string> f = kpse.readable_file(<string> name)
3065 \stopfunctioncall
3067 The return value is the actual absolute filename you should use, because the disk
3068 name is not always the same as the requested name, due to aliases and
3069 system|-|specific handling under e.g.\ \MSDOS. Returns \type {nil} if the file
3070 does not exist or is not readable.
3072 \subsection{\type {expand_path}}
3074 Like kpsewhich's \type {-expand-path}:
3076 \startfunctioncall
3077 <string> r = kpse.expand_path(<string> s)
3078 \stopfunctioncall
3080 \subsection{\type {expand_var}}
3082 Like kpsewhich's \type {-expand-var}:
3084 \startfunctioncall
3085 <string> r = kpse.expand_var(<string> s)
3086 \stopfunctioncall
3088 \subsection{\type {expand_braces}}
3090 Like kpsewhich's \type {-expand-braces}:
3092 \startfunctioncall
3093 <string> r = kpse.expand_braces(<string> s)
3094 \stopfunctioncall
3096 \subsection{\type {show_path}}
3098 Like kpsewhich's \type {-show-path}:
3100 \startfunctioncall
3101 <string> r = kpse.show_path(<string> ftype)
3102 \stopfunctioncall
3105 \subsection{\type {var_value}}
3107 Like kpsewhich's \type {-var-value}:
3109 \startfunctioncall
3110 <string> r = kpse.var_value(<string> s)
3111 \stopfunctioncall
3113 \subsection{\type {version}}
3115 Returns the kpathsea version string.
3117 \startfunctioncall
3118 <string> r = kpse.version()
3119 \stopfunctioncall
3122 \section{The \type {lang} library}
3124 This library provides the interface to \LUATEX's structure
3125 representing a language, and the associated functions.
3127 \startfunctioncall
3128 <language> l = lang.new()
3129 <language> l = lang.new(<number> id)
3130 \stopfunctioncall
3132 This function creates a new userdata object. An object of type \type {<language>}
3133 is the first argument to most of the other functions in the \type {lang}
3134 library. These functions can also be used as if they were object methods, using
3135 the colon syntax.
3137 Without an argument, the next available internal id number will be assigned to
3138 this object. With argument, an object will be created that links to the internal
3139 language with that id number.
3141 \startfunctioncall
3142 <number> n = lang.id(<language> l)
3143 \stopfunctioncall
3145 returns the internal \type {\language} id number this object refers to.
3147 \startfunctioncall
3148 <string> n = lang.hyphenation(<language> l)
3149 lang.hyphenation(<language> l, <string> n)
3150 \stopfunctioncall
3152 Either returns the current hyphenation exceptions for this language, or adds new
3153 ones. The syntax of the string is explained in~\in {section}
3154 [patternsexceptions].
3156 \startfunctioncall
3157 lang.clear_hyphenation(<language> l)
3158 \stopfunctioncall
3160 Clears the exception dictionary (string) for this language.
3162 \startfunctioncall
3163 <string> n = lang.clean(<language> l, <string> o)
3164 <string> n = lang.clean(<string> o)
3165 \stopfunctioncall
3167 Creates a hyphenation key from the supplied hyphenation value. The syntax of the
3168 argument string is explained in~\in {section} [patternsexceptions]. This function
3169 is useful if you want to do something else based on the words in a dictionary
3170 file, like spell|-|checking.
3172 \startfunctioncall
3173 <string> n = lang.patterns(<language> l)
3174 lang.patterns(<language> l, <string> n)
3175 \stopfunctioncall
3177 Adds additional patterns for this language object, or returns the current set.
3178 The syntax of this string is explained in~\in {section} [patternsexceptions].
3180 \startfunctioncall
3181 lang.clear_patterns(<language> l)
3182 \stopfunctioncall
3184 Clears the pattern dictionary for this language.
3186 \startfunctioncall
3187 <number> n = lang.prehyphenchar(<language> l)
3188 lang.prehyphenchar(<language> l, <number> n)
3189 \stopfunctioncall
3191 Gets or sets the \quote {pre|-|break} hyphen character for implicit hyphenation
3192 in this language (initially the hyphen, decimal 45).
3194 \startfunctioncall
3195 <number> n = lang.posthyphenchar(<language> l)
3196 lang.posthyphenchar(<language> l, <number> n)
3197 \stopfunctioncall
3199 Gets or sets the \quote {post|-|break} hyphen character for implicit hyphenation
3200 in this language (initially null, decimal~0, indicating emptiness).
3202 \startfunctioncall
3203 <number> n = lang.preexhyphenchar(<language> l)
3204 lang.preexhyphenchar(<language> l, <number> n)
3205 \stopfunctioncall
3207 Gets or sets the \quote {pre|-|break} hyphen character for explicit hyphenation
3208 in this language (initially null, decimal~0, indicating emptiness).
3210 \startfunctioncall
3211 <number> n = lang.postexhyphenchar(<language> l)
3212 lang.postexhyphenchar(<language> l, <number> n)
3213 \stopfunctioncall
3215 Gets or sets the \quote {post|-|break} hyphen character for explicit hyphenation
3216 in this language (initially null, decimal~0, indicating emptiness).
3218 \startfunctioncall
3219 <boolean> success = lang.hyphenate(<node> head)
3220 <boolean> success = lang.hyphenate(<node> head, <node> tail)
3221 \stopfunctioncall
3223 Inserts hyphenation points (discretionary nodes) in a node list. If \type {tail}
3224 is given as argument, processing stops on that node. Currently, \type {success}
3225 is always true if \type {head} (and \type {tail}, if specified) are proper nodes,
3226 regardless of possible other errors.
3228 Hyphenation works only on \quote {characters}, a special subtype of all the glyph
3229 nodes with the node subtype having the value \type {1}. Glyph modes with
3230 different subtypes are not processed. See \in {section~} [charsandglyphs] for
3231 more details.
3233 The following two commands can be used to set or query hj codes:
3235 \startfunctioncall
3236 lang.sethjcode(<language> l, <number> char, <number> usedchar)
3237 <number> usedchar = lang.gethjcode(<language> l, <number> char)
3238 \stopfunctioncall
3240 When you set a hjcode the current sets get initialized unless the set was already
3241 initialized due to \type {\savinghyphcodes} being larger than zero.
3243 \section{The \type {lua} library}
3245 This library contains one read|-|only item:
3247 \starttyping
3248 <string> s = lua.version
3249 \stoptyping
3251 This returns the \LUA\ version identifier string. The value is currently
3252 \directlua {tex.print(lua.version)}.
3254 \subsection{\LUA\ bytecode registers}
3256 \LUA\ registers can be used to communicate \LUA\ functions across \LUA\ chunks.
3257 The accepted values for assignments are functions and \type {nil}. Likewise, the
3258 retrieved value is either a function or \type {nil}.
3260 \starttyping
3261 lua.bytecode[<number> n] = <function> f
3262 lua.bytecode[<number> n]()
3263 \stoptyping
3265 The contents of the \type {lua.bytecode} array is stored inside the format file
3266 as actual \LUA\ bytecode, so it can also be used to preload \LUA\ code.
3268 Note: The function must not contain any upvalues. Currently, functions containing
3269 upvalues can be stored (and their upvalues are set to \type {nil}), but this is
3270 an artifact of the current \LUA\ implementation and thus subject to change.
3272 The associated function calls are
3274 \startfunctioncall
3275 <function> f = lua.getbytecode(<number> n)
3276 lua.setbytecode(<number> n, <function> f)
3277 \stopfunctioncall
3279 Note: Since a \LUA\ file loaded using \type {loadfile(filename)} is essentially
3280 an anonymous function, a complete file can be stored in a bytecode register like
3281 this:
3283 \startfunctioncall
3284 lua.bytecode[n] = loadfile(filename)
3285 \stopfunctioncall
3287 Now all definitions (functions, variables) contained in the file can be
3288 created by executing this bytecode register:
3290 \startfunctioncall
3291 lua.bytecode[n]()
3292 \stopfunctioncall
3294 Note that the path of the file is stored in the \LUA\ bytecode to be used in
3295 stack backtraces and therefore dumped into the format file if the above code is
3296 used in \INITEX. If it contains private information, i.e. the user name, this
3297 information is then contained in the format file as well. This should be kept in
3298 mind when preloading files into a bytecode register in \INITEX.
3300 \subsection{\LUA\ chunk name registers}
3302 There is an array of 65536 (0--65535) potential chunk names for use with the
3303 \type {\directlua} and \type {\latelua} primitives.
3305 \startfunctioncall
3306 lua.name[<number> n] = <string> s
3307 <string> s = lua.name[<number> n]
3308 \stopfunctioncall
3310 If you want to unset a \LUA\ name, you can assign \type {nil} to it.
3312 \section{The \type {mplib} library}
3314 The \MP\ library interface registers itself in the table \type {mplib}. It is
3315 based on \MPLIB\ version \ctxlua {context(mplib.version())}.
3317 \subsection{\type {mplib.new}}
3319 To create a new \METAPOST\ instance, call
3321 \startfunctioncall
3322 <mpinstance> mp = mplib.new({...})
3323 \stopfunctioncall
3325 This creates the \type {mp} instance object. The argument hash can have a number
3326 of different fields, as follows:
3328 \starttabulate[|lT|l|p|p|]
3329 \NC \ssbf name \NC \bf type \NC \bf description \NC \bf default \NC \NR
3330 \NC error_line \NC number \NC error line width \NC 79 \NC \NR
3331 \NC print_line \NC number \NC line length in ps output \NC 100 \NC \NR
3332 \NC random_seed \NC number \NC the initial random seed \NC variable \NC \NR
3333 \NC interaction \NC string \NC the interaction mode,
3334 one of
3335 \type {batch},
3336 \type {nonstop},
3337 \type {scroll},
3338 \type {errorstop} \NC \type {errorstop} \NC \NR
3339 \NC job_name \NC string \NC \type {--jobname} \NC \type {mpout} \NC \NR
3340 \NC find_file \NC function \NC a function to find files \NC only local files \NC \NR
3341 \stoptabulate
3343 The \type {find_file} function should be of this form:
3345 \starttyping
3346 <string> found = finder (<string> name, <string> mode, <string> type)
3347 \stoptyping
3349 with:
3351 \starttabulate[|lT|l|p|]
3352 \NC \bf name \NC \bf the requested file \NC \NR
3353 \NC mode \NC the file mode: \type {r} or \type {w} \NC \NR
3354 \NC type \NC the kind of file, one of: \type {mp}, \type {tfm}, \type {map},
3355 \type {pfb}, \type {enc} \NC \NR
3356 \stoptabulate
3358 Return either the full path name of the found file, or \type {nil} if the file
3359 cannot be found.
3361 Note that the new version of \MPLIB\ no longer uses binary mem files, so the way
3362 to preload a set of macros is simply to start off with an \type {input} command
3363 in the first \type {mp:execute()} call.
3365 \subsection{\type {mp:statistics}}
3367 You can request statistics with:
3369 \startfunctioncall
3370 <table> stats = mp:statistics()
3371 \stopfunctioncall
3373 This function returns the vital statistics for an \MPLIB\ instance. There are
3374 four fields, giving the maximum number of used items in each of four allocated
3375 object classes:
3377 \starttabulate[|lT|l|p|]
3378 \NC main_memory \NC number \NC memory size \NC \NR
3379 \NC hash_size \NC number \NC hash size\NC \NR
3380 \NC param_size \NC number \NC simultaneous macro parameters\NC \NR
3381 \NC max_in_open \NC number \NC input file nesting levels\NC \NR
3382 \stoptabulate
3384 Note that in the new version of \MPLIB, this is informational only. The objects
3385 are all allocated dynamically, so there is no chance of running out of space
3386 unless the available system memory is exhausted.
3388 \subsection{\type {mp:execute}}
3390 You can ask the \METAPOST\ interpreter to run a chunk of code by calling
3392 \startfunctioncall
3393 <table> rettable = mp:execute('metapost language chunk')
3394 \stopfunctioncall
3396 for various bits of \METAPOST\ language input. Be sure to check the \type
3397 {rettable.status} (see below) because when a fatal \METAPOST\ error occurs the
3398 \MPLIB\ instance will become unusable thereafter.
3400 Generally speaking, it is best to keep your chunks small, but beware that all
3401 chunks have to obey proper syntax, like each of them is a small file. For
3402 instance, you cannot split a single statement over multiple chunks.
3404 In contrast with the normal stand alone \type {mpost} command, there is {\em no}
3405 implied \quote{input} at the start of the first chunk.
3407 \subsection{\type {mp:finish}}
3409 \startfunctioncall
3410 <table> rettable = mp:finish()
3411 \stopfunctioncall
3413 If for some reason you want to stop using an \MPLIB\ instance while processing is
3414 not yet actually done, you can call \type {mp:finish}. Eventually, used memory
3415 will be freed and open files will be closed by the \LUA\ garbage collector, but
3416 an explicit \type {mp:finish} is the only way to capture the final part of the
3417 output streams.
3419 \subsection{Result table}
3421 The return value of \type {mp:execute} and \type {mp:finish} is a table with a
3422 few possible keys (only \type {status} is always guaranteed to be present).
3424 \starttabulate[|l|l|p|]
3425 \NC log \NC string \NC output to the \quote {log} stream \NC \NR
3426 \NC term \NC string \NC output to the \quote {term} stream \NC \NR
3427 \NC error \NC string \NC output to the \quote {error} stream
3428 (only used for \quote {out of memory}) \NC \NR
3429 \NC status \NC number \NC the return value:
3430 \type {0} = good,
3431 \type {1} = warning,
3432 \type {2} = errors,
3433 \type {3} = fatal error \NC \NR
3434 \NC fig \NC table \NC an array of generated figures (if any) \NC \NR
3435 \stoptabulate
3437 When \type {status} equals~3, you should stop using this \MPLIB\ instance
3438 immediately, it is no longer capable of processing input.
3440 If it is present, each of the entries in the \type {fig} array is a userdata
3441 representing a figure object, and each of those has a number of object methods
3442 you can call:
3444 \starttabulate[|l|l|p|]
3445 \NC boundingbox \NC function \NC returns the bounding box, as an array of 4
3446 values\NC \NR
3447 \NC postscript \NC function \NC returns a string that is the ps output of the
3448 \type {fig}. this function accepts two optional
3449 integer arguments for specifying the values of
3450 \type {prologues} (first argument) and \type
3451 {procset} (second argument)\NC \NR
3452 \NC svg \NC function \NC returns a string that is the svg output of the
3453 \type {fig}. This function accepts an optional
3454 integer argument for specifying the value of
3455 \type {prologues}\NC \NR
3456 \NC objects \NC function \NC returns the actual array of graphic objects in
3457 this \type {fig} \NC \NR
3458 \NC copy_objects \NC function \NC returns a deep copy of the array of graphic
3459 objects in this \type {fig} \NC \NR
3460 \NC filename \NC function \NC the filename this \type {fig}'s \POSTSCRIPT\
3461 output would have written to in stand alone
3462 mode \NC \NR
3463 \NC width \NC function \NC the \type {fontcharwd} value \NC \NR
3464 \NC height \NC function \NC the \type {fontcharht} value \NC \NR
3465 \NC depth \NC function \NC the \type {fontchardp} value \NC \NR
3466 \NC italcorr \NC function \NC the \type {fontcharit} value \NC \NR
3467 \NC charcode \NC function \NC the (rounded) \type {charcode} value \NC \NR
3468 \stoptabulate
3470 Note: you can call \type {fig:objects()} only once for any one \type {fig}
3471 object!
3473 When the boundingbox represents a \quote {negated rectangle}, i.e.\ when the
3474 first set of coordinates is larger than the second set, the picture is empty.
3476 Graphical objects come in various types that each has a different list of
3477 accessible values. The types are: \type {fill}, \type {outline}, \type {text},
3478 \type {start_clip}, \type {stop_clip}, \type {start_bounds}, \type {stop_bounds},
3479 \type {special}.
3481 There is helper function (\type {mplib.fields(obj)}) to get the list of
3482 accessible values for a particular object, but you can just as easily use the
3483 tables given below.
3485 All graphical objects have a field \type {type} that gives the object type as a
3486 string value; it is not explicit mentioned in the following tables. In the
3487 following, \type {number}s are \POSTSCRIPT\ points represented as a floating
3488 point number, unless stated otherwise. Field values that are of type \type
3489 {table} are explained in the next section.
3491 \subsubsection{fill}
3493 \starttabulate[|l|l|p|]
3494 \NC path \NC table \NC the list of knots \NC \NR
3495 \NC htap \NC table \NC the list of knots for the reversed trajectory \NC \NR
3496 \NC pen \NC table \NC knots of the pen \NC \NR
3497 \NC color \NC table \NC the object's color \NC \NR
3498 \NC linejoin \NC number \NC line join style (bare number)\NC \NR
3499 \NC miterlimit \NC number \NC miterlimit\NC \NR
3500 \NC prescript \NC string \NC the prescript text \NC \NR
3501 \NC postscript \NC string \NC the postscript text \NC \NR
3502 \stoptabulate
3504 The entries \type {htap} and \type {pen} are optional.
3506 There is helper function (\type {mplib.pen_info(obj)}) that returns a table
3507 containing a bunch of vital characteristics of the used pen (all values are
3508 floats):
3510 \starttabulate[|l|l|p|]
3511 \NC width \NC number \NC width of the pen \NC \NR
3512 \NC sx \NC number \NC $x$ scale \NC \NR
3513 \NC rx \NC number \NC $xy$ multiplier \NC \NR
3514 \NC ry \NC number \NC $yx$ multiplier \NC \NR
3515 \NC sy \NC number \NC $y$ scale \NC \NR
3516 \NC tx \NC number \NC $x$ offset \NC \NR
3517 \NC ty \NC number \NC $y$ offset \NC \NR
3518 \stoptabulate
3520 \subsubsection{outline}
3522 \starttabulate[|l|l|p|]
3523 \NC path \NC table \NC the list of knots \NC \NR
3524 \NC pen \NC table \NC knots of the pen \NC \NR
3525 \NC color \NC table \NC the object's color \NC \NR
3526 \NC linejoin \NC number \NC line join style (bare number) \NC \NR
3527 \NC miterlimit \NC number \NC miterlimit \NC \NR
3528 \NC linecap \NC number \NC line cap style (bare number) \NC \NR
3529 \NC dash \NC table \NC representation of a dash list \NC \NR
3530 \NC prescript \NC string \NC the prescript text \NC \NR
3531 \NC postscript \NC string \NC the postscript text \NC \NR
3532 \stoptabulate
3534 The entry \type {dash} is optional.
3536 \subsubsection{text}
3538 \starttabulate[|l|l|p|]
3539 \NC text \NC string \NC the text \NC \NR
3540 \NC font \NC string \NC font tfm name \NC \NR
3541 \NC dsize \NC number \NC font size \NC \NR
3542 \NC color \NC table \NC the object's color \NC \NR
3543 \NC width \NC number \NC \NC \NR
3544 \NC height \NC number \NC \NC \NR
3545 \NC depth \NC number \NC \NC \NR
3546 \NC transform \NC table \NC a text transformation \NC \NR
3547 \NC prescript \NC string \NC the prescript text \NC \NR
3548 \NC postscript \NC string \NC the postscript text \NC \NR
3549 \stoptabulate
3551 \subsubsection{special}
3553 \starttabulate[|l|l|p|]
3554 \NC prescript \NC string \NC special text \NC \NR
3555 \stoptabulate
3557 \subsubsection{start_bounds, start_clip}
3559 \starttabulate[|l|l|p|]
3560 \NC path \NC table \NC the list of knots \NC \NR
3561 \stoptabulate
3563 \subsubsection{stop_bounds, stop_clip}
3565 Here are no fields available.
3567 \subsection{Subsidiary table formats}
3569 \subsubsection{Paths and pens}
3571 Paths and pens (that are really just a special type of paths as far as \MPLIB\ is
3572 concerned) are represented by an array where each entry is a table that
3573 represents a knot.
3575 \starttabulate[|lT|l|p|]
3576 \NC left_type \NC string \NC when present: endpoint, but usually absent \NC \NR
3577 \NC right_type \NC string \NC like \type {left_type} \NC \NR
3578 \NC x_coord \NC number \NC X coordinate of this knot \NC \NR
3579 \NC y_coord \NC number \NC Y coordinate of this knot \NC \NR
3580 \NC left_x \NC number \NC X coordinate of the precontrol point of this knot \NC \NR
3581 \NC left_y \NC number \NC Y coordinate of the precontrol point of this knot \NC \NR
3582 \NC right_x \NC number \NC X coordinate of the postcontrol point of this knot \NC \NR
3583 \NC right_y \NC number \NC Y coordinate of the postcontrol point of this knot \NC \NR
3584 \stoptabulate
3586 There is one special case: pens that are (possibly transformed) ellipses have an
3587 extra string-valued key \type {type} with value \type {elliptical} besides the
3588 array part containing the knot list.
3590 \subsubsection{Colors}
3592 A color is an integer array with 0, 1, 3 or 4 values:
3594 \starttabulate[|l|l|p|]
3595 \NC 0 \NC marking only \NC no values \NC \NR
3596 \NC 1 \NC greyscale \NC one value in the range $(0,1)$, \quote {black} is $0$ \NC \NR
3597 \NC 3 \NC \RGB \NC three values in the range $(0,1)$, \quote {black} is $0,0,0$ \NC \NR
3598 \NC 4 \NC \CMYK \NC four values in the range $(0,1)$, \quote {black} is $0,0,0,1$ \NC \NR
3599 \stoptabulate
3601 If the color model of the internal object was \type {uninitialized}, then it was
3602 initialized to the values representing \quote {black} in the colorspace \type
3603 {defaultcolormodel} that was in effect at the time of the \type {shipout}.
3605 \subsubsection{Transforms}
3607 Each transform is a six|-|item array.
3609 \starttabulate[|l|l|p|]
3610 \NC 1 \NC number \NC represents x \NC \NR
3611 \NC 2 \NC number \NC represents y \NC \NR
3612 \NC 3 \NC number \NC represents xx \NC \NR
3613 \NC 4 \NC number \NC represents yx \NC \NR
3614 \NC 5 \NC number \NC represents xy \NC \NR
3615 \NC 6 \NC number \NC represents yy \NC \NR
3616 \stoptabulate
3618 Note that the translation (index 1 and 2) comes first. This differs from the
3619 ordering in \POSTSCRIPT, where the translation comes last.
3621 \subsubsection{Dashes}
3623 Each \type {dash} is two-item hash, using the same model as \POSTSCRIPT\ for the
3624 representation of the dashlist. \type {dashes} is an array of \quote {on} and
3625 \quote {off}, values, and \type {offset} is the phase of the pattern.
3627 \starttabulate[|l|l|p|]
3628 \NC dashes \NC hash \NC an array of on-off numbers \NC \NR
3629 \NC offset \NC number \NC the starting offset value \NC \NR
3630 \stoptabulate
3632 \subsection{Character size information}
3634 These functions find the size of a glyph in a defined font. The \type {fontname}
3635 is the same name as the argument to \type {infont}; the \type {char} is a glyph
3636 id in the range 0 to 255; the returned \type {w} is in AFM units.
3638 \subsubsection{\type {mp:char_width}}
3640 \startfunctioncall
3641 <number> w = mp:char_width(<string> fontname, <number> char)
3642 \stopfunctioncall
3644 \subsubsection{\type {mp:char_height}}
3646 \startfunctioncall
3647 <number> w = mp:char_height(<string> fontname, <number> char)
3648 \stopfunctioncall
3650 \subsubsection{\type {mp:char_depth}}
3652 \startfunctioncall
3653 <number> w = mp:char_depth(<string> fontname, <number> char)
3654 \stopfunctioncall
3656 \section{The \type {node} library}
3658 The \type {node} library contains functions that facilitate dealing with (lists
3659 of) nodes and their values. They allow you to create, alter, copy, delete, and
3660 insert \LUATEX\ node objects, the core objects within the typesetter.
3662 \LUATEX\ nodes are represented in \LUA\ as userdata with the metadata type
3663 \type {luatex.node}. The various parts within a node can be accessed using
3664 named fields.
3666 Each node has at least the three fields \type {next}, \type {id}, and \type
3667 {subtype}:
3669 \startitemize[intro]
3671 \startitem
3672 The \type {next} field returns the userdata object for the next node in a
3673 linked list of nodes, or \type {nil}, if there is no next node.
3674 \stopitem
3676 \startitem
3677 The \type {id} indicates \TEX's \quote{node type}. The field \type {id} has a
3678 numeric value for efficiency reasons, but some of the library functions also
3679 accept a string value instead of \type {id}.
3680 \stopitem
3682 \startitem
3683 The \type {subtype} is another number. It often gives further information
3684 about a node of a particular \type {id}, but it is most important when
3685 dealing with \quote {whatsits}, because they are differentiated solely based
3686 on their \type {subtype}.
3687 \stopitem
3689 \stopitemize
3691 The other available fields depend on the \type {id} (and for \quote {whatsits},
3692 the \type {subtype}) of the node. Further details on the various fields and their
3693 meanings are given in~\in{chapter}[nodes].
3695 Support for \type {unset} (alignment) nodes is partial: they can be queried and
3696 modified from \LUA\ code, but not created.
3698 Nodes can be compared to each other, but: you are actually comparing indices into
3699 the node memory. This means that equality tests can only be trusted under very
3700 limited conditions. It will not work correctly in any situation where one of the
3701 two nodes has been freed and|/|or reallocated: in that case, there will be false
3702 positives.
3704 At the moment, memory management of nodes should still be done explicitly by the
3705 user. Nodes are not \quote {seen} by the \LUA\ garbage collector, so you have to
3706 call the node freeing functions yourself when you are no longer in need of a node
3707 (list). Nodes form linked lists without reference counting, so you have to be
3708 careful that when control returns back to \LUATEX\ itself, you have not deleted
3709 nodes that are still referenced from a \type {next} pointer elsewhere, and that
3710 you did not create nodes that are referenced more than once.
3712 There are statistics available with regards to the allocated node memory, which
3713 can be handy for tracing.
3715 \subsection{Node handling functions}
3717 \subsubsection{\type {node.is_node}}
3719 \startfunctioncall
3720 <boolean> t = node.is_node(<any> item)
3721 \stopfunctioncall
3723 This function returns true if the argument is a userdata object of
3724 type \type {<node>}.
3726 \subsubsection{\type {node.types}}
3728 \startfunctioncall
3729 <table> t = node.types()
3730 \stopfunctioncall
3732 This function returns an array that maps node id numbers to node type strings,
3733 providing an overview of the possible top|-|level \type {id} types.
3735 \subsubsection{\type {node.whatsits}}
3737 \startfunctioncall
3738 <table> t = node.whatsits()
3739 \stopfunctioncall
3741 \TEX's \quote{whatsits} all have the same \type {id}. The various subtypes are
3742 defined by their \type {subtype} fields. The function is much like \type
3743 {node.types}, except that it provides an array of \type {subtype} mappings.
3745 \subsubsection{\type {node.id}}
3747 \startfunctioncall
3748 <number> id = node.id(<string> type)
3749 \stopfunctioncall
3751 This converts a single type name to its internal numeric representation.
3753 \subsubsection{\type {node.subtype}}
3755 \startfunctioncall
3756 <number> subtype = node.subtype(<string> type)
3757 \stopfunctioncall
3759 This converts a single whatsit name to its internal numeric representation (\type
3760 {subtype}).
3762 \subsubsection{\type {node.type}}
3764 \startfunctioncall
3765 <string> type = node.type(<any> n)
3766 \stopfunctioncall
3768 In the argument is a number, then this function converts an internal numeric
3769 representation to an external string representation. Otherwise, it will return
3770 the string \type {node} if the object represents a node, and \type {nil}
3771 otherwise.
3773 \subsubsection{\type {node.fields}}
3775 \startfunctioncall
3776 <table> t = node.fields(<number> id)
3777 <table> t = node.fields(<number> id, <number> subtype)
3778 \stopfunctioncall
3780 This function returns an array of valid field names for a particular type of
3781 node. If you want to get the valid fields for a \quote {whatsit}, you have to
3782 supply the second argument also. In other cases, any given second argument will
3783 be silently ignored.
3785 This function accepts string \type {id} and \type {subtype} values as well.
3787 \subsubsection{\type {node.has_field}}
3789 \startfunctioncall
3790 <boolean> t = node.has_field(<node> n, <string> field)
3791 \stopfunctioncall
3793 This function returns a boolean that is only true if \type {n} is
3794 actually a node, and it has the field.
3796 \subsubsection{\type {node.new}}
3798 \startfunctioncall
3799 <node> n = node.new(<number> id)
3800 <node> n = node.new(<number> id, <number> subtype)
3801 \stopfunctioncall
3803 Creates a new node. All of the new node's fields are initialized to either zero
3804 or \type {nil} except for \type {id} and \type {subtype} (if supplied). If you
3805 want to create a new whatsit, then the second argument is required, otherwise it
3806 need not be present. As with all node functions, this function creates a node on
3807 the \TEX\ level.
3809 This function accepts string \type {id} and \type {subtype} values as well.
3811 \subsubsection{\type {node.free}}
3813 \startfunctioncall
3814 node.free(<node> n)
3815 \stopfunctioncall
3817 Removes the node \type {n} from \TEX's memory. Be careful: no checks are done on
3818 whether this node is still pointed to from a register or some \type {next} field:
3819 it is up to you to make sure that the internal data structures remain correct.
3821 \subsubsection{\type {node.flush_list}}
3823 \startfunctioncall
3824 node.flush_list(<node> n)
3825 \stopfunctioncall
3827 Removes the node list \type {n} and the complete node list following \type {n}
3828 from \TEX's memory. Be careful: no checks are done on whether any of these nodes
3829 is still pointed to from a register or some \type {next} field: it is up to you
3830 to make sure that the internal data structures remain correct.
3832 \subsubsection{\type {node.copy}}
3834 \startfunctioncall
3835 <node> m = node.copy(<node> n)
3836 \stopfunctioncall
3838 Creates a deep copy of node \type {n}, including all nested lists as in the case
3839 of a hlist or vlist node. Only the \type {next} field is not copied.
3841 \subsubsection{\type {node.copy_list}}
3843 \startfunctioncall
3844 <node> m = node.copy_list(<node> n)
3845 <node> m = node.copy_list(<node> n, <node> m)
3846 \stopfunctioncall
3848 Creates a deep copy of the node list that starts at \type {n}. If \type {m} is
3849 also given, the copy stops just before node \type {m}.
3851 Note that you cannot copy attribute lists this way, specialized functions for
3852 dealing with attribute lists will be provided later but are not there yet.
3853 However, there is normally no need to copy attribute lists as when you do
3854 assignments to the \type {attr} field or make changes to specific attributes, the
3855 needed copying and freeing takes place automatically.
3857 \subsubsection{\type {node.next}}
3859 \startfunctioncall
3860 <node> m = node.next(<node> n)
3861 \stopfunctioncall
3863 Returns the node following this node, or \type {nil} if there is no such node.
3865 \subsubsection{\type {node.prev}}
3867 \startfunctioncall
3868 <node> m = node.prev(<node> n)
3869 \stopfunctioncall
3871 Returns the node preceding this node, or \type {nil} if there is no such node.
3873 \subsubsection{\type {node.current_attr}}
3875 \startfunctioncall
3876 <node> m = node.current_attr()
3877 \stopfunctioncall
3879 Returns the currently active list of attributes, if there is one.
3881 The intended usage of \type {current_attr} is as follows:
3883 \starttyping
3884 local x1 = node.new("glyph")
3885 x1.attr = node.current_attr()
3886 local x2 = node.new("glyph")
3887 x2.attr = node.current_attr()
3888 \stoptyping
3892 \starttyping
3893 local x1 = node.new("glyph")
3894 local x2 = node.new("glyph")
3895 local ca = node.current_attr()
3896 x1.attr = ca
3897 x2.attr = ca
3898 \stoptyping
3900 The attribute lists are ref counted and the assignment takes care of incrementing
3901 the refcount. You cannot expect the value \type {ca} to be valid any more when
3902 you assign attributes (using \type {tex.setattribute}) or when control has been
3903 passed back to \TEX.
3905 Note: this function is somewhat experimental, and it returns the {\it actual}
3906 attribute list, not a copy thereof. Therefore, changing any of the attributes in
3907 the list will change these values for all nodes that have the current attribute
3908 list assigned to them.
3910 \subsubsection{\type {node.hpack}}
3912 \startfunctioncall
3913 <node> h, <number> b = node.hpack(<node> n)
3914 <node> h, <number> b = node.hpack(<node> n, <number> w, <string> info)
3915 <node> h, <number> b = node.hpack(<node> n, <number> w, <string> info, <string> dir)
3916 \stopfunctioncall
3918 This function creates a new hlist by packaging the list that begins at node \type
3919 {n} into a horizontal box. With only a single argument, this box is created using
3920 the natural width of its components. In the three argument form, \type {info}
3921 must be either \type {additional} or \type {exactly}, and \type {w} is the
3922 additional (\type {\hbox spread}) or exact (\type {\hbox to}) width to be used. The
3923 second return value is the badness of the generated box.
3925 Caveat: at this moment, there can be unexpected side|-|effects to this function,
3926 like updating some of the \type {\marks} and \type {\inserts}. Also note that the
3927 content of \type {h} is the original node list \type {n}: if you call \type
3928 {node.free(h)} you will also free the node list itself, unless you explicitly set
3929 the \type {list} field to \type {nil} beforehand. And in a similar way, calling
3930 \type {node.free(n)} will invalidate \type {h} as well!
3932 \subsubsection{\type {node.vpack}}
3934 \startfunctioncall
3935 <node> h, <number> b = node.vpack(<node> n)
3936 <node> h, <number> b = node.vpack(<node> n, <number> w, <string> info)
3937 <node> h, <number> b = node.vpack(<node> n, <number> w, <string> info, <string> dir)
3938 \stopfunctioncall
3940 This function creates a new vlist by packaging the list that begins at node \type
3941 {n} into a vertical box. With only a single argument, this box is created using
3942 the natural height of its components. In the three argument form, \type {info}
3943 must be either \type {additional} or \type {exactly}, and \type {w} is the
3944 additional (\type {\vbox spread}) or exact (\type {\vbox to}) height to be used.
3946 The second return value is the badness of the generated box.
3948 See the description of \type {node.hpack()} for a few memory allocation caveats.
3950 \subsubsection{\type {node.dimensions}}
3952 \startfunctioncall
3953 <number> w, <number> h, <number> d = node.dimensions(<node> n)
3954 <number> w, <number> h, <number> d = node.dimensions(<node> n, <string> dir)
3955 <number> w, <number> h, <number> d = node.dimensions(<node> n, <node> t)
3956 <number> w, <number> h, <number> d = node.dimensions(<node> n, <node> t, <string> dir)
3957 \stopfunctioncall
3959 This function calculates the natural in-line dimensions of the node list starting
3960 at node \type {n} and terminating just before node \type {t} (or the end of the
3961 list, if there is no second argument). The return values are scaled points. An
3962 alternative format that starts with glue parameters as the first three arguments
3963 is also possible:
3965 \startfunctioncall
3966 <number> w, <number> h, <number> d =
3967 node.dimensions(<number> glue_set, <number> glue_sign,
3968 <number> glue_order, <node> n)
3969 <number> w, <number> h, <number> d =
3970 node.dimensions(<number> glue_set, <number> glue_sign,
3971 <number> glue_order, <node> n, <string> dir)
3972 <number> w, <number> h, <number> d =
3973 node.dimensions(<number> glue_set, <number> glue_sign,
3974 <number> glue_order, <node> n, <node> t)
3975 <number> w, <number> h, <number> d =
3976 node.dimensions(<number> glue_set, <number> glue_sign,
3977 <number> glue_order, <node> n, <node> t, <string> dir)
3978 \stopfunctioncall
3980 This calling method takes glue settings into account and is especially useful for
3981 finding the actual width of a sublist of nodes that are already boxed, for
3982 example in code like this, which prints the width of the space in between the
3983 \type {a} and \type {b} as it would be if \type {\box0} was used as-is:
3985 \starttyping
3986 \setbox0 = \hbox to 20pt {a b}
3988 \directlua{print (node.dimensions(
3989 tex.box[0].glue_set,
3990 tex.box[0].glue_sign,
3991 tex.box[0].glue_order,
3992 tex.box[0].head.next,
3993 node.tail(tex.box[0].head)
3994 )) }
3995 \stoptyping
3997 \subsubsection{\type {node.mlist_to_hlist}}
3999 \startfunctioncall
4000 <node> h = node.mlist_to_hlist(<node> n,
4001 <string> display_type, <boolean> penalties)
4002 \stopfunctioncall
4004 This runs the internal mlist to hlist conversion, converting the math list in
4005 \type {n} into the horizontal list \type {h}. The interface is exactly the same
4006 as for the callback \type {mlist_to_hlist}.
4008 \subsubsection{\type {node.slide}}
4010 \startfunctioncall
4011 <node> m = node.slide(<node> n)
4012 \stopfunctioncall
4014 Returns the last node of the node list that starts at \type {n}. As a
4015 side|-|effect, it also creates a reverse chain of \type {prev} pointers between
4016 nodes.
4018 \subsubsection{\type {node.tail}}
4020 \startfunctioncall
4021 <node> m = node.tail(<node> n)
4022 \stopfunctioncall
4024 Returns the last node of the node list that starts at \type {n}.
4026 \subsubsection{\type {node.length}}
4028 \startfunctioncall
4029 <number> i = node.length(<node> n)
4030 <number> i = node.length(<node> n, <node> m)
4031 \stopfunctioncall
4033 Returns the number of nodes contained in the node list that starts at \type {n}.
4034 If \type {m} is also supplied it stops at \type {m} instead of at the end of the
4035 list. The node \type {m} is not counted.
4037 \subsubsection{\type {node.count}}
4039 \startfunctioncall
4040 <number> i = node.count(<number> id, <node> n)
4041 <number> i = node.count(<number> id, <node> n, <node> m)
4042 \stopfunctioncall
4044 Returns the number of nodes contained in the node list that starts at \type {n}
4045 that have a matching \type {id} field. If \type {m} is also supplied, counting
4046 stops at \type {m} instead of at the end of the list. The node \type {m} is not
4047 counted.
4049 This function also accept string \type {id}'s.
4051 \subsubsection{\type {node.traverse}}
4053 \startfunctioncall
4054 <node> t = node.traverse(<node> n)
4055 \stopfunctioncall
4057 This is a \LUA\ iterator that loops over the node list that starts at \type {n}.
4058 Typically code looks like this:
4060 \starttyping
4061 for n in node.traverse(head) do
4064 \stoptyping
4066 is functionally equivalent to:
4068 \starttyping
4070 local n
4071 local function f (head,var)
4072 local t
4073 if var == nil then
4074 t = head
4075 else
4076 t = var.next
4078 return t
4080 while true do
4081 n = f (head, n)
4082 if n == nil then break end
4086 \stoptyping
4088 It should be clear from the definition of the function \type {f} that even though
4089 it is possible to add or remove nodes from the node list while traversing, you
4090 have to take great care to make sure all the \type {next} (and \type {prev})
4091 pointers remain valid.
4093 If the above is unclear to you, see the section \quote {For Statement} in the
4094 \LUA\ Reference Manual.
4096 \subsubsection{\type {node.traverse_id}}
4098 \startfunctioncall
4099 <node> t = node.traverse_id(<number> id, <node> n)
4100 \stopfunctioncall
4102 This is an iterator that loops over all the nodes in the list that starts at
4103 \type {n} that have a matching \type {id} field.
4105 See the previous section for details. The change is in the local function \type
4106 {f}, which now does an extra while loop checking against the upvalue \type {id}:
4108 \starttyping
4109 local function f(head,var)
4110 local t
4111 if var == nil then
4112 t = head
4113 else
4114 t = var.next
4116 while not t.id == id do
4117 t = t.next
4119 return t
4121 \stoptyping
4123 \subsubsection{\type {node.end_of_math}}
4125 \startfunctioncall
4126 <node> t = node.end_of_math(<node> start)
4127 \stopfunctioncall
4129 Looks for and returns the next \type {math_node} following the \type {start}. If
4130 the given node is a math endnode this helper return that node, else it follows
4131 the list and return the next math endnote. If no such node is found nil is
4132 returned.
4134 \subsubsection{\type {node.remove}}
4136 \startfunctioncall
4137 <node> head, current = node.remove(<node> head, <node> current)
4138 \stopfunctioncall
4140 This function removes the node \type {current} from the list following \type
4141 {head}. It is your responsibility to make sure it is really part of that list.
4142 The return values are the new \type {head} and \type {current} nodes. The
4143 returned \type {current} is the node following the \type {current} in the calling
4144 argument, and is only passed back as a convenience (or \type {nil}, if there is
4145 no such node). The returned \type {head} is more important, because if the
4146 function is called with \type {current} equal to \type {head}, it will be
4147 changed.
4149 \subsubsection{\type {node.insert_before}}
4151 \startfunctioncall
4152 <node> head, new = node.insert_before(<node> head, <node> current, <node> new)
4153 \stopfunctioncall
4155 This function inserts the node \type {new} before \type {current} into the list
4156 following \type {head}. It is your responsibility to make sure that \type
4157 {current} is really part of that list. The return values are the (potentially
4158 mutated) \type {head} and the node \type {new}, set up to be part of the list
4159 (with correct \type {next} field). If \type {head} is initially \type {nil}, it
4160 will become \type {new}.
4162 \subsubsection{\type {node.insert_after}}
4164 \startfunctioncall
4165 <node> head, new = node.insert_after(<node> head, <node> current, <node> new)
4166 \stopfunctioncall
4168 This function inserts the node \type {new} after \type {current} into the list
4169 following \type {head}. It is your responsibility to make sure that \type
4170 {current} is really part of that list. The return values are the \type {head} and
4171 the node \type {new}, set up to be part of the list (with correct \type {next}
4172 field). If \type {head} is initially \type {nil}, it will become \type {new}.
4174 \subsubsection{\type {node.first_glyph}}
4176 \startfunctioncall
4177 <node> n = node.first_glyph(<node> n)
4178 <node> n = node.first_glyph(<node> n, <node> m)
4179 \stopfunctioncall
4181 Returns the first node in the list starting at \type {n} that is a glyph node
4182 with a subtype indicating it is a glyph, or \type {nil}. If \type {m} is given,
4183 processing stops at (but including) that node, otherwise processing stops at the
4184 end of the list.
4186 \subsubsection{\type {node.ligaturing}}
4188 \startfunctioncall
4189 <node> h, <node> t, <boolean> success = node.ligaturing(<node> n)
4190 <node> h, <node> t, <boolean> success = node.ligaturing(<node> n, <node> m)
4191 \stopfunctioncall
4193 Apply \TEX-style ligaturing to the specified nodelist. The tail node \type {m} is
4194 optional. The two returned nodes \type {h} and \type {t} are the new head and
4195 tail (both \type {n} and \type {m} can change into a new ligature).
4197 \subsubsection{\type {node.kerning}}
4199 \startfunctioncall
4200 <node> h, <node> t, <boolean> success = node.kerning(<node> n)
4201 <node> h, <node> t, <boolean> success = node.kerning(<node> n, <node> m)
4202 \stopfunctioncall
4204 Apply \TEX|-|style kerning to the specified node list. The tail node \type {m} is
4205 optional. The two returned nodes \type {h} and \type {t} are the head and tail
4206 (either one of these can be an inserted kern node, because special kernings with
4207 word boundaries are possible).
4209 \subsubsection{\type {node.unprotect_glyphs}}
4211 \startfunctioncall
4212 node.unprotect_glyphs(<node> n)
4213 \stopfunctioncall
4215 Subtracts 256 from all glyph node subtypes. This and the next function are
4216 helpers to convert from \type {characters} to \type {glyphs} during node
4217 processing.
4219 \subsubsection{\type {node.protect_glyphs}}
4221 \startfunctioncall
4222 node.protect_glyphs(<node> n)
4223 \stopfunctioncall
4225 Adds 256 to all glyph node subtypes in the node list starting at \type {n},
4226 except that if the value is 1, it adds only 255. The special handling of 1 means
4227 that \type {characters} will become \type {glyphs} after subtraction of 256.
4229 \subsubsection{\type {node.last_node}}
4231 \startfunctioncall
4232 <node> n = node.last_node()
4233 \stopfunctioncall
4235 This function pops the last node from \TEX's \quote{current list}. It returns
4236 that node, or \type {nil} if the current list is empty.
4238 \subsubsection{\type {node.write}}
4240 \startfunctioncall
4241 node.write(<node> n)
4242 \stopfunctioncall
4244 This is an experimental function that will append a node list to \TEX's \quote
4245 {current list} The node list is not deep|-|copied! There is no error checking
4246 either!
4248 \subsubsection{\type {node.protrusion_skippable}}
4249 \startfunctioncall
4250 <boolean> skippable = node.protrusion_skippable(<node> n)
4251 \stopfunctioncall
4253 Returns \type {true} if, for the purpose of line boundary discovery when
4254 character protrusion is active, this node can be skipped.
4256 \subsection{Attribute handling}
4258 Attributes appear as linked list of userdata objects in the \type {attr} field of
4259 individual nodes. They can be handled individually, but it is much safer and more
4260 efficient to use the dedicated functions associated with them.
4262 \subsubsection{\type {node.has_attribute}}
4264 \startfunctioncall
4265 <number> v = node.has_attribute(<node> n, <number> id)
4266 <number> v = node.has_attribute(<node> n, <number> id, <number> val)
4267 \stopfunctioncall
4269 Tests if a node has the attribute with number \type {id} set. If \type {val} is
4270 also supplied, also tests if the value matches \type {val}. It returns the value,
4271 or, if no match is found, \type {nil}.
4273 \subsubsection{\type {node.set_attribute}}
4275 \startfunctioncall
4276 node.set_attribute(<node> n, <number> id, <number> val)
4277 \stopfunctioncall
4279 Sets the attribute with number \type {id} to the value \type {val}. Duplicate
4280 assignments are ignored. {\em [needs explanation]}
4282 \subsubsection{\type {node.unset_attribute}}
4284 \startfunctioncall
4285 <number> v = node.unset_attribute(<node> n, <number> id)
4286 <number> v = node.unset_attribute(<node> n, <number> id, <number> val)
4287 \stopfunctioncall
4289 Unsets the attribute with number \type {id}. If \type {val} is also supplied, it
4290 will only perform this operation if the value matches \type {val}. Missing
4291 attributes or attribute|-|value pairs are ignored.
4293 If the attribute was actually deleted, returns its old value. Otherwise, returns
4294 \type {nil}.
4296 \section{The \type {pdf} library}
4298 This contains variables and functions that are related to the \PDF\ backend.
4300 \subsection{\type {pdf.mapfile}, \type {pdf.mapline}}
4302 \startfunctioncall
4303 pdf.mapfile(<string> map file)
4304 pdf.mapline(<string> map line)
4305 \stopfunctioncall
4307 These two functions can be used to replace primitives \type {\pdfmapfile} and
4308 \type {\pdfmapline} from \PDFTEX. They expect a string as only parameter and have
4309 no return value.
4311 The also functions replace the former variables \type {pdf.pdfmapfile} and
4312 \type {pdf.pdfmapline}.
4314 \subsection{\type {pdf.catalog}, \type {pdf.info},\type {pdf.names},
4315 \type {pdf.trailer}}
4317 These variables offer a read|-|write interface to the corresponding \PDFTEX\
4318 token lists. The value types are strings and they are written out to the \PDF\
4319 file directly after the \PDFTEX\ token registers.
4321 The preferred interface is now \type {pdf.setcatalog}, \type {pdf.setinfo}
4322 \type {pdf.setnames} and \type {pdf.settrailer} for setting these properties
4323 and \type {pdf.getcatalog}, \type {pdf.getinfo} \type {pdf.getnames} and
4324 \type {pdf.gettrailer} for querying them,
4326 The corresponding \quote {\type {pdf}} parameter names \type {pdf.pdfcatalog},
4327 \type {pdf.pdfinfo}, \type {pdf.pdfnames}, and \type {pdf.pdftrailer} are
4328 not available.
4330 \subsection{\type {pdf.<set/get>pageattributes}, \type {pdf.<set/get>pageresources},
4331 \type {pdf.<set/get>pagesattributes}}
4333 These variables offer a read|-|write interface to related token lists. The value
4334 types are strings. The variables have no interaction with the corresponding
4335 \PDFTEX\ token registers \type {\pdfpageattr}, \type {\pdfpageresources}, and \type
4336 {\pdfpagesattr}. They are written out to the \PDF\ file directly after the
4337 \PDFTEX\ token registers.
4339 The preferred interface is now \type {pdf.setpageattributes}, \type
4340 {pdf.setpagesattributes} and \type {pdf.setpageresources} for setting these
4341 properties and \type {pdf.getpageattributes}, \type {pdf.getpageattributes}
4342 and \type {pdf.getpageresources} for querying them.
4344 \subsection{\type {pdf.<set/get>xformattributes}, \type {pdf.<set/get>xformresources}}
4346 These variables offer a read|-|write interface to related token lists. The value
4347 types are strings. The variables have no interaction with the corresponding
4348 \PDFTEX\ token registers \type {\pdfxformattr} and \type {\pdfxformresources}. They
4349 are written out to the \PDF\ file directly after the \PDFTEX\ token registers.
4351 The preferred interface is now \type {pdf.setxformattributes} and \type
4352 {pdf.setxformattributes} for setting these properties and \type
4353 {pdf.getxformattributes} and \type {pdf.getxformresources} for querying them.
4355 \subsection{\type {pdf.setcompresslevel} and \type {pdf.setobjcompresslevel}}
4357 These two functions set the level of compression. The minimum valu sis~0,
4358 the maximum is~9.
4360 \subsection{\type {pdf.setdecimaldigits} and \type {pdf.getdecimaldigits}}
4362 These two functions set the accuracy of floats written to the \PDF file. You can
4363 set any value but the backend will not go below 3 and above 6.
4365 \subsection{\type {pdf.setpkresolution} and \type {pdf.getpkresolution}}
4367 These setter takes two arguments: the resolution and an optional zero or one that
4368 indicates if this is a fixed one. The getter returns these two values.
4370 \subsection{\type {pdf.lastobj}, \type {pdf.lastlink}, \type {pdf.lastannot},
4371 and \type {pdf.retval}}
4373 These status variables are similar to the ones traditionally used at the \TEX\
4374 end.
4376 \subsection{\type {pdf.setorigin}, \type {pdf.getorigin}}
4378 This one is used to set the horizonal and/or vertical offset (a traditional
4379 backend property).
4381 \starttyping
4382 pdf.setorigin() -- sets both to 0pt
4383 pdf.setorigin(tex.sp("1in")) -- sets both to 1in
4384 pdf.setorigin(tex.sp("1in"),tex.sp("1in"))
4385 \stoptyping
4387 The counterpart of this function returns two values.
4389 \subsection{\type {pdf.setlinkmargin}, \type {pdf.getlinkmargin} \type
4390 {pdf.setdestmargin}, \type {pdf.getdestmargin} \type {pdf.setthreadmargin},
4391 \type {pdf.getthreadmargin} \type {pdf.setxformmargin}, \type
4392 {pdf.getxformmargin}}
4394 These function can be used to set and retrieve the margins that are added to the
4395 natural bounding boxes of the respective objects.
4397 \subsection{\type {pdf.h}, \type {pdf.v}}
4399 These are the \type {h} and \type {v} values that define the current location on
4400 the output page, measured from its lower left corner. The values can be queried
4401 using scaled points as units.
4403 \starttyping
4404 local h = pdf.h
4405 local v = pdf.v
4406 \stoptyping
4408 \subsection{\type {pdf.getpos}, \type {pdf.gethpos}, \type {pdf.getvpos}}
4410 These are the function variants of \type {pdf.h} and \type {pdf.v}. Sometimes
4411 using a function is preferred over a key so this saves wrapping. Also, these
4412 functions are faster then the key based access, as \type {h} and \type {v} keys
4413 are not real variables but looked up using a metatable call. The \type {getpos}
4414 function returns two values, the other return one.
4416 \starttyping
4417 local h, v = pdf.getpos()
4418 \stoptyping
4420 \subsection{\type {pdf.hasmatrix}, \type {pdf.getmatrix}}
4422 The current matrix transformation is available via the \type {getmatrix} command,
4423 which returns 6 values: \type {sx}, \type {rx}, \type {ry}, \type {sy}, \type
4424 {tx}, and \type {ty}. The \type {hasmatrix} function returns \type {true} when a
4425 matrix is applied.
4427 \starttyping
4428 if pdf.hasmatrix() then
4429 local sx, rx, ry, sy, tx, ty = pdf.getmatrix()
4430 -- do something useful or not
4432 \stoptyping
4434 \subsection{\type {pdf.print}}
4436 A print function to write stuff to the \PDF\ document that can be used from
4437 within a \type {\latelua} argument. This function is not to be used inside
4438 \type {\directlua} unless you know {\it exactly} what you are doing.
4440 \startfunctioncall
4441 pdf.print(<string> s)
4442 pdf.print(<string> type, <string> s)
4443 \stopfunctioncall
4445 The optional parameter can be used to mimic the behavior of \type {\pdfliteral}:
4446 the \type {type} is \type {direct} or \type {page}.
4448 \subsection{\type {pdf.immediateobj}}
4450 This function creates a \PDF\ object and immediately writes it to the \PDF\ file.
4451 It is modelled after \PDFTEX's \type {\immediate} \type {\pdfobj} primitives. All
4452 function variants return the object number of the newly generated object.
4454 \startfunctioncall
4455 <number> n = pdf.immediateobj(<string> objtext)
4456 <number> n = pdf.immediateobj("file", <string> filename)
4457 <number> n = pdf.immediateobj("stream", <string> streamtext, <string> attrtext)
4458 <number> n = pdf.immediateobj("streamfile", <string> filename, <string> attrtext)
4459 \stopfunctioncall
4461 The first version puts the \type {objtext} raw into an object. Only the object
4462 wrapper is automatically generated, but any internal structure (like \type {<<
4463 >>} dictionary markers) needs to provided by the user. The second version with
4464 keyword \type {"file"} as 1st argument puts the contents of the file with name
4465 \type {filename} raw into the object. The third version with keyword \type
4466 {"stream"} creates a stream object and puts the \type {streamtext} raw into the
4467 stream. The stream length is automatically calculated. The optional \type
4468 {attrtext} goes into the dictionary of that object. The fourth version with
4469 keyword \type {"streamfile"} does the same as the 3rd one, it just reads the
4470 stream data raw from a file.
4472 An optional first argument can be given to make the function use a previously
4473 reserved \PDF\ object.
4475 \startfunctioncall
4476 <number> n = pdf.immediateobj(<integer> n, <string> objtext)
4477 <number> n = pdf.immediateobj(<integer> n, "file", <string> filename)
4478 <number> n = pdf.immediateobj(<integer> n, "stream", <string> streamtext, <string> attrtext)
4479 <number> n = pdf.immediateobj(<integer> n, "streamfile", <string> filename, <string> attrtext)
4480 \stopfunctioncall
4482 \subsection{\type {pdf.obj}}
4484 This function creates a \PDF\ object, which is written to the \PDF\ file only
4485 when referenced, e.g., by \type {pdf.refobj()}.
4487 All function variants return the object number of the newly generated object, and
4488 there are two separate calling modes.
4490 The first mode is modelled after \PDFTEX's \type {\pdfobj} primitive.
4492 \startfunctioncall
4493 <number> n = pdf.obj(<string> objtext)
4494 <number> n = pdf.obj("file", <string> filename)
4495 <number> n = pdf.obj("stream", <string> streamtext, <string> attrtext)
4496 <number> n = pdf.obj("streamfile", <string> filename, <string> attrtext)
4497 \stopfunctioncall
4499 An optional first argument can be given to make the function use a previously
4500 reserved \PDF\ object.
4502 \startfunctioncall
4503 <number> n = pdf.obj(<integer> n, <string> objtext)
4504 <number> n = pdf.obj(<integer> n, "file", <string> filename)
4505 <number> n = pdf.obj(<integer> n, "stream", <string> streamtext, <string> attrtext)
4506 <number> n = pdf.obj(<integer> n, "streamfile", <string> filename, <string> attrtext)
4507 \stopfunctioncall
4509 The second mode accepts a single argument table with key--value pairs.
4511 \startfunctioncall
4512 <number> n = pdf.obj {
4513 type = <string>,
4514 immmediate = <boolean>,
4515 objnum = <number>,
4516 attr = <string>,
4517 compresslevel = <number>,
4518 objcompression = <boolean>,
4519 file = <string>,
4520 string = <string>
4522 \stopfunctioncall
4524 The \type {type} field can have the values \type {raw} and \type {stream}, this
4525 field is required, the others are optional (within constraints).
4527 Note: this mode makes \type {pdf.obj} look more flexible than it actually is: the
4528 constraints from the separate parameter version still apply, so for example you
4529 can't have both \type {string} and \type {file} at the same time.
4531 \subsection{\type {pdf.refobj}}
4533 This function, the \LUA\ version of the \type {\pdfrefobj} primitive, references an
4534 object by its object number, so that the object will be written out.
4536 \startfunctioncall
4537 pdf.refobj(<integer> n)
4538 \stopfunctioncall
4540 This function works in both the \type {\directlua} and \type {\latelua} environment.
4541 Inside \type {\directlua} a new whatsit node \quote {pdf_refobj} is created, which
4542 will be marked for flushing during page output and the object is then written
4543 directly after the page, when also the resources objects are written out. Inside
4544 \type {\latelua} the object will be marked for flushing.
4546 This function has no return values.
4548 \subsection{\type {pdf.reserveobj}}
4550 This function creates an empty \PDF\ object and returns its number.
4552 \startfunctioncall
4553 <number> n = pdf.reserveobj()
4554 <number> n = pdf.reserveobj("annot")
4555 \stopfunctioncall
4557 \subsection{\type {pdf.registerannot}}
4559 This function adds an object number to the \type {/Annots} array for the current
4560 page without doing anything else. This function can only be used from within
4561 \type {\latelua}.
4563 \startfunctioncall
4564 pdf.registerannot (<number> objnum)
4565 \stopfunctioncall
4567 \subsection{\type {pdf.newcolorstack}}
4569 This function allocates a new color stack and returns it's id. The arguments
4570 are the same as for the similar backend extension primitive.
4572 \startfunctioncall
4573 pdf.newcolorstack("0 g","page",true) -- page|direct|origin
4574 \stopfunctioncall
4576 \section{The \type {pdfscanner} library}
4578 The \type {pdfscanner} library allows interpretation of PDF content streams and
4579 \type {/ToUnicode} (cmap) streams. You can get those streams from the \type
4580 {epdf} library, as explained in an earlier section. There is only a single
4581 top|-|level function in this library:
4583 \startfunctioncall
4584 pdfscanner.scan (<Object> stream, <table> operatortable, <table> info)
4585 \stopfunctioncall
4587 The first argument, \type {stream}, should be either a PDF stream object, or a
4588 PDF array of PDF stream objects (those options comprise the possible return
4589 values of \type {<Page>:getContents()} and \type {<Object>:getStream()} in the
4590 \type {epdf} library).
4592 The second argument, \type {operatortable}, should be a Lua table where the keys
4593 are PDF operator name strings and the values are Lua functions (defined by you)
4594 that are used to process those operators. The functions are called whenever the
4595 scanner finds one of these PDF operators in the content stream(s). The functions
4596 are called with two arguments: the \type {scanner} object itself, and the \type
4597 {info} table that was passed are the third argument to \type {pdfscanner.scan}.
4599 Internally, \type {pdfscanner.scan} loops over the PDF operators in the
4600 stream(s), collecting operands on an internal stack until it finds a PDF
4601 operator. If that PDF operator's name exists in \type {operatortable}, then the
4602 associated function is executed. After the function has run (or when there is no
4603 function to execute) the internal operand stack is cleared in preparation for the
4604 next operator, and processing continues.
4606 The \type {scanner} argument to the processing functions is needed because it
4607 offers various methods to get the actual operands from the internal operand
4608 stack.
4610 A simple example of processing a PDF's document stream could look like this:
4612 \starttyping
4613 function Do (scanner, info)
4614 local val = scanner:pop()
4615 local name = val[2] -- val[1] == 'name'
4616 local resources = info.resources
4617 local xobject = resources:lookup("XObject"):getDict():lookup(name)
4618 print (info.space ..'Use XObject '.. name)
4619 if xobject and xobject:isStream() then
4620 local dict = xobject:getStream():getDict()
4621 if dict then
4622 local name = dict:lookup("Subtype")
4623 if name:getName() == "Form" then
4624 local newinfo = {
4625 space = info.space .. " " ,
4626 resources = dict:lookup("Resources"):getDict()
4628 pdfscanner.scan(xobject, operatortable, newinfo)
4634 operatortable = { Do = Do }
4636 doc = epdf.open(arg[1])
4637 pagenum = 1
4639 while pagenum <= doc:getNumPages() do
4640 local page = doc:getCatalog():getPage(pagenum)
4641 local info = {
4642 space = " " ,
4643 resources = page:getResourceDict()
4645 print('Page ' .. pagenum)
4646 pdfscanner.scan(page:getContents(), operatortable, info)
4647 pagenum = pagenum + 1
4649 \stoptyping
4651 This example iterates over all the actual content in the PDF, and prints out the
4652 found XObject names. While the code demonstrates quite some of the \type {epdf}
4653 functions, let's focus on the type \type {pdfscanner} specific code instead.
4655 From the bottom up, the line
4657 \starttyping
4658 pdfscanner.scan(page:getContents(), operatortable, info)
4659 \stoptyping
4661 runs the scanner with the PDF page's top-level content.
4663 The third argument, \type {info}, contains two entries: \type {space} is used to
4664 indent the printed output, and \type {resources} is needed so that embedded \type
4665 {XForms} can find their own content.
4667 The second argument, \type {operatortable} defines a processing function for a
4668 single PDF operator, \type {Do}.
4670 The function \type {Do} prints the name of the current XObject, and then starts a
4671 new scanner for that object's content stream, under the condition that the
4672 XObject is in fact a \type {/Form}. That nested scanner is called with new \type
4673 {info} argument with an updated \type {space} value so that the indentation of
4674 the output nicely nests, and with an new \type {resources} field to help the next
4675 iteration down to properly process any other, embedded XObjects.
4677 Of course, this is not a very useful example in practise, but for the purpose of
4678 demonstrating \type {pdfscanner}, it is just long enough. It makes use of only
4679 one \type {scanner} method: \type {scanner:pop()}. That function pops the top
4680 operand of the internal stack, and returns a \LUA\ table where the object at index
4681 one is a string representing the type of the operand, and object two is its
4682 value.
4684 The list of possible operand types and associated \LUA\ value types is:
4686 \starttabulate[|lT|p|]
4687 \NC integer \NC <number> \NC \NR
4688 \NC real \NC <number> \NC \NR
4689 \NC boolean \NC <boolean> \NC \NR
4690 \NC name \NC <string> \NC \NR
4691 \NC operator \NC <string> \NC \NR
4692 \NC string \NC <string> \NC \NR
4693 \NC array \NC <table> \NC \NR
4694 \NC dict \NC <table> \NC \NR
4695 \stoptabulate
4697 In case of \type {integer} or \type {real}, the value is always a \LUA\ (floating
4698 point) number.
4700 In case of \type {name}, the leading slash is always stripped.
4702 In case of \type {string}, please bear in mind that PDF actually supports
4703 different types of strings (with different encodings) in different parts of the
4704 PDF document, so may need to reencode some of the results; \type {pdfscanner}
4705 always outputs the byte stream without reencoding anything. \type {pdfscanner}
4706 does not differentiate between literal strings and hexadecimal strings (the
4707 hexadecimal values are decoded), and it treats the stream data for inline images
4708 as a string that is the single operand for \type {EI}.
4710 In case of \type {array}, the table content is a list of \type {pop} return
4711 values.
4713 In case of \type {dict}, the table keys are PDF name strings and the values are
4714 \type {pop} return values.
4716 \blank
4718 There are few more methods defined that you can ask \type {scanner}:
4720 \starttabulate[|lT|p|]
4721 \NC pop \NC as explained above \NC \NR
4722 \NC popNumber \NC return only the value of a \type {real} or \type {integer} \NC \NR
4723 \NC popName \NC return only the value of a \type {name} \NC \NR
4724 \NC popString \NC return only the value of a \type {string} \NC \NR
4725 \NC popArray \NC return only the value of a \type {array} \NC \NR
4726 \NC popDict \NC return only the value of a \type {dict} \NC \NR
4727 \NC popBool \NC return only the value of a \type {boolean} \NC \NR
4728 \NC done \NC abort further processing of this \type {scan()} call \NC \NR
4729 \stoptabulate
4731 The \type {popXXX} are convenience functions, and come in handy when you know the
4732 type of the operands beforehand (which you usually do, in PDF). For example, the
4733 \type {Do} function could have used \type {local name = scanner:popName()}
4734 instead, because the single operand to the \type {Do} operator is always a PDF
4735 name object.
4737 The \type {done} function allows you to abort processing of a stream once you
4738 have learned everything you want to learn. This comes in handy while parsing
4739 \type {/ToUnicode}, because there usually is trailing garbage that you are not
4740 interested in. Without \type {done}, processing only end at the end of the
4741 stream, possibly wasting CPU cycles.
4743 \section{The \type {status} library}
4745 This contains a number of run|-|time configuration items that you may find useful
4746 in message reporting, as well as an iterator function that gets all of the names
4747 and values as a table.
4749 \startfunctioncall
4750 <table> info = status.list()
4751 \stopfunctioncall
4753 The keys in the table are the known items, the value is the current value. Almost
4754 all of the values in \type {status} are fetched through a metatable at run|-|time
4755 whenever they are accessed, so you cannot use \type {pairs} on \type {status},
4756 but you {\it can\/} use \type {pairs} on \type {info}, of course. If you do not
4757 need the full list, you can also ask for a single item by using its name as an
4758 index into \type {status}.
4760 The current list is:
4762 \starttabulate[|lT|p|]
4763 \NC \ssbf key \NC \bf explanation \NC \NR
4764 \NC pdf_gone \NC written \PDF\ bytes \NC \NR
4765 \NC pdf_ptr \NC not yet written \PDF\ bytes \NC \NR
4766 \NC dvi_gone \NC written \DVI\ bytes \NC \NR
4767 \NC dvi_ptr \NC not yet written \DVI\ bytes \NC \NR
4768 \NC total_pages \NC number of written pages \NC \NR
4769 \NC output_file_name \NC name of the \PDF\ or \DVI\ file \NC \NR
4770 \NC log_name \NC name of the log file \NC \NR
4771 \NC banner \NC terminal display banner \NC \NR
4772 \NC var_used \NC variable (one|-|word) memory in use \NC \NR
4773 \NC dyn_used \NC token (multi|-|word) memory in use \NC \NR
4774 \NC str_ptr \NC number of strings \NC \NR
4775 \NC init_str_ptr \NC number of \INITEX\ strings \NC \NR
4776 \NC max_strings \NC maximum allowed strings \NC \NR
4777 \NC pool_ptr \NC string pool index \NC \NR
4778 \NC init_pool_ptr \NC \INITEX\ string pool index \NC \NR
4779 \NC pool_size \NC current size allocated for string characters \NC \NR
4780 \NC node_mem_usage \NC a string giving insight into currently used nodes \NC \NR
4781 \NC var_mem_max \NC number of allocated words for nodes \NC \NR
4782 \NC fix_mem_max \NC number of allocated words for tokens \NC \NR
4783 \NC fix_mem_end \NC maximum number of used tokens \NC \NR
4784 \NC cs_count \NC number of control sequences \NC \NR
4785 \NC hash_size \NC size of hash \NC \NR
4786 \NC hash_extra \NC extra allowed hash \NC \NR
4787 \NC font_ptr \NC number of active fonts \NC \NR
4788 \NC input_ptr \NC th elevel of input we're at \NC \NR
4789 \NC max_in_stack \NC max used input stack entries \NC \NR
4790 \NC max_nest_stack \NC max used nesting stack entries \NC \NR
4791 \NC max_param_stack \NC max used parameter stack entries \NC \NR
4792 \NC max_buf_stack \NC max used buffer position \NC \NR
4793 \NC max_save_stack \NC max used save stack entries \NC \NR
4794 \NC stack_size \NC input stack size \NC \NR
4795 \NC nest_size \NC nesting stack size \NC \NR
4796 \NC param_size \NC parameter stack size \NC \NR
4797 \NC buf_size \NC current allocated size of the line buffer \NC \NR
4798 \NC save_size \NC save stack size \NC \NR
4799 \NC obj_ptr \NC max \PDF\ object pointer \NC \NR
4800 \NC obj_tab_size \NC \PDF\ object table size \NC \NR
4801 \NC pdf_os_cntr \NC max \PDF\ object stream pointer \NC \NR
4802 \NC pdf_os_objidx \NC \PDF\ object stream index \NC \NR
4803 \NC pdf_dest_names_ptr \NC max \PDF\ destination pointer \NC \NR
4804 \NC dest_names_size \NC \PDF\ destination table size \NC \NR
4805 \NC pdf_mem_ptr \NC max \PDF\ memory used \NC \NR
4806 \NC pdf_mem_size \NC \PDF\ memory size \NC \NR
4807 \NC largest_used_mark \NC max referenced marks class \NC \NR
4808 \NC filename \NC name of the current input file \NC \NR
4809 \NC inputid \NC numeric id of the current input \NC \NR
4810 \NC linenumber \NC location in the current input file \NC \NR
4811 \NC lasterrorstring \NC last \TEX\ error string \NC \NR
4812 \NC lastluaerrorstring \NC last \LUA\ error string \NC \NR
4813 \NC lastwarningtag \NC last warning string\NC \NR
4814 \NC lastwarningstring \NC last warning tag, normally an indication of in what part\NC \NR
4815 \NC lasterrorcontext \NC last error context string (with newlines) \NC \NR
4816 \NC luabytecodes \NC number of active \LUA\ bytecode registers \NC \NR
4817 \NC luabytecode_bytes \NC number of bytes in \LUA\ bytecode registers \NC \NR
4818 \NC luastate_bytes \NC number of bytes in use by \LUA\ interpreters \NC \NR
4819 \NC output_active \NC \type {true} if the \type {\output} routine is active \NC \NR
4820 \NC callbacks \NC total number of executed callbacks so far \NC \NR
4821 \NC indirect_callbacks \NC number of those that were themselves
4822 a result of other callbacks (e.g. file readers) \NC \NR
4823 \NC luatex_version \NC the \LUATEX\ version number \NC \NR
4824 \NC luatex_revision \NC the \LUATEX\ revision string \NC \NR
4825 \NC ini_version \NC \type {true} if this is an \INITEX\ run \NC \NR
4826 \NC shell_escape \NC \type {0} means disabled, \type {1} is restricted and
4827 \type {2} means anything is permitted \NC \NR
4828 \stoptabulate
4830 The error and warning messages can be wiped with the \type {resetmessages}
4831 function.
4833 \section{The \type {tex} library}
4835 The \type {tex} table contains a large list of virtual internal \TEX\
4836 parameters that are partially writable.
4838 The designation \quote {virtual} means that these items are not properly defined
4839 in \LUA, but are only front\-ends that are handled by a metatable that operates
4840 on the actual \TEX\ values. As a result, most of the \LUA\ table operators (like
4841 \type {pairs} and \type {#}) do not work on such items.
4843 At the moment, it is possible to access almost every parameter that has these
4844 characteristics:
4846 \startitemize[packed]
4847 \item You can use it after \type {\the}
4848 \item It is a single token.
4849 \item Some special others, see the list below
4850 \stopitemize
4852 This excludes parameters that need extra arguments, like \type {\the\scriptfont}.
4854 The subset comprising simple integer and dimension registers are
4855 writable as well as readable (stuff like \type {\tracingcommands} and
4856 \type {\parindent}).
4858 \subsection{Internal parameter values}
4860 For all the parameters in this section, it is possible to access them directly
4861 using their names as index in the \type {tex} table, or by using one of the
4862 functions \type {tex.get} and \type {tex.set}. If you created aliasses,
4863 you can use accessors like \type {tex.getdimen} as these also understand
4864 names of built|-|in variables.
4866 The exact parameters and return values differ depending on the actual parameter,
4867 and so does whether \type {tex.set} has any effect. For the parameters that {\it
4868 can\/} be set, it is possible to use \type {global} as the first argument to
4869 \type {tex.set}; this makes the assignment global instead of local.
4871 \startfunctioncall
4872 tex.set (<string> n, ...)
4873 tex.set ("global", <string> n, ...)
4874 ... = tex.get (<string> n)
4875 \stopfunctioncall
4877 There are also dedicated setters, getters and checkers:
4879 \startfunctioncall
4880 local d = tex.getdimen("foo")
4881 if tex.isdimen("bar") then
4882 tex.setdimen("bar",d)
4884 \stopfunctioncall
4886 There are such helpers for \type {dimen}, \type {count}, \type {skip}, \type
4887 {box} and \type {attribute} registers.
4889 \subsubsection{Integer parameters}
4891 The integer parameters accept and return \LUA\ numbers.
4893 Read|-|write:
4895 \starttwocolumns
4896 \starttyping
4897 tex.adjdemerits
4898 tex.binoppenalty
4899 tex.brokenpenalty
4900 tex.catcodetable
4901 tex.clubpenalty
4902 tex.day
4903 tex.defaulthyphenchar
4904 tex.defaultskewchar
4905 tex.delimiterfactor
4906 tex.displaywidowpenalty
4907 tex.doublehyphendemerits
4908 tex.endlinechar
4909 tex.errorcontextlines
4910 tex.escapechar
4911 tex.exhyphenpenalty
4912 tex.fam
4913 tex.finalhyphendemerits
4914 tex.floatingpenalty
4915 tex.globaldefs
4916 tex.hangafter
4917 tex.hbadness
4918 tex.holdinginserts
4919 tex.hyphenpenalty
4920 tex.interlinepenalty
4921 tex.language
4922 tex.lastlinefit
4923 tex.lefthyphenmin
4924 tex.linepenalty
4925 tex.localbrokenpenalty
4926 tex.localinterlinepenalty
4927 tex.looseness
4928 tex.mag
4929 tex.maxdeadcycles
4930 tex.month
4931 tex.newlinechar
4932 tex.outputpenalty
4933 tex.pausing
4934 tex.postdisplaypenalty
4935 tex.predisplaydirection
4936 tex.predisplaypenalty
4937 tex.pretolerance
4938 tex.relpenalty
4939 tex.righthyphenmin
4940 tex.savinghyphcodes
4941 tex.savingvdiscards
4942 tex.showboxbreadth
4943 tex.showboxdepth
4944 tex.time
4945 tex.tolerance
4946 tex.tracingassigns
4947 tex.tracingcommands
4948 tex.tracinggroups
4949 tex.tracingifs
4950 tex.tracinglostchars
4951 tex.tracingmacros
4952 tex.tracingnesting
4953 tex.tracingonline
4954 tex.tracingoutput
4955 tex.tracingpages
4956 tex.tracingparagraphs
4957 tex.tracingrestores
4958 tex.tracingscantokens
4959 tex.tracingstats
4960 tex.uchyph
4961 tex.vbadness
4962 tex.widowpenalty
4963 tex.year
4964 \stoptyping
4965 \stoptwocolumns
4967 Read|-|only:
4969 \startthreecolumns
4970 \starttyping
4971 tex.deadcycles
4972 tex.insertpenalties
4973 tex.parshape
4974 tex.prevgraf
4975 tex.spacefactor
4976 \stoptyping
4977 \stopthreecolumns
4979 \subsubsection{Dimension parameters}
4981 The dimension parameters accept \LUA\ numbers (signifying scaled points) or
4982 strings (with included dimension). The result is always a number in scaled
4983 points.
4985 Read|-|write:
4987 \startthreecolumns
4988 \starttyping
4989 tex.boxmaxdepth
4990 tex.delimitershortfall
4991 tex.displayindent
4992 tex.displaywidth
4993 tex.emergencystretch
4994 tex.hangindent
4995 tex.hfuzz
4996 tex.hoffset
4997 tex.hsize
4998 tex.lineskiplimit
4999 tex.mathsurround
5000 tex.maxdepth
5001 tex.nulldelimiterspace
5002 tex.overfullrule
5003 tex.pagebottomoffset
5004 tex.pageheight
5005 tex.pageleftoffset
5006 tex.pagerightoffset
5007 tex.pagetopoffset
5008 tex.pagewidth
5009 tex.parindent
5010 tex.predisplaysize
5011 tex.scriptspace
5012 tex.splitmaxdepth
5013 tex.vfuzz
5014 tex.voffset
5015 tex.vsize
5016 tex.prevdepth
5017 tex.prevgraf
5018 tex.spacefactor
5019 \stoptyping
5020 \stopthreecolumns
5022 Read|-|only:
5024 \startthreecolumns
5025 \starttyping
5026 tex.pagedepth
5027 tex.pagefilllstretch
5028 tex.pagefillstretch
5029 tex.pagefilstretch
5030 tex.pagegoal
5031 tex.pageshrink
5032 tex.pagestretch
5033 tex.pagetotal
5034 \stoptyping
5035 \stopthreecolumns
5037 Beware: as with all \LUA\ tables you can add values to them. So, the following is valid:
5039 \starttyping
5040 tex.foo = 123
5041 \stoptyping
5043 When you access a \TEX\ parameter a look up takes place. For read||only variables
5044 that means that you will get something back, but when you set them you create a
5045 new entry in the table thereby making the original invisible.
5047 There are a few special cases that we make an exception for: \type {prevdepth},
5048 \type {prevgraf} and \type {spacefactor}. These normally are accessed via the
5049 \type {tex.nest} table:
5051 \starttyping
5052 tex.nest[tex.nest.ptr].prevdepth = p
5053 tex.nest[tex.nest.ptr].spacefactor = s
5054 \stoptyping
5056 However, the following also works:
5058 \starttyping
5059 tex.prevdepth = p
5060 tex.spacefactor = s
5061 \stoptyping
5063 Keep in mind that when you mess with node lists directly at the \LUA\ end you
5064 might need to update the top of the nesting stack's \type {prevdepth} explicitly
5065 as there is no way \LUATEX\ can guess your intentions. By using the accessor in
5066 the \type {tex} tables, you get and set the values atthe top of the nest stack.
5068 \subsubsection{Direction parameters}
5070 The direction parameters are read|-|only and return a \LUA\ string.
5072 \startthreecolumns
5073 \starttyping
5074 tex.bodydir
5075 tex.mathdir
5076 tex.pagedir
5077 tex.pardir
5078 tex.textdir
5079 \stoptyping
5080 \stopthreecolumns
5082 \subsubsection{Glue parameters}
5084 The glue parameters accept and return a userdata object that represents a \type
5085 {glue_spec} node.
5087 \startthreecolumns
5088 \starttyping
5089 tex.abovedisplayshortskip
5090 tex.abovedisplayskip
5091 tex.baselineskip
5092 tex.belowdisplayshortskip
5093 tex.belowdisplayskip
5094 tex.leftskip
5095 tex.lineskip
5096 tex.parfillskip
5097 tex.parskip
5098 tex.rightskip
5099 tex.spaceskip
5100 tex.splittopskip
5101 tex.tabskip
5102 tex.topskip
5103 tex.xspaceskip
5104 \stoptyping
5105 \stopthreecolumns
5107 \subsubsection{Muglue parameters}
5109 All muglue parameters are to be used read|-|only and return a \LUA\ string.
5111 \startthreecolumns
5112 \starttyping
5113 tex.medmuskip
5114 tex.thickmuskip
5115 tex.thinmuskip
5116 \stoptyping
5117 \stopthreecolumns
5119 \subsubsection{Tokenlist parameters}
5121 The tokenlist parameters accept and return \LUA\ strings. \LUA\ strings are
5122 converted to and from token lists using \type {\the} \type {\toks} style expansion:
5123 all category codes are either space (10) or other (12). It follows that assigning
5124 to some of these, like \quote {tex.output}, is actually useless, but it feels bad
5125 to make exceptions in view of a coming extension that will accept full|-|blown
5126 token strings.
5128 \startthreecolumns
5129 \starttyping
5130 tex.errhelp
5131 tex.everycr
5132 tex.everydisplay
5133 tex.everyeof
5134 tex.everyhbox
5135 tex.everyjob
5136 tex.everymath
5137 tex.everypar
5138 tex.everyvbox
5139 tex.output
5140 tex.pdfpageattr
5141 tex.pdfpageresources
5142 tex.pdfpagesattr
5143 tex.pdfpkmode
5144 \stoptyping
5145 \stopthreecolumns
5147 \subsection{Convert commands}
5149 All \quote {convert} commands are read|-|only and return a \LUA\ string. The
5150 supported commands at this moment are:
5152 \starttwocolumns
5153 \starttyping
5154 tex.eTeXVersion
5155 tex.eTeXrevision
5156 tex.formatname
5157 tex.jobname
5158 tex.luatexbanner
5159 tex.luatexrevision
5160 tex.pdfnormaldeviate
5161 tex.fontname(number)
5162 tex.pdffontname(number)
5163 tex.pdffontobjnum(number)
5164 tex.pdffontsize(number)
5165 tex.uniformdeviate(number)
5166 tex.number(number)
5167 tex.romannumeral(number)
5168 tex.pdfpageref(number)
5169 tex.pdfxformname(number)
5170 tex.fontidentifier(number)
5171 \stoptyping
5172 \stoptwocolumns
5174 If you are wondering why this list looks haphazard; these are all the cases of
5175 the \quote {convert} internal command that do not require an argument, as well as
5176 the ones that require only a simple numeric value.
5178 The special (lua-only) case of \type {tex.fontidentifier} returns the \type
5179 {csname} string that matches a font id number (if there is one).
5181 if these are really needed in a macro package.
5183 \subsection{Last item commands}
5185 All \quote {last item} commands are read|-|only and return a number.
5187 The supported commands at this moment are:
5189 \startthreecolumns
5190 \starttyping
5191 tex.lastpenalty
5192 tex.lastkern
5193 tex.lastskip
5194 tex.lastnodetype
5195 tex.inputlineno
5196 tex.pdflastobj
5197 tex.pdflastxform
5198 tex.pdflastximage
5199 tex.pdflastximagepages
5200 tex.pdflastannot
5201 tex.pdflastxpos
5202 tex.pdflastypos
5203 tex.pdfrandomseed
5204 tex.pdflastlink
5205 tex.luatexversion
5206 tex.eTeXminorversion
5207 tex.eTeXversion
5208 tex.currentgrouplevel
5209 tex.currentgrouptype
5210 tex.currentiflevel
5211 tex.currentiftype
5212 tex.currentifbranch
5213 tex.pdflastximagecolordepth
5214 \stoptyping
5215 \stopthreecolumns
5217 \subsection{Attribute, count, dimension, skip and token registers}
5219 \TEX's attributes (\type {\attribute}), counters (\type {\count}), dimensions (\type
5220 {\dimen}), skips (\type {\skip}) and token (\type {\toks}) registers can be accessed
5221 and written to using two times five virtual sub|-|tables of the \type {tex}
5222 table:
5224 \startthreecolumns
5225 \starttyping
5226 tex.attribute
5227 tex.count
5228 tex.dimen
5229 tex.skip
5230 tex.toks
5231 \stoptyping
5232 \stopthreecolumns
5234 It is possible to use the names of relevant \type {\attributedef}, \type {\countdef},
5235 \type {\dimendef}, \type {\skipdef}, or \type {\toksdef} control sequences as indices
5236 to these tables:
5238 \starttyping
5239 tex.count.scratchcounter = 0
5240 enormous = tex.dimen['maxdimen']
5241 \stoptyping
5243 In this case, \LUATEX\ looks up the value for you on the fly. You have to use a
5244 valid \type {\countdef} (or \type {\attributedef}, or \type {\dimendef}, or \type
5245 {\skipdef}, or \type {\toksdef}), anything else will generate an error (the intent
5246 is to eventually also allow \type {<chardef tokens>} and even macros that expand
5247 into a number).
5249 The attribute and count registers accept and return \LUA\ numbers.
5251 The dimension registers accept \LUA\ numbers (in scaled points) or strings (with
5252 an included absolute dimension; \type {em} and \type {ex} and \type {px} are
5253 forbidden). The result is always a number in scaled points.
5255 The token registers accept and return \LUA\ strings. \LUA\ strings are converted
5256 to and from token lists using \type {\the} \type {\toks} style expansion: all
5257 category codes are either space (10) or other (12).
5259 The skip registers accept and return \type {glue_spec} userdata node objects (see
5260 the description of the node interface elsewhere in this manual).
5262 As an alternative to array addressing, there are also accessor functions defined
5263 for all cases, for example, here is the set of possibilities for \type {\skip}
5264 registers:
5266 \startfunctioncall
5267 tex.setskip (<number> n, <node> s)
5268 tex.setskip (<string> s, <node> s)
5269 tex.setskip ('global',<number> n, <node> s)
5270 tex.setskip ('global',<string> s, <node> s)
5271 <node> s = tex.getskip (<number> n)
5272 <node> s = tex.getskip (<string> s)
5273 \stopfunctioncall
5275 We have similar setters for \type {count}, \type {dimen}, \type {muskip}, and
5276 \type {toks}. Counters and dimen are represented by numbers, skips and muskips by
5277 nodes, and toks by strings. For tokens registers we have an alternative where a
5278 catcode table is specified:
5280 \startfunctioncall
5281 tex.scantoks(0,3,"$e=mc^2$")
5282 tex.scantoks("global",0,"$\int\limits^1_2$")
5283 \stopfunctioncall
5285 In the function-based interface, it is possible to define values globally by
5286 using the string \type {global} as the first function argument.
5288 \subsection{Character code registers}
5290 \TEX's character code tables (\type {\lccode}, \type {\uccode}, \type {\sfcode}, \type
5291 {\catcode}, \type {\mathcode}, \type {\delcode}) can be accessed and written to using
5292 six virtual subtables of the \type {tex} table
5294 \startthreecolumns
5295 \starttyping
5296 tex.lccode
5297 tex.uccode
5298 tex.sfcode
5299 tex.catcode
5300 tex.mathcode
5301 tex.delcode
5302 \stoptyping
5303 \stopthreecolumns
5305 The function call interfaces are roughly as above, but there are a few twists.
5306 \type {sfcode}s are the simple ones:
5308 \startfunctioncall
5309 tex.setsfcode (<number> n, <number> s)
5310 tex.setsfcode ('global', <number> n, <number> s)
5311 <number> s = tex.getsfcode (<number> n)
5312 \stopfunctioncall
5314 The function call interface for \type {lccode} and \type {uccode} additionally
5315 allows you to set the associated sibling at the same time:
5317 \startfunctioncall
5318 tex.setlccode (['global'], <number> n, <number> lc)
5319 tex.setlccode (['global'], <number> n, <number> lc, <number> uc)
5320 <number> lc = tex.getlccode (<number> n)
5321 tex.setuccode (['global'], <number> n, <number> uc)
5322 tex.setuccode (['global'], <number> n, <number> uc, <number> lc)
5323 <number> uc = tex.getuccode (<number> n)
5324 \stopfunctioncall
5326 The function call interface for \type {catcode} also allows you to specify a
5327 category table to use on assignment or on query (default in both cases is the
5328 current one):
5330 \startfunctioncall
5331 tex.setcatcode (['global'], <number> n, <number> c)
5332 tex.setcatcode (['global'], <number> cattable, <number> n, <number> c)
5333 <number> lc = tex.getcatcode (<number> n)
5334 <number> lc = tex.getcatcode (<number> cattable, <number> n)
5335 \stopfunctioncall
5337 The interfaces for \type {delcode} and \type {mathcode} use small array tables to
5338 set and retrieve values:
5340 \startfunctioncall
5341 tex.setmathcode (['global'], <number> n, <table> mval )
5342 <table> mval = tex.getmathcode (<number> n)
5343 tex.setdelcode (['global'], <number> n, <table> dval )
5344 <table> dval = tex.getdelcode (<number> n)
5345 \stopfunctioncall
5347 Where the table for \type {mathcode} is an array of 3 numbers, like this:
5349 \starttyping
5350 {<number> mathclass, <number> family, <number> character}
5351 \stoptyping
5353 And the table for \type {delcode} is an array with 4 numbers, like this:
5355 \starttyping
5356 {<number> small_fam, <number> small_char, <number> large_fam, <number> large_char}
5357 \stoptyping
5359 You can also avoid the table:
5361 \startfunctioncall
5362 class, family, char = tex.getmathcodes (<number> n)
5363 smallfam, smallchar, largefam, largechar = tex.getdelcodes (<number> n)
5364 \stopfunctioncall
5366 Normally, the third and fourth values in a delimiter code assignment will be zero
5367 according to \type {\Udelcode} usage, but the returned table can have values there
5368 (if the delimiter code was set using \type {\delcode}, for example). Unset \type
5369 {delcode}'s can be recognized because \type {dval[1]} is $-1$.
5371 \subsection{Box registers}
5373 It is possible to set and query actual boxes, using the node interface as defined
5374 in the \type {node} library:
5376 \starttyping
5377 tex.box
5378 \stoptyping
5380 for array access, or
5382 \starttyping
5383 tex.setbox(<number> n, <node> s)
5384 tex.setbox(<string> cs, <node> s)
5385 tex.setbox('global', <number> n, <node> s)
5386 tex.setbox('global', <string> cs, <node> s)
5387 <node> n = tex.getbox(<number> n)
5388 <node> n = tex.getbox(<string> cs)
5389 \stoptyping
5391 for function|-|based access. In the function-based interface, it is possible to
5392 define values globally by using the string \type {global} as the first function
5393 argument.
5395 Be warned that an assignment like
5397 \starttyping
5398 tex.box[0] = tex.box[2]
5399 \stoptyping
5401 does not copy the node list, it just duplicates a node pointer. If \type {\box2}
5402 will be cleared by \TEX\ commands later on, the contents of \type {\box0} becomes
5403 invalid as well. To prevent this from happening, always use \type
5404 {node.copy_list()} unless you are assigning to a temporary variable:
5406 \starttyping
5407 tex.box[0] = node.copy_list(tex.box[2])
5408 \stoptyping
5410 The following function will register a box for reuse (this is modelled after so
5411 called xforms in \PDF). You can (re)use the box with \type {\useboxresource} or
5412 by creating a rule node with subtype~2.
5414 \starttyping
5415 local index = tex.saveboxresource(n,attributes,resources,immediate)
5416 \stoptyping
5418 The optional second and third arguments are strings, the fourth is a boolean.
5420 You can generate the reference (a rule type) with:
5422 \starttyping
5423 local reused = tex.useboxresource(n,wd,ht,dp)
5424 \stoptyping
5426 The dimensions are optional and the final ones are returned as extra values. The
5427 following is just a bonus (no dimensions returned means that the resource is
5428 unknown):
5430 \starttyping
5431 local w, h, d = tex.getboxresourcedimensions(n)
5432 \stoptyping
5434 You can split a box:
5436 \starttyping
5437 local vlist = tex.splitbox(n,height,mode)
5438 \stoptyping
5440 The remainder is kept in the original box and a packaged vlist is returned. This
5441 operation is comparable to the \type {\vsplit} operation. The mode can be \type
5442 {additional} or \type {exactly} and concerns the split off box.
5444 \subsection{Math parameters}
5446 It is possible to set and query the internal math parameters using:
5448 \startfunctioncall
5449 tex.setmath(<string> n, <string> t, <number> n)
5450 tex.setmath('global', <string> n, <string> t, <number> n)
5451 <number> n = tex.getmath(<string> n, <string> t)
5452 \stopfunctioncall
5454 As before an optional first parameter \type {global} indicates a global
5455 assignment.
5457 The first string is the parameter name minus the leading \quote {Umath}, and the
5458 second string is the style name minus the trailing \quote {style}.
5460 Just to be complete, the values for the math parameter name are:
5462 \starttyping
5463 quad axis operatorsize
5464 overbarkern overbarrule overbarvgap
5465 underbarkern underbarrule underbarvgap
5466 radicalkern radicalrule radicalvgap
5467 radicaldegreebefore radicaldegreeafter radicaldegreeraise
5468 stackvgap stacknumup stackdenomdown
5469 fractionrule fractionnumvgap fractionnumup
5470 fractiondenomvgap fractiondenomdown fractiondelsize
5471 limitabovevgap limitabovebgap limitabovekern
5472 limitbelowvgap limitbelowbgap limitbelowkern
5473 underdelimitervgap underdelimiterbgap
5474 overdelimitervgap overdelimiterbgap
5475 subshiftdrop supshiftdrop subshiftdown
5476 subsupshiftdown subtopmax supshiftup
5477 supbottommin supsubbottommax subsupvgap
5478 spaceafterscript connectoroverlapmin
5479 ordordspacing ordopspacing ordbinspacing ordrelspacing
5480 ordopenspacing ordclosespacing ordpunctspacing ordinnerspacing
5481 opordspacing opopspacing opbinspacing oprelspacing
5482 opopenspacing opclosespacing oppunctspacing opinnerspacing
5483 binordspacing binopspacing binbinspacing binrelspacing
5484 binopenspacing binclosespacing binpunctspacing bininnerspacing
5485 relordspacing relopspacing relbinspacing relrelspacing
5486 relopenspacing relclosespacing relpunctspacing relinnerspacing
5487 openordspacing openopspacing openbinspacing openrelspacing
5488 openopenspacing openclosespacing openpunctspacing openinnerspacing
5489 closeordspacing closeopspacing closebinspacing closerelspacing
5490 closeopenspacing closeclosespacing closepunctspacing closeinnerspacing
5491 punctordspacing punctopspacing punctbinspacing punctrelspacing
5492 punctopenspacing punctclosespacing punctpunctspacing punctinnerspacing
5493 innerordspacing inneropspacing innerbinspacing innerrelspacing
5494 inneropenspacing innerclosespacing innerpunctspacing innerinnerspacing
5495 \stoptyping
5497 The values for the style parameter name are:
5499 \starttyping
5500 display crampeddisplay
5501 text crampedtext
5502 script crampedscript
5503 scriptscript crampedscriptscript
5504 \stoptyping
5506 The value is either a number (representing a dimension or number) or a glue spec
5507 node representing a muskip for \type {ordordspacing} and similar spacing
5508 parameters.
5510 \subsection{Special list heads}
5512 The virtual table \type {tex.lists} contains the set of internal registers that
5513 keep track of building page lists.
5515 \starttabulate[|lT|p|]
5516 \NC \bf field \NC \bf description \NC \NR
5517 \NC page_ins_head \NC circular list of pending insertions \NC \NR
5518 \NC contrib_head \NC the recent contributions \NC \NR
5519 \NC page_head \NC the current page content \NC \NR
5520 %NC temp_head \NC \NC \NR
5521 \NC hold_head \NC used for held-over items for next page \NC \NR
5522 \NC adjust_head \NC head of the current \type {\vadjust} list \NC \NR
5523 \NC pre_adjust_head \NC head of the current \type {\vadjust pre} list \NC \NR
5524 %NC align_head \NC \NC \NR
5525 \NC page_discards_head \NC head of the discarded items of a page break \NC \NR
5526 \NC split_discards_head \NC head of the discarded items in a vsplit \NC \NR
5527 \stoptabulate
5529 \subsection{Semantic nest levels}
5531 The virtual table \type {tex.nest} contains the currently active
5532 semantic nesting state. It has two main parts: a zero-based array of userdata for
5533 the semantic nest itself, and the numerical value \type {tex.nest.ptr}, which
5534 gives the highest available index. Neither the array items in \type {tex.nest[]}
5535 nor \type {tex.nest.ptr} can be assigned to (as this would confuse the
5536 typesetting engine beyond repair), but you can assign to the individual values
5537 inside the array items, e.g.\ \type {tex.nest[tex.nest.ptr].prevdepth}.
5539 \type {tex.nest[tex.nest.ptr]} is the current nest state, \type {tex.nest[0]} the
5540 outermost (main vertical list) level.
5542 The known fields are:
5544 \starttabulate[|lT|l|l|p|]
5545 \NC \ssbf key \NC \bf type \NC \bf modes \NC \bf explanation \NC \NR
5546 \NC mode \NC number \NC all \NC The current mode. This is a number representing the
5547 main mode at this level:\crlf
5548 \type {0} == no mode (this happens during \type {\write})\crlf
5549 \type {1} == vertical,\crlf
5550 \type {127} = horizontal,\crlf
5551 \type {253} = display math.\crlf
5552 \type {-1} == internal vertical,\crlf
5553 \type {-127} = restricted horizontal,\crlf
5554 \type {-253} = inline math. \NC \NR
5555 \NC modeline \NC number \NC all \NC source input line where this mode was entered in,
5556 negative inside the output routine \NC \NR
5557 \NC head \NC node \NC all \NC the head of the current list \NC \NR
5558 \NC tail \NC node \NC all \NC the tail of the current list \NC \NR
5559 \NC prevgraf \NC number \NC vmode \NC number of lines in the previous paragraph \NC \NR
5560 \NC prevdepth \NC number \NC vmode \NC depth of the previous paragraph (equal to \type {\pdfignoreddimen}
5561 when it is to be ignored) \NC \NR
5562 \NC spacefactor \NC number \NC hmode \NC the current space factor \NC \NR
5563 \NC dirs \NC node \NC hmode \NC used for temporary storage by the line break algorithm\NC \NR
5564 \NC noad \NC node \NC mmode \NC used for temporary storage of a pending fraction numerator,
5565 for \type {\over} etc. \NC \NR
5566 \NC delimptr \NC node \NC mmode \NC used for temporary storage of the previous math delimiter,
5567 for \type {\middle} \NC \NR
5568 \NC mathdir \NC boolean \NC mmode \NC true when during math processing the \type {\mathdir} is not
5569 the same as the surrounding \type {\textdir} \NC \NR
5570 \NC mathstyle \NC number \NC mmode \NC the current \type {\mathstyle} \NC \NR
5571 \stoptabulate
5573 \subsection[sec:luaprint]{Print functions}
5575 The \type {tex} table also contains the three print functions that are the
5576 major interface from \LUA\ scripting to \TEX.
5578 The arguments to these three functions are all stored in an in|-|memory virtual
5579 file that is fed to the \TEX\ scanner as the result of the expansion of
5580 \type {\directlua}.
5582 The total amount of returnable text from a \type {\directlua} command is only
5583 limited by available system \RAM. However, each separate printed string has to
5584 fit completely in \TEX's input buffer.
5586 The result of using these functions from inside callbacks is undefined
5587 at the moment.
5589 \subsubsection{\type {tex.print}}
5591 \startfunctioncall
5592 tex.print(<string> s, ...)
5593 tex.print(<number> n, <string> s, ...)
5594 tex.print(<table> t)
5595 tex.print(<number> n, <table> t)
5596 \stopfunctioncall
5598 Each string argument is treated by \TEX\ as a separate input line. If there is a
5599 table argument instead of a list of strings, this has to be a consecutive array
5600 of strings to print (the first non-string value will stop the printing process).
5602 The optional parameter can be used to print the strings using the catcode regime
5603 defined by \type {\catcodetable}~\type {n}. If \type {n} is $-1$, the currently
5604 active catcode regime is used. If \type {n} is $-2$, the resulting catcodes are
5605 the result of \type {\the} \type {\toks}: all category codes are 12 (other) except for
5606 the space character, that has category code 10 (space). Otherwise, if \type {n}
5607 is not a valid catcode table, then it is ignored, and the currently active
5608 catcode regime is used instead.
5610 The very last string of the very last \type {tex.print()} command in a \type
5611 {\directlua} will not have the \type {\endlinechar} appended, all others do.
5613 \subsubsection{\type {tex.sprint}}
5615 \startfunctioncall
5616 tex.sprint(<string> s, ...)
5617 tex.sprint(<number> n, <string> s, ...)
5618 tex.sprint(<table> t)
5619 tex.sprint(<number> n, <table> t)
5620 \stopfunctioncall
5622 Each string argument is treated by \TEX\ as a special kind of input line that
5623 makes it suitable for use as a partial line input mechanism:
5625 \startitemize[packed]
5626 \startitem
5627 \TEX\ does not switch to the \quote {new line} state, so that leading spaces
5628 are not ignored.
5629 \stopitem
5630 \startitem
5631 No \type {\endlinechar} is inserted.
5632 \stopitem
5633 \startitem
5634 Trailing spaces are not removed.
5636 Note that this does not prevent \TEX\ itself from eating spaces as result of
5637 interpreting the line. For example, in
5639 \starttyping
5640 before\directlua{tex.sprint("\\relax")tex.sprint(" inbetween")}after
5641 \stoptyping
5642 the space before \type {in between} will be gobbled as a result of the \quote
5643 {normal} scanning of \type {\relax}.
5644 \stopitem
5645 \stopitemize
5647 If there is a table argument instead of a list of strings, this has to
5648 be a consecutive array of strings to print (the first non-string value
5649 will stop the printing process).
5651 The optional argument sets the catcode regime, as with \type {tex.print()}.
5653 \subsubsection{\type {tex.tprint}}
5655 \startfunctioncall
5656 tex.tprint({<number> n, <string> s, ...}, {...})
5657 \stopfunctioncall
5659 This function is basically a shortcut for repeated calls to \type
5660 {tex.sprint(<number> n, <string> s, ...)}, once for each of the supplied argument
5661 tables.
5663 \subsubsection{\type {tex.cprint}}
5665 This function takes a number indicating the to be used catcode, plus either a
5666 table of strings or an argument list of strings that will be pushed into the
5667 input stream.
5669 \startfunctioncall
5670 tex.cprint( 1," 1: $&{\\foo}") tex.print("\\par") -- a lot of \bgroup s
5671 tex.cprint( 2," 2: $&{\\foo}") tex.print("\\par") -- matching \egroup s
5672 tex.cprint( 9," 9: $&{\\foo}") tex.print("\\par") -- all get ignored
5673 tex.cprint(10,"10: $&{\\foo}") tex.print("\\par") -- all become spaces
5674 tex.cprint(11,"11: $&{\\foo}") tex.print("\\par") -- letters
5675 tex.cprint(12,"12: $&{\\foo}") tex.print("\\par") -- other characters
5676 tex.cprint(14,"12: $&{\\foo}") tex.print("\\par") -- comment triggers
5677 \stopfunctioncall
5679 \subsubsection{\type {tex.write}}
5681 \startfunctioncall
5682 tex.write(<string> s, ...)
5683 tex.write(<table> t)
5684 \stopfunctioncall
5686 Each string argument is treated by \TEX\ as a special kind of input line that
5687 makes it suitable for use as a quick way to dump information:
5689 \startitemize
5690 \item All catcodes on that line are either \quote{space} (for '~') or
5691 \quote{character} (for all others).
5692 \item There is no \type {\endlinechar} appended.
5693 \stopitemize
5695 If there is a table argument instead of a list of strings, this has to be a
5696 consecutive array of strings to print (the first non-string value will stop the
5697 printing process).
5699 \subsection{Helper functions}
5701 \subsubsection{\type {tex.round}}
5703 \startfunctioncall
5704 <number> n = tex.round(<number> o)
5705 \stopfunctioncall
5707 Rounds \LUA\ number \type {o}, and returns a number that is in the range of a
5708 valid \TEX\ register value. If the number starts out of range, it generates a
5709 \quote {number to big} error as well.
5711 \subsubsection{\type {tex.scale}}
5713 \startfunctioncall
5714 <number> n = tex.scale(<number> o, <number> delta)
5715 <table> n = tex.scale(table o, <number> delta)
5716 \stopfunctioncall
5718 Multiplies the \LUA\ numbers \type {o} and \type {delta}, and returns a rounded
5719 number that is in the range of a valid \TEX\ register value. In the table
5720 version, it creates a copy of the table with all numeric top||level values scaled
5721 in that manner. If the multiplied number(s) are of range, it generates
5722 \quote{number to big} error(s) as well.
5724 Note: the precision of the output of this function will depend on your computer's
5725 architecture and operating system, so use with care! An interface to \LUATEX's
5726 internal, 100\% portable scale function will be added at a later date.
5728 \subsubsection{\type {tex.sp}}
5730 \startfunctioncall
5731 <number> n = tex.sp(<number> o)
5732 <number> n = tex.sp(<string> s)
5733 \stopfunctioncall
5735 Converts the number \type {o} or a string \type {s} that represents an explicit
5736 dimension into an integer number of scaled points.
5738 For parsing the string, the same scanning and conversion rules are used that
5739 \LUATEX\ would use if it was scanning a dimension specifier in its \TEX|-|like
5740 input language (this includes generating errors for bad values), expect for the
5741 following:
5743 \startitemize[n]
5744 \startitem
5745 only explicit values are allowed, control sequences are not handled
5746 \stopitem
5747 \startitem
5748 infinite dimension units (\type {fil...}) are forbidden
5749 \stopitem
5750 \startitem
5751 \type {mu} units do not generate an error (but may not be useful either)
5752 \stopitem
5753 \stopitemize
5755 \subsubsection{\type {tex.definefont}}
5757 \startfunctioncall
5758 tex.definefont(<string> csname, <number> fontid)
5759 tex.definefont(<boolean> global, <string> csname, <number> fontid)
5760 \stopfunctioncall
5762 Associates \type {csname} with the internal font number \type {fontid}. The
5763 definition is global if (and only if) \type {global} is specified and true (the
5764 setting of \type {globaldefs} is not taken into account).
5766 \subsubsection{\type {tex.getlinenumber} and \type {tex.setlinenumber}}
5768 You can mess with the current line number:
5770 \startfunctioncall
5771 local n = tex.getlinenumber()
5772 tex.setlinenumber(n+10)
5773 \stopfunctioncall
5775 which can be shortcut to:
5777 \startfunctioncall
5778 tex.setlinenumber(10,true)
5779 \stopfunctioncall
5781 This might be handy when you have a callback that read numbers from a file and
5782 combines them in one line (in which case an error message probably has to refer
5783 to the original line). Interference with \TEX's internal handling of numbers is
5784 of course possible.
5786 \subsubsection{\type {tex.error}}
5788 \startfunctioncall
5789 tex.error(<string> s)
5790 tex.error(<string> s, <table> help)
5791 \stopfunctioncall
5793 This creates an error somewhat like the combination of \type {\errhelp} and \type
5794 {\errmessage} would. During this error, deletions are disabled.
5796 The array part of the \type {help} table has to contain strings, one for each
5797 line of error help.
5799 \subsubsection{\type {tex.hashtokens}}
5801 \startfunctioncall
5802 for i,v in pairs (tex.hashtokens()) do ... end
5803 \stopfunctioncall
5805 Returns a name and token table pair (see~\in {section} [luatokens] about token
5806 tables) iterator for every non-zero entry in the hash table. This can be useful
5807 for debugging, but note that this also reports control sequences that may be
5808 unreachable at this moment due to local redefinitions: it is strictly a dump of
5809 the hash table.
5811 \subsection[luaprimitives]{Functions for dealing with primitives }
5813 \subsubsection{\type {tex.enableprimitives}}
5815 \startfunctioncall
5816 tex.enableprimitives(<string> prefix, <table> primitive names)
5817 \stopfunctioncall
5819 This function accepts a prefix string and an array of primitive names.
5821 For each combination of \quote {prefix} and \quote {name}, the \type
5822 {tex.enableprimitives} first verifies that \quote {name} is an actual primitive
5823 (it must be returned by one of the \type {tex.extraprimitives()} calls explained
5824 below, or part of \TEX82, or \type {\directlua}). If it is not, \type
5825 {tex.enableprimitives} does nothing and skips to the next pair.
5827 But if it is, then it will construct a csname variable by concatenating the
5828 \quote {prefix} and \quote {name}, unless the \quote {prefix} is already the
5829 actual prefix of \quote {name}. In the latter case, it will discard the \quote
5830 {prefix}, and just use \quote {name}.
5832 Then it will check for the existence of the constructed csname. If the csname is
5833 currently undefined (note: that is not the same as \type {\relax}), it will
5834 globally define the csname to have the meaning: run code belonging to the
5835 primitive \quote {name}. If for some reason the csname is already defined, it
5836 does nothing and tries the next pair.
5838 An example:
5840 \starttyping
5841 tex.enableprimitives('LuaTeX', {'formatname'})
5842 \stoptyping
5844 will define \type {\LuaTeXformatname} with the same intrinsic meaning as the
5845 documented primitive \type {\formatname}, provided that the control sequences \type
5846 {\LuaTeXformatname} is currently undefined.
5848 When \LUATEX\ is run with \type {--ini} only the \TEX82 primitives and \type
5849 {\directlua} are available, so no extra primitives {\bf at all}.
5851 If you want to have all the new functionality available using their default
5852 names, as it is now, you will have to add
5854 \starttyping
5855 \ifx\directlua\undefined \else
5856 \directlua {tex.enableprimitives('',tex.extraprimitives ())}
5858 \stoptyping
5860 near the beginning of your format generation file. Or you can choose different
5861 prefixes for different subsets, as you see fit.
5863 Calling some form of \type {tex.enableprimitives()} is highly important though,
5864 because if you do not, you will end up with a \TEX82-lookalike that can run \LUA\
5865 code but not do much else. The defined csnames are (of course) saved in the
5866 format and will be available at runtime.
5868 \subsubsection{\type {tex.extraprimitives}}
5870 \startfunctioncall
5871 <table> t = tex.extraprimitives(<string> s, ...)
5872 \stopfunctioncall
5874 This function returns a list of the primitives that originate from the engine(s)
5875 given by the requested string value(s). The possible values and their (current)
5876 return values are:
5878 \startluacode
5879 function document.showprimitives(tag)
5880 for k, v in table.sortedpairs(tex.extraprimitives(tag)) do
5881 if v == ' ' then
5882 v = '\\normalcontrolspace'
5884 context.type(v)
5885 context.space()
5888 \stopluacode
5890 \starttabulate[|l|pl|]
5891 \NC \bf name\NC \bf values \NC \NR
5892 \NC tex \NC \ctxlua{document.showprimitives('tex') } \NC \NR
5893 \NC core \NC \ctxlua{document.showprimitives('core') } \NC \NR
5894 \NC etex \NC \ctxlua{document.showprimitives('etex') } \NC \NR
5895 \NC luatex \NC \ctxlua{document.showprimitives('luatex') } \NC \NR
5896 \stoptabulate
5898 Note that \type {'luatex'} does not contain \type {directlua}, as that is
5899 considered to be a core primitive, along with all the \TEX82 primitives, so it is
5900 part of the list that is returned from \type {'core'}.
5902 % \type {'umath'} is a subset of \type {'luatex'} that covers the Unicode math
5903 % primitives as it might be desired to handle the prefixing of that subset
5904 % differently.
5906 Running \type {tex.extraprimitives()} will give you the complete list of
5907 primitives \type {-ini} startup. It is exactly equivalent to \type
5908 {tex.extraprimitives('etex' and 'luatex')}.
5910 \subsubsection{\type {tex.primitives}}
5912 \startfunctioncall
5913 <table> t = tex.primitives()
5914 \stopfunctioncall
5916 This function returns a hash table listing all primitives that \LUATEX\ knows
5917 about. The keys in the hash are primitives names, the values are tables
5918 representing tokens (see~\in{section }[luatokens]). The third value is always
5919 zero.
5921 {\em In the beginning we had \type {omega} and \type {pdftex} subsets but in the
5922 meantime relevant primitives ave been promoted (either or not adapted) to the
5923 \type {luatex} set when found useful, or removed when considered to be of no use.
5924 Originally we had two sets of math definition primitives but the \OMEGA\ ones
5925 have been removed, so we no longer have a subset for math either.}
5927 \subsection{Core functionality interfaces}
5929 \subsubsection{\type {tex.badness}}
5931 \startfunctioncall
5932 <number> b = tex.badness(<number> t, <number> s)
5933 \stopfunctioncall
5935 This helper function is useful during linebreak calculations. \type {t} and \type
5936 {s} are scaled values; the function returns the badness for when total \type {t}
5937 is supposed to be made from amounts that sum to \type {s}. The returned number is
5938 a reasonable approximation of $100(t/s)^3$;
5940 \subsubsection{\type {tex.resetparagraph}}
5942 This function resets the parameters that \TEX\ normally resets when a new paragraph
5943 is seen.
5945 \subsubsection{\type {tex.linebreak}}
5947 \startfunctioncall
5948 local <node> nodelist, <table> info =
5949 tex.linebreak(<node> listhead, <table> parameters)
5950 \stopfunctioncall
5952 The understood parameters are as follows:
5954 \starttabulate[|l|l|p|]
5955 \NC \bf name \NC \bf type \NC \bf description \NC \NR
5956 \NC pardir \NC string \NC \NC \NR
5957 \NC pretolerance \NC number \NC \NC \NR
5958 \NC tracingparagraphs \NC number \NC \NC \NR
5959 \NC tolerance \NC number \NC \NC \NR
5960 \NC looseness \NC number \NC \NC \NR
5961 \NC hyphenpenalty \NC number \NC \NC \NR
5962 \NC exhyphenpenalty \NC number \NC \NC \NR
5963 \NC pdfadjustspacing \NC number \NC \NC \NR
5964 \NC adjdemerits \NC number \NC \NC \NR
5965 \NC pdfprotrudechars \NC number \NC \NC \NR
5966 \NC linepenalty \NC number \NC \NC \NR
5967 \NC lastlinefit \NC number \NC \NC \NR
5968 \NC doublehyphendemerits \NC number \NC \NC \NR
5969 \NC finalhyphendemerits \NC number \NC \NC \NR
5970 \NC hangafter \NC number \NC \NC \NR
5971 \NC interlinepenalty \NC number or table \NC if a table, then it is an array like \type {\interlinepenalties} \NC \NR
5972 \NC clubpenalty \NC number or table \NC if a table, then it is an array like \type {\clubpenalties} \NC \NR
5973 \NC widowpenalty \NC number or table \NC if a table, then it is an array like \type {\widowpenalties} \NC \NR
5974 \NC brokenpenalty \NC number \NC \NC \NR
5975 \NC emergencystretch \NC number \NC in scaled points \NC \NR
5976 \NC hangindent \NC number \NC in scaled points \NC \NR
5977 \NC hsize \NC number \NC in scaled points \NC \NR
5978 \NC leftskip \NC glue_spec node \NC \NC \NR
5979 \NC rightskip \NC glue_spec node \NC \NC \NR
5980 \NC pdfignoreddimen \NC number \NC in scaled points \NC \NR
5981 \NC parshape \NC table \NC \NC \NR
5982 \stoptabulate
5984 Note that there is no interface for \type {\displaywidowpenalties}, you have to
5985 pass the right choice for \type {widowpenalties} yourself.
5987 The meaning of the various keys should be fairly obvious from the table (the
5988 names match the \TEX\ and \PDFTEX\ primitives) except for the last 5 entries. The
5989 four \type {pdf...line...} keys are ignored if their value equals \type
5990 {pdfignoreddimen}.
5992 It is your own job to make sure that \type {listhead} is a proper paragraph list:
5993 this function does not add any nodes to it. To be exact, if you want to replace
5994 the core line breaking, you may have to do the following (when you are not
5995 actually working in the \type {pre_linebreak_filter} or \type {linebreak_filter}
5996 callbacks, or when the original list starting at listhead was generated in
5997 horizontal mode):
5999 \startitemize
6000 \startitem
6001 add an \quote {indent box} and perhaps a \type {local_par} node at the start
6002 (only if you need them)
6003 \stopitem
6004 \startitem
6005 replace any found final glue by an infinite penalty (or add such a penalty,
6006 if the last node is not a glue)
6007 \stopitem
6008 \startitem
6009 add a glue node for the \type {\parfillskip} after that penalty node
6010 \stopitem
6011 \startitem
6012 make sure all the \type {prev} pointers are OK
6013 \stopitem
6014 \stopitemize
6016 The result is a node list, it still needs to be vpacked if you want to assign it
6017 to a \type {\vbox}.
6019 The returned \type {info} table contains four values that are all numbers:
6021 \starttabulate[|l|p|]
6022 \NC prevdepth \NC depth of the last line in the broken paragraph \NC \NR
6023 \NC prevgraf \NC number of lines in the broken paragraph \NC \NR
6024 \NC looseness \NC the actual looseness value in the broken paragraph \NC \NR
6025 \NC demerits \NC the total demerits of the chosen solution \NC \NR
6026 \stoptabulate
6028 Note there are a few things you cannot interface using this function: You cannot
6029 influence font expansion other than via \type {pdfadjustspacing}, because the
6030 settings for that take place elsewhere. The same is true for hbadness and hfuzz
6031 etc. All these are in the \type {hpack()} routine, and that fetches its own
6032 variables via globals.
6034 \subsubsection{\type {tex.shipout}}
6036 \startfunctioncall
6037 tex.shipout(<number> n)
6038 \stopfunctioncall
6040 Ships out box number \type {n} to the output file, and clears the box register.
6042 \section[texconfig]{The \type {texconfig} table}
6044 This is a table that is created empty. A startup \LUA\ script could
6045 fill this table with a number of settings that are read out by
6046 the executable after loading and executing the startup file.
6048 \starttabulate[|lT|l|l|p|]
6049 \NC \ssbf key \NC \bf type \NC \bf default \NC \bf explanation \NC \NR
6050 \NC kpse_init \NC boolean \NC true
6052 \type {false} totally disables \KPATHSEA\ initialisation, and enables
6053 interpretation of the following numeric key--value pairs. (only ever unset
6054 this if you implement {\it all\/} file find callbacks!)
6055 \NC \NR
6057 shell_escape \NC string \NC \type {'f'} \NC
6058 Use \type {'y'} or \type {'t'} or \type {'1'} to enable \type {\write18}
6059 unconditionally, \type {'p'} to enable the commands that are listed in \type
6060 {shell_escape_commands}
6061 \NC \NR
6063 shell_escape_commands \NC string \NC \NC Comma-separated list of command
6064 names that may be executed by \type {\write18} even if \type {shell_escape}
6065 is set to \type {'p'}. Do {\it not\/} use spaces around commas, separate any
6066 required command arguments by using a space, and use the \ASCII\ double quote
6067 (\type {"}) for any needed argument or path quoting
6068 \NC \NR
6070 \NC string_vacancies \NC number \NC 75000 \NC cf.\ web2c docs \NC \NR
6071 \NC pool_free \NC number \NC 5000 \NC cf.\ web2c docs \NC \NR
6072 \NC max_strings \NC number \NC 15000 \NC cf.\ web2c docs \NC \NR
6073 \NC strings_free \NC number \NC 100 \NC cf.\ web2c docs \NC \NR
6074 \NC nest_size \NC number \NC 50 \NC cf.\ web2c docs \NC \NR
6075 \NC max_in_open \NC number \NC 15 \NC cf.\ web2c docs \NC \NR
6076 \NC param_size \NC number \NC 60 \NC cf.\ web2c docs \NC \NR
6077 \NC save_size \NC number \NC 4000 \NC cf.\ web2c docs \NC \NR
6078 \NC stack_size \NC number \NC 300 \NC cf.\ web2c docs \NC \NR
6079 \NC dvi_buf_size \NC number \NC 16384 \NC cf.\ web2c docs \NC \NR
6080 \NC error_line \NC number \NC 79 \NC cf.\ web2c docs \NC \NR
6081 \NC half_error_line \NC number \NC 50 \NC cf.\ web2c docs \NC \NR
6082 \NC max_print_line \NC number \NC 79 \NC cf.\ web2c docs \NC \NR
6083 \NC hash_extra \NC number \NC 0 \NC cf.\ web2c docs \NC \NR
6084 \NC pk_dpi \NC number \NC 72 \NC cf.\ web2c docs \NC \NR
6085 \NC trace_file_names \NC boolean \NC true
6087 \type {false} disables \TEX's normal file open|-|close feedback (the
6088 assumption is that callbacks will take care of that)
6089 \NC \NR
6090 \NC file_line_error \NC boolean \NC false
6092 do \type {file:line} style error messages
6093 \NC \NR
6094 \NC halt_on_error \NC boolean \NC false
6096 abort run on the first encountered error
6097 \NC \NR
6098 \NC formatname \NC string \NC
6100 if no format name was given on the command line, this key will be tested first
6101 instead of simply quitting
6102 \NC \NR
6103 \NC jobname \NC string \NC
6105 if no input file name was given on the command line, this key will be tested
6106 first instead of simply giving up
6107 \NC \NR
6108 \stoptabulate
6110 Note: the numeric values that match web2c parameters are only used if \type
6111 {kpse_init} is explicitly set to \type {false}. In all other cases, the normal
6112 values from \type {texmf.cnf} are used.
6114 \section{The \type {texio} library}
6116 This library takes care of the low|-|level I/O interface.
6118 \subsection{Printing functions}
6120 \subsubsection{\type {texio.write}}
6122 \startfunctioncall
6123 texio.write(<string> target, <string> s, ...)
6124 texio.write(<string> s, ...)
6125 \stopfunctioncall
6127 Without the \type {target} argument, writes all given strings to the same
6128 location(s) \TEX\ writes messages to at this moment. If \type {\batchmode} is in
6129 effect, it writes only to the log, otherwise it writes to the log and the
6130 terminal. The optional \type {target} can be one of three possibilities: \type
6131 {term}, \type {log} or \type {term and log}.
6133 Note: If several strings are given, and if the first of these strings is or might
6134 be one of the targets above, the \type {target} must be specified explicitly to
6135 prevent \LUA\ from interpreting the first string as the target.
6137 \subsubsection{\type {texio.write_nl}}
6139 \startfunctioncall
6140 texio.write_nl(<string> target, <string> s, ...)
6141 texio.write_nl(<string> s, ...)
6142 \stopfunctioncall
6144 This function behaves like \type {texio.write}, but make sure that the given
6145 strings will appear at the beginning of a new line. You can pass a single empty
6146 string if you only want to move to the next line.
6148 \subsubsection{\type {texio.setescape}}
6150 You can disable \type {^^} escaping of control characters by passing a value of
6151 zero.
6153 \subsection{The \type {token} libray}
6155 The current \type {token} library will be replaced by a new one that is more
6156 flexible and powerful. The transition takes place in steps. In version 0.80 we
6157 have \type {token} and in version 0.85 the old lib will be replaced
6158 completely. So if you use this new mechanism in production code you need to be
6159 aware of incompatible updates between 0.80 and 0.90. Because the related in- and
6160 output code will also be cleaned up and rewritten you should be aware of
6161 incompatible logging and error reporting too.
6163 The old library presents tokens as triplets or numbers, the new library presents
6164 a userdata object. The old library used a callback to intercept tokens in the
6165 input but the new library provides a basic scanner infrastructure that can be
6166 used to write macros that accept a wide range of arguments. This interface is on
6167 purpose kept general and as performance is quite ok one can build additional
6168 parsers without too much overhead. It's up to macro package writers to see how
6169 they can benefit from this as the main principle behind \LUATEX\ is to provide a
6170 minimal set of tools and no solutions.
6172 The current functions in the \type {token} namespace are given in the next
6173 table:
6175 \starttabulate[|lT|lT|p|]
6176 \NC \bf function \NC \bf argument \NC \bf result \NC \NR
6178 \NC is_token \NC token \NC checks if the given argument is a token userdatum \NC \NR
6179 \NC get_next \NC \NC returns the next token in the input \NC \NR
6180 \NC scan_keyword \NC string \NC returns true if the given keyword is gobbled \NC \NR
6181 \NC scan_int \NC \NC returns a number \NC \NR
6182 \NC scan_dimen \NC infinity, mu-units \NC returns a number representing a dimension and or two numbers being the filler and order \NC \NR
6183 \NC scan_glue \NC mu-units \NC returns a glue spec node \NC \NR
6184 \NC scan_toks \NC definer, expand \NC returns a table of tokens token list (this can become a linked list in later releases) \NC \NR
6185 \NC scan_code \NC bitset \NC returns a character if its category is in the given bitset (representing catcodes) \NC \NR
6186 \NC scan_string \NC \NC returns a string given between \type {{}}, as \type {\macro} or as sequence of characters with catcode 11 or 12 \NC \NR
6187 \NC scan_word \NC \NC returns a sequence of characters with catcode 11 or 12 as string \NC \NR
6188 \NC scan_csname \NC \NC returns \type {foo} after scanning \type {\foo} \NC \NR
6189 \NC set_macro \NC see below \NC assign a macro \NC \NR
6190 \NC create \NC \NC returns a userdata token object of the given control sequence name (or character); this interface can change \NC \NR
6191 \stoptabulate
6193 The scanners can be considered stable apart from the one scanning for a token.
6194 This is because futures releases can return a linked list instead of a table (as
6195 with nodes). The \type {scan_code} function takes an optional number, the \type
6196 {keyword} function a normal \LUA\ string. The \type {infinity} boolean signals
6197 that we also permit \type {fill} as dimension and the \type {mu-units} flags the
6198 scanner that we expect math units. When scanning tokens we can indicate that we
6199 are defining a macro, in which case the result will also provide information
6200 about what arguments are expected and in the result this is separated from the
6201 meaning by a separator token. The \type {expand} flag determines if the list will
6202 be expanded.
6204 The string scanner scans for something between curly braces and expands on the
6205 way, or when it sees a control sequence it will return its meaning. Otherwise it
6206 will scan characters with catcode \type {letter} or \type {other}. So, given the
6207 following definition:
6209 \startbuffer
6210 \def\bar{bar}
6211 \def\foo{foo-\bar}
6212 \stopbuffer
6214 \typebuffer \getbuffer
6216 we get:
6218 \starttabulate[|l|Tl|l|]
6219 \NC \type {\directlua{token.scan_string()}{foo}} \NC \directlua{context("{\\red\\type {"..token.scan_string().."}}")} {foo} \NC full expansion \NR
6220 \NC \type {\directlua{token.scan_string()}foo} \NC \directlua{context("{\\red\\type {"..token.scan_string().."}}")} foo \NC letters and others \NR
6221 \NC \type {\directlua{token.scan_string()}\foo} \NC \directlua{context("{\\red\\type {"..token.scan_string().."}}")}\foo \NC meaning \NR
6222 \stoptabulate
6224 The \type {\foo} case only gives the meaning, but one can pass an already
6225 expanded definition (\type {\edef}'d). In the case of the braced variant one can of
6226 course use the \type {\detokenize} and \type {\unexpanded} primitives as there we
6227 do expand.
6229 The \type {scan_word} scanner can be used to implement for instance a number scanner:
6231 \starttyping
6232 function token.scan_number(base)
6233 return tonumber(token.scan_word(),base)
6235 \stoptyping
6237 This scanner accepts any valid \LUA\ number so it is a way to pick up floats
6238 in the input.
6240 The creator function can be used as follows:
6242 \starttyping
6243 local t = token.create("relax")
6244 \stoptyping
6246 This gives back a token object that has the properties of the \type {\relax}
6247 primitive. The possible properties of tokens are:
6249 \starttabulate[|lT|p|]
6250 \NC command \NC a number representing the internal command number \NC \NR
6251 \NC cmdname \NC the type of the command (for instance the catcode in case of a
6252 character or the classifier that determines the internal
6253 treatment \NC \NR
6254 \NC csname \NC the associated control sequence (if applicable) \NC \NR
6255 \NC id \NC the unique id of the token \NC \NR
6256 %NC tok \NC \NC \NR % might change
6257 \NC active \NC a boolean indicating the active state of the token \NC \NR
6258 \NC expandable \NC a boolean indicating if the token (macro) is expandable \NC \NR
6259 \NC protected \NC a boolean indicating if the token (macro) is protected \NC \NR
6260 \stoptabulate
6262 The numbers that represent a catcode are the same as in \TEX\ itself, so using
6263 this information assumes that you know a bit about \TEX's internals. The other
6264 numbers and names are used consistently but are not frozen. So, when you use them
6265 for comparing you can best query a known primitive or character first to see the
6266 values.
6268 More interesting are the scanners. You can use the \LUA\ interface as follows:
6270 \starttyping
6271 \directlua {
6272 function mymacro(n)
6277 \def\mymacro#1{%
6278 \directlua {
6279 mymacro(\number\dimexpr#1)
6283 \mymacro{12pt}
6284 \mymacro{\dimen0}
6285 \stoptyping
6287 You can also do this:
6289 \starttyping
6290 \directlua {
6291 function mymacro()
6292 local d = token.scan_dimen()
6297 \def\mymacro{%
6298 \directlua {
6299 mymacro()
6303 \mymacro 12pt
6304 \mymacro \dimen0
6305 \stoptyping
6307 It is quite clear from looking at the code what the first method needs as
6308 argument(s). For the second method you need to look at the \LUA\ code to see what
6309 gets picked up. Instead of passing from \TEX\ to \LUA\ we let \LUA\ fetch from
6310 the input stream.
6312 In the first case the input is tokenized and then turned into a string when it's
6313 passed to \LUA\ where it gets interpreted. In the second case only a function
6314 call gets interpreted but then the input is picked up by explicitly calling the
6315 scanner functions. These return proper \LUA\ variables so no further conversion
6316 has to be done. This is more efficient but in practice (given what \TEX\ has to
6317 do) this effect should not be overestimated. For numbers and dimensions it saves a
6318 bit but for passing strings conversion to and from tokens has to be done anyway
6319 (although we can probably speed up the process in later versions if needed).
6321 When the interface is stable and has replaced the old one completely we will add
6322 some more information here. By that time the internals have been cleaned up a bit
6323 more so we know then what will stay and go. A positive side effect of this
6324 transition is that we can simplify the input part because we no longer need to
6325 intercept using callbacks.
6327 The \type {set_macro} function can get upto 4 arguments:
6329 \starttyping
6330 setmacro("csname","content")
6331 setmacro("csname","content","global")
6332 setmacro("csname")
6333 \stoptyping
6335 You can pass a catcodetable identifier as first argument:
6337 \starttyping
6338 setmacro(catcodetable,"csname","content")
6339 setmacro(catcodetable,"csname","content","global")
6340 setmacro(catcodetable,"csname")
6341 \stoptyping
6343 The results are like:
6345 \starttyping
6346 \def\csname{content}
6347 \gdef\csname{content}
6348 \def\csname{}
6349 \stoptyping
6351 There is a (for now) experimental putter:
6353 \starttyping
6354 local t1 = token.get_next()
6355 local t2 = token.get_next()
6356 local t3 = token.get_next()
6357 local t4 = token.get_next()
6358 -- watch out, we flush in sequence
6359 token.put_next { t1, t2 }
6360 -- but this one gets pushed in front
6361 token.put_next ( t3, t4 )
6362 \stoptyping
6364 When we scan \type {wxyz!} we get \type {yzwx!} back. The argument is either a table
6365 with tokens or a list of tokens.
6367 \stopchapter
6369 \stopcomponent