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

sile-typesetter / sile / 9400954821

06 Jun 2024 11:12AM UTC coverage: 61.625% (-11.6%) from 73.209%
9400954821

push

github

web-flow
Merge pull request #2041 from alerque/keep-space-after-envs

2 of 30 new or added lines in 2 files covered. (6.67%)

1933 existing lines in 67 files now uncovered.

10613 of 17222 relevant lines covered (61.62%)

2870.98 hits per line

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

64.67
/classes/book.lua
1
--- book document class.
2
-- @use classes.book
3

4
local plain = require("classes.plain")
11✔
5

6
local class = pl.class(plain)
11✔
7
class._name = "book"
11✔
8

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

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

60
function class:endPage ()
11✔
61
   if not SILE.scratch.headers.skipthispage then
29✔
62
      if self:oddPage() and SILE.scratch.headers.right then
52✔
63
         SILE.typesetNaturally(SILE.getFrame("runningHead"), function ()
2✔
64
            SILE.settings:toplevelState()
1✔
65
            SILE.settings:set("current.parindent", SILE.types.node.glue())
2✔
66
            SILE.settings:set("document.lskip", SILE.types.node.glue())
2✔
67
            SILE.settings:set("document.rskip", SILE.types.node.glue())
2✔
68
            -- SILE.settings:set("typesetter.parfillskip", SILE.types.node.glue())
69
            SILE.process(SILE.scratch.headers.right)
1✔
70
            SILE.call("par")
1✔
71
         end)
72
      elseif not self:oddPage() and SILE.scratch.headers.left then
50✔
73
         SILE.typesetNaturally(SILE.getFrame("runningHead"), function ()
×
74
            SILE.settings:toplevelState()
×
75
            SILE.settings:set("current.parindent", SILE.types.node.glue())
×
76
            SILE.settings:set("document.lskip", SILE.types.node.glue())
×
77
            SILE.settings:set("document.rskip", SILE.types.node.glue())
×
78
            -- SILE.settings:set("typesetter.parfillskip", SILE.types.node.glue())
79
            SILE.process(SILE.scratch.headers.left)
×
80
            SILE.call("par")
×
81
         end)
82
      end
83
   end
84
   SILE.scratch.headers.skipthispage = false
29✔
85
   return plain.endPage(self)
29✔
86
end
87

88
function class:finish ()
11✔
89
   local ret = plain.finish(self)
11✔
90
   return ret
11✔
91
end
92

93
function class:registerCommands ()
11✔
94
   plain.registerCommands(self)
11✔
95

96
   self:registerCommand("left-running-head", function (_, content)
22✔
UNCOV
97
      local closure = SILE.settings:wrap()
×
UNCOV
98
      SILE.scratch.headers.left = function ()
×
99
         closure(content)
×
100
      end
101
   end, "Text to appear on the top of the left page")
11✔
102

103
   self:registerCommand("right-running-head", function (_, content)
22✔
104
      local closure = SILE.settings:wrap()
2✔
105
      SILE.scratch.headers.right = function ()
2✔
106
         closure(content)
1✔
107
      end
108
   end, "Text to appear on the top of the right page")
13✔
109

110
   self:registerCommand("book:sectioning", function (options, content)
22✔
111
      local level = SU.required(options, "level", "book:sectioning")
2✔
112
      local number
113
      if SU.boolean(options.numbering, true) then
4✔
114
         SILE.call("increment-multilevel-counter", { id = "sectioning", level = level })
2✔
115
         number = self.packages.counters:formatMultilevelCounter(self:getMultilevelCounter("sectioning"))
6✔
116
      end
117
      if SU.boolean(options.toc, true) then
4✔
118
         SILE.call("tocentry", { level = level, number = number }, SU.ast.subContent(content))
4✔
119
      end
120
      if SU.boolean(options.numbering, true) then
4✔
121
         if options.msg then
2✔
UNCOV
122
            SILE.call("fluent", { number = number }, { options.msg })
×
123
         else
124
            SILE.call("show-multilevel-counter", { id = "sectioning" })
2✔
125
         end
126
      end
127
   end)
128

129
   self:registerCommand("book:chapter:post", function (_, _)
22✔
UNCOV
130
      SILE.call("par")
×
UNCOV
131
      SILE.call("noindent")
×
132
   end)
133

134
   self:registerCommand("book:section:post", function (_, _)
22✔
135
      SILE.process({ " " })
2✔
136
   end)
137

138
   self:registerCommand("book:subsection:post", function (_, _)
22✔
139
      SILE.process({ " " })
×
140
   end)
141

142
   self:registerCommand("book:left-running-head-font", function (_, content)
22✔
143
      SILE.call("font", { size = "9pt" }, content)
×
144
   end)
145

146
   self:registerCommand("book:right-running-head-font", function (_, content)
22✔
147
      SILE.call("font", { size = "9pt", style = "Italic" }, content)
1✔
148
   end)
149

150
   self:registerCommand("chapter", function (options, content)
22✔
UNCOV
151
      SILE.typesetter:leaveHmode()
×
UNCOV
152
      SILE.call("open-spread", { double = false })
×
UNCOV
153
      SILE.call("noindent")
×
UNCOV
154
      SILE.scratch.headers.right = nil
×
UNCOV
155
      SILE.call("set-counter", { id = "footnote", value = 1 })
×
UNCOV
156
      SILE.call("book:chapterfont", {}, function ()
×
UNCOV
157
         SILE.call("book:sectioning", {
×
158
            numbering = options.numbering,
159
            toc = options.toc,
160
            level = 1,
161
            msg = "book-chapter-title",
UNCOV
162
         }, content)
×
163
      end)
UNCOV
164
      local lang = SILE.settings:get("document.language")
×
UNCOV
165
      local postcmd = "book:chapter:post"
×
UNCOV
166
      if SILE.Commands[postcmd .. ":" .. lang] then
×
UNCOV
167
         postcmd = postcmd .. ":" .. lang
×
168
      end
UNCOV
169
      SILE.call(postcmd)
×
UNCOV
170
      SILE.call("book:chapterfont", {}, content)
×
UNCOV
171
      SILE.call("left-running-head", {}, function ()
×
172
         SILE.settings:temporarily(function ()
×
173
            SILE.call("book:left-running-head-font", {}, content)
×
174
         end)
175
      end)
UNCOV
176
      SILE.call("bigskip")
×
UNCOV
177
      SILE.call("nofoliothispage")
×
178
      -- English typography (notably) expects the first paragraph under a section
179
      -- not to be indented. Frenchies, don't use this class :)
UNCOV
180
      SILE.call("noindent")
×
181
   end, "Begin a new chapter")
11✔
182

183
   self:registerCommand("section", function (options, content)
22✔
184
      SILE.typesetter:leaveHmode()
2✔
185
      SILE.call("goodbreak")
2✔
186
      SILE.call("bigskip")
2✔
187
      SILE.call("noindent")
2✔
188
      SILE.call("book:sectionfont", {}, function ()
4✔
189
         SILE.call("book:sectioning", {
4✔
190
            numbering = options.numbering,
2✔
191
            toc = options.toc,
2✔
192
            level = 2,
193
         }, content)
2✔
194
         local lang = SILE.settings:get("document.language")
2✔
195
         local postcmd = "book:section:post"
2✔
196
         if SILE.Commands[postcmd .. ":" .. lang] then
2✔
197
            postcmd = postcmd .. ":" .. lang
×
198
         end
199
         SILE.call(postcmd)
2✔
200
         SILE.process(content)
2✔
201
      end)
202
      if not SILE.scratch.counters.folio.off then
2✔
203
         SILE.call("right-running-head", {}, function ()
4✔
204
            SILE.call("book:right-running-head-font", {}, function ()
2✔
205
               SILE.call("rightalign", {}, function ()
2✔
206
                  SILE.settings:temporarily(function ()
2✔
207
                     if SU.boolean(options.numbering, true) then
2✔
208
                        SILE.call("show-multilevel-counter", { id = "sectioning", level = 2 })
1✔
209
                        SILE.typesetter:typeset(" ")
1✔
210
                     end
211
                     SILE.process(content)
1✔
212
                  end)
213
               end)
214
            end)
215
         end)
216
      end
217
      SILE.call("novbreak")
2✔
218
      SILE.call("bigskip")
2✔
219
      SILE.call("novbreak")
2✔
220
      -- English typography (notably) expects the first paragraph under a section
221
      -- not to be indented. Frenchies, don't use this class :)
222
      SILE.call("noindent")
2✔
223
      SILE.typesetter:inhibitLeading()
2✔
224
   end, "Begin a new section")
13✔
225

226
   self:registerCommand("subsection", function (options, content)
22✔
227
      SILE.typesetter:leaveHmode()
×
228
      SILE.call("goodbreak")
×
229
      SILE.call("noindent")
×
230
      SILE.call("medskip")
×
231
      SILE.call("book:subsectionfont", {}, function ()
×
232
         SILE.call("book:sectioning", {
×
233
            numbering = options.numbering,
234
            toc = options.toc,
235
            level = 3,
236
         }, content)
×
237
         local lang = SILE.settings:get("document.language")
×
238
         local postcmd = "book:subsection:post"
×
239
         if SILE.Commands[postcmd .. ":" .. lang] then
×
240
            postcmd = postcmd .. ":" .. lang
×
241
         end
242
         SILE.call(postcmd)
×
243
         SILE.process(content)
×
244
      end)
245
      SILE.typesetter:leaveHmode()
×
246
      SILE.call("novbreak")
×
247
      SILE.call("medskip")
×
248
      SILE.call("novbreak")
×
249
      -- English typography (notably) expects the first paragraph under a section
250
      -- not to be indented. Frenchies, don't use this class :)
251
      SILE.call("noindent")
×
252
      SILE.typesetter:inhibitLeading()
×
253
   end, "Begin a new subsection")
11✔
254

255
   self:registerCommand("book:chapterfont", function (_, content)
22✔
UNCOV
256
      SILE.settings:temporarily(function ()
×
UNCOV
257
         SILE.call("font", { weight = 800, size = "22pt" }, content)
×
258
      end)
259
   end)
260
   self:registerCommand("book:sectionfont", function (_, content)
22✔
261
      SILE.settings:temporarily(function ()
4✔
262
         SILE.call("font", { weight = 800, size = "15pt" }, content)
2✔
263
      end)
264
   end)
265

266
   self:registerCommand("book:subsectionfont", function (_, content)
22✔
267
      SILE.settings:temporarily(function ()
×
268
         SILE.call("font", { weight = 800, size = "12pt" }, content)
×
269
      end)
270
   end)
271
end
272

273
return class
11✔
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