I was reading about Fermat's Principle that states the variation of the optical path $\mathrm A$ is zero.
The variation of the action $\mathrm A$ was given by:
$$\delta \mathrm A = \delta \int_A^B n(\mathbf r(s))\sqrt{\frac{\mathrm d\mathbf r}{\mathrm d s}\cdot \frac{\mathrm d\mathbf r}{\mathrm ds}}~\mathrm ds,\tag I$$
But then, the author made re-parametrization of the path by defining $\mathrm d\tau = n(\mathbf r(s)) ~\mathrm ds$ and wrote that the variation
$$\delta \mathrm A =\delta\int_A^B \frac12 n^2(\mathbf r(\tau))~{\frac{\mathrm d\mathbf r}{\mathrm d \tau}\cdot \frac{\mathrm d\mathbf r}{\mathrm d\tau}}~\mathrm d\tau\tag{II}$$ is equivalent to $\mathrm{(I)};$ the author proceeded further to write:
$$\delta\mathrm A= \int_A^B \underbrace{\frac{\mathrm ds}{\mathrm d\tau}}_{?}\left[\underbrace{\frac{n~\mathrm ds}{\mathrm d\tau}}_{?}\frac{\partial n}{\partial\mathbf r} - \frac{\mathrm d}{\mathrm ds}\left(\underbrace{\frac{n~\mathrm ds}{\mathrm d\tau}n~\frac{\mathrm d\mathbf r}{\mathrm ds}}_{?}\right)\right]~\mathrm d\tau;$$ the author remarked that this variation is same as that for $\mathrm {(I)}$ when re-parametrised again to $s\,.$
However, I'm not getting how he wrote the variation for $\mathrm{(II)}$ above; how did he get the term $\frac{\mathrm ds}{\mathrm d\tau},\frac{n~\mathrm ds}{\mathrm d\tau} $ and the term within the parenthesis?
I thought the term along with $\frac{\partial n}{\partial \mathbf r}$ would be ${\frac{\mathrm d\mathbf r}{\mathrm d \tau}\cdot \frac{\mathrm d\mathbf r}{\mathrm d\tau}};$ but here it is $\frac{\mathrm ds}{\mathrm d\tau}\frac{n~\mathrm ds}{\mathrm d\tau}$ which is what I'm not getting.
Also, how is the variation the same as that for $\mathrm{(I)}$ when re-parametrised back to $s$?