Why is the integral of the tangent function a natural log function? I understand the mechanics of using $u$-substitution to solve
$$\int\tan(x)\,dx = -\ln(\cos(x))$$
The textbook/online $u$-sub solution examples smack of "because that's what makes it work."  What I'm looking for is an explanation of why it works.  What are the properties of these trig and log functions that enable them to be related via integrals and derivatives?
 A: I think the best way to see it is to go backwards from $-\ln(\cos(x))$ using the chain rule.  We have that $$\frac{d}{dx}\bigl(-\ln(\cos(x))\bigr) = -\frac{d}{dx}\ln(\cos(x)) = -\frac{\frac{d}{dx}\cos(x)}{\cos(x)} = -\frac{-\sin(x)}{\cos(x)}= 
 \tan(x).$$  That then means that $$\int\tan(x)\,dx = -\ln(\cos(x)).$$
There's nothing really special about trig functions going on here as much as we have an integral of the form $$\int\frac{-f'(x)}{f(x)}\,dx.$$
A: Notice that in general:
$$\int\frac{f'(x)}{f(x)}dx\stackrel{u=f(x)}{=}\int\frac{u'}{u}\frac{du}{u'}=\int\frac{du}{u}=\ln|u|+C=\ln|f(x)|+C$$

In your case:
$$\int\tan(x)dx=\int\frac{\sin(x)}{\cos(x)}dx=\int\frac{[-\cos(x)]'}{\cos(x)}dx=-\ln|\cos(x)|+C$$
try making the substitution $u=\cos x$ and see what you get

In terms of a deeper meaning, you could use the exponential definition of $\sin$ and $\cos$ to get:
$$\tan(x)=\frac{e^{ix}-e^{-ix}}{e^{ix}+e^{-ix}}$$
and notice that:
$$\frac{d}{dx}\left[e^{ix}+e^{-ix}\right]=i\left(e^{ix}-e^{-ix}\right)$$
A: $\ln x$ is a function such that the slope at each $x > 0$ is $1/x$. That is, $\frac{d}{dx} \ln x = 1/x$.
By the Chain Rule, $\frac{d}{dx} \ln (f(x)) = \frac{f'(x)}{f(x)}$.
In your case, put $f(x) = \cos x$.
