diff --git a/crates/typst-library/src/layout/page.rs b/crates/typst-library/src/layout/page.rs index b2efed199..495b390dc 100644 --- a/crates/typst-library/src/layout/page.rs +++ b/crates/typst-library/src/layout/page.rs @@ -378,7 +378,10 @@ impl PageElem { let mut frames = child.layout(vt, styles, regions)?.into_frames(); // Align the child to the pagebreak's parity. - if extend_to.is_some_and(|p| p.matches(page_counter.physical().get())) { + // Check for page count after adding the pending frames + if extend_to + .is_some_and(|p| !p.matches(page_counter.physical().get() + frames.len())) + { // Insert empty page after the current pages. let size = area.map(Abs::is_finite).select(area, Size::zero()); frames.push(Frame::hard(size)); diff --git a/tests/ref/layout/pagebreak-parity.png b/tests/ref/layout/pagebreak-parity.png index af08bac11..8c05dc92d 100644 Binary files a/tests/ref/layout/pagebreak-parity.png and b/tests/ref/layout/pagebreak-parity.png differ diff --git a/tests/typ/layout/pagebreak-parity.typ b/tests/typ/layout/pagebreak-parity.typ index 4d6ae9414..1cfbd450e 100644 --- a/tests/typ/layout/pagebreak-parity.typ +++ b/tests/typ/layout/pagebreak-parity.typ @@ -21,3 +21,15 @@ Seventh First #pagebreak(to: "odd") Third + +--- +#set page(height: 30pt, width: 80pt) + +// Test when content extends to more than one page +First + +Second + +#pagebreak(to: "odd") + +Third