diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/strc-not.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/strc-not.lua | 156 |
1 files changed, 96 insertions, 60 deletions
diff --git a/Master/texmf-dist/tex/context/base/strc-not.lua b/Master/texmf-dist/tex/context/base/strc-not.lua index be883af57eb..07cd3249646 100644 --- a/Master/texmf-dist/tex/context/base/strc-not.lua +++ b/Master/texmf-dist/tex/context/base/strc-not.lua @@ -8,33 +8,31 @@ if not modules then modules = { } end modules ['strc-not'] = { local format = string.format local next = next -local texsprint, texwrite, texcount = tex.sprint, tex.write, tex.count +local texcount = tex.count -local ctxcatcodes = tex.ctxcatcodes +local trace_notes = false trackers.register("structures.notes", function(v) trace_notes = v end) -local trace_notes = false trackers.register("structure.notes", function(v) trace_notes = v end) +local report_notes = logs.reporter("structure","notes") -structure = structure or { } -structure.helpers = structure.helpers or { } -structure.lists = structure.lists or { } -structure.sections = structure.sections or { } -structure.counters = structure.counters or { } -structure.notes = structure.notes or { } +local structures = structures +local helpers = structures.helpers +local lists = structures.lists +local sections = structures.sections +local counters = structures.counters +local notes = structures.notes +local references = structures.references -structure.notes.states = structure.notes.states or { } -structure.lists.enhancers = structure.lists.enhancers or { } +notes.states = notes.states or { } +lists.enhancers = lists.enhancers or { } -storage.register("structure/notes/states", structure.notes.states, "structure.notes.states") +storage.register("structures/notes/states", notes.states, "structures.notes.states") -local helpers = structure.helpers -local lists = structure.lists -local sections = structure.sections -local counters = structure.counters -local notes = structure.notes - -local notestates = structure.notes.states +local notestates = notes.states local notedata = { } +local variables = interfaces.variables +local context = context + -- state: store, insert, postpone function notes.store(tag,n) @@ -43,16 +41,16 @@ function notes.store(tag,n) nd = { } notedata[tag] = nd end - local nnd = #nd+1 + local nnd = #nd + 1 nd[nnd] = n local state = notestates[tag] if state.kind ~= "insert" then if trace_notes then - logs.report("notes","storing %s with state %s as %s",tag,state.kind,nnd) + report_notes("storing %s with state %s as %s",tag,state.kind,nnd) end state.start = state.start or nnd end - texwrite(#nd) + context(#nd) end local function get(tag,n) @@ -62,9 +60,11 @@ local function get(tag,n) nd = nd[n] if nd then if trace_notes then - logs.report("notes","getting %s of %s",n,tag) + report_notes("getting note %s of '%s'",n,tag) end - return structure.lists.collected[nd] + -- is this right? + local newdata = lists.collected[nd] + return newdata end end end @@ -74,13 +74,14 @@ local function getn(tag) return (nd and #nd) or 0 end -nodes.get = get -nodes.getn = getn +notes.get = get +notes.getn = getn -- we could make a special enhancer function notes.listindex(tag,n) - return notedata[tag][n] + local ndt = notedata[tag] + return ndt and ndt[n] end function notes.define(tag,kind,number) @@ -92,11 +93,12 @@ function notes.save(tag,newkind) local state = notestates[tag] if state and not state.saved then if trace_notes then - logs.report("notes","saving state of %s: %s -> %s",tag,state.kind,newkind or state.kind) + report_notes("saving state of '%s': %s -> %s",tag,state.kind,newkind or state.kind) end - state.saved = notedata[tag] + state.saveddata = notedata[tag] state.savedkind = state.kind state.kind = newkind or state.kind + state.saved = true notedata[tag] = { } end end @@ -105,18 +107,19 @@ function notes.restore(tag,forcedstate) local state = notestates[tag] if state and state.saved then if trace_notes then - logs.report("notes","restoring state of %s: %s -> %s",tag,state.kind,state.savedkind) + report_notes("restoring state of '%s': %s -> %s",tag,state.kind,state.savedkind) end - state.saved = nil + notedata[tag] = state.saveddata state.kind = forcedstate or state.savedkind - notedata[tag] = state.saved + state.saveddata = nil + state.saved = false end end function notes.setstate(tag,newkind) local state = notestates[tag] if trace_notes then - logs.report("notes","setting state of %s from %s to %s",tag,(state and state.kind) or "unset",newkind) + report_notes("setting state of '%s' from %s to %s",tag,(state and state.kind) or "unset",newkind) end if not state then state = { @@ -136,7 +139,7 @@ end function notes.getstate(tag) local state = notestates[tag] - texsprint(ctxcatcodes,(state and state.kind ) or "unknown") + context(state and state.kind or "unknown") end function notes.doifcontent(tag) @@ -162,7 +165,7 @@ local function internal(tag,n) if r then local i = r.internal --~ return i and lists.internals[i] - return i and jobreferences.internals[i] + return i and references.internals[i] -- dependency on references end end return nil @@ -214,7 +217,7 @@ function notes.deltapage(tag,n) if li then local metadata, pagenumber = li.metadata, li.pagenumber if metadata and pagenumber then - local symbolpage = metadata.symbolpage or 0 + local symbolpage = references.symbolpage or 0 local notepage = pagenumber.number or 0 if notepage > 0 and symbolpage > 0 then if notepage < symbolpage then @@ -231,12 +234,12 @@ function notes.deltapage(tag,n) what = 3 end end - texwrite(what) + context(what) end function notes.postpone() if trace_notes then - logs.report("notes","postponing all insert notes") + report_notes("postponing all insert notes") end for tag, state in next, notestates do if state.kind ~= "store" then @@ -245,28 +248,39 @@ function notes.postpone() end end -function notes.setsymbolpage(tag,n) - local nd = get(tag,n) - if nd then - nd.metadata.symbolpage = texcount.realpageno +function notes.setsymbolpage(tag,n,l) + local l = l or notes.listindex(tag,n) + if l then + local p = texcount.realpageno + if trace_notes then + report_notes("note %s of '%s' with list index %s gets page %s",n,tag,l,p) + end + lists.cached[l].references.symbolpage = p + else + report_notes("internal error: note %s of '%s' is not initialized",n,tag) end end function notes.getsymbolpage(tag,n) local nd = get(tag,n) - nd = nd and nd.metadata.symbolpage - texwrite(nd or 0) + local p = nd and nd.references.symbolpage or 0 + if trace_notes then + report_notes("page number of note symbol %s of '%s' is %s",n,tag,p) + end + context(p) end function notes.getnumberpage(tag,n) local li = internal(tag,n) - li = li and li.pagenumber - li = li and li.numbers - li = li and li[1] - texwrite(li or 0) + li = li and li.references + li = li and li.realpage or 0 + if trace_notes then + report_notes("page number of note number %s of '%s' is %s",n,tag,li) + end + context(li) end -function notes.flush(tag,whatkind) -- store and postpone +function notes.flush(tag,whatkind,how) -- store and postpone local state = notestates[tag] local kind = state.kind if kind == whatkind then @@ -275,10 +289,10 @@ function notes.flush(tag,whatkind) -- store and postpone if kind == "postpone" then if nd and ns then if trace_notes then - logs.report("notes","flushing state %s of %s from %s to %s",whatkind,tag,ns,#nd) + report_notes("flushing state %s of %s from %s to %s",whatkind,tag,ns,#nd) end for i=ns,#nd do - texsprint(ctxcatcodes,format("\\handlenoteinsert{%s}{%s}",tag,i)) + context.handlenoteinsert(tag,i) end end state.start = nil @@ -286,31 +300,45 @@ function notes.flush(tag,whatkind) -- store and postpone elseif kind == "store" then if nd and ns then if trace_notes then - logs.report("notes","flushing state %s of %s from %s to %s",whatkind,tag,ns,#nd) + report_notes("flushing state %s of %s from %s to %s",whatkind,tag,ns,#nd) end + -- todo: as registers: start, stop, inbetween for i=ns,#nd do - texsprint(ctxcatcodes,format("\\handlenoteitself{%s}{%s}",tag,i)) + -- tricky : trialtypesetting + if how == variables.page then + local rp = get(tag,i) + rp = rp and rp.references + rp = rp and rp.symbolpage or 0 + if rp > texcount.realpageno then + state.start = i + return + end + end + if i > ns then + context.betweennoteitself(tag) + end + context.handlenoteitself(tag,i) end end state.start = nil elseif kind == "reset" then if nd and ns then if trace_notes then - logs.report("notes","flushing state %s of %s from %s to %s",whatkind,tag,ns,#nd) + report_notes("flushing state %s of %s from %s to %s",whatkind,tag,ns,#nd) end end state.start = nil elseif trace_notes then - logs.report("notes","not flushing state %s of %s",whatkind,tag) + report_notes("not flushing state %s of %s",whatkind,tag) end elseif trace_notes then - logs.report("notes","not flushing state %s of %s",whatkind,tag) + report_notes("not flushing state %s of %s",whatkind,tag) end end function notes.flushpostponed() if trace_notes then - logs.report("notes","flushing all postponed notes") + report_notes("flushing all postponed notes") end for tag, _ in next, notestates do notes.flush(tag,"postpone") @@ -319,7 +347,7 @@ end function notes.resetpostponed() if trace_notes then - logs.report("notes","resetting all postponed notes") + report_notes("resetting all postponed notes") end for tag, state in next, notestates do if state.kind == "postpone" then @@ -330,9 +358,17 @@ function notes.resetpostponed() end function notes.title(tag,n) - structure.lists.savedtitle(tag,notedata[tag][n]) + lists.savedtitle(tag,notedata[tag][n]) end function notes.number(tag,n,spec) - structure.lists.savedprefixednumber(tag,notedata[tag][n]) + lists.savedprefixednumber(tag,notedata[tag][n]) +end + +function notes.internalid(tag,n) + local nd = get(tag,n) + if nd then + local r = nd.references + return r.internal + end end |