function to generate .tex