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, LaTeXML-html.xsl and LaTeXML-html5.xsl, found at installationdir/LaTeXML/style/ — they’re short, consisting mainly of an xsl:include and setting appropriate parameters and output method; thus modifying the parameters and and adding your own rules, or including your own modules should be relatively easy.

Naturally, this requires a familiarity with LaTeXML’s schema (see I), as well as XSLT and XHTML. See the other stylesheet modules in the same directory as the base stylesheet for guidance. Generally the strategy is to use various parameters to switch between common behaviors and to use templates with modes that can be overridden in the less common cases.

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.

NOTE: I’m trying to make stylesheets easily customizable. However, this is getting tricky.

  • You can import stylesheets which allows the templates to be overridden.

  • You can call the overridden stylesheet using apply-imports

  • You can not call apply-imports to call an overridden named template! (although you seemingly can override them?)

  • You can refer to xslt modules using URN’s, provided you have loaded the LaTeXML.catalog:

    <xsl:import href=”urn:x-LaTeXML:XSLT:LaTeXML-all-xhtml.xsl”/>

§ 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 LaTeXML.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),

Mode begin and end

For most elements, once the main html element has been opened and the primary attributes have been added but before any content has been added, a template with mode begin is called; thus it can add either attributes or content. Just before closing the main html element, a template with mode end is called.

Computing class and style

Templates with mode classes and styling.