Previous step: “PDF literal strings


TeXML code is too verbose and sometimes redundant to be authored manually. For example, on the previous step, the TeXML code contains the same string 3 times.

Actually, it's not a problem. TeXML is not intended to be created manually. Instead, TeXML is to be generated, preferrably by XSLT from XML.

Let's generate the TeXML code similar to that on the previous step. The source XML:

    <title>Заголовок (Title)</title>
    <para>first paragraph</para>
    <para>second paragraph</para>
    ... more paragraphs ...
  ... more sections ...

An XSLT program to convert such XML documents:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<!-- convert "document": create header and continue -->
<xsl:template match="document">
    <!-- create header -->
    <TeXML escape="0">
    <!-- process content -->
    <env name="document">

<!-- convert "para": process content and add "\par" -->
<xsl:template match="para">
  <xsl:apply-templates />
  <cmd name="par" gr="0" nl2="1" />

<!-- convert sections by converting "title" -->
<xsl:template match="title">
  <cmd name="section">
      <cmd name="texorpdfstring">
        <parm><xsl:value-of select="."/></parm>
        <parm><pdf><xsl:value-of select="."/></pdf></parm>
    <parm><xsl:value-of select="."/></parm>


On the one hand, the only achievement is that complexity is moved to XSLT. But on the other hand, it's a great improvement: the non-trivial construction is written only once (section command with the texorpdfstring and pdf commands inside the option). In addition, the complexity is hidden from the authors who write texts in XML and don't know much about LaTeX.

Next step: “Encodings

This page: http://getfo.org/texml/tour_xslt.html