summaryrefslogtreecommitdiff
path: root/indexing/xindex/lualatex/xindex-lib.lua
diff options
context:
space:
mode:
Diffstat (limited to 'indexing/xindex/lualatex/xindex-lib.lua')
-rw-r--r--indexing/xindex/lualatex/xindex-lib.lua86
1 files changed, 67 insertions, 19 deletions
diff --git a/indexing/xindex/lualatex/xindex-lib.lua b/indexing/xindex/lualatex/xindex-lib.lua
index 86b103823b..17d1c96d28 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.51,
+ version = 0.53,
comment = "main library to xindex.lua",
author = "Herbert Voss",
copyright = "Herbert Voss",
@@ -97,6 +97,10 @@ function NormalizedChars(strOrig) -- return normalized UTF string (รค -> a) wit
return table.concat(str)
end
+function literalize(s) -- escaping characters ( ) . % + - * ? [ ] ^ $ with %
+ return s:gsub("[%(%)%.%%%+%-%*%?%[%]%^%$]", function(c) return "%" .. c end)
+end
+
-- local strOrigTrue = strOrig
-- strOrig = table.concat(str)
-- c = string.upper(get_normalized_char(alphabet_upper,utf.sub(strOrig,1,1)))
@@ -238,6 +242,7 @@ function checkParenthesis(Entries) -- search for |( ... |) entries
end
function replaceVerticalChar(v)
+ --if not v then return v,"" end
if not v:match('|') then
return v,""
else
@@ -549,6 +554,12 @@ function GenerateSortKey(a)
else
a["SortKey"] = A:match'^%s*(.*)' -- strip only left spaces
end
+ for _,v in pairs(escape_chars) do
+ V2 = NormalizedUpper(v[2])
+ V3 = NormalizedUpper(v[3])
+ a["SortKey"] = a["SortKey"]:gsub(V2, V3)
+ end
+ -- print("-a:"..a["SortKey"])
else
A = NormalizedChars(getSortString(a["Entry"].." "..Apage..a["pages"][1]["special"]):gsub('!',' ')) -- replace! by empty
if ignoreSpace then
@@ -556,15 +567,12 @@ function GenerateSortKey(a)
else
a["SortKey"] = A:match'^%s*(.*)' -- strip only left spaces
end
+ -- print("-a:"..a["SortKey"])
+ for _,v in pairs(escape_chars) do
+ a["SortKey"] = a["SortKey"]:gsub(v[2], v[3])
+ end
end
-- s:gsub("%s+", "") strip spaces
- if findStr(a["SortKey"],"\\braceLeft") < 2 then a["SortKey"] = '{ '..Apage end
- if findStr(a["SortKey"],"\\braceRight") < 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
--- if findStr(a["SortKey"],"\\textbar") < 2 then a["SortKey"] = '| '..Apage end
-- a["SortKey"] = a["SortKey"]:gsub("%s+", "")
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
@@ -573,7 +581,7 @@ function GenerateSortKey(a)
a["SortKey"] = "/"..a["SortKey"] -- sort it after /
end
end
- -- print("Sortkey: " .. a["SortKey"])
+ --print("Sortkey: " .. a["SortKey"])
end
function GenerateSortKeys(Index)
@@ -591,7 +599,7 @@ function UTFCompare(a,b)
else
compare = A<B
end
- writeLog(1,"UTFCompare: A--B "..A.."--"..B.."A<B:"..tostring(compare).."\n",2)
+ writeLog(1,"UTFCompare: "..A.."<"..B.." : "..tostring(compare).."\n",2)
return compare
end
@@ -786,18 +794,54 @@ function checkHyperpage(lines)
if fix_hyperref then
writeLog(1,"fix vertical bar with hyperref ... ",0)
-- hyperref ignores the vertical bar in "| and also other escape chars
+ --
+ -- \index{"|} -> \indexentry{"|hyperpage}{1} -> \textbar|hyperpage
+ -- \index{foo"|bar} -> \indexentry{foo"|hyperindexformat{\bar}}{1} -> foo\textbar bar|hyperpage
end
- local sub_str = esc_char..'|hyperpage'
+ local sub_str0 = esc_char..'|hyperpage'
+ local sub_str1 = esc_char..'|hyperindexformat'
for i=1,#lines do
+ local l = lines[i]
if fix_hyperref then
- s = lines[i]:find(sub_str)
- print(i,lines[i],s)
- if s == nil then s = 0 end
- if s == 2 then
- lines[i] = lines[i]:gsub(sub_str, '\\textbar|hyperpage') -- "| -> \textbar
+ s0 = l:find(sub_str0) -- test for hyperpage
+ s1 = l:find(esc_char..sub_str0)
+ --print(i,l,s0,s1)
+ if s0 == nil then
+ s0 = 0
+ s1 = 0
+ end
+ if s1 == nil and s0 > 0 then -- no ""|
+ l = l:gsub(sub_str0, '\\textbar|hyperpage') -- "| -> \textbar
+ else
+ -- part 2
+ s0 = l:find(sub_str1)
+ s1 = l:find(esc_char..sub_str1)
+ --print(i,l,s0,s1)
+ if s0 == nil then
+ s0 = 0
+ s1 = 0
+ elseif s1 == nil then
+ s1 = 0
+ end
+ if s1 == 0 and s0 > 0 then
+ -- get foo and bar from {foo"|hyperindexformat{\bar}}
+ items = l:gmatch("%{(.-)%}")
+ var = {}
+ for item in items do
+ var[#var+1] = item
+ end
+ if s0 > 2 then
+ u1 = var[1]:split('"|')[1] -- foo
+ else
+ u1 = ''
+ end
+ v1 = var[1]:split("\\")[2] -- bar
+ l = '{'..u1..'\\textbar '..v1.."|hyperpage}{"..var[2].."}"
+ -- l = foo"|bar -> foo\textbar bar
+ end
end
end
- lines[i] = string.gsub(lines[i],'|?hyperpage}{','}{')
+ lines[i] = string.gsub(l,'|?hyperpage}{','}{')
end -- for
writeLog(1,"done\n",0)
return true, lines
@@ -825,7 +869,9 @@ function itemOutput(last, v, hyperpage)
str = " \\item "..Entry.."\n"
end
for i, str0 in ipairs(escape_chars) do -- undo the escape char setting
- str = str:gsub(str0[2],str0[3])
+ if i < 5 then
+ str = str:gsub(str0[2],str0[3])
+ end
end
outFile:write(str); indLines=indLines+1
lastItems = {}
@@ -858,7 +904,9 @@ function itemOutput(last, v, hyperpage)
end
end
for i, str0 in ipairs(escape_chars) do -- undo the escape char setting
- str = string.gsub(str,str0[2],str0[3])
+ if i < 5 then
+ str = string.gsub(str,str0[2],str0[3])
+ end
end
outFile:write(str); indLines=indLines+1
else