diff --git a/packages/bibtex/bibliography.lua b/packages/bibtex/bibliography.lua index 06f3b8d62b..3d46e06e21 100644 --- a/packages/bibtex/bibliography.lua +++ b/packages/bibtex/bibliography.lua @@ -319,11 +319,12 @@ Bibliography = { Errors = { UNKNOWN_REFERENCE = 1, + UNKNOWN_TYPE = 2, }, Style = { andAuthors = function(item) - local authors = namesplit(item.Author) + local authors = namesplit(item.author) if #authors == 1 then return parse_name(authors[1]).ll else @@ -337,7 +338,7 @@ Bibliography = { andSurnames = function (max) return function(item) - local authors = namesplit(item.Author) + local authors = namesplit(item.author) if #authors > max then return parse_name(authors[1]).ll .. SILE.fluent:get_message("bibliography-et-al") else @@ -349,11 +350,11 @@ Bibliography = { transEditor = function(item) local r = {} - if item.Editor then - r[#r+1] = SILE.fluent:get_message("bibliography-edited-by")({ name = item.Editor }) + if item.editor then + r[#r+1] = SILE.fluent:get_message("bibliography-edited-by")({ name = item.editor }) end - if item.Translator then - r[#r+1] = SILE.fluent:get_message("bibliography-translated-by")({ name = item.Translator }) + if item.translator then + r[#r+1] = SILE.fluent:get_message("bibliography-translated-by")({ name = item.translator }) end if #r then return table.concat(r, ", ") end return nil diff --git a/packages/bibtex/init.lua b/packages/bibtex/init.lua index f24952b42d..361ce77282 100644 --- a/packages/bibtex/init.lua +++ b/packages/bibtex/init.lua @@ -13,16 +13,21 @@ local bibtexparser = epnf.define(function (_ENV) local _ = WS^0 local sep = lpeg.S(",;") * _ local myID = C(identifier + lpeg.P(1)) / function (t) return t end + local myTag = C(identifier + lpeg.P(1)) / function (t) return t:lower() end local value = balanced + doubleq + myID - local pair = lpeg.Cg(myID * _ * "=" * _ * C(value)) * _ * sep^-1 / function (...) local t= {...}; return t[1], t[#t] end + local pair = lpeg.Cg(myTag * _ * "=" * _ * C(value)) * _ * sep^-1 / function (...) local t= {...}; return t[1], t[#t] end local list = lpeg.Cf(lpeg.Ct("") * pair^0, rawset) + local commentKey = lpeg.Cmt(R("az", "AZ")^1, function(_, _, a) + return a:lower() == "comment" + end) START "document" - document = (V"entry" + V"comment")^1 * (-1 + E("Unexpected character at end of input")) + document = (V"comment" + V"entry")^1 -- order important: @comment must have precedence over @other + * (-1 + E("Unexpected character at end of input")) comment = WS + ( V"blockcomment" + (P("%") * (1-lpeg.S("\r\n"))^0 * lpeg.S("\r\n")) /function () return "" end) -- Don't bother telling me about comments - blockcomment = P("@comment")+ balanced/function () return "" end -- Don't bother telling me about comments - entry = Ct( P("@") * Cg(myID, "type") * _ * P("{") * _ * Cg(myID, "label") * _ * sep * list * P("}") * _ ) + blockcomment = (P("@") * commentKey) + balanced/function () return "" end -- Don't bother telling me about comments + entry = Ct( P("@") * Cg(myTag, "type") * _ * P("{") * _ * Cg(myID, "label") * _ * sep * list * P("}") * _ ) end) -- luacheck: pop @@ -76,7 +81,7 @@ local function registerCommands (_) local bibstyle = require("packages.bibtex.styles." .. style) local cite = Bibliography.produceCitation(options, SILE.scratch.bibtex.bib, bibstyle) if cite == Bibliography.Errors.UNKNOWN_REFERENCE then - SU.warn("Unknown reference in citation "..options) + SU.warn("Unknown reference in citation "..options.key) return end SILE.doTexlike(cite) @@ -88,7 +93,11 @@ local function registerCommands (_) local bibstyle = require("packages.bibtex.styles." .. style) local cite = Bibliography.produceReference(options, SILE.scratch.bibtex.bib, bibstyle) if cite == Bibliography.Errors.UNKNOWN_REFERENCE then - SU.warn("Unknown reference in citation "..options) + SU.warn("Unknown reference in citation "..options.key) + return + end + if cite == Bibliography.Errors.UNKNOWN_TYPE then + SU.warn("Unknown type for citation reference "..options.key) return end SILE.doTexlike(cite)