外部ラテックスパッケージ| .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// 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パッケージ)アーカイブ

次に、次の非常にシンプルなラテックスファイルもあります。これは、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// 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}

NOTE: The result was verified using the pgfplots package version 1.18.1. While the version of the pfg package included in the Aspose.TeX library is 3.1.9a.

外部フォントパッケージを使用します

原則として、LaTexディストリビューションは、版形セットに利用できる一連のデフォルトのフォントを提供します。これらのフォントを除き、Asops.texには、標準以外のフォントパッケージが多数含まれています。たとえば、amsfontseurosym、および wasysym。上で見たように、Aspose.TeXでは、外部パッケージを使用することもできます。しかし、ほとんどの場合、フォントが含まれていないパッケージについて話していました。 Aspose.TeX ‘SObject Texエンジン拡張機能は、各Texの内部フォント名に対応する物理フォントを判断するために、.map拡張機能による特定の形式のテキストファイルですを必要とします。これらのフォントマップは、初期化フェーズ中にTexのメモリにロードする必要があります。そして、もちろん、それらはあなたがプラグインしているパッケージのファイルに存在する必要があります。エンジンはすべてのフォントマップの名前がわからないため、 .map拡張子を持つすべてのファイルを探します。したがって、 IinputWorkingDirectoryインターフェイスの実装は、 rebysinginputDirectoryオプションの値として使用されます。より具体的には、この実装は ifileCollectorインターフェイスも実装する必要があります。標準の実装 - inputFilesSystemDirectoryおよび 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ライブラリで動作しない可能性が最も高くなります。後者はlatex2eカーネルに基づいているためです。

また、LaTexファイルが必要とするパッケージは、Aspose.TeXライブラリのオブジェクトTexエンジンによってサポートされていないデバイス依存のプリミティブコマンドを直接呼び出すことがあります。残念ながら、このようなパッケージは確かに機能しません。

Have any questions about Aspose.TeX?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.