Moving dynamics horizontally

Here are two functions to move dynamics easily. The first one moves the dynamics horizontally and drops / raises it closer to the staff if there's room. With the second one you can move the dynamics also vertically.

\version "2.24.0"

%% http://lsr.di.unimi.it/LSR/Item?id=469

%LSR This snippet was contributed by Risto Vääräniemi

dynamicsX = 
#(define-music-function (offset)(number?)
  #{
     \once \override DynamicText.X-offset = $offset
     \once \override DynamicLineSpanner.Y-offset = #0
  #})

dynamicsXY = 
#(define-music-function (offsetX offsetY)(number? number?)
  #{
     \once \override DynamicText.X-offset = $offsetX
     \once \override DynamicLineSpanner.Y-offset = $offsetY
  #})

{
   b'2\f \dynamicsX #-3 b'2\f \dynamicsXY #-3 #-6 b'2\f
}