# Unmatched pairs for lilypond ties and slurs

In lilypond, ties and slurs are expected to come in matched pairs. I keep coming across situations where a tie or a slur aren't matched. For example:

• As demonstrated in the MWE below, it is possible to have a tied note that goes into a coda (or repeat or some other form of musical jumping) but in lilypond the ~ form of the tie can't be added to the first note in the coda because it is separated from it's initiating note by line breaks and additional notes
• It actually surprises me that musical redirections like coda and segno aren't environments like the \repeat volta n {} \alternative{{}{}} setup but that's neither here nor there, I simply bring it up in case I'm wrong and there actually is an environment for coda's and segno notation and jumping.
• I frequently use a lilypond-book compile to produce only one or two bars to include in a document, and I may want an a tie or slur to be implicitly started, but I only care about presenting the bar in question following the tie or slur marking.

I know lilypond is designed more for typesetting than understanding flow, but can I force lilypond to print a tie or a slur without having an original note in mind?

\version "2.18.2"
{
\relative c'' \repeat unfold 2 {
c4 c c c~
}

% Set coda sign as rehearsal mark and adjust size if needed
\once \override Score.RehearsalMark.font-size = #4
\mark \markup { \musicglyph #"scripts.coda" }
\relative c'' \repeat unfold 2 {
c4 c c c
}

\break

\once \override Score.RehearsalMark.extra-offset = #'( -4.5 . 0 )

\once \override Score.RehearsalMark.font-size = #5
\mark \markup { \musicglyph #"scripts.coda" }

% The coda
\relative c'' \repeat unfold 5 {
~c4 c c c
}
\bar"|."
}


To get this MWE to successfully compile, all that is needed is to remove the ~ infront of the last c4 in the final unfold environment.

(I'm a little puzzled why I can't get my stack exchange code indenting to work, it's just toggling, but perhaps it's just a temporary glitch.)

Turns out Lilypond has a command to add tied notes that may be unmatched due to codas or repeat signs:

If you follow the tied note that is other wise unable to be connected with the tie-initiator with the command \repeatTie, the tie shows up in the right place.

I thought there would have been a more general environment style solution so while this works for ties, I haven't yet found an equivalent solution for the slurs.

It took me a while to figure out that \repeatTie has to follow, not precede, the note you wish to connect.

\version "2.18.2"
{
\relative c'' \repeat unfold 2 {
c4 c c c~
}

% Set coda sign as rehearsal mark and adjust size if needed
\once \override Score.RehearsalMark.font-size = #4
\mark \markup { \musicglyph #"scripts.coda" }
\relative c'' \repeat unfold 2 {
c4 c c c
}

\break

\once \override Score.RehearsalMark.extra-offset = #'( -4.5 . 0 )

\once \override Score.RehearsalMark.font-size = #5
\mark \markup { \musicglyph #"scripts.coda" }

% The coda
\relative c'' \repeat unfold 5 {
c4\repeatTie c c c
}
\bar"|."
}


The problem here is the \repeat unfold 2 { ... } after the first coda sign.

That does not contain a ~ for "start tie." When it is expanded, Lilypond has finished typesetting its last note, without a tie.

So the in the following ~c4, the ~ has nothing to attach itself to.

One fix is just to remove the \repeat unfold 2 and put the ~ where it belongs:

\relative c'' { c4 c c c | c c c c~ }

\break
...
% The coda
\relative c'' \repeat unfold 5 {
c4 c c c
}


If you really want to keep the \repeat unfold construct, you can make a parallel passage consisting only of spacer rests, and start the tie from inside that:

    \mark \markup { \musicglyph #"scripts.coda" }
\relative c'' {
<< \repeat unfold 2 { c4 c c c }
{ s4*7 s4~ }
>>
}

\break
...
% The coda
\relative c'' \repeat unfold 5 {
c4 c c c
}
\bar"|."


This works because the ~ is "merged" with the notes after the \repeat unfold has been expanded. Incidentally, this is also a good way to attach different dynamic marks, etc, to different repeats of the music in a \repeat unfold.

• I'm not sure I'm following this completely. My actual situation doesn't use repeat, but it does use other instrument specific melody creation commands for score and part layouts, so I have tried to start with the first solution you describe. As you describe lilypond has not typeset a tie when it does it's last note. To my understanding, that's the whole problem. The tied note I need to "link" is in the middle of a block of notes, it's not at the end of the line. Unfortunately spacers give unwanted space and the tie just gets added to the wrong side of the desired note. May 29 '17 at 3:53
• If you post an example that shows your real problem, you might get a better answer. To be honest, I found your original question hard to understand - and how it relates to Lilypond-book wasn't clear at all. The basic question seemed to be "why doesn't the tie into the coda (that starts on the second system) work?" which is what I answered. Sorry if that wasn't the question you really wanted to ask.
– user19146
May 29 '17 at 9:58