refactor latex backend
refactor pdf backend
some other improvements in pdf backend