summaryrefslogtreecommitdiff
path: root/biblio/citation-style-language/citeproc-latex-core.lua
diff options
context:
space:
mode:
Diffstat (limited to 'biblio/citation-style-language/citeproc-latex-core.lua')
-rw-r--r--biblio/citation-style-language/citeproc-latex-core.lua55
1 files changed, 18 insertions, 37 deletions
diff --git a/biblio/citation-style-language/citeproc-latex-core.lua b/biblio/citation-style-language/citeproc-latex-core.lua
index 0be2381797..8472818bac 100644
--- a/biblio/citation-style-language/citeproc-latex-core.lua
+++ b/biblio/citation-style-language/citeproc-latex-core.lua
@@ -7,6 +7,7 @@
local core = {}
local citeproc = require("citeproc")
+local bibtex -- = require("citeproc-bibtex") -- load on demand
local util = citeproc.util
require("lualibs")
@@ -15,44 +16,24 @@ core.locale_file_format = "csl-locales-%s.xml"
core.uncited_ids = {}
core.uncite_all_items = false
-function core.error(message)
- if luatexbase then
- luatexbase.module_error("csl", message)
- else
- util.error(message)
- end
-end
-
-function core.warning(message)
- if luatexbase then
- luatexbase.module_warning("csl", message)
- else
- util.warning(message)
- end
-end
-function core.info(message)
- if luatexbase then
- luatexbase.module_info("csl", message)
+function core.read_file(file_name, ftype, file_info)
+ if file_info then
+ file_info = util.capitalize(file_info)
else
- util.info(message)
+ file_info = "File"
end
-end
-
-
-function core.read_file(file_name, ftype, file_info)
- file_info = file_info or "file"
local path = kpse.find_file(file_name, ftype)
if not path then
if ftype and not util.endswith(file_name, ftype) then
file_name = file_name .. ftype
end
- core.error(string.format('Cannot find %s "%s"', file_info, file_name))
+ util.error(string.format('%s "%s" not found', file_info, file_name))
return nil
end
local file = io.open(path, "r")
if not file then
- core.error(string.format('Cannot open %s "%s"', file_info, path))
+ util.error(string.format('Cannot open %s "%s"', file_info, path))
return nil
end
local contents = file:read("*a")
@@ -85,7 +66,7 @@ local function read_data_file(data_file)
extension = ".bib"
contents = core.read_file(data_file, "bib", "database file")
else
- core.error(string.format('Cannot find database file "%s"', data_file .. ".json"))
+ util.error(string.format('Cannot find database file "%s"', data_file .. ".json"))
end
end
end
@@ -95,7 +76,8 @@ local function read_data_file(data_file)
if extension == ".json" then
csl_items = utilities.json.tolua(contents)
elseif extension == ".bib" then
- csl_items = citeproc.parse_bib(contents)
+ bibtex = bibtex or require("citeproc-bibtex")
+ csl_items = bibtex.parse(contents)
end
return file_name, csl_items
@@ -111,7 +93,7 @@ local function read_data_files(data_files)
for _, item in ipairs(csl_items) do
local id = item.id
if bib[id] then
- core.warning(string.format('Duplicate entry key "%s" in "%s".', id, file_name))
+ util.warning(string.format('Duplicate entry key "%s" in "%s".', id, file_name))
else
bib[id] = item
end
@@ -132,9 +114,6 @@ function core.make_citeproc_sys(data_files)
end,
retrieveItem = function (id)
local res = core.bib[id]
- -- if not res then
- -- core.warning(string.format('Failed to find entry "%s".', id))
- -- end
return res
end
}
@@ -146,9 +125,9 @@ function core.init(style_name, data_files, lang)
if style_name == "" or #data_files == 0 then
return nil
end
- local style = core.read_file(style_name .. ".csl", nil, "style file")
+ local style = core.read_file(style_name .. ".csl", nil, "style")
if not style then
- core.error(string.format('Failed to load style "%s.csl"', style_name))
+ util.error(string.format('Failed to load style "%s.csl"', style_name))
return nil
end
@@ -244,10 +223,12 @@ function core.update_uncited_items(engine, citations)
for _, citation in ipairs(citations) do
if citation.citationID == "@nocite" then
for _, cite_item in ipairs(citation.citationItems) do
- table.insert(core.uncited_ids, cite_item.id)
if cite_item.id == "*" then
- for id, _ in pairs(core.bib) do
- table.insert(core.uncited_ids, id)
+ if not core.uncite_all_items then
+ for id, _ in pairs(core.bib) do
+ table.insert(core.uncited_ids, id)
+ end
+ core.uncite_all_items = true
end
else
table.insert(core.uncited_ids, cite_item.id)