外部乳胶软件包| .NET的Aspose.TeX
外部乳胶软件包
Aspose.TeX库包含许多 常见的乳胶软件包。因此,您不必担心如何将这些包装提供给图书馆的Tex引擎。但是有时(或经常)您的乳胶文件可能需要一个包裹以外的包装包装。如果是这种情况,您可以尝试通过 queldInputDirectory texoptions类实例提供所需的输入,即所需的包源文件。我们将看到这两个示例如何工作。
打开包装所需的输入(fancybox软件包)
假设我们有以下简单的乳胶文件,这是我们的 示例解决方案:
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”软件包源文件。这是一个简单的软件包,因此它确实由一个文件组成。我们可以将此文件放在文件系统中的任何位置,并如下所示指定目录路径:
1options.RequiredInputDirectory = new InputFileSystemDirectory("path-to-directory-where-fancybox.sty-located");使用此选项运行Tex作业(不要忘记根据需要调整其他选项)后,我们将获得输出文档(即PNG图像)。

这是该示例的完整源代码:
1// External LaTeX packages from file system
2
3// Create conversion options for Object LaTeX format upon Object TeX engine extension.
4TeXOptions options = TeXOptions.ConsoleAppOptions(TeXConfig.ObjectLaTeX);
5// Specify a file system working directory for the output.
6options.OutputWorkingDirectory = new OutputFileSystemDirectory(OutputDir);
7// Specify a file system working directory for the required input.
8// The directory containing packages may be located anywhere.
9options.RequiredInputDirectory = new InputFileSystemDirectory(Path.Combine(DataDir, "packages"));
10// Initialize the options for saving in PNG format.
11options.SaveOptions = new PngSaveOptions();
12// Run LaTeX to PNG conversion.
13new TeXJob(Path.Combine(DataDir, "required-input-fs.tex"), new ImageDevice(), options).Run();存档所需的输入(pgfplots软件包)
现在,我们说我们也有以下简单的乳胶文件,这是我们的示例解决方案中的“必需输入” 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
7第一个例子是并排绘制的 2D 和 3D 数学表达式。
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存档中,因此这是存档的布局:

这就是我们指定对这些源文件的访问的方式:
1using (Stream zipStream = File.Open("path-to-zip-with-pgfplots-sources"), FileMode.Open))
2{
3 ...
4 options.RequiredInputDirectory = new InputZipDirectory(zipStream);
5 ...
6}通过此选项运行Tex作业后,我们将获得输出文档:

这是该示例的完整源代码:
1// External LaTeX packages from ZIP archive
2
3// Create conversion options for Object LaTeX format upon Object TeX engine extension.
4TeXOptions options = TeXOptions.ConsoleAppOptions(TeXConfig.ObjectLaTeX);
5// Specify a file system working directory for the output.
6options.OutputWorkingDirectory = new OutputFileSystemDirectory(OutputDir);
7// Initialize the options for saving in PNG format.
8options.SaveOptions = new PngSaveOptions();
9// Create a file stream for the ZIP archive containing the required package.
10// The ZIP archive may be located anywhere.
11using (Stream zipStream = File.Open(Path.Combine(DataDir, "packages\\pgfplots.zip"), FileMode.Open))
12{
13 // Specify a ZIP working directory for the required input.
14 options.RequiredInputDirectory = new InputZipDirectory(zipStream, "");
15
16 // Run LaTeX to PNG conversion.
17 new TeXJob(Path.Combine(DataDir, "required-input-zip.tex"), new ImageDevice(), options).Run();
18}注意: 结果是使用
pgfplots软件包版本 1.18.1 验证的。而 Aspose.TeX 库中包含的pfg软件包版本为 3.1.9a。
采用外部字体软件包
通常,乳胶分布提供一组可用于排版的默认字体。除这些字体外,Aspose.TeX包括许多非标准字体软件包。例如,amsfonts',eurosym和wasysym`。如上所述,Aspose.TeX还允许使用外部包装。但是大多数情况下,我们在谈论不包含字体的软件包。
Aspose.TeX的对象Tex引擎扩展需要字体映射(以“约定”为“ .map”扩展为特定格式的文本文件),以确定哪些物理字体对应于每个Tex的内部字体名称。这些字体图必须在初始化阶段加载到Tex的内存中。而且,当然,它们必须存在于您要插入的软件包的文件中。由于引擎不知道所有字体地图的名称,因此它可以在所有文件中查找所有文件。因此,用于 InsirceInputInputDirectory选项的 IinputworkingDirectory接口的实现必须提供一种通过扩展访问文件名的收集的方法。更具体地说,该实现还必须实现 IfileCollector接口。标准实现 - InputFilesystemDirectory和 InputzipDirectory - 已经这样做。
下面,我们提供了一个自定义所需输入目录的说明性示例,该目录还实现了 IfileCollector接口。在专注于按扩展程序收集文件名的同时,我们故意省略了文件存储和检索的详细信息。
1// Custom implementation of IInputWorkingDirectory for external packages with fonts
2
3// This is an implementation of IInputWorkingDirectory that is suitable for the TeX job's RequiredInputDirectory option
4// in case required input contains fonts provided by external packages.
5// The class additionally implements IFileCollector, which provides access to file collections by extension.
6// This is necessary to load external font maps, which are files (outside TeX syntax) that map TeX's
7// internal font names to file names of physical fonts.
8public class RequiredInputDirectory : IInputWorkingDirectory, IFileCollector
9{
10 private Dictionary<string, Dictionary<string, string>> _fileNames =
11 new Dictionary<string, Dictionary<string, string>>();
12
13 public RequiredInputDirectory()
14 {
15 }
16
17 // This method should preliminarily be called for each file entry that is supposed to be located inside
18 // the required input directory. Inside is an example of how the dictionary of file names could be organized
19 // for easy collection of file names by extension.
20 // Here fileName is a full file name. This can be a file path on a file system, a URL, or whatever else (theoretically).
21 public void StoreFileName(string fileName)
22 {
23 string extension = Path.GetExtension(fileName);
24 string name = Path.GetFileNameWithoutExtension(fileName);
25
26 Dictionary<string, string> files;
27 if (!_fileNames.TryGetValue(extension, out files))
28 _fileNames.Add(extension, files = new Dictionary<string, string>());
29
30 files[name] = fileName;
31 }
32
33 // The IInputWorkingDirectory implementation.
34 public NamedStream GetFile(string fileName, bool searchSubdirectories = false)
35 {
36 // Try to find the file in our stored files
37 foreach (var extFiles in _fileNames.Values)
38 {
39 foreach (var file in extFiles.Values)
40 {
41 if (file.EndsWith(fileName) || Path.GetFileName(file) == fileName)
42 {
43 return new NamedStream(File.OpenRead(file), fileName);
44 }
45 }
46 }
47 // If not found in stored files, return null (file not available)
48 return new NamedStream(null, fileName);
49 }
50
51 // Here is how we gather file collections by extension.
52 public string[] GetFileNamesByExtension(string extension, string path = null)
53 {
54 Dictionary<string, string> files;
55 if (!_fileNames.TryGetValue(extension, out files))
56 return new string[0];
57
58 return new List<string>(files.Values).ToArray();
59 }
60
61 public void Dispose()
62 {
63 _fileNames.Clear();
64 }
65}限制
可能会在 LaTeX3e内核下开发乳胶文件所需的包装。这样的软件包很可能无法与Aspose.TeX库一起使用,因为后者基于LaTeX2e内核。
您的乳胶文件要求的软件包可能会直接调用Aspose.TeX库的对象Tex引擎不支持设备的原始命令。不幸的是,这样的软件包无法确定。