When using the subsitituion rule in integration of an integral $\displaystyle \int f(x)\,\mathrm dx$, one turns the integral from the form $$\displaystyle \int f(x(t))\,\mathrm dx \quad(*)$$ into the form $$\int f(x(t))\,\frac{\mathrm dx}{\mathrm dt}\mathrm dt \quad(**)$$. This transform is usually accomplished by means of differenting the subsitution $x = x(t)$, such that $\dfrac{\mathrm dx}{\mathrm dt} = \dfrac{\mathrm d x(t)}{\mathrm dt}$. Now, at this point, one turns this into a differential form by means of magic, s.t. $\mathrm dx = \dfrac{\mathrm dx(t)}{\mathrm dt}\mathrm dt$. This now substitutes the differential term $\mathrm dx$ in the original expression $(*)$ to the one in the transformed expression $(**)$.
I'd like to learn that magic step a bit more rigorous – so that I can better understand it. It is often explained by "multiplication" of $\mathrm dt$, which do make sense, but it does not explain the nature of differentials; when is "multiplication" allowed? It seems there should be a more rigorous way of explaining it, perhaps by defining the "multiplication.
So, in what ways can differentials like $\mathrm dx$ and $\mathrm dt$ be formalized in this context? I've seen them being compared to small numbers, which often work, but can this analogy fail? (And what are the prerequisites needed to understand them?)