Skip to content

Commit

Permalink
support other index locators
Browse files Browse the repository at this point in the history
  • Loading branch information
michal-h21 committed Dec 8, 2024
1 parent 3392b16 commit baee50f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
# Changelog

- 2024/12/08

- support other index locators than index command counters.
https://tex.stackexchange.com/a/732446/2891

- 2024/12/05

- recognize inline math and comments as inline content in the `fixinlines` DOM filter.

- 2024/11/09

- fixed `tablerows` for longtables longer than 200 rows.
https://tex.stackexchange.com/a/730466/2891
https://tex.stackexchange.com/a/730466/2891

- 2024/10/22

Expand Down
11 changes: 7 additions & 4 deletions make4ht-indexing.lua
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,11 @@ local parse_idx = function(content)
if line:match("^\\beforeentry") then
-- increment index entry number
current_entry = current_entry + 1
local file, dest = line:match("\\beforeentry%s*{(.-)}{(.-)}")
map[current_entry] = {file = file, dest = dest}
local file, dest, locator = line:match("\\beforeentry%s*{(.-)}{(.-)}{(.-)}")
-- if the third argument to \beforeentry is not empty,
-- use it as a index entry locator instead of the index counter
if locator and locator == "" then locator = nil end
map[current_entry] = {file = file, dest = dest, locator = locator}
elseif line:match("^\\indexentry") then
-- replace the page number with the current
-- index entry number
Expand All @@ -93,9 +96,10 @@ end

-- replace numbers in .ind file with links back to text
local function replace_index_pages(rest, entries)
return rest:gsub("(%{?%d+%}?)", function(page)
return rest:gsub("%{?(%d+)%}?", function(page)
local entry = entries[tonumber(page)]
if entry then
page = entry.locator or page
-- construct link to the index entry
return "\\Link[" .. entry.file .."]{".. entry.dest .."}{}" .. page .."\\EndLink{}"
else
Expand Down Expand Up @@ -123,7 +127,6 @@ local fix_idx_pages = function(content, idxobj)
return replace_index_pages(rest, entries)
end)
end
print(line)
buffer[#buffer+1] = line
end
return table.concat(buffer, "\n")
Expand Down

0 comments on commit baee50f

Please sign in to comment.