Fix nested theorem numbering: child counters now inherit correct parent number#35
Conversation
Move frame-counter.step() to the beginning of each frame body so that child counters (e.g. corollary inside theorem) inherit the correct parent number. Remove the +1 adjustment in display-number since the counter is already at the right value when here() is evaluated. Update theorion-display-number to use the metadata location (after the step) for accurate counter reads. Add regression test. Co-authored-by: OrangeX4 <34951714+OrangeX4@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes hierarchical theorem numbering when a child frame (e.g., corollary) is placed inside a parent frame’s body (e.g., theorem) by ensuring the parent counter is stepped before nested content is laid out.
Changes:
- Move
frame-counter.step()to the start of the frame body so nested children see the incremented parent number at their location. - Update
display-numberto remove the previous+1adjustment (counter is now stepped earlier). - Update
theorion-display-numberto compute numbering using the<theorion-frame-metadata>location (after stepping) to keep outlines/refs correct. - Add a regression test and reference snapshot for nested numbering.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
core.typ |
Adjusts counter stepping and numbering-location logic to make nested child counters inherit the correct parent number. |
tests/issues/i-nested-numbering/test.typ |
Adds a regression test covering nested corollaries within theorems (including multiple nested corollaries). |
tests/issues/i-nested-numbering/ref/1.png |
Adds the visual reference output for the new regression test. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| let get-loc = () => { | ||
| let metadata-els = query(selector(<theorion-frame-metadata>).after(el.location())) | ||
| if metadata-els.len() > 0 { | ||
| metadata-els.first().location() | ||
| } else { | ||
| el.location() | ||
| } | ||
| } |
There was a problem hiding this comment.
get-loc performs a query(...) each time it’s called. Since the numbering function may call get-loc more than once (especially for user-supplied numbering functions), this can repeat an O(N) query unnecessarily. Consider computing the metadata location once (outside the closure) and making get-loc return that cached location.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Child-counter frames (e.g.
corollary) placed inside a parent frame body (e.g.theorem) received the wrong parent number. The counter step was emitted at the end of the figure body, so any nested child readtheorem-counter = n-1instead ofn.Sequential placement (corollary after theorem) is unaffected.
Changes (
core.typ)make-frame— emitframe-counter.step()at the start of the figure body (before metadata + render), not the end; nested children now see the incremented parent counter at their document locationdisplay-number— drop the+1offset; the step precedeshere()so the raw counter value is already correcttheorion-display-number— use the<theorion-frame-metadata>label location (inside the body, after the step) instead ofel.location()(the figure anchor, before the step) to maintain correct numbering in outlines and cross-referencesOriginal prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.