In my text book the MGF of a Gamma distributed R.V., $X \in \Gamma(p,a)$, is computed as follows: $$ \psi_X(t)=\int_0^{\infty}e^{tx}\frac 1 {\Gamma(p)}x^{p-1}\frac 1 {a^p}e^{-x/a}dx= $$ $$ =\frac 1 {a^p} \frac 1 {\left(\frac 1 {a}-t\right)^p}\int_0^{\infty}\frac 1 {\Gamma(p)}x^{p-1}\left(\frac 1 {a}-t\right)^p e^{-x(\frac 1 a -t)}dx= $$ $$ =\frac 1 {a^p} \frac 1 {\left(\frac 1 {a}-t\right)^p} \cdot 1 $$ It seems to me that the author knew what he wanted the final answer to be and as such simply inserted the expression $$ \frac {\left(\frac 1 {a}-t\right)^p} {\left(\frac 1 {a}-t\right)^p} $$ into the integral, and then moved the denominator outside of the integral while keeping the numerator inside to get the integral to be equal to 1.
What is the logical step-by-step solution to the above computation and how did he know to insert the expression above into the integral and then take out its denominator to get an integral equal to 1?
It is a matter of choice of exposition. Alternately, and perhaps a bit more naturally, we can gather the $e^{tx}e^{-x/a}$ of the first line into one term $e^{-x(1/a-t)}$ and use the substitution $u=x(1/a-t)$.