[Note that this is a reference request; I already know a couple of routine ways to prove the identity.]
In April I posted this answer. Then yesterday I had occasion to conjecture that in general $$ \left(\frac{p\sin x + q\cos x}{r\sin x + s\cos x} = \frac{p\tan x + q}{r\tan x + s} \right) = a + b \tan(x - \varphi) $$ for some $a,b,\varphi$ depending on $p,q,r,s$.
The special case I posted in April was one in which $p=s$ and $r=q$ and there was nothing in it I thought was messy. On this one I'm getting $\tan\varphi=r/s$ (that part's easy) and $a$ and $b$ are slightly messy rational functions of $p,q,r,s$. (Among the values of $\varphi$ whose tangent is $r/s$ I know of no reason to prefer any particular one.)
Are this identity and the specifics of the function $$p,q,r,s\mapsto a,b,\varphi \tag 1$$ universally known and out there in the literature somewhere?
And did I miss some elegant pattern in $(1)$?
We have $$a+b\tan(x-\phi)=a+\frac{b\tan x-b\tan\phi}{1+\tan x\tan\phi}$$ $$=\frac{\tan x(b-a\tan \phi)+(a-b\tan \phi)}{1+\tan x\tan \phi}$$
We can equate this to $$\frac{\frac ps\tan x+\frac qs}{\frac rs\tan x+1}$$ if we allow $$\frac ps=b-a\tan \phi$$ $$\frac qs=a-b\tan \phi$$ and $$\frac rs=\tan \phi$$
Now, by eliminating $\tan \phi$ and solving simultaneously for $a$ and $b$, we get $$a=\frac{rp-sq}{r^2-s^2}$$ $$b=\frac{rq-sp}{r^2-s^2}$$