summaryrefslogtreecommitdiff
path: root/indexing/xindex/lualatex/xindex-lib.lua
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2023-07-07 03:00:56 +0000
committerNorbert Preining <norbert@preining.info>2023-07-07 03:00:56 +0000
commit2178d699db60492a15e11c107f17da33543af865 (patch)
tree157f2907e3778e17df8a7e891bc276b83b444f48 /indexing/xindex/lualatex/xindex-lib.lua
parent97f4d34e17013b3239a49484afcb3d805ab09f38 (diff)
CTAN sync 202307070300
Diffstat (limited to 'indexing/xindex/lualatex/xindex-lib.lua')
-rw-r--r--indexing/xindex/lualatex/xindex-lib.lua51
1 files changed, 41 insertions, 10 deletions
diff --git a/indexing/xindex/lualatex/xindex-lib.lua b/indexing/xindex/lualatex/xindex-lib.lua
index 97ede6b8fc..f321765c64 100644
--- a/indexing/xindex/lualatex/xindex-lib.lua
+++ b/indexing/xindex/lualatex/xindex-lib.lua
@@ -9,7 +9,7 @@
-----------------------------------------------------------------------
if not modules then modules = { } end modules ['xindex-lib'] = {
- version = 0.48,
+ version = 0.49,
comment = "main library to xindex.lua",
author = "Herbert Voss",
copyright = "Herbert Voss",
@@ -125,7 +125,8 @@ function read_lines_from(infile)
str = line:gsub('^\\%a+%s*{','{') -- remove "\\indexentry "
writeLog(1,"read_lines: str="..str.." ("..utf.sub(str,2,2)..")\n",2)
if getCharType(utf.sub(str,2,2)) == 0 then -- we have a symbol
- lines[#lines + 1] = str:gsub('^{*','{ ') -- add a space before the symbol
+ lines[#lines + 1] = str:gsub('^{*','{') -- add a space ... why????
+-- lines[#lines + 1] = str:gsub('^{*','{ ') -- add a space before the symbol
else
lines[#lines + 1] = str
end
@@ -275,6 +276,7 @@ function getEntryAndPage(w, nextW, EntryList)
sortChar= NormalizedUpper(utf.sub(IndexString,1,1)), -- :byte(), -- Initial for later output
Macro = macro
}
+ --print("Entry:"..EntryList[#EntryList]["sortChar"])
if args_v then
if Special == "" then Special = "-" end
writeLog(1,"getEntryAndPage: "..tostring(IndexString,pageNo,Special,utf.sub(IndexString,1,1),macro).."\n",2)
@@ -318,7 +320,7 @@ end
--[[ example entry
EntryList[2] = {
- Entry = "Johann", -- the index item foo@bar
+ Entry = 'Johann//escapedexcl//', -- the index item foo@bar
pages = { -- the page number(s) and the part after |
{ number = 111,
special = '\\emph' },
@@ -502,6 +504,19 @@ function getCharType(c)
end
end
+function findStr(s,f)
+ if s == nil then return 99999 end
+ str = s:match'^%s*(.*)' -- strip left spaces
+-- s:gsub("%s+", "")-- strip spaces
+-- print(s,f)
+ local i,j = str:find(f)
+-- print(tostring(i),tostring(j))
+ if i == nil
+ then return 99999 -- makes it easier to compare with <
+ else return i
+ end
+end
+
--print(get_category(utf8.codepoint('ö')))
--print(category_to_number(get_category(utf8.codepoint('ö'))))
@@ -532,22 +547,36 @@ function GenerateSortKey(a)
if ignoreSpace then
a["SortKey"] = A:gsub("%s+", "") -- remove spaces
else
- a["SortKey"] = A
+ a["SortKey"] = A:match'^%s*(.*)' -- strip only left spaces
end
else
A = NormalizedChars(getSortString(a["Entry"].." "..Apage..a["pages"][1]["special"]):gsub('!',' ')) -- replace! by empty
if ignoreSpace then
a["SortKey"] = A:gsub("%s+", "")-- remove spaces
else
- a["SortKey"] = A
+ a["SortKey"] = A:match'^%s*(.*)' -- strip only left spaces
end
end
- -- print(a["SortKey"])
- -- return A
+-- s:gsub("%s+", "") strip spaces
+ if findStr(a["SortKey"],"\\parenLeft") < 2 then a["SortKey"] = '{ '..Apage end
+ if findStr(a["SortKey"],"\\parenRight") < 2 then a["SortKey"] = '} '..Apage end
+ if findStr(a["SortKey"],"//escapedexcl//") < 2 then a["SortKey"] = '! '..Apage end
+ if findStr(a["SortKey"],"//escapedquote//") < 2 then a["SortKey"] = '" '..Apage end
+ if findStr(a["SortKey"],"//escapedat//") < 2 then a["SortKey"] = '@ '..Apage end
+ if findStr(a["SortKey"],"//escapedvert//") < 2 then a["SortKey"] = '| '..Apage end
+ -- a["SortKey"] = a["SortKey"]:gsub("%s+", "")
+ -- print("Sortkey: " .. a["SortKey"])
+ if not use_UCA then -- test if it is a symbol after 9 and before A or after Z
+ if (a["SortKey"]:byte() > 57 and a["SortKey"]:byte() < 65) or
+ (a["SortKey"]:byte() > 122 and a["SortKey"]:byte() < 128) then -- symbol above digits
+ a["SortKey"] = "/"..a["SortKey"] -- sort it after /
+ end
+ end
end
function GenerateSortKeys(Index)
for _, entry in ipairs(Index) do
+-- print("<<".._..entry["Entry"])
GenerateSortKey(entry)
end
end
@@ -555,12 +584,13 @@ end
function UTFCompare(a,b)
local A = a["SortKey"]
local B = b["SortKey"]
- writeLog(1,"UTFCompare: A--B "..A.."--"..B.."\n",2)
if use_UCA then
- return collator_obj:compare_strings(A,B)
+ compare = collator_obj:compare_strings(A,B)
else
- return A<B
+ compare = A<B
end
+ writeLog(1,"UTFCompare: A--B "..A.."--"..B.."A<B:"..tostring(compare).."\n",2)
+ return compare
end
@@ -923,6 +953,7 @@ function getSortChar(codepoints)
return getSortChar(codepoints)
end
local sort_char = utf8.char(table.unpack(codes))
+ --print("SortChar:"..sort_char)
-- print unicode category of the first char
return upper(sort_char) -- use unicode.utf8.upper to make the char uppercase
end