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

sile-typesetter / sile / 9428787025

08 Jun 2024 12:27PM UTC coverage: 68.206% (+3.6%) from 64.56%
9428787025

push

github

alerque
docs(manual): Expand notes about DTP a bit

11799 of 17299 relevant lines covered (68.21%)

5851.23 hits per line

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

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

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

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

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

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

60
function class:endPage ()
34✔
61
   if not SILE.scratch.headers.skipthispage then
70✔
62
      if self:oddPage() and SILE.scratch.headers.right then
134✔
63
         SILE.typesetNaturally(SILE.getFrame("runningHead"), function ()
4✔
64
            SILE.settings:toplevelState()
2✔
65
            SILE.settings:set("current.parindent", SILE.types.node.glue())
4✔
66
            SILE.settings:set("document.lskip", SILE.types.node.glue())
4✔
67
            SILE.settings:set("document.rskip", SILE.types.node.glue())
4✔
68
            -- SILE.settings:set("typesetter.parfillskip", SILE.types.node.glue())
69
            SILE.process(SILE.scratch.headers.right)
2✔
70
            SILE.call("par")
2✔
71
         end)
72
      elseif not self:oddPage() and SILE.scratch.headers.left then
130✔
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
70✔
85
   return plain.endPage(self)
70✔
86
end
87

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

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

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

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

110
   self:registerCommand("book:sectioning", function (options, content)
68✔
111
      local level = SU.required(options, "level", "book:sectioning")
6✔
112
      local number
113
      if SU.boolean(options.numbering, true) then
12✔
114
         SILE.call("increment-multilevel-counter", { id = "sectioning", level = level })
6✔
115
         number = self.packages.counters:formatMultilevelCounter(self:getMultilevelCounter("sectioning"))
18✔
116
      end
117
      if SU.boolean(options.toc, true) then
12✔
118
         SILE.call("tocentry", { level = level, number = number }, SU.ast.subContent(content))
12✔
119
      end
120
      if SU.boolean(options.numbering, true) then
12✔
121
         if options.msg then
6✔
122
            SILE.call("fluent", { number = number }, { options.msg })
8✔
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 (_, _)
68✔
130
      SILE.call("par")
3✔
131
      SILE.call("noindent")
3✔
132
   end)
133

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

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

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

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

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

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

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

258
   self:registerCommand("book:chapterfont", function (_, content)
68✔
259
      SILE.settings:temporarily(function ()
16✔
260
         SILE.call("font", { weight = 800, size = "22pt" }, content)
8✔
261
      end)
262
   end)
263
   self:registerCommand("book:sectionfont", function (_, content)
68✔
264
      SILE.settings:temporarily(function ()
4✔
265
         SILE.call("font", { weight = 800, size = "15pt" }, content)
2✔
266
      end)
267
   end)
268

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

276
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

© 2025 Coveralls, Inc