Input Sources

Input Sources

Aspose.TeX FOSS for Python provides two input source classes: FileInputSource for reading TeX markup from disk, and StringInputSource for in-memory input.


FileInputSource

FileInputSource reads TeX markup from a file path:

from aspose_tex import TeXJob, TeXOptions, PdfDevice, FileInputSource

job = TeXJob(FileInputSource("document.tex"), PdfDevice(), options=TeXOptions())
pdf_bytes = job.run()

StringInputSource

StringInputSource accepts raw TeX markup as a Python string:

from aspose_tex import TeXJob, TeXOptions, PdfDevice, StringInputSource

tex = "Hello, world!"
job = TeXJob(StringInputSource(tex), PdfDevice(), options=TeXOptions())
pdf_bytes = job.run()

Tips and Best Practices

  • Use FileInputSource for existing .tex files on disk.
  • Use StringInputSource when generating TeX markup programmatically.
  • Both sources implement the InputSource abstract base class and are interchangeable as TeXJob constructor arguments.

API Reference Summary

ClassDescription
FileInputSourceRead TeX markup from a file path
StringInputSourceRead TeX markup from a Python string
InputSourceAbstract base class for input sources

See Also