外部ラテックスパッケージ| .NETのAspose.TeX
外部ラテックスパッケージ
Aspose.TeXライブラリには、 一般的なラテックスパッケージが含まれています。したがって、これらのパッケージをライブラリのTexエンジンに提供する方法を心配する必要はありません。ただし、ラテックスファイルがパッケージの「ネイティブにサポートされている「バンドル」を超えるパッケージが必要になる場合があります。この場合、 Texoptionsクラスインスタンスの rebulyinputDirectoryオプションを使用して、必要な入力、つまり必要なパッケージのソースファイルを提供するようにしてください。これが2つの例でどのように機能するかを確認します。
未解決の必要な入力(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}3行目では、ファイルには「ネイティブに」サポートされていない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パッケージ)アーカイブ
次に、次の非常にシンプルなラテックスファイルもあります。これは、required-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}3行目では、ファイルにはpgfplotsパッケージが必要であることがわかります。これは「ネイティブに」サポートされていません。繰り返しますが、pgfplotsパッケージソースファイルがあると想定しています。 LaTexタイプセットアプリケーションのインストールディレクトリにそれらを見つけた場合、2つの場所に分割されたファイルが非常に多数です。 \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}NOTE: The result was verified using the
pgfplotspackage version 1.18.1. While the version of thepfgpackage included in the Aspose.TeX library is 3.1.9a.
外部フォントパッケージを使用します
原則として、LaTexディストリビューションは、版形セットに利用できる一連のデフォルトのフォントを提供します。これらのフォントを除き、Asops.texには、標準以外のフォントパッケージが多数含まれています。たとえば、amsfonts、eurosym、および wasysym。上で見たように、Aspose.TeXでは、外部パッケージを使用することもできます。しかし、ほとんどの場合、フォントが含まれていないパッケージについて話していました。
Aspose.TeX ‘SObject Texエンジン拡張機能は、各Texの内部フォント名に対応する物理フォントを判断するために、.map拡張機能による特定の形式のテキストファイルですを必要とします。これらのフォントマップは、初期化フェーズ中にTexのメモリにロードする必要があります。そして、もちろん、それらはあなたがプラグインしているパッケージのファイルに存在する必要があります。エンジンはすべてのフォントマップの名前がわからないため、 .map拡張子を持つすべてのファイルを探します。したがって、
IinputWorkingDirectoryインターフェイスの実装は、
rebysinginputDirectoryオプションの値として使用されます。より具体的には、この実装は
ifileCollectorインターフェイスも実装する必要があります。標準の実装 -
inputFilesSystemDirectoryおよび
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カーネルに基づいているためです。
また、LaTexファイルが必要とするパッケージは、Aspose.TeXライブラリのオブジェクトTexエンジンによってサポートされていないデバイス依存のプリミティブコマンドを直接呼び出すことがあります。残念ながら、このようなパッケージは確かに機能しません。