Context. We discuss the case of lines formed by scattering, which comprises both coherent and incoherent scattering. Both processes contribute to form the line profiles in the so-called second solar spectrum, which is the spectrum of the linear polarization of such lines observed close to the solar limb. However, most of the lines cannot be simply modeled with a two-level or two-term atom model, and we present a generalized formalism for this purpose. Aims. The aim is to obtain a formalism that is able to describe scattering in line centers (resonant scattering or incoherent scattering) and in far wings (Rayleigh/Raman scattering or coherent scattering) for a multilevel and multiline atom. Methods. The method is designed to overcome the Markov approximation, which is often performed in the atom-photon interaction description. The method was already presented in the two first papers of this series, but the final equations of those papers were for a two-level atom.Results. We present here the final equations generalized for the multilevel and multiline atom. We describe the main steps of the theoretical development, and, in particular, how we performed the series development to overcome the Markov approximation. Conclusions. The statistical equilibrium equations for the atomic density matrix and the radiative transfer equation coefficients are obtained with line profiles. The Doppler redistribution is also taken into account because we show that the statistical equilibrium equations must be solved for each atomic velocity class.