4.1 LaTeXML Customization

§ 4.1.5 Rewriting

The following functions are a bit tricky to use (and describe), but can be quite useful in some circumstances.

DefLigature($regexp,%options)

applies a regular expression to substitute textnodes after they are closed; the only option is fontTest=>$code which restricts the ligature to text nodes where the current font passes &$code($font).

DefMathLigature($code,%options)

allows replacement of sequences of math nodes. It applies $code to the current Document and each sequence of math nodes encountered in the document; if a replacement should occur, $code should return a list of the form ($n,$string,attributes) in which case, the text content of the first node is replaced by $string, the given attributes are added, and the following $n-1 nodes are removed.

DefRewrite(%spec)

defines document rewrite rules. These specifications describe what document nodes match:

  • label=>$label restricts to nodes contained within an element whose labels includes $label;

  • scope=>$scope generalizes label; the most useful form a string like ’section:1.3.2’ where it matches the section element whose refnum is 1.3.2;

  • xpath=>$xpath selects nodes matching the given XPath;

  • match=>$tex selects nodes that look like what processing the TeX string $tex would produce;

  • regexp=>$regexp selects text nodes that match the given regular expression.

The following specifications describe what to do with the matched nodes:

  • attributes=>{attr} adds the given attributes to the matching nodes;

  • replace=>$tex replaces the matching nodes with the result of processing the TeX string $tex.