Evaluating an indefinite integral $\int\sqrt {x^2 + a^2} dx$ indefinite integral $$\int\sqrt {x^2 + a^2} dx$$
After some transformations and different substitution, I got stuck at this
$$a^2\ln|x+(x^2+a^2)| + \int\sec\theta\tan^2\theta d\theta$$
I am not sure I am getting the first step correct. Tried substituting $ x=a\tan \theta$ but that doesn't help either.

Here we have another way to see this:
$$
\int \sqrt{x^2+a^2} dx 
$$
using the substitution
$$
t=x+\sqrt{x^2+a^2}\\
\sqrt{x^2+a^2}=t-x
$$
and squaring we have
$$
a^2 =t^2-2tx\\
x=\frac{t^2-a^2}{2t}.
$$
Finally we can use:
$$
dx=\frac{2t(t)-(t^2-a^2)(1)}{2t^2}dt = \frac{t^2+a^2}{2t^2}dt\\
\sqrt{x^2+a^2}=t-\frac{t^2-a^2}{2t}=\frac{t^2+a^2}{2t}.
$$
Thus:
$$
\int \sqrt{x^2+a^2} dx = \int \frac{t^2+a^2}{2t} \frac{t^2+a^2}{2t^2}dt=\int \frac{(t^2+a^2)^2}{4t^3}dt
$$
which is elementary, if we expand the square of the binomial:
$$
\int\frac{t}{4}dt+\int\frac{a^2}{2t}dt+\int\frac{a^4}{4t^3}dt=\frac{t^2}{8}+a^2\ln\sqrt{t}-\frac{a^4}{16t^4},
$$
where as stated $t=x+\sqrt{x^2+a^2}.$
