  We present a derivation of the cosmological distance-redshift relation up to
second order in perturbation theory. In addition, we find the observed redshift
and the lensing magnification to second order. We do not require that the
density contrast is small, we only that the metric potentials and peculiar
velocities are small. Thus our results apply into the nonlinear regime, and can
be used for most dark energy models. We present the results in a form which can
be readily computed in an N-body simulation. This paper accompanies
arXiv:1207.2109, where the key results are summarised in a physically
transparent form and applications are discussed.
