4 Customization

§4.2 latexmlpost Customization

The current postprocessing framework works by passing the document through a sequence of postprocessing filter modules. Each module is responsible for carrying out a specific transformation, augmentation or conversion on the document. In principle, this architecture has the flexibility to employ new filters to perform new or customized conversions. However, the driver, latexmlpost, currently provides no convenient means to instanciate and incorporate outside filters, short of developing your own specialized version.

Consequently, we will consider custom postprocessing filters outside the scope of this manual (but of course, you are welcome to explore the code, or contact us with suggestions).

The two areas where customization is most practical is in altering the XSLT transforms used and extending the CSS stylesheets.

§4.2.1 XSLT

LaTeXML provides stylesheets for transforming its XML format to XHTML and HTML. These stylesheets are modular with components corresponding to the schema modules. Probably the best strategy for customizing the transform involves making a copy of the standard base stylesheets, LaTeXML-xhtml.xsl and LaTeXML-html.xsl, found at installationdir/LaTeXML/style/— they’re short, consisting mainly of sequence of xsl:include — and adding your own rules, or including your own modules. The two stylesheets differ primarily in their use of namespaces and handling of math.

Naturally, this requires a familiarity with LaTeXML’s schema (see F), as well as XSLT and XHTML. See the other stylesheet modules in the same directory as the base stylesheet for guidance.

Conversion to formats other than XHTML are, of course, possible, as well, but are neither supplied nor covered here. How complex the transformation will be depends on the extent that the LaTeXML schema can be mapped to the desired one, and to what extent LaTeXML has lost or hidden information represented in the original document. Again, familiarity with the schema is needed, and the provided XHTML stylesheets may suggest an approach.

§4.2.2 CSS

CSS stylesheets can be supplied to latexmlpost to be included in the generated documents in addition to, or as a replacement for, the standard stylesheet core.css. See the directory installationdir/LaTeXML/style/ for samples.

To best take advantage of this capability so as to design CSS rules with the correct specificity, the following points are helpful:

  • LaTeXML converts the TeX to its own schema, with structural elements (like equation) getting their own tag; others are transformed to something more generic, such as note. In the latter case, a class attribute is often used to distinguish. For example, a \footnote generates

      <note class=’footnote’>…

    whereas an \endnote generates

      <note class=’endnote’>…
  • The provided XSLT stylesheets transform LaTeXML’s schema to XHTML, generating a combined class attribute consisting of any class attributes already present as well as the LaTeXML tag name. However, there are some variations on the theme. For example, LaTeX’s \section yeilds a LaTeXML element section, with a title element underneath. When transformed to XHTML, the former becomes a <div class='section'>, while the latter becomes <h2 class='section-title'> (for example, the h-level may vary with the document structure),