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

sile-typesetter / sile / 6713098919

31 Oct 2023 10:21PM UTC coverage: 52.831% (-21.8%) from 74.636%
6713098919

push

github

web-flow
Merge d0a2a1ee9 into b185d4972

45 of 45 new or added lines in 3 files covered. (100.0%)

8173 of 15470 relevant lines covered (52.83%)

6562.28 hits per line

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

0.0
/packages/infonode/init.lua
1
local base = require("packages.base")
×
2

3
local package = pl.class(base)
×
4
package._name = "infonode"
×
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.nodefactory.zerohbox)
×
13
_info.type = "info"
×
14

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

19
function _info:outputYourself ()
×
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 = {} }
×
30
end
31

32
local _deprecate  = [[
33
  Directly calling info node handling functions is no longer necessary. All the
34
  SILE core classes and anything inheriting from them will take care of this
35
  automatically using hooks. Custom classes that override the class:endPage()
36
  function may need to handle this in other ways. By calling this hook directly
37
  you are likely causing it to run twice and duplicate entries.
38
]]
×
39

40
function package:_init ()
×
41
  base._init(self)
×
42
  if not SILE.scratch.info then
×
43
    SILE.scratch.info = { thispage = {} }
×
44
  end
45
  self.class:registerHook("newpage", newPageInfo)
×
46
  self:deprecatedExport("newPageInfo", function (class)
×
47
    SU.deprecated("class:newPageInfo", nil, "0.13.0", "0.15.0", _deprecate)
×
48
    return class:newPageInfo()
×
49
  end)
50
end
51

52
function package:registerCommands ()
×
53

54
  self:registerCommand("info", function (options, _)
×
55
    SU.required(options, "category", "info node")
×
56
    SU.required(options, "value", "info node")
×
57
    table.insert(SILE.typesetter.state.nodes, _info({
×
58
          category = options.category,
59
          value = options.value
×
60
      }))
61
  end, "Inserts an info node onto the current page")
×
62

63
end
64

65
package.documentation = [[
66
\begin{document}
67
\autodoc:note{This package is only for class designers.}
68

69
While typesetting a document, SILE first breaks a paragraph into lines, then arranges lines into a page, and later outputs the page.
70
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.
71
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.
72

73
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.
74
\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>}.
75
Categories are used to group similar sets of node together.
76

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

80
\begin[type=autodoc:codeblock]{raw}
81
SILE.call("info", { category = "references", value = ref }, {})
82
\end{raw}
83

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

86
\begin[type=autodoc:codeblock]{raw}
87
local refs = SILE.scratch.info.thispage.references
88
local runningHead = SILE.shaper.shape(refs[1] .. " - " .. refs[#refs])
89
SILE.typesetNaturally(rhFrame, runningHead);
90
\end{raw}
91
\end{document}
92
]]
×
93

94
return package
×
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

© 2025 Coveralls, Inc