followingup-whatsits.tex /size: 4116 b    last modification: 2021-10-28 13:50
1% language=us runpath=texruns:manuals/followingup
2
3\startcomponent followingup-whatsits
4
5\environment followingup-style
6
7\startchapter[title={Whatsits}]
8
9% \startsection[title={...}]
10
11Whatsits provide the natural extension mechanism for \TEX. In \PDFTEX\ there are
12plenty such whatsits, for instance for \PDF\ annotations. In \LUATEX\ this
13mechanism was reorganized so that the code was better isolated. In the first
14versions of \LUAMETATEX\ only a handful was left. Stepwise some were removed and
15in the end we could stick to only one general whatsit because one can implement
16the few needed to be compatible with \TEX.
17
18We started out with this set of whatsits:
19
20\starttabulate[|B|p|]
21\NC open    \NC open a file for writing (delayed) \NC \NR
22\NC write   \NC write to an open file (or terminal otherwise) \NC \NR
23\NC close   \NC close an opened file \NC \NR
24\NC special \NC write some literal \PDF\ code to the output file \NC \NR
25\NC user    \NC store and retrieve data in a node \NC \NR
26\NC latelua \NC execute code delayed (in the backend) \NC \NR
27\NC literal \NC write some literal \PDF\ code to the output file, controlled by a mode \NC \NR
28\NC save    \NC push the transformation state \NC \NR
29\NC restore \NC pop the transformation state \NC \NR
30\NC matrix  \NC apply a transformation (\type {rx sx sy ry}) \NC \NR
31\NC savepos \NC register a position to be queried afterwards (\type {x y}) \NC \NR
32\stoptabulate
33
34The \type {\openout}, \type {\write} and \type {\closeout} primitives relate to
35the first three but they can be prefixed with \type {\immediate} in which case
36they don't end up as whatsits but are applied directly. The \type {special} is
37actually meant for \DVI\ while the \type {\(pdf)literal} is for \PDF\ output. The
38first four are available in regular \TEX.
39
40The last four are dealt with exclusively in the backend and by removing the
41backend they basically became no|-|ops. I kept them for a while but in the end
42decided to kick them out. Instead a generic whatsit was introduced that could be
43used as signal with the same function. That simple whatsit only has a subtype
44(and of course optionally attributes). And, as \CONTEXT\ has its own backend, we
45can intercept them as we like. The saving in code is not spectacular but keeping
46it around (basically doing nothing) neither. The impact on \CONTEXT\ was not that
47large because for instance saving positions is done differently and
48transformations are encapsulated in a few helpers that could easily be adapted.
49
50From there it was a small step to also remove the literal whatsit, so then we had
51five whatsits left, plus the generic one. I then entered sentimental mode: should
52we keep the first four or not. Of course we want to be \TEX\ compatible but we
53can remove the code and provide a compatible replacement using macros and our own
54simple whatsit nodes. That keeps all the housekeeping at the \LUA\ end,
55simplifies the \CCODE, and we're still \TEX.
56
57Of course, once we remove these and only have the delayed \LUA\ whatsit and user
58whatsits left, we can as well replace these too. In \LUATEX\ user nodes are
59actually not dealt with in the backend. One can create them at the \LUA\ end and
60query them in callbacks. The \TEX\ machinery just ignores them, like any whatsit.
61In retrospect they could have been first class nodes, but making them whatsits
62was wise because that way they can be ignored consistently when needed.
63
64So, in the end all we need is a simple whatsit. As I removed the subtypes
65stepwise there was an intermediate mix of code to recognize simple whatsits from
66core whatsits but that distinction went away. Doing this kind of refactoring is
67best done stepwise because that way I can compile some large documents and see if
68things break. As a consequence again some code could be simplified as we
69basically no longer have extensions. Of course at the \CONTEXT\ end the removed
70primitives had to be added but that didn't take much effort. The binary shrunk
71some 30K but (a small amount of) \LUA\ code was added to provide a compatible
72functionality (not that we use it).
73
74% \stopsection
75
76\stopchapter
77
78\stopcomponent
79