display information when failed to generate pdf

Save output of pdflatex into a file so that it can be dumped when the
generation of the pdf fails.