Chapter 22. Math

Table of Contents

Plain text math
Graphic math
Math in SVG
MathML
Equation numbering

DocBook does not have elements to describe mathematics. DocBook does provide two container elements for mathematics: equation to format the math as a block (with or without a title), and inlinequation to include math within a paragraph or other inline context. You have several alternatives for what you put in the container element:

Plain text math

Some mathematics can be expressed as straight text, using characters from the keyboard and special characters entered as entities. You might think you could put the text in an inlineequation element, but its content model does not permit bare text.

Starting with version 4.5 of the DocBook XML DTD, you can use a mathphrase element inside an equation or inlineequation element for plain text math. A mathphrase can contain text, superscript, subscript, and emphasis, which is sufficient for simple math expressions. For example:

<inlineequation>
  <mathphrase>E = mc<superscript>2</superscript></mathphrase>
</inlineequation>

In HTML output, this is output inside a span class="mathphrase" container, to which you can assign a CSS style to format it in italics, for example.

In print output, the default behavior does not add any styling to mathphrase. If you want it in italics, for example, you could add a customization like the following:

<xsl:template match="mathphrase">
   <xsl:call-template name="inline.italicseq"/>
</xsl:template>

If you are using DocBook 4.4 or earlier, the only solution seems to be to use phrase with a role="math" attribute for inline instances. The stylesheets do not apply any special formatting to phrase by default, so you would have to create a stylesheet customization if you want special formatting. The following example makes the math italic:

<xsl:template match="phrase[@role = 'math']">
  <xsl:call-template name="inline.italicseq"/>
</xsl:template>

The math you can display this way is limited to a linear sequence of text and symbols, with superscript and subscript as the only modifiers.