2019-07-17 21:14:34 +02:00
|
|
|
do
|
2020-05-26 19:29:58 +02:00
|
|
|
local ourpath = arg[0]:match('^%-%-lua=(.*)luametalatex%-init%.lua$')
|
|
|
|
kpse = assert(package.loadlib(ourpath .. 'kpse.so', 'luaopen_kpse'))()
|
2019-07-17 21:14:34 +02:00
|
|
|
end
|
2019-07-18 20:02:58 +02:00
|
|
|
do
|
2020-05-26 19:29:58 +02:00
|
|
|
local arg0, progname
|
|
|
|
for _, a in ipairs(arg) do
|
|
|
|
if a:sub(1,11) == "--progname=" then
|
|
|
|
progname = a:sub(12)
|
|
|
|
elseif a:sub(1,7) == "--arg0=" then
|
|
|
|
arg0 = a:sub(8)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
kpse.set_program_name(arg0, progname)
|
2019-07-18 20:02:58 +02:00
|
|
|
end
|
2019-07-17 21:14:34 +02:00
|
|
|
package.searchers[2] = function(modname)
|
2020-05-26 19:29:58 +02:00
|
|
|
local filename = kpse.find_file(modname, "lua", true)
|
2019-07-17 21:14:34 +02:00
|
|
|
if not filename then
|
|
|
|
return string.format("\n\tno file located through kpse for %s", modname)
|
|
|
|
end
|
|
|
|
local mod, msg = loadfile(filename)
|
|
|
|
if msg then
|
|
|
|
error(string.format("error loading module '%s' from file '%s':\n\t%s", modname, filename, msg))
|
|
|
|
end
|
|
|
|
return mod, filename
|
|
|
|
end
|
2020-05-26 19:29:58 +02:00
|
|
|
-- kpse.set_maketex("kpse_fmt_format", true)
|
2019-07-17 21:14:34 +02:00
|
|
|
bit32 = require'luametalatex-bit32'
|
|
|
|
kpse.init_prog("LUATEX", 400, "nexthi", nil)
|
|
|
|
status.init_kpse = 1
|
2019-07-20 16:39:34 +02:00
|
|
|
require'luametalatex-init-config'
|
2019-07-17 21:14:34 +02:00
|
|
|
status.safer_option = 0
|
2020-05-28 14:37:19 +02:00
|
|
|
status.shell_escape = 0
|
2019-07-17 21:14:34 +02:00
|
|
|
local read_tfm = require'luametalatex-font-tfm'
|
2020-01-02 04:14:39 +01:00
|
|
|
local read_vf = require'luametalatex-font-vf'
|
2019-07-17 21:14:34 +02:00
|
|
|
font.read_tfm = read_tfm
|
|
|
|
font.read_vf = read_vf
|
2020-01-02 04:14:39 +01:00
|
|
|
require'module'
|
2019-07-17 21:14:34 +02:00
|
|
|
font.fonts = {}
|
|
|
|
function font.getfont(id)
|
|
|
|
return font.fonts[id]
|
|
|
|
end
|
|
|
|
pdf = {
|
|
|
|
getfontname = function(id) -- No font sharing
|
|
|
|
return id
|
|
|
|
end,
|
|
|
|
}
|
2020-01-02 04:14:39 +01:00
|
|
|
local olddefinefont = font.define
|
|
|
|
function font.define(f)
|
|
|
|
local i = olddefinefont(f)
|
|
|
|
font.fonts[i] = f
|
|
|
|
return i
|
|
|
|
end
|
2019-07-17 21:14:34 +02:00
|
|
|
callback.register('define_font', function(name, size)
|
2020-01-02 04:14:39 +01:00
|
|
|
local f = read_tfm(name, size)
|
|
|
|
local id = font.define(f)
|
2019-07-17 21:14:34 +02:00
|
|
|
if status.ini_version then
|
2020-01-02 04:14:39 +01:00
|
|
|
lua.prepared_code[#lua.prepared_code+1] = string.format("assert(%i == font.define(font.read_tfm(%q, %i)))", id, name, size)
|
2019-07-17 21:14:34 +02:00
|
|
|
end
|
2020-01-02 04:14:39 +01:00
|
|
|
return id
|
2019-07-17 21:14:34 +02:00
|
|
|
end)
|
|
|
|
callback.register('find_log_file', function(name) return name end)
|
2020-05-26 19:29:58 +02:00
|
|
|
-- callback.register('find_read_file', function(i, name) return kpse.find_file(name, 'tex', true) end)
|
|
|
|
callback.register('find_data_file', function(name, ...) return kpse.find_file(name, 'tex', true) end)
|
|
|
|
callback.register('read_data_file', function(name) error[[TODO]]return kpse.find_file(name, 'tex', true) end)
|
|
|
|
-- local file_meta = {\
|
|
|
|
callback.register('open_data_file', function(name)
|
|
|
|
local f = io.open(name)
|
|
|
|
return setmetatable({
|
|
|
|
reader = function() return f:read() end,
|
|
|
|
close = function()error[[1]] return f:close() end,
|
|
|
|
}, {
|
|
|
|
__gc = function()f:close()end,
|
|
|
|
})
|
|
|
|
end)
|
|
|
|
callback.register('find_format_file', function(name) return kpse.find_file(name, 'fmt', true) end)
|
2020-05-31 09:30:49 +02:00
|
|
|
callback.register('handle_error_hook', function()
|
|
|
|
repeat
|
|
|
|
texio.write_nl'? '
|
|
|
|
local line = io.read()
|
|
|
|
if not line then
|
|
|
|
error[[TODO: Handle EOL]]
|
|
|
|
end
|
|
|
|
if line == "" then return 3 end
|
|
|
|
local first = line:sub(1,1):upper()
|
|
|
|
if first == 'H' then
|
|
|
|
texio.write(tex.gethelptext())
|
|
|
|
elseif first == 'I' then
|
|
|
|
line = line:sub(2)
|
|
|
|
tex.runtoks(function()
|
|
|
|
tex.sprint(token.scan_token(), line)
|
|
|
|
end)
|
|
|
|
return 3
|
|
|
|
elseif first == 'Q' then texio.write'OK, entering \\batchmode...\n' return 0
|
|
|
|
elseif first == 'R' then texio.write'OK, entering \\nonstopmode...\n' return 1
|
|
|
|
elseif first == 'S' then texio.write'OK, entering \\scrollmode...\n' return 2
|
|
|
|
elseif first == 'X' then return -1
|
|
|
|
else
|
|
|
|
texio.write'Type <return> to proceed, S to scroll future error messages,\
|
|
|
|
\z R to run without stopping, Q to run quietly,\
|
|
|
|
\z I to insert something,\
|
|
|
|
\z H for help, X to quit.'
|
|
|
|
end
|
|
|
|
until false
|
|
|
|
-- print('handle')
|
|
|
|
return 3
|
2019-07-17 21:14:34 +02:00
|
|
|
end)
|
|
|
|
callback.register('pre_dump', function()
|
2020-05-28 14:37:19 +02:00
|
|
|
lua.prepared_code[1] = string.format("fixupluafunctions(%i)", fixupluafunctions())
|
2020-01-02 04:14:39 +01:00
|
|
|
lua.bytecode[1] = assert(load(table.concat(lua.prepared_code, ' ')))
|
2019-07-17 21:14:34 +02:00
|
|
|
end)
|
2020-05-26 19:29:58 +02:00
|
|
|
function texconfig.init()
|
2020-05-28 14:37:19 +02:00
|
|
|
lua.bytecode[2]()
|
2020-05-26 19:29:58 +02:00
|
|
|
if not status.ini_version then
|
|
|
|
lua.bytecode[2] = nil
|
|
|
|
end
|
|
|
|
end
|
2019-07-17 21:14:34 +02:00
|
|
|
if status.ini_version then
|
2020-05-28 14:37:19 +02:00
|
|
|
lua.prepared_code = {false}
|
2019-07-17 21:14:34 +02:00
|
|
|
local code = package.searchers[2]('luametalatex-firstcode')
|
|
|
|
if type(code) == "string" then error(string.format("Initialization code not found %s", code)) end
|
|
|
|
lua.bytecode[2] = code
|
|
|
|
end
|