Skip to content

The running head skips the page the chapter opens on - #30

Merged
alpibrupa merged 1 commit into
mainfrom
running-head-skips-openers
Sep 4, 2026
Merged

The running head skips the page the chapter opens on#30
alpibrupa merged 1 commit into
mainfrom
running-head-skips-openers

Conversation

@alpibrupa

Copy link
Copy Markdown
Contributor

Closes #29.

Since #20 a chapter's title ran top-centre on every page of that chapter — including the chapter's own opening page, where the title is already set two inches below in 1.8em, and where book typography conventionally drops the running head.

#29 recorded this as a limitation because named page groups cannot express it, and that part was right. WeasyPrint reads :first as the first page of the document rather than of the group, so @page chapter:first suppresses only the very first chapter's opener. Alternating the names between chapters — which should have broken the grouping — does not help either. Verified on 69.0 with four chapters given alternating names:

['-', 'Title 1', 'Title 1', 'Title 2', 'Title 2', 'Title 2', 'Title 3', ...]

Openers two, three and four still print.

The mechanism that works is not page groups at all. CSS Paged Media gives string() a second argument for exactly this case — first-except yields the empty string on the page where the string was set, and the set happens on the chapter's own opening page:

['-', 'Title 1', 'Title 1', '-', 'Title 2', 'Title 2', '-', 'Title 3', 'Title 3', '-', 'Title 4', 'Title 4']

One keyword. No named pages, no alternating classes, continuation pages untouched.

Verified across all four books in the series — 67 chapter and appendix openers, none carrying a running head; 328 continuation pages that still do:

book pages openers openers with a head pages with a head
production 163 17 0 137
evidence 96 17 0 70
ledger 96 17 0 70
decision 76 16 0 51

144 tests pass, ruff clean, 4 import contracts kept. The new test pins the keyword itself, since the behaviour rests entirely on it and a well-meaning simplification back to string(chaptertitle) would silently restore the bug.

🤖 Generated with Claude Code

Since #20 a chapter's title ran top-centre on every page of that chapter,
including the chapter's own opening page -- where the title is already set two
inches below in 1.8em, and where book typography conventionally drops the
running head.

#29 recorded this as a limitation on the grounds that named page groups cannot
express it, and that part was right. WeasyPrint reads `:first` as the first
page of the document rather than of the page group, so `@page chapter:first`
suppresses only the very first chapter's opener. Alternating the names between
chapters, which should have broken the grouping, does not help either --
verified on 69.0, where four chapters given alternating names still print
their titles on openers two, three and four.

The mechanism that does work is not page groups at all. CSS Paged Media gives
`string()` a second argument for exactly this case: `first-except` yields the
empty string on the page where the string was set, and the set happens on the
chapter's own opening page. One keyword, no named pages, no alternating
classes, and continuation pages are untouched.

Verified across the four books in the series: 67 chapter and appendix openers,
none carrying a running head, and 328 continuation pages that still do.

Closes #29.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@alpibrupa
alpibrupa merged commit 1b5973e into main Sep 4, 2026
4 checks passed
@alpibrupa
alpibrupa deleted the running-head-skips-openers branch September 4, 2026 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bookkit: the running header prints on chapter-opening pages

1 participant