Peace be with you, guys... ;-) <quote author="Wols Lists">The OP's eXample is more complicated but as far as I can tell this is what he's aiming at. </quote>
Of course, I did some experimenting on my own before asking here on the list. I was aware that the problem only appears if I use my function inside a \relative statement, but not (as far as I remember) if I start a \relative expression at the same moment the function is called. And, of course, no problem in absolute mode. I was hoping to to find a solution that can deal with all of the above situations and the user doesn't have to care. That's why David's solution is perfect for my aim. I also have seen Han-Wen's function, but I could not test if it fits my needs. It did not compile without errors. Maybe it doesn't work with recent LY versions, maybe it was a mistake by me... Thanks to everyone who replied. I'm glad this list exists and I know where to find help. Cheers, Klaus