summaryrefslogtreecommitdiff
path: root/macros/luatex/generic/minim/minim-hooks.tex
blob: b3b80926541e8af04211cad880fed1b29fe96745 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56

% The purpose of this module is allowing arbitrary code be run at specific 
% places. I have not yet included it in the manual, because I still am a bit 
% unsure about the details of the implementation.
%
% The first thing done here is inserting a callback into \shipout (and 
% tex.shipout) mirroring finish_pdf, allowing last-minute manipulation before 
% the pdf code will be assembled.
%
% The second feature is adding things to the beginning of a paragraph without 
% (seemingly) disturbing \everypar, and also adding things to the next 
% paragraph only.
%
% Both features are implemented in a way that is repeatable and should coexist 
% peacefully with other packages doing something of the same. But please let me 
% know if you run into any problems.

\ifdefined\minimhooksloaded
    \message{(skipped)}
    \expandafter\endinput\fi
\chardef\minimhooksloaded = \catcode`\:
\catcode`\: = 11

\input minim-alloc

% 1 the pre_shipout callback

\newbox\minim:shipout:box \let\minim:shipout:orig = \shipout
\def\minim:shipout:do{\minim:shipout:orig\box\minim:shipout:box}
\directlua{require('minim-hooks')} \let\shipout\minim:shipout

% 1 invisibly adding to \everypar

\let\minim:everypar = \everypar
\newtoks\minim:ateverypar
\newtoks\minim:atnextpar
\newtoks\everypar \everypar\minim:everypar
\minim:everypar\expandafter{\expandafter
    \minim:changeparindent
    % expansion makes this process repeatable
    \expandafter\the\everypar
    \the\minim:ateverypar
    \minim:atnextpar\expandafter
        {\expandafter}\the\minim:atnextpar}
\let\minim:changeparindent = \relax % as of yet unused

% There is no need for the following.

%\let\minim:par = \par
%\newtoks\minim:aftereverypar
%\protected\def\par{\ifhmode \unskip
%    \the\minim:aftereverypar \fi \minim:par}

\catcode`\: = \minimhooksloaded