diff options
author | Karl Berry <karl@freefriends.org> | 2015-05-08 22:36:52 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2015-05-08 22:36:52 +0000 |
commit | 5dc3418fd91c83782dce77f0b65549e14f118f51 (patch) | |
tree | 9b4ec94c1bb0be9831fd3b887de69df098d46211 /Master/texmf-dist/tex/context/base/publ-sor.lua | |
parent | b810c0301dd20283addb956384210b7926eef35d (diff) |
context
git-svn-id: svn://tug.org/texlive/trunk@37284 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/context/base/publ-sor.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/publ-sor.lua | 78 |
1 files changed, 48 insertions, 30 deletions
diff --git a/Master/texmf-dist/tex/context/base/publ-sor.lua b/Master/texmf-dist/tex/context/base/publ-sor.lua index c3fcdb0eed1..c442e395395 100644 --- a/Master/texmf-dist/tex/context/base/publ-sor.lua +++ b/Master/texmf-dist/tex/context/base/publ-sor.lua @@ -126,6 +126,7 @@ local function sortsequence(dataset,list,sorttype) if not sequence and type(sorttype) == "string" then local list = toarray(sorttype) if #list > 0 then + local indexdone = false sequence = { } for i=1,#list do local entry = toarray(list[i]) @@ -137,6 +138,16 @@ local function sortsequence(dataset,list,sorttype) default = default == s_default and c_default or default or c_default, unknown = unknown == s_unknown and c_unknown or unknown or c_unknown, } + if field == "index" then + indexdone = true + end + end + if not indexdone then + sequence[#sequence+1] = { + field = "index", + default = 0, + unknown = 0, + } end end if trace_sorters then @@ -155,12 +166,13 @@ local function sortsequence(dataset,list,sorttype) end for i=1,#sequence do - local step = sequence[i] - local field = step.field or "?" - local default = step.default or c_default - local unknown = step.unknown or c_unknown - local fldtype = types[field] - local writer = fldtype and writers[fldtype] + local step = sequence[i] + local field = step.field or "?" + local default = step.default or c_default + local unknown = step.unknown or c_unknown + local fldtype = types[field] + local fldwriter = step.writer or fldtype + local writer = fldwriter and writers[fldwriter] if trace_sorters then report("% 3i : field %a, type %a, default %a, unknown %a",i,field,fldtype, @@ -172,7 +184,7 @@ local function sortsequence(dataset,list,sorttype) if writer then local h = #helpers + 1 getters[i] = f_writer(h,field,default,field) - helpers[h] = f_helper(h,fldtype,field,fldtype) + helpers[h] = f_helper(h,fldwriter,field,fldtype) else getters[i] = f_getter(field,default,field) end @@ -213,54 +225,60 @@ local function sortsequence(dataset,list,sorttype) end +-- index : order in dataset +-- order : order of citations +-- short : alphabetic + suffix +-- reference : order in list +-- default : automatic sorter +-- authoryear : sort order list + +-- tag | listindex | 0 | u | u.btxint | data.index + local sorters = { - [v_short] = function(dataset,rendering,list) + [v_short] = function(dataset,rendering,list) -- should we store it local shorts = rendering.shorts local function compare(a,b) - local aa, bb = a and a[1], b and b[1] + local aa = a and a[1] + local bb = b and b[1] if aa and bb then aa, bb = shorts[aa], shorts[bb] return aa and bb and aa < bb + else + return a[1] < b[1] end - return false end sort(list,compare) end, - [v_reference] = function(dataset,rendering,list) + [v_reference] = function(dataset,rendering,list) -- tag local function compare(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 + return a[1] < b[1] end sort(list,compare) end, - [v_dataset] = function(dataset,rendering,list) + [v_dataset] = function(dataset,rendering,list) -- dataset index local function compare(a,b) --- inspect(a,b) - local aa, bb = a and a[6], b and b[6] + local aa = a and a[6] + local bb = b and b[6] if aa and bb then - -- aa, bb = list[aa].index or 0, list[bb].index or 0 - return aa and bb and aa < bb + return aa < bb + else + return a[1] < b[1] end - return false end sort(list,compare) end, - [v_default] = function(dataset,rendering,list,sorttype) -- experimental - if sorttype == "" or sorttype == v_default then + [v_default] = function(dataset,rendering,list,sorttype) + if sorttype == "" or sorttype == v_default then -- listorder local function compare(a,b) - local aa, bb = a and a[3], b and b[3] - if aa and bb then - return aa and bb and aa < bb - end - return false + return a[2] < b[2] end sort(list,compare) else - local valid = sortsequence(dataset,list,sorttype) + local valid = sortsequence(dataset,list,sorttype) -- field order if valid and #valid > 0 then + -- hm, we have a complication here because a sortsequence doesn't know if there's a field + -- so there is no real catch possible here .., anyway, we add a index as last entry when no + -- one is set so that should be good enough (needs testing) for i=1,#valid do local v = valid[i] valid[i] = list[v.index] |