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