plasTeX 3.0 — A Python Framework for Processing LaTeX Documents

4.3 Packages

Packages in plasTeX are loaded in one of three ways: standard LaTeX package, Python package, and INI file. LaTeX packages are loaded in much the same way that LaTeX itself loads packages. The kpsewhich program is used to locate the requested file which can be either in the search path of your LaTeX distribution or in one of the directories specified in the TEXINPUTS environment variable. plasTeX read the file and expand the macros therein just as LaTeX would do. This happens only if the --load-tex-packages option is set (which is the default value), or the package is white-listed in the --tex-packages option (see Section2.1.1). It will work as expected only for simple packages.

Python packages are located by successively trying three strategies. First plasTeX looks into the directories listed in the --packages-dirs option (see Section2.1.1), in the order they are listed. If this fail then plasTeX looks into the plugins listed in the --plugins option (see Sections 2.1.1 and 6.8), in the reversed order they are listed (the general idea here is that later plugins are allowed to overrule earlier ones). If this also fails then plasTeX looks into the builtin packages folder that comes with every installation of plasTeX. After a package is loaded, it is checked to see if there is a function called ProcessOptions in its namespace. If there is, that function is called with two arguments: 1) the dictionary of options that were specified when loading the package, and 2) the document object that is currently being processed. This function allows you to make adjustments to the loaded macros based on the options specified, and define new commands in the document’s context (see section 4.2.3 for more information). Of course, you can also define Python based macros (section 4.2.1) in the Python package as well.

The last type of packages is based on the INI file format. This format is discussed in more detail in section 4.2.2. INI formatted packages are loaded in conjunction with a LaTeX or Python package. When a package is loaded, an INI file with the same basename is searched for in the same director as the package. If it exists, it is loaded as well. For example, if you had a package called ‘python.sty’ and a file called ‘python.ini’ in the same package directory, ‘python.sty’ would be loaded first, then ‘python.ini’ would be loaded. The same operation applies for Python based packages.