-- tex4ht-findhtf.lua (2026-12-03-12:45), generated from tex4ht-4ht.tex -- Copyright 2026 TeX Users Group --[[ % % This work may be distributed and/or modified under the % conditions of the LaTeX Project Public License, either % version 1.3c of this license or (at your option) any % later version. The latest version of this license is in % http://www.latex-project.org/lppl.txt % and version 1.3c or later is part of all distributions % of LaTeX version 2005/12/01 or later. % % This work has the LPPL maintenance status "maintained". % % The Current Maintainer of this work % is the TeX4ht Project . % % If you modify this program, changing the % version identification would be appreciated. \immediate\write-1{version 2026-12-03-12:45} --]] -- the TEXMF paths returned by kpse.expand_var are in the form of multiple directories separated by comma. we need to return these, where the tex4ht/htf-fonts directory exists local function get_valid_htf_paths(texmf) local paths = {} -- the text in texmf variable is surrounded by { }, we need to remove it texmf = texmf:gsub("{", ""):gsub("}", "") for path in string.gmatch(texmf, "([^,]+)") do -- some paths also contain !! at the start, we need to remove that too path = path:gsub("!!", "") -- unicode contains char tables, alias contains pointers from other supported fonts to unicode tables for _, subpath in ipairs {"unicode", "alias"} do local htf_path = path .. "/tex4ht/ht-fonts/" .. subpath if lfs.attributes(htf_path, "mode") == "directory" then paths [#paths + 1] = htf_path end end end -- the paths need to be reversed, as user's TEXMF variable is searched in reverse order local new_paths = {} for i = #paths, 1, -1 do new_paths[#new_paths + 1] = paths[i] end return new_paths end -- this function needs to search for .htf files in the given path and add them to the htf_files table. if search_subdir is true, it also needs to search in subdirectories local function find_htf_in_dir(path, htf_files, search_subdir) for file in lfs.dir(path) do if file:match("%.htf$") then local without_suffix = file:gsub("%.htf$", "") htf_files[without_suffix] = path .. "/" .. file elseif search_subdir and lfs.attributes(path .. "/" .. file, "mode") == "directory" and file ~= "." and file ~= ".." then find_htf_in_dir(path .. "/" .. file, htf_files, search_subdir) end end return htf_files end -- we need to find all HTF files that are stored in subdirectories of the value of TEXMF needs to be retrieved using the kpse library -- the recursive search for .htf files needs to be done using luafilesystem local function find_htf_files() local htf_files = {} local texmf = kpse.expand_var("$TEXMF") local valid_paths = get_valid_htf_paths(texmf) -- now we need to search for .htf files in the valid paths for _, path in ipairs(valid_paths) do find_htf_in_dir(path, htf_files, true) end -- we need to search in the current directory too find_htf_in_dir(".", htf_files, false) return htf_files end local htf_files = find_htf_files() return htf_files