tag

digraph InheritanceGraph { graph [bgcolor=transparent, color=lightsteelblue2, fontname=Arial, fontsize=10, outputorder=edgesfirst, overlap=prism, penwidth=2, rankdir=LR, splines=spline, style="dashed, rounded", truecolor=true]; node [colorscheme=pastel19, fontname=Arial, fontsize=10, height=0, penwidth=2, shape=box, style="filled, rounded", width=0]; edge [color=lightslategrey, penwidth=1]; subgraph "cluster_abjad.tag" { graph [label="abjad.tag"]; node [color=1]; "abjad.tag.Tag" [URL="../api/abjad/tag.html#abjad.tag.Tag", color=black, fontcolor=white, label=Tag, target=_top]; } subgraph cluster_builtins { graph [label=builtins]; node [color=2]; "builtins.object" [URL="https://docs.python.org/3.10/library/functions.html#object", label=object, target=_top]; } "builtins.object" -> "abjad.tag.Tag"; }


Classes

Tag

Tag.

class abjad.tag.Tag(string='')[source]

Tag.

>>> abjad.Tag("YELLOW")
Tag(string='YELLOW')
>>> abjad.Tag("YELLOW:RED")
Tag(string='YELLOW:RED')

Raises exception on duplicate words in tag:

>>> abjad.Tag("YELLOW:RED:RED")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<string>", line 4, in __init__
  File "/Users/trevor/abjad/abjad/tag.py", line 49, in __post_init__
    self.words()
  File "/Users/trevor/abjad/abjad/tag.py", line 196, in words
    raise Exception(f"duplicate words in tag: {self.string!r}")
Exception: duplicate words in tag: 'YELLOW:RED:RED'

Raises exception on multiple only-edition tags:

>>> abjad.Tag("+SEGMENT:+PARTS")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<string>", line 4, in __init__
  File "/Users/trevor/abjad/abjad/tag.py", line 49, in __post_init__
    self.words()
  File "/Users/trevor/abjad/abjad/tag.py", line 205, in words
    raise Exception(f"at most one only-edition tag: {only_edition_tags!r}.")
Exception: at most one only-edition tag: ['+SEGMENT', '+PARTS'].

Raises exception on mixed only-edition / not-edition tags:

>>> abjad.Tag("+SEGMENT:-PARTS")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<string>", line 4, in __init__
  File "/Users/trevor/abjad/abjad/tag.py", line 49, in __post_init__
    self.words()
  File "/Users/trevor/abjad/abjad/tag.py", line 209, in words
    raise Exception(message)
Exception: only-edition and not-edition forbidden in same tag:

  ['+SEGMENT'] / ['-PARTS']

Attributes Summary

__delattr__

Implement delattr(self, name).

__eq__

Return self==value.

__ge__

Return self>=value.

__gt__

Return self>value.

__hash__

Return hash(self).

__le__

Return self<=value.

__lt__

Return self<value.

__post_init__

__repr__

Return repr(self).

__setattr__

Implement setattr(self, name, value).

append

Appends word to tag.

editions

Gets edition tags in tag.

invert_edition_tags

Inverts edition tags in tag.

not_editions

Gets not-edition tags in tag.

only_edition

Gets only-edition tag in tag.

words

Gets words.


Special methods

overridden __delattr__(name)

Implement delattr(self, name).

overridden __eq__(other)

Return self==value.

overridden __ge__(other)

Return self>=value.

overridden __gt__(other)

Return self>value.

overridden __hash__()

Return hash(self).

overridden __le__(other)

Return self<=value.

overridden __lt__(other)

Return self<value.

__post_init__()[source]
overridden __repr__()

Return repr(self).

overridden __setattr__(name, value)

Implement setattr(self, name, value).


Methods

append(word)[source]

Appends word to tag.

>>> abjad.Tag("-PARTS").append(abjad.Tag("DEFAULT_CLEF"))
Tag(string='-PARTS:DEFAULT_CLEF')
Return type:

Tag

editions()[source]

Gets edition tags in tag.

>>> abjad.Tag("FOO").editions()
[]
>>> abjad.Tag("+SEGMENT").only_edition()
Tag(string='+SEGMENT')
>>> abjad.Tag("+SEGMENT:FOO").only_edition()
Tag(string='+SEGMENT')
>>> abjad.Tag("-SEGMENT").editions()
[Tag(string='-SEGMENT')]
>>> abjad.Tag("-SEGMENT:FOO").editions()
[Tag(string='-SEGMENT')]
>>> abjad.Tag("-SEGMENT:-PARTS").editions()
[Tag(string='-SEGMENT'), Tag(string='-PARTS')]
Return type:

list[Tag]

invert_edition_tags()[source]

Inverts edition tags in tag.

>>> abjad.Tag("FOO").invert_edition_tags()
Tag(string='FOO')
>>> abjad.Tag("FOO:-PARTS").invert_edition_tags()
Tag(string='FOO:+PARTS')
>>> abjad.Tag("FOO:+PARTS").invert_edition_tags()
Tag(string='FOO:-PARTS')
Return type:

Tag

not_editions()[source]

Gets not-edition tags in tag.

>>> abjad.Tag("FOO").not_editions()
[]
>>> abjad.Tag("-SEGMENT").not_editions()
[Tag(string='-SEGMENT')]
>>> abjad.Tag("-SEGMENT:FOO").not_editions()
[Tag(string='-SEGMENT')]
>>> abjad.Tag("-SEGMENT:-PARTS").not_editions()
[Tag(string='-SEGMENT'), Tag(string='-PARTS')]
Return type:

list[Tag]

only_edition()[source]

Gets only-edition tag in tag.

>>> abjad.Tag("FOO").only_edition() is None
True
>>> abjad.Tag("+SEGMENT").only_edition()
Tag(string='+SEGMENT')
>>> abjad.Tag("+SEGMENT:FOO").only_edition()
Tag(string='+SEGMENT')
Return type:

Optional[Tag]

words()[source]

Gets words.

>>> abjad.Tag("-PARTS:DEFAULT_CLEF").words()
['-PARTS', 'DEFAULT_CLEF']
Return type:

list[str]


Functions

activate

Activates tag in text.

deactivate

Deactivates tag in text.

double_tag

Double tags strings.

left_shift_tags

Left shifts tags in strings.

remove_tags

Removes all tags from string.

abjad.tag.activate(text, tag)[source]

Activates tag in text.

Writes (deactivated) tag with "%@%" prefix into LilyPond input:

>>> staff = abjad.Staff("c'4 d' e' f'")
>>> markup = abjad.Markup(r"\markup { \with-color #red Allegro }")
>>> abjad.attach(
...     markup,
...     staff[0],
...     deactivate=True,
...     tag=abjad.Tag("RED_MARKUP"),
... )
>>> text = abjad.lilypond(staff, tags=True)
>>> text = abjad.tag.left_shift_tags(text)
>>> print(text)
\new Staff
{
    c'4
      %! RED_MARKUP
    %@% - \markup { \with-color #red Allegro }
    d'4
    e'4
    f'4
}
>>> abjad.show(staff)  

Activates tag:

>>> text, count, skipped = abjad.activate(text, abjad.Tag("RED_MARKUP"))
>>> print(text)
\new Staff
{
    c'4
      %! RED_MARKUP
    - \markup { \with-color #red Allegro } %@%
    d'4
    e'4
    f'4
}
>>> lines = [_.strip("\n") for _ in text.split("\n")]
>>> string = "\n".join(lines)
>>> lilypond_file = abjad.LilyPondFile([string])
>>> abjad.show(lilypond_file)  

Deactivates tag again:

>>> text, count, skipped = abjad.deactivate(text, abjad.Tag("RED_MARKUP"))
>>> print(text)
\new Staff
{
    c'4
      %! RED_MARKUP
    %@% - \markup { \with-color #red Allegro }
    d'4
    e'4
    f'4
}
>>> lines = [_.strip("\n") for _ in text.split("\n")]
>>> string = "\n".join(lines)
>>> lilypond_file = abjad.LilyPondFile([string])
>>> abjad.show(lilypond_file)  

Activates tag again:

>>> text, count, skipped = abjad.activate(text, abjad.Tag("RED_MARKUP"))
>>> print(text)
\new Staff
{
    c'4
      %! RED_MARKUP
    - \markup { \with-color #red Allegro } %@%
    d'4
    e'4
    f'4
}
>>> lines = [_.strip("\n") for _ in text.split("\n")]
>>> string = "\n".join(lines)
>>> lilypond_file = abjad.LilyPondFile([string])
>>> abjad.show(lilypond_file)  

Tags can toggle indefinitely.

Returns (text, count, skipped) triple.

Count gives number of activated tags.

Skipped gives number of skipped tags.

Return type:

tuple[str, int, int]

abjad.tag.deactivate(text, tag, prepend_empty_chord=False)[source]

Deactivates tag in text.

Writes (active) tag into LilyPond input:

>>> staff = abjad.Staff("c'4 d' e' f'")
>>> string = r"\markup { \with-color #red Allegro }"
>>> markup = abjad.Markup(string)
>>> abjad.attach(
...     markup,
...     staff[0],
...     tag=abjad.Tag("RED_MARKUP"),
... )
>>> text = abjad.lilypond(staff, tags=True)
>>> text = abjad.tag.left_shift_tags(text)
>>> print(text)
\new Staff
{
    c'4
      %! RED_MARKUP
    - \markup { \with-color #red Allegro }
    d'4
    e'4
    f'4
}
>>> abjad.show(staff)  

Deactivates tag:

>>> text = abjad.lilypond(staff, tags=True)
>>> text, count, skipped = abjad.deactivate(text, abjad.Tag("RED_MARKUP"))
>>> print(text)
\new Staff
{
    c'4
      %! RED_MARKUP
%%% - \markup { \with-color #red Allegro }
    d'4
    e'4
    f'4
}
>>> lines = [_.strip("\n") for _ in text.split("\n")]
>>> string = "\n".join(lines)
>>> lilypond_file = abjad.LilyPondFile([string])
>>> abjad.show(lilypond_file)  

Activates tag again:

>>> text, count, skipped = abjad.activate(text, abjad.Tag("RED_MARKUP"))
>>> print(text)
\new Staff
{
    c'4
      %! RED_MARKUP
    - \markup { \with-color #red Allegro }
    d'4
    e'4
    f'4
}
>>> lines = [_.strip("\n") for _ in text.split("\n")]
>>> string = "\n".join(lines)
>>> lilypond_file = abjad.LilyPondFile([string])
>>> abjad.show(lilypond_file)  

Deactivates tag again:

>>> text, count, skipped = abjad.deactivate(text, abjad.Tag("RED_MARKUP"))
>>> print(text)
\new Staff
{
    c'4
      %! RED_MARKUP
%%% - \markup { \with-color #red Allegro }
    d'4
    e'4
    f'4
}
>>> lines = [_.strip("\n") for _ in text.split("\n")]
>>> string = "\n".join(lines)
>>> lilypond_file = abjad.LilyPondFile([string])
>>> abjad.show(lilypond_file)  

Tags can toggle indefinitely.

Return type:

tuple[str, int, int]

abjad.tag.double_tag(strings, tag_, deactivate=False)[source]

Double tags strings.

Return type:

list[str]

abjad.tag.left_shift_tags(text)[source]

Left shifts tags in strings.

Return type:

str

abjad.tag.remove_tags(string)[source]

Removes all tags from string.

Return type:

str