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
|
%D \module
%D [ file=mtx-context-compare,
%D version=2015.07.14,
%D title=\CONTEXT\ Extra Trickry,
%D subtitle=Compare 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.
% begin help
%
% usage: context --extra=compare [options] file-1 file-2
%
% example: context --extra=compare file1.pdf file-2.pdf
%
% end help
\input mtx-context-common.tex
\starttext
\starttexdefinition unexpanded ShowBoth #1#2#3
\startTEXpage[width=21cm]
\startoverlay
{\externalfigure[#1][page=#3,width=21cm]}
{\externalfigure[#2][page=#3,width=21cm]}
\stopoverlay
\stopTEXpage
\stoptexdefinition
\starttexdefinition unexpanded ShowPage #1#2
\startTEXpage[width=21cm]
\externalfigure[#1][page=#2,width=21cm]
\stopTEXpage
\stoptexdefinition
\startluacode
local report = logs.reporter("compare")
local fileone = document.files[1] or ""
local filetwo = document.files[2] or ""
if fileone == "" or filetwo == "" then
report("provide two filenames")
os.exit()
end
if not lfs.isfile(fileone) then
report("unknown file %a",fileone)
os.exit()
end
if not lfs.isfile(filetwo) then
report("unknown file %a",filetwo)
os.exit()
end
local function check(name)
local fig = figures.push { name = name }
figures.identify()
figures.check()
local used = fig.used
figures.pop()
return used
end
local one = check(fileone) -- can crash
local two = check(filetwo) -- can crash
if not one then
report("invalid file %a",fileone)
os.exit()
end
if not two then
report("invalid file %a",filetwo)
os.exit()
end
local n_one = tonumber(one.pages)
local n_two = tonumber(two.pages)
if not n_one or n_one ~= n_two then
report("files have different nofpages (%s vs %s)",n_one or "?",n_two or "?")
end
if n_one > n_two then
for i=1,n_two do
context.ShowBoth(fileone,filetwo,i)
end
for i=n_two+1,n_one do
context.ShowPage(fileone,i)
end
else
for i=1,n_one do
context.ShowBoth(fileone,filetwo,i)
end
for i=n_one+1,n_two do
context.ShowPage(filetwo,i)
end
end
\stopluacode
\stoptext
\endinput
|