Aspose TeX for Python – FAQ
Q: What is Aspose TeX for Python?
A: Aspose TeX for Python is a pure‑Python API (built on top of the Aspose TeX .NET library via pythonnet) that renders and converts LaTeX/TeX documents to PDF, XPS, SVG, PNG, JPEG, BMP, TIFF and other image formats without requiring any external TeX distribution. It runs in‑process and is suited for web services, desktop apps, and automated report generators.
Q: How do I install Aspose TeX for Python?
A: Run pip install aspose-tex-python-net. The package bundles the required pythonnet runtime automatically. Install it inside any virtual environment (Windows, Linux, macOS) with Python 3.8 or later. Verify the installation with:
1import aspose.tex as tex
2print(tex.__version__)Q: Do I need a local TeX distribution (MiKTeX, TeX Live, etc.)?
A: No. All parsing and rendering logic is built into Aspose TeX, so you never need an external TeX engine. The library includes over 300 core LaTeX packages and common class files out of the box.
Q: How can I convert a .tex file to PDF with a few lines of code?
A:
1import aspose.tex as tex
2
3doc = tex.Document("sample.tex") # load LaTeX source
4doc.save("sample.pdf", tex.SaveFormat.PDF) # write PDFYou can also create a document from a string (tex.Document(latex_source)) or an in‑memory stream.
Q: Which output formats can Aspose TeX for Python generate?
A: PDF, XPS, SVG, PNG, JPEG, BMP, and TIFF. Each format can be controlled via specific SaveOptions objects (e.g., PdfSaveOptions, ImageSaveOptions, SvgSaveOptions).
Q: How do I embed custom fonts into the generated PDF?
A: Register a custom font folder before rendering:
1font_src = tex.FontSource()
2font_src.add_folder(r"C:\MyFonts") # or "/home/user/fonts"
3tex.FontSettings.set_default_sources([font_src])
4doc.save("out.pdf", tex.PdfSaveOptions())By default all used fonts are embedded; disable embedding with PdfSaveOptions.embed_fonts = False.
Q: What LaTeX packages and classes are supported out of the box?
A: More than 300 core packages (e.g., amsmath, graphicx, hyperref, xcolor, tikz, pgfplots, booktabs) and common classes (article, report, book, memoir).
Q: How can I use a third‑party .sty or class file that is not built‑in?
A: Place the .sty/.cls file in the same directory as the source document or add its folder to the document’s resource loaders:
1doc = tex.Document("mydoc.tex")
2doc.resource_loaders.append(tex.FolderResourceLoader(r"C:\MyLatexPackages"))The engine will load the custom files automatically on the next conversion.
Q: What are the main limitations of the engine?
A:
| Limitation | Details |
|---|---|
Shell escape (\write18) | Disabled for security. |
| Full TikZ externalization | Not supported; most TikZ graphics render in‑process, but extremely complex drawings may fail. |
| Unicode font coverage | Only TrueType/OpenType fonts with complete glyph sets are fully supported; legacy Type 1 fonts may need conversion. |
| Very large documents (> 500 pages) | Can consume significant memory; consider streaming pages with Document.save(output_stream, options). |
Q: How do I apply a license key and what licensing models are available?
A: Apply the license once per process:
1import aspose.tex as tex
2tex.License().set_license("Aspose.Total.NET.lic")Licensing options: Free Trial (10‑page limit, no watermark), Developer/Single‑Machine (unlimited pages on one machine), Enterprise/Multi‑Seat (unlimited across organization with priority support).
Q: Is the library thread‑safe for parallel conversions?
A: Yes, provided each thread creates its own Document instance. Static objects such as the License must be set before any parallel work starts.
Q: Which .NET runtime version does Aspose TeX for Python require?
A: The package ships with the .NET 6 (x64) runtime binaries. They are loaded automatically by pythonnet on the first import; you do not need to install .NET manually.
Q: How can I set page size, orientation, and DPI for raster outputs?
A: Use the PageSetup and ImageSaveOptions objects:
1doc.page_setup.size = tex.PageSize.A4
2doc.page_setup.orientation = tex.PageOrientation.LANDSCAPE
3
4opts = tex.ImageSaveOptions()
5opts.dpi = 300
6doc.save("out.png", opts)Q: Can I render LaTeX directly from a string or an in‑memory stream?
A: Absolutely. Pass the LaTeX source string to the constructor or use a io.BytesIO stream:
1src = r"\section{Hello}\textbf{World}"
2doc = tex.Document(src) # from string
3# or
4stream = io.BytesIO(src.encode())
5doc = tex.Document(stream) # from streamQ: Where can I find official documentation, code samples, and support channels?
A: Check the next resources:
- Official Documentation
- Getting Started Guide
- Code Samples & GitHub Gists
- Support Forum
- Issue Tracker (private for customers) - Provided after purchase
All examples are available in both Python and C#; the C# code can be directly translated thanks to pythonnet.