Step 1: Rewrite the integrand.
We are given the integral
\[
\int \left[ \log(1+\cos x) - x \tan\left(\frac{x}{2}\right) \right] dx
\]
Split the integral into two parts:
\[
\int \log(1+\cos x)\,dx - \int x \tan\left(\frac{x}{2}\right)\,dx
\]
Step 2: Use the identity for tangent.
Recall that
\[
\tan\left(\frac{x}{2}\right) = \frac{\sin x}{1+\cos x}
\]
Thus, the second term becomes
\[
\int x \frac{\sin x}{1+\cos x}\,dx
\]
Step 3: Apply differentiation insight.
Observe that
\[
\frac{d}{dx}\left[\log(1+\cos x)\right] = -\frac{\sin x}{1+\cos x}
\]
Hence, the given integrand matches the derivative structure of
\[
x \log(1+\cos x)
\]
Step 4: Write the final result.
Therefore, the integral evaluates to
\[
x \log|1+\cos x| + C
\]