Skip to content

prf:algorithm: support continuous line numbering for algorithm2e-style algorithms (nested blocks restart at 1) #70

Description

@mmcky

Summary

algorithm2e (LaTeX) numbers every algorithm line continuously (1…N) and conveys nesting — while / for / repeat bodies — through indentation. When such an algorithm is rendered in MyST (e.g. inside a {prf:algorithm} directive), the natural representation is an ordered list with a nested ordered list for each loop body. But CommonMark restarts numbering at 1 for every nested list, so the loop body is numbered 1, 2, 3… again instead of continuing the outer count.

Example

1. $t \leftarrow 0$
2. input $X_0$
3. **while** $t < \infty$ **do**
   1. observe $X_t$
   2. choose action $A_t$
   3. receive reward $r(X_t, A_t)$
   4. draw $X_{t+1}$ from $P(X_t, A_t, \cdot)$
   5. $t \leftarrow t + 1$
4. **end**

Renders as: 1, 2, 3, then 1, 2, 3, 4, 5 (restarted), then 4.

algorithm2e (PDF) renders as: continuous 1 … 9, with the loop body indented but its line numbers continuing the sequence.

Request

An enhancement so algorithm-style content can render with continuous line numbering across nested blocks while keeping the indentation that shows loop/conditional structure — i.e. algorithm2e parity. This may take the form of a {prf:algorithm} option, a list-numbering mode, or directive-level support; the exact mechanism is open.

Context

Surfaced converting the QuantEcon Dynamic Programming Volume I book; reported downstream at QuantEcon/book-dp-public#31 (item 1). The converter side is tracked at QuantEcon/claude-latex-to-myst#169 — this upstream issue is the likely home if continuous-numbering-with-indentation cannot be produced in plain MyST/CommonMark.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions