We use density-functional theory to calculate the electronic density induce
d by a diatomic molecule in a free-electron gas, as well as the embedding e
nergy. We perform the calculations for two molecules, Hz and LM. We study t
he dependence of the results on parameters such as the internuclear distanc
e or the mean electronic density of the medium. We discuss the evolution of
the system as the medium electronic density is modified with the help of t
he induced density of levels. We show that the response of the medium is se
nsitive to the presence of an electric-dipole moment in the isolated molecu
le. The electron gas screens the interaction between the two centers of the
molecule, but can also play a role in transferring charge between them. We
show that the shape of the embedding energy variation can be related with
different types of molecular adsorption. [S0163-1829(99)02227-4].