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

sile-typesetter / sile / 9441244789

10 Jun 2024 01:45AM UTC coverage: 49.048% (-11.6%) from 60.675%
9441244789

push

github

web-flow
Merge 8a4989eae into 519864108

8320 of 16963 relevant lines covered (49.05%)

1813.12 hits per line

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

83.33
/packages/folio/init.lua
1
local base = require("packages.base")
3✔
2

3
local package = pl.class(base)
3✔
4
package._name = "folio"
3✔
5

6
function package.incrementFolio (_)
3✔
7
   SILE.scratch.counters.folio.value = SILE.scratch.counters.folio.value + 1
×
8
end
9

10
function package:outputFolio (frame)
3✔
11
   if not frame then
3✔
12
      frame = "folio"
3✔
13
   end
14
   local folio = self.class.packages.counters:formatCounter(SILE.scratch.counters.folio)
3✔
15
   if not SILE.quiet then
3✔
16
      io.stderr:write("[" .. folio .. "] ")
3✔
17
   end
18
   if SILE.scratch.counters.folio.off then
3✔
19
      if SILE.scratch.counters.folio.off == 2 then
×
20
         SILE.scratch.counters.folio.off = false
×
21
      end
22
   else
23
      local folioFrame = SILE.getFrame(frame)
3✔
24
      if folioFrame then
3✔
25
         SILE.typesetNaturally(folioFrame, function ()
6✔
26
            SILE.settings:pushState()
3✔
27
            -- Restore the settings to the top of the queue, which should be the document #986
28
            SILE.settings:toplevelState()
3✔
29

30
            -- Reset settings the document may have but should not be applied to footnotes
31
            -- See also same resets in footnote package
32
            for _, v in ipairs({
18✔
33
               "current.hangAfter",
34
               "current.hangIndent",
35
               "linebreak.hangAfter",
36
               "linebreak.hangIndent",
37
            }) do
3✔
38
               SILE.settings:set(v, SILE.settings.defaults[v])
12✔
39
            end
40

41
            SILE.call("foliostyle", {}, { folio })
3✔
42
            SILE.typesetter:leaveHmode()
3✔
43
            SILE.settings:popState()
3✔
44
         end)
45
      end
46
   end
47
end
48

49
function package:_init (options)
3✔
50
   base._init(self)
3✔
51
   self:loadPackage("counters")
3✔
52
   SILE.scratch.counters.folio = { value = 1, display = "arabic" }
3✔
53
   self.class:registerHook("newpage", function ()
6✔
54
      self:incrementFolio()
×
55
   end)
56
   self.class:registerHook("endpage", function ()
6✔
57
      self:outputFolio(options and options.frame)
3✔
58
   end)
59
   self:export("outputFolio", self.outputFolio)
3✔
60
end
61

62
function package:registerCommands ()
3✔
63
   self:registerCommand("folios", function (_, _)
6✔
64
      SILE.scratch.counters.folio.off = false
×
65
   end)
66

67
   self:registerCommand("nofolios", function (_, _)
6✔
68
      SILE.scratch.counters.folio.off = true
×
69
   end)
70

71
   self:registerCommand("nofoliothispage", function (_, _)
6✔
72
      SILE.scratch.counters.folio.off = 2
×
73
   end)
74

75
   self:registerCommand("nofoliosthispage", function (_, _)
6✔
76
      SU.deprecated("nofoliosthispage", "nofoliothispage", "0.12.1", "0.14.0")
×
77
   end, "Deprecated")
3✔
78

79
   self:registerCommand("foliostyle", function (_, content)
6✔
80
      SILE.call("center", {}, content)
3✔
81
   end)
82
end
83

84
package.documentation = [[
85
\begin{document}
86
The \autodoc:package{folio} package (which is automatically loaded by the \autodoc:class{plain} class, and therefore by nearly every SILE class) controls the output of folios—the old-time typesetter word for page numbers.
87

88
It provides four commands to users:
89

90
\begin{itemize}
91
\item{\autodoc:command{\nofolios}: turns page numbers off.}
92
\item{\autodoc:command{\nofoliothispage}: turns page numbers off for one page, then on again afterward.}
93
\item{\autodoc:command{\folios}: turns page numbers back on.}
94
\item{\autodoc:command{\foliostyle}: a command you can override to style the page numbers. By default, they are centered on the page.}
95
\end{itemize}
96

97
If, for instance, you want to set page numbers in a different font you can redefine the command like so:
98

99
\begin[type=autodoc:codeblock]{raw}
100
\define[command=foliostyle]{\center{\font[family=Albertus]{\process}}}
101
\end{raw}
102

103
If you want to put page numbers on the left side of even pages and the right side of odd pages, there are a couple of ways you can do that.
104
The complicated way is to define a command in Lua which inspects the page number and then sets the number ragged left or ragged right appropriately.
105
The easy way is just to put your folio frame where you want it on the master page.
106
\end{document}
107
]]
3✔
108

109
return package
3✔
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