How to Use the TeX Engine in Python

How to Use the TeX Engine in Python

How to Use the TeX Engine in Python

TeXJob is the main entry point for the Aspose.TeX FOSS engine. It accepts an input source, an output device, and optional TeXOptions, then runs the typesetting pipeline when run() is called.

Typeset to PDF

from aspose_tex import TeXJob, TeXOptions, PdfDevice, StringInputSource

pdf_bytes = TeXJob(StringInputSource("Hello!"), PdfDevice(), options=TeXOptions()).run()
with open("output.pdf", "wb") as f:
    f.write(pdf_bytes)

Typeset to SVG

from aspose_tex import TeXJob, TeXOptions, SvgDevice, StringInputSource

device = SvgDevice()
TeXJob(StringInputSource("Hello!"), device, options=TeXOptions()).run()
for i, svg in enumerate(device.get_all_pages()):
    with open(f"page_{i}.svg", "wb") as f:
        f.write(svg)

Typeset to DVI

from aspose_tex import TeXJob, TeXOptions, DviDevice, StringInputSource

dvi_bytes = TeXJob(StringInputSource("Hello!"), DviDevice(), options=TeXOptions()).run()

See Also