summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/strc-not.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/strc-not.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/strc-not.lua75
1 files changed, 57 insertions, 18 deletions
diff --git a/Master/texmf-dist/tex/context/base/strc-not.lua b/Master/texmf-dist/tex/context/base/strc-not.lua
index 32a836ba86c..be883af57eb 100644
--- a/Master/texmf-dist/tex/context/base/strc-not.lua
+++ b/Master/texmf-dist/tex/context/base/strc-not.lua
@@ -1,6 +1,6 @@
if not modules then modules = { } end modules ['strc-not'] = {
version = 1.001,
- comment = "companion to strc-not.tex",
+ comment = "companion to strc-not.mkiv",
author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
copyright = "PRAGMA ADE / ConTeXt Development Team",
license = "see context related readme files"
@@ -52,14 +52,14 @@ function notes.store(tag,n)
end
state.start = state.start or nnd
end
- tex.write(#nd)
+ texwrite(#nd)
end
-function notes.get(tag,n)
+local function get(tag,n)
local nd = notedata[tag]
if nd then
- n = n or #notedata
- nd = nd[n or n]
+ n = n or #nd
+ nd = nd[n]
if nd then
if trace_notes then
logs.report("notes","getting %s of %s",n,tag)
@@ -69,6 +69,20 @@ function notes.get(tag,n)
end
end
+local function getn(tag)
+ local nd = notedata[tag]
+ return (nd and #nd) or 0
+end
+
+nodes.get = get
+nodes.getn = getn
+
+-- we could make a special enhancer
+
+function notes.listindex(tag,n)
+ return notedata[tag][n]
+end
+
function notes.define(tag,kind,number)
local state = notes.setstate(tag,kind)
state.number = number
@@ -77,6 +91,9 @@ end
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)
+ end
state.saved = notedata[tag]
state.savedkind = state.kind
state.kind = newkind or state.kind
@@ -84,11 +101,14 @@ function notes.save(tag,newkind)
end
end
-function notes.restore(tag)
+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)
+ end
state.saved = nil
- state.kind = state.savedkind
+ state.kind = forcedstate or state.savedkind
notedata[tag] = state.saved
end
end
@@ -136,7 +156,7 @@ function notes.doifcontent(tag)
end
local function internal(tag,n)
- local nd = notes.get(tag,n)
+ local nd = get(tag,n)
if nd then
local r = nd.references
if r then
@@ -154,6 +174,20 @@ local function ordered(kind,name,n)
return o and o[n]
end
+notes.internal = internal
+notes.ordered = ordered
+
+function notes.doifonsamepageasprevious(tag)
+ local same = false
+ local n = getn(tag,n)
+ local current, previous = get(tag,n), get(tag,n-1)
+ if current and previous then
+ local cr, pr = current.references, previous.references
+ same = cr and pr and cr.realpage == pr.realpage
+ end
+ commands.doifelse(same)
+end
+
function notes.checkpagechange(tag) -- called before increment !
local nd = notedata[tag] -- can be unset at first entry
if nd then
@@ -197,7 +231,7 @@ function notes.deltapage(tag,n)
what = 3
end
end
- tex.write(what)
+ texwrite(what)
end
function notes.postpone()
@@ -212,14 +246,14 @@ function notes.postpone()
end
function notes.setsymbolpage(tag,n)
- local nd = notes.get(tag,n)
+ local nd = get(tag,n)
if nd then
nd.metadata.symbolpage = texcount.realpageno
end
end
function notes.getsymbolpage(tag,n)
- local nd = notes.get(tag,n)
+ local nd = get(tag,n)
nd = nd and nd.metadata.symbolpage
texwrite(nd or 0)
end
@@ -236,9 +270,9 @@ function notes.flush(tag,whatkind) -- store and postpone
local state = notestates[tag]
local kind = state.kind
if kind == whatkind then
+ local nd = notedata[tag]
+ local ns = state.start -- first index
if kind == "postpone" then
- local nd = notedata[tag]
- local ns = state.start -- first index
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)
@@ -250,17 +284,22 @@ function notes.flush(tag,whatkind) -- store and postpone
state.start = nil
state.kind = "insert"
elseif kind == "store" then
- local nd = notedata[tag]
- local ns = state.start -- first index
- if trace_notes then
- logs.report("notes","flushing state %s of %s from %s to %s",whatkind,tag,ns,#nd)
- end
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)
+ end
for i=ns,#nd do
texsprint(ctxcatcodes,format("\\handlenoteitself{%s}{%s}",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)
+ end
+ end
+ state.start = nil
elseif trace_notes then
logs.report("notes","not flushing state %s of %s",whatkind,tag)
end