Transferred code across from TexSynth_