fix getsup (HH)
[luatex.git] / manual / luatex-callbacks.tex
blob37213eb73434e40032579b36fe2525d2d7c51ad7
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[|lT|p|]
401 \NC \rmbf value \NC \bf explanation \NC \NR
402 \NC pre_box \NC interline material is being added \NC \NR
403 \NC pre_adjust \NC \type {\vadjust} material is being added \NC \NR
404 \NC box \NC a typeset box is being added (always called) \NC \NR
405 \NC adjust \NC \type {\vadjust} material is being added \NC \NR
406 \stoptabulate
408 \subsection{\type {buildpage_filter}}
410 This callback is called whenever \LUATEX\ is ready to move stuff to the main
411 vertical list. You can use this callback to do specialized manipulation of the
412 page building stage like imposition or column balancing.
414 \startfunctioncall
415 function(<string> extrainfo)
417 \stopfunctioncall
419 The string \type {extrainfo} gives some additional information about what \TEX's
420 state is with respect to the \quote {current page}. The possible values for the
421 \type {buildpage_filter} callback are:
423 \starttabulate[|lT|p|]
424 \NC \rmbf value \NC \bf explanation \NC \NR
425 \NC alignment \NC a (partial) alignment is being added \NC \NR
426 \NC after_output \NC an output routine has just finished \NC \NR
427 \NC new_graf \NC the beginning of a new paragraph \NC \NR
428 \NC vmode_par \NC \type {\par} was found in vertical mode \NC \NR
429 \NC hmode_par \NC \type {\par} was found in horizontal mode \NC \NR
430 \NC insert \NC an insert is added \NC \NR
431 \NC penalty \NC a penalty (in vertical mode) \NC \NR
432 \NC before_display \NC immediately before a display starts \NC \NR
433 \NC after_display \NC a display is finished \NC \NR
434 \NC end \NC \LUATEX\ is terminating (it's all over) \NC \NR
435 \stoptabulate
437 \subsection{\type {build_page_insert}}
439 This callback is called when the pagebuilder adds an insert. There is not much
440 control over this mechanism but this callback permits some last minute
441 manipulations of the spacing before an insert, something that might be handy when
442 for instance multiple inserts (types) are appended in a row.
444 \startfunctioncall
445 function(<number> n, <number> i)
446 return <number> register
448 \stopfunctioncall
450 with
452 \starttabulate[|lT|p|]
453 \NC \rmbf value \NC \bf explanation \NC \NR
454 \NC n \NC the insert class \NC \NR
455 \NC i \NC the order of the insert \NC \NR
456 \stoptabulate
458 The return value is a number indicating the skip register to use for the
459 prepended spacing. This permits for instance a different top space (when \type
460 {i} equals one) and intermediate space (when \type {i} is larger than one). Of course
461 you can mess with the insert box but you need to make sure that \LUATEX\ is happy
462 afterwards.
464 \subsection{\type {pre_linebreak_filter}}
466 This callback is called just before \LUATEX\ starts converting a list of nodes
467 into a stack of \type {\hbox}es, after the addition of \type {\parfillskip}.
469 \startfunctioncall
470 function(<node> head, <string> groupcode)
471 return true | false | <node> newhead
473 \stopfunctioncall
475 The string called \type {groupcode} identifies the nodelist's context within
476 \TEX's processing. The range of possibilities is given in the table below, but
477 not all of those can actually appear in \type {pre_linebreak_filter}, some are
478 for the \type {hpack_filter} and \type {vpack_filter} callbacks that will be
479 explained in the next two paragraphs.
481 \starttabulate[|lT|p|]
482 \NC \rmbf value \NC \bf explanation \NC \NR
483 \NC <empty> \NC main vertical list \NC \NR
484 \NC hbox \NC \type {\hbox} in horizontal mode \NC \NR
485 \NC adjusted_hbox \NC \type {\hbox} in vertical mode \NC \NR
486 \NC vbox \NC \type {\vbox} \NC \NR
487 \NC vtop \NC \type {\vtop} \NC \NR
488 \NC align \NC \type {\halign} or \type {\valign} \NC \NR
489 \NC disc \NC discretionaries \NC \NR
490 \NC insert \NC packaging an insert \NC \NR
491 \NC vcenter \NC \type {\vcenter} \NC \NR
492 \NC local_box \NC \type {\localleftbox} or \type {\localrightbox} \NC \NR
493 \NC split_off \NC top of a \type {\vsplit} \NC \NR
494 \NC split_keep \NC remainder of a \type {\vsplit} \NC \NR
495 \NC align_set \NC alignment cell \NC \NR
496 \NC fin_row \NC alignment row \NC \NR
497 \stoptabulate
499 As for all the callbacks that deal with nodes, the return value can be one of
500 three things:
502 \startitemize
503 \startitem
504 boolean \type {true} signals successful processing
505 \stopitem
506 \startitem
507 \type {<node>} signals that the \quote {head} node should be replaced by the
508 returned node
509 \stopitem
510 \startitem
511 boolean \type {false} signals that the \quote {head} node list should be
512 ignored and flushed from memory
513 \stopitem
514 \stopitemize
516 This callback does not replace any internal code.
518 \subsection{\type {linebreak_filter}}
520 This callback replaces \LUATEX's line breaking algorithm.
522 \startfunctioncall
523 function(<node> head, <boolean> is_display)
524 return <node> newhead
526 \stopfunctioncall
528 The returned node is the head of the list that will be added to the main vertical
529 list, the boolean argument is true if this paragraph is interrupted by a
530 following math display.
532 If you return something that is not a \type {<node>}, \LUATEX\ will apply the
533 internal linebreak algorithm on the list that starts at \type {<head>}.
534 Otherwise, the \type {<node>} you return is supposed to be the head of a list of
535 nodes that are all allowed in vertical mode, and at least one of those has to
536 represent a hbox. Failure to do so will result in a fatal error.
538 Setting this callback to \type {false} is possible, but dangerous, because it is
539 possible you will end up in an unfixable \quote {deadcycles loop}.
541 \subsection{\type {append_to_vlist_filter}}
543 This callback is called whenever \LUATEX\ adds a box to a vertical list:
545 \startfunctioncall
546 function(<node> box, <string> locationcode, <number prevdepth>,
547 <boolean> mirrored)
548 return list, prevdepth
550 \stopfunctioncall
552 It is ok to return nothing in which case you also need to flush the box or deal
553 with it yourself. The prevdepth is also optional. Locations are \type {box},
554 \type {alignment}, \type {equation}, \type {equation_number} and \type
555 {post_linebreak}.
557 \subsection{\type {post_linebreak_filter}}
559 This callback is called just after \LUATEX\ has converted a list of nodes into a
560 stack of \type {\hbox}es.
562 \startfunctioncall
563 function(<node> head, <string> groupcode)
564 return true | false | <node> newhead
566 \stopfunctioncall
568 This callback does not replace any internal code.
570 \subsection{\type {hpack_filter}}
572 This callback is called when \TEX\ is ready to start boxing some horizontal mode
573 material. Math items and line boxes are ignored at the moment.
575 \startfunctioncall
576 function(<node> head, <string> groupcode, <number> size,
577 <string> packtype [, <string> direction] [, <node> attributelist])
578 return true | false | <node> newhead
580 \stopfunctioncall
582 The \type {packtype} is either \type {additional} or \type {exactly}. If \type
583 {additional}, then the \type {size} is a \type {\hbox spread ...} argument. If
584 \type {exactly}, then the \type {size} is a \type {\hbox to ...}. In both cases,
585 the number is in scaled points.
587 The \type {direction} is either one of the three-letter direction specifier
588 strings, or \type {nil}.
590 This callback does not replace any internal code.
592 \subsection{\type {vpack_filter}}
594 This callback is called when \TEX\ is ready to start boxing some vertical mode
595 material. Math displays are ignored at the moment.
597 This function is very similar to the \type {hpack_filter}. Besides the fact
598 that it is called at different moments, there is an extra variable that matches
599 \TEX's \type {\maxdepth} setting.
601 \startfunctioncall
602 function(<node> head, <string> groupcode, <number> size, <string> packtype,
603 <number> maxdepth [, <string> direction] [, <node> attributelist]))
604 return true | false | <node> newhead
606 \stopfunctioncall
608 This callback does not replace any internal code.
610 \subsection{\type {hpack_quality}}
612 This callback can be used to intercept the overfull messages that can result from
613 packing a horizontal list (as happens in the par builder). The function takes a
614 few arguments:
616 \startfunctioncall
617 function(<string> incident, <number> detail, <node> head, <number> first,
618 <number> last)
619 return <node> whatever
621 \stopfunctioncall
623 The incident is one of \type {overfull}, \type {underfull}, \type {loose} or
624 \type {tight}. The detail is either the amount of overflow in case of \type
625 {overfull}, or the badness otherwise. The head is the list that is constructed
626 (when protrusion or expansion is enabled, this is an intermediate list).
627 Optionally you can return a node, for instance an overfull rule indicator. That
628 node will be appended to the list (just like \TEX's own rule would).
630 \subsection{\type {vpack_quality}}
632 This callback can be used to intercept the overfull messages that can result from
633 packing a vertical list (as happens in the page builder). The function takes a
634 few arguments:
636 \startfunctioncall
637 function(<string> incident, <number> detail, <node> head, <number> first,
638 <number> last)
640 \stopfunctioncall
642 The incident is one of \type {overfull}, \type {underfull}, \type {loose} or
643 \type {tight}. The detail is either the amount of overflow in case of \type
644 {overfull}, or the badness otherwise. The head is the list that is constructed.
646 \subsection{\type {process_rule}}
648 This is an experimental callback. It can be used with rules of subtype~4
649 (user). The callback gets three arguments: the node, the width and the
650 height. The callback can use \type {pdf.print} to write code to the \PDF\
651 file but beware of not messing up the final result. No checking is done.
653 \subsection{\type {pre_output_filter}}
655 This callback is called when \TEX\ is ready to start boxing the box 255 for \type
656 {\output}.
658 \startfunctioncall
659 function(<node> head, <string> groupcode, <number> size, <string> packtype,
660 <number> maxdepth [, <string> direction])
661 return true | false | <node> newhead
663 \stopfunctioncall
665 This callback does not replace any internal code.
667 \subsection{\type {hyphenate}}
669 \startfunctioncall
670 function(<node> head, <node> tail)
672 \stopfunctioncall
674 No return values. This callback has to insert discretionary nodes in the node
675 list it receives.
677 Setting this callback to \type {false} will prevent the internal discretionary
678 insertion pass.
680 \subsection{\type {ligaturing}}
682 \startfunctioncall
683 function(<node> head, <node> tail)
685 \stopfunctioncall
687 No return values. This callback has to apply ligaturing to the node list it
688 receives.
690 You don't have to worry about return values because the \type {head} node that is
691 passed on to the callback is guaranteed not to be a glyph_node (if need be, a
692 temporary node will be prepended), and therefore it cannot be affected by the
693 mutations that take place. After the callback, the internal value of the \quote
694 {tail of the list} will be recalculated.
696 The \type {next} of \type {head} is guaranteed to be non-nil.
698 The \type {next} of \type {tail} is guaranteed to be nil, and therefore the
699 second callback argument can often be ignored. It is provided for orthogonality,
700 and because it can sometimes be handy when special processing has to take place.
702 Setting this callback to \type {false} will prevent the internal ligature
703 creation pass.
705 You must not ruin the node list. For instance, the head normally is a local par node,
706 and the tail a glue. Messing too much can push \LUATEX\ into panic mode.
708 \subsection{\type {kerning}}
710 \startfunctioncall
711 function(<node> head, <node> tail)
713 \stopfunctioncall
715 No return values. This callback has to apply kerning between the nodes in the
716 node list it receives. See \type {ligaturing} for calling conventions.
718 Setting this callback to \type {false} will prevent the internal kern insertion
719 pass.
721 You must not ruin the node list. For instance, the head normally is a local par node,
722 and the tail a glue. Messing too much can push \LUATEX\ into panic mode.
724 \subsection{\type {insert_local_par}}
726 Each paragraph starts with a local par node that keeps track of for instance
727 the direction. You can hook a callback into the creator:
729 \startfunctioncall
730 function(<node> local_par, <string> location)
732 \stopfunctioncall
734 There is no return value and you should make sure that the node stays valid
735 as otherwise \TEX\ can get confused.
737 \subsection{\type {mlist_to_hlist}}
739 This callback replaces \LUATEX's math list to node list conversion algorithm.
741 \startfunctioncall
742 function(<node> head, <string> display_type, <boolean> need_penalties)
743 return <node> newhead
745 \stopfunctioncall
747 The returned node is the head of the list that will be added to the vertical or
748 horizontal list, the string argument is either \quote {text} or \quote {display}
749 depending on the current math mode, the boolean argument is \type {true} if
750 penalties have to be inserted in this list, \type {false} otherwise.
752 Setting this callback to \type {false} is bad, it will almost certainly result in
753 an endless loop.
755 \section{Information reporting callbacks}
757 \subsection{\type {pre_dump}}
759 \startfunctioncall
760 function()
762 \stopfunctioncall
764 This function is called just before dumping to a format file starts. It does not
765 replace any code and there are neither arguments nor return values.
767 \subsection{\type {start_run}}
769 \startfunctioncall
770 function()
772 \stopfunctioncall
774 This callback replaces the code that prints \LUATEX's banner. Note that for
775 successful use, this callback has to be set in the \LUA\ initialization script,
776 otherwise it will be seen only after the run has already started.
778 \subsection{\type {stop_run}}
780 \startfunctioncall
781 function()
783 \stopfunctioncall
785 This callback replaces the code that prints \LUATEX's statistics and \quote
786 {output written to} messages.
788 \subsection{\type {start_page_number}}
790 \startfunctioncall
791 function()
793 \stopfunctioncall
795 Replaces the code that prints the \type {[} and the page number at the begin of
796 \type {\shipout}. This callback will also override the printing of box information
797 that normally takes place when \type {\tracingoutput} is positive.
799 \subsection{\type {stop_page_number}}
801 \startfunctioncall
802 function()
804 \stopfunctioncall
806 Replaces the code that prints the \type {]} at the end of \type {\shipout}.
808 \subsection{\type {show_error_hook}}
810 \startfunctioncall
811 function()
813 \stopfunctioncall
815 This callback is run from inside the \TEX\ error function, and the idea is to
816 allow you to do some extra reporting on top of what \TEX\ already does (none of
817 the normal actions are removed). You may find some of the values in the \type
818 {status} table useful. This callback does not replace any internal code.
820 \subsection{\type {show_error_message}}
822 \startfunctioncall
823 function()
825 \stopfunctioncall
827 This callback replaces the code that prints the error message. The usual
828 interaction after the message is not affected.
830 \subsection{\type {show_lua_error_hook}}
832 \startfunctioncall
833 function()
835 \stopfunctioncall
837 This callback replaces the code that prints the extra \LUA\ error message.
839 \subsection{\type {start_file}}
841 \startfunctioncall
842 function(category,filename)
844 \stopfunctioncall
846 This callback replaces the code that prints \LUATEX's when a file is opened like
847 \type {(filename} for regular files. The category is a number:
849 \starttabulate[|||]
850 \NC 1 \NC a normal data file, like a \TEX\ source \NC \NR
851 \NC 2 \NC a font map coupling font names to resources \NC \NR
852 \NC 3 \NC an image file (\type {png}, \type {pdf}, etc) \NC \NR
853 \NC 4 \NC an embedded font subset \NC \NR
854 \NC 5 \NC a fully embedded font \NC \NR
855 \stoptabulate
857 \subsection{\type {stop_file}}
859 \startfunctioncall
860 function(category)
862 \stopfunctioncall
864 This callback replaces the code that prints \LUATEX's when a file is closed like
865 the \type {)} for regular files.
867 \subsection{\type {call_edit}}
869 \startfunctioncall
870 function(filename,linenumber)
872 \stopfunctioncall
874 This callback replaces the call to an external editor when \quote{E} is pressed
875 in reply to an error message. Processing will end immediately after the callback
876 returns control to the main program.
878 \section{PDF-related callbacks}
880 \subsection{\type {finish_pdffile}}
882 \startfunctioncall
883 function()
885 \stopfunctioncall
887 This callback is called when all document pages are already written to the \PDF\
888 file and \LUATEX\ is about to finalize the output document structure. Its
889 intended use is final update of \PDF\ dictionaries such as \type {/Catalog} or
890 \type {/Info}. The callback does not replace any code. There are neither
891 arguments nor return values.
893 \subsection{\type {finish_pdfpage}}
895 \startfunctioncall
896 function(shippingout)
898 \stopfunctioncall
900 This callback is called after the \PDF\ page stream has been assembled and before
901 the page object gets finalized.
903 \section{Font-related callbacks}
905 \subsection{\type {define_font}}
907 \startfunctioncall
908 function(<string> name, <number> size, <number> id)
909 return <table> font | <number> id
911 \stopfunctioncall
913 The string \type {name} is the filename part of the font specification, as given
914 by the user.
916 The number \type {size} is a bit special:
918 \startitemize[packed]
919 \startitem
920 If it is positive, it specifies an \quote{at size} in scaled points.
921 \stopitem
922 \startitem
923 If it is negative, its absolute value represents a \quote {scaled} setting
924 relative to the designsize of the font.
925 \stopitem
926 \stopitemize
928 The \type {id} is the internal number assigned to the font.
930 The internal structure of the \type {font} table that is to be returned is
931 explained in \in {chapter} [fonts]. That table is saved internally, so you can
932 put extra fields in the table for your later \LUA\ code to use. In alternative,
933 \type {retval} can be a previously defined fontid. This is useful if a previous
934 definition can be reused instead of creating a whole new font structure.
936 Setting this callback to \type {false} is pointless as it will prevent font
937 loading completely but will nevertheless generate errors.
939 \stopchapter
941 \stopcomponent