Refactored code and added latex2pdf method.