Add export to latex function.

Also some reformating.