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

  1. score
  2. config

Within score

  1. metadata
  2. part-list
  3. parts

Within config

  1. defaults
  2. appearance
  3. print
  4. import-detail
  5. links
  6. bookmarks

Within parts

  1. Parts in part-list order
  2. Staffs in declared order
  3. Voices in declared order
  4. Measures in score order
  5. Music-data items in canonical ordered sequence

Within a measure

  1. attributes
  2. print
  3. direction
  4. harmony
  5. figured-bass
  6. Note-like events
  7. backup
  8. forward
  9. sound
  10. listening
  11. barline
  12. grouping
  13. link
  14. bookmark

Within a note

  1. Identity or pitch/rest form
  2. Duration
  3. Voice
  4. Staff
  5. Instrument
  6. Type
  7. Dots
  8. time-modification
  9. Accidental
  10. Notehead
  11. Stem
  12. Beams
  13. Lyrics
  14. Note-level playback, print, and positioning fields
  15. Tie state
  16. Notation-related fields

Within notation-related fields

  1. tied
  2. slur
  3. tuplet
  4. glissando
  5. slide
  6. ornaments
  7. technical
  8. articulations
  9. dynamics
  10. fermata
  11. arpeggiate
  12. non-arpeggiate
  13. accidental-mark
  14. other-notation

Within attributes

  1. divisions
  2. key
  3. time
  4. staves
  5. clef
  6. transpose
  7. staff-details
  8. measure-style

Within defaults

  1. scaling
  2. concert-score
  3. page-layout
  4. system-layout
  5. staff-layout
  6. appearance
  7. music-font
  8. word-font
  9. lyric-font
  10. lyric-language

Canonical Emission Must Not

Next Steps