Karakas Online

Chapter 10. Mathematics

Table of Contents
10.1. DBTeXMath
10.2. Writing Mathematics in LyX
10.3. The magic behind the math
10.3.1. SGML math code correction
10.3.2. HTML and RTF
10.3.3. PDF and PS
10.4. Problems of the DBTeXMath method

Since LyX is a frontend for LaTeX, it is no secret that it has exceptional capabilities when it comes to typesetting mathematics. However, when it comes to transforming the .lyx document to different format, the possibilities are rather limited[1]:

The above is not a satisfactory situation. Even if we can get mathematics in some formats, we would have to abandon the SGML framework we have been using so far. It would be nice if we could continue to write in a DocBook SGML document in LyX, using all the excellent math typestting capabilities of TeX/LaTeX and then export to whichever of the above formats through our usual scripts and tools like openjade, pdfjadetex etc. In fact, as the following example already shows, we can:

Equation 10-1. (eq2)

Let's see what is going on, from the SGML point of view, when you type an equation like Equation 10-1[2] in LyX: when exported to SGML, this equation yelds the following MathML code:

 <equation>
  <alt>\begin{equation}
{\displaystyle }\int _{a}^{b}x^{2}dx=\frac{1}{3}(b-a)^{3}\label{eq2}\end{equation}

  </alt>
  <math>
   <mtable>
    <mtr>
     <mrow>[par][displaystyle [par]]<mo> &int; </mo>
      <mrow>
       <msup><mi> x </mi><mn> 2 </mn>
       </msup>
      </mrow><mo> &InvisibleTimes; </mo>
      <mrow><mo> &DifferentialD; </mo><mi> x </mi>
      </mrow><mn> = </mn>
      <mfrac><mn> 1 </mn><mn> 3 </mn>
      </mfrac>
      <msup><fenced open="(" close=")">
       <mrow><mi> b </mi><mn> - </mn><mi> a </mi>
       </mrow></fenced><mn> 3 </mn>
      </msup>
     </mrow>
    </mtr>
   </mtable>
  </math>
 </equation>

There are some remarks due here:

As you see, LyX is already capable of producing the (excessively verbose) MathML version of our equation. However, the technologies for delivering Math on the Web through MathML are in constant flow (see a MathML status report). Furthermore, my openjade will spit dozens of errors, one for each MathML tag. Even if I were able to eliminate these through the use of some extra module, it seems that the quality of the results, be it online or printed, is going to be rather dissapointing, as the following quote by Allin Cottrell[3] clearly indicates:

A dsssl engine such as openjade can turn the MathML into TeX for you but the results are likely to be disappointing, particularly if you are used to typesetting mathematics using TeX itself. TeX's native mathematical typesetting is near-perfect, only occasionally requiring manual tweaking to achieve optimal results; it is also rather comprehensive, with the aid of the AMS (American Mathematical Society) extensions if need be. But if you take the route of MathML to TeX via dsssl and jade, the specifics of the math typesetting must be handled by the dsssl stylesheet. David Carlisle put some work into this a few years back (for which we can be grateful), but he didn't finish the job and nobody else has done so since. Thus if you send MathML through jade to TeX you are likely to find (a) that those elements that are recognized by the stylesheets are typeset less adeptly than by TeX itself (with clumsy-looking spacing), while (b) various important elements may not be recognized at all. For example in my field of statistics the overbar (denoting the arithmetic mean) is a common modifier, but it is simply ignored. Other formulations common in statistics are also ignored, or are not dealt with properly, so this route is not really usable for me.

Allin Cottrell has introduced the DBTeXMath method, which I have slightly modified and incorporated in the method I presented so far. In the following sections I will first describe the necessary steps and software, then the explanation of the details.

Notes

[1]

Even if the starting point is not a LyX document, the task of presenting Mathematics on the Web is not a trivial one, although (or exactly because) there is a bunch of solutions to choose from, see Math Typesetting for the Internet.

[2]

as you can see already, cross-references to equations (and with them also equation labels and titles) do work for all formats too with the method I will describe.

[3]

the creator of the DBTeXMath method that we are going to use here

Last updated Mon Sep 24 01:19:25 CEST 2007 Permalink: http://www.karakas-online.de/mySGML/mathematics.html All contents © 2002-2007 Chris Karakas