Prevent 2-line pages

Hello everyone,
I am typesetting a novel where chapters always begin on a new page.
Occasionally, the page before the new chapter is very tiny, like 2 lines (see image below) :


This left page looks pretty bad and it would look way better if those two lines were added to the previous pages (and the former paragraphs were a bit more condensed to make room for them, of course)
Is there a way to automatically prevent 2-line pages (or even n-line pages, I may have a few cases of 3-line pages which are as disgraceful) throughout the whole book ?

2 Likes

According to the text() function’s documentation, a widow is “a single line of paragraph on the next page”. You can increase the cost of these so that they are avoided more strongly:

#set text(costs(widow: 100%))

But since your example has 2 lines, I think it will not be counted as a widow by Typst.
Besides adding a feature to Typst that allows defining what counts as a widow, I don’t have any other ideas for reacting to these occurrences. Feature requests can be submitted to the project’s issue tracker.

2 Likes

Yeah, it seems there is no solution to my problem as of now.
I will then submit a feature request (if this has not been asked before, of course !)

Thanks for your reply

1 Like

There is already an open issue about better control for widows: More fine-grained control over widow/orphan preventation · Issue #5931 · typst/typst · GitHub

I encourage you to upvote this, as the team tends to prioritise features that have the most likes. If you have good ideas or important considerations that one should keep in mind when implementing this in the layout engine, you should add those to the discussion :slight_smile:

I agree with @gezepi that there isn’t much you can do for now, besides manually adjusting spacing. The feature you seek is computationally expensive and implementing this within typst would require doing extremely hacky things, which would likely break other parts of the document

1 Like

Haha, I was just in the middle of editing my reply to express that there is already a feature request for that !
As for my current solution, I went for carefully adjusting spacing and tracking on specific paragraphs (where it would be less noticeable). The relevant files are thoroughly commented to make sure I can easily revert the changes in case of a working solution in Typst (e.g. the control over widow/orphan).

Thank you all for your replies ! Topic closed :slight_smile:

2 Likes