diff options
Diffstat (limited to 'tex/context/base/strc-pag.lua')
-rw-r--r-- | tex/context/base/strc-pag.lua | 109 |
1 files changed, 73 insertions, 36 deletions
diff --git a/tex/context/base/strc-pag.lua b/tex/context/base/strc-pag.lua index e7750815e..fde2de942 100644 --- a/tex/context/base/strc-pag.lua +++ b/tex/context/base/strc-pag.lua @@ -10,36 +10,38 @@ local texcount, format = tex.count, string.format local ctxcatcodes = tex.ctxcatcodes local texsprint, texwrite = tex.sprint, tex.write +local allocate, mark = utilities.storage.allocate, utilities.storage.mark local trace_pages = false trackers.register("structures.pages", function(v) trace_pages = v end) local report_pages = logs.new("pages") -local structures = structures +local structures = structures -structures.pages = structures.pages or { } +local helpers = structures.helpers +local sections = structures.sections +local pages = structures.pages +local processors = structures.processors +local sets = structures.sets +local counters = structures.counters -local helpers = structures.helpers or { } -local sections = structures.sections or { } -local pages = structures.pages or { } -local processors = structures.processors or { } -local sets = structures.sets or { } -local counters = structures.counters or { } +local counterdata = counters.data -local variables = interfaces.variables +local variables = interfaces.variables -- storage -pages.collected = pages.collected or { } -pages.tobesaved = pages.tobesaved or { } +local collected, tobesaved = allocate(), allocate() -local collected, tobesaved = pages.collected, pages.tobesaved +pages.collected = collected +pages.tobesaved = tobesaved local function initializer() - collected, tobesaved = pages.collected, pages.tobesaved + collected = mark(pages.collected) + tobesaved = mark(pages.tobesaved) end -job.register('structures.pages.collected', pages.tobesaved, initializer) +job.register('structures.pages.collected', tobesaved, initializer) local specification = { } -- to be checked @@ -77,23 +79,6 @@ function counters.specials.userpage() end end ---~ function pages.pagenumber(localspec) ---~ local deltaspec ---~ if localspec then ---~ for k,v in next, localspec do ---~ if v ~= "" and v ~= specification[k] then ---~ if not deltaspec then deltaspec = { } end ---~ deltaspec[k] = v ---~ end ---~ end ---~ end ---~ if deltaspec then ---~ return { realpage = texcount.realpageno, specification = deltaspec } ---~ else ---~ return { realpage = texcount.realpageno } ---~ end ---~ end - local function convertnumber(str,n) return format("\\convertnumber{%s}{%s}",str or "numbers",n) end @@ -122,7 +107,7 @@ end -- (pagespec.prefix == yes|unset) and (pages.prefix == yes) => prefix -function pages.analyse(entry,pagespecification) +function pages.analyze(entry,pagespecification) -- safeguard if not entry then return false, false, "no entry" @@ -163,7 +148,7 @@ end function helpers.page(data,pagespec) if data then - local pagedata = pages.analyse(data,pagespec) + local pagedata = pages.analyze(data,pagespec) if pagedata then pages.number(pagedata,pagespec) end @@ -172,7 +157,7 @@ end function helpers.prefixpage(data,prefixspec,pagespec) if data then - local pagedata, prefixdata, e = pages.analyse(data,pagespec) + local pagedata, prefixdata, e = pages.analyze(data,pagespec) if pagedata then if prefixdata then sections.typesetnumber(prefixdata,"prefix",prefixspec or false,prefixdata or false,pagedata.prefixdata or false) @@ -194,7 +179,7 @@ end -- -function helpers.analyse(entry,specification) +function helpers.analyze(entry,specification) -- safeguard if not entry then return false, false, "no entry" @@ -228,7 +213,7 @@ end function helpers.prefix(data,prefixspec) if data then - local _, prefixdata, status = helpers.analyse(data,prefixspec) + local _, prefixdata, status = helpers.analyze(data,prefixspec) if prefixdata then sections.typesetnumber(prefixdata,"prefix",prefixspec or false,data.prefixdata or false,prefixdata or false) end @@ -243,3 +228,55 @@ function pages.is_odd(n) return n % 2 ~= 0 end end + +-- move to strc-pag.lua + +function counters.analyze(name,counterspecification) + local cd = counterdata[name] + -- safeguard + if not cd then + return false, false, "no counter data" + end + -- section data + local sectiondata = sections.current() + if not sectiondata then + return cd, false, "not in section" + end + local references = sectiondata.references + if not references then + return cd, false, "no references" + end + local section = references.section + if not section then + return cd, false, "no section" + end + sectiondata = sections.collected[references.section] + if not sectiondata then + return cd, false, "no section data" + end + -- local preferences + local no = variables.no + if counterspecification and counterspecification.prefix == no then + return cd, false, "current spec blocks prefix" + end + -- stored preferences (not used) + if cd.prefix == no then + return cd, false, "entry blocks prefix" + end + -- sectioning + -- if sectiondata.prefix == no then + -- return false, false, "sectiondata blocks prefix" + -- end + -- final verdict + return cd, sectiondata, "okay" +end + +function counters.prefixedconverted(name,prefixspec,numberspec) + local cd, prefixdata, result = counters.analyze(name,prefixspec) + if cd then + if prefixdata then + sections.typesetnumber(prefixdata,"prefix",prefixspec or false,cd or false) + end + counters.converted(name,numberspec) + end +end |