sinc with TeXLive revision 41114. (trunk,fix prev. wrong message)
[luatex.git] / manual / luatex-callbacks.tex
blobaa6f9ed8a2db64c254a7ca4e99799c59bec3c643
1 % language=uk
3 \environment luatex-style
4 \environment luatex-logos
6 \startcomponent luatex-callbacks
8 \startchapter[reference=callbacks,title={\LUATEX\ \LUA\ callbacks}]
10 \section {Registering callbacks}
12 This library has functions that register, find and list callbacks. Callbacks are
13 \LUA\ functions that are called in well defined places. There are two kind of
14 callbacks: those that mix with existing functionality, and those that (when
15 enabled) replace functionality. In mosty cases the second category is expected to
16 behave similar to the built in functionality because in a next step specific
17 data is expected. For instance, you can replace the hyphenation routine. The
18 function gets a list that can be hyphenated (or not). The final list should be
19 valid and is (normally) used for constructing a paragraph. Another function can
20 replace the ligature builder and|/|or kerner. Doing something else is possible
21 but in the end might not give the user the expected outcome.
23 The first thing you need to do is registering a callback:
25 \startfunctioncall
26 id, error =
27 callback.register (<string> callback_name, <function> func)
28 id, error =
29 callback.register (<string> callback_name, nil)
30 id, error =
31 callback.register (<string> callback_name, false)
32 \stopfunctioncall
34 Here the \syntax {callback_name} is a predefined callback name, see below. The
35 function returns the internal \type {id} of the callback or \type {nil}, if the
36 callback could not be registered. In the latter case, \type {error} contains an
37 error message, otherwise it is \type {nil}.
39 \LUATEX\ internalizes the callback function in such a way that it does not matter
40 if you redefine a function accidentally.
42 Callback assignments are always global. You can use the special value \type {nil}
43 instead of a function for clearing the callback.
45 For some minor speed gain, you can assign the boolean \type {false} to the
46 non|-|file related callbacks, doing so will prevent \LUATEX\ from executing
47 whatever it would execute by default (when no callback function is registered at
48 all). Be warned: this may cause all sorts of grief unless you know {\em exactly}
49 what you are doing!
51 \startfunctioncall
52 <table> info =
53 callback.list()
54 \stopfunctioncall
56 The keys in the table are the known callback names, the value is a boolean where
57 \type {true} means that the callback is currently set (active).
59 \startfunctioncall
60 <function> f = callback.find (callback_name)
61 \stopfunctioncall
63 If the callback is not set, \type {callback.find} returns \type {nil}.
65 \section{File discovery callbacks}
67 The behaviour documented in this subsection is considered stable in the sense that
68 there will not be backward|-|incompatible changes any more.
70 \subsection{\type {find_read_file} and \type {find_write_file}}
72 Your callback function should have the following conventions:
74 \startfunctioncall
75 <string> actual_name =
76 function (<number> id_number, <string> asked_name)
77 \stopfunctioncall
79 Arguments:
81 \startitemize
83 \sym{id_number}
85 This number is zero for the log or \type {\input} files. For \TEX's \type {\read}
86 or \type {\write} the number is incremented by one, so \type {\read0} becomes~1.
88 \sym{asked_name}
90 This is the user|-|supplied filename, as found by \type {\input}, \type {\openin}
91 or \type {\openout}.
93 \stopitemize
95 Return value:
97 \startitemize
99 \sym{actual_name}
101 This is the filename used. For the very first file that is read in by \TEX, you
102 have to make sure you return an \type {actual_name} that has an extension and
103 that is suitable for use as \type {jobname}. If you don't, you will have to
104 manually fix the name of the log file and output file after \LUATEX\ is finished,
105 and an eventual format filename will become mangled. That is because these file
106 names depend on the jobname.
108 You have to return \type {nil} if the file cannot be found.
110 \stopitemize
112 \subsection{\type {find_font_file}}
114 Your callback function should have the following conventions:
116 \startfunctioncall
117 <string> actual_name =
118 function (<string> asked_name)
119 \stopfunctioncall
121 The \type {asked_name} is an \OTF\ or \TFM\ font metrics file.
123 Return \type {nil} if the file cannot be found.
125 \subsection{\type {find_output_file}}
127 Your callback function should have the following conventions:
129 \startfunctioncall
130 <string> actual_name =
131 function (<string> asked_name)
132 \stopfunctioncall
134 The \type {asked_name} is the \PDF\ or \DVI\ file for writing.
136 \subsection{\type {find_format_file}}
138 Your callback function should have the following conventions:
140 \startfunctioncall
141 <string> actual_name =
142 function (<string> asked_name)
143 \stopfunctioncall
145 The \type {asked_name} is a format file for reading (the format file for writing
146 is always opened in the current directory).
148 \subsection{\type {find_vf_file}}
150 Like \type {find_font_file}, but for virtual fonts. This applies to both \ALEPH's
151 \OVF\ files and traditional Knuthian \VF\ files.
153 \subsection{\type {find_map_file}}
155 Like \type {find_font_file}, but for map files.
157 \subsection{\type {find_enc_file}}
159 Like \type {find_font_file}, but for enc files.
161 \subsection{\type {find_sfd_file}}
163 Like \type {find_font_file}, but for subfont definition files.
165 \subsection{\type {find_pk_file}}
167 Like \type {find_font_file}, but for pk bitmap files. This callback takes two
168 arguments: \type {name} and \type {dpi}. In your callback you can decide to
169 look for:
171 \starttyping
172 <base res>dpi/<fontname>.<actual res>pk
173 \stoptyping
175 but other strategies are possible. It is up to you to find a \quote {reasonable}
176 bitmap file to go with that specification.
178 \subsection{\type {find_data_file}}
180 Like \type {find_font_file}, but for embedded files (\type {\pdfobj file '...'}).
182 \subsection{\type {find_opentype_file}}
184 Like \type {find_font_file}, but for \OPENTYPE\ font files.
186 \subsection{\type {find_truetype_file} and \type {find_type1_file}}
188 Your callback function should have the following conventions:
190 \startfunctioncall
191 <string> actual_name =
192 function (<string> asked_name)
193 \stopfunctioncall
195 The \type {asked_name} is a font file. This callback is called while \LUATEX\ is
196 building its internal list of needed font files, so the actual timing may
197 surprise you. Your return value is later fed back into the matching \type
198 {read_file} callback.
200 Strangely enough, \type {find_type1_file} is also used for \OPENTYPE\ (\OTF)
201 fonts.
203 \subsection{\type {find_image_file}}
205 Your callback function should have the following conventions:
207 \startfunctioncall
208 <string> actual_name =
209 function (<string> asked_name)
210 \stopfunctioncall
212 The \type {asked_name} is an image file. Your return value is used to open a file
213 from the hard disk, so make sure you return something that is considered the name
214 of a valid file by your operating system.
216 \subsection[iocallback]{File reading callbacks}
218 The behavior documented in this subsection is considered stable in the sense that
219 there will not be backward-incompatible changes any more.
221 \subsection{\type {open_read_file}}
223 Your callback function should have the following conventions:
225 \startfunctioncall
226 <table> env =
227 function (<string> file_name)
228 \stopfunctioncall
230 Argument:
232 \startitemize
234 \sym{file_name}
236 The filename returned by a previous \type {find_read_file} or the return value of
237 \type {kpse.find_file()} if there was no such callback defined.
239 \stopitemize
241 Return value:
243 \startitemize
245 \sym{env}
247 This is a table containing at least one required and one optional callback
248 function for this file. The required field is \type {reader} and the associated
249 function will be called once for each new line to be read, the optional one is
250 \type {close} that will be called once when \LUATEX\ is done with the file.
252 \LUATEX\ never looks at the rest of the table, so you can use it to store your
253 private per|-|file data. Both the callback functions will receive the table as
254 their only argument.
256 \stopitemize
258 \subsubsection{\type {reader}}
260 \LUATEX\ will run this function whenever it needs a new input line from the file.
262 \startfunctioncall
263 function(<table> env)
264 return <string> line
266 \stopfunctioncall
268 Your function should return either a string or \type {nil}. The value \type {nil}
269 signals that the end of file has occurred, and will make \TEX\ call the optional
270 \type {close} function next.
272 \subsubsection{\type {close}}
274 \LUATEX\ will run this optional function when it decides to close the file.
276 \startfunctioncall
277 function(<table> env)
279 \stopfunctioncall
281 Your function should not return any value.
283 \subsection{General file readers}
285 There is a set of callbacks for the loading of binary data files. These all use
286 the same interface:
288 \startfunctioncall
289 function(<string> name)
290 return <boolean> success, <string> data, <number> data_size
292 \stopfunctioncall
294 The \type {name} will normally be a full path name as it is returned by either
295 one of the file discovery callbacks or the internal version of \type
296 {kpse.find_file()}.
298 \startitemize
300 \sym{success}
302 Return \type {false} when a fatal error occurred (e.g.\ when the file cannot be
303 found, after all).
305 \sym{data}
307 The bytes comprising the file.
309 \sym{data_size}
311 The length of the \type {data}, in bytes.
313 \stopitemize
315 Return an empty string and zero if the file was found but there was a
316 reading problem.
318 The list of functions is as follows:
320 \starttabulate[|lT|p|]
321 \NC read_font_file \NC ofm or tfm files \NC \NR
322 \NC read_vf_file \NC virtual fonts \NC \NR
323 \NC read_map_file \NC map files \NC \NR
324 \NC read_enc_file \NC encoding files \NC \NR
325 \NC read_sfd_file \NC subfont definition files \NC \NR
326 \NC read_pk_file \NC pk bitmap files \NC \NR
327 \NC read_data_file \NC embedded files (as is possible with \PDF\ objects) \NC \NR
328 \NC read_truetype_file \NC \TRUETYPE\ font files \NC \NR
329 \NC read_type1_file \NC \TYPEONE\ font files \NC \NR
330 \NC read_opentype_file \NC \OPENTYPE\ font files \NC \NR
331 \stoptabulate
333 \section{Data processing callbacks}
335 \subsection{\type {process_input_buffer}}
337 This callback allows you to change the contents of the line input buffer just
338 before \LUATEX\ actually starts looking at it.
340 \startfunctioncall
341 function(<string> buffer)
342 return <string> adjusted_buffer
344 \stopfunctioncall
346 If you return \type {nil}, \LUATEX\ will pretend like your callback never
347 happened. You can gain a small amount of processing time from that. This callback
348 does not replace any internal code.
350 \subsection{\type {process_output_buffer}}
352 This callback allows you to change the contents of the line output buffer just
353 before \LUATEX\ actually starts writing it to a file as the result of a \type
354 {\write} command. It is only called for output to an actual file (that is,
355 excluding the log, the terminal, and \type {\write18} calls).
357 \startfunctioncall
358 function(<string> buffer)
359 return <string> adjusted_buffer
361 \stopfunctioncall
363 If you return \type {nil}, \LUATEX\ will pretend like your callback never
364 happened. You can gain a small amount of processing time from that. This callback
365 does not replace any internal code.
367 \subsection{\type {process_jobname}}
369 This callback allows you to change the jobname given by \type {\jobname} in \TEX\
370 and \type {tex.jobname} in Lua. It does not affect the internal job name or the
371 name of the output or log files.
373 \startfunctioncall
374 function(<string> jobname)
375 return <string> adjusted_jobname
377 \stopfunctioncall
379 The only argument is the actual job name; you should not use \type {tex.jobname}
380 inside this function or infinite recursion may occur. If you return \type {nil},
381 \LUATEX\ will pretend your callback never happened. This callback does not
382 replace any internal code.
384 \section{Node list processing callbacks}
386 The description of nodes and node lists is in~\in{chapter}[nodes].
388 \subsection{\type {contribute_filter}}
390 This callback is called when \LUATEX\ adds contents to list:
392 \startfunctioncall
393 function(<string> extrainfo)
395 \stopfunctioncall
397 The string reports the group code. From this you can deduce from
398 what list you can give a treat.
400 \starttabulate
401 \NC \bf group codes \NC \bf pointer \NC \NR
403 \NC\type {pre_box} \NC \type {contrib_head} \NC \NR
404 \NC\type {pre_adjust_tail} \NC \type {pre_adjust_head} \NC \NR
405 \NC\type {just} \NC \type {just_box} \NC \NR
406 \NC\type {adjust_tail} \NC \type {adjust_head} \NC \NR
407 \stoptabulate
409 \subsection{\type {buildpage_filter} and \type {contribute_filter}}
411 This callback is called whenever \LUATEX\ is ready to move stuff to the main
412 vertical list. You can use this callback to do specialized manipulation of the
413 page building stage like imposition or column balancing.
415 \startfunctioncall
416 function(<string> extrainfo)
418 \stopfunctioncall
420 The string \type {extrainfo} gives some additional information about what \TEX's
421 state is with respect to the \quote {current page}. The possible values for the
422 \type {buildpage_filter} callback are:
424 \starttabulate[|lT|p|]
425 \NC \ssbf value \NC \bf explanation \NC \NR
426 \NC alignment \NC a (partial) alignment is being added \NC \NR
427 \NC after_output \NC an output routine has just finished \NC \NR
428 \NC new_graf \NC the beginning of a new paragraph \NC \NR
429 \NC vmode_par \NC \type {\par} was found in vertical mode \NC \NR
430 \NC hmode_par \NC \type {\par} was found in horizontal mode \NC \NR
431 \NC insert \NC an insert is added \NC \NR
432 \NC penalty \NC a penalty (in vertical mode) \NC \NR
433 \NC before_display \NC immediately before a display starts \NC \NR
434 \NC after_display \NC a display is finished \NC \NR
435 \NC end \NC \LUATEX\ is terminating (it's all over) \NC \NR
436 \stoptabulate
438 And for the \type {contribute_filter} called in the post line break handler
439 we have four cases (three are only called when there is a need for it).
441 \starttabulate[|lT|p|]
442 \NC \ssbf value \NC \bf explanation \NC \NR
443 \NC pre_box \NC interline material is being added \NC \NR
444 \NC pre_adjust \NC \type {\vadjust} material is being added \NC \NR
445 \NC box \NC a typeset box is being added (always called) \NC \NR
446 \NC adjust \NC \type {\vadjust} material is being added \NC \NR
447 \stoptabulate
449 Just before the \type {box} related call we have a callout to the \type
450 {append_to_vlist_filter}. These callbacks do not replace any internal code.
452 \subsection{\type {pre_linebreak_filter}}
454 This callback is called just before \LUATEX\ starts converting a list of nodes
455 into a stack of \type {\hbox}es, after the addition of \type {\parfillskip}.
457 \startfunctioncall
458 function(<node> head, <string> groupcode)
459 return true | false | <node> newhead
461 \stopfunctioncall
463 The string called \type {groupcode} identifies the nodelist's context within
464 \TEX's processing. The range of possibilities is given in the table below, but
465 not all of those can actually appear in \type {pre_linebreak_filter}, some are
466 for the \type {hpack_filter} and \type {vpack_filter} callbacks that will be
467 explained in the next two paragraphs.
469 \starttabulate[|lT|p|]
470 \NC \ssbf value \NC \bf explanation \NC \NR
471 \NC <empty> \NC main vertical list \NC \NR
472 \NC hbox \NC \type {\hbox} in horizontal mode \NC \NR
473 \NC adjusted_hbox \NC \type {\hbox} in vertical mode \NC \NR
474 \NC vbox \NC \type {\vbox} \NC \NR
475 \NC vtop \NC \type {\vtop} \NC \NR
476 \NC align \NC \type {\halign} or \type {\valign} \NC \NR
477 \NC disc \NC discretionaries \NC \NR
478 \NC insert \NC packaging an insert \NC \NR
479 \NC vcenter \NC \type {\vcenter} \NC \NR
480 \NC local_box \NC \type {\localleftbox} or \type {\localrightbox} \NC \NR
481 \NC split_off \NC top of a \type {\vsplit} \NC \NR
482 \NC split_keep \NC remainder of a \type {\vsplit} \NC \NR
483 \NC align_set \NC alignment cell \NC \NR
484 \NC fin_row \NC alignment row \NC \NR
485 \stoptabulate
487 As for all the callbacks that deal with nodes, the return value can be one of
488 three things:
490 \startitemize
491 \startitem
492 boolean \type {true} signals successful processing
493 \stopitem
494 \startitem
495 \type {<node>} signals that the \quote {head} node should be replaced by the
496 returned node
497 \stopitem
498 \startitem
499 boolean \type {false} signals that the \quote {head} node list should be
500 ignored and flushed from memory
501 \stopitem
502 \stopitemize
504 This callback does not replace any internal code.
506 \subsection{\type {linebreak_filter}}
508 This callback replaces \LUATEX's line breaking algorithm.
510 \startfunctioncall
511 function(<node> head, <boolean> is_display)
512 return <node> newhead
514 \stopfunctioncall
516 The returned node is the head of the list that will be added to the main vertical
517 list, the boolean argument is true if this paragraph is interrupted by a
518 following math display.
520 If you return something that is not a \type {<node>}, \LUATEX\ will apply the
521 internal linebreak algorithm on the list that starts at \type {<head>}.
522 Otherwise, the \type {<node>} you return is supposed to be the head of a list of
523 nodes that are all allowed in vertical mode, and at least one of those has to
524 represent a hbox. Failure to do so will result in a fatal error.
526 Setting this callback to \type {false} is possible, but dangerous, because it is
527 possible you will end up in an unfixable \quote {deadcycles loop}.
529 \subsection{\type {append_to_vlist_filter}}
531 This callback is called whenever \LUATEX\ adds a box to a vertical list:
533 \startfunctioncall
534 function(<node> box, <string> locationcode, <number prevdepth>,
535 <boolean> mirrored)
536 return list, prevdepth
538 \stopfunctioncall
540 It is ok to return nothing in which case you also need to flush the box or deal
541 with it yourself. The prevdepth is also optional. Locations are \type {box},
542 \type {alignment}, \type {equation}, \type {equation_number} and \type
543 {post_linebreak}.
545 \subsection{\type {post_linebreak_filter}}
547 This callback is called just after \LUATEX\ has converted a list of nodes into a
548 stack of \type {\hbox}es.
550 \startfunctioncall
551 function(<node> head, <string> groupcode)
552 return true | false | <node> newhead
554 \stopfunctioncall
556 This callback does not replace any internal code.
558 \subsection{\type {hpack_filter}}
560 This callback is called when \TEX\ is ready to start boxing some horizontal mode
561 material. Math items and line boxes are ignored at the moment.
563 \startfunctioncall
564 function(<node> head, <string> groupcode, <number> size,
565 <string> packtype [, <string> direction] [, <node> attributelist])
566 return true | false | <node> newhead
568 \stopfunctioncall
570 The \type {packtype} is either \type {additional} or \type {exactly}. If \type
571 {additional}, then the \type {size} is a \type {\hbox spread ...} argument. If
572 \type {exactly}, then the \type {size} is a \type {\hbox to ...}. In both cases,
573 the number is in scaled points.
575 The \type {direction} is either one of the three-letter direction specifier
576 strings, or \type {nil}.
578 This callback does not replace any internal code.
580 \subsection{\type {vpack_filter}}
582 This callback is called when \TEX\ is ready to start boxing some vertical mode
583 material. Math displays are ignored at the moment.
585 This function is very similar to the \type {hpack_filter}. Besides the fact
586 that it is called at different moments, there is an extra variable that matches
587 \TEX's \type {\maxdepth} setting.
589 \startfunctioncall
590 function(<node> head, <string> groupcode, <number> size, <string> packtype,
591 <number> maxdepth [, <string> direction] [, <node> attributelist]))
592 return true | false | <node> newhead
594 \stopfunctioncall
596 This callback does not replace any internal code.
598 \subsection{\type {hpack_quality}}
600 This callback can be used to intercept the overfull messages that can result from
601 packing a horizontal list (as happens in the par builder). The function takes a
602 few arguments:
604 \startfunctioncall
605 function(<string> incident, <number> detail, <node> head, <number> first,
606 <number> last)
607 return <node> whatever
609 \stopfunctioncall
611 The incident is one of \type {overfull}, \type {underfull}, \type {loose} or
612 \type {tight}. The detail is either the amount of overflow in case of \type
613 {overfull}, or the badness otherwise. The head is the list that is constructed
614 (when protrusion or expansion is enabled, this is an intermediate list).
615 Optionally you can return a node, for instance an overfull rule indicator. That
616 node will be appended to the list (just like \TEX's own rule would).
618 \subsection{\type {vpack_quality}}
620 This callback can be used to intercept the overfull messages that can result from
621 packing a vertical list (as happens in the page builder). The function takes a
622 few arguments:
624 \startfunctioncall
625 function(<string> incident, <number> detail, <node> head, <number> first,
626 <number> last)
628 \stopfunctioncall
630 The incident is one of \type {overfull}, \type {underfull}, \type {loose} or
631 \type {tight}. The detail is either the amount of overflow in case of \type
632 {overfull}, or the badness otherwise. The head is the list that is constructed.
634 \subsection{\type {process_rule}}
636 This is an experimental callback. It can be used with rules of subtype~4
637 (user). The callback gets three arguments: the node, the width and the
638 height. The callback can use \type {pdf.print} to write code to the \PDF\
639 file but beware of not messing up the final result. No checking is done.
641 \subsection{\type {pre_output_filter}}
643 This callback is called when \TEX\ is ready to start boxing the box 255 for \type
644 {\output}.
646 \startfunctioncall
647 function(<node> head, <string> groupcode, <number> size, <string> packtype,
648 <number> maxdepth [, <string> direction])
649 return true | false | <node> newhead
651 \stopfunctioncall
653 This callback does not replace any internal code.
655 \subsection{\type {hyphenate}}
657 \startfunctioncall
658 function(<node> head, <node> tail)
660 \stopfunctioncall
662 No return values. This callback has to insert discretionary nodes in the node
663 list it receives.
665 Setting this callback to \type {false} will prevent the internal discretionary
666 insertion pass.
668 \subsection{\type {ligaturing}}
670 \startfunctioncall
671 function(<node> head, <node> tail)
673 \stopfunctioncall
675 No return values. This callback has to apply ligaturing to the node list it
676 receives.
678 You don't have to worry about return values because the \type {head} node that is
679 passed on to the callback is guaranteed not to be a glyph_node (if need be, a
680 temporary node will be prepended), and therefore it cannot be affected by the
681 mutations that take place. After the callback, the internal value of the \quote
682 {tail of the list} will be recalculated.
684 The \type {next} of \type {head} is guaranteed to be non-nil.
686 The \type {next} of \type {tail} is guaranteed to be nil, and therefore the
687 second callback argument can often be ignored. It is provided for orthogonality,
688 and because it can sometimes be handy when special processing has to take place.
690 Setting this callback to \type {false} will prevent the internal ligature
691 creation pass.
693 You must not ruin the node list. For instance, the head normally is a local par node,
694 and the tail a glue. Messing too much can push \LUATEX\ into panic mode.
696 \subsection{\type {kerning}}
698 \startfunctioncall
699 function(<node> head, <node> tail)
701 \stopfunctioncall
703 No return values. This callback has to apply kerning between the nodes in the
704 node list it receives. See \type {ligaturing} for calling conventions.
706 Setting this callback to \type {false} will prevent the internal kern insertion
707 pass.
709 You must not ruin the node list. For instance, the head normally is a local par node,
710 and the tail a glue. Messing too much can push \LUATEX\ into panic mode.
712 \subsection{\type {insert_local_par}}
714 Each paragraph starts with a local par node that keeps track of for instance
715 the direction. You can hook a callback into the creator:
717 \startfunctioncall
718 function(<node> local_par, <string> location)
720 \stopfunctioncall
722 There is no return value and you should make sure that the node stays valid
723 as otherwise \TEX\ can get confused.
725 \subsection{\type {mlist_to_hlist}}
727 This callback replaces \LUATEX's math list to node list conversion algorithm.
729 \startfunctioncall
730 function(<node> head, <string> display_type, <boolean> need_penalties)
731 return <node> newhead
733 \stopfunctioncall
735 The returned node is the head of the list that will be added to the vertical or
736 horizontal list, the string argument is either \quote {text} or \quote {display}
737 depending on the current math mode, the boolean argument is \type {true} if
738 penalties have to be inserted in this list, \type {false} otherwise.
740 Setting this callback to \type {false} is bad, it will almost certainly result in
741 an endless loop.
743 \section{Information reporting callbacks}
745 \subsection{\type {pre_dump}}
747 \startfunctioncall
748 function()
750 \stopfunctioncall
752 This function is called just before dumping to a format file starts. It does not
753 replace any code and there are neither arguments nor return values.
755 \subsection{\type {start_run}}
757 \startfunctioncall
758 function()
760 \stopfunctioncall
762 This callback replaces the code that prints \LUATEX's banner. Note that for
763 successful use, this callback has to be set in the \LUA\ initialization script,
764 otherwise it will be seen only after the run has already started.
766 \subsection{\type {stop_run}}
768 \startfunctioncall
769 function()
771 \stopfunctioncall
773 This callback replaces the code that prints \LUATEX's statistics and \quote
774 {output written to} messages.
776 \subsection{\type {start_page_number}}
778 \startfunctioncall
779 function()
781 \stopfunctioncall
783 Replaces the code that prints the \type {[} and the page number at the begin of
784 \type {\shipout}. This callback will also override the printing of box information
785 that normally takes place when \type {\tracingoutput} is positive.
787 \subsection{\type {stop_page_number}}
789 \startfunctioncall
790 function()
792 \stopfunctioncall
794 Replaces the code that prints the \type {]} at the end of \type {\shipout}.
796 \subsection{\type {show_error_hook}}
798 \startfunctioncall
799 function()
801 \stopfunctioncall
803 This callback is run from inside the \TEX\ error function, and the idea is to
804 allow you to do some extra reporting on top of what \TEX\ already does (none of
805 the normal actions are removed). You may find some of the values in the \type
806 {status} table useful. This callback does not replace any internal code.
808 \subsection{\type {show_error_message}}
810 \startfunctioncall
811 function()
813 \stopfunctioncall
815 This callback replaces the code that prints the error message. The usual
816 interaction after the message is not affected.
818 \subsection{\type {show_lua_error_hook}}
820 \startfunctioncall
821 function()
823 \stopfunctioncall
825 This callback replaces the code that prints the extra \LUA\ error message.
827 \subsection{\type {start_file}}
829 \startfunctioncall
830 function(category,filename)
832 \stopfunctioncall
834 This callback replaces the code that prints \LUATEX's when a file is opened like
835 \type {(filename} for regular files. The category is a number:
837 \starttabulate[|||]
838 \NC 1 \NC a normal data file, like a \TEX\ source \NC \NR
839 \NC 2 \NC a font map coupling font names to resources \NC \NR
840 \NC 3 \NC an image file (\type {png}, \type {pdf}, etc) \NC \NR
841 \NC 4 \NC an embedded font subset \NC \NR
842 \NC 5 \NC a fully embedded font \NC \NR
843 \stoptabulate
845 \subsection{\type {stop_file}}
847 \startfunctioncall
848 function(category)
850 \stopfunctioncall
852 This callback replaces the code that prints \LUATEX's when a file is closed like
853 the \type {)} for regular files.
855 \section{PDF-related callbacks}
857 \subsection{\type {finish_pdffile}}
859 \startfunctioncall
860 function()
862 \stopfunctioncall
864 This callback is called when all document pages are already written to the \PDF\
865 file and \LUATEX\ is about to finalize the output document structure. Its
866 intended use is final update of \PDF\ dictionaries such as \type {/Catalog} or
867 \type {/Info}. The callback does not replace any code. There are neither
868 arguments nor return values.
870 \subsection{\type {finish_pdfpage}}
872 \startfunctioncall
873 function(shippingout)
875 \stopfunctioncall
877 This callback is called after the \PDF\ page stream has been assembled and before
878 the page object gets finalized.
880 \section{Font-related callbacks}
882 \subsection{\type {define_font}}
884 \startfunctioncall
885 function(<string> name, <number> size, <number> id)
886 return <table> font | <number> id
888 \stopfunctioncall
890 The string \type {name} is the filename part of the font specification, as given
891 by the user.
893 The number \type {size} is a bit special:
895 \startitemize[packed]
896 \startitem
897 If it is positive, it specifies an \quote{at size} in scaled points.
898 \stopitem
899 \startitem
900 If it is negative, its absolute value represents a \quote {scaled} setting
901 relative to the designsize of the font.
902 \stopitem
903 \stopitemize
905 The \type {id} is the internal number assigned to the font.
907 The internal structure of the \type {font} table that is to be returned is
908 explained in \in {chapter} [fonts]. That table is saved internally, so you can
909 put extra fields in the table for your later \LUA\ code to use. In alternative,
910 \type {retval} can be a previously defined fontid. This is useful if a previous
911 definition can be reused instead of creating a whole new font structure.
913 Setting this callback to \type {false} is pointless as it will prevent font
914 loading completely but will nevertheless generate errors.
916 \stopchapter
918 \stopcomponent