  The g-function was introduced by Affleck and Ludwig in the context of
critical quantum systems with boundaries. In the framework of the thermodynamic
Bethe ansatz (TBA) method for relativistic scattering theories, all attempts to
write an exact integral equation for the off-critical version of this quantity
have, up to now, been unsuccesful. We tackle this problem by using an
n-particle cluster expansion, close in spirit to form-factor calculations of
correlators on the plane. The leading contribution already disagrees with all
previous proposals, but a study of this and subsequent terms allows us to
deduce an exact infrared expansion for g, written purely in terms of TBA
pseudoenergies. Although we only treat the thermally-perturbed Ising and the
scaling Lee-Yang models in detail, we propose a general formula for g which
should be valid for any model with entirely diagonal scattering.
