その他のTEX変換出力形式| Python
現在、LaTex以外の形式で記述されたTEXファイルを変換する必要がある可能性は低いです。ただし、何らかの理由でTex LanguageまたはTexの内部を勉強している場合、それはまだ可能です。いずれにせよ、pythonのAspose.TeXを使用すると、plane tex形式で記述されたファイルを変換できます。また、これらの形式で設計されたカスタム形式と型文書を作成することもできます。
まず、カスタム形式を作成します。
カスタム形式の作成
フォーマットファイルは、TEXエンジンの内部状態のバイナリ表現であることに留意してください。
1# Create TeX engine options for no format upon ObjectTeX engine extension.
2options = TeXOptions.console_app_options(TeXConfig.object_ini_tex)
3# Specify a file system working directory for the input.
4options.input_working_directory = InputFileSystemDirectory(Util.input_directory)
5# Specify a file system working directory for the output.
6options.output_working_directory = OutputFileSystemDirectory(Util.output_directory)
7
8# Run format creation.
9TeXJob.create_format("customtex", options)
10
11# For further output to look fine.
12options.terminal_out.writer.write_line()
ご覧のとおり、コードはTEXファイルを変換するためのコードに似ています。ただし、いくつかの区別があります。
まず、この場合、 texconfig.object_ini_texジョブ構成を利用します。この構成により、エンジンの状態が「バージン」であることが保証されます。つまり、内部パラメーターにはデフォルト値があり、制御シーケンスのセットがプリミティブのセットに合わせます。この例では、一連のプリミティブが展開されます Aspose.TeXおよびObject Texの記事。
それに続いて、通常どおり、入力および出力作業ディレクトリのセットアップを進めます。入力作業ディレクトリには、メイン形式のソースファイルとそのすべての依存関係を含める必要があります。
2番目の大きな違いは、ジョブを実行する方法です。この場合、static create_format()メソッドを使用します。これは、オプションと併せて、メインソースファイルの名前が形式名と同一であることを要求します。
カスタム形式で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.
3with FormatProvider(InputFileSystemDirectory(Util.output_directory), "customtex") as format_provider:
4 # Create conversion options for a custom format upon ObjectTeX engine extension.
5 options = TeXOptions.console_app_options(TeXConfig.object_tex(format_provider))
6 options.job_name = "typeset-with-custom-format"
7 # Specify the input working directory. This is not required here as we are providing the main input as a stream.
8 # But it is required when the main input has dependencies (e.g. images).
9 options.input_working_directory = InputFileSystemDirectory(Util.input_directory)
10 # Specify a file system working directory for the output.
11 options.output_working_directory = OutputFileSystemDirectory(Util.output_directory)
12
13 # Run the job.
14 TeXJob(BytesIO("Congratulations! You have successfully typeset this text with your own TeX format!\\end".encode('ascii')),
15 XpsDevice(), options).run()
16
17 # For further output to look fine.
18 options.terminal_out.writer.write_line()
形式を指定するには、 formatproviderクラスのインスタンスを作成する必要があります。 Options Constructorでは、 texconfig.object_tex()構成を使用します。これは、フォーマットプロバイダーが引数として必要で、エンジンの「処女」状態の上に形式をロードします。
残りのコードは、この ガイドで前述した機能を利用しているため、おなじみのものでなければなりません。
Plain Tex形式でTexファイルを植林します
上記のコードからフォーマットプロバイダーを削除すると、エンジンはデフォルト形式をロードします。これは オブジェクトTexである4番目の意味でです。したがって、Plain Tex形式でTexファイルが記述されている場合は、このアプローチを使用してサポートされているターゲット形式に変換できます。