mtx-context-arrange.tex /size: 3963 b    last modification: 2020-07-01 14:35
1
%D \module
2
%D [ file=mtx-context-arrange,
3
%D version=2009.03.21,
4
%D title=\CONTEXT\ Extra Trickry,
5
%D subtitle=Arrange Files,
6
%D author=Hans Hagen,
7
%D date=\currentdate,
8
%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9
%C
10
%C This module is part of the \CONTEXT\ macro||package and is
11
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12
%C details.
13 14
%D This is a \TEXEXEC\ features that has been moved to \MKIV.
15 16
% begin help
17
%
18
% usage: context --extra=arrange [options] list-of-files
19
%
20
% --sort : sort filenames first
21
% --paperoffset=dimension : left-top-offset
22
% --noduplex : singlesided (doublesided is default)
23
% --backspace=dimension : extra left offset
24
% --topspace=dimension : extra top offset
25
% --marking : add cutmarks
26
% --addempty=list : add empty pages at/after (comma separated list)
27
% --printformat : 2UP, etc
28
% --paperformat=spec : paper*print or paperxprint
29
%
30
% example: context --extra=arrange --printformat=2UP --paperformat=A4*A3,landscape myfile
31
% context --extra=arrange --printformat=xy --paperformat=A4*A2 --nx=2 --ny=2 myfile
32
% end help
33 34
\input
mtx
-
context
-
common
.
tex
35 36
\doifdocumentargument
{
paperoffset
}
{
37
\definepapersize
38
[
offset
=
\getdocumentargumentdefault
{
paperoffset
}{
0
pt
}
]
39
}
40 41
\doifdocumentargumentelse
{
noduplex
}
{
42
\setuppagenumbering
43
[
alternative
=
doublesided
]
44
\setdocumentargument
{
sided
}{
doublesided
}
45
}
{
46
\setdocumentargument
{
sided
}{
singlesided
}
47
}
48 49 50
\setuppapersize
51
[
\getdocumentargument
{
paperformat
_
paper
}
]
52
[
\getdocumentargument
{
paperformat
_
print
}
]
53 54
% todo: autopapersize
55
%
56
% \setuppapersize
57
% [A4]
58
% [A3,landscape]
59 60
\setdocumentargumentdefault
{
textwidth
}
{
0
cm
}
61
\setdocumentargumentdefault
{
backspace
}
{
0
cm
}
62
\setdocumentargumentdefault
{
topspace
}
{
0
cm
}
63 64
\setuplayout
65
[
backspace
=
\getdocumentargument
{
backspace
}
,
66
topspace
=
\getdocumentargument
{
topspace
}
,
67
width
=
middle
,
68
height
=
middle
,
69
location
=
middle
,
70
header
=
0
pt
,
71
footer
=
0
pt
]
72 73
\doifdocumentargument
{
marking
}
{
yes
}
{
74
\setuplayout
75
[
marking
=
on
]
76
}
77 78
\startluacode
79
local
printformat
=
document
.
arguments
.
printformat
or
"
"
80
if
printformat
=
=
"
"
then
81
printformat
=
"
normal
"
82
elseif
string
.
find
(
printformat
,
"
xy
"
)
then
83
if
false
then
84
context
.
setuplayout
{
85
nx
=
document
.
arguments
.
nx
or
1
,
86
ny
=
document
.
arguments
.
ny
or
1
,
87
}
88
printformat
=
"
XY,\\v!rotated
"
89
else
90
context
.
setuppaper
{
91
nx
=
document
.
arguments
.
nx
or
1
,
92
ny
=
document
.
arguments
.
ny
or
1
,
93
}
94
printformat
=
"
XY
"
95
end
96
elseif
string
.
find
(
printformat
,
"
.*up
"
)
then
97
printformat
=
"
2UP,\\v!rotated
"
98
elseif
string
.
find
(
printformat
,
"
.*down
"
)
then
99
printformat
=
"
2DOWN,\\v!rotated
"
100
elseif
string
.
find
(
printformat
,
"
.*side
"
)
then
101
printformat
=
"
2SIDE,\\v!rotated
"
102
end
103
document
.
setargument
(
"
printformat
"
,
printformat
)
104
\stopluacode
105 106
\setuparranging
107
[
\getdocumentargument
{
sided
}
,
108
\getdocumentargument
{
printformat
}
]
109 110
\starttext
111 112
\startluacode
113
local
arguments
=
document
.
arguments
114
local
files
=
document
.
files
115
local
noffiles
=
#
files
116
if
noffiles
>
0
then
117
if
arguments
.
sort
then
118
table
.
sort
(
files
)
119
end
120
local
emptypages
=
arguments
.
addempty
or
"
"
121
local
textwidth
=
arguments
.
textwidth
or
"
0cm
"
122
for
i
=
1
,
noffiles
do
123
local
filename
=
files
[
i
]
124
if
not
string
.
find
(
file
.
basename
(
filename
)
,
"
^mtx%-context%-
"
)
then
125
context
.
insertpages
(
126
{
filename
}
,
127
{
emptypages
}
,
128
{
width
=
textwidth
}
129
)
130
end
131
end
132
else
133
context
(
"
no files given
"
)
134
end
135
\stopluacode
136 137
\stoptext
138