• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

sile-typesetter / sile / 15507594683

07 Jun 2025 11:54AM UTC coverage: 30.951% (-30.4%) from 61.309%
15507594683

push

github

alerque
chore(tooling): Add post-checkout hook to clear makedeps on branch switch

6363 of 20558 relevant lines covered (30.95%)

3445.44 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

64.29
/packages/infonode/init.lua
1
local base = require("packages.base")
2✔
2

3
local package = pl.class(base)
2✔
4
package._name = "infonode"
2✔
5

6
-- Info nodes are used to store information about what actually ends up on which page.
7
-- Index terms are an obvious use for this, as well as anything where you wanted to
8
-- know where something had ended up after the page builder had broken the page.
9
-- Check out SILE.scratch.info.thispage in your end-of-page routine and see what nodes
10
-- are there.
11

12
local _info = pl.class(SILE.types.node.zerohbox)
2✔
13
_info.type = "info"
2✔
14

15
function _info:__tostring ()
2✔
16
   return "I<" .. self.category .. "|" .. tostring(self.value) .. ">"
×
17
end
18

19
function _info:outputYourself ()
2✔
20
   if not SILE.scratch.info.thispage[self.category] then
×
21
      SILE.scratch.info.thispage[self.category] = { self.value }
×
22
   else
23
      local i = #SILE.scratch.info.thispage[self.category] + 1
×
24
      SILE.scratch.info.thispage[self.category][i] = self.value
×
25
   end
26
end
27

28
local function newPageInfo (_)
29
   SILE.scratch.info = { thispage = {} }
15✔
30
end
31

32
function package:_init ()
2✔
33
   base._init(self)
2✔
34
   if not SILE.scratch.info then
2✔
35
      SILE.scratch.info = { thispage = {} }
2✔
36
   end
37
   self.class:registerHook("newpage", newPageInfo)
2✔
38
end
39

40
function package:registerCommands ()
2✔
41
   self.commands:register("info", function (options, _)
6✔
42
      SU.required(options, "category", "info node")
×
43
      SU.required(options, "value", "info node")
×
44
      table.insert(
×
45
         SILE.typesetter.state.nodes,
×
46
         _info({
×
47
            category = options.category,
48
            value = options.value,
49
         })
50
      )
51
   end, "Inserts an info node onto the current page")
2✔
52
end
53

54
package.documentation = [[
55
\begin{document}
56
\autodoc:note{This package is only for class designers.}
57

58
While typesetting a document, SILE first breaks a paragraph into lines, then arranges lines into a page, and later outputs the page.
59
In other words, while it is looking at the text of a paragraph, it is not clear what page the text will eventually end up on.
60
This makes it difficult to produce indexes, tables of contents, and so on, where one needs to know the page number for a particular element.
61

62
To get around this problem, the \autodoc:package{infonode} package allows you to insert \em{information nodes} into the text stream; when a page is outputted, these nodes are collected into a list, and a class’s output routine can examine this list to determine which nodes fell on a particular page.
63
\autodoc:package{infonode} provides the \autodoc:command{\info} command to put an information node into the text stream; it has two required parameters, \autodoc:parameter{category=<name>} and \autodoc:parameter{value=<any object>}.
64
Categories are used to group similar sets of node together.
65

66
As an example, when typesetting a Bible, you may wish to display which range of verses are on each page as a running header.
67
During the command which starts a new verse, you would insert an information node with the verse reference:
68

69
\begin[type=autodoc:codeblock]{raw}
70
SILE.call("info", { category = "references", value = ref }, {})
71
\end{raw}
72

73
During the \code{endPage} method which is called at the end of every page, we look at the list of “references” information nodes:
74

75
\begin[type=autodoc:codeblock]{raw}
76
local refs = SILE.scratch.info.thispage.references
77
local runningHead = SILE.shaper.shape(refs[1] .. " - " .. refs[#refs])
78
SILE.typesetNaturally(rhFrame, runningHead);
79
\end{raw}
80
\end{document}
81
]]
2✔
82

83
return package
2✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc