Is there a conventon for how to insert alignment points?

Do you add a space around & or not? Is there a convention, or is this purely a personal preference?

In documentation, it is used without spaces:

$ sum_(k=0)^n k
    &= 1 + ... + n \
    &= (n(n+1)) / 2 $

I haven’t used them enough, but I think that in most cases it is more readable to surround it with spaces. What do you think?

As a Latex user I’ve always thought of & as being attached to the next symbol (this symbol serving as the alignment point), and it’s never been very clear to me how the “alternative right and left alignment” works, so I just doubled the symbol (writing &&) where necessary based on memory or by trial and error.

Now checking the typst documentation I see it says

this creates blocks of alternatingly right- and left-aligned columns

which I find very helpful: thinking of alignment in columns is much easier, more concrete. Then logically the most readable way to arrange the source code must be to show the actual columns, ideally with the correct alignment already in the source. Taking the example from Math – Typst Documentation this gives

$
(3x + y) / 7 & = 9        &                 & "given"      \
      3x + y & = 63       & "multiply by 7"                \
          3x & = 63 - y   &                 & "subtract y" \
           x & = 21 - y/3 &   "divide by 3"
$

I’m not sure it’s the most readable but it does help understanding how the alignments work. Also it’s a chore to align the source like that manually so I’ll wait for a plugin in my text editor to do it for me :slight_smile:

1 Like

Huh, so in another example, it used in both ways. This can imply that there is no convention.

The way the alignment points work in Typst is slightly different than in TeX. You might be interested in having a read through Wonky math alignment · Issue #1268 · typst/typst · GitHub.

1 Like

Thanks! This shows that in my previous post things look very simple because I don’t consider in which column the spaces (e.g. between 7 and =) should land. Reality is more complicated…