\MakeShortVerb{\|} \def\cmd#1{\texttt{\char'134#1}} \title{How does \acro{HTML} handle mathematics?} \author{Malcolm Clark} \begin{Article} \section{Introduction} There is a very short answer to the question posed in the title: not at all. However, as an instantiation of SGML (see, for example, \cite{EvH}, \cite{Goossens} and \cite{Bryan}), we can look first at how mathematics is handled in other \acro{SGML} \acro{DTD}s; and then examine how the expired \acro{HTML}3 draft proposed to include mathematics. The \acro{DTD}s already available which are designed to handle mathematics include \acro{ISO}\,9573 (\cite{ISO9573}) (confusingly, also known as \acro{ISO}\,12083), which is part of \acro{CALS}, \acro{AAP} (Association of American Publishers) (\cite{AAP}), and the \acro{HTML}3 draft (\cite{math}). The Euromath \acro{DTD} might also be relevant (\cite{Euromath}), but since its status is closer to that of proprietary it is too awkward to consider here. Van Herwijnen (\cite{EvH}) comments on the first two, comparing them to \TeX\ and |eqn|. A longer and more detailed examination of the \acro{AAP}, Euromath and \acro{ISO}\,12083\slash \acro{ISO}\,9573 is given in Poppelier, van Herwijnen and Rowley (\cite{PvHR}). Van Herwijnen provides an example from physics for the decay of a particle together with representations in \TeX, |eqn|, \acro{ISO}\,9573 and \acro{AAP}. The equation is: \begin{displaymath} \Gamma(J/\psi\rightarrow\eta_c\gamma) = \frac{\alpha Q_c^2}{24} \left\vert A(J/\psi\rightarrow\eta_c\gamma)\right\vert^2 \frac{m_\psi^2}{m_{\eta_c}^2} \left(1-\frac{m_{\eta_c}^2}{m_\psi^2}\right)^3 \end{displaymath} The entire expression is too extensive to compare here, but the left hand side of the equation in \acro{ISO}\,9573 may be given as \begin{Verbatim} Γ J/ψ → η c γ \end{Verbatim} while using the AAP dtd, it could be \begin{Verbatim} G(Jy &ar; h cg) \end{Verbatim} For the sake of completeness, the |eqn| alternative is \begin{Verbatim} Gamma(J/psi rarrow eta sub c gamma) \end{Verbatim} Eric's comments are interesting. He comments that the two \acro{SGML} representations are cumbersome and difficult to read, especially when contrasted to \TeX\ and |eqn|. He also rails against the obsession with representation. For example $\Gamma$ `means' decay width, but as far as the \acro{DTD}s are concerned we have \texttt{\Γ} and \texttt{G}. To be fair, \TeX\ and |eqn| hardly fare better, but at least we do know that we could have provided a more meaningful command. The second representation (\acro{AAP}) is particularly unfortunate, since instead of treating the symbol as a symbol, it treats it as a Greek letter. Of course, Eric is deeply imbued with the basic notions of \acro{SGML}, and would be very sensitive to this. His contention is that someone who already knew \TeX\ or |eqn| would have no motivation for learning or using these rather baroque alternatives. There is a point to be made about the rather cumbersome nature of the \acro{SGML}. Writing it by hand will be cumbersome, but surely no-one ever wants to write in this way. Structure editors are available. In the \TeX\ world, Scientific Word gives a structure editor for \LaTeX. This can be done since it is possible to hold an equation as elements in a tree structure, so that modification or correction to an element can be managed quite simply, and changes can propagate down the tree. The same sort of thing exists within the \acro{SGML} world. Euromath uses the Grif (\cite{Grif} and \cite{GrifSA}) editor for just this, and it would be easy to see other similar editors, like Chamberlin's Quill (\cite{Chamberlin}) maintaining the information. There is a question lurking whether mathematicians would actually like to input in this way. Just as experienced keyboarders find \acro{GUI}s very difficult and slow to use, perhaps the same sort of resistance would be found. However, the real point is that humans should not be expected to write \acro{SGML}. If they really must write \LaTeX, then an approach like Scientific Word, which could be coerced into generating a tree structure which could be mapped onto a \acro{DTD}, is potentially more valuable. A general issue, which Eric raises implicitly, is that none of the \acro{DTD}s offer a way of encoding meaning in a flexible way. Either the element is present already, or it is not. There appears to be no straightforward way of extending the range of elements. In the world of high energy physics and mathematics this must be something of a straightjacket. On the other hand, the bane of many editors' lives is the ease with which individual authors can `extend' \TeX\ or \LaTeX\ by adding a few new definitions. \subsection{SGML Notations} If we really did have existing equations, then one way to handle them within \acro{SGML} is through a Notation (see also \cite{Bryan}). A Notation permits a document to include data which is not to be parsed. It is therefore possible to include \TeX\ or \LaTeX\ and assume that at that point a convenient processor will be magicked to deal with it. He gives the example of the definition in a \acro{DTD}: \begin{Verbatim} \end{Verbatim} which may then be used later with the |Formula| element as \begin{Verbatim} ... \end{Verbatim} A scheme which already maps \acro{SGML} to \LaTeX\ (e.g.~\cite{Flynn} or \cite{Goossens2}) would find this a very easy way to absorb maths, provided all the equations were in the same notation. The prospect of a \cmd{newcommand} or \cmd{def} within the Notation could be worrying. Although this sort of expedient is plausible, it is not entirely successful. One of the arguments behind the use of \acro{SGML} is that it codes structure or meaning, rather than appearance (to echo one of Eric's points). \TeX\ and \LaTeX\ sometimes code meaning, but not in a consistent and reliable way. How do we extract information? If we have \acro{SGML}, it is relatively easy to find corresponding structural elements, which may then be extracted. Once we start including a Notation, this chance is all but gone; and if we include alternative Notations (say \TeX, \LaTeX\ \emph{and} |eqn|) it becomes even more problematic. It is not clear to me how these Notations, or even the \acro{DTD}s differentiate between in-line and displayed equations. I assume that an attribute could be included which specified the style. On the other hand \acro{ISO}\,12083 distinguishes between in line, displayed and `display formula groups' styles, through the use of different elements. There is perhaps a deeper question here, which is this, should it be at all relevant? Should the author be able to specify that some equations are in-line and others are to be displayed? It should make no difference at all to the content, although it would make great changes to the appearance. But to deal with maths is to deal with appearance, to a large extent. The display seems to be a key issue. Since many equations are strongly two dimensional (as opposed to the one dimensional nature of most text), it is a key question whether it is reasonable to expect this aspect to be reflected in any linearisation. To give \acro{ISO}\,12083 its due, it says ``Since there is no consensus on how to describe the semantics of formulas, it only describes the presentational or visual structure.'' \section{\acro{HTML}3 (expired draft)} \acro{HTML}3 supports a || element which provides some capability for the inclusion of maths expressions. The draft (\cite{math}) does indicate that this capability is limited. It describes the functionality as similar to that found in ``common word processing packages''. In itself this may be seen as a hint of one of the driving forces within \acro{HTML}3 -- a desire to emulate word processor functionality. For a language which derives initially from a high energy physics community, this is a modest aim. The other design aim of || in \acro{HTML}3 is to be ``concise and comparatively easy to read''. As a rider, it is suggested that this will make formulae longer than \LaTeX, but shorter than Euromath or \acro{ISO}\,12083. It is stated that the maths owes ``a lot to \LaTeX's math mode''. In some cases it uses names for elements which are derived from \TeX/\LaTeX. Immediately a misconception springs up. The second paragraph of the section on maths gives examples of \LaTeX\ commands: namely \cmd{atop}, \cmd{choose} and \cmd{sqrt}. Only \cmd{sqrt} is a \LaTeX\ command. The \cmd{atop} and \cmd{choose} are unrepentant \TeX. Ignoring for a moment the fact that there is a clear confusion between \LaTeX\ and \TeX\ in the mind of the author of the draft (Dave Raggett),\footnote{I suspect this is quite a widespread misunderstanding.} there is actually a deeper problem. The use of an operator like \cmd{over} requires much more work on the part of a processor, since it is often not until the whole expression has been parsed that sense can be made of what is actually \cmd{over} what (see \cite{seb}). From years of teaching \TeX, I can confirm that the \cmd{over} command (and its buddies, \cmd{above}, \cmd{atop}, \cmd{choose}, \cmd{brack} and \cmd{brace}) can lead to immense frustration and confusion. \acro{HTML}3 also has an || token, but this is quite different from \TeX's \cmd{above}. Since the \TeX\ command is quite typographic, specifying the width of the line separating numerator and denominator, this is probably not too ambiguous. The function of the \acro{HTML}3 tag is to allow something to be drawn above an expression. There is a similar || tag. || is a sort of numerator operator: \begin{Verbatim} x+y \end{Verbatim} gives something like \begin{displaymath} \overline{x+y} \end{displaymath} with the nuance that the element takes an attribute |sym| which can specify other symbols: |line| (the default), |cub|, |larr|, |rarr|, |hat| and |tilde| (in a sense |hat| and |tilde| correspond to \cmd{widehat} and \cmd{widetilde}). For example, \begin{displaymath} \overbrace{a+b+c} \end{displaymath} would be \begin{Verbatim} a+b+c \end{Verbatim} the corresponding || has the same list of possible |sym| attributes, though I don't immediately understand what |hat| and |tilde| would do. There are also some terminological surprises. || almost borrows the use of underscore and carat/circumflex for sub-scripts and super-scripts, except that they are referred to as index and exponent. The |^| and |_| are actually |shortref|s for || and ||.\footnote{The notion of exponent and index may be welcome, since we would expect \acro{HTML} to be concerned with the underlying content. Perhaps \TeX\ does tend to overload the idea, since a superscript may signify more things than just an exponent. A semantic separation might be a very good idea, but this is unlikely to be the intention, since they are |shortref| characters for || and ||. Poppelier \textsl{et al.}\ put this very succinctly: ``What is the function of the 2 in SU$_2$, $\log_2x$, $x_2$, $x^2$ $T_2^2$? In SU$_2$ it is the number of dimensions in the Lie group; in $\log_2x$ it is the base of the logarithm; if $x$ is a vector, the ${}_2$ in $x_2$ is an index; the ${}^2$ in $x^2$ could be a power, but if $T$ is a tensor, the ${}^2$ in $T_2^2$ is a contrainvariant tensor index.'' } Since \acro{HTML} syntax and \LaTeX\ syntax are rather different, the ease of \LaTeX's sub- and super-scripting has to be abandoned. The \acro{HTML} tag has to be terminated. It is unfortunate that there was not a way of employing an implied end tag. For example \begin{small} \begin{displaymath} a^{23}_n \end{displaymath} \end{small} is given from \begin{Verbatim} a^23^_n_ \end{Verbatim} Should you need to subscript a subscript, the |shortref| form cannot be used. Although || does support a grouping operator, \begin{displaymath} a_{b_c} \end{displaymath} is obtained from \begin{Verbatim} abc \end{Verbatim} Perhaps cleverly, superscripting an expression with a binary operator results in the expression being placed over the operator, like \cmd{stackrel}. For example \begin{displaymath} A \stackrel{\alpha'}{\longrightarrow} B \stackrel{\beta'}{\longleftarrow} C \end{displaymath} would be \begin{Verbatim} A →^α′^ B ←^β′^ C \end{Verbatim} In passing note that the use of the `prime' operator is different from \TeX\slash \LaTeX\ use, and the use of space. I am not entirely clear about the use of space in ||. It is certainly not ignored, as in \TeX, and the draft does comment on the use of different horizontal white space within the equation. The draft runs \begin{quote} Spacing between constants, variables and operators is determined automatically. Additional spacing can be inserted with entities such as | |, |&sp;| and |&quadsp;|. White space in the markup is used only to delimit adjacent variables or constants. You don't need spaces before or after binary operators or other special symbols as these are recognised by the \acro{HTML} math tokeniser. White space can be useful, though, for increased legibility while authoring. \end{quote} This does imply a rather different use of space. This use of space does have the effect that a `prescript' can be made quite unambiguously simply by ensuring it is preceded by a space. It would imply a string |sin| is recognised as `some sort of function'. The string |xyz|, would also presumably imply `function', while in \LaTeX\ it would imply the three variables $x$, $y$ and $z$. It does leave unclear how \(\sin^2\theta \) and \begin{displaymath} \max_{i=1}^n x_i \end{displaymath} would be handled with ease. If the $\sin^2\theta$ uses || but the \begin{displaymath} \max_{i=1}^n x_i \end{displaymath} requires || and || then we have an interesting inconsistency. || does adopt \TeX/\LaTeX's notion of binary operators, and in general claims to reflect the assumptions of \TeX/\LaTeX. It does not however provide support for multi-line equations, stating that `this can be effectively handled by combining math with the |TABLE| element'. To me this wanders far from the basic concepts of \acro{SGML}. However, what it appears to mean is that the || tag uses the same sort of syntax as ||, not that an array uses the table tags. From the draft, it is anticipated that chemistry could be set from within the || tag. I would view this as a mistake. It may be (almost) defensible from within \LaTeX\ to use math structures, although the various chemistry packages at least try to separate the notions. It seems unfortunate that HTML3 should not attempt something similar.\footnote{And of course this emphasises the inadequacy of referring to a subscript as an index and a superscript as an exponent. The terms are pretty meaningless for chemical notation.} An example might be \begin{Verbatim} Fe_2_^2+^+Cr_2_O_4_ \end{Verbatim} for \begin{displaymath} \mathrm{Fe}_2^{2+}+\mathrm{Cr}^{}_2\mathrm{O}^{}_4 \end{displaymath} where the different notational style of chemistry is tackled, notably its use of an upright font and consistent baselines for subscripts. Some hints on appearance are provided: it is expected that functions (operators), numbers and other constants are portrayed in an upright font, and variables are italic. Unlike \TeX/\LaTeX, limits for integrals and summation signs are said to be placed directly above or below, or to the immediate right (depending on the symbol). Unfortunately, the draft does not indicate quite what this ambiguous term means. I suppose it does not mean `emulate' the \TeX/\LaTeX\ mode, though that is obviously plausible, and from the point of view of a browser author could be a reasonable path. What does it look like? \begin{Verbatim} ∫_a_^b^{f(x)1+x} d x \end{Verbatim} for \begin{displaymath} \int_a^b\frac{f(x)}{1+x}dx \end{displaymath} Note that the sub- and super-scripts, like \TeX/\LaTeX\ also denote limits. Some maths accents are available: ||, ||, ||, ||, || and ||. There are no explicit equivalents for \cmd{check}, \cmd{breve}, \cmd{acute} and \cmd{grave}, although they could be created with ||. Another borrowing from \TeX/\LaTeX\ is the notion of grouping: \acro{HTML}3 uses a || element where \TeX/\LaTeX\ would use parentheses. || can be replaced by a |shortref| form of |{| and |}|, which greatly aids brevity and comprehension.\footnote{Should you need the symbols themselves, they are obtained by the entities \texttt{\{} and \texttt{\}}.} Although \TeX nically a braced group is a sort of `box', perhaps || might have been a better, though less concise term, in the context. It is perhaps an unfortunate choice, since `box' carries overtones for many \TeX\ users. Still, it does ensure that all the power of grouping is present (fairly essential in view of the || element). To overload slightly, one of the attributes of the || element is |box|, which causes a box to be drawn around the formulae. The || element is used in a number of ways; it is used, for example with the || and || commands for delimiters which grow. This leads to a rather strange construction: \begin{Verbatim} f(x)= ( 1+x sin x ) <\box> \end{Verbatim} where |(| gives a left parenthesis of appropriate size and |)| gives the corresponding right parenthesis. As with \TeX, it is recognised that sometimes it may be necessary to have a delimiter larger than `default'. || therefore has a |size| attribute to enable this to happen. The permitted values are |normal|, |medium|, |large| and |huge|. The |shortref| form cannot take attributes. Integrals (and other large operands which are stretchy) also need the use of ||, without any corresponding ||. For example \begin{Verbatim} ∫_-&inf;_^&inf;^ f(x,y) x^2^+y^2^ d x d y \end{Verbatim} should give \begin{displaymath} \int_{-\infty}^\infty\frac{f(x,y)}{x^2+y^2}dx\,dy \end{displaymath} Although || is said to recognise functions as maths entities, there is no list of all the entities given in the draft. However, straightforward elements like || and || exist which work the same as their \TeX\ counterparts. The \LaTeX\ notation for $\root n \of x$ however is \cmd{sqrt} with an optional argument: |\sqrt[n]{x}|, not as HTML3: \begin{Verbatim} nx \end{Verbatim} which is rather closer to \TeX. What the draft terms `Greek letters' are available in a similar way to \TeX/\LaTeX\ as entity references (and includes omicron). Some control over font styles is available through || and ||. The first emboldens, while the latter makes upright (Times?). You may even combine the two as ||. Note that these changes apply to variables and constants, and not to numbers, delimiters, operators and other symbols. An interesting attribute is |class|, so that we could identify a vector as \begin{Verbatim} a=A′ \end{Verbatim} Arrays or matrices are quite verbose, but broadly similar to \LaTeX. They are introduced by ||, while each row starts with || and each cell with an ||. This is in line with HTML's |
| model. Adapting some aspects of \LaTeX, column definitions can be added, for example |coldef="CCCC"|, the default, where columns are centred. The alternatives are |R| and |L|. This is one of the few instances in HTML where case is vital. If the attributes are separated by |+|, |-| or |=| this will propagate down the array as a separator. For example \begin{Verbatim} \end{Verbatim} Other attributes include |ldelim| and |rdelim| to specify the right and left delimiters of the array or matrix. Unlike other instances where a name is used, the symbol itself appears to be used in this context. \subsection{Summary} I tend to think that this makes it more difficult for someone with a \LaTeX\ background to interpret ||. When two languages are quite different, there is rarely confusion in flipping from one to the other, but when they share many similarities it can be frustratingly simple to converge at all the wrong times. Note also that || uses the ISO entity names for symbols (\cite{SandS}) rather than the \TeX\ names. In a few cases this sows potential confusion. The confusion which exists within the draft between \TeX\ and \LaTeX\ is not of itself a problem, except that people coming to HTML3, being told it is `like \LaTeX', would find some key differences. The main divergences are \begin{enumerate} \item the interpretation of space\label{space} \item need to close most \acro{SGML} elements (e.g.\ |^| and |_|) \item || \item interpretation of functions (a consequence of \ref{space}) \item entity names similar but not identical to corresponding commands \item use of |′| \item missing commands \item poor support for cross-referencing \end{enumerate} \section{Future of maths in HTML} At this point, it may be worth considering the extent to which any maths expression can divorce the semantic component from the form on the page. Often the way equations are portrayed can assist in their interpretation. Both tables and maths seem to be examples where the meaning and the appearance are very closely intertwined. There are instances where an author changes notation in order to pursue an argument. One assumes that the essential meaning does not change between changes in notation, and that perhaps a markup system might not even note the change, except perhaps as an attribute. The draft document which forms the basis of this discussion expired in September, 1995. Some of the new structures which it introduced, notably tables, form part of most browsers now, but mathematics didn't make it (although || and ||, without || did) (see \cite{html32}). An email from Dave Raggett (to David Carlisle), who wrote the draft, notes that \acro{W}3\acro{C} \begin{quote} has set up a small working party on math, and we expect to publish a detailed proposal by early Summer. The March'95 spec will provide a starting point, but we may end up with something rather different. \end{quote} \noindent He goes on to state: \begin{quotation} \noindent The \acro{W}3\acro{C} math group has the goal to develop an open specification for \acro{HTML} math that: \begin{itemize} \item[]Is suitable for teaching, and scientific publishing. \item[]Works with symbolic and numerical math applications \item[]Supports filters to/from other math formats, e.g.\ \TeX \item[]Is easy to learn and to edit by hand \item[]Is well suited to template and other math editing techniques \item[]Can be rendered to: \begin{itemize} \item[]graphical displays \item[]speech synthesisers \item[]plain text displays e.g.\ \acro{VT}100 emulators \item[]print media, including braille \end{itemize} \item[]Supports lengthy expressions via fold\slash unfold and line breaking with author control. \end{itemize} This is shaping up as the need for simple macros and declarations that define terms etc. for use across multiple || elements, and parsing of |PCDATA| using ``models'' referenced by || elements. These models define how to interpret stuff at a level sufficient to support symbolic manipulation without having to make all these distinctions explicit in the markup itself. \end{quotation} This is quite a bold extrapolation from the original specification. Some of the suggestions seem to me to be incompatible. The inclusion of symbolic and numerical applications is interesting and goes far beyond the existing maths \acro{DTD}s. The relevant \acro{W}3\acro{C} web page (\cite{W3C}) contains a reference to \acro{QED}, an ambitious programme to build a `single, distributed, computerized repository that rigorously represents all important, established mathematical knowledge'. If this genuinely represents part of \acro{HTML}'s solution to maths, we will have some time to wait before a system is available. \section{Conclusion} It is not clear to me at present whether \acro{HTML} will ever be rich enough to do the sorts of things which mathematicians and physicists want to do with maths. Of course, it could be that these are not the market at all. I have long argued that one of \TeX's (and \LaTeX's) major problems is that the population of users who benefit by it is small -- very much a minority. And the expansion of the use of computers has made them an even smaller minority. At best we are a niche market. Some of the simpler problems are already tackled quite conveniently by word processors, further eroding the niche. Why bother with mathematics at all? Is it really worth the effort, compared with something sexy like |