1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22\input mtxcontextcommon.tex
23
24\starttext
25
26\starttexdefinition unexpanded ShowBoth #1#2#3
27 \startTEXpage[width=21cm]
28 \startoverlay
29 {\externalfigure[#1][page=#3,width=21cm]}
30 {\externalfigure[#2][page=#3,width=21cm]}
31 \stopoverlay
32 \stopTEXpage
33\stoptexdefinition
34
35\starttexdefinition unexpanded ShowPage #1#2
36 \startTEXpage[width=21cm]
37 \externalfigure[#1][page=#2,width=21cm]
38 \stopTEXpage
39\stoptexdefinition
40
41\startluacode
42
43local report = logs.reporter("compare")
44
45local fileone = document.files[1] or ""
46local filetwo = document.files[2] or ""
47
48if fileone == "" or filetwo == "" then
49 report("provide two filenames")
50 os.exit()
51end
52
53if not lfs.isfile(fileone) then
54 report("unknown file %a",fileone)
55 os.exit()
56end
57
58if not lfs.isfile(filetwo) then
59 report("unknown file %a",filetwo)
60 os.exit()
61end
62
63local function check(name)
64 local fig = figures.push { name = name }
65 figures.identify()
66 figures.check()
67 local used = fig.used
68 figures.pop()
69 return used
70end
71
72local one = check(fileone)
73local two = check(filetwo)
74
75if not one then
76 report("invalid file %a",fileone)
77 os.exit()
78end
79
80if not two then
81 report("invalid file %a",filetwo)
82 os.exit()
83end
84
85local n_one = tonumber(one.pages)
86local n_two = tonumber(two.pages)
87
88if not n_one or n_one ~= n_two then
89 report("files have different nofpages (%s vs %s)",n_one or "?",n_two or "?")
90end
91
92if n_one > n_two then
93 for i=1,n_two do
94 context.ShowBoth(fileone,filetwo,i)
95 end
96 for i=n_two+1,n_one do
97 context.ShowPage(fileone,i)
98 end
99else
100 for i=1,n_one do
101 context.ShowBoth(fileone,filetwo,i)
102 end
103 for i=n_one+1,n_two do
104 context.ShowPage(filetwo,i)
105 end
106end
107
108\stopluacode
109
110\stoptext
111
112\endinput
113 |