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

sile-typesetter / sile / 6915845768

18 Nov 2023 07:23PM UTC coverage: 63.161% (-5.6%) from 68.751%
6915845768

push

github

web-flow
Merge 0f5c09a66 into f64e235fa

9802 of 15519 relevant lines covered (63.16%)

2045.54 hits per line

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

87.69
/packages/footnotes/init.lua
1
local base = require("packages.base")
9✔
2

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

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

23
end
24

25
function package:registerCommands ()
9✔
26

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

35
  self:registerCommand("footnote:separator", function (_, content)
18✔
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, _)
18✔
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)
18✔
52
    SILE.call("footnotemark")
3✔
53
    local opts = SILE.scratch.insertions.classes.footnote or {}
3✔
54
    local frame = opts.insertInto and SILE.getFrame(opts.insertInto.frame)
3✔
55
    local oldGetTargetLength = SILE.typesetter.getTargetLength
3✔
56
    local oldFrame = SILE.typesetter.frame
3✔
57
    SILE.typesetter.getTargetLength = function () return SILE.length(0xFFFFFF) end
5✔
58
    SILE.settings:pushState()
3✔
59
    -- Restore the settings to the top of the queue, which should be the document #986
60
    SILE.settings:toplevelState()
3✔
61
    SILE.typesetter:initFrame(frame)
3✔
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({
18✔
66
      "current.hangAfter",
67
      "current.hangIndent",
68
      "linebreak.hangAfter",
69
      "linebreak.hangIndent" }) do
3✔
70
      SILE.settings:set(v, SILE.settings.defaults[v])
12✔
71
    end
72

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

89
  self:registerCommand("footnote:font", function (_, content)
18✔
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 ()
9✔
94
      SILE.process(content)
3✔
95
    end)
96
  end)
97

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

101
  self:registerCommand("footnote:counter", function (_, _)
18✔
102
    SILE.call("noindent")
3✔
103
    SILE.typesetter:typeset(self.class.packages.counters:formatCounter(SILE.scratch.counters.footnote) .. ".")
6✔
104
    SILE.call("qquad")
3✔
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
]]
9✔
121

122
return package
9✔
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