| 1 |
% language=us runpath=texruns:manuals/luametatex |
| 2 |
|
| 3 |
\environment luametatex-style |
| 4 |
|
| 5 |
% callback.names |
| 6 |
% also numbers |
| 7 |
|
| 8 |
\startdocument[title=Callbacks] |
| 9 |
|
| 10 |
\startsection[title={Introduction}] |
| 11 |
|
| 12 |
Right from the start of the \LUATEX\ project callbacks were the way to extend the |
| 13 |
engine. At various places in processing the document source and typesetting the |
| 14 |
text the engine checks if there is a callback set and if so, calls out to \LUA. |
| 15 |
Here we collect the various callbacks. For examples you can consult the \CONTEXT\ |
| 16 |
code base. |
| 17 |
|
| 18 |
The \type {callback} library has functions that register, find and list |
| 19 |
callbacks. Callbacks are \LUA\ functions that are called in well defined places. |
| 20 |
There are two kinds of callbacks: those that mix with existing functionality, and |
| 21 |
those that (when enabled) replace functionality. In most cases the second |
| 22 |
category is expected to behave similar to the built in functionality because in a |
| 23 |
next step specific data is expected. For instance, you can replace the |
| 24 |
hyphenation routine. The function gets a list that can be hyphenated (or not). |
| 25 |
The final list should be valid and is (normally) used for constructing a |
| 26 |
paragraph. Another function can replace the ligature builder and|/|or kern |
| 27 |
routine. Doing something else is possible but in the end might not give the user |
| 28 |
the expected outcome. |
| 29 |
|
| 30 |
In order for a callback to kick in you need register it. This can be permanent or |
| 31 |
temporarily. |
| 32 |
|
| 33 |
\starttyping[option=LUA] |
| 34 |
id = callback.register(<t:string> callback_name, <function> func) |
| 35 |
id = callback.register(<t:string> callback_name, nil) |
| 36 |
id = callback.register(<t:string> callback_name, false) |
| 37 |
\stoptyping |
| 38 |
|
| 39 |
Here the \type {callback_name} is a predefined callback name as discusses in |
| 40 |
following sections. The function returns the internal \type {id} of the callback |
| 41 |
or \type {nil}, if the callback could not be registered. \LUAMETATEX\ |
| 42 |
internalizes the callback function in such a way that it does not matter if you |
| 43 |
redefine a function accidentally. |
| 44 |
|
| 45 |
Callback assignments are always global. You can use the special value \type {nil} |
| 46 |
instead of a function for clearing the callback. |
| 47 |
|
| 48 |
For some minor speed gain, you can assign the boolean \type {false} to the |
| 49 |
non|-|file related callbacks, doing so will prevent \LUATEX\ from executing |
| 50 |
whatever it would execute by default (when no callback function is registered at |
| 51 |
all). {\em This needs checking.} |
| 52 |
|
| 53 |
\starttyping[option=LUA] |
| 54 |
<table> info = callback.list() |
| 55 |
\stoptyping |
| 56 |
|
| 57 |
The keys in the table are the known callback names, the value is a boolean where |
| 58 |
\type {true} means that the callback is currently set (active). |
| 59 |
|
| 60 |
\starttyping[option=LUA] |
| 61 |
<function> f = callback.find(callback_name) |
| 62 |
\stoptyping |
| 63 |
|
| 64 |
If the callback is not set, \type {find} returns \type {nil}. The \type {known} |
| 65 |
function can be used to check if a callback is supported. |
| 66 |
|
| 67 |
\starttyping[option=LUA] |
| 68 |
if callback.known("foo") then |
| 69 |
-- do what is needed |
| 70 |
end |
| 71 |
\stoptyping |
| 72 |
|
| 73 |
\stopsection |
| 74 |
|
| 75 |
\startsection[title=Files] |
| 76 |
|
| 77 |
\startsubsection[title=find_log_file] |
| 78 |
|
| 79 |
This is one of the callbacks that has to be set in order for the engine to work |
| 80 |
at all. |
| 81 |
|
| 82 |
\starttyping[option=LUA] |
| 83 |
function ( |
| 84 |
<t:string> askedname |
| 85 |
) |
| 86 |
return <t:string> foundname |
| 87 |
end |
| 88 |
\stoptyping |
| 89 |
|
| 90 |
\stopsubsection |
| 91 |
|
| 92 |
\startsubsection[title=find_format_file] |
| 93 |
|
| 94 |
A format file is an efficient memory dump of the (in our case \CONTEXT) macro |
| 95 |
package. In \LUATEX\ it can have a mix of \TEX and \LUA\ code but one should be |
| 96 |
aware that storing the \LUA\ state is not up to the engine. |
| 97 |
|
| 98 |
\starttyping[option=LUA] |
| 99 |
function (<t:string> askedname) |
| 100 |
return <t:string> foundname |
| 101 |
end |
| 102 |
\stoptyping |
| 103 |
|
| 104 |
A format file can be read from any valid location but is always written in the |
| 105 |
current directory. When written the number of bytes for each section is reported. |
| 106 |
When read all kind of checks take place ijn order to intercept corruption or |
| 107 |
incompatibilities. Contrary to \LUATEX, the \LUAMETATEX\ is not (zip) compressed so, |
| 108 |
in spite of more aggressive compression of data otherwise the file is a bit larger. |
| 109 |
|
| 110 |
\stopsubsection |
| 111 |
|
| 112 |
\startsubsection[title=open_data_file] |
| 113 |
|
| 114 |
This callback function gets a filename passed. The return value is either the boolean |
| 115 |
value false or a table with two functions. A mandate \type {reader} function fill be |
| 116 |
called once for each new line to be read, the optional \type {close} function will |
| 117 |
be called once \LUATEX\ is done with the file. |
| 118 |
|
| 119 |
\starttyping[option=LUA] |
| 120 |
function ( |
| 121 |
<t:string> filename |
| 122 |
) |
| 123 |
return <table> { |
| 124 |
<function> reader(<table> environment) end, |
| 125 |
<function> close (<table> environment) end, |
| 126 |
} |
| 127 |
end |
| 128 |
\stoptyping |
| 129 |
|
| 130 |
\LUAMETATEX\ never looks at the rest of the table, so we can use it to store |
| 131 |
additional per|-|file data. Both the callback functions will receive the table as |
| 132 |
their only argument. |
| 133 |
|
| 134 |
\stopsubsection |
| 135 |
|
| 136 |
\startsubsection[title=start_file] |
| 137 |
|
| 138 |
This callback replaces the code that \LUAMETATEX\ prints when a file is opened like |
| 139 |
\type {(filename} for regular files. The category is a number: |
| 140 |
|
| 141 |
\starttyping[option=LUA] |
| 142 |
function ( |
| 143 |
<t:integer> category, |
| 144 |
<t:string> filename |
| 145 |
) |
| 146 |
-- no return values |
| 147 |
end |
| 148 |
\stoptyping |
| 149 |
|
| 150 |
The following categories can occur: |
| 151 |
|
| 152 |
\starttabulate[|c|l|] |
| 153 |
% \DB value \BC meaning \NC \NR |
| 154 |
% \TB |
| 155 |
\FL |
| 156 |
\BC value \BC meaning \NC \NR |
| 157 |
\ML |
| 158 |
\NC 1 \NC a normal data file, like a \TEX\ source \NC \NR |
| 159 |
\NC 2 \NC a font map coupling font names to resources \NC \NR |
| 160 |
\NC 3 \NC an image file (\type {png}, \type {pdf}, etc) \NC \NR |
| 161 |
\NC 4 \NC an embedded font subset \NC \NR |
| 162 |
\NC 5 \NC a fully embedded font \NC \NR |
| 163 |
\LL |
| 164 |
\stoptabulate |
| 165 |
|
| 166 |
\stopsubsection |
| 167 |
|
| 168 |
\startsubsection[title=stop_file] |
| 169 |
|
| 170 |
This callback replaces the code that \LUAMETATEX\ prints when a file is closed like |
| 171 |
the \type {)} for regular files. |
| 172 |
|
| 173 |
\starttyping[option=LUA] |
| 174 |
function ( |
| 175 |
<t:integer> category |
| 176 |
) |
| 177 |
-- no return values |
| 178 |
end |
| 179 |
\stoptyping |
| 180 |
|
| 181 |
\stopsubsection |
| 182 |
|
| 183 |
\stopsection |
| 184 |
|
| 185 |
\startsection[title=Running] |
| 186 |
|
| 187 |
\startsubsection[title=process_jobname] |
| 188 |
|
| 189 |
This callback allows you to change the jobname given by \type {\jobname} in \TEX\ |
| 190 |
and \type {tex.jobname} in \LUA. It does not affect the internal job name or the |
| 191 |
name of the output or log files. |
| 192 |
|
| 193 |
\starttyping[option=LUA] |
| 194 |
function ( |
| 195 |
<t:string> jobname |
| 196 |
) |
| 197 |
return <t:string> adjusted_jobname |
| 198 |
end |
| 199 |
\stoptyping |
| 200 |
|
| 201 |
The only argument is the actual job name; you should not use \type {tex.jobname} |
| 202 |
inside this function or infinite recursion may occur. If you return \type {nil}, |
| 203 |
\LUAMETATEX\ will pretend your callback never happened. This callback does not |
| 204 |
replace any internal code. |
| 205 |
|
| 206 |
\stopsubsection |
| 207 |
|
| 208 |
\startsubsection[title=pre_dump] |
| 209 |
|
| 210 |
This function is called just before dumping to a format file starts. It does not |
| 211 |
replace any code and there are neither arguments nor return values. It can be used to do some |
| 212 |
cleanup and other housekeeping. |
| 213 |
|
| 214 |
\starttyping[option=LUA] |
| 215 |
function ( |
| 216 |
-- no arguments |
| 217 |
) |
| 218 |
-- no return values |
| 219 |
end |
| 220 |
\stoptyping |
| 221 |
|
| 222 |
\stopsubsection |
| 223 |
|
| 224 |
\startsubsection[title=start_run] |
| 225 |
|
| 226 |
\starttyping[option=LUA] |
| 227 |
function( |
| 228 |
-- no arguments |
| 229 |
) |
| 230 |
-- no return values |
| 231 |
end |
| 232 |
\stoptyping |
| 233 |
|
| 234 |
This callback replaces the code that prints \LUATEX's banner. Note that for |
| 235 |
successful use, this callback has to be set in the \LUA\ initialization script, |
| 236 |
otherwise it will be seen only after the run has already started. |
| 237 |
|
| 238 |
\stopsubsection |
| 239 |
|
| 240 |
\startsubsection[title=stop_run] |
| 241 |
|
| 242 |
\starttyping[option=LUA] |
| 243 |
function( |
| 244 |
-- no arguments |
| 245 |
) |
| 246 |
-- no return values |
| 247 |
end |
| 248 |
\stoptyping |
| 249 |
|
| 250 |
This callback replaces the code that prints \LUATEX's statistics and \quote |
| 251 |
{output written to} messages. The engine can still do housekeeping and therefore |
| 252 |
you should not rely on this hook for postprocessing the \PDF\ or log file. |
| 253 |
|
| 254 |
\stopsubsection |
| 255 |
|
| 256 |
\startsubsection[title=intercept_tex_error] |
| 257 |
|
| 258 |
This callback is run from inside the \TEX\ error function, and the idea is to |
| 259 |
allow you to do some extra reporting on top of what \TEX\ already does (none of |
| 260 |
the normal actions are removed). You may find some of the values in the \type |
| 261 |
{status} table useful. The \TEX\ related callback gets two arguments: the current |
| 262 |
processing mode and a boolean indicating if there was a runaway. |
| 263 |
|
| 264 |
|
| 265 |
\starttyping[option=LUA] |
| 266 |
function ( |
| 267 |
-- no arguments |
| 268 |
) |
| 269 |
-- no return values |
| 270 |
end |
| 271 |
\stoptyping |
| 272 |
|
| 273 |
\stopsubsection |
| 274 |
|
| 275 |
\startsubsection[title=intercept_lua_error] |
| 276 |
|
| 277 |
This callback is similar to the one discussed in the previous section but for |
| 278 |
\LUA. Of course we should in a recoverable state for this to work well. |
| 279 |
|
| 280 |
\starttyping[option=LUA] |
| 281 |
function ( |
| 282 |
-- no arguments |
| 283 |
) |
| 284 |
-- no return values |
| 285 |
end |
| 286 |
\stoptyping |
| 287 |
|
| 288 |
\stopsubsection |
| 289 |
|
| 290 |
\startsubsection[title=show_error_message] |
| 291 |
|
| 292 |
This callback replaces the code that prints the error message. The usual |
| 293 |
interaction after the message is not affected but it is best to quit the run |
| 294 |
after reporting. |
| 295 |
|
| 296 |
\starttyping[option=LUA] |
| 297 |
function ( |
| 298 |
-- no arguments |
| 299 |
) |
| 300 |
-- no return values |
| 301 |
end |
| 302 |
\stoptyping |
| 303 |
|
| 304 |
\stopsubsection |
| 305 |
|
| 306 |
\startsubsection[title=show_warning_message] |
| 307 |
|
| 308 |
This callback replaces the code that prints a (non fatal) warning message. The |
| 309 |
usual interaction after the message is not affected. |
| 310 |
|
| 311 |
\starttyping[option=LUA] |
| 312 |
function ( |
| 313 |
-- no arguments |
| 314 |
) |
| 315 |
-- no return values |
| 316 |
end |
| 317 |
\stoptyping |
| 318 |
|
| 319 |
\stopsubsection |
| 320 |
|
| 321 |
\startsubsection[title=wrapup_run] |
| 322 |
|
| 323 |
|
| 324 |
This callback is called after the \PDF\ and log files are closed. Use it at your own |
| 325 |
risk. efine_f |
| 326 |
risk. |
| 327 |
|
| 328 |
\starttyping[option=LUA] |
| 329 |
function ( |
| 330 |
-- no arguments |
| 331 |
) |
| 332 |
-- no return values |
| 333 |
end |
| 334 |
\stoptyping |
| 335 |
|
| 336 |
\stopsubsection |
| 337 |
|
| 338 |
\startsubsection[title=handle_overload] |
| 339 |
|
| 340 |
One characteristic of \TEX\ is that you have quite some control over what a |
| 341 |
control sequence triggers. For instance, \type {\hbox} normally starts a |
| 342 |
horizontal box but a user can redefine this primitive as macro to do whatever is |
| 343 |
required. This means that when other macros use this primitive their behavior |
| 344 |
will change. One way out of this is using aliases, for instance: |
| 345 |
|
| 346 |
\starttyping |
| 347 |
\normalsetbox0\normalhbox{test} |
| 348 |
\normalifdim\normalwd0>10pt \normalbox0 \normalfi |
| 349 |
\stoptyping |
| 350 |
|
| 351 |
But even these normal aliases can be redefined. Of course you can use special |
| 352 |
characters like \type {_} in names but once you start doing this: |
| 353 |
|
| 354 |
\starttyping |
| 355 |
\p_setbox0\p_hbox{test} |
| 356 |
\p_ifdim\p_wd0>10pt \p_box0 \p_fi |
| 357 |
\stoptyping |
| 358 |
|
| 359 |
you should wonder if you still offer the user \TEX\ as a programming language. |
| 360 |
It's not the route that \CONTEXT\ takes. |
| 361 |
|
| 362 |
In \LUAMETATEX\ every macro (including primitives) can be flagged and that happens |
| 363 |
with so called prefixes. Traditional \TEX\ offers: |
| 364 |
|
| 365 |
\starttyping |
| 366 |
\global\def\foo{...} |
| 367 |
\long \def\foo{...} % no-op |
| 368 |
\outer \def\foo{...} % no-op |
| 369 |
\stoptyping |
| 370 |
|
| 371 |
The \type {\long} and \type {\outer} made sense at that time but are no-ops in |
| 372 |
\LUAMETATEX: every macro can take \type {\par} equivalents as arguments and can |
| 373 |
be \ defined at every level. The \ETEX\ extensions introduced this prefix: |
| 374 |
|
| 375 |
\starttyping |
| 376 |
\protected\def\foo{...} |
| 377 |
\stoptyping |
| 378 |
|
| 379 |
which prevents expansion unless the value is really expected (needed). The |
| 380 |
\LUAMETATEX\ engine added: |
| 381 |
|
| 382 |
\starttyping |
| 383 |
\semiprotected\def\foo{...} |
| 384 |
\stoptyping |
| 385 |
|
| 386 |
but when eventually I see no reason to use it in \CONTEXT\ it might be dropped. A |
| 387 |
special prefix is: |
| 388 |
|
| 389 |
\starttyping |
| 390 |
\constant\def\foo{...} |
| 391 |
\stoptyping |
| 392 |
|
| 393 |
This effectively is equivalent to \type {\edef} but signals that in some |
| 394 |
scenarios (like an \type {\csname} equivalent situation) no expansion and |
| 395 |
checking has to happen which improves performance. |
| 396 |
|
| 397 |
These two prefixes are just signals to \LUA\ driven functionality: |
| 398 |
|
| 399 |
\starttyping |
| 400 |
\deferred \foo |
| 401 |
\immediate \foo |
| 402 |
\stoptyping |
| 403 |
|
| 404 |
The prefixes do nothing except when \type {\foo} are \LUA\ calls that can use |
| 405 |
this information to adapt behavior. Because we have no backend the macro package |
| 406 |
has to come up with equivalents for e.g.\ \type {\write} than can be immediate or |
| 407 |
deferred (default) operations. |
| 408 |
|
| 409 |
Another prefix relates to alignments: |
| 410 |
|
| 411 |
\starttyping |
| 412 |
\noaligned\protected\def\foo{...} |
| 413 |
\stoptyping |
| 414 |
|
| 415 |
Which makes a macro accepted between alignment rows where otherwise protected |
| 416 |
macros will trigger an error due to look ahead. |
| 417 |
|
| 418 |
A definition with \type {\def} or \type {\gdef} can take arguments and these can be |
| 419 |
made optional with: |
| 420 |
|
| 421 |
\starttyping |
| 422 |
\def\tolerant[#1]{...} |
| 423 |
\stoptyping |
| 424 |
|
| 425 |
but there are more features related to tolerant: |
| 426 |
|
| 427 |
\starttyping |
| 428 |
\def\tolerant[#1]#*[#2]{...} |
| 429 |
\stoptyping |
| 430 |
|
| 431 |
that are discusses in low level manuals. Users can define macros that are |
| 432 |
reported (in tracing) as if they were primitives: |
| 433 |
|
| 434 |
\starttyping |
| 435 |
\untraced\protected\def\foo{...} |
| 436 |
\stoptyping |
| 437 |
|
| 438 |
The prefixes \type {\constrained} and \type {\retained} relate to register values |
| 439 |
being saved and restored in groups. The \type {\inherited} is used in for |
| 440 |
instance math spacing assignments where we need dynamic binding to for instance |
| 441 |
\type {\muskip} registers (instead of values). |
| 442 |
|
| 443 |
Although not related to the callback discussed here we mentioned these prefixes because |
| 444 |
they belong to the \type {prefixed_cmd} operator|/|operand pair. So to come back to |
| 445 |
users being able to use primitives instead of funny unreadable aliases. It's good to |
| 446 |
keep in mind that one can combine prefixes like the following: |
| 447 |
|
| 448 |
\starttyping |
| 449 |
\frozen \foo{...} |
| 450 |
\immutable \foo{...} |
| 451 |
\instance \foo{...} |
| 452 |
\mutable \foo{...} |
| 453 |
\overloaded\foo{...} |
| 454 |
\permanent \foo{...} |
| 455 |
\stoptyping |
| 456 |
|
| 457 |
so this is valid too: |
| 458 |
|
| 459 |
\starttyping |
| 460 |
\global\permanent\untraced\tolerant\protected\def\foo[#1]#*[#2]{...} |
| 461 |
\stoptyping |
| 462 |
|
| 463 |
So what do these prefixes do? It depends on the value of an internal |
| 464 |
integer \type {\overloadmode} where the following values have meaning: |
| 465 |
|
| 466 |
\starttabulate[|c|l|c|c|c|c|c|] |
| 467 |
% \DB \BC \BC immutable \BC permanent \BC primitive \BC frozen \BC instance \NC \NR |
| 468 |
% \TB |
| 469 |
\FL |
| 470 |
\BC \BC \BC immutable \BC permanent \BC primitive \BC frozen \BC instance \NC \NR |
| 471 |
\ML |
| 472 |
\NC 1 \NC warning \NC \star \NC \star \NC \star \NC \NC \NC \NR |
| 473 |
\NC 2 \NC error \NC \star \NC \star \NC \star \NC \NC \NC \NR |
| 474 |
\NC 3 \NC warning \NC \star \NC \star \NC \star \NC \star \NC \NC \NR |
| 475 |
\NC 4 \NC error \NC \star \NC \star \NC \star \NC \star \NC \NC \NR |
| 476 |
\NC 5 \NC warning \NC \star \NC \star \NC \star \NC \star \NC \star \NC \NR |
| 477 |
\NC 6 \NC error \NC \star \NC \star \NC \star \NC \star \NC \star \NC \NR |
| 478 |
\LL |
| 479 |
\stoptabulate |
| 480 |
|
| 481 |
The \type {\enforced} prefix can be used to bypass this mechanism: |
| 482 |
|
| 483 |
\starttyping |
| 484 |
\permanent\protected\def\foo{...} |
| 485 |
|
| 486 |
\protected\def\oof{\enforced\def\foo{...}} |
| 487 |
\stoptyping |
| 488 |
|
| 489 |
But only in so called quote {ini} mode, that is when the format file is created. In order to |
| 490 |
save work we also have: |
| 491 |
|
| 492 |
\starttyping |
| 493 |
\aliased\let\foo\relax |
| 494 |
\stoptyping |
| 495 |
|
| 496 |
This makes \type {\foo} a copy (or more precise, a reference) including all |
| 497 |
flags, so in this case it will be flagged a a primitive which is \type |
| 498 |
{\permanent} too. You cannot define primitives yourself but when reported in a |
| 499 |
trace you see it being a primitive indeed. |
| 500 |
|
| 501 |
Of course this all means that one has to define basically all relevant macros |
| 502 |
with a combination of prefixes and that happens to be the case in \CONTEXT, which |
| 503 |
in the end makes this callback a rather \CONTEXT\ specific one. |
| 504 |
|
| 505 |
\starttyping[option=LUA] |
| 506 |
function ( |
| 507 |
<t:boolean> error, |
| 508 |
<t:integer> overload, |
| 509 |
<t:string> csname, |
| 510 |
<t:integer> flags |
| 511 |
) |
| 512 |
-- no return values |
| 513 |
end |
| 514 |
\stoptyping |
| 515 |
|
| 516 |
\stopsubsection |
| 517 |
|
| 518 |
\stopsection |
| 519 |
|
| 520 |
\startsection[title=Fonts] |
| 521 |
|
| 522 |
\startsubsection[title=define_font] |
| 523 |
|
| 524 |
The engine has no font loader but it does need some information about the glyphs |
| 525 |
that are uses like width, height and depth, possibly italic correction, kerns, |
| 526 |
and ligatures. And for math some more information is needed. Keep in mind that |
| 527 |
for instance italic correction is something specific for \TEX\ and that kerns and |
| 528 |
ligatures only are needed when you leave them to the engine. For modern \OPENTYPE\ fonts |
| 529 |
we let \LUA\ deal with this. |
| 530 |
|
| 531 |
\starttyping[option=LUA] |
| 532 |
function ( |
| 533 |
<t:string> name, |
| 534 |
<t:integer> size |
| 535 |
) |
| 536 |
return <t:integer> id |
| 537 |
end |
| 538 |
\stoptyping |
| 539 |
|
| 540 |
The string \type {name} is the filename part of the font specification, as given |
| 541 |
by the user, for instance when \type {\font} is used for defining an instance. |
| 542 |
The number \type {size} is a bit special: |
| 543 |
|
| 544 |
\startitemize[packed] |
| 545 |
\startitem |
| 546 |
If it is positive, it specifies an \quote{at size} in scaled points. |
| 547 |
\stopitem |
| 548 |
\startitem |
| 549 |
If it is negative, its absolute value represents a \quote {scaled} setting |
| 550 |
relative to the design size of the font. |
| 551 |
\stopitem |
| 552 |
\stopitemize |
| 553 |
|
| 554 |
The font can be defined with \type {font.define} which returns a font identifier |
| 555 |
that can be returned in the callback. Contrary to \LUATEX, in \LUAMETATEX\ |
| 556 |
we only accept a number. |
| 557 |
|
| 558 |
The internal structure of the \type {font} table that is passed to \type |
| 559 |
{font.define} is explained elsewhere but there can be much more in that table. |
| 560 |
Likely the macro package will keep the passes table around for other usage, for |
| 561 |
instance for usage in the backend. |
| 562 |
|
| 563 |
Setting this callback to \type {false} is pointless because it will prevent font |
| 564 |
loading completely because without fonts there is little to do for the engine. |
| 565 |
|
| 566 |
\stopsubsection |
| 567 |
|
| 568 |
\startsubsection[title=quality_font] |
| 569 |
|
| 570 |
When you use font expansion you will normally pass the glyph specific expansion and |
| 571 |
compression values along with the dimensions. However, this can be delayed. When we |
| 572 |
use par passes (or otherwise set one of the adjust parameters) and a font has not |
| 573 |
yet bee setup for expansion this callback will kick in but only once per font. |
| 574 |
|
| 575 |
\starttyping[option=LUA] |
| 576 |
function ( |
| 577 |
<t:integer> id |
| 578 |
) |
| 579 |
-- no return values |
| 580 |
end |
| 581 |
\stoptyping |
| 582 |
|
| 583 |
The function can set additional parameters in the font and pass them to \TEX\ using |
| 584 |
helpers from the font library. |
| 585 |
|
| 586 |
\stopsubsection |
| 587 |
|
| 588 |
\stopsection |
| 589 |
|
| 590 |
\startsection[title=Typesetting] |
| 591 |
|
| 592 |
\startsubsection[title=pre_output] |
| 593 |
|
| 594 |
This callback is called when \TEX\ is ready to start boxing the box 255 for \prm |
| 595 |
{output}. The callback does not replace any internal code. |
| 596 |
|
| 597 |
\starttyping[option=LUA] |
| 598 |
function ( |
| 599 |
<t:node> head, |
| 600 |
<t:string> groupcode, |
| 601 |
<t:integer> size, |
| 602 |
<t:string> packtype, |
| 603 |
<t:integer> maxdepth, |
| 604 |
<t:integer> direction |
| 605 |
) |
| 606 |
return <t:node> newhead |
| 607 |
end |
| 608 |
\stoptyping |
| 609 |
|
| 610 |
\stopsubsection |
| 611 |
|
| 612 |
\startsubsection[title=buildpage] |
| 613 |
|
| 614 |
This callback is called whenever \LUAMETATEX\ is ready to move stuff to the main |
| 615 |
vertical list. You can use this callback to do specialized manipulation of the |
| 616 |
page building stage like imposition or column balancing. |
| 617 |
|
| 618 |
\starttyping[option=LUA] |
| 619 |
function ( |
| 620 |
<t:string> extrainfo |
| 621 |
) |
| 622 |
-- no return values |
| 623 |
end |
| 624 |
\stoptyping |
| 625 |
|
| 626 |
The string \type {extrainfo} gives some additional information about what \TEX's |
| 627 |
state is with respect to the \quote {current page}. The possible values for this |
| 628 |
callback are: |
| 629 |
|
| 630 |
\starttabulate[|l|p|] |
| 631 |
% \DB value \BC explanation \NC \NR |
| 632 |
% \TB |
| 633 |
\FL |
| 634 |
\BC value \BC explanation \NC \NR |
| 635 |
\ML |
| 636 |
\NC \type{alignment} \NC a (partial) alignment is being added \NC \NR |
| 637 |
\NC \type{after_output} \NC an output routine has just finished \NC \NR |
| 638 |
\NC \type{new_graf} \NC the beginning of a new paragraph \NC \NR |
| 639 |
\NC \type{vmode_par} \NC \type {\par} was found in vertical mode \NC \NR |
| 640 |
\NC \type{hmode_par} \NC \type {\par} was found in horizontal mode \NC \NR |
| 641 |
\NC \type{insert} \NC an insert is added \NC \NR |
| 642 |
\NC \type{penalty} \NC a penalty (in vertical mode) \NC \NR |
| 643 |
\NC \type{before_display} \NC immediately before a display starts \NC \NR |
| 644 |
\NC \type{after_display} \NC a display is finished \NC \NR |
| 645 |
\NC \type{end} \NC \LUAMETATEX\ is terminating (it's all over) \NC \NR |
| 646 |
\LL |
| 647 |
\stoptabulate |
| 648 |
|
| 649 |
|
| 650 |
\stopsubsection |
| 651 |
|
| 652 |
\startsubsection[title=hpack] |
| 653 |
|
| 654 |
This callback is called when \TEX\ is ready to start boxing some horizontal mode |
| 655 |
material. Math items and line boxes are ignored at the moment. The callback does |
| 656 |
not replace any internal code. |
| 657 |
|
| 658 |
\starttyping[option=LUA] |
| 659 |
function ( |
| 660 |
<t:node> head, |
| 661 |
<t:string> groupcode, |
| 662 |
<t:integer> size, |
| 663 |
<t:string> packtype |
| 664 |
<t:integer> direction, |
| 665 |
<t:node> attributelist |
| 666 |
) |
| 667 |
return <t:node> newhead |
| 668 |
end |
| 669 |
\stoptyping |
| 670 |
|
| 671 |
The \type {packtype} is either \type {additional} or \type {exactly}. If \type |
| 672 |
{additional}, then the \type {size} is a \type {\hbox spread ...} argument. If |
| 673 |
\type {exactly}, then the \type {size} is a \type {\hbox to ...}. In both cases, |
| 674 |
the number is in scaled points. |
| 675 |
|
| 676 |
\stopsubsection |
| 677 |
|
| 678 |
\startsubsection[title=vpack] |
| 679 |
|
| 680 |
This callback is called when \TEX\ is ready to start boxing some vertical mode |
| 681 |
material. Math displays are ignored at the moment. The callback does not replace |
| 682 |
any internal code. |
| 683 |
|
| 684 |
This function is very similar to \type {hpack}. Besides the fact that it is |
| 685 |
called at different moments, there is an extra variable that matches \TEX's \type |
| 686 |
{\maxdepth} setting. |
| 687 |
|
| 688 |
\starttyping[option=LUA] |
| 689 |
function ( |
| 690 |
<t:node> head, |
| 691 |
<t:string> groupcode, |
| 692 |
<t:integer> size, |
| 693 |
<t:string> packtype, |
| 694 |
<t:integer> maxdepth, |
| 695 |
<t:integer> direction, |
| 696 |
<t:node> attributelist |
| 697 |
) |
| 698 |
return <t:node> newhead |
| 699 |
end |
| 700 |
\stoptyping |
| 701 |
|
| 702 |
\stopsubsection |
| 703 |
|
| 704 |
\startsubsection[title=hyphenate] |
| 705 |
|
| 706 |
This callback is supposed to insert discretionary nodes in the node list it |
| 707 |
receives. |
| 708 |
|
| 709 |
\starttyping[option=LUA] |
| 710 |
function ( |
| 711 |
<t:node> head, |
| 712 |
<t:node> tail |
| 713 |
) |
| 714 |
-- no return values |
| 715 |
end |
| 716 |
\stoptyping |
| 717 |
|
| 718 |
Setting this callback to \type {false} will prevent the internal discretionary |
| 719 |
insertion pass. |
| 720 |
|
| 721 |
\stopsubsection |
| 722 |
|
| 723 |
\startsubsection[title=ligaturing] |
| 724 |
|
| 725 |
This callback, which expects no return values, has to apply ligaturing to the |
| 726 |
node list it receives. |
| 727 |
|
| 728 |
\starttyping[option=LUA] |
| 729 |
function ( |
| 730 |
<t:node> head, |
| 731 |
<t:node> tail |
| 732 |
) |
| 733 |
-- no return values |
| 734 |
end |
| 735 |
\stoptyping |
| 736 |
|
| 737 |
You don't have to worry about return values because the \type {head} node that is |
| 738 |
passed on to the callback is guaranteed not to be a glyph_node (if need be, a |
| 739 |
temporary node will be prepended), and therefore it cannot be affected by the |
| 740 |
mutations that take place. After the callback, the internal value of the \quote |
| 741 |
{tail of the list} will be recalculated. |
| 742 |
|
| 743 |
The \type {next} of \type {head} is guaranteed to be non-nil. The \type {next} of |
| 744 |
\type {tail} is guaranteed to be nil, and therefore the second callback argument |
| 745 |
can often be ignored. It is provided for orthogonality, and because it can |
| 746 |
sometimes be handy when special processing has to take place. |
| 747 |
|
| 748 |
Setting this callback to \type {false} will prevent the internal ligature |
| 749 |
creation pass. You must not ruin the node list. For instance, the head normally |
| 750 |
is a local par node, and the tail a glue. Messing too much can push \LUATEX\ into |
| 751 |
panic mode. |
| 752 |
|
| 753 |
\stopsubsection |
| 754 |
|
| 755 |
\startsubsection[title=kerning] |
| 756 |
|
| 757 |
This callback has to apply kerning between the nodes in the node list it |
| 758 |
receives. See \type {ligaturing} for calling conventions. |
| 759 |
|
| 760 |
\starttyping[option=LUA] |
| 761 |
function ( |
| 762 |
<t:node> head, |
| 763 |
<t:node> tail |
| 764 |
) |
| 765 |
-- no return values |
| 766 |
end |
| 767 |
\stoptyping |
| 768 |
|
| 769 |
Setting this callback to \type {false} will prevent the internal kern insertion |
| 770 |
pass. You must not ruin the node list. For instance, the head normally is a local |
| 771 |
par node, and the tail a glue. Messing too much can push \LUATEX\ into panic |
| 772 |
mode. |
| 773 |
|
| 774 |
\stopsubsection |
| 775 |
|
| 776 |
\startsubsection[title=glyph_run] |
| 777 |
|
| 778 |
When set this callback is triggered when \TEX\ normally handles the ligaturing |
| 779 |
and kerning. In \LUATEX\ you use the \typ {hpack} and \typ {pre_linebreak} |
| 780 |
callbacks for that (where each passes different arguments). This callback doesn't |
| 781 |
get triggered when there are no glyphs (in \LUATEX\ this optimization is |
| 782 |
controlled by a a variable). |
| 783 |
|
| 784 |
\starttyping[option=LUA] |
| 785 |
function ( |
| 786 |
<t:node> head, |
| 787 |
<t:string> groupcode, |
| 788 |
<t:integer> direction |
| 789 |
) |
| 790 |
return <t:node> newhead |
| 791 |
end |
| 792 |
\stoptyping |
| 793 |
|
| 794 |
The traditional \TEX\ font processing is bypassed so you need to take care of that |
| 795 |
with the helpers. (For the moment we keep the ligaturing and kerning callbacks but |
| 796 |
they are kind of obsolete.) |
| 797 |
|
| 798 |
\stopsubsection |
| 799 |
|
| 800 |
\startsubsection[title=pre_linebreak] |
| 801 |
|
| 802 |
This callback is called just before \LUATEX\ starts converting a list of nodes |
| 803 |
into a stack of \type {\hbox}es, after the addition of \type {\parfillskip}. The |
| 804 |
callback does not replace any internal code. |
| 805 |
|
| 806 |
\starttyping[option=LUA] |
| 807 |
function ( |
| 808 |
<t:node> head, |
| 809 |
<t:string> groupcode |
| 810 |
) |
| 811 |
return <t:node> newhead |
| 812 |
end |
| 813 |
\stoptyping |
| 814 |
|
| 815 |
The string called \type {groupcode} identifies the nodelist's context within |
| 816 |
\TEX's processing. The range of possibilities is given in the table below, but |
| 817 |
not all of those can actually appear here, some are for the \type {hpack} and |
| 818 |
\type {vpack} callbacks. |
| 819 |
|
| 820 |
\starttabulate[|l|p|] |
| 821 |
% \DB value \BC explanation \NC \NR |
| 822 |
% \TB |
| 823 |
\FL |
| 824 |
\BC value \BC explanation \NC \NR |
| 825 |
\ML |
| 826 |
\NC \type{<empty>} \NC main vertical list \NC \NR |
| 827 |
\NC \type{hbox} \NC \type {\hbox} in horizontal mode \NC \NR |
| 828 |
\NC \type{adjusted_hbox} \NC \type {\hbox} in vertical mode \NC \NR |
| 829 |
\NC \type{vbox} \NC \type {\vbox} \NC \NR |
| 830 |
\NC \type{vtop} \NC \type {\vtop} \NC \NR |
| 831 |
\NC \type{align} \NC \type {\halign} or \type {\valign} \NC \NR |
| 832 |
\NC \type{disc} \NC discretionaries \NC \NR |
| 833 |
\NC \type{insert} \NC packaging an insert \NC \NR |
| 834 |
\NC \type{vcenter} \NC \type {\vcenter} \NC \NR |
| 835 |
\NC \type{local_box} \NC \type {\localleftbox} or \type {\localrightbox} \NC \NR |
| 836 |
\NC \type{split_off} \NC top of a \type {\vsplit} \NC \NR |
| 837 |
\NC \type{split_keep} \NC remainder of a \type {\vsplit} \NC \NR |
| 838 |
\NC \type{align_set} \NC alignment cell \NC \NR |
| 839 |
\NC \type{fin_row} \NC alignment row \NC \NR |
| 840 |
\LL |
| 841 |
\stoptabulate |
| 842 |
|
| 843 |
As for all the callbacks that deal with nodes, the return value can be one of |
| 844 |
three things: |
| 845 |
|
| 846 |
\startitemize |
| 847 |
\startitem |
| 848 |
boolean \type {true} signals successful processing |
| 849 |
\stopitem |
| 850 |
\startitem |
| 851 |
\type {<t:node>} signals that the \quote {head} node should be replaced by the |
| 852 |
returned node |
| 853 |
\stopitem |
| 854 |
\startitem |
| 855 |
boolean \type {false} signals that the \quote {head} node list should be |
| 856 |
ignored and flushed from memory |
| 857 |
\stopitem |
| 858 |
\stopitemize |
| 859 |
|
| 860 |
\stopsubsection |
| 861 |
|
| 862 |
\startsubsection[title=linebreak] |
| 863 |
|
| 864 |
This callback replaces \LUATEX's line breaking algorithm. The callback does not |
| 865 |
replace any internal code. |
| 866 |
|
| 867 |
\starttyping[option=LUA] |
| 868 |
function ( |
| 869 |
<t:node> head, |
| 870 |
<t:boolean> is_display |
| 871 |
) |
| 872 |
return <t:node> newhead |
| 873 |
end |
| 874 |
\stoptyping |
| 875 |
|
| 876 |
The returned node is the head of the list that will be added to the main vertical |
| 877 |
list, the boolean argument is true if this paragraph is interrupted by a |
| 878 |
following math display. |
| 879 |
|
| 880 |
If you return something that is not a \type {<t:node>}, \LUATEX\ will apply the |
| 881 |
internal linebreak algorithm on the list that starts at \type {<head>}. |
| 882 |
Otherwise, the \type {<t:node>} you return is supposed to be the head of a list of |
| 883 |
nodes that are all allowed in vertical mode, and at least one of those has to |
| 884 |
represent an \type {\hbox}. Failure to do so will result in a fatal error. |
| 885 |
|
| 886 |
Setting this callback to \type {false} is possible, but dangerous, because it is |
| 887 |
possible you will end up in an unfixable \quote {deadcycles loop}. |
| 888 |
|
| 889 |
\stopsubsection |
| 890 |
|
| 891 |
\startsubsection[title=post_linebreak] |
| 892 |
|
| 893 |
This callback is called just after \LUATEX\ has converted a list of nodes into a |
| 894 |
stack of \type {\hbox}es. |
| 895 |
|
| 896 |
\starttyping[option=LUA] |
| 897 |
function ( |
| 898 |
<t:node> head, |
| 899 |
<t:string> groupcode |
| 900 |
) |
| 901 |
return <t:node> newhead |
| 902 |
end |
| 903 |
\stoptyping |
| 904 |
|
| 905 |
\stopsubsection |
| 906 |
|
| 907 |
\startsubsection[title=append_to_vlist] |
| 908 |
|
| 909 |
This callback is called whenever \LUATEX\ adds a box to a vertical list (the |
| 910 |
\type {mirrored} argument is obsolete): |
| 911 |
|
| 912 |
\starttyping[option=LUA] |
| 913 |
function ( |
| 914 |
<t:node> box, |
| 915 |
<t:string> locationcode, |
| 916 |
<t:integer> prevdepth |
| 917 |
) |
| 918 |
return <t:node> list [, <t:integer> prevdepth [, <t:boolean> checkdepth ] ] |
| 919 |
end |
| 920 |
\stoptyping |
| 921 |
|
| 922 |
It is ok to return nothing or \type {nil} in which case you also need to flush |
| 923 |
the box or deal with it yourself. The prevdepth is also optional. Locations are |
| 924 |
\type {box}, \type {alignment}, \type {equation}, \type {equation_number} and |
| 925 |
\type {post_linebreak}. When the third argument returned is \type {true} the |
| 926 |
normal prevdepth correction will be applied, based on the first node. |
| 927 |
|
| 928 |
\stopsubsection |
| 929 |
|
| 930 |
\startsubsection[title=alignment] |
| 931 |
|
| 932 |
This is an experimental callback that when set is called several times during the |
| 933 |
construction of an alignment. The context values are available in \typ |
| 934 |
{tex.getalignmentcontextvalues()}. |
| 935 |
|
| 936 |
\starttyping[option=LUA] |
| 937 |
function ( |
| 938 |
<t:node> head, |
| 939 |
<t:string> context, |
| 940 |
<t:node> attributes, |
| 941 |
<t:node> preamble |
| 942 |
) |
| 943 |
-- no return values |
| 944 |
end |
| 945 |
\stoptyping |
| 946 |
|
| 947 |
There are no sanity checks so if a user messes up the passed node lists the results |
| 948 |
can be unpredictable and, as with other node related callbacks, crash the engine. |
| 949 |
|
| 950 |
\stopsubsection |
| 951 |
|
| 952 |
\startsubsection[title=local_box] |
| 953 |
|
| 954 |
Local boxes are a somewhat tricky and error prone feature so use this callback |
| 955 |
with care because the paragraph is easily messed up. A line can have a left, |
| 956 |
right and middle box where the middle one has no width. This callback does not |
| 957 |
replace any internal code. The callback gets quite some parameters passed: |
| 958 |
|
| 959 |
\starttyping[option=LUA] |
| 960 |
function ( |
| 961 |
<t:node> linebox, |
| 962 |
<t:node> leftbox, |
| 963 |
<t:node> rightbox, |
| 964 |
<t:node> middlebox, |
| 965 |
<t:integer> linenumber, |
| 966 |
<t:integer> leftskip, |
| 967 |
<t:integer> rightskip, |
| 968 |
<t:integer> lefthang, |
| 969 |
<t:integer> righthang, |
| 970 |
<t:integer> indentation, |
| 971 |
<t:integer> parinitleftskip, |
| 972 |
<t:integer> parinitrightskip, |
| 973 |
<t:integer> parfillleftskip, |
| 974 |
<t:integer> parfillrightskip, |
| 975 |
<t:integer> overshoot |
| 976 |
) |
| 977 |
-- no return values |
| 978 |
end |
| 979 |
\stoptyping |
| 980 |
|
| 981 |
This is an experimental callback that will be tested in different \CONTEXT\ |
| 982 |
mechanisms before it will be declared stable. |
| 983 |
|
| 984 |
\stopsubsection |
| 985 |
|
| 986 |
\startsubsection[title=packed_vbox] |
| 987 |
|
| 988 |
After the \type {vpack} callback (see previous section) is triggered the box get |
| 989 |
packed and after that this callback can be configured to kick in. |
| 990 |
|
| 991 |
\starttyping[option=LUA] |
| 992 |
function ( |
| 993 |
<t:node> head, |
| 994 |
<t:string> groupcode |
| 995 |
) |
| 996 |
return <t:node> newhead |
| 997 |
end |
| 998 |
\stoptyping |
| 999 |
|
| 1000 |
\stopsubsection |
| 1001 |
|
| 1002 |
\startsubsection[title=handle_uleader] |
| 1003 |
|
| 1004 |
The \typ {\uleaders} command inserts a user leader into the list. When a list get packed |
| 1005 |
and has such leaders, a run over the list happens after packing so that it can be |
| 1006 |
finalized. |
| 1007 |
|
| 1008 |
\starttyping[option=LUA] |
| 1009 |
function ( |
| 1010 |
<t:node> head, |
| 1011 |
<t:string> context, |
| 1012 |
<t:integer> index, |
| 1013 |
<t:node> box, |
| 1014 |
<t:integer> location |
| 1015 |
) |
| 1016 |
return <t:node> head |
| 1017 |
end |
| 1018 |
\stoptyping |
| 1019 |
|
| 1020 |
\stopsubsection |
| 1021 |
|
| 1022 |
\startsubsection[title=italic_correction] |
| 1023 |
|
| 1024 |
The concept of italic correction is very much related to traditional \TEX\ fonts. |
| 1025 |
At least in 2024 it is absent from \OPENTYPE\ although it has some meaning in |
| 1026 |
\OPENTYPE\ math. In \TEX\ this correction is normally inserted by \type {\/} |
| 1027 |
although in \LUAMETATEX\ we also have \typ {\explicititaliccorrection} as well as |
| 1028 |
\typ {\forcedleftcorrection} and \typ {\forcedrightcorrection}. |
| 1029 |
|
| 1030 |
When this callback is enabled it gets triggered when one of left or right |
| 1031 |
correction commands is given and the returned kern is then used as correction. |
| 1032 |
|
| 1033 |
\starttyping[option=LUA] |
| 1034 |
function ( |
| 1035 |
<t:node> glyph, |
| 1036 |
<t:integer> kern, |
| 1037 |
<t:integer> subtype, |
| 1038 |
) |
| 1039 |
return <t:integer> kern |
| 1040 |
end |
| 1041 |
\stoptyping |
| 1042 |
|
| 1043 |
\stopsubsection |
| 1044 |
|
| 1045 |
\startsubsection[title=insert_par] |
| 1046 |
|
| 1047 |
Each paragraph starts with a local par node that keeps track of for instance |
| 1048 |
the direction. You can hook a callback into the creator: |
| 1049 |
|
| 1050 |
\starttyping[option=LUA] |
| 1051 |
function ( |
| 1052 |
<t:node> par, |
| 1053 |
<t:string> location |
| 1054 |
) |
| 1055 |
-- no return values |
| 1056 |
end |
| 1057 |
\stoptyping |
| 1058 |
|
| 1059 |
There is no return value and you should make sure that the node stays valid |
| 1060 |
as otherwise \TEX\ can get confused. |
| 1061 |
|
| 1062 |
\stopsubsection |
| 1063 |
|
| 1064 |
\startsubsection[title=append_line] |
| 1065 |
|
| 1066 |
Every time a line is added this callback is triggered, when set. migrated |
| 1067 |
material and adjusts also qualify as such and the detail relates to the adjust |
| 1068 |
index. |
| 1069 |
|
| 1070 |
\starttyping[option=LUA] |
| 1071 |
function ( |
| 1072 |
<t:node> head, |
| 1073 |
<t:node> tail, |
| 1074 |
<t:string> context, |
| 1075 |
<t:integer> detail |
| 1076 |
) |
| 1077 |
return <t:node> newhead |
| 1078 |
end |
| 1079 |
\stoptyping |
| 1080 |
|
| 1081 |
A list of possible context values can be queried with \typ |
| 1082 |
{tex.getappendlinecontextvalues()}. |
| 1083 |
|
| 1084 |
\stopsubsection |
| 1085 |
|
| 1086 |
\startsubsection[title=insert_distance] |
| 1087 |
|
| 1088 |
This callback is called when the page builder adds an insert. There is not much |
| 1089 |
control over this mechanism but this callback permits some last minute |
| 1090 |
manipulations of the spacing before an insert, something that might be handy when |
| 1091 |
for instance multiple inserts (types) are appended in a row. |
| 1092 |
|
| 1093 |
\starttyping[option=LUA] |
| 1094 |
function ( |
| 1095 |
<t:integer> class, |
| 1096 |
<t:integer> order |
| 1097 |
) |
| 1098 |
return <t:integer> register |
| 1099 |
end |
| 1100 |
\stoptyping |
| 1101 |
|
| 1102 |
The return value is a number indicating the skip register to use for the |
| 1103 |
prepended spacing. This permits for instance a different top space (when \type |
| 1104 |
{class} equals one) and intermediate space (when \type {class} is larger than |
| 1105 |
one). Of course you can mess with the insert box but you need to make sure that |
| 1106 |
\LUATEX\ is happy afterwards. |
| 1107 |
|
| 1108 |
\stopsubsection |
| 1109 |
|
| 1110 |
\startsubsection[title=begin_paragraph] |
| 1111 |
|
| 1112 |
Every time a paragraph starts this callback, when configured, will kick in: |
| 1113 |
|
| 1114 |
\starttyping[option=LUA] |
| 1115 |
function ( |
| 1116 |
<t:boolean> invmode, |
| 1117 |
<t:boolean> indented, |
| 1118 |
<t:string> context |
| 1119 |
) |
| 1120 |
return <t:boolean> indented |
| 1121 |
end |
| 1122 |
\stoptyping |
| 1123 |
|
| 1124 |
There are many places where a new paragraph can be triggered: |
| 1125 |
|
| 1126 |
\startfourrows |
| 1127 |
\getbuffer[engine:syntax:parcontextcodes] |
| 1128 |
\stopfourrows |
| 1129 |
|
| 1130 |
\stopsubsection |
| 1131 |
|
| 1132 |
\startsubsection[title=paragraph_context] |
| 1133 |
|
| 1134 |
When the return value of this callback is \typ {false} the paragraph related |
| 1135 |
settings, when they have been updated, will not be updated. |
| 1136 |
|
| 1137 |
\starttyping[option=LUA] |
| 1138 |
function ( |
| 1139 |
<t:string> context |
| 1140 |
) |
| 1141 |
return <t:boolean> ignore |
| 1142 |
end |
| 1143 |
\stoptyping |
| 1144 |
|
| 1145 |
\stopsubsection |
| 1146 |
|
| 1147 |
\startsubsection[title=missing_character] |
| 1148 |
|
| 1149 |
This callback is triggered when a character node is created and the font doesn't |
| 1150 |
have the requested character. |
| 1151 |
|
| 1152 |
\starttyping[option=LUA] |
| 1153 |
function ( |
| 1154 |
<t:integer> location, |
| 1155 |
<t:node> glyph, |
| 1156 |
<t:integer> font, |
| 1157 |
<t:integer> character |
| 1158 |
) |
| 1159 |
-- no return value |
| 1160 |
end |
| 1161 |
\stoptyping |
| 1162 |
|
| 1163 |
When \prm {tracinglostchars} is set to a positive value a message goes to the log |
| 1164 |
and a value larger than one also makes it show up non the terminal. In the |
| 1165 |
callback, the location is one of: |
| 1166 |
|
| 1167 |
\startfourrows |
| 1168 |
\getbuffer[engine:syntax:missingcharactervalues] |
| 1169 |
\stopfourrows |
| 1170 |
|
| 1171 |
\stopsubsection |
| 1172 |
|
| 1173 |
\startsubsection[title=process_character] |
| 1174 |
|
| 1175 |
This callback is experimental and gets called when a glyph node is created and |
| 1176 |
the callback field in a character is set. |
| 1177 |
|
| 1178 |
\starttyping[option=LUA] |
| 1179 |
function ( |
| 1180 |
<t:integer> font, |
| 1181 |
<t:integer> character |
| 1182 |
) |
| 1183 |
-- no return value |
| 1184 |
end |
| 1185 |
\stoptyping |
| 1186 |
|
| 1187 |
\stopsubsection |
| 1188 |
|
| 1189 |
\startsubsection[title=tail_append] |
| 1190 |
|
| 1191 |
% This callback is called when \LUATEX\ adds contents to list: |
| 1192 |
|
| 1193 |
% \starttyping[option=LUA] |
| 1194 |
% function ( |
| 1195 |
% <t:string> extrainfo |
| 1196 |
% ) |
| 1197 |
% end |
| 1198 |
% \stoptyping |
| 1199 |
|
| 1200 |
% The string reports the group code. From this you can deduce from |
| 1201 |
% what list you can give a treat. |
| 1202 |
|
| 1203 |
% \starttabulate[|l|p|] |
| 1204 |
% \DB value \BC explanation \NC \NR |
| 1205 |
% \TB |
| 1206 |
% \NC \type{pre_box} \NC interline material is being added \NC \NR |
| 1207 |
% \NC \type{pre_adjust} \NC \type {\vadjust} material is being added \NC \NR |
| 1208 |
% \NC \type{box} \NC a typeset box is being added (always called) \NC \NR |
| 1209 |
% \NC \type{adjust} \NC \type {\vadjust} material is being added \NC \NR |
| 1210 |
% \LL |
| 1211 |
% \stoptabulate |
| 1212 |
|
| 1213 |
\stopsubsection |
| 1214 |
|
| 1215 |
\stopsection |
| 1216 |
|
| 1217 |
\startsection[title=Tracing] |
| 1218 |
|
| 1219 |
\startsubsection[title=hpack_quality] |
| 1220 |
|
| 1221 |
This callback can be used to intercept the overfull messages that can result from |
| 1222 |
packing a horizontal list (as happens in the par builder). The function takes a |
| 1223 |
few arguments: |
| 1224 |
|
| 1225 |
\starttyping[option=LUA] |
| 1226 |
function ( |
| 1227 |
<t:string> incident, |
| 1228 |
<t:integer> detail, |
| 1229 |
<t:node> head, |
| 1230 |
<t:integer> first, |
| 1231 |
<t:integer> last |
| 1232 |
) |
| 1233 |
return <t:node> whatever |
| 1234 |
end |
| 1235 |
\stoptyping |
| 1236 |
|
| 1237 |
The incident is one of \type {overfull}, \type {underfull}, \type {loose} or |
| 1238 |
\type {tight}. The detail is either the amount of overflow in case of \type |
| 1239 |
{overfull}, or the badness otherwise. The head is the list that is constructed |
| 1240 |
(when protrusion or expansion is enabled, this is an intermediate list). |
| 1241 |
Optionally you can return a node, for instance an overfull rule indicator. That |
| 1242 |
node will be appended to the list (just like \TEX's own rule would). |
| 1243 |
|
| 1244 |
\stopsubsection |
| 1245 |
|
| 1246 |
\startsubsection[title=vpack_quality] |
| 1247 |
|
| 1248 |
This callback can be used to intercept the overfull messages that can result from |
| 1249 |
packing a vertical list (as happens in the page builder). The function takes a |
| 1250 |
few arguments: |
| 1251 |
|
| 1252 |
\starttyping[option=LUA] |
| 1253 |
function ( |
| 1254 |
<t:string> incident, |
| 1255 |
<t:integer> detail, |
| 1256 |
<t:node> head, |
| 1257 |
<t:integer> first, |
| 1258 |
<t:integer> last |
| 1259 |
) |
| 1260 |
-- no return values |
| 1261 |
end |
| 1262 |
\stoptyping |
| 1263 |
|
| 1264 |
The incident is one of \type {overfull}, \type {underfull}, \type {loose} or |
| 1265 |
\type {tight}. The detail is either the amount of overflow in case of \type |
| 1266 |
{overfull}, or the badness otherwise. The head is the list that is constructed. |
| 1267 |
|
| 1268 |
\stopsubsection |
| 1269 |
|
| 1270 |
\startsubsection[title=line_break] |
| 1271 |
|
| 1272 |
This callback is actually a set of callbacks that has to be deals with as a |
| 1273 |
whole. The main reason why we have this callback is that we wanted to be able to |
| 1274 |
see what the par builder is doing, especially when we implement multiple |
| 1275 |
paragraph building passes. This makes the callback pretty much a rather \CONTEXT\ |
| 1276 |
specific one. |
| 1277 |
|
| 1278 |
{\em We can also consider fetching the passive and active lists because we now keep |
| 1279 |
much more info around.} |
| 1280 |
|
| 1281 |
\starttyping[option=LUA] |
| 1282 |
function( |
| 1283 |
<t:integer> context, |
| 1284 |
<t:integer> checks, |
| 1285 |
... |
| 1286 |
) |
| 1287 |
-- no return values |
| 1288 |
end |
| 1289 |
\stoptyping |
| 1290 |
|
| 1291 |
\starttyping[option=LUA] |
| 1292 |
function initialize ( |
| 1293 |
<t:integer> context, |
| 1294 |
<t:integer> checks, |
| 1295 |
<t:integer> subpasses |
| 1296 |
) |
| 1297 |
-- no return values |
| 1298 |
end |
| 1299 |
\stoptyping |
| 1300 |
|
| 1301 |
\starttyping[option=LUA] |
| 1302 |
function start ( |
| 1303 |
<t:integer> context, |
| 1304 |
<t:integer> checks, |
| 1305 |
<t:integer> pass, |
| 1306 |
<t:integer> subpass, |
| 1307 |
<t:integer> classes, |
| 1308 |
<t:integer> decent |
| 1309 |
) |
| 1310 |
-- no return values |
| 1311 |
end |
| 1312 |
\stoptyping |
| 1313 |
|
| 1314 |
\starttyping[option=LUA] |
| 1315 |
function stop ( |
| 1316 |
<t:integer> context, |
| 1317 |
<t:integer> checks, |
| 1318 |
<t:integer> demerits |
| 1319 |
) |
| 1320 |
-- no return values |
| 1321 |
end |
| 1322 |
\stoptyping |
| 1323 |
|
| 1324 |
\starttyping[option=LUA] |
| 1325 |
function collect ( |
| 1326 |
<t:integer> context, |
| 1327 |
<t:integer> checks |
| 1328 |
) |
| 1329 |
-- no return values |
| 1330 |
end |
| 1331 |
\stoptyping |
| 1332 |
|
| 1333 |
\starttyping[option=LUA] |
| 1334 |
function line ( |
| 1335 |
<t:integer> context, |
| 1336 |
<t:integer> checks, |
| 1337 |
<t:integer> box, |
| 1338 |
<t:integer> badness, |
| 1339 |
<t:integer> overshoot, |
| 1340 |
<t:integer> shrink, |
| 1341 |
<t:integer> stretch, |
| 1342 |
<t:integer> line, |
| 1343 |
<t:integer> serial |
| 1344 |
) |
| 1345 |
-- no return values |
| 1346 |
end |
| 1347 |
\stoptyping |
| 1348 |
|
| 1349 |
\starttyping[option=LUA] |
| 1350 |
function delete ( |
| 1351 |
<t:integer> context, |
| 1352 |
<t:integer> checks, |
| 1353 |
<t:integer> serial |
| 1354 |
) |
| 1355 |
-- no return values |
| 1356 |
end |
| 1357 |
\stoptyping |
| 1358 |
|
| 1359 |
\starttyping[option=LUA] |
| 1360 |
function wrapup ( |
| 1361 |
<t:integer> context, |
| 1362 |
<t:integer> checks, |
| 1363 |
<t:integer> demerits, |
| 1364 |
<t:integer> looseness |
| 1365 |
) |
| 1366 |
-- no return values |
| 1367 |
end |
| 1368 |
\stoptyping |
| 1369 |
\starttyping[option=LUA] |
| 1370 |
function check ( |
| 1371 |
<t:integer> context, |
| 1372 |
<t:integer> checks, |
| 1373 |
<t:integer> pass, |
| 1374 |
<t:integer> subpass, |
| 1375 |
<t:integer> serial, |
| 1376 |
<t:integer> prevserial, |
| 1377 |
<t:integer> linenumber, |
| 1378 |
<t:integer> nodetype, |
| 1379 |
<t:integer> fitness,, |
| 1380 |
<t:integer> demerits, |
| 1381 |
<t:integer> classes, |
| 1382 |
<t:integer> badness, |
| 1383 |
<t:integer> demerits, |
| 1384 |
<t:node> breakpoint, |
| 1385 |
<t:integer> short, |
| 1386 |
<t:integer> glue, |
| 1387 |
<t:integer> linewidth |
| 1388 |
) |
| 1389 |
return <t:integer> demerits -- optional |
| 1390 |
end |
| 1391 |
\stoptyping |
| 1392 |
|
| 1393 |
\starttyping[option=LUA] |
| 1394 |
function list ( |
| 1395 |
<t:integer> context, |
| 1396 |
<t:integer> checks, |
| 1397 |
<t:integer> serial |
| 1398 |
) |
| 1399 |
-- no return values |
| 1400 |
end |
| 1401 |
\stoptyping |
| 1402 |
|
| 1403 |
Every one of these gets a \type {context} and \type {checks} passes. Possible |
| 1404 |
contexts are: |
| 1405 |
|
| 1406 |
\startfourrows |
| 1407 |
\getbuffer[engine:syntax:linebreakcontextcodes] |
| 1408 |
\stopfourrows |
| 1409 |
|
| 1410 |
The \type {checks} parameters is the value of \type {\linebreakchecks} which |
| 1411 |
makes it possible to plug in actions depending on that number. To give an idea if |
| 1412 |
what gets called, this is what you get when typesetting \type {tufte.tex}: |
| 1413 |
initialize, start, report, delete, delete, stop, start, report, report, delete, |
| 1414 |
report, report, report, delete, delete, report, report, report, delete, report, |
| 1415 |
delete, delete, report, report, report, delete, report, delete, delete, report, |
| 1416 |
report, delete, report, report, delete, delete, delete, report, delete, report, |
| 1417 |
delete, delete, report, report, report, delete, delete, report, delete, report, |
| 1418 |
report, delete, report, delete, delete, delete, report, report, delete, report, |
| 1419 |
report, delete, report, delete, report, delete, report, delete, delete, report, |
| 1420 |
report, report, report, delete, delete, delete, delete, delete, delete, delete, |
| 1421 |
delete, delete, report, stop, collect, list, list, list, list, list, list, list, |
| 1422 |
list, list, line, line, line, line, line, line, line, line, line, wrapup. |
| 1423 |
|
| 1424 |
\stopsubsection |
| 1425 |
|
| 1426 |
\startsubsection[title=show_build] |
| 1427 |
|
| 1428 |
You can trace (and even influence) the page builder with this callback. It comes in |
| 1429 |
several variants that are called during the process. Callbacks like these assume that |
| 1430 |
one knows what is going on in the engine. |
| 1431 |
|
| 1432 |
\starttyping[option=LUA] |
| 1433 |
function initialize ( |
| 1434 |
<t:integer> context |
| 1435 |
) |
| 1436 |
-- no return values |
| 1437 |
end |
| 1438 |
\stoptyping |
| 1439 |
|
| 1440 |
\starttyping[option=LUA] |
| 1441 |
function step ( |
| 1442 |
<t:integer> context, |
| 1443 |
<t:node> current, |
| 1444 |
<t:integer> pagegoal, |
| 1445 |
<t:integer> pagetotal |
| 1446 |
) |
| 1447 |
-- no return values |
| 1448 |
end |
| 1449 |
\stoptyping |
| 1450 |
|
| 1451 |
\starttyping[option=LUA] |
| 1452 |
function check ( |
| 1453 |
<t:integer> context, |
| 1454 |
<t:node> current, |
| 1455 |
<t:boolean> moveon, |
| 1456 |
<t:boolean> fireup, |
| 1457 |
<t:integer> badness, |
| 1458 |
<t:integer> costs, |
| 1459 |
<t:integer> penalty |
| 1460 |
) |
| 1461 |
return <t:boolean> moveon, <t:boolean> fireup |
| 1462 |
end |
| 1463 |
\stoptyping |
| 1464 |
|
| 1465 |
\starttyping[option=LUA] |
| 1466 |
function skip ( |
| 1467 |
<t:integer> context, |
| 1468 |
<t:node> current, |
| 1469 |
) |
| 1470 |
-- no return values |
| 1471 |
end |
| 1472 |
\stoptyping |
| 1473 |
|
| 1474 |
\starttyping[option=LUA] |
| 1475 |
function move ( |
| 1476 |
<t:integer> context, |
| 1477 |
<t:node> current, |
| 1478 |
<t:integer> lastheight, |
| 1479 |
<t:integer> lastdepth, |
| 1480 |
<t:integer> laststretch, |
| 1481 |
<t:integer> lastshrink, |
| 1482 |
<t:boolean> hasstretch |
| 1483 |
) |
| 1484 |
-- no return values |
| 1485 |
end |
| 1486 |
\stoptyping |
| 1487 |
|
| 1488 |
\starttyping[option=LUA] |
| 1489 |
function fireup ( |
| 1490 |
<t:integer> context, |
| 1491 |
<t:node> current |
| 1492 |
) |
| 1493 |
-- no return values |
| 1494 |
end |
| 1495 |
\stoptyping |
| 1496 |
|
| 1497 |
\starttyping[option=LUA] |
| 1498 |
function wrapup ( |
| 1499 |
<t:integer> context |
| 1500 |
) |
| 1501 |
-- no return values |
| 1502 |
end |
| 1503 |
\stoptyping |
| 1504 |
|
| 1505 |
\stopsubsection |
| 1506 |
|
| 1507 |
\startsubsection[title=show_whatsit] |
| 1508 |
|
| 1509 |
Because we only have a generic whatsit it is up to the macro package to provide |
| 1510 |
details when tracing them. |
| 1511 |
|
| 1512 |
\starttyping[option=LUA] |
| 1513 |
function ( |
| 1514 |
<t:node> whatsit, |
| 1515 |
<t:integer> indentation, |
| 1516 |
<t:integer> tracinglevel, |
| 1517 |
<t:integer> currentlevel, |
| 1518 |
<t:integer> inputlevel |
| 1519 |
) |
| 1520 |
-- no return value |
| 1521 |
end |
| 1522 |
\stoptyping |
| 1523 |
|
| 1524 |
Here \type {indentation} tells how many periods are to be typeset if you want to |
| 1525 |
be compatible with the rest of tracing. The \type {tracinglevel} indicates if the |
| 1526 |
current level and|/|or input level are shown cf. \type {\tracinglevels}. Of |
| 1527 |
course one is free to show whatever in whatever way suits the whatsit best. |
| 1528 |
|
| 1529 |
\stopsubsection |
| 1530 |
|
| 1531 |
\startsubsection[title=linebreak_quality] |
| 1532 |
|
| 1533 |
\starttyping[option=LUA] |
| 1534 |
function ( |
| 1535 |
<t:node> par, |
| 1536 |
<t:integer> id, |
| 1537 |
<t:integer> pass, |
| 1538 |
<t:integer> subpass, |
| 1539 |
<t:integer> subpasses, |
| 1540 |
<t:integer> state, |
| 1541 |
<t:integer> overfull, |
| 1542 |
<t:integer> underfull, |
| 1543 |
<t:integer> verdict, |
| 1544 |
<t:integer> classified, |
| 1545 |
<t:integer> line |
| 1546 |
) |
| 1547 |
return <t:node> result |
| 1548 |
end |
| 1549 |
\stoptyping |
| 1550 |
|
| 1551 |
\stopsubsection |
| 1552 |
|
| 1553 |
\startsubsection[title=show_loners] |
| 1554 |
|
| 1555 |
In spite of widow, club, broken and shaping penalties we can have single lines in the |
| 1556 |
result. When set, this callback replaces the output that normally \typ {\tracingloners} |
| 1557 |
produces. |
| 1558 |
|
| 1559 |
\starttyping[option=LUA] |
| 1560 |
function ( |
| 1561 |
<t:integer> options, |
| 1562 |
<t:integer> penalty |
| 1563 |
) |
| 1564 |
return <t:node> result |
| 1565 |
end |
| 1566 |
\stoptyping |
| 1567 |
|
| 1568 |
The options are those set on the encountered penalty: |
| 1569 |
|
| 1570 |
\startthreerows |
| 1571 |
\getbuffer[engine:syntax:penaltyoptioncodes] |
| 1572 |
\stopthreerows |
| 1573 |
|
| 1574 |
\stopsubsection |
| 1575 |
|
| 1576 |
\startsubsection[title=get_attribute] |
| 1577 |
|
| 1578 |
Because attributes are abstract pairs of indices and values the reported |
| 1579 |
properties makes not much sense and are very macro package (and user) dependent. |
| 1580 |
This callback permits more verbose reporting by the engine when tracing is |
| 1581 |
enabled. |
| 1582 |
|
| 1583 |
\starttyping[option=LUA] |
| 1584 |
function ( |
| 1585 |
<t:integer> index, |
| 1586 |
<t:integer> value |
| 1587 |
) |
| 1588 |
return <t:string>, <t:string> |
| 1589 |
end |
| 1590 |
\stoptyping |
| 1591 |
|
| 1592 |
\stopsubsection |
| 1593 |
|
| 1594 |
\startsubsection[title=get_noad_class] |
| 1595 |
|
| 1596 |
We have built|-|in math classes but there can also be user defined ones. This |
| 1597 |
callback can be used to report more meaningful strings instead of numbers when |
| 1598 |
tracing. |
| 1599 |
|
| 1600 |
\starttyping[option=LUA] |
| 1601 |
function ( |
| 1602 |
<t:integer> class |
| 1603 |
) |
| 1604 |
return <t:string> |
| 1605 |
end |
| 1606 |
\stoptyping |
| 1607 |
|
| 1608 |
\stopsubsection |
| 1609 |
|
| 1610 |
\startsubsection[title=get_math_dictionary] |
| 1611 |
todo |
| 1612 |
\stopsubsection |
| 1613 |
|
| 1614 |
\startsubsection[title=show_lua_call] |
| 1615 |
|
| 1616 |
When the engine traces something that involves a \LUA\ call it makes sense to report something |
| 1617 |
more meaningful than just that. This callback can be used provide a meaningful string (like the |
| 1618 |
name of a function). |
| 1619 |
|
| 1620 |
\starttyping[option=LUA] |
| 1621 |
function ( |
| 1622 |
<t:string> name, |
| 1623 |
<t:integer> index |
| 1624 |
) |
| 1625 |
return <t:string> |
| 1626 |
end |
| 1627 |
\stoptyping |
| 1628 |
|
| 1629 |
\stopsubsection |
| 1630 |
|
| 1631 |
\startsubsection[title=trace_memory] |
| 1632 |
|
| 1633 |
When the engine starts all kind of memory is pre|-|allocated> depending on the |
| 1634 |
configuration more gets allocated when a category runs out of memory. The |
| 1635 |
\LUAMETATEX\ engine is more dynamic than \LUATEX. If this callback is set it will |
| 1636 |
get called as follows: |
| 1637 |
|
| 1638 |
\starttyping[option=LUA] |
| 1639 |
function ( |
| 1640 |
<t:string> category, |
| 1641 |
<t:boolean> success |
| 1642 |
) |
| 1643 |
-- no return value |
| 1644 |
end |
| 1645 |
\stoptyping |
| 1646 |
|
| 1647 |
The boolean indicates if the allocation has been successful. One can best quit |
| 1648 |
the run when this one is \type {false} which the engine is likely to do that |
| 1649 |
anyway, be in in a less graceful way that you might like. |
| 1650 |
|
| 1651 |
\stopsubsection |
| 1652 |
|
| 1653 |
\startsubsection[title=paragraph_pass] |
| 1654 |
|
| 1655 |
{\em This callback is not yet stable.} |
| 1656 |
|
| 1657 |
\stopsubsection |
| 1658 |
|
| 1659 |
\stopsection |
| 1660 |
|
| 1661 |
\startsection[title=Math] |
| 1662 |
|
| 1663 |
\startsubsection[title=mlist_to_hlist] |
| 1664 |
|
| 1665 |
This callback replaces \LUATEX's math list to node list conversion algorithm. |
| 1666 |
|
| 1667 |
\starttyping[option=LUA] |
| 1668 |
function ( |
| 1669 |
<t:node> head, |
| 1670 |
<t:string> display_type, |
| 1671 |
<t:boolean> need_penalties |
| 1672 |
) |
| 1673 |
return <t:node> newhead |
| 1674 |
end |
| 1675 |
\stoptyping |
| 1676 |
|
| 1677 |
The returned node is the head of the list that will be added to the vertical or |
| 1678 |
horizontal list, the string argument is either \quote {text} or \quote {display} |
| 1679 |
depending on the current math mode, the boolean argument is \type {true} if |
| 1680 |
penalties have to be inserted in this list, \type {false} otherwise. |
| 1681 |
|
| 1682 |
Setting this callback to \type {false} is bad, it will almost certainly result in |
| 1683 |
an endless loop. |
| 1684 |
|
| 1685 |
\stopsubsection |
| 1686 |
|
| 1687 |
\startsubsection[title=math_rule] |
| 1688 |
|
| 1689 |
In math rules are used for fractions, radicals and accents. In the case of |
| 1690 |
radicals rules mix with glyphs to build the symbol. In \CONTEXT\ we can enable an |
| 1691 |
alternate approach that uses glyphs instead of rules so that we can have more |
| 1692 |
consistent shapes, for instance with slopes or non square endings. This callback |
| 1693 |
takes care of that. |
| 1694 |
|
| 1695 |
\starttyping[option=LUA] |
| 1696 |
function ( |
| 1697 |
<t:integer> subtype, |
| 1698 |
<t:integer> font, |
| 1699 |
<t:integer> width, |
| 1700 |
<t:integer> height, |
| 1701 |
<t:node> attributes |
| 1702 |
) |
| 1703 |
return <t:node> rule |
| 1704 |
end |
| 1705 |
\stoptyping |
| 1706 |
|
| 1707 |
\stopsubsection |
| 1708 |
|
| 1709 |
\startsubsection[title=make_extensible] |
| 1710 |
|
| 1711 |
Like \typ {math_rule} this callback is used to construct nicer extensibles in \CONTEXT\ |
| 1712 |
math support. It can optionally be followed by \typ {register_extensible}. |
| 1713 |
|
| 1714 |
\starttyping[option=LUA] |
| 1715 |
function ( |
| 1716 |
<t:node> extensible, |
| 1717 |
<t:integer> fnt, |
| 1718 |
<t:integer> chr, |
| 1719 |
<t:integer> size, |
| 1720 |
<t:integer> width, |
| 1721 |
<t:integer> height, |
| 1722 |
<t:integer> depth, |
| 1723 |
<t:integer> linewidth, |
| 1724 |
<t:integer> axis, |
| 1725 |
<t:integer> exheight, |
| 1726 |
<t:integer> emwidth |
| 1727 |
) |
| 1728 |
return <t:node> -- boxed extensible |
| 1729 |
end |
| 1730 |
\stoptyping |
| 1731 |
|
| 1732 |
\stopsubsection |
| 1733 |
|
| 1734 |
\startsubsection[title=register_extensible] |
| 1735 |
|
| 1736 |
This callback is a possible follow up on \typ {make_extensible} and it can be |
| 1737 |
used to share pre-build extensibles or package them otherwise (for instance as |
| 1738 |
\TYPETHREE\ glyph). |
| 1739 |
|
| 1740 |
\starttyping[option=LUA] |
| 1741 |
function ( |
| 1742 |
<t:integer> fnt, |
| 1743 |
<t:integer> chr, |
| 1744 |
<t:integer> size, |
| 1745 |
<t:node> attributes, |
| 1746 |
<t:node> extensible |
| 1747 |
) |
| 1748 |
return <t:node> -- boxed |
| 1749 |
end |
| 1750 |
\stoptyping |
| 1751 |
|
| 1752 |
\stopsubsection |
| 1753 |
|
| 1754 |
\startsubsection[title=balance] |
| 1755 |
|
| 1756 |
This callback is comparable with the \type {line_break} callback. We use it for |
| 1757 |
tracing in \CONTEXT\ during development (as well as for documentation). |
| 1758 |
|
| 1759 |
\stopsubsection |
| 1760 |
|
| 1761 |
\startsubsection[title=balance_insert] |
| 1762 |
|
| 1763 |
This is callback kicks in every time an insert is seen when balancing. |
| 1764 |
|
| 1765 |
\starttyping[option=LUA] |
| 1766 |
function ( |
| 1767 |
<t:node> current, |
| 1768 |
<t:integer> callback, |
| 1769 |
<t:integer> insert_index, |
| 1770 |
<t:integer> insert_identifier |
| 1771 |
) |
| 1772 |
-- no return value |
| 1773 |
end |
| 1774 |
\stoptyping |
| 1775 |
|
| 1776 |
\stopsubsection |
| 1777 |
|
| 1778 |
\startsubsection[title=balance_boundary] |
| 1779 |
|
| 1780 |
When balancing, this is callback kicks in every time a node resulting from \prm |
| 1781 |
{balanceboundary} is seen. |
| 1782 |
|
| 1783 |
\starttyping[option=LUA] |
| 1784 |
function ( |
| 1785 |
<t:integer> boundary_data, |
| 1786 |
<t:integer> boundary_reserved, |
| 1787 |
<t:integer> shape_identifier, |
| 1788 |
<t:integer> shape_slot |
| 1789 |
) |
| 1790 |
return |
| 1791 |
<t:integer>, -- action |
| 1792 |
<t:integer>, -- penalty |
| 1793 |
<t:integer> -- extra |
| 1794 |
end |
| 1795 |
\stoptyping |
| 1796 |
|
| 1797 |
What happens after the callback returns control to \TEX\ depends on the first |
| 1798 |
return value: |
| 1799 |
|
| 1800 |
\showenginevalues{getbalancecallbackvalues} |
| 1801 |
|
| 1802 |
This is an experimental feature. In due time there will be a bit more explanation |
| 1803 |
here. |
| 1804 |
|
| 1805 |
\stopsubsection |
| 1806 |
|
| 1807 |
\stopsection |
| 1808 |
|
| 1809 |
\stopdocument |
| 1810 |
|
| 1811 |
% timestamp october 2024, after running into Anna von Hausswolff's "All Thoughts |
| 1812 |
% Fly" live at Basilica di Santa Maria dei Servi 29.11.2021 |