Added similar to original tex gen function.