\( \newcommand{\thin}{\,} \newcommand{\verythin}{\hspace{0.04em}} \)

Space Math

Mathematical notation can be ambiguous. Does \(h(c + 1)\) mean the function \(h\) evaluated at \(c+1\), or does it mean the quantity \(h\) times the quantity \(c+1\)? Does \(|X|\) refer to absolute value, determinant, cardinality, order, or length? Is \((1,8)\) an open interval or a point on a coordinate plane? Does \(\mathbf{A} \times \mathbf{B}\) refer to cross product, Cartesian product, direct product, or ordinary multiplication?

Without context, answers to those questions are only guesses. Even if the guess is correct, only someone knowledgeable in the subject will know how to pronounce the symbols. This is bad for students, because understanding how to talk about the notation is part of learning. And it is bad for anyone listening with a screen reader, because the words they hear could be different than the intended meaning.

The original author of the formula knew what they intended, but current methods of writing mathematics do not provide an easy way to distinguish between common ambiguous expressions. Space Math will provide that facility. The syntax has similarities to LaTeX (without the backslashes) and to AsciiMath (with some new features), with some ideas borrowed from Python. The lowly "space" character does a lot of the work, with intuitive macros mostlly taking care of the remainder. The following examples illustrate the idea.

Space Math syntax incorporates ingredients from LaTeX, AsciiMath, and UnicodeMath. To the extent possible, Space Math is backward compatible with all three of those languages, meaning that the majority of expressions in those systems are parsed correctly when incorporated into Space Math.

The first step in this ambitious project is to develop a formal definition of the language. Once the grammar of the language is specified, it will be possible to write a parser, and then write routines to output as LaTeX for printing and MathML for the Web (perhaps via LaTeXML), with the Web version retaining the semantic information from the original source.

Questions, comments, skeptical remarks, or expressions of interest to David Farmer farmer@aimath.org

Examples of Space Math

  1. \(f\) of the quantity \(x + 1\) plus \(g\) times the quantity \(y + h\)
    f(x+1) + g (y+h)
    \(f(x+1) + g\thin(y+h)\)
  2. Don't require markup which can be inferred from context.
    int_5^20 4 x dx = 2x^2 |_5^20 = 750
    \[ \int_5^{20} 4\verythin x \thin dx = 2\verythin x^2 \bigg|_5^{20} = 750 \]
    TeX forces the writer to type \, before the dx, or else the spacing looks bad. Space Math recognizes that int and d(something) form a pair, and it does the right thing. Similarly, Space Math automatically resizes the vertical evaluation bar. For those who like their integrals with an upright "d", as in \(\mathrm{d}x\), that is a decision concerning the output: the input markup is the same.

    Numbers are numbers, not strings of characters, so x^20 in Space Math is like x^{20} in TeX. Since a number next to a letter automatically means implied multiplication, the space in 4 x is optional.

  3. Don't write |x|. Write abs(x), or card(x), or len(x) or length(x), or det(x), whichever you mean. (In simple cases, the parentheses around the argument of those functions is optional: abs -5 = 5 becomes \(|\verythin{-5}\verythin| = 5\). )

    abs(x) = cases: x if x > 0, -x when x < 0, 0 otherwise.
    \[ |x| = \begin{cases} x & \text{if}\ \ x > 0, \\ -x & \text{when}\ \ x < 0, \\ 0 & \text{otherwise.} \end{cases} \]
    Space Math uses a Python-like syntax for multiline constructions (but is not rigid about requiring the exact same indentation on every line). In the cases environment it recognizes several common keywords, as shown above.
  4. Leave space around symbols like < when they are used literally, such as 3 + 5 < 10 - 1. That example happens to work if you omit all the spaces, but in other situations the presence (or absence) of spaces helps clarify the meaning.
    ZZ prod ZZ isom <a, b | a b = b a> <u, v> = 0 "if" u perp v
     
      \[ \mathbb Z \times \mathbb Z \simeq \langle a,\verythin b \ | \ a\verythin b = b\verythin a \rangle \] \[ \langle u, v \rangle = 0 \ \ \text{ if }\ \ u \perp v \]
    The space before and lack of space after the <, and vice-versa for >, helps ensure the expressions are interpreted correctly.

    The abbreviations prod, isom, and perp can be written out fully. Replacing prod by cross, times, or by will achieve the same visual appearance, but the operation being performed is the product of groups, and using different markup could cause incorrect interpretation. (We wrote "could", because the software may be clever enough to recognize that \(\mathbb Z\) is a group, and so those other operations either don't make sense, or are less likely. But that is not an argument against writing the markup properly.)

    Under discussion: What is the right way to indicate that u and v in the above example are vectors? Maybe vec u? Who controls whether the vector v is displayed as bold \(\mathbf{v}\), or with a little arrow \(\vec{v}\), or in some other way?

    The meaning of an expression, and more importantly its pronunciation, can depend on the subject area. What looks like a group presentation in algebra, <a | b>, is bra-ket notation in physics. The accuracy of Space Math is increased when the subject is specified.

  5. Multiline aligned expressions. Consider the system of nonlinear equations and inequalities
    system: 15 x^33 + pi x y = 99 x <= 2 x + 5y - 7 x^11 + 9y^3 cos(x y^-1) > 1 + 2 + ... + 100 + hat y_j - conj(x^2)
    \begin{align} 15\verythin x^{33} + \pi\verythin x\verythin y =\mathstrut& 99 \\ x \le \mathstrut& 2\verythin x + 5\verythin y - 7\verythin x^{11} + 9\verythin y^3 \\ \cos(x\verythin y^{-1}) >\mathstrut& 1 + 2 + \cdots + 100 \\ & + \hat{y}_j - \overline{x^2} \end{align}

    Several principles are illustrated. The system environment recognizes a new math line by a blank line. Default alignment is after the first relation in the line, or before the first symbol in the line. (There also is LaTeX style &-alignment.)

    Decorations, like \(\tilde f\), are interpreted as having higher priority than subscripts or superscripts, and so do not require parentheses when applied to a one-letter object. Don't write overline or bar when you intend mean or conj[ugate] or line[segment] or some other specific object/operation.

    The ... were interpreted as \cdots in the above setting, but would be interpreted as \ldots in an expression like $2, 4, 6, 8, ...$. The special words cdots and ldots are available for those who do not trust Space Math to do the right thing.

    The linearsystem variant assumes the system is linear and all the unknowns are on the left side and appear in the same order. The output vertically aligns the terms with the same variable, leaving blank space if the coefficient of a term is 0. If you have a system which is linear but you don't want the terms to line up, then just use system.

    A derivation is similar to a system, but is used when each line relates to the previous line. Ignoring the meaning of the lines, it looks like a system where only the first line has something on the left.

  6. Trigonometric functions are special. There is a long history of omitting the parentheses around the argument to a trig function in certain situations. For example, \(\sin \pi/2 = 1\). Logarithms are also treated that way: \(\log 2 \approx 0.694\). Not everyone considers this to be good practice, but it is common and Space Math supports it. The implied argument property of "trig-like functions" is formalized in the following way:
    Function application has higher priority than addition and higher priority than multiplication by a function, but lower priority than multiplication involving numbers and variables.
    For example:
    sin 2 pi n alpha = 2sin pi n alpha cos pi n alpha
     
      \[ \sin 2\verythin \pi\verythin n\verythin \alpha = 2\sin \pi\verythin n\verythin \alpha \cos \pi\verythin n\verythin \alpha \]

    The argument to the trig function on the left is \(2 \pi n \alpha\), and the argument to each trig function on the right is \(\pi n \alpha\). Visually, the output looks the same as TeX, but Space Math provides extra information to a screen reader. The multiple spaces before the cos in the source are interpreted the same as one space.

    By default the output shows the parentheses as given in the input, but there is an output option which inserts the implied parentheses.

    Many built-in functions are "trig like", meaning that in many cases it is not necessary to type the parentheses around their argument. For example, abs 2x is typeset as \(|2x|\).

  7. Iterated subscripts or superscripts prioritize from the right. Use double subscript __ or double superscript ^^ to put symbols on the left.
    e^-x^2 + a_n_i + c_{j k} + F_1__2(a, b; c; z)
     
      \[ e^{-x^2} + a_{n_i} + c_{j\verythin k} + {}_2F_1(a, b; c; z) \]

    If there is one subscript or superscript on the left, one can write it like _2 F_1.

    If you intend to mean \((e^\sigma)^2\) then use parentheses in the source — after all, those are required for clarity in the output. Writing \(e^{5 x^2}\) or \(e^{x^2 -7}\) requires grouping in the source. Note that the unary minus in e^-x^2 causes -x^2 to be a group.

    In the expression a_{1 1} the 1 1 is viewed as a double index, not implied multiplication. Writing a_11 does not require brackets, and refers to the \(j=11\) element of the sequence (a_j)_{j=0}^infty.

    Under discussion: does 5 -3 mean "5 times negative 3" or "5 minus 3"? Viewed literally, it looks like multiplication. But it is confusing to typeset that expression with implied multiplication and no parentheses, so it seems unlikely that is what the author intended. Does 1/2pi have the \(\pi\) in the numerator or the denominator? Do the spaces in these versions change the meaning?: 1 / 2 pi or 1/2 pi. If the author really meant \(\pi/2\), is it likely they would have typed any of those expressions? (Opinion: possibly one of those three options, but definitely not the other two.)

    Space Math is not a programming language: it is a convenient way to type math formulas while capturing the author's intent.

    Space Math allows the author to specify a subject area. This adjusts certain defaults. For example, in chemistry the elements are set in an upright font. The isotope used for radiocarbon dating, \({}^{14}\mathrm{C}\) can be written C^^14. Under discussion: should Space Math understand the mhchem ch macro?

  8. Any discussion of math markup has to mention the quadratic formula, right? Note that, as usually written in TeX, quantities such as \(bx\) and \(4ac\) appear imperfectly because there is no small space between \(b\) and \(x\), or between \(a\) and \(c\). Multiletter variables are not distinguished from a product of variables. Space Math inserts those very thin spaces automatically, because it interprets the space in the source as implied multiplication. (Note that some people do not like the thin space for implied multiplication. That is a decision made at the output stage: the input markup is the same whether or not those thin spaces are desired. The examples in this document include the very thin spaces in the display math, but generally not in the inline math. Compare the \(4ac\) above and the \(4\verythin a\verythin c\) below.)

    The motivation for Space Math is not the appearance of the output, which comes from TeX: Space Math is converted to TeX for typesetting. The purpose is to provide an easy way to distinguish between common ambiguous expressions.

    If $a x^2 + b x + c = 0$ then $$ x = (-b +- sqrt(b^2 - 4 a c))/(2a) $$
    If \(a \verythin x^2 + b\verythin x + c = 0\) then \[ x = \frac{-b \pm \sqrt{b^2 - 4\verythin a\verythin c}}{2\verythin a} \]
    There are several other ways to write the quadratic formula. Space Math understands most common LaTeX macros, with the backslash omitted, and any of (), [], or {} can be used for grouping. For example: x = frac[-b pm sqrt(b^2 - 4a c)]{2a}.

FAQ

  1. What problems does Space Math solve?

    Space Math offers two advantages over other methods of typing math formulas.

    a) Expressions like \(a(x + h)\), or \(|X|\), or \((a,b)\), are ambiguous. A person using a screen reader (software that reads text out loud, typically to someone who cannot see the words) may hear the formulas pronounced incorrectly, giving the symbols a different meaning than intended. Space Math provides an easy way to resolve the ambiguity.

    b) TeX is a typesetting language, not an authoring language. As a consequence, in LaTeX the writer has to type characters which carry no meaning, and also must worry about fine typographic points. The input int_5^10 7x dx in Space Math produces the same appearance as \int_5^{10} 7x\,dx in TeX. The naive view is that Space Math eliminated 5 characters. The preferred interpretation is that Space Math only required the author to think about the content of the formula, not its appearance.

    Space Math can be viewed either as a way to make mathematics more accessible, or as a convenient shortcut for producing formulas in TeX.

  2. Is Space Math like (La)TeX? "I already know LaTeX and would rather not learn something else."

    Almost everything in LaTeX math mode will work as expected in Space Math, including popular packages such as amssymb. Space Math looks a lot like LaTeX math with all the backslashes and spacing adjustments deleted. But you can leave in the backslashes if you wish.

    To take advantage of the new features of Space Math, insert spaces to indicate implied multiplication instead of a 2-letter variable, or function application instead of implied multiplication: c(t + 1) is the function c evaluated at t + 1, while c (t + 1) is the quantity c times the quantity t + 1. A little space makes all the difference. In TeX, those expressions are typeset identically and a screen reader has to guess how to pronounce them. In Space Math output, there will be a tiny gap to indicate the implied multiplication and a screen reader will pronounce both expressions correctly.

  3. Is Space Math like AsciiMath? "Students find AsciiMath easy to use and I'd rather not have them learn something else."

    Many of the symbol-based expressions in AsciiMath will work as expected in Space Math and almost all AsciiMath keywords are recognized.

    Space Math provides an easy way to write some expressions which are very difficult to do in AsciiMath, such as a multiline system of equations.

    AsciiMath always interprets its keywords as keywords, even when adjacent to other letters. For example, the string of characters lending in AsciiMath typesets as   \(\le nd \in g\) , while in Space Math is it just the variable 'lending'.

  4. Is the point of Space Math to capture the semantics of the math expressions?

    Space Math is about both more, and less, than the meaning of the formulas. All four of the expressions \[ \exp(x+5) \ \ \ \ \ \ \ \ \ \ e^{x+5} \ \ \ \ \ \ \ \ \ \ e^{5+x} \ \ \ \ \ \ \ \ \ \ e^{(x+5)} \] have the same meaning, but they are pronounced differently. The author of each expression probably had a good reason for choosing that specific form. Space Math allows the writer to create the intended formula, and generally focuses on preserving the information needed to pronounce the expression correctly. When an expression can have multiple meanings, but the pronunciation is the same in all cases, typically Space Math does not attempt to make a distinction.

    For example, the symbol \(\pi\) often means the number which is approximately 3.14159, but it also could appear in a number theory context as \(\pi(100) = 25\). That is, \(\pi\) is a function and that expression is pronounced "pi of 100 equals 25". It means there are 25 prime numbers less than 100.

    In a group theory context, the same formula \(\pi(100) = 25\) could appear and be pronounced exactly the same, but now it means: the permutation \(\pi\) sends 100 to 25. In both cases, Space Math knows that \(\pi\) is a function because the input was pi(100) = 25 with no space between the pi and the (100), but it does not know anything about that function.

  5. Isn't it confusing and non-obvious to give meaning to spaces, especially in multi-line expressions?

    Using a space for implied multiplication becomes natural fairly quickly, and also makes sense mathematically because function application, multi-letter variables, and multiplication, are fundamentally different.

    In many other cases there are keywords available. For example, interval(3,5), point(3,5), and gcd(3,5) are unambiguous in the source, and it is a choice whether those keywords appear in the output. (Showing "point" or "interval" in the output is an unlikely choice, but that information is hidden in the output so a screen reader can make use of it. In an introductory number theory book the author might want to see \(\gcd(3,5)\), but in a research paper the letters "gcd" tend not to be shown.)

    After typing "point" or "interval" repeatedly, the author may wish to have an easier way, which is available by appropriate use of spaces. Compare (3,5) and (3, 5). Which is point and which is an interval? One can also use "French notation" to unambiguously describe intervals on the real line: ]3,5[ is the open interval \(3 < x < 5\). The notation used in the output does not have to be the same as in the input.

    The multiline Python-like expressions have an inline form, for those who find that more natural: abs(x) = cases(x if x > 0,; -x when x < 0,; 0 otherwise.). The keyword now looks like a function, and the line ends at the semicolon. That expression can be written across several lines so that the source is easy to read and write, but it is the semicolons, not the newlines, which convey the structure.

  6. What exactly is the difference between LaTeX and Space Math?

    For those who already know LaTeX math, here is one way to think about it:

    a) Leave off all the backslashes and spacing directives like \,. Don't bother with \left or \right or \bigg or \mathstrut because size adjustments are made automatically. (And yes, there is a way to over-ride the automatic resizing.)

    b) Use spaces to make it clear if you mean multi-letter variable, or implied multiplication, or function application. Spaces also clarify a few other ambiguous constructions.

    c) Parentheses, square brackets, and curly brackets all are viewed literally, and also can be used for grouping, with the interpretation depending on context: {x | x^2 > 5} is a set and e^(x+3) is \(e^{x+3}\). If you intended to write \(e^{(x+3)}\), then supply the extra parentheses: e^((x+3)) or e^[(x+3)] or e^{(x+3)}.

    d) Numbers exist as a unit: x^15 means \(x^{15}\). If habit makes you insert the brackets in the source, as x^{15}, you still get the same output. For compatibility with longstanding TeX practice, the frac method of creating a fraction interprets numbers as characters: frac12 means \(\frac12\). That can also be written as 1/2 and you get the upright fraction \(\frac12\) in the output. (And yes, there is a way to get a slanted \(1/2\).)

    e) Functions and their arguments exist as a unit: e^f(x) gives \(e^{f(x)}\), while e^f (x) gives \(e^{f}(x)\),

    f) There are a small number of special constructions which go a long way toward resolving common ambiguities. Never type |x|. Instead, use whichever of these is appropriate: abs(x), card(x), det(x), len(x) or length(x), or norm(x). Or, leave out the parentheses in many case because all of those funcitons are "trig like". Is \((a,b)\) a point or an interval? If you can puzzle out which of (a,b) or (a, b) refers to a point and which an open interval, then you are starting to think the Space Math way. Write a times b if that is what you mean -- otherwise write a cross b or a by b, the latter for cases like "chess is played on an \(8\times 8\) grid of squares", or "a \(5 \times 7\) matrix cannot have a two-sided inverse because it is not square".

    g) A few more things, which are under discussion.

  7. How can I use Space Math?

    Space Math is currently under development. A test page is available, but not all of the features have been implemented.