summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/strc-pag.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/strc-pag.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/strc-pag.lua131
1 files changed, 86 insertions, 45 deletions
diff --git a/Master/texmf-dist/tex/context/base/strc-pag.lua b/Master/texmf-dist/tex/context/base/strc-pag.lua
index 2610595872a..bce8a2c3a4e 100644
--- a/Master/texmf-dist/tex/context/base/strc-pag.lua
+++ b/Master/texmf-dist/tex/context/base/strc-pag.lua
@@ -9,33 +9,39 @@ if not modules then modules = { } end modules ['strc-pag'] = {
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("structure.pages", function(v) trace_pages = v end)
+local trace_pages = false trackers.register("structures.pages", function(v) trace_pages = v end)
-structure.pages = structure.pages or { }
+local report_pages = logs.reporter("structure","pages")
-local helpers = structure.helpers or { }
-local sections = structure.sections or { }
-local pages = structure.pages or { }
-local processors = structure.processors or { }
-local sets = structure.sets or { }
+local structures = structures
-local variables = interfaces.variables
+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 counterdata = counters.data
+
+local variables = interfaces.variables
+local context = context
-- storage
-jobpages = jobpages or { }
-jobpages.collected = jobpages.collected or { }
-jobpages.tobesaved = jobpages.tobesaved or { }
+local collected, tobesaved = allocate(), allocate()
-local collected, tobesaved = jobpages.collected, jobpages.tobesaved
+pages.collected = collected
+pages.tobesaved = tobesaved
local function initializer()
- collected, tobesaved = jobpages.collected, jobpages.tobesaved
+ collected = pages.collected
+ tobesaved = pages.tobesaved
end
-job.register('jobpages.collected', jobpages.tobesaved, initializer)
+job.register('structures.pages.collected', tobesaved, initializer)
local specification = { } -- to be checked
@@ -43,7 +49,7 @@ function pages.save(prefixdata,numberdata)
local realpage, userpage = texcount.realpageno, texcount.userpageno
if realpage > 0 then
if trace_pages then
- logs.report("pages","saving page %s.%s",realpage,userpage)
+ report_pages("saving page %s.%s",realpage,userpage)
end
local data = {
number = userpage,
@@ -56,40 +62,23 @@ function pages.save(prefixdata,numberdata)
collected[realpage] = data
end
elseif trace_pages then
- logs.report("pages","not saving page %s.%s",realpage,userpage)
+ report_pages("not saving page %s.%s",realpage,userpage)
end
end
-function structure.counters.specials.userpage()
+function counters.specials.userpage()
local r = texcount.realpageno
if r > 0 then
local t = tobesaved[r]
if t then
t.number = texcount.userpageno
if trace_pages then
- logs.report("pages","forcing pagenumber of realpage %s to %s",r,t.number)
+ report_pages("forcing pagenumber of realpage %s to %s",r,t.number)
end
end
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
@@ -105,10 +94,10 @@ function pages.number(realdata,pagespec)
processors.sprint(ctxcatcodes,starter)
end
if conversion ~= "" then
- texsprint(ctxcatcodes,format("\\convertnumber{%s}{%s}",conversion,userpage))
+ context.convertnumber(conversion,userpage)
else
if conversionset == "" then conversionset = "default" end
- local theconversion = sets.get("structure:conversions",block,conversionset,index,"numbers")
+ local theconversion = sets.get("structure:conversions",block,conversionset,1,"numbers") -- to be checked: 1
processors.sprint(ctxcatcodes,theconversion,convertnumber,userpage)
end
if stopper ~= "" then
@@ -118,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"
@@ -154,12 +143,12 @@ function pages.analyse(entry,pagespecification)
return pagedata, false, "pagedata blocks prefix"
end
-- final verdict
- return pagedata, jobsections.collected[references.section], "okay"
+ return pagedata, sections.collected[references.section], "okay"
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
@@ -168,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)
@@ -190,7 +179,7 @@ end
--
-function helpers.analyse(entry,specification)
+function helpers.analyze(entry,specification)
-- safeguard
if not entry then
return false, false, "no entry"
@@ -205,7 +194,7 @@ function helpers.analyse(entry,specification)
if not section then
return entry, false, "no section"
end
- sectiondata = jobsections.collected[references.section]
+ local sectiondata = sections.collected[references.section]
if not sectiondata then
return entry, false, "no section data"
end
@@ -224,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
@@ -239,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