summaryrefslogtreecommitdiff
path: root/tex/context/base/strc-reg.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/strc-reg.lua')
-rw-r--r--tex/context/base/strc-reg.lua77
1 files changed, 55 insertions, 22 deletions
diff --git a/tex/context/base/strc-reg.lua b/tex/context/base/strc-reg.lua
index 2356acb9b..7e7736e2b 100644
--- a/tex/context/base/strc-reg.lua
+++ b/tex/context/base/strc-reg.lua
@@ -13,32 +13,35 @@ local utfchar = utf.char
local lpegmatch = lpeg.match
local allocate = utilities.storage.allocate
-local trace_registers = false trackers.register("structures.registers", function(v) trace_registers = v end)
+local trace_registers = false trackers.register("structures.registers", function(v) trace_registers = v end)
-local report_registers = logs.reporter("structure","registers")
+local report_registers = logs.reporter("structure","registers")
-local structures = structures
-local registers = structures.registers
-local helpers = structures.helpers
-local sections = structures.sections
-local documents = structures.documents
-local pages = structures.pages
-local references = structures.references
+local structures = structures
+local registers = structures.registers
+local helpers = structures.helpers
+local sections = structures.sections
+local documents = structures.documents
+local pages = structures.pages
+local references = structures.references
-local mappings = sorters.mappings
-local entries = sorters.entries
-local replacements = sorters.replacements
+local mappings = sorters.mappings
+local entries = sorters.entries
+local replacements = sorters.replacements
-local processors = typesetters.processors
-local splitprocessor = processors.split
+local processors = typesetters.processors
+local splitprocessor = processors.split
-local texgetcount = tex.getcount
+local texgetcount = tex.getcount
-local variables = interfaces.variables
-local context = context
-local commands = commands
+local variables = interfaces.variables
+local context = context
+local commands = commands
-local matchingtilldepth, numberatdepth = sections.matchingtilldepth, sections.numberatdepth
+local matchingtilldepth = sections.matchingtilldepth
+local numberatdepth = sections.numberatdepth
+
+local absmaxlevel = 5 -- \c_strc_registers_maxlevel
-- some day we will share registers and lists (although there are some conceptual
-- differences in the application of keywords)
@@ -661,18 +664,39 @@ local function collapsepages(pages)
return #pages
end
+-- todo: determine max
+
function registers.flush(data,options,prefixspec,pagespec)
local collapse_singles = options.compress == variables.yes
local collapse_ranges = options.compress == variables.all
local result = data.result
+ local done = { } -- reused
+ local maxlevel = 0
+ --
+ for i=1,#result do
+ local data = result[i].data
+ for d=1,#data do
+ local m = #data[d].list
+ if m > maxlevel then
+ maxlevel = m
+ end
+ end
+ end
+ if maxlevel > absmaxlevel then
+ maxlevel = absmaxlevel
+ report_registers("limiting level to %a",maxlevel)
+ end
+ --
context.startregisteroutput()
for i=1,#result do
-- ranges need checking !
local sublist = result[i]
- local done = { false, false, false, false }
local data = sublist.data
local d, n = 0, 0
context.startregistersection(sublist.tag)
+ for i=1,maxlevel do
+ done[i] = false
+ end
for d=1,#data do
local entry = data[d]
if entry.metadata.kind == "see" then
@@ -685,20 +709,26 @@ function registers.flush(data,options,prefixspec,pagespec)
end
end
end
+ local e = { } -- reused
while d < #data do
d = d + 1
local entry = data[d]
- local e = { false, false, false, false }
local metadata = entry.metadata
local kind = metadata.kind
local list = entry.list
- for i=1,4 do -- max 4
+ for i=1,maxlevel do
+ e[i] = false
+ end
+ for i=1,maxlevel do
if list[i] then
e[i] = list[i][1]
end
if e[i] ~= done[i] then
if e[i] and e[i] ~= "" then
done[i] = e[i]
+ for j=i+1,maxlevel do
+ done[j] = false
+ end
if n == i then
context.stopregisterentries()
context.startregisterentries(n)
@@ -722,6 +752,9 @@ function registers.flush(data,options,prefixspec,pagespec)
end
else
done[i] = false
+ for j=i,maxlevel do
+ done[j] = false
+ end
end
end
end