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.lua112
1 files changed, 83 insertions, 29 deletions
diff --git a/Master/texmf-dist/tex/context/base/bibl-tra.lua b/Master/texmf-dist/tex/context/base/bibl-tra.lua
index 6a70160230e..223554b4daa 100644
--- a/Master/texmf-dist/tex/context/base/bibl-tra.lua
+++ b/Master/texmf-dist/tex/context/base/bibl-tra.lua
@@ -6,32 +6,60 @@ if not modules then modules = { } end modules ['bibl-tra'] = {
license = "see context related readme files"
}
+-- also see bibl-tra-new !
+
+-- temporary hack, needed for transition
+
+if not publications then
+
+ local hacks = utilities.storage.allocate()
+
+ job.register('publications.collected',hacks,function(t) publications.collected = t end)
+
+end
+
+-- end of hack
+
+
+local match, gmatch, format, concat, sort = string.match, string.gmatch, string.format, table.concat, table.sort
+
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 variables, constants = interfaces.variables, interfaces.constants
-
local trace_bibtex = false trackers.register("publications.bibtex", function(v) trace_bibtex = v end)
local report_tex = logs.reporter("publications","tex")
-local context, structures = context, structures
+local context = context
+local structures = structures
-local references = structures.references
-local sections = structures.sections
+local references = structures.references
+local sections = structures.sections
-local list, done, alldone, used, registered, ordered = { }, { }, { }, { }, { }, { }
-local mode = 0
+local variables = interfaces.variables
-local template = utilities.strings.striplong([[
- \citation{*}
- \bibstyle{cont-%s}
- \bibdata{%s}
-]])
+local v_short = variables.short
+local v_cite = variables.cite
+local v_default = variables.default
+local v_reference = variables.default
+
+local list = { }
+local done = { }
+local alldone = { }
+local used = { }
+local registered = { }
+local ordered = { }
+local shorts = { }
+local mode = 0
+
+local template = [[
+\citation{*}
+\bibstyle{cont-%s}
+\bibdata{%s}
+]]
local bibtexbin = environment.arguments.mlbibtex and "mlbibcontext" or "bibtex"
@@ -44,8 +72,9 @@ function hacks.process(settings)
local database = settings.database or ""
local jobname = tex.jobname
if database ~= "" then
- interfaces.showmessage("publications",3)
- io.savedata(file.addsuffix(jobname,"aux"),format(template,style,database))
+ local targetfile = file.addsuffix(jobname,"aux")
+ interfaces.showmessage("publications",3,targetfile)
+ io.savedata(targetfile,format(template,style,database))
if trace_bibtex then
report_tex("processing bibtex file %a using %a",jobname,bibtexbin)
end
@@ -54,12 +83,17 @@ function hacks.process(settings)
end
end
-function hacks.register(str)
+function hacks.register(tag,short)
+ if not short or short == "" then
+ short = tag
+ end
if trace_bibtex then
- report_tex("registering bibtex entry %a",str)
+ report_tex("registering bibtex entry %a with shortcut %a",tag,short)
end
- registered[#registered+1] = str
- ordered[str] = #registered
+ local top = #registered + 1
+ registered[top] = tag
+ ordered [tag] = top
+ shorts [tag] = short
end
function hacks.nofregistered()
@@ -90,19 +124,38 @@ function hacks.add(str,listindex)
end
end
-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
- local oa, ob = ordered[aa], ordered[bb]
- return oa and ob and oa < ob
- end
- return false
-end
-
function hacks.flush(sortvariant)
- if sortvariant == "" or sortvariant == variables.cite or sortvariant == "default" then
+ local compare -- quite some checking for non-nil
+ if sortvariant == "" or sortvariant == v_cite or sortvariant == v_default then
-- order is cite order i.e. same as list
+ elseif sortvariant == v_short then
+ compare = function(a,b)
+ local aa, bb = a and a[1], b and b[1]
+ if aa and bb then
+ local oa, ob = shorts[aa], shorts[bb]
+ return oa and ob and oa < ob
+ end
+ return false
+ end
+ elseif sortvariant == v_reference then
+ compare = function(a,b)
+ local aa, bb = a and a[1], b and b[1]
+ if aa and bb then
+ return aa and bb and aa < bb
+ end
+ return false
+ end
else
+ compare = function(a,b)
+ local aa, bb = a and a[1], b and b[1]
+ if aa and bb then
+ local oa, ob = ordered[aa], ordered[bb]
+ return oa and ob and oa < ob
+ end
+ return false
+ end
+ end
+ if compare then
sort(list,compare)
end
for i=1,#list do
@@ -235,6 +288,7 @@ function hacks.resolve(prefix,block,reference) -- maybe already feed it split
if c[3] then
context.dowithbibtexnumrefrange(#collected,i,prefix,c[1],c[2],c[3],c[4])
else
+-- print(#collected,i,prefix,c[1],c[2])
context.dowithbibtexnumref(#collected,i,prefix,c[1],c[2])
end
end