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

sile-typesetter / sile / 6713098919

31 Oct 2023 10:21PM UTC coverage: 52.831% (-21.8%) from 74.636%
6713098919

push

github

web-flow
Merge d0a2a1ee9 into b185d4972

45 of 45 new or added lines in 3 files covered. (100.0%)

8173 of 15470 relevant lines covered (52.83%)

6562.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")
7✔
2

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

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

10
function package:outputFolio (frame)
7✔
11
  if not frame then frame = "folio" end
7✔
12
  local folio = self.class.packages.counters:formatCounter(SILE.scratch.counters.folio)
7✔
13
  if not SILE.quiet then
7✔
14
    io.stderr:write("[" .. folio .. "] ")
7✔
15
  end
16
  if SILE.scratch.counters.folio.off then
7✔
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)
6✔
22
    if (folioFrame) then
6✔
23
      SILE.typesetNaturally(folioFrame, function ()
12✔
24
        SILE.settings:pushState()
6✔
25
        -- Restore the settings to the top of the queue, which should be the document #986
26
        SILE.settings:toplevelState()
6✔
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({
36✔
31
          "current.hangAfter",
32
          "current.hangIndent",
33
          "linebreak.hangAfter",
34
          "linebreak.hangIndent" }) do
6✔
35
          SILE.settings:set(v, SILE.settings.defaults[v])
24✔
36
        end
37

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

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

55
function package:registerCommands ()
7✔
56

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

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

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

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

73
  self:registerCommand("foliostyle", function (_, content)
14✔
74
    SILE.call("center", {}, content)
6✔
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
]]
7✔
103

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