Problem
Differentiate the following inverse trig. function for $x\in (-1, 1)$:
$$f(x) = \sec^{-1}\left(\sqrt{1+x^2}\right)$$
Attempting to solve
Putting $x = \tan(\theta)$ so that $\theta \in \left(\dfrac{-\pi}{4}, \dfrac{\pi}{4}\right)$
$$\begin{align}\implies f(x) & = \sec^{-1}\left(\sqrt{1+\tan^2\theta}\right)\\&=\sec^{-1}\left(\sqrt{\sec^2\theta}\right)\\&=\sec^{-1}\left(|\sec\theta|\right)\tag{$*$}\end{align}$$
This is equal to $\theta$ only when $\theta \in \left(0, \pi\right)$. I'm not getting it... what to do when $\theta$ doesn't lie in that interval?
I'm having great difficulties in defining $\sec^{-1}\left(\sec x\right)$ for different intervals.
Edit
By some sort of graphing, I obtained the solution as,
$$f'(x) = \begin{cases}\dfrac{1}{1 + x^2},\quad {\rm if\: } x\in(0, 1)\\\\\dfrac{-1}{1+x^2},\quad{\rm if\ }x \in(-1,0)\end{cases}$$
which implies that the above expression $(*)$ can be defined as, $$\sec^{-1}\left(|\sec\theta|\right) = \begin{cases} \theta + C_1, \quad {\rm if \:} \theta \in \left(0, \dfrac{\pi}{4}\right)\\\\-\theta + C_2, \quad {\rm if \:} \theta \in\left(-\dfrac{\pi}{4},0\right) \end{cases}$$
---though I've obtained the derivative, but still, I'm not understanding it :(

Quibble: you mean "such that" rather than "so that".
Okay, continuing with your substitution method, but choosing a more suitable restriction:
Let $\theta \in [0,\pi){\setminus}\left\{\frac\pi2\right\}$ and $x = \tan\theta.$ Then
$$=\begin{cases}\theta,&{\rm if\: } \theta\in[0, \frac\pi2)\\\\\pi-\theta,&{\rm if\ }\theta \in(\frac\pi2,\pi)\end{cases}.$$
So, $$f'(x)=\begin{cases}\dfrac{\mathrm d\theta}{\mathrm dx},&{\rm if\: } \theta\in[0, \frac\pi2)\\\\-\dfrac{\mathrm d\theta}{\mathrm dx},&{\rm if\ }\theta \in(\frac\pi2,\pi)\end{cases},$$ giving
noting that $f$ has no derivative at $x=0$ since