Gauge invariant formulation of the interaction of electromagnetic radiation and matter