feat: Pagebreak headings if the page is too far advanced

Can be configured using the `heading_pagebreak_percentage` property
This commit is contained in:
Laurenz 2024-03-24 14:31:50 +01:00
parent edb1a55ada
commit 9b6fe813df
No known key found for this signature in database
GPG key ID: E3D5C22DBA1A8C36
4 changed files with 29 additions and 1 deletions

Binary file not shown.

View file

@ -26,6 +26,13 @@ you can supply it if it is not "Introduction" using the `first_chapter_title` pa
caption: [Code example explaining how to configure language and a different first chapter] caption: [Code example explaining how to configure language and a different first chapter]
) )
// By default, the template will *not* apply a pagebreak
// on non-top-level headings to avoid headings without content
// on the same page but can be enabled.
// The threshold percentage on the page can be configured
// by providing the `heading_pagebreak_percentage` propery like `0.7` or `none`.
// Top-level headings will always have a (weak) pagebreak.
== Bibliography == Bibliography
As for bibliography / reference listing, As for bibliography / reference listing,

View file

@ -140,6 +140,12 @@
// This is required to generate the content section correctly // This is required to generate the content section correctly
first_chapter_title: "Introduction", first_chapter_title: "Introduction",
// Factor of page location when to pagebreak headings
// to avoid a heading without content on the same page.
// Can be disabled by setting it to none
// WARNING: can result in "layout did not converge within 5 attempts" issue
heading_pagebreak_percentage: none,
// set automatically by using the template via `#show: thesis.with(...) // set automatically by using the template via `#show: thesis.with(...)
body, body,
) = [ ) = [
@ -207,6 +213,21 @@
// (weak = no pagebreak on already blank pages) // (weak = no pagebreak on already blank pages)
if it.level == 1 { if it.level == 1 {
pagebreak(weak: true) pagebreak(weak: true)
} else if heading_pagebreak_percentage != none {
// If a heading would start at the very end of a page,
// it would not look right => pagebreak
context {
let here_abs = here().position().y
let here_rel = here_abs.abs / page.height
if here_rel > heading_pagebreak_percentage {
// Write but hide to assess location correctly
// Hidden will not have any influence
// on the output besides correct calculation
hide[#here_abs.abs #page.height rel: #here_rel%]
pagebreak(weak: true)
}
}
} }
[ [

View file

@ -36,4 +36,4 @@ but I am too lazy to explain.
= Summary and Conclusion = Summary and Conclusion
#lorem(100) #lorem(250)