Theory of ionic ordering, crystal distortion, and magnetic exchange due to covalent forces in spinels