# Complex beam in Lilypond

I'm trying to reproduce a scanned score with Lilypond. The original (the part of interest, at least), looks like this :

My Lilypond code is the following (I put the crescendo in the upper staff) :

%%%%%%%%%%
%% VERSION
%%%%%%%%%%

\version "2.20.0.3"

%%%%%%%%%
%% LYRICS
%%%%%%%%%

singerLyrics = \lyricmode {
%   Ah! |
}

%%%%%%%%%%%
%% PIANO UP
%%%%%%%%%%%

pianoUpper = \relative c' {
\clef "treble"
\time 6/8
\key c \major

<f d'>4( <f d'>8 << {<g b>4[ f8} {f'8. d16 b8]}) >> |
}

%%%%%%%%%%%%
%% PIANO LOW
%%%%%%%%%%%%

pianoLower = \relative c {
\clef "bass"
\time 6/8
\key c \major

g <f' g b> <f g b> g, <f' g b> <f g b> |
}

%%%%%%%%
%% SCORE
%%%%%%%%

\score {
<<
\new PianoStaff <<
\new Staff = "upper" {\new Voice = "singer" \pianoUpper}
\new Lyrics \lyricsto singer \singerLyrics
\new Staff = "lower" \pianoLower
>>
>>
}

And it produces the following result :

Which is upsetting, because I obviously don't want the beam to look like that.

Has someone an idea of how I can make the beam look better, like on my original scanned score?

• I can’t answer your question since I don’t know Lilypond but is there a way you can create 2 independent voices in the treble clef? I think that would do it. – John Belzaguy Apr 19 at 3:02

## 2 Answers

You need to replace the << ... >> construct with this:

<< { f'8. d16 <a f>8 } \\ { <g b>4 s8 } >>. Here's a lilybin1 where I did that for you: http://lilybin.com/jslb5y/1 (plus I wrapped the rest of the line into the construct to make the ties work).

The reason is simple: first of all, you used << {...} {...} >>, which does not make two independent voices, but pastes the contents of the two braces together. The condition is that both need to have the same rhythm (if they don't, weird stuff happens). So it's not what you would primarily want to use. I use it only when I need to write a lot of chords that have many repeating notes, like in this lilybin: http://lilybin.com/8dc2z0/1 .

What you want to use is the construct << { ... } \\ { ... } >> (notice the two backslashes). That temporarily splits up the music into two different voices. The first brace is treated as \voiceOne and the second one as \voiceTwo, the settings like \stemUp or \tieDown do not transfer from outside to inside of this construct, and very importantly, you cannot have a tie/slur/beam starting outside and ending inside.

1 Lilybin is a web app that makes it possible to share Lilypond snippets. It compiles them and shows the resulting score. You can also edit the code as you want and compile again and again, so you can experiment more with the snippets.

• Thank you for your answer. I am new at Lilypond, so I learnt a few useful things; very much appreciated. One question, though : in general, if I ask a question about engraving with Lilypond here, is it better to show the results of my .ly in a lilybin, or is a screenshot just fine? – JambonSama Apr 19 at 11:49
• @JambonSama: You're welcome. I think it doesn't matter, do what is more comfortable for you. There have been good Lilypond questions with both. – Ramillies Apr 19 at 14:52
• I actually stumbled upon the documentation (lilypond.org/doc/v2.18/Documentation/notation/multiple-voices) relevant to my original question looking for something else, and I learnt a valuable info in the process. When entering multiple voices, they should be in the following order: Voice 1: highest Voice 2: lowest Voice 3: second highest Voice 4: second lowest Voice 5: third highest Voice 6: third lowest etc. because it simplifies the automatic layout process. The odd-numbered voices are given upstems, and the even-numbered voices are given downstems. – JambonSama Apr 29 at 0:22
• @JambonSama, that is certainly true. That's what you get if you use commands \voiceOne, \voiceTwo, and so on up to \voiceSix. And the construct << { } \\ { } \\ ... \\ { } >> automatically adds \voiceOne to the first braces, \voiceTwo to the second, and so on. (Sometimes it's not what you want; I typeset a lot of guitar scores with a lot of voices on the same staff and then, if I use this construct, it automatically generates a \voiceTwo which clashes with my basses that were the \voiceTwo for the whole piece.) – Ramillies Apr 29 at 7:06

Here's how I did it:

\version "2.18.2"
\include "english.ly"

global =
{
\time 6/8
}

pianoUpper =
{
<< {
<f'd''>4\( q8 f''8. d''16 <f'b'>8\)
} \\ {
s4. <g'b'>
} >>
}

dyn = { p4.\< s4 s8\! }

pianoLower = { \clef bass g,8 <f g b> q g, q q }

\score
{
\new PianoStaff
{
<<
\new Staff << \global \pianoUpper >>
\new Dynamics \dyn
\new Staff << \global \pianoLower >>
>>
}
\layout {}
}

I used Lilypond's << ... \\ ... >> construct to get the upper and lower voices in the upper stave. Even though all the notes in the first half of the bar in the upper stave had their stems going up, so that was not a reason to put them in the two-voice construct, I put them in the upper voice of this two-voice construct anyway, so that the phrasing slur would belong to that upper voice. (A slur or phrasing slur doesn't work if it starts in one voice and ends in another.)