外部乳胶软件包| .NET
外部乳胶软件包
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// Create conversion options for Object LaTeX format upon Object TeX engine extension.
2TeXOptions options = TeXOptions.ConsoleAppOptions(TeXConfig.ObjectLaTeX);
3// Specify a file system working directory for the output.
4options.OutputWorkingDirectory = new OutputFileSystemDirectory(RunExamples.OutputDirectory);
5// Specify a file system working directory for the required input.
6// The directory containing packages may be located anywhere.
7options.RequiredInputDirectory = new InputFileSystemDirectory(Path.Combine(RunExamples.InputDirectory, "packages"));
8// Initialize the options for saving in PNG format.
9options.SaveOptions = new PngSaveOptions();
10// Run LaTeX to PNG conversion.
11new TeXJob(Path.Combine(RunExamples.InputDirectory, "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// Create conversion options for Object LaTeX format upon Object TeX engine extension.
2TeXOptions options = TeXOptions.ConsoleAppOptions(TeXConfig.ObjectLaTeX);
3// Specify a file system working directory for the output.
4options.OutputWorkingDirectory = new OutputFileSystemDirectory(RunExamples.OutputDirectory);
5// Initialize the options for saving in PNG format.
6options.SaveOptions = new PngSaveOptions();
7// Create a file stream for the ZIP archive containing the required package.
8// The ZIP archive may be located anywhere.
9using (Stream zipStream = File.Open(Path.Combine(RunExamples.InputDirectory, "packages\\pgfplots.zip"), FileMode.Open))
10{
11 // Specify a ZIP working directory for the required input.
12 options.RequiredInputDirectory = new InputZipDirectory(zipStream, "");
13
14 // Run LaTeX to PNG conversion.
15 new TeXJob(Path.Combine(RunExamples.InputDirectory, "required-input-zip.tex"), new ImageDevice(), options).Run();
16}
注意: 结果是使用
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// This is an implementation of IInputWorkingDirectory that is suitable for the TeX job's RequiredInputDirectory option
2// in case required input contains fonts provided by external packages.
3// The class additionally implements IFileCollector, which provides access to file collections by extension.
4// This is necessary to load external font maps, which are files (outside TeX syntax) that map TeX's
5// internal font names to file names of physical fonts.
6public class RequiredInputDirectory : IInputWorkingDirectory, IFileCollector
7{
8 private Dictionary<string, Dictionary<string, string>> _fileNames =
9 new Dictionary<string, Dictionary<string, string>>();
10
11 public RequiredInputDirectory()
12 {
13 }
14
15 // This method should preliminarily be called for each file entry that is supposed to be located inside
16 // the required input directory. Inside is an example of how the dictionary of file names could be organized
17 // for easy collection of file names by extension.
18 // Here fileName is a full file name. This can be a file path on a file system, a URL, or whatever else (theoretically).
19 public void StoreFileName(string fileName)
20 {
21 string extension = Path.GetExtension(fileName);
22 string name = Path.GetFileNameWithoutExtension(fileName);
23
24 Dictionary<string, string> files;
25 if (!_fileNames.TryGetValue(extension, out files))
26 _fileNames.Add(extension, files = new Dictionary<string, string>());
27
28 files[name] = fileName;
29 }
30
31 // The IInputWorkingDirectory implementation.
32 public NamedStream GetFile(string fileName, bool searchSubdirectories = false)
33 {
34 return new NamedStream(null, fileName); // Here we actually return a stream for the file requested by its name.
35 }
36
37 // Here is how we gather file collections by extension.
38 public string[] GetFileNamesByExtension(string extension, string path = null)
39 {
40 Dictionary<string, string> files;
41 if (!_fileNames.TryGetValue(extension, out files))
42 return new string[0];
43
44 return new List<string>(files.Values).ToArray();
45 }
46
47 public void Dispose()
48 {
49 _fileNames.Clear();
50 }
51}
限制
可能会在 * latex3e 内核下开发乳胶文件所需的包装。这样的软件包很可能无法与Aspose.TeX库一起使用,因为后者基于lastx2e*内核。
您的乳胶文件要求的软件包可能会直接调用Aspose.TeX库的对象Tex引擎不支持设备的原始命令。不幸的是,这样的软件包无法确定。