How to properly abbreviate symbols with subscript in math?

I would like to abbreviate $omega_0$ as o0 in formulas. So I define it as

#let o0 = $omega_0$

Later, I want to use write the square of this in a formula, i.e.

$o0^2$

But this does not render as $omega_0^2$ (with 0 and 2 on top of each other), but with the 2 to the right of the whole $omega_0$.

How do I define an abbreviated mathematical variable with a subscript so that I can add squaring later on when I use it?

It seems that you aren’t yet using Typst v0.12, as that behaviour was fixed with the latest update.

1 Like

Oh, indeed, ArchLinux has still 0.11.1. Trying this in typst.app, it works as expected. So I will wait for 0.12.

However, if I look at the representation of what I’m producing, I still get something that seems wrong:

#let o0 = $omega_0$
#repr($o0^2$)

shows

equation(
  block: false,
  body: attach(
    base: equation(block: false, body: attach(base: [ω], b: [0])),
    t: [2],
  ),
)

which contains unnecessarily nested equations. I understand why it happens (because of the $$ in the definition of o0), but is does not seem right. Is there a more correct way to define o0 than to enclose its body in $$?

In principle you can write the math function call out directly:

#let o0 = math.attach(sym.omega, b: [0])
#repr($o0^2$)

Which is still not perfect:

equation(
  block: false,
  body: attach(base: attach(base: [ω], b: [0]), t: [2]),
)

However, as far as I know that should not matter at all. Nested equations in particular are expected in idiomatic Typst markup and are eliminated during layout. 0.12 is now doing the same for attachments (or so it seems, I don’t know the details). So I wouldn’t worry about it. $$ is the clean way to do this.

2 Likes

? It was updated on 10/19

Oh, indeed. I didn’t do pacman -Sy, so I got the old version even though I installed on Oct 25. Unfortunate timing.

Hey @Dominique_Unruh, welcome to the forum! I’ve updated your post to better fit our guidelines for the Questions category: How to post in the Questions category

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

1 Like