Skip to content

Commit bdba2ea

Browse files
OmikhleiaDidier Willis
authored andcommitted
feat(packages): Add \cites to output grouped bibliographic citations
1 parent f828e9b commit bdba2ea

1 file changed

Lines changed: 32 additions & 2 deletions

File tree

packages/bibtex/init.lua

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,8 +533,6 @@ function package:registerCommands ()
533533
end)
534534

535535
self:registerCommand("csl:cite", function (options, content)
536-
-- TODO:
537-
-- - multiple citation keys (but how to handle locators then?)
538536
local entry, citnum = self:getEntryForCite(options, content, false)
539537
if entry then
540538
local engine = self:getCslEngine()
@@ -548,6 +546,34 @@ function package:registerCommands ()
548546
end
549547
end, "Produce a single citation.")
550548

549+
self:registerCommand("cites", function (_, content)
550+
if type(content) ~= "table" then
551+
SU.error("Table content expected in \\cites")
552+
end
553+
local cites = {}
554+
for i = 1, #content do
555+
if type(content[i]) == "table" then
556+
local c = content[i]
557+
if c.command ~= "cite" then
558+
SU.error("Only \\cite commands are allowed in \\cites")
559+
end
560+
local o = c.options
561+
local entry, citnum = self:getEntryForCite(o, c, false)
562+
if entry then
563+
local locator = self:getLocator(o)
564+
local csljson = bib2csl(entry, citnum)
565+
csljson.locator = locator
566+
cites[#cites + 1] = csljson
567+
end
568+
end
569+
end
570+
if #cites > 0 then
571+
local engine = self:getCslEngine()
572+
local cite = engine:cite(cites)
573+
SILE.processString(("<sile>%s</sile>"):format(cite), "xml")
574+
end
575+
end, "Produce a group of citations.")
576+
551577
self:registerCommand("csl:reference", function (options, content)
552578
local entry, citnum = self:getEntryForCite(options, content, true)
553579
if entry then
@@ -670,6 +696,10 @@ Some frequent abbreviations are also supported (art, chap, col, fig…)
670696
To mark an entry as cited without actually producing a citation, use \autodoc:command{\nocite{<key>}}.
671697
This is useful when you want to include an entry in the bibliography without citing it in the text.
672698
699+
To generate multiple citations grouped correctly, use \autodoc:command{\cites{\cite{<key1>}, \cite{<key2>}, …}}.
700+
This wrapper command only accepts \autodoc:command{\cite} elements following their standard syntax.
701+
Any other element triggers an error, and any text content is silently ignored.
702+
673703
To produce a bibliography of cited references, use \autodoc:command{\printbibliography}.
674704
After printing the bibliography, the list of cited entries will be cleared. This allows you to start fresh for subsequent uses (e.g., in a different chapter).
675705
If you want to include all entries in the bibliography, not just those that have been cited, set the option \autodoc:parameter{cited} to false.

0 commit comments

Comments
 (0)