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: Create a TeXJob with the Object LaTeX configuration, PdfSaveOptions and a PdfDevice. Set ASPOSE_TEX_INPUT_FILE to your input file and ASPOSE_TEX_OUTPUT_DIR to the output directory, or edit the default paths. Apply a license before conversion as described in Licensing.

 1# Convert LaTeX to PDF.
 2import os
 3from pathlib import Path
 4from aspose.tex import Interaction, TeXConfig, TeXJob, TeXOptions
 5from aspose.tex.io import InputFileSystemDirectory, OutputFileSystemDirectory, OutputMemoryTerminal
 6from aspose.tex.presentation.pdf import PdfDevice, PdfSaveOptions
 7
 8# Set these paths to your LaTeX document and output directory.
 9input_file = Path(os.environ.get("ASPOSE_TEX_INPUT_FILE", "hello-world.ltx")).resolve()
10output_dir = Path(os.environ.get("ASPOSE_TEX_OUTPUT_DIR", "output")).resolve()
11if not input_file.is_file():
12    raise FileNotFoundError(input_file)
13output_dir.mkdir(parents=True, exist_ok=True)
14
15# Use the Object LaTeX format and resolve additional inputs beside the main file.
16options = TeXOptions.console_app_options(TeXConfig.object_latex)
17options.input_working_directory = InputFileSystemDirectory(str(input_file.parent))
18options.output_working_directory = OutputFileSystemDirectory(str(output_dir))
19options.interaction = Interaction.NONSTOP_MODE
20options.terminal_out = OutputMemoryTerminal()
21options.save_options = PdfSaveOptions()
22device = PdfDevice()
23job_result = TeXJob(str(input_file), device, options).run()

The default output filename follows the input stem: hello-world.ltx produces hello-world.pdf. See LaTeX to PDF for details.

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, PngSaveOptions, SvgSaveOptions).

Q: How do I embed custom fonts into the generated PDF?

A: Fonts are selected by the TeX or LaTeX document and its packages. For package resources, see External LaTeX packages. To control whether only used glyphs are embedded, use the subset_fonts property of PdfSaveOptions; this is different from selecting a custom font. See Subsetting fonts for a complete XPS example using the same option.

Q: What LaTeX packages and classes are supported out of the box?

A: The library includes common LaTeX packages and classes. Consult the embedded package list for coverage. The external package example for pgfplots supplies its package sources externally through required_input_directory.

Q: How can I use a third‑party .sty or class file that is not built‑in?

A: Set TeXOptions.required_input_directory to an InputFileSystemDirectory containing the required package files. The complete example below loads fancybox.sty from ExternalLaTeXPackages/packages and converts required-input-fs.tex to PNG. Set ASPOSE_TEX_INPUT_DIR to the parent of ExternalLaTeXPackages (default: input) and ASPOSE_TEX_OUTPUT_DIR to the output folder (default: output). Apply a license first.

 1# Load an external LaTeX package from a directory.
 2import os
 3from pathlib import Path
 4from os import path
 5from io import BytesIO
 6from aspose.tex import Interaction, TeXConfig, TeXJob, TeXOptions
 7from aspose.tex.io import InputFileSystemDirectory, InputZipDirectory, OutputFileSystemDirectory, OutputMemoryTerminal
 8from aspose.tex.presentation.image import ImageDevice, PngSaveOptions
 9
10output_dir = Path(os.environ.get("ASPOSE_TEX_OUTPUT_DIR", "output")).resolve()
11output_dir.mkdir(parents=True, exist_ok=True)
12input_dir = Path(os.environ.get("ASPOSE_TEX_INPUT_DIR", "input")).resolve() / "ExternalLaTeXPackages"
13# Create conversion options for Object LaTeX format upon Object TeX engine extension.
14options = TeXOptions.console_app_options(TeXConfig.object_latex)
15options.interaction = Interaction.NONSTOP_MODE
16options.terminal_out = OutputMemoryTerminal()
17# Specify a file system working directory for the output.
18options.output_working_directory = OutputFileSystemDirectory(str(output_dir))
19# Specify a file system working directory for the required input.
20# The directory containing packages may be located anywhere.
21options.required_input_directory = InputFileSystemDirectory(path.join(str(input_dir), "packages"))
22# Initialize the options for saving in PNG format.
23options.save_options = PngSaveOptions()
24# Run LaTeX to PNG conversion.
25TeXJob(path.join(str(input_dir), "required-input-fs.tex"), ImageDevice(True), options).run()

For ZIP archives and package compatibility restrictions, see External LaTeX packages.

Q: What are the main limitations of the engine?

A:

LimitationDetails
Shell escape (\write18)Disabled for security.
Full TikZ externalizationNot supported; most TikZ graphics render in‑process, but extremely complex drawings may fail.
Unicode font coverageOnly 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 before using other Aspose.TeX classes. Set ASPOSE_TEX_PYTHON_NET_LICENSE_PATH to your license file, or place Aspose.TeX.Python-net.lic in the working directory:

 1# Apply a license from a file before using other Aspose.TeX classes.
 2import os
 3from aspose.tex import License
 4
 5# Set this environment variable, or place the license in the working directory.
 6license_path = os.environ.get(
 7    "ASPOSE_TEX_PYTHON_NET_LICENSE_PATH", "Aspose.TeX.Python-net.lic"
 8)
 9license = License()
10license.set_license(license_path)

For file, stream and metered examples and evaluation limitations, see Licensing.

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: Define page size and orientation in the LaTeX source. For example, save this A4 landscape document as landscape.ltx:

1\documentclass{article}
2\usepackage[a4paper,landscape]{geometry}
3\begin{document}
4Hello, World!
5\end{document}

Set PngSaveOptions.resolution before assigning the save options to the job. This example uses 300 DPI. Set ASPOSE_TEX_INPUT_FILE to landscape.ltx and ASPOSE_TEX_OUTPUT_DIR to your output directory, or use the example’s default paths:

 1# Convert an A4 landscape LaTeX document to PNG at 300 DPI.
 2import os
 3from pathlib import Path
 4from aspose.tex import Interaction, TeXConfig, TeXJob, TeXOptions
 5from aspose.tex.io import InputFileSystemDirectory, OutputFileSystemDirectory, OutputMemoryTerminal
 6from aspose.tex.presentation.image import ImageDevice, PngSaveOptions
 7
 8# Set these paths to your LaTeX document and output directory.
 9input_file = Path(os.environ.get("ASPOSE_TEX_INPUT_FILE", "landscape.ltx")).resolve()
10output_dir = Path(os.environ.get("ASPOSE_TEX_OUTPUT_DIR", "output")).resolve()
11if not input_file.is_file():
12    raise FileNotFoundError(input_file)
13output_dir.mkdir(parents=True, exist_ok=True)
14
15# Use the Object LaTeX format and resolve additional inputs beside the main file.
16options = TeXOptions.console_app_options(TeXConfig.object_latex)
17options.input_working_directory = InputFileSystemDirectory(str(input_file.parent))
18options.output_working_directory = OutputFileSystemDirectory(str(output_dir))
19options.interaction = Interaction.NONSTOP_MODE
20options.terminal_out = OutputMemoryTerminal()
21# Page size and orientation are defined in the LaTeX input (geometry package).
22# Set the raster resolution in dots per inch.
23save_options = PngSaveOptions()
24save_options.resolution = 300
25options.save_options = save_options
26device = ImageDevice(True)
27job_result = TeXJob(str(input_file), device, options).run()

The result is landscape.png, approximately 3508 by 2480 pixels.

Q: Can I render LaTeX directly from a string or an in‑memory stream?

A: Encode a complete LaTeX document into a binary BytesIO stream and pass it to TeXJob with TeXConfig.object_latex. Set ASPOSE_TEX_OUTPUT_DIR to the output folder, or use the default output. Apply a license first as described in Licensing.

 1# Render LaTeX supplied as a binary in-memory stream to XPS.
 2import os
 3from pathlib import Path
 4from aspose.tex import Interaction, TeXConfig, TeXJob, TeXOptions
 5from io import BytesIO
 6from aspose.tex.io import OutputFileSystemDirectory, OutputMemoryTerminal
 7from aspose.tex.presentation.xps import XpsDevice
 8
 9output_dir = Path(os.environ.get("ASPOSE_TEX_OUTPUT_DIR", "output")).resolve()
10output_dir.mkdir(parents=True, exist_ok=True)
11
12options = TeXOptions.console_app_options(TeXConfig.object_latex)
13options.interaction = Interaction.NONSTOP_MODE
14options.output_working_directory = OutputFileSystemDirectory(str(output_dir))
15options.terminal_out = OutputMemoryTerminal()
16latex_source = r"\documentclass{article} \begin{document} Hello, World! \end{document}"
17device = XpsDevice()
18with BytesIO(latex_source.encode("ascii")) as input_stream:
19    job_result = TeXJob(input_stream, device, options).run()

The example creates texput.xps and texput.log. See Other ways to provide main input for details.

Q: Where can I find official documentation, code samples, and support channels?

A: Check the next resources:

All examples are available in both Python and C#; the C# code can be directly translated thanks to pythonnet.