summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/lualatex/xindex/xindex-lib.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/lualatex/xindex/xindex-lib.lua')
-rw-r--r--Master/texmf-dist/tex/lualatex/xindex/xindex-lib.lua118
1 files changed, 74 insertions, 44 deletions
diff --git a/Master/texmf-dist/tex/lualatex/xindex/xindex-lib.lua b/Master/texmf-dist/tex/lualatex/xindex/xindex-lib.lua
index 595ffc2dd7a..3f24bee3678 100644
--- a/Master/texmf-dist/tex/lualatex/xindex/xindex-lib.lua
+++ b/Master/texmf-dist/tex/lualatex/xindex/xindex-lib.lua
@@ -9,7 +9,7 @@
-----------------------------------------------------------------------
if not modules then modules = { } end modules ['xindex-lib'] = {
- version = 0.60,
+ version = 0.61,
comment = "main library to xindex.lua",
author = "Herbert Voss",
copyright = "Herbert Voss",
@@ -296,7 +296,8 @@ function getEntryAndPage(w, nextW, EntryList)
--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)
+ writeLog(1,"getEntryAndPage: "..
+ tostring(IndexString,pageNo,Special,utf.sub(IndexString,1,1),macro).."\n",2)
end
return EntryList
end
@@ -305,6 +306,7 @@ function compressEntryList(EntryList)
-- require 'xindex-pretty'.dump(EntryList) -- only for internal dump
local newList = {}
newList[1] = EntryList[1] -- at least one entry
+ print("----------------- start compressEntryList ----------------")
local nPages = 1
for k=2,#EntryList do
if EntryList[k] then -- exists?
@@ -349,7 +351,6 @@ EntryList[2] = {
}
]]
-
function deletePageDups(pages)
if #pages == 1 then return pages end
local newPages = {pages[1]}
@@ -372,7 +373,7 @@ end
function compressPageList(pages) -- called with (v["pages"])
writeLog(1,"compressPageList: we have "..#pages.." pages for this entry\n",2)
--- require 'xindex-pretty'.dump(pages) -- only for internal dump
+ --print(require 'xindex-pretty'.dump(pages)) -- only for internal dump
pages = deletePageDups(pages) -- delete duplicate page numbers with same special
local str
if #pages == 1 then -- only one pageno
@@ -392,6 +393,26 @@ function compressPageList(pages) -- called with (v["pages"])
-- (pages[1]["special"] == pages[2]["special"]) then
-- pages[2] = nil
end
+ else -- pages are not numbers
+ rangeStartA,rangeEndA = pages[1]["number"]:find("-") or 0,0
+ rangeStartB,rangeEndB = pages[2]["number"]:find("-") or 0,0
+ if rangeStartA > 1 then
+ pageA = pages[1]["number"]:gmatch("([^-]+)")(1) -- split 12--44 into 12
+ pageB = pages[2]["number"]
+ if pageA > pageB then -- change pages
+ local temp = pages[1]["number"]
+ pages[1]["number"] = pages[2]["number"]
+ pages[2]["number"] = temp
+ end
+ elseif rangeStartB > 1 then -- change pages
+ pageA = pages[1]["number"]
+ pageB = pages[2]["number"]:gmatch("([^-]+)")(1) -- split 12--44 into 12
+ if pageA > pageB then
+ local temp = pages[1]["number"]
+ pages[1]["number"] = pages[2]["number"]
+ pages[2]["number"] = temp
+ end
+ end
end
return pages
end
@@ -409,7 +430,7 @@ function compressPageList(pages) -- called with (v["pages"])
series = {pages[2]}
startIndex = 3
end
-if args_v then print ("compressPageList: more than two pages for the entry\n") end
+ if args_v then print ("compressPageList: more than two pages for the entry\n") end
for i=startIndex,#pages do
if (toNumber(pages[i-1]["number"]) and toNumber(pages[i]["number"])) then -- do we have two arabic or two roman numbers?
if ((toNumber(pages[i]["number"])-toNumber(pages[i-1]["number"])) == 1) and
@@ -603,24 +624,33 @@ function GenerateSortKeys(Index)
end
end
+-- Entry = "Johann", -- the index item foo@bar
+-- pages = { -- the page number(s) and the part after |
+-- { number = 111,
+
+
function UCACompare(a,b)
+ local pageA = a["pages"][1]["number"]
+ local pageB = b["pages"][1]["number"]
if ignoreSpace then
- A = a["Entry"]:gsub("%s+", "") -- str = str:gsub("%s+", "")
- B = b["Entry"]:gsub("%s+", "")
+ A = a["Entry"]:gsub("%s+", "")..tostring(pageA) -- str = str:gsub("%s+", "")
+ B = b["Entry"]:gsub("%s+", "")..tostring(pageB)
else
- A = a["Entry"]
- B = b["Entry"]
+ A = a["Entry"]..tostring(pageA)
+ B = b["Entry"]..tostring(pageB)
end
+ if A=="Abendmahl" or B=="Abendmahl" then print(A,B,A==B) end
+ if A==B then return True end
--print(A,B)
compare = collator_obj:compare_strings(A,B)
- writeLog(1,"UCACompare: "..A.."<"..B.." : "..tostring(compare).."\n",2)
+-- writeLog(1,"UCACompare: "..A.."<"..B.." : "..tostring(compare).."\n",2)
return compare
end
function UTFCompare(a,b)
local A = a["SortKey"]
local B = b["SortKey"]
- writeLog(1,"UTFCompare: "..A.."<"..B.." : "..tostring(A<B).."\n",2)
+-- writeLog(1,"UTFCompare: "..A.."<"..B.." : "..tostring(A<B).."\n",2)
return A<B
end
@@ -729,7 +759,7 @@ function getPageList(v,hyperpage)
else
Pages = compressPageList(v["pages"])
end
--- require 'xindex-pretty'.dump(Pages) -- only for internal dump
+-- print(require 'xindex-pretty'.dump(Pages)) -- only for internal dump
local pageNo
--[[
\indexentry{Auto|hyperindexformat{\textbf}}{1}
@@ -739,18 +769,17 @@ function getPageList(v,hyperpage)
\item foo, \hyperpage{1\nohyperpage{f}},
\hyperpage{4\nohyperpage{ff}}, \hyperpage{8}
-
]]
if hyperpage then
- if string.find(v["pages"][1]["special"],"hyperindexformat") then
--- pageNo = v["pages"][1]["special"].."{"..checkFF(Pages[1]["number"].."}")
- pageNo = v["pages"][1]["special"].."{"..Pages[1]["number"].."}"
+ if string.find(Pages[1]["special"],"hyperindexformat") then
+-- pageNo = Pages[1]["special"].."{"..checkFF(Pages[1]["number"].."}")
+ pageNo = Pages[1]["special"].."{"..Pages[1]["number"].."}"
else
pageNo = "\\hyperpage{"..checkFF(Pages[1]["number"]).."}"
end
for i=2,#Pages do
- if string.find(v["pages"][i]["special"],"hyperindexformat") then
- pageNo = pageNo..", "..v["pages"][i]["special"].."{"..Pages[i]["number"].."}"
+ if string.find(Pages[i]["special"],"hyperindexformat") then
+ pageNo = pageNo..", "..Pages[i]["special"].."{"..Pages[i]["number"].."}"
-- pageNo = pageNo..", "..v["pages"][i]["special"].."{"..checkFF(Pages[i]["number"].."}")
else
pageNo = pageNo..", \\hyperpage{"..checkFF(Pages[i]["number"]).."}"
@@ -804,8 +833,9 @@ end
function checkHyperpage(lines)
local hyperpage = false
+ local l
for i=1,#lines do
- if string.find(lines[i],'hyperpage}') then
+ if string.find(lines[i],'hyperpage}') or string.find(lines[i],'hyperindexformat}') then
hyperpage = true
break
end
@@ -816,49 +846,49 @@ function checkHyperpage(lines)
-- 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
+ -- \index{foo"|bar} -> \indexentry{foo"||hyperindexformat{\bar}}{1} -> foo\textbar bar|hyperpage
end
local sub_str0 = esc_char..'|hyperpage'
local sub_str1 = esc_char..'|hyperindexformat'
for i=1,#lines do
- local l = lines[i]
+ l = lines[i]
if fix_hyperref then
- s0 = l:find(sub_str0) -- test for hyperpage
- s1 = l:find(esc_char..sub_str0)
- --print(i,l,s0,s1)
+ s0 = l:find(sub_str0) -- test for "|hyperpage
+ s1 = l:find(esc_char..sub_str0) -- test for ”"|hyperpage
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
+ l = l:gsub(sub_str0, '\\textbar|hyperpage') -- "|hyperpage -> \textbar|hyperpage
+ end
+ -- part 2
+ s0 = l:find(sub_str1) -- look for "|hyperindexformat
+ s1 = l:find(esc_char..sub_str1) -- look for ""|hyperindexformat
+ --print(i,l,s0,s1)
+ if s0 == nil then
s0 = 0
s1 = 0
- elseif s1 == nil then
+ elseif s1 == nil then
s1 = 0
- end
- if s1 == 0 and s0 > 0 then
+ end
+ if s1 == 0 and s0 > 0 then -- found "|hyperindexformat
-- get foo and bar from {foo"|hyperindexformat{\bar}}
- items = l:gmatch("%{(.-)%}")
- var = {}
- for item in items do
+ -- \indexentry{marriage|hyperindexformat{\seealso{coemptio}}}{301}
+ items = l:gmatch("%{(.-)%}")
+ var = {}
+ for item in items do
var[#var+1] = item
- end
- if s0 > 2 then
+ end
+ if s0 > 2 then
u1 = var[1]:split('"|')[1] -- foo
- else
+ else
u1 = ''
- end
- v1 = var[1]:split("\\")[2] -- bar
- l = '{'..u1..'\\textbar '..v1.."|hyperpage}{"..var[2].."}"
- -- l = foo"|bar -> foo\textbar bar
end
+ v1 = var[1]:split("\\")[2] -- bar
+ print(u1,v1,var[1],var[2])
+ l = '{'..u1..'\\textbar '..v1.."|hyperindexformat}{"..var[2].."}"
+ -- l = foo"|bar -> foo\textbar bar
end
end
lines[i] = string.gsub(l,'|?hyperpage}{','}{')