diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/strc-pag.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/strc-pag.lua | 110 |
1 files changed, 72 insertions, 38 deletions
diff --git a/Master/texmf-dist/tex/context/base/strc-pag.lua b/Master/texmf-dist/tex/context/base/strc-pag.lua index b95f0842ac6..2610595872a 100644 --- a/Master/texmf-dist/tex/context/base/strc-pag.lua +++ b/Master/texmf-dist/tex/context/base/strc-pag.lua @@ -1,6 +1,6 @@ if not modules then modules = { } end modules ['strc-pag'] = { version = 1.001, - comment = "companion to strc-pag.tex", + comment = "companion to strc-pag.mkiv", author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", copyright = "PRAGMA ADE / ConTeXt Development Team", license = "see context related readme files" @@ -11,6 +11,8 @@ local texcount, format = tex.count, string.format local ctxcatcodes = tex.ctxcatcodes local texsprint, texwrite = tex.sprint, tex.write +local trace_pages = false trackers.register("structure.pages", function(v) trace_pages = v end) + structure.pages = structure.pages or { } local helpers = structure.helpers or { } @@ -35,51 +37,75 @@ end job.register('jobpages.collected', jobpages.tobesaved, initializer) -local specification = { } +local specification = { } -- to be checked -function pages.save(userspec) +function pages.save(prefixdata,numberdata) local realpage, userpage = texcount.realpageno, texcount.userpageno - local data = { - number = userpage, - specification = helpers.simplify(userspec or specification), - block = sections.currentblock(), - } - tobesaved[realpage] = data - if not collected[realpage] then - collected[realpage] = data + if realpage > 0 then + if trace_pages then + logs.report("pages","saving page %s.%s",realpage,userpage) + end + local data = { + number = userpage, + block = sections.currentblock(), + prefixdata = prefixdata and helpers.simplify(prefixdata), + numberdata = numberdata and helpers.simplify(numberdata), + } + tobesaved[realpage] = data + if not collected[realpage] then + collected[realpage] = data + end + elseif trace_pages then + logs.report("pages","not saving page %s.%s",realpage,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 +function structure.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) end end end - if deltaspec then - return { realpage = texcount.realpageno, specification = deltaspec } - else - return { realpage = texcount.realpageno } - 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 -function pages.number(realdata,pagespecification) - local userpage, block = realdata.number, realdata.block or "" - local conversionset = (pagespecification and pagespecification.conversionset) or realdata.conversionset or "" - local conversion = (pagespecification and pagespecification.conversion ) or realdata.conversion or "" - local stopper = (pagespecification and pagespecification.stopper ) or realdata.stopper or "" +function pages.number(realdata,pagespec) + local userpage, block = realdata.number, realdata.block or "" -- sections.currentblock() + local numberspec = realdata.numberdata + local conversionset = (pagespec and pagespec.conversionset ~= "" and pagespec.conversionset) or (numberspec and numberspec.conversionset ~= "" and numberspec.conversionset) or "" + local conversion = (pagespec and pagespec.conversion ~= "" and pagespec.conversion ) or (numberspec and numberspec.conversion ~= "" and numberspec.conversion ) or "" + local starter = (pagespec and pagespec.starter ~= "" and pagespec.starter ) or (numberspec and numberspec.starter ~= "" and numberspec.starter ) or "" + local stopper = (pagespec and pagespec.stopper ~= "" and pagespec.stopper ) or (numberspec and numberspec.stopper ~= "" and numberspec.stopper ) or "" + if starter ~= "" then + processors.sprint(ctxcatcodes,starter) + end if conversion ~= "" then - texsprint(ctxcatcodes,format("\\convertnumber{%s}{%s}",conversion,number)) + texsprint(ctxcatcodes,format("\\convertnumber{%s}{%s}",conversion,userpage)) else if conversionset == "" then conversionset = "default" end local theconversion = sets.get("structure:conversions",block,conversionset,index,"numbers") @@ -119,11 +145,11 @@ function pages.analyse(entry,pagespecification) return pagedata, false, "current spec blocks prefix" end -- stored preferences - if entry.prefix == no then - return pagedata, false, "entry blocks prefix" - end +--~ if entry.prefix == no then +--~ return pagedata, false, "entry blocks prefix" +--~ end -- stored page state - pagespecification = pagedata.specification + pagespecification = pagedata.prefixdata if pagespecification and pagespecification.prefix == no then return pagedata, false, "pagedata blocks prefix" end @@ -143,10 +169,9 @@ end function helpers.prefixpage(data,prefixspec,pagespec) if data then local pagedata, prefixdata, e = pages.analyse(data,pagespec) ---~ tex.write(e) if pagedata then if prefixdata then - sections.typesetnumber(prefixdata,"prefix",prefixspec or false,prefixdata or false,pagedata.specification or false) + sections.typesetnumber(prefixdata,"prefix",prefixspec or false,prefixdata or false,pagedata.prefixdata or false) end pages.number(pagedata,pagespec) end @@ -170,7 +195,7 @@ function helpers.analyse(entry,specification) if not entry then return false, false, "no entry" end - local no = variables.no + local yes, no = variables.yes, variables.no -- section data local references = entry.references if not references then @@ -199,9 +224,18 @@ end function helpers.prefix(data,prefixspec) if data then - local _, prefixdata = helpers.analyse(data,prefixspec) + local _, prefixdata, status = helpers.analyse(data,prefixspec) if prefixdata then sections.typesetnumber(prefixdata,"prefix",prefixspec or false,data.prefixdata or false,prefixdata or false) end end end + +function pages.is_odd(n) + n = n or texcount.realpageno + if texcount.pagenoshift % 2 == 0 then + return n % 2 == 0 + else + return n % 2 ~= 0 + end +end |