Skip to content

Commit

Permalink
fix: Extraneous blank pages are sometimes inserted before chapters or…
Browse files Browse the repository at this point in the history
… parts.

Or anything that tries to check whether a page break is needed
  • Loading branch information
Omikhleia authored and Didier Willis committed Aug 2, 2023
1 parent 5be0edc commit 4992c8c
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions packages/resilient/sectioning/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,24 @@ function package:_init (options)
self.class:loadPackage("counters")
end

local function hasContent()
-- Important, flushes nodes to output queue.
SILE.typesetter:leaveHmode()
-- The frame breaking logic is a bit messy:
-- It's not enough to check if the output queue is empty, because in some
-- cases where horizontal mode was already left, the output queue might still
-- contain vglue nodes. These are ignored afterwards at the top of a frame,
-- so do not count.
local hasNonGlueContent = false
for _, vnode in ipairs(SILE.typesetter.state.outputQueue) do
if not vnode.is_vglue then
hasNonGlueContent = true
break
end
end
return hasNonGlueContent
end

function package:registerCommands ()

local resolveSectionStyleDef = function (name)
Expand Down Expand Up @@ -141,15 +159,15 @@ function package:registerCommands ()
-- I really had hard times to make this work correctly. It now
-- seems ok, but it might be fragile.
SILE.typesetter:leaveHmode() -- Important, flushes nodes to output queue.
if #SILE.typesetter.state.outputQueue ~= 0 then
if hasContent() then
-- We are not at the top of a page, eject the current content.
SILE.call("supereject")
end
SILE.typesetter:leaveHmode() -- Important again...
-- ... so now we are at the top of a page, and only need
-- to add a blank page if we have not landed on an odd page.
if not SILE.documentState.documentClass:oddPage() then
SILE.typesetter:typeset("")
SILE.typesetter:typeset("") -- Some non glue empty content to force a page break.
SILE.typesetter:leaveHmode()
-- Disable headers and footers if we can... i.e. the
-- supporting class loaded all the necessary commands.
Expand All @@ -166,7 +184,7 @@ function package:registerCommands ()

self:registerCommand("open-on-any-page", function (_, _)
SILE.typesetter:leaveHmode() -- Important, flushes nodes to output queue.
if #SILE.typesetter.state.outputQueue ~= 0 then
if hasContent() then
-- We are not at the top of a page, eject the current content.
SILE.call("supereject")
end
Expand Down

0 comments on commit 4992c8c

Please sign in to comment.