summaryrefslogtreecommitdiff
path: root/tex/context/base/bibl-tra.lua
diff options
context:
space:
mode:
authorMarius <mariausol@gmail.com>2013-08-08 12:00:15 +0300
committerMarius <mariausol@gmail.com>2013-08-08 12:00:15 +0300
commit7e69eda2c0f61a9c55ee44c8bff3573b151447ff (patch)
treec4c2612514b8f4222d8b0cf9ce7e20d6f344cd3f /tex/context/base/bibl-tra.lua
parentcdce0fa06cf058270517c660a04f3f0de4fddb93 (diff)
downloadcontext-7e69eda2c0f61a9c55ee44c8bff3573b151447ff.tar.gz
beta 2013.08.08 10:48
Diffstat (limited to 'tex/context/base/bibl-tra.lua')
-rw-r--r--tex/context/base/bibl-tra.lua66
1 files changed, 44 insertions, 22 deletions
diff --git a/tex/context/base/bibl-tra.lua b/tex/context/base/bibl-tra.lua
index 63a7b7852..39eae3bcd 100644
--- a/tex/context/base/bibl-tra.lua
+++ b/tex/context/base/bibl-tra.lua
@@ -6,6 +6,8 @@ if not modules then modules = { } end modules ['bibl-tra'] = {
license = "see context related readme files"
}
+-- also see bibl-tra-new !
+
local match, gmatch, format, concat, sort = string.match, string.gmatch, string.format, table.concat, table.sort
bibtex = bibtex or { }
@@ -18,26 +20,27 @@ local trace_bibtex = false trackers.register("publications.bibtex", function(v)
local report_tex = logs.reporter("publications","tex")
-local context = context
-local structures = structures
+local context = context
+local structures = structures
-local references = structures.references
-local sections = structures.sections
+local references = structures.references
+local sections = structures.sections
-local variables = interfaces.variables
+local variables = interfaces.variables
-local v_short = variables.short
-local v_cite = variables.cite
-local v_default = variables.default
+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 list = { }
+local done = { }
+local alldone = { }
+local used = { }
+local registered = { }
+local ordered = { }
+local shorts = { }
+local mode = 0
local template = utilities.strings.striplong([[
\citation{*}
@@ -74,9 +77,9 @@ function hacks.register(tag,short)
report_tex("registering bibtex entry %a with shortcut %a",tag,short)
end
local top = #registered + 1
- registered[top] = tag
- ordered [tag] = top
- shorts [short] = top
+ registered[top] = tag
+ ordered [tag] = top
+ shorts [tag] = short
end
function hacks.nofregistered()
@@ -108,18 +111,37 @@ function hacks.add(str,listindex)
end
function hacks.flush(sortvariant)
+ 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
- local data = sortvariant == v_short and shorts or ordered
- local function compare(a,b) -- quite some checking for non-nil
+ compare = function(a,b)
local aa, bb = a and a[1], b and b[1]
if aa and bb then
- local oa, ob = data[aa], data[bb]
+ 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