LADL — the Label Auto-assignment Definition Language — is a declarative modeling language for automatic label assignment (numbering, figure and table captions, note and example counting, ordered-list schemes) across technical documentation and publishing systems. This gem implements the LADL specification MN 112 as a runtime: it parses labeling style profiles, evaluates them against a content tree, and produces the labels.
The engine is shared; flavor behavior comes entirely from profiles. The
engine ships NO bundled profiles: each flavor profile lives in its
flavor gem and each taste profile in metanorma-taste (per the release
plan, one LADL profile extraction per flavor gem / per taste), loaded
through Ladl.load_profile. The MN 112-A worked profile instance from
the specification is kept as the conformance fixture
(spec/fixtures/iso_iec_label_style.lml).
require "ladl"
profile = Ladl.iso_iec_profile
tree = Ladl::ContentElement.new(id: "doc", type: "document",
children: [
Ladl::ContentElement.new(id: "c1", type: "clause"),
Ladl::ContentElement.new(id: "ax1", type: "annex", children: [
Ladl::ContentElement.new(id: "ax1s1", type: "clause"),
]),
])
result = Ladl::Runtime::Engine.new(profile).label(tree)
result.local_for(tree.children.first) # => "Clause 1"
result.global_for(tree.children.first) # => "Clause 1"
result.local_for(tree.children.last.children.first) # => "A.1"Load a custom profile written in the MN 112 .lml instance syntax:
profile = Ladl.load_profile("my_flavor.lml")Adapt a metanorma-document presentation tree:
content = Ladl::Adapters::MetanormaDocument.wrap(mn_document_root)
result = Ladl::Runtime::Engine.new(profile).label(content)LADL models labeling over three object trees (MN 112 "Architecture"):
| Tree | Model | Role |
|---|---|---|
Content tree |
|
The elements being labeled. Provided by the host (a metanorma-document presentation tree wrapped by the adapter, or any duck-typed tree). |
Context tree |
|
Label contexts that scope labeller counters (document, clause, annex,
list), linked by |
Labeller tree |
|
Hierarchical labellers bound to contexts, linked by |
|
Parses the |
|
Groups parsed instances by base class and hydrates them into the typed
profile models through lutaml-model mappings ( |
|
The loaded style plus instance tables (labellers, contexts, templates, sequences). |
|
Wires profile references into indexes: labellers by context instance
and element type, context instances by name and parent, sequence
resolution against the registry and profile-defined sequences, and
labeller-tree ancestry for |
|
The labeling run: walks the content tree depth-first, instantiates label context instances, resolves each element’s labeller, increments counters scoped by context instance and parent element, selects label templates by condition, and renders patterns. The walk plans and counts first, then renders, so conditional templates see final sibling counts. |
|
String interpolation of |
|
The output: a |
|
The default sequences MN 112 requires of a compliant runtime (decimal, Roman, alphabetic, Cyrillic, Greek, Chinese, Japanese, Korean, Arabic, Hebrew) plus the expansion rules and arithmetic for profile-defined sequence instances. |
| MN 112 concept | Class / module |
|---|---|
Label |
|
Labeller |
|
Sequence |
|
Labeling format |
|
Label context |
|
Label context condition |
|
Label template |
|
Label style |
|
ContentElement |
|
String interpolation |
|
Runtime requirements (MN 112 "Runtime") |
|
Default sequences |
|
Value for position |
|
Algorithm to resolve the label |
|
Instance model examples (MN 112-A) |
|
-
Counter scope. A labeller’s counters live in the context instance its
contextbinds it to: notes bound toClauseContextcount per clause (across subclauses); annex figures bound toAnnexContextcount per annex; list items bound toListContextcount per list. -
Parent scoping. A labeller with a
parentlabeller additionally scopes its counter per enclosing parent element: subfigure letters restart per figure; nested ordered-list items restart per containing item. -
%pn. The parent value is the hierarchical path of the nearest enclosing element labeled by the current labeller’s ancestor chain (subclause 1.2 for 1.2.1; the annex for Figure A.1), falling back to the nearest enclosing element of the parent labeller’s type (an enclosing figure labeled by the annex figure labeller for a subfigure). -
%parent/%self. The rendered global label of the context element anchoring the labeller’s counter frame, and the element’s own local label (used inside global templates). -
Conditional templates. The first template whose condition evaluates to true wins; the first unconditional template is the fallback (MN 112 algorithm).
-
Direction.
char_direction/directionare carried on models; rendering emits logical order and relies on Unicode bidi for display.
MN 112 is a draft; the following points are ambiguous in the text and were resolved as documented. Each is testable in the suite and is a candidate for a spec ruling.
-
ArabicNumericSequence. RESOLVED 2026-11-26 by engine evidence: ISO/IEC deliverables label clauses with Western digits, so the bundled ISO/IEC and IETF profiles now bind clause numbering toDecimalNumericSequence, and the registry restoresArabicNumericSequenceto its MN 112 definition (Arabic-script numerals ١, ٢, ٣).ArabicIndicNumericSequence(the RTL example’s name in MN 112) remains as the explicit RTL-flavored spelling. -
%parentin the Japanese example. RESOLVED 2026-11-27: the ISO/IEC style templates in the bundled fixtures carried invented term words (Clause %n), which made%parentrenderClause 1instead of the pure value. MN 112 is self-consistent: the Japanese chapter template is%n(rendering 二), so%parentの%n→ 二の一 reproduces exactly, and%parent.%n→ 1.1 likewise. The fixture templates now match MN 112 (term words appear only where MN 112 writes them, as in the subfigureFigure %pn %n). -
SimpleLabelStyle template. RESOLVED 2026-11-27 together with 2: with the pure templates (
%n,%parent.%n), the stated output "1.1" reproduces exactly. -
%pnbeyond one level. RESOLVED by the spec’s own example: the MN 112 subfigure template (Figure %pn %n)→ "Figure A.1 a)") is only satisfiable when%pncarries the two-level parent path (A.1), so the engine computes%pnas the hierarchical path (parent chain values joined with.). -
Instantiation of annex clauses. The profile distinguishes annex clauses only by their enclosing annex; no context is name-matched by the clause type inside annexes. The engine instantiates the child context of the element’s labeller context (
AnnexClauseContextfor annex clauses) and falls back to name matching. -
MN 112-A profile gaps. RESOLVED 2026-11-26 by engine evidence: the current ISO engine (isodoc
annex_namesrecursion) labels annex subclauses hierarchically (A.1.1, A.1.1.1) and numbers annex notes/examples, so the profile now carriesAnnexSubclauseLabeller,AnnexNoteLabellerandAnnexExampleLabeller(bound toAnnexClauseContext). The suite covers A.1.1 and annex notes/examples end to end. -
cycle_length. RESOLVED by engine evidence: the ISO annex expansion (Annex Z → Annex AA) that isodoc implements is bijective (spreadsheet-style) decomposition, which is what the engine applies whencycle_lengthis present. -
append_suffixexpansion. The expansion result after the character set is exhausted is underdefined; the engine appends cycling suffix characters symmetrically toprepend_prefix. -
NumericSequence
formatattribute. RESOLVED: profile-defined sequence instances are supported by the profile syntax — an.lmlprofile can declare `instance X < NumericSequence { format = "decimal"-
}` (or derive from a registry sequence via
base_sequence), and the bundled registry defaults (decimal, Roman, alphabetic, …) areNumericSequenceinstances selected by theformatattribute.
-
-
char_directionvsdirection. MN 112 declares both on the sequence models; the engine carries both and treatsdirectionas taking precedence. -
Profile syntax vs lutaml-lml. MN 112 profiles use unquoted instance names with
<inheritance (instance Foo < Bar); the released LutaML grammar (lutaml-lml, RS 3001) spells inheritance as a body statement (isa Bar;) with quoted instance names. The parser now ACCEPTS BOTH SPELLINGS (2026-11-26), so a profile written in either syntax loads and labels identically; the bundled profiles keep the MN 112 spelling. Full grammar unification — extending the RS 3001 grammar with<inheritance, or amending MN 112 toisa— remains a language-level decision on the lutaml-lml side. -
Counter restart for notes in subclauses. RESOLVED 2026-11-26 by engine evidence: isodoc’s
note_anchor_names/example_anchor_namesrestart the counter for every clause and subclause (Counter.newper section;increment_labelreturns an empty label for a singleton), so ISO/IEC note numbering IS per section. The profile now carriesSubclauseNoteLabeller/SubclauseExampleLabellerbound toSubclauseContext: lone notes render "NOTE", notes continue "NOTE 1, NOTE 2" within one subclause and restart in the next, and global refs anchor at the enclosing section ("1.2, NOTE").
bundle install bundle exec rspec
Run the full test suite with bundle exec rspec. The suite covers the
.lml parser, the profile loader against the bundled ISO/IEC profile,
every default sequence, the core models, the resolver, the renderer,
the engine algorithm (counter scoping, %pn resolution, conditional
templates) and the metanorma-document adapter.