finding locations of many files via kpse

Erik Nijenhuis erik at xerdi.com
Wed Jul 3 15:00:05 CEST 2024


Hi Norbert,

On Wed, 2024-07-03 at 21:08 +0900, Norbert Preining wrote:
> In my case, all files are to be opened by LaTeX and all options would be
> the same, so that would be fine, but ...

I can think of another way, by extending the command line options with a Lua
init script. (Maybe the gitinfo-lua example isn't much of a good example after
all)

This way, you could pass the files as command line arguments, handle it in a Lua
init script, and continue using the default behavior of LuaHBLaTeX, I think?

I have an example for that, requiring files in an early stage to pass to lua-
placeholders (yaml files). The below init script handles some parameters of
those:
```
if not modules then
    modules = {}
end

modules.xdp = {
    name        = 'xdp',
    version     = '0.0.1',      --TAGVERSION
    date        = '2023-12-20', --TAGDATE
    description = "Xerdi's Documentation Project — Utilities for LuaLaTeX",
    author      = 'Erik Nijenhuis',
    license     = 'Copyright 2023 Xerdi'
}

local api = {
    placeholders = require('lua-placeholders'),
    git = require('gitinfo-lua')
}

for _, a in ipairs(arg) do
    if string.find(a, '-+recipe=.*') then
        local recipe_file = string.gsub(a, '-+recipe=(.*)', '%1')
        api.placeholders.recipe(recipe_file)
        texio.write_nl("Info: loading recipe '" .. recipe_file .. "'.\n")
    end
    if string.find(a, '-+payload=.*') then
        local payload_file = string.gsub(a, '-+payload=(.*)', '%1')
        api.placeholders.payload(payload_file)
        texio.write_nl("Info: loading payload '" .. payload_file .. "'.\n")
    end
    if string.find(a, '-+final') then
        api.placeholders.set_strict()
    end
    if string.find(a, '-+gitdir=.*') then
        local git_dir = string.gsub(a, '-+gitdir=(.*)', '%1')
        api.git:dir(git_dir)
        texio.write_nl('Info: using git directory "' .. git_dir .. '"')
    end
end
texio.write_nl('\n')

function api.replace(str, search, replace)
    return string.gsub(str, '%s*' .. search .. '%s*', replace or '')
end

function api.for_csv(str, replace)
    return api.replace(str, '%s*,%s*', replace)
end

local xdp = {}
local xdp_mt = {
    __index = api,
    __newindex = nil
}
setmetatable(xdp, xdp_mt)

return xdp
```
If you may find that useful, I have a corresponding Bash script for it as well,
which builds up the command.

> Nice, great, thanks a lot. Honestly, I liked the idea of a texlua script
> because it is (1) a scripting language so easy to develop and test, and
> move to other computers, and (2) it uses direct library calls.
This one can be used with lualatex i.o. texlua. However, handling the command
line arguments in Lua will be the same, I presume.

Kind regards, Erik



More information about the texhax mailing list.