Other ways to provide main TeX input file | Java

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 accepts 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 we can deal with it:

1// Create conversion options instance.
2...
3// Create some device.
4...
5// Run LaTeX to XPS conversion.
6new TeXJob(new ByteArrayInputStream(
7    "\\documentclass{article} \\begin{document} Hello, World! \\end{document}".getBytes("ASCII")),
8           new XpsDevice(), 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. See here and here for 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 allow us to 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.
4new TeXJob(new XpsDevice(), options).run();

As soon as it is 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.
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.