Evaluate the integral of $\frac{1}{\sqrt{x^2-a^2}}$
Put $x=a\sec\theta\implies dx=a\sec\theta\tan\theta d\theta$ $$ \begin{align} & \ \ \ \int \frac{dx}{\sqrt{x^2-a^2}} \\ &=\int \frac{a\sec\theta\tan\theta d\theta}{\sqrt{a^2\sec^2\theta-a^2}} \\ &=\int \frac{a\sec\theta\tan\theta d\theta}{a\sqrt{\tan^2\theta}}\\ &= \int\frac{a\sec\theta\tan\theta d\theta}{a\color{red}{\tan\theta}}\\ &=\int\sec\theta d\theta \\ &=\log \lvert \sec\theta+\tan\theta \rvert|+C_0 \\ & \mbox{where $C_0$ is an arbitrary constant of integration } \\ &=\log \left\lvert \frac{x}{a}+\sqrt{\frac{x^2}{a^2}-1} \right\rvert + C_0 \\ &= \log \left\lvert \frac{x+\sqrt{x^2-a^2}}{a} \right\rvert +C_0 \\ &= \log \left\lvert x+\sqrt{x^2-a^2} \right\rvert -\log|a|+C_0 \\ &= \log|x+\sqrt{x^2-a^2}|+ C, & \mbox{ where $C = \log \lvert a \rvert + C_0$}. \end{align} $$ This is how it is solve in my reference. But, $\sqrt{\tan^2\theta}=|\tan\theta|$ right ? Then, does that imply $$ \int\frac{dx}{\sqrt{x^2-a^2}}=\int\frac{a\sec\theta\tan\theta d\theta}{a\color{red}{|\tan\theta|}}=\color{red}{\pm}\int\sec\theta d\theta $$ Why am I getting this confusion and is the first solution complete ?
Suppose that $a>0$.
The work is just for the case when $x>a$. The case for $x<-a$ is different, but the finals result is the same.
Let $x=a\sec\theta$, where $\theta\in[0,\frac{\pi}{2})\cup(\frac{\pi}{2},\pi]$. This is the domain of $\textrm{arcsec}$.
For $x< -a$, $\theta\in(\frac{\pi}{2},\pi]$ and so $\tan\theta\le0$.
$$\sqrt{x^2-a^2}=\sqrt{a^2\tan^2\theta}=-a\tan\theta$$
\begin{align*} \int\frac{dx}{\sqrt{x^2-a^2}}&=\int\frac{a\sec\theta\tan\theta}{-a\tan\theta}d \theta\\ &=-\int\sec\theta d\theta\\ &=-\ln|\sec\theta+\tan\theta|+C\\ &=\ln|\sec\theta-\tan\theta|+C\\ &=\ln\left|\frac{x}{a}-\frac{-\sqrt{x^2-a^2}}{a}\right|+C\\ &=\ln\left|x+\sqrt{x^2-a^2}\right|-\ln|a|+C \end{align*}
There are two minus signs and they cancel each other to reach the final result.