1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20\writestatus{loading}{ConTeXt Anchoring Macros Synchronization}
21
22\registerctxluafile{anchsnc}{}
23
24\unprotect
25
26\ifx\??syncposcounter\undefined \installcorenamespace{syncposcounter} \fi
27\ifx\s!syncpos \undefined \def\s!syncpos {syncpos} \fi
28
29\let\c_sync_n\relax
30
31\unexpanded\def\definesyncpositions[#1]
32 {\ifcsname\??syncposcounter:#1\endcsname \else
33 \expandafter\newcount\csname\??syncposcounter:#1\endcsname
34 \fi}
35
36\unexpanded\def\syncposition
37 {\dodoubleempty\anch_sync_position}
38
39\def\anch_sync_position[#1][#2]
40 {\dontleavehmode
41 \ifcsname\??syncposcounter:#1\endcsname
42 \let\c_sync_n\lastnamedcs
43 \global\advance\c_sync_n\plusone
44 \enabletextarearegistration
45 \setpositionplus{\s!syncpos:#1:\the\c_sync_n}{#2}\hpack{\strut}
46 \else
47 \strut
48 \fi
49 \ignorespaces}
50
51\protect
52
53\continueifinputfile{anchsnc.mkiv}
54
55\starttext
56
57
58
59\setuplayout[location=middle]
60
61\setupbodyfont[dejavu]
62
63\definesyncpositions[1]
64\definesyncpositions[2]
65
66
67
68\startMPdefinitions
69 input "mp-asnc.mpiv" ;
70
71 SetSyncColor(1,0,"magenta") ;
72 SetSyncColor(1,1,"red") ;
73 SetSyncColor(1,2,"green") ;
74 SetSyncColor(1,3,"blue") ;
75 SetSyncColor(1,4,"yellow") ;
76
77 SetSyncColor(2,0,"magenta") ;
78 SetSyncColor(2,1,"red") ;
79 SetSyncColor(2,2,"green") ;
80 SetSyncColor(2,3,"blue") ;
81 SetSyncColor(2,4,"yellow") ;
82\stopMPdefinitions
83
84\startuseMPgraphic{sync1}
85 StartPage ;
86 StartSync(1) ;
87 SyncHOffset := 0 ;
88 SyncWidth := BackSpace LeftMarginDistance;
89 CollectSyncDataPage ;
90
91 PruneSyncPaths ;
92 CollapseSyncPaths ;
93 MakeSyncPaths ;
94
95 FillSyncPaths ;
96 StopSync ;
97 clip currentpicture to Page ;
98 setbounds currentpicture to Page ;
99 StopPage ;
100\stopuseMPgraphic
101
102\startuseMPgraphic{sync2}
103 StartSync(2) ;
104 SyncHOffset := -1cm ;
105 SyncWidth := 1cm ;
106 CollectSyncDataRegion(OverlayRegion) ;
107 ExtendSyncPaths ;
108 MakeSyncPaths ;
109 FillSyncPaths ;
110 StopSync ;
111 clip currentpicture to OverlayBox leftenlarged 1cm;
112 setbounds currentpicture to OverlayBox ;
113\stopuseMPgraphic
114
115\defineoverlay[tempoverlay1][\useMPgraphic{sync1}]
116\defineoverlay[tempoverlay2][\useMPgraphic{sync2}]
117
118\setupbackgrounds[page][background=tempoverlay1]
119
120\framed[region=yes,background=tempoverlay2,width=14cm,align=normal]{
121 \syncposition[2][1]\samplefile{ward}\endgraf
122 \syncposition[2][2]\samplefile{ward}\endgraf
123 \syncposition[2][3]\samplefile{ward}\endgraf
124}
125
126
127\vskip1cm \hskip1cm \framed[region=yes,background=tempoverlay2,width=16cm,align=normal]{
128 \syncposition[2][1]\samplefile{ward}\endgraf
129 \syncposition[2][2]\samplefile{ward}\endgraf
130 \syncposition[2][3]\samplefile{ward}\endgraf
131}
132
133\vskip1cm \hskip1cm \framed[region=yes,background=tempoverlay2,width=10cm,align=normal]{
134 \syncposition[2][1]\samplefile{ward}\endgraf
135 \syncposition[2][2]\samplefile{ward}\endgraf
136 \syncposition[2][3]\samplefile{ward}\endgraf
137}
138
139
140\dorecurse {100} {
141
142 \startchapter[title={Test #1}]
143 \syncposition[1][1,reset]\dorecurse{20}{\samplefile{ward}\endgraf}
144 \syncposition[1][2]\dorecurse {4}{\samplefile{ward}\endgraf}
145 \syncposition[1][3]\dorecurse {7}{\samplefile{ward}\endgraf}
146 \syncposition[1][4]\dorecurse {3}{\samplefile{ward}\endgraf}
147 \stopchapter
148}
149
150\dorecurse {100} {
151
152 \startchapter[title={Test #1}]
153 \syncposition[1][1]\dorecurse{1}{\samplefile{ward}\endgraf}
154 \syncposition[1][2]\dorecurse{1}{\samplefile{ward}\endgraf}
155 \syncposition[1][3]\dorecurse{1}{\samplefile{ward}\endgraf}
156 \syncposition[1][4]\dorecurse{1}{\samplefile{ward}\endgraf}
157 \stopchapter
158}
159
160\stoptext
161 |