The Wittig reaction and related processes
In the Wittig reaction a phosphorus ylide reacts with an aldehyde or a ketone to give an alkene and triphenylphosphine oxide. The C=C double bond forms exactly where the C=O was, without the mixtures of regioisomers given by eliminations, and its geometry can be controlled by choosing the type of ylide.
Phosphorus ylides
An ylide is a species with a carbanion directly bonded to a positively charged heteroatom. Phosphorus ylides are prepared in two steps: triphenylphosphine, a good nucleophile, displaces a primary or secondary alkyl halide (SN2) to give a phosphonium salt; a strong base then removes the proton from the carbon bonded to phosphorus, which is acidic because the negative charge sits next to P+.

The ylide is usually written in the P=C double-bond form (a phosphorane), but it behaves like the dipolar form: the carbon is nucleophilic. The base required depends on the substituents on the carbon. Ylides bearing alkyl groups (non-stabilized) need n-BuLi, NaNH2 or NaHMDS and are very reactive; those with a conjugated electron-withdrawing group, such as an ester or a ketone (stabilized), form with weak bases, are often stable solids that can be bought, and react well with aldehydes but poorly with ketones.
Mechanism
The ylide and the carbonyl compound combine in a [2+2] cycloaddition that forms a four-membered ring containing phosphorus and oxygen, the oxaphosphetane. This intermediate fragments (a cycloreversion) into the alkene and triphenylphosphine oxide. The driving force of the whole reaction is the formation of the P=O bond, one of the strongest in organic chemistry (about 540 kJ/mol).

For a long time the first intermediate was proposed to be a betaine (the alkoxide with P+), which then closed to the oxaphosphetane. Low-temperature 31P NMR studies show that, in the absence of lithium salts, the oxaphosphetane forms directly; betaines are involved only when lithium stabilizes them.
Stereoselectivity
The geometry of the alkene is decided when the oxaphosphetane forms. With non-stabilized ylides the cycloaddition is fast and irreversible, and the most favourable transition state, in which the substituents point away from the phenyl groups on phosphorus, leads to the cis oxaphosphetane and the Z alkene, especially in the absence of lithium salts. With stabilized ylides the more stable trans oxaphosphetane forms, and the product is the E alkene.

If the E alkene is wanted from a non-stabilized ylide, the Schlosser modification can be used: the reaction is run at −78 °C with lithium salts, which stabilize the betaine; a second equivalent of phenyllithium is added, which deprotonates it to the β-oxido ylide; this equilibrates to the more stable trans form, and subsequent protonation and elimination give the E alkene.
The Horner–Wadsworth–Emmons reaction
The carbanions of phosphonates are more nucleophilic than stabilized ylides and also react with ketones. Phosphonates are prepared by the Arbuzov reaction: a trialkyl phosphite displaces an alkyl halide, and the intermediate phosphonium salt loses an alkyl group through attack by the halide. NaH or another base forms the carbanion, which gives almost exclusively the E alkene with an aldehyde. Another practical advantage is that the by-product, a dialkyl phosphate, is water-soluble and is removed by simple washing, whereas triphenylphosphine oxide usually requires chromatography.

In the Still–Gennari variant the ethoxy groups of the phosphonate are replaced by strongly electron-withdrawing 2,2,2-trifluoroethoxy groups. Elimination from the oxaphosphetane is accelerated so much that it occurs before the intermediates can equilibrate, and with a potassium base and a crown ether at −78 °C the Z alkene is obtained.
Review the basics in the Wittig reaction in Organic Chemistry made transparent. The reaction was described by Georg Wittig in 1953–1954; the phosphonate variant was introduced by Leopold Horner in 1958 and developed by William S. Wadsworth and William D. Emmons in 1961.