Aspose.TeX FOSS for Python
Aspose.TeX FOSS for Python is a free, open-source, pure-Python library for TeX/LaTeX processing. It parses real TeX/LaTeX source through its own from-scratch interpreter and produces PDF, DVI, and SVG output, with no external TeX installation required — Computer Modern fonts ship bundled inside the package.
Navigation
- At a Glance
- Key Capabilities
- Installation
- Dependencies
- Quick Start
- Additional Examples
- API Reference
- Documentation & Resources
- Scope and Limitations
- Development and Testing
- License
At a Glance
flowchart TD
subgraph StartingPoints["Starting Points"]
direction TB
i1["A plain-text document (TeX/LaTeX source, from a path, string, or bytes)"]
end
PRODUCT["Aspose.TeX FOSS for Python"]
subgraph Capabilities["Core Capabilities"]
direction TB
c1["Tokenize and interpret TeX/LaTeX input"]
c2["Resolve fonts and glyph metrics"]
c3["Build lines and pages from typeset boxes"]
c4["Write PDF, DVI, or SVG output"]
end
subgraph Outputs["Outputs"]
direction TB
o1["PDF document (file path or in-memory bytes)"]
o2["DVI document (file path or in-memory bytes)"]
o3["SVG document (file path or in-memory bytes, multi-page)"]
end
StartingPoints --> PRODUCT --> Capabilities --> Outputs
Key Capabilities
- Parse and interpret real TeX/LaTeX source through
TeXJob, driving the tokenizer, macro expander, and mode-machine dispatch that process control sequences, groups, and paragraph text. - Resolve font metrics and glyph outlines from the bundled Computer Modern
.tfm/.pfbdata, independent of the output format a job targets. - Build lines and pages from typeset boxes with a real line-breaking and page-building pipeline,
then hand each finished page to an
OutputDevice. - Write finished pages through
PdfDevice,DviDevice, orSvgDevice— pass aPathfor file output, or leave the destination empty for in-memorybytes. SvgDeviceembeds glyph outlines straight from the bundled Computer Modern PFB fonts as<path>elements, so the rendered SVG needs no external fonts;get_all_pages()returns every page of a multi-page document as a list of byte strings.- Configure a job with
TeXOptions— job name, magnification, andextra_format_paths, which is searched after the bundled format data and before the current working directory for\inputfiles. - Collect run diagnostics via
TeXJob.messages, which returns a copy of the messages collected during the most recent run:\messageand\write 16append plain-text entries,\errmessageprefixes them with!, and\write -1logs through the standardaspose_texlogger without appearing in the returned list.
Installation
Requirements: Python 3.10+.
Install the package from PyPI:
pip install aspose-tex-foss
The package is imported as aspose_tex. To run the MCP server, install the mcp extra and start
it with python -m aspose_tex.mcp:
pip install "aspose-tex-foss[mcp]"
From source (contributors)
git clone https://github.com/aspose-tex-foss/Aspose.TeX-FOSS-for-Python.git
cd Aspose.TeX-FOSS-for-Python
pip install -e ".[dev]"
The dev extra adds pytest, ruff, build, and twine.
Dependencies
Required Package Dependencies
No required third-party package dependencies. The published aspose-tex-foss package declares
no runtime dependencies; the optional mcp extra installs the mcp package.
Native and System Requirements
- Requires Python 3.10 or later (
requires-python = ">=3.10").
Development Dependencies
pytest(>=7.4),ruff(>=0.4),build(>=1.2), andtwine(>=5.0) — the test runner, linter, and packaging/publishing tools used for development;tomli(>=2.0) is an additional dev dependency on Python versions before 3.11. None of these are required to use the library itself.
Quick Start
from aspose_tex import TeXJob, TeXOptions, PdfDevice, create_input_source
source = create_input_source("Hello World\n\\bye")
device = PdfDevice()
job = TeXJob(source, device, options=TeXOptions(load_format=False))
pdf_bytes = job.run()
create_input_source accepts a Path, a str, or bytes. Pass a Path to PdfDevice instead
of leaving it empty to write straight to disk — run() then returns None and the file holds the
output:
from pathlib import Path
from aspose_tex import TeXJob, TeXOptions, PdfDevice, create_input_source
source = create_input_source("Hello World\n\\bye")
device = PdfDevice(Path("hello.pdf"))
job = TeXJob(source, device, options=TeXOptions(load_format=False))
job.run() # hello.pdf is written to disk
Additional Examples
View Additional Code Examples
DVI Output
from aspose_tex import TeXJob, TeXOptions, DviDevice, create_input_source
source = create_input_source("Hello World\n\\bye")
device = DviDevice()
job = TeXJob(source, device, options=TeXOptions(load_format=False))
dvi_bytes = job.run()
DVI can also be written directly to a file instead of into memory:
from pathlib import Path
from aspose_tex import TeXJob, TeXOptions, DviDevice, create_input_source
source = create_input_source("Hello World\n\\bye")
device = DviDevice(Path("hello.dvi"))
job = TeXJob(source, device, options=TeXOptions(load_format=False))
job.run() # returns None; output is on disk
SVG Output
from aspose_tex import TeXJob, TeXOptions, SvgDevice, create_input_source
source = create_input_source("Hello World\n\\bye")
device = SvgDevice()
job = TeXJob(source, device, options=TeXOptions(load_format=False))
svg_bytes = job.run() # UTF-8 encoded SVG 1.1 document
Writing to a file path picks the file name automatically (hello.svg, or hello-1.svg /
hello-2.svg for a multi-page document):
from pathlib import Path
from aspose_tex import TeXJob, TeXOptions, SvgDevice, create_input_source
source = create_input_source("Hello World\n\\bye")
device = SvgDevice(Path("output/hello"))
job = TeXJob(source, device, options=TeXOptions(load_format=False))
job.run() # writes output/hello.svg
A multi-page document run in memory returns one SVG byte string per page:
from aspose_tex import TeXJob, TeXOptions, SvgDevice, create_input_source
source = create_input_source("Page one\n\\eject\nPage two\n\\bye")
device = SvgDevice()
job = TeXJob(source, device, options=TeXOptions(load_format=False))
job.run()
pages = device.get_all_pages() # list[bytes], one SVG per page
Job Options
from aspose_tex import TeXJob, TeXOptions, PdfDevice, create_input_source
opts = TeXOptions(job_name="hello", magnification=1200, load_format=False)
source = create_input_source("Hello World\n\\bye")
device = PdfDevice()
job = TeXJob(source, device, options=opts)
pdf_bytes = job.run()
Messages and Logging
from pathlib import Path
from aspose_tex import TeXJob, TeXOptions, DviDevice, create_input_source
opts = TeXOptions(load_format=False, extra_format_paths=[Path("tex-inputs")])
source = create_input_source("\\input chapter1\n\\bye")
job = TeXJob(source, DviDevice(), options=opts)
dvi_bytes = job.run()
messages = job.messages
The extra_format_paths option above is searched after the bundled format data and before the
current working directory when resolving \input files. To see log output from the engine (the
package attaches only a logging.NullHandler by default):
import logging
logging.basicConfig(level=logging.INFO)
logging.getLogger("aspose_tex").setLevel(logging.INFO)
API Reference
The primary entry point is TeXJob, which combines an InputSource, an OutputDevice
(PdfDevice, DviDevice, or SvgDevice), and TeXOptions into one runnable job.
View the Core API Surface
Core API
| Class | Description |
|---|---|
AsposeTeXError |
Base exception for all aspose_tex errors. |
EngineError |
Raised for TeX engine errors (infinite recursion, undefined register, etc.). |
FontError |
Raised for font-related failures (TFM not found, corrupt file, invalid char, etc.). |
InputError |
Raised for input reading failures (file not found, stack underflow, etc.). |
Presentation
| Class | Description |
|---|---|
DviDevice |
DVI output device — wraps DviWriter. |
OutputDevice |
Abstract base class for all output devices. |
PdfDevice |
PDF output device — wraps PdfWriter. |
SvgDevice |
SVG output device — wraps SvgWriter. |
TeXJob |
Main entry point for processing TeX input. |
TeXOptions |
Configuration for a TeX processing job — job name, magnification, and font/format search paths. |
Enumerations
| Enumeration | Description |
|---|---|
OutputFormat |
Supported output formats: DVI, PDF, SVG. |
Detailed Member Reference
Processing
TeXJobTeXJob(source, device, options=None)run() -> bytes | Nonemessages -> list[str]
TeXOptionsjob_name: str = "texput"magnification: int = 1000extra_font_paths: list[Path]load_format: bool | str | None = "plain"extra_format_paths: list[Path]
Output Devices
OutputDevicedestination -> Path | io.BytesIOfinalize()get_bytes() -> bytes | None
PdfDevice(destination=None)DviDevice(destination=None)SvgDevice(destination=None)get_all_pages() -> list[bytes] | None
Input Sources
create_input_source(source)— factory returning aFileInputSourceorStringInputSourcefrom aPath,str, orbytes.
Exceptions
AsposeTeXError— base exception for the package.InputErrorEngineErrorFontError
Documentation & Resources
- Getting started guide — installation, walkthroughs, and feature guides for this library.
- How-to guides & FAQ — task-focused answers for common TeX/LaTeX-processing questions.
- Full API reference — the complete, browsable reference for the public API surface (the API reference section above covers the essentials).
- Found a bug or have a feature request? Open an issue on GitHub.
Scope and Limitations
- This is a Pre-Alpha release: the core engine and public API are under active development, and interfaces may change between releases.
- Plain TeX is the supported format. The default
load_format="plain"option (TeXOptions) loads Knuth's macros from the bundledplain.tex, with its output routine, footnotes, and inserts. The examples above passload_format=Falseto run a document from primitives alone; leave it out to use the plain macros. - LaTeX and the e-TeX and pdfTeX extensions are not implemented yet.
\documentclass,\numexpr,\pdfoutput, and similar commands raiseEngineError. \specialis not implemented and raisesEngineErroras an undefined control sequence.- Automatic hyphenation needs the plain format, which loads the bundled US-English patterns from
format/hyphen.tex. Withload_format=Falseno patterns are loaded. Other languages are added the TeX way: a format file onextra_format_pathssets\languageand runs\patternsand\hyphenation. The bundledhyphenation/directory is reserved and empty. - Named file-stream I/O (
\openin,\openout,\closein,\closeout,\read, and\writeto streams 0 through 15) raisesNotImplementedError— only\write 16(message log),\write -1(silent log),\message, and\errmessageare implemented;\ifeofalways evaluates false.\writetakes effect at once, not at shipout.
These limitations don't apply to Aspose.TeX for Python — Enterprise Edition, which adds full feature completeness, broader format coverage, and commercial support.
Development and Testing
Install the development extras and run the test suite:
pip install -e ".[dev]"
pytest
About 180 test modules cover the tokenizer, macro expander, box and page builder, font subsystem, and
each output writer, including an automated end-to-end suite that compiles fixture documents
through the public TeXJob API and compares the result against committed MiKTeX-generated DVI
baselines — semantically (page count, glyph stream, line and rule positions, font metadata), not
byte-for-byte, so the suite has no MiKTeX dependency at test time. Lint with:
ruff check .
The package registers a logging.NullHandler on the aspose_tex logger, so integrating
applications can opt into standard Python logging without unexpected default-handler warnings.
License
This project is licensed under the MIT License. The MIT License permits use, copying, modification, distribution, sublicensing, and commercial use, provided its copyright and permission notice are retained. The software is provided without warranty.
Bundled Computer Modern fonts are covered separately — see the font license file.
Metadata
Release files for aspose-tex-foss 26.11.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| aspose_tex_foss-26.11.1-py3-none-any.whl | Python 3 | none | any | Details for aspose_tex_foss-26.11.1-py3-none-any.whl |
Release files / aspose_tex_foss-26.11.1-py3-none-any.whl
| Download URL | aspose_tex_foss-26.11.1-py3-none-any.whl |
|---|---|
| Size | 2.1 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c5c4207c48b4243dd06c7f5d64f49ce7b5214fa84bbb3408359914719fec47bd
|
|
BLAKE2b-256 checksum How to use checksums |
d9da8c778361aeb69e46219b03804b9d0e78a4dd376b97bf62b54557b7fb2b8f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.6
|
Security for aspose-tex-foss 26.11.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.