This is the publisher's version, also available electronically from http://journals.aps.org/pre/abstract/10.1103/PhysRevE.68.016704.We demonstrate that the Nosé method for constant-temperature molecular-dynamics simulation [Mol. Phys. 52, 255 (1984)] can be substantially generalized by the addition of auxiliary variables to encompass an infinite variety of Hamiltonian thermostats. Such thermostats can be used to enhance ergodicity in systems, such as the one-dimensional harmonic oscillator or certain molecular systems, for which the standard Nosé-Hoover methods fail to reproduce converged canonical distributions. In this respect the method is similar in spirit to the method of Nosé-Hoover chains, but is both more general and Hamiltonian in structure (which allows for the use of efficient symplectic integration schemes). In particular, we show that, within the generalized Nosé formalism outlined herein, any Hamiltonian system can be thermostated with any other, including a copy of itself. This gives one an enormous flexibility in choosing the form of the thermostating bath. Numerical experiments are included in which a harmonic oscillator is thermostated with a collection of noninteracting harmonic oscillators as well as by a soft billiard system