# Expanding electromagnetic field Lagrangian in terms of gauge field

The electromagnetic field tensor is given by $$F_{\mu \nu} = \partial_{\mu}A_{\nu} - \partial_{\nu}A_{\mu}$$, and it appears in the Lagrangian as $$L = -\frac{1}{4}F_{\mu\nu}^2 - A_{\mu}J_{\mu}.$$ Schwartz's QFT textbook says that (chapter 8, page 116) $$F_{\mu\nu}^2 = 2(\partial_{\mu}A_{\nu})^2 - 2(\partial_{\mu}A_{\mu})^2,$$ but I do not see how that is correct.

The first step of the expansion gives $$F_{\mu\nu}^2 = (\partial_{\mu}A_{\nu})^2 - \partial_{\mu}A_{\nu}\partial_{\nu}A_{\mu} - \partial_{\nu}A_{\mu}\partial_{\mu}A_{\nu} + (\partial_{\nu}A_{\mu})^2$$, and I see that the first and last term add up to produce $$2(\partial_{\mu}A_{\nu})^2$$. However, the second term $$\partial_{\mu}A_{\nu}\partial_{\nu}A_{\mu}$$ when expanded has a term like $$\partial_{0}A_{1}\partial_{1}A_{0}$$, and I don't see how this is present in $$(\partial_{\mu}A_{\mu})^2 = (\partial_{0}A_{0} + \partial_{1}A_{1} + \partial_{2}A_{2} + \partial_{3}A_{3})^2$$.

All of these quantities are underneath a $d^4x$ integral, since $S = \int d^4x\, \mathcal{L}$, so we can integrate by parts twice: $$(\partial_\mu A^\nu)(\partial_\nu A^\mu) = -A^\nu (\partial_\mu \partial_\nu A^\mu) = (\partial_\nu A^\nu)(\partial_\mu A^\mu) = (\partial_\mu A^\mu)^2.$$ So you can always swap the locations of two derivatives under an integral. For some discussion of how this process changes the field theory, see my question.