On Fri 24 Nov 2023 at 16:23:52 (+0200), YTG 123 wrote:
> 
> I have alternative versions of lyrics text, which I would like to
> export in different files (or \book blocks). The music, order of
> staves, etc. is identical.
> 
> Ideally, I would want to do this as cleanly and with as little code
> duplication as possible.

Perhaps an easy way to do this is as in the attached files.

Place all the lyrics for one version in one file (o-sing.ily),
using different variable names for all the different sections,
books etc in the piece. (I've just used the voice names for brevity.)

Now write a corresponding file (sing-ye.ily) with the alternative
lyrics, but using all the same corresponding variable names.

Merely include the appropriate lyrics filename in the master file
to produce the appropriate output file(s).

This method uses one simple modification of the master file to
change all the lyrics in all the output files (by removing the
%% in my master file example).

If even that amount of modification of source files is not possible,
then you can instead use the same filename for the two versions
of the lyrics, but place them in two different directories (and
also a different directory from the master file). Then select
which lyrics file is included in the run by using an appropriate
--include=<directoryname> in the LilyPond command line.

Cheers,
David.
sopranotext = \lyricmode {
  O sing joy -- ful -- ly,
}
altotext = \lyricmode {
  O sing joy -- ful -- ly,
}
tenortext = \lyricmode {
  O sing joy -- ful -- ly,
}
basstext = \lyricmode {
  O sing joy -- ful -- ly,
}
sopranotext = \lyricmode {
  Sing ye joy -- ful -- ly,
}
altotext = \lyricmode {
  Sing ye joy -- ful -- ly,
}
tenortext = \lyricmode {
  Sing ye joy -- ful -- ly,
}
basstext = \lyricmode {
  Sing ye joy -- ful -- ly,
}
\language english
\include "o-sing.ily"
%%\include "sing-ye.ily"

global = {
  \key af \major
  \time 3/4
  s2. * 2
}
soprano = \relative {
  af'2 af4
  af4. af8 af4
}
alto = \relative {
  ef'2 ef4
  f4. f8 ef4
}
tenor = \relative {
  c'2 c4
  df4. df8 ef4
}
bass = \relative {
  af2 af4
  df,4. df8 c4
}

\book {
  \bookOutputSuffix "choir"
  \score {
    \new ChoirStaff <<
      \new Staff <<
        \clef treble \global
        \new Voice { \soprano }
        \addlyrics { \sopranotext }
      >>
      \new Staff <<
        \clef treble \global
        \new Voice { \alto }
        \addlyrics { \altotext }
      >>
      \new Staff <<
        \clef "treble_8" \global
        \new Voice { \tenor }
        \addlyrics { \tenortext }
      >>
      \new Staff <<
        \clef bass \global
        \new Voice { \bass }
        \addlyrics { \basstext }
      >>
    >>
    \layout { }
  }
}

\book {
  \bookOutputSuffix "piano"
  \score {
    \new PianoStaff <<
      \new Staff = up <<
        \clef treble \global
        \new Voice { \voiceOne \soprano }
        \addlyrics \with { alignAboveContext = up } { \sopranotext }
        \new Voice { \voiceTwo \alto }
      >>
      \new Staff <<
        \clef bass \global
        \new Voice { \voiceOne \tenor }
        \new Voice { \voiceTwo \bass }
        \addlyrics { \basstext }
      >>
    >>
    \layout { }
  }
}

Reply via email to