Added export to latex and fixed some bugs