Concept:
Trigonometric integrals containing tangent and cotangent are often much easier to solve if first simplified by converting everything to fundamental sines and cosines or by utilizing Pythagorean identities.
Step 1: Simplify the denominator.
Using the Pythagorean identity $1 + \tan^2 x = \sec^2 x$:
$$\int \frac{\tan x + \cot x}{\sec^2 x} dx$$
Step 2: Convert to sine and cosine.
Substitute $\tan x = \frac{\sin x}{\cos x}$, $\cot x = \frac{\cos x}{\sin x}$, and $\sec^2 x = \frac{1}{\cos^2 x}$:
$$= \int \frac{\frac{\sin x}{\cos x} + \frac{\cos x}{\sin x}}{\frac{1}{\cos^2 x}} dx$$
Step 3: Find a common denominator for the numerator.
$$= \int \frac{\frac{\sin^2 x + \cos^2 x}{\sin x \cos x}}{\frac{1}{\cos^2 x}} dx$$
Since $\sin^2 x + \cos^2 x = 1$:
$$= \int \frac{\frac{1}{\sin x \cos x}}{\frac{1}{\cos^2 x}} dx$$
Step 4: Simplify the complex fraction.
Multiply by the reciprocal of the denominator:
$$= \int \frac{1}{\sin x \cos x} \cdot \cos^2 x \ dx$$
Cancel one $\cos x$:
$$= \int \frac{\cos x}{\sin x} dx$$
$$= \int \cot x \ dx$$
Step 5: Integrate the standard function.
The integral of $\cot x$ is a standard formula:
$$= \log|\sin x| + C$$