  Duality is an indispensable tool for describing the strong-coupling dynamics
of gauge theories. However, its actual realization is often quite subtle:
quantities such as the partition function can transform covariantly, with
degrees of freedom rearranged in a nonlocal fashion. We study this phenomenon
in the context of the electromagnetic duality of abelian $p$-forms. A careful
calculation of the duality anomaly on an arbitrary $D$-dimensional manifold
shows that the effective actions agree exactly in odd $D$, while in even $D$
they differ by a term proportional to the Euler number. Despite this anomaly,
the trace of the stress tensor agrees between the dual theories. We also
compute the change in the vacuum entanglement entropy under duality, relating
this entanglement anomaly to the duality of an "edge mode" theory in two fewer
dimensions. Previous work on this subject has led to conflicting results; we
explain and resolve these discrepancies.
