The partition function of a massless scalar field on a Euclidean spacetime manifold ℝd−1 × 𝕋2 and with momentum operator in the compact spatial dimension coupled through a purely imaginary chemical potential is computed. It is modular covariant and admits a simple expression in terms of a real analytic SL(2, ℤ) Eisenstein series with s = (d + 1)/2. Different techniques for computing the partition function illustrate complementary aspects of the Eisenstein series: the functional approach gives its series representation, the operator approach yields its Fourier series, while the proper time/heat kernel/world-line approach shows that it is the Mellin transform of a Riemann theta function. High/low temperature duality is generalized to the case of a non-vanishing chemical potential. By clarifying the dependence of the partition function on the geometry of the torus, we discuss how modular covariance is a consequence of full SL(2, ℤ) invariance. When the spacetime manifold is ℝp × 𝕋q+1, the partition function is given in terms of a SL(q + 1, ℤ) Eisenstein series again with s = (d + 1)/2. In this case, we obtain the high/low temperature duality through a suitably adapted dual parametrization of the lattice defining the torus. On 𝕋d+1, the computation is more subtle. An additional divergence leads to an harmonic anomaly.