From 5a54386deeaa0439ae9a805abb0cef456e00ece4 Mon Sep 17 00:00:00 2001 From: GloamXun Date: Mon, 19 Oct 2026 14:24:50 +0800 Subject: [PATCH] Start chapters on a new page --- README.md | 2 +- crates/texrra-core/src/document_parser.rs | 3 +++ docs/ROADMAP.md | 2 +- docs/STATUS.md | 6 +++--- tests/typeset.rs | 9 ++++++++- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 15abf1b..068eb57 100644 --- a/README.md +++ b/README.md @@ -490,7 +490,7 @@ advisory breaks, starred `\vspace`/`\hspace`, `center`, `\hrule`, `\fbox`, | Notes/floats | footnotes with page-bottom insertion area, title/author `\thanks`, figure/table `[htbp]` placement (top/bottom/page/here approximations) | deferred float queue, `\textfraction` | | Contents | `\tableofcontents`, `\listoffigures`, `\listoftables` generated from numbered headings and captions, dotted leaders, page numbers resolved after pagination | per-chapter book/report contents | | Pages | A4/Letter/... page sizes, margins/geometry, automatic pagination, `\newpage`, `\pagebreak`, plain/fancy page styles, `\thispagestyle`, fancyhdr L/C/R headers and footers | — | -| Classes/packages | built-in + local classes, option protocol, local package options, base font sizes 10/11/12pt, chapter headings and numbering | class-specific formatting (automatic chapter page breaks) | +| Classes/packages | built-in + local classes, option protocol, local package options, base font sizes 10/11/12pt, chapter headings and numbering, chapter page breaks | class-specific formatting beyond chapter breaks | | Live preview | incremental paragraph cache, page-hash diffing, SVG refresh | — | The compatibility layer also covers spacing macros, text symbols/letters, style diff --git a/crates/texrra-core/src/document_parser.rs b/crates/texrra-core/src/document_parser.rs index 0ea5a0e..b4548bc 100644 --- a/crates/texrra-core/src/document_parser.rs +++ b/crates/texrra-core/src/document_parser.rs @@ -1262,6 +1262,9 @@ impl Parser { let level = level.min(3); if level == 0 { self.has_chapters = true; + if !self.document.blocks.is_empty() { + self.push_block(Block::PageBreak); + } } let runs = if numbered { let number = self.next_section_number(level); diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md index b75cae4..67c379b 100644 --- a/docs/ROADMAP.md +++ b/docs/ROADMAP.md @@ -11,7 +11,7 @@ styles (plain/fancy, `\thispagestyle`, fancyhdr headers/footers, `\thepage`); geometry-aware `\textwidth`/`\textheight` named length registers; table of contents and figure/table lists with dotted leaders; native PDF rectangles; unified pagination; `\centering`/`\raggedright`/`\raggedleft` declarations and environments; -chapter headings with chapter-prefixed section numbering +chapter headings with chapter-prefixed section numbering and page breaks (`build_positioned_pages` is the only page builder and no separate break planner remains). diff --git a/docs/STATUS.md b/docs/STATUS.md index 7957dca..f156e15 100644 --- a/docs/STATUS.md +++ b/docs/STATUS.md @@ -38,7 +38,8 @@ the source changes; the SVG preview is refreshed per page. figures/tables, with dotted leaders and page numbers resolved after pagination. - Chapters: `\chapter` is a level-0 heading; chapter numbers prefix section - numbers (`1.1`, `1.1.1`) and reset lower counters. + numbers (`1.1`, `1.1.1`) and reset lower counters. Chapters after the first + block start on a new page. - Class sizes: 10pt/11pt/12pt set the body size and propagate through headings, title material, lists, tables, block boxes, footnotes, and the default paragraph indent (10/12pt use 15pt; 11pt uses 17pt). @@ -66,8 +67,7 @@ See `docs/ROADMAP.md` for concrete implementation plans. collected; the insertion area currently follows the page where the paragraph ends rather than the exact reference line. - Contents: chapter headings are listed with chapter-prefixed section - numbers, but contents are not split per chapter and `\chapter` does not - force a page break. + numbers, but contents are not split per chapter. - Miscellaneous: a document-level `\renewcommand{\maketitle}` is ignored in favor of the engine title block. diff --git a/tests/typeset.rs b/tests/typeset.rs index 70d8bf8..f461d18 100644 --- a/tests/typeset.rs +++ b/tests/typeset.rs @@ -966,7 +966,14 @@ fn chapter_headings_number_sections_and_enter_contents() { "#; let value = fresh_preview(source, "chapters.tex"); assert_eq!(value["status"], "ok", "{}", value["message"]); - let svg = page_svg(&value, 0); + assert!( + pages(&value).len() >= 2, + "chapters did not start on a new page: {value}" + ); + let svg = (0..pages(&value).len()) + .map(|index| page_svg(&value, index)) + .collect::>() + .join(""); for needle in [ "Contents", "First", "Chapter", "Alpha", "Beta", "Gamma", "1.1", "1.1.1", "2.1", ] {