Density functional theory in the canonical ensemble I General formalism - J. A. Hernando (2001)