Modern investigations of magnetic chemically peculiar stars reveal a variety of complex processes in their atmospheres. Realistic spectrum synthesis modelling of these objects has to take into account anomalous chemical composition, strong magnetic field and chemical stratification. These effects complicate calculation of theoretical spectra, especially when one has to deal with a large number of lines and wide spectral regions. To overcome the formidable problem of comparing model and observed spectra for magnetic chemically peculiar stars, a new suite of spectrum synthesis programs was developed. Here we describe in detail the synthesis codes, st\ and sm\ and present examples of their application to various aspects of the peculiar-star surface phenomena. The new codes proved to be reliable tools for the line identification, magnetic field determination, chemical abundance and stratification analysis.