Combine all four terms over sinxcosx to get integrand 1+sinx+cosxsinxcosx; with s=sinx+cosx this is 2s−1, integrating to 21(sinx−cosx−x)+C.
Simplify the denominator.
tanx+cotx=sinxcosxsin2x+cos2x=sinxcosx1,secx+cscx=sinxcosxsinx+cosx.
Adding, the denominator =sinxcosx1+sinx+cosx, so
∫tanx+cotx+secx+cscxdx=∫1+sinx+cosxsinxcosxdx.
Key substitution. Let s=sinx+cosx. Then s2=1+2sinxcosx, so sinxcosx=2s2−1, and the integrand becomes
1+ssinxcosx=1+s(s2−1)/2=2(1+s)(s−1)(s+1)=2s−1=2sinx+cosx−1. …