  In this paper we show how a Lagrangian variational principle can be used to
derive the SPMHD (smoothed particle magnetohydrodynamics) equations for ideal
MHD. We also consider the effect of a variable smoothing length in the SPH
kernels after which we demonstrate by numerical tests that the consistent
treatment of terms relating to the gradient of the smoothing length in the
SPMHD equations significantly improves the accuracy of the algorithm. Our
results complement those obtained in a companion paper (Price and Monaghan
2003a, paper I) for non ideal MHD where artificial dissipative terms were
included to handle shocks.
