其他TEX转换输出格式| .NET的Aspose.TeX
您目前不太可能要转换以除乳胶以外的任何其他格式编写的TEX文件。但是,如果您出于某种原因正在学习Tex语言和/或内部语言,这是可能的。无论如何,Aspose.TeX for .NET允许您转换以普通Tex格式编写的文件。它还使您可以创建以这些格式设计的自定义格式和排版文档。
我们将从创建自定义格式开始。
创建自定义格式
让我们记住,格式文件是Tex发动机内部状态的二进制文件。
1// Create TeX engine options for no format upon ObjectTeX engine extension.
2TeXOptions options = TeXOptions.ConsoleAppOptions(TeXConfig.ObjectIniTeX);
3// Specify a file system working directory for the input.
4options.InputWorkingDirectory = new InputFileSystemDirectory(RunExamples.InputDirectory);
5// Specify a file system working directory for the output.
6options.OutputWorkingDirectory = new OutputFileSystemDirectory(RunExamples.OutputDirectory);
7
8// Run format creation.
9TeXJob.CreateFormat("customtex", options);
10
11// For further output to look fine.
12options.TerminalOut.Writer.WriteLine();
如您所见,该代码类似于用于转换Tex文件的代码。但是有一些差异。
首先,在这里我们使用 TexConfig.ObigntInitex作业配置。这是一种特殊的配置,它使引擎的状态“处女”,即内部参数具有其默认值,并且控制序列的集合与原始序列相吻合。在我们的示例中,从提到的意义上提到的 此处的含义扩展了一组原语。
接下来,我们照常设置输入和输出工作目录。输入工作目录需要包含主要格式源文件及其所有依赖项。
第二个关键区别是我们运行工作的方式。这次,我们使用静态 createformat()方法,该方法与选项一起使用主源文件的名称,该名称必须与格式名称相同。
以您的自定义格式排版TEX文件
现在,我们已经拥有自己的TEX格式,我们想在以这种格式写下Tex文件。这是代码:
1// Create the file system input working directory.
2// Create the format provider using the file system input working directory.
3// We use the project output directory as our custom format file is supposed to be located there.
4using (FormatProvider formatProvider =
5 new FormatProvider(new InputFileSystemDirectory(RunExamples.OutputDirectory), "customtex"))
6{
7 // Create conversion options for a custom format upon ObjectTeX engine extension.
8 TeXOptions options = TeXOptions.ConsoleAppOptions(TeXConfig.ObjectTeX(formatProvider));
9 options.JobName = "typeset-with-custom-format";
10 // Specify the input working directory. This is not required here as we are providing the main input as a stream.
11 // But it is required when the main input has dependencies (e.g. images).
12 options.InputWorkingDirectory = new InputFileSystemDirectory(RunExamples.InputDirectory);
13 // Specify a file system working directory for the output.
14 options.OutputWorkingDirectory = new OutputFileSystemDirectory(RunExamples.OutputDirectory);
15
16 // Run the job.
17 new TeXJob(new MemoryStream(Encoding.ASCII.GetBytes(
18 "Congratulations! You have successfully typeset this text with your own TeX format!\\end")),
19 new XpsDevice(), options).Run();
20
21 // For further output to look fine.
22 options.TerminalOut.Writer.WriteLine();
23}
显然,我们必须以某种方式指定格式。首先,我们需要创建一个 formatprovider类的实例。然后,在选项构造函数中,我们使用 TexConfig.Objecttex()配置,该配置将我们的格式提供程序作为参数,并将格式加载到引擎的“处女”状态之上。
代码的其余部分应该熟悉。它使用此 指南前面讨论的功能。
以普通Tex格式排版Tex文件
如果我们从刚刚演示的代码中丢弃格式提供商,则引擎将加载默认格式,即 Object Tex在其第四种意义上。因此,如果您有一个以普通Tex格式编写的TEX文件,则可以将其转换为任何受支持的目标格式。