summaryrefslogtreecommitdiff
path: root/tex/context/base/bibl-tra.lua
diff options
context:
space:
mode:
authorMarius <mariausol@gmail.com>2013-10-20 01:21:09 +0300
committerMarius <mariausol@gmail.com>2013-10-20 01:21:09 +0300
commitb8ac6d7b7fdb16293c28034c349efd5b0b7b20b3 (patch)
tree0e9051dbe21b4e9cfc72fe594df5b0fe7bc511f3 /tex/context/base/bibl-tra.lua
parent965214d981e6129b782c67adcaf3a81aedcb0bac (diff)
downloadcontext-b8ac6d7b7fdb16293c28034c349efd5b0b7b20b3.tar.gz
beta 2013.10.20 07:09
Diffstat (limited to 'tex/context/base/bibl-tra.lua')
-rw-r--r--tex/context/base/bibl-tra.lua84
1 files changed, 62 insertions, 22 deletions
diff --git a/tex/context/base/bibl-tra.lua b/tex/context/base/bibl-tra.lua
index 6a7016023..39eae3bcd 100644
--- a/tex/context/base/bibl-tra.lua
+++ b/tex/context/base/bibl-tra.lua
@@ -6,26 +6,41 @@ 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 { }
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 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 = utilities.strings.striplong([[
\citation{*}
@@ -54,12 +69,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 +110,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 +274,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