2019-07-17 21:14:34 +02:00
|
|
|
do
|
2020-06-11 01:16:42 +02:00
|
|
|
local ourpath = arg[0]:match('^%-%-lua=(.*[/\\])[^/\\]*%.lua$')
|
2020-05-26 19:29:58 +02:00
|
|
|
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-06-11 01:16:42 +02:00
|
|
|
local callback_register = callback.register
|
2020-01-02 04:14:39 +01:00
|
|
|
require'module'
|
2019-07-17 21:14:34 +02:00
|
|
|
pdf = {
|
|
|
|
getfontname = function(id) -- No font sharing
|
|
|
|
return id
|
|
|
|
end,
|
2020-06-13 14:34:53 +02:00
|
|
|
variable = {},
|
2019-07-17 21:14:34 +02:00
|
|
|
}
|
2020-06-19 16:33:48 +02:00
|
|
|
require'luametalatex-font-resolve' -- Replace font.define
|
|
|
|
|
2020-06-18 01:38:20 +02:00
|
|
|
local function base_define_font_cb(name, size)
|
2020-01-02 04:14:39 +01:00
|
|
|
local f = read_tfm(name, size)
|
2020-06-18 01:38:20 +02:00
|
|
|
if not f then return end
|
2020-01-02 04:14:39 +01:00
|
|
|
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
|
2020-06-18 01:38:20 +02:00
|
|
|
end
|
|
|
|
callback_register('define_font', base_define_font_cb)
|
2020-06-11 01:16:42 +02:00
|
|
|
callback_register('find_log_file', function(name) return name end)
|
|
|
|
do
|
|
|
|
local function normal_find_data_file(name)
|
|
|
|
return kpse.find_file(name, 'tex', true)
|
|
|
|
end
|
|
|
|
if status.ini_version then
|
2020-06-16 21:14:52 +02:00
|
|
|
function unhook_expl()
|
|
|
|
callback_register('find_data_file', normal_find_data_file)
|
|
|
|
end
|
2020-06-11 01:16:42 +02:00
|
|
|
callback_register('find_data_file', function(name)
|
|
|
|
if name == 'ltexpl.ltx' then
|
|
|
|
name = 'luametalatex-ltexpl-hook'
|
|
|
|
end
|
|
|
|
return normal_find_data_file(name)
|
|
|
|
end)
|
|
|
|
else
|
|
|
|
callback_register('find_data_file', normal_find_data_file)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
callback_register('read_data_file', function(name) error[[TODO]]return kpse.find_file(name, 'tex', true) end)
|
|
|
|
callback_register('open_data_file', function(name)
|
2020-05-26 19:29:58 +02:00
|
|
|
local f = io.open(name)
|
|
|
|
return setmetatable({
|
2020-06-12 21:52:35 +02:00
|
|
|
reader = function()
|
|
|
|
local line = f:read()
|
2020-06-15 07:01:40 +02:00
|
|
|
return line
|
2020-06-12 21:52:35 +02:00
|
|
|
end,
|
2020-05-26 19:29:58 +02:00
|
|
|
close = function()error[[1]] return f:close() end,
|
|
|
|
}, {
|
|
|
|
__gc = function()f:close()end,
|
|
|
|
})
|
|
|
|
end)
|
2020-06-11 01:16:42 +02:00
|
|
|
callback_register('find_format_file', function(name) return kpse.find_file(name, 'fmt', true) end)
|
|
|
|
callback_register('handle_error_hook', function()
|
2020-05-31 09:30:49 +02:00
|
|
|
repeat
|
|
|
|
texio.write_nl'? '
|
|
|
|
local line = io.read()
|
|
|
|
if not line then
|
2020-06-11 01:16:42 +02:00
|
|
|
tex.fatalerror'End of line encountered on terminal'
|
2020-05-31 09:30:49 +02:00
|
|
|
end
|
|
|
|
if line == "" then return 3 end
|
|
|
|
local first = line:sub(1,1):upper()
|
|
|
|
if first == 'H' then
|
2020-07-01 19:47:25 +02:00
|
|
|
texio.write(tex.gethelptext() or "Sorry, I don't know how to help in this situation.\n\z
|
|
|
|
Maybe you should try asking a human?")
|
2020-05-31 09:30:49 +02:00
|
|
|
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
|
|
|
|
return 3
|
2019-07-17 21:14:34 +02:00
|
|
|
end)
|
2020-06-11 01:16:42 +02:00
|
|
|
callback_register('pre_dump', function()
|
2020-06-30 15:14:24 +02:00
|
|
|
local prepared = lua.prepared_code
|
|
|
|
prepared[1] = string.format("fixupluafunctions(%i)", fixupluafunctions())
|
2020-06-15 07:02:06 +02:00
|
|
|
for i=0,0 do -- maybeFIXME: In practise only one language is preloaded in LuaTeX anyway
|
|
|
|
-- for i=0,tex.count[19] do -- Sometimes catches reserved language ids which are not used yet
|
|
|
|
-- for i=0,lang.new():id()-1 do -- lang.new():id() is always 0 in luametatex?!?
|
|
|
|
local l = lang.new(i)
|
|
|
|
local str = string.format("do \z
|
|
|
|
local l = lang.new(%i)\z
|
|
|
|
l:hyphenationmin(%i)\z
|
|
|
|
l:prehyphenchar(%i)\z
|
|
|
|
l:posthyphenchar(%i)\z
|
|
|
|
l:preexhyphenchar(%i)\z
|
|
|
|
l:postexhyphenchar(%i)",
|
|
|
|
i,
|
|
|
|
l:hyphenationmin(),
|
|
|
|
l:prehyphenchar(),
|
|
|
|
l:posthyphenchar(),
|
|
|
|
l:preexhyphenchar(),
|
|
|
|
l:postexhyphenchar())
|
|
|
|
local patterns = l:patterns()
|
|
|
|
local exceptions = l:hyphenation()
|
|
|
|
if patterns and exceptions then
|
|
|
|
str = string.format("%sl:patterns(%q)l:hyphenation(%q)end", str, patterns, exceptions)
|
|
|
|
elseif patterns then
|
|
|
|
str = string.format("%sl:patterns(%q)end", str, patterns)
|
|
|
|
elseif exceptions then
|
|
|
|
str = string.format("%sl:hyphenation(%q)end", str, exceptions)
|
|
|
|
else
|
|
|
|
str = str .. 'end'
|
|
|
|
end
|
2020-06-30 15:14:24 +02:00
|
|
|
prepared[#prepared+1] = str
|
2020-06-15 07:02:06 +02:00
|
|
|
end
|
2020-06-30 15:14:24 +02:00
|
|
|
for i=2,#prepared do
|
|
|
|
if type(prepared[i]) ~= 'string' then
|
|
|
|
prepared[i] = assert(prepared[i]())
|
|
|
|
end
|
|
|
|
end
|
|
|
|
lua.bytecode[1] = assert(load(table.concat(prepared, ' ')))
|
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
|