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

sile-typesetter / sile / 5913454052

19 Aug 2023 08:49PM UTC coverage: 54.288% (-20.1%) from 74.359%
5913454052

push

github

web-flow
Merge bb71e7fce into c8a15fb85

8469 of 15600 relevant lines covered (54.29%)

6468.28 hits per line

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

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

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

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

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

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

38
        SILE.call("foliostyle", {}, { folio })
7✔
39
        SILE.typesetter:leaveHmode()
7✔
40
        SILE.settings:popState()
7✔
41
      end)
42
    end
43
  end
44
end
45

46
function package:_init (options)
8✔
47
  base._init(self)
8✔
48
  self:loadPackage("counters")
8✔
49
  SILE.scratch.counters.folio = { value = 1, display = "arabic" }
8✔
50
  self.class:registerHook("newpage", function() self:incrementFolio() end)
8✔
51
  self.class:registerHook("endpage", function () self:outputFolio(options and options.frame) end)
24✔
52
  self:export("outputFolio", self.outputFolio)
8✔
53
end
54

55
function package:registerCommands ()
8✔
56

57
  self:registerCommand("folios", function (_, _)
16✔
58
    SILE.scratch.counters.folio.off = false
×
59
  end)
60

61
  self:registerCommand("nofolios", function (_, _)
16✔
62
    SILE.scratch.counters.folio.off = true
1✔
63
  end)
64

65
  self:registerCommand("nofoliothispage", function (_, _)
16✔
66
    SILE.scratch.counters.folio.off = 2
×
67
  end)
68

69
  self:registerCommand("nofoliosthispage", function (_, _)
16✔
70
    SU.deprecated("nofoliosthispage", "nofoliothispage", "0.12.1", "0.14.0")
×
71
  end, "Deprecated")
8✔
72

73
  self:registerCommand("foliostyle", function (_, content)
16✔
74
    SILE.call("center", {}, content)
7✔
75
  end)
76

77
end
78

79
package.documentation= [[
80
\begin{document}
81
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.
82

83
It provides four commands to users:
84

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

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

94
\begin[type=autodoc:codeblock]{raw}
95
\define[command=foliostyle]{\center{\font[family=Albertus]{\process}}}
96
\end{raw}
97

98
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.
99
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.
100
The easy way is just to put your folio frame where you want it on the master page.
101
\end{document}
102
]]
8✔
103

104
return package
8✔
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