其他TEX转换输出格式|爪哇

您目前不太可能要转换以除乳胶以外的任何其他格式编写的TEX文件。但是,如果您出于某种原因正在学习Tex语言和/或内部语言,这是可能的。无论如何,用于 Java 的 Aspose.TeX允许您转换以简单的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.setInputWorkingDirectory(new InputFileSystemDirectory(Utils.getInputDirectory()));
 5// Specify a file system working directory for the output.
 6options.setOutputWorkingDirectory(new OutputFileSystemDirectory(Utils.getOutputDirectory()));
 7
 8// Run format creation.
 9TeXJob.createFormat("customtex", options);
10
11// For further output to look fine.
12options.getTerminalOut().getWriter().newLine();

如您所见,该代码类似于用于转换Tex文件的代码。但是有一些差异。

首先,在这里,我们使用 TexConfig.ObigntInitex()作业配置。这是一种特殊的配置,它使引擎的状态“处女”,即内部参数具有其默认值,并且控制序列的集合与原始序列相吻合。在我们的示例中,从提到的意义上提到的 此处的含义扩展了一组原语。

接下来,我们照常设置输入和输出工作目录。输入工作目录需要包含主要格式源文件及其所有依赖项。

第二个关键区别是我们运行工作的方式。这次,我们使用静态 createformat()方法,该方法与选项一起使用主源文件的名称,该名称必须与格式名称相同。

以您的自定义格式排版TEX文件

现在,我们已经拥有自己的TEX格式,我们想在以这种格式写下Tex文件。这是代码:

 1// Create the format provider using the file system input working directory.
 2// We use the project output directory as our custom format file is supposed to be located there.
 3final FormatProvider formatProvider = new FormatProvider(
 4    new InputFileSystemDirectory(Utils.getOutputDirectory()), "customtex");
 5try {
 6  // Create conversion options for a custom format upon ObjectTeX engine extension.
 7  TeXOptions options = TeXOptions.consoleAppOptions(TeXConfig.objectTeX(formatProvider));
 8  options.setJobName("typeset-with-custom-format");
 9  // Specify the input working directory. This is not required here as we are providing the main input as a stream.
10  // But it is required when the main input has dependencies (e.g. images).
11  options.setInputWorkingDirectory(new InputFileSystemDirectory(Utils.getInputDirectory()));
12  // Specify a file system working directory for the output.
13  options.setOutputWorkingDirectory(new OutputFileSystemDirectory(Utils.getOutputDirectory()));
14  
15  // Run the job.
16  new TeXJob(new ByteArrayInputStream(
17    "Congratulations! You have successfully typeset this text with your own TeX format!\\end".getBytes("ASCII")),
18    new XpsDevice(), options).run();
19  
20  // For further output to look fine.
21  options.getTerminalOut().getWriter().newLine();
22} finally {
23  formatProvider.close();
24}

显然,我们必须以某种方式指定格式。首先,我们需要创建一个 formatprovider类的实例。然后,在选项构造函数中,我们使用 TexConfig.Objecttex()配置,该配置将我们的格式提供程序作为参数,并将格式加载到引擎的“处女”状态之上。

代码的其余部分应该熟悉。它使用此 指南前面讨论的功能。

以普通Tex格式排版Tex文件

如果我们从刚刚演示的代码中丢弃格式提供商,则引擎将加载默认格式,即 Object Tex在其第四种意义上。因此,如果您有一个以普通Tex格式编写的TEX文件,则可以将其转换为任何受支持的目标格式。

Have any questions about Aspose.TeX?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.