Distortion-free enhancement of terahertz signals measured by electro-optic sampling. I. Theory