LaTeX to XPS | Aspose.TeX for Python

Another target format is XPS. An XPS file is essentially a ZIP package that contains еру paginated content of a document, along with the necessary metadata for proper display by specific viewers (such as Windows XPS Viewer) and printing. The package consists of various files, some of which are binary and contain resources like images, fonts, and ICC profiles. Others are XML files in specific schemas, including files that contain the document data itself. The document data is divided into multiple files, with each file representing an individual page of the document. These files consist of a single page element and a tree of child elements, including Canvas, Path, and Glyphs. The Canvas element is a grouping element that can contain other Canvases, Paths, and Glyphs, and it controls the appearance of all child elements as a group. Path elements are used to define vector graphics paths, while Glyphs elements are used to define textual content. All three elements have properties that define various aspects of appearance.

There exists the Aspose.Page library, which offers an API for manipulating XPS documents and also enables the conversion of these documents to PDF and raster image formats.

Converting LaTeX to XPS

The process of converting LaTeX to XPS is equally straightforward, similar to the conversion to raster image formats. However, it requires setting the save_options to an instance of the XpsSaveOptions class (either by default or explicitly), and changing the device to an instance of the XpsDevice class.

1# Create conversion options instance.
2...
3# Initialize the options for saving in XPS format.
4so = XpsSaveOptions()
5options.save_options = so  # Default value. Arbitrary assignment.
6# Run LaTeX to XPS conversion.
7TeXJob(path.join(Util.input_directory, "sample.ltx"), XpsDevice(), options).run()

An alternative way to write the main output XPS file

There is an alternative constructor available for the XpsDevice class, which allows for obtaining the resulting XPS file in a different manner.

 1# Create the stream to write the XPS file to.
 2with open(path.join(Util.output_directory, "any-name.xps"), "wb") as xps_stream:
 3    # Create conversion options for Object LaTeX format upon Object TeX engine extension.
 4    options = TeXOptions.console_app_options(TeXConfig.object_latex)
 5    # Specify a file system working directory for the output.
 6    options.output_working_directory = OutputFileSystemDirectory(Util.output_directory)
 7    # Initialize the options for saving in XPS format.
 8    options.save_options = XpsSaveOptions()  # Default value. Arbitrary assignment.
 9    # Run LaTeX to XPS conversion.
10    TeXJob(path.join(Util.input_directory, "hello-world.ltx"), XpsDevice(xps_stream), options).run()

The effect is the same as we get here.

You can also explore the free web app for LaTeX-to-XPS conversion, which is developed using the Aspose.TeX for .NET API.

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.