texlive[72937] trunk: texfindpkg (22nov24)

commits+karl at tug.org commits+karl at tug.org
Fri Nov 22 22:52:55 CET 2024


Revision: 72937
          https://tug.org/svn/texlive?view=revision&revision=72937
Author:   karl
Date:     2024-11-22 22:52:55 +0100 (Fri, 22 Nov 2024)
Log Message:
-----------
texfindpkg (22nov24)

Modified Paths:
--------------
    trunk/Build/source/texk/texlive/linked_scripts/texfindpkg/texfindpkg.lua
    trunk/Master/texmf-dist/doc/man/man1/texfindpkg.1
    trunk/Master/texmf-dist/doc/man/man1/texfindpkg.man1.pdf
    trunk/Master/texmf-dist/doc/support/texfindpkg/README.md
    trunk/Master/texmf-dist/scripts/texfindpkg/texfindpkg.lua
    trunk/Master/texmf-dist/source/support/texfindpkg/tfpbuild.lua
    trunk/Master/texmf-dist/tex/latex/texfindpkg/texfindpkg.json.gz

Modified: trunk/Build/source/texk/texlive/linked_scripts/texfindpkg/texfindpkg.lua
===================================================================
--- trunk/Build/source/texk/texlive/linked_scripts/texfindpkg/texfindpkg.lua	2024-11-22 21:52:42 UTC (rev 72936)
+++ trunk/Build/source/texk/texlive/linked_scripts/texfindpkg/texfindpkg.lua	2024-11-22 21:52:55 UTC (rev 72937)
@@ -1,14 +1,14 @@
 #!/usr/bin/env texlua
 
 -- Description: Install TeX packages and their dependencies
--- Copyright: 2023 (c) Jianrui Lyu <tolvjr at 163.com>
+-- Copyright: 2023-2024 (c) Jianrui Lyu <tolvjr at 163.com>
 -- Repository: https://github.com/lvjr/texfindpkg
 -- License: GNU General Public License v3.0
 
 local tfp = tfp or {}
 
-tfp.version = "2023E"
-tfp.date = "2023-05-05"
+tfp.version = "2024A"
+tfp.date = "2024-11-22"
 
 local building = tfp.building
 local tfpresult = ""
@@ -135,7 +135,8 @@
   end
 end
 
-local tlpkgdata = {}
+local tlfiletopkg = {}
+local tlpkgtofile = {}
 local tlinspkgdata = {}
 
 local function tlExtractFiles(name, desc)
@@ -147,12 +148,15 @@
   end
   -- ignore package files in doc folder
   desc = match(desc, "\nrunfiles .+") or ""
+  local flist = {}
   for base, ext in gmatch(desc, "/([%a%d%-%.]+)%.([%a%d]+)\n") do
     if ext == "sty" or ext == "cls" or ext == "tex" or ext == "ltx" then
       dbgPrint(name, base .. "." .. ext)
-      tlpkgdata[base .. "." .. ext] = name
+      tlfiletopkg[base .. "." .. ext] = name
+      insert(flist, base .. "." .. ext)
     end
   end
+  tlpkgtofile[name]= flist
 end
 
 local function tlExtractPackages(name, desc)
@@ -161,7 +165,7 @@
 
 local function tlParsePackageDB(tlpkgtext)
   gsub(tlpkgtext, "name (.-)\n(.-)\n\n", tlExtractFiles)
-  return tlpkgdata
+  return tlfiletopkg
 end
 
 local function tlParseTwoPackageDB()
@@ -193,7 +197,8 @@
   end
 end
 
-local mtpkgdata = {}
+local mtfiletopkg = {}
+local mtpkgtofile = {}
 local mtinspkgdata = {}
 
 local function mtExtractFiles(name, desc)
@@ -203,12 +208,15 @@
     --print(name)
     return
   end
+  local flist = {}
   for base, ext in gmatch(desc, "/([%a%d%-%.]+)%.([%a%d]+)\r?\n") do
     if ext == "sty" or ext == "cls" or ext == "tex" or ext == "ltx" then
       dbgPrint(name, base .. "." .. ext)
-      mtpkgdata[base .. "." .. ext] = name
+      mtfiletopkg[base .. "." .. ext] = name
+      insert(flist, base .. "." .. ext)
     end
   end
+  mtpkgtofile[name]= flist
 end
 
 local function mtExtractPackages(name, desc)
@@ -218,7 +226,7 @@
 local function mtParsePackageDB(mtpkgtext)
   -- package-manifests.ini might use different eol characters
   gsub(mtpkgtext, "%[(.-)%]\r?\n(.-)\r?\n\r?\n", mtExtractFiles)
-  return mtpkgdata
+  return mtfiletopkg
 end
 
 local function mtParseTwoPackageDB()
@@ -232,6 +240,7 @@
 ------------------------------------------------------------
 
 local dist               -- name of current tex distribution
+local totaldeplist = {}  -- list of all depending packages
 local totalinslist = {}  -- list of all missing packages
 local filecount = 0      -- total number of files found
 
@@ -247,14 +256,22 @@
   end
 end
 
-local function findOnePackage(fname)
+local function findPackageFromFile(fname)
   if dist == "texlive" then
-    return tlpkgdata[fname]
+    return tlfiletopkg[fname]
   else
-    return mtpkgdata[fname]
+    return mtfiletopkg[fname]
   end
 end
 
+local function findFilesInPackage(pkg)
+  if dist == "texlive" then
+    return tlpkgtofile[pkg]
+  else
+    return mtpkgtofile[pkg]
+  end
+end
+
 local function checkInsPakage(pkg)
   if dist == "texlive" then
     return tlinspkgdata[pkg]
@@ -284,6 +301,8 @@
     end
     tfpExecute("tlmgr install " .. pkgs)
   else
+    -- miktex fails if one of the packages is already installed
+    -- so we install miktex packages one by one
     for _, p in ipairs(list) do
       tfpRealPrint("installing miktex package: " .. p)
       tfpExecute("miktex packages install " .. p)
@@ -308,6 +327,7 @@
   if #list > 0 then
     filecount = filecount + 1
   end
+  table.sort(list)
   local pkgs = concat(list, " ")
   if #list == 1 then
     tfpPrint(dist .. " package needed: " .. pkgs)
@@ -327,6 +347,7 @@
       tfpRealPrint("these packages are already installed")
     end
   else
+    table.sort(inslist)
     local pkgs = concat(inslist, " ")
     if #inslist == 1 then
       tfpRealPrint(dist .. " package not yet installed: " .. pkgs)
@@ -359,12 +380,15 @@
 
 local function printDependency(fname, level)
   local msg = fname
-  local pkg = findOnePackage(fname)
+  local pkg = findPackageFromFile(fname)
   if pkg then
     msg = msg .. " (from " .. pkg .. ")"
     if not valueExists(pkglist, pkg) then
       insert(pkglist, pkg)
     end
+    if not valueExists(totaldeplist, pkg) then
+      insert(totaldeplist, pkg)
+    end
   else
     msg = msg .. " (not found)"
   end
@@ -397,6 +421,9 @@
 
 local function queryByFileName(fname)
   fnlist, pkglist = {}, {} -- reset the list
+  if not find(fname, "%.") then
+    fname = fname .. ".sty"
+  end
   tfpPrint("building dependency tree for " .. fname .. ":")
   tfpPrint(rep("-", 24))
   findDependencies(fname, 0)
@@ -412,6 +439,28 @@
   listSomePackages(pkglist)
 end
 
+local function queryByPackageName(pname)
+  local list = findFilesInPackage(pname)
+  if list == nil then
+    tfpPrint(dist .. " package " .. pname .. " doesn't exist")
+    return
+  end
+  if #list > 0 then
+    tfpPrint("finding package files in " .. dist .. " package " .. pname)
+    for _, fname in ipairs(list) do
+      tfpPrint(rep("=", 48))
+      tfpPrint("found package file " .. fname .. " in " .. dist .. " package " .. pname)
+      queryByFileName(fname)
+    end
+  else
+    tfpPrint("could not find any package file in " .. dist .. " package " .. pname)
+    listSomePackages({pname})
+    if not valueExists(totaldeplist, pname) then
+      insert(totaldeplist, pname)
+    end
+  end
+end
+
 local function getFileNameFromCmdEnvName(cmdenv, name)
   --print(name)
   local flist = {}
@@ -465,11 +514,14 @@
   elseif t == "file" then
     tfpPrint(rep("=", 48))
     queryByFileName(name)
-  else
-    -- do something for t == "pkg"
+  else -- t == "pkg"
+    tfpPrint(rep("=", 48))
+    queryByPackageName(name)
   end
 end
 
+local outfile = nil
+
 local function query(namelist)
   for _, v in ipairs(namelist) do
     queryOne(v[1], v[2])
@@ -476,12 +528,30 @@
   end
   if filecount > 1 then
     tfpRealPrint(rep("=", 48))
+    table.sort(totaldeplist)
+    local pkgs = concat(totaldeplist, " ")
+    if #totaldeplist == 0 then
+      --tfpRealPrint("no packages needed are found")
+    elseif #totaldeplist == 1 then
+      tfpRealPrint(dist .. " package needed in total: " .. pkgs)
+    else
+      tfpRealPrint(dist .. " packages needed in total: " .. pkgs)
+    end
+    tfpRealPrint(rep("=", 48))
+    table.sort(totalinslist)
     local pkgs = concat(totalinslist, " ")
-    if #totalinslist == 1 then
+    if #totalinslist == 0 then
+      tfpRealPrint("you don't need to install any packages")
+    elseif #totalinslist == 1 then
       tfpRealPrint(dist .. " package not yet installed in total: " .. pkgs)
     else
       tfpRealPrint(dist .. " packages not yet installed in total: " .. pkgs)
     end
+    if outfile then
+      --print(outfile)
+      pkgs = concat(totaldeplist, "\n")
+      fileWrite(pkgs, outfile)
+    end
   end
 end
 
@@ -515,16 +585,58 @@
   end
 end
 
+local function readArgsInFile(list, inname)
+  local intext = fileRead(inname)
+  if not intext then
+    tfpPrint("error in reading input file " .. inname)
+    return list
+  end
+  tfpPrint("reading input file " .. inname)
+  for line in gmatch(intext, "%s*(.-)%s*\r?\n") do
+    line = match(line, "(.-)%s*#") or line
+    --print("|" .. line .. "|")
+    if line ~= "" then
+      insert(list, line)
+    end
+  end
+  return list
+end
+
+local function readArgList(arglist)
+  local reallist = {}
+  local isinput = false
+  local isoutput = false
+  for _, v in ipairs(arglist) do
+    if isinput then
+      reallist = readArgsInFile(reallist, v)
+      isinput = false
+    elseif isoutput then
+      outfile = v
+      isoutput = false
+    elseif v == "-i" then
+      isinput = true
+    elseif v == "-o" then
+      isoutput = true
+    else
+      insert(reallist, v)
+    end
+  end
+  return reallist
+end
+
 local function parseArgList(arglist)
+  local reallist = readArgList(arglist)
   local namelist = {}
   local nametype = nil
-  for _, v in ipairs(arglist) do
-    if v == "-f" then
-      nametype = "file"
-    elseif v == "-c" then
+  for _, v in ipairs(reallist) do
+    if v == "-c" then
       nametype = "cmd"
     elseif v == "-e" then
       nametype = "env"
+    elseif v == "-f" then
+      nametype = "file"
+    elseif v == "-p" then
+      nametype = "pkg"
     else
       if nametype then
         insert(namelist, {nametype, v})
@@ -568,9 +680,12 @@
    version      Print version information and exit
 
 valid options are:
-   -f           Query or install by file name
    -c           Query or install by command name
    -e           Query or install by environment name
+   -f           Query or install by file name
+   -p           Query or install by package name
+   -i           Read arguments line by line from a file
+   -o           Write total dependent list to a file
 
 please report bug at https://github.com/lvjr/texfindpkg
 ]]

Modified: trunk/Master/texmf-dist/doc/man/man1/texfindpkg.1
===================================================================
--- trunk/Master/texmf-dist/doc/man/man1/texfindpkg.1	2024-11-22 21:52:42 UTC (rev 72936)
+++ trunk/Master/texmf-dist/doc/man/man1/texfindpkg.1	2024-11-22 21:52:55 UTC (rev 72937)
@@ -1,4 +1,4 @@
-.TH texfindpkg 1 "2023-05-05" "2023E"
+.TH texfindpkg 1 "2024-11-22" "2024A"
 .SH NAME
 TexFindPkg \- Query or install TeX packages and their dependencies
 .SH SYNOPSIS
@@ -18,12 +18,14 @@
 Print version information and exit
 .SH OPTIONS
 Various options apply
-.IP -f 6
-Query or install packages by file name
 .IP -c 6
 Query or install packages by command name
 .IP -e 6
 Query or install packages by environment name
+.IP -f 6
+Query or install packages by file name
+.IP -p 6
+Query or install packages by package name
 .SH BUGS
 Please log issues on
 https://github.com/lvjr/texfindpkg/issues

Modified: trunk/Master/texmf-dist/doc/man/man1/texfindpkg.man1.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/doc/support/texfindpkg/README.md
===================================================================
--- trunk/Master/texmf-dist/doc/support/texfindpkg/README.md	2024-11-22 21:52:42 UTC (rev 72936)
+++ trunk/Master/texmf-dist/doc/support/texfindpkg/README.md	2024-11-22 21:52:55 UTC (rev 72937)
@@ -2,7 +2,7 @@
 
 ```
 Description: Query or Install TeX packages and their dependencies
-Copyright: 2023 (c) Jianrui Lyu <tolvjr at 163.com>
+Copyright: 2023-2024 (c) Jianrui Lyu <tolvjr at 163.com>
 Repository: https://github.com/lvjr/texfindpkg
 License: GNU General Public License v3.0
 ```
@@ -23,7 +23,7 @@
 | texfindpkg.1       | TEXMF/doc/man/man1/texfindpkg.1 |
 | README.md          | TEXMF/doc/support/texfindpkg/README.md |
 | texfindpkg.lua     | TEXMF/scripts/texfindpkg/texfindpkg.lua |
-| texfindpkg.json.gz | TEXMF/scripts/texfindpkg/texfindpkg.json.gz |
+| texfindpkg.json.gz | TEXMF/tex/latex/texfindpkg/texfindpkg.json.gz |
 | tfpbuild.lua       | TEXMF/source/texfindpkg/tfpbuild.lua |
 
 Then you could create a symbolic link from `/usr/local/bin/texfindpkg` to `path/to/texfindpkg.lua` on Linux or MacOS,
@@ -45,14 +45,47 @@
 The `<action>` could be `query`, `install`, `help` or `version`.
 The leading dashes in any `<action>` will be removed first.
 
-For `query` action, you pass `-f`, `-c` or `-e` as `<option>`
-to indicate the following `<name>` is a file name, command name or environment name.
-For example,
-
+For `query` action, you pass `-c`, `-e`, `-f` or `-p` as `<option>`
+to indicate the following `<name>` is a command name, environment name, file name or package name.
+For example (for `-f` option, you can omit file extension in the name if it is `.sty`),
+- `texfindpkg query -c fakeverb` means querying package with command `\fakeverb`;
+- `texfindpkg query -e frame` means querying package with environment `{frame}`;
 - `texfindpkg query -f array.sty` means querying package with file `array.sty`;
-- `texfindpkg query -c fakeverb` means querying package with command `\fakeverb`;
-- `texfindpkg query -e frame` means querying package with environment `{frame}`.
+- `texfindpkg query -p caption` means querying LaTeX packages in TeXLive/MiKTeX package `caption`.
 
+You can query a lot of names in one go. For example,
+```
+texfindpkg query -c fakeverb -e verbatim tblr -f array longtable -p caption
+```
+
+When you have a lot of names to query, you may want to list them in a file and use `-i` option to insert them.
+For example, if you have a file `input.txt` of lines (comments starting with `#` characters are ignored in it)
+```
+-c
+fakeverb
+-e
+verbatim
+tblr
+-f
+array
+longtable
+-p
+caption
+```
+then the following command produces the same result as the previous one does:
+```
+texfindpkg query -i input.txt
+```
+
+Furthermore you can save total dependent list of packages to a file with `-o` option:
+```
+texfindpkg query -i input.txt -o output.txt
+```
+
+With `-i` and `-o` options, it is quite easy to install a minimal TeXLive distribution with all dependencies resolved,
+which is useful for you to run regression tests with GitHub Actions if you are a package writer.
+Please see `latex-package.txt` and `texlive-package.txt` in [tabularray](https://github.com/lvjr/tabularray/tree/main/.github/workflows) repository for a practical example.
+
 The only difference between `query` and `install` actions is that
 with `install` action TeXFindPkg will install missing TeXLive or MiKTeX packages at the end.
 

Modified: trunk/Master/texmf-dist/scripts/texfindpkg/texfindpkg.lua
===================================================================
--- trunk/Master/texmf-dist/scripts/texfindpkg/texfindpkg.lua	2024-11-22 21:52:42 UTC (rev 72936)
+++ trunk/Master/texmf-dist/scripts/texfindpkg/texfindpkg.lua	2024-11-22 21:52:55 UTC (rev 72937)
@@ -1,14 +1,14 @@
 #!/usr/bin/env texlua
 
 -- Description: Install TeX packages and their dependencies
--- Copyright: 2023 (c) Jianrui Lyu <tolvjr at 163.com>
+-- Copyright: 2023-2024 (c) Jianrui Lyu <tolvjr at 163.com>
 -- Repository: https://github.com/lvjr/texfindpkg
 -- License: GNU General Public License v3.0
 
 local tfp = tfp or {}
 
-tfp.version = "2023E"
-tfp.date = "2023-05-05"
+tfp.version = "2024A"
+tfp.date = "2024-11-22"
 
 local building = tfp.building
 local tfpresult = ""
@@ -135,7 +135,8 @@
   end
 end
 
-local tlpkgdata = {}
+local tlfiletopkg = {}
+local tlpkgtofile = {}
 local tlinspkgdata = {}
 
 local function tlExtractFiles(name, desc)
@@ -147,12 +148,15 @@
   end
   -- ignore package files in doc folder
   desc = match(desc, "\nrunfiles .+") or ""
+  local flist = {}
   for base, ext in gmatch(desc, "/([%a%d%-%.]+)%.([%a%d]+)\n") do
     if ext == "sty" or ext == "cls" or ext == "tex" or ext == "ltx" then
       dbgPrint(name, base .. "." .. ext)
-      tlpkgdata[base .. "." .. ext] = name
+      tlfiletopkg[base .. "." .. ext] = name
+      insert(flist, base .. "." .. ext)
     end
   end
+  tlpkgtofile[name]= flist
 end
 
 local function tlExtractPackages(name, desc)
@@ -161,7 +165,7 @@
 
 local function tlParsePackageDB(tlpkgtext)
   gsub(tlpkgtext, "name (.-)\n(.-)\n\n", tlExtractFiles)
-  return tlpkgdata
+  return tlfiletopkg
 end
 
 local function tlParseTwoPackageDB()
@@ -193,7 +197,8 @@
   end
 end
 
-local mtpkgdata = {}
+local mtfiletopkg = {}
+local mtpkgtofile = {}
 local mtinspkgdata = {}
 
 local function mtExtractFiles(name, desc)
@@ -203,12 +208,15 @@
     --print(name)
     return
   end
+  local flist = {}
   for base, ext in gmatch(desc, "/([%a%d%-%.]+)%.([%a%d]+)\r?\n") do
     if ext == "sty" or ext == "cls" or ext == "tex" or ext == "ltx" then
       dbgPrint(name, base .. "." .. ext)
-      mtpkgdata[base .. "." .. ext] = name
+      mtfiletopkg[base .. "." .. ext] = name
+      insert(flist, base .. "." .. ext)
     end
   end
+  mtpkgtofile[name]= flist
 end
 
 local function mtExtractPackages(name, desc)
@@ -218,7 +226,7 @@
 local function mtParsePackageDB(mtpkgtext)
   -- package-manifests.ini might use different eol characters
   gsub(mtpkgtext, "%[(.-)%]\r?\n(.-)\r?\n\r?\n", mtExtractFiles)
-  return mtpkgdata
+  return mtfiletopkg
 end
 
 local function mtParseTwoPackageDB()
@@ -232,6 +240,7 @@
 ------------------------------------------------------------
 
 local dist               -- name of current tex distribution
+local totaldeplist = {}  -- list of all depending packages
 local totalinslist = {}  -- list of all missing packages
 local filecount = 0      -- total number of files found
 
@@ -247,14 +256,22 @@
   end
 end
 
-local function findOnePackage(fname)
+local function findPackageFromFile(fname)
   if dist == "texlive" then
-    return tlpkgdata[fname]
+    return tlfiletopkg[fname]
   else
-    return mtpkgdata[fname]
+    return mtfiletopkg[fname]
   end
 end
 
+local function findFilesInPackage(pkg)
+  if dist == "texlive" then
+    return tlpkgtofile[pkg]
+  else
+    return mtpkgtofile[pkg]
+  end
+end
+
 local function checkInsPakage(pkg)
   if dist == "texlive" then
     return tlinspkgdata[pkg]
@@ -284,6 +301,8 @@
     end
     tfpExecute("tlmgr install " .. pkgs)
   else
+    -- miktex fails if one of the packages is already installed
+    -- so we install miktex packages one by one
     for _, p in ipairs(list) do
       tfpRealPrint("installing miktex package: " .. p)
       tfpExecute("miktex packages install " .. p)
@@ -308,6 +327,7 @@
   if #list > 0 then
     filecount = filecount + 1
   end
+  table.sort(list)
   local pkgs = concat(list, " ")
   if #list == 1 then
     tfpPrint(dist .. " package needed: " .. pkgs)
@@ -327,6 +347,7 @@
       tfpRealPrint("these packages are already installed")
     end
   else
+    table.sort(inslist)
     local pkgs = concat(inslist, " ")
     if #inslist == 1 then
       tfpRealPrint(dist .. " package not yet installed: " .. pkgs)
@@ -359,12 +380,15 @@
 
 local function printDependency(fname, level)
   local msg = fname
-  local pkg = findOnePackage(fname)
+  local pkg = findPackageFromFile(fname)
   if pkg then
     msg = msg .. " (from " .. pkg .. ")"
     if not valueExists(pkglist, pkg) then
       insert(pkglist, pkg)
     end
+    if not valueExists(totaldeplist, pkg) then
+      insert(totaldeplist, pkg)
+    end
   else
     msg = msg .. " (not found)"
   end
@@ -397,6 +421,9 @@
 
 local function queryByFileName(fname)
   fnlist, pkglist = {}, {} -- reset the list
+  if not find(fname, "%.") then
+    fname = fname .. ".sty"
+  end
   tfpPrint("building dependency tree for " .. fname .. ":")
   tfpPrint(rep("-", 24))
   findDependencies(fname, 0)
@@ -412,6 +439,28 @@
   listSomePackages(pkglist)
 end
 
+local function queryByPackageName(pname)
+  local list = findFilesInPackage(pname)
+  if list == nil then
+    tfpPrint(dist .. " package " .. pname .. " doesn't exist")
+    return
+  end
+  if #list > 0 then
+    tfpPrint("finding package files in " .. dist .. " package " .. pname)
+    for _, fname in ipairs(list) do
+      tfpPrint(rep("=", 48))
+      tfpPrint("found package file " .. fname .. " in " .. dist .. " package " .. pname)
+      queryByFileName(fname)
+    end
+  else
+    tfpPrint("could not find any package file in " .. dist .. " package " .. pname)
+    listSomePackages({pname})
+    if not valueExists(totaldeplist, pname) then
+      insert(totaldeplist, pname)
+    end
+  end
+end
+
 local function getFileNameFromCmdEnvName(cmdenv, name)
   --print(name)
   local flist = {}
@@ -465,11 +514,14 @@
   elseif t == "file" then
     tfpPrint(rep("=", 48))
     queryByFileName(name)
-  else
-    -- do something for t == "pkg"
+  else -- t == "pkg"
+    tfpPrint(rep("=", 48))
+    queryByPackageName(name)
   end
 end
 
+local outfile = nil
+
 local function query(namelist)
   for _, v in ipairs(namelist) do
     queryOne(v[1], v[2])
@@ -476,12 +528,30 @@
   end
   if filecount > 1 then
     tfpRealPrint(rep("=", 48))
+    table.sort(totaldeplist)
+    local pkgs = concat(totaldeplist, " ")
+    if #totaldeplist == 0 then
+      --tfpRealPrint("no packages needed are found")
+    elseif #totaldeplist == 1 then
+      tfpRealPrint(dist .. " package needed in total: " .. pkgs)
+    else
+      tfpRealPrint(dist .. " packages needed in total: " .. pkgs)
+    end
+    tfpRealPrint(rep("=", 48))
+    table.sort(totalinslist)
     local pkgs = concat(totalinslist, " ")
-    if #totalinslist == 1 then
+    if #totalinslist == 0 then
+      tfpRealPrint("you don't need to install any packages")
+    elseif #totalinslist == 1 then
       tfpRealPrint(dist .. " package not yet installed in total: " .. pkgs)
     else
       tfpRealPrint(dist .. " packages not yet installed in total: " .. pkgs)
     end
+    if outfile then
+      --print(outfile)
+      pkgs = concat(totaldeplist, "\n")
+      fileWrite(pkgs, outfile)
+    end
   end
 end
 
@@ -515,16 +585,58 @@
   end
 end
 
+local function readArgsInFile(list, inname)
+  local intext = fileRead(inname)
+  if not intext then
+    tfpPrint("error in reading input file " .. inname)
+    return list
+  end
+  tfpPrint("reading input file " .. inname)
+  for line in gmatch(intext, "%s*(.-)%s*\r?\n") do
+    line = match(line, "(.-)%s*#") or line
+    --print("|" .. line .. "|")
+    if line ~= "" then
+      insert(list, line)
+    end
+  end
+  return list
+end
+
+local function readArgList(arglist)
+  local reallist = {}
+  local isinput = false
+  local isoutput = false
+  for _, v in ipairs(arglist) do
+    if isinput then
+      reallist = readArgsInFile(reallist, v)
+      isinput = false
+    elseif isoutput then
+      outfile = v
+      isoutput = false
+    elseif v == "-i" then
+      isinput = true
+    elseif v == "-o" then
+      isoutput = true
+    else
+      insert(reallist, v)
+    end
+  end
+  return reallist
+end
+
 local function parseArgList(arglist)
+  local reallist = readArgList(arglist)
   local namelist = {}
   local nametype = nil
-  for _, v in ipairs(arglist) do
-    if v == "-f" then
-      nametype = "file"
-    elseif v == "-c" then
+  for _, v in ipairs(reallist) do
+    if v == "-c" then
       nametype = "cmd"
     elseif v == "-e" then
       nametype = "env"
+    elseif v == "-f" then
+      nametype = "file"
+    elseif v == "-p" then
+      nametype = "pkg"
     else
       if nametype then
         insert(namelist, {nametype, v})
@@ -568,9 +680,12 @@
    version      Print version information and exit
 
 valid options are:
-   -f           Query or install by file name
    -c           Query or install by command name
    -e           Query or install by environment name
+   -f           Query or install by file name
+   -p           Query or install by package name
+   -i           Read arguments line by line from a file
+   -o           Write total dependent list to a file
 
 please report bug at https://github.com/lvjr/texfindpkg
 ]]

Modified: trunk/Master/texmf-dist/source/support/texfindpkg/tfpbuild.lua
===================================================================
--- trunk/Master/texmf-dist/source/support/texfindpkg/tfpbuild.lua	2024-11-22 21:52:42 UTC (rev 72936)
+++ trunk/Master/texmf-dist/source/support/texfindpkg/tfpbuild.lua	2024-11-22 21:52:55 UTC (rev 72937)
@@ -1,7 +1,7 @@
 #!/usr/bin/env texlua
 
 -- Description: Install TeX packages and their dependencies
--- Copyright: 2023 (c) Jianrui Lyu <tolvjr at 163.com>
+-- Copyright: 2023-2024 (c) Jianrui Lyu <tolvjr at 163.com>
 -- Repository: https://github.com/lvjr/texfindpkg
 -- License: GNU General Public License v3.0
 
@@ -104,7 +104,34 @@
 
 local cwldata = {}
 
+-- Ignore lines after "# from xxx option of somepkg", see #7
+local function ignoreCmdsFromOptions(cwl)
+  local result = ""
+  local isignored = false
+  for line in gmatch(cwl .. "\n\n", "([^\r\n]-)\r?\n") do
+    if not isignored then
+      if match(line, "# from [^ ]+ option of [^ ]+") then
+        isignored = true
+        --print("start ignoring: " .. line)
+      else
+        result = result .. line .. "\n"
+      end
+    else
+      if match(line, "^ -$") or match(line, "^#endif$") then
+        isignored = false
+        --print("stop ignoring: " .. line)
+      end
+    end
+  end
+  if isignored then
+    dbgPrint("missing stop point!")
+  end
+  --print(result)
+  return result
+end
+
 local function extractFileData(cwl)
+  cwl = ignoreCmdsFromOptions(cwl)
   -- the cwl files have different eol characters
   local deps = {}
   for base in gmatch(cwl, "\n#include:(.-)[\r\n]") do

Modified: trunk/Master/texmf-dist/tex/latex/texfindpkg/texfindpkg.json.gz
===================================================================
(Binary files differ)



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