4 Understanding Macros and Packages
Macros and packages in plasTeX live a dual life. On one hand, macros can be defined in LaTeX files and expanded by plasTeX itself. On the other hand, macros can also be implemented as Python classes. Packages are the same way. plasTeX can handle some LaTeX packages natively. Others may have to be implemented in Python. In most cases, both implementations work transparently together. If you don’t define that many macros, and the ones that you do define are simple or even of intermediate complexity, it’s probably better to just let plasTeX handle them natively. However, there are some reasons that you may want to implement Python versions of your macros:
Python versions of macros are generally faster
You have more control over what gets inserted into the output document
You can store information in the document’s userdata dictionary for use later
You can prevent a macro from being expanded into primitive LaTeX commands, so that a custom renderer can be used on that node
Some macros just don’t make sense in a plasTeX document
Some macros are just too complicated for plasTeX
If any of these reasons appeal to you, read the following sections on how to implement macros and packages in plasTeX.