<s>[INST] Evaluate $\int\frac{\cos x}{\sin x + \cos x}\,\text{d}x$. I'm trying to figure out how to take this indefinite integral:
$$ \int\frac{\cos x}{\sin x + \cos x}\,\text{d}x.$$
I tried simplifying and rearranging it, and this is the best I got:
$$\int\frac{1}{\tan x + 1 }\,\text{d}x.$$
But I still can't figure out how to integrate from there. I know that it's integrable, as Wolfram Alpha indicates that the integral is $ \frac{1}{2}\big(x+\ln{(\sin x + \cos x)}\big)+C$, but I can't figure out the steps to deriving it. Does anyone know how to evaluate this integral?
 [/INST] $\displaystyle \int \frac{1}{1+ \tan x} \ dx $
$ \displaystyle = \int \frac{1}{1+u} \frac{1}{1+u^{2}} \ du$ (let $u = \tan x$) 
$ \displaystyle =  \frac{1}{2} \int \left( \frac{1}{1+u} + \frac{1-u}{1+u^{2}} \right) \ du$
$ \displaystyle = \frac{1}{2} \int \left( \frac{1}{1+u}  - \frac{u}{1+u^{2}} + \frac{1}{1+u^{2}} \right) \ du $
$ \displaystyle =\frac{1}{2} \left(\ln(1+u) - \frac{1}{2} \ln(1+u^{2}) + \arctan u \right) + C$
$ \displaystyle =\frac{1}{2} \left(\ln(1+u) - \ln(\sqrt{1+u^{2}}) + \arctan u \right) + C$
$ \displaystyle = \frac{1}{2} \left( \ln(1+\tan x) - \ln (\sqrt{1+\tan^{2}x}) + x \right) + C$
$  \displaystyle = \frac{1}{2} \left( \ln(1+\tan x) - \ln (\sec x) + x \right) + C$
$ \displaystyle = \frac{1}{2} \Big( \ln \big(\frac{1+ \tan x}{\sec x}\big)  + x \Big) + C$
$ \displaystyle = \frac{1}{2} \left( \ln (\cos x + \sin x ) + x \right) + C $
</s>