外部乳胶软件包| 通过 .NET 为 Python 提供 Aspose.TeX
外部乳胶软件包
Aspose.TeX库带有各种 常见的乳胶包裹,因此无需手动向Tex发动机提供这些软件包。但是,在某些情况下,您的乳胶文件需要一个包装中未包含的软件包。在这种情况下,您可以尝试通过 queld_input_directory texoptions类实例提供必要的输入,例如所需软件包的源文件。我们将探讨这两个示例的工作方式。
请先应用
许可证。将 ASPOSE_TEX_INPUT_DIR 设置为包含 ExternalLaTeXPackages 的文件夹(默认为 input),其中应保留两个 .tex 文件和 packages 子目录。将 ASPOSE_TEX_OUTPUT_DIR 设置为输出文件夹(默认为 output)。
所需的输入以未包装的形式(``Fancybox’‘软件包)提供。
假设我们有以下名为ruild-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}文件的第三行表示它需要`fancybox“软件包,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’软件包)提供
现在,假设我们有以下名为“必需input-zip.tex”的乳胶文件,这也是我们示例解决方案的简单文件:
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}在第三行上,可以观察到该文件需要“ PGFPLOTS”软件包,而不是“本地”支持。再一次,假设我们拥有“ PGFPLOTS”软件包的源文件,这些文件很多,并且位于任何乳胶排放应用程序的安装目录中的两个不同目录中。可以在\ tex \ generic和\tex\latex目录”中找到“ pgfplots”文件夹。为了使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。
限制
如果您遇到乳胶文件所需的latex3ekernel an的软件包,则不太可能与Aspose.TeX库一起使用。这是因为库基于 latex2e内核。
此外,在某些情况下,您的乳胶文件要求的包装直接使用了Aspose.TeX library的object tex引擎不支持设备的原始命令。在这种情况下,该软件包将无法与库一起使用。