Aspose.TeX's input interface | Python

For formal definitions of the I/O implementation in Aspose.TeX for Python, please consult the API reference.

The idea behind the input directory

Given that the I/O primitives of the TeX language can only handle file names, Aspose.TeX for Python defines a directory as a mapping between names and collections of data. These collections of data can be files, streams, arrays, or any other type. The API allows for separate specification of input and output working directories. It provides the general InputWorkingDirectory class, which users can implement for their specific needs. Additionally, the API provides built-in implementations, which will be discussed later. The interface includes the get_file() method, which retrieves the data stream and determines the full file name based on a given name, which serves as the mapping key.

Retrieving file input from the disk file system

Here is the approach we would take:

1# Create conversion options instance.
3# Specify a file system working directory for the input.
4options.input_working_directory = InputFileSystemDirectory(Utils.input_directory)

This particular use case is fairly straightforward, so we can move on from it now.

Retrieving file input from a ZIP archive

Another option is to store the input files in a ZIP archive and treat it as an input directory. In such a scenario, the following steps should be followed:

1# Open the stream for the ZIP archive that will serve as the input working directory.
2with open(path.join(Utils.input_directory, "")) as in_zip_stream:
3    # Create conversion options instance.
4    ...
5    # Specify a ZIP archive working directory for the input. You can also specify a path inside the archive.
6    options.input_working_directory = InputZipDirectory(in_zip_stream, "in")

To begin with, we create the stream that contains the ZIP file. Subsequently, after creating the conversion options, we assign an instance of the InputZipDirectory class to the input_working_directory property. The second parameter of the constructor represents the base path within the archive. If we desire the entire archive to function as the input directory, we should provide an empty string as the argument.

The idea behind the input terminal

Now let’s consider the concept of terminal input. Aspose.TeX for Python defines the general IInputTerminal interface specifically for this purpose, which includes a single property that returns an instance of TerminalReader implementation. The available implementations will be discussed later on.

Getting terminal input from the console

To achieve this, we need to assign an instance of the InputConsoleTerminal class to the terminal_in option.

1# Create conversion options instance.
3# Specify the console as the input terminal.
4options.terminal_in = InputConsoleTerminal()  # Default. Arbitrary assignment.

However, to be honest, this is the default value for the option, so there is no real need to explicitly specify it. Given the absence of other implementations, this section is purely for demonstration purposes.

In theory, if we have an interactive TeX file (or script) with predictable behavior, it might be desirable to implement a version of the input terminal that includes a corresponding script to respond to the TeX engine’s requests. Feel free to give it a try when you have the opportunity!

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.