<s>[INST] What is the integral of $\frac{2x+1}{x^2+1}$ I know the integral can be found by writing it as $$\frac{1}{x^2+1} +\frac{2x}{x^2+1}$$ This gives us an answer of $$\ln(x^2+4) +\frac{1}{2} \tan^{-1} \frac{x}{2}$$ However, when I let $x=2\tan u$, I get 
$$\frac{1}{2} \tan^{-1} \frac{x}{2} + 2\ln\left|\text{sec(tan}^{-1} \frac{x}{2})\right|$$ This can be simplified and will give the same results for large values of $x$ but not smaller values. What am I doing wrong. Sorry for the format, I am still trying to figure out Latex.
 [/INST] You were right to write the expression like
$$\frac{1}{x^2+1} +\frac{2x}{x^2+1}$$

The easiest way to find the integral is to notice that
$$\frac{2x}{x^2+1} = \frac{(x^2+1)'}{x^2+1}$$
and this is a logarithmic derivative.
Also, 
$$\int \frac{dx}{x^2+1} = \arctan x + C$$
</s>