plasTeX 3.0 — A Python Framework for Processing LaTeX Documents

5.5 XHTML Renderer

The XHTML renderer used to be the default renderer of plasTeX but is now deprecated in favor of the HTML5 renderer, and kept only for backward compatibility purposes. The XHTML renderer is a subclass of the Page Template Renderer (section 5.3). Since the Page Template Renderer can render any variant of XML or HTML, the XHTML renderer has very little to do in the Python code. Almost all of the additional processing in the XHTML renderer has to do with generated images. Since MathJax (or KaTeX) didn’t exist at the time when XHTML was used, all LaTeXequations are converted to images by this renderer. In order for inline equations to line up correctly with the text around them, CSS attributes are used to adjust the vertical alignment. Since the images aren’t generated until after all of the document has been rendered, this CSS information is added in post-processing (i.e. the cleanup method).

In addition to the processing of images, all characters with a ordinal greater than 127 are converted into numerical entities. This should prevent any rendering problems due to unknown encodings.

Most of the work in this renderer was in creating the templates for every LaTeX construct. Since this renderer was intended to be the basis of all HTML-based renderers, it must be capable of rendering all LaTeX constructs; therefore, there are ZPT templates for every LaTeX command, and the commands in some common LaTeX packages.