def buildPDF(self, bookPath, inputDirectory, outputPath): """ Build a PDF from the given a LaTeX book document. @type bookPath: L{FilePath} @param bookPath: The location of a LaTeX document defining a book. @type inputDirectory: L{FilePath} @param inputDirectory: The directory which the inputs of the book are relative to. @type outputPath: L{FilePath} @param outputPath: The location to which to write the resulting book. """ if not bookPath.basename().endswith(".tex"): raise ValueError("Book filename must end with .tex") workPath = FilePath(mkdtemp()) try: startDir = os.getcwd() try: os.chdir(inputDirectory.path) texToDVI = [ "latex", "-interaction=nonstopmode", "-output-directory=" + workPath.path, bookPath.path] # What I tell you three times is true! # The first two invocations of latex on the book file allows it # correctly create page numbers for in-text references. Why this is # the case, I could not tell you. -exarkun for i in range(3): self.run(texToDVI) bookBaseWithoutExtension = bookPath.basename()[:-4] dviPath = workPath.child(bookBaseWithoutExtension + ".dvi") psPath = workPath.child(bookBaseWithoutExtension + ".ps") pdfPath = workPath.child(bookBaseWithoutExtension + ".pdf") self.run([ "dvips", "-o", psPath.path, "-t", "letter", "-Ppdf", dviPath.path]) self.run(["ps2pdf13", psPath.path, pdfPath.path]) pdfPath.moveTo(outputPath) workPath.remove() finally: os.chdir(startDir) except: workPath.moveTo(bookPath.parent().child(workPath.basename())) raise
def buildPDF(self, bookPath, inputDirectory, outputPath): """ Build a PDF from the given a LaTeX book document. @type bookPath: L{FilePath} @param bookPath: The location of a LaTeX document defining a book. @type inputDirectory: L{FilePath} @param inputDirectory: The directory which the inputs of the book are relative to. @type outputPath: L{FilePath} @param outputPath: The location to which to write the resulting book. """ if not bookPath.basename().endswith(".tex"): raise ValueError("Book filename must end with .tex") workPath = FilePath(mkdtemp()) try: startDir = os.getcwd() try: os.chdir(inputDirectory.path) texToDVI = ["latex", "-interaction=nonstopmode", "-output-directory=" + workPath.path, bookPath.path] # What I tell you three times is true! # The first two invocations of latex on the book file allows it # correctly create page numbers for in-text references. Why this is # the case, I could not tell you. -exarkun for i in range(3): self.run(texToDVI) bookBaseWithoutExtension = bookPath.basename()[:-4] dviPath = workPath.child(bookBaseWithoutExtension + ".dvi") psPath = workPath.child(bookBaseWithoutExtension + ".ps") pdfPath = workPath.child(bookBaseWithoutExtension + ".pdf") self.run(["dvips", "-o", psPath.path, "-t", "letter", "-Ppdf", dviPath.path]) self.run(["ps2pdf13", psPath.path, pdfPath.path]) pdfPath.moveTo(outputPath) workPath.remove() finally: os.chdir(startDir) except: workPath.moveTo(bookPath.parent().child(workPath.basename())) raise