Duality and emergent gauge symmetry