MarkupCommand

class markuptools.MarkupCommand(name=None, *arguments)

LilyPond markup command.

>>> import abjad

Initializes a complex LilyPond markup command:

>>> circle = abjad.MarkupCommand('draw-circle', 2.5, 0.1, False)
>>> square = abjad.MarkupCommand('rounded-box', 'hello?')
>>> line = abjad.MarkupCommand('line', [square, 'wow!'])
>>> rotate = abjad.MarkupCommand('rotate', 60, line)
>>> combine = abjad.MarkupCommand('combine', rotate, circle)
>>> print(format(combine, 'lilypond'))
\combine
    \rotate
        #60
        \line
            {
                \rounded-box
                    hello?
                wow!
            }
    \draw-circle
        #2.5
        #0.1
        ##f
>>> note = abjad.Note("c'4")
>>> markup = abjad.Markup(combine)
>>> abjad.attach(markup, note)
>>> show(note) 

Works with the LilyPond \score markup command:

>>> small_staff = abjad.Staff("fs'16 gs'16 as'16 b'16")
>>> small_staff.remove_commands.append('Clef_engraver')
>>> small_staff.remove_commands.append('Time_signature_engraver')
>>> abjad.setting(small_staff).font_size = -3
>>> layout_block = abjad.lilypondfiletools.Block(name='layout')
>>> layout_block.indent = 0
>>> layout_block.ragged_right = True
>>> command = abjad.MarkupCommand(
...     'score',
...     [small_staff, layout_block],
...     )
>>> f(command)
\score
    {
        \new Staff \with {
            \remove Clef_engraver
            \remove Time_signature_engraver
            fontSize = #-3
        } {
            fs'16
            gs'16
            as'16
            b'16
        }
        \layout {
            indent = #0
            ragged-right = ##t
        }
    }
>>> markup = abjad.Markup(contents=command, direction=Up)
>>> staff = abjad.Staff("c'4 d'4 e'4 f'4")
>>> abjad.attach(markup, staff[0])
>>> show(staff) 

Lineage

digraph InheritanceGraph { graph [background=transparent, bgcolor=transparent, color=lightslategrey, fontname=Arial, outputorder=edgesfirst, overlap=prism, penwidth=2, rankdir=LR, root="__builtin__.object", splines=spline, style="dotted, rounded", truecolor=true]; node [colorscheme=pastel19, fontname=Arial, fontsize=12, penwidth=2, style="filled, rounded"]; edge [color=lightsteelblue2, penwidth=2]; subgraph cluster_abctools { graph [label=abctools]; "abjad.tools.abctools.AbjadObject.AbjadObject" [color=1, group=0, label=AbjadObject, shape=box]; "abjad.tools.abctools.AbjadObject.AbstractBase" [color=1, group=0, label=AbstractBase, shape=box]; "abjad.tools.abctools.AbjadValueObject.AbjadValueObject" [color=1, group=0, label=AbjadValueObject, shape=box]; "abjad.tools.abctools.AbjadObject.AbjadObject" -> "abjad.tools.abctools.AbjadValueObject.AbjadValueObject"; "abjad.tools.abctools.AbjadObject.AbstractBase" -> "abjad.tools.abctools.AbjadObject.AbjadObject"; } subgraph cluster_markuptools { graph [label=markuptools]; "abjad.tools.markuptools.MarkupCommand.MarkupCommand" [color=black, fontcolor=white, group=2, label=<<B>MarkupCommand</B>>, shape=box, style="filled, rounded"]; } subgraph cluster_builtins { graph [label=builtins]; "builtins.object" [color=2, group=1, label=object, shape=box]; } "abjad.tools.abctools.AbjadValueObject.AbjadValueObject" -> "abjad.tools.markuptools.MarkupCommand.MarkupCommand"; "builtins.object" -> "abjad.tools.abctools.AbjadObject.AbstractBase"; }

Bases

Attribute summary

arguments Gets markup command arguments.
combine_markup_commands(*commands) Combines markup command and / or strings.
force_quotes Is true when markup command should force quotes around arguments.
name Gets markup command name.
__copy__(*arguments) Copies Abjad value object.
__eq__(argument) Is true when argument is a markup command with command and arguments equal to those of this markup command.
__format__([format_specification]) Formats markup command.
__hash__() Hashes markup command.
__ne__(argument) Is true when Abjad object does not equal argument.
__repr__() Gets markup command interpreter representation.
__str__() Gets string representation of markup command.

Read-only properties

MarkupCommand.arguments

Gets markup command arguments.

>>> arguments = ('draw-circle', 1, 0.1, False)
>>> command = abjad.MarkupCommand(*arguments)
>>> command.arguments
(1, 0.1, False)

Returns tuple.

MarkupCommand.name

Gets markup command name.

>>> arguments = ('draw-circle', 1, 0.1, False)
>>> command = abjad.MarkupCommand(*arguments)
>>> command.name
'draw-circle'

Returns string.

Read/write properties

MarkupCommand.force_quotes

Is true when markup command should force quotes around arguments. Otherwise false.

Here’s a markup command formatted in the usual way without forced quotes:

>>> lines = ['foo', 'bar blah', 'baz']
>>> command = abjad.MarkupCommand('column', lines)
>>> markup = abjad.Markup(command)
>>> f(markup)
\markup {
    \column
        {
            foo
            "bar blah"
            baz
        }
    }

The markup command forces quotes around only the spaced string 'bar blah'.

Here’s the same markup command with forced quotes:

>>> lines = ['foo', 'bar blah', 'baz']
>>> command = abjad.MarkupCommand('column', lines)
>>> command.force_quotes = True
>>> markup = abjad.Markup(command)
>>> f(markup)
\markup {
    \column
        {
            "foo"
            "bar blah"
            "baz"
        }
    }

The markup command forces quotes around all strings.

The rendered result of forced and unforced quotes is the same.

Defaults to false.

Returns true or false.

Class & static methods

static MarkupCommand.combine_markup_commands(*commands)

Combines markup command and / or strings.

LilyPond’s ‘combine’ markup command can only take two arguments, so in order to combine more than two stencils, a cascade of ‘combine’ commands must be employed. combine_markup_commands simplifies this process.

>>> markup_a = abjad.MarkupCommand(
...     'draw-circle',
...     4,
...     0.4,
...     False,
...     )
>>> markup_b = abjad.MarkupCommand(
...     'filled-box',
...     abjad.SchemePair((-4, 4)),
...     abjad.SchemePair((-0.5, 0.5)),
...     1,
...     )
>>> markup_c = "some text"
>>> markup = abjad.MarkupCommand.combine_markup_commands(
...     markup_a,
...     markup_b,
...     markup_c,
...     )
>>> result = format(markup, 'lilypond')
>>> print(result)
\combine
    \combine
        \draw-circle
            #4
            #0.4
            ##f
        \filled-box
            #'(-4 . 4)
            #'(-0.5 . 0.5)
            #1
    "some text"

Returns a markup command instance, or a string if that was the only argument.

Special methods

(AbjadValueObject).__copy__(*arguments)

Copies Abjad value object.

Returns new Abjad value object.

MarkupCommand.__eq__(argument)

Is true when argument is a markup command with command and arguments equal to those of this markup command. Otherwise false.

>>> command_1 = abjad.MarkupCommand('box')
>>> command_2 = abjad.MarkupCommand('box')
>>> command_3 = abjad.MarkupCommand('line')
>>> command_1 == command_1
True
>>> command_1 == command_2
True
>>> command_1 == command_3
False
>>> command_2 == command_1
True
>>> 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

Returns true or false.

MarkupCommand.__format__(format_specification='')

Formats markup command.

Prints storage format:

>>> circle = abjad.MarkupCommand('draw-circle', 2.5, 0.1, False)
>>> square = abjad.MarkupCommand('rounded-box', 'hello?')
>>> line = abjad.MarkupCommand('line', [square, 'wow!'])
>>> rotate = abjad.MarkupCommand('rotate', 60, line)
>>> combine = abjad.MarkupCommand('combine', rotate, circle)
>>> print(format(combine, 'storage'))
abjad.MarkupCommand(
    'combine',
    abjad.MarkupCommand(
        'rotate',
        60,
        abjad.MarkupCommand(
            'line',
            [
                abjad.MarkupCommand(
                    'rounded-box',
                    'hello?'
                    ),
                'wow!',
                ]
            )
        ),
    abjad.MarkupCommand(
        'draw-circle',
        2.5,
        0.1,
        False
        )
    )

Prints LilyPond format:

>>> circle = abjad.MarkupCommand('draw-circle', 2.5, 0.1, False)
>>> square = abjad.MarkupCommand('rounded-box', 'hello?')
>>> line = abjad.MarkupCommand('line', [square, 'wow!'])
>>> rotate = abjad.MarkupCommand('rotate', 60, line)
>>> combine = abjad.MarkupCommand('combine', rotate, circle)
>>> print(format(combine, 'lilypond'))
\combine
    \rotate
        #60
        \line
            {
                \rounded-box
                    hello?
                wow!
            }
    \draw-circle
        #2.5
        #0.1
        ##f

Set format_specification to ‘’, ‘lilypond’ or ‘storage’. Interprets ‘’ equal to ‘storage’.

Returns string.

MarkupCommand.__hash__()

Hashes markup command.

Required to be explicitly redefined on Python 3 if __eq__ changes.

Returns integer.

(AbjadObject).__ne__(argument)

Is true when Abjad object does not equal argument. Otherwise false.

Returns true or false.

MarkupCommand.__repr__()

Gets markup command interpreter representation.

Interpreter representation is evaluable.

>>> command = abjad.MarkupCommand('hspace', 0)
>>> command
abjad.MarkupCommand(
    'hspace',
    0
    )
>>> eval(repr(command))
abjad.MarkupCommand(
    'hspace',
    0
    )

Returns string.

MarkupCommand.__str__()

Gets string representation of markup command.

>>> circle = abjad.MarkupCommand('draw-circle', 2.5, 0.1, False)
>>> square = abjad.MarkupCommand('rounded-box', 'hello?')
>>> line = abjad.MarkupCommand('line', [square, 'wow!'])
>>> rotate = abjad.MarkupCommand('rotate', 60, line)
>>> combine = abjad.MarkupCommand('combine', rotate, circle)
>>> print(str(combine))
\combine
    \rotate
        #60
        \line
            {
                \rounded-box
                    hello?
                wow!
            }
    \draw-circle
        #2.5
        #0.1
        ##f

Returns string.