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
|
%D \module
%D [ file=mtx-context-arrange,
%D version=2009.03.21,
%D title=\CONTEXT\ Extra Trickry,
%D subtitle=Arrange Files,
%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 \TEXEXEC\ features that has been moved to \MKIV.
% begin help
%
% usage: context --extra=arrange [options] list-of-files
%
% --sort : sort filenames first
% --paperoffset=dimension : left-top-offset
% --noduplex : singlesided (doublesided is default)
% --backspace=dimension : extra left offset
% --topspace=dimension : extra top offset
% --marking : add cutmarks
% --addempty=list : add empty pages at/after (comma separated list)
% --printformat : 2UP, etc
% --paperformat=spec : paper*print or paperxprint
%
% example: context --extra=arrange --printformat=2UP --paperformat=A4*A3,landscape myfile
% context --extra=arrange --printformat=xy --paperformat=A4*A2 --nx=2 --ny=2 myfile
% end help
\input mtx-context-common.tex
\doifdocumentargument {paperoffset} {
\definepapersize
[offset=\getdocumentargument{paperoffset}]
}
\doifdocumentargumentelse {noduplex} {
\setuppagenumbering
[alternative=doublesided]
\setdocumentargument{sided}{doublesided}
} {
\setdocumentargument{sided}{singlesided}
}
\setuppapersize
[\getdocumentargument{paperformat_paper}]
[\getdocumentargument{paperformat_print}]
% todo: autopapersize
%
% \setuppapersize
% [A4]
% [A3,landscape]
\setdocumentargumentdefault {textwidth} {0cm}
\setdocumentargumentdefault {backspace} {0cm}
\setdocumentargumentdefault {topspace} {0cm}
\setuplayout
[backspace=\getdocumentargument{backspace},
topspace=\getdocumentargument{topspace},
width=middle,
height=middle,
location=middle,
header=0pt,
footer=0pt]
\doifdocumentargument {marking} {yes} {
\setuplayout
[marking=on]
}
\startluacode
local printformat = document.arguments.printformat or ""
if printformat == "" then
printformat = "normal"
elseif string.find(printformat,"xy") then
if false then
context.setuplayout {
nx = document.arguments.nx or 1,
ny = document.arguments.ny or 1,
}
printformat = "XY,\\v!rotated"
else
context.setuppaper {
nx = document.arguments.nx or 1,
ny = document.arguments.ny or 1,
}
printformat = "XY"
end
elseif string.find(printformat,".*up") then
printformat = "2UP,\\v!rotated"
elseif string.find(printformat,".*down") then
printformat = "2DOWN,\\v!rotated"
elseif string.find(printformat,".*side") then
printformat = "2SIDE,\\v!rotated"
end
document.setargument("printformat",printformat)
\stopluacode
\setuparranging
[\getdocumentargument{sided},
\getdocumentargument{printformat}]
\starttext
\startluacode
local arguments = document.arguments
local files = document.files
local noffiles = #files
if noffiles > 0 then
if arguments.sort then
table.sort(files)
end
local emptypages = arguments.addempty or ""
local textwidth = arguments.textwidth or "0cm"
for i=1,noffiles do
local filename = files[i]
if not string.find(file.basename(filename),"^mtx%-context%-") then
context.insertpages (
{ filename },
{ emptypages },
{ width = textwidth }
)
end
end
else
context("no files given")
end
\stopluacode
\stoptext
|