How to Left-align Text using Math Mode's Alignment Operator?

I have a problem when using math mode’s alignment operator. It always right align text. See this example:

#set page(height: auto, width: auto, margin: 20pt)

$
&not exists x exists y (Q(x, y) <--> Q(y, x)) #h(160pt) &"Original" \
equiv &forall x not exists y (Q(x,y) <--> Q(y, x)) &"De Morgan's Law" \
equiv &forall x forall y space not (Q(x,y) <--> Q(y, x)) &"De Morgan's Law" \
equiv &forall x forall y space ((Q(x,y) and not Q(y,x)) or (not Q(x,y) and Q(y, x))) &"By (1)"
$

The output is:

However, my intended output is to look more like the traditional math example solutions e.g.

I am aware that this is achievable using a grid, but I think this use case is very common that I might be missing out on something. If there’s a better method to do this quick and easy please let me know.

Thank you for your time!

The alignment alternates between right and left with every alignment point, thus in your example, the alignments are

$
/*
Right & Left                    &             Right
*/
      &not exists ... #h(160pt) &        "Original" \
equiv &forall x ...             & "De Morgan's Law" \
equiv &forall x ...             & "De Morgan's Law" \
equiv &forall x ...             &          "By (1)"
$

You can simply put two of these alignment points together (&&) to skip one alternation and use the other alignment.

1 Like

Alignment markers alternate alignment between left and right, which is why the the part before the first & is right aligned, and the part between the first and second & is left aligned. You can achieve the behavior you want by doubling up to && so that it toggles twice, cancelling each other out, turning right & left & right into right & left && left.

For your case this would be:

#set page(height: auto, width: auto, margin: 20pt)

$
&not exists x exists y (Q(x, y) <--> Q(y, x)) #h(160pt) &&"Original" \
equiv &forall x not exists y (Q(x,y) <--> Q(y, x)) &&"De Morgan's Law" \
equiv &forall x forall y space not (Q(x,y) <--> Q(y, x)) &&"De Morgan's Law" \
equiv &forall x forall y space ((Q(x,y) and not Q(y,x)) or (not Q(x,y) and Q(y, x))) &&"By (1)"
$
1 Like

Welcome to the forum @Hasan! I’ve updated your post title to better suit our question guidelines: How to post in the Questions category

Make sure your title is a question you’d ask to a friend about Typst. :wink:

Thank you both @Eric @Bolt. I hope I asked earlier for help instead of using grid all these weeks lol. It works very well.