Added a wait for tex output to be valid. Should fix race condition once and for all.