LilyPond Notation Reference: 3.3.2 Different editions from one source

### 3.3.2 Different editions from one source

Several mechanisms are available to facilitate the generation of different versions of a score from the same music source. Variables are perhaps most useful for combining lengthy sections of music and/or annotation in various ways, while tags are more useful for selecting one from several alternative shorter sections of music. Whichever method is used, separating the notation from the structure of the score will make it easier to change the structure while leaving the notation untouched.

#### Using variables

If sections of the music are defined in variables they can be reused in different parts of the score, see pieces with variables Organizing pieces with variables. For example, an a cappella vocal score frequently includes a piano reduction of the parts for rehearsal purposes which is identical to the vocal music, so the music need be entered only once. Music from two variables may be combined on one staff, see Automatic part combining. Here is an example:

>     sopranoMusic = \relative c'' { a4 b c b8( a) }
>     altoMusic = \relative g' { e4 e e f }
>     tenorMusic = \relative c' { c4 b e d8( c) }
>     bassMusic = \relative c' { a4 gis a d, }
>     allLyrics = \lyricmode {King of glo -- ry }
>     <<
>       \new Staff = "Soprano" \sopranoMusic
>       \new Lyrics \allLyrics
>       \new Staff = "Alto" \altoMusic
>       \new Lyrics \allLyrics
>       \new Staff = "Tenor" {
>         \clef "treble_8"
>         \tenorMusic
>       }
>       \new Lyrics \allLyrics
>       \new Staff = "Bass" {
>         \clef "bass"
>         \bassMusic
>       }
>       \new Lyrics \allLyrics
>       \new PianoStaff <<
>         \new Staff = "RH" {
>           \set Staff.printPartCombineTexts = ##f
>           \partcombine
>           \sopranoMusic
>           \altoMusic
>         }
>         \new Staff = "LH" {
>           \set Staff.printPartCombineTexts = ##f
>           \clef "bass"
>           \partcombine
>           \tenorMusic
>           \bassMusic
>         }
>       >>
>     >>

Separate scores showing just the vocal parts or just the piano part can be produced by changing just the structural statements, leaving the musical notation unchanged.

For lengthy scores, the variable definitions may be placed in separate files which are then included, see Including LilyPond files.

#### 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
>     }

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
>     }

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 { a4 a a a }
>       \tag #'b \tag #'both { b4 b b b }
>     }
>     <<
>     \keepWithTag #'a \music
>     \keepWithTag #'b \music
>     \keepWithTag #'both \music
>     >>

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

>     music = \relative c'' {
>     \tag #'A { a4 a a a }
>     \tag #'B { b4 b b b }
>     \tag #'C { c4 c c c }
>     \tag #'D { d4 d d d }
>     }
>     {
>     \removeWithTag #'B
>     \removeWithTag #'C
>     \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.

#### Using global settings

Global settings can be included from a separate file:

>     lilypond -dinclude-settings=MY_SETTINGS.ly MY_SCORE.ly

Groups of settings such as page size, font or type face can be stored in separate files. This allows different editions from the same score as well as standard settings to be applied to many scores, simply by specifying the proper settings file.

This technique also works well with the use of style sheets, as discussed in Style sheets.

#### See also

Learning Manual: Organizing pieces with variables, Style sheets.

Notation Reference: Including LilyPond files.

其它语言：deutsch, español, français, 日本語。

#### LilyPond — Notation Reference