Skip to content

Code numbering: honour scope in book mode and template in captions#56

Merged
mmcky merged 3 commits into
mainfrom
feature/code-numbering
Jun 12, 2026
Merged

Code numbering: honour scope in book mode and template in captions#56
mmcky merged 3 commits into
mainfrom
feature/code-numbering

Conversation

@mmcky

@mmcky mmcky commented Jun 12, 2026

Copy link
Copy Markdown

Fixes #47

What

Two gaps in code (enumerable code-block) numbering, both surfaced wiring book-dp1's listings to match its LaTeX PDF:

  1. numbering.code.scope was ignored. code was missing from AUTO_PREFIX_KINDS, the gate on the entire book-mode prefix + scope machinery — so listings enumerated 1, 2, 3, … with no chapter prefix while proof:*/exercise/figure honored scope:. Adding code to the set gives Listing 1.1, 1.2, … 2.1 (and section scope 1.1.1 works too). Non-book projects are unaffected: the gate also requires numbering.book.enabled.
  2. The caption noun ignored the configured template. getCaptionLabel always used the built-in default (Program %s), so with template: "Listing %s" references said "Listing 1" while the caption said "Program 1". Captions now resolve numbering[kind].template exactly like getReferenceTemplate does for cross-references. Defaults are unchanged for every kind, because fillNumbering always supplies the built-in template — only explicitly configured templates change output.

One wrinkle found while testing: ReferenceState.resolveStateProvider(identifier) requires a page argument and returns undefined without one, so the caption transform falls back to the state's own numbering for 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:

before after
enumerators 1, 2, 1 1.1, 1.2, 2.1
caption Program 1: Listing 1.1:
{numref} Listing 1 Listing 1.1
  • 4 new tests in enumerate.spec.ts: chapter prefix + cross-chapter reset, section scope, caption template, and caption default fallback (which pinned the built-in templates' non-breaking space)
  • Full monorepo build + test (73 turbo tasks incl. the e2e numbering snapshots) and lint pass

🤖 Generated with Claude Code

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>
Copilot AI review requested due to automatic review settings June 12, 2026 02:38

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 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 code to the book-mode auto-prefix/scope machinery so numbering.code.scope applies (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.

Comment thread packages/myst-transforms/src/enumerate.ts Outdated
Comment thread packages/myst-transforms/src/enumerate.ts Outdated
mmcky and others added 2 commits June 12, 2026 12:51
…-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 mmcky merged commit 7385451 into main Jun 12, 2026
6 checks passed
@mmcky mmcky deleted the feature/code-numbering branch June 12, 2026 03:05
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>
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.

numbering.code: scope ignored (no chapter prefix) and caption noun stays "Program" despite template "Listing %s"

2 participants