First attempt for --output-directory implementation
This commit is contained in:
parent
ae36af4134
commit
24765e80eb
@ -51,10 +51,15 @@ local colorstacks = {{
|
||||
page_stack = {"0 g 0 G"},
|
||||
}}
|
||||
local spacer_cmd = token.command_id'spacer'
|
||||
local output_directory = arg['output-directory']
|
||||
local dir_sep = '/' -- FIXME
|
||||
local function get_pfile()
|
||||
if not pfile then
|
||||
pdfname = tex.jobname .. '.pdf'
|
||||
pfile = newpdf.open(tex.jobname .. '.pdf')
|
||||
if output_directory then
|
||||
pdfname = output_directory .. dir_sep .. pdfname
|
||||
end
|
||||
pfile = newpdf.open(pdfname)
|
||||
end
|
||||
return pfile
|
||||
end
|
||||
|
@ -4,6 +4,27 @@ local read_tfm = font.read_tfm
|
||||
local font_define = font.define
|
||||
local callbacks = require'luametalatex-callbacks'
|
||||
|
||||
local find_file = kpse.find_file
|
||||
local output_directory = arg['output-directory']
|
||||
|
||||
local dir_sep = '/' -- FIXME
|
||||
|
||||
if output_directory then
|
||||
local old_find_file = find_file
|
||||
local kpse_absolute = kpse.is_absolute
|
||||
local attributes = lfs.attributes
|
||||
function find_file(path, kind, must_exists)
|
||||
--kind is always "tex"
|
||||
if not kpse_absolute(path) then
|
||||
local new_path = output_directory .. dir_sep .. path
|
||||
if attributes(new_path, 'mode') == 'file' then
|
||||
return new_path
|
||||
end
|
||||
end
|
||||
return old_find_file(path, kind, must_exists)
|
||||
end
|
||||
end
|
||||
|
||||
if status.ini_version then
|
||||
function callbacks.define_font(name, size)
|
||||
local f = read_tfm(name, size)
|
||||
@ -26,7 +47,11 @@ else
|
||||
end
|
||||
callbacks.__freeze'define_font'
|
||||
|
||||
if output_directory then
|
||||
function callbacks.find_log_file(name) return output_directory .. dir_sep .. name end
|
||||
else
|
||||
function callbacks.find_log_file(name) return name end
|
||||
end
|
||||
callbacks.__freeze'find_log_file'
|
||||
|
||||
-- find_data_file is not an engine callback in luametatex, so we don't __freeze it
|
||||
@ -38,11 +63,11 @@ if status.ini_version then
|
||||
if name == 'expl3.ltx' then
|
||||
name = 'luametalatex-ltexpl-hook'
|
||||
end
|
||||
return kpse.find_file(name, 'tex', true)
|
||||
return find_file(name, 'tex', true)
|
||||
end
|
||||
end
|
||||
local function normal_find_data_file(name)
|
||||
return kpse.find_file(name, 'tex', true)
|
||||
return find_file(name, 'tex', true)
|
||||
end
|
||||
function callbacks.open_data_file(name)
|
||||
local find_callback = callbacks.find_data_file
|
||||
@ -50,7 +75,7 @@ function callbacks.open_data_file(name)
|
||||
if find_callback then
|
||||
path = find_callback(name)
|
||||
else
|
||||
path = kpse.find_file(name, 'tex', true)
|
||||
path = find_file(name, 'tex', true)
|
||||
end
|
||||
if not path then return end
|
||||
|
||||
|
@ -55,7 +55,6 @@ do
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local new_whatsit = require'luametalatex-whatsits'.new
|
||||
local whatsit_id = node.id'whatsit'
|
||||
local spacer_cmd, relax_cmd = token.command_id'spacer', token.command_id'relax'
|
||||
@ -98,12 +97,18 @@ local immediate_flag = lmlt.flag.immediate
|
||||
local l = lpeg or require'lpeg'
|
||||
local add_file_extension = l.Cs((1-('.' * (1-l.S'./\\')^0) * -1)^0 * (l.P(1)^1+l.Cc'.tex'))
|
||||
local ofiles, ifiles = {}, {}
|
||||
local output_directory = arg['output-directory']
|
||||
local dir_sep = '/' -- FIXME
|
||||
local function do_openout(p)
|
||||
if ofiles[p.file] then
|
||||
ofiles[p.file]:close()
|
||||
end
|
||||
local msg
|
||||
ofiles[p.file], msg = io.open(add_file_extension:match(p.name), 'w')
|
||||
local name = add_file_extension:match(p.name)
|
||||
if output_directory then
|
||||
name = output_directory .. dir_sep .. name
|
||||
end
|
||||
ofiles[p.file], msg = io.open(name, 'w')
|
||||
if not ofiles[p.file] then
|
||||
error(msg)
|
||||
end
|
||||
|
@ -104,6 +104,7 @@ end
|
||||
|
||||
if initex then
|
||||
local build_bytecode = nil -- To be filled
|
||||
local output_directory = arg['output-directory']
|
||||
function callbacks.pre_dump()
|
||||
local user_callback = callbacks.pre_dump
|
||||
if user_callback then user_callback() end
|
||||
@ -144,6 +145,9 @@ if initex then
|
||||
end
|
||||
end
|
||||
lua.bytecode[tex.count[262]+1] = build_bytecode(table.concat(prepared, '\n'))
|
||||
if output_directory then
|
||||
lfs.chdir(output_directory) -- We can't change the location TeX writes it's format to, so we change the current directory instead
|
||||
end
|
||||
end
|
||||
callbacks.__freeze('pre_dump', true)
|
||||
return function(f)
|
||||
|
BIN
luametalatex.so
BIN
luametalatex.so
Binary file not shown.
Loading…
Reference in New Issue
Block a user