その他のTEX変換出力形式| Java

現在、ラテックス以外の形式で記述された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.objectinitex()ジョブ構成を使用します。これは、エンジンの状態「Virgin」を離れる特別な構成です。つまり、内部パラメーターにはデフォルト値があり、コントロールシーケンスのセットはプリミティブのセットと一致します。私たちの例では、プリミティブのセットは、 ここに言及された意味で拡張されます。

次に、通常どおり、入力および出力作業ディレクトリを設定します。入力作業ディレクトリには、メイン形式のソースファイルとそのすべての依存関係を含める必要があります。

そして、2番目の重要な違いは、私たちが仕事をする方法です。今回は、static 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()構成を使用します。これは、フォーマットプロバイダーを引数として受け取り、エンジンの「処女」状態の上に形式をロードします。

残りのコードはあなたに馴染みがあるはずです。この ガイドで前述した機能を使用します。

Plain Tex形式でTexファイルを植林します

実証されたコードからフォーマットプロバイダーを捨てると、エンジンはデフォルト形式をロードします。これは オブジェクトTexである4番目の意味でです。したがって、Plain Tex形式でTexファイルが書かれている場合、この方法では、サポートされているターゲット形式に変換できます。

Have any questions about Aspose.TeX?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.