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]:
For HTML, export to LaTeX and then use latex2html. This has some disadvantages:
Excessive memory usage: latex2html will consume a lot of memory (FIXME: is this still the case?)
Most important: We are talking about an SGML document here and all the DocBook markup will be lost if you transform it back to LaTeX - just think about the admonitions (see Section 4.7), callouts (see Section 4.8) and all the other SGML stuff that will be impossible to transform back!
For PostScript®, export to LaTeX, then create the .dvi file (by calling LaTeX) and then the PS file using dvips. That's O.K., since it directly uses TeX and the mathematics will be as accurately typeset as possible.
For PDF, transform the above PostScript® file to PDF using ps2pdf, or some commercial program like the Acrobat® Distiller®. Taking the roundtrip to PS in order to arrive at PDF has some serious drawbacks, though (FIXME: which ones?) After all, pdfjadetex was developed to avoid exactly these drawbacks, so it would be nice if we could use it.
For RTF, no way seems to exist to get mathematics from LyX in this format.
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:
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> ∫ </mo> <mrow> <msup><mi> x </mi><mn> 2 </mn> </msup> </mrow><mo> ⁢ </mo> <mrow><mo> ⅆ </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:
The TeX code that typesets the equation is enclosed between the <alt> tags. We will make heavy use of this fact later.
The equation is again output, this time between the <math> tags. This is MathML.
The whole is enclosed in the DocBook <equation> tags.
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.
[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 |