Magnetic helicity in magnetohydrodynamic turbulence with a mean magnetic field