Skip to content

Book parts: section: parts dividers with Roman labels - #26

Merged
mmcky merged 5 commits into
mainfrom
feature/book-parts
May 15, 2026
Merged

mmcky merged 5 commits into
mainfrom
feature/book-parts

Conversation

@mmcky

@mmcky mmcky commented May 14, 2026

Copy link
Copy Markdown

Summary

Adds section: parts to the book-numbering feature. A section: parts ParentEntry emits a Roman-numbered divider folder ("Part I — Theory") and wraps a group of chapters. The chapter counter continues across part boundaries — Ch 5 → Part II → Ch 6 — matching the LaTeX book default and unblocking dp2-style books.

This extends qe-v2 (book-numbering) to cover the part-divider structure flagged as the one remaining gap for dp2.

Behaviour

Input Output
section: parts ParentEntry LocalProjectFolder at level -1, title "Part I — <title>", section: 'parts'
Children of a parts subtree Default to section: chapters (overridable per child); land at level 0
Multiple parts in TOC Roman counter increments I → II → …
numbering.parts.format Overrides Roman default (e.g., arabic → Part 1 …)
numbering.parts.label Overrides "Part %s" template (e.g., "Book %s" → Book I …)
numbering.book unset No formatting; raw title used (backwards-compatible)
TOC without parts level defaults to 1 unchanged (regression check)

Implementation

  • myst-toc — extend BookSection with 'parts'; add to BOOK_SECTION_CHOICES for validation.
  • myst-cli/fromTOC.ts:
    • formatPartTitle() builds "Part {Roman} — {title}" using formatCounter from myst-transforms.
    • pagesFromEntries threads a mutable PartCounter through recursion; section parts increments and emits a structural folder; section parts children inherit section: 'chapters' by default.
    • hasPartsSubtree() auto-detects parts in the TOC and starts projectFromTOC at level=-1 so chapters land at heading_1 (not heading_2).
  • Demo — quantecon/demo-book-parts (gitignored scratch) exercises two parts × two chapters + an appendix and verifies dp2-style numbering end-to-end.

Verified output (from the local demo)

Part I — Theory          (folder, level=-1, section=parts)
  ch1                    enumerator=1   → "Chapter 1 Introduction"
  ch2                    enumerator=2   → "Chapter 2 Theory"
Part II — Applications   (folder, level=-1, section=parts)
  ch3                    enumerator=3   → "Chapter 3 Applications"   ← continues across parts
  ch4                    enumerator=4   → "Chapter 4 Extensions"
app-a                    enumerator=A   → "Appendix A"               ← Alph counter unaffected

Figures auto-prefix correctly: fig-intro=1.1, fig-theory=2.1, fig-applications=3.1.

Tests

  • 8 new unit tests in packages/myst-cli/src/project/fromTOC.parts.spec.ts covering folder emission, counter-across-parts, format/label overrides, book-mode gating, child-section default, parts+appendices coexistence, and the no-parts regression.
  • myst-toc parametric test now covers 'parts'.
  • All pre-existing project tests (69) still pass. The 5 failing tests in resolveTemplate / resolveArticles were already failing on main before this PR.

Scope intentionally deferred

  • reset_on_part: true (Quarto-style chapter reset on part entry) — schema accepts it; not consumed.
  • Standalone part-divider pages (synthetic .md content for PDF rendering) — sidebar-only for now, sufficient for web-first books like QuantEcon's.
  • Cross-refs to parts ([](#part-1)) — would need id: on ParentEntry; follow-up if needed.

Test plan

  • CI passes (lint, docs build, bun + node 20/22/24)
  • Local: cd quantecon/demo-book-parts && myst build --site produces the table above
  • After merge: tag qe-v3, bump quantecon/VERSION.yml

🤖 Generated with Claude Code

Extends BookSection with 'parts' and wires the structural-divider
behaviour through fromTOC:

- `section: parts` ParentEntry emits a LocalProjectFolder at part level
  (-1) with a pre-formatted title ("Part I — Theory")
- Children of a parts subtree default to `section: chapters` (the dp2
  convention) and bump to chapter level (0)
- Project-level `numbering.parts.{format,label}` override the Roman /
  "Part %s" defaults
- TOC auto-detects parts and starts at level=-1 so chapter pages land
  at heading_1, not heading_2
- Existing TOCs without parts keep their level=1 start (regression
  test included)

Chapter counter continues across part boundaries (Ch 5 → Part II →
Ch 6) — verified end-to-end in quantecon/demo-book-parts. This is the
LaTeX `book` default and matches dp2's numbering.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
Copilot AI review requested due to automatic review settings May 14, 2026 06:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends the book-numbering / book-section TOC feature to support section: parts, enabling “Part I — …” divider folders (Roman-numbered by default) that wrap chapter groups while keeping chapter numbering continuous across part boundaries (LaTeX book-style).

Changes:

  • Added 'parts' to BookSection and TOC validation choices in myst-toc.
  • Updated projectFromTOC / TOC-to-pages conversion to emit structural part divider folders and default part children to section: chapters.
  • Added a dedicated unit test suite covering part emission, formatting overrides, section inheritance, and regression behavior.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/myst-toc/tests/examples.spec.ts Extends section parsing tests to include parts.
packages/myst-toc/src/types.ts Adds parts to the BookSection union and documents semantics.
packages/myst-toc/src/toc.ts Updates validation choices to accept section: parts.
packages/myst-cli/src/project/fromTOC.ts Emits part divider folders, threads a part counter, defaults part children to chapters, and auto-adjusts base level when parts are present.
packages/myst-cli/src/project/fromTOC.parts.spec.ts Adds unit tests for section: parts behavior and configuration overrides.
.changeset/book-parts.md Declares patch releases for myst-toc and myst-cli describing the new feature.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/myst-toc/src/types.ts Resolved
Three review findings, all fixed:

1. types.ts: "Roman-numeralled" → "Roman-numbered" (typo in doc comment)

2. fromTOC.ts hasPartsSubtree(): restrict detection to non-file
   ParentEntry so it matches the emission predicate exactly. A
   FileEntry/URLEntry tagged with section: parts is malformed (a
   divider can't be a file) and gets downgraded to section: chapters
   without emitting a folder — previously this still shifted the top-
   level start level to -1, producing off-by-one levels for the rest
   of the TOC. Added a regression test asserting the rogue file stays
   at level 1 and no parts folder is emitted.

3. fromTOC.parts.spec.ts basename(): use path.basename from node:path
   instead of splitting on '/' so the test passes on Windows where
   memfs/resolveExtension use backslash separators.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
mmcky added a commit that referenced this pull request May 15, 2026
…ERSION.yml

Two tracker files now record orthogonal facts, cross-referenced by
squash-commit SHA:

- VERSION.yml answers "what's in our main?" — diagnostic identifier
  for the integration build. Drops its `upstream:` block (was an
  always-`pending` placeholder).
- UPSTREAM-PRS.yml answers "how do we plan to ship those squash
  commits upstream?" — bundles related squashes into logical upstream
  PR candidates (so a feature spanning multiple commits, or two
  features that form one upstream story, can be tracked as a single
  unit), records dependency order for cherry-pick, tracks status.

Seeds UPSTREAM-PRS.yml with three candidates: myst-to-ipynb (#16),
book-mode-with-section-scope (#22 + #28, bundled — they form one
coherent upstream story since #28 builds on #22's auto-prefix hooks),
and book-parts (#26, planned). Adds the missing book-proof-scope
entry to VERSION.yml's merged_features.

README updated to partition the two files' roles and reference
UPSTREAM-PRS.yml from the cherry-pick workflow.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
mmcky added a commit that referenced this pull request May 15, 2026
* docs(quantecon): cherry-pick upstream model, batched tags

Replace the "preserve feature branch, push as upstream PR" workflow
with "delete feature branch after merge; cherry-pick main squash
commits onto a fresh branch off upstream/main when upstreaming."

Why:
- Feature branches that depend on prior QuantEcon-only features were
  awkward to branch from upstream/main (had to carry the dependency
  inline or wait for it to upstream first).
- Branching from main lets dependencies just work; the squash commit
  on main is already the upstream-ready artifact.
- Cherry-picking at upstream-PR time lets us bundle related squashes
  into a coherent story ("book mode + section scope") when that's the
  right unit for upstream review, or split them.

Tagging also moves from per-PR to batched: a `qe-vN` tag is cut at a
checkpoint covering multiple features, not on each merge.

Updates the diagram, branching-model table, "Develop a new feature",
"Opening an upstream PR" (now cherry-pick-driven), "When upstream
merges", "Resolving merge conflicts between features", and the
VERSION.yml comment block. Adds an `upstream/<topic>` branch type to
the branching model.

Co-Authored-By: Claude Opus 4.7 <[email protected]>

* docs(quantecon): add UPSTREAM-PRS.yml; split upstream tracking from VERSION.yml

Two tracker files now record orthogonal facts, cross-referenced by
squash-commit SHA:

- VERSION.yml answers "what's in our main?" — diagnostic identifier
  for the integration build. Drops its `upstream:` block (was an
  always-`pending` placeholder).
- UPSTREAM-PRS.yml answers "how do we plan to ship those squash
  commits upstream?" — bundles related squashes into logical upstream
  PR candidates (so a feature spanning multiple commits, or two
  features that form one upstream story, can be tracked as a single
  unit), records dependency order for cherry-pick, tracks status.

Seeds UPSTREAM-PRS.yml with three candidates: myst-to-ipynb (#16),
book-mode-with-section-scope (#22 + #28, bundled — they form one
coherent upstream story since #28 builds on #22's auto-prefix hooks),
and book-parts (#26, planned). Adds the missing book-proof-scope
entry to VERSION.yml's merged_features.

README updated to partition the two files' roles and reference
UPSTREAM-PRS.yml from the cherry-pick workflow.

Co-Authored-By: Claude Opus 4.7 <[email protected]>

* docs(quantecon): address Copilot feedback on PR #30

- VERSION.yml header: remove double-accounting in the tag-cut steps.
  Per-PR landing already appends each feature to merged_features with
  tag: null; the tag-cut workflow just *sets* the tag field on those
  pre-existing entries and bumps qe_version. The old wording said
  "Append each newly-included feature" which contradicted the
  per-PR-landing description below it.
- README "About this folder": the allow-list now contains README.md,
  VERSION.yml, UPSTREAM-PRS.yml, and .gitignore itself — the original
  text only mentioned the first two.

Co-Authored-By: Claude Opus 4.7 <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 <[email protected]>
mmcky and others added 2 commits May 15, 2026 11:04
Smoke test confirming PR #26 and PR #28 operate at independent layers:
parts are a TOC artefact (fromTOC.ts); scope is an in-page counter
(enumerate.ts). The two features have no file overlap and no shared
state, so they should compose naturally. A future change that
accidentally couples them (e.g. by reading scope from inside fromTOC)
would silently regress book-dp2-style projects — pin the expected
output now so any such regression is caught at the TOC layer.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@mmcky
mmcky merged commit 5edc040 into main May 15, 2026
5 checks passed
mmcky added a commit that referenced this pull request May 15, 2026
Bumps qe_version to qe-v4 and adds the book-parts entry (id: 4) to
merged_features with its squash sha 5edc040. The git tag qe-v4 will be
cut on the squash commit of this PR.

Also moves the book-parts entry in UPSTREAM-PRS.yml from `status:
planned` → `pending` and fills in its `commits` list with the now-known
squash sha.

Also syncs the VERSION.yml header comment to the new tag-cut workflow
(metadata PR first, then tag) so it matches README §"Maintaining
VERSION.yml". Previous comment text still described the legacy
"tag-then-update" order and the "batched not per-PR" convention.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
mmcky added a commit that referenced this pull request May 15, 2026
Bumps qe_version to qe-v4 and adds the book-parts entry (id: 4) to
merged_features with its squash sha 5edc040. The git tag qe-v4 will be
cut on the squash commit of this PR.

Also moves the book-parts entry in UPSTREAM-PRS.yml from `status:
planned` → `pending` and fills in its `commits` list with the now-known
squash sha.

Also syncs the VERSION.yml header comment to the new tag-cut workflow
(metadata PR first, then tag) so it matches README §"Maintaining
VERSION.yml". Previous comment text still described the legacy
"tag-then-update" order and the "batched not per-PR" convention.

Co-authored-by: Claude Opus 4.7 <[email protected]>
@mmcky
mmcky deleted the feature/book-parts branch May 15, 2026 02:07
mmcky added a commit that referenced this pull request Nov 4, 2026
…11-04

Conflicts resolved:
- packages/myst-toc/src/types.ts, packages/myst-toc/src/toc.ts,
  packages/myst-cli/src/project/types.ts: keep both sides. Upstream's
  new `searchable` entry key (jupyter-book#2976) sits next to the
  fork's book-mode `section` key (#22, #26); upstream's lines come first
  so the fork's stay a pure addition after them.
- packages/mystmd/tests/endToEnd.spec.ts, packages/mystmd/tests/exports.yml:
  take upstream's `args` + APP_PATH invocation (jupyter-book#3106),
  keep the fork's per-case `retry` loop and the two retried Jupyter
  execution cases (#62).
- packages/mystmd/package.json: take upstream's removal of `npm link`
  (jupyter-book#3106), keep the fork's `copy:qe-version` steps (#42).
- packages/myst-cli/package.json: take upstream's 1.12.0 release ranges,
  keep the fork's myst-to-ipynb dependency.
- packages/myst-to-jats/package.json: take upstream's release ranges,
  keep the fork's katex ^0.16.21 bump (#81).
- bun.lock: take upstream's refreshed workspace ranges, keep the fork's
  myst-to-ipynb and katex ^0.16.21 lines.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

2 participants