Aspose.TeX's output interface | C++
Please, refer to Aspose.TeX for C++ API reference for formal definitions of I/O implementation.
The concept of the output directory
Since I/O primitives of the TeX language can only deal with file names, Aspose.TeX 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 IOutputWorkingDirectory interface for the output, which the user can implement for their own purposes. It also provides its own implementations, which will be discussed below. The interface extends IInputWorkingDirectory, since the engine may first create and write a file, and then read it back. The interface’s own method GetOutputFile() returns the stream to write to, as opposed to the stream to read returned by GetFile().
Writing file output to the disk file system
As we mentioned above, the most common value for the OutputDirectory would likely be an instance of the OutputFileSystemDirectory class.
Here’s how we would set it:
1// Create conversion options instance.
2...
3// Specify a file system working directory for the output.
4options->set_OutputWorkingDirectory(System::MakeObject<OutputFileSystemDirectory>(RunExamples::OutputDirectory));
This use case is quite simple, so there’s no need to focus on it anymore.
Writing file output to a ZIP archive
We can also create a file (or stream) and let the TeX engine use it as a ZIP archive to store the output files. Here it is:
1 // Open the stream for the ZIP archive that will serve as the output working directory.
2 System::SharedPtr<System::IO::Stream> outZipStream = System::IO::File::Open(System::IO::Path::Combine(RunExamples::OutputDirectory, u"zip-pdf-out.zip"), System::IO::FileMode::Create);
3
4 // Create conversion options instance.
5 ...
6 // Specify a ZIP archive working directory for the output.
7 options->set_OutputWorkingDirectory(System::MakeObject<OutputZipDirectory>(outZipStream));
First, we create an output stream for the ZIP file. Then, after creating the conversion options, we set the OutputWorkingDirectory option to be an instance of the OutputZipDirectory class.
The concept of the output terminal
There’s another important part of the output — the terminal output. As for this one, Aspose.TeX for C++ defines the general IOutputTerminal interface having only one property that returns a TextWriter implementation instance. Provided implementations are discussed below.
Writing terminal output to the console
To do this, we need to set the TerminalOut option to be an instance of the OutputConsoleTerminal class.
1// Create conversion options instance.
2...
3// Specify the console as the output terminal.
4options->set_TerminalOut(System::MakeObject<OutputConsoleTerminal>()); // Default. No need to specify.
Again, this is the default value of the option, so there’s no real need to specify it. Due to this, this section serves only demonstration purposes.
Writing terminal output to a file
Unlike the input terminal, Aspose.TeX for C++ provides an implementation of the IOutputTerminal, which allows us to write the terminal output to a file in some output directory.
1// Create conversion options instance.
2...
3// Specify that the terminal output must be written to a file in the output working directory.
4// The file name is <job_name>.trm.
5options->set_TerminalOut(System::MakeObject<OutputFileTerminal>(options->get_OutputWorkingDirectory()));
Here we ask the TeX engine to write the terminal output to the file with the name <job_name>.trm, which will be stored in the same output directory that we specified for the rest of the output. But this is not necessary. We might as well pass any other instance of any implementation of IOutputTerminal to the constructor.