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
|
#!/usr/bin/env texlua
VERSION = "0.2"
--[[
musixtex.lua: runs [pdf]etex -> musixflx -> [pdfe]tex [ -> dvips -> ps2pdf ]
(c) Copyright 2011 Bob Tennent rdt@cs.queensu.ca
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
--]]
--[[
ChangeLog:
version 0.2 2011-04-21 RDT
Allow basename.tex as filename.
Add -p option for pdfetex processing.
Add standard -v -h options.
--]]
tex = "etex"
musixflx = "musixflx"
dvips = "dvips -q"
ps2pdf = "ps2pdf"
function usage()
print("Usage: [texlua] musixtex.lua [options] basename[.tex]")
end
function whoami ()
print("This is musixtex.lua version ".. VERSION .. ".")
end
if #arg == 0 then
usage()
os.exit(1)
end
narg = 1
if arg[narg] == "-v" then
whoami()
os.exit(0)
elseif arg[narg] == "-h" then
usage()
os.exit(0)
end
while narg ~= #arg do
if arg[narg] == "-p" then
tex = "pdfetex"
else
print("Argument \"".. arg[narg] .. "\" ignored.")
end
narg = narg+1
end
filename = arg[narg]
if not filename then
usage()
os.exit(1)
end
extension = string.sub(filename, -4, -1)
if extension == ".tex" then
basename = string.sub(filename, 1, -5)
else
basename = filename
end
if not io.open(basename .. ".tex", "r") then
print("Non-existent file: ", basename .. ".tex")
os.exit(2)
end
whoami()
print("Processing ".. basename .. ".tex")
os.remove( basename .. ".mx2" )
if
(os.execute(tex .. " " .. basename) == 0)
and (os.execute(musixflx .. " " .. basename) == 0)
and (os.execute(tex .. " " .. basename) == 0)
and (tex == "pdfetex" or (os.execute(dvips .. " -o " .. basename ..".ps " .. basename) == 0) )
and (tex == "pdfetex" or (os.execute(ps2pdf .. " " .. basename .. ".ps " .. basename .. ".pdf") == 0) )
then
print(basename .. ".pdf generated.")
exit_code = 0
else
print("musixtex processing fails.")
exit_code = 3
end
os.remove( basename .. ".mx1" )
os.remove( basename .. ".mx2" )
os.remove( basename .. ".dvi" )
os.remove( basename .. ".ps" )
os.exit( exit_code )
|