page-ins.mkiv /size: 7059 b    last modification: 2021-10-28 13:50
1
%D \module
2
%D [ file=page-ins,
3
%D version=2002.04.16, % was core-ins
4
%D title=\CONTEXT\ Insertion Macros,
5
%D subtitle=Insertions,
6
%D author=Hans Hagen,
7
%D date=\currentdate,
8
%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9
%C
10
%C This module is part of the \CONTEXT\ macro||package and is
11
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12
%C details.
13 14
\writestatus
{
loading
}
{
ConTeXt
Core
Macros
/
Insertions
}
15 16
%D Insertions are special data collections that are associated to \TEX's internal
17
%D page builder. When multiple footnote classes were introduced, I decided to
18
%D isolate some of the functionality in a module.
19 20
\registerctxluafile
{
page
-
ins
}
{
}
21 22
\unprotect
23 24
%D Because we need to deal with inserts at the \LUA\ end as well,
25
%D we provide a proper installer.
26 27
% Not yet used as we need to adapt some code to this.
28 29
\installcorenamespace
{
insertion
}
30
\installcorenamespace
{
insertionnumber
}
31 32
\installcommandhandler
\??insertion
{
insertion
}
\??insertion
33 34
\setupinsertion
35
[
%c!n=\plusone,
36
%c!distance=\zeropoint,
37
%c!maxheight=\maxdimen,
38
%c!factor=\plusthousand,
39
\c!location
=
\v!page
]
40 41
\newconstant
\insertionmigrationmode
42 43
\def
\page_inserts_check_anchoring
44
{
\edef
\p_anchoring
{
\namedinsertionparameter
\empty
\c!anchoring
}
%
45
\insertionmigrationmode
\ifx
\p_anchoring
\v!auto
\plusone
\else
\zerocount
\fi
46
\clf_setinsertmigration
{
\p_anchoring
}
}
47 48
\appendtoks
49
\ifx
\currentinsertionparent
\empty
50
\page_inserts_check_anchoring
51
\fi
52
\to
\everysetupinsertion
53 54
\setupinsertion
55
[
\c!anchoring
=
\v!none
]
56 57
\appendtoks
58
\page_inserts_check_anchoring
59
\to
\everystarttext
% or \everyjob
60 61
\newcount
\currentinsertionnumber
% This is a count and not a macro !
62 63
\newtoks
\t_page_inserts_list
64 65
\let
\doprocessinsert
\relax
66 67
%D Maybe some day we will move settings here.
68 69
\unexpanded
\def
\setcurrentinsertion
#
1
%
70
{
\edef
\currentinsertion
{
#
1
}
%
71
\currentinsertionnumber
\csname
\??insertionnumber
\currentinsertion
\endcsname
}
72 73
\def
\namedinsertionnumber
#
1
{
\csname
\??insertionnumber
#
1
\endcsname
}
74 75
\unexpanded
\def
\page_inserts_synchronize_registers
76
{
\currentinsertionnumber
\csname
\??insertionnumber
\currentinsertion
\endcsname
}
77 78
% for practical reasons we still set these elsewhere but that might change in the future
79
%
80
% \global\count\currentinsertionnumber\numexpr\insertionparameter\c!factor/\insertionparameter\c!n\relax
81
% \global\skip \currentinsertionnumber\insertionparameter\c!distance \relax
82
% \global\dimen\currentinsertionnumber\insertionparameter\c!maxheight\relax}
83
% \floatingpenalty\zerocount
84 85
\appendtoks
86
\ifx
\currentinsertionparent
\empty
\else
87
\page_inserts_synchronize_registers
88
\fi
89
\to
\everysetupinsertion
90 91
\unexpanded
\def
\page_inserts_process
#
1
% beware, this adapts currentinsertion !
92
{
\edef
\currentinsertion
{
#
1
}
%
93
\currentinsertionnumber
\csname
\??insertionnumber
\currentinsertion
\endcsname
94
\doprocessinsert
\currentinsertionnumber
}
% old method
95 96
\unexpanded
\def
\processinsertions
97
{
\the
\t_page_inserts_list
}
98 99
\unexpanded
\def
\synchronizeinsertions
100
{
\let
\doprocessinsert
\page_inserts_synchronize
101
\processinsertions
}
102 103
\unexpanded
\def
\page_inserts_synchronize
#
1
% yes or no
104
{
\ifvoid
#
1
\else
105
\insert
#
1
{
\unvbox
#
1
}
%
106
\fi
}
107 108
\unexpanded
\def
\doifelseinsertion
#
1
%
109
{
\ifcsname
\??insertionnumber
#
1
\endcsname
110
\expandafter
\firstoftwoarguments
111
\else
112
\expandafter
\secondoftwoarguments
113
\fi
}
114 115
\let
\doifinsertionelse
\doifelseinsertion
116 117
% \unexpanded\def\startinsertion[#1]%
118
% {\insert\csname\??insertionnumber#1\endcsname\bgroup}
119
%
120
% \unexpanded\def\stopinsertion
121
% {\egroup}
122 123
% For the moment we use the regular insertion allocator so that users can
124
% still define their own insertions (not that they will play nicely with
125
% all context mechanisms then). We can use the dimensions at the \LUA\ end
126
% so we don't need to pass pass them explicitly. Actually, when we see an
127
% insertion node at that end, we already know the number.
128 129
\appendtoks
130
\ifx
\currentinsertionparent
\empty
131
\ifcsname
\??insertionnumber
\currentinsertion
\endcsname
132
% bad news
133
\else
134
\expandafter
\newinsert
\csname
\??insertionnumber
\currentinsertion
\endcsname
135
\page_inserts_synchronize_registers
136
\clf_defineinsertion
137
{
\currentinsertion
}
%
138
{
%
139
number
\currentinsertionnumber
140
}
%
141
\relax
142
\t_page_inserts_list
\expandafter
\expandafter
\expandafter
143
{
\expandafter
\the
\expandafter
\t_page_inserts_list
144
\expandafter
\page_inserts_process
\csname
\??insertionnumber
\currentinsertion
\endcsname
}
%
145
\count
\currentinsertionnumber
\plusthousand
146
\skip
\currentinsertionnumber
\zeropoint
147
\dimen
\currentinsertionnumber
\maxdimen
148
\fi
149
\else
150
\expandafter
\let
\csname
\??insertionnumber
\currentinsertion
\expandafter
\endcsname
151
\csname
\??insertionnumber
\currentinsertionparent
\endcsname
152
\fi
153
\to
\everydefineinsertion
154 155
\appendtoks
156
\ifx
\currentinsertionparent
\empty
\else
157
\clf_setupinsertion
158
{
\currentinsertion
}
159
{
%
160
location
{
\insertionparameter
\c!location
}
%
161
}
%
162
\relax
163
\fi
164
\to
\everysetupinsertion
165 166
\unexpanded
\def
\page_inserts_set_location
#
1
#
2
% fast one
167
{
\clf_setinsertionlocation
{
#
1
}
{
#
2
}
}
168 169
%D Auxiliary macros:
170 171
\def
\page_insert_insertion_height
#
1
%
172
{
\dimexpr
\expandafter
\page_insert_insertion_height_indeed
\csname
\??insertionnumber
#
1
\endcsname
\relax
}
173 174
\def
\page_insert_insertion_height_indeed
#
1
%
175
{
\ifvoid
#
1
\zeropoint
\else
1
\skip
#
1
+
\ht
#
1
\fi
}
176 177
%D Obsolete:
178 179
% \installcorenamespace{insertionbackup}
180
%
181
% \unexpanded\def\installbackupinsertion#1%
182
% {\ifcsname\??insertionbackup\string#1\endcsname \else
183
% \expandafter\newinsert\csname\??insertionbackup\string#1\endcsname
184
% \count\csname\??insertionbackup\string#1\endcsname\zerocount
185
% \skip \csname\??insertionbackup\string#1\endcsname\zeropoint
186
% \dimen\csname\??insertionbackup\string#1\endcsname\maxdimen
187
% \fi}
188
%
189
% \unexpanded\def\saveinsertionbox#1% hm, actually unknown
190
% {\global\setbox\csname\??insertionbackup\string#1\endcsname
191
% \ifdim\ht#1>\zeropoint\box#1\else\emptybox\fi}
192
%
193
% \unexpanded\def\restoreinsertionbox#1%
194
% {\ifvoid\backupinsertion#1\else % if void, we keep the content
195
% \global\setbox#1\box\csname\??insertionbackup\string#1\endcsname
196
% \fi}
197
%
198
% \unexpanded\def\eraseinsertionbackup#1%
199
% {\global\setbox\csname\??insertionbackup\string#1\endcsname\emptybox}
200
%
201
% \unexpanded\def\saveinsertiondata#1%
202
% {\global\skip \csname\??insertionbackup\string#1\endcsname\skip #1%
203
% \global\count\csname\??insertionbackup\string#1\endcsname\count#1%
204
% \global\dimen\csname\??insertionbackup\string#1\endcsname\dimen#1}
205
%
206
% \unexpanded\def\restoreinsertiondata#1%
207
% {\global\skip #1\skip \csname\??insertionbackup\string#1\endcsname
208
% \global\count#1\count\csname\??insertionbackup\string#1\endcsname
209
% \global\dimen#1\dimen\csname\??insertionbackup\string#1\endcsname}
210 211
\protect
\endinput
212