3. LilyPond commands

>>> import abjad

LilyPond commands allow you to attach arbitrary LilyPond commands to Abjad score components.

3.1. Creating LilyPond commands

Use LilyPondCommand to create a LilyPond command:

>>> command = abjad.LilyPondCommand('bar "||"', 'after')

3.2. Understanding the interpreter representation of LilyPond commands

>>> command
LilyPondCommand('bar "||"', format_slot='after')

LilyPondCommand tells you the command’s class.

'bar "||"' tells you the LilyPond command to be formatted.

'after' tells you where the command will be formatted relative to the leaf to which it is attached.

3.3. Attaching LilyPond command to Abjad components

Use attach() to attach a LilyPond command to any Abjad component:

>>> staff = abjad.Staff()
>>> staff.extend("{ d''16 ( c''16 fs''16 g''16 ) }")
>>> staff.extend("{ f''16 ( e''16 d''16 c''16 ) }")
>>> staff.extend("{ cs''16 ( d''16 f''16 d''16 ) }")
>>> staff.extend("{ a'8 b'8 }")
>>> staff.extend("{ d''16 ( c''16 fs''16 g''16 )} ")
>>> staff.extend("{ f''16 ( e''16 d''16 c''16 ) }")
>>> staff.extend("{ cs''16 ( d''16 f''16 d''16 ) }")
>>> staff.extend("{ a'8 b'8 c''2 }")
>>> key_signature = abjad.KeySignature('f', 'major')
>>> leaf = abjad.inspect(staff).get_leaf(0)
>>> abjad.attach(key_signature, leaf)
>>> abjad.attach(command, staff[-2])
>>> show(staff)

3.4. Inspecting the LilyPond commands attached to a leaf

Use the inspector to get the LilyPond commands attached to a leaf:

>>> abjad.inspect(staff[-2]).get_indicators(abjad.LilyPondCommand)
(LilyPondCommand('bar "||"', format_slot='after'),)

3.5. Detaching LilyPond commands

Use detach() to detach LilyPond commands:

>>> abjad.detach(command, staff[-2])
(LilyPondCommand('bar "||"', format_slot='after'),)
>>> show(staff)

3.6. Getting the name of a LilyPond command

Use name to get the name of a LilyPond command:

>>> command.name
'bar "||"'

3.7. Comparing LilyPond commands

LilyPond commands compare equal with equal names. Otherwise LilyPond commands do not compare equal:

>>> command_1 = abjad.LilyPondCommand('bar "||"', 'after')
>>> command_2 = abjad.LilyPondCommand('bar "||"', 'before')
>>> command_3 = abjad.LilyPondCommand('slurUp')
>>> command_1 == command_1
True
>>> command_1 == command_2
False
>>> command_1 == command_3
False
>>> command_2 == command_1
False
>>> command_2 == command_2
True
>>> command_2 == command_3
False
>>> command_3 == command_1
False
>>> command_3 == command_2
False
>>> command_3 == command_3
True