外部ラテックスパッケージ| .NET経由でPython用のAspose.TeX
外部ラテックスパッケージ
Aspose.TeXライブラリには、さまざまな 一般的なラテックスパッケージが付属しているため、これらのパッケージをTexエンジンに手動で提供する必要はありません。ただし、ラテックスファイルには、ライブラリのパッケージの「バンドル」に含まれていないパッケージが必要な状況がある場合があります。そのような場合、 rebused_input_directory texoptionsクラスインスタンスのオプションを介して、必要なパッケージのソースファイルなど、必要な入力を提供してみてください。これが2つの例でどのように機能するかを探ります。
まず
ライセンスを適用します。ASPOSE_TEX_INPUT_DIR に、2 つの .tex ファイルと packages サブフォルダーを含む ExternalLaTeXPackages の親フォルダーを指定します(既定値:input)。ASPOSE_TEX_OUTPUT_DIR に出力フォルダーを指定します(既定値:output)。
未梱包のフォーム(fancyboxパッケージ)で提供される必要な入力。
「required-input-fs.tex」という名前の次の基本的なラテックスファイルがあるとします。これは サンプルソリューションの一部です。
1\documentclass{article}
2\usepackage[a6paper,landscape]{geometry}
3\usepackage{fancybox}
4\begin{document}
5Test: \fbox{
6 \begin{Bitemize}[b]
7 \item First item
8 \item A second one\\ on two lines
9 \item(2pt) A third with extra space
10 \end{Bitemize}
11}
12\par\bigskip
13Test: \fbox{
14 \begin{Beqnarray}[t]
15 y & = & x^2 \\
16 a^2 + 2ab + b^2 & = & (a + b)^2 \\
17 \int_0^\infty e^{-ax} dx & = & \frac{1}{a}
18 \end{Beqnarray}
19}
20\end{document}ファイルの3行目は、「ネイティブ」サポートには含まれていない「Fancybox」パッケージが必要であることを示しています。 「Fancybox」パッケージのソースファイルがあると仮定しましょう。単一のファイルで構成される単純なパッケージであるため、このファイルをファイルシステムのどこにでも配置して、次のようにディレクトリパスを指定できます。
1from aspose.tex.io import InputFileSystemDirectory
2
3# Configure an existing TeXOptions instance.
4options.required_input_directory = InputFileSystemDirectory('path-to-directory-where-fancybox.sty-located')このオプションでTEXジョブを実行したら(必要に応じて他のオプションを調整することを忘れないでください)、この場合はPNG画像である出力ドキュメントを取得します。

これが例の完全なソースコードです。
1# Load an external LaTeX package from a directory.
2import os
3from pathlib import Path
4from os import path
5from io import BytesIO
6from aspose.tex import Interaction, TeXConfig, TeXJob, TeXOptions
7from aspose.tex.io import InputFileSystemDirectory, InputZipDirectory, OutputFileSystemDirectory, OutputMemoryTerminal
8from aspose.tex.presentation.image import ImageDevice, PngSaveOptions
9
10output_dir = Path(os.environ.get("ASPOSE_TEX_OUTPUT_DIR", "output")).resolve()
11output_dir.mkdir(parents=True, exist_ok=True)
12input_dir = Path(os.environ.get("ASPOSE_TEX_INPUT_DIR", "input")).resolve() / "ExternalLaTeXPackages"
13# Create conversion options for Object LaTeX format upon Object TeX engine extension.
14options = TeXOptions.console_app_options(TeXConfig.object_latex)
15options.interaction = Interaction.NONSTOP_MODE
16options.terminal_out = OutputMemoryTerminal()
17# Specify a file system working directory for the output.
18options.output_working_directory = OutputFileSystemDirectory(str(output_dir))
19# Specify a file system working directory for the required input.
20# The directory containing packages may be located anywhere.
21options.required_input_directory = InputFileSystemDirectory(path.join(str(input_dir), "packages"))
22# Initialize the options for saving in PNG format.
23options.save_options = PngSaveOptions()
24# Run LaTeX to PNG conversion.
25TeXJob(path.join(str(input_dir), "required-input-fs.tex"), ImageDevice(True), options).run()アーカイブフォームで必要な入力を提供する(pgfplotsパッケージ)
次に、「必要な入力Zip.tex」という名前の次のLaTexファイルがあるとします。これは、例のソリューションからの簡単なファイルでもあります。
1\documentclass{article}
2\usepackage[margin=0.25in]{geometry}
3\usepackage{pgfplots}
4\pgfplotsset{width=10cm,compat=1.18}
5\begin{document}
6
7First example is 2D and 3D math expressions plotted side-by-side.
8
9%Here begins the 2D plot
10\begin{tikzpicture}
11\begin{axis}
12\addplot[color=red]{exp(x)};
13\end{axis}
14\end{tikzpicture}
15%Here ends the 2D plot
16\hskip 5pt
17%Here begins the 3D plot
18\begin{tikzpicture}
19\begin{axis}
20\addplot3[
21 surf,
22]
23{exp(-x^2-y^2)*x};
24\end{axis}
25\end{tikzpicture}
26%Here ends the 3D plot
27
28\end{document}3行目では、ファイルが「ネイティブに」サポートされていないpgfplotsパッケージが必要であることが観察できます。繰り返しになりますが、pgfplots」パッケージのソースファイルを所有していると仮定すると、これらのファイルは非常に多く、LaTexタイプセットアプリケーションのインストールディレクトリ内の2つの異なるディレクトリにあります。 pgfplotsフォルダーは、\tex\genericと \ tex \ latexディレクトリの両方にあります。 Aspose.TeXライブラリが正しく機能するには、これらの両方のフォルダーの内容を入力として提供する必要があります。これを達成するために、これらのソースファイルをzipアーカイブにパッケージ化したいと考えています。以下は、アーカイブの目的のレイアウトです。

そして、これらのソースファイルへのアクセシビリティを定義する方法は次のとおりです。
1from aspose.tex.io import InputZipDirectory
2
3# Configure an existing TeXOptions instance and run the job while the stream is open.
4with open("path-to-zip-with-pgfplots-sources", "rb") as zip_stream:
5 options.required_input_directory = InputZipDirectory(zip_stream, "")
6 # Run TeXJob here, as shown in the complete example below.このオプションでTEXジョブを実行した後、出力ドキュメントを取得します。

これが例の完全なソースコードです。
1# Load external LaTeX packages from a ZIP archive.
2import os
3from pathlib import Path
4from os import path
5from io import BytesIO
6from aspose.tex import Interaction, TeXConfig, TeXJob, TeXOptions
7from aspose.tex.io import InputFileSystemDirectory, InputZipDirectory, OutputFileSystemDirectory, OutputMemoryTerminal
8from aspose.tex.presentation.image import ImageDevice, PngSaveOptions
9
10output_dir = Path(os.environ.get("ASPOSE_TEX_OUTPUT_DIR", "output")).resolve()
11output_dir.mkdir(parents=True, exist_ok=True)
12input_dir = Path(os.environ.get("ASPOSE_TEX_INPUT_DIR", "input")).resolve() / "ExternalLaTeXPackages"
13# Create conversion options for Object LaTeX format upon Object TeX engine extension.
14options = TeXOptions.console_app_options(TeXConfig.object_latex)
15options.interaction = Interaction.NONSTOP_MODE
16options.terminal_out = OutputMemoryTerminal()
17# Specify a file system working directory for the output.
18options.output_working_directory = OutputFileSystemDirectory(str(output_dir))
19# Initialize the options for saving in PNG format.
20options.save_options = PngSaveOptions()
21# Create a file stream for the ZIP archive containing the required package.
22# The ZIP archive may be located anywhere.
23with open(path.join(str(input_dir), "packages/pgfplots.zip"), "rb") as zip_stream:
24 # Specify a ZIP working directory for the required input.
25 options.required_input_directory = InputZipDirectory(zip_stream, "")
26
27 # Run LaTeX to PNG conversion.
28 TeXJob(path.join(str(input_dir), "required-input-zip.tex"), ImageDevice(True), options).run()注意: この結果は
pgfplotsパッケージのバージョン 1.18.1 を使用して検証されました。Aspose.TeX ライブラリに含まれるpfgパッケージのバージョンは 3.1.9a です。
制限
latex3eカーネルANの下で開発されたパッケージに出くわした場合、LaTexファイルで必要とされている場合、Aspose.TeXライブラリを使用する可能性は低いです。これは、ライブラリが * latex2e *カーネルに基づいているためです。
さらに、ラテックスファイルに必要なパッケージが、Aspose.TeXライブラリのオブジェクトtexエンジンによってサポートされていないデバイス依存のプリミティブコマンドを直接使用する場合があります。そのような場合、パッケージはライブラリで動作しません。