Aspose.TeX的输入接口 | .NET
请参阅 Aspose.TeX for .NET 的 API 参考文档 以获取 I/O 实现的正式定义。
输入目录的概念
由于 TeX 语言的 I/O 原语只能处理文件名,Aspose.TeX for .NET 将目录定义为名称与数据块之间的映射。数据块可以是文件、流、数组或其他任何东西。API 允许我们分别指定输入和输出工作目录。它提供了通用的 IInputWorkingDirectory 接口,用户可以自行实现。它还提供了自己的实现,稍后将讨论。该接口定义了 GetFile() 方法,该方法返回数据流并确定文件的完整名称,同时将某个假设的不同名称作为第一个参数,该参数实际上是映射键。
从磁盘文件系统获取文件输入
下面是实现方式:
1// Getting file input from the disk file system
2
3// Create conversion options instance.
4TeXOptions options = TeXOptions.ConsoleAppOptions(TeXConfig.ObjectTeX());
5// ...
6// Specify a file system working directory for the input.
7options.InputWorkingDirectory = new InputFileSystemDirectory(DataDir);此用例相当简单,无需再作进一步说明。
从 ZIP 存档获取文件输入
我们也可以将输入文件放入 ZIP 存档,并将其视为输入目录。在这种情况下,应按以下步骤进行:
1// Getting file input from a ZIP archive
2
3// Open the stream for the ZIP archive that will serve as the input working directory.
4using (Stream inZipStream = File.Open(Path.Combine(DataDir, "zip-in.zip"), FileMode.Open))
5{
6 // Create conversion options instance.
7 TeXOptions options = TeXOptions.ConsoleAppOptions(TeXConfig.ObjectTeX());
8 // ...
9 // Specify a ZIP archive working directory for the input. You can also specify a path inside the archive.
10 options.InputWorkingDirectory = new InputZipDirectory(inZipStream, "in");首先,创建包含 ZIP 文件的流。随后,在创建转换选项后,我们将 InputWorkingDirectory 选项设置为 InputZipDirectory 类的实例。构造函数的第二个参数是存档内部的基路径。如果希望整个存档成为输入目录,则应传入空字符串。
输入终端的概念
现在需要提醒的是还有终端输入。针对该输入,Aspose.TeX for .NET 定义了通用的 IInputTerminal 接口,该接口仅包含一个返回 TextReader 实例的属性。下面将讨论提供的实现。
从控制台获取终端输入
为此,需要将 TerminalIn 选项设置为 InputConsoleTerminal 类的实例。
1// Getting terminal input from the console
2
3// Create conversion options instance.
4TeXOptions options = TeXOptions.ConsoleAppOptions(TeXConfig.ObjectTeX());
5// ...
6// Specify the console as the input terminal.
7options.TerminalIn = new InputConsoleTerminal(); // Default. Arbitrary assignment.但说实话,这正是该选项的默认值,因此实际上无需显式指定。鉴于此,并且目前没有其他实现,此章节仅用于演示目的。
理论上,如果我们拥有具有可预测行为的交互式 TeX 文件(或脚本),可以实现一个输入终端的版本,用于响应 TeX 引擎请求的补充脚本。有时间可以尝试一下!