mtx-context-copy.tex /size: 5085 b    last modification: 2020-07-01 14:35
1
% engine=luatex
2 3
%D \module
4
%D [ file=mtx-context-copy,
5
%D version=2008.11.10, % about that time i started playing with this
6
%D title=\CONTEXT\ Extra Trickry,
7
%D subtitle=Copying Files,
8
%D author=Hans Hagen,
9
%D date=\currentdate,
10
%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
11
%C
12
%C This module is part of the \CONTEXT\ macro||package and is
13
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
14
%C details.
15 16
%D This is a \TEXEXEC\ features that has been moved to \MKIV.
17 18
% begin help
19
%
20
% usage: context --extra=copy [options] list-of-files
21
%
22
% --interaction : add hyperlinks
23
%
24
% end help
25 26
\input
mtx
-
context
-
common
.
tex
27 28
\doif
{
\getdocumentargument
{
interaction
}}
{
yes
}
{
29
\setupinteraction
30
[
state
=
start
]
31
\setupexternalfigures
32
[
interaction
=
yes
]
33
}
34 35
\setupexternalfigures
36
[
directory
=]
37 38
\definepapersize
39
[
fit
]
40
[
width
=
\figurewidth
,
41
height
=
\figureheight
]
42 43
\setuplayout
44
[
page
]
45 46
% this will be an option to \copypages
47 48
\unexpanded
\def
\CopyPages
[#
1
]
%
49
{
\dorecurse
50
{
\noffigurepages
}
51
{
\startTEXpage
52
\externalfigure
[#
1
][
page
=
\recurselevel
]
%
53
\stopTEXpage
}}
54 55
\starttext
56 57
\startluacode
58 59
local
find
=
string
.
find
60 61
if
#
document
.
files
=
=
0
then
62
context
(
"
no files given
"
)
63
else
64
if
document
.
arguments
.
pattern
then
65
document
.
files
=
dir
.
glob
(
document
.
arguments
.
pattern
)
66
end
67
for
i
=
1
,
#
document
.
files
do
68
local
filename
=
document
.
files
[
i
]
69
if
not
find
(
filename
,
"
^mtx%-context%-
"
)
and
not
find
(
filename
,
"
^context%-extra
"
)
then
70
logs
.
report
(
"
copy
"
,
filename
)
71
context
.
getfiguredimensions
72
{
filename
}
73
context
.
setuppapersize
74
{
"
fit
"
}
75
context
.
CopyPages
76
{
filename
}
77
end
78
end
79
end
80 81
\stopluacode
82 83
\stoptext
84 85 86
% def copyoutput
87
% copyortrim(false,'copy')
88
% end
89 90
% def trimoutput
91
% copyortrim(true,'trim')
92
% end
93 94
% def copyortrim(trim=false,what='unknown')
95
% if job = TEX.new(logger) then
96
% prepare(job)
97
% job.cleanuptemprunfiles
98
% files = if @commandline.option('sort') then @commandline.arguments.sort else @commandline.arguments end
99
% if files.length > 0 then
100
% if f = File.open(job.tempfilename('tex'),'w') then
101
% scale = @commandline.checkedoption('scale')
102
% begin
103
% scale = (scale.to_f * 1000.0).to_i if scale.to_i < 10
104
% rescue
105
% scale = 1000
106
% end
107
% scale = scale.to_i
108
% paperoffset = @commandline.checkedoption('paperoffset', '0cm')
109
% f << "\\starttext\n"
110
% files.each do |filename|
111
% result = @commandline.checkedoption('result','texexec')
112
% begin
113
% if (filename !~ /^texexec/io) && (filename !~ /^#{result}/) then
114
% report("copying file: #{filename}")
115
% f << "\\getfiguredimensions\n"
116
% f << " [#{filename}]\n"
117
% f << " [scale=#{scale},\n"
118
% f << " page=1,\n"
119
% f << " size=trimbox\n" if trim
120
% f << "]\n"
121
% f << "\\definepapersize\n"
122
% f << " [copy]\n"
123
% f << " [width=\\figurewidth,\n"
124
% f << " height=\\figureheight]\n"
125
% f << "\\setuppapersize\n"
126
% f << " [copy][copy]\n"
127
% f << "\\setuplayout\n"
128
% f << " [page]\n"
129
% f << "\\setupexternalfigures\n"
130
% f << " [directory=]\n"
131
% f << "\\copypages\n"
132
% f << " [#{filename}]\n"
133
% f << " [scale=#{scale},\n"
134
% f << " marking=on,\n" if @commandline.option('markings')
135
% f << " size=trimbox,\n" if trim
136
% f << " offset=#{paperoffset}]\n"
137
% end
138
% rescue
139
% report("wrong specification")
140
% end
141
% end
142
% f << "\\stoptext\n"
143
% f.close
144
% job.setvariable('interface','english')
145
% job.setvariable('simplerun',true)
146
% # job.setvariable('nooptionfile',true)
147
% job.setvariable('files',[job.tempfilename])
148
% job.processtex
149
% else
150
% report("no files to #{what}")
151
% end
152
% else
153
% report("no files to #{what}")
154
% end
155
% job.cleanuptemprunfiles
156
% end
157
% end
158