Refactoring latex.sh