summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/bibl-tra.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/bibl-tra.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/bibl-tra.lua85
1 files changed, 55 insertions, 30 deletions
diff --git a/Master/texmf-dist/tex/context/base/bibl-tra.lua b/Master/texmf-dist/tex/context/base/bibl-tra.lua
index 44223102859..4ae81188d87 100644
--- a/Master/texmf-dist/tex/context/base/bibl-tra.lua
+++ b/Master/texmf-dist/tex/context/base/bibl-tra.lua
@@ -6,21 +6,28 @@ if not modules then modules = { } end modules ['bibl-bib'] = {
license = "see context related readme files"
}
-bibtex = bibtex or { }
+bibtex = bibtex or { }
+local bibtex = bibtex
+
bibtex.hacks = bibtex.hacks or { }
+local hacks = bibtex.hacks
local match, gmatch, format, concat, sort = string.match, string.gmatch, string.format, table.concat, table.sort
-local texsprint, ctxcatcodes = tex.sprint, tex.ctxcatcodes
local variables, constants = interfaces.variables, interfaces.constants
local trace_bibtex = false trackers.register("publications.bibtex", function(v) trace_bibtex = v end)
-local hacks = bibtex.hacks
+local report_tex = logs.reporter("publications","tex")
+
+local context, structures = context, structures
+
+local references = structures.references
+local sections = structures.sections
local list, done, alldone, used, registered, ordered = { }, { }, { }, { }, { }, { }
local mode = 0
-local template = string.striplong([[
+local template = utilities.strings.striplong([[
\citation{*}
\bibstyle{cont-%s}
\bibdata{%s}
@@ -34,7 +41,7 @@ function hacks.process(settings)
interfaces.showmessage("publications",3)
io.savedata(file.addsuffix(jobname,"aux"),format(template,style,database))
if trace_bibtex then
- logs.report("publications","processing bibtex file '%s'",jobname)
+ report_tex("processing bibtex file '%s'",jobname)
end
os.execute(format("bibtex %s",jobname))
-- purge 'm
@@ -43,12 +50,16 @@ end
function hacks.register(str)
if trace_bibtex then
- logs.report("publications","registering bibtex entry '%s'",str)
+ report_tex("registering bibtex entry '%s'",str)
end
registered[#registered+1] = str
ordered[str] = #registered
end
+function hacks.nofregistered()
+ return #registered
+end
+
function hacks.reset(m)
mode, list, done = m, { }, { }
end
@@ -58,14 +69,14 @@ function hacks.add(str,listindex)
-- skip
elseif mode == 1 then
-- all locals but no duplicates
- local sc = structure.sections.currentid()
+ local sc = sections.currentid()
if done[str] ~= sc then
done[str], alldone[str] = sc, true
list[#list+1] = { str, listindex }
end
elseif mode == 2 then
-- all locals but no preceding
- local sc = structure.sections.currentid()
+ local sc = sections.currentid()
if not alldone[str] and done[str] ~= sc then
done[str], alldone[str] = sc, true
list[#list+1] = { str, listindex }
@@ -73,13 +84,13 @@ function hacks.add(str,listindex)
end
end
-local function compare(a,b)
- local aa, bb = a[1], b[1]
+local function compare(a,b) -- quite some checking for non-nil
+ local aa, bb = a and a[1], b and b[1]
if aa and bb then
- return ordered[aa] < ordered[bb]
- else
- return true
+ local oa, ob = ordered[aa], ordered[bb]
+ return oa and ob and oa < ob
end
+ return false
end
function hacks.flush(sortvariant)
@@ -93,6 +104,12 @@ function hacks.flush(sortvariant)
end
end
+function hacks.filterall()
+ for i=1,#registered do
+ list[i] = { registered[i], i }
+ end
+end
+
function hacks.registerplaced(str)
used[str] = true
end
@@ -106,15 +123,16 @@ end
-- we look forward
local function compare(a,b)
- return a[3] < b[3]
+ local aa, bb = a and a[3], b and b[3]
+ return aa and bb and aa < bb
end
function hacks.resolve(prefix,block,reference) -- maybe already feed it split
- local subset = jobreferences.collected[prefix or ""] or jobreferences.collected[""]
+ local subset = references.collected[prefix or ""] or references.collected[""]
if subset then
- local result, done = { }, { }
+ local result, nofresult, done = { }, 0, { }
block = tonumber(block)
- for rest in gmatch(reference,"([^,%s]+)") do
+ for rest in gmatch(reference,"[^, ]+") do
local blk, tag, found = block, nil, nil
if block then
tag = blk .. ":" .. rest
@@ -136,9 +154,10 @@ function hacks.resolve(prefix,block,reference) -- maybe already feed it split
found = subset[tag]
end
if found then
- local current = found.entries and found.entries.text
+ local current = tonumber(found.entries and found.entries.text) -- tonumber needed
if current and not done[current] then
- result[#result+1] = { blk, rest, current }
+ nofresult = nofresult + 1
+ result[nofresult] = { blk, rest, current }
done[current] = true
end
end
@@ -146,8 +165,8 @@ function hacks.resolve(prefix,block,reference) -- maybe already feed it split
-- todo: ranges so the interface will change
sort(result,compare)
local first, last, firsti, lasti, firstr, lastr
- local collected = { }
- for i=1,#result do
+ local collected, nofcollected = { }, 0
+ for i=1,nofresult do
local r = result[i]
local current = r[3]
if not first then
@@ -156,28 +175,34 @@ function hacks.resolve(prefix,block,reference) -- maybe already feed it split
last, lasti, lastr = current, i, r
else
if last > first + 1 then
- collected[#collected+1] = { firstr[1], firstr[2], lastr[1], lastr[2] }
+ nofcollected = nofcollected + 1
+ collected[nofcollected] = { firstr[1], firstr[2], lastr[1], lastr[2] }
else
- collected[#collected+1] = { firstr[1], firstr[2] }
+ nofcollected = nofcollected + 1
+ collected[nofcollected] = { firstr[1], firstr[2] }
if last > first then
- collected[#collected+1] = { lastr[1], lastr[2] }
+ nofcollected = nofcollected + 1
+ collected[nofcollected] = { lastr[1], lastr[2] }
end
end
first, last, firsti, lasti, firstr, lastr = current, current, i, i, r, r
end
end
- if first then
+ if first and last then
if last > first + 1 then
- collected[#collected+1] = { firstr[1], firstr[2], lastr[1], lastr[2] }
+ nofcollected = nofcollected + 1
+ collected[nofcollected] = { firstr[1], firstr[2], lastr[1], lastr[2] }
else
- collected[#collected+1] = { firstr[1], firstr[2] }
+ nofcollected = nofcollected + 1
+ collected[nofcollected] = { firstr[1], firstr[2] }
if last > first then
- collected[#collected+1] = { lastr[1], lastr[2] }
+ nofcollected = nofcollected + 1
+ collected[nofcollected] = { lastr[1], lastr[2] }
end
end
end
- if #collected > 0 then
- for i=1,#collected do
+ if nofcollected > 0 then
+ for i=1,nofcollected do
local c = collected[i]
if c[3] then
context.dowithbibtexnumrefrange(#collected,i,prefix,c[1],c[2],c[3],c[4])