Other ways to provide main TeX input file | C++

Providing the main input file to the TeX engine as a stream

Up to this point, we only knew how to pass the main input file to the TeX engine as a file name, whether fully specified or in short form, whether with an extension or without it. But there’s another constructor of the TeXJob class, which takes a stream as the first argument. This is convenient if for some reason we have the main input file in a form other than a file on the disk file system. Here’s how it can be implemented:

1// Create conversion options instance.
2...
3// Create some device.
4...
5// Run LaTeX to XPS conversion.
6System::MakeObject<Aspose::TeX::TeXJob>(System::MakeObject<System::IO::MemoryStream>(System::Text::Encoding::get_ASCII()->GetBytes(
7    u"\\documentclass{article} \\begin{document} Hello, World! \\end{document}")), device, options)->Run();

Note that all output files will have the name texput. That’s because the engine can’t get any other name anywhere. texput is the default job name. Here and here are details about job names.

Entering the main TeX input file from the terminal

There’s yet another constructor of the TeXJob class, which doesn’t let us specify the input at all. So what is such a TeX job going to process, you may wonder? This time we will need an input terminal. The TeX engine will ask us to enter the file name from the terminal.

Here is the code:

1// Create conversion options instance.
2...
3// Run LaTeX to XPS conversion.
4System::MakeObject<Aspose::TeX::TeXJob>(System::MakeObject<XpsDevice>(), options)->Run();

As soon as it’s run, the engine sticks, waiting for us to enter the file name (with or without a path, with or without an extension):

Terminal window

And this is how it would look on the output terminal which is the console:

 1This is ObjectTeX, Version 3.1415926-1.0 (Aspose.TeX 21.8)
 2entering extended mode
 3**<path_to_the_file>/hello-world.ltx
 4(<path_to_the_file>/hello-world.ltx
 5LaTeX2e <2011/06/27>
 6(article.cls
 7Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
 8(size10.clo))
 9No file hello-world.aux.
10[1]
11(<output_directory>\hello-world.aux) )
12Output written on hello-world.xps (1 page).
13Transcript written on hello-world.log.

Have any questions about Aspose.TeX?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.