Skip to content

Commit

Permalink
fix(footnotes): relocate footnoteManager:typesetFootnotes to parallel…
Browse files Browse the repository at this point in the history
…Pagebreak to avoid overflow footnote content being stuck in the same frame.
  • Loading branch information
no-vici committed Jan 23, 2025
1 parent ccbb79b commit 50a5956
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions packages/parallel/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ function FootnoteManager:add(frame, note)
end

-- Get footnotes for a specific frame
function FootnoteManager:get(frame)
return self.frames[frame]
end
-- function FootnoteManager:get(frame)
-- return self.frames[frame]
-- end

-- Iterate over footnotes for a specific frame
function FootnoteManager:processNotes(frame, callback)
Expand All @@ -41,6 +41,11 @@ function FootnoteManager:processNotes(frame, callback)
end
end

-- Clear footnotes for a specific frame
function FootnoteManager:clear(frame)
self.frames[frame] = {}
end

-- Create an instance of the FootnoteManager
local footnoteManager = FootnoteManager:new()

Expand Down Expand Up @@ -209,6 +214,8 @@ function FootnoteManager:processSingleNote(frame, note, context, typesetter)
-- Note needs to be split
self:handleOverflowingNote(noteQueue, context, typesetter)
end
-- Reset noteQueue to release memory
noteQueue = nil
end

function FootnoteManager:handleOverflowingNote(noteQueue, context, typesetter)
Expand Down Expand Up @@ -293,6 +300,8 @@ function FootnoteManager:typesetFootnotes()
else
log("No footnotes to process for frame: " .. frame)
end
-- Flush footnote frames
footnoteManager:clear(frame)
end
end

Expand Down Expand Up @@ -321,8 +330,8 @@ local parallelPagebreak = function()

if #linesToFit > 0 then
hasOverflow = true
-- overflowContent[frame] = linesToFit
overflowContent[frame] = pl.tablex.copy(linesToFit)
overflowContent[frame] = linesToFit
-- overflowContent[frame] = pl.tablex.copy(linesToFit)
-- Reset output queue to avoid double processing
typesetter.state.outputQueue = {}
else
Expand All @@ -335,6 +344,9 @@ local parallelPagebreak = function()
-- End the current page
SILE.documentState.documentClass:endPage()

-- At this point, all markers for the page are committed. Now typeset footnotes.
footnoteManager:typesetFootnotes()

if hasOverflow then
-- Start a new page
SILE.documentState.documentClass:newPage()
Expand Down Expand Up @@ -399,7 +411,7 @@ function package:_init (options)
for frame, typesetter in pairs(options.ftn_frames) do
footnotePool[frame] = SILE.typesetters.base(SILE.getFrame(typesetter))
footnotePool[frame].id = typesetter
-- You should not disable the auto page-building here, otherwise you can't typeset
-- NOTE: You should not disable the auto page-building here, otherwise you can't typeset
-- any footnotes on the last page of your document.
end

Expand Down Expand Up @@ -454,7 +466,7 @@ function package:registerCommands()
SILE.typesetter:pushExplicitVglue(SILE.types.length(height):absolute())
end)

self:registerCommand("sync", function(_, _)
registerSimpleCommand("sync", function(_, _)
local anybreak = false

-- Check for potential page breaks.
Expand All @@ -477,8 +489,9 @@ function package:registerCommands()
return
end

-- Typeset footnotes after ensuring all main text is processed
footnoteManager:typesetFootnotes()
-- Typeset footnotes after ensuring all main text is processed.
-- NOTE: Perhaps this should be done in the page builder?
-- footnoteManager:typesetFootnotes()

-- Add balancing glue to align frame heights
addBalancingGlue()
Expand Down Expand Up @@ -508,7 +521,7 @@ function package:registerCommands()
end)
end)

-- Stolen from `resilient.footnotes` package
-- Adapted from `resilient.footnotes` package
registerSimpleCommand("parallel_footnote:rule", function(options, _)
local width = SU.cast("measurement", options.width or "20%fw") -- "Usually 1/5 of the text block"
local beforeskipamount = SU.cast("vglue", options.beforeskipamount or "1ex")
Expand Down

0 comments on commit 50a5956

Please sign in to comment.