summaryrefslogtreecommitdiff
path: root/tex/context/base/mkxl/anch-snc.mkxl
blob: dcf2c86cba94b60a13102cdfebb8b397dd99b4c6 (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
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
%D \module
%D   [       file=anch-snc,
%D        version=2003.12.01, % actually 1999 so real old
%D          title=\CONTEXT\ Anchoring Macros,
%D       subtitle=Synchronization,
%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.

%D This is a rather old mechanism that we once needed in an actually nice design.
%D Those were the times that processing a rather complex xml file with \PDFTEX\ into
%D a 400 page document took 45 minutes (a few runs) while nowadays with luatex and
%D \MKIV\ (and \LMTX) we express runtime in seconds.
%D
%D In retrospect it was a waste of time (and money) to invest in all these
%D mechanisms because the publishers we were dealign with were far from ready for
%D dealing with xml and let alone automatic rendering. But, as the code still worked
%D well after nearly two decades I decided to revive it .. maybe some curious
%D \CONTEXT\ user can benefit from it after all.
%D
%D The logic is mostly the same as in \MKII\ but some work is now delegated to \LUA\
%D so that we save memory and gain some runtime. As this was not really a used
%D module the interface also was upgraded. As we know the bottlenecks in \METAPOST\
%D we also work around those a bit. It made sense too change the interface to use
%D the new \LMTX\ mechanisms for passing parameters. The old interface can be found
%D in the \MKII\ and \MKIV\ files.

%D TODO: bleed | autobleed

\writestatus{loading}{ConTeXt Anchoring Macros / Synchronization}

\registerctxluafile{anch-snc}{}
\registerctxluafile{mlib-snc}{}

%D \stoptyping
%D \starttext
%D
%D \setuplayout[location=middle]
%D \setupbodyfont[dejavu]
%D
%D \definesyncpositions[1]
%D \definesyncpositions[2]
%D
%D % \startuseMPgraphic{sync1}
%D %     StartPage ;
%D %         lmt_synchronizer [ ... ] ;
%D %         clip currentpicture to Page ;
%D %         setbounds currentpicture to Page ;
%D %     StopPage ;
%D % \stopuseMPgraphic
%D
%D \startuseMPgraphic{sync1}
%D     lmt_synchronizer [
%D       % page       = "yes",
%D         index      = 1,
%D         hoffset    = 0,
%D         width      = BackSpace - LeftMarginDistance,
%D         extend     = false,
%D         prune      = true,
%D         draw       = false,
%D         fill       = true,
%D     ] ;
%D \stopuseMPgraphic
%D
%D \startuseMPgraphic{sync2}
%D     lmt_synchronizer [
%D         index   = 2,
%D         region  = OverlayRegion,
%D         hoffset = -1cm,
%D         width   = 1cm,
%D         extend  = true,
%D         prune   = false,
%D         draw    = false,
%D         fill    = true,
%D     ] ;
%D     clip currentpicture to OverlayBox leftenlarged 1cm;
%D     setbounds currentpicture to OverlayBox ;
%D \stopuseMPgraphic
%D
%D \defineoverlay[tempoverlay1][\useMPgraphic{sync1}]
%D \defineoverlay[tempoverlay2][\useMPgraphic{sync2}]
%D
%D \setupbackgrounds[page][background=tempoverlay1]
%D
%D \framed[region=yes,background=tempoverlay2,width=14cm,align=normal]{%
%D     \syncposition[2][1]\samplefile{ward}\endgraf
%D     \syncposition[2][2]\samplefile{ward}\endgraf
%D     \syncposition[2][3]\samplefile{ward}\endgraf
%D }
%D
%D \vskip1cm \hskip1cm \framed[region=yes,background=tempoverlay2,width=16cm,align=normal]{%
%D     \syncposition[2][1]\samplefile{ward}\endgraf
%D     \syncposition[2][2]\samplefile{ward}\endgraf
%D     \syncposition[2][3]\samplefile{ward}\endgraf
%D }
%D
%D \vskip1cm \hskip1cm \framed[region=yes,background=tempoverlay2,width=10cm,align=normal]{%
%D     \syncposition[2][1]\samplefile{ward}\endgraf
%D     \syncposition[2][2]\samplefile{ward}\endgraf
%D     \syncposition[2][3]\samplefile{ward}\endgraf
%D }
%D
%D \dorecurse {100} {
%D     \startchapter[title={Test #1}]
%D         \syncposition[1][1,reset]\dorecurse{20}{\samplefile{ward}\endgraf}
%D         \syncposition[1][2]\dorecurse {4}{\samplefile{ward}\endgraf}
%D         \syncposition[1][3]\dorecurse {7}{\samplefile{ward}\endgraf}
%D         \syncposition[1][4]\dorecurse {3}{\samplefile{ward}\endgraf}
%D     \stopchapter
%D }
%D
%D \dorecurse {100} {
%D     \startchapter[title={Test #1}]
%D         \syncposition[1][1]\dorecurse{1}{\samplefile{ward}\endgraf}
%D         \syncposition[1][2]\dorecurse{1}{\samplefile{ward}\endgraf}
%D         \syncposition[1][3]\dorecurse{1}{\samplefile{ward}\endgraf}
%D         \syncposition[1][4]\dorecurse{1}{\samplefile{ward}\endgraf}
%D     \stopchapter
%D }
%D
%D \stoptext
%D \stoptyping

%D We could actually use par positions but in \LMTX\ we have syncpos entries
%D somewhat optimized.

\unprotect

\installcorenamespace{syncposcounter}

\let\c_sync_n\relax

\permanent\protected\def\definesyncpositions[#1]%
  {\ifcsname\??syncposcounter:#1\endcsname \else
     \expandafter\newcount\csname\??syncposcounter:#1\endcsname
   \fi}

\permanent\tolerant\protected\def\syncposition[#1]#*[#2]%
  {\dontleavehmode
   \ifcsname\??syncposcounter:#1\endcsname
     \let\c_sync_n\lastnamedcs
     \global\advance\c_sync_n\plusone
     \enabletextarearegistration
     \setpositionplus{\s!syncpos:#1:\the\c_sync_n}{#2}\hpack{\strut}%
   \else
     \strut
   \fi
   \ignorespaces}

\protect