Skip to content

The h1 title is scheme level 0: an empty number that restarts the count - #59

Merged
jph00 merged 1 commit into
mainfrom
title-numbering-boundary
Sep 3, 2026
Merged

The h1 title is scheme level 0: an empty number that restarts the count#59
jph00 merged 1 commit into
mainfrom
title-numbering-boundary

Conversation

@PiotrCzapla

@PiotrCzapla PiotrCzapla commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Needs AnswerDotAI/mdhtml2docx#13 , description and rationale is there.


Claude's summary of the change:

SCHEMES now carry the h1 title as level 0 with an empty lvlText: legal is '', %2., (%3), ... and decimal is '', %2., %2.%3., ... Bumping level 0 resets every level below, which HeadingNums already did, so %2 is the h2 counter and each h1 restarts the count. Scheme index, heading level minus one and Word's ilvl are the same number, so bump and display are untouched and the exporters do no level arithmetic: HTML and gfm skip an empty number, Typst emits "" for the title branch, and full looks for %2 instead of %1. A custom {lvlText: numFmt} dict has the same shape, title entry first. A title has no number to cite; [@sec-t] on an h1 raises the existing "needs a number" error, and {ref=text} cites it.

Tests: cargo test and 929 pytest cases pass (test_math_callbacks_with_math_core needs the optional math-core, unrelated). New test_title_is_numbering_boundary covers HTML, gfm and the scheme shape; the Typst test checks the title branch; fixtures that cited an h1 by number now cite an h2.

@PiotrCzapla
PiotrCzapla force-pushed the title-numbering-boundary branch from 634c419 to db57d22 Compare September 3, 2026 20:51
@PiotrCzapla PiotrCzapla changed the title h1 title as numbering boundary: schemes number from h2, restart at every h1 The h1 title is scheme level 0: an empty number that restarts the count Sep 3, 2026
Numbering schemes now carry the title as their first level, in Word's own
terms: `SCHEMES['legal']` is `''`, `%2.`, `(%3)`, ... and `'decimal'` is
`''`, `%2.`, `%2.%3.`, ... Level 0 is the h1 document title; its empty
lvlText shows nothing, and bumping it resets every level below (the rule
HeadingNums already implements), so a file holding several documents, each
opening with an h1, numbers each of them from 1. `%2` is the h2 counter.
Scheme index, heading level minus one, and Word's ilvl are the same number,
so the exporters need no level arithmetic: they only skip an empty number.
A title has no number to cite; cite it with `{ref=text}`.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@PiotrCzapla
PiotrCzapla force-pushed the title-numbering-boundary branch from db57d22 to 48954ee Compare September 3, 2026 21:01
@PiotrCzapla
PiotrCzapla marked this pull request as ready for review September 3, 2026 21:06
@PiotrCzapla
PiotrCzapla requested a review from jph00 September 3, 2026 21:06
@jph00
jph00 merged commit 7f1440d into main Sep 3, 2026
6 checks passed
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.

2 participants