refactor latex converter code