Variational formulation for hyperelastic material

Hi,
I am facing difficulties to derive the variation formulations given in the hands-on tutorial of Fenics. Here is the link for the tutorial:
https://fenics-handson.readthedocs.io/en/latest/elasticity/doc.html

Could anyone please let me know how to derive these momentum balance equations given in this tutorial.

# Balance of momentum
    S, pp = stress(u, p)
    S0, pp0 = stress(u0, p0)
    F1 = (1.0/dt)*inner(u-u0, _u)*dx \
       - ( q*inner(v, _u)*dx + (1.0-q)*inner(v0, _u)*dx )
    F2a = inner(S, grad(_v))*dx + pp*_p*dx
    F2b = inner(S0, grad(_v))*dx + pp0*_p*dx
    F2 = (1.0/dt)*inner(v-v0, _v)*dx + q*F2a + (1.0-q)*F2b