Skip to content

Commit

Permalink
fix: chapter title in running header should honor its numberstyle
Browse files Browse the repository at this point in the history
Closes #46
More precisely the second part of it (the first was fixed in #47).
This is slightly breaking (the header numberstyle was ignored on
chapters, but this was an oversight). Users might have to remove
it from their style file if they do no want it.
  • Loading branch information
Omikhleia authored and Didier Willis committed Jun 22, 2023
1 parent f56ae98 commit f978d6c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
40 changes: 23 additions & 17 deletions classes/resilient/book.lua
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,24 @@ function class:declareSettings ()
})
end

function class:runningHeaderSectionReference (options, content)
if SU.boolean(options.numbering, true) then
local sty = self:resolveStyle(options.style)
local numsty = sty.sectioning and sty.sectioning.numberstyle
and sty.sectioning.numberstyle.header
if numsty and sty.sectioning.counter.id then
local number = self.packages.counters:formatMultilevelCounter(
self:getMultilevelCounter(sty.sectioning.counter.id), {
noleadingzeros = true,
level = sty.sectioning.counter.level -- up to the sectioning level
}
)
SILE.call("style:apply:number", { name = numsty, text = number })
end
end
SILE.process(content)
end

function class:registerCommands ()
base.registerCommands(self)

Expand Down Expand Up @@ -416,34 +434,22 @@ function class:registerCommands ()
SILE.call("set-multilevel-counter", { id = "sections", level = 1, value = 0 })
end, "Apply part hooks (counter resets, footers and headers, etc.)")

self:registerCommand("sectioning:chapter:hook", function (_, content)
self:registerCommand("sectioning:chapter:hook", function (options, content)
-- Chapters re-enable folios, have no header, and reset the footnote counter.
SILE.call("noheaderthispage")
SILE.call("folios")
SILE.call("set-counter", { id = "footnote", value = 1 })

-- Chapters, here, go in the even header.
SILE.call("even-running-header", {}, content)
SILE.call("even-running-header", {}, function ()
self:runningHeaderSectionReference(options, content)
end)
end, "Apply chapter hooks (counter resets, footers and headers, etc.)")

self:registerCommand("sectioning:section:hook", function (options, content)
-- Sections, here, go in the odd header.
SILE.call("odd-running-header", {}, function ()
if SU.boolean(options.numbering, true) then
local sty = self:resolveStyle("sectioning-section")
local numsty = sty.sectioning and sty.sectioning.numberstyle
and sty.sectioning.numberstyle.header
if numsty and sty.sectioning.counter.id then
local number = self.packages.counters:formatMultilevelCounter(
self:getMultilevelCounter(sty.sectioning.counter.id), {
noleadingzeros = true,
level = sty.sectioning.counter.level -- up to the section level
}
)
SILE.call("style:apply:number", { name = numsty, text = number })
end
end
SILE.process(content)
self:runningHeaderSectionReference(options, content)
end)
end, "Applies section hooks (footers and headers, etc.)")

Expand Down
1 change: 0 additions & 1 deletion examples/sile-resilient-manual-styles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,6 @@ sectioning-chapter:
level: 1
hook: "sectioning:chapter:hook"
numberstyle:
header: "sectioning-chapter-head-number"
main: "sectioning-chapter-main-number"
reference: "sectioning-chapter-ref-number"
settings:
Expand Down

0 comments on commit f978d6c

Please sign in to comment.