6.6 plasTeX.Renderers — The plasTeX Rendering Framework

The renderer is responsible for taking the information in a plasTeX document object and creating a another (usually visual) representation of it. This representation may be HTML, XML, RTF, etc. While this could be implemented in various ways. One rendering framework is included with plasTeX.

The renderer is essentially just a dictionary of functions1. The keys in this dictionary correspond to names of the nodes in the document object. The values are the functions that are called when a node in the document object needs to be rendered. The only argument to the function is the node itself. What this function does in the rendering process is completely up to it; however, it should refrain from changing the document object itself as other renderers may be using that same object.

There are some responsibilities that all renderers share. Renderers are responsible for checking options in the configuration object. For instance, renderers are responsible for generating filenames, creating directories, writing files in the proper encoding, generating images, splitting the document into multiple output files, etc. Of course, how it accomplishes this is really renderer dependent. An example of a renderer based on Zope Page Templates (ZPT) is included with plasTeX. This renderer is capable of generating XML and HTML output.

Footnotes

  1. “functions” is being used loosely here. Actually, any Python callable object (i.e. function, method, or any object with the __call__ method implemented) can be used