Aspose.TeX的输入接口| Python

有关 Aspose.TeX for Python 中 I/O 实现的正式定义,请查阅 API 参考

输入目录背后的想法

鉴于Tex语言的I/O元素只能处理文件名,aspose.tex for Python将目录定义为名称和数据集合之间的映射。这些数据集可以是文件,流,数组或任何其他类型。 API允许单独规范输入和输出工作目录。它提供了常规 InputWorkingDirectory类,用户可以为其特定需求实施。此外,API提供了内置的实现,将在后面讨论。该接口包括 get_file()方法,该方法可检索数据流并根据给定名称确定完整的文件名,该名称用作映射密钥。

从磁盘文件系统检索文件输入

这是我们将采用的方法:

1# Create conversion options instance.
2...
3# Specify a file system working directory for the input.
4options.input_working_directory = InputFileSystemDirectory(Utils.input_directory)

这种特殊的用例相当简单,因此我们现在可以从中继续前进。

从zip档案中检索文件输入

另一个选项是将输入文件存储在zip存档中,并将其视为输入目录。在这种情况下,应遵循以下步骤:

1# Open the stream for the ZIP archive that will serve as the input working directory.
2with open(path.join(Utils.input_directory, "zip-in.zip")) as in_zip_stream:
3    # Create conversion options instance.
4    ...
5    # Specify a ZIP archive working directory for the input. You can also specify a path inside the archive.
6    options.input_working_directory = InputZipDirectory(in_zip_stream, "in")

首先,我们创建包含zip文件的流。随后,在创建转换选项后,我们将 InputzipDirectory类的实例分配给 Input_working_directory属性。构造函数的第二个参数表示存档中的基本路径。如果我们希望整个存档作为输入目录,则应提供一个空字符串作为参数。

输入终端背后的想法

现在,让我们考虑终端输入的概念。 python的aspose.tex定义了用于此目的的常规 iinputterminal接口,其中包括一个单个属性,该属性返回 终端Rreader实现的实例。可用的实现将在稍后讨论。

从控制台获取终端输入

为了实现这一目标,我们需要将 InputConsoleterminal类的实例分配给 terminal_in选项。

1# Create conversion options instance.
2...
3# Specify the console as the input terminal.
4options.terminal_in = InputConsoleTerminal()  # Default. Arbitrary assignment.

但是,老实说,这是该选项的默认值,因此无需明确指定它。鉴于没有其他实施,本节纯粹是出于演示目的。

从理论上讲,如果我们具有具有可预测行为的交互式TEX文件(或脚本),则希望实现输入终端的版本,该版本包括一个相应的脚本来响应Tex Engine的请求。有机会时,请随时尝试一下!

Have any questions about Aspose.TeX?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.