Canonical .pta formatting ensures consistent, deterministic source output regardless of input origin.
Required Rules
Canonical formatting MUST:
| Rule | Description |
|---|---|
| Indentation | Use two-space indentation |
| Opening braces | Place on the same line as the block header |
| One per line | Use one field or block entry per line |
| Block ordering | Preserve canonical block ordering |
| Field ordering | Preserve canonical field ordering within each object family |
| Strings | Emit with double quotes |
| Booleans | Emit as true or false |
| References | Emit as @identifier |
| Determinism | Emit the same canonical shape for semantically equivalent IR states |
| Config ordering | Preserve deterministic ordering inside config, including part and measure order within config.print |
Recommended Rules
Canonical formatting SHOULD:
| Rule | Description |
|---|---|
| Omit empty blocks | Omit semantically empty optional blocks |
| No alignment | Avoid horizontal alignment whitespace |
| Scalars first | Keep related scalar fields ahead of nested blocks when canonical ordering allows it |
| Preserve order | Preserve deterministic ordering for repeated metadata, repeated notations, and repeated measure-content families |
Example
score {
title "Example"
composer "Author"
part "Piano" {
measure 1 {
time 4/4
key c-major
clef treble
note c4 quarter
note e4 quarter
note g4 quarter
rest quarter
}
measure 2 {
note c4 half
note g4 half
}
}
}
Canonical Emission Order
Top-Level
scoreconfig
Within score
metadatapart-listparts
Within config
defaultsappearanceprintimport-detaillinksbookmarks
Within parts
- Parts in
part-listorder - Staffs in declared order
- Voices in declared order
- Measures in score order
- Music-data items in canonical ordered sequence
Within a measure
attributesprintdirectionharmonyfigured-bass- Note-like events
backupforwardsoundlisteningbarlinegroupinglinkbookmark
Within a note
- Identity or pitch/rest form
- Duration
- Voice
- Staff
- Instrument
- Type
- Dots
time-modification- Accidental
- Notehead
- Stem
- Beams
- Lyrics
- Note-level playback, print, and positioning fields
- Tie state
- Notation-related fields
Within notation-related fields
tiedslurtupletglissandoslideornamentstechnicalarticulationsdynamicsfermataarpeggiatenon-arpeggiateaccidental-markother-notation
Within attributes
divisionskeytimestavescleftransposestaff-detailsmeasure-style
Within defaults
scalingconcert-scorepage-layoutsystem-layoutstaff-layoutappearancemusic-fontword-fontlyric-fontlyric-language
Canonical Emission Must Not
- Silently remove a semantic distinction
- Collapse distinct notation roles
- Hide defaults/layout semantics because they are inconvenient to author
- Treat XML tree similarity as the correctness criterion
- Delete container-originated metadata
- Reorder score-state fields outside the canonical
attributesorder - Flatten structured content into unstructured text
- Merge
tiestate intotiednotation or vice versa - Erase numbering or identity from span-bearing notation families
Next Steps
- CLI Reference: compile — compile
.ptato MusicXML - CLI Reference: format — format
.ptain canonical style