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

sile-typesetter / sile / 9304060604

30 May 2024 02:07PM UTC coverage: 74.124% (-0.6%) from 74.707%
9304060604

push

github

alerque
style: Reformat Lua with stylua

8104 of 11995 new or added lines in 184 files covered. (67.56%)

15 existing lines in 11 files now uncovered.

12444 of 16788 relevant lines covered (74.12%)

7175.1 hits per line

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

79.73
/classes/plain.lua
1
local base = require("classes.base")
181✔
2

3
local class = pl.class(base)
181✔
4
class._name = "plain"
181✔
5

6
class.defaultFrameset = {
181✔
7
   content = {
181✔
8
      left = "5%pw",
9
      right = "95%pw",
10
      top = "5%ph",
11
      bottom = "top(footnotes)",
12
   },
181✔
13
   folio = {
181✔
14
      left = "left(content)",
15
      right = "right(content)",
16
      top = "bottom(footnotes)+2%ph",
17
      bottom = "97%ph",
18
   },
181✔
19
   footnotes = {
181✔
20
      left = "left(content)",
21
      right = "right(content)",
22
      height = "0",
23
      bottom = "90%ph",
24
   },
181✔
25
}
181✔
26
class.firstContentFrame = "content"
181✔
27

28
local skips = {
181✔
29
   small = "3pt plus 1pt minus 1pt",
30
   med = "6pt plus 2pt minus 2pt",
31
   big = "12pt plus 4pt minus 4pt",
32
}
33

34
function class:_init (options)
181✔
35
   base._init(self, options)
181✔
36
   self:loadPackage("bidi")
181✔
37
   self:loadPackage("folio")
181✔
38
end
39

40
function class:declareOptions ()
181✔
41
   base.declareOptions(self)
181✔
42
   self:declareOption("direction", function (_, value)
362✔
43
      if value then
6✔
44
         SILE.documentState.direction = value
6✔
45
         SILE.settings:set("font.direction", value, true)
6✔
46
         for _, frame in pairs(self.defaultFrameset) do
24✔
47
            if not frame.direction then
18✔
48
               frame.direction = value
18✔
49
            end
50
         end
51
      end
52
      return SILE.documentState.direction
6✔
53
   end)
54
end
55

56
function class:setOptions (options)
181✔
57
   -- TODO: set a default direction here?
58
   base.setOptions(self, options)
181✔
59
end
60

61
function class:declareSettings ()
181✔
62
   base.declareSettings(self)
181✔
63
   for k, v in pairs(skips) do
724✔
64
      SILE.settings:declare({
1,086✔
65
         parameter = "plain." .. k .. "skipamount",
543✔
66
         type = "vglue",
67
         default = SILE.nodefactory.vglue(v),
1,086✔
68
         help = "The amount of a \\" .. k .. "skip",
543✔
69
      })
70
   end
71
end
72

73
function class:registerCommands ()
181✔
74
   SILE.classes.base.registerCommands(self)
181✔
75

76
   self:registerCommand("noindent", function (_, content)
362✔
77
      if #SILE.typesetter.state.nodes ~= 0 then
110✔
78
         SU.warn(
28✔
79
            "\\noindent called after nodes already received in a paragraph, the setting will have no effect because the parindent (if any) has already been output"
80
         )
14✔
81
      end
82
      SILE.settings:set("current.parindent", SILE.nodefactory.glue())
220✔
83
      SILE.process(content)
110✔
84
   end, "Do not add an indent to the start of this paragraph")
291✔
85

86
   self:registerCommand("neverindent", function (_, content)
362✔
87
      SILE.settings:set("current.parindent", SILE.nodefactory.glue())
120✔
88
      SILE.settings:set("document.parindent", SILE.nodefactory.glue())
120✔
89
      SILE.process(content)
60✔
90
   end, "Turn off all indentation")
241✔
91

92
   self:registerCommand("indent", function (_, content)
362✔
93
      SILE.settings:set("current.parindent", SILE.settings:get("document.parindent"))
8✔
94
      SILE.process(content)
4✔
95
   end, "Do add an indent to the start of this paragraph, even if previously told otherwise")
185✔
96

97
   for k, _ in pairs(skips) do
724✔
98
      self:registerCommand(k .. "skip", function (_, _)
1,086✔
99
         SILE.typesetter:leaveHmode()
53✔
100
         SILE.typesetter:pushExplicitVglue(SILE.settings:get("plain." .. k .. "skipamount"))
106✔
101
      end, "Skip vertically by a " .. k .. " amount")
1,139✔
102
   end
103

104
   self:registerCommand("hfill", function (_, _)
362✔
105
      SILE.typesetter:pushExplicitGlue(SILE.nodefactory.hfillglue())
50✔
106
   end, "Add a huge horizontal glue")
206✔
107

108
   self:registerCommand("vfill", function (_, _)
362✔
109
      SILE.typesetter:leaveHmode()
379✔
110
      SILE.typesetter:pushExplicitVglue(SILE.nodefactory.vfillglue())
758✔
111
   end, "Add huge vertical glue")
560✔
112

113
   self:registerCommand("hss", function (_, _)
362✔
NEW
114
      SILE.typesetter:initline()
×
NEW
115
      SILE.typesetter:pushGlue(SILE.nodefactory.hssglue())
×
NEW
116
      table.insert(SILE.typesetter.state.nodes, SILE.nodefactory.zerohbox())
×
117
   end, "Add glue which stretches and shrinks horizontally (good for centering)")
181✔
118

119
   self:registerCommand("vss", function (_, _)
362✔
NEW
120
      SILE.typesetter:pushExplicitVglue(SILE.nodefactory.vssglue())
×
121
   end, "Add glue which stretches and shrinks vertically")
181✔
122

123
   local _thinspacewidth = SILE.measurement(0.16667, "em")
181✔
124

125
   self:registerCommand("thinspace", function (_, _)
362✔
NEW
126
      SILE.call("glue", { width = _thinspacewidth })
×
127
   end)
128

129
   self:registerCommand("negthinspace", function (_, _)
362✔
NEW
130
      SILE.call("glue", { width = -_thinspacewidth })
×
131
   end)
132

133
   self:registerCommand("enspace", function (_, _)
362✔
NEW
134
      SILE.call("glue", { width = SILE.measurement(1, "en") })
×
135
   end)
136

137
   self:registerCommand("relax", function (_, _) end)
181✔
138

139
   self:registerCommand("enskip", function (_, _)
362✔
NEW
140
      SILE.call("enspace")
×
141
   end)
142

143
   local _quadwidth = SILE.measurement(1, "em")
181✔
144

145
   self:registerCommand("quad", function (_, _)
362✔
146
      SILE.call("glue", { width = _quadwidth })
1✔
147
   end)
148

149
   self:registerCommand("qquad", function (_, _)
362✔
150
      SILE.call("glue", { width = _quadwidth * 2 })
90✔
151
   end)
152

153
   self:registerCommand("slash", function (_, _)
362✔
NEW
154
      SILE.typesetter:typeset("/")
×
NEW
155
      SILE.call("penalty", { penalty = 50 })
×
156
   end)
157

158
   self:registerCommand("break", function (_, _)
362✔
159
      SILE.call("penalty", { penalty = -10000 })
45✔
160
   end, "Requests a frame break (if in vertical mode) or a line break (if in horizontal mode)")
226✔
161

162
   self:registerCommand("cr", function (_, _)
362✔
163
      SILE.call("hfill")
3✔
164
      SILE.call("break")
3✔
165
   end, "Fills a line with a stretchable glue and then requests a line break")
184✔
166

167
   -- Despite their name, in older versions, \framebreak and \pagebreak worked badly in horizontal
168
   -- mode. The former was a linebreak, and the latter did nothing. That was surely not intended.
169
   -- There are many ways, though to assume what's wrong or what the user's intent ought to be.
170
   -- We now warn, and terminate the paragraph, but to all extents this might be a wrong approach to
171
   -- reconsider at some point.
172

173
   self:registerCommand("framebreak", function (_, _)
362✔
174
      if not SILE.typesetter:vmode() then
22✔
NEW
175
         SU.warn("framebreak was not intended to work in horizontal mode. Behaviour may change in future versions")
×
176
      end
177
      SILE.call("penalty", { penalty = -10000, vertical = true })
11✔
178
   end, "Requests a frame break (switching to vertical mode if needed)")
192✔
179

180
   self:registerCommand("pagebreak", function (_, _)
362✔
181
      if not SILE.typesetter:vmode() then
10✔
NEW
182
         SU.warn("pagebreak was not intended to work in horizontal mode. Behaviour may change in future versions")
×
183
      end
184
      SILE.call("penalty", { penalty = -20000, vertical = true })
5✔
185
   end, "Requests a non-negotiable page break (switching to vertical mode if needed)")
186✔
186

187
   self:registerCommand("nobreak", function (_, _)
362✔
NEW
188
      SILE.call("penalty", { penalty = 10000 })
×
189
   end, "Inhibits a frame break (if in vertical mode) or a line break (if in horizontal mode)")
181✔
190

191
   self:registerCommand("novbreak", function (_, _)
362✔
192
      SILE.call("penalty", { penalty = 10000, vertical = true })
7✔
193
   end, "Inhibits a frame break (switching to vertical mode if needed)")
188✔
194

195
   self:registerCommand(
362✔
196
      "allowbreak",
181✔
197
      function (_, _)
NEW
198
         SILE.call("penalty", { penalty = 0 })
×
199
      end,
200
      "Allows a page break (if in vertical mode) or a line break (if in horizontal mode) at a point would not be considered as suitable for breaking"
201
   )
181✔
202

203
   -- THIS SEEMS BROKEN BUT THE COMMAND NOT MENTIONED IN THE SILE MANUAL
204
   -- In TeX, "\filbreak" compensates the vertical fill if no break actually occurs
205
   -- (\def\filbreak{\par\vfil\penalty-200\vfilneg)
206
   self:registerCommand("filbreak", function (_, _)
362✔
NEW
207
      SILE.call("vfill")
×
NEW
208
      SILE.call("penalty", { penalty = -200 })
×
209
   end, "I HAVE THE SAME NAME AS A TEX COMMAND BUT DON'T SEEM TO BE THE SAME")
181✔
210

211
   -- NOTE: TeX's "\goodbreak" does a \par first, so always switches to vertical mode.
212
   -- SILE differs here, allowing it both within a paragraph (line breaking) and between
213
   -- paragraphs (page breaking).
214
   self:registerCommand("goodbreak", function (_, _)
362✔
215
      SILE.call("penalty", { penalty = -500 })
4✔
216
   end, "Indicates a good potential point to break a frame (if in vertical mode) or a line (if in horizontal mode")
185✔
217

218
   self:registerCommand("eject", function (_, _)
362✔
219
      SILE.call("vfill")
3✔
220
      SILE.call("break")
3✔
221
   end, "Fills the page with stretchable vglue and then request a page break")
184✔
222

223
   self:registerCommand("supereject", function (_, _)
362✔
224
      SILE.call("vfill")
191✔
225
      SILE.call("penalty", { penalty = -20000 })
191✔
226
   end, "Fills the page with stretchable vglue and then requests a non-negotiable page break")
372✔
227

228
   self:registerCommand("justified", function (_, content)
362✔
229
      SILE.settings:set("document.rskip", nil)
1✔
230
      SILE.settings:set("document.spaceskip", nil)
1✔
231
      SILE.process(content)
1✔
232
      SILE.call("par")
1✔
233
   end)
234

235
   self:registerCommand("rightalign", function (_, content)
362✔
236
      SILE.call("raggedleft", {}, function ()
8✔
237
         SILE.process(content)
4✔
238
         SILE.call("par")
4✔
239
      end)
240
   end)
241

242
   self:registerCommand("em", function (_, content)
362✔
243
      SILE.call("font", { style = "Italic" }, content)
38✔
244
   end)
245

246
   self:registerCommand("strong", function (_, content)
362✔
NEW
247
      SILE.call("font", { weight = 700 }, content)
×
248
   end)
249

250
   self:registerCommand("code", function (options, content)
362✔
251
      -- IMPLEMENTATION NOTE:
252
      -- The \code command came from the url package, though used in plenty of
253
      -- places. It was referring to the verbatim:font from the verbatim
254
      -- package, which _should_ be sort of unrelated.
255
      -- Trying to untangle the things here, by introducing the
256
      -- definition from the former, but it's of sub-quality...
257
      -- The ugly -3 size is a HACK of sorts.
258
      options.family = options.family or "Hack"
1✔
259
      options.size = options.size or SILE.settings:get("font.size") - 3
2✔
260
      SILE.call("font", options, content)
1✔
261
   end)
262

263
   self:registerCommand("nohyphenation", function (_, content)
362✔
NEW
264
      SILE.call("font", { language = "und" }, content)
×
265
   end)
266

267
   self:registerCommand("raggedright", function (_, content)
362✔
268
      SILE.call("ragged", { right = true }, content)
7✔
269
   end)
270

271
   self:registerCommand("raggedleft", function (_, content)
362✔
272
      SILE.call("ragged", { left = true }, content)
6✔
273
   end)
274

275
   self:registerCommand("quote", function (_, content)
362✔
NEW
276
      SU.deprecated(
×
277
         "\\quote",
278
         "\\pullquote",
279
         "0.14.5",
280
         "0.16.0",
NEW
281
         [[
×
282
  The \quote command has *such* bad output it is being completely
283
  deprecated as unsuitable for general purpose use. The pullquote
284
  package (\use[module=packages.pullquote]) provides one alternative,
285
  but you can also copy and adapt the original source from the plain
NEW
286
  class if you need to maintain exact output past SILE v0.16.0.]]
×
287
      )
NEW
288
      SILE.call("smallskip")
×
NEW
289
      SILE.call("par")
×
NEW
290
      local margin = SILE.measurement(2.5, "em")
×
NEW
291
      SILE.settings:set("document.lskip", margin)
×
NEW
292
      SILE.settings:set("document.lskip", margin)
×
NEW
293
      SILE.call("font", { size = SILE.measurement(0.8, "em") }, function ()
×
NEW
294
         SILE.call("noindent")
×
NEW
295
         SILE.process(content)
×
296
      end)
NEW
297
      SILE.call("par")
×
NEW
298
      SILE.settings:set("document.lskip", nil)
×
NEW
299
      SILE.settings:set("document.rskip", nil)
×
NEW
300
      SILE.call("smallskip")
×
301
   end)
302

303
   self:registerCommand("listitem", function (_, content)
362✔
NEW
304
      SU.deprecated(
×
305
         "\\listitem",
306
         "\\item",
307
         "0.14.6",
308
         "0.16.0",
NEW
309
         [[
×
310
  The new list package (\use[module=packages.lists) has much better
311
  typography for lists. If you want to maintain the exact output of listitem
312
  past SILE v0.16.0 copy the source of \listitem from the plain class into
NEW
313
  your project.]]
×
314
      )
NEW
315
      SILE.call("medskip")
×
NEW
316
      SILE.typesetter:typeset("• ")
×
UNCOV
317
      SILE.process(content)
×
NEW
318
      SILE.call("medskip")
×
319
   end)
320

321
   self:registerCommand("sloppy", function (_, _)
362✔
NEW
322
      SILE.settings:set("linebreak.tolerance", 9999)
×
323
   end)
324

325
   self:registerCommand("awful", function (_, _)
362✔
NEW
326
      SILE.settings:set("linebreak.tolerance", 10000)
×
327
   end)
328

329
   self:registerCommand("center", function (_, content)
362✔
330
      if #SILE.typesetter.state.nodes ~= 0 then
125✔
NEW
331
         SU.warn("\\center environment started after other nodes in a paragraph, may not center as expected")
×
332
      end
333
      SILE.settings:temporarily(function ()
250✔
334
         SILE.settings:set("current.parindent", 0)
125✔
335
         SILE.settings:set("document.parindent", 0)
125✔
336
         SILE.call("ragged", { left = true, right = true }, content)
125✔
337
      end)
338
   end)
339

340
   self:registerCommand("ragged", function (options, content)
362✔
341
      SILE.settings:temporarily(function ()
278✔
342
         if SU.boolean(options.left, false) then
278✔
343
            SILE.settings:set("document.lskip", SILE.nodefactory.hfillglue())
264✔
344
         end
345
         if SU.boolean(options.right, false) then
278✔
346
            SILE.settings:set("document.rskip", SILE.nodefactory.hfillglue())
266✔
347
         end
348
         SILE.settings:set("typesetter.parfillskip", SILE.nodefactory.glue())
278✔
349
         SILE.settings:set("document.parindent", SILE.nodefactory.glue())
278✔
350
         SILE.settings:set("document.spaceskip", SILE.length("1spc", 0, 0))
278✔
351
         SILE.process(content)
139✔
352
         SILE.call("par")
139✔
353
      end)
354
   end)
355

356
   self:registerCommand("hbox", function (_, content)
362✔
357
      local hbox, hlist = SILE.typesetter:makeHbox(content)
66✔
358
      SILE.typesetter:pushHbox(hbox)
66✔
359
      if #hlist > 0 then
66✔
NEW
360
         SU.warn("Hbox has migrating content (ignored for now, but likely to break in future versions)")
×
361
         -- Ugly shim:
362
         -- One day we ought to do SILE.typesetter:pushHlist(hlist) here, so as to push
363
         -- back the migrating contents from within the hbox'ed content.
364
         -- However, old Lua code assumed the hbox to be returned, and sometimes removed it
365
         -- from the typesetter queue (for measuring, etc.), assuming it was the last
366
         -- element in the queue...
367
      end
368
      return hbox
66✔
369
   end, "Compiles all the enclosed horizontal-mode material into a single hbox")
181✔
370

371
   self:registerCommand("vbox", function (options, content)
362✔
372
      local vbox
373
      SILE.settings:temporarily(function ()
90✔
374
         if options.width then
45✔
NEW
375
            SILE.settings:set("typesetter.breakwidth", SILE.length(options.width))
×
376
         end
377
         SILE.typesetter:pushState()
45✔
378
         SILE.process(content)
45✔
379
         SILE.typesetter:leaveHmode(1)
45✔
380
         vbox = SILE.pagebuilder:collateVboxes(SILE.typesetter.state.outputQueue)
90✔
381
         SILE.typesetter:popState()
45✔
382
      end)
383
      return vbox
45✔
384
   end, "Compiles all the enclosed material into a single vbox")
181✔
385
end
386

387
return class
181✔
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