Derivation of the elasticity of substitution of a general production function with labor-augmenting technological progress I am following and trying to fully understand a famous and interesting work of Bentolila and Saint-paul (2003). They try to explain movements of the factor's share in terms of a relationship between the labor share ($LS$) and the capital-output ratio ($k$). To summarize as much as possible they start from a general production function with labor-augmenting technological progress and constant returns to scale:

$$Y_{i} = F(K_{i},B_{i}L_{i})=K_{i}f(l_{i}),$$

where $l_{i}=\frac{B_{i}L_{i}}{K_{i}}.$ And show that under the usual microeconomic assumptions of equilibrium (i.e. labor its paid its marginal product), there exists a unique function $g(\cdot)$ such that:

$$S_{Li} = g(k_{i}).$$

where $S_{Li}=\frac{w_iL_i}{p_iY_i}$ the labor share in the industries revenues, with $w_i$ denoting the wage, $p_i$ the product's price and $k_i=\frac{K_i}{Y_i}$ is the capital-output ratio. 

Then, at page 6 of the paper, they employ the standard definition of elasticity of substitution to production function above, i.e. $\sigma_{i}=\frac{d(K_i/L_i)}{d(r/w)}\cdot \frac{r/w}{K_i/L_i}$ to obtain the following result:

$$\sigma_{i}=\frac{f'(l_{i})}{l_{i}f''(l_{i})}\left [1-\frac{l_{i}f'(l_{i})}{f(l_{i})} \right ]$$

I am trying to do all the derivations, but I can't find a way to derive this last formula with the same result. Is there someone who could kindly help me and show me the steps?.
You have that in  equilibrium each factor is paid its marginal product, so 
$$\tag1\frac{w_i}{p_i}=B_if'(l_i)$$ and $$\tag2\frac{r_i}{p_i}=f(l_i)-K_if'(l_i)\frac{B_iL_i}{K_i^2}=f(l_i)-l_if'(l_i)$$ so deviding (2) by (1) we have:

$$\tag3\frac{r_i}{w_i}=\frac{f(l_i)-l_if'(l_i)}{B_if'(l_i)}.$$

Take the derivative of $r_i/w_i$ with respect to $l_i$:
$$\tag4\frac{d(r_i/w_i)}{d(l_i)}=\frac{(f'(l_i)-(f'(l_i)+l_if''(l_i)))B_if'(l_i)-B_if''(l_i)(f(l_i)-l_if'(l_i))}{(B_if'(l_i))^2}=-\frac{f''(l_i)f(l_i)}{B_i(f'(l_i))^2}$$

Note that $l_i=\frac{B_i}{(K_i/L_i)}$ so 
$$\tag5\frac{d(l_i)}{d(K_i/L_i)}=-\frac{B_i}{(K_i/L_i)^2}=\frac{l_i}{(K_i/L_i)}.$$ Using the chain rule ans substituting (4) and (5) we have:
$$\frac{d(r_i/w_i)}{d(K_i/L_i)}=\frac{d(r_i/w_i)}{d(l_i)}\frac{d(l_i)}{d(K_i/L_i)}=\frac{l_if''(l_i)f(l_i)}{(K_i/L_i)B_i(f'(l_i))^2}$$ and by the inverse function theorem we get:
$$\tag 6\frac{d(K_i/L_i)}{d(r_i/w_i)}=\frac{(K_i/L_i)B_i(f'(l_i))^2}{l_if''(l_i)f(l_i)}$$

Finally by multiplying (3) and (6) and dividing  by  $(K_i/L_i)$ we conclude that 

$$\sigma_i=\frac{d(K_i/L_i)}{d(r_i/w_i)}\frac{r_i/w_i}{K_i/L_i}=\frac{(K_i/L_i)B_i(f'(l_i))^2}{l_if''(l_i)f(l_i)}\cdot\frac{f(l_i)-l_if'(l_i)}{(K_i/L_i)B_if'(l_i)}=\frac{f'(l_i)(f(l_i)-l_if'(l_i))}{l_if''(l_i)f(l_i)}=\frac{f(l_i)}{l_if''(l_i)}\left[1-\frac{l_if'(l_i)}{f(l_i)}\right]$$

as desired. $Q.E.D.$