Executed 2026-11-22 · PyMuPDF 1.28.2 · 0 guessed numbers

Split by bookmarks: 9 chapters, 10/10, one bug caught

The numbers first: 10 bookmarks in, naive per-bookmark splitting produced 12 overlapping chapters, the fixed boundary rule produced 9 chapters, 10/10 bookmarks verified. This run closes the loop between our merge offset formula and the split filter-and-minus rule: split a merged document by its own bookmarks, one chapter per bookmark, and check every destination.

The bug we hit first

All 10 bookmarks sat at level 1, so a naive “one chapter per bookmark” rule created overlapping chapters: A s3 and A s4 both target page 3, and both claimed pages 3… (12 bookmarks written across 10 chapters). A split with overlaps is not a split.

The fixed rule

A new chapter starts only at a bookmark whose destination page is strictly greater than the previous chapter’s start. Bookmarks sharing a page belong to the current chapter. Boundary: chapter end = next chapter start − 1 (last chapter runs to the final page).

The executed result

Decision rule this run supports

Bookmark-driven splitting is safe only when the boundary rule deduplicates same-page bookmarks. With that rule, per-chapter bookmark counts sum exactly to the source outline — a check any tool can show instead of claiming “bookmarks preserved”.