diff options
author | Karl Berry <karl@freefriends.org> | 2020-03-03 23:05:59 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2020-03-03 23:05:59 +0000 |
commit | a5b08d6e4f20abd36645525e5907068dd1b6743b (patch) | |
tree | 21aa21d4a848402205fe76fe50fee254e805cbc0 /Master/texmf-dist/scripts/make4ht/make4ht-indexing.lua | |
parent | bb0d98952d1aee8d64d8f04a6352b4b761955ed4 (diff) |
make4ht (1mar20)
git-svn-id: svn://tug.org/texlive/trunk@54053 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/scripts/make4ht/make4ht-indexing.lua')
-rwxr-xr-x | Master/texmf-dist/scripts/make4ht/make4ht-indexing.lua | 55 |
1 files changed, 53 insertions, 2 deletions
diff --git a/Master/texmf-dist/scripts/make4ht/make4ht-indexing.lua b/Master/texmf-dist/scripts/make4ht/make4ht-indexing.lua index 072536556a8..a86fd139aa2 100755 --- a/Master/texmf-dist/scripts/make4ht/make4ht-indexing.lua +++ b/Master/texmf-dist/scripts/make4ht/make4ht-indexing.lua @@ -142,8 +142,12 @@ local process_index = function(indname, idx) return true end +local get_idxname = function(par) + return par.idxfile or par.input .. ".idx" +end + local prepare_tmp_idx = function(par) - par.idxfile = par.idxfile or par.input .. ".idx" + par.idxfile = get_idxname(par) -- construct the .ind name, based on the .idx name par.indfile = par.indfile or par.idxfile:gsub("idx$", "ind") load_enc() @@ -156,10 +160,56 @@ local prepare_tmp_idx = function(par) return newidxfile, idxdata end -local run_indexing_command = function(command, par) + +local splitindex = function(par) + local files = {} + local idxfiles = {} + local buffer + local idxfile = get_idxname(par) + for line in io.lines(idxfile) do + local file = line:match("indexentry%[(.-)%]") + if file then + -- generate idx name for the current output file + file = par.input .. "-" ..file .. ".idx" + local current = files[file] or {} + -- remove file name from the index entry + local indexentry = line:gsub("indexentry%[.-%]", "indexentry") + -- save the index entry and preseding line to the current buffer + table.insert(current, buffer) + table.insert(current, indexentry) + files[file] = current + end + -- + buffer = line + end + -- save idx files + for filename, contents in pairs(files) do + log:info("Saving split index file: " .. filename) + idxfiles[#idxfiles+1] = filename + local f = io.open(filename, "w") + f:write(table.concat(contents, "\n")) + f:close() + end + return idxfiles +end + +local function run_indexing_command (command, par) -- detect command name from the command. It will be the first word local cmd_name = command:match("^[%a]+") or "indexing" local xindylog = logging.new(cmd_name) + -- support split index + local subindexes = splitindex(par) + if #subindexes > 0 then + -- call the command again on all files produced by splitindex + for _, subindex in ipairs(subindexes) do + -- make copy of the parameters + local t = {} + for k,v in pairs(par) do t[k] = v end + t.idxfile = subindex + run_indexing_command(command, t) + end + return nil + end local newidxfile, idxdata = prepare_tmp_idx(par) if not newidxfile then -- the idxdata will contain error message in the case of error @@ -182,6 +232,7 @@ local run_indexing_command = function(command, par) par.indfile = nil end + M.get_utf8 = get_utf8 M.load_enc = load_enc M.parse_idx = parse_idx |