Hi,

On Fri, Nov 24, 2023 at 9:25 AM YTG 123 <ytg1234.pm...@gmail.com> wrote:

> Hello,
>
> 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.
>

I do something a bit like this on a regular basis - generating multiple
versions from the same music. In my case, instead of doing different lyrics
I'm doing some instrument specific formatting and such. But the basic idea
is pretty similar. Perhaps something like this?

\version "2.25.10"

music = { c'4 d' e' }
lyricsOne = \lyricmode { do re mi }
lyricsTwo = \lyricmode { a b c }

% Header info common to all versions
main_header =
\header {
  title = "Main Title"
  composer = "Written by Foo Bar"
}

% Here is the main body of the score, so we can call it as needed
main_score = <<
  \new Staff {
    \new Voice = "VOne" {
      \music
    }
  }
  \tag #'(showLyricsOne) {
    \new Lyrics  \lyricsto "VOne" {
      \lyricsOne
    }
  }
  \tag #'(showLyricsTwo) {
    \new Lyrics  \lyricsto "VOne" {
      \lyricsTwo
    }
  }
>>

% With what I usually do everything from here down is in a separate file,
that includes in everything above

\book {
  \paper {
    output-suffix = "both_lyrics"
  }
  \header {
    pdftitle = "Song Title - Both Lyrics"
    subtitle = "Both Lyrics"
  }
  \main_header
  \score {
    \main_score
    \layout {
      % As needed
    }
  }
}

\book {
  \paper {
    output-suffix = "first_lyrics"
  }
  \header {
    pdftitle = "Song Title - First Lyrics"
    subtitle = "First Lyrics"
  }
  \main_header
  \score {
    \keepWithTag #'showLyricsOne
    %\removeWithTag #'showLyricsTwo
    \main_score
    \layout {
      % As needed
    }
  }
}

\book {
  \paper {
    output-suffix = "second_lyrics"
  }
  \header {
    pdftitle = "Song Title - Second Lyrics"
    subtitle = "Second Lyrics"
  }
  \main_header
  \score {
    \keepWithTag #'showLyricsTwo
    %\removeWithTag #'showLyricsOne
    \main_score
    \layout {
      % As needed
    }
  }
}

As a source file named example1.ly this produces 3 PDFs:
example1-both_lyrics.pdf, example1-first_lyrics.pdf and
example1-second_lyrics.pdf
http://lilypond.org/doc/v2.25/Documentation/notation/output-file-names
goes over how to control the output file names.

Using pdftitle in a \header block to set the displayed PDF title gets
covered in
http://lilypond.org/doc/v2.25/Documentation/notation/creating-output-file-metadata

In this example I'm using tags to control which lyrics get shown when.
There are 2 ways to use them: \keepWithTag and \removeWithTag  Details on
how they both get used are in
http://lilypond.org/doc/v2.25/Documentation/notation/using-tags
Short version: \keepWithTag keeps music with that tag and untagged music,
while \removeWithTag keeps everything but the music with the selected tag.
There's more to it than that - especially if you get into using multiple
tags at the same time. But this example is simple enough that it could work
either way - swap the two commented tag commands in each score to try it
out, and you'll see that the output is the same.
-- 
Michael

Reply via email to