A refocusing pulse train consisting of a semiselective refocusing pulse and a selective inversion pulse to obtain a pure-phase refocusing at the frequency of maximal excitation of the semiselective refocusing pulse is proposed and applied to in vivo lactate and beta-hydroxybutyrate editing using difference spectroscopy. It is shown, using both rotation matrix theory and phantom experiments, that the soft inversion pulse has to be halved to flank the semiselective pulse to obtain perfect refocusing and cancellation of interfering resonances. The editing method is used to obtain lactate and beta-hydroxybutyrate spectra from the occipital cortex of juvenile epilepsy patients before and after ketogenic diet treatment.