Equation numbering

DocBook provides the equation element as a wrapper for math if you want to add a title and number to each math example. The default format is similar to numbered tables and figures, as in the following example:

Equation 22.1. Mass Energy Equivalence

E = mc2

You can modify the generated text for the equation number and title by changing the appropriate gentext template. See the section “Generated text” for details on gentext customization. In the English locale file common/en.xml, the equation gentext template looks like the following:

<l:context name="title">
  ...
  <l:template name="equation" text="Equation&#160;%n.&#160;%t"/>

Some publications call for a different way of formatting numbered equations, where the title is omitted and the number appears to the left or right of the equation. For example:

E = mc2            (3.1)

The stylesheets do not have a parameter to select this format, but it can be accomplished with a customization of the stylesheet template for equation. Here is such a customization that works for print output:

<xsl:template match="equation">
  <fo:table width="100%" table-layout="fixed">
    <xsl:attribute name="id">
      <xsl:call-template name="object.id"/>
    </xsl:attribute>
    <fo:table-column column-width="90%"/>
    <fo:table-column column-width="10%"/>
    <fo:table-body start-indent="0pt" end-indent="0pt">
      <fo:table-row>
        <fo:table-cell text-align="center">
          <fo:block>
            <xsl:apply-templates/>
          </fo:block>
        </fo:table-cell>
        <fo:table-cell text-align="right" display-align="center">
          <fo:block>
            <xsl:text>(</xsl:text>
            <xsl:apply-templates select="." mode="label.markup"/>
            <xsl:text>)</xsl:text>
          </fo:block>
        </fo:table-cell>
      </fo:table-row>
    </fo:table-body>
  </fo:table>
</xsl:template>

It wraps the equation content in a one-row, two-column table, with the content in the left column and the equation number in the right column. The number is generated by processing the equation element in mode="label.markup". You can change the table column order and alignment if you want the number on the left instead. Any title is ignored, although title is optional in the equation element.