提供主Tex输入文件的替代方法| Python

使用流向Tex发动机提供主要输入文件

到目前为止,我们只学会了如何将 主输入文件作为文件名提供给Tex引擎,无论是完整的形式还是以缩短形式,有或没有扩展名。但是, Texjob类中可用 另一个构造函数接受流作为第一个参数。如果出于某种原因,主输入文件不在磁盘文件系统上的文件形式。这是如何实现它的示例:

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()

请注意,所有输出文件将命名为“ Texput”。这是因为该引擎无法访问任何其他名称。 texput是默认的作业名称。您可以找到有关作业名称 TEX输出如何设置作业名称段落的更多详细信息。

通过终端输入主Tex输入文件

Texjob类中有 另一个构造函数,它根本不允许我们指定输入。您可能想知道这样的Tex工作会发生什么。在这种情况下,我们需要使用输入终端。 TEX引擎将提示我们从终端输入文件名。

这是代码:

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()

运行后,引擎将暂停并等待我们输入文件名(有或没有路径,以及或不带扩展名):

终端窗口

这是输出终端(控制台)上显示的方式:

 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.