Previous: Using variables, Up: Different editions from one source


Using tags

The \tag #'partA command marks a music expression with the name partA. Expressions tagged in this way can be selected or filtered out by name later, using either \keepWithTag #'name or \removeWithTag #'name. The result of applying these filters to tagged music is as follows:

Filter Result
Tagged music preceded by \keepWithTag #'name Untagged music and music tagged with name is included; music tagged with any other tag name is excluded.
Tagged music preceded by \removeWithTag #'name Untagged music and music tagged with any tag name other than name is included; music tagged with name is excluded.
Tagged music not preceded by either \keepWithTag or \removeWithTag All tagged and untagged music is included.

The arguments of the \tag, \keepWithTag and \removeWithTag commands should be a symbol (such as #'score or #'part), followed by a music expression.

In the following example, we see two versions of a piece of music, one showing trills with the usual notation, and one with trills explicitly expanded:

     
     music = \relative g' {
       g8. c32 d
       \tag #'trills {d8.\trill }
       \tag #'expand {\repeat unfold 3 {e32 d} }
       c32 d
      }
     
     \score {
       \keepWithTag #'trills \music
     }
     \score {
       \keepWithTag #'expand \music
     }

[image of music]

Alternatively, it is sometimes easier to exclude sections of music:

     
     music = \relative g' {
       g8. c32 d
       \tag #'trills {d8.\trill }
       \tag #'expand {\repeat unfold 3 {e32 d} }
       c32 d
      }
     
     \score {
       \removeWithTag #'expand
       \music
     }
     \score {
       \removeWithTag #'trills
       \music
     }

[image of music]

Tagged filtering can be applied to articulations, texts, etc. by prepending

-\tag #'your-tag

to an articulation. For example, this would define a note with a conditional fingering indication and a note with a conditional annotation:

c1-\tag #'finger ^4
c1-\tag #'warn ^"Watch!"

Multiple tags may be placed on expressions with multiple \tag entries:

     
     music = \relative c'' {
       \tag #'a \tag #'both { a a a a }
       \tag #'b \tag #'both { b b b b }
     }
     <<
     \keepWithTag #'a \music
     \keepWithTag #'b \music
     \keepWithTag #'both \music
     >>

[image of music]

Multiple \removeWithTag filters may be applied to a single music expression to remove several differently named tagged sections:

     
     music = \relative c'' {
     \tag #'A { a a a a }
     \tag #'B { b b b b }
     \tag #'C { c c c c }
     \tag #'D { d d d d }
     }
     {
     \removeWithTag #'B
     \removeWithTag #'C
     \music
     }

[image of music]

Two or more \keepWithTag filters applied to a single music expression will cause all tagged sections to be removed, as the first filter will remove all tagged sections except the one named, and the second filter will remove even that tagged section.

See also

Learning Manual: Organizing pieces with variables.

Notation Reference: Automatic part combining, Including LilyPond files.

This page is for LilyPond-2.11.58 (development-branch).

Report errors to http://post.gmane.org/post.php?group=gmane.comp.gnu.lilypond.bugs.

Your suggestions for the documentation are welcome.

Other languages: français, deutsch.