Excitation of forbidden lines in gaseous nebulae I. Formulation and calculations for 2pq ions