Skip to content

Commit 691bfe2

Browse files
OmikhleiaDidier Willis
authored andcommitted
feat(packages): Add option for filler between item and page in indexer
1 parent e272e43 commit 691bfe2

1 file changed

Lines changed: 25 additions & 8 deletions

File tree

packages/indexer/init.lua

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,11 @@ function package:_init (options)
107107
self.config = pl.tablex.merge({
108108
["page-range-format"] = "expanded",
109109
["page-range-delimiter"] = "",
110-
["page-delimiter"] = ", "
110+
["page-delimiter"] = ", ",
111+
filler = "dotfill"
111112
}, options, true)
112113
self:loadPackage("infonode")
114+
self:loadPackage("leaders")
113115
self.class:registerHook("endpage", self.buildIndex)
114116
if not SILE.scratch.index then
115117
SILE.scratch.index = {}
@@ -206,11 +208,20 @@ function package:registerCommands ()
206208
self:registerCommand("index:item", function (options, content)
207209
-- Unconventional: options.pageno is an AST
208210
SILE.settings:temporarily(function ()
209-
SILE.settings:set("typesetter.parfillskip", SILE.types.node.glue())
211+
if self.config.filler ~= "comma" then
212+
SILE.settings:set("typesetter.parfillskip", SILE.types.node.glue())
213+
end
210214
SILE.settings:set("current.parindent", SILE.types.node.glue())
211215
SILE.call("code", {}, content)
212-
-- Ideally, leaders
213-
SILE.call("hss")
216+
if self.config.filler == "dotfill" then
217+
SILE.call("dotfill")
218+
elseif self.config.filler == "fill" then
219+
SILE.call("hss")
220+
elseif self.config.filler == "comma" then
221+
SILE.typesetter:typeset(", ")
222+
else
223+
SU.error("Unknown filler: " .. self.config.filler)
224+
end
214225
SILE.process(options.pageno)
215226
SILE.call("smallskip")
216227
end)
@@ -223,16 +234,22 @@ An index is essentially the same thing as a table of contents, but sorted.
223234
224235
The package accepts several configuration options:
225236
\begin{itemize}
226-
\item{\autodoc:parameter{page-range-format}: The format used to display page ranges.
237+
\item{\autodoc:parameter{page-range-format}: The format used to display page ranges for arabic numbers.
227238
Possible values are:
228239
\begin{itemize}
229240
\item{\code{none}: All numbers are displayed, without page range collapsing.}
230-
\item{\code{expanded}: All digits are displayed in both numbers in a page range: 42–45, 321–328, 2787–2816.}
231-
\item{\code{minimal}: All digits repeated in the second number are left out in a page range: 42–5, 321–8, 2787–816}
232-
\item{\code{minimal-two}: As \code{minimal}, but at least two digits are kept in the second number when it has two or more digits long.}
241+
\item{\code{expanded} (default): All digits are displayed in a page range: 42–45, 321–328, 2787–2816.}
242+
\item{\code{minimal}: All digits repeated in the second number are left out in a page range: 42–5, 321–8, 2787–816.}
243+
\item{\code{minimal-two}: As \code{minimal}, but at least two digits are kept in the second number when it has two or more digits long: 42–45, 321–28, 2787–816.}
233244
\end{itemize}}
234245
\item{\autodoc:parameter{page-range-delimiter}: The delimiter between the start and end of a page range.}
235246
\item{\autodoc:parameter{page-delimiter}: The delimiter between pages.}
247+
\item{\autodoc:parameter{filler}: The filler between the index item and the page number. Possible values are:
248+
\begin{itemize}
249+
\item{\code{dotfill} (default): Fill with dots (leaders).}
250+
\item{\code{fill}: Fill with a stretchable space.}
251+
\item{\code{comma}: Use a comma, and page numbers are not flushed to the end of the line.}
252+
\end{itemize}}
236253
\end{itemize}
237254
238255
This package provides the \autodoc:command{\indexentry} command, which can be called as either \autodoc:command{\indexentry[label=<text>]} or \autodoc:command{\indexentry{<text>}} (so that it can be called from a macro).

0 commit comments

Comments
 (0)