Alternative methods to supply main TeX input file | Python

Supplying the main input file to the TeX engine using a stream

So far, we have only learned how to provide the main input file to the TeX engine as a file name, whether in its full form or in a shortened form, with or without an extension. However, there is another constructor available in the TeXJob class that accepts a stream as the first argument. This is useful if, for some reason, the main input file is not in the form of a file on the disk file system. Here is an example of how it can be implemented:

1# Create conversion options instance.
2...
3# Create some device.
4...
5# Run LaTeX to XPS conversion.
6TeXJob(BytesIO(r"\documentclass{article} \begin{document} Hello, World! \end{document}".encode("ascii")),
7      XpsDevice(), options).run()

Note that all output files will be named texput. This is because the engine does not have access to any other name. texput is the default job name. You can find more detailed information about job names TeX output and How to set the job name paragraphs.

Inputting the main TeX input file through the terminal

There is one more constructor available in the TeXJob class that does not allow us to specify the input at all. You might be wondering what such a TeX job would process. In this case, we would need to use an input terminal. The TeX engine will prompt 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. When prompted, enter the /-separated path to the LaTeX file.
4TeXJob(XpsDevice(), options).run()

As soon as it’s run, the engine will pause and wait for us to input the file name (with or without a path, and with or without an extension):

Terminal Window

And here is how it would appear on the output terminal (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.