Package atessera.comp

Class PdfLatex

java.lang.Object
atessera.comp.PdfLatex

public final class PdfLatex extends Object
Facade for compiling LaTeX documents to PDF using pdflatex.

This class encapsulates a three-pass pdflatex pipeline:

  1. First pass — resolves cross-references.
  2. Second pass — resolves table of contents and bibliography.
  3. Third pass — finalises all references and produces the definitive PDF.

All three passes run with --interaction=batchmode to suppress interactive prompts. The LaTeX source is written as main.tex in the working directory. Additional text files (e.g. code listings) and binary files (e.g. images) can be supplied alongside.

After a successful compilation the resulting PDF is available via getOutput(). On failure the contents of main.log are available via getLog().

See Also:
  • Constructor Details

    • PdfLatex

      public PdfLatex(Compiler compiler, List<String> source, Map<String,byte[]> images, Map<String,List<String>> listings)
      Constructs a new PdfLatex compilation facade.
      Parameters:
      compiler - the underlying Compiler to use; must not be null
      source - the LaTeX source as a list of lines; must not be null
      images - binary image files to include; keys are file names, values are raw bytes; must not be null
      listings - additional text files (e.g. code listings); keys are file names, values are lists of lines; must not be null
  • Method Details

    • compile

      public boolean compile()
      Runs the three-pass pdflatex pipeline.
      Returns:
      true if all three passes completed successfully and the PDF was produced; false otherwise
      Throws:
      IllegalStateException - if the compiler result is inconsistent (e.g. zero exit code but no PDF, or non-zero exit code but no log file)
    • getOutput

      public byte[] getOutput()
      Returns the compiled PDF document.
      Returns:
      the PDF as a byte array, or null if compilation has not been run or was unsuccessful
    • getLog

      public List<String> getLog()
      Returns the contents of main.log after a failed compilation.
      Returns:
      the log file as a list of lines, or null if the log was not captured (e.g. because compilation succeeded or has not been run)
    • getRawOutput

      public List<List<String>> getRawOutput()
      Returns the raw stdout captured from each command in the pipeline.
      Returns:
      an unmodifiable view of the captured stdout, or null before compilation
    • getRawErrorOutput

      public List<List<String>> getRawErrorOutput()
      Returns the raw stderr captured from each command in the pipeline.
      Returns:
      an unmodifiable view of the captured stderr, or null before compilation
    • getStackTrace

      public String getStackTrace()
      Returns the stack trace if an internal exception occurred during compilation.
      Returns:
      the stack trace as a string, or null if no exception was thrown