# ConTeXt LMTX: mathalignment does not work properly

The following piece of code

\starttext
\startformula
\startmathalignment[n=9, align={middle,middle,middle,middle,middle,middle,middle,middle,middle}]
\NC x^{2}y^{2}-xy^{2}-x^{2}y+xy \NC = \NC 0^{2}y^{2} \NC - \NC 0y^{2} \NC - \NC 0^{2}y \NC + \NC 0y \NR
\NC                             \NC = \NC 0          \NC - \NC 0      \NC - \NC 0      \NC + \NC 0  \NR
\NC                             \NC = \NC 0                                                         \NR
\stopmathalignment
\stopformula
\stoptext


produces this result

with ConTeXt MKIV (texlive 2022) and that result

with ConTeXt LMTX (2022.08.25 19:21).

Is it a bug or something changed?

Yes, there are changes (math is currently in active development). Let me try to explain and suggest what to do.

Firstly, if you want all columns midaligned, you should replace

align={middle,middle,...,middle}


by

align={all:middle}


If you want to align first one left and second one right, you do

align={1:left,2:right}


Next, the reason you get the tight spacing in LMTX is that you have so many alignment points, and for every cell, you enter and leave math mode. The system tries to remember the math classes between different cells, and use that to insert appropriate inter-atom spacing. But that is not always trivial. Let us look at the first part of your right-hand side in the first line:

\NC 0^{2}y^{2} \NC - \NC 0y^{2} \NC


Here, the y^{2} at the end of the first cell is an ordinary atom (with superscript, but that does not matter). The - in the next cell is usually a binary minus. But if we have an ordinary-binary-end (yes, we leave math again when leaving the cell with minus) combination in a formula, the binary is converted to an ordinary, and we get ordinary-ordinary spacing instead, and that means it gets tight. (This conversion of the binary to ordinary is a good thing, since people tend to write $a-$ to mean for example a left-limit at a, and then it is expected to have no extra space between the a and the -. Same, and perhaps more clear, if the minus happens to be in front: $-a$ should give a unary minus (same sign but no space).)

One way to get around your problem is simply to use less cells in the align, and perhaps also to align differently. This way, the system will not see ordinary-binary-end, but for example ordinary-binary-ordinary, and then there will be "correct" spacing. You could for example try this:

\startformula
\startmathalignment[n=5, align={all:left}]
\NC x^{2}y^{2}-xy^{2}-x^{2}y+xy \NC = 0^{2}y^{2} \NC - 0y^{2} \NC - 0^{2}y \NC +  0y \NR
\NC                             \NC = 0          \NC - 0      \NC - 0      \NC +  0  \NR
\NC                             \NC = 0          \NC          \NC          \NC       \NR
\stopmathalignment
\stopformula


It comes out as:

Personally, I would skip the middle line completely and move the last line up:

\startformula
x^{2}y^{2}-xy^{2}-x^{2}y+xy = 0^{2}y^{2} - 0y^{2} - 0^{2}y + 0y = 0
\stopformula


Result:

If you really want to break and align on the equal signs, I would suggest the rather recent ways of doing so without using alignments:

\startformula
x^{2}y^{2}-xy^{2}-x^{2}y+xy \alignhere = 0^{2}y^{2} - 0y^{2} - 0^{2}y + 0y \breakhere = 0
\stopformula


Result:

• Another option is to add ord atoms around the bin so \NC {} - {} \NC etc., which is similar to what the align environment in amsmath does for every odd alignment point. Commented Sep 2, 2022 at 16:41
• The braces no longer force an ord, do they? I think they are now merely used for grouping. (I did not try.) Commented Sep 3, 2022 at 7:19
• Neither did I. I need to re-learn how the basics work with LMTX. Commented Sep 5, 2022 at 14:45