Aspose.TeX's input interface | C++

Please, refer to Aspose.TeX for C++ API reference for formal definitions of I/O implementation.

The concept of the input directory

Since I/O primitives of the TeX language can only deal with file names, Aspose.TeX for C++ defines a directory as a mapping between names and bulks of data. The bulks of data are supposed to be files, streams, arrays, or whatever else.The API allows us to specify the input and output working directories separately. It provides the general IInputWorkingDirectory interface, which the user can implement for their own purposes. It also provides its own implementations, which will be discussed below. The interface defines the GetFile() method, which returns the data stream and determines the full name of the file, while taking some, hypothetically different, name as the first argument, which, in fact, is the mapping key.

Getting file input from the disk file system

Here’s how we would do it:

1// Create conversion options instance.
2...
3// Specify a file system working directory for input.
4options->set_InputWorkingDirectory(System::MakeObject<InputFileSystemDirectory>(RunExamples::InputDirectory));

This use case is quite simple, so there’s no need to focus on it anymore.

Getting file input from a ZIP archive

We can also put the input files in a ZIP archive and consider it an input directory. In this case, we should proceed as follows:

1    // Open a stream on a ZIP archive that will serve as the input working directory.
2    System::SharedPtr<System::IO::Stream> inZipStream = System::IO::File::Open(System::IO::Path::Combine(RunExamples::InputDirectory, u"zip-in.zip"), System::IO::FileMode::Open);
3
4    // Create conversion options instance.
5    ...
6    // Specify a ZIP archive working directory for input.
7    options->set_InputWorkingDirectory(System::MakeObject<InputZipDirectory>(inZipStream, u"in"));

First, we create the stream containing the ZIP file. Then, after creating the conversion options, we set the InputWorkingDirectory option to be an instance of the InputZipDirectory class. The second argument of the constructor is the base path inside the archive. If we want the entire archive to be an input directory, we should pass the empty string.

The concept of the input terminal

Now it’s time to remember that there is also the terminal input. As for this one, Aspose.TeX for C++ defines the general IInputTerminal interface having only one property that returns a TextReader implementation instance. Provided implementations are discussed below.

Getting terminal input from the console

To do this, we need to set the TerminalIn option to be an instance of the InputConsoleTerminal class.

1// Create conversion options instance.
2...
3// Specify the console as the input terminal.
4options->set_TerminalIn(System::MakeObject<InputConsoleTerminal>()); // Default. Not necessary to specify.

But, to tell you the truth, this is the default value of the option, so there’s no real need to specify it. :-) Due to this fact, and as long as there are no other implementations, this section serves only demonstration purposes.

Theoretically, if we have an interactive TeX file (or script) with predictable behavior, we may want to implement a version of the input terminal that would contain a complementary script for responding to the TeX engine’s requests. Try your hand when you have time!

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.