Skip to content

Book mode: support section-level prefix for proof:* enumerators (LaTeX-style chapter.section.counter) #27

Description

@mmcky

Summary

In numbering.book: true mode, proof:* elements (theorem, lemma, proposition, example, remark, algorithm, exercise, etc.) pick up the chapter prefix only, giving Theorem 5.1, Lemma 5.2. LaTeX book class with \newtheorem{theorem}[section] instead gives Theorem 5.1.2 (chapter 5, section 1, second theorem). For books being converted from LaTeX where the printed PDF is the canonical reference, this divergence breaks reader cross-walking between the PDF and the MyST site.

There appears to be no current mechanism to opt in to the deeper prefix.

Concrete example (from QuantEcon/book-dp1 Vol I PDF)

Element LaTeX PDF qe-v2 MyST
Theorem 1.2.1 Neumann Series 1.2.1 1.1
Theorem 1.2.3 Banach 1.2.3 1.2
Proposition 5.1.1 5.1.1 5.1
Lemma 5.1.2 5.1.2 5.1 or 5.2

Sections themselves, figures, and equations all match the PDF correctly under qe-v2. The mismatch is specific to proof:*.

Where the limitation lives

packages/myst-transforms/src/enumerate.ts:558-572incrementCount builds autoPrefix = \${this.enumerator}.`from the page's chapter enumerator only. There is no path that consults the current heading_2 enumerator.resolveEnumerator(line 519) does a single%ssubstitution on the already-composed string, sonumbering[kind].enumerator` templates can't inject a section level either.

Proposed feature

A scope (or prefix) option on the relevant numbering kinds, e.g.:

project:
  numbering:
    book: true
    proof:
      scope: heading_2     # default: 'chapter' (current behaviour)

or per-kind:

numbering:
  proof:theorem:
    scope: heading_2

When scope: heading_2, the auto-prefix should be ${currentChapter}.${currentSection}. and the counter should reset on heading_2 boundary (matching LaTeX \newtheorem{theorem}[section]).

Optionally a more general scope: heading_3, etc. (matching [subsection]).

The counter-reset behaviour also needs to follow the chosen scope — i.e. targetCounts[kind].main should reset when a new heading_2 is visited, not just on page boundaries.

Why this matters

For book conversions where the PDF is published or canonical, references like 'see Theorem 5.1.2' appearing in body text are referring to a specific 3-level number that must match the rendered enumerator. With chapter-only prefixes, prose and cross-refs stop agreeing. The current behaviour suits articles or doc-sites with one-flat-counter-per-chapter conventions, but not LaTeX-derived books.

Context

Found during the QuantEcon/book-dp1 MyST conversion (mystmd-conversion branch) using qe-v2 / PR #22. Related (separate) issue: #25.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions