  This paper gives an introduction to the Keldysh formalism, with emphasis on
its usefulness in time-dependent density functional theory. In the first part
we introduce the Keldysh contour and the one-particle Green function defined on
this contour. We then discuss how to combine and manipulate functions with
time-arguments on the contour. The effects of electron-electron interaction can
be taken systematically into account, as we illustrate by propagating the
Kadanoff-Baym equations for the second-order self-energy approximation. It is
important to use conserving approximations such that the evolution of the
electron density, momentum, and total energy agrees with the macroscopic
conservation laws. One of the main topics in this paper is the non-interacting
Green function, which is the relevant quantity for time-dependent density
functional theory. We discuss this Green function in detail, and show how the
Keldysh contour in a simple way allows us to derive the time-dependent
Kohn-Sham potential from an action functional. The formalism in a similar way
leads to response functions that obey the causality principle. To illustrate
these points, we discuss the time-dependent optimized effective potential
equations.
