  Aims. We present a new sub-grid model, HYACINTH -- HYdrogen And Carbon
chemistry in the INTerstellar medium in Hydro simulations -- for computing the
non-equilibrium abundances of ${\rm H_2}$ and its carbon-based tracers, namely
${\rm CO}$, ${\rm C}$, and ${\rm C^+}$, in cosmological simulations of galaxy
formation. Methods. The model accounts for the unresolved density structure in
simulations using a variable probability distribution function of sub-grid
densities and a temperature-density relation. Included is a simplified chemical
network that has been tailored for hydrogen and carbon chemistry within
molecular clouds and easily integrated into large-scale simulations with
minimal computational overhead. As an example, we applied HYACINTH to a
simulated galaxy at redshift $z \sim 2.5$ in post-processing and compared the
resulting abundances with observations. Results. The chemical predictions from
HYACINTH are in reasonable agreement with high-resolution molecular-cloud
simulations at different metallicities. By post-processing a galaxy simulation
with HYACINTH, we reproduced the $\rm H\,I-{\rm H_2}$ transition as a function
of the hydrogen column density $N_{\rm H}$ for both Milky-Way-like and
Large-Magellanic-Cloud-like conditions. Column density maps reveal that ${\rm
CO}$ is concentrated in the peaks of the ${\rm H_2}$ distribution, while atomic
carbon more broadly traces the bulk of ${\rm H_2}$ in our post-processed
galaxy. Based on both the column density maps and the surface density profiles
of the different gas species in the post-processed galaxy, we find that ${\rm
C^+}$ maintains a substantially high surface density out to $\sim 10 \, \rm
kpc$ as opposed to other components that exhibit a higher central
concentration. This is similar to the extended $[\rm C\,II]$ emission found in
some recent observations at high redshifts.
