Skip to content

Commit

Permalink
fix: Standalone chapter/part number does not work with all paragraph …
Browse files Browse the repository at this point in the history
…alignments

A 'break' only works well in some environments and a 'cr' in others.
For parts and chapters, with the 'standalone' numbering on its
own line,  we need a more robust 'hardbreak' solution to force a line
break properly whatever the paragraph alignment is set to.
  • Loading branch information
Omikhleia authored and Didier Willis committed Sep 12, 2023
1 parent c0035b9 commit 075f051
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion packages/resilient/sectioning/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ function package:registerCommands ()
createCommand("style:apply:number", { name = secStyle.numberstyle.main, text = number })
if SU.boolean(numSty.numbering and numSty.numbering.standalone, false) then
titleContent[#titleContent + 1] =
createCommand("break") -- HACK. Pretty weak unless the parent paragraph style is ragged.
createCommand("hardbreak")
end
end
end
Expand Down Expand Up @@ -247,6 +247,22 @@ function package:registerCommands ()
SILE.typesetter:leaveHmode()
end, "Open a single page")

self:registerCommand("hardbreak", function (_, _)
-- We don't want to use a cr here, because it would affect parindents,
-- insert a parskip, and maybe other things.
-- It's a bit tricky to handle a hardbreak depending on the alignment
-- of the paragraph:
-- justified = we can't use a break, a cr (hfill+break) would work
-- ragged left = we can't use a cr
-- centered = we can't use a cr
-- ragged right = we don't care, a break is sufficient and safer
-- Knowning the alignment is not obvious, neither guessing it from the skips.
-- Using a parfillskip seems to do the trick, but it's maybe a bit hacky.
-- This is nevertheless what would have occurred with a par.
SILE.typesetter:pushGlue(SILE.settings:get("typesetter.parfillskip"))
SILE.call("break")
end, "Insert a hard break respecting the paragraph alignment")

end

package.documentation = [[\begin{document}
Expand Down

0 comments on commit 075f051

Please sign in to comment.