texlive[68891] trunk: cluttex (18nov23)

commits+karl at tug.org commits+karl at tug.org
Sat Nov 18 21:55:23 CET 2023


Revision: 68891
          https://tug.org/svn/texlive?view=revision&revision=68891
Author:   karl
Date:     2023-11-18 21:55:22 +0100 (Sat, 18 Nov 2023)
Log Message:
-----------
cluttex (18nov23)

Modified Paths:
--------------
    trunk/Build/source/texk/texlive/linked_scripts/cluttex/cluttex.lua
    trunk/Master/texmf-dist/doc/man/man1/Makefile
    trunk/Master/texmf-dist/doc/support/cluttex/CHANGELOG.md
    trunk/Master/texmf-dist/doc/support/cluttex/Makefile
    trunk/Master/texmf-dist/doc/support/cluttex/README.md
    trunk/Master/texmf-dist/doc/support/cluttex/bin/cluttex.bat
    trunk/Master/texmf-dist/doc/support/cluttex/doc/Makefile
    trunk/Master/texmf-dist/doc/support/cluttex/doc/cluttex-ja.pdf
    trunk/Master/texmf-dist/doc/support/cluttex/doc/cluttex-ja.tex
    trunk/Master/texmf-dist/doc/support/cluttex/doc/cluttex.pdf
    trunk/Master/texmf-dist/doc/support/cluttex/doc/cluttex.tex
    trunk/Master/texmf-dist/doc/support/cluttex/src/cluttex.lua
    trunk/Master/texmf-dist/doc/support/cluttex/src/texrunner/handleoption.lua
    trunk/Master/texmf-dist/doc/support/cluttex/src/texrunner/luatexinit.lua
    trunk/Master/texmf-dist/scripts/cluttex/cluttex.lua
    trunk/Master/tlpkg/libexec/ctan2tds
    trunk/Master/tlpkg/tlpsrc/cluttex.tlpsrc

Added Paths:
-----------
    trunk/Master/texmf-dist/doc/man/man1/cluttex.1
    trunk/Master/texmf-dist/doc/man/man1/cluttex.man1.pdf
    trunk/Master/texmf-dist/doc/support/cluttex/VERSION_0_6

Modified: trunk/Build/source/texk/texlive/linked_scripts/cluttex/cluttex.lua
===================================================================
--- trunk/Build/source/texk/texlive/linked_scripts/cluttex/cluttex.lua	2023-11-18 20:40:31 UTC (rev 68890)
+++ trunk/Build/source/texk/texlive/linked_scripts/cluttex/cluttex.lua	2023-11-18 20:55:22 UTC (rev 68891)
@@ -1272,6 +1272,21 @@
   return texio_write(...)
 end
 ]==])
+
+  -- Fix "arg" to make luamplib work
+  initscript:write([==[
+if string.match(arg[0], "^%-%-lua=") then
+  local minindex = 0
+  while arg[minindex - 1] ~= nil do
+    minindex = minindex - 1
+  end
+  local arg2 = {}
+  for i = 0, #arg - minindex do
+    arg2[i] = arg[i + minindex]
+  end
+  arg = arg2
+end
+]==])
   initscript:close()
 end
 
@@ -1369,7 +1384,7 @@
 end
 package.preload["texrunner.handleoption"] = function(...)
 local COPYRIGHT_NOTICE = [[
-Copyright (C) 2016-2021  ARATA Mizuki
+Copyright (C) 2016-2023  ARATA Mizuki
 
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -1417,8 +1432,9 @@
                                  cross-references.  [default: 3]
       --start-with-draft       Start with draft mode.
       --[no-]change-directory  Change directory before running TeX.
-      --watch                  Watch input files for change.  Requires fswatch
-                                 program to be installed.
+      --watch[=ENGINE]         Watch input files for change.  Requires fswatch
+                                 or inotifywait to be installed. ENGINE is one of
+                                 `fswatch', `inotifywait' or `auto' [default: `auto']
       --tex-option=OPTION      Pass OPTION to TeX as a single option.
       --tex-options=OPTIONs    Pass OPTIONs to TeX as multiple options.
       --dvipdfmx-option[s]=OPTION[s]  Same for dvipdfmx.
@@ -1492,6 +1508,8 @@
   },
   {
     long = "watch",
+    param = true,
+    default = "auto",
   },
   {
     short = "h",
@@ -1682,7 +1700,7 @@
 
     elseif name == "watch" then
       assert(options.watch == nil, "multiple --watch options")
-      options.watch = true
+      options.watch = param
 
     elseif name == "help" then
       usage(arg)
@@ -1840,6 +1858,15 @@
 
   set_default_values(options)
 
+  -- parameter validy check TODO should this be organized as function like
+  -- set_default_values and with a key in the option spec (list or function)?
+  if options.watch then
+	  if options.watch ~= "fswatch" and options.watch ~= "inotifywait" then
+		message.error("Unknown wait engine '", options.watch, "'.")
+		os.exit(1)
+	  end
+  end
+
   if options.output_format == "pdf" then
     if options.check_driver ~= nil then
       error("--check-driver can only be used when the output format is DVI.")
@@ -2933,7 +2960,7 @@
 }
 end
 --[[
-  Copyright 2016-2021 ARATA Mizuki
+  Copyright 2016-2023 ARATA Mizuki
 
   This file is part of ClutTeX.
 
@@ -2951,7 +2978,7 @@
   along with ClutTeX.  If not, see <http://www.gnu.org/licenses/>.
 ]]
 
-CLUTTEX_VERSION = "v0.5.1"
+CLUTTEX_VERSION = "v0.6"
 
 -- Standard libraries
 local coroutine = coroutine
@@ -3051,9 +3078,13 @@
 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 ""
@@ -3063,14 +3094,15 @@
 
 -- 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)
@@ -3104,6 +3136,11 @@
   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.
@@ -3299,7 +3336,7 @@
       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), "&&",
@@ -3318,12 +3355,34 @@
     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),
@@ -3330,6 +3389,7 @@
             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)
@@ -3492,7 +3552,7 @@
       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
@@ -3516,7 +3576,7 @@
       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
@@ -3541,7 +3601,13 @@
       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

Modified: trunk/Master/texmf-dist/doc/man/man1/Makefile
===================================================================
--- trunk/Master/texmf-dist/doc/man/man1/Makefile	2023-11-18 20:40:31 UTC (rev 68890)
+++ trunk/Master/texmf-dist/doc/man/man1/Makefile	2023-11-18 20:55:22 UTC (rev 68891)
@@ -41,9 +41,12 @@
 # See ../Makefile for the so.rules target which generates this list of rules,
 # and tlpkg/bin/tl-update-man for a way to verify the list.
 
-man1/cslatex.man1.pdf: man1/cslatex.1 man1/latex.1
+man1/cllualatex.man1.pdf: man1/cllualatex.1 man1/cluttex.1
 	$(MKPDF)
 
+man1/clxelatex.man1.pdf: man1/clxelatex.1 man1/cluttex.1
+	$(MKPDF)
+
 man1/ctangle.man1.pdf: man1/ctangle.1 man1/cweb.1
 	$(MKPDF)
 
@@ -143,9 +146,6 @@
 man1/pdfclose.man1.pdf: man1/pdfclose.1 man1/pdfopen.1
 	$(MKPDF)
 
-man1/pdfcslatex.man1.pdf: man1/pdfcslatex.1 man1/latex.1
-	$(MKPDF)
-
 man1/pdflatex-dev.man1.pdf: man1/pdflatex-dev.1 man1/latex-dev.1
 	$(MKPDF)
 

Added: trunk/Master/texmf-dist/doc/man/man1/cluttex.1
===================================================================
--- trunk/Master/texmf-dist/doc/man/man1/cluttex.1	                        (rev 0)
+++ trunk/Master/texmf-dist/doc/man/man1/cluttex.1	2023-11-18 20:55:22 UTC (rev 68891)
@@ -0,0 +1,144 @@
+.Dd November 18, 2023
+.Dt CLUTTEX 1
+.Os
+.Sh NAME
+.Nm cluttex
+.Nd a tool for processing TeX files
+.Sh SYNOPSIS
+.Nm
+.Fl e
+.Ar ENGINE
+.Op options
+.Op Fl \-
+.Ar FILE.tex
+.Sh DESCRIPTION
+Process TeX files without cluttering your working directory.
+.Pp
+The following options are accepted:
+.Bl -tag -width Ds
+.It Fl e , Fl \-engine Ns = Ns Ar ENGINE
+Specify which TeX engine to use.
+.Ar ENGINE
+is one of the following:
+pdflatex, pdftex,
+lualatex, luatex, luajittex,
+xelatex, xetex, latex, etex, tex,
+platex, eptex, ptex,
+uplatex, euptex, uptex,
+.It Fl \-engine\-executable Ns = Ns Ar COMMAND+OPTIONs
+The actual TeX command to use.
+[default:
+.Ar ENGINE ]
+.It Fl o , Fl \-output Ns = Ns Ar FILE
+The name of output file.
+[default:
+.Ar JOBNAME Ns
+\&.pdf or
+.Ar JOBNAME Ns
+\&.dvi]
+.It Fl \-fresh
+Clean intermediate files before running TeX.
+Cannot be used with --output-directory.
+.It Fl \-max-iterations Ns = Ns Ar N
+Maximum number of running TeX to resolve cross-references.
+[default: 3]
+.It Fl \-start-with-draft
+Start with draft mode.
+.It Fl \-change-directory , Fl \-no-change-directory
+Change directory before running TeX.
+[default: no]
+.It Fl \-watch Ns Op = Ns Ar ENGINE
+Watch input files for change.
+Requires fswatch or inotifywait to be installed.
+.Ar ENGINE
+is one of
+.Sq fswatch ,
+.Sq inotifywait
+or
+.Sq auto .
+[default: auto]
+.It Fl \-tex-option Ns = Ns Ar OPTION
+Pass
+.Ar OPTION
+to TeX as a single option.
+.It Fl \-tex-options Ns = Ns Ar OPTIONs
+Pass
+.Ar OPTIONs
+to TeX as multiple options.
+.It Fl \-dvipdfmx-option Ns = Ns Ar OPTION , Fl \-dvipdfmx-options Ns = Ns Ar OPTIONs
+Same for dvipdfmx.
+.It Fl \-makeindex Ns = Ns Ar COMMAND+OPTIONs
+Command to generate index, such as
+.Sq makeindex
+or
+.Sq mendex .
+.It Fl \-bibtex Ns = Ns Ar COMMAND+OPTIONs
+Command for BibTeX, such as
+.Sq bibtex
+or
+.Sq pbibtex .
+.It Fl \-biber Ns Op = Ns Ar COMMAND+OPTIONs
+Command for Biber.
+.It Fl \-makeglossaries Ns Op = Ns Ar COMMAND+OPTIONs
+Command for makeglossaries.
+.It Fl h , Fl \-help
+Print this message and exit.
+.It Fl v , Fl \-version
+Print version information and exit.
+.It Fl V , Fl \-verbose
+Be more verbose.
+.It Fl \-color Ns Op = Ns Ar WHEN
+Make ClutTeX's message more colorful.
+.Ar WHEN
+is one of
+.Sq always ,
+.Sq auto ,
+or
+.Sq never .
+[default:
+.Sq auto
+if Fl \-color is omitted,
+.Sq always
+if
+.Ar WHEN
+is omitted]
+.It Fl \-includeonly Ns = Ns Ar NAMEs
+Insert
+.Sq \eincludeonly{ Ns Ar NAMEs Ns } .
+.It Fl \-make-depends Ns = Ns Ar FILE
+Write dependencies as a Makefile rule.
+.It Fl \-print\-output\-directory
+Print the output directory and exit.
+.It Fl \-package\-support Ns = Ns Ar PKG1 Ns Op , Ns Ar PKG2 Ns ,...
+Enable special support for some shell-escaping packages.
+Currently supported: minted, epstopdf.
+.It Fl \-check\-driver Ns = Ns Ar DRIVER
+Check that the correct driver file is loaded.
+.Ar DRIVER
+is one of
+.Sq dvipdfmx ,
+.Sq dvips ,
+.Sq dvisvgm .
+.It Fl \-shell-escape , Fl \-no-shell-escape
+.It Fl \-shell-restricted
+.It Fl \-synctex Ns = Ns Ar NUMBER
+.It Fl \-fmt Ns = Ns Ar FMTNAME
+.It Fl \-file-line-error , Fl \-no-file-line-error
+[default: yes]
+.It Fl \-halt-on-error , Fl \-no-halt-on-error
+[default: yes]
+.It Fl \-interaction Ns = Ns Ar STRING
+[default: nonstopmode]
+.It Fl \-jobname Ns = Ns Ar STRING
+.It Fl \-output-directory Ns = Ns Ar DIR
+[default: somewhere in the temporary directory]
+.It Fl \-output-format Ns = Ns Ar FORMAT
+.Ar FORMAT
+is
+.Sq pdf
+or
+.Sq dvi .
+[default: pdf]
+.El
+.Sh EXIT STATUS
+.Ex -std


Property changes on: trunk/Master/texmf-dist/doc/man/man1/cluttex.1
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: trunk/Master/texmf-dist/doc/man/man1/cluttex.man1.pdf
===================================================================
(Binary files differ)

Index: trunk/Master/texmf-dist/doc/man/man1/cluttex.man1.pdf
===================================================================
--- trunk/Master/texmf-dist/doc/man/man1/cluttex.man1.pdf	2023-11-18 20:40:31 UTC (rev 68890)
+++ trunk/Master/texmf-dist/doc/man/man1/cluttex.man1.pdf	2023-11-18 20:55:22 UTC (rev 68891)

Property changes on: trunk/Master/texmf-dist/doc/man/man1/cluttex.man1.pdf
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/pdf
\ No newline at end of property
Modified: trunk/Master/texmf-dist/doc/support/cluttex/CHANGELOG.md
===================================================================
--- trunk/Master/texmf-dist/doc/support/cluttex/CHANGELOG.md	2023-11-18 20:40:31 UTC (rev 68890)
+++ trunk/Master/texmf-dist/doc/support/cluttex/CHANGELOG.md	2023-11-18 20:55:22 UTC (rev 68891)
@@ -1,3 +1,15 @@
+Version 0.6 (2023-11-18)
+-----
+
+Changes:
+
+* Fix "arg" table in luatexinit to support luamplib
+* Handle the combination of `--output-directory` and `--change-directory` properly ([Issue #7](https://github.com/minoki/cluttex/issues/7), thanks to @atticus-sullivan)
+* Change `LUAINPUTS` environment variable to find Lua files if `--change-directory` is used ([PR #11](https://github.com/minoki/cluttex/pull/11), thanks to @atticus-sullivan)
+* Watch engine can be selected via an optional argument to `--watch` ([PR #10](https://github.com/minoki/cluttex/pull/10), thanks to @atticus-sullivan)
+* Decrease `max_print_line` to avoid issue with BibTeX from TeX Live 2023.
+* Rerun biber if bib files are updated ([PR #12](https://github.com/minoki/cluttex/pull/12), thanks to @atticus-sullivan)
+
 Version 0.5.1 (2021-11-04)
 -----
 

Modified: trunk/Master/texmf-dist/doc/support/cluttex/Makefile
===================================================================
--- trunk/Master/texmf-dist/doc/support/cluttex/Makefile	2023-11-18 20:40:31 UTC (rev 68890)
+++ trunk/Master/texmf-dist/doc/support/cluttex/Makefile	2023-11-18 20:55:22 UTC (rev 68891)
@@ -1,6 +1,6 @@
 all: bin/cluttex bin/cluttex.bat
 
-.PHONY: all archive
+.PHONY: all archive check-version
 
 sources= \
  src/texrunner/pathutil.lua \
@@ -35,6 +35,18 @@
 	lua build.lua --windows-batchfile $@
 	lua checkglobal.lua $@
 
-archive: all
+version_file=$(shell bin/cluttex --version 2>&1 | grep --only-matching -E 'v\d+(\.\d+)*' | sed 's/^v/VERSION_/;s/\./_/g')
+
+check-version: all
+	@bin/cluttex --version
+	grep VERSION src/cluttex.lua
+	grep VERSION bin/cluttex
+	grep VERSION bin/cluttex.bat
+	grep -i VERSION doc/cluttex.tex
+	grep -i VERSION doc/cluttex-ja.tex
+
+archive: all check-version
+	@bin/cluttex --version
 	git archive --format=tar --prefix=cluttex/ -o cluttex.tar HEAD
+	mkdir -p cluttex && touch cluttex/$(version_file) && tar -r -f cluttex.tar cluttex/$(version_file)
 	gzip -k9 cluttex.tar

Modified: trunk/Master/texmf-dist/doc/support/cluttex/README.md
===================================================================
--- trunk/Master/texmf-dist/doc/support/cluttex/README.md	2023-11-18 20:40:31 UTC (rev 68890)
+++ trunk/Master/texmf-dist/doc/support/cluttex/README.md	2023-11-18 20:55:22 UTC (rev 68891)
@@ -60,7 +60,7 @@
   \[default: 3\]
 * `--[no-]change-directory`
   Change the current working directory to the output directory when running TeX.
-* `--watch`
+* `--watch[=ENGINE]`
   Watch input files for change.
   Requires [fswatch](http://emcrisostomo.github.io/fswatch/) program or `inotifywait` program to be installed on Unix systems.
 * `--color[=WHEN]`

Added: trunk/Master/texmf-dist/doc/support/cluttex/VERSION_0_6
===================================================================
Modified: trunk/Master/texmf-dist/doc/support/cluttex/bin/cluttex.bat
===================================================================
--- trunk/Master/texmf-dist/doc/support/cluttex/bin/cluttex.bat	2023-11-18 20:40:31 UTC (rev 68890)
+++ trunk/Master/texmf-dist/doc/support/cluttex/bin/cluttex.bat	2023-11-18 20:55:22 UTC (rev 68891)
@@ -1275,6 +1275,21 @@
   return texio_write(...)
 end
 ]==])
+
+  -- Fix "arg" to make luamplib work
+  initscript:write([==[
+if string.match(arg[0], "^%-%-lua=") then
+  local minindex = 0
+  while arg[minindex - 1] ~= nil do
+    minindex = minindex - 1
+  end
+  local arg2 = {}
+  for i = 0, #arg - minindex do
+    arg2[i] = arg[i + minindex]
+  end
+  arg = arg2
+end
+]==])
   initscript:close()
 end
 
@@ -1372,7 +1387,7 @@
 end
 package.preload["texrunner.handleoption"] = function(...)
 local COPYRIGHT_NOTICE = [[
-Copyright (C) 2016-2021  ARATA Mizuki
+Copyright (C) 2016-2023  ARATA Mizuki
 
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -1420,8 +1435,9 @@
                                  cross-references.  [default: 3]
       --start-with-draft       Start with draft mode.
       --[no-]change-directory  Change directory before running TeX.
-      --watch                  Watch input files for change.  Requires fswatch
-                                 program to be installed.
+      --watch[=ENGINE]         Watch input files for change.  Requires fswatch
+                                 or inotifywait to be installed. ENGINE is one of
+                                 `fswatch', `inotifywait' or `auto' [default: `auto']
       --tex-option=OPTION      Pass OPTION to TeX as a single option.
       --tex-options=OPTIONs    Pass OPTIONs to TeX as multiple options.
       --dvipdfmx-option[s]=OPTION[s]  Same for dvipdfmx.
@@ -1495,6 +1511,8 @@
   },
   {
     long = "watch",
+    param = true,
+    default = "auto",
   },
   {
     short = "h",
@@ -1685,7 +1703,7 @@
 
     elseif name == "watch" then
       assert(options.watch == nil, "multiple --watch options")
-      options.watch = true
+      options.watch = param
 
     elseif name == "help" then
       usage(arg)
@@ -1843,6 +1861,15 @@
 
   set_default_values(options)
 
+  -- parameter validy check TODO should this be organized as function like
+  -- set_default_values and with a key in the option spec (list or function)?
+  if options.watch then
+	  if options.watch ~= "fswatch" and options.watch ~= "inotifywait" then
+		message.error("Unknown wait engine '", options.watch, "'.")
+		os.exit(1)
+	  end
+  end
+
   if options.output_format == "pdf" then
     if options.check_driver ~= nil then
       error("--check-driver can only be used when the output format is DVI.")
@@ -2936,7 +2963,7 @@
 }
 end
 --[[
-  Copyright 2016-2021 ARATA Mizuki
+  Copyright 2016-2023 ARATA Mizuki
 
   This file is part of ClutTeX.
 
@@ -2954,7 +2981,7 @@
   along with ClutTeX.  If not, see <http://www.gnu.org/licenses/>.
 ]]
 
-CLUTTEX_VERSION = "v0.5.1"
+CLUTTEX_VERSION = "v0.6"
 
 -- Standard libraries
 local coroutine = coroutine
@@ -3054,9 +3081,13 @@
 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 ""
@@ -3066,14 +3097,15 @@
 
 -- 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)
@@ -3107,6 +3139,11 @@
   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.
@@ -3302,7 +3339,7 @@
       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), "&&",
@@ -3321,12 +3358,34 @@
     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),
@@ -3333,6 +3392,7 @@
             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)
@@ -3495,7 +3555,7 @@
       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
@@ -3519,7 +3579,7 @@
       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
@@ -3544,7 +3604,13 @@
       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

Modified: trunk/Master/texmf-dist/doc/support/cluttex/doc/Makefile
===================================================================
--- trunk/Master/texmf-dist/doc/support/cluttex/doc/Makefile	2023-11-18 20:40:31 UTC (rev 68890)
+++ trunk/Master/texmf-dist/doc/support/cluttex/doc/Makefile	2023-11-18 20:55:22 UTC (rev 68891)
@@ -1,4 +1,4 @@
-all: cluttex.pdf cluttex-ja.pdf
+all: cluttex.pdf cluttex-ja.pdf lint-manual
 
 cluttex.pdf: cluttex.tex
 	cluttex -e pdflatex -o $@ --make-depends=cluttex.pdf.dep $<
@@ -10,7 +10,10 @@
 	-rm -rf $(shell cluttex -e pdflatex --print-output-directory cluttex.tex)
 	-rm -rf $(shell cluttex -e lualatex --print-output-directory cluttex-ja.tex)
 
-.PHONY: all clean-outdir
+lint-manual:
+	mandoc -Tlint cluttex.1
 
+.PHONY: all clean-outdir lint-manual
+
 -include cluttex.pdf.dep
 -include cluttex-ja.pdf.dep

Modified: trunk/Master/texmf-dist/doc/support/cluttex/doc/cluttex-ja.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/doc/support/cluttex/doc/cluttex-ja.tex
===================================================================
--- trunk/Master/texmf-dist/doc/support/cluttex/doc/cluttex-ja.tex	2023-11-18 20:40:31 UTC (rev 68890)
+++ trunk/Master/texmf-dist/doc/support/cluttex/doc/cluttex-ja.tex	2023-11-18 20:55:22 UTC (rev 68891)
@@ -11,9 +11,27 @@
 \crefformat{section}{#2セクション#1#3}
 \crefformat{subsection}{#2サブセクション#1#3}
 
-\title{\ClutTeX{}マニュアル\\(バージョン0.5.1)}
+\ltjsetparameter{
+  alxspmode={`\-,allow},
+  alxspmode={`\\,allow},
+  alxspmode={`\.,allow},
+  alxspmode={`\{,preonly},
+  alxspmode={`\},postonly},
+  alxspmode={`\_,allow},
+  alxspmode={`\$,allow},
+  alxspmode={`\!,allow},
+  alxspmode={`\*,allow},
+  alxspmode={`\^,allow},
+  alxspmode={`\:,allow},
+  alxspmode={`\#,allow},
+  alxspmode={`\/,allow},
+  alxspmode={`\<,preonly},
+  alxspmode={`\>,postonly},
+}
+
+\title{\ClutTeX{}マニュアル\\(バージョン0.6)}%VERSION
 \author{ARATA Mizuki}
-\date{2021年11月4日}
+\date{2023年11月18日}
 
 \begin{document}
 \maketitle
@@ -72,7 +90,7 @@
 \item[\texttt{--max-iterations=\metavar{N}}]
   相互参照の解決等のために最大何回処理を行うかを指定する。
   デフォルト:3
-\item[\texttt{--watch}]
+\item[\texttt{--watch[=\metavar{ENGINE}]}]
   入力ファイルを監視する。
   別途、\texttt{fswatch}プログラムまたは\texttt{inotifywait}プログラムが必要となる場合がある。
   詳しくは\cref{sec:watch-mode}を参照。
@@ -162,6 +180,7 @@
 
 Windows上では、\ClutTeX{}単体でファイルシステムの監視を行う。
 一方で、それ以外のOS(Unix系)では、\texttt{fswatch}\footnote{\url{http://emcrisostomo.github.io/fswatch/}}プログラムまたは\texttt{inotifywait}プログラムが予めインストールされている必要がある。
+補助プログラムは自動検出されるが、\metavar{ENGINE}引数で明示的に指定することもできる。
 
 \section{MakeIndexや\BibTeX}
 MakeIndexや\BibTeX を使って処理を行う場合は、\texttt{--makeindex}や\texttt{--bibtex}等のオプションを指定する。

Modified: trunk/Master/texmf-dist/doc/support/cluttex/doc/cluttex.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/doc/support/cluttex/doc/cluttex.tex
===================================================================
--- trunk/Master/texmf-dist/doc/support/cluttex/doc/cluttex.tex	2023-11-18 20:40:31 UTC (rev 68890)
+++ trunk/Master/texmf-dist/doc/support/cluttex/doc/cluttex.tex	2023-11-18 20:55:22 UTC (rev 68891)
@@ -8,9 +8,9 @@
 \newcommand\texpkg[1]{\texttt{#1}}
 \newcommand\metavar[1]{\textnormal{\textsf{#1}}}
 
-\title{\ClutTeX\ manual\\(Version 0.5.1)}
+\title{\ClutTeX\ manual\\(Version 0.6)}
 \author{ARATA Mizuki}
-\date{2021-11-04}
+\date{2023-11-18}
 
 \begin{document}
 \maketitle
@@ -66,7 +66,7 @@
 \item[\texttt{--max-iterations=\metavar{N}}]
   Set maximum number of run, for resolving cross-references and etc.
   Default: 3
-\item[\texttt{--watch}]
+\item[\texttt{--watch[=\metavar{ENGINE}]}]
   Watch input files for change.
   May need an external program to be available.
   See \autoref{sec:watch-mode} for details.
@@ -155,6 +155,7 @@
 
 On Windows, a built-in filesystem watcher is implemented.
 On other platforms, an auxiliary program \texttt{fswatch}\footnote{\url{http://emcrisostomo.github.io/fswatch/}} or \texttt{inotifywait} needs to be installed.
+The auxiliary program will be detected automatically, but it could also be specified by the \metavar{ENGINE} argument.
 
 \section{MakeIndex and \BibTeX}
 If you want to generate index or bibliography, using MakeIndex or \BibTeX, set \texttt{--makeindex}, \texttt{--bibtex}, or \texttt{--biber} option.

Modified: trunk/Master/texmf-dist/doc/support/cluttex/src/cluttex.lua
===================================================================
--- trunk/Master/texmf-dist/doc/support/cluttex/src/cluttex.lua	2023-11-18 20:40:31 UTC (rev 68890)
+++ trunk/Master/texmf-dist/doc/support/cluttex/src/cluttex.lua	2023-11-18 20:55:22 UTC (rev 68891)
@@ -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 @@
 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 @@
 
 -- 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 @@
   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 @@
       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,12 +400,34 @@
     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),
@@ -402,6 +434,7 @@
             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 @@
       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 @@
       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 @@
       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

Modified: trunk/Master/texmf-dist/doc/support/cluttex/src/texrunner/handleoption.lua
===================================================================
--- trunk/Master/texmf-dist/doc/support/cluttex/src/texrunner/handleoption.lua	2023-11-18 20:40:31 UTC (rev 68890)
+++ trunk/Master/texmf-dist/doc/support/cluttex/src/texrunner/handleoption.lua	2023-11-18 20:55:22 UTC (rev 68891)
@@ -1,5 +1,5 @@
 local COPYRIGHT_NOTICE = [[
-Copyright (C) 2016-2021  ARATA Mizuki
+Copyright (C) 2016-2023  ARATA Mizuki
 
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -47,8 +47,9 @@
                                  cross-references.  [default: 3]
       --start-with-draft       Start with draft mode.
       --[no-]change-directory  Change directory before running TeX.
-      --watch                  Watch input files for change.  Requires fswatch
-                                 program to be installed.
+      --watch[=ENGINE]         Watch input files for change.  Requires fswatch
+                                 or inotifywait to be installed. ENGINE is one of
+                                 `fswatch', `inotifywait' or `auto' [default: `auto']
       --tex-option=OPTION      Pass OPTION to TeX as a single option.
       --tex-options=OPTIONs    Pass OPTIONs to TeX as multiple options.
       --dvipdfmx-option[s]=OPTION[s]  Same for dvipdfmx.
@@ -122,6 +123,8 @@
   },
   {
     long = "watch",
+    param = true,
+    default = "auto",
   },
   {
     short = "h",
@@ -312,7 +315,7 @@
 
     elseif name == "watch" then
       assert(options.watch == nil, "multiple --watch options")
-      options.watch = true
+      options.watch = param
 
     elseif name == "help" then
       usage(arg)
@@ -470,6 +473,15 @@
 
   set_default_values(options)
 
+  -- parameter validy check TODO should this be organized as function like
+  -- set_default_values and with a key in the option spec (list or function)?
+  if options.watch then
+	  if options.watch ~= "fswatch" and options.watch ~= "inotifywait" then
+		message.error("Unknown wait engine '", options.watch, "'.")
+		os.exit(1)
+	  end
+  end
+
   if options.output_format == "pdf" then
     if options.check_driver ~= nil then
       error("--check-driver can only be used when the output format is DVI.")

Modified: trunk/Master/texmf-dist/doc/support/cluttex/src/texrunner/luatexinit.lua
===================================================================
--- trunk/Master/texmf-dist/doc/support/cluttex/src/texrunner/luatexinit.lua	2023-11-18 20:40:31 UTC (rev 68890)
+++ trunk/Master/texmf-dist/doc/support/cluttex/src/texrunner/luatexinit.lua	2023-11-18 20:55:22 UTC (rev 68891)
@@ -93,6 +93,21 @@
   return texio_write(...)
 end
 ]==])
+
+  -- Fix "arg" to make luamplib work
+  initscript:write([==[
+if string.match(arg[0], "^%-%-lua=") then
+  local minindex = 0
+  while arg[minindex - 1] ~= nil do
+    minindex = minindex - 1
+  end
+  local arg2 = {}
+  for i = 0, #arg - minindex do
+    arg2[i] = arg[i + minindex]
+  end
+  arg = arg2
+end
+]==])
   initscript:close()
 end
 

Modified: trunk/Master/texmf-dist/scripts/cluttex/cluttex.lua
===================================================================
--- trunk/Master/texmf-dist/scripts/cluttex/cluttex.lua	2023-11-18 20:40:31 UTC (rev 68890)
+++ trunk/Master/texmf-dist/scripts/cluttex/cluttex.lua	2023-11-18 20:55:22 UTC (rev 68891)
@@ -1272,6 +1272,21 @@
   return texio_write(...)
 end
 ]==])
+
+  -- Fix "arg" to make luamplib work
+  initscript:write([==[
+if string.match(arg[0], "^%-%-lua=") then
+  local minindex = 0
+  while arg[minindex - 1] ~= nil do
+    minindex = minindex - 1
+  end
+  local arg2 = {}
+  for i = 0, #arg - minindex do
+    arg2[i] = arg[i + minindex]
+  end
+  arg = arg2
+end
+]==])
   initscript:close()
 end
 
@@ -1369,7 +1384,7 @@
 end
 package.preload["texrunner.handleoption"] = function(...)
 local COPYRIGHT_NOTICE = [[
-Copyright (C) 2016-2021  ARATA Mizuki
+Copyright (C) 2016-2023  ARATA Mizuki
 
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -1417,8 +1432,9 @@
                                  cross-references.  [default: 3]
       --start-with-draft       Start with draft mode.
       --[no-]change-directory  Change directory before running TeX.
-      --watch                  Watch input files for change.  Requires fswatch
-                                 program to be installed.
+      --watch[=ENGINE]         Watch input files for change.  Requires fswatch
+                                 or inotifywait to be installed. ENGINE is one of
+                                 `fswatch', `inotifywait' or `auto' [default: `auto']
       --tex-option=OPTION      Pass OPTION to TeX as a single option.
       --tex-options=OPTIONs    Pass OPTIONs to TeX as multiple options.
       --dvipdfmx-option[s]=OPTION[s]  Same for dvipdfmx.
@@ -1492,6 +1508,8 @@
   },
   {
     long = "watch",
+    param = true,
+    default = "auto",
   },
   {
     short = "h",
@@ -1682,7 +1700,7 @@
 
     elseif name == "watch" then
       assert(options.watch == nil, "multiple --watch options")
-      options.watch = true
+      options.watch = param
 
     elseif name == "help" then
       usage(arg)
@@ -1840,6 +1858,15 @@
 
   set_default_values(options)
 
+  -- parameter validy check TODO should this be organized as function like
+  -- set_default_values and with a key in the option spec (list or function)?
+  if options.watch then
+	  if options.watch ~= "fswatch" and options.watch ~= "inotifywait" then
+		message.error("Unknown wait engine '", options.watch, "'.")
+		os.exit(1)
+	  end
+  end
+
   if options.output_format == "pdf" then
     if options.check_driver ~= nil then
       error("--check-driver can only be used when the output format is DVI.")
@@ -2933,7 +2960,7 @@
 }
 end
 --[[
-  Copyright 2016-2021 ARATA Mizuki
+  Copyright 2016-2023 ARATA Mizuki
 
   This file is part of ClutTeX.
 
@@ -2951,7 +2978,7 @@
   along with ClutTeX.  If not, see <http://www.gnu.org/licenses/>.
 ]]
 
-CLUTTEX_VERSION = "v0.5.1"
+CLUTTEX_VERSION = "v0.6"
 
 -- Standard libraries
 local coroutine = coroutine
@@ -3051,9 +3078,13 @@
 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 ""
@@ -3063,14 +3094,15 @@
 
 -- 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)
@@ -3104,6 +3136,11 @@
   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.
@@ -3299,7 +3336,7 @@
       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), "&&",
@@ -3318,12 +3355,34 @@
     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),
@@ -3330,6 +3389,7 @@
             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)
@@ -3492,7 +3552,7 @@
       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
@@ -3516,7 +3576,7 @@
       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
@@ -3541,7 +3601,13 @@
       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

Modified: trunk/Master/tlpkg/libexec/ctan2tds
===================================================================
--- trunk/Master/tlpkg/libexec/ctan2tds	2023-11-18 20:40:31 UTC (rev 68890)
+++ trunk/Master/tlpkg/libexec/ctan2tds	2023-11-18 20:55:22 UTC (rev 68891)
@@ -2098,6 +2098,7 @@
  'cjw',         '\.tex|' . $standardtex,
  'clock',       '\.sty|clock\.tex',
  'cloze',	'\.tex|' . $standardtex,
+ 'cluttex',	'NULL', # not build.lua or checkglobal.lua
  'cmap',        '\.cmap|' . $standardtex,
  'codebox',	'\.sty',		# not ctxdoc-en.cls
  'codehigh',	'\.lua$|' . $standardtex,
@@ -3852,6 +3853,7 @@
  'chklref'		=> '\.1$',
  'citation-style-language' => '\.1$',
  'clojure-pamphlet'	=> '\.1$',
+ 'cluttex'		=> '\.1$',
  'crossrefware'		=> '\.1$',
  'ctanbib'              => '\.1$',
  'ctan-o-mat'           => '\.1$',
@@ -6205,8 +6207,9 @@
 }
 
 sub PREHOOK_cluttex {
-  print "PREHOOK_$package - mv */cluttex for specialscripts\n";
+  print "PREHOOK_$package - mv */cluttex for specialscripts and doc/*.1\n";
   &SYSTEM ("$MV bin/cluttex cluttex.lua");
+  &SYSTEM ("$MV doc/cluttex.1 .");
 }
 
 sub PREHOOK_cm {

Modified: trunk/Master/tlpkg/tlpsrc/cluttex.tlpsrc
===================================================================
--- trunk/Master/tlpkg/tlpsrc/cluttex.tlpsrc	2023-11-18 20:40:31 UTC (rev 68890)
+++ trunk/Master/tlpkg/tlpsrc/cluttex.tlpsrc	2023-11-18 20:55:22 UTC (rev 68891)
@@ -1,3 +1,6 @@
 binpattern f bin/${ARCH}/${PKGNAME}
 binpattern f bin/${ARCH}/cllualatex
 binpattern f bin/${ARCH}/clxelatex
+#
+docpattern f man/man1/cllualatex.*
+docpattern f man/man1/clxelatex.*



More information about the tex-live-commits mailing list.