A multi-band effective-mass Hamiltonian is derived for lattice-matched semiconductor nanostructures in a slowly varying external magnetic field. The theory is derived from the first-principles magnetic-field coupling Hamiltonian of Pickard and Mauri, which is applicable to nonlocal norm-conserving pseudopotentials in the local density approximation to density functional theory. The pseudopotential of the nanostructure is treated as a perturbation of a bulk reference crystal, with linear and quadratic response terms included in k.p perturbation theory. The resulting Hamiltonian contains several interface terms that have not been included in previous work on nanostructures in a magnetic field. The derivation provides the first direct analytical expressions showing how the coupling of the nonlocal potential to the magnetic field influences the effective magnetic dipole moment of the electron.