Improved latex parsing