summaryrefslogtreecommitdiff
path: root/support/cluttex/src/cluttex.lua
diff options
context:
space:
mode:
Diffstat (limited to 'support/cluttex/src/cluttex.lua')
-rw-r--r--support/cluttex/src/cluttex.lua61
1 files changed, 50 insertions, 11 deletions
diff --git a/support/cluttex/src/cluttex.lua b/support/cluttex/src/cluttex.lua
index d7875c0ab1..065d7fcc54 100644
--- a/support/cluttex/src/cluttex.lua
+++ b/support/cluttex/src/cluttex.lua
@@ -1,6 +1,6 @@
#!/usr/bin/env texlua
--[[
- Copyright 2016-2021 ARATA Mizuki
+ Copyright 2016-2023 ARATA Mizuki
This file is part of ClutTeX.
@@ -18,7 +18,7 @@
along with ClutTeX. If not, see <http://www.gnu.org/licenses/>.
]]
-CLUTTEX_VERSION = "v0.5.1"
+CLUTTEX_VERSION = "v0.6"
-- Standard libraries
local table = table
@@ -123,9 +123,13 @@ end
local original_wd = filesys.currentdir()
if options.change_directory then
local TEXINPUTS = os.getenv("TEXINPUTS") or ""
- filesys.chdir(options.output_directory)
+ local LUAINPUTS = os.getenv("LUAINPUTS") or ""
+ assert(filesys.chdir(options.output_directory))
options.output = pathutil.abspath(options.output, original_wd)
os.setenv("TEXINPUTS", original_wd .. pathsep .. TEXINPUTS)
+ os.setenv("LUAINPUTS", original_wd .. pathsep .. LUAINPUTS)
+ -- after changing the pwd, '.' is always the output_directory (needed for some path generation)
+ options.output_directory = "."
end
if options.bibtex or options.biber then
local BIBINPUTS = os.getenv("BIBINPUTS") or ""
@@ -135,14 +139,15 @@ end
-- Set `max_print_line' environment variable if not already set.
if os.getenv("max_print_line") == nil then
- os.setenv("max_print_line", "65536")
+ os.setenv("max_print_line", "16384")
end
--- TODO: error_line, half_error_line
--[[
According to texmf.cnf:
45 < error_line < 255,
30 < half_error_line < error_line - 15,
60 <= max_print_line.
+
+ On TeX Live 2023, (u)(p)bibtex fails if max_print_line >= 20000.
]]
local function path_in_output_directory(ext)
@@ -176,6 +181,11 @@ if engine.is_luatex then
tex_options.lua_initialization_script = initscriptfile
end
+-- handle change_directory properly (needs to be after initscript gen)
+if options.change_directory then
+ tex_options.output_directory = nil
+end
+
-- Run TeX command (*tex, *latex)
-- should_rerun, newauxstatus = single_run([auxstatus])
-- This function should be run in a coroutine.
@@ -371,7 +381,7 @@ local function single_run(auxstatus, iteration)
bibtex_aux_hash2 = md5.sum(table.concat(biblines2, "\n"))
end
local output_bbl = path_in_output_directory("bbl")
- if bibtex_aux_hash ~= bibtex_aux_hash2 or reruncheck.comparefiletime(mainauxfile, output_bbl, auxstatus) then
+ if bibtex_aux_hash ~= bibtex_aux_hash2 or reruncheck.comparefiletime(pathutil.abspath(mainauxfile), output_bbl, auxstatus) then
-- The input for BibTeX command has changed...
local bibtex_command = {
"cd", shellutil.escape(options.output_directory), "&&",
@@ -390,18 +400,41 @@ local function single_run(auxstatus, iteration)
end
elseif options.biber then
for _,file in ipairs(filelist) do
+ -- usual compilation with biber
+ -- tex -> pdflatex tex -> aux,bcf,pdf,run.xml
+ -- bcf -> biber bcf -> bbl
+ -- tex,bbl -> pdflatex tex -> aux,bcf,pdf,run.xml
if pathutil.ext(file.path) == "bcf" then
-- Run biber if the .bcf file is new or updated
local bcffileinfo = {path = file.path, abspath = file.abspath, kind = "auxiliary"}
local output_bbl = pathutil.replaceext(file.abspath, "bbl")
- if reruncheck.comparefileinfo({bcffileinfo}, auxstatus) or reruncheck.comparefiletime(file.abspath, output_bbl, auxstatus) then
- local bbl_dir = pathutil.dirname(file.abspath)
+ local updated_dot_bib = false
+ -- get the .bib files, the bcf uses as input
+ for l in io.lines(file.abspath) do
+ local bib = l:match("<bcf:datasource .*>(.*)</bcf:datasource>") -- might be unstable if biblatex adds e.g. a linebreak
+ if bib then
+ local bibfile = pathutil.join(original_wd, bib)
+ local succ, err = io.open(bibfile, "r") -- check if file is present, don't use touch to avoid triggering a rerun
+ if succ then
+ succ:close()
+ local updated_dot_bib_tmp = not reruncheck.comparefiletime(pathutil.abspath(mainauxfile), bibfile, auxstatus)
+ if updated_dot_bib_tmp then
+ message.info(bibfile.." is newer than aux")
+ end
+ updated_dot_bib = updated_dot_bib_tmp or updated_dot_bib
+ else
+ message.warn(bibfile .. " is not accessible (" .. err .. ")")
+ end
+ end
+ end
+ if updated_dot_bib or reruncheck.comparefileinfo({bcffileinfo}, auxstatus) or reruncheck.comparefiletime(file.abspath, output_bbl, auxstatus) then
local biber_command = {
options.biber, -- Do not escape options.biber to allow additional options
"--output-directory", shellutil.escape(options.output_directory),
pathutil.basename(file.abspath)
}
coroutine.yield(table.concat(biber_command, " "))
+ -- watch for changes in the bbl
table.insert(filelist, {path = output_bbl, abspath = output_bbl, kind = "auxiliary"})
else
local succ, err = filesys.touch(output_bbl)
@@ -564,7 +597,7 @@ if options.watch then
watcher:close()
return true
end
- elseif shellutil.has_command("fswatch") then
+ elseif shellutil.has_command("fswatch") and (options.watch == "auto" or options.watch == "fswatch") then
if CLUTTEX_VERBOSITY >= 2 then
message.info("Using `fswatch' command")
end
@@ -588,7 +621,7 @@ if options.watch then
end
return false
end
- elseif shellutil.has_command("inotifywait") then
+ elseif shellutil.has_command("inotifywait") and (options.watch == "auto" or options.watch == "inotifywait") then
if CLUTTEX_VERBOSITY >= 2 then
message.info("Using `inotifywait' command")
end
@@ -613,7 +646,13 @@ if options.watch then
return false
end
else
- message.error("Could not watch files because neither `fswatch' nor `inotifywait' was installed.")
+ if options.watch == "auto" then
+ message.error("Could not watch files because neither `fswatch' nor `inotifywait' was installed.")
+ elseif options.watch == "fswatch" then
+ message.error("Could not watch files because your selected engine `fswatch' was not installed.")
+ elseif options.watch == "inotifywait" then
+ message.error("Could not watch files because your selected engine `inotifywait' was not installed.")
+ end
message.info("See ClutTeX's manual for details.")
os.exit(1)
end