MathJax-docs icon indicating copy to clipboard operation
MathJax-docs copied to clipboard

More description needed for option `mathmlSpacing`

Open universemaster opened this issue 3 years ago • 1 comments

The documentation for options need more information for mathmlSpacing vs TexRules.

I've spent 30 minutes reading through issues and source code but it is still not clear to me precisely what this option does.

It would be great to have an example for each option clearly highlighting the differences.

universemaster avatar Jun 07 '22 14:06 universemaster

You are right that there should be more detail about this.

MathML and TeX approach the spacing between items in very different ways. MathML inserts spacing on both sides of <mo> elements (Math Operator elements) based on the Operator Dictionary and the position of the <mo> within the surrounding <mrow> (the <mo> will be in a prefix, infix, or postfix position in the expression). Some renderers also add space in other locations, but that is not required by the specification as it currently stands. For example, Firefox will put a small amount of space between <mi> (Math Identifier) elements when the mathvariant attribute is different between the two <mi>. This means that <mi>sin</mi><mi>x</mi> will have a small space between "sin" and "x", since the multi-character <mi>sin</mi> has the normal variant by default, while the single-character <mi>x</mi> has the italic variant.

TeX, on the other hand, determines spacing based on the class of adjacent items in the expression (not just at operators). TeX assigns each item a TeX class (OP = large operator, BIN = binary operator, REL = relation, OPEN = open delimiter, etc.) and specifies a spacing too use between each possible pairing of adjacent classes (see the TeXBook Chapter 18 (p. 170)). So TeX can have spacing in palces that MathML doesn't, and the spacing does not always agree between the two.

For example, TeX does not put spacing between two adjacent relations; e.g., x == y in TeX will have no extra space between the two equal signs (other than what is part of the glyph in the font itself). But in MathML, both equal signs are in infix position, and so get an equal amount of space on both sides, meaning there will be twice that extra space between the two equals.

MJX-1 vs. MML-1

TeX does some rewriting of classes to make some situations work better. For example, in x + -y to make the minus sign act as negation rather than a binary operator, whereas an extra <mrow> is needed for this case in MathML (and the TeX input jax doesn't add one).

MJX-2 vs. MML-2

Other places involve the spacing between two things neither of which is an <mo>, though the conditions where these include spacing is rare. One is the spacing for \sin x, where both are <mi> nodes:

MJX-3 vs. MML-3

Firefox handles that by putting space between <mi> that have different variants, as discussed above, though MathJax doesn't do that. That approach introduces extra space in places where TeX would not, for example, in a\mathbf{i}.

I hope that helps clarify the difference between the two modes.

dpvc avatar Jun 08 '22 14:06 dpvc