+ # Search for pdflatex executable
+ pdflatex = find_exe(["pdflatex"])
+ if pdflatex == None:
+ warning("Can't find pdflatex. Some pages failed with all the possible routes.")
+ failed_pages = []
+ else:
+ # Create a new LaTeX file from the original but only with failed pages
+ pdf_latex_file = latex_file_re.sub("_pdflatex.tex", latex_file)
+ filter_pages(latex_file, pdf_latex_file, failed_pages)
+
+ # pdflatex call
+ error_pages = []
+ pdflatex_status, pdflatex_stdout = run_latex(pdflatex, pdf_latex_file)
+ if pdflatex_status:
+ error_pages = check_latex_log(latex_file_re.sub(".log", pdf_latex_file))
+
+ pdf_file = latex_file_re.sub(".pdf", pdf_latex_file)
+ latex_file_root = latex_file_re.sub("", pdf_latex_file)
+
+ # Converter call to produce bitmaps
+ if use_pdftocairo:
+ conv_call = '%s -png -transp -r %d "%s" "%s"' \
+ % (conv, resolution, pdf_file, latex_file_root)
+ conv_status, conv_stdout = run_command(conv_call)
+ if not conv_status:
+ seqnum_re = re.compile("-([0-9]+)")
+ for name in glob.glob("%s-*.png" % latex_file_root):
+ match = seqnum_re.search(name)
+ if match != None:
+ new_name = seqnum_re.sub(str(int(match.group(1))), name)
+ os.rename(name, new_name)
+ else:
+ conv_call = '%s -dNOPAUSE -dBATCH -dSAFER -sDEVICE=%s ' \
+ '-sOutputFile="%s%%d.%s" ' \
+ '-dGraphicsAlphaBit=%d -dTextAlphaBits=%d ' \
+ '-r%f "%s"' \
+ % (conv, gs_device, latex_file_root, \
+ gs_ext, alpha, alpha, resolution, pdf_file)
+ conv_status, conv_stdout = run_command(conv_call)
+
+ if conv_status:
+ # Give up!
+ warning("Some pages failed with all the possible routes")
+ failed_pages = []
+ else:
+ # We've done it!
+ pdf_log_file = latex_file_re.sub(".log", pdf_latex_file)
+ pdf_metrics = legacy_extract_metrics_info(pdf_log_file)
+
+ # Invalidate metrics for pages that produced errors
+ if len(error_pages) > 0:
+ for index in error_pages:
+ pdf_metrics.pop(index - 1)
+ pdf_metrics.insert(index - 1, (index, -1.0))
+ error_count += 1
+
+ original_bitmap = latex_file_re.sub("%d." + output_format, pdf_latex_file)
+ destination_bitmap = latex_file_re.sub("%d." + output_format, latex_file)
+
+ # Join the metrics with the those from dvips and rename the bitmap images
+ join_metrics_and_rename(legacy_metrics, pdf_metrics, failed_pages,
+ original_bitmap, destination_bitmap)
+
+ return error_count
+
+
+# The file has been processed through latex and we expect dvi output.
+# Run dvips, taking note whether it was successful.