Skip to content

Commit

Permalink
feat(typesetters): Discourage page breaks after hyphenated lines
Browse files Browse the repository at this point in the history
  • Loading branch information
Omikhleia authored and Didier Willis committed Feb 4, 2025
1 parent 4ff5c60 commit ba49c8c
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion typesetters/base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ function typesetter.declareSettings (_)
help = "Whether to ignore paragraph initial spaces",
})

SILE.settings:declare({
parameter = "typesetter.brokenpenalty",
type = "integer",
default = 100,
help = "Penalty to be applied to broken (hyphenated) lines",
})

SILE.settings:declare({
parameter = "typesetter.orphanpenalty",
type = "integer",
Expand Down Expand Up @@ -647,6 +654,8 @@ function typesetter:boxUpNodes ()
pageBreakPenalty = SILE.settings:get("typesetter.widowpenalty")
elseif #lines > 1 and index == (#lines - 1) then
pageBreakPenalty = SILE.settings:get("typesetter.orphanpenalty")
elseif line.is_broken then
pageBreakPenalty = SILE.settings:get("typesetter.brokenpenalty")
end
vboxes[#vboxes + 1] = self:leadingFor(vbox, self.state.previousVbox)
vboxes[#vboxes + 1] = vbox
Expand Down Expand Up @@ -1255,12 +1264,16 @@ function typesetter:breakpointsToLines (breakpoints)
SU.debug("typesetter", "Skipping a line containing only discardable nodes")
linestart = point.position + 1
else
local is_broken = false
if slice[#slice].is_discretionary then
-- The line ends, with a discretionary:
-- repeat it on the next line, so as to account for a potential postbreak.
linestart = point.position
-- And mark it as used as prebreak for now.
slice[#slice]:markAsPrebreak()
-- We'll want a "brokenpenalty" eventually (if not an orphan or widow)
-- to discourage page breaking after this line.
is_broken = true
else
linestart = point.position + 1
end
Expand All @@ -1282,7 +1295,7 @@ function typesetter:breakpointsToLines (breakpoints)
slice = self:_reboxLiners(slice)
end

local thisLine = { ratio = ratio, nodes = slice }
local thisLine = { ratio = ratio, nodes = slice, is_broken = is_broken }
lines[#lines + 1] = thisLine
end
end
Expand Down

0 comments on commit ba49c8c

Please sign in to comment.