Once I met the indefinite integral $$I=\int \frac{\tan (3 x)}{\tan x+\sec x} d x,$$ I thought of triple-angle formula of tangent
$$\tan 3 x =\frac{3 \tan x-\tan ^3 x}{1-3 \tan ^2 x} \tag*{} $$
For simplicity, I first rationalised the denominator of $I$ as $$\displaystyle I=\int \tan (3 x)(\sec x-\tan x) d x\tag*{} $$ and get $\displaystyle \begin{aligned}I & =\int \frac{\left(3-\tan ^2 x\right) \tan x}{1-3 \tan ^2 x}(\sec x-\tan x) d x \\& =\int \frac{3-\tan ^2 x}{1-3 \tan ^2 x}\left(\sec x \tan x-\sec ^2 x+1\right) d x \\& = \underbrace{\int \frac{4-s^2}{4-3 s^2} d s}_{J} - \underbrace{\int \frac{3-t^2}{1-3 t^2} d t}_{K} + \underbrace{\int \frac{3-\tan ^2 x}{1-3 \tan ^2 x} d x}_{L} \end{aligned}\tag*{} $ where $s=\sec x$ and $t=\tan x$.
To deal with these $3$ integrals, we used the result:
$$ \int \frac{1}{a^2-b^2 x^2} d x=\frac{1}{a b} \tanh ^{-1}\left(\frac{b x}{a}\right)+c $$
For $J$, $$\displaystyle \begin{aligned}\int \frac{4-s^2}{4-3 s^2} d s & =\frac{1}{3} \int \frac{8+\left(4-3 s^2\right)}{4-3 s^2} d s\\&=\frac{8}{3} \int \frac{d s}{2^2-(\sqrt{3} s)^2}+\frac{s}{3} \\& =\frac{4}{3 \sqrt{3}} \tanh ^{-1}\left(\frac{\sqrt{3} s}{2}\right)+\frac{s}{3}+c_1\end{aligned}\tag*{} $$
For $K$, $\displaystyle \begin{aligned}K & =\int \frac{3-t^2}{1-3 t^2} d t \\& =\frac{1}{3} \int \frac{8+\left(1-3 t^2\right)}{1-3 t^2} d t \\& =\frac{8}{3 \sqrt{3}} \tanh ^{-1}(\sqrt{3} t)+\frac{t}{3}+c_2\end{aligned}\tag*{} $
For $L$, $\displaystyle \begin{aligned}L & =\int \frac{3-\tan ^2 x}{1-3 \tan ^2 x} d x \\& =\int \frac{2 \sec ^2 x+\left(1-3 \tan ^2 x\right)}{1-3 \tan ^2 x} d x \\& =2 \int \frac{d t}{1-3 t^2}+x\\&=\frac{2}{\sqrt{3}} \tanh ^{-1}(\sqrt{3} t)+x+c_3\end{aligned}\tag*{} $
Now we can conclude that $ \boxed{\displaystyle I=\frac{4}{3\sqrt{3}} \tanh ^{-1}\left(\frac{\sqrt{3} \sec x}{2}\right)+\frac{\sec x}{3}-\frac{2}{3 \sqrt{3}} \tanh ^{-1}(\sqrt{3} \tan x)-\frac{\tan x}{3}+x+C }\tag*{} $
My solution is rather tedious and long. Is there any simpler method?
Your comments and alternative methods are highly appreciated.