plasTeX 3.0 — A Python Framework for Processing LaTeX Documents

6.3.1 plasTeX vs. XML

The plasTeX DOM and XML DOM have more similarities than differences. This similarity is purely intentional to reduce the learning curve and to prevent reinventing the wheel. However, the XML DOM can be a bit cumbersome especially when you’re used to much simpler and more elegant Python code. Because of this, some Python behaviors were adopted into the plasTeX DOM. The good news is that these extensions do not break compatibility with the XML DOM. There are, however, some differences due to conventions used LaTeX.

The only significant difference between the plasTeX DOM and the XML DOM is that plasTeX nodes do not have true attributes like in XML. Attributes in XML are more like arguments in LaTeX, because they are similar the plasTeX DOM actually puts the LaTeX macro arguments into the attributes dictionary. This does create an incompatibility though since XML DOM attributes can only be strings whereas LaTeX arguments can contain lots of markup. In addition, plasTeX allows you to convert these arguments into Python strings, lists, dictionaries, etc., so essentially any type of object can occur in the attributes dictionary.

Other than paying attention to the the attributes dictionary difference, you can use most other XML DOM methods on plasTeX document objects to create nodes, delete nodes, etc. The full API is described below.

In most cases, you will not need to be concerned with instantiating nodes. The plasTeX framework does this. However, the API can be helpful if you want to modify the document object that plasTeX creates.