Is Maxwell theory gauge invariant on non-trivial manifolds? I've done my share of QFT, but as a mostly condensed matter person I'm unfamiliar with any discussion of how the gauge invariance of Maxwell theory might depend on the manifold which it's defined on. I imagine this has been discussed somewhere but I can't find any clear discussions online.
My question is the following: we know that the Maxwell Lagrangian with sources is
$$\mathcal{L}_{M} = -\frac{1}{4}F^{\mu\nu}F_{\mu\nu}-A_{\mu}J^{\mu}$$
The resulting equations of motion are of course
$$\partial_{\mu}F^{\mu\nu}=J^{\nu} \Rightarrow \partial_{\nu}J^{\nu}=0$$
Under a gauge transformation $A_{\mu}\rightarrow A_{\mu}+\partial_{\mu}\Lambda$, the field strength is invariant, so we have
$$\mathcal{L}_{M}'=\mathcal{L}_{M}-\left(\partial_{\mu}\Lambda\right)J^{\mu} = \mathcal{L}_{M}-\partial_{\mu}\left(\Lambda J^{\mu}\right)$$
The usual story is that this is a total derivative, so we don't need to worry about it if the boundary terms behave nicely at infinity. But what if we define our theory on, say, a sphere with finite extent? Then what happens? It seems that the story has to be modified, much as the discussion of gauge invariance in Chern-Simons theory becomes somewhat delicate. Can someone point me to a reference discussing this, or perhaps say what's wrong with my logic? I've never heard discussion of this point which seems odd to me.
 A: Maxwellian, and indeed arbitary Yang-Mills, gauge theory is indeed gauge invariant on all manifolds $M$. One may write the action in a manifestly geometric way as
$$ S[A] = \int_M \mathrm{tr}(F\wedge{\star} F) + \mathrm{tr}(A\wedge{\star}j)$$
and $F = \mathrm{d}A + A\wedge A$, so no replacement of ordinary derivatives by covariant derivatives is necessary anywhere (recall that the exterior derivative $\mathrm{d}$ and the wedge products $\wedge$ are always properly covariant because the antisymmetrization in their definition kills off the symmetric terms spoiling covariance for an ordinary derivative $\partial_\mu A$).
Now, a gauge transformation is $A\mapsto gAg^{-1} + g^{-1}\mathrm{d}g$, inducing $F\mapsto gFg^{-1}$, so the kinetic term is gauge invariant, and the coupling term behaves as
$$ A\wedge{\star}j\mapsto gAg^{-1} \wedge g{\star}jg^{-1} + g^{-1}\mathrm{d}g\wedge{\star}j$$
Writing $g^{-1}\mathrm{d}g = \mathrm{d}\chi$ for $g =\exp(\chi)$, we remain with checking that
$$ \int_M \mathrm{d}\chi\wedge{\star}j = \int_M \mathrm{d}(\chi\wedge{\star}j) - \int_M \chi\wedge\mathrm{d}{\star}j$$
vanishes, which it indeed does: The first term vanishes by Stokes' theorem and the fact that manifolds have no boundary, the second because the conserved current has vanishing divergence, and $\mathrm{d}{\star}j$ is just the divergence of the current.
Non-trivial topology of the manifold can have interesting effects (e.g. Aharonov-Bohm effect), but never spoils gauge invariance.
A: The obvious generalisation to curved spacetime is $F_{\mu\nu}=\nabla_\mu A_\nu-\nabla_\nu A_\mu$, but in a torsion-free theory such as general relativity the Christoffel symbols cancel, giving the usual formula with $\partial$ and hence the usual gauge invariance. Note that if a transformation effects $\delta S = \int d^n x \partial_\mu V^\mu$ in $n$-dimensional Minkowski spacetime then the general case multiplies the integration measure by $\sqrt{|g|}$ and replaces the $\partial $ with $\nabla$, giving $$\delta S = \int d^n x \sqrt{|g|}\nabla_\mu V^\mu = \int d^n x \partial_\mu \left( \sqrt{|g|} V^\mu\right),$$ which is still an integral of a total derivative.
