How does a thin gas uphold its emission spectrum? This question has been bothering me for many years and maybe I've been too embarassed to ask up until now. The reason why a thin atomic gas has an absorption spectrum has been explained to me by noting that the atoms absorb certain frequencies only and reemit the absorbed radiation in all directions. This explaines the effect for the usual experimental setup. 
However, I think the sun's spectral lines cannot be explained in this way. Assuming the direction of reemission is random would mean that most of the solid angle from an atom in the sun's atmosphere would be facing outwards. This would lead one to expect the intensity at the absorption lines to be only slightly weaker, while the lines are in reality quite pronounced. What mechanism explains this behaviour? 
Also what would be the emission spectrum of a thin atomic gas in thermal equilibrium? Would it have spectral lines? 
 A: A simple way to think about the Sun's absorption spectrum is to think of the solar atmosphere as a cool layer on top of something that is much hotter that is emitting blackbody radiation. (In reality it is more like a  smoothly varying continuum of layers, but this doesn't affect the argument).
A fraction of the blackbody photons are headed towards our spectrograph, but they have to get through the layer of cooler gas. Some of them are absorbed at particular wavelengths corresponding to atomic transitions and then re-emitted in all directions. Roughly half of the re-emission is directed outwards, but only a vanishingly small fraction of those re-emitted photons are in the original direction and thus we see an absorption line. However, other photons could be scattered into our line of sight from light that was not travelling in our direction originally. I think your confusion is over whether this compensates?
The answer is no, because the specific intensity of light emitted from the cooler overlying layer is much lower than that of light originating further in (it goes as $T^4$). So another way of looking at a spectral line is to imagine each wavelength originating at a particular depth (a gross simplification). The bottom of a spectral absorption line originates high up in the cooler part of the atmosphere, whilst the continuum originates in hotter interior layers.
An optically thin atomic gas would have an observed spectrum consisting of narrow emission lines. Exactly which lines and at what wavelengths depends what the gas is made of and its temperature and density.
