Move out LaTeX utility code, and fix some double extensions while we're at it.