summaryrefslogtreecommitdiff
path: root/tex/context/base/page-ins.mkii
blob: ce0f51d7282958b29d379659c6c051f5bddc6bf6 (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
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
%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
%D to \TEX's internal page builder. When multiple footnote
%D classes were introduced, I decided to isolate some of the
%D functionality in a module.

\unprotect

\newtoks\@@insertionlist

\def\processinsertions{\the\@@insertionlist}

\let\doprocessinsert\gobbleoneargument

%\def\installinsertion#1%
%  {\ifx#1\undefined
%     \newinsert#1%
%     \count#1\plusthousand
%     \skip #1\zeropoint
%     \dimen#1\maxdimen
%     \appendtoks\doprocessinsert#1\to\@@insertionlist
%   \fi}

\def\installinsertion#1%
  {\ifx#1\undefined
     \let#1\relax
   \fi
   \ifx#1\relax % permits \csname...\endcsname
     \newinsert#1%
     \count#1\plusthousand
     \skip #1\zeropoint
     \dimen#1\maxdimen
     \appendtoks\doprocessinsert#1\to\@@insertionlist
   \fi}


\def\synchronizeinsertions
  {\def\doprocessinsert##1{\ifvoid##1\else\insert##1{\unvbox##1}\fi}%
   \processinsertions}

%D For instance, when we postpone footnotes, we need to save
%D some data related to the inserts. The next methods are
%D far from ideal, but better than nothing. We save and
%D restore box content and associated data independently.
%D The box content is only restores when non||void.

\def\backupinsertion#1%
  {\csname\string#1\endcsname}

\def\installbackupinsertion#1%
  {\expandafter\newinsert\csname\string#1\endcsname
   \count\backupinsertion#1\zerocount
   \skip \backupinsertion#1\zeropoint
   \dimen\backupinsertion#1\maxdimen}

\def\saveinsertionbox#1%
  {\ifdim\ht#1>\zeropoint % hm, actually unknown
     \global\setbox\backupinsertion#1\box#1%
   \else
     \global\setbox\backupinsertion#1\emptybox
   \fi}

\def\restoreinsertionbox#1%
  {\ifvoid\backupinsertion#1\else % if void, we keep the content
     \global\setbox#1\box\backupinsertion#1%
   \fi}

\def\eraseinsertionbackup#1%
  {\global\setbox\backupinsertion#1\emptybox}

\def\saveinsertiondata#1%
  {\global\skip \backupinsertion#1\skip #1%
   \global\count\backupinsertion#1\count#1%
   \global\dimen\backupinsertion#1\dimen#1}

\def\restoreinsertiondata#1%
  {\global\skip #1\skip \backupinsertion#1%
   \global\count#1\count\backupinsertion#1%
   \global\dimen#1\dimen\backupinsertion#1}

%D Auxiliary macros:

\def\addinsertionheight#1\to#2%
  {\ifvoid#1\else
     \advance#2 1\skip#1\relax
     \advance#2  \ht  #1\relax
   \fi}

\protect \endinput