Effect of closed classical orbits on quantum spectra: Ionization of atoms in a magnetic field. II. Derivation of formulas.