A Lagrangian formulation in magnetofluid dynamics