In this paper, we present a new calculation of composition-dependent radiative cooling and heating curves of low-density gas, intended primarily for use in numerical simulations of galaxy formation and evolution. These curves depend on only five parameters: temperature, density, redshift, [Fe/H] and [Mg/Fe]. They are easily tabulated and can be efficiently interpolated during a simulation. The ionization equilibrium of 14 key elements is determined for temperatures between 10 K and 109 K and densities up to 100 amu cm-3 taking into account collisional and radiative ionization, by the cosmic UV background and an interstellar radiation field, and by charge-transfer reactions. These elements, ranging from H to Ni, are the ones most abundantly produced and/or released by SNIa, SNII and intermediate-mass stars. Self-shielding of the gas at high densities by neutral hydrogen is taken into account in an approximate way by exponentially suppressing the H-ionizing part of the cosmic UV background for H I densities above a threshold density of nHI, crit = 0.007 cm-3. We discuss how the ionization equilibrium, and the cooling and heating curves, depends on the physical properties of the gas. The main advantage of the work presented here is that, within the confines of a well-defined chemical evolution model and adopting the ionization equilibrium approximation, it provides accurate cooling and heating curves for a wide range of physical and chemical gas properties, including the effects of self-shielding. The latter is key to resolving the formation of cold, neutral, high-density clouds suitable for star formation in galaxy simulations.