Skip to content
Kaleidl

The labeling model

New here? Start with the guide.

Technical documents carry labels everywhere a reader looks. Clauses number 1, 2, 3; the clauses of Annex A number A.1 and A.2; the same figure is Figure 7 in the main body and Figure A.1 inside an annex; a lone note prints as NOTE, while a second note forces the first to become NOTE 1. Publishers state these rules in style guides and encode them, again and again, as imperative code inside their systems.

LADL — the Label Auto-assignment Definition Language, specified in MN 112 — states the rules as data instead. A profile declares how a document family labels itself, and a conforming engine evaluates the profile against a content tree and produces every label and every cross-reference. Kaleidl is the Ruby reference engine, and the same semantic ships in Python, Rust and TypeScript. This page is the model in six sections; the specification page carries the full contract with worked examples.

The three trees

MN 112 models a labeling scheme as three instance trees, and every part of the model lives in one of them. The content tree arrives from the host and describes the elements being labeled — clauses, annexes, figures, notes, list items — each with a type and an identity. The context tree comes from the profile and describes where labeling scopes begin, with contexts linked by a parent reference the way the document itself nests. The labeller tree binds the two: each labeller serves one element type within one context, draws its value from a sequence, and may name a parent labeller so that subclauses know the clause they hang from.

{
  "type": "document",
  "id": "doc",
  "context": "DocumentContext",
  "children": [
    {
      "type": "clause",
      "id": "c1",
      "context": "ClauseContext",
      "children": [
        {
          "type": "subclause",
          "id": "c1_s1",
          "context": "SubclauseContext",
          "children": [
            { "type": "note", "id": "c1_s1_n1" },
            { "type": "example", "id": "c1_s1_x1" }
          ]
        },
        { "type": "note", "id": "c1_n1" },
        { "type": "note", "id": "c1_n2" }
      ]
    },
    // clause 2, the annexes, and the bibliography follow
    // with the same declaration pattern — figures carry
    // FigureContext, annex clauses carry AnnexClauseContext
  ]
}

Anatomy of a profile

A profile is a set of typed instances: one LabelStyle that references the rest, the LabelContext instances that form the context tree, the LabelTemplate instances that give labels their shape, the Labeller instances that bind types to sequences and templates, and the sequences themselves. The excerpt below carries the annex scheme of the ISO/IEC Directives Part 2 style exactly as the conformance vectors carry it.

schema: mn112/1
instances:
- name: AnnexContext
  type: LabelContext
  properties:
    name: "annex"
    parent: {ref: DocumentContext}

- name: AnnexTemplate
  type: LabelTemplate
  properties:
    pattern: "{annex} %n"

- name: AnnexClauseTemplate
  type: LabelTemplate
  properties:
    pattern: "%pn.%n"

- name: AnnexLabeller
  type: Labeller
  properties:
    id: "annex_labeller"
    sequence: {ref: AlphaUpperNumericSequence}
    context: {ref: DocumentContext}
    type: "annex"
    template: {ref: AnnexTemplate}

- name: AnnexClauseLabeller
  type: Labeller
  properties:
    id: "annex_clause_labeller"
    sequence: {ref: DecimalNumericSequence}
    context: {ref: AnnexContext}
    parent: {ref: AnnexLabeller}
    type: "clause"
    template: {ref: AnnexClauseTemplate}

Two bindings in this excerpt carry the whole behavior. The annex clause labeller binds to the annex context, so it labels clauses only inside annexes, while the main clause labeller binds to the document context and never sees them. The same labeller names AnnexLabeller as its parent labeller, so the parent value it substitutes for %pn is the annex's letter, and the pattern %pn.%n renders A.1, A.2, B.1.

ElementRoleLabel
a1first annexAnnex A
a1c1its first clauseA.1
a1c2its second clauseA.2
a2second annexAnnex B
a2c1its first clauseB.1

Engine output: the excerpt's profile run against a two-annex tree, verified with kaleidl-ts.

Counted labels: conditions

A labeller may carry one template or an ordered list of them, and a template may carry a condition. The engine walks the tree, plans and counts first, and renders afterwards, so each conditional template is evaluated against the final count of like-labeled siblings in its context. The first template whose condition holds is selected; the first unconditional template is the fallback. That one mechanism carries the whole of the single-note rule:

- name: NoteSingleTemplate
  type: LabelTemplate
  properties:
    pattern: "{note}"

- name: NoteMultipleTemplate
  type: LabelTemplate
  properties:
    pattern: "{note} %n"
    condition:
      type: "element_count_gt"
      threshold: 1

- name: NoteLabeller
  type: Labeller
  properties:
    id: "note_labeller"
    sequence: {ref: DecimalNumericSequence}
    context: {ref: ClauseContext}
    type: "note"
    template:
    - {ref: NoteSingleTemplate}
    - {ref: NoteMultipleTemplate}

The ISO/IEC style applies the same pair to examples, to notes inside subclauses, and to notes inside annexes. A note inside a subclause binds a subclause note labeller and restarts per subclause, so two subclauses each carrying one note print NOTE twice, while two notes in one clause print NOTE 1 and NOTE 2. A terminological entry's notes bind a separate labeller whose only template carries no condition, which is why the note to entry is always numbered.

ElementSituationLabel
c1n1the only note of clause 1NOTE
c2n1first of three notes in clause 2NOTE 1
c2n2second of three notes in clause 2NOTE 2
c2n3third of three notes in clause 2NOTE 3

Engine output: the conditional note pair run against two clauses, verified with kaleidl-ts.

The label vocabulary

Term words in a pattern are not literals — they are {key} tokens, and the engine resolves each key through a label vocabulary. The vocabulary is the host document's i18n table, and its values are Fluent (FTL) message patterns resolved by the rhoella engine. {note_to_entry} resolves to the message "Note { $n } to entry" in English and "Note { $n } à l'article" in French, so the designation structure itself is language data rather than profile text.

Keys absent from the host table fall back to the English default vocabulary; a key absent from both, or a catalog message that references a message the vocabulary does not define, is a profile error and the engine raises it. Labels never leak braces or question-marked fallbacks into a published document.

Two realizations of one profile

MN 112 defines two realizations of a profile, and a runtime accepts both: the LutaML instance syntax, carried in .lml files, and a YAML realization, carried under the schema key mn112/1. The conformance suite stores each profile in both forms and holds runtimes to identical labeling from either, because equivalent realizations derive the same instance data.

// The same annex scheme in the LutaML instance syntax
instance AnnexContext < LabelContext {
  name = "annex"
  parent = DocumentContext
}

instance AnnexLabeller < Labeller {
  id = "annex_labeller"
  sequence = AlphaUpperNumericSequence
  context = DocumentContext
  type = "annex"
  template = AnnexTemplate
}
- name: AnnexLabeller
  type: Labeller
  properties:
    id: "annex_labeller"
    sequence: {ref: AlphaUpperNumericSequence}
    context: {ref: DocumentContext}
    type: "annex"
    template: {ref: AnnexTemplate}

The LML realization states inheritance in the header of the instance block, and the YAML realization states it as type and properties. The loader dispatches on the file extension, so a flavor keeps its profile in whichever form it maintains and the runtime reads the other without change.

Conformance

A conforming runtime provides fifteen built-in sequences — decimal, Arabic-Indic, Roman upper and lower, alphabetic upper and lower, Chinese, Japanese and Korean numerals, and the Cyrillic, Greek and Hebrew character sequences — and accepts both profile realizations. The conformance vectors at kaleidl/kaleidl-testsuite pin document trees to their expected label sets: the ISO/IEC Directives Part 2 style end to end, terminological entries with notes to entry, ordered-list ladders four levels deep, and the full sequence battery. Every runtime in the Kaleidl fleet vendors the vectors at a pinned reference and re-verifies the snapshot against the testsuite.

The specification page carries the detailed contract: every instance type with its attributes, the template placeholders, the condition types, the sequence semantics with engine-verified outputs, the counter-scoping rules, and a fully worked document labeled by the ISO/IEC style. The playground runs the same engine in the browser against a profile you can edit.