How can I right-align text in math mode?

Is there a way to align text, such that the text is on the right side of the page on block math?

I tried using:

$
x = y #h(1fr) text("text on the right")
$

But this will not create any horizontal gap and the text is directly after the equation.

Thanks for the help in advance

Hello @jw01 , welcome to the forum,

Please see How to properly align math? as this is a duplicate.

If the question is specifically about layouting text inside math blocks, answer could also be found here: How do I make the math area take up the whole width of the page?

I guess using fixed horziontal spacing works. Do you per chance know why #h(1fr) does not work the same as in plain text?
Even if i use

#show math.equation.where(block: true): set block(width: 100%)

#h(1fr) still does nothing in the math environment. If i use it in text it would take the whole space and would force everything behind it to be on the right side of the page.

I’d guess this has something to do with relative/fractional lengths being implemented differently when inside of math mode, but i’m not sure why this behavior arises and whether or not it is a bug

there’s an open issue for fractional unit spacing in math: Fractional units are broken in math · Issue #5780 · typst/typst · GitHub


What do you think about this solution for the question?

#import "@preview/intextual:0.1.1": flushr, intertext-rule
#show: intertext-rule
$
x = y #h(1fr) flushr("text on the right")
$

bild

1 Like

This is a good solution. I hope the fractions problem will get fixed soon, that would be a little easier. Until then i guess i will be using intextual. Thank you

1 Like

intextual has a notice about its side effects - which are probably ok, but if they are not you’ll need to apply its intertext-rule only on select equations.

Side Effects :warning:

The show: intertext-rule rule will draw an invisible 100% width line above each math.equation.where(block: true) to determine the boundaries of the container. This affects standard equation alignment in enums/lists and grids/tables with auto width.

In default Typst, block equations in enums/lists will be centered according to the maximum horizontal space required by any enum/list item, however, with the intertext-rule applied, the maximum available width will always be used.