1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24\continuewhenlmtxmode
25
26\input mtxcontextcommon.tex
27
28\setupexternalfigures
29 [directory=]
30
31\definepapersize
32 [fit]
33 [width=\figurewidth,
34 height=\figureheight]
35
36\setuplayout
37 [page]
38
39\doif {\getdocumentargument{interaction}} {yes} {
40 \setupinteraction
41 [state=start]
42 \setupexternalfigures
43 [interaction=yes]
44}
45
46\doif {\getdocumentargument{tracelinks}} {yes} {
47 \enabletrackers[figures.links]
48
49
50}
51
52\starttexdefinition CopyPages #1
53
54 \filterpages[#1][all][alternative=page]
55
56\stoptexdefinition
57
58\starttexdefinition CopyEntry #1#2#3#4
59
60 \doifelsesomething {#4} {
61 \setupinteraction
62 [state=start]
63 \setupexternalfigures
64 [interaction={#4}]
65 \writestatus
66 {filter pages}
67 {file #1, first page #2, last page #3, interaction #4}
68
69 } {
70 \setupinteraction
71 [state=stop]
72 \setupexternalfigures
73 [interaction=]
74 \writestatus
75 {filter pages}
76 {file #1, first page #2, last page #3}
77 }
78
79 \filterpages[#1][#2:#3][alternative=page]
80
81\stoptexdefinition
82
83\starttext
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\startluacode
113
114 local find = string.find
115
116 if #document.files == 0 then
117 context("no files given")
118 elseif document.arguments.template then
119 local filename = file.addsuffix(document.files[1],"lua")
120 local template = table.load(filename)
121 if template then
122 local list = template.list
123 if type(list) == "table" then
124 for i=1,#list do
125 local entry = list[i]
126 local filename = entry.filename or ""
127 local first = tonumber(entry.first) or 1
128 local last = tonumber(entry.last) or "*"
129 local interaction = entry.interaction or ""
130 local pageoffset = tonumber(entry.pageoffset)
131 local minheight = tonumber(entry.minheight)
132 if interaction ~= "" then
133 if pageoffset then
134 interaction = interaction .. ",pageoffset:" .. pageoffset
135 end
136 if minheight then
137 interaction = interaction .. ",minheight:" .. minheight
138 end
139 end
140 context.CopyEntry(filename,first,last,interaction)
141 end
142 end
143 else
144 logs.report("copy","invalid or missing template file")
145 end
146 else
147 if document.arguments.pattern then
148 document.files = dir.glob(document.arguments.pattern)
149 end
150 for i=1,#document.files do
151 local filename = document.files[i]
152 if not find(filename,"^mtx%-context%-") and not find(filename,"^context%-extra") then
153 logs.report("copy",filename)
154 context.CopyPages(filename)
155 end
156 end
157 end
158
159\stopluacode
160
161\stoptext
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235 |