A mathematical approach to electromagnetism