How to write a two variable function $f(x,t)$ in terms of Dirac-Delta $\delta(x)$ function and a function $P(t)$?
For example;
I read something in a book. You can find the following picture.
But I don' t understand the logic behind this. Could you explain it?

They want a force density but don't have a smooth load. Instead they have a point load. To represent a point load as a force density one can use Dirac $\delta$. A point load $P$ at $x=g$ is represented as the force density $f(x) = P \, \delta(x-g).$
In the example they also have that both the force $P$ and the placement $g$ varies with time $t$. This makes also the force density $f$ depend on $t$. Thus we get $$f(x,t) = P(t) \, \delta(x-g(t)).$$