diff options
Diffstat (limited to 'Master/texmf-dist/doc/support/cluttex/src/cluttex.lua')
-rw-r--r-- | Master/texmf-dist/doc/support/cluttex/src/cluttex.lua | 200 |
1 files changed, 130 insertions, 70 deletions
diff --git a/Master/texmf-dist/doc/support/cluttex/src/cluttex.lua b/Master/texmf-dist/doc/support/cluttex/src/cluttex.lua index 92952af58df..0ac50f90f77 100644 --- a/Master/texmf-dist/doc/support/cluttex/src/cluttex.lua +++ b/Master/texmf-dist/doc/support/cluttex/src/cluttex.lua @@ -18,7 +18,7 @@ along with ClutTeX. If not, see <http://www.gnu.org/licenses/>. ]] -CLUTTEX_VERSION = "v0.3" +CLUTTEX_VERSION = "v0.4" -- Standard libraries local table = table @@ -42,6 +42,7 @@ local reruncheck = require "texrunner.reruncheck" local luatexinit = require "texrunner.luatexinit" local recoverylib = require "texrunner.recovery" local message = require "texrunner.message" +local safename = require "texrunner.safename" local extract_bibtex_from_aux_file = require "texrunner.auxfile".extract_bibtex_from_aux_file local handle_cluttex_options = require "texrunner.handleoption".handle_cluttex_options @@ -62,7 +63,15 @@ end local inputfile, engine, options = handle_cluttex_options(arg) -local jobname = options.jobname or pathutil.basename(pathutil.trimext(inputfile)) +local jobname_for_output +if options.jobname == nil then + local basename = pathutil.basename(pathutil.trimext(inputfile)) + options.jobname = safename.escapejobname(basename) + jobname_for_output = basename +else + jobname_for_output = options.jobname +end +local jobname = options.jobname assert(jobname ~= "", "jobname cannot be empty") if options.output_format == nil then @@ -76,13 +85,13 @@ else end if options.output == nil then - options.output = jobname .. "." .. output_extension + options.output = jobname_for_output .. "." .. output_extension end -- Prepare output directory if options.output_directory == nil then local inputfile_abs = pathutil.abspath(inputfile) - options.output_directory = genOutputDirectory(inputfile_abs, jobname, options.engine) + options.output_directory = genOutputDirectory(inputfile_abs, jobname, options.engine_executable or options.engine) if not fsutil.isdir(options.output_directory) then assert(fsutil.mkdir_rec(options.output_directory)) @@ -102,6 +111,12 @@ elseif options.fresh then os.exit(1) end +-- --print-output-directory +if options.print_output_directory then + io.write(options.output_directory, "\n") + os.exit(0) +end + local pathsep = ":" if os.type == "windows" then pathsep = ";" @@ -140,6 +155,7 @@ local recorderfile = path_in_output_directory("fls") local recorderfile2 = path_in_output_directory("cluttex-fls") local tex_options = { + engine_executable = options.engine_executable, interaction = options.interaction, file_line_error = options.file_line_error, halt_on_error = options.halt_on_error, @@ -166,7 +182,7 @@ end -- should_rerun, newauxstatus = single_run([auxstatus]) -- This function should be run in a coroutine. local function single_run(auxstatus, iteration) - local minted = false + local minted, epstopdf = false, false local bibtex_aux_hash = nil local mainauxfile = path_in_output_directory("aux") if fsutil.isfile(recorderfile) then @@ -179,7 +195,9 @@ local function single_run(auxstatus, iteration) for _,fileinfo in ipairs(filelist) do if string.match(fileinfo.path, "minted/minted%.sty$") then minted = true - break + end + if string.match(fileinfo.path, "epstopdf%.sty$") then + epstopdf = true end end if options.bibtex then @@ -198,14 +216,38 @@ local function single_run(auxstatus, iteration) end --local timestamp = os.time() + local tex_injection = "" + if options.includeonly then - tex_options.tex_injection = string.format("%s\\includeonly{%s}", tex_options.tex_injection or "", options.includeonly) + tex_injection = string.format("%s\\includeonly{%s}", tex_options.tex_injection or "", options.includeonly) end - if minted and not (tex_options.tex_injection and string.find(tex_options.tex_injection,"minted") == nil) then - tex_options.tex_injection = string.format("%s\\PassOptionsToPackage{outputdir=%s}{minted}", tex_options.tex_injection or "", options.output_directory) + if minted or options.package_support["minted"] then + local outdir = options.output_directory + if os.type == "windows" then + outdir = string.gsub(outdir, "\\", "/") -- Use forward slashes + end + tex_injection = string.format("%s\\PassOptionsToPackage{outputdir=%s}{minted}", tex_injection or "", outdir) + if not options.package_support["minted"] then + message.diag("You may want to use --package-support=minted option.") + end + end + if epstopdf or options.package_support["epstopdf"] then + local outdir = options.output_directory + if os.type == "windows" then + outdir = string.gsub(outdir, "\\", "/") -- Use forward slashes + end + if string.sub(outdir, -1, -1) ~= "/" then + outdir = outdir.."/" -- Must end with a directory separator + end + tex_injection = string.format("%s\\PassOptionsToPackage{outdir=%s}{epstopdf}", tex_injection or "", outdir) + if not options.package_support["epstopdf"] then + message.diag("You may want to use --package-support=epstopdf option.") + end end + local inputline = tex_injection .. safename.safeinput(inputfile, engine) + local current_tex_options, lightweight_mode = tex_options, false if iteration == 1 and options.start_with_draft then current_tex_options = {} @@ -222,7 +264,7 @@ local function single_run(auxstatus, iteration) current_tex_options.draftmode = false end - local command = engine:build_command(inputfile, current_tex_options) + local command = engine:build_command(inputline, current_tex_options) local execlog -- the contents of .log file @@ -492,18 +534,7 @@ end if options.watch then -- Watch mode - local success, status = do_typeset() - -- TODO: filenames here can be UTF-8 if command_line_encoding=utf-8 - local filelist, filemap = reruncheck.parse_recorder_file(recorderfile, options) - if engine.is_luatex and fsutil.isfile(recorderfile2) then - filelist, filemap = reruncheck.parse_recorder_file(recorderfile2, options, filelist, filemap) - end - local input_files_to_watch = {} - for _,fileinfo in ipairs(filelist) do - if fileinfo.kind == "input" then - table.insert(input_files_to_watch, fileinfo.abspath) - end - end + local fswatcherlib if os.type == "windows" then -- Windows: Try built-in filesystem watcher @@ -513,73 +544,71 @@ if options.watch then end fswatcherlib = result end + + local do_watch if fswatcherlib then if CLUTTEX_VERBOSITY >= 2 then message.info("Using built-in filesystem watcher for Windows") end - local watcher = assert(fswatcherlib.new()) - for _,path in ipairs(input_files_to_watch) do - assert(watcher:add_file(path)) - end - while true do + do_watch = function(files) + local watcher = assert(fswatcherlib.new()) + for _,path in ipairs(files) do + assert(watcher:add_file(path)) + end local result = assert(watcher:next()) if CLUTTEX_VERBOSITY >= 2 then - message.info(string.format("%s %s"), result.action, result.path) - end - local success, status = do_typeset() - if not success then - -- Not successful + message.info(string.format("%s %s", result.action, result.path)) end + watcher:close() + return true end elseif shellutil.has_command("fswatch") then - local fswatch_command = {"fswatch", "--event=Updated", "--"} - for _,path in ipairs(input_files_to_watch) do - table.insert(fswatch_command, shellutil.escape(path)) + if CLUTTEX_VERBOSITY >= 2 then + message.info("Using `fswatch' command") end - local fswatch_command_str = table.concat(fswatch_command, " ") - if CLUTTEX_VERBOSITY >= 1 then - message.exec(fswatch_command_str) - end - local fswatch = assert(io.popen(fswatch_command_str, "r")) - for l in fswatch:lines() do - local found = false - for _,path in ipairs(input_files_to_watch) do - if l == path then - found = true - break - end + do_watch = function(files) + local fswatch_command = {"fswatch", "--one-event", "--event=Updated", "--"} + for _,path in ipairs(files) do + table.insert(fswatch_command, shellutil.escape(path)) + end + local fswatch_command_str = table.concat(fswatch_command, " ") + if CLUTTEX_VERBOSITY >= 1 then + message.exec(fswatch_command_str) end - if found then - local success, status = do_typeset() - if not success then - -- Not successful + local fswatch = assert(io.popen(fswatch_command_str, "r")) + for l in fswatch:lines() do + for _,path in ipairs(files) do + if l == path then + fswatch:close() + return true + end end end + return false end elseif shellutil.has_command("inotifywait") then - local inotifywait_command = {"inotifywait", "--monitor", "--event=modify", "--event=attrib", "--format=%w", "--quiet"} - for _,path in ipairs(input_files_to_watch) do - table.insert(inotifywait_command, shellutil.escape(path)) + if CLUTTEX_VERBOSITY >= 2 then + message.info("Using `inotifywait' command") end - local inotifywait_command_str = table.concat(inotifywait_command, " ") - if CLUTTEX_VERBOSITY >= 1 then - message.exec(inotifywait_command_str) - end - local inotifywait = assert(io.popen(inotifywait_command_str, "r")) - for l in inotifywait:lines() do - local found = false - for _,path in ipairs(input_files_to_watch) do - if l == path then - found = true - break - end + do_watch = function(files) + local inotifywait_command = {"inotifywait", "--event=modify", "--event=attrib", "--format=%w", "--quiet"} + for _,path in ipairs(files) do + table.insert(inotifywait_command, shellutil.escape(path)) + end + local inotifywait_command_str = table.concat(inotifywait_command, " ") + if CLUTTEX_VERBOSITY >= 1 then + message.exec(inotifywait_command_str) end - if found then - local success, status = do_typeset() - if not success then - -- Not successful + local inotifywait = assert(io.popen(inotifywait_command_str, "r")) + for l in inotifywait:lines() do + for _,path in ipairs(files) do + if l == path then + inotifywait:close() + return true + end end end + return false end else message.error("Could not watch files because neither `fswatch' nor `inotifywait' was installed.") @@ -587,6 +616,37 @@ if options.watch then os.exit(1) end + local success, status = do_typeset() + -- TODO: filenames here can be UTF-8 if command_line_encoding=utf-8 + local filelist, filemap = reruncheck.parse_recorder_file(recorderfile, options) + if engine.is_luatex and fsutil.isfile(recorderfile2) then + filelist, filemap = reruncheck.parse_recorder_file(recorderfile2, options, filelist, filemap) + end + local input_files_to_watch = {} + for _,fileinfo in ipairs(filelist) do + if fileinfo.kind == "input" then + table.insert(input_files_to_watch, fileinfo.abspath) + end + end + + while do_watch(input_files_to_watch) do + local success, status = do_typeset() + if not success then + -- error + else + local filelist, filemap = reruncheck.parse_recorder_file(recorderfile, options) + if engine.is_luatex and fsutil.isfile(recorderfile2) then + filelist, filemap = reruncheck.parse_recorder_file(recorderfile2, options, filelist, filemap) + end + input_files_to_watch = {} + for _,fileinfo in ipairs(filelist) do + if fileinfo.kind == "input" then + table.insert(input_files_to_watch, fileinfo.abspath) + end + end + end + end + else -- Not in watch mode local success, status = do_typeset() |