summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/publ-tra.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/publ-tra.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/publ-tra.lua670
1 files changed, 427 insertions, 243 deletions
diff --git a/Master/texmf-dist/tex/context/base/publ-tra.lua b/Master/texmf-dist/tex/context/base/publ-tra.lua
index 98c81d800dd..65e9b7ff486 100644
--- a/Master/texmf-dist/tex/context/base/publ-tra.lua
+++ b/Master/texmf-dist/tex/context/base/publ-tra.lua
@@ -6,291 +6,475 @@ if not modules then modules = { } end modules ['publ-tra'] = {
license = "see context related readme files"
}
-local sortedhash = table.sortedhash
-
-local tracers = { }
-publications.tracers = tracers
-local datasets = publications.datasets
-
-local context = context
-local NC, NR = context.NC, context.NR
-local bold = context.bold
-local darkgreen, darkred, darkblue = context.darkgreen, context.darkred, context.darkblue
-
-local fields = table.sorted {
- "abstract",
- "address",
- "annotate",
- "author",
- "booktitle",
- "chapter",
- "comment",
- "country",
- "doi",
- "edition",
- "editor",
- "eprint",
- "howpublished",
- "institution",
- "isbn",
- "issn",
- "journal",
- "key",
- "keyword",
- "keywords",
- "language",
- "lastchecked",
- "month",
- "names",
- "note",
- "notes",
- "number",
- "organization",
- "pages",
- "publisher",
- "school",
- "series",
- "size",
- "title",
- "type",
- "url",
- "volume",
- "year",
- "nationality",
- "assignee",
- "bibnumber",
- "day",
- "dayfiled",
- "monthfiled",
- "yearfiled",
- "revision",
-}
+-- todo: use context.tt .. more efficient, less code
-local citevariants = table.sorted {
- "author",
- "authoryear",
- "authoryears",
- "authornum",
- "year",
- "short",
- "serial",
- "key",
- "doi",
- "url",
- "type",
- "page",
- "none",
- "num",
-}
+local next, type = next, type
-local listvariants = table.sorted {
- "author",
- "editor",
- "artauthor",
-}
+local sortedhash = table.sortedhash
+local sortedkeys = table.sortedkeys
+local settings_to_array = utilities.parsers.settings_to_array
+local formatters = string.formatters
+local concat = table.concat
--- local categories = table.sorted {
--- "article",
--- "book",
--- "booklet",
--- "conference",
--- "inbook",
--- "incollection",
--- "inproceedings",
--- "manual",
--- "mastersthesis",
--- "misc",
--- "phdthesis",
--- "proceedings",
--- "techreport",
--- "unpublished",
--- }
-
-local categories = {
- article = {
- required = { "author", "title", "journal", "year" },
- optional = { "volume", "number", "pages", "month", "note" },
- },
- book = {
- required = { { "author", "editor" }, "title", "publisher", "year" },
- optional = { { "volume", "number" }, "series", "address", "edition", "month","note" },
- },
- booklet = {
- required = { "title" },
- optional = { "author", "howpublished", "address", "month", "year", "note" },
- },
- inbook = {
- required = { { "author", "editor" }, "title", { "chapter", "pages" }, "publisher","year" },
- optional = { { "volume", "number" }, "series", "type", "address", "edition", "month", "note" },
- },
- incollection = {
- required = { "author", "title", "booktitle", "publisher", "year" },
- optional = { "editor", { "volume", "number" }, "series", "type", "chapter", "pages", "address", "edition", "month", "note" },
- },
- inproceedings = {
- required = { "author", "title", "booktitle", "year" },
- optional = { "editor", { "volume", "number" }, "series", "pages", "address", "month","organization", "publisher", "note" },
- },
- manual = {
- required = { "title" },
- optional = { "author", "organization", "address", "edition", "month", "year", "note" },
- },
- mastersthesis = {
- required = { "author", "title", "school", "year" },
- optional = { "type", "address", "month", "note" },
- },
- misc = {
- required = { "author", "title", "howpublished", "month", "year", "note" },
- optional = { "author", "title", "howpublished", "month", "year", "note" },
- },
- phdthesis = {
- required = { "author", "title", "school", "year" },
- optional = { "type", "address", "month", "note" },
- },
- proceedings = {
- required = { "title", "year" },
- optional = { "editor", { "volume", "number" }, "series", "address", "month", "organization", "publisher", "note" },
- },
- techreport = {
- required = { "author", "title", "institution", "year" },
- optional = { "type", "number", "address", "month", "note" },
- },
- unpublished = {
- required = { "author", "title", "note" },
- optional = { "month", "year" },
- },
-}
+local context = context
+local commands = commands
+
+local v_default = interfaces.variables.default
+
+local publications = publications
+local tracers = publications.tracers
+local tables = publications.tables
+local datasets = publications.datasets
+local specifications = publications.specifications
+local citevariants = publications.citevariants
+local getfield = publications.getfield
+local getcasted = publications.getcasted
-publications.tracers.fields = fields
-publications.tracers.categories = categories
-publications.tracers.citevariants = citevariants
-publications.tracers.listvariants = listvariants
--- -- --
+local ctx_NC, ctx_NR, ctx_HL, ctx_FL, ctx_ML, ctx_LL, ctx_EQ = context.NC, context.NR, context.HL, context.FL, context.ML, context.LL, context.EQ
-function tracers.showdatasetfields(dataset)
- local luadata = datasets[dataset].luadata
+local ctx_starttabulate = context.starttabulate
+local ctx_stoptabulate = context.stoptabulate
+
+local ctx_formatted = context.formatted
+local ctx_bold = ctx_formatted.monobold
+local ctx_monobold = ctx_formatted.monobold
+local ctx_verbatim = ctx_formatted.verbatim
+
+local ctx_rotate = context.rotate
+local ctx_llap = context.llap
+local ctx_rlap = context.rlap
+local ctx_page = context.page
+
+local privates = tables.privates
+local specials = tables.specials
+
+local report = logs.reporter("publications","tracers")
+
+function tracers.showdatasetfields(settings)
+ local dataset = settings.dataset
+ local current = datasets[dataset]
+ local luadata = current.luadata
+ local specification = settings.specification
+ local fielddata = specification and specifications[specification] or specifications.apa
+ local categories = fielddata.categories
if next(luadata) then
- context.starttabulate { "|lT|lT|pT|" }
- NC() bold("tag")
- NC() bold("category")
- NC() bold("fields")
- NC() NR() context.FL() -- HL()
- for k, v in sortedhash(luadata) do
- NC() context(k)
- NC() context(v.category)
- NC()
- for k, v in sortedhash(v) do
- if k ~= "details" and k ~= "tag" and k ~= "category" then
- context("%s ",k)
+ ctx_starttabulate { "|lT|lT|pTl|" }
+ ctx_NC() ctx_bold("tag")
+ ctx_NC() ctx_bold("category")
+ ctx_NC() ctx_bold("fields")
+ ctx_NC() ctx_NR()
+ ctx_FL()
+ for tag, entry in sortedhash(luadata) do
+ local category = entry.category
+ local catedata = categories[category]
+ local fields = catedata and catedata.fields or { }
+ ctx_NC() context(tag)
+ ctx_NC() context(category)
+ ctx_NC() -- grouping around colors needed
+ for key, value in sortedhash(entry) do
+ if privates[key] then
+ -- skip
+ elseif specials[key] then
+ context("{\\darkblue %s} ",key)
+ else
+ local kind = fields[key]
+ if kind == "required" then
+ context("{\\darkgreen %s} ",key)
+ elseif kind == "optional" then
+ context("%s ",key)
+ else
+ context("{\\darkyellow %s} ",key)
+ end
end
end
- NC() NR()
+ ctx_NC() ctx_NR()
end
- context.stoptabulate()
+ ctx_stoptabulate()
end
end
-function tracers.showdatasetcompleteness(dataset)
+function tracers.showdatasetcompleteness(settings)
+ local dataset = settings.dataset
+ local current = datasets[dataset]
+ local luadata = current.luadata
+ local specification = settings.specification
+ local fielddata = specification and specifications[specification] or specifications.apa
+ local categories = fielddata.categories
- dataset = datasets[dataset]
+ -- local lpegmatch = lpeg.match
+ -- local texescape = lpeg.patterns.texescape
- local preamble = { "|lBTw(10em)|p|" }
+ local preamble = { "|lTBw(5em)|lBTp(10em)|plT|" }
- local function required(key,value,indirect)
- NC() darkgreen(key)
- NC() if indirect then
- darkblue(value)
- elseif value then
- context(value)
+ local function identified(tag,category,crossref)
+ ctx_NC()
+ ctx_NC() ctx_monobold(category)
+ ctx_NC() if crossref then
+ ctx_monobold("%s\\hfill\\darkblue => %s",tag,crossref)
else
- darkred("\\tttf [missing]")
+ ctx_monobold(tag)
end
- NC() NR()
+ ctx_NC() ctx_NR()
end
- local function optional(key,value,indirect)
- NC() context(key)
- NC() if indirect then
- darkblue(value)
- elseif value then
- context(value)
- end
- NC() NR()
+ local function required(done,foundfields,key,value,indirect)
+ ctx_NC() if not done then ctx_monobold("required") end
+ ctx_NC() context(key)
+ ctx_NC()
+ if indirect then
+ if value then
+ context("\\darkblue")
+ ctx_verbatim(value)
+ else
+ context("\\darkred\\tttf [missing crossref]")
+ end
+ elseif value then
+ ctx_verbatim(value)
+ else
+ context("\\darkred\\tttf [missing value]")
+ end
+ ctx_NC() ctx_NR()
+ foundfields[key] = nil
+ return done or true
end
- local function identified(tag,crossref)
- NC() context("tag")
- NC() if crossref then
- context("\\tttf %s\\hfill\\darkblue => %s",tag,crossref)
- else
- context("\\tttf %s",tag)
- end
- NC() NR()
+ local function optional(done,foundfields,key,value,indirect)
+ ctx_NC() if not done then ctx_monobold("optional") end
+ ctx_NC() context(key)
+ ctx_NC()
+ if indirect then
+ context("\\darkblue")
+ ctx_verbatim(value)
+ elseif value then
+ ctx_verbatim(value)
+ end
+ ctx_NC() ctx_NR()
+ foundfields[key] = nil
+ return done or true
end
- local luadata = datasets[dataset].luadata
+ local function special(done,key,value)
+ ctx_NC() if not done then ctx_monobold("special") end
+ ctx_NC() context(key)
+ ctx_NC() ctx_verbatim(value)
+ ctx_NC() ctx_NR()
+ return done or true
+ end
+
+ local function extra(done,key,value)
+ ctx_NC() if not done then ctx_monobold("extra") end
+ ctx_NC() context(key)
+ ctx_NC() ctx_verbatim(value)
+ ctx_NC() ctx_NR()
+ return done or true
+ end
if next(luadata) then
- for tag, entry in table.sortedhash(luadata) do
- local category = entry.category
- local fields = categories[category]
+ for tag, entry in sortedhash(luadata) do
+ local category = entry.category
+ local fields = categories[category]
+ local foundfields = { }
+ for k, v in next, entry do
+ foundfields[k] = true
+ end
+ ctx_starttabulate(preamble)
+ identified(tag,category,entry.crossref)
+ ctx_FL()
if fields then
- context.starttabulate(preamble)
- identified(tag,entry.crossref)
- context.HL()
local requiredfields = fields.required
- local optionalfields = fields.optional
- for i=1,#requiredfields do
- local r = requiredfields[i]
- if type(r) == "table" then
- local okay = true
- for i=1,#r do
- local ri = r[i]
- if rawget(entry,ri) then
- required(ri,entry[ri])
- okay = true
- elseif entry[ri] then
- required(ri,entry[ri],true)
- okay = true
+ local sets = fields.sets or { }
+ local done = false
+ if requiredfields then
+ for i=1,#requiredfields do
+ local r = requiredfields[i]
+ local r = sets[r] or r
+ if type(r) == "table" then
+ local okay = false
+ for i=1,#r do
+ local ri = r[i]
+ if rawget(entry,ri) then
+ done = required(done,foundfields,ri,entry[ri])
+ okay = true
+ elseif entry[ri] then
+ done = required(done,foundfields,ri,entry[ri],true)
+ okay = true
+ end
end
+ if not okay then
+ done = required(done,foundfields,table.concat(r," {\\letterbar} "))
+ end
+ elseif rawget(entry,r) then
+ done = required(done,foundfields,r,entry[r])
+ elseif entry[r] then
+ done = required(done,foundfields,r,entry[r],true)
+ else
+ done = required(done,foundfields,r)
end
- if not okay then
- required(table.concat(r,"\\letterbar "))
- end
- elseif rawget(entry,r) then
- required(r,entry[r])
- elseif entry[r] then
- required(r,entry[r],true)
- else
- required(r)
end
end
- for i=1,#optionalfields do
- local o = optionalfields[i]
- if type(o) == "table" then
- for i=1,#o do
- local oi = o[i]
- if rawget(entry,oi) then
- optional(oi,entry[oi])
- elseif entry[oi] then
- optional(oi,entry[oi],true)
+ local optionalfields = fields.optional
+ local done = false
+ if optionalfields then
+ for i=1,#optionalfields do
+ local o = optionalfields[i]
+ local o = sets[o] or o
+ if type(o) == "table" then
+ for i=1,#o do
+ local oi = o[i]
+ if rawget(entry,oi) then
+ done = optional(done,foundfields,oi,entry[oi])
+ elseif entry[oi] then
+ done = optional(done,foundfields,oi,entry[oi],true)
+ end
end
+ elseif rawget(entry,o) then
+ done = optional(done,foundfields,o,entry[o])
+ elseif entry[o] then
+ done = optional(done,foundfields,o,entry[o],true)
end
- elseif rawget(entry,o) then
- optional(o,entry[o])
- elseif entry[o] then
- optional(o,entry[o],true)
end
end
- context.stoptabulate()
+ end
+ local done = false
+ for k, v in sortedhash(foundfields) do
+ if privates[k] then
+ -- skip
+ elseif specials[k] then
+ done = special(done,k,entry[k])
+ end
+ end
+ local done = false
+ for k, v in sortedhash(foundfields) do
+ if privates[k] then
+ -- skip
+ elseif not specials[k] then
+ done = extra(done,k,entry[k])
+ end
+ end
+ ctx_stoptabulate()
+ end
+ end
+
+end
+
+function tracers.showfields(settings)
+ local rotation = settings.rotation
+ local specification = settings.specification
+ local fielddata = specification and specifications[specification] or specifications.apa
+ local categories = fielddata.categories
+ local validfields = { }
+ for category, data in next, categories do
+ local sets = data.sets
+ local fields = data.fields
+ for name, list in next, fields do
+ validfields[name] = true
+ end
+ end
+ local s_categories = sortedkeys(categories)
+ local s_fields = sortedkeys(validfields)
+ ctx_starttabulate { "|l" .. string.rep("|c",#s_categories) .. "|" }
+ ctx_FL()
+ ctx_NC()
+ if rotation then
+ rotation = { rotation = rotation }
+ end
+ for i=1,#s_categories do
+ ctx_NC()
+ local txt = formatters["\\bf %s"](s_categories[i])
+ if rotation then
+ ctx_rotate(rotation,txt)
+ else
+ context(txt)
+ end
+ end
+ ctx_NC() ctx_NR()
+ ctx_FL()
+ for i=1,#s_fields do
+ local field = s_fields[i]
+ ctx_NC()
+ ctx_bold(field)
+ for j=1,#s_categories do
+ ctx_NC()
+ local kind = categories[s_categories[j]].fields[field]
+ if kind == "required" then
+ context("\\darkgreen*")
+ elseif kind == "optional" then
+ context("*")
+ end
+ end
+ ctx_NC() ctx_NR()
+ end
+ ctx_LL()
+ ctx_stoptabulate()
+end
+
+function tracers.showtables(settings)
+ for name, list in sortedhash(tables) do
+ ctx_starttabulate { "|Tl|Tl|" }
+ ctx_FL()
+ ctx_NC()
+ ctx_rlap(function() ctx_bold(name) end)
+ ctx_NC()
+ ctx_NC()
+ ctx_NR()
+ ctx_FL()
+ for k, v in sortedhash(list) do
+ ctx_NC()
+ context(k)
+ ctx_NC()
+ if type(v) == "table" then
+ context("% t",v)
else
- -- error
+ context(tostring(v))
+ end
+ ctx_NC()
+ ctx_NR()
+ end
+ ctx_LL()
+ ctx_stoptabulate()
+ end
+end
+
+function tracers.showdatasetauthors(settings)
+
+ local dataset = settings.dataset
+ local field = settings.field
+
+ local sortkey = publications.writers.author
+
+ if not dataset or dataset == "" then dataset = v_default end
+ if not field or field == "" then field = "author" end
+
+ local function row(i,k,v)
+ ctx_NC()
+ if i then
+ ctx_verbatim(i)
+ end
+ ctx_NC()
+ ctx_verbatim(k)
+ ctx_EQ()
+ if type(v) == "table" then
+ local t = { }
+ for i=1,#v do
+ local vi = v[i]
+ if type(vi) == "table" then
+ t[i] = concat(vi,"-")
+ else
+ t[i] = vi
+ end
+ end
+ ctx_verbatim(concat(t, " | "))
+ else
+ ctx_verbatim(v)
+ end
+ ctx_NC()
+ ctx_NR()
+ end
+
+ local function authorrow(ai,k,i)
+ local v = ai[k]
+ if v then
+ row(i,k,v)
+ end
+ end
+
+ local function commonrow(key,value)
+ ctx_NC() ctx_rlap(function() ctx_verbatim(key) end)
+ ctx_NC()
+ ctx_EQ() ctx_verbatim(value)
+ ctx_NC() ctx_NR()
+ end
+
+ local d = datasets[dataset].luadata
+
+ local trialtypesetting = context.trialtypesetting()
+
+ for tag, entry in sortedhash(d) do
+
+ local a, f, k = getcasted(dataset,tag,field)
+
+ if type(a) == "table" and #a > 0 and k == "author" then
+ context.start()
+ context.tt()
+ ctx_starttabulate { "|B|Bl|p|" }
+ ctx_FL()
+ local original = getfield(dataset,tag,field)
+ commonrow("tag",tag)
+ commonrow("field",field)
+ commonrow("original",original)
+ commonrow("sortkey",sortkey(a))
+ for i=1,#a do
+ ctx_ML()
+ local ai = a[i]
+ if ai then
+ authorrow(ai,"original",i)
+ authorrow(ai,"snippets")
+ authorrow(ai,"initials")
+ authorrow(ai,"firstnames")
+ authorrow(ai,"vons")
+ authorrow(ai,"surnames")
+ authorrow(ai,"juniors")
+ local options = ai.options
+ if options then
+ row(false,"options",sortedkeys(options))
+ end
+ elseif not trialtypesetting then
+ report("bad author name: %s",original or "?")
+ end
+ end
+ ctx_LL()
+ ctx_stoptabulate()
+ context.stop()
+ end
+
+ end
+
+end
+
+function tracers.showentry(dataset,tag)
+ local dataset = datasets[dataset]
+ if dataset then
+ local entry = dataset.luadata[tag]
+ local done = false
+ for k, v in sortedhash(entry) do
+ if not privates[k] then
+ ctx_verbatim("%w[%s: %s]",done and 1 or 0,k,v)
+ done = true
end
end
end
+end
+
+local skipped = { index = true, default = true }
+function tracers.showvariants(dataset,pages)
+ local variants = sortedkeys(citevariants)
+ for tag in publications.sortedentries(dataset or v_default) do
+ if pages then
+ ctx_page()
+ end
+ ctx_starttabulate { "|T||" }
+ for i=1,#variants do
+ local variant = variants[i]
+ if not skipped[variant] then
+ ctx_NC() context(variant)
+ -- ctx_EQ() citevariants[variant] { dataset = v_default, reference = tag, variant = variant }
+ ctx_EQ() context.cite({variant},{dataset .. "::" .. tag})
+ ctx_NC() ctx_NR()
+ end
+ end
+ ctx_stoptabulate()
+ if pages then
+ ctx_page()
+ end
+ end
end
commands.showbtxdatasetfields = tracers.showdatasetfields
commands.showbtxdatasetcompleteness = tracers.showdatasetcompleteness
+commands.showbtxfields = tracers.showfields
+commands.showbtxtables = tracers.showtables
+commands.showbtxdatasetauthors = tracers.showdatasetauthors
+commands.showbtxentry = tracers.showentry
+commands.showbtxvariants = tracers.showvariants