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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
%D \module
%D [ file=core-ins,
%D version=2002.04.16,
%D title=\CONTEXT\ Insertion Macros,
%D subtitle=Insertions,
%D author=Hans Hagen,
%D date=\currentdate,
%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
\writestatus{loading}{ConTeXt Core Macros / Insertions}
%D Insertions are special data collections that are associated to \TEX's internal
%D page builder. When multiple footnote classes were introduced, I decided to
%D isolate some of the functionality in a module.
\registerctxluafile{page-ins}{1.001}
\unprotect
%D Because we need to deal with inserts at the \LUA\ end as well,
%D we provide a proper installer.
% Not yet used as we need to adapt some code to this.
\installcorenamespace{insertion}
\installcorenamespace{insertionnumber}
\installcommandhandler \??insertion {insertion} \??insertion
\setupinsertion
[%c!n=\plusone,
%c!distance=\zeropoint,
%c!maxheight=\maxdimen,
%c!factor=\plusthousand,
\c!location=\v!page]
\newcount\currentinsertionnumber % This is a count and not a macro !
\newtoks\t_page_inserts_list
\let\doprocessinsert\relax
%D Maybe some day we will move settings here.
\unexpanded\def\setcurrentinsertion#1%
{\edef\currentinsertion{#1}%
\currentinsertionnumber\csname\??insertionnumber\currentinsertion\endcsname}
\def\namedinsertionnumber#1{\csname\??insertionnumber#1\endcsname}
\unexpanded\def\page_inserts_synchronize_registers
{\currentinsertionnumber\csname\??insertionnumber\currentinsertion\endcsname}
% for practical reasone we still set these elsewhere but that might chaneg in the future
%
% \global\count\currentinsertionnumber\numexpr\insertionparameter\c!factor/\insertionparameter\c!n\relax
% \global\skip \currentinsertionnumber\insertionparameter\c!distance \relax
% \global\dimen\currentinsertionnumber\insertionparameter\c!maxheight\relax}
\appendtoks
\page_inserts_synchronize_registers
\to \everysetupinsertion
\unexpanded\def\page_inserts_process#1% beware, this addapts currentinsertion !
{\edef\currentinsertion{#1}%
\currentinsertionnumber\csname\??insertionnumber\currentinsertion\endcsname
\doprocessinsert\currentinsertionnumber} % old method
\unexpanded\def\processinsertions
{\the\t_page_inserts_list}
\unexpanded\def\synchronizeinsertions
{\let\doprocessinsert\page_inserts_synchronize
\processinsertions}
\unexpanded\def\page_inserts_synchronize#1% yes or no
{\ifvoid#1\else
\insert#1{\unvbox#1}%
\fi}
\unexpanded\def\doifelseinsertion#1%
{\ifcsname\??insertionnumber#1\endcsname
\expandafter\firstoftwoarguments
\else
\expandafter\secondoftwoarguments
\fi}
\let\doifinsertionelse\doifelseinsertion
% \unexpanded\def\startinsertion[#1]%
% {\insert\csname\??insertionnumber#1\endcsname\bgroup}
%
% \unexpanded\def\stopinsertion
% {\egroup}
% For the moment we use the regular insertion allocator so that users can
% still define their own insertions (not that they will play nicely with
% all context mechanisms then). We can use the dimensions at the \LUA\ end
% so we don't need to pass pass them explicitly. Actually, when we see an
% insertion node at that end, we already know the number.
\appendtoks
\ifx\currentinsertionparent\empty
\ifcsname\??insertionnumber\currentinsertion\endcsname
% bad news
\else
\expandafter\newinsert\csname\??insertionnumber\currentinsertion\endcsname
\page_inserts_synchronize_registers
\clf_defineinsertion
{\currentinsertion}%
{%
number \currentinsertionnumber
}%
\relax
\t_page_inserts_list\expandafter\expandafter\expandafter
{\expandafter\the\expandafter\t_page_inserts_list
\expandafter\page_inserts_process\csname\??insertionnumber\currentinsertion\endcsname}%
\count\currentinsertionnumber\plusthousand
\skip \currentinsertionnumber\zeropoint
\dimen\currentinsertionnumber\maxdimen
\fi
\else
\expandafter\let\csname\??insertionnumber\currentinsertion\expandafter\endcsname
\csname\??insertionnumber\currentinsertionparent\endcsname
\fi
\to \everydefineinsertion
\appendtoks
\clf_setupinsertion
{\currentinsertion}
{%
location {\insertionparameter\c!location}%
}%
\relax
\to \everysetupinsertion
\unexpanded\def\page_inserts_set_location#1#2% fast one
{\clf_setinsertionlocation{#1}{#2}}
%D Auxiliary macros:
\def\page_insert_insertion_height#1%
{\dimexpr\expandafter\page_insert_insertion_height_indeed\csname\??insertionnumber#1\endcsname\relax}
\def\page_insert_insertion_height_indeed#1%
{\ifvoid#1\zeropoint\else1\skip#1+\ht#1\fi}
%D Obsolete:
% \installcorenamespace{insertionbackup}
%
% \unexpanded\def\installbackupinsertion#1%
% {\ifcsname\??insertionbackup\string#1\endcsname \else
% \expandafter\newinsert\csname\??insertionbackup\string#1\endcsname
% \count\csname\??insertionbackup\string#1\endcsname\zerocount
% \skip \csname\??insertionbackup\string#1\endcsname\zeropoint
% \dimen\csname\??insertionbackup\string#1\endcsname\maxdimen
% \fi}
%
% \unexpanded\def\saveinsertionbox#1% hm, actually unknown
% {\global\setbox\csname\??insertionbackup\string#1\endcsname
% \ifdim\ht#1>\zeropoint\box#1\else\emptybox\fi}
%
% \unexpanded\def\restoreinsertionbox#1%
% {\ifvoid\backupinsertion#1\else % if void, we keep the content
% \global\setbox#1\box\csname\??insertionbackup\string#1\endcsname
% \fi}
%
% \unexpanded\def\eraseinsertionbackup#1%
% {\global\setbox\csname\??insertionbackup\string#1\endcsname\emptybox}
%
% \unexpanded\def\saveinsertiondata#1%
% {\global\skip \csname\??insertionbackup\string#1\endcsname\skip #1%
% \global\count\csname\??insertionbackup\string#1\endcsname\count#1%
% \global\dimen\csname\??insertionbackup\string#1\endcsname\dimen#1}
%
% \unexpanded\def\restoreinsertiondata#1%
% {\global\skip #1\skip \csname\??insertionbackup\string#1\endcsname
% \global\count#1\count\csname\??insertionbackup\string#1\endcsname
% \global\dimen#1\dimen\csname\??insertionbackup\string#1\endcsname}
\protect \endinput
|