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

sile-typesetter / sile / 4558108092

pending completion
4558108092

push

github

GitHub
Merge 6714a4c3d into ddb6391fb

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

10797 of 15559 relevant lines covered (69.39%)

6602.48 hits per line

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

76.02
/classes/book.lua
1
local plain = require("classes.plain")
34✔
2

3
local class = pl.class(plain)
34✔
4
class._name = "book"
34✔
5

6
class.defaultFrameset = {
34✔
7
  content = {
34✔
8
    left = "8.3%pw",
9
    right = "86%pw",
10
    top = "11.6%ph",
11
    bottom = "top(footnotes)"
×
12
  },
34✔
13
  folio = {
34✔
14
    left = "left(content)",
15
    right = "right(content)",
16
    top = "bottom(footnotes)+3%ph",
17
    bottom = "bottom(footnotes)+5%ph"
×
18
  },
34✔
19
  runningHead = {
34✔
20
    left = "left(content)",
21
    right = "right(content)",
22
    top = "top(content)-8%ph",
23
    bottom = "top(content)-3%ph"
×
24
  },
34✔
25
  footnotes = {
34✔
26
    left = "left(content)",
27
    right = "right(content)",
28
    height = "0",
29
    bottom = "83.3%ph"
×
30
  }
34✔
31
}
34✔
32

33
function class:_init (options)
34✔
34
  plain._init(self, options)
34✔
35
  self:loadPackage("counters")
34✔
36
  self:loadPackage("masters", {{
68✔
37
      id = "right",
38
      firstContentFrame = self.firstContentFrame,
34✔
39
      frames = self.defaultFrameset
34✔
40
    }})
34✔
41
  self:loadPackage("twoside", {
34✔
42
      oddPageMaster = "right",
43
      evenPageMaster = "left"
×
44
    })
45
  self:loadPackage("tableofcontents")
34✔
46
  self:loadPackage("footnotes", {
68✔
47
      insertInto = "footnotes",
48
      stealFrom = { "content" }
34✔
49
    })
50
  if not SILE.scratch.headers then SILE.scratch.headers = {} end
34✔
51
end
52

53
function class:endPage ()
34✔
54
  if not SILE.scratch.headers.skipthispage then
70✔
55
    if self:oddPage() and SILE.scratch.headers.right then
134✔
56
      SILE.typesetNaturally(SILE.getFrame("runningHead"), function ()
4✔
57
        SILE.settings:toplevelState()
2✔
58
        SILE.settings:set("current.parindent", SILE.nodefactory.glue())
4✔
59
        SILE.settings:set("document.lskip", SILE.nodefactory.glue())
4✔
60
        SILE.settings:set("document.rskip", SILE.nodefactory.glue())
4✔
61
        -- SILE.settings:set("typesetter.parfillskip", SILE.nodefactory.glue())
62
        SILE.process(SILE.scratch.headers.right)
2✔
63
        SILE.call("par")
2✔
64
      end)
65
    elseif not self:oddPage() and SILE.scratch.headers.left then
130✔
66
      SILE.typesetNaturally(SILE.getFrame("runningHead"), function ()
×
67
        SILE.settings:toplevelState()
×
68
        SILE.settings:set("current.parindent", SILE.nodefactory.glue())
×
69
        SILE.settings:set("document.lskip", SILE.nodefactory.glue())
×
70
        SILE.settings:set("document.rskip", SILE.nodefactory.glue())
×
71
        -- SILE.settings:set("typesetter.parfillskip", SILE.nodefactory.glue())
72
        SILE.process(SILE.scratch.headers.left)
×
73
        SILE.call("par")
×
74
      end)
75
    end
76
  end
77
  SILE.scratch.headers.skipthispage = false
70✔
78
  return plain.endPage(self)
70✔
79
end
80

81
function class:finish ()
34✔
82
  local ret = plain.finish(self)
34✔
83
  return ret
34✔
84
end
85

86
function class:registerCommands ()
34✔
87

88
  plain.registerCommands(self)
34✔
89

90
  self:registerCommand("left-running-head", function (_, content)
68✔
91
    local closure = SILE.settings:wrap()
4✔
92
    SILE.scratch.headers.left = function () closure(content) end
4✔
93
  end, "Text to appear on the top of the left page")
38✔
94

95
  self:registerCommand("right-running-head", function (_, content)
68✔
96
    local closure = SILE.settings:wrap()
3✔
97
    SILE.scratch.headers.right = function () closure(content) end
7✔
98
  end, "Text to appear on the top of the right page")
37✔
99

100
  self:registerCommand("book:sectioning", function (options, content)
68✔
101
    local level = SU.required(options, "level", "book:sectioning")
6✔
102
    local number
103
    if SU.boolean(options.numbering, true) then
12✔
104
      SILE.call("increment-multilevel-counter", { id = "sectioning", level = level })
6✔
105
      number = self.packages.counters:formatMultilevelCounter(self:getMultilevelCounter("sectioning"))
18✔
106
    end
107
    if SU.boolean(options.toc, true) then
12✔
108
      SILE.call("tocentry", { level = level, number = number }, SU.subContent(content))
12✔
109
    end
110
    if SU.boolean(options.numbering, true) then
12✔
111
      if options.msg then
6✔
112
        SILE.call("fluent", { number = number }, { options.msg })
8✔
113
      else
114
        SILE.call("show-multilevel-counter", { id = "sectioning" })
2✔
115
      end
116
    else
117
      -- https://github.com/sile-typesetter/sile/issues/1707
118
      -- https://github.com/sile-typesetter/sile/issues/1751
119
      SILE.call("hbox")
×
120
    end
121
  end)
122

123
  self:registerCommand("book:chapter:post", function (_, _)
68✔
124
    SILE.call("par")
3✔
125
  end)
126

127
  self:registerCommand("book:section:post", function (_, _)
68✔
128
    SILE.process({ " " })
2✔
129
  end)
130

131
  self:registerCommand("book:subsection:post", function (_, _)
68✔
132
    SILE.process({ " " })
×
133
  end)
134

135
  self:registerCommand("book:left-running-head-font", function (_, content)
68✔
136
    SILE.call("font", { size = "9pt" }, content)
×
137
  end)
138

139
  self:registerCommand("book:right-running-head-font", function (_, content)
68✔
140
    SILE.call("font", { size = "9pt", style = "Italic" }, content)
1✔
141
  end)
142

143
  self:registerCommand("chapter", function (options, content)
68✔
144
    SILE.typesetter:leaveHmode()
4✔
145
    SILE.call("open-spread", { double = false })
4✔
146
    SILE.call("noindent")
4✔
147
    SILE.scratch.headers.right = nil
4✔
148
    SILE.call("set-counter", { id = "footnote", value = 1 })
4✔
149
    SILE.call("book:chapterfont", {}, function ()
8✔
150
      SILE.call("book:sectioning", {
8✔
151
        numbering = options.numbering,
4✔
152
        toc = options.toc,
4✔
153
        level = 1,
154
        msg = "book-chapter-title"
×
155
      }, content)
4✔
156
    end)
157
    local lang = SILE.settings:get("document.language")
4✔
158
    local postcmd = "book:chapter:post"
4✔
159
    if SILE.Commands[postcmd .. ":" .. lang] then
4✔
160
      postcmd = postcmd .. ":" .. lang
1✔
161
    end
162
    SILE.call(postcmd)
4✔
163
    SILE.call("book:chapterfont", {}, content)
4✔
164
    SILE.call("left-running-head", {}, function ()
8✔
165
      SILE.settings:temporarily(function ()
×
166
        SILE.call("book:left-running-head-font", {}, content)
×
167
      end)
168
    end)
169
    SILE.call("bigskip")
4✔
170
    SILE.call("nofoliothispage")
4✔
171
  end, "Begin a new chapter")
38✔
172

173
  self:registerCommand("section", function (options, content)
68✔
174
    SILE.typesetter:leaveHmode()
2✔
175
    SILE.call("goodbreak")
2✔
176
    SILE.call("bigskip")
2✔
177
    SILE.call("noindent")
2✔
178
    SILE.call("book:sectionfont", {}, function ()
4✔
179
      SILE.call("book:sectioning", {
4✔
180
        numbering = options.numbering,
2✔
181
        toc = options.toc,
2✔
182
        level = 2
×
183
      }, content)
2✔
184
      local lang = SILE.settings:get("document.language")
2✔
185
      local postcmd = "book:section:post"
2✔
186
      if SILE.Commands[postcmd .. ":" .. lang] then
2✔
187
        postcmd = postcmd .. ":" .. lang
×
188
      end
189
      SILE.call(postcmd)
2✔
190
      SILE.process(content)
2✔
191
    end)
192
    if not SILE.scratch.counters.folio.off then
2✔
193
      SILE.call("right-running-head", {}, function ()
4✔
194
        SILE.call("book:right-running-head-font", {}, function ()
2✔
195
          SILE.call("rightalign", {}, function ()
2✔
196
            SILE.settings:temporarily(function ()
2✔
197
              if SU.boolean(options.numbering, true) then
2✔
198
                SILE.call("show-multilevel-counter", { id = "sectioning", level = 2 })
1✔
199
                SILE.typesetter:typeset(" ")
1✔
200
              end
201
              SILE.process(content)
1✔
202
            end)
203
          end)
204
        end)
205
      end)
206
    end
207
    SILE.call("novbreak")
2✔
208
    SILE.call("bigskip")
2✔
209
    SILE.call("novbreak")
2✔
210
    SILE.typesetter:inhibitLeading()
2✔
211
  end, "Begin a new section")
36✔
212

213
  self:registerCommand("subsection", function (options, content)
68✔
214
    SILE.typesetter:leaveHmode()
×
215
    SILE.call("goodbreak")
×
216
    SILE.call("noindent")
×
217
    SILE.call("medskip")
×
218
    SILE.call("book:subsectionfont", {}, function ()
×
219
      SILE.call("book:sectioning", {
×
220
            numbering = options.numbering,
221
            toc = options.toc,
222
            level = 3
×
223
          }, content)
×
224
      local lang = SILE.settings:get("document.language")
×
225
      local postcmd = "book:subsection:post"
×
226
      if SILE.Commands[postcmd .. ":" .. lang] then
×
227
        postcmd = postcmd .. ":" .. lang
×
228
      end
229
      SILE.call(postcmd)
×
230
      SILE.process(content)
×
231
    end)
232
    SILE.typesetter:leaveHmode()
×
233
    SILE.call("novbreak")
×
234
    SILE.call("medskip")
×
235
    SILE.call("novbreak")
×
236
    SILE.typesetter:inhibitLeading()
×
237
  end, "Begin a new subsection")
34✔
238

239
  self:registerCommand("book:chapterfont", function (_, content)
68✔
240
    SILE.settings:temporarily(function ()
16✔
241
      SILE.call("font", { weight = 800, size = "22pt" }, content)
8✔
242
    end)
243
  end)
244
  self:registerCommand("book:sectionfont", function (_, content)
68✔
245
    SILE.settings:temporarily(function ()
4✔
246
      SILE.call("font", { weight = 800, size = "15pt" }, content)
2✔
247
    end)
248
  end)
249

250
  self:registerCommand("book:subsectionfont", function (_, content)
68✔
251
    SILE.settings:temporarily(function ()
×
252
      SILE.call("font", { weight = 800, size = "12pt" }, content)
×
253
    end)
254
  end)
255

256
end
257

258
return class
34✔
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