Code numbering: honour scope in book mode and template in captions#56
Merged
Conversation
Two gaps in `code` (enumerable code-block) numbering relative to the other enumerable kinds: - `code` was missing from AUTO_PREFIX_KINDS, so `numbering.code.scope` and the book-mode chapter prefix never applied (listings enumerated 1, 2, ... instead of 1.1, 1.2, ... 2.1) - getCaptionLabel ignored the configured numbering templates, so a `template: "Listing %s"` rendered references as "Listing 1" but the caption header as "Program 1"; captions now resolve the template the same way cross-references do (defaults unchanged, since fillNumbering always supplies the built-in template) Fixes #47 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes two inconsistencies in enumerable code (code-block) numbering so book-mode listings and their captions match the configured numbering behavior (scope + template), aligning captions with cross-references.
Changes:
- Add
codeto the book-mode auto-prefix/scope machinery sonumbering.code.scopeapplies (e.g., chapter/section prefixes in book mode). - Make caption labels use
numbering[kind].template(when provided) so caption nouns match{numref}output. - Add targeted tests for chapter/section scoping and caption template vs default fallback, plus a changeset entry.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/myst-transforms/src/enumerate.ts | Enables book-mode scoped prefixes for code and updates caption label generation to respect configured templates. |
| packages/myst-transforms/src/enumerate.spec.ts | Adds regression tests covering code scoping and caption-template behavior. |
| .changeset/code-numbering.md | Records the behavior change as a patch release note for myst-transforms. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…-less captions - Resolve the providing page state once per container instead of two linear searches across states (target lookup + numbering selection) - Containers without a kind are figures (kindFromNode); their caption label now honours numbering.figure.template instead of a hard-coded default Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
mmcky
added a commit
that referenced
this pull request
Jun 12, 2026
…res (#58) VERSION.yml: bumps qe_version to qe-v8; adds merged features 10 (code-numbering, 7385451) and 11 (proof-unnumbered, 75e07a9); sets tag: qe-v8 on features 8-11 (fancy-lists, cite-code-span, code-numbering, proof-unnumbered). UPSTREAM-PRS.yml: appends the code-numbering squash to the book-mode-with-section-scope bundle (its scope half builds on the bundle's AUTO_PREFIX_KINDS machinery); adds a standalone proof-unnumbered candidate (verified byte-identical to upstream before the change, clean cherry-pick). After squash-merging this PR, tag the resulting main commit: git tag qe-v8 <sha> -m "qe-v8: fancy lists, cite code-span guard, code numbering, unnumbered proofs" git push origin qe-v8 Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #47
What
Two gaps in
code(enumerable code-block) numbering, both surfaced wiring book-dp1's listings to match its LaTeX PDF:numbering.code.scopewas ignored.codewas missing fromAUTO_PREFIX_KINDS, the gate on the entire book-mode prefix + scope machinery — so listings enumerated1, 2, 3, …with no chapter prefix whileproof:*/exercise/figurehonoredscope:. Addingcodeto the set givesListing 1.1, 1.2, … 2.1(and section scope1.1.1works too). Non-book projects are unaffected: the gate also requiresnumbering.book.enabled.getCaptionLabelalways used the built-in default (Program %s), so withtemplate: "Listing %s"references said "Listing 1" while the caption said "Program 1". Captions now resolvenumbering[kind].templateexactly likegetReferenceTemplatedoes for cross-references. Defaults are unchanged for every kind, becausefillNumberingalways supplies the built-in template — only explicitly configured templates change output.One wrinkle found while testing:
ReferenceState.resolveStateProvider(identifier)requires apageargument and returnsundefinedwithout one, so the caption transform falls back to the state's ownnumberingfor single-page states (the multi-page resolver path resolves normally).Verification
With the issue's config (
numbering.book: true,code: { scope: chapter, template: "Listing %s" }) on a two-chapter project:1,2,11.1,1.2,2.1Program 1:Listing 1.1:{numref}Listing 1Listing 1.1enumerate.spec.ts: chapter prefix + cross-chapter reset, section scope, caption template, and caption default fallback (which pinned the built-in templates' non-breaking space)🤖 Generated with Claude Code