  The Teichm\"uller space $\mathcal{T}_S(\mathbf{b})$ of hyperbolic metrics on
a surface $S$ with fixed lengths at the boundary components is symplectic. We
prove that any sum of infinitesimal earthquakes on $S$ that is tangent to
$\mathcal{T}_S(\mathbf{b})$ is Hamiltonian, by providing a Hamiltonian
$\mathbb{L}$. Such function extends the classical length map associated to a
compactly supported measured geodesic lamination and shares with it some
peculiar properties, such as properness and strict convexity along earthquakes
paths under usual topological conditions. As an application, we prove that any
non-Fuchsian affine representation of $\pi_1(S)$ into $\mathbb{R}^{2,1}\rtimes
SO_0(2,1)$ with cocompact discrete linear part is determined by the
singularities of the two invariant regular domains in $\mathbb{R}^{2,1}$
pointed out by Barbot, once the boundary lengths are fixed.
