I mostly work on choral scores, where the problem might even be more imminent due to the lyrics. And I very much think allowing dynamics to overlap with the staff is a good idea, so I’ve been facing this a lot and made many essays at writing a music function that is easy to use (easy to understand and easy to type), versatile, and well maintainable. Unfortunately I haven’t found a satisfactory solution yet, and I can’t delve into the subject more right now. So I’m sorry to provide no more help at the moment except for this issue tracker link:
<https://sourceforge.net/p/testlilyissues/issues/4316/>. Some of the problems encountered are mentioned there.
HTH a bit,
Simon