Thanks David and Paul - that's helpful. However, while the situation improved the output is still not what i want:
\version "2.19.13"
voiceDivisi =
#(define-music-function (parser location m1 m2) (ly:music? ly:music?)
#{
\tag divI { $m1 }
\tag divII { $m2 }
\tag together << { \dynamicUp $m1 } \\ { \dynamicDown $m2 } >>
#})
music = \relative c' {
\voiceDivisi {
c4 d e f
}{
a,1
}
}
musicII = \relative c' {
\voiceDivisi {
f4 e d c
} {
a1
}
}
\new Staff \with { instrumentName = "part I" }
\removeWithTag divII.together { \music \musicII }
\new Staff \with { instrumentName = "part II" }
\removeWithTag divI.together { \music \musicII }
\new Staff \with { instrumentName = "combined" }
\removeWithTag divI.divII { \music \musicII }
if i understand correctly, "relativization" happens too late, i.e. after the music is processed by the voiceDivisi function.
How should i work around this? Maybe instead of using tags i should write a function with a switch statement inside? I know that i can put \relative command inside \voiceDivisi, but i'd like to avoid this as it would add a lot of typing.
best,
Janek