plasTeX 3.0 — A Python Framework for Processing LaTeX Documents

6.8.2 Package plugin

For a slighly more complicated example, assume that you have implemented a python version of some package that is not natively supported by plasTeX, or you don’t like the available implementation and, for some reason, contributing your implementation to plasTeXis not possible. You can use the --packages-dir option to use your implementation, but this is not convenient if you want to distribute it. So you can create a folder with the following structure

\begin{forest} 
  for tree={
    font=\ttfamily,
    grow'=0,
    child anchor=west,
    parent anchor=south,
    anchor=west,
    calign=first,
    edge path={
      \noexpand\path [draw, \forestoption{edge}]
      (!u.south west) +(7.5pt,0) |- node[fill,inner sep=1.25pt] {} (.child anchor)\forestoption{edge label};
    },
    before typesetting nodes={
      if n=1
        {insert before={[,phantom]}}
        {}
    },
    fit=band,
    before computing xy={l=15pt},
  }
[my_package_plugin
  [pyproject.toml]
  [src
    [plastex_foo_package
      [__init__.py]
          [Packages
            [foo.py]
          ]
        [templates
          [Foo.jinja2]
        ]
    ]
  ]
]
\end{forest}

The ‘pyproject.toml’ was already explained and the ‘__init__.py’ can be empty in this case. In this case the plugin name is plastex_foo_package. The content of ‘foo.py’ could be:

from plasTeX import Command

class foo(Command):
    pass

and the content of ‘Foo.jinja2’ could be:

name: foo
Foo!

When compiling a file using this plugin, you can put \usepackage{foo} in the preamble and then use the \foo command that will be rendered as “Foo!” with any template based renderer (for instance the default HTML5 renderer).