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

sile-typesetter / sile / 4556650005

pending completion
4556650005

push

github

GitHub
Merge 128b78f18 into ddb6391fb

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

11627 of 15618 relevant lines covered (74.45%)

6850.56 hits per line

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

75.86
/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
      if SU.boolean(options.numbering, true) then
8✔
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
      end
164
      SILE.process(content)
4✔
165
    end)
166
    SILE.call("left-running-head", {}, function ()
8✔
167
      SILE.settings:temporarily(function ()
×
168
        SILE.call("book:left-running-head-font", {}, content)
×
169
      end)
170
    end)
171
    SILE.call("bigskip")
4✔
172
    SILE.call("nofoliothispage")
4✔
173
  end, "Begin a new chapter")
38✔
174

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

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

245
  self:registerCommand("book:chapterfont", function (_, content)
68✔
246
    SILE.settings:temporarily(function ()
8✔
247
      SILE.call("font", { weight = 800, size = "22pt" }, content)
4✔
248
    end)
249
  end)
250
  self:registerCommand("book:sectionfont", function (_, content)
68✔
251
    SILE.settings:temporarily(function ()
4✔
252
      SILE.call("font", { weight = 800, size = "15pt" }, content)
2✔
253
    end)
254
  end)
255

256
  self:registerCommand("book:subsectionfont", function (_, content)
68✔
257
    SILE.settings:temporarily(function ()
×
258
      SILE.call("font", { weight = 800, size = "12pt" }, content)
×
259
    end)
260
  end)
261

262
end
263

264
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