I'm reading these notes that say: total differentiation gives $$ P=a_LW+a_KR\implies dP=a_LdW+a_KdR+[Wd(a_L)+Rd(a_K)]\tag{i}. $$ Please let me explain the notation: we can think of $R,W$ and $P$ as rent, wage, and price respectively. The quantities $a_L$ and $a_K$ come from the minimization problem: $$ \min_{a_L,a_K} a_LW+a_KR\quad\text{s.t.}\quad a_K=g(a_L).\tag{ii} $$ The function $g$ doesn't depend on $W$ and $R$ and we know that the optimal $a_L$ and $a_K$ are interior solutions that only depend on $\frac{W}{R}$. Then, the author claims $[Wd(a_L)+Rd(a_K)]=0$ in (i) and so $$ dP=a_LdW+a_KdR.\tag{iii} $$ I can see why $[Wd(a_L)+Rd(a_K)]=0$ because it's just the first-order condition for (ii): $$ 0=W+g'(a_L)R\implies -\frac{W}{R}=g'(a_L)=\left.\frac{da_K}{da_L}\right|_{a_L=a_L(W/R)}. $$
My question: I can sort of follow why the author gets (i) and (iii) but I am uncomfortable by the seeming lack of rigor. What is and how to arrive at the rigorous analog of (iii) (e.g., $-\frac{W}{R}=\frac{da_K}{da_L}$ is the rigorous version of $[Wd(a_L)+Rd(a_K)]=0$)?
p.s. I would also appreciate some references so that I can understand things like this better in the future. Thank you!
Edit: I figured it out! I'll leave this post here for my own record and just in case someone else might find it useful.
Typing things all out to MSE really helped!
The rigorous version of (iii) is $$ 1=a_L\frac{dW}{dP}+a_L\frac{dR}{dP}\tag{iv}. $$ To get here, we differentiate $$ P=Wa_L(W/R)+Ra_K(W/R) $$ w.r.t to $P$ to arrive at $$ 1=a_L\frac{dW}{dP}+a_L\frac{dR}{dP}+\left(\frac{d(W/R)}{dP}\right)\left[Wa'_L(W/R)+Ra'_K(W/R)\right]. $$ So we are done if the expression inside $[\cdot]$ is $0$, but this follows because $$ Wa'_L(W/R)+Ra'_K(W/R)=a'_L(W/R)[W+Rg'(a_L(W/R))]=0. $$