  We investigate the interplay between the enumerative geometry of Calabi-Yau
fourfolds with fluxes and the modularity of elliptic genera in four-dimensional
string theories. We argue that certain contributions to the elliptic genus are
given by derivatives of modular or quasi-modular forms, which encode BPS
invariants of Calabi-Yau or non-Calabi-Yau threefolds that are embedded in the
given fourfold. As a result, the elliptic genus is only a quasi-Jacobi form,
rather than a modular or quasi-modular one in the usual sense. This manifests
itself as a holomorphic anomaly of the spectral flow symmetry, and in an
elliptic holomorphic anomaly equation that maps between different flux sectors.
We support our general considerations by a detailed study of examples,
including non-critical strings in four dimensions. For the critical heterotic
string, we explain how anomaly cancellation is restored due to the properties
of the derivative sector. Essentially, while the modular sector of the elliptic
genus takes care of anomaly cancellation involving the universal B-field, the
quasi-Jacobi one accounts for additional B-fields that can be present. Thus
once again, diverse mathematical ingredients, namely here the algebraic
geometry of fourfolds, relative Gromow-Witten theory pertaining to flux
backgrounds, and the modular properties of (quasi-)Jacobi forms, conspire in an
intriguing manner precisely as required by stringy consistency.
