summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/scripts/make4ht/make4ht-indexing.lua
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2023-02-24 21:33:48 +0000
committerKarl Berry <karl@freefriends.org>2023-02-24 21:33:48 +0000
commit9668d7af73978ef4f35305fef6788411da9db46e (patch)
treece26d92681e19e56db990815887e6d6011c9856e /Master/texmf-dist/scripts/make4ht/make4ht-indexing.lua
parent177a37a680764ab3656cb80500c0bf5c1b4e7436 (diff)
make4ht (24feb23)
git-svn-id: svn://tug.org/texlive/trunk@66130 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/scripts/make4ht/make4ht-indexing.lua')
-rwxr-xr-xMaster/texmf-dist/scripts/make4ht/make4ht-indexing.lua11
1 files changed, 8 insertions, 3 deletions
diff --git a/Master/texmf-dist/scripts/make4ht/make4ht-indexing.lua b/Master/texmf-dist/scripts/make4ht/make4ht-indexing.lua
index eb9c9b50172..746c062cb31 100755
--- a/Master/texmf-dist/scripts/make4ht/make4ht-indexing.lua
+++ b/Master/texmf-dist/scripts/make4ht/make4ht-indexing.lua
@@ -80,7 +80,7 @@ local parse_idx = function(content)
elseif line:match("^\\indexentry") then
-- replace the page number with the current
-- index entry number
- local result = line:gsub("{[0-9]+}", "{"..current_entry .."}")
+ local result = line:gsub("{[0-9]+}$", "{"..current_entry .."}")
buffer[#buffer+1] = get_utf8(result)
else
buffer[#buffer+1] = line
@@ -96,11 +96,14 @@ local fix_idx_pages = function(content, idxobj)
local entries = idxobj.map
for line in content:gmatch("([^\n]+)") do
local line = line:gsub("(%s*\\%a+.-%,)(.+)$", function(start,rest)
+ -- there is a problem when index term itself contains numbers, like Bible verses (1:2),
+ -- because they will be detected as page numbers too. I cannot find a good solution
+ -- that wouldn't break something else.
return start .. rest:gsub("(%d+)", function(page)
local entry = entries[tonumber(page)]
if entry then
-- construct link to the index entry
- return "\\Link[" .. entry.file .."]{".. entry.dest .."}{}" .. page .."\\EndLink{}"
+ return "\\Link[" .. entry.file .."]{".. entry.dest .."}{}" .. page .."\\EndLink{}"
else
return page
end
@@ -148,6 +151,7 @@ end
local prepare_tmp_idx = function(par)
par.idxfile = get_idxname(par)
+ if not par.idxfile or not mkutils.file_exists(par.idxfile) then return nil, "Cannot load idx file " .. (par.idxfile or "''") end
-- construct the .ind name, based on the .idx name
par.indfile = par.indfile or par.idxfile:gsub("idx$", "ind")
load_enc()
@@ -166,6 +170,7 @@ local splitindex = function(par)
local idxfiles = {}
local buffer
local idxfile = get_idxname(par)
+ if not idxfile or not mkutils.file_exists(idxfile) then return nil, "Cannot load idx file " .. (idxfile or "''") end
for line in io.lines(idxfile) do
local file = line:match("indexentry%[(.-)%]")
if file then
@@ -198,7 +203,7 @@ local function run_indexing_command (command, par)
local cmd_name = command:match("^[%a]+") or "indexing"
local xindylog = logging.new(cmd_name)
-- support split index
- local subindexes = splitindex(par)
+ local subindexes = splitindex(par) or {}
if #subindexes > 0 then
-- call the command again on all files produced by splitindex
for _, subindex in ipairs(subindexes) do