TITLE: Simplest way to integrate $\int \frac{1}{1+\tan x}dx,$
QUESTION [7 upvotes]: $$\int \frac{1}{1+\tan x}dx,$$
A substitution like $t = \tan x, \;dt = (1+t^2)dx$ etc. immediately comes to mind, but I find this method a bit lengthy with the partial fractions. Is there a more concise solution to this?

REPLY [2 votes]: Note that
$$\tan\left(x-{\pi\over4}\right)={\tan x-\tan\left(\pi\over4\right)\over1+\tan x\tan\left(\pi\over4\right)}={\tan x-1\over1+\tan x}=1-{2\over1+\tan x}$$
so
$$\int{dx\over1+\tan x}={1\over2}\int\left(1-\tan\left(x-{\pi\over4}\right)\right)dx={1\over2}\left(x+\ln\left|\cos\left(x-{\pi\over4}\right)\right| \right)+c\\
={1\over2}\left(x+\ln|\cos x+\sin x|-\ln\sqrt2 \right)+c\\
={1\over2}(x+\ln|\cos x+\sin x|)+C$$