It is clear to me how to integrate $f(g(x))g'(x)\,\mathrm dx$ by substitution, and why it works.
But sometimes there is no $g'(x)\,\mathrm dx$ term, and we can "create" it artificially. The following method described in Spivak Calculus:
Assume that we want to find $$\int f(g(x))\,\mathrm dx$$ let $$u = g(x)$$ $$x = g^{-1}(u)$$ $$\mathrm dx = (g^{-1})'(u)\,\mathrm du$$ then $$\int f(g(x)) \, \mathrm dx = \int f(u)(g^{-1})'(u)\,\mathrm du$$ This method can not be always applied with success, but sometimes it works pretty good. For example: $$\int \frac{1 + e^x}{1 - e^x}\,\mathrm dx = \int \frac{1 + u}{1 - u} \frac{1}{u}\,\mathrm du = \int \frac{2}{1 - u} + \frac{1}{u}\,\mathrm du$$ Here $u = e^x, x = ln(u)$ and $\mathrm dx = \frac{1}{u}\,\mathrm du$
The algorithm described before it just convenient symbolic manipulation, and Spivak gives the following explanation why this method always works: $$\int f(g(x))\,\mathrm dx = \int f(g(x))\frac{1}{g'(x)}g'(x)\,\mathrm dx$$ let $$u = g(x)$$ $$x = g^{-1}(u)$$ $$\frac{1}{g'(x)} = \frac{1}{g'(g^{-1}(u))} = (g^{-1})'(u)$$ $$\mathrm du = g'(x)\,\mathrm dx$$ and we get $$\int f(g(x))\frac{1}{g'(x)}g'(x)\,\mathrm dx = \int f(u)(g^{-1})'(u)\,\mathrm du$$ as it was stated before.
It is not clear to me why it is correct to apply substitution at this (the last) step. OK, let $g'(x)\,\mathrm dx = \mathrm du$. But the rest of the expression under integral is $f(g(x))\frac{1}{g'(x)}$, not just $f(g(x))$ as in "pure" substitution algorithm.
May be this trick can be explained in more details or in different way?