Denoting by q i (i = 1, ..., n) the set of extensive variables which characterize the state of a thermodynamic system, we write the associated intensive variables γ i , the partial derivatives of the entropy S = S q 1 , ..., q n ≡ q 0 , in the form γ i = −p i /p 0 where p 0 behaves as a gauge factor. When regarded as independent, the variables q i , p i (i = 0, ..., n) define a space T having a canonical symplectic structure where they appear as conjugate. A thermodynamic system is represented by a n + 1-dimensional gauge-invariant Lagrangean submanifold M of T. Any thermodynamic process, even dissipative, taking place on M is represented by a Hamiltonian trajectory in T, governed by a Hamiltonian function which is zero on M. A mapping between the equations of state of different systems is likewise represented by a canonical transformation in T. Moreover a Riemannian metric arises naturally from statistical mechanics for any thermodynamic system, with the differentials dq i as contravariant components of an infinitesimal shift and the dp i 's as covariant ones. Illustrative examples are given.