Context.Observations have long demonstrated the molecular diversity of the diffuse interstellar medium (ISM). Only now, with the advent of high-performance computing, does it become possible for numerical simulations of astrophysical fluids to include a treatment of chemistry, to faithfully reproduce the abundances of the many observed species, and especially that of CO, which is used as a proxy for molecular hydrogen. When applying photon-dominated region (PDR) codes to describe the UV-driven chemistry of uniform density cloud models, it is found that the observed abundances of CO are not well reproduced. Aims. Our main purpose is to estimate the effect of assuming uniform density on the line-of-sight in PDR chemistry models, compared to a more realistic distribution for which total gas densities may well vary by several orders of magnitude. A secondary goal of this paper is to estimate the amount of molecular hydrogen that is not properly traced by the CO (J = 1 → 0) line, the so-called "dark molecular gas". Methods. We used results from a magnetohydrodynamical (MHD) simulation as a model for the density structures found in a turbulent diffuse ISM with no star-formation activity. The Meudon PDR code was then applied to several lines of sight through this model, to derive their chemical structures.Results. We found that compared to the uniform density assumption, maximal chemical abundances for H 2 , CO, CH and CN are increased by a factor ∼2-4 when taking into account density fluctuations on the line of sight. The correlations between column densities of CO, CH and CN with respect to those of H 2 are also found to be in better overall agreement with observations. For instance, at N