Solution (source code)

= Solution

Multiply the <secant function> integrand by $(\sec\theta+\tan\theta)/(\sec\theta+\tan\theta)$:
$$
\int\sec\theta\,d\theta
=\int\frac{\sec^2\theta+\sec\theta\tan\theta}{\sec\theta+\tan\theta}\,d\theta
=\boxed{\log|\sec\theta+\tan\theta|+C.}
$$
The numerator is the <derivative> of the denominator. The formula holds on any real interval avoiding zeros of $\cos\theta$; on such an interval $\sec\theta+\tan\theta$ cannot vanish because $(\sec\theta+\tan\theta)(\sec\theta-\tan\theta)=1$.