• 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/footnotes/init.lua
1
local base = require("packages.base")
×
2

3
local package = pl.class(base)
×
4
package._name = "footnotes"
×
5

6
function package:_init (options)
×
7
  base._init(self)
×
8
  self:loadPackage("counters")
×
9
  self:loadPackage("raiselower")
×
10
  self:loadPackage("insertions")
×
11
  if not SILE.scratch.counters.footnotes then
×
12
    SILE.scratch.counters.footnote = { value = 1, display = "arabic" }
×
13
  end
14
  options = options or {}
×
15
  self.class:initInsertionClass("footnote", {
×
16
    insertInto = options.insertInto or "footnotes",
17
    stealFrom = options.stealFrom or { "content" },
18
    maxHeight = SILE.length("75%ph"),
19
    topBox = SILE.nodefactory.vglue("2ex"),
20
    interInsertionSkip = SILE.length("1ex"),
21
  })
22

23
end
24

25
function package:registerCommands ()
×
26

27
  self:registerCommand("footnotemark", function (_, _)
×
28
    SILE.call("raise", { height = "0.7ex" }, function ()
×
29
      SILE.call("font", { size = "1.5ex" }, function ()
×
30
        SILE.typesetter:typeset(self.class.packages.counters:formatCounter(SILE.scratch.counters.footnote))
×
31
      end)
32
    end)
33
  end)
34

35
  self:registerCommand("footnote:separator", function (_, content)
×
36
    SILE.settings:pushState()
×
37
    local material = SILE.call("vbox", {}, content)
×
38
    SILE.scratch.insertions.classes.footnote.topBox = material
×
39
    SILE.settings:popState()
×
40
  end)
41

42
  self:registerCommand("footnote:options", function (options, _)
×
43
    if options["maxHeight"] then
×
44
      SILE.scratch.insertions.classes.footnote.maxHeight = SILE.length(options["maxHeight"])
×
45
    end
46
    if options["interInsertionSkip"] then
×
47
      SILE.scratch.insertions.classes.footnote.interInsertionSkip = SILE.length(options["interInsertionSkip"])
×
48
    end
49
  end)
50

51
  self:registerCommand("footnote", function (options, content)
×
52
    SILE.call("footnotemark")
×
53
    local opts = SILE.scratch.insertions.classes.footnote or {}
×
54
    local frame = opts.insertInto and SILE.getFrame(opts.insertInto.frame)
×
55
    local oldGetTargetLength = SILE.typesetter.getTargetLength
×
56
    local oldFrame = SILE.typesetter.frame
×
57
    SILE.typesetter.getTargetLength = function () return SILE.length(0xFFFFFF) end
×
58
    SILE.settings:pushState()
×
59
    -- Restore the settings to the top of the queue, which should be the document #986
60
    SILE.settings:toplevelState()
×
61
    SILE.typesetter:initFrame(frame)
×
62

63
    -- Reset settings the document may have but should not be applied to footnotes
64
    -- See also same resets in folio package
65
    for _, v in ipairs({
×
66
      "current.hangAfter",
67
      "current.hangIndent",
68
      "linebreak.hangAfter",
69
      "linebreak.hangIndent" }) do
×
70
      SILE.settings:set(v, SILE.settings.defaults[v])
×
71
    end
72

73
    -- Apply the font before boxing, so relative baselineskip applies #1027
74
    local material
75
    SILE.call("footnote:font", {}, function ()
×
76
      material = SILE.call("vbox", {}, function ()
×
77
        SILE.call("footnote:atstart", options)
×
78
        SILE.call("footnote:counter", options)
×
79
        SILE.process(content)
×
80
      end)
81
    end)
82
    SILE.settings:popState()
×
83
    SILE.typesetter.getTargetLength = oldGetTargetLength
×
84
    SILE.typesetter.frame = oldFrame
×
85
    self.class:insert("footnote", material)
×
86
    SILE.scratch.counters.footnote.value = SILE.scratch.counters.footnote.value + 1
×
87
  end)
88

89
  self:registerCommand("footnote:font", function (_, content)
×
90
    -- The footnote frame has is settings reset to the toplevel state, so if one does
91
    -- something relative (as below), it is expected to be the main value from the
92
    -- document.
93
    SILE.call("font", { size = SILE.settings:get("font.size") * 0.9 }, function ()
×
94
      SILE.process(content)
×
95
    end)
96
  end)
97

98
  self:registerCommand("footnote:atstart", function (_, _)
×
99
  end)
100

101
  self:registerCommand("footnote:counter", function (_, _)
×
102
    SILE.call("noindent")
×
103
    SILE.typesetter:typeset(self.class.packages.counters:formatCounter(SILE.scratch.counters.footnote) .. ".")
×
104
    SILE.call("qquad")
×
105
  end)
106

107
end
108

109
package.documentation = [[
110
\begin{document}
111
The \autodoc:package{footnotes} package allows you to add footnotes to text with the \autodoc:command{\footnote} command.
112
Other commands provided by the package, not described here, take care of formatting the footnotes.
113

114
Usually, a document class is responsible for automatically loading this package.
115
Minimally, upon initialization, it needs a frame identifier for the the footnotes, and one or more frame(s) which will be reduced as the footnotes take place.
116
By default, it uses, respectively, the \code{footnotes} and \code{content} frames, which are assumed to be present in the default standard layout.
117

118
For the record, it internally relies on the \autodoc:package{insertions} package and tells it which frame should receive the footnotes that are typeset.
119
\end{document}
120
]]
×
121

122
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